31 #ifdef HAVE_UNSIGNED_CHAR 33 #define UCH(x) ((int) (x)) 35 #ifdef CHAR_IS_UNSIGNED 37 #define UCH(x) ((int) (x)) 40 #define UCH(x) ((int) (x) & 0xFF) 45 #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) 52 typedef struct _bmp_source_struct {
71 register FILE *
infile = sinfo->pub.input_file;
75 ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);
86 switch (mapentrysize) {
89 for (
i = 0;
i < cmaplen;
i++) {
97 for (
i = 0;
i < cmaplen;
i++) {
105 ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP);
131 image_ptr = (*cinfo->mem->access_virt_sarray)
136 inptr = image_ptr[0];
137 outptr =
source->pub.buffer[0];
138 for (col = cinfo->image_width; col > 0; col--) {
140 *outptr++ = colormap[0][
t];
141 *outptr++ = colormap[1][
t];
142 *outptr++ = colormap[2][
t];
160 image_ptr = (*cinfo->mem->access_virt_sarray)
167 inptr = image_ptr[0];
168 outptr =
source->pub.buffer[0];
169 for (col = cinfo->image_width; col > 0; col--) {
170 outptr[2] = *inptr++;
171 outptr[1] = *inptr++;
172 outptr[0] = *inptr++;
199 if (progress !=
NULL) {
204 image_ptr = (*cinfo->mem->access_virt_sarray)
207 out_ptr = image_ptr[0];
208 for (col =
source->row_width; col > 0; col--) {
211 ERREXIT(cinfo, JERR_INPUT_EOF);
215 if (progress !=
NULL)
219 switch (
source->bits_per_pixel) {
227 ERREXIT(cinfo, JERR_BMP_BADDEPTH);
229 source->source_row = cinfo->image_height;
232 return (*
source->pub.get_pixel_rows) (cinfo, sinfo);
246 #define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \ 247 (((unsigned int) UCH(array[offset+1])) << 8)) 248 #define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \ 249 (((INT32) UCH(array[offset+1])) << 8) + \ 250 (((INT32) UCH(array[offset+2])) << 16) + \ 251 (((INT32) UCH(array[offset+3])) << 24)) 256 unsigned int biPlanes;
258 INT32 biXPelsPerMeter,biYPelsPerMeter;
260 int mapentrysize = 0;
265 if (!
ReadOK(
source->pub.input_file, bmpfileheader, 14))
266 ERREXIT(cinfo, JERR_INPUT_EOF);
267 if (
GET_2B(bmpfileheader,0) != 0x4D42)
276 ERREXIT(cinfo, JERR_INPUT_EOF);
278 if (headerSize < 12 || headerSize > 64)
279 ERREXIT(cinfo, JERR_BMP_BADHEADER);
280 if (!
ReadOK(
source->pub.input_file, bmpinfoheader+4, headerSize-4))
281 ERREXIT(cinfo, JERR_INPUT_EOF);
283 switch ((
int) headerSize) {
288 biPlanes =
GET_2B(bmpinfoheader,8);
291 switch (
source->bits_per_pixel) {
294 TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (
int) biWidth, (
int) biHeight);
297 TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (
int) biWidth, (
int) biHeight);
300 ERREXIT(cinfo, JERR_BMP_BADDEPTH);
304 ERREXIT(cinfo, JERR_BMP_BADPLANES);
310 biWidth =
GET_4B(bmpinfoheader,4);
311 biHeight =
GET_4B(bmpinfoheader,8);
312 biPlanes =
GET_2B(bmpinfoheader,12);
314 biCompression =
GET_4B(bmpinfoheader,16);
315 biXPelsPerMeter =
GET_4B(bmpinfoheader,24);
316 biYPelsPerMeter =
GET_4B(bmpinfoheader,28);
317 biClrUsed =
GET_4B(bmpinfoheader,32);
320 switch (
source->bits_per_pixel) {
323 TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (
int) biWidth, (
int) biHeight);
326 TRACEMS2(cinfo, 1, JTRC_BMP, (
int) biWidth, (
int) biHeight);
329 ERREXIT(cinfo, JERR_BMP_BADDEPTH);
333 ERREXIT(cinfo, JERR_BMP_BADPLANES);
334 if (biCompression != 0)
335 ERREXIT(cinfo, JERR_BMP_COMPRESSED);
337 if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) {
339 cinfo->X_density = (
UINT16) (biXPelsPerMeter/100);
340 cinfo->Y_density = (
UINT16) (biYPelsPerMeter/100);
341 cinfo->density_unit = 2;
345 ERREXIT(cinfo, JERR_BMP_BADHEADER);
350 bPad = bfOffBits - (headerSize + 14);
353 if (mapentrysize > 0) {
356 else if (biClrUsed > 256)
357 ERREXIT(cinfo, JERR_BMP_BADCMAP);
359 source->colormap = (*cinfo->mem->alloc_sarray)
365 bPad -= biClrUsed * mapentrysize;
370 ERREXIT(cinfo, JERR_BMP_BADHEADER);
371 while (--bPad >= 0) {
376 if (
source->bits_per_pixel == 24)
380 while ((row_width & 3) != 0) row_width++;
381 source->row_width = row_width;
384 source->whole_image = (*cinfo->mem->request_virt_sarray)
388 if (cinfo->progress !=
NULL) {
394 source->pub.buffer = (*cinfo->mem->alloc_sarray)
397 source->pub.buffer_height = 1;
399 cinfo->in_color_space =
JCS_RGB;
400 cinfo->input_components = 3;
401 cinfo->data_precision = 8;
for(n=1;n< outline->n_points;n++)
struct _bmp_source_struct * bmp_source_ptr
struct jpeg_common_struct * j_common_ptr
start_input_bmp(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
GLsizei GLsizei GLchar * source
#define GETJSAMPLE(value)
#define ERREXIT(cinfo, code)
#define TRACEMS2(cinfo, lvl, code, p1, p2)
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
jinit_read_bmp(j_compress_ptr cinfo)
#define GET_2B(array, offset)
read_byte(bmp_source_ptr sinfo)
finish_input_bmp(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
GLenum GLenum GLvoid * row
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
struct jpeg_progress_mgr pub
struct _bmp_source_struct bmp_source_struct
get_24bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
int completed_extra_passes
read_colormap(bmp_source_ptr sinfo, int cmaplen, int mapentrysize)
#define ReadOK(file, buffer, len)
struct cdjpeg_progress_mgr * cd_progress_ptr
preload_image(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
struct jvirt_sarray_control * jvirt_sarray_ptr
get_8bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
#define GET_4B(array, offset)