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