Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
jcapistd.c
00001 /* 00002 * jcapistd.c 00003 * 00004 * Copyright (C) 1994-1996, Thomas G. Lane. 00005 * Modified 2013 by Guido Vollbeding. 00006 * This file is part of the Independent JPEG Group's software. 00007 * For conditions of distribution and use, see the accompanying README file. 00008 * 00009 * This file contains application interface code for the compression half 00010 * of the JPEG library. These are the "standard" API routines that are 00011 * used in the normal full-compression case. They are not used by a 00012 * transcoding-only application. Note that if an application links in 00013 * jpeg_start_compress, it will end up linking in the entire compressor. 00014 * We thus must separate this file from jcapimin.c to avoid linking the 00015 * whole compression library into a transcoder. 00016 */ 00017 00018 #define JPEG_INTERNALS 00019 #include "jinclude.h" 00020 #include "jpeglib.h" 00021 00022 00023 /* 00024 * Compression initialization. 00025 * Before calling this, all parameters and a data destination must be set up. 00026 * 00027 * We require a write_all_tables parameter as a failsafe check when writing 00028 * multiple datastreams from the same compression object. Since prior runs 00029 * will have left all the tables marked sent_table=TRUE, a subsequent run 00030 * would emit an abbreviated stream (no tables) by default. This may be what 00031 * is wanted, but for safety's sake it should not be the default behavior: 00032 * programmers should have to make a deliberate choice to emit abbreviated 00033 * images. Therefore the documentation and examples should encourage people 00034 * to pass write_all_tables=TRUE; then it will take active thought to do the 00035 * wrong thing. 00036 */ 00037 00038 GLOBAL(void) 00039 jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables) 00040 { 00041 if (cinfo->global_state != CSTATE_START) 00042 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 00043 00044 if (write_all_tables) 00045 jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */ 00046 00047 /* (Re)initialize error mgr and destination modules */ 00048 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); 00049 (*cinfo->dest->init_destination) (cinfo); 00050 /* Perform master selection of active modules */ 00051 jinit_compress_master(cinfo); 00052 /* Set up for the first pass */ 00053 (*cinfo->master->prepare_for_pass) (cinfo); 00054 /* Ready for application to drive first pass through jpeg_write_scanlines 00055 * or jpeg_write_raw_data. 00056 */ 00057 cinfo->next_scanline = 0; 00058 cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING); 00059 } 00060 00061 00062 /* 00063 * Write some scanlines of data to the JPEG compressor. 00064 * 00065 * The return value will be the number of lines actually written. 00066 * This should be less than the supplied num_lines only in case that 00067 * the data destination module has requested suspension of the compressor, 00068 * or if more than image_height scanlines are passed in. 00069 * 00070 * Note: we warn about excess calls to jpeg_write_scanlines() since 00071 * this likely signals an application programmer error. However, 00072 * excess scanlines passed in the last valid call are *silently* ignored, 00073 * so that the application need not adjust num_lines for end-of-image 00074 * when using a multiple-scanline buffer. 00075 */ 00076 00077 GLOBAL(JDIMENSION) 00078 jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, 00079 JDIMENSION num_lines) 00080 { 00081 JDIMENSION row_ctr, rows_left; 00082 00083 if (cinfo->global_state != CSTATE_SCANNING) 00084 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 00085 if (cinfo->next_scanline >= cinfo->image_height) 00086 WARNMS(cinfo, JWRN_TOO_MUCH_DATA); 00087 00088 /* Call progress monitor hook if present */ 00089 if (cinfo->progress != NULL) { 00090 cinfo->progress->pass_counter = (long) cinfo->next_scanline; 00091 cinfo->progress->pass_limit = (long) cinfo->image_height; 00092 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 00093 } 00094 00095 /* Give master control module another chance if this is first call to 00096 * jpeg_write_scanlines. This lets output of the frame/scan headers be 00097 * delayed so that application can write COM, etc, markers between 00098 * jpeg_start_compress and jpeg_write_scanlines. 00099 */ 00100 if (cinfo->master->call_pass_startup) 00101 (*cinfo->master->pass_startup) (cinfo); 00102 00103 /* Ignore any extra scanlines at bottom of image. */ 00104 rows_left = cinfo->image_height - cinfo->next_scanline; 00105 if (num_lines > rows_left) 00106 num_lines = rows_left; 00107 00108 row_ctr = 0; 00109 (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines); 00110 cinfo->next_scanline += row_ctr; 00111 return row_ctr; 00112 } 00113 00114 00115 /* 00116 * Alternate entry point to write raw data. 00117 * Processes exactly one iMCU row per call, unless suspended. 00118 */ 00119 00120 GLOBAL(JDIMENSION) 00121 jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, 00122 JDIMENSION num_lines) 00123 { 00124 JDIMENSION lines_per_iMCU_row; 00125 00126 if (cinfo->global_state != CSTATE_RAW_OK) 00127 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 00128 if (cinfo->next_scanline >= cinfo->image_height) { 00129 WARNMS(cinfo, JWRN_TOO_MUCH_DATA); 00130 return 0; 00131 } 00132 00133 /* Call progress monitor hook if present */ 00134 if (cinfo->progress != NULL) { 00135 cinfo->progress->pass_counter = (long) cinfo->next_scanline; 00136 cinfo->progress->pass_limit = (long) cinfo->image_height; 00137 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 00138 } 00139 00140 /* Give master control module another chance if this is first call to 00141 * jpeg_write_raw_data. This lets output of the frame/scan headers be 00142 * delayed so that application can write COM, etc, markers between 00143 * jpeg_start_compress and jpeg_write_raw_data. 00144 */ 00145 if (cinfo->master->call_pass_startup) 00146 (*cinfo->master->pass_startup) (cinfo); 00147 00148 /* Verify that at least one iMCU row has been passed. */ 00149 lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size; 00150 if (num_lines < lines_per_iMCU_row) 00151 ERREXIT(cinfo, JERR_BUFFER_SIZE); 00152 00153 /* Directly compress the row. */ 00154 if (! (*cinfo->coef->compress_data) (cinfo, data)) { 00155 /* If compressor did not consume the whole row, suspend processing. */ 00156 return 0; 00157 } 00158 00159 /* OK, we processed one iMCU row. */ 00160 cinfo->next_scanline += lines_per_iMCU_row; 00161 return lines_per_iMCU_row; 00162 }
Generated on Wed Jul 13 2022 18:56:09 by
