[LIBJPEG]
[reactos.git] / reactos / dll / 3rdparty / libjpeg / jcinit.c
1 /*
2 * jcinit.c
3 *
4 * Copyright (C) 1991-1997, Thomas G. Lane.
5 * Modified 2003-2013 by Guido Vollbeding.
6 * This file is part of the Independent JPEG Group's software.
7 * For conditions of distribution and use, see the accompanying README file.
8 *
9 * This file contains initialization logic for the JPEG compressor.
10 * This routine is in charge of selecting the modules to be executed and
11 * making an initialization call to each one.
12 *
13 * Logically, this code belongs in jcmaster.c. It's split out because
14 * linking this routine implies linking the entire compression library.
15 * For a transcoding-only application, we want to be able to use jcmaster.c
16 * without linking in the whole library.
17 */
18
19 #define JPEG_INTERNALS
20 #include "jinclude.h"
21 #include "jpeglib.h"
22
23
24 /*
25 * Master selection of compression modules.
26 * This is done once at the start of processing an image. We determine
27 * which modules will be used and give them appropriate initialization calls.
28 */
29
30 GLOBAL(void)
31 jinit_compress_master (j_compress_ptr cinfo)
32 {
33 long samplesperrow;
34 JDIMENSION jd_samplesperrow;
35
36 /* For now, precision must match compiled-in value... */
37 if (cinfo->data_precision != BITS_IN_JSAMPLE)
38 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
39
40 /* Sanity check on image dimensions */
41 if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||
42 cinfo->input_components <= 0)
43 ERREXIT(cinfo, JERR_EMPTY_IMAGE);
44
45 /* Width of an input scanline must be representable as JDIMENSION. */
46 samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
47 jd_samplesperrow = (JDIMENSION) samplesperrow;
48 if ((long) jd_samplesperrow != samplesperrow)
49 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
50
51 /* Initialize master control (includes parameter checking/processing) */
52 jinit_c_master_control(cinfo, FALSE /* full compression */);
53
54 /* Preprocessing */
55 if (! cinfo->raw_data_in) {
56 jinit_color_converter(cinfo);
57 jinit_downsampler(cinfo);
58 jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
59 }
60 /* Forward DCT */
61 jinit_forward_dct(cinfo);
62 /* Entropy encoding: either Huffman or arithmetic coding. */
63 if (cinfo->arith_code)
64 jinit_arith_encoder(cinfo);
65 else {
66 jinit_huff_encoder(cinfo);
67 }
68
69 /* Need a full-image coefficient buffer in any multi-pass mode. */
70 jinit_c_coef_controller(cinfo,
71 (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
72 jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
73
74 jinit_marker_writer(cinfo);
75
76 /* We can now tell the memory manager to allocate virtual arrays. */
77 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
78
79 /* Write the datastream header (SOI) immediately.
80 * Frame and scan headers are postponed till later.
81 * This lets application insert special markers after the SOI.
82 */
83 (*cinfo->marker->write_file_header) (cinfo);
84 }