/*1* jcinit.c2*3* Copyright (C) 1991-1997, Thomas G. Lane.4* Modified 2003-2013 by Guido Vollbeding.5* 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 and10* making an initialization call to each one.11*12* Logically, this code belongs in jcmaster.c. It's split out because13* linking this routine implies linking the entire compression library.14* For a transcoding-only application, we want to be able to use jcmaster.c15* without linking in the whole library.16*/1718#define JPEG_INTERNALS19#include "jinclude.h"20#include "jpeglib.h"212223/*24* Master selection of compression modules.25* This is done once at the start of processing an image. We determine26* which modules will be used and give them appropriate initialization calls.27*/2829GLOBAL(void)30jinit_compress_master (j_compress_ptr cinfo)31{32long samplesperrow;33JDIMENSION jd_samplesperrow;3435/* For now, precision must match compiled-in value... */36if (cinfo->data_precision != BITS_IN_JSAMPLE)37ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);3839/* Sanity check on image dimensions */40if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||41cinfo->input_components <= 0)42ERREXIT(cinfo, JERR_EMPTY_IMAGE);4344/* Width of an input scanline must be representable as JDIMENSION. */45samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;46jd_samplesperrow = (JDIMENSION) samplesperrow;47if ((long) jd_samplesperrow != samplesperrow)48ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);4950/* Initialize master control (includes parameter checking/processing) */51jinit_c_master_control(cinfo, FALSE /* full compression */);5253/* Preprocessing */54if (! cinfo->raw_data_in) {55jinit_color_converter(cinfo);56jinit_downsampler(cinfo);57jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);58}59/* Forward DCT */60jinit_forward_dct(cinfo);61/* Entropy encoding: either Huffman or arithmetic coding. */62if (cinfo->arith_code)63jinit_arith_encoder(cinfo);64else {65jinit_huff_encoder(cinfo);66}6768/* Need a full-image coefficient buffer in any multi-pass mode. */69jinit_c_coef_controller(cinfo,70(boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));71jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);7273jinit_marker_writer(cinfo);7475/* We can now tell the memory manager to allocate virtual arrays. */76(*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);7778/* Write the datastream header (SOI) immediately.79* Frame and scan headers are postponed till later.80* This lets application insert special markers after the SOI.81*/82(*cinfo->marker->write_file_header) (cinfo);83}848586