OLD | NEW |
1 /* | 1 /* |
2 * rdtarga.c | 2 * rdtarga.c |
3 * | 3 * |
| 4 * This file was part of the Independent JPEG Group's software: |
4 * Copyright (C) 1991-1996, Thomas G. Lane. | 5 * Copyright (C) 1991-1996, Thomas G. Lane. |
5 * This file is part of the Independent JPEG Group's software. | 6 * It was modified by The libjpeg-turbo Project to include only code relevant |
6 * For conditions of distribution and use, see the accompanying README file. | 7 * to libjpeg-turbo. |
| 8 * For conditions of distribution and use, see the accompanying README.ijg |
| 9 * file. |
7 * | 10 * |
8 * This file contains routines to read input images in Targa format. | 11 * This file contains routines to read input images in Targa format. |
9 * | 12 * |
10 * These routines may need modification for non-Unix environments or | 13 * These routines may need modification for non-Unix environments or |
11 * specialized applications. As they stand, they assume input from | 14 * specialized applications. As they stand, they assume input from |
12 * an ordinary stdio stream. They further assume that reading begins | 15 * an ordinary stdio stream. They further assume that reading begins |
13 * at the start of the file; start_input may need work if the | 16 * at the start of the file; start_input may need work if the |
14 * user interface has already read some data (e.g., to determine that | 17 * user interface has already read some data (e.g., to determine that |
15 * the file is indeed Targa format). | 18 * the file is indeed Targa format). |
16 * | 19 * |
17 * Based on code contributed by Lee Daniel Crocker. | 20 * Based on code contributed by Lee Daniel Crocker. |
18 */ | 21 */ |
19 | 22 |
20 #include "cdjpeg.h"» » /* Common decls for cjpeg/djpeg applications */ | 23 #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ |
21 | 24 |
22 #ifdef TARGA_SUPPORTED | 25 #ifdef TARGA_SUPPORTED |
23 | 26 |
24 | 27 |
25 /* Macros to deal with unsigned chars as efficiently as compiler allows */ | 28 /* Macros to deal with unsigned chars as efficiently as compiler allows */ |
26 | 29 |
27 #ifdef HAVE_UNSIGNED_CHAR | 30 #ifdef HAVE_UNSIGNED_CHAR |
28 typedef unsigned char U_CHAR; | 31 typedef unsigned char U_CHAR; |
29 #define UCH(x)» ((int) (x)) | 32 #define UCH(x) ((int) (x)) |
30 #else /* !HAVE_UNSIGNED_CHAR */ | 33 #else /* !HAVE_UNSIGNED_CHAR */ |
31 #ifdef CHAR_IS_UNSIGNED | 34 #ifdef __CHAR_UNSIGNED__ |
32 typedef char U_CHAR; | 35 typedef char U_CHAR; |
33 #define UCH(x)» ((int) (x)) | 36 #define UCH(x) ((int) (x)) |
34 #else | 37 #else |
35 typedef char U_CHAR; | 38 typedef char U_CHAR; |
36 #define UCH(x)» ((int) (x) & 0xFF) | 39 #define UCH(x) ((int) (x) & 0xFF) |
37 #endif | 40 #endif |
38 #endif /* HAVE_UNSIGNED_CHAR */ | 41 #endif /* HAVE_UNSIGNED_CHAR */ |
39 | 42 |
40 | 43 |
41 #define»ReadOK(file,buffer,len)»(JFREAD(file,buffer,len) == ((size_t) (len))) | 44 #define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) |
42 | 45 |
43 | 46 |
44 /* Private version of data source object */ | 47 /* Private version of data source object */ |
45 | 48 |
46 typedef struct _tga_source_struct * tga_source_ptr; | 49 typedef struct _tga_source_struct *tga_source_ptr; |
47 | 50 |
48 typedef struct _tga_source_struct { | 51 typedef struct _tga_source_struct { |
49 struct cjpeg_source_struct pub; /* public fields */ | 52 struct cjpeg_source_struct pub; /* public fields */ |
50 | 53 |
51 j_compress_ptr cinfo;»» /* back link saves passing separate parm */ | 54 j_compress_ptr cinfo; /* back link saves passing separate parm */ |
52 | 55 |
53 JSAMPARRAY colormap;» » /* Targa colormap (converted to my format) */ | 56 JSAMPARRAY colormap; /* Targa colormap (converted to my format) */ |
54 | 57 |
55 jvirt_sarray_ptr whole_image;»/* Needed if funny input row order */ | 58 jvirt_sarray_ptr whole_image; /* Needed if funny input row order */ |
56 JDIMENSION current_row;» /* Current logical row number to read */ | 59 JDIMENSION current_row; /* Current logical row number to read */ |
57 | 60 |
58 /* Pointer to routine to extract next Targa pixel from input file */ | 61 /* Pointer to routine to extract next Targa pixel from input file */ |
59 JMETHOD(void, read_pixel, (tga_source_ptr sinfo)); | 62 void (*read_pixel) (tga_source_ptr sinfo); |
60 | 63 |
61 /* Result of read_pixel is delivered here: */ | 64 /* Result of read_pixel is delivered here: */ |
62 U_CHAR tga_pixel[4]; | 65 U_CHAR tga_pixel[4]; |
63 | 66 |
64 int pixel_size;» » /* Bytes per Targa pixel (1 to 4) */ | 67 int pixel_size; /* Bytes per Targa pixel (1 to 4) */ |
65 | 68 |
66 /* State info for reading RLE-coded pixels; both counts must be init to 0 */ | 69 /* State info for reading RLE-coded pixels; both counts must be init to 0 */ |
67 int block_count;» » /* # of pixels remaining in RLE block */ | 70 int block_count; /* # of pixels remaining in RLE block */ |
68 int dup_pixel_count;» » /* # of times to duplicate previous pixel */ | 71 int dup_pixel_count; /* # of times to duplicate previous pixel */ |
69 | 72 |
70 /* This saves the correct pixel-row-expansion method for preload_image */ | 73 /* This saves the correct pixel-row-expansion method for preload_image */ |
71 JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, | 74 JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo); |
72 » » » » cjpeg_source_ptr sinfo)); | |
73 } tga_source_struct; | 75 } tga_source_struct; |
74 | 76 |
75 | 77 |
76 /* For expanding 5-bit pixel values to 8-bit with best rounding */ | 78 /* For expanding 5-bit pixel values to 8-bit with best rounding */ |
77 | 79 |
78 static const UINT8 c5to8bits[32] = { | 80 static const UINT8 c5to8bits[32] = { |
79 0, 8, 16, 25, 33, 41, 49, 58, | 81 0, 8, 16, 25, 33, 41, 49, 58, |
80 66, 74, 82, 90, 99, 107, 115, 123, | 82 66, 74, 82, 90, 99, 107, 115, 123, |
81 132, 140, 148, 156, 165, 173, 181, 189, | 83 132, 140, 148, 156, 165, 173, 181, 189, |
82 197, 206, 214, 222, 230, 239, 247, 255 | 84 197, 206, 214, 222, 230, 239, 247, 255 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 143 |
142 /* Duplicate previously read pixel? */ | 144 /* Duplicate previously read pixel? */ |
143 if (sinfo->dup_pixel_count > 0) { | 145 if (sinfo->dup_pixel_count > 0) { |
144 sinfo->dup_pixel_count--; | 146 sinfo->dup_pixel_count--; |
145 return; | 147 return; |
146 } | 148 } |
147 | 149 |
148 /* Time to read RLE block header? */ | 150 /* Time to read RLE block header? */ |
149 if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */ | 151 if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */ |
150 i = read_byte(sinfo); | 152 i = read_byte(sinfo); |
151 if (i & 0x80) {» » /* Start of duplicate-pixel block? */ | 153 if (i & 0x80) { /* Start of duplicate-pixel block? */ |
152 sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */ | 154 sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */ |
153 sinfo->block_count = 0;» /* then read new block header */ | 155 sinfo->block_count = 0; /* then read new block header */ |
154 } else { | 156 } else { |
155 sinfo->block_count = i & 0x7F; /* number of pixels after this one */ | 157 sinfo->block_count = i & 0x7F; /* number of pixels after this one */ |
156 } | 158 } |
157 } | 159 } |
158 | 160 |
159 /* Read next pixel */ | 161 /* Read next pixel */ |
160 for (i = 0; i < sinfo->pixel_size; i++) { | 162 for (i = 0; i < sinfo->pixel_size; i++) { |
161 sinfo->tga_pixel[i] = (U_CHAR) getc(infile); | 163 sinfo->tga_pixel[i] = (U_CHAR) getc(infile); |
162 } | 164 } |
163 } | 165 } |
164 | 166 |
165 | 167 |
166 /* | 168 /* |
167 * Read one row of pixels. | 169 * Read one row of pixels. |
168 * | 170 * |
169 * We provide several different versions depending on input file format. | 171 * We provide several different versions depending on input file format. |
170 */ | 172 */ |
171 | 173 |
172 | 174 |
173 METHODDEF(JDIMENSION) | 175 METHODDEF(JDIMENSION) |
174 get_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) | 176 get_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
175 /* This version is for reading 8-bit grayscale pixels */ | 177 /* This version is for reading 8-bit grayscale pixels */ |
176 { | 178 { |
177 tga_source_ptr source = (tga_source_ptr) sinfo; | 179 tga_source_ptr source = (tga_source_ptr) sinfo; |
178 register JSAMPROW ptr; | 180 register JSAMPROW ptr; |
179 register JDIMENSION col; | 181 register JDIMENSION col; |
180 | 182 |
181 ptr = source->pub.buffer[0]; | 183 ptr = source->pub.buffer[0]; |
182 for (col = cinfo->image_width; col > 0; col--) { | 184 for (col = cinfo->image_width; col > 0; col--) { |
183 (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ | 185 (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ |
184 *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); | 186 *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); |
185 } | 187 } |
186 return 1; | 188 return 1; |
187 } | 189 } |
188 | 190 |
189 METHODDEF(JDIMENSION) | 191 METHODDEF(JDIMENSION) |
190 get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) | 192 get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
(...skipping 17 matching lines...) Expand all Loading... |
208 } | 210 } |
209 | 211 |
210 METHODDEF(JDIMENSION) | 212 METHODDEF(JDIMENSION) |
211 get_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) | 213 get_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
212 /* This version is for reading 16-bit pixels */ | 214 /* This version is for reading 16-bit pixels */ |
213 { | 215 { |
214 tga_source_ptr source = (tga_source_ptr) sinfo; | 216 tga_source_ptr source = (tga_source_ptr) sinfo; |
215 register int t; | 217 register int t; |
216 register JSAMPROW ptr; | 218 register JSAMPROW ptr; |
217 register JDIMENSION col; | 219 register JDIMENSION col; |
218 | 220 |
219 ptr = source->pub.buffer[0]; | 221 ptr = source->pub.buffer[0]; |
220 for (col = cinfo->image_width; col > 0; col--) { | 222 for (col = cinfo->image_width; col > 0; col--) { |
221 (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ | 223 (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ |
222 t = UCH(source->tga_pixel[0]); | 224 t = UCH(source->tga_pixel[0]); |
223 t += UCH(source->tga_pixel[1]) << 8; | 225 t += UCH(source->tga_pixel[1]) << 8; |
224 /* We expand 5 bit data to 8 bit sample width. | 226 /* We expand 5 bit data to 8 bit sample width. |
225 * The format of the 16-bit (LSB first) input word is | 227 * The format of the 16-bit (LSB first) input word is |
226 * xRRRRRGGGGGBBBBB | 228 * xRRRRRGGGGGBBBBB |
227 */ | 229 */ |
228 ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F]; | 230 ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F]; |
229 t >>= 5; | 231 t >>= 5; |
230 ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F]; | 232 ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F]; |
231 t >>= 5; | 233 t >>= 5; |
232 ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F]; | 234 ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F]; |
233 ptr += 3; | 235 ptr += 3; |
234 } | 236 } |
235 return 1; | 237 return 1; |
236 } | 238 } |
237 | 239 |
238 METHODDEF(JDIMENSION) | 240 METHODDEF(JDIMENSION) |
239 get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) | 241 get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
240 /* This version is for reading 24-bit pixels */ | 242 /* This version is for reading 24-bit pixels */ |
241 { | 243 { |
242 tga_source_ptr source = (tga_source_ptr) sinfo; | 244 tga_source_ptr source = (tga_source_ptr) sinfo; |
243 register JSAMPROW ptr; | 245 register JSAMPROW ptr; |
244 register JDIMENSION col; | 246 register JDIMENSION col; |
245 | 247 |
246 ptr = source->pub.buffer[0]; | 248 ptr = source->pub.buffer[0]; |
247 for (col = cinfo->image_width; col > 0; col--) { | 249 for (col = cinfo->image_width; col > 0; col--) { |
248 (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ | 250 (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ |
249 *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */ | 251 *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */ |
250 *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]); | 252 *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]); |
251 *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); | 253 *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); |
252 } | 254 } |
253 return 1; | 255 return 1; |
254 } | 256 } |
255 | 257 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 333 |
332 METHODDEF(void) | 334 METHODDEF(void) |
333 start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) | 335 start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) |
334 { | 336 { |
335 tga_source_ptr source = (tga_source_ptr) sinfo; | 337 tga_source_ptr source = (tga_source_ptr) sinfo; |
336 U_CHAR targaheader[18]; | 338 U_CHAR targaheader[18]; |
337 int idlen, cmaptype, subtype, flags, interlace_type, components; | 339 int idlen, cmaptype, subtype, flags, interlace_type, components; |
338 unsigned int width, height, maplen; | 340 unsigned int width, height, maplen; |
339 boolean is_bottom_up; | 341 boolean is_bottom_up; |
340 | 342 |
341 #define GET_2B(offset)» ((unsigned int) UCH(targaheader[offset]) + \ | 343 #define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \ |
342 » » » (((unsigned int) UCH(targaheader[offset+1])) << 8)) | 344 (((unsigned int) UCH(targaheader[offset+1])) << 8)) |
343 | 345 |
344 if (! ReadOK(source->pub.input_file, targaheader, 18)) | 346 if (! ReadOK(source->pub.input_file, targaheader, 18)) |
345 ERREXIT(cinfo, JERR_INPUT_EOF); | 347 ERREXIT(cinfo, JERR_INPUT_EOF); |
346 | 348 |
347 /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */ | 349 /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */ |
348 if (targaheader[16] == 15) | 350 if (targaheader[16] == 15) |
349 targaheader[16] = 16; | 351 targaheader[16] = 16; |
350 | 352 |
351 idlen = UCH(targaheader[0]); | 353 idlen = UCH(targaheader[0]); |
352 cmaptype = UCH(targaheader[1]); | 354 cmaptype = UCH(targaheader[1]); |
353 subtype = UCH(targaheader[2]); | 355 subtype = UCH(targaheader[2]); |
354 maplen = GET_2B(5); | 356 maplen = GET_2B(5); |
355 width = GET_2B(12); | 357 width = GET_2B(12); |
356 height = GET_2B(14); | 358 height = GET_2B(14); |
357 source->pixel_size = UCH(targaheader[16]) >> 3; | 359 source->pixel_size = UCH(targaheader[16]) >> 3; |
358 flags = UCH(targaheader[17]);»/* Image Descriptor byte */ | 360 flags = UCH(targaheader[17]); /* Image Descriptor byte */ |
359 | 361 |
360 is_bottom_up = ((flags & 0x20) == 0);»/* bit 5 set => top-down */ | 362 is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */ |
361 interlace_type = flags >> 6;» /* bits 6/7 are interlace code */ | 363 interlace_type = flags >> 6; /* bits 6/7 are interlace code */ |
362 | 364 |
363 if (cmaptype > 1 ||» » /* cmaptype must be 0 or 1 */ | 365 if (cmaptype > 1 || /* cmaptype must be 0 or 1 */ |
364 source->pixel_size < 1 || source->pixel_size > 4 || | 366 source->pixel_size < 1 || source->pixel_size > 4 || |
365 (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */ | 367 (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */ |
366 interlace_type != 0)» /* currently don't allow interlaced image */ | 368 interlace_type != 0 || /* currently don't allow interlaced image */ |
| 369 width == 0 || height == 0) /* image width/height must be non-zero */ |
367 ERREXIT(cinfo, JERR_TGA_BADPARMS); | 370 ERREXIT(cinfo, JERR_TGA_BADPARMS); |
368 | 371 |
369 if (subtype > 8) { | 372 if (subtype > 8) { |
370 /* It's an RLE-coded file */ | 373 /* It's an RLE-coded file */ |
371 source->read_pixel = read_rle_pixel; | 374 source->read_pixel = read_rle_pixel; |
372 source->block_count = source->dup_pixel_count = 0; | 375 source->block_count = source->dup_pixel_count = 0; |
373 subtype -= 8; | 376 subtype -= 8; |
374 } else { | 377 } else { |
375 /* Non-RLE file */ | 378 /* Non-RLE file */ |
376 source->read_pixel = read_non_rle_pixel; | 379 source->read_pixel = read_non_rle_pixel; |
377 } | 380 } |
378 | 381 |
379 /* Now should have subtype 1, 2, or 3 */ | 382 /* Now should have subtype 1, 2, or 3 */ |
380 components = 3;» » /* until proven different */ | 383 components = 3; /* until proven different */ |
381 cinfo->in_color_space = JCS_RGB; | 384 cinfo->in_color_space = JCS_RGB; |
382 | 385 |
383 switch (subtype) { | 386 switch (subtype) { |
384 case 1:» » » /* Colormapped image */ | 387 case 1: /* Colormapped image */ |
385 if (source->pixel_size == 1 && cmaptype == 1) | 388 if (source->pixel_size == 1 && cmaptype == 1) |
386 source->get_pixel_rows = get_8bit_row; | 389 source->get_pixel_rows = get_8bit_row; |
387 else | 390 else |
388 ERREXIT(cinfo, JERR_TGA_BADPARMS); | 391 ERREXIT(cinfo, JERR_TGA_BADPARMS); |
389 TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height); | 392 TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height); |
390 break; | 393 break; |
391 case 2:» » » /* RGB image */ | 394 case 2: /* RGB image */ |
392 switch (source->pixel_size) { | 395 switch (source->pixel_size) { |
393 case 2: | 396 case 2: |
394 source->get_pixel_rows = get_16bit_row; | 397 source->get_pixel_rows = get_16bit_row; |
395 break; | 398 break; |
396 case 3: | 399 case 3: |
397 source->get_pixel_rows = get_24bit_row; | 400 source->get_pixel_rows = get_24bit_row; |
398 break; | 401 break; |
399 case 4: | 402 case 4: |
400 source->get_pixel_rows = get_32bit_row; | 403 source->get_pixel_rows = get_32bit_row; |
401 break; | 404 break; |
402 default: | 405 default: |
403 ERREXIT(cinfo, JERR_TGA_BADPARMS); | 406 ERREXIT(cinfo, JERR_TGA_BADPARMS); |
404 break; | 407 break; |
405 } | 408 } |
406 TRACEMS2(cinfo, 1, JTRC_TGA, width, height); | 409 TRACEMS2(cinfo, 1, JTRC_TGA, width, height); |
407 break; | 410 break; |
408 case 3:» » » /* Grayscale image */ | 411 case 3: /* Grayscale image */ |
409 components = 1; | 412 components = 1; |
410 cinfo->in_color_space = JCS_GRAYSCALE; | 413 cinfo->in_color_space = JCS_GRAYSCALE; |
411 if (source->pixel_size == 1) | 414 if (source->pixel_size == 1) |
412 source->get_pixel_rows = get_8bit_gray_row; | 415 source->get_pixel_rows = get_8bit_gray_row; |
413 else | 416 else |
414 ERREXIT(cinfo, JERR_TGA_BADPARMS); | 417 ERREXIT(cinfo, JERR_TGA_BADPARMS); |
415 TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height); | 418 TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height); |
416 break; | 419 break; |
417 default: | 420 default: |
418 ERREXIT(cinfo, JERR_TGA_BADPARMS); | 421 ERREXIT(cinfo, JERR_TGA_BADPARMS); |
(...skipping 14 matching lines...) Expand all Loading... |
433 source->pub.get_pixel_rows = preload_image; | 436 source->pub.get_pixel_rows = preload_image; |
434 } else { | 437 } else { |
435 /* Don't need a virtual array, but do need a one-row input buffer. */ | 438 /* Don't need a virtual array, but do need a one-row input buffer. */ |
436 source->whole_image = NULL; | 439 source->whole_image = NULL; |
437 source->pub.buffer = (*cinfo->mem->alloc_sarray) | 440 source->pub.buffer = (*cinfo->mem->alloc_sarray) |
438 ((j_common_ptr) cinfo, JPOOL_IMAGE, | 441 ((j_common_ptr) cinfo, JPOOL_IMAGE, |
439 (JDIMENSION) width * components, (JDIMENSION) 1); | 442 (JDIMENSION) width * components, (JDIMENSION) 1); |
440 source->pub.buffer_height = 1; | 443 source->pub.buffer_height = 1; |
441 source->pub.get_pixel_rows = source->get_pixel_rows; | 444 source->pub.get_pixel_rows = source->get_pixel_rows; |
442 } | 445 } |
443 | 446 |
444 while (idlen--)» » /* Throw away ID field */ | 447 while (idlen--) /* Throw away ID field */ |
445 (void) read_byte(source); | 448 (void) read_byte(source); |
446 | 449 |
447 if (maplen > 0) { | 450 if (maplen > 0) { |
448 if (maplen > 256 || GET_2B(3) != 0) | 451 if (maplen > 256 || GET_2B(3) != 0) |
449 ERREXIT(cinfo, JERR_TGA_BADCMAP); | 452 ERREXIT(cinfo, JERR_TGA_BADCMAP); |
450 /* Allocate space to store the colormap */ | 453 /* Allocate space to store the colormap */ |
451 source->colormap = (*cinfo->mem->alloc_sarray) | 454 source->colormap = (*cinfo->mem->alloc_sarray) |
452 ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3); | 455 ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3); |
453 /* and read it from the file */ | 456 /* and read it from the file */ |
454 read_colormap(source, (int) maplen, UCH(targaheader[7])); | 457 read_colormap(source, (int) maplen, UCH(targaheader[7])); |
455 } else { | 458 } else { |
456 if (cmaptype)» » /* but you promised a cmap! */ | 459 if (cmaptype) /* but you promised a cmap! */ |
457 ERREXIT(cinfo, JERR_TGA_BADPARMS); | 460 ERREXIT(cinfo, JERR_TGA_BADPARMS); |
458 source->colormap = NULL; | 461 source->colormap = NULL; |
459 } | 462 } |
460 | 463 |
461 cinfo->input_components = components; | 464 cinfo->input_components = components; |
462 cinfo->data_precision = 8; | 465 cinfo->data_precision = 8; |
463 cinfo->image_width = width; | 466 cinfo->image_width = width; |
464 cinfo->image_height = height; | 467 cinfo->image_height = height; |
465 } | 468 } |
466 | 469 |
(...skipping 14 matching lines...) Expand all Loading... |
481 */ | 484 */ |
482 | 485 |
483 GLOBAL(cjpeg_source_ptr) | 486 GLOBAL(cjpeg_source_ptr) |
484 jinit_read_targa (j_compress_ptr cinfo) | 487 jinit_read_targa (j_compress_ptr cinfo) |
485 { | 488 { |
486 tga_source_ptr source; | 489 tga_source_ptr source; |
487 | 490 |
488 /* Create module interface object */ | 491 /* Create module interface object */ |
489 source = (tga_source_ptr) | 492 source = (tga_source_ptr) |
490 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 493 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
491 » » » » SIZEOF(tga_source_struct)); | 494 sizeof(tga_source_struct)); |
492 source->cinfo = cinfo;» /* make back link for subroutines */ | 495 source->cinfo = cinfo; /* make back link for subroutines */ |
493 /* Fill in method ptrs, except get_pixel_rows which start_input sets */ | 496 /* Fill in method ptrs, except get_pixel_rows which start_input sets */ |
494 source->pub.start_input = start_input_tga; | 497 source->pub.start_input = start_input_tga; |
495 source->pub.finish_input = finish_input_tga; | 498 source->pub.finish_input = finish_input_tga; |
496 | 499 |
497 return (cjpeg_source_ptr) source; | 500 return (cjpeg_source_ptr) source; |
498 } | 501 } |
499 | 502 |
500 #endif /* TARGA_SUPPORTED */ | 503 #endif /* TARGA_SUPPORTED */ |
OLD | NEW |