Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/vncdll/winvnc/libjpeg/jcapistd.c
Views: 11784
/*1* jcapistd.c2*3* Copyright (C) 1994-1996, Thomas G. Lane.4* This file is part of the Independent JPEG Group's software.5* For conditions of distribution and use, see the accompanying README file.6*7* This file contains application interface code for the compression half8* of the JPEG library. These are the "standard" API routines that are9* used in the normal full-compression case. They are not used by a10* transcoding-only application. Note that if an application links in11* jpeg_start_compress, it will end up linking in the entire compressor.12* We thus must separate this file from jcapimin.c to avoid linking the13* whole compression library into a transcoder.14*/1516#define JPEG_INTERNALS17#include "jinclude.h"18#include "jpeglib.h"192021/*22* Compression initialization.23* Before calling this, all parameters and a data destination must be set up.24*25* We require a write_all_tables parameter as a failsafe check when writing26* multiple datastreams from the same compression object. Since prior runs27* will have left all the tables marked sent_table=TRUE, a subsequent run28* would emit an abbreviated stream (no tables) by default. This may be what29* is wanted, but for safety's sake it should not be the default behavior:30* programmers should have to make a deliberate choice to emit abbreviated31* images. Therefore the documentation and examples should encourage people32* to pass write_all_tables=TRUE; then it will take active thought to do the33* wrong thing.34*/3536GLOBAL(void)37jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)38{39if (cinfo->global_state != CSTATE_START)40ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);4142if (write_all_tables)43jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */4445/* (Re)initialize error mgr and destination modules */46(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);47(*cinfo->dest->init_destination) (cinfo);48/* Perform master selection of active modules */49jinit_compress_master(cinfo);50/* Set up for the first pass */51(*cinfo->master->prepare_for_pass) (cinfo);52/* Ready for application to drive first pass through jpeg_write_scanlines53* or jpeg_write_raw_data.54*/55cinfo->next_scanline = 0;56cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);57}585960/*61* Write some scanlines of data to the JPEG compressor.62*63* The return value will be the number of lines actually written.64* This should be less than the supplied num_lines only in case that65* the data destination module has requested suspension of the compressor,66* or if more than image_height scanlines are passed in.67*68* Note: we warn about excess calls to jpeg_write_scanlines() since69* this likely signals an application programmer error. However,70* excess scanlines passed in the last valid call are *silently* ignored,71* so that the application need not adjust num_lines for end-of-image72* when using a multiple-scanline buffer.73*/7475GLOBAL(JDIMENSION)76jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,77JDIMENSION num_lines)78{79JDIMENSION row_ctr, rows_left;8081if (cinfo->global_state != CSTATE_SCANNING)82ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);83if (cinfo->next_scanline >= cinfo->image_height)84WARNMS(cinfo, JWRN_TOO_MUCH_DATA);8586/* Call progress monitor hook if present */87if (cinfo->progress != NULL) {88cinfo->progress->pass_counter = (long) cinfo->next_scanline;89cinfo->progress->pass_limit = (long) cinfo->image_height;90(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);91}9293/* Give master control module another chance if this is first call to94* jpeg_write_scanlines. This lets output of the frame/scan headers be95* delayed so that application can write COM, etc, markers between96* jpeg_start_compress and jpeg_write_scanlines.97*/98if (cinfo->master->call_pass_startup)99(*cinfo->master->pass_startup) (cinfo);100101/* Ignore any extra scanlines at bottom of image. */102rows_left = cinfo->image_height - cinfo->next_scanline;103if (num_lines > rows_left)104num_lines = rows_left;105106row_ctr = 0;107(*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);108cinfo->next_scanline += row_ctr;109return row_ctr;110}111112113/*114* Alternate entry point to write raw data.115* Processes exactly one iMCU row per call, unless suspended.116*/117118GLOBAL(JDIMENSION)119jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,120JDIMENSION num_lines)121{122JDIMENSION lines_per_iMCU_row;123124if (cinfo->global_state != CSTATE_RAW_OK)125ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);126if (cinfo->next_scanline >= cinfo->image_height) {127WARNMS(cinfo, JWRN_TOO_MUCH_DATA);128return 0;129}130131/* Call progress monitor hook if present */132if (cinfo->progress != NULL) {133cinfo->progress->pass_counter = (long) cinfo->next_scanline;134cinfo->progress->pass_limit = (long) cinfo->image_height;135(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);136}137138/* Give master control module another chance if this is first call to139* jpeg_write_raw_data. This lets output of the frame/scan headers be140* delayed so that application can write COM, etc, markers between141* jpeg_start_compress and jpeg_write_raw_data.142*/143if (cinfo->master->call_pass_startup)144(*cinfo->master->pass_startup) (cinfo);145146/* Verify that at least one iMCU row has been passed. */147lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;148if (num_lines < lines_per_iMCU_row)149ERREXIT(cinfo, JERR_BUFFER_SIZE);150151/* Directly compress the row. */152if (! (*cinfo->coef->compress_data) (cinfo, data)) {153/* If compressor did not consume the whole row, suspend processing. */154return 0;155}156157/* OK, we processed one iMCU row. */158cinfo->next_scanline += lines_per_iMCU_row;159return lines_per_iMCU_row;160}161162163