istereo2

annotate libs/libjpeg/jdapistd.c @ 2:81d35769f546

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