You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pixmap_v2.patch 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. diff -ur fltk-1.3.2.org/FL/Fl_Image.H fltk-1.3.2/FL/Fl_Image.H
  2. --- fltk-1.3.2.org/FL/Fl_Image.H 2012-11-09 17:02:08.000000000 +0100
  3. +++ fltk-1.3.2/FL/Fl_Image.H 2013-01-16 14:40:51.543230638 +0100
  4. @@ -26,6 +26,7 @@
  5. #include <stdlib.h>
  6. class Fl_Widget;
  7. +class Fl_Pixmap;
  8. struct Fl_Menu_Item;
  9. struct Fl_Label;
  10. @@ -203,6 +204,7 @@
  11. */
  12. Fl_RGB_Image(const uchar *bits, int W, int H, int D=3, int LD=0) :
  13. Fl_Image(W,H,D), array(bits), alloc_array(0), id_(0), mask_(0) {data((const char **)&array, 1); ld(LD);}
  14. + Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg=FL_GRAY);
  15. virtual ~Fl_RGB_Image();
  16. virtual Fl_Image *copy(int W, int H);
  17. Fl_Image *copy() { return copy(w(), h()); }
  18. diff -ur fltk-1.3.2.org/src/fl_draw_pixmap.cxx fltk-1.3.2/src/fl_draw_pixmap.cxx
  19. --- fltk-1.3.2.org/src/fl_draw_pixmap.cxx 2012-04-22 05:09:31.000000000 +0200
  20. +++ fltk-1.3.2/src/fl_draw_pixmap.cxx 2013-01-16 14:40:51.542230588 +0100
  21. @@ -58,99 +58,6 @@
  22. return 1;
  23. }
  24. -#ifdef U64
  25. -
  26. -// The callback from fl_draw_image to get a row of data passes this:
  27. -struct pixmap_data {
  28. - int w, h;
  29. - const uchar*const* data;
  30. - union {
  31. - U64 colors[256];
  32. - U64* byte1[256];
  33. - };
  34. -};
  35. -
  36. -// callback for 1 byte per pixel:
  37. -static void cb1(void*v, int x, int y, int w, uchar* buf) {
  38. - pixmap_data& d = *(pixmap_data*)v;
  39. - const uchar* p = d.data[y]+x;
  40. - U64* q = (U64*)buf;
  41. - for (int X=w; X>0; X-=2, p += 2) {
  42. - if (X>1) {
  43. -# if WORDS_BIGENDIAN
  44. - *q++ = (d.colors[p[0]]<<32) | d.colors[p[1]];
  45. -# else
  46. - *q++ = (d.colors[p[1]]<<32) | d.colors[p[0]];
  47. -# endif
  48. - } else {
  49. -# if WORDS_BIGENDIAN
  50. - *q++ = d.colors[p[0]]<<32;
  51. -# else
  52. - *q++ = d.colors[p[0]];
  53. -# endif
  54. - }
  55. - }
  56. -}
  57. -
  58. -// callback for 2 bytes per pixel:
  59. -static void cb2(void*v, int x, int y, int w, uchar* buf) {
  60. - pixmap_data& d = *(pixmap_data*)v;
  61. - const uchar* p = d.data[y]+2*x;
  62. - U64* q = (U64*)buf;
  63. - for (int X=w; X>0; X-=2) {
  64. - U64* colors = d.byte1[*p++];
  65. - int index = *p++;
  66. - if (X>1) {
  67. - U64* colors1 = d.byte1[*p++];
  68. - int index1 = *p++;
  69. -# if WORDS_BIGENDIAN
  70. - *q++ = (colors[index]<<32) | colors1[index1];
  71. -# else
  72. - *q++ = (colors1[index1]<<32) | colors[index];
  73. -# endif
  74. - } else {
  75. -# if WORDS_BIGENDIAN
  76. - *q++ = colors[index]<<32;
  77. -# else
  78. - *q++ = colors[index];
  79. -# endif
  80. - }
  81. - }
  82. -}
  83. -
  84. -#else // U32
  85. -
  86. -// The callback from fl_draw_image to get a row of data passes this:
  87. -struct pixmap_data {
  88. - int w, h;
  89. - const uchar*const* data;
  90. - union {
  91. - U32 colors[256];
  92. - U32* byte1[256];
  93. - };
  94. -};
  95. -
  96. -// callback for 1 byte per pixel:
  97. -static void cb1(void*v, int x, int y, int w, uchar* buf) {
  98. - pixmap_data& d = *(pixmap_data*)v;
  99. - const uchar* p = d.data[y]+x;
  100. - U32* q = (U32*)buf;
  101. - for (int X=w; X--;) *q++ = d.colors[*p++];
  102. -}
  103. -
  104. -// callback for 2 bytes per pixel:
  105. -static void cb2(void*v, int x, int y, int w, uchar* buf) {
  106. - pixmap_data& d = *(pixmap_data*)v;
  107. - const uchar* p = d.data[y]+2*x;
  108. - U32* q = (U32*)buf;
  109. - for (int X=w; X--;) {
  110. - U32* colors = d.byte1[*p++];
  111. - *q++ = colors[*p++];
  112. - }
  113. -}
  114. -
  115. -#endif // U64 else U32
  116. -
  117. uchar **fl_mask_bitmap; // if non-zero, create bitmap and store pointer here
  118. /**
  119. @@ -200,34 +107,33 @@
  120. }
  121. #endif
  122. -/**
  123. - Draw XPM image data, with the top-left corner at the given position.
  124. - \see fl_draw_pixmap(char* const* data, int x, int y, Fl_Color bg)
  125. - */
  126. -int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg) {
  127. - pixmap_data d;
  128. - if (!fl_measure_pixmap(cdata, d.w, d.h)) return 0;
  129. +int fl_convert_pixmap(const char*const* cdata, uchar* out, Fl_Color bg) {
  130. + int w, h;
  131. const uchar*const* data = (const uchar*const*)(cdata+1);
  132. int transparent_index = -1;
  133. +
  134. + if (!fl_measure_pixmap(cdata, w, h))
  135. + return 0;
  136. +
  137. + if ((chars_per_pixel < 1) || (chars_per_pixel > 2))
  138. + return 0;
  139. +
  140. + uchar colors[1<<(chars_per_pixel*8)][4];
  141. +
  142. #ifdef WIN32
  143. uchar *transparent_c = (uchar *)0; // such that transparent_c[0,1,2] are the RGB of the transparent color
  144. color_count = 0;
  145. used_colors = (uchar *)malloc(abs(ncolors)*3*sizeof(uchar));
  146. #endif
  147. - if (ncolors < 0) { // FLTK (non standard) compressed colormap
  148. + if (ncolors < 0) {
  149. + // FLTK (non standard) compressed colormap
  150. ncolors = -ncolors;
  151. const uchar *p = *data++;
  152. // if first color is ' ' it is transparent (put it later to make
  153. // it not be transparent):
  154. if (*p == ' ') {
  155. - uchar* c = (uchar*)&d.colors[(int)' '];
  156. -#ifdef U64
  157. - *(U64*)c = 0;
  158. -# if WORDS_BIGENDIAN
  159. - c += 4;
  160. -# endif
  161. -#endif
  162. + uchar* c = colors[(int)' '];
  163. transparent_index = ' ';
  164. Fl::get_color(bg, c[0], c[1], c[2]); c[3] = 0;
  165. #ifdef WIN32
  166. @@ -238,13 +144,7 @@
  167. }
  168. // read all the rest of the colors:
  169. for (int i=0; i < ncolors; i++) {
  170. - uchar* c = (uchar*)&d.colors[*p++];
  171. -#ifdef U64
  172. - *(U64*)c = 0;
  173. -# if WORDS_BIGENDIAN
  174. - c += 4;
  175. -# endif
  176. -#endif
  177. + uchar* c = colors[*p++];
  178. #ifdef WIN32
  179. used_colors[3*color_count] = *p;
  180. used_colors[3*color_count+1] = *(p+1);
  181. @@ -254,69 +154,44 @@
  182. *c++ = *p++;
  183. *c++ = *p++;
  184. *c++ = *p++;
  185. -#ifdef __APPLE_QUARTZ__
  186. *c = 255;
  187. -#else
  188. - *c = 0;
  189. -#endif
  190. }
  191. - } else { // normal XPM colormap with names
  192. - if (chars_per_pixel>1) memset(d.byte1, 0, sizeof(d.byte1));
  193. + } else {
  194. + // normal XPM colormap with names
  195. for (int i=0; i<ncolors; i++) {
  196. const uchar *p = *data++;
  197. // the first 1 or 2 characters are the color index:
  198. int ind = *p++;
  199. uchar* c;
  200. - if (chars_per_pixel>1) {
  201. -#ifdef U64
  202. - U64* colors = d.byte1[ind];
  203. - if (!colors) colors = d.byte1[ind] = new U64[256];
  204. -#else
  205. - U32* colors = d.byte1[ind];
  206. - if (!colors) colors = d.byte1[ind] = new U32[256];
  207. -#endif
  208. - c = (uchar*)&colors[*p];
  209. - ind = (ind<<8)|*p++;
  210. - } else {
  211. - c = (uchar *)&d.colors[ind];
  212. - }
  213. + if (chars_per_pixel>1)
  214. + ind = (ind<<8)|*p++;
  215. + c = colors[ind];
  216. // look for "c word", or last word if none:
  217. const uchar *previous_word = p;
  218. for (;;) {
  219. - while (*p && isspace(*p)) p++;
  220. - uchar what = *p++;
  221. - while (*p && !isspace(*p)) p++;
  222. - while (*p && isspace(*p)) p++;
  223. - if (!*p) {p = previous_word; break;}
  224. - if (what == 'c') break;
  225. - previous_word = p;
  226. - while (*p && !isspace(*p)) p++;
  227. + while (*p && isspace(*p)) p++;
  228. + uchar what = *p++;
  229. + while (*p && !isspace(*p)) p++;
  230. + while (*p && isspace(*p)) p++;
  231. + if (!*p) {p = previous_word; break;}
  232. + if (what == 'c') break;
  233. + previous_word = p;
  234. + while (*p && !isspace(*p)) p++;
  235. }
  236. -#ifdef U64
  237. - *(U64*)c = 0;
  238. -# if WORDS_BIGENDIAN
  239. - c += 4;
  240. -# endif
  241. -#endif
  242. -#ifdef __APPLE_QUARTZ__
  243. - c[3] = 255;
  244. -#endif
  245. int parse = fl_parse_color((const char*)p, c[0], c[1], c[2]);
  246. + c[3] = 255;
  247. if (parse) {
  248. #ifdef WIN32
  249. - used_colors[3*color_count] = c[0];
  250. - used_colors[3*color_count+1] = c[1];
  251. - used_colors[3*color_count+2] = c[2];
  252. - color_count++;
  253. + used_colors[3*color_count] = c[0];
  254. + used_colors[3*color_count+1] = c[1];
  255. + used_colors[3*color_count+2] = c[2];
  256. + color_count++;
  257. #endif
  258. - }
  259. - else {
  260. + } else {
  261. // assume "None" or "#transparent" for any errors
  262. - // "bg" should be transparent...
  263. - Fl::get_color(bg, c[0], c[1], c[2]);
  264. -#ifdef __APPLE_QUARTZ__
  265. + // "bg" should be transparent...
  266. + Fl::get_color(bg, c[0], c[1], c[2]);
  267. c[3] = 0;
  268. -#endif
  269. transparent_index = ind;
  270. #ifdef WIN32
  271. transparent_c = c;
  272. @@ -324,7 +199,6 @@
  273. }
  274. }
  275. }
  276. - d.data = data;
  277. #ifdef WIN32
  278. if (transparent_c) {
  279. make_unused_color(transparent_c[0], transparent_c[1], transparent_c[2]);
  280. @@ -334,77 +208,76 @@
  281. make_unused_color(r, g, b);
  282. }
  283. #endif
  284. +
  285. + U32 *q = (U32*)out;
  286. + for (int Y = 0; Y < h; Y++) {
  287. + const uchar* p = data[Y];
  288. + if (chars_per_pixel <= 1) {
  289. + for (int X = 0; X < w; X++)
  290. + memcpy(q++, colors[*p++], 4);
  291. + } else {
  292. + for (int X = 0; X < w; X++) {
  293. + int ind = (*p++)<<8;
  294. + ind |= *p++;
  295. + memcpy(q++, colors[ind], 4);
  296. + }
  297. + }
  298. + }
  299. + return 1;
  300. +}
  301. +
  302. +/**
  303. + Draw XPM image data, with the top-left corner at the given position.
  304. + \see fl_draw_pixmap(char* const* data, int x, int y, Fl_Color bg)
  305. + */
  306. +int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg) {
  307. + int w, h;
  308. +
  309. + if (!fl_measure_pixmap(cdata, w, h))
  310. + return 0;
  311. +
  312. + uchar buffer[w*h*4];
  313. +
  314. + if (!fl_convert_pixmap(cdata, buffer, bg))
  315. + return 0;
  316. +
  317. + // FIXME: Hack until fl_draw_image() supports alpha properly
  318. #ifdef __APPLE_QUARTZ__
  319. if (Fl_Surface_Device::surface() == Fl_Display_Device::display_device()) {
  320. - U32 *array = new U32[d.w * d.h], *q = array;
  321. - for (int Y = 0; Y < d.h; Y++) {
  322. - const uchar* p = data[Y];
  323. - if (chars_per_pixel <= 1) {
  324. - for (int X = 0; X < d.w; X++) {
  325. - *q++ = d.colors[*p++];
  326. - }
  327. - } else {
  328. - for (int X = 0; X < d.w; X++) {
  329. - U32* colors = (U32*)d.byte1[*p++];
  330. - *q++ = colors[*p++];
  331. - }
  332. - }
  333. - }
  334. - Fl_RGB_Image* rgb = new Fl_RGB_Image((uchar*)array, d.w, d.h, 4);
  335. + Fl_RGB_Image* rgb = new Fl_RGB_Image(buffer, w, h, 4);
  336. rgb->draw(x, y);
  337. delete rgb;
  338. - delete[] array;
  339. - }
  340. - else {
  341. + } else {
  342. #endif // __APPLE_QUARTZ__
  343. -
  344. // build the mask bitmap used by Fl_Pixmap:
  345. - if (fl_mask_bitmap && transparent_index >= 0) {
  346. - int W = (d.w+7)/8;
  347. - uchar* bitmap = new uchar[W * d.h];
  348. + if (fl_mask_bitmap) {
  349. + int W = (w+7)/8;
  350. + uchar* bitmap = new uchar[W * h];
  351. *fl_mask_bitmap = bitmap;
  352. - for (int Y = 0; Y < d.h; Y++) {
  353. - const uchar* p = data[Y];
  354. - if (chars_per_pixel <= 1) {
  355. - int dw = d.w;
  356. - for (int X = 0; X < W; X++) {
  357. - uchar b = (dw-->0 && *p++ != transparent_index);
  358. - if (dw-->0 && *p++ != transparent_index) b |= 2;
  359. - if (dw-->0 && *p++ != transparent_index) b |= 4;
  360. - if (dw-->0 && *p++ != transparent_index) b |= 8;
  361. - if (dw-->0 && *p++ != transparent_index) b |= 16;
  362. - if (dw-->0 && *p++ != transparent_index) b |= 32;
  363. - if (dw-->0 && *p++ != transparent_index) b |= 64;
  364. - if (dw-->0 && *p++ != transparent_index) b |= 128;
  365. + const uchar *p = &buffer[3];
  366. + uchar b = 0;
  367. + for (int Y = 0; Y < h; Y++) {
  368. + b = 0;
  369. + for (int X = 0, bit = 1; X < w; X++, p += 4) {
  370. + if (*p > 127) b |= bit;
  371. + bit <<= 1;
  372. + if (bit > 0x80 || X == w-1) {
  373. *bitmap++ = b;
  374. - }
  375. - } else {
  376. - uchar b = 0, bit = 1;
  377. - for (int X = 0; X < d.w; X++) {
  378. - int ind = *p++;
  379. - ind = (ind<<8) | (*p++);
  380. - if (ind != transparent_index) b |= bit;
  381. -
  382. - if (bit < 128) bit <<= 1;
  383. - else {
  384. - *bitmap++ = b;
  385. - b = 0;
  386. - bit = 1;
  387. + bit = 1;
  388. + b = 0;
  389. }
  390. }
  391. -
  392. - if (bit > 1) *bitmap++ = b;
  393. }
  394. - }
  395. +
  396. }
  397. - fl_draw_image(chars_per_pixel==1 ? cb1 : cb2, &d, x, y, d.w, d.h, 4);
  398. + fl_draw_image(buffer, x, y, w, h, 4);
  399. +
  400. #ifdef __APPLE_QUARTZ__
  401. }
  402. #endif
  403. - if (chars_per_pixel > 1) for (int i = 0; i < 256; i++) delete[] d.byte1[i];
  404. return 1;
  405. }
  406. diff -ur fltk-1.3.2.org/src/Fl_Image.cxx fltk-1.3.2/src/Fl_Image.cxx
  407. --- fltk-1.3.2.org/src/Fl_Image.cxx 2012-11-09 17:02:08.000000000 +0100
  408. +++ fltk-1.3.2/src/Fl_Image.cxx 2013-01-16 14:41:38.404162795 +0100
  409. @@ -165,7 +165,22 @@
  410. //
  411. size_t Fl_RGB_Image::max_size_ = ~((size_t)0);
  412. -/** The destructor free all memory and server resources that are used by the image. */
  413. +int fl_convert_pixmap(const char*const* cdata, uchar* out, Fl_Color bg);
  414. +
  415. +/** The constructor creates a new RGBA image from the specified Fl_Pixmap.
  416. +
  417. + The RGBA image is built fully opaque except for the transparent area
  418. + of the pixmap that is assigned the \par bg color with full transparency */
  419. +Fl_RGB_Image::Fl_RGB_Image(const Fl_Pixmap *pxm, Fl_Color bg):
  420. + Fl_Image(pxm->w(), pxm->h(), 4), id_(0), mask_(0)
  421. +{
  422. + array = new uchar[w() * h() * d()];
  423. + alloc_array = 1;
  424. + fl_convert_pixmap(pxm->data(), (uchar*)array, bg);
  425. + data((const char **)&array, 1);
  426. +}
  427. +
  428. +/** The destructor frees all memory and server resources that are used by the image. */
  429. Fl_RGB_Image::~Fl_RGB_Image() {
  430. uncache();
  431. if (alloc_array) delete[] (uchar *)array;
  432. diff -ur fltk-1.3.2.org/src/ps_image.cxx fltk-1.3.2/src/ps_image.cxx
  433. --- fltk-1.3.2.org/src/ps_image.cxx 2011-07-19 06:49:30.000000000 +0200
  434. +++ fltk-1.3.2/src/ps_image.cxx 2013-01-16 14:40:51.541228080 +0100
  435. @@ -185,72 +185,38 @@
  436. extern uchar **fl_mask_bitmap;
  437. +struct callback_data {
  438. + const uchar *data;
  439. + int D, LD;
  440. +};
  441. -void Fl_PostScript_Graphics_Driver::draw_image(const uchar *data, int ix, int iy, int iw, int ih, int D, int LD) {
  442. - double x = ix, y = iy, w = iw, h = ih;
  443. - if (D<3){ //mono
  444. - draw_image_mono(data, ix, iy, iw, ih, D, LD);
  445. - return;
  446. - }
  447. +static void draw_image_cb(void *data, int x, int y, int w, uchar *buf) {
  448. + struct callback_data *cb_data;
  449. + const uchar *curdata;
  450. + cb_data = (struct callback_data*)data;
  451. + curdata = cb_data->data + x*cb_data->D + y*cb_data->LD;
  452. - int i,j, k;
  453. + memcpy(buf, curdata, w*cb_data->D);
  454. +}
  455. - fprintf(output,"save\n");
  456. - const char * interpol;
  457. - if (lang_level_>1){
  458. - if (interpolate_)
  459. - interpol="true";
  460. - else
  461. - interpol="false";
  462. - if (mask && lang_level_>2)
  463. - fprintf(output, "%g %g %g %g %i %i %i %i %s CIM\n", x , y+h , w , -h , iw , ih, mx, my, interpol);
  464. - else
  465. - fprintf(output, "%g %g %g %g %i %i %s CII\n", x , y+h , w , -h , iw , ih, interpol);
  466. - } else
  467. - fprintf(output , "%g %g %g %g %i %i CI", x , y+h , w , -h , iw , ih);
  468. +void Fl_PostScript_Graphics_Driver::draw_image(const uchar *data, int ix, int iy, int iw, int ih, int D, int LD) {
  469. + if (D<3){ //mono
  470. + draw_image_mono(data, ix, iy, iw, ih, D, LD);
  471. + return;
  472. + }
  473. + struct callback_data cb_data;
  474. if (!LD) LD = iw*D;
  475. - uchar *curmask=mask;
  476. -
  477. - for (j=0; j<ih;j++){
  478. - if (mask){
  479. -
  480. - for (k=0;k<my/ih;k++){
  481. - for (i=0; i<((mx+7)/8);i++){
  482. - if (!(i%80)) fprintf(output, "\n");
  483. - fprintf(output, "%.2x",swap_byte(*curmask));
  484. - curmask++;
  485. - }
  486. - fprintf(output,"\n");
  487. - }
  488. - }
  489. - const uchar *curdata=data+j*LD;
  490. - for (i=0 ; i<iw ; i++) {
  491. - uchar r = curdata[0];
  492. - uchar g = curdata[1];
  493. - uchar b = curdata[2];
  494. - if (lang_level_<3 && D>3) { //can do mixing using bg_* colors)
  495. - unsigned int a2 = curdata[3]; //must be int
  496. - unsigned int a = 255-a2;
  497. - r = (a2 * r + bg_r * a)/255;
  498. - g = (a2 * g + bg_g * a)/255;
  499. - b = (a2 * b + bg_b * a)/255;
  500. - }
  501. - if (!(i%40)) fprintf(output, "\n");
  502. - fprintf(output, "%.2x%.2x%.2x", r, g, b);
  503. - curdata +=D;
  504. - }
  505. - fprintf(output,"\n");
  506. -
  507. - }
  508. -
  509. - fprintf(output," >\nrestore\n" );
  510. + cb_data.data = data;
  511. + cb_data.D = D;
  512. + cb_data.LD = LD;
  513. + draw_image(draw_image_cb, &cb_data, ix, iy, iw, ih, D);
  514. }
  515. void Fl_PostScript_Graphics_Driver::draw_image(Fl_Draw_Image_Cb call, void *data, int ix, int iy, int iw, int ih, int D) {
  516. @@ -325,6 +291,14 @@
  517. uchar g = curdata[1];
  518. uchar b = curdata[2];
  519. + if (lang_level_<3 && D>3) { //can do mixing using bg_* colors)
  520. + unsigned int a2 = curdata[3]; //must be int
  521. + unsigned int a = 255-a2;
  522. + r = (a2 * r + bg_r * a)/255;
  523. + g = (a2 * g + bg_g * a)/255;
  524. + b = (a2 * b + bg_b * a)/255;
  525. + }
  526. +
  527. if (!(i%40)) fputs("\n", output);
  528. fprintf(output, "%.2x%.2x%.2x", r, g, b);