blob: 78aa465786648da3466368441e31eb0c0b9c0712 [file] [log] [blame]
Thomas G. Lanebc79e061995-08-02 00:00:00 +00001/*
2 * jcinit.c
3 *
Thomas G. Lane5ead57a1998-03-27 00:00:00 +00004 * Copyright (C) 1991-1997, Thomas G. Lane.
Thomas G. Lanebc79e061995-08-02 00:00:00 +00005 * This file is part of the Independent JPEG Group's software.
Alex Naidis6eb7d372016-10-16 23:10:08 +02006 * For conditions of distribution and use, see the accompanying README.ijg
7 * file.
Thomas G. Lanebc79e061995-08-02 00:00:00 +00008 *
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
Thomas G. Lane489583f1996-02-07 00:00:00 +000030GLOBAL(void)
Leon Scroggins III3993b372018-07-16 10:43:45 -040031jinit_compress_master(j_compress_ptr cinfo)
Thomas G. Lanebc79e061995-08-02 00:00:00 +000032{
33 /* Initialize master control (includes parameter checking/processing) */
34 jinit_c_master_control(cinfo, FALSE /* full compression */);
35
36 /* Preprocessing */
Leon Scroggins III3993b372018-07-16 10:43:45 -040037 if (!cinfo->raw_data_in) {
Thomas G. Lanebc79e061995-08-02 00:00:00 +000038 jinit_color_converter(cinfo);
39 jinit_downsampler(cinfo);
40 jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
41 }
42 /* Forward DCT */
43 jinit_forward_dct(cinfo);
44 /* Entropy encoding: either Huffman or arithmetic coding. */
45 if (cinfo->arith_code) {
DRC66f97e62010-11-23 05:49:54 +000046#ifdef C_ARITH_CODING_SUPPORTED
Guido Vollbeding1e247ac1998-03-28 00:00:00 +000047 jinit_arith_encoder(cinfo);
DRC66f97e62010-11-23 05:49:54 +000048#else
Thomas G. Lanebc79e061995-08-02 00:00:00 +000049 ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
DRC66f97e62010-11-23 05:49:54 +000050#endif
Thomas G. Lanebc79e061995-08-02 00:00:00 +000051 } else {
52 if (cinfo->progressive_mode) {
53#ifdef C_PROGRESSIVE_SUPPORTED
54 jinit_phuff_encoder(cinfo);
55#else
56 ERREXIT(cinfo, JERR_NOT_COMPILED);
57#endif
58 } else
59 jinit_huff_encoder(cinfo);
60 }
61
62 /* Need a full-image coefficient buffer in any multi-pass mode. */
Leon Scroggins III3993b372018-07-16 10:43:45 -040063 jinit_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||
64 cinfo->optimize_coding));
Thomas G. Lanebc79e061995-08-02 00:00:00 +000065 jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
66
67 jinit_marker_writer(cinfo);
68
69 /* We can now tell the memory manager to allocate virtual arrays. */
Leon Scroggins III3993b372018-07-16 10:43:45 -040070 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
Thomas G. Lanebc79e061995-08-02 00:00:00 +000071
72 /* Write the datastream header (SOI) immediately.
73 * Frame and scan headers are postponed till later.
74 * This lets application insert special markers after the SOI.
75 */
76 (*cinfo->marker->write_file_header) (cinfo);
77}