istereo

annotate libs/libjpeg/jcapistd.c @ 26:862a3329a8f0

wohooo, added a shitload of code from zlib/libpng/libjpeg. When the good lord was raining shared libraries the iphone held a fucking umbrella...
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 06:28:38 +0300
parents
children
rev   line source
nuclear@26 1 /*
nuclear@26 2 * jcapistd.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 compression half
nuclear@26 9 * of the JPEG library. These are the "standard" API routines that are
nuclear@26 10 * used in the normal full-compression 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_compress, it will end up linking in the entire compressor.
nuclear@26 13 * We thus must separate this file from jcapimin.c to avoid linking the
nuclear@26 14 * whole compression 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 /*
nuclear@26 23 * Compression initialization.
nuclear@26 24 * Before calling this, all parameters and a data destination must be set up.
nuclear@26 25 *
nuclear@26 26 * We require a write_all_tables parameter as a failsafe check when writing
nuclear@26 27 * multiple datastreams from the same compression object. Since prior runs
nuclear@26 28 * will have left all the tables marked sent_table=TRUE, a subsequent run
nuclear@26 29 * would emit an abbreviated stream (no tables) by default. This may be what
nuclear@26 30 * is wanted, but for safety's sake it should not be the default behavior:
nuclear@26 31 * programmers should have to make a deliberate choice to emit abbreviated
nuclear@26 32 * images. Therefore the documentation and examples should encourage people
nuclear@26 33 * to pass write_all_tables=TRUE; then it will take active thought to do the
nuclear@26 34 * wrong thing.
nuclear@26 35 */
nuclear@26 36
nuclear@26 37 GLOBAL(void)
nuclear@26 38 jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
nuclear@26 39 {
nuclear@26 40 if (cinfo->global_state != CSTATE_START)
nuclear@26 41 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
nuclear@26 42
nuclear@26 43 if (write_all_tables)
nuclear@26 44 jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
nuclear@26 45
nuclear@26 46 /* (Re)initialize error mgr and destination modules */
nuclear@26 47 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
nuclear@26 48 (*cinfo->dest->init_destination) (cinfo);
nuclear@26 49 /* Perform master selection of active modules */
nuclear@26 50 jinit_compress_master(cinfo);
nuclear@26 51 /* Set up for the first pass */
nuclear@26 52 (*cinfo->master->prepare_for_pass) (cinfo);
nuclear@26 53 /* Ready for application to drive first pass through jpeg_write_scanlines
nuclear@26 54 * or jpeg_write_raw_data.
nuclear@26 55 */
nuclear@26 56 cinfo->next_scanline = 0;
nuclear@26 57 cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
nuclear@26 58 }
nuclear@26 59
nuclear@26 60
nuclear@26 61 /*
nuclear@26 62 * Write some scanlines of data to the JPEG compressor.
nuclear@26 63 *
nuclear@26 64 * The return value will be the number of lines actually written.
nuclear@26 65 * This should be less than the supplied num_lines only in case that
nuclear@26 66 * the data destination module has requested suspension of the compressor,
nuclear@26 67 * or if more than image_height scanlines are passed in.
nuclear@26 68 *
nuclear@26 69 * Note: we warn about excess calls to jpeg_write_scanlines() since
nuclear@26 70 * this likely signals an application programmer error. However,
nuclear@26 71 * excess scanlines passed in the last valid call are *silently* ignored,
nuclear@26 72 * so that the application need not adjust num_lines for end-of-image
nuclear@26 73 * when using a multiple-scanline buffer.
nuclear@26 74 */
nuclear@26 75
nuclear@26 76 GLOBAL(JDIMENSION)
nuclear@26 77 jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
nuclear@26 78 JDIMENSION num_lines)
nuclear@26 79 {
nuclear@26 80 JDIMENSION row_ctr, rows_left;
nuclear@26 81
nuclear@26 82 if (cinfo->global_state != CSTATE_SCANNING)
nuclear@26 83 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
nuclear@26 84 if (cinfo->next_scanline >= cinfo->image_height)
nuclear@26 85 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
nuclear@26 86
nuclear@26 87 /* Call progress monitor hook if present */
nuclear@26 88 if (cinfo->progress != NULL) {
nuclear@26 89 cinfo->progress->pass_counter = (long) cinfo->next_scanline;
nuclear@26 90 cinfo->progress->pass_limit = (long) cinfo->image_height;
nuclear@26 91 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
nuclear@26 92 }
nuclear@26 93
nuclear@26 94 /* Give master control module another chance if this is first call to
nuclear@26 95 * jpeg_write_scanlines. This lets output of the frame/scan headers be
nuclear@26 96 * delayed so that application can write COM, etc, markers between
nuclear@26 97 * jpeg_start_compress and jpeg_write_scanlines.
nuclear@26 98 */
nuclear@26 99 if (cinfo->master->call_pass_startup)
nuclear@26 100 (*cinfo->master->pass_startup) (cinfo);
nuclear@26 101
nuclear@26 102 /* Ignore any extra scanlines at bottom of image. */
nuclear@26 103 rows_left = cinfo->image_height - cinfo->next_scanline;
nuclear@26 104 if (num_lines > rows_left)
nuclear@26 105 num_lines = rows_left;
nuclear@26 106
nuclear@26 107 row_ctr = 0;
nuclear@26 108 (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
nuclear@26 109 cinfo->next_scanline += row_ctr;
nuclear@26 110 return row_ctr;
nuclear@26 111 }
nuclear@26 112
nuclear@26 113
nuclear@26 114 /*
nuclear@26 115 * Alternate entry point to write raw data.
nuclear@26 116 * Processes exactly one iMCU row per call, unless suspended.
nuclear@26 117 */
nuclear@26 118
nuclear@26 119 GLOBAL(JDIMENSION)
nuclear@26 120 jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
nuclear@26 121 JDIMENSION num_lines)
nuclear@26 122 {
nuclear@26 123 JDIMENSION lines_per_iMCU_row;
nuclear@26 124
nuclear@26 125 if (cinfo->global_state != CSTATE_RAW_OK)
nuclear@26 126 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
nuclear@26 127 if (cinfo->next_scanline >= cinfo->image_height) {
nuclear@26 128 WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
nuclear@26 129 return 0;
nuclear@26 130 }
nuclear@26 131
nuclear@26 132 /* Call progress monitor hook if present */
nuclear@26 133 if (cinfo->progress != NULL) {
nuclear@26 134 cinfo->progress->pass_counter = (long) cinfo->next_scanline;
nuclear@26 135 cinfo->progress->pass_limit = (long) cinfo->image_height;
nuclear@26 136 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
nuclear@26 137 }
nuclear@26 138
nuclear@26 139 /* Give master control module another chance if this is first call to
nuclear@26 140 * jpeg_write_raw_data. This lets output of the frame/scan headers be
nuclear@26 141 * delayed so that application can write COM, etc, markers between
nuclear@26 142 * jpeg_start_compress and jpeg_write_raw_data.
nuclear@26 143 */
nuclear@26 144 if (cinfo->master->call_pass_startup)
nuclear@26 145 (*cinfo->master->pass_startup) (cinfo);
nuclear@26 146
nuclear@26 147 /* Verify that at least one iMCU row has been passed. */
nuclear@26 148 lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
nuclear@26 149 if (num_lines < lines_per_iMCU_row)
nuclear@26 150 ERREXIT(cinfo, JERR_BUFFER_SIZE);
nuclear@26 151
nuclear@26 152 /* Directly compress the row. */
nuclear@26 153 if (! (*cinfo->coef->compress_data) (cinfo, data)) {
nuclear@26 154 /* If compressor did not consume the whole row, suspend processing. */
nuclear@26 155 return 0;
nuclear@26 156 }
nuclear@26 157
nuclear@26 158 /* OK, we processed one iMCU row. */
nuclear@26 159 cinfo->next_scanline += lines_per_iMCU_row;
nuclear@26 160 return lines_per_iMCU_row;
nuclear@26 161 }