| OLD | NEW |
| 1 /* | 1 /* |
| 2 * jdapimin.c | 2 * jdapimin.c |
| 3 * | 3 * |
| 4 * This file was part of the Independent JPEG Group's software: |
| 4 * Copyright (C) 1994-1998, Thomas G. Lane. | 5 * Copyright (C) 1994-1998, Thomas G. Lane. |
| 5 * This file is part of the Independent JPEG Group's software. | 6 * libjpeg-turbo Modifications: |
| 6 * For conditions of distribution and use, see the accompanying README file. | 7 * Copyright (C) 2016, D. R. Commander. |
| 8 * For conditions of distribution and use, see the accompanying README.ijg |
| 9 * file. |
| 7 * | 10 * |
| 8 * This file contains application interface code for the decompression half | 11 * This file contains application interface code for the decompression half |
| 9 * of the JPEG library. These are the "minimum" API routines that may be | 12 * of the JPEG library. These are the "minimum" API routines that may be |
| 10 * needed in either the normal full-decompression case or the | 13 * needed in either the normal full-decompression case or the |
| 11 * transcoding-only case. | 14 * transcoding-only case. |
| 12 * | 15 * |
| 13 * Most of the routines intended to be called directly by an application | 16 * Most of the routines intended to be called directly by an application |
| 14 * are in this file or in jdapistd.c. But also see jcomapi.c for routines | 17 * are in this file or in jdapistd.c. But also see jcomapi.c for routines |
| 15 * shared by compression and decompression, and jdtrans.c for the transcoding | 18 * shared by compression and decompression, and jdtrans.c for the transcoding |
| 16 * case. | 19 * case. |
| 17 */ | 20 */ |
| 18 | 21 |
| 19 #define JPEG_INTERNALS | 22 #define JPEG_INTERNALS |
| 20 #include "jinclude.h" | 23 #include "jinclude.h" |
| 21 #include "jpeglib.h" | 24 #include "jpeglib.h" |
| 25 #include "jdmaster.h" |
| 22 | 26 |
| 23 | 27 |
| 24 /* | 28 /* |
| 25 * Initialization of a JPEG decompression object. | 29 * Initialization of a JPEG decompression object. |
| 26 * The error manager must already be set up (in case memory manager fails). | 30 * The error manager must already be set up (in case memory manager fails). |
| 27 */ | 31 */ |
| 28 | 32 |
| 29 GLOBAL(void) | 33 GLOBAL(void) |
| 30 jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) | 34 jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) |
| 31 { | 35 { |
| 32 int i; | 36 int i; |
| 33 | 37 |
| 34 /* Guard against version mismatches between library and caller. */ | 38 /* Guard against version mismatches between library and caller. */ |
| 35 cinfo->mem = NULL;» » /* so jpeg_destroy knows mem mgr not called */ | 39 cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ |
| 36 if (version != JPEG_LIB_VERSION) | 40 if (version != JPEG_LIB_VERSION) |
| 37 ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); | 41 ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); |
| 38 if (structsize != SIZEOF(struct jpeg_decompress_struct)) | 42 if (structsize != sizeof(struct jpeg_decompress_struct)) |
| 39 ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, | 43 ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, |
| 40 » (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize); | 44 (int) sizeof(struct jpeg_decompress_struct), (int) structsize); |
| 41 | 45 |
| 42 /* For debugging purposes, we zero the whole master structure. | 46 /* For debugging purposes, we zero the whole master structure. |
| 43 * But the application has already set the err pointer, and may have set | 47 * But the application has already set the err pointer, and may have set |
| 44 * client_data, so we have to save and restore those fields. | 48 * client_data, so we have to save and restore those fields. |
| 45 * Note: if application hasn't set client_data, tools like Purify may | 49 * Note: if application hasn't set client_data, tools like Purify may |
| 46 * complain here. | 50 * complain here. |
| 47 */ | 51 */ |
| 48 { | 52 { |
| 49 struct jpeg_error_mgr * err = cinfo->err; | 53 struct jpeg_error_mgr * err = cinfo->err; |
| 50 void * client_data = cinfo->client_data; /* ignore Purify complaint here */ | 54 void * client_data = cinfo->client_data; /* ignore Purify complaint here */ |
| 51 MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct)); | 55 MEMZERO(cinfo, sizeof(struct jpeg_decompress_struct)); |
| 52 cinfo->err = err; | 56 cinfo->err = err; |
| 53 cinfo->client_data = client_data; | 57 cinfo->client_data = client_data; |
| 54 } | 58 } |
| 55 cinfo->is_decompressor = TRUE; | 59 cinfo->is_decompressor = TRUE; |
| 56 | 60 |
| 57 /* Initialize a memory manager instance for this object */ | 61 /* Initialize a memory manager instance for this object */ |
| 58 jinit_memory_mgr((j_common_ptr) cinfo); | 62 jinit_memory_mgr((j_common_ptr) cinfo); |
| 59 | 63 |
| 60 /* Zero out pointers to permanent structures. */ | 64 /* Zero out pointers to permanent structures. */ |
| 61 cinfo->progress = NULL; | 65 cinfo->progress = NULL; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 73 * for COM, APPn markers before calling jpeg_read_header. | 77 * for COM, APPn markers before calling jpeg_read_header. |
| 74 */ | 78 */ |
| 75 cinfo->marker_list = NULL; | 79 cinfo->marker_list = NULL; |
| 76 jinit_marker_reader(cinfo); | 80 jinit_marker_reader(cinfo); |
| 77 | 81 |
| 78 /* And initialize the overall input controller. */ | 82 /* And initialize the overall input controller. */ |
| 79 jinit_input_controller(cinfo); | 83 jinit_input_controller(cinfo); |
| 80 | 84 |
| 81 /* OK, I'm ready */ | 85 /* OK, I'm ready */ |
| 82 cinfo->global_state = DSTATE_START; | 86 cinfo->global_state = DSTATE_START; |
| 87 |
| 88 /* The master struct is used to store extension parameters, so we allocate it |
| 89 * here. |
| 90 */ |
| 91 cinfo->master = (struct jpeg_decomp_master *) |
| 92 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, |
| 93 sizeof(my_decomp_master)); |
| 94 MEMZERO(cinfo->master, sizeof(my_decomp_master)); |
| 83 } | 95 } |
| 84 | 96 |
| 85 | 97 |
| 86 /* | 98 /* |
| 87 * Destruction of a JPEG decompression object | 99 * Destruction of a JPEG decompression object |
| 88 */ | 100 */ |
| 89 | 101 |
| 90 GLOBAL(void) | 102 GLOBAL(void) |
| 91 jpeg_destroy_decompress (j_decompress_ptr cinfo) | 103 jpeg_destroy_decompress (j_decompress_ptr cinfo) |
| 92 { | 104 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 114 default_decompress_parms (j_decompress_ptr cinfo) | 126 default_decompress_parms (j_decompress_ptr cinfo) |
| 115 { | 127 { |
| 116 /* Guess the input colorspace, and set output colorspace accordingly. */ | 128 /* Guess the input colorspace, and set output colorspace accordingly. */ |
| 117 /* (Wish JPEG committee had provided a real way to specify this...) */ | 129 /* (Wish JPEG committee had provided a real way to specify this...) */ |
| 118 /* Note application may override our guesses. */ | 130 /* Note application may override our guesses. */ |
| 119 switch (cinfo->num_components) { | 131 switch (cinfo->num_components) { |
| 120 case 1: | 132 case 1: |
| 121 cinfo->jpeg_color_space = JCS_GRAYSCALE; | 133 cinfo->jpeg_color_space = JCS_GRAYSCALE; |
| 122 cinfo->out_color_space = JCS_GRAYSCALE; | 134 cinfo->out_color_space = JCS_GRAYSCALE; |
| 123 break; | 135 break; |
| 124 | 136 |
| 125 case 3: | 137 case 3: |
| 126 if (cinfo->saw_JFIF_marker) { | 138 if (cinfo->saw_JFIF_marker) { |
| 127 cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ | 139 cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ |
| 128 } else if (cinfo->saw_Adobe_marker) { | 140 } else if (cinfo->saw_Adobe_marker) { |
| 129 switch (cinfo->Adobe_transform) { | 141 switch (cinfo->Adobe_transform) { |
| 130 case 0: | 142 case 0: |
| 131 » cinfo->jpeg_color_space = JCS_RGB; | 143 cinfo->jpeg_color_space = JCS_RGB; |
| 132 » break; | 144 break; |
| 133 case 1: | 145 case 1: |
| 134 » cinfo->jpeg_color_space = JCS_YCbCr; | 146 cinfo->jpeg_color_space = JCS_YCbCr; |
| 135 » break; | 147 break; |
| 136 default: | 148 default: |
| 137 » WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); | 149 WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); |
| 138 » cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ | 150 cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ |
| 139 » break; | 151 break; |
| 140 } | 152 } |
| 141 } else { | 153 } else { |
| 142 /* Saw no special markers, try to guess from the component IDs */ | 154 /* Saw no special markers, try to guess from the component IDs */ |
| 143 int cid0 = cinfo->comp_info[0].component_id; | 155 int cid0 = cinfo->comp_info[0].component_id; |
| 144 int cid1 = cinfo->comp_info[1].component_id; | 156 int cid1 = cinfo->comp_info[1].component_id; |
| 145 int cid2 = cinfo->comp_info[2].component_id; | 157 int cid2 = cinfo->comp_info[2].component_id; |
| 146 | 158 |
| 147 if (cid0 == 1 && cid1 == 2 && cid2 == 3) | 159 if (cid0 == 1 && cid1 == 2 && cid2 == 3) |
| 148 » cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ | 160 cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ |
| 149 else if (cid0 == 82 && cid1 == 71 && cid2 == 66) | 161 else if (cid0 == 82 && cid1 == 71 && cid2 == 66) |
| 150 » cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ | 162 cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ |
| 151 else { | 163 else { |
| 152 » TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); | 164 TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); |
| 153 » cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ | 165 cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ |
| 154 } | 166 } |
| 155 } | 167 } |
| 156 /* Always guess RGB is proper output colorspace. */ | 168 /* Always guess RGB is proper output colorspace. */ |
| 157 cinfo->out_color_space = JCS_RGB; | 169 cinfo->out_color_space = JCS_RGB; |
| 158 break; | 170 break; |
| 159 | 171 |
| 160 case 4: | 172 case 4: |
| 161 if (cinfo->saw_Adobe_marker) { | 173 if (cinfo->saw_Adobe_marker) { |
| 162 switch (cinfo->Adobe_transform) { | 174 switch (cinfo->Adobe_transform) { |
| 163 case 0: | 175 case 0: |
| 164 » cinfo->jpeg_color_space = JCS_CMYK; | 176 cinfo->jpeg_color_space = JCS_CMYK; |
| 165 » break; | 177 break; |
| 166 case 2: | 178 case 2: |
| 167 » cinfo->jpeg_color_space = JCS_YCCK; | 179 cinfo->jpeg_color_space = JCS_YCCK; |
| 168 » break; | 180 break; |
| 169 default: | 181 default: |
| 170 » WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); | 182 WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); |
| 171 » cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ | 183 cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ |
| 172 » break; | 184 break; |
| 173 } | 185 } |
| 174 } else { | 186 } else { |
| 175 /* No special markers, assume straight CMYK. */ | 187 /* No special markers, assume straight CMYK. */ |
| 176 cinfo->jpeg_color_space = JCS_CMYK; | 188 cinfo->jpeg_color_space = JCS_CMYK; |
| 177 } | 189 } |
| 178 cinfo->out_color_space = JCS_CMYK; | 190 cinfo->out_color_space = JCS_CMYK; |
| 179 break; | 191 break; |
| 180 | 192 |
| 181 default: | 193 default: |
| 182 cinfo->jpeg_color_space = JCS_UNKNOWN; | 194 cinfo->jpeg_color_space = JCS_UNKNOWN; |
| 183 cinfo->out_color_space = JCS_UNKNOWN; | 195 cinfo->out_color_space = JCS_UNKNOWN; |
| 184 break; | 196 break; |
| 185 } | 197 } |
| 186 | 198 |
| 187 /* Set defaults for other decompression parameters. */ | 199 /* Set defaults for other decompression parameters. */ |
| 188 cinfo->scale_num = 1;»» /* 1:1 scaling */ | 200 cinfo->scale_num = 1; /* 1:1 scaling */ |
| 189 cinfo->scale_denom = 1; | 201 cinfo->scale_denom = 1; |
| 190 cinfo->output_gamma = 1.0; | 202 cinfo->output_gamma = 1.0; |
| 191 cinfo->buffered_image = FALSE; | 203 cinfo->buffered_image = FALSE; |
| 192 cinfo->raw_data_out = FALSE; | 204 cinfo->raw_data_out = FALSE; |
| 193 cinfo->dct_method = JDCT_DEFAULT; | 205 cinfo->dct_method = JDCT_DEFAULT; |
| 194 cinfo->do_fancy_upsampling = TRUE; | 206 cinfo->do_fancy_upsampling = TRUE; |
| 195 cinfo->do_block_smoothing = TRUE; | 207 cinfo->do_block_smoothing = TRUE; |
| 196 cinfo->quantize_colors = FALSE; | 208 cinfo->quantize_colors = FALSE; |
| 197 /* We set these in case application only sets quantize_colors. */ | 209 /* We set these in case application only sets quantize_colors. */ |
| 198 cinfo->dither_mode = JDITHER_FS; | 210 cinfo->dither_mode = JDITHER_FS; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 cinfo->global_state != DSTATE_INHEADER) | 258 cinfo->global_state != DSTATE_INHEADER) |
| 247 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 259 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
| 248 | 260 |
| 249 retcode = jpeg_consume_input(cinfo); | 261 retcode = jpeg_consume_input(cinfo); |
| 250 | 262 |
| 251 switch (retcode) { | 263 switch (retcode) { |
| 252 case JPEG_REACHED_SOS: | 264 case JPEG_REACHED_SOS: |
| 253 retcode = JPEG_HEADER_OK; | 265 retcode = JPEG_HEADER_OK; |
| 254 break; | 266 break; |
| 255 case JPEG_REACHED_EOI: | 267 case JPEG_REACHED_EOI: |
| 256 if (require_image)» » /* Complain if application wanted an image */ | 268 if (require_image) /* Complain if application wanted an image */ |
| 257 ERREXIT(cinfo, JERR_NO_IMAGE); | 269 ERREXIT(cinfo, JERR_NO_IMAGE); |
| 258 /* Reset to start state; it would be safer to require the application to | 270 /* Reset to start state; it would be safer to require the application to |
| 259 * call jpeg_abort, but we can't change it now for compatibility reasons. | 271 * call jpeg_abort, but we can't change it now for compatibility reasons. |
| 260 * A side effect is to free any temporary memory (there shouldn't be any). | 272 * A side effect is to free any temporary memory (there shouldn't be any). |
| 261 */ | 273 */ |
| 262 jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */ | 274 jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */ |
| 263 retcode = JPEG_HEADER_TABLES_ONLY; | 275 retcode = JPEG_HEADER_TABLES_ONLY; |
| 264 break; | 276 break; |
| 265 case JPEG_SUSPENDED: | 277 case JPEG_SUSPENDED: |
| 266 /* no work */ | 278 /* no work */ |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } else if (cinfo->global_state == DSTATE_BUFIMAGE) { | 390 } else if (cinfo->global_state == DSTATE_BUFIMAGE) { |
| 379 /* Finishing after a buffered-image operation */ | 391 /* Finishing after a buffered-image operation */ |
| 380 cinfo->global_state = DSTATE_STOPPING; | 392 cinfo->global_state = DSTATE_STOPPING; |
| 381 } else if (cinfo->global_state != DSTATE_STOPPING) { | 393 } else if (cinfo->global_state != DSTATE_STOPPING) { |
| 382 /* STOPPING = repeat call after a suspension, anything else is error */ | 394 /* STOPPING = repeat call after a suspension, anything else is error */ |
| 383 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 395 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
| 384 } | 396 } |
| 385 /* Read until EOI */ | 397 /* Read until EOI */ |
| 386 while (! cinfo->inputctl->eoi_reached) { | 398 while (! cinfo->inputctl->eoi_reached) { |
| 387 if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) | 399 if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) |
| 388 return FALSE;» » /* Suspend, come back later */ | 400 return FALSE; /* Suspend, come back later */ |
| 389 } | 401 } |
| 390 /* Do final cleanup */ | 402 /* Do final cleanup */ |
| 391 (*cinfo->src->term_source) (cinfo); | 403 (*cinfo->src->term_source) (cinfo); |
| 392 /* We can use jpeg_abort to release memory and reset global_state */ | 404 /* We can use jpeg_abort to release memory and reset global_state */ |
| 393 jpeg_abort((j_common_ptr) cinfo); | 405 jpeg_abort((j_common_ptr) cinfo); |
| 394 return TRUE; | 406 return TRUE; |
| 395 } | 407 } |
| OLD | NEW |