/src/libjpeg-turbo.main/jcinit.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * jcinit.c | 
| 3 |  |  * | 
| 4 |  |  * This file was part of the Independent JPEG Group's software: | 
| 5 |  |  * Copyright (C) 1991-1997, Thomas G. Lane. | 
| 6 |  |  * Lossless JPEG Modifications: | 
| 7 |  |  * Copyright (C) 1999, Ken Murchison. | 
| 8 |  |  * libjpeg-turbo Modifications: | 
| 9 |  |  * Copyright (C) 2020, 2022, D. R. Commander. | 
| 10 |  |  * For conditions of distribution and use, see the accompanying README.ijg | 
| 11 |  |  * file. | 
| 12 |  |  * | 
| 13 |  |  * This file contains initialization logic for the JPEG compressor. | 
| 14 |  |  * This routine is in charge of selecting the modules to be executed and | 
| 15 |  |  * making an initialization call to each one. | 
| 16 |  |  * | 
| 17 |  |  * Logically, this code belongs in jcmaster.c.  It's split out because | 
| 18 |  |  * linking this routine implies linking the entire compression library. | 
| 19 |  |  * For a transcoding-only application, we want to be able to use jcmaster.c | 
| 20 |  |  * without linking in the whole library. | 
| 21 |  |  */ | 
| 22 |  |  | 
| 23 |  | #define JPEG_INTERNALS | 
| 24 |  | #include "jinclude.h" | 
| 25 |  | #include "jpeglib.h" | 
| 26 |  | #include "jpegapicomp.h" | 
| 27 |  |  | 
| 28 |  |  | 
| 29 |  | /* | 
| 30 |  |  * Master selection of compression modules. | 
| 31 |  |  * This is done once at the start of processing an image.  We determine | 
| 32 |  |  * which modules will be used and give them appropriate initialization calls. | 
| 33 |  |  */ | 
| 34 |  |  | 
| 35 |  | GLOBAL(void) | 
| 36 |  | jinit_compress_master(j_compress_ptr cinfo) | 
| 37 | 4.78k | { | 
| 38 |  |   /* Initialize master control (includes parameter checking/processing) */ | 
| 39 | 4.78k |   jinit_c_master_control(cinfo, FALSE /* full compression */); | 
| 40 |  |  | 
| 41 |  |   /* Preprocessing */ | 
| 42 | 4.78k |   if (!cinfo->raw_data_in) { | 
| 43 | 4.74k |     if (cinfo->data_precision == 16) { | 
| 44 | 4.74k | #ifdef C_LOSSLESS_SUPPORTED | 
| 45 | 4.74k |       j16init_color_converter(cinfo); | 
| 46 | 4.74k |       j16init_downsampler(cinfo); | 
| 47 | 4.74k |       j16init_c_prep_controller(cinfo, | 
| 48 | 4.74k |                                 FALSE /* never need full buffer here */); | 
| 49 |  | #else | 
| 50 |  |       ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 
| 51 |  | #endif | 
| 52 | 4.74k |     } else if (cinfo->data_precision == 12) { | 
| 53 | 0 |       j12init_color_converter(cinfo); | 
| 54 | 0 |       j12init_downsampler(cinfo); | 
| 55 | 0 |       j12init_c_prep_controller(cinfo, | 
| 56 | 0 |                                 FALSE /* never need full buffer here */); | 
| 57 | 0 |     } else { | 
| 58 | 0 |       jinit_color_converter(cinfo); | 
| 59 | 0 |       jinit_downsampler(cinfo); | 
| 60 | 0 |       jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */); | 
| 61 | 0 |     } | 
| 62 | 4.74k |   } | 
| 63 |  |  | 
| 64 | 4.78k |   if (cinfo->master->lossless) { | 
| 65 | 4.74k | #ifdef C_LOSSLESS_SUPPORTED | 
| 66 |  |     /* Prediction, sample differencing, and point transform */ | 
| 67 | 4.74k |     if (cinfo->data_precision == 16) | 
| 68 | 4.74k |       j16init_lossless_compressor(cinfo); | 
| 69 | 0 |     else if (cinfo->data_precision == 12) | 
| 70 | 0 |       j12init_lossless_compressor(cinfo); | 
| 71 | 0 |     else | 
| 72 | 0 |       jinit_lossless_compressor(cinfo); | 
| 73 |  |     /* Entropy encoding: either Huffman or arithmetic coding. */ | 
| 74 | 4.74k |     if (cinfo->arith_code) { | 
| 75 | 0 |       ERREXIT(cinfo, JERR_ARITH_NOTIMPL); | 
| 76 | 4.74k |     } else { | 
| 77 | 4.74k |       jinit_lhuff_encoder(cinfo); | 
| 78 | 4.74k |     } | 
| 79 |  |  | 
| 80 |  |     /* Need a full-image difference buffer in any multi-pass mode. */ | 
| 81 | 4.74k |     if (cinfo->data_precision == 16) | 
| 82 | 4.74k |       j16init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 || | 
| 83 | 4.74k |                                                  cinfo->optimize_coding)); | 
| 84 | 0 |     else if (cinfo->data_precision == 12) | 
| 85 | 0 |       j12init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 || | 
| 86 | 0 |                                                  cinfo->optimize_coding)); | 
| 87 | 0 |     else | 
| 88 | 0 |       jinit_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 || | 
| 89 | 0 |                                                cinfo->optimize_coding)); | 
| 90 |  | #else | 
| 91 |  |     ERREXIT(cinfo, JERR_NOT_COMPILED); | 
| 92 |  | #endif | 
| 93 | 4.74k |   } else { | 
| 94 | 35 |     if (cinfo->data_precision == 16) | 
| 95 | 0 |       ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 
| 96 |  |     /* Forward DCT */ | 
| 97 | 35 |     if (cinfo->data_precision == 12) | 
| 98 | 0 |       j12init_forward_dct(cinfo); | 
| 99 | 35 |     else | 
| 100 | 35 |       jinit_forward_dct(cinfo); | 
| 101 |  |     /* Entropy encoding: either Huffman or arithmetic coding. */ | 
| 102 | 35 |     if (cinfo->arith_code) { | 
| 103 | 0 | #ifdef C_ARITH_CODING_SUPPORTED | 
| 104 | 0 |       jinit_arith_encoder(cinfo); | 
| 105 |  | #else | 
| 106 |  |       ERREXIT(cinfo, JERR_ARITH_NOTIMPL); | 
| 107 |  | #endif | 
| 108 | 35 |     } else { | 
| 109 | 35 |       if (cinfo->progressive_mode) { | 
| 110 | 0 | #ifdef C_PROGRESSIVE_SUPPORTED | 
| 111 | 0 |         jinit_phuff_encoder(cinfo); | 
| 112 |  | #else | 
| 113 |  |         ERREXIT(cinfo, JERR_NOT_COMPILED); | 
| 114 |  | #endif | 
| 115 | 0 |       } else | 
| 116 | 35 |         jinit_huff_encoder(cinfo); | 
| 117 | 35 |     } | 
| 118 |  |  | 
| 119 |  |     /* Need a full-image coefficient buffer in any multi-pass mode. */ | 
| 120 | 35 |     if (cinfo->data_precision == 12) | 
| 121 | 0 |       j12init_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 || | 
| 122 | 0 |                                                  cinfo->optimize_coding)); | 
| 123 | 35 |     else | 
| 124 | 35 |       jinit_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 || | 
| 125 | 35 |                                                cinfo->optimize_coding)); | 
| 126 | 35 |   } | 
| 127 |  |  | 
| 128 | 4.78k |   if (cinfo->data_precision == 16) | 
| 129 | 4.74k | #ifdef C_LOSSLESS_SUPPORTED | 
| 130 | 4.74k |     j16init_c_main_controller(cinfo, FALSE /* never need full buffer here */); | 
| 131 |  | #else | 
| 132 |  |     ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 
| 133 |  | #endif | 
| 134 | 35 |   else if (cinfo->data_precision == 12) | 
| 135 | 0 |     j12init_c_main_controller(cinfo, FALSE /* never need full buffer here */); | 
| 136 | 35 |   else | 
| 137 | 35 |     jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); | 
| 138 |  |  | 
| 139 | 4.78k |   jinit_marker_writer(cinfo); | 
| 140 |  |  | 
| 141 |  |   /* We can now tell the memory manager to allocate virtual arrays. */ | 
| 142 | 4.78k |   (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo); | 
| 143 |  |  | 
| 144 |  |   /* Write the datastream header (SOI) immediately. | 
| 145 |  |    * Frame and scan headers are postponed till later. | 
| 146 |  |    * This lets application insert special markers after the SOI. | 
| 147 |  |    */ | 
| 148 | 4.78k |   (*cinfo->marker->write_file_header) (cinfo); | 
| 149 | 4.78k | } |