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