gfx2mo5: can now convert bitmap16 files.


git-svn-id: svn://localhost/thomson@68 85ae3b6b-dc8f-4344-a89d-598714f2e4e5
diff --git a/tools/gfx2mo5/libraw2mo5.c b/tools/gfx2mo5/libraw2mo5.c
index 47bd147..ac92612 100644
--- a/tools/gfx2mo5/libraw2mo5.c
+++ b/tools/gfx2mo5/libraw2mo5.c
@@ -18,6 +18,7 @@
   int previous = 0;
   bool lfo = false;
   uint8_t val;
+  static const int width = 320;
 
   tmpBuffer = (unsigned char*)calloc(0x4000,1);
   if (tmpBuffer == NULL)
@@ -25,7 +26,6 @@
     printf("Allocation tmpBuffer raté\n");
     exit(4);
   }
-	#define width 320
 
   for (y = 0; y < height; y++)
 	for (x = 0; x < 320; x+=8) {
@@ -93,3 +93,47 @@
 
   return tmpBuffer;
 }
+
+
+unsigned char *raw2bm16(unsigned char *input, int height)
+{
+  unsigned char *tmpBuffer;
+  int x,y;
+  int p1 = 0;
+  int p2 = 0x2000;
+  static const int width = 160;
+
+  tmpBuffer = (unsigned char*)calloc(0x4000,1);
+  if (tmpBuffer == NULL)
+  {
+    printf("Allocation tmpBuffer raté\n");
+    exit(4);
+  }
+
+  for (y = 0; y < height; y++)
+	for (x = 0; x < width; x+=4) {
+		int pix;
+
+		for(pix = 0; pix < 4; pix++) {
+			int nc = input[y*width+x+pix];
+			if (nc > 15) printf("Color over limit!\n");
+
+			switch(pix) {
+				case 0:
+					tmpBuffer[p1] = nc << 4;
+					break;
+				case 1:
+					tmpBuffer[p1++] |= nc;
+					break;
+				case 2:
+					tmpBuffer[p2] = nc << 4;
+					break;
+				case 3:
+					tmpBuffer[p2++] |= nc;
+					break;
+			}
+		}
+  }
+
+  return tmpBuffer;
+}
diff --git a/tools/gfx2mo5/libraw2mo5.h b/tools/gfx2mo5/libraw2mo5.h
index 38815e0..df97936 100644
--- a/tools/gfx2mo5/libraw2mo5.h
+++ b/tools/gfx2mo5/libraw2mo5.h
@@ -9,6 +9,10 @@
 #ifndef LIBRAW2mo5_H
 #define LIBRAW2mo5_H 1
 
+/* Convert picture to MO5/TO7/"40 columns" format (320x200, 16 colors, 8x1 blocks) */
 unsigned char * raw2mo5(unsigned char *input, int height, int fixup, bool to);
 
+/* Convert picture to "direct bitmap 16" format (160x200, 16 colors) */
+unsigned char * raw2bm16(unsigned char *input, int height);
+
 #endif
diff --git a/tools/gfx2mo5/png2mo5.c b/tools/gfx2mo5/png2mo5.c
index 2e02e22..1ca122c 100644
--- a/tools/gfx2mo5/png2mo5.c
+++ b/tools/gfx2mo5/png2mo5.c
@@ -38,8 +38,9 @@
   int pxsize;
 
   char opt;
-  int fixup = -1;
-  bool to = false;
+  int fixup;
+  bool to;
+  bool bitmap16;
 
   unsigned char thomheader[] = {
   	// Block 1 : address A7C0, 1 byte, select FORME
@@ -50,17 +51,22 @@
 
 
   // End marker block : type=255, size and address=0
-  const unsigned char end[]={255,0,0,0,0};
+  static const unsigned char end[]={255,0,0,0,0};
 
   if(argc < 3) 
   {
     printf("Utilisation : %s [options] input_filename output_filename\n",argv[0]);
+	printf("Option -m s: Mode to use (bm16/40c)\n");
 	printf("Option -t: use TO transcoding.\n");
 	printf("Option -f n: use modified algorithm to avoid artifacts on some MO5 gate array versions. n is the index of the background color.\n");
     exit(0);
   }
 
-  while((opt = getopt(argc, argv, "tf:")) != -1) {
+  fixup = -1;
+  to = false;
+  bitmap16 = false;
+
+  while((opt = getopt(argc, argv, "tf:m:")) != -1) {
     switch(opt) {
       case 't':
 		  to = true;
@@ -72,6 +78,9 @@
 	  case 'f':
 		  fixup = atoi(optarg);
 		  break;
+	  case 'm':
+		  if (strcmp(optarg, "bm16") == 0)
+			  bitmap16 = true;
 	}
   }
 
@@ -152,9 +161,22 @@
 
   png_read_image(png_ptr, ptrRow);
 
-  outBuffer = raw2mo5(inBuffer, height, fixup, to);
+  if (bitmap16) {
+	if (width != 160) {
+		puts("Image not using the full screen width are not supported yet!");
+		return ERROR;
+	}
+	outBuffer = raw2bm16(inBuffer, height);
+	pxsize = width * height / 4;
+  } else {
+	if (width != 320) {
+		puts("Image not using the full screen width are not supported yet!");
+		return ERROR;
+	}
+	outBuffer = raw2mo5(inBuffer, height, fixup, to);
+	pxsize = width * height / 8;
+  }
 
-  pxsize = width * height / 8;
   thomheader[7] = pxsize >> 8;
   thomheader[8] = pxsize;