Final 350 project
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
includes/jcapimin.c@0:791a779d6220, 2017-07-31 (annotated)
- Committer:
- shoaib_ahmed
- Date:
- Mon Jul 31 09:16:35 2017 +0000
- Revision:
- 0:791a779d6220
final project;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shoaib_ahmed | 0:791a779d6220 | 1 | /* |
shoaib_ahmed | 0:791a779d6220 | 2 | * jcapimin.c |
shoaib_ahmed | 0:791a779d6220 | 3 | * |
shoaib_ahmed | 0:791a779d6220 | 4 | * Copyright (C) 1994-1998, Thomas G. Lane. |
shoaib_ahmed | 0:791a779d6220 | 5 | * Modified 2003-2010 by Guido Vollbeding. |
shoaib_ahmed | 0:791a779d6220 | 6 | * This file is part of the Independent JPEG Group's software. |
shoaib_ahmed | 0:791a779d6220 | 7 | * For conditions of distribution and use, see the accompanying README file. |
shoaib_ahmed | 0:791a779d6220 | 8 | * |
shoaib_ahmed | 0:791a779d6220 | 9 | * This file contains application interface code for the compression half |
shoaib_ahmed | 0:791a779d6220 | 10 | * of the JPEG library. These are the "minimum" API routines that may be |
shoaib_ahmed | 0:791a779d6220 | 11 | * needed in either the normal full-compression case or the transcoding-only |
shoaib_ahmed | 0:791a779d6220 | 12 | * case. |
shoaib_ahmed | 0:791a779d6220 | 13 | * |
shoaib_ahmed | 0:791a779d6220 | 14 | * Most of the routines intended to be called directly by an application |
shoaib_ahmed | 0:791a779d6220 | 15 | * are in this file or in jcapistd.c. But also see jcparam.c for |
shoaib_ahmed | 0:791a779d6220 | 16 | * parameter-setup helper routines, jcomapi.c for routines shared by |
shoaib_ahmed | 0:791a779d6220 | 17 | * compression and decompression, and jctrans.c for the transcoding case. |
shoaib_ahmed | 0:791a779d6220 | 18 | */ |
shoaib_ahmed | 0:791a779d6220 | 19 | |
shoaib_ahmed | 0:791a779d6220 | 20 | #define JPEG_INTERNALS |
shoaib_ahmed | 0:791a779d6220 | 21 | #include "jinclude.h" |
shoaib_ahmed | 0:791a779d6220 | 22 | #include "jpeglib.h" |
shoaib_ahmed | 0:791a779d6220 | 23 | |
shoaib_ahmed | 0:791a779d6220 | 24 | |
shoaib_ahmed | 0:791a779d6220 | 25 | /* |
shoaib_ahmed | 0:791a779d6220 | 26 | * Initialization of a JPEG compression object. |
shoaib_ahmed | 0:791a779d6220 | 27 | * The error manager must already be set up (in case memory manager fails). |
shoaib_ahmed | 0:791a779d6220 | 28 | */ |
shoaib_ahmed | 0:791a779d6220 | 29 | |
shoaib_ahmed | 0:791a779d6220 | 30 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 31 | jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize) |
shoaib_ahmed | 0:791a779d6220 | 32 | { |
shoaib_ahmed | 0:791a779d6220 | 33 | int i; |
shoaib_ahmed | 0:791a779d6220 | 34 | |
shoaib_ahmed | 0:791a779d6220 | 35 | /* Guard against version mismatches between library and caller. */ |
shoaib_ahmed | 0:791a779d6220 | 36 | cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ |
shoaib_ahmed | 0:791a779d6220 | 37 | if (version != JPEG_LIB_VERSION) |
shoaib_ahmed | 0:791a779d6220 | 38 | ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); |
shoaib_ahmed | 0:791a779d6220 | 39 | if (structsize != SIZEOF(struct jpeg_compress_struct)) |
shoaib_ahmed | 0:791a779d6220 | 40 | ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, |
shoaib_ahmed | 0:791a779d6220 | 41 | (int) SIZEOF(struct jpeg_compress_struct), (int) structsize); |
shoaib_ahmed | 0:791a779d6220 | 42 | |
shoaib_ahmed | 0:791a779d6220 | 43 | /* For debugging purposes, we zero the whole master structure. |
shoaib_ahmed | 0:791a779d6220 | 44 | * But the application has already set the err pointer, and may have set |
shoaib_ahmed | 0:791a779d6220 | 45 | * client_data, so we have to save and restore those fields. |
shoaib_ahmed | 0:791a779d6220 | 46 | * Note: if application hasn't set client_data, tools like Purify may |
shoaib_ahmed | 0:791a779d6220 | 47 | * complain here. |
shoaib_ahmed | 0:791a779d6220 | 48 | */ |
shoaib_ahmed | 0:791a779d6220 | 49 | { |
shoaib_ahmed | 0:791a779d6220 | 50 | struct jpeg_error_mgr * err = cinfo->err; |
shoaib_ahmed | 0:791a779d6220 | 51 | void * client_data = cinfo->client_data; /* ignore Purify complaint here */ |
shoaib_ahmed | 0:791a779d6220 | 52 | MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct)); |
shoaib_ahmed | 0:791a779d6220 | 53 | cinfo->err = err; |
shoaib_ahmed | 0:791a779d6220 | 54 | cinfo->client_data = client_data; |
shoaib_ahmed | 0:791a779d6220 | 55 | } |
shoaib_ahmed | 0:791a779d6220 | 56 | cinfo->is_decompressor = FALSE; |
shoaib_ahmed | 0:791a779d6220 | 57 | |
shoaib_ahmed | 0:791a779d6220 | 58 | /* Initialize a memory manager instance for this object */ |
shoaib_ahmed | 0:791a779d6220 | 59 | jinit_memory_mgr((j_common_ptr) cinfo); |
shoaib_ahmed | 0:791a779d6220 | 60 | |
shoaib_ahmed | 0:791a779d6220 | 61 | /* Zero out pointers to permanent structures. */ |
shoaib_ahmed | 0:791a779d6220 | 62 | cinfo->progress = NULL; |
shoaib_ahmed | 0:791a779d6220 | 63 | cinfo->dest = NULL; |
shoaib_ahmed | 0:791a779d6220 | 64 | |
shoaib_ahmed | 0:791a779d6220 | 65 | cinfo->comp_info = NULL; |
shoaib_ahmed | 0:791a779d6220 | 66 | |
shoaib_ahmed | 0:791a779d6220 | 67 | for (i = 0; i < NUM_QUANT_TBLS; i++) { |
shoaib_ahmed | 0:791a779d6220 | 68 | cinfo->quant_tbl_ptrs[i] = NULL; |
shoaib_ahmed | 0:791a779d6220 | 69 | cinfo->q_scale_factor[i] = 100; |
shoaib_ahmed | 0:791a779d6220 | 70 | } |
shoaib_ahmed | 0:791a779d6220 | 71 | |
shoaib_ahmed | 0:791a779d6220 | 72 | for (i = 0; i < NUM_HUFF_TBLS; i++) { |
shoaib_ahmed | 0:791a779d6220 | 73 | cinfo->dc_huff_tbl_ptrs[i] = NULL; |
shoaib_ahmed | 0:791a779d6220 | 74 | cinfo->ac_huff_tbl_ptrs[i] = NULL; |
shoaib_ahmed | 0:791a779d6220 | 75 | } |
shoaib_ahmed | 0:791a779d6220 | 76 | |
shoaib_ahmed | 0:791a779d6220 | 77 | /* Must do it here for emit_dqt in case jpeg_write_tables is used */ |
shoaib_ahmed | 0:791a779d6220 | 78 | cinfo->block_size = DCTSIZE; |
shoaib_ahmed | 0:791a779d6220 | 79 | cinfo->natural_order = jpeg_natural_order; |
shoaib_ahmed | 0:791a779d6220 | 80 | cinfo->lim_Se = DCTSIZE2-1; |
shoaib_ahmed | 0:791a779d6220 | 81 | |
shoaib_ahmed | 0:791a779d6220 | 82 | cinfo->script_space = NULL; |
shoaib_ahmed | 0:791a779d6220 | 83 | |
shoaib_ahmed | 0:791a779d6220 | 84 | cinfo->input_gamma = 1.0; /* in case application forgets */ |
shoaib_ahmed | 0:791a779d6220 | 85 | |
shoaib_ahmed | 0:791a779d6220 | 86 | /* OK, I'm ready */ |
shoaib_ahmed | 0:791a779d6220 | 87 | cinfo->global_state = CSTATE_START; |
shoaib_ahmed | 0:791a779d6220 | 88 | } |
shoaib_ahmed | 0:791a779d6220 | 89 | |
shoaib_ahmed | 0:791a779d6220 | 90 | |
shoaib_ahmed | 0:791a779d6220 | 91 | /* |
shoaib_ahmed | 0:791a779d6220 | 92 | * Destruction of a JPEG compression object |
shoaib_ahmed | 0:791a779d6220 | 93 | */ |
shoaib_ahmed | 0:791a779d6220 | 94 | |
shoaib_ahmed | 0:791a779d6220 | 95 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 96 | jpeg_destroy_compress (j_compress_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 97 | { |
shoaib_ahmed | 0:791a779d6220 | 98 | jpeg_destroy((j_common_ptr) cinfo); /* use common routine */ |
shoaib_ahmed | 0:791a779d6220 | 99 | } |
shoaib_ahmed | 0:791a779d6220 | 100 | |
shoaib_ahmed | 0:791a779d6220 | 101 | |
shoaib_ahmed | 0:791a779d6220 | 102 | /* |
shoaib_ahmed | 0:791a779d6220 | 103 | * Abort processing of a JPEG compression operation, |
shoaib_ahmed | 0:791a779d6220 | 104 | * but don't destroy the object itself. |
shoaib_ahmed | 0:791a779d6220 | 105 | */ |
shoaib_ahmed | 0:791a779d6220 | 106 | |
shoaib_ahmed | 0:791a779d6220 | 107 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 108 | jpeg_abort_compress (j_compress_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 109 | { |
shoaib_ahmed | 0:791a779d6220 | 110 | jpeg_abort((j_common_ptr) cinfo); /* use common routine */ |
shoaib_ahmed | 0:791a779d6220 | 111 | } |
shoaib_ahmed | 0:791a779d6220 | 112 | |
shoaib_ahmed | 0:791a779d6220 | 113 | |
shoaib_ahmed | 0:791a779d6220 | 114 | /* |
shoaib_ahmed | 0:791a779d6220 | 115 | * Forcibly suppress or un-suppress all quantization and Huffman tables. |
shoaib_ahmed | 0:791a779d6220 | 116 | * Marks all currently defined tables as already written (if suppress) |
shoaib_ahmed | 0:791a779d6220 | 117 | * or not written (if !suppress). This will control whether they get emitted |
shoaib_ahmed | 0:791a779d6220 | 118 | * by a subsequent jpeg_start_compress call. |
shoaib_ahmed | 0:791a779d6220 | 119 | * |
shoaib_ahmed | 0:791a779d6220 | 120 | * This routine is exported for use by applications that want to produce |
shoaib_ahmed | 0:791a779d6220 | 121 | * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but |
shoaib_ahmed | 0:791a779d6220 | 122 | * since it is called by jpeg_start_compress, we put it here --- otherwise |
shoaib_ahmed | 0:791a779d6220 | 123 | * jcparam.o would be linked whether the application used it or not. |
shoaib_ahmed | 0:791a779d6220 | 124 | */ |
shoaib_ahmed | 0:791a779d6220 | 125 | |
shoaib_ahmed | 0:791a779d6220 | 126 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 127 | jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress) |
shoaib_ahmed | 0:791a779d6220 | 128 | { |
shoaib_ahmed | 0:791a779d6220 | 129 | int i; |
shoaib_ahmed | 0:791a779d6220 | 130 | JQUANT_TBL * qtbl; |
shoaib_ahmed | 0:791a779d6220 | 131 | JHUFF_TBL * htbl; |
shoaib_ahmed | 0:791a779d6220 | 132 | |
shoaib_ahmed | 0:791a779d6220 | 133 | for (i = 0; i < NUM_QUANT_TBLS; i++) { |
shoaib_ahmed | 0:791a779d6220 | 134 | if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL) |
shoaib_ahmed | 0:791a779d6220 | 135 | qtbl->sent_table = suppress; |
shoaib_ahmed | 0:791a779d6220 | 136 | } |
shoaib_ahmed | 0:791a779d6220 | 137 | |
shoaib_ahmed | 0:791a779d6220 | 138 | for (i = 0; i < NUM_HUFF_TBLS; i++) { |
shoaib_ahmed | 0:791a779d6220 | 139 | if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL) |
shoaib_ahmed | 0:791a779d6220 | 140 | htbl->sent_table = suppress; |
shoaib_ahmed | 0:791a779d6220 | 141 | if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL) |
shoaib_ahmed | 0:791a779d6220 | 142 | htbl->sent_table = suppress; |
shoaib_ahmed | 0:791a779d6220 | 143 | } |
shoaib_ahmed | 0:791a779d6220 | 144 | } |
shoaib_ahmed | 0:791a779d6220 | 145 | |
shoaib_ahmed | 0:791a779d6220 | 146 | |
shoaib_ahmed | 0:791a779d6220 | 147 | /* |
shoaib_ahmed | 0:791a779d6220 | 148 | * Finish JPEG compression. |
shoaib_ahmed | 0:791a779d6220 | 149 | * |
shoaib_ahmed | 0:791a779d6220 | 150 | * If a multipass operating mode was selected, this may do a great deal of |
shoaib_ahmed | 0:791a779d6220 | 151 | * work including most of the actual output. |
shoaib_ahmed | 0:791a779d6220 | 152 | */ |
shoaib_ahmed | 0:791a779d6220 | 153 | |
shoaib_ahmed | 0:791a779d6220 | 154 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 155 | jpeg_finish_compress (j_compress_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 156 | { |
shoaib_ahmed | 0:791a779d6220 | 157 | JDIMENSION iMCU_row; |
shoaib_ahmed | 0:791a779d6220 | 158 | |
shoaib_ahmed | 0:791a779d6220 | 159 | if (cinfo->global_state == CSTATE_SCANNING || |
shoaib_ahmed | 0:791a779d6220 | 160 | cinfo->global_state == CSTATE_RAW_OK) { |
shoaib_ahmed | 0:791a779d6220 | 161 | /* Terminate first pass */ |
shoaib_ahmed | 0:791a779d6220 | 162 | if (cinfo->next_scanline < cinfo->image_height) |
shoaib_ahmed | 0:791a779d6220 | 163 | ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); |
shoaib_ahmed | 0:791a779d6220 | 164 | (*cinfo->master->finish_pass) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 165 | } else if (cinfo->global_state != CSTATE_WRCOEFS) |
shoaib_ahmed | 0:791a779d6220 | 166 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
shoaib_ahmed | 0:791a779d6220 | 167 | /* Perform any remaining passes */ |
shoaib_ahmed | 0:791a779d6220 | 168 | while (! cinfo->master->is_last_pass) { |
shoaib_ahmed | 0:791a779d6220 | 169 | (*cinfo->master->prepare_for_pass) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 170 | for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) { |
shoaib_ahmed | 0:791a779d6220 | 171 | if (cinfo->progress != NULL) { |
shoaib_ahmed | 0:791a779d6220 | 172 | cinfo->progress->pass_counter = (long) iMCU_row; |
shoaib_ahmed | 0:791a779d6220 | 173 | cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows; |
shoaib_ahmed | 0:791a779d6220 | 174 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); |
shoaib_ahmed | 0:791a779d6220 | 175 | } |
shoaib_ahmed | 0:791a779d6220 | 176 | /* We bypass the main controller and invoke coef controller directly; |
shoaib_ahmed | 0:791a779d6220 | 177 | * all work is being done from the coefficient buffer. |
shoaib_ahmed | 0:791a779d6220 | 178 | */ |
shoaib_ahmed | 0:791a779d6220 | 179 | if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL)) |
shoaib_ahmed | 0:791a779d6220 | 180 | ERREXIT(cinfo, JERR_CANT_SUSPEND); |
shoaib_ahmed | 0:791a779d6220 | 181 | } |
shoaib_ahmed | 0:791a779d6220 | 182 | (*cinfo->master->finish_pass) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 183 | } |
shoaib_ahmed | 0:791a779d6220 | 184 | /* Write EOI, do final cleanup */ |
shoaib_ahmed | 0:791a779d6220 | 185 | (*cinfo->marker->write_file_trailer) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 186 | (*cinfo->dest->term_destination) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 187 | /* We can use jpeg_abort to release memory and reset global_state */ |
shoaib_ahmed | 0:791a779d6220 | 188 | jpeg_abort((j_common_ptr) cinfo); |
shoaib_ahmed | 0:791a779d6220 | 189 | } |
shoaib_ahmed | 0:791a779d6220 | 190 | |
shoaib_ahmed | 0:791a779d6220 | 191 | |
shoaib_ahmed | 0:791a779d6220 | 192 | /* |
shoaib_ahmed | 0:791a779d6220 | 193 | * Write a special marker. |
shoaib_ahmed | 0:791a779d6220 | 194 | * This is only recommended for writing COM or APPn markers. |
shoaib_ahmed | 0:791a779d6220 | 195 | * Must be called after jpeg_start_compress() and before |
shoaib_ahmed | 0:791a779d6220 | 196 | * first call to jpeg_write_scanlines() or jpeg_write_raw_data(). |
shoaib_ahmed | 0:791a779d6220 | 197 | */ |
shoaib_ahmed | 0:791a779d6220 | 198 | |
shoaib_ahmed | 0:791a779d6220 | 199 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 200 | jpeg_write_marker (j_compress_ptr cinfo, int marker, |
shoaib_ahmed | 0:791a779d6220 | 201 | const JOCTET *dataptr, unsigned int datalen) |
shoaib_ahmed | 0:791a779d6220 | 202 | { |
shoaib_ahmed | 0:791a779d6220 | 203 | JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val)); |
shoaib_ahmed | 0:791a779d6220 | 204 | |
shoaib_ahmed | 0:791a779d6220 | 205 | if (cinfo->next_scanline != 0 || |
shoaib_ahmed | 0:791a779d6220 | 206 | (cinfo->global_state != CSTATE_SCANNING && |
shoaib_ahmed | 0:791a779d6220 | 207 | cinfo->global_state != CSTATE_RAW_OK && |
shoaib_ahmed | 0:791a779d6220 | 208 | cinfo->global_state != CSTATE_WRCOEFS)) |
shoaib_ahmed | 0:791a779d6220 | 209 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
shoaib_ahmed | 0:791a779d6220 | 210 | |
shoaib_ahmed | 0:791a779d6220 | 211 | (*cinfo->marker->write_marker_header) (cinfo, marker, datalen); |
shoaib_ahmed | 0:791a779d6220 | 212 | write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */ |
shoaib_ahmed | 0:791a779d6220 | 213 | while (datalen--) { |
shoaib_ahmed | 0:791a779d6220 | 214 | (*write_marker_byte) (cinfo, *dataptr); |
shoaib_ahmed | 0:791a779d6220 | 215 | dataptr++; |
shoaib_ahmed | 0:791a779d6220 | 216 | } |
shoaib_ahmed | 0:791a779d6220 | 217 | } |
shoaib_ahmed | 0:791a779d6220 | 218 | |
shoaib_ahmed | 0:791a779d6220 | 219 | /* Same, but piecemeal. */ |
shoaib_ahmed | 0:791a779d6220 | 220 | |
shoaib_ahmed | 0:791a779d6220 | 221 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 222 | jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen) |
shoaib_ahmed | 0:791a779d6220 | 223 | { |
shoaib_ahmed | 0:791a779d6220 | 224 | if (cinfo->next_scanline != 0 || |
shoaib_ahmed | 0:791a779d6220 | 225 | (cinfo->global_state != CSTATE_SCANNING && |
shoaib_ahmed | 0:791a779d6220 | 226 | cinfo->global_state != CSTATE_RAW_OK && |
shoaib_ahmed | 0:791a779d6220 | 227 | cinfo->global_state != CSTATE_WRCOEFS)) |
shoaib_ahmed | 0:791a779d6220 | 228 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
shoaib_ahmed | 0:791a779d6220 | 229 | |
shoaib_ahmed | 0:791a779d6220 | 230 | (*cinfo->marker->write_marker_header) (cinfo, marker, datalen); |
shoaib_ahmed | 0:791a779d6220 | 231 | } |
shoaib_ahmed | 0:791a779d6220 | 232 | |
shoaib_ahmed | 0:791a779d6220 | 233 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 234 | jpeg_write_m_byte (j_compress_ptr cinfo, int val) |
shoaib_ahmed | 0:791a779d6220 | 235 | { |
shoaib_ahmed | 0:791a779d6220 | 236 | (*cinfo->marker->write_marker_byte) (cinfo, val); |
shoaib_ahmed | 0:791a779d6220 | 237 | } |
shoaib_ahmed | 0:791a779d6220 | 238 | |
shoaib_ahmed | 0:791a779d6220 | 239 | |
shoaib_ahmed | 0:791a779d6220 | 240 | /* |
shoaib_ahmed | 0:791a779d6220 | 241 | * Alternate compression function: just write an abbreviated table file. |
shoaib_ahmed | 0:791a779d6220 | 242 | * Before calling this, all parameters and a data destination must be set up. |
shoaib_ahmed | 0:791a779d6220 | 243 | * |
shoaib_ahmed | 0:791a779d6220 | 244 | * To produce a pair of files containing abbreviated tables and abbreviated |
shoaib_ahmed | 0:791a779d6220 | 245 | * image data, one would proceed as follows: |
shoaib_ahmed | 0:791a779d6220 | 246 | * |
shoaib_ahmed | 0:791a779d6220 | 247 | * initialize JPEG object |
shoaib_ahmed | 0:791a779d6220 | 248 | * set JPEG parameters |
shoaib_ahmed | 0:791a779d6220 | 249 | * set destination to table file |
shoaib_ahmed | 0:791a779d6220 | 250 | * jpeg_write_tables(cinfo); |
shoaib_ahmed | 0:791a779d6220 | 251 | * set destination to image file |
shoaib_ahmed | 0:791a779d6220 | 252 | * jpeg_start_compress(cinfo, FALSE); |
shoaib_ahmed | 0:791a779d6220 | 253 | * write data... |
shoaib_ahmed | 0:791a779d6220 | 254 | * jpeg_finish_compress(cinfo); |
shoaib_ahmed | 0:791a779d6220 | 255 | * |
shoaib_ahmed | 0:791a779d6220 | 256 | * jpeg_write_tables has the side effect of marking all tables written |
shoaib_ahmed | 0:791a779d6220 | 257 | * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress |
shoaib_ahmed | 0:791a779d6220 | 258 | * will not re-emit the tables unless it is passed write_all_tables=TRUE. |
shoaib_ahmed | 0:791a779d6220 | 259 | */ |
shoaib_ahmed | 0:791a779d6220 | 260 | |
shoaib_ahmed | 0:791a779d6220 | 261 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 262 | jpeg_write_tables (j_compress_ptr cinfo) |
shoaib_ahmed | 0:791a779d6220 | 263 | { |
shoaib_ahmed | 0:791a779d6220 | 264 | if (cinfo->global_state != CSTATE_START) |
shoaib_ahmed | 0:791a779d6220 | 265 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
shoaib_ahmed | 0:791a779d6220 | 266 | |
shoaib_ahmed | 0:791a779d6220 | 267 | /* (Re)initialize error mgr and destination modules */ |
shoaib_ahmed | 0:791a779d6220 | 268 | (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); |
shoaib_ahmed | 0:791a779d6220 | 269 | (*cinfo->dest->init_destination) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 270 | /* Initialize the marker writer ... bit of a crock to do it here. */ |
shoaib_ahmed | 0:791a779d6220 | 271 | jinit_marker_writer(cinfo); |
shoaib_ahmed | 0:791a779d6220 | 272 | /* Write them tables! */ |
shoaib_ahmed | 0:791a779d6220 | 273 | (*cinfo->marker->write_tables_only) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 274 | /* And clean up. */ |
shoaib_ahmed | 0:791a779d6220 | 275 | (*cinfo->dest->term_destination) (cinfo); |
shoaib_ahmed | 0:791a779d6220 | 276 | /* |
shoaib_ahmed | 0:791a779d6220 | 277 | * In library releases up through v6a, we called jpeg_abort() here to free |
shoaib_ahmed | 0:791a779d6220 | 278 | * any working memory allocated by the destination manager and marker |
shoaib_ahmed | 0:791a779d6220 | 279 | * writer. Some applications had a problem with that: they allocated space |
shoaib_ahmed | 0:791a779d6220 | 280 | * of their own from the library memory manager, and didn't want it to go |
shoaib_ahmed | 0:791a779d6220 | 281 | * away during write_tables. So now we do nothing. This will cause a |
shoaib_ahmed | 0:791a779d6220 | 282 | * memory leak if an app calls write_tables repeatedly without doing a full |
shoaib_ahmed | 0:791a779d6220 | 283 | * compression cycle or otherwise resetting the JPEG object. However, that |
shoaib_ahmed | 0:791a779d6220 | 284 | * seems less bad than unexpectedly freeing memory in the normal case. |
shoaib_ahmed | 0:791a779d6220 | 285 | * An app that prefers the old behavior can call jpeg_abort for itself after |
shoaib_ahmed | 0:791a779d6220 | 286 | * each call to jpeg_write_tables(). |
shoaib_ahmed | 0:791a779d6220 | 287 | */ |
shoaib_ahmed | 0:791a779d6220 | 288 | } |