/* * rdbmp.c * * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1996, Thomas G. Lane. * Modified 2009-2017 by Guido Vollbeding. * libjpeg-turbo Modifications: * Modified 2011 by Siarhei Siamashka. * Copyright (C) 2015, 2017-2018, 2021-2022, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * * This file contains routines to read input images in Microsoft "BMP" * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors). * Currently, only 8-, 24-, and 32-bit images are supported, not 1-bit or * 4-bit (feeding such low-depth images into JPEG would be silly anyway). * Also, we don't support RLE-compressed files. * * These routines may need modification for non-Unix environments or * specialized applications. As they stand, they assume input from * an ordinary stdio stream. They further assume that reading begins * at the start of the file; start_input may need work if the * user interface has already read some data (e.g., to determine that * the file is indeed BMP format). * * This code contributed by James Arthur Boucher. */ #include "cmyk.h" #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #ifdef BMP_SUPPORTED /* Macros to deal with unsigned chars as efficiently as compiler allows */ U_CHAR; #define UCH(x) … #define ReadOK(file, buffer, len) … static int alpha_index[JPEG_NUMCS] = …; /* Private version of data source object */ bmp_source_ptr; bmp_source_struct; LOCAL(int) read_byte(bmp_source_ptr sinfo) /* Read next byte from BMP file */ { … } LOCAL(void) read_colormap(bmp_source_ptr sinfo, int cmaplen, int mapentrysize) /* Read the colormap from a BMP file */ { … } /* * Read one row of pixels. * The image has been read into the whole_image array, but is otherwise * unprocessed. We must read it out in top-to-bottom row order, and if * it is an 8-bit image, we must expand colormapped pixels to 24bit format. */ METHODDEF(JDIMENSION) get_8bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) /* This version is for reading 8-bit colormap indexes */ { … } METHODDEF(JDIMENSION) get_24bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) /* This version is for reading 24-bit pixels */ { … } METHODDEF(JDIMENSION) get_32bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) /* This version is for reading 32-bit pixels */ { … } /* * This method loads the image into whole_image during the first call on * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call * get_8bit_row, get_24bit_row, or get_32bit_row on subsequent calls. */ METHODDEF(JDIMENSION) preload_image(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) { … } /* * Read the file header; return image size and component count. */ METHODDEF(void) start_input_bmp(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) { … } /* * Finish up at the end of the file. */ METHODDEF(void) finish_input_bmp(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) { … } /* * The module selection routine for BMP format input. */ GLOBAL(cjpeg_source_ptr) jinit_read_bmp(j_compress_ptr cinfo, boolean use_inversion_array) { … } #endif /* BMP_SUPPORTED */