blob: 347cf6daba61e1e98f1a43e74bcf1c06d792aa2a [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.
6 * For conditions of distribution and use, see the accompanying README file.
7 *
8 * This file contains initialization logic for the JPEG compressor.
9 * This routine is in charge of selecting the modules to be executed and
10 * making an initialization call to each one.
11 *
12 * Logically, this code belongs in jcmaster.c. It's split out because
13 * linking this routine implies linking the entire compression library.
14 * For a transcoding-only application, we want to be able to use jcmaster.c
15 * without linking in the whole library.
16 */
17
18#define JPEG_INTERNALS
19#include "jinclude.h"
20#include "jpeglib.h"
21
22
23/*
24 * Master selection of compression modules.
25 * This is done once at the start of processing an image. We determine
26 * which modules will be used and give them appropriate initialization calls.
27 */
28
Thomas G. Lane489583f1996-02-07 00:00:00 +000029GLOBAL(void)
Thomas G. Lanebc79e061995-08-02 00:00:00 +000030jinit_compress_master (j_compress_ptr cinfo)
31{
32 /* Initialize master control (includes parameter checking/processing) */
33 jinit_c_master_control(cinfo, FALSE /* full compression */);
34
35 /* Preprocessing */
36 if (! cinfo->raw_data_in) {
37 jinit_color_converter(cinfo);
38 jinit_downsampler(cinfo);
39 jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
40 }
41 /* Forward DCT */
42 jinit_forward_dct(cinfo);
43 /* Entropy encoding: either Huffman or arithmetic coding. */
44 if (cinfo->arith_code) {
DRC66f97e62010-11-23 05:49:54 +000045#ifdef C_ARITH_CODING_SUPPORTED
Guido Vollbeding1e247ac1998-03-28 00:00:00 +000046 jinit_arith_encoder(cinfo);
DRC66f97e62010-11-23 05:49:54 +000047#else
Thomas G. Lanebc79e061995-08-02 00:00:00 +000048 ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
DRC66f97e62010-11-23 05:49:54 +000049#endif
Thomas G. Lanebc79e061995-08-02 00:00:00 +000050 } else {
51 if (cinfo->progressive_mode) {
52#ifdef C_PROGRESSIVE_SUPPORTED
53 jinit_phuff_encoder(cinfo);
54#else
55 ERREXIT(cinfo, JERR_NOT_COMPILED);
56#endif
57 } else
58 jinit_huff_encoder(cinfo);
59 }
60
61 /* Need a full-image coefficient buffer in any multi-pass mode. */
62 jinit_c_coef_controller(cinfo,
DRCe5eaf372014-05-09 18:00:32 +000063 (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
Thomas G. Lanebc79e061995-08-02 00:00:00 +000064 jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
65
66 jinit_marker_writer(cinfo);
67
68 /* We can now tell the memory manager to allocate virtual arrays. */
69 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
70
71 /* Write the datastream header (SOI) immediately.
72 * Frame and scan headers are postponed till later.
73 * This lets application insert special markers after the SOI.
74 */
75 (*cinfo->marker->write_file_header) (cinfo);
76}