istereo

annotate libs/libjpeg/jdapistd.c @ 28:c0ae8e668447

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