dbf-halloween2015

annotate libs/libjpeg/jdapistd.c @ 4:4316c0c879e9

fixed RUN script for macosx
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 06:18:18 +0200
parents
children
rev   line source
nuclear@1 1 /*
nuclear@1 2 * jdapistd.c
nuclear@1 3 *
nuclear@1 4 * Copyright (C) 1994-1996, Thomas G. Lane.
nuclear@1 5 * This file is part of the Independent JPEG Group's software.
nuclear@1 6 * For conditions of distribution and use, see the accompanying README file.
nuclear@1 7 *
nuclear@1 8 * This file contains application interface code for the decompression half
nuclear@1 9 * of the JPEG library. These are the "standard" API routines that are
nuclear@1 10 * used in the normal full-decompression case. They are not used by a
nuclear@1 11 * transcoding-only application. Note that if an application links in
nuclear@1 12 * jpeg_start_decompress, it will end up linking in the entire decompressor.
nuclear@1 13 * We thus must separate this file from jdapimin.c to avoid linking the
nuclear@1 14 * whole decompression library into a transcoder.
nuclear@1 15 */
nuclear@1 16
nuclear@1 17 #define JPEG_INTERNALS
nuclear@1 18 #include "jinclude.h"
nuclear@1 19 #include "jpeglib.h"
nuclear@1 20
nuclear@1 21
nuclear@1 22 /* Forward declarations */
nuclear@1 23 LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
nuclear@1 24
nuclear@1 25
nuclear@1 26 /*
nuclear@1 27 * Decompression initialization.
nuclear@1 28 * jpeg_read_header must be completed before calling this.
nuclear@1 29 *
nuclear@1 30 * If a multipass operating mode was selected, this will do all but the
nuclear@1 31 * last pass, and thus may take a great deal of time.
nuclear@1 32 *
nuclear@1 33 * Returns FALSE if suspended. The return value need be inspected only if
nuclear@1 34 * a suspending data source is used.
nuclear@1 35 */
nuclear@1 36
nuclear@1 37 GLOBAL(boolean)
nuclear@1 38 jpeg_start_decompress (j_decompress_ptr cinfo)
nuclear@1 39 {
nuclear@1 40 if (cinfo->global_state == DSTATE_READY) {
nuclear@1 41 /* First call: initialize master control, select active modules */
nuclear@1 42 jinit_master_decompress(cinfo);
nuclear@1 43 if (cinfo->buffered_image) {
nuclear@1 44 /* No more work here; expecting jpeg_start_output next */
nuclear@1 45 cinfo->global_state = DSTATE_BUFIMAGE;
nuclear@1 46 return TRUE;
nuclear@1 47 }
nuclear@1 48 cinfo->global_state = DSTATE_PRELOAD;
nuclear@1 49 }
nuclear@1 50 if (cinfo->global_state == DSTATE_PRELOAD) {
nuclear@1 51 /* If file has multiple scans, absorb them all into the coef buffer */
nuclear@1 52 if (cinfo->inputctl->has_multiple_scans) {
nuclear@1 53 #ifdef D_MULTISCAN_FILES_SUPPORTED
nuclear@1 54 for (;;) {
nuclear@1 55 int retcode;
nuclear@1 56 /* Call progress monitor hook if present */
nuclear@1 57 if (cinfo->progress != NULL)
nuclear@1 58 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
nuclear@1 59 /* Absorb some more input */
nuclear@1 60 retcode = (*cinfo->inputctl->consume_input) (cinfo);
nuclear@1 61 if (retcode == JPEG_SUSPENDED)
nuclear@1 62 return FALSE;
nuclear@1 63 if (retcode == JPEG_REACHED_EOI)
nuclear@1 64 break;
nuclear@1 65 /* Advance progress counter if appropriate */
nuclear@1 66 if (cinfo->progress != NULL &&
nuclear@1 67 (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
nuclear@1 68 if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
nuclear@1 69 /* jdmaster underestimated number of scans; ratchet up one scan */
nuclear@1 70 cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
nuclear@1 71 }
nuclear@1 72 }
nuclear@1 73 }
nuclear@1 74 #else
nuclear@1 75 ERREXIT(cinfo, JERR_NOT_COMPILED);
nuclear@1 76 #endif /* D_MULTISCAN_FILES_SUPPORTED */
nuclear@1 77 }
nuclear@1 78 cinfo->output_scan_number = cinfo->input_scan_number;
nuclear@1 79 } else if (cinfo->global_state != DSTATE_PRESCAN)
nuclear@1 80 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
nuclear@1 81 /* Perform any dummy output passes, and set up for the final pass */
nuclear@1 82 return output_pass_setup(cinfo);
nuclear@1 83 }
nuclear@1 84
nuclear@1 85
nuclear@1 86 /*
nuclear@1 87 * Set up for an output pass, and perform any dummy pass(es) needed.
nuclear@1 88 * Common subroutine for jpeg_start_decompress and jpeg_start_output.
nuclear@1 89 * Entry: global_state = DSTATE_PRESCAN only if previously suspended.
nuclear@1 90 * Exit: If done, returns TRUE and sets global_state for proper output mode.
nuclear@1 91 * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.
nuclear@1 92 */
nuclear@1 93
nuclear@1 94 LOCAL(boolean)
nuclear@1 95 output_pass_setup (j_decompress_ptr cinfo)
nuclear@1 96 {
nuclear@1 97 if (cinfo->global_state != DSTATE_PRESCAN) {
nuclear@1 98 /* First call: do pass setup */
nuclear@1 99 (*cinfo->master->prepare_for_output_pass) (cinfo);
nuclear@1 100 cinfo->output_scanline = 0;
nuclear@1 101 cinfo->global_state = DSTATE_PRESCAN;
nuclear@1 102 }
nuclear@1 103 /* Loop over any required dummy passes */
nuclear@1 104 while (cinfo->master->is_dummy_pass) {
nuclear@1 105 #ifdef QUANT_2PASS_SUPPORTED
nuclear@1 106 /* Crank through the dummy pass */
nuclear@1 107 while (cinfo->output_scanline < cinfo->output_height) {
nuclear@1 108 JDIMENSION last_scanline;
nuclear@1 109 /* Call progress monitor hook if present */
nuclear@1 110 if (cinfo->progress != NULL) {
nuclear@1 111 cinfo->progress->pass_counter = (long) cinfo->output_scanline;
nuclear@1 112 cinfo->progress->pass_limit = (long) cinfo->output_height;
nuclear@1 113 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
nuclear@1 114 }
nuclear@1 115 /* Process some data */
nuclear@1 116 last_scanline = cinfo->output_scanline;
nuclear@1 117 (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
nuclear@1 118 &cinfo->output_scanline, (JDIMENSION) 0);
nuclear@1 119 if (cinfo->output_scanline == last_scanline)
nuclear@1 120 return FALSE; /* No progress made, must suspend */
nuclear@1 121 }
nuclear@1 122 /* Finish up dummy pass, and set up for another one */
nuclear@1 123 (*cinfo->master->finish_output_pass) (cinfo);
nuclear@1 124 (*cinfo->master->prepare_for_output_pass) (cinfo);
nuclear@1 125 cinfo->output_scanline = 0;
nuclear@1 126 #else
nuclear@1 127 ERREXIT(cinfo, JERR_NOT_COMPILED);
nuclear@1 128 #endif /* QUANT_2PASS_SUPPORTED */
nuclear@1 129 }
nuclear@1 130 /* Ready for application to drive output pass through
nuclear@1 131 * jpeg_read_scanlines or jpeg_read_raw_data.
nuclear@1 132 */
nuclear@1 133 cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
nuclear@1 134 return TRUE;
nuclear@1 135 }
nuclear@1 136
nuclear@1 137
nuclear@1 138 /*
nuclear@1 139 * Read some scanlines of data from the JPEG decompressor.
nuclear@1 140 *
nuclear@1 141 * The return value will be the number of lines actually read.
nuclear@1 142 * This may be less than the number requested in several cases,
nuclear@1 143 * including bottom of image, data source suspension, and operating
nuclear@1 144 * modes that emit multiple scanlines at a time.
nuclear@1 145 *
nuclear@1 146 * Note: we warn about excess calls to jpeg_read_scanlines() since
nuclear@1 147 * this likely signals an application programmer error. However,
nuclear@1 148 * an oversize buffer (max_lines > scanlines remaining) is not an error.
nuclear@1 149 */
nuclear@1 150
nuclear@1 151 GLOBAL(JDIMENSION)
nuclear@1 152 jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
nuclear@1 153 JDIMENSION max_lines)
nuclear@1 154 {
nuclear@1 155 JDIMENSION row_ctr;
nuclear@1 156
nuclear@1 157 if (cinfo->global_state != DSTATE_SCANNING)
nuclear@1 158 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
nuclear@1 159 if (cinfo->output_scanline >= cinfo->output_height) {
nuclear@1 160 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
nuclear@1 161 return 0;
nuclear@1 162 }
nuclear@1 163
nuclear@1 164 /* Call progress monitor hook if present */
nuclear@1 165 if (cinfo->progress != NULL) {
nuclear@1 166 cinfo->progress->pass_counter = (long) cinfo->output_scanline;
nuclear@1 167 cinfo->progress->pass_limit = (long) cinfo->output_height;
nuclear@1 168 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
nuclear@1 169 }
nuclear@1 170
nuclear@1 171 /* Process some data */
nuclear@1 172 row_ctr = 0;
nuclear@1 173 (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
nuclear@1 174 cinfo->output_scanline += row_ctr;
nuclear@1 175 return row_ctr;
nuclear@1 176 }
nuclear@1 177
nuclear@1 178
nuclear@1 179 /*
nuclear@1 180 * Alternate entry point to read raw data.
nuclear@1 181 * Processes exactly one iMCU row per call, unless suspended.
nuclear@1 182 */
nuclear@1 183
nuclear@1 184 GLOBAL(JDIMENSION)
nuclear@1 185 jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
nuclear@1 186 JDIMENSION max_lines)
nuclear@1 187 {
nuclear@1 188 JDIMENSION lines_per_iMCU_row;
nuclear@1 189
nuclear@1 190 if (cinfo->global_state != DSTATE_RAW_OK)
nuclear@1 191 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
nuclear@1 192 if (cinfo->output_scanline >= cinfo->output_height) {
nuclear@1 193 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
nuclear@1 194 return 0;
nuclear@1 195 }
nuclear@1 196
nuclear@1 197 /* Call progress monitor hook if present */
nuclear@1 198 if (cinfo->progress != NULL) {
nuclear@1 199 cinfo->progress->pass_counter = (long) cinfo->output_scanline;
nuclear@1 200 cinfo->progress->pass_limit = (long) cinfo->output_height;
nuclear@1 201 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
nuclear@1 202 }
nuclear@1 203
nuclear@1 204 /* Verify that at least one iMCU row can be returned. */
nuclear@1 205 lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
nuclear@1 206 if (max_lines < lines_per_iMCU_row)
nuclear@1 207 ERREXIT(cinfo, JERR_BUFFER_SIZE);
nuclear@1 208
nuclear@1 209 /* Decompress directly into user's buffer. */
nuclear@1 210 if (! (*cinfo->coef->decompress_data) (cinfo, data))
nuclear@1 211 return 0; /* suspension forced, can do nothing more */
nuclear@1 212
nuclear@1 213 /* OK, we processed one iMCU row. */
nuclear@1 214 cinfo->output_scanline += lines_per_iMCU_row;
nuclear@1 215 return lines_per_iMCU_row;
nuclear@1 216 }
nuclear@1 217
nuclear@1 218
nuclear@1 219 /* Additional entry points for buffered-image mode. */
nuclear@1 220
nuclear@1 221 #ifdef D_MULTISCAN_FILES_SUPPORTED
nuclear@1 222
nuclear@1 223 /*
nuclear@1 224 * Initialize for an output pass in buffered-image mode.
nuclear@1 225 */
nuclear@1 226
nuclear@1 227 GLOBAL(boolean)
nuclear@1 228 jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
nuclear@1 229 {
nuclear@1 230 if (cinfo->global_state != DSTATE_BUFIMAGE &&
nuclear@1 231 cinfo->global_state != DSTATE_PRESCAN)
nuclear@1 232 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
nuclear@1 233 /* Limit scan number to valid range */
nuclear@1 234 if (scan_number <= 0)
nuclear@1 235 scan_number = 1;
nuclear@1 236 if (cinfo->inputctl->eoi_reached &&
nuclear@1 237 scan_number > cinfo->input_scan_number)
nuclear@1 238 scan_number = cinfo->input_scan_number;
nuclear@1 239 cinfo->output_scan_number = scan_number;
nuclear@1 240 /* Perform any dummy output passes, and set up for the real pass */
nuclear@1 241 return output_pass_setup(cinfo);
nuclear@1 242 }
nuclear@1 243
nuclear@1 244
nuclear@1 245 /*
nuclear@1 246 * Finish up after an output pass in buffered-image mode.
nuclear@1 247 *
nuclear@1 248 * Returns FALSE if suspended. The return value need be inspected only if
nuclear@1 249 * a suspending data source is used.
nuclear@1 250 */
nuclear@1 251
nuclear@1 252 GLOBAL(boolean)
nuclear@1 253 jpeg_finish_output (j_decompress_ptr cinfo)
nuclear@1 254 {
nuclear@1 255 if ((cinfo->global_state == DSTATE_SCANNING ||
nuclear@1 256 cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
nuclear@1 257 /* Terminate this pass. */
nuclear@1 258 /* We do not require the whole pass to have been completed. */
nuclear@1 259 (*cinfo->master->finish_output_pass) (cinfo);
nuclear@1 260 cinfo->global_state = DSTATE_BUFPOST;
nuclear@1 261 } else if (cinfo->global_state != DSTATE_BUFPOST) {
nuclear@1 262 /* BUFPOST = repeat call after a suspension, anything else is error */
nuclear@1 263 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
nuclear@1 264 }
nuclear@1 265 /* Read markers looking for SOS or EOI */
nuclear@1 266 while (cinfo->input_scan_number <= cinfo->output_scan_number &&
nuclear@1 267 ! cinfo->inputctl->eoi_reached) {
nuclear@1 268 if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
nuclear@1 269 return FALSE; /* Suspend, come back later */
nuclear@1 270 }
nuclear@1 271 cinfo->global_state = DSTATE_BUFIMAGE;
nuclear@1 272 return TRUE;
nuclear@1 273 }
nuclear@1 274
nuclear@1 275 #endif /* D_MULTISCAN_FILES_SUPPORTED */