Path: blob/master/thirdparty/libjpeg-turbo/src/jcinit.c
9904 views
/*1* jcinit.c2*3* This file was part of the Independent JPEG Group's software:4* Copyright (C) 1991-1997, Thomas G. Lane.5* Lossless JPEG Modifications:6* Copyright (C) 1999, Ken Murchison.7* libjpeg-turbo Modifications:8* Copyright (C) 2020, 2022, 2024, D. R. Commander.9* For conditions of distribution and use, see the accompanying README.ijg10* file.11*12* This file contains initialization logic for the JPEG compressor.13* This routine is in charge of selecting the modules to be executed and14* making an initialization call to each one.15*16* Logically, this code belongs in jcmaster.c. It's split out because17* linking this routine implies linking the entire compression library.18* For a transcoding-only application, we want to be able to use jcmaster.c19* without linking in the whole library.20*/2122#define JPEG_INTERNALS23#include "jinclude.h"24#include "jpeglib.h"25#include "jpegapicomp.h"262728/*29* Master selection of compression modules.30* This is done once at the start of processing an image. We determine31* which modules will be used and give them appropriate initialization calls.32*/3334GLOBAL(void)35jinit_compress_master(j_compress_ptr cinfo)36{37/* Initialize master control (includes parameter checking/processing) */38jinit_c_master_control(cinfo, FALSE /* full compression */);3940/* Preprocessing */41if (!cinfo->raw_data_in) {42if (cinfo->data_precision <= 8) {43jinit_color_converter(cinfo);44jinit_downsampler(cinfo);45jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);46} else if (cinfo->data_precision <= 12) {47j12init_color_converter(cinfo);48j12init_downsampler(cinfo);49j12init_c_prep_controller(cinfo,50FALSE /* never need full buffer here */);51} else {52#ifdef C_LOSSLESS_SUPPORTED53j16init_color_converter(cinfo);54j16init_downsampler(cinfo);55j16init_c_prep_controller(cinfo,56FALSE /* never need full buffer here */);57#else58ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);59#endif60}61}6263if (cinfo->master->lossless) {64#ifdef C_LOSSLESS_SUPPORTED65/* Prediction, sample differencing, and point transform */66if (cinfo->data_precision <= 8)67jinit_lossless_compressor(cinfo);68else if (cinfo->data_precision <= 12)69j12init_lossless_compressor(cinfo);70else71j16init_lossless_compressor(cinfo);72/* Entropy encoding: either Huffman or arithmetic coding. */73if (cinfo->arith_code) {74ERREXIT(cinfo, JERR_ARITH_NOTIMPL);75} else {76jinit_lhuff_encoder(cinfo);77}7879/* Need a full-image difference buffer in any multi-pass mode. */80if (cinfo->data_precision <= 8)81jinit_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||82cinfo->optimize_coding));83else if (cinfo->data_precision <= 12)84j12init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||85cinfo->optimize_coding));86else87j16init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||88cinfo->optimize_coding));89#else90ERREXIT(cinfo, JERR_NOT_COMPILED);91#endif92} else {93/* Forward DCT */94if (cinfo->data_precision == 8)95jinit_forward_dct(cinfo);96else if (cinfo->data_precision == 12)97j12init_forward_dct(cinfo);98else99ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);100/* Entropy encoding: either Huffman or arithmetic coding. */101if (cinfo->arith_code) {102#ifdef C_ARITH_CODING_SUPPORTED103jinit_arith_encoder(cinfo);104#else105ERREXIT(cinfo, JERR_ARITH_NOTIMPL);106#endif107} else {108if (cinfo->progressive_mode) {109#ifdef C_PROGRESSIVE_SUPPORTED110jinit_phuff_encoder(cinfo);111#else112ERREXIT(cinfo, JERR_NOT_COMPILED);113#endif114} else115jinit_huff_encoder(cinfo);116}117118/* Need a full-image coefficient buffer in any multi-pass mode. */119if (cinfo->data_precision == 12)120j12init_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||121cinfo->optimize_coding));122else123jinit_c_coef_controller(cinfo, (boolean)(cinfo->num_scans > 1 ||124cinfo->optimize_coding));125}126127if (cinfo->data_precision <= 8)128jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);129else if (cinfo->data_precision <= 12)130j12init_c_main_controller(cinfo, FALSE /* never need full buffer here */);131else132#ifdef C_LOSSLESS_SUPPORTED133j16init_c_main_controller(cinfo, FALSE /* never need full buffer here */);134#else135ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);136#endif137138jinit_marker_writer(cinfo);139140/* We can now tell the memory manager to allocate virtual arrays. */141(*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);142143/* Write the datastream header (SOI) immediately.144* Frame and scan headers are postponed till later.145* This lets application insert special markers after the SOI.146*/147(*cinfo->marker->write_file_header) (cinfo);148}149150151