wrbmp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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, 2019, 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 (IsExtRGB(cinfo->out_color_space)) {
  261. if (cinfo->quantize_colors) {
  262. /* Colormapped RGB */
  263. bits_per_pixel = 8;
  264. cmap_entries = 256;
  265. } else {
  266. /* Unquantized, full color RGB */
  267. bits_per_pixel = 24;
  268. cmap_entries = 0;
  269. }
  270. } else if (cinfo->out_color_space == JCS_RGB565 ||
  271. cinfo->out_color_space == JCS_CMYK) {
  272. bits_per_pixel = 24;
  273. cmap_entries = 0;
  274. } else {
  275. /* Grayscale output. We need to fake a 256-entry colormap. */
  276. bits_per_pixel = 8;
  277. cmap_entries = 256;
  278. }
  279. /* File size */
  280. headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */
  281. bfSize = headersize + (long)dest->row_width * (long)cinfo->output_height;
  282. /* Set unused fields of header to 0 */
  283. MEMZERO(bmpfileheader, sizeof(bmpfileheader));
  284. MEMZERO(bmpcoreheader, sizeof(bmpcoreheader));
  285. /* Fill the file header */
  286. bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */
  287. bmpfileheader[1] = 0x4D;
  288. PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */
  289. /* we leave bfReserved1 & bfReserved2 = 0 */
  290. PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */
  291. /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */
  292. PUT_2B(bmpcoreheader, 0, 12); /* bcSize */
  293. PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */
  294. PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */
  295. PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */
  296. PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */
  297. if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t)14)
  298. ERREXIT(cinfo, JERR_FILE_WRITE);
  299. if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t)12)
  300. ERREXIT(cinfo, JERR_FILE_WRITE);
  301. if (cmap_entries > 0)
  302. write_colormap(cinfo, dest, cmap_entries, 3);
  303. }
  304. /*
  305. * Write the colormap.
  306. * Windows uses BGR0 map entries; OS/2 uses BGR entries.
  307. */
  308. LOCAL(void)
  309. write_colormap(j_decompress_ptr cinfo, bmp_dest_ptr dest, int map_colors,
  310. int map_entry_size)
  311. {
  312. JSAMPARRAY colormap = cinfo->colormap;
  313. int num_colors = cinfo->actual_number_of_colors;
  314. FILE *outfile = dest->pub.output_file;
  315. int i;
  316. if (colormap != NULL) {
  317. if (cinfo->out_color_components == 3) {
  318. /* Normal case with RGB colormap */
  319. for (i = 0; i < num_colors; i++) {
  320. putc(GETJSAMPLE(colormap[2][i]), outfile);
  321. putc(GETJSAMPLE(colormap[1][i]), outfile);
  322. putc(GETJSAMPLE(colormap[0][i]), outfile);
  323. if (map_entry_size == 4)
  324. putc(0, outfile);
  325. }
  326. } else {
  327. /* Grayscale colormap (only happens with grayscale quantization) */
  328. for (i = 0; i < num_colors; i++) {
  329. putc(GETJSAMPLE(colormap[0][i]), outfile);
  330. putc(GETJSAMPLE(colormap[0][i]), outfile);
  331. putc(GETJSAMPLE(colormap[0][i]), outfile);
  332. if (map_entry_size == 4)
  333. putc(0, outfile);
  334. }
  335. }
  336. } else {
  337. /* If no colormap, must be grayscale data. Generate a linear "map". */
  338. for (i = 0; i < 256; i++) {
  339. putc(i, outfile);
  340. putc(i, outfile);
  341. putc(i, outfile);
  342. if (map_entry_size == 4)
  343. putc(0, outfile);
  344. }
  345. }
  346. /* Pad colormap with zeros to ensure specified number of colormap entries */
  347. if (i > map_colors)
  348. ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i);
  349. for (; i < map_colors; i++) {
  350. putc(0, outfile);
  351. putc(0, outfile);
  352. putc(0, outfile);
  353. if (map_entry_size == 4)
  354. putc(0, outfile);
  355. }
  356. }
  357. /*
  358. * Startup: write the file header unless the inversion array is being used.
  359. */
  360. METHODDEF(void)
  361. start_output_bmp(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
  362. {
  363. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  364. if (!dest->use_inversion_array) {
  365. /* Write the header and colormap */
  366. if (dest->is_os2)
  367. write_os2_header(cinfo, dest);
  368. else
  369. write_bmp_header(cinfo, dest);
  370. }
  371. }
  372. METHODDEF(void)
  373. finish_output_bmp(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
  374. {
  375. bmp_dest_ptr dest = (bmp_dest_ptr)dinfo;
  376. register FILE *outfile = dest->pub.output_file;
  377. JSAMPARRAY image_ptr;
  378. register JSAMPROW data_ptr;
  379. JDIMENSION row;
  380. register JDIMENSION col;
  381. cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress;
  382. if (dest->use_inversion_array) {
  383. /* Write the header and colormap */
  384. if (dest->is_os2)
  385. write_os2_header(cinfo, dest);
  386. else
  387. write_bmp_header(cinfo, dest);
  388. /* Write the file body from our virtual array */
  389. for (row = cinfo->output_height; row > 0; row--) {
  390. if (progress != NULL) {
  391. progress->pub.pass_counter = (long)(cinfo->output_height - row);
  392. progress->pub.pass_limit = (long)cinfo->output_height;
  393. (*progress->pub.progress_monitor) ((j_common_ptr)cinfo);
  394. }
  395. image_ptr = (*cinfo->mem->access_virt_sarray)
  396. ((j_common_ptr)cinfo, dest->whole_image, row - 1, (JDIMENSION)1,
  397. FALSE);
  398. data_ptr = image_ptr[0];
  399. for (col = dest->row_width; col > 0; col--) {
  400. putc(GETJSAMPLE(*data_ptr), outfile);
  401. data_ptr++;
  402. }
  403. }
  404. if (progress != NULL)
  405. progress->completed_extra_passes++;
  406. }
  407. /* Make sure we wrote the output file OK */
  408. fflush(outfile);
  409. if (ferror(outfile))
  410. ERREXIT(cinfo, JERR_FILE_WRITE);
  411. }
  412. /*
  413. * The module selection routine for BMP format output.
  414. */
  415. GLOBAL(djpeg_dest_ptr)
  416. jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
  417. boolean use_inversion_array)
  418. {
  419. bmp_dest_ptr dest;
  420. JDIMENSION row_width;
  421. /* Create module interface object, fill in method pointers */
  422. dest = (bmp_dest_ptr)
  423. (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
  424. sizeof(bmp_dest_struct));
  425. dest->pub.start_output = start_output_bmp;
  426. dest->pub.finish_output = finish_output_bmp;
  427. dest->pub.calc_buffer_dimensions = NULL;
  428. dest->is_os2 = is_os2;
  429. if (cinfo->out_color_space == JCS_GRAYSCALE) {
  430. dest->pub.put_pixel_rows = put_gray_rows;
  431. } else if (IsExtRGB(cinfo->out_color_space)) {
  432. if (cinfo->quantize_colors)
  433. dest->pub.put_pixel_rows = put_gray_rows;
  434. else
  435. dest->pub.put_pixel_rows = put_pixel_rows;
  436. } else if (!cinfo->quantize_colors &&
  437. (cinfo->out_color_space == JCS_RGB565 ||
  438. cinfo->out_color_space == JCS_CMYK)) {
  439. dest->pub.put_pixel_rows = put_pixel_rows;
  440. } else {
  441. ERREXIT(cinfo, JERR_BMP_COLORSPACE);
  442. }
  443. /* Calculate output image dimensions so we can allocate space */
  444. jpeg_calc_output_dimensions(cinfo);
  445. /* Determine width of rows in the BMP file (padded to 4-byte boundary). */
  446. if (cinfo->out_color_space == JCS_RGB565) {
  447. row_width = cinfo->output_width * 2;
  448. dest->row_width = dest->data_width = cinfo->output_width * 3;
  449. while ((row_width & 3) != 0) row_width++;
  450. } else if (!cinfo->quantize_colors &&
  451. (IsExtRGB(cinfo->out_color_space) ||
  452. cinfo->out_color_space == JCS_CMYK)) {
  453. row_width = cinfo->output_width * cinfo->output_components;
  454. dest->row_width = dest->data_width = cinfo->output_width * 3;
  455. } else {
  456. row_width = cinfo->output_width * cinfo->output_components;
  457. dest->row_width = dest->data_width = row_width;
  458. }
  459. while ((dest->row_width & 3) != 0) dest->row_width++;
  460. dest->pad_bytes = (int)(dest->row_width - dest->data_width);
  461. if (use_inversion_array) {
  462. /* Allocate space for inversion array, prepare for write pass */
  463. dest->whole_image = (*cinfo->mem->request_virt_sarray)
  464. ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
  465. dest->row_width, cinfo->output_height, (JDIMENSION)1);
  466. dest->cur_output_row = 0;
  467. if (cinfo->progress != NULL) {
  468. cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress;
  469. progress->total_extra_passes++; /* count file input as separate pass */
  470. }
  471. } else {
  472. dest->iobuffer = (JSAMPLE *)(*cinfo->mem->alloc_small)
  473. ((j_common_ptr)cinfo, JPOOL_IMAGE, dest->row_width);
  474. }
  475. dest->use_inversion_array = use_inversion_array;
  476. /* Create decompressor output buffer. */
  477. dest->pub.buffer = (*cinfo->mem->alloc_sarray)
  478. ((j_common_ptr)cinfo, JPOOL_IMAGE, row_width, (JDIMENSION)1);
  479. dest->pub.buffer_height = 1;
  480. return (djpeg_dest_ptr)dest;
  481. }
  482. #endif /* BMP_SUPPORTED */