Blame SOURCES/pixmap.patch

ceac5b
Index: src/ps_image.cxx
ceac5b
===================================================================
ceac5b
--- src/ps_image.cxx	(revision 9132)
ceac5b
+++ src/ps_image.cxx	(working copy)
ceac5b
@@ -185,72 +185,38 @@
ceac5b
 
ceac5b
 extern uchar **fl_mask_bitmap;
ceac5b
 
ceac5b
+struct callback_data {
ceac5b
+  const uchar *data;
ceac5b
+  int D, LD;
ceac5b
+};
ceac5b
 
ceac5b
-void Fl_PostScript_Graphics_Driver::draw_image(const uchar *data, int ix, int iy, int iw, int ih, int D, int LD) {
ceac5b
-  double x = ix, y = iy, w = iw, h = ih;
ceac5b
 
ceac5b
+static void draw_image_cb(void *data, int x, int y, int w, uchar *buf) {
ceac5b
+  struct callback_data *cb_data;
ceac5b
+  const uchar *curdata;
ceac5b
+
ceac5b
+  cb_data = (struct callback_data*)data;
ceac5b
+  curdata = cb_data->data + x*cb_data->D + y*cb_data->LD;
ceac5b
+
ceac5b
+  memcpy(buf, curdata, w*cb_data->D);
ceac5b
+}
ceac5b
+
ceac5b
+
ceac5b
+void Fl_PostScript_Graphics_Driver::draw_image(const uchar *data, int ix, int iy, int iw, int ih, int D, int LD) {
ceac5b
   if (D<3){ //mono
ceac5b
     draw_image_mono(data, ix, iy, iw, ih, D, LD);
ceac5b
     return;
ceac5b
   }
ceac5b
 
ceac5b
+  struct callback_data cb_data;
ceac5b
 
ceac5b
-  int i,j, k;
ceac5b
-
ceac5b
-  fprintf(output,"save\n");
ceac5b
-
ceac5b
-  const char * interpol;
ceac5b
-  if (lang_level_>1){
ceac5b
-    if (interpolate_)
ceac5b
-      interpol="true";
ceac5b
-    else
ceac5b
-      interpol="false";
ceac5b
-    if (mask && lang_level_>2)
ceac5b
-      fprintf(output, "%g %g %g %g %i %i %i %i %s CIM\n", x , y+h , w , -h , iw , ih, mx, my, interpol);
ceac5b
-    else
ceac5b
-      fprintf(output, "%g %g %g %g %i %i %s CII\n", x , y+h , w , -h , iw , ih, interpol);
ceac5b
-  } else
ceac5b
-    fprintf(output , "%g %g %g %g %i %i CI", x , y+h , w , -h , iw , ih);
ceac5b
-
ceac5b
-
ceac5b
   if (!LD) LD = iw*D;
ceac5b
-  uchar *curmask=mask;
ceac5b
 
ceac5b
-  for (j=0; j
ceac5b
-    if (mask){
ceac5b
+  cb_data.data = data;
ceac5b
+  cb_data.D = D;
ceac5b
+  cb_data.LD = LD;
ceac5b
 
ceac5b
-      for (k=0;k
ceac5b
-        for (i=0; i<((mx+7)/8);i++){
ceac5b
-          if (!(i%80)) fprintf(output, "\n");
ceac5b
-          fprintf(output, "%.2x",swap_byte(*curmask));
ceac5b
-          curmask++;
ceac5b
-        }
ceac5b
-        fprintf(output,"\n");
ceac5b
-      }
ceac5b
-    }
ceac5b
-    const uchar *curdata=data+j*LD;
ceac5b
-    for (i=0 ; i
ceac5b
-      uchar r = curdata[0];
ceac5b
-      uchar g =  curdata[1];
ceac5b
-      uchar b =  curdata[2];
ceac5b
-      if (lang_level_<3 && D>3) { //can do  mixing using bg_* colors)
ceac5b
-        unsigned int a2 = curdata[3]; //must be int
ceac5b
-        unsigned int a = 255-a2;
ceac5b
-        r = (a2 * r + bg_r * a)/255;
ceac5b
-        g = (a2 * g + bg_g * a)/255;
ceac5b
-        b = (a2 * b + bg_b * a)/255;
ceac5b
-      }
ceac5b
-      if (!(i%40)) fprintf(output, "\n");
ceac5b
-      fprintf(output, "%.2x%.2x%.2x", r, g, b);
ceac5b
-      curdata +=D;
ceac5b
-    }
ceac5b
-    fprintf(output,"\n");
ceac5b
-
ceac5b
-  }
ceac5b
-
ceac5b
-  fprintf(output," >\nrestore\n" );
ceac5b
-
ceac5b
-
ceac5b
+  draw_image(draw_image_cb, &cb_data, ix, iy, iw, ih, D);
ceac5b
 }
ceac5b
 
ceac5b
 void Fl_PostScript_Graphics_Driver::draw_image(Fl_Draw_Image_Cb call, void *data, int ix, int iy, int iw, int ih, int D) {
ceac5b
@@ -325,6 +291,14 @@
ceac5b
 	uchar g =  curdata[1];
ceac5b
 	uchar b =  curdata[2];
ceac5b
 
ceac5b
+        if (lang_level_<3 && D>3) { //can do  mixing using bg_* colors)
ceac5b
+          unsigned int a2 = curdata[3]; //must be int
ceac5b
+          unsigned int a = 255-a2;
ceac5b
+          r = (a2 * r + bg_r * a)/255;
ceac5b
+          g = (a2 * g + bg_g * a)/255;
ceac5b
+          b = (a2 * b + bg_b * a)/255;
ceac5b
+        }
ceac5b
+
ceac5b
 	if (!(i%40)) 	fputs("\n", output);
ceac5b
 	fprintf(output, "%.2x%.2x%.2x", r, g, b);
ceac5b
 
ceac5b
Index: src/Fl_Image.cxx
ceac5b
===================================================================
ceac5b
--- src/Fl_Image.cxx	(revision 9293)
ceac5b
+++ src/Fl_Image.cxx	(working copy)
ceac5b
@@ -163,7 +163,23 @@
ceac5b
 //
ceac5b
 // RGB image class...
ceac5b
 //
ceac5b
-/**  The destructor free all memory and server resources that are used by  the image. */
ceac5b
+
ceac5b
+int fl_convert_pixmap(const char*const* cdata, uchar* out, Fl_Color bg);
ceac5b
+
ceac5b
+/** The constructor creates a new RGBA image from the specified Fl_Pixmap. 
ceac5b
+ 
ceac5b
+ The RGBA image is built fully opaque except for the transparent area
ceac5b
+ of the pixmap that is assigned the \par bg color with full transparency */
ceac5b
+Fl_RGB_Image::Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg):
ceac5b
+  Fl_Image(pxm->w(), pxm->h(), 4), id_(0), mask_(0)
ceac5b
+{
ceac5b
+  array = new uchar[w() * h() * d()];
ceac5b
+  alloc_array = 1;
ceac5b
+  fl_convert_pixmap(pxm->data(), (uchar*)array, bg);
ceac5b
+  data((const char **)&array, 1);
ceac5b
+}
ceac5b
+
ceac5b
+/**  The destructor frees all memory and server resources that are used by the image. */
ceac5b
 Fl_RGB_Image::~Fl_RGB_Image() {
ceac5b
   uncache();
ceac5b
   if (alloc_array) delete[] (uchar *)array;
ceac5b
Index: src/fl_draw_pixmap.cxx
ceac5b
===================================================================
ceac5b
--- src/fl_draw_pixmap.cxx	(revision 9420)
ceac5b
+++ src/fl_draw_pixmap.cxx	(working copy)
ceac5b
@@ -58,99 +58,6 @@
ceac5b
   return 1;
ceac5b
 }
ceac5b
 
ceac5b
-#ifdef U64
ceac5b
-
ceac5b
-// The callback from fl_draw_image to get a row of data passes this:
ceac5b
-struct pixmap_data {
ceac5b
-  int w, h;
ceac5b
-  const uchar*const* data;
ceac5b
-  union {
ceac5b
-    U64 colors[256];
ceac5b
-    U64* byte1[256];
ceac5b
-  };
ceac5b
-};
ceac5b
-
ceac5b
-// callback for 1 byte per pixel:
ceac5b
-static void cb1(void*v, int x, int y, int w, uchar* buf) {
ceac5b
-  pixmap_data& d = *(pixmap_data*)v;
ceac5b
-  const uchar* p = d.data[y]+x;
ceac5b
-  U64* q = (U64*)buf;
ceac5b
-  for (int X=w; X>0; X-=2, p += 2) {
ceac5b
-    if (X>1) {
ceac5b
-#  if WORDS_BIGENDIAN
ceac5b
-      *q++ = (d.colors[p[0]]<<32) | d.colors[p[1]];
ceac5b
-#  else
ceac5b
-      *q++ = (d.colors[p[1]]<<32) | d.colors[p[0]];
ceac5b
-#  endif
ceac5b
-    } else {
ceac5b
-#  if WORDS_BIGENDIAN
ceac5b
-      *q++ = d.colors[p[0]]<<32;
ceac5b
-#  else
ceac5b
-      *q++ = d.colors[p[0]];
ceac5b
-#  endif
ceac5b
-    }
ceac5b
-  }
ceac5b
-}
ceac5b
-
ceac5b
-// callback for 2 bytes per pixel:
ceac5b
-static void cb2(void*v, int x, int y, int w, uchar* buf) {
ceac5b
-  pixmap_data& d = *(pixmap_data*)v;
ceac5b
-  const uchar* p = d.data[y]+2*x;
ceac5b
-  U64* q = (U64*)buf;
ceac5b
-  for (int X=w; X>0; X-=2) {
ceac5b
-    U64* colors = d.byte1[*p++];
ceac5b
-    int index = *p++;
ceac5b
-    if (X>1) {
ceac5b
-      U64* colors1 = d.byte1[*p++];
ceac5b
-      int index1 = *p++;
ceac5b
-#  if WORDS_BIGENDIAN
ceac5b
-      *q++ = (colors[index]<<32) | colors1[index1];
ceac5b
-#  else
ceac5b
-      *q++ = (colors1[index1]<<32) | colors[index];
ceac5b
-#  endif
ceac5b
-    } else {
ceac5b
-#  if WORDS_BIGENDIAN
ceac5b
-      *q++ = colors[index]<<32;
ceac5b
-#  else
ceac5b
-      *q++ = colors[index];
ceac5b
-#  endif
ceac5b
-    }
ceac5b
-  }
ceac5b
-}
ceac5b
-
ceac5b
-#else // U32
ceac5b
-
ceac5b
-// The callback from fl_draw_image to get a row of data passes this:
ceac5b
-struct pixmap_data {
ceac5b
-  int w, h;
ceac5b
-  const uchar*const* data;
ceac5b
-  union {
ceac5b
-    U32 colors[256];
ceac5b
-    U32* byte1[256];
ceac5b
-  };
ceac5b
-};
ceac5b
-
ceac5b
-// callback for 1 byte per pixel:
ceac5b
-static void cb1(void*v, int x, int y, int w, uchar* buf) {
ceac5b
-  pixmap_data& d = *(pixmap_data*)v;
ceac5b
-  const uchar* p = d.data[y]+x;
ceac5b
-  U32* q = (U32*)buf;
ceac5b
-  for (int X=w; X--;) *q++ = d.colors[*p++];
ceac5b
-}
ceac5b
-
ceac5b
-// callback for 2 bytes per pixel:
ceac5b
-static void cb2(void*v, int x, int y, int w, uchar* buf) {
ceac5b
-  pixmap_data& d = *(pixmap_data*)v;
ceac5b
-  const uchar* p = d.data[y]+2*x;
ceac5b
-  U32* q = (U32*)buf;
ceac5b
-  for (int X=w; X--;) {
ceac5b
-    U32* colors = d.byte1[*p++];
ceac5b
-    *q++ = colors[*p++];
ceac5b
-  }
ceac5b
-}
ceac5b
-
ceac5b
-#endif // U64 else U32
ceac5b
-
ceac5b
 uchar **fl_mask_bitmap; // if non-zero, create bitmap and store pointer here
ceac5b
 
ceac5b
 /**
ceac5b
@@ -200,34 +107,33 @@
ceac5b
 }
ceac5b
 #endif
ceac5b
 
ceac5b
-/**
ceac5b
-  Draw XPM image data, with the top-left corner at the given position.
ceac5b
-  \see fl_draw_pixmap(char* const* data, int x, int y, Fl_Color bg)
ceac5b
-  */
ceac5b
-int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg) {
ceac5b
-  pixmap_data d;
ceac5b
-  if (!fl_measure_pixmap(cdata, d.w, d.h)) return 0;
ceac5b
+int fl_convert_pixmap(const char*const* cdata, uchar* out, Fl_Color bg) {
ceac5b
+  int w, h;
ceac5b
   const uchar*const* data = (const uchar*const*)(cdata+1);
ceac5b
   int transparent_index = -1;
ceac5b
+
ceac5b
+  if (!fl_measure_pixmap(cdata, w, h))
ceac5b
+    return 0;
ceac5b
+
ceac5b
+  if ((chars_per_pixel < 1) || (chars_per_pixel > 2))
ceac5b
+    return 0;
ceac5b
+
ceac5b
+  uchar colors[1<<(chars_per_pixel*8)][4];
ceac5b
+
ceac5b
 #ifdef WIN32
ceac5b
   uchar *transparent_c = (uchar *)0; // such that transparent_c[0,1,2] are the RGB of the transparent color
ceac5b
   color_count = 0;
ceac5b
   used_colors = (uchar *)malloc(abs(ncolors)*3*sizeof(uchar));
ceac5b
 #endif
ceac5b
 
ceac5b
-  if (ncolors < 0) {	// FLTK (non standard) compressed colormap
ceac5b
+  if (ncolors < 0) {
ceac5b
+    // FLTK (non standard) compressed colormap
ceac5b
     ncolors = -ncolors;
ceac5b
     const uchar *p = *data++;
ceac5b
     // if first color is ' ' it is transparent (put it later to make
ceac5b
     // it not be transparent):
ceac5b
     if (*p == ' ') {
ceac5b
-      uchar* c = (uchar*)&d.colors[(int)' '];
ceac5b
-#ifdef U64
ceac5b
-      *(U64*)c = 0;
ceac5b
-#  if WORDS_BIGENDIAN
ceac5b
-      c += 4;
ceac5b
-#  endif
ceac5b
-#endif
ceac5b
+      uchar* c = colors[(int)' '];
ceac5b
       transparent_index = ' ';
ceac5b
       Fl::get_color(bg, c[0], c[1], c[2]); c[3] = 0;
ceac5b
 #ifdef WIN32
ceac5b
@@ -238,13 +144,7 @@
ceac5b
     }
ceac5b
     // read all the rest of the colors:
ceac5b
     for (int i=0; i < ncolors; i++) {
ceac5b
-      uchar* c = (uchar*)&d.colors[*p++];
ceac5b
-#ifdef U64
ceac5b
-      *(U64*)c = 0;
ceac5b
-#  if WORDS_BIGENDIAN
ceac5b
-      c += 4;
ceac5b
-#  endif
ceac5b
-#endif
ceac5b
+      uchar* c = colors[*p++];
ceac5b
 #ifdef WIN32
ceac5b
       used_colors[3*color_count] = *p;
ceac5b
       used_colors[3*color_count+1] = *(p+1);
ceac5b
@@ -254,69 +154,44 @@
ceac5b
       *c++ = *p++;
ceac5b
       *c++ = *p++;
ceac5b
       *c++ = *p++;
ceac5b
-#ifdef __APPLE_QUARTZ__
ceac5b
       *c = 255;
ceac5b
-#else
ceac5b
-      *c = 0;
ceac5b
-#endif
ceac5b
     }
ceac5b
-  } else {	// normal XPM colormap with names
ceac5b
-    if (chars_per_pixel>1) memset(d.byte1, 0, sizeof(d.byte1));
ceac5b
+  } else {
ceac5b
+    // normal XPM colormap with names
ceac5b
     for (int i=0; i
ceac5b
       const uchar *p = *data++;
ceac5b
       // the first 1 or 2 characters are the color index:
ceac5b
       int ind = *p++;
ceac5b
       uchar* c;
ceac5b
-      if (chars_per_pixel>1) {
ceac5b
-#ifdef U64
ceac5b
-	U64* colors = d.byte1[ind];
ceac5b
-	if (!colors) colors = d.byte1[ind] = new U64[256];
ceac5b
-#else
ceac5b
-	U32* colors = d.byte1[ind];
ceac5b
-	if (!colors) colors = d.byte1[ind] = new U32[256];
ceac5b
-#endif
ceac5b
-	c = (uchar*)&colors[*p];
ceac5b
-	ind = (ind<<8)|*p++;
ceac5b
-      } else {
ceac5b
-	c = (uchar *)&d.colors[ind];
ceac5b
-      }
ceac5b
+      if (chars_per_pixel>1)
ceac5b
+        ind = (ind<<8)|*p++;
ceac5b
+      c = colors[ind];
ceac5b
       // look for "c word", or last word if none:
ceac5b
       const uchar *previous_word = p;
ceac5b
       for (;;) {
ceac5b
-	while (*p && isspace(*p)) p++;
ceac5b
-	uchar what = *p++;
ceac5b
-	while (*p && !isspace(*p)) p++;
ceac5b
-	while (*p && isspace(*p)) p++;
ceac5b
-	if (!*p) {p = previous_word; break;}
ceac5b
-	if (what == 'c') break;
ceac5b
-	previous_word = p;
ceac5b
-	while (*p && !isspace(*p)) p++;
ceac5b
+        while (*p && isspace(*p)) p++;
ceac5b
+        uchar what = *p++;
ceac5b
+        while (*p && !isspace(*p)) p++;
ceac5b
+        while (*p && isspace(*p)) p++;
ceac5b
+        if (!*p) {p = previous_word; break;}
ceac5b
+        if (what == 'c') break;
ceac5b
+        previous_word = p;
ceac5b
+        while (*p && !isspace(*p)) p++;
ceac5b
       }
ceac5b
-#ifdef U64
ceac5b
-      *(U64*)c = 0;
ceac5b
-#  if WORDS_BIGENDIAN
ceac5b
-      c += 4;
ceac5b
-#  endif
ceac5b
-#endif
ceac5b
-#ifdef __APPLE_QUARTZ__
ceac5b
-      c[3] = 255;
ceac5b
-#endif
ceac5b
       int parse = fl_parse_color((const char*)p, c[0], c[1], c[2]);
ceac5b
+      c[3] = 255;
ceac5b
       if (parse) {
ceac5b
 #ifdef WIN32
ceac5b
-	used_colors[3*color_count] = c[0];
ceac5b
-	used_colors[3*color_count+1] = c[1];
ceac5b
-	used_colors[3*color_count+2] = c[2];
ceac5b
-	color_count++;
ceac5b
+        used_colors[3*color_count] = c[0];
ceac5b
+        used_colors[3*color_count+1] = c[1];
ceac5b
+        used_colors[3*color_count+2] = c[2];
ceac5b
+        color_count++;
ceac5b
 #endif
ceac5b
-	}
ceac5b
-      else {
ceac5b
+      } else {
ceac5b
         // assume "None" or "#transparent" for any errors
ceac5b
-	// "bg" should be transparent...
ceac5b
-	Fl::get_color(bg, c[0], c[1], c[2]);
ceac5b
-#ifdef __APPLE_QUARTZ__
ceac5b
+        // "bg" should be transparent...
ceac5b
+        Fl::get_color(bg, c[0], c[1], c[2]);
ceac5b
         c[3] = 0;
ceac5b
-#endif
ceac5b
 	transparent_index = ind;
ceac5b
 #ifdef WIN32
ceac5b
 	transparent_c = c;
ceac5b
@@ -324,7 +199,6 @@
ceac5b
       }
ceac5b
     }
ceac5b
   }
ceac5b
-  d.data = data;
ceac5b
 #ifdef WIN32
ceac5b
   if (transparent_c) {
ceac5b
     make_unused_color(transparent_c[0], transparent_c[1], transparent_c[2]);
ceac5b
@@ -334,77 +208,76 @@
ceac5b
     make_unused_color(r, g, b);
ceac5b
   }
ceac5b
 #endif
ceac5b
+
ceac5b
+  U32 *q = (U32*)out;
ceac5b
+  for (int Y = 0; Y < h; Y++) {
ceac5b
+    const uchar* p = data[Y];
ceac5b
+    if (chars_per_pixel <= 1) {
ceac5b
+      for (int X = 0; X < w; X++)
ceac5b
+        memcpy(q++, colors[*p++], 4);
ceac5b
+    } else {
ceac5b
+      for (int X = 0; X < w; X++) {
ceac5b
+        int ind = (*p++)<<8;
ceac5b
+        ind |= *p++;
ceac5b
+        memcpy(q++, colors[ind], 4);
ceac5b
+      }
ceac5b
+    }
ceac5b
+  }
ceac5b
   
ceac5b
+  return 1;
ceac5b
+}
ceac5b
+
ceac5b
+/**
ceac5b
+  Draw XPM image data, with the top-left corner at the given position.
ceac5b
+  \see fl_draw_pixmap(char* const* data, int x, int y, Fl_Color bg)
ceac5b
+  */
ceac5b
+int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg) {
ceac5b
+  int w, h;
ceac5b
+
ceac5b
+  if (!fl_measure_pixmap(cdata, w, h))
ceac5b
+    return 0;
ceac5b
+
ceac5b
+  uchar buffer[w*h*4];
ceac5b
+
ceac5b
+  if (!fl_convert_pixmap(cdata, buffer, bg))
ceac5b
+    return 0;
ceac5b
+
ceac5b
+  // FIXME: Hack until fl_draw_image() supports alpha properly
ceac5b
 #ifdef  __APPLE_QUARTZ__
ceac5b
   if (Fl_Surface_Device::surface() == Fl_Display_Device::display_device()) {
ceac5b
-    U32 *array = new U32[d.w * d.h], *q = array;
ceac5b
-    for (int Y = 0; Y < d.h; Y++) {
ceac5b
-      const uchar* p = data[Y];
ceac5b
-      if (chars_per_pixel <= 1) {
ceac5b
-	for (int X = 0; X < d.w; X++) {
ceac5b
-	  *q++ = d.colors[*p++];
ceac5b
-	}
ceac5b
-      } else {
ceac5b
-	for (int X = 0; X < d.w; X++) {
ceac5b
-	  U32* colors = (U32*)d.byte1[*p++];
ceac5b
-	  *q++ = colors[*p++];
ceac5b
-	}
ceac5b
-      }
ceac5b
-    }
ceac5b
-    Fl_RGB_Image* rgb = new Fl_RGB_Image((uchar*)array, d.w, d.h, 4);
ceac5b
+    Fl_RGB_Image* rgb = new Fl_RGB_Image(buffer, w, h, 4);
ceac5b
     rgb->draw(x, y);
ceac5b
     delete rgb;
ceac5b
-    delete[] array;
ceac5b
-    }
ceac5b
-  else {
ceac5b
+  } else {
ceac5b
 #endif // __APPLE_QUARTZ__
ceac5b
-
ceac5b
   // build the mask bitmap used by Fl_Pixmap:
ceac5b
-  if (fl_mask_bitmap && transparent_index >= 0) {
ceac5b
-    int W = (d.w+7)/8;
ceac5b
-    uchar* bitmap = new uchar[W * d.h];
ceac5b
+  if (fl_mask_bitmap) {
ceac5b
+    int W = (w+7)/8;
ceac5b
+    uchar* bitmap = new uchar[W * h];
ceac5b
     *fl_mask_bitmap = bitmap;
ceac5b
-    for (int Y = 0; Y < d.h; Y++) {
ceac5b
-      const uchar* p = data[Y];
ceac5b
-      if (chars_per_pixel <= 1) {
ceac5b
-	int dw = d.w;
ceac5b
-	for (int X = 0; X < W; X++) {
ceac5b
-	  uchar b = (dw-->0 && *p++ != transparent_index);
ceac5b
-	  if (dw-->0 && *p++ != transparent_index) b |= 2;
ceac5b
-	  if (dw-->0 && *p++ != transparent_index) b |= 4;
ceac5b
-	  if (dw-->0 && *p++ != transparent_index) b |= 8;
ceac5b
-	  if (dw-->0 && *p++ != transparent_index) b |= 16;
ceac5b
-	  if (dw-->0 && *p++ != transparent_index) b |= 32;
ceac5b
-	  if (dw-->0 && *p++ != transparent_index) b |= 64;
ceac5b
-	  if (dw-->0 && *p++ != transparent_index) b |= 128;
ceac5b
+    const uchar *p = &buffer[3];
ceac5b
+    uchar b = 0;
ceac5b
+    for (int Y = 0; Y < h; Y++) {
ceac5b
+      b = 0;
ceac5b
+      for (int X = 0, bit = 1; X < w; X++, p += 4) {
ceac5b
+	if (*p > 127) b |= bit;
ceac5b
+	bit <<= 1;
ceac5b
+	if (bit > 0x80 || X == w-1) {
ceac5b
 	  *bitmap++ = b;
ceac5b
-	}
ceac5b
-      } else {
ceac5b
-        uchar b = 0, bit = 1;
ceac5b
-	for (int X = 0; X < d.w; X++) {
ceac5b
-	  int ind = *p++;
ceac5b
-	  ind = (ind<<8) | (*p++);
ceac5b
-	  if (ind != transparent_index) b |= bit;
ceac5b
-
ceac5b
-          if (bit < 128) bit <<= 1;
ceac5b
-	  else {
ceac5b
-	    *bitmap++ = b;
ceac5b
-	    b = 0;
ceac5b
-	    bit = 1;
ceac5b
+	  bit = 1;
ceac5b
+	  b = 0;
ceac5b
 	  }
ceac5b
 	}
ceac5b
-
ceac5b
-        if (bit > 1) *bitmap++ = b;
ceac5b
       }
ceac5b
-    }
ceac5b
+    
ceac5b
   }
ceac5b
 
ceac5b
-  fl_draw_image(chars_per_pixel==1 ? cb1 : cb2, &d, x, y, d.w, d.h, 4);
ceac5b
+  fl_draw_image(buffer, x, y, w, h, 4);
ceac5b
+
ceac5b
 #ifdef __APPLE_QUARTZ__
ceac5b
     }
ceac5b
 #endif
ceac5b
 
ceac5b
-  if (chars_per_pixel > 1) for (int i = 0; i < 256; i++) delete[] d.byte1[i];
ceac5b
   return 1;
ceac5b
 }
ceac5b
 
ceac5b
Index: FL/Fl_Image.H
ceac5b
===================================================================
ceac5b
--- FL/Fl_Image.H	(revision 9601)
ceac5b
+++ FL/Fl_Image.H	(working copy)
ceac5b
@@ -25,6 +25,7 @@
ceac5b
 #  include "Enumerations.H"
ceac5b
 
ceac5b
 class Fl_Widget;
ceac5b
+class Fl_Pixmap;
ceac5b
 struct Fl_Menu_Item;
ceac5b
 struct Fl_Label;
ceac5b
 
ceac5b
@@ -201,6 +202,7 @@
ceac5b
   */
ceac5b
   Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0) :
ceac5b
     Fl_Image(W,H,D), array(bits), alloc_array(0), id_(0), mask_(0) {data((const char **)&array, 1); ld(LD);}
ceac5b
+  Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg=FL_GRAY);
ceac5b
   virtual ~Fl_RGB_Image();
ceac5b
   virtual Fl_Image *copy(int W, int H);
ceac5b
   Fl_Image *copy() { return copy(w(), h()); }