| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#define JPEG_INTERNALS |
| 20 |
#include "jinclude.h" |
| 21 |
#include "jpeglib.h" |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
GLOBAL(void) |
| 30 |
jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize) |
| 31 |
{ |
| 32 |
int i; |
| 33 |
|
| 34 |
|
| 35 |
cinfo->mem = NULL; |
| 36 |
if (version != JPEG_LIB_VERSION) |
| 37 |
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); |
| 38 |
if (structsize != SIZEOF(struct jpeg_compress_struct)) |
| 39 |
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, |
| 40 |
(int) SIZEOF(struct jpeg_compress_struct), (int) structsize); |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
{ |
| 49 |
struct jpeg_error_mgr * err = cinfo->err; |
| 50 |
void * client_data = cinfo->client_data; |
| 51 |
MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct)); |
| 52 |
cinfo->err = err; |
| 53 |
cinfo->client_data = client_data; |
| 54 |
} |
| 55 |
cinfo->is_decompressor = FALSE; |
| 56 |
|
| 57 |
|
| 58 |
jinit_memory_mgr((j_common_ptr) cinfo); |
| 59 |
|
| 60 |
|
| 61 |
cinfo->progress = NULL; |
| 62 |
cinfo->dest = NULL; |
| 63 |
|
| 64 |
cinfo->comp_info = NULL; |
| 65 |
|
| 66 |
for (i = 0; i < NUM_QUANT_TBLS; i++) |
| 67 |
cinfo->quant_tbl_ptrs[i] = NULL; |
| 68 |
|
| 69 |
for (i = 0; i < NUM_HUFF_TBLS; i++) { |
| 70 |
cinfo->dc_huff_tbl_ptrs[i] = NULL; |
| 71 |
cinfo->ac_huff_tbl_ptrs[i] = NULL; |
| 72 |
} |
| 73 |
|
| 74 |
cinfo->script_space = NULL; |
| 75 |
|
| 76 |
cinfo->input_gamma = 1.0; |
| 77 |
|
| 78 |
|
| 79 |
cinfo->global_state = CSTATE_START; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
GLOBAL(void) |
| 88 |
jpeg_destroy_compress (j_compress_ptr cinfo) |
| 89 |
{ |
| 90 |
jpeg_destroy((j_common_ptr) cinfo); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
GLOBAL(void) |
| 100 |
jpeg_abort_compress (j_compress_ptr cinfo) |
| 101 |
{ |
| 102 |
jpeg_abort((j_common_ptr) cinfo); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
GLOBAL(void) |
| 119 |
jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress) |
| 120 |
{ |
| 121 |
int i; |
| 122 |
JQUANT_TBL * qtbl; |
| 123 |
JHUFF_TBL * htbl; |
| 124 |
|
| 125 |
for (i = 0; i < NUM_QUANT_TBLS; i++) { |
| 126 |
if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL) |
| 127 |
qtbl->sent_table = suppress; |
| 128 |
} |
| 129 |
|
| 130 |
for (i = 0; i < NUM_HUFF_TBLS; i++) { |
| 131 |
if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL) |
| 132 |
htbl->sent_table = suppress; |
| 133 |
if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL) |
| 134 |
htbl->sent_table = suppress; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
GLOBAL(void) |
| 147 |
jpeg_finish_compress (j_compress_ptr cinfo) |
| 148 |
{ |
| 149 |
JDIMENSION iMCU_row; |
| 150 |
|
| 151 |
if (cinfo->global_state == CSTATE_SCANNING || |
| 152 |
cinfo->global_state == CSTATE_RAW_OK) { |
| 153 |
|
| 154 |
if (cinfo->next_scanline < cinfo->image_height) |
| 155 |
ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); |
| 156 |
(*cinfo->master->finish_pass) (cinfo); |
| 157 |
} else if (cinfo->global_state != CSTATE_WRCOEFS) |
| 158 |
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
| 159 |
|
| 160 |
while (! cinfo->master->is_last_pass) { |
| 161 |
(*cinfo->master->prepare_for_pass) (cinfo); |
| 162 |
for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) { |
| 163 |
if (cinfo->progress != NULL) { |
| 164 |
cinfo->progress->pass_counter = (long) iMCU_row; |
| 165 |
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows; |
| 166 |
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL)) |
| 172 |
ERREXIT(cinfo, JERR_CANT_SUSPEND); |
| 173 |
} |
| 174 |
(*cinfo->master->finish_pass) (cinfo); |
| 175 |
} |
| 176 |
|
| 177 |
(*cinfo->marker->write_file_trailer) (cinfo); |
| 178 |
(*cinfo->dest->term_destination) (cinfo); |
| 179 |
|
| 180 |
jpeg_abort((j_common_ptr) cinfo); |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
GLOBAL(void) |
| 192 |
jpeg_write_marker (j_compress_ptr cinfo, int marker, |
| 193 |
const JOCTET *dataptr, unsigned int datalen) |
| 194 |
{ |
| 195 |
JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val)); |
| 196 |
|
| 197 |
if (cinfo->next_scanline != 0 || |
| 198 |
(cinfo->global_state != CSTATE_SCANNING && |
| 199 |
cinfo->global_state != CSTATE_RAW_OK && |
| 200 |
cinfo->global_state != CSTATE_WRCOEFS)) |
| 201 |
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
| 202 |
|
| 203 |
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen); |
| 204 |
write_marker_byte = cinfo->marker->write_marker_byte; |
| 205 |
while (datalen--) { |
| 206 |
(*write_marker_byte) (cinfo, *dataptr); |
| 207 |
dataptr++; |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
GLOBAL(void) |
| 214 |
jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen) |
| 215 |
{ |
| 216 |
if (cinfo->next_scanline != 0 || |
| 217 |
(cinfo->global_state != CSTATE_SCANNING && |
| 218 |
cinfo->global_state != CSTATE_RAW_OK && |
| 219 |
cinfo->global_state != CSTATE_WRCOEFS)) |
| 220 |
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
| 221 |
|
| 222 |
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen); |
| 223 |
} |
| 224 |
|
| 225 |
GLOBAL(void) |
| 226 |
jpeg_write_m_byte (j_compress_ptr cinfo, int val) |
| 227 |
{ |
| 228 |
(*cinfo->marker->write_marker_byte) (cinfo, val); |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
GLOBAL(void) |
| 254 |
jpeg_write_tables (j_compress_ptr cinfo) |
| 255 |
{ |
| 256 |
if (cinfo->global_state != CSTATE_START) |
| 257 |
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
| 258 |
|
| 259 |
|
| 260 |
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); |
| 261 |
(*cinfo->dest->init_destination) (cinfo); |
| 262 |
|
| 263 |
jinit_marker_writer(cinfo); |
| 264 |
|
| 265 |
(*cinfo->marker->write_tables_only) (cinfo); |
| 266 |
|
| 267 |
(*cinfo->dest->term_destination) (cinfo); |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
} |