/* * wrbmp.c * * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1996, Thomas G. Lane. * libjpeg-turbo Modifications: * Copyright (C) 2013, Linaro Limited. * Copyright (C) 2014-2015, 2017, 2019, 2022, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * * This file contains routines to write output images in Microsoft "BMP" * format (MS Windows 3.x and OS/2 1.x flavors). * Either 8-bit colormapped or 24-bit full-color format can be written. * No compression is supported. * * These routines may need modification for non-Unix environments or * specialized applications. As they stand, they assume output to * an ordinary stdio stream. * * This code contributed by James Arthur Boucher. */ #include "cmyk.h" #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include "jconfigint.h" #ifdef BMP_SUPPORTED /* * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. * This is not yet implemented. */ #if BITS_IN_JSAMPLE != 8 Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ #endif /* * Since BMP stores scanlines bottom-to-top, we have to invert the image * from JPEG's top-to-bottom order. To do this, we save the outgoing data * in a virtual array during put_pixel_row calls, then actually emit the * BMP file during finish_output. The virtual array contains one JSAMPLE per * pixel if the output is grayscale or colormapped, three if it is full color. */ /* Private version of data destination object */ bmp_dest_struct; bmp_dest_ptr; /* Forward declarations */ LOCAL(void) write_colormap(j_decompress_ptr cinfo, bmp_dest_ptr dest, int map_colors, int map_entry_size); static INLINE boolean is_big_endian(void) { … } /* * Write some pixel data. * In this module rows_supplied will always be 1. */ METHODDEF(void) put_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, JDIMENSION rows_supplied) /* This version is for writing 24-bit pixels */ { … } METHODDEF(void) put_gray_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, JDIMENSION rows_supplied) /* This version is for grayscale OR quantized color output */ { … } /* * Finish up at the end of the file. * * Here is where we really output the BMP file. * * First, routines to write the Windows and OS/2 variants of the file header. */ LOCAL(void) write_bmp_header(j_decompress_ptr cinfo, bmp_dest_ptr dest) /* Write a Windows-style BMP file header, including colormap if needed */ { … } LOCAL(void) write_os2_header(j_decompress_ptr cinfo, bmp_dest_ptr dest) /* Write an OS2-style BMP file header, including colormap if needed */ { … } /* * Write the colormap. * Windows uses BGR0 map entries; OS/2 uses BGR entries. */ LOCAL(void) write_colormap(j_decompress_ptr cinfo, bmp_dest_ptr dest, int map_colors, int map_entry_size) { … } /* * Startup: write the file header unless the inversion array is being used. */ METHODDEF(void) start_output_bmp(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) { … } METHODDEF(void) finish_output_bmp(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) { … } /* * The module selection routine for BMP format output. */ GLOBAL(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2, boolean use_inversion_array) { … } #endif /* BMP_SUPPORTED */