dbf-halloween2015

diff libs/libjpeg/jcapistd.c @ 1:c3f5c32cb210

barfed all the libraries in the source tree to make porting easier
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 00:36:56 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/libjpeg/jcapistd.c	Sun Nov 01 00:36:56 2015 +0200
     1.3 @@ -0,0 +1,161 @@
     1.4 +/*
     1.5 + * jcapistd.c
     1.6 + *
     1.7 + * Copyright (C) 1994-1996, Thomas G. Lane.
     1.8 + * This file is part of the Independent JPEG Group's software.
     1.9 + * For conditions of distribution and use, see the accompanying README file.
    1.10 + *
    1.11 + * This file contains application interface code for the compression half
    1.12 + * of the JPEG library.  These are the "standard" API routines that are
    1.13 + * used in the normal full-compression case.  They are not used by a
    1.14 + * transcoding-only application.  Note that if an application links in
    1.15 + * jpeg_start_compress, it will end up linking in the entire compressor.
    1.16 + * We thus must separate this file from jcapimin.c to avoid linking the
    1.17 + * whole compression library into a transcoder.
    1.18 + */
    1.19 +
    1.20 +#define JPEG_INTERNALS
    1.21 +#include "jinclude.h"
    1.22 +#include "jpeglib.h"
    1.23 +
    1.24 +
    1.25 +/*
    1.26 + * Compression initialization.
    1.27 + * Before calling this, all parameters and a data destination must be set up.
    1.28 + *
    1.29 + * We require a write_all_tables parameter as a failsafe check when writing
    1.30 + * multiple datastreams from the same compression object.  Since prior runs
    1.31 + * will have left all the tables marked sent_table=TRUE, a subsequent run
    1.32 + * would emit an abbreviated stream (no tables) by default.  This may be what
    1.33 + * is wanted, but for safety's sake it should not be the default behavior:
    1.34 + * programmers should have to make a deliberate choice to emit abbreviated
    1.35 + * images.  Therefore the documentation and examples should encourage people
    1.36 + * to pass write_all_tables=TRUE; then it will take active thought to do the
    1.37 + * wrong thing.
    1.38 + */
    1.39 +
    1.40 +GLOBAL(void)
    1.41 +jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
    1.42 +{
    1.43 +  if (cinfo->global_state != CSTATE_START)
    1.44 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
    1.45 +
    1.46 +  if (write_all_tables)
    1.47 +    jpeg_suppress_tables(cinfo, FALSE);	/* mark all tables to be written */
    1.48 +
    1.49 +  /* (Re)initialize error mgr and destination modules */
    1.50 +  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
    1.51 +  (*cinfo->dest->init_destination) (cinfo);
    1.52 +  /* Perform master selection of active modules */
    1.53 +  jinit_compress_master(cinfo);
    1.54 +  /* Set up for the first pass */
    1.55 +  (*cinfo->master->prepare_for_pass) (cinfo);
    1.56 +  /* Ready for application to drive first pass through jpeg_write_scanlines
    1.57 +   * or jpeg_write_raw_data.
    1.58 +   */
    1.59 +  cinfo->next_scanline = 0;
    1.60 +  cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
    1.61 +}
    1.62 +
    1.63 +
    1.64 +/*
    1.65 + * Write some scanlines of data to the JPEG compressor.
    1.66 + *
    1.67 + * The return value will be the number of lines actually written.
    1.68 + * This should be less than the supplied num_lines only in case that
    1.69 + * the data destination module has requested suspension of the compressor,
    1.70 + * or if more than image_height scanlines are passed in.
    1.71 + *
    1.72 + * Note: we warn about excess calls to jpeg_write_scanlines() since
    1.73 + * this likely signals an application programmer error.  However,
    1.74 + * excess scanlines passed in the last valid call are *silently* ignored,
    1.75 + * so that the application need not adjust num_lines for end-of-image
    1.76 + * when using a multiple-scanline buffer.
    1.77 + */
    1.78 +
    1.79 +GLOBAL(JDIMENSION)
    1.80 +jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
    1.81 +		      JDIMENSION num_lines)
    1.82 +{
    1.83 +  JDIMENSION row_ctr, rows_left;
    1.84 +
    1.85 +  if (cinfo->global_state != CSTATE_SCANNING)
    1.86 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
    1.87 +  if (cinfo->next_scanline >= cinfo->image_height)
    1.88 +    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
    1.89 +
    1.90 +  /* Call progress monitor hook if present */
    1.91 +  if (cinfo->progress != NULL) {
    1.92 +    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
    1.93 +    cinfo->progress->pass_limit = (long) cinfo->image_height;
    1.94 +    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
    1.95 +  }
    1.96 +
    1.97 +  /* Give master control module another chance if this is first call to
    1.98 +   * jpeg_write_scanlines.  This lets output of the frame/scan headers be
    1.99 +   * delayed so that application can write COM, etc, markers between
   1.100 +   * jpeg_start_compress and jpeg_write_scanlines.
   1.101 +   */
   1.102 +  if (cinfo->master->call_pass_startup)
   1.103 +    (*cinfo->master->pass_startup) (cinfo);
   1.104 +
   1.105 +  /* Ignore any extra scanlines at bottom of image. */
   1.106 +  rows_left = cinfo->image_height - cinfo->next_scanline;
   1.107 +  if (num_lines > rows_left)
   1.108 +    num_lines = rows_left;
   1.109 +
   1.110 +  row_ctr = 0;
   1.111 +  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
   1.112 +  cinfo->next_scanline += row_ctr;
   1.113 +  return row_ctr;
   1.114 +}
   1.115 +
   1.116 +
   1.117 +/*
   1.118 + * Alternate entry point to write raw data.
   1.119 + * Processes exactly one iMCU row per call, unless suspended.
   1.120 + */
   1.121 +
   1.122 +GLOBAL(JDIMENSION)
   1.123 +jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
   1.124 +		     JDIMENSION num_lines)
   1.125 +{
   1.126 +  JDIMENSION lines_per_iMCU_row;
   1.127 +
   1.128 +  if (cinfo->global_state != CSTATE_RAW_OK)
   1.129 +    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
   1.130 +  if (cinfo->next_scanline >= cinfo->image_height) {
   1.131 +    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
   1.132 +    return 0;
   1.133 +  }
   1.134 +
   1.135 +  /* Call progress monitor hook if present */
   1.136 +  if (cinfo->progress != NULL) {
   1.137 +    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
   1.138 +    cinfo->progress->pass_limit = (long) cinfo->image_height;
   1.139 +    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
   1.140 +  }
   1.141 +
   1.142 +  /* Give master control module another chance if this is first call to
   1.143 +   * jpeg_write_raw_data.  This lets output of the frame/scan headers be
   1.144 +   * delayed so that application can write COM, etc, markers between
   1.145 +   * jpeg_start_compress and jpeg_write_raw_data.
   1.146 +   */
   1.147 +  if (cinfo->master->call_pass_startup)
   1.148 +    (*cinfo->master->pass_startup) (cinfo);
   1.149 +
   1.150 +  /* Verify that at least one iMCU row has been passed. */
   1.151 +  lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
   1.152 +  if (num_lines < lines_per_iMCU_row)
   1.153 +    ERREXIT(cinfo, JERR_BUFFER_SIZE);
   1.154 +
   1.155 +  /* Directly compress the row. */
   1.156 +  if (! (*cinfo->coef->compress_data) (cinfo, data)) {
   1.157 +    /* If compressor did not consume the whole row, suspend processing. */
   1.158 +    return 0;
   1.159 +  }
   1.160 +
   1.161 +  /* OK, we processed one iMCU row. */
   1.162 +  cinfo->next_scanline += lines_per_iMCU_row;
   1.163 +  return lines_per_iMCU_row;
   1.164 +}