wrbmp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /*
  2. * wrbmp.c
  3. *
  4. * This file was part of the Independent JPEG Group's software:
  5. * Copyright (C) 1994-1996, Thomas G. Lane.
  6. * libjpeg-turbo Modifications:
  7. * Copyright (C) 2013, Linaro Limited.
  8. * Copyright (C) 2014-2015, 2017, D. R. Commander.
  9. * For conditions of distribution and use, see the accompanying README.ijg
  10. * file.
  11. *
  12. * This file contains routines to write output images in Microsoft "BMP"
  13. * format (MS Windows 3.x and OS/2 1.x flavors).
  14. * Either 8-bit colormapped or 24-bit full-color format can be written.
  15. * No compression is supported.
  16. *
  17. * These routines may need modification for non-Unix environments or
  18. * specialized applications. As they stand, they assume output to
  19. * an ordinary stdio stream.
  20. *
  21. * This code contributed by James Arthur Boucher.
  22. */
  23. #include "cmyk.h"
  24. #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
  25. #include "jconfigint.h"
  26. #ifdef BMP_SUPPORTED
  27. /*
  28. * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.
  29. * This is not yet implemented.
  30. */
  31. #if BITS_IN_JSAMPLE != 8
  32. Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */
  33. #endif
  34. /*
  35. * Since BMP stores scanlines bottom-to-top, we have to invert the image
  36. * from JPEG's top-to-bottom order. To do this, we save the outgoing data
  37. * in a virtual array during put_pixel_row calls, then actually emit the
  38. * BMP file during finish_output. The virtual array contains one JSAMPLE per
  39. * pixel if the output is grayscale or colormapped, three if it is full color.
  40. */
  41. /* Private version of data destination object */
  42. typedef struct {
  43. struct djpeg_dest_struct pub; /* public fields */
  44. boolean is_os2; /* saves the OS2 format request flag */
  45. jvirt_sarray_ptr whole_image; /* needed to reverse row order */
  46. JDIMENSION data_width; /* JSAMPLEs per row */
  47. JDIMENSION row_width; /* physical width of one row in the BMP file */
  48. int pad_bytes; /* number of padding bytes needed per row */
  49. JDIMENSION cur_output_row; /* next row# to write to virtual array */
  50. boolean use_inversion_array; /* TRUE = buffer the whole image, which is
  51. stored to disk in bottom-up order, and
  52. receive rows from the calling program in
  53. top-down order
  54. FALSE = the calling program will maintain
  55. its own image buffer and write the rows in
  56. bottom-up order */
  57. JSAMPLE *iobuffer; /* I/O buffer (used to buffer a single row to
  58. disk if use_inversion_array == FALSE) */
  59. } bmp_dest_struct;
  60. typedef bmp_dest_struct *bmp_dest_ptr;
  61. /* Forward declarations */
  62. LOCAL(void) write_colormap(j_decompress_ptr cinfo, bmp_dest_ptr dest,
  63. int map_colors, int map_entry_size);
  64. static INLINE boolean is_big_endian(void)
  65. {
  66. int test_value = 1;
  67. if (*(char *)&test_value != 1)
  68. return TRUE;
  69. return FALSE;
  70. }
  71. /*
  72. * Write some pixel data.
  73. * In this module rows_supplied will always be 1.
  74. */
  75. METHODDEF(void)
  76. put_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
  77. JDIMENSION rows_supplied)
  78. /* This version is for writing 24-bit pixels */
  79. {
  80. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  81. JSAMPARRAY image_ptr;
  82. register JSAMPROW inptr, outptr;
  83. register JDIMENSION col;
  84. int pad;
  85. if (dest->use_inversion_array) {
  86. /* Access next row in virtual array */
  87. image_ptr = (*cinfo->mem->access_virt_sarray)
  88. ((j_common_ptr)cinfo, dest->whole_image,
  89. dest->cur_output_row, (JDIMENSION)1, TRUE);
  90. dest->cur_output_row++;
  91. outptr = image_ptr[0];
  92. } else {
  93. outptr = dest->iobuffer;
  94. }
  95. /* Transfer data. Note destination values must be in BGR order
  96. * (even though Microsoft's own documents say the opposite).
  97. */
  98. inptr = dest->pub.buffer[0];
  99. if (cinfo->out_color_space == JCS_EXT_BGR) {
  100. MEMCOPY(outptr, inptr, dest->row_width);
  101. outptr += cinfo->output_width * 3;
  102. } else if (cinfo->out_color_space == JCS_RGB565) {
  103. boolean big_endian = is_big_endian();
  104. unsigned short *inptr2 = (unsigned short *)inptr;
  105. for (col = cinfo->output_width; col > 0; col--) {
  106. if (big_endian) {
  107. outptr[0] = (*inptr2 >> 5) & 0xF8;
  108. outptr[1] = ((*inptr2 << 5) & 0xE0) | ((*inptr2 >> 11) & 0x1C);
  109. outptr[2] = *inptr2 & 0xF8;
  110. } else {
  111. outptr[0] = (*inptr2 << 3) & 0xF8;
  112. outptr[1] = (*inptr2 >> 3) & 0xFC;
  113. outptr[2] = (*inptr2 >> 8) & 0xF8;
  114. }
  115. outptr += 3;
  116. inptr2++;
  117. }
  118. } else if (cinfo->out_color_space == JCS_CMYK) {
  119. for (col = cinfo->output_width; col > 0; col--) {
  120. /* can omit GETJSAMPLE() safely */
  121. JSAMPLE c = *inptr++, m = *inptr++, y = *inptr++, k = *inptr++;
  122. cmyk_to_rgb(c, m, y, k, outptr + 2, outptr + 1, outptr);
  123. outptr += 3;
  124. }
  125. } else {
  126. register int rindex = rgb_red[cinfo->out_color_space];
  127. register int gindex = rgb_green[cinfo->out_color_space];
  128. register int bindex = rgb_blue[cinfo->out_color_space];
  129. register int ps = rgb_pixelsize[cinfo->out_color_space];
  130. for (col = cinfo->output_width; col > 0; col--) {
  131. /* can omit GETJSAMPLE() safely */
  132. outptr[0] = inptr[bindex];
  133. outptr[1] = inptr[gindex];
  134. outptr[2] = inptr[rindex];
  135. outptr += 3; inptr += ps;
  136. }
  137. }
  138. /* Zero out the pad bytes. */
  139. pad = dest->pad_bytes;
  140. while (--pad >= 0)
  141. *outptr++ = 0;
  142. if (!dest->use_inversion_array)
  143. (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->row_width);
  144. }
  145. METHODDEF(void)
  146. put_gray_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
  147. JDIMENSION rows_supplied)
  148. /* This version is for grayscale OR quantized color output */
  149. {
  150. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  151. JSAMPARRAY image_ptr;
  152. register JSAMPROW inptr, outptr;
  153. int pad;
  154. if (dest->use_inversion_array) {
  155. /* Access next row in virtual array */
  156. image_ptr = (*cinfo->mem->access_virt_sarray)
  157. ((j_common_ptr)cinfo, dest->whole_image,
  158. dest->cur_output_row, (JDIMENSION)1, TRUE);
  159. dest->cur_output_row++;
  160. outptr = image_ptr[0];
  161. } else {
  162. outptr = dest->iobuffer;
  163. }
  164. /* Transfer data. */
  165. inptr = dest->pub.buffer[0];
  166. MEMCOPY(outptr, inptr, cinfo->output_width);
  167. outptr += cinfo->output_width;
  168. /* Zero out the pad bytes. */
  169. pad = dest->pad_bytes;
  170. while (--pad >= 0)
  171. *outptr++ = 0;
  172. if (!dest->use_inversion_array)
  173. (void)JFWRITE(dest->pub.output_file, dest->iobuffer, dest->row_width);
  174. }
  175. /*
  176. * Finish up at the end of the file.
  177. *
  178. * Here is where we really output the BMP file.
  179. *
  180. * First, routines to write the Windows and OS/2 variants of the file header.
  181. */
  182. LOCAL(void)
  183. write_bmp_header(j_decompress_ptr cinfo, bmp_dest_ptr dest)
  184. /* Write a Windows-style BMP file header, including colormap if needed */
  185. {
  186. char bmpfileheader[14];
  187. char bmpinfoheader[40];
  188. #define PUT_2B(array, offset, value) \
  189. (array[offset] = (char)((value) & 0xFF), \
  190. array[offset + 1] = (char)(((value) >> 8) & 0xFF))
  191. #define PUT_4B(array, offset, value) \
  192. (array[offset] = (char)((value) & 0xFF), \
  193. array[offset + 1] = (char)(((value) >> 8) & 0xFF), \
  194. array[offset + 2] = (char)(((value) >> 16) & 0xFF), \
  195. array[offset + 3] = (char)(((value) >> 24) & 0xFF))
  196. long headersize, bfSize;
  197. int bits_per_pixel, cmap_entries;
  198. /* Compute colormap size and total file size */
  199. if (IsExtRGB(cinfo->out_color_space)) {
  200. if (cinfo->quantize_colors) {
  201. /* Colormapped RGB */
  202. bits_per_pixel = 8;
  203. cmap_entries = 256;
  204. } else {
  205. /* Unquantized, full color RGB */
  206. bits_per_pixel = 24;
  207. cmap_entries = 0;
  208. }
  209. } else if (cinfo->out_color_space == JCS_RGB565 ||
  210. cinfo->out_color_space == JCS_CMYK) {
  211. bits_per_pixel = 24;
  212. cmap_entries = 0;
  213. } else {
  214. /* Grayscale output. We need to fake a 256-entry colormap. */
  215. bits_per_pixel = 8;
  216. cmap_entries = 256;
  217. }
  218. /* File size */
  219. headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */
  220. bfSize = headersize + (long)dest->row_width * (long)cinfo->output_height;
  221. /* Set unused fields of header to 0 */
  222. MEMZERO(bmpfileheader, sizeof(bmpfileheader));
  223. MEMZERO(bmpinfoheader, sizeof(bmpinfoheader));
  224. /* Fill the file header */
  225. bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
  226. bmpfileheader[1] = 0x4D;
  227. PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
  228. /* we leave bfReserved1 & bfReserved2 = 0 */
  229. PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
  230. /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */
  231. PUT_2B(bmpinfoheader, 0, 40); /* biSize */
  232. PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */
  233. PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */
  234. PUT_2B(bmpinfoheader, 12, 1); /* biPlanes - must be 1 */
  235. PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */
  236. /* we leave biCompression = 0, for none */
  237. /* we leave biSizeImage = 0; this is correct for uncompressed data */
  238. if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */
  239. PUT_4B(bmpinfoheader, 24, (long)(cinfo->X_density * 100)); /* XPels/M */
  240. PUT_4B(bmpinfoheader, 28, (long)(cinfo->Y_density * 100)); /* XPels/M */
  241. }
  242. PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */
  243. /* we leave biClrImportant = 0 */
  244. if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t)14)
  245. ERREXIT(cinfo, JERR_FILE_WRITE);
  246. if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t)40)
  247. ERREXIT(cinfo, JERR_FILE_WRITE);
  248. if (cmap_entries > 0)
  249. write_colormap(cinfo, dest, cmap_entries, 4);
  250. }
  251. LOCAL(void)
  252. write_os2_header(j_decompress_ptr cinfo, bmp_dest_ptr dest)
  253. /* Write an OS2-style BMP file header, including colormap if needed */
  254. {
  255. char bmpfileheader[14];
  256. char bmpcoreheader[12];
  257. long headersize, bfSize;
  258. int bits_per_pixel, cmap_entries;
  259. /* Compute colormap size and total file size */
  260. if (cinfo->out_color_space == JCS_RGB ||
  261. (cinfo->out_color_space >= JCS_EXT_RGB &&
  262. cinfo->out_color_space <= JCS_EXT_ARGB)) {
  263. if (cinfo->quantize_colors) {
  264. /* Colormapped RGB */
  265. bits_per_pixel = 8;
  266. cmap_entries = 256;
  267. } else {
  268. /* Unquantized, full color RGB */
  269. bits_per_pixel = 24;
  270. cmap_entries = 0;
  271. }
  272. } else if (cinfo->out_color_space == JCS_RGB565 ||
  273. cinfo->out_color_space == JCS_CMYK) {
  274. bits_per_pixel = 24;
  275. cmap_entries = 0;
  276. } else {
  277. /* Grayscale output. We need to fake a 256-entry colormap. */
  278. bits_per_pixel = 8;
  279. cmap_entries = 256;
  280. }
  281. /* File size */
  282. headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */
  283. bfSize = headersize + (long)dest->row_width * (long)cinfo->output_height;
  284. /* Set unused fields of header to 0 */
  285. MEMZERO(bmpfileheader, sizeof(bmpfileheader));
  286. MEMZERO(bmpcoreheader, sizeof(bmpcoreheader));
  287. /* Fill the file header */
  288. bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
  289. bmpfileheader[1] = 0x4D;
  290. PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
  291. /* we leave bfReserved1 & bfReserved2 = 0 */
  292. PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
  293. /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */
  294. PUT_2B(bmpcoreheader, 0, 12); /* bcSize */
  295. PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */
  296. PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */
  297. PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */
  298. PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */
  299. if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t)14)
  300. ERREXIT(cinfo, JERR_FILE_WRITE);
  301. if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t)12)
  302. ERREXIT(cinfo, JERR_FILE_WRITE);
  303. if (cmap_entries > 0)
  304. write_colormap(cinfo, dest, cmap_entries, 3);
  305. }
  306. /*
  307. * Write the colormap.
  308. * Windows uses BGR0 map entries; OS/2 uses BGR entries.
  309. */
  310. LOCAL(void)
  311. write_colormap(j_decompress_ptr cinfo, bmp_dest_ptr dest, int map_colors,
  312. int map_entry_size)
  313. {
  314. JSAMPARRAY colormap = cinfo->colormap;
  315. int num_colors = cinfo->actual_number_of_colors;
  316. FILE *outfile = dest->pub.output_file;
  317. int i;
  318. if (colormap != NULL) {
  319. if (cinfo->out_color_components == 3) {
  320. /* Normal case with RGB colormap */
  321. for (i = 0; i < num_colors; i++) {
  322. putc(GETJSAMPLE(colormap[2][i]), outfile);
  323. putc(GETJSAMPLE(colormap[1][i]), outfile);
  324. putc(GETJSAMPLE(colormap[0][i]), outfile);
  325. if (map_entry_size == 4)
  326. putc(0, outfile);
  327. }
  328. } else {
  329. /* Grayscale colormap (only happens with grayscale quantization) */
  330. for (i = 0; i < num_colors; i++) {
  331. putc(GETJSAMPLE(colormap[0][i]), outfile);
  332. putc(GETJSAMPLE(colormap[0][i]), outfile);
  333. putc(GETJSAMPLE(colormap[0][i]), outfile);
  334. if (map_entry_size == 4)
  335. putc(0, outfile);
  336. }
  337. }
  338. } else {
  339. /* If no colormap, must be grayscale data. Generate a linear "map". */
  340. for (i = 0; i < 256; i++) {
  341. putc(i, outfile);
  342. putc(i, outfile);
  343. putc(i, outfile);
  344. if (map_entry_size == 4)
  345. putc(0, outfile);
  346. }
  347. }
  348. /* Pad colormap with zeros to ensure specified number of colormap entries */
  349. if (i > map_colors)
  350. ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i);
  351. for (; i < map_colors; i++) {
  352. putc(0, outfile);
  353. putc(0, outfile);
  354. putc(0, outfile);
  355. if (map_entry_size == 4)
  356. putc(0, outfile);
  357. }
  358. }
  359. /*
  360. * Startup: write the file header unless the inversion array is being used.
  361. */
  362. METHODDEF(void)
  363. start_output_bmp(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
  364. {
  365. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  366. if (!dest->use_inversion_array) {
  367. /* Write the header and colormap */
  368. if (dest->is_os2)
  369. write_os2_header(cinfo, dest);
  370. else
  371. write_bmp_header(cinfo, dest);
  372. }
  373. }
  374. METHODDEF(void)
  375. finish_output_bmp(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
  376. {
  377. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  378. register FILE *outfile = dest->pub.output_file;
  379. JSAMPARRAY image_ptr;
  380. register JSAMPROW data_ptr;
  381. JDIMENSION row;
  382. register JDIMENSION col;
  383. cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress;
  384. if (dest->use_inversion_array) {
  385. /* Write the header and colormap */
  386. if (dest->is_os2)
  387. write_os2_header(cinfo, dest);
  388. else
  389. write_bmp_header(cinfo, dest);
  390. /* Write the file body from our virtual array */
  391. for (row = cinfo->output_height; row > 0; row--) {
  392. if (progress != NULL) {
  393. progress->pub.pass_counter = (long)(cinfo->output_height - row);
  394. progress->pub.pass_limit = (long)cinfo->output_height;
  395. (*progress->pub.progress_monitor) ((j_common_ptr)cinfo);
  396. }
  397. image_ptr = (*cinfo->mem->access_virt_sarray)
  398. ((j_common_ptr)cinfo, dest->whole_image, row - 1, (JDIMENSION)1,
  399. FALSE);
  400. data_ptr = image_ptr[0];
  401. for (col = dest->row_width; col > 0; col--) {
  402. putc(GETJSAMPLE(*data_ptr), outfile);
  403. data_ptr++;
  404. }
  405. }
  406. if (progress != NULL)
  407. progress->completed_extra_passes++;
  408. }
  409. /* Make sure we wrote the output file OK */
  410. fflush(outfile);
  411. if (ferror(outfile))
  412. ERREXIT(cinfo, JERR_FILE_WRITE);
  413. }
  414. /*
  415. * The module selection routine for BMP format output.
  416. */
  417. GLOBAL(djpeg_dest_ptr)
  418. jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
  419. boolean use_inversion_array)
  420. {
  421. bmp_dest_ptr dest;
  422. JDIMENSION row_width;
  423. /* Create module interface object, fill in method pointers */
  424. dest = (bmp_dest_ptr)
  425. (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
  426. sizeof(bmp_dest_struct));
  427. dest->pub.start_output = start_output_bmp;
  428. dest->pub.finish_output = finish_output_bmp;
  429. dest->pub.calc_buffer_dimensions = NULL;
  430. dest->is_os2 = is_os2;
  431. if (cinfo->out_color_space == JCS_GRAYSCALE) {
  432. dest->pub.put_pixel_rows = put_gray_rows;
  433. } else if (cinfo->out_color_space == JCS_RGB ||
  434. (cinfo->out_color_space >= JCS_EXT_RGB &&
  435. cinfo->out_color_space <= JCS_EXT_ARGB)) {
  436. if (cinfo->quantize_colors)
  437. dest->pub.put_pixel_rows = put_gray_rows;
  438. else
  439. dest->pub.put_pixel_rows = put_pixel_rows;
  440. } else if (cinfo->out_color_space == JCS_RGB565 ||
  441. cinfo->out_color_space == JCS_CMYK) {
  442. dest->pub.put_pixel_rows = put_pixel_rows;
  443. } else {
  444. ERREXIT(cinfo, JERR_BMP_COLORSPACE);
  445. }
  446. /* Calculate output image dimensions so we can allocate space */
  447. jpeg_calc_output_dimensions(cinfo);
  448. /* Determine width of rows in the BMP file (padded to 4-byte boundary). */
  449. if (cinfo->out_color_space == JCS_RGB565) {
  450. row_width = cinfo->output_width * 2;
  451. dest->row_width = dest->data_width = cinfo->output_width * 3;
  452. while ((row_width & 3) != 0) row_width++;
  453. } else if (!cinfo->quantize_colors &&
  454. (IsExtRGB(cinfo->out_color_space) ||
  455. cinfo->out_color_space == JCS_CMYK)) {
  456. row_width = cinfo->output_width * cinfo->output_components;
  457. dest->row_width = dest->data_width = cinfo->output_width * 3;
  458. } else {
  459. row_width = cinfo->output_width * cinfo->output_components;
  460. dest->row_width = dest->data_width = row_width;
  461. }
  462. while ((dest->row_width & 3) != 0) dest->row_width++;
  463. dest->pad_bytes = (int)(dest->row_width - dest->data_width);
  464. if (use_inversion_array) {
  465. /* Allocate space for inversion array, prepare for write pass */
  466. dest->whole_image = (*cinfo->mem->request_virt_sarray)
  467. ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
  468. dest->row_width, cinfo->output_height, (JDIMENSION)1);
  469. dest->cur_output_row = 0;
  470. if (cinfo->progress != NULL) {
  471. cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress;
  472. progress->total_extra_passes++; /* count file input as separate pass */
  473. }
  474. } else {
  475. dest->iobuffer = (JSAMPLE *)(*cinfo->mem->alloc_small)
  476. ((j_common_ptr)cinfo, JPOOL_IMAGE, dest->row_width);
  477. }
  478. dest->use_inversion_array = use_inversion_array;
  479. /* Create decompressor output buffer. */
  480. dest->pub.buffer = (*cinfo->mem->alloc_sarray)
  481. ((j_common_ptr)cinfo, JPOOL_IMAGE, row_width, (JDIMENSION)1);
  482. dest->pub.buffer_height = 1;
  483. return (djpeg_dest_ptr)dest;
  484. }
  485. #endif /* BMP_SUPPORTED */