source: golgotha/src/i4/loaders/jpg/jcapistd.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 6.4 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9/*
10 * jcapistd.c
11 *
12 * Copyright (C) 1994-1996, Thomas G. Lane.
13 * This file is part of the Independent JPEG Group's software.
14 * For conditions of distribution and use, see the accompanying README file.
15 *
16 * This file contains application interface code for the compression half
17 * of the JPEG library.  These are the "standard" API routines that are
18 * used in the normal full-compression case.  They are not used by a
19 * transcoding-only application.  Note that if an application links in
20 * jpeg_start_compress, it will end up linking in the entire compressor.
21 * We thus must separate this file from jcapimin.c to avoid linking the
22 * whole compression library into a transcoder.
23 */
24
25#define JPEG_INTERNALS
26#include "loaders/jpg/jinclude.h"
27#include "loaders/jpg/jpeglib.h"
28
29
30/*
31 * Compression initialization.
32 * Before calling this, all parameters and a data destination must be set up.
33 *
34 * We require a write_all_tables parameter as a failsafe check when writing
35 * multiple datastreams from the same compression object.  Since prior runs
36 * will have left all the tables marked sent_table=TRUE, a subsequent run
37 * would emit an abbreviated stream (no tables) by default.  This may be what
38 * is wanted, but for safety's sake it should not be the default behavior:
39 * programmers should have to make a deliberate choice to emit abbreviated
40 * images.  Therefore the documentation and examples should encourage people
41 * to pass write_all_tables=TRUE; then it will take active thought to do the
42 * wrong thing.
43 */
44
45GLOBAL(void)
46jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
47{
48  if (cinfo->global_state != CSTATE_START)
49    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
50
51  if (write_all_tables)
52    jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
53
54  /* (Re)initialize error mgr and destination modules */
55  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
56  (*cinfo->dest->init_destination) (cinfo);
57  /* Perform master selection of active modules */
58  jinit_compress_master(cinfo);
59  /* Set up for the first pass */
60  (*cinfo->master->prepare_for_pass) (cinfo);
61  /* Ready for application to drive first pass through jpeg_write_scanlines
62   * or jpeg_write_raw_data.
63   */
64  cinfo->next_scanline = 0;
65  cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
66}
67
68
69/*
70 * Write some scanlines of data to the JPEG compressor.
71 *
72 * The return value will be the number of lines actually written.
73 * This should be less than the supplied num_lines only in case that
74 * the data destination module has requested suspension of the compressor,
75 * or if more than image_height scanlines are passed in.
76 *
77 * Note: we warn about excess calls to jpeg_write_scanlines() since
78 * this likely signals an application programmer error.  However,
79 * excess scanlines passed in the last valid call are *silently* ignored,
80 * so that the application need not adjust num_lines for end-of-image
81 * when using a multiple-scanline buffer.
82 */
83
84GLOBAL(JDIMENSION)
85jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
86                      JDIMENSION num_lines)
87{
88  JDIMENSION row_ctr, rows_left;
89
90  if (cinfo->global_state != CSTATE_SCANNING)
91    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
92  if (cinfo->next_scanline >= cinfo->image_height)
93    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
94
95  /* Call progress monitor hook if present */
96  if (cinfo->progress != NULL) {
97    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
98    cinfo->progress->pass_limit = (long) cinfo->image_height;
99    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
100  }
101
102  /* Give master control module another chance if this is first call to
103   * jpeg_write_scanlines.  This lets output of the frame/scan headers be
104   * delayed so that application can write COM, etc, markers between
105   * jpeg_start_compress and jpeg_write_scanlines.
106   */
107  if (cinfo->master->call_pass_startup)
108    (*cinfo->master->pass_startup) (cinfo);
109
110  /* Ignore any extra scanlines at bottom of image. */
111  rows_left = cinfo->image_height - cinfo->next_scanline;
112  if (num_lines > rows_left)
113    num_lines = rows_left;
114
115  row_ctr = 0;
116  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
117  cinfo->next_scanline += row_ctr;
118  return row_ctr;
119}
120
121
122/*
123 * Alternate entry point to write raw data.
124 * Processes exactly one iMCU row per call, unless suspended.
125 */
126
127GLOBAL(JDIMENSION)
128jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
129                     JDIMENSION num_lines)
130{
131  JDIMENSION lines_per_iMCU_row;
132
133  if (cinfo->global_state != CSTATE_RAW_OK)
134    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
135  if (cinfo->next_scanline >= cinfo->image_height) {
136    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
137    return 0;
138  }
139
140  /* Call progress monitor hook if present */
141  if (cinfo->progress != NULL) {
142    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
143    cinfo->progress->pass_limit = (long) cinfo->image_height;
144    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
145  }
146
147  /* Give master control module another chance if this is first call to
148   * jpeg_write_raw_data.  This lets output of the frame/scan headers be
149   * delayed so that application can write COM, etc, markers between
150   * jpeg_start_compress and jpeg_write_raw_data.
151   */
152  if (cinfo->master->call_pass_startup)
153    (*cinfo->master->pass_startup) (cinfo);
154
155  /* Verify that at least one iMCU row has been passed. */
156  lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
157  if (num_lines < lines_per_iMCU_row)
158    ERREXIT(cinfo, JERR_BUFFER_SIZE);
159
160  /* Directly compress the row. */
161  if (! (*cinfo->coef->compress_data) (cinfo, data)) {
162    /* If compressor did not consume the whole row, suspend processing. */
163    return 0;
164  }
165
166  /* OK, we processed one iMCU row. */
167  cinfo->next_scanline += lines_per_iMCU_row;
168  return lines_per_iMCU_row;
169}
Note: See TracBrowser for help on using the repository browser.