Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: rdbmp.c

Issue 1953443002: Update to libjpeg_turbo 1.4.90 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mac/jsimdcfg.inc ('k') | rdcolmap.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * rdbmp.c 2 * rdbmp.c
3 * 3 *
4 * This file was part of the Independent JPEG Group's software: 4 * This file was part of the Independent JPEG Group's software:
5 * Copyright (C) 1994-1996, Thomas G. Lane. 5 * Copyright (C) 1994-1996, Thomas G. Lane.
6 * Modified 2009-2010 by Guido Vollbeding. 6 * Modified 2009-2010 by Guido Vollbeding.
7 * libjpeg-turbo Modifications: 7 * libjpeg-turbo Modifications:
8 * Modified 2011 by Siarhei Siamashka. 8 * Modified 2011 by Siarhei Siamashka.
9 * For conditions of distribution and use, see the accompanying README file. 9 * Copyright (C) 2015, D. R. Commander.
10 * For conditions of distribution and use, see the accompanying README.ijg
11 * file.
10 * 12 *
11 * This file contains routines to read input images in Microsoft "BMP" 13 * This file contains routines to read input images in Microsoft "BMP"
12 * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors). 14 * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors).
13 * Currently, only 8-bit and 24-bit images are supported, not 1-bit or 15 * Currently, only 8-bit and 24-bit images are supported, not 1-bit or
14 * 4-bit (feeding such low-depth images into JPEG would be silly anyway). 16 * 4-bit (feeding such low-depth images into JPEG would be silly anyway).
15 * Also, we don't support RLE-compressed files. 17 * Also, we don't support RLE-compressed files.
16 * 18 *
17 * These routines may need modification for non-Unix environments or 19 * These routines may need modification for non-Unix environments or
18 * specialized applications. As they stand, they assume input from 20 * specialized applications. As they stand, they assume input from
19 * an ordinary stdio stream. They further assume that reading begins 21 * an ordinary stdio stream. They further assume that reading begins
20 * at the start of the file; start_input may need work if the 22 * at the start of the file; start_input may need work if the
21 * user interface has already read some data (e.g., to determine that 23 * user interface has already read some data (e.g., to determine that
22 * the file is indeed BMP format). 24 * the file is indeed BMP format).
23 * 25 *
24 * This code contributed by James Arthur Boucher. 26 * This code contributed by James Arthur Boucher.
25 */ 27 */
26 28
27 #include "cdjpeg.h"» » /* Common decls for cjpeg/djpeg applications */ 29 #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
28 30
29 #ifdef BMP_SUPPORTED 31 #ifdef BMP_SUPPORTED
30 32
31 33
32 /* Macros to deal with unsigned chars as efficiently as compiler allows */ 34 /* Macros to deal with unsigned chars as efficiently as compiler allows */
33 35
34 #ifdef HAVE_UNSIGNED_CHAR 36 #ifdef HAVE_UNSIGNED_CHAR
35 typedef unsigned char U_CHAR; 37 typedef unsigned char U_CHAR;
36 #define UCH(x)» ((int) (x)) 38 #define UCH(x) ((int) (x))
37 #else /* !HAVE_UNSIGNED_CHAR */ 39 #else /* !HAVE_UNSIGNED_CHAR */
38 #ifdef CHAR_IS_UNSIGNED 40 #ifdef __CHAR_UNSIGNED__
39 typedef char U_CHAR; 41 typedef char U_CHAR;
40 #define UCH(x)» ((int) (x)) 42 #define UCH(x) ((int) (x))
41 #else 43 #else
42 typedef char U_CHAR; 44 typedef char U_CHAR;
43 #define UCH(x)» ((int) (x) & 0xFF) 45 #define UCH(x) ((int) (x) & 0xFF)
44 #endif 46 #endif
45 #endif /* HAVE_UNSIGNED_CHAR */ 47 #endif /* HAVE_UNSIGNED_CHAR */
46 48
47 49
48 #define»ReadOK(file,buffer,len)»(JFREAD(file,buffer,len) == ((size_t) (len))) 50 #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len)))
49 51
50 52
51 /* Private version of data source object */ 53 /* Private version of data source object */
52 54
53 typedef struct _bmp_source_struct * bmp_source_ptr; 55 typedef struct _bmp_source_struct *bmp_source_ptr;
54 56
55 typedef struct _bmp_source_struct { 57 typedef struct _bmp_source_struct {
56 struct cjpeg_source_struct pub; /* public fields */ 58 struct cjpeg_source_struct pub; /* public fields */
57 59
58 j_compress_ptr cinfo;»» /* back link saves passing separate parm */ 60 j_compress_ptr cinfo; /* back link saves passing separate parm */
59 61
60 JSAMPARRAY colormap;» » /* BMP colormap (converted to my format) */ 62 JSAMPARRAY colormap; /* BMP colormap (converted to my format) */
61 63
62 jvirt_sarray_ptr whole_image;»/* Needed to reverse row order */ 64 jvirt_sarray_ptr whole_image; /* Needed to reverse row order */
63 JDIMENSION source_row;» /* Current source row number */ 65 JDIMENSION source_row; /* Current source row number */
64 JDIMENSION row_width;»» /* Physical width of scanlines in file */ 66 JDIMENSION row_width; /* Physical width of scanlines in file */
65 67
66 int bits_per_pixel;» » /* remembers 8- or 24-bit format */ 68 int bits_per_pixel; /* remembers 8- or 24-bit format */
67 } bmp_source_struct; 69 } bmp_source_struct;
68 70
69 71
70 LOCAL(int) 72 LOCAL(int)
71 read_byte (bmp_source_ptr sinfo) 73 read_byte (bmp_source_ptr sinfo)
72 /* Read next byte from BMP file */ 74 /* Read next byte from BMP file */
73 { 75 {
74 register FILE *infile = sinfo->pub.input_file; 76 register FILE *infile = sinfo->pub.input_file;
75 register int c; 77 register int c;
76 78
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 source->source_row--; 135 source->source_row--;
134 image_ptr = (*cinfo->mem->access_virt_sarray) 136 image_ptr = (*cinfo->mem->access_virt_sarray)
135 ((j_common_ptr) cinfo, source->whole_image, 137 ((j_common_ptr) cinfo, source->whole_image,
136 source->source_row, (JDIMENSION) 1, FALSE); 138 source->source_row, (JDIMENSION) 1, FALSE);
137 139
138 /* Expand the colormap indexes to real data */ 140 /* Expand the colormap indexes to real data */
139 inptr = image_ptr[0]; 141 inptr = image_ptr[0];
140 outptr = source->pub.buffer[0]; 142 outptr = source->pub.buffer[0];
141 for (col = cinfo->image_width; col > 0; col--) { 143 for (col = cinfo->image_width; col > 0; col--) {
142 t = GETJSAMPLE(*inptr++); 144 t = GETJSAMPLE(*inptr++);
143 *outptr++ = colormap[0][t];»/* can omit GETJSAMPLE() safely */ 145 *outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */
144 *outptr++ = colormap[1][t]; 146 *outptr++ = colormap[1][t];
145 *outptr++ = colormap[2][t]; 147 *outptr++ = colormap[2][t];
146 } 148 }
147 149
148 return 1; 150 return 1;
149 } 151 }
150 152
151 153
152 METHODDEF(JDIMENSION) 154 METHODDEF(JDIMENSION)
153 get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) 155 get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
154 /* This version is for reading 24-bit pixels */ 156 /* This version is for reading 24-bit pixels */
155 { 157 {
156 bmp_source_ptr source = (bmp_source_ptr) sinfo; 158 bmp_source_ptr source = (bmp_source_ptr) sinfo;
157 JSAMPARRAY image_ptr; 159 JSAMPARRAY image_ptr;
158 register JSAMPROW inptr, outptr; 160 register JSAMPROW inptr, outptr;
159 register JDIMENSION col; 161 register JDIMENSION col;
160 162
161 /* Fetch next row from virtual array */ 163 /* Fetch next row from virtual array */
162 source->source_row--; 164 source->source_row--;
163 image_ptr = (*cinfo->mem->access_virt_sarray) 165 image_ptr = (*cinfo->mem->access_virt_sarray)
164 ((j_common_ptr) cinfo, source->whole_image, 166 ((j_common_ptr) cinfo, source->whole_image,
165 source->source_row, (JDIMENSION) 1, FALSE); 167 source->source_row, (JDIMENSION) 1, FALSE);
166 168
167 /* Transfer data. Note source values are in BGR order 169 /* Transfer data. Note source values are in BGR order
168 * (even though Microsoft's own documents say the opposite). 170 * (even though Microsoft's own documents say the opposite).
169 */ 171 */
170 inptr = image_ptr[0]; 172 inptr = image_ptr[0];
171 outptr = source->pub.buffer[0]; 173 outptr = source->pub.buffer[0];
172 for (col = cinfo->image_width; col > 0; col--) { 174 for (col = cinfo->image_width; col > 0; col--) {
173 outptr[2] = *inptr++;» /* can omit GETJSAMPLE() safely */ 175 outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
174 outptr[1] = *inptr++; 176 outptr[1] = *inptr++;
175 outptr[0] = *inptr++; 177 outptr[0] = *inptr++;
176 outptr += 3; 178 outptr += 3;
177 } 179 }
178 180
179 return 1; 181 return 1;
180 } 182 }
181 183
182 184
183 METHODDEF(JDIMENSION) 185 METHODDEF(JDIMENSION)
184 get_32bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) 186 get_32bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
185 /* This version is for reading 32-bit pixels */ 187 /* This version is for reading 32-bit pixels */
186 { 188 {
187 bmp_source_ptr source = (bmp_source_ptr) sinfo; 189 bmp_source_ptr source = (bmp_source_ptr) sinfo;
188 JSAMPARRAY image_ptr; 190 JSAMPARRAY image_ptr;
189 register JSAMPROW inptr, outptr; 191 register JSAMPROW inptr, outptr;
190 register JDIMENSION col; 192 register JDIMENSION col;
191 193
192 /* Fetch next row from virtual array */ 194 /* Fetch next row from virtual array */
193 source->source_row--; 195 source->source_row--;
194 image_ptr = (*cinfo->mem->access_virt_sarray) 196 image_ptr = (*cinfo->mem->access_virt_sarray)
195 ((j_common_ptr) cinfo, source->whole_image, 197 ((j_common_ptr) cinfo, source->whole_image,
196 source->source_row, (JDIMENSION) 1, FALSE); 198 source->source_row, (JDIMENSION) 1, FALSE);
197 /* Transfer data. Note source values are in BGR order 199 /* Transfer data. Note source values are in BGR order
198 * (even though Microsoft's own documents say the opposite). 200 * (even though Microsoft's own documents say the opposite).
199 */ 201 */
200 inptr = image_ptr[0]; 202 inptr = image_ptr[0];
201 outptr = source->pub.buffer[0]; 203 outptr = source->pub.buffer[0];
202 for (col = cinfo->image_width; col > 0; col--) { 204 for (col = cinfo->image_width; col > 0; col--) {
203 outptr[2] = *inptr++;» /* can omit GETJSAMPLE() safely */ 205 outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */
204 outptr[1] = *inptr++; 206 outptr[1] = *inptr++;
205 outptr[0] = *inptr++; 207 outptr[0] = *inptr++;
206 inptr++;» » » /* skip the 4th byte (Alpha channel) */ 208 inptr++; /* skip the 4th byte (Alpha channel) */
207 outptr += 3; 209 outptr += 3;
208 } 210 }
209 211
210 return 1; 212 return 1;
211 } 213 }
212 214
213 215
214 /* 216 /*
215 * This method loads the image into whole_image during the first call on 217 * This method loads the image into whole_image during the first call on
216 * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call 218 * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 /* 274 /*
273 * Read the file header; return image size and component count. 275 * Read the file header; return image size and component count.
274 */ 276 */
275 277
276 METHODDEF(void) 278 METHODDEF(void)
277 start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) 279 start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
278 { 280 {
279 bmp_source_ptr source = (bmp_source_ptr) sinfo; 281 bmp_source_ptr source = (bmp_source_ptr) sinfo;
280 U_CHAR bmpfileheader[14]; 282 U_CHAR bmpfileheader[14];
281 U_CHAR bmpinfoheader[64]; 283 U_CHAR bmpinfoheader[64];
282 #define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \ 284 #define GET_2B(array,offset) ((unsigned short) UCH(array[offset]) + \
283 » » » (((unsigned int) UCH(array[offset+1])) << 8)) 285 (((unsigned short) UCH(array[offset+1])) << 8))
284 #define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \ 286 #define GET_4B(array,offset) ((unsigned int) UCH(array[offset]) + \
285 » » » (((INT32) UCH(array[offset+1])) << 8) + \ 287 (((unsigned int) UCH(array[offset+1])) << 8) + \
286 » » » (((INT32) UCH(array[offset+2])) << 16) + \ 288 (((unsigned int) UCH(array[offset+2])) << 16) + \
287 » » » (((INT32) UCH(array[offset+3])) << 24)) 289 (((unsigned int) UCH(array[offset+3])) << 24))
288 INT32 bfOffBits; 290 unsigned int bfOffBits;
289 INT32 headerSize; 291 unsigned int headerSize;
290 INT32 biWidth; 292 int biWidth;
291 INT32 biHeight; 293 int biHeight;
292 unsigned int biPlanes; 294 unsigned short biPlanes;
293 INT32 biCompression; 295 unsigned int biCompression;
294 INT32 biXPelsPerMeter,biYPelsPerMeter; 296 int biXPelsPerMeter,biYPelsPerMeter;
295 INT32 biClrUsed = 0; 297 unsigned int biClrUsed = 0;
296 int mapentrysize = 0;»» /* 0 indicates no colormap */ 298 int mapentrysize = 0; /* 0 indicates no colormap */
297 INT32 bPad; 299 int bPad;
298 JDIMENSION row_width; 300 JDIMENSION row_width;
299 301
300 /* Read and verify the bitmap file header */ 302 /* Read and verify the bitmap file header */
301 if (! ReadOK(source->pub.input_file, bmpfileheader, 14)) 303 if (! ReadOK(source->pub.input_file, bmpfileheader, 14))
302 ERREXIT(cinfo, JERR_INPUT_EOF); 304 ERREXIT(cinfo, JERR_INPUT_EOF);
303 if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */ 305 if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */
304 ERREXIT(cinfo, JERR_BMP_NOT); 306 ERREXIT(cinfo, JERR_BMP_NOT);
305 bfOffBits = (INT32) GET_4B(bmpfileheader,10); 307 bfOffBits = GET_4B(bmpfileheader,10);
306 /* We ignore the remaining fileheader fields */ 308 /* We ignore the remaining fileheader fields */
307 309
308 /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows), 310 /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows),
309 * or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which. 311 * or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which.
310 */ 312 */
311 if (! ReadOK(source->pub.input_file, bmpinfoheader, 4)) 313 if (! ReadOK(source->pub.input_file, bmpinfoheader, 4))
312 ERREXIT(cinfo, JERR_INPUT_EOF); 314 ERREXIT(cinfo, JERR_INPUT_EOF);
313 headerSize = (INT32) GET_4B(bmpinfoheader,0); 315 headerSize = GET_4B(bmpinfoheader,0);
314 if (headerSize < 12 || headerSize > 64) 316 if (headerSize < 12 || headerSize > 64)
315 ERREXIT(cinfo, JERR_BMP_BADHEADER); 317 ERREXIT(cinfo, JERR_BMP_BADHEADER);
316 if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4)) 318 if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4))
317 ERREXIT(cinfo, JERR_INPUT_EOF); 319 ERREXIT(cinfo, JERR_INPUT_EOF);
318 320
319 switch ((int) headerSize) { 321 switch (headerSize) {
320 case 12: 322 case 12:
321 /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */ 323 /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */
322 biWidth = (INT32) GET_2B(bmpinfoheader,4); 324 biWidth = (int) GET_2B(bmpinfoheader,4);
323 biHeight = (INT32) GET_2B(bmpinfoheader,6); 325 biHeight = (int) GET_2B(bmpinfoheader,6);
324 biPlanes = GET_2B(bmpinfoheader,8); 326 biPlanes = GET_2B(bmpinfoheader,8);
325 source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10); 327 source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10);
326 328
327 switch (source->bits_per_pixel) { 329 switch (source->bits_per_pixel) {
328 case 8:» » » /* colormapped image */ 330 case 8: /* colormapped image */
329 mapentrysize = 3;»» /* OS/2 uses RGBTRIPLE colormap */ 331 mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */
330 TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight); 332 TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, biWidth, biHeight);
331 break; 333 break;
332 case 24:» » » /* RGB image */ 334 case 24: /* RGB image */
333 TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight); 335 TRACEMS2(cinfo, 1, JTRC_BMP_OS2, biWidth, biHeight);
334 break; 336 break;
335 default: 337 default:
336 ERREXIT(cinfo, JERR_BMP_BADDEPTH); 338 ERREXIT(cinfo, JERR_BMP_BADDEPTH);
337 break; 339 break;
338 } 340 }
339 break; 341 break;
340 case 40: 342 case 40:
341 case 64: 343 case 64:
342 /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */ 344 /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */
343 /* or OS/2 2.x header, which has additional fields that we ignore */ 345 /* or OS/2 2.x header, which has additional fields that we ignore */
344 biWidth = GET_4B(bmpinfoheader,4); 346 biWidth = (int) GET_4B(bmpinfoheader,4);
345 biHeight = GET_4B(bmpinfoheader,8); 347 biHeight = (int) GET_4B(bmpinfoheader,8);
346 biPlanes = GET_2B(bmpinfoheader,12); 348 biPlanes = GET_2B(bmpinfoheader,12);
347 source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14); 349 source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14);
348 biCompression = GET_4B(bmpinfoheader,16); 350 biCompression = GET_4B(bmpinfoheader,16);
349 biXPelsPerMeter = GET_4B(bmpinfoheader,24); 351 biXPelsPerMeter = (int) GET_4B(bmpinfoheader,24);
350 biYPelsPerMeter = GET_4B(bmpinfoheader,28); 352 biYPelsPerMeter = (int) GET_4B(bmpinfoheader,28);
351 biClrUsed = GET_4B(bmpinfoheader,32); 353 biClrUsed = GET_4B(bmpinfoheader,32);
352 /* biSizeImage, biClrImportant fields are ignored */ 354 /* biSizeImage, biClrImportant fields are ignored */
353 355
354 switch (source->bits_per_pixel) { 356 switch (source->bits_per_pixel) {
355 case 8:» » » /* colormapped image */ 357 case 8: /* colormapped image */
356 mapentrysize = 4;»» /* Windows uses RGBQUAD colormap */ 358 mapentrysize = 4; /* Windows uses RGBQUAD colormap */
357 TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight); 359 TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, biWidth, biHeight);
358 break; 360 break;
359 case 24:» » » /* RGB image */ 361 case 24: /* RGB image */
360 TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); 362 TRACEMS2(cinfo, 1, JTRC_BMP, biWidth, biHeight);
361 break; 363 break;
362 case 32:» » » /* RGB image + Alpha channel */ 364 case 32: /* RGB image + Alpha channel */
363 TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); 365 TRACEMS2(cinfo, 1, JTRC_BMP, biWidth, biHeight);
364 break; 366 break;
365 default: 367 default:
366 ERREXIT(cinfo, JERR_BMP_BADDEPTH); 368 ERREXIT(cinfo, JERR_BMP_BADDEPTH);
367 break; 369 break;
368 } 370 }
369 if (biCompression != 0) 371 if (biCompression != 0)
370 ERREXIT(cinfo, JERR_BMP_COMPRESSED); 372 ERREXIT(cinfo, JERR_BMP_COMPRESSED);
371 373
372 if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) { 374 if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) {
373 /* Set JFIF density parameters from the BMP data */ 375 /* Set JFIF density parameters from the BMP data */
374 cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */ 376 cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */
375 cinfo->Y_density = (UINT16) (biYPelsPerMeter/100); 377 cinfo->Y_density = (UINT16) (biYPelsPerMeter/100);
376 cinfo->density_unit = 2;» /* dots/cm */ 378 cinfo->density_unit = 2; /* dots/cm */
377 } 379 }
378 break; 380 break;
379 default: 381 default:
380 ERREXIT(cinfo, JERR_BMP_BADHEADER); 382 ERREXIT(cinfo, JERR_BMP_BADHEADER);
381 return; 383 return;
382 } 384 }
383 385
384 if (biWidth <= 0 || biHeight <= 0) 386 if (biWidth <= 0 || biHeight <= 0)
385 ERREXIT(cinfo, JERR_BMP_EMPTY); 387 ERREXIT(cinfo, JERR_BMP_EMPTY);
386 if (biPlanes != 1) 388 if (biPlanes != 1)
387 ERREXIT(cinfo, JERR_BMP_BADPLANES); 389 ERREXIT(cinfo, JERR_BMP_BADPLANES);
388 390
389 /* Compute distance to bitmap data --- will adjust for colormap below */ 391 /* Compute distance to bitmap data --- will adjust for colormap below */
390 bPad = bfOffBits - (headerSize + 14); 392 bPad = bfOffBits - (headerSize + 14);
391 393
392 /* Read the colormap, if any */ 394 /* Read the colormap, if any */
393 if (mapentrysize > 0) { 395 if (mapentrysize > 0) {
394 if (biClrUsed <= 0) 396 if (biClrUsed <= 0)
395 biClrUsed = 256;» » /* assume it's 256 */ 397 biClrUsed = 256; /* assume it's 256 */
396 else if (biClrUsed > 256) 398 else if (biClrUsed > 256)
397 ERREXIT(cinfo, JERR_BMP_BADCMAP); 399 ERREXIT(cinfo, JERR_BMP_BADCMAP);
398 /* Allocate space to store the colormap */ 400 /* Allocate space to store the colormap */
399 source->colormap = (*cinfo->mem->alloc_sarray) 401 source->colormap = (*cinfo->mem->alloc_sarray)
400 ((j_common_ptr) cinfo, JPOOL_IMAGE, 402 ((j_common_ptr) cinfo, JPOOL_IMAGE,
401 (JDIMENSION) biClrUsed, (JDIMENSION) 3); 403 (JDIMENSION) biClrUsed, (JDIMENSION) 3);
402 /* and read it from the file */ 404 /* and read it from the file */
403 read_colormap(source, (int) biClrUsed, mapentrysize); 405 read_colormap(source, (int) biClrUsed, mapentrysize);
404 /* account for size of colormap */ 406 /* account for size of colormap */
405 bPad -= biClrUsed * mapentrysize; 407 bPad -= biClrUsed * mapentrysize;
406 } 408 }
407 409
408 /* Skip any remaining pad bytes */ 410 /* Skip any remaining pad bytes */
409 if (bPad < 0)»» » /* incorrect bfOffBits value? */ 411 if (bPad < 0) /* incorrect bfOffBits value? */
410 ERREXIT(cinfo, JERR_BMP_BADHEADER); 412 ERREXIT(cinfo, JERR_BMP_BADHEADER);
411 while (--bPad >= 0) { 413 while (--bPad >= 0) {
412 (void) read_byte(source); 414 (void) read_byte(source);
413 } 415 }
414 416
415 /* Compute row width in file, including padding to 4-byte boundary */ 417 /* Compute row width in file, including padding to 4-byte boundary */
416 if (source->bits_per_pixel == 24) 418 if (source->bits_per_pixel == 24)
417 row_width = (JDIMENSION) (biWidth * 3); 419 row_width = (JDIMENSION) (biWidth * 3);
418 else if (source->bits_per_pixel == 32) 420 else if (source->bits_per_pixel == 32)
419 row_width = (JDIMENSION) (biWidth * 4); 421 row_width = (JDIMENSION) (biWidth * 4);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 */ 464 */
463 465
464 GLOBAL(cjpeg_source_ptr) 466 GLOBAL(cjpeg_source_ptr)
465 jinit_read_bmp (j_compress_ptr cinfo) 467 jinit_read_bmp (j_compress_ptr cinfo)
466 { 468 {
467 bmp_source_ptr source; 469 bmp_source_ptr source;
468 470
469 /* Create module interface object */ 471 /* Create module interface object */
470 source = (bmp_source_ptr) 472 source = (bmp_source_ptr)
471 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 473 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
472 » » » » SIZEOF(bmp_source_struct)); 474 sizeof(bmp_source_struct));
473 source->cinfo = cinfo;» /* make back link for subroutines */ 475 source->cinfo = cinfo; /* make back link for subroutines */
474 /* Fill in method ptrs, except get_pixel_rows which start_input sets */ 476 /* Fill in method ptrs, except get_pixel_rows which start_input sets */
475 source->pub.start_input = start_input_bmp; 477 source->pub.start_input = start_input_bmp;
476 source->pub.finish_input = finish_input_bmp; 478 source->pub.finish_input = finish_input_bmp;
477 479
478 return (cjpeg_source_ptr) source; 480 return (cjpeg_source_ptr) source;
479 } 481 }
480 482
481 #endif /* BMP_SUPPORTED */ 483 #endif /* BMP_SUPPORTED */
OLDNEW
« no previous file with comments | « mac/jsimdcfg.inc ('k') | rdcolmap.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698