/src/libjpeg-turbo.main/jcapistd.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * jcapistd.c | 
| 3 |  |  * | 
| 4 |  |  * This file was part of the Independent JPEG Group's software: | 
| 5 |  |  * Copyright (C) 1994-1996, Thomas G. Lane. | 
| 6 |  |  * libjpeg-turbo Modifications: | 
| 7 |  |  * Copyright (C) 2022, D. R. Commander. | 
| 8 |  |  * For conditions of distribution and use, see the accompanying README.ijg | 
| 9 |  |  * file. | 
| 10 |  |  * | 
| 11 |  |  * This file contains application interface code for the compression half | 
| 12 |  |  * of the JPEG library.  These are the "standard" API routines that are | 
| 13 |  |  * used in the normal full-compression case.  They are not used by a | 
| 14 |  |  * transcoding-only application.  Note that if an application links in | 
| 15 |  |  * jpeg_start_compress, it will end up linking in the entire compressor. | 
| 16 |  |  * We thus must separate this file from jcapimin.c to avoid linking the | 
| 17 |  |  * whole compression library into a transcoder. | 
| 18 |  |  */ | 
| 19 |  |  | 
| 20 |  | #define JPEG_INTERNALS | 
| 21 |  | #include "jinclude.h" | 
| 22 |  | #include "jpeglib.h" | 
| 23 |  | #include "jsamplecomp.h" | 
| 24 |  |  | 
| 25 |  |  | 
| 26 |  | #if BITS_IN_JSAMPLE == 8 | 
| 27 |  |  | 
| 28 |  | /* | 
| 29 |  |  * Compression initialization. | 
| 30 |  |  * Before calling this, all parameters and a data destination must be set up. | 
| 31 |  |  * | 
| 32 |  |  * We require a write_all_tables parameter as a failsafe check when writing | 
| 33 |  |  * multiple datastreams from the same compression object.  Since prior runs | 
| 34 |  |  * will have left all the tables marked sent_table=TRUE, a subsequent run | 
| 35 |  |  * would emit an abbreviated stream (no tables) by default.  This may be what | 
| 36 |  |  * is wanted, but for safety's sake it should not be the default behavior: | 
| 37 |  |  * programmers should have to make a deliberate choice to emit abbreviated | 
| 38 |  |  * images.  Therefore the documentation and examples should encourage people | 
| 39 |  |  * to pass write_all_tables=TRUE; then it will take active thought to do the | 
| 40 |  |  * wrong thing. | 
| 41 |  |  */ | 
| 42 |  |  | 
| 43 |  | GLOBAL(void) | 
| 44 |  | jpeg_start_compress(j_compress_ptr cinfo, boolean write_all_tables) | 
| 45 | 13.1k | { | 
| 46 | 13.1k |   if (cinfo->global_state != CSTATE_START) | 
| 47 | 0 |     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 
| 48 |  |  | 
| 49 | 13.1k |   if (write_all_tables) | 
| 50 | 13.1k |     jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */ | 
| 51 |  |  | 
| 52 |  |   /* (Re)initialize error mgr and destination modules */ | 
| 53 | 13.1k |   (*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo); | 
| 54 | 13.1k |   (*cinfo->dest->init_destination) (cinfo); | 
| 55 |  |   /* Perform master selection of active modules */ | 
| 56 | 13.1k |   jinit_compress_master(cinfo); | 
| 57 |  |   /* Set up for the first pass */ | 
| 58 | 13.1k |   (*cinfo->master->prepare_for_pass) (cinfo); | 
| 59 |  |   /* Ready for application to drive first pass through _jpeg_write_scanlines | 
| 60 |  |    * or _jpeg_write_raw_data. | 
| 61 |  |    */ | 
| 62 | 13.1k |   cinfo->next_scanline = 0; | 
| 63 | 13.1k |   cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING); | 
| 64 | 13.1k | } | 
| 65 |  |  | 
| 66 |  | #endif | 
| 67 |  |  | 
| 68 |  |  | 
| 69 |  | /* | 
| 70 |  |  * Write some scanlines of data to the JPEG compressor. | 
| 71 |  |  * | 
| 72 |  |  * The return value will be the number of lines actually written. | 
| 73 |  |  * This should be less than the supplied num_lines only in case that | 
| 74 |  |  * the data destination module has requested suspension of the compressor, | 
| 75 |  |  * or if more than image_height scanlines are passed in. | 
| 76 |  |  * | 
| 77 |  |  * Note: we warn about excess calls to _jpeg_write_scanlines() since | 
| 78 |  |  * this likely signals an application programmer error.  However, | 
| 79 |  |  * excess scanlines passed in the last valid call are *silently* ignored, | 
| 80 |  |  * so that the application need not adjust num_lines for end-of-image | 
| 81 |  |  * when using a multiple-scanline buffer. | 
| 82 |  |  */ | 
| 83 |  |  | 
| 84 |  | GLOBAL(JDIMENSION) | 
| 85 |  | _jpeg_write_scanlines(j_compress_ptr cinfo, _JSAMPARRAY scanlines, | 
| 86 |  |                       JDIMENSION num_lines) | 
| 87 | 13.0k | { | 
| 88 | 13.0k | #if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) | 
| 89 | 13.0k |   JDIMENSION row_ctr, rows_left; | 
| 90 |  |  | 
| 91 | 13.0k |   if (cinfo->data_precision != BITS_IN_JSAMPLE) | 
| 92 | 0 |     ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 
| 93 |  |  | 
| 94 | 13.0k |   if (cinfo->global_state != CSTATE_SCANNING) | 
| 95 | 0 |     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 
| 96 | 13.0k |   if (cinfo->next_scanline >= cinfo->image_height) | 
| 97 | 0 |     WARNMS(cinfo, JWRN_TOO_MUCH_DATA); | 
| 98 |  |  | 
| 99 |  |   /* Call progress monitor hook if present */ | 
| 100 | 13.0k |   if (cinfo->progress != NULL) { | 
| 101 | 0 |     cinfo->progress->pass_counter = (long)cinfo->next_scanline; | 
| 102 | 0 |     cinfo->progress->pass_limit = (long)cinfo->image_height; | 
| 103 | 0 |     (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); | 
| 104 | 0 |   } | 
| 105 |  |  | 
| 106 |  |   /* Give master control module another chance if this is first call to | 
| 107 |  |    * _jpeg_write_scanlines.  This lets output of the frame/scan headers be | 
| 108 |  |    * delayed so that application can write COM, etc, markers between | 
| 109 |  |    * jpeg_start_compress and _jpeg_write_scanlines. | 
| 110 |  |    */ | 
| 111 | 13.0k |   if (cinfo->master->call_pass_startup) | 
| 112 | 3.83k |     (*cinfo->master->pass_startup) (cinfo); | 
| 113 |  |  | 
| 114 |  |   /* Ignore any extra scanlines at bottom of image. */ | 
| 115 | 13.0k |   rows_left = cinfo->image_height - cinfo->next_scanline; | 
| 116 | 13.0k |   if (num_lines > rows_left) | 
| 117 | 0 |     num_lines = rows_left; | 
| 118 |  |  | 
| 119 | 13.0k |   row_ctr = 0; | 
| 120 | 13.0k |   (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, num_lines); | 
| 121 | 13.0k |   cinfo->next_scanline += row_ctr; | 
| 122 | 13.0k |   return row_ctr; | 
| 123 |  | #else | 
| 124 |  |   ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 
| 125 |  |   return 0; | 
| 126 |  | #endif | 
| 127 | 13.0k | } | Line | Count | Source |  | 87 | 13.0k | { |  | 88 | 13.0k | #if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) |  | 89 | 13.0k |   JDIMENSION row_ctr, rows_left; |  | 90 |  |  |  | 91 | 13.0k |   if (cinfo->data_precision != BITS_IN_JSAMPLE) |  | 92 | 0 |     ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |  | 93 |  |  |  | 94 | 13.0k |   if (cinfo->global_state != CSTATE_SCANNING) |  | 95 | 0 |     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |  | 96 | 13.0k |   if (cinfo->next_scanline >= cinfo->image_height) |  | 97 | 0 |     WARNMS(cinfo, JWRN_TOO_MUCH_DATA); |  | 98 |  |  |  | 99 |  |   /* Call progress monitor hook if present */ |  | 100 | 13.0k |   if (cinfo->progress != NULL) { |  | 101 | 0 |     cinfo->progress->pass_counter = (long)cinfo->next_scanline; |  | 102 | 0 |     cinfo->progress->pass_limit = (long)cinfo->image_height; |  | 103 | 0 |     (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); |  | 104 | 0 |   } |  | 105 |  |  |  | 106 |  |   /* Give master control module another chance if this is first call to |  | 107 |  |    * _jpeg_write_scanlines.  This lets output of the frame/scan headers be |  | 108 |  |    * delayed so that application can write COM, etc, markers between |  | 109 |  |    * jpeg_start_compress and _jpeg_write_scanlines. |  | 110 |  |    */ |  | 111 | 13.0k |   if (cinfo->master->call_pass_startup) |  | 112 | 3.83k |     (*cinfo->master->pass_startup) (cinfo); |  | 113 |  |  |  | 114 |  |   /* Ignore any extra scanlines at bottom of image. */ |  | 115 | 13.0k |   rows_left = cinfo->image_height - cinfo->next_scanline; |  | 116 | 13.0k |   if (num_lines > rows_left) |  | 117 | 0 |     num_lines = rows_left; |  | 118 |  |  |  | 119 | 13.0k |   row_ctr = 0; |  | 120 | 13.0k |   (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, num_lines); |  | 121 | 13.0k |   cinfo->next_scanline += row_ctr; |  | 122 | 13.0k |   return row_ctr; |  | 123 |  | #else |  | 124 |  |   ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |  | 125 |  |   return 0; |  | 126 |  | #endif |  | 127 | 13.0k | } | 
Unexecuted instantiation: jpeg16_write_scanlinesUnexecuted instantiation: jpeg_write_scanlines | 
| 128 |  |  | 
| 129 |  |  | 
| 130 |  | #if BITS_IN_JSAMPLE != 16 | 
| 131 |  |  | 
| 132 |  | /* | 
| 133 |  |  * Alternate entry point to write raw data. | 
| 134 |  |  * Processes exactly one iMCU row per call, unless suspended. | 
| 135 |  |  */ | 
| 136 |  |  | 
| 137 |  | GLOBAL(JDIMENSION) | 
| 138 |  | _jpeg_write_raw_data(j_compress_ptr cinfo, _JSAMPIMAGE data, | 
| 139 |  |                      JDIMENSION num_lines) | 
| 140 | 0 | { | 
| 141 | 0 |   JDIMENSION lines_per_iMCU_row; | 
| 142 |  | 
 | 
| 143 | 0 |   if (cinfo->data_precision != BITS_IN_JSAMPLE) | 
| 144 | 0 |     ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 
| 145 |  | 
 | 
| 146 | 0 |   if (cinfo->master->lossless) | 
| 147 | 0 |     ERREXIT(cinfo, JERR_NOTIMPL); | 
| 148 |  | 
 | 
| 149 | 0 |   if (cinfo->global_state != CSTATE_RAW_OK) | 
| 150 | 0 |     ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 
| 151 | 0 |   if (cinfo->next_scanline >= cinfo->image_height) { | 
| 152 | 0 |     WARNMS(cinfo, JWRN_TOO_MUCH_DATA); | 
| 153 | 0 |     return 0; | 
| 154 | 0 |   } | 
| 155 |  |  | 
| 156 |  |   /* Call progress monitor hook if present */ | 
| 157 | 0 |   if (cinfo->progress != NULL) { | 
| 158 | 0 |     cinfo->progress->pass_counter = (long)cinfo->next_scanline; | 
| 159 | 0 |     cinfo->progress->pass_limit = (long)cinfo->image_height; | 
| 160 | 0 |     (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); | 
| 161 | 0 |   } | 
| 162 |  |  | 
| 163 |  |   /* Give master control module another chance if this is first call to | 
| 164 |  |    * _jpeg_write_raw_data.  This lets output of the frame/scan headers be | 
| 165 |  |    * delayed so that application can write COM, etc, markers between | 
| 166 |  |    * jpeg_start_compress and _jpeg_write_raw_data. | 
| 167 |  |    */ | 
| 168 | 0 |   if (cinfo->master->call_pass_startup) | 
| 169 | 0 |     (*cinfo->master->pass_startup) (cinfo); | 
| 170 |  |  | 
| 171 |  |   /* Verify that at least one iMCU row has been passed. */ | 
| 172 | 0 |   lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE; | 
| 173 | 0 |   if (num_lines < lines_per_iMCU_row) | 
| 174 | 0 |     ERREXIT(cinfo, JERR_BUFFER_SIZE); | 
| 175 |  |  | 
| 176 |  |   /* Directly compress the row. */ | 
| 177 | 0 |   if (!(*cinfo->coef->_compress_data) (cinfo, data)) { | 
| 178 |  |     /* If compressor did not consume the whole row, suspend processing. */ | 
| 179 | 0 |     return 0; | 
| 180 | 0 |   } | 
| 181 |  |  | 
| 182 |  |   /* OK, we processed one iMCU row. */ | 
| 183 | 0 |   cinfo->next_scanline += lines_per_iMCU_row; | 
| 184 | 0 |   return lines_per_iMCU_row; | 
| 185 | 0 | } Unexecuted instantiation: jpeg12_write_raw_dataUnexecuted instantiation: jpeg_write_raw_data | 
| 186 |  |  | 
| 187 |  | #endif /* BITS_IN_JSAMPLE != 16 */ |