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