/src/libjpeg-turbo.main/src/turbojpeg-mp.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2009-2026 D. R. Commander |
3 | | * |
4 | | * Redistribution and use in source and binary forms, with or without |
5 | | * modification, are permitted provided that the following conditions are met: |
6 | | * |
7 | | * - Redistributions of source code must retain the above copyright notice, |
8 | | * this list of conditions and the following disclaimer. |
9 | | * - Redistributions in binary form must reproduce the above copyright notice, |
10 | | * this list of conditions and the following disclaimer in the documentation |
11 | | * and/or other materials provided with the distribution. |
12 | | * - Neither the name of the libjpeg-turbo Project nor the names of its |
13 | | * contributors may be used to endorse or promote products derived from this |
14 | | * software without specific prior written permission. |
15 | | * |
16 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", |
17 | | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
20 | | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | | * POSSIBILITY OF SUCH DAMAGE. |
27 | | */ |
28 | | |
29 | | /* TurboJPEG API functions that must be compiled for multiple data |
30 | | precisions */ |
31 | | |
32 | | #if BITS_IN_JSAMPLE == 8 |
33 | 36.2M | #define _JSAMPLE JSAMPLE |
34 | 27.2k | #define _JSAMPROW JSAMPROW |
35 | 36.2M | #define _buffer buffer |
36 | 28.7k | #define _jinit_read_png jinit_read_png |
37 | 0 | #define _jinit_write_png jinit_write_png |
38 | 18.3k | #define _jinit_read_ppm jinit_read_ppm |
39 | 0 | #define _jinit_write_ppm jinit_write_ppm |
40 | 0 | #define _jpeg_crop_scanline jpeg_crop_scanline |
41 | 0 | #define _jpeg_read_scanlines jpeg_read_scanlines |
42 | 0 | #define _jpeg_skip_scanlines jpeg_skip_scanlines |
43 | 27.2k | #define _jpeg_write_scanlines jpeg_write_scanlines |
44 | | #elif BITS_IN_JSAMPLE == 12 |
45 | 0 | #define _JSAMPLE J12SAMPLE |
46 | 0 | #define _JSAMPROW J12SAMPROW |
47 | 0 | #define _buffer buffer12 |
48 | 0 | #define _jinit_read_png j12init_read_png |
49 | 0 | #define _jinit_write_png j12init_write_png |
50 | 0 | #define _jinit_read_ppm j12init_read_ppm |
51 | 0 | #define _jinit_write_ppm j12init_write_ppm |
52 | 0 | #define _jpeg_crop_scanline jpeg12_crop_scanline |
53 | 0 | #define _jpeg_read_scanlines jpeg12_read_scanlines |
54 | 0 | #define _jpeg_skip_scanlines jpeg12_skip_scanlines |
55 | 0 | #define _jpeg_write_scanlines jpeg12_write_scanlines |
56 | | #elif BITS_IN_JSAMPLE == 16 |
57 | 0 | #define _JSAMPLE J16SAMPLE |
58 | 0 | #define _JSAMPROW J16SAMPROW |
59 | 0 | #define _buffer buffer16 |
60 | 0 | #define _jinit_read_png j16init_read_png |
61 | 0 | #define _jinit_write_png j16init_write_png |
62 | 0 | #define _jinit_read_ppm j16init_read_ppm |
63 | 0 | #define _jinit_write_ppm j16init_write_ppm |
64 | 0 | #define _jpeg_read_scanlines jpeg16_read_scanlines |
65 | 0 | #define _jpeg_write_scanlines jpeg16_write_scanlines |
66 | | #endif |
67 | | |
68 | 0 | #define _GET_NAME(name, suffix) name##suffix |
69 | 0 | #define GET_NAME(name, suffix) _GET_NAME(name, suffix) |
70 | 81.7k | #define _GET_STRING(name, suffix) #name #suffix |
71 | 81.7k | #define GET_STRING(name, suffix) _GET_STRING(name, suffix) |
72 | | |
73 | | |
74 | | /******************************** Compressor *********************************/ |
75 | | |
76 | | /* TurboJPEG 3.0+ */ |
77 | | DLLEXPORT int GET_NAME(tj3Compress, BITS_IN_JSAMPLE) |
78 | | (tjhandle handle, const _JSAMPLE *srcBuf, int width, int pitch, int height, |
79 | | int pixelFormat, unsigned char **jpegBuf, size_t *jpegSize) |
80 | 27.2k | { |
81 | 27.2k | static const char FUNCTION_NAME[] = GET_STRING(tj3Compress, BITS_IN_JSAMPLE); |
82 | 27.2k | int i, retval = 0; |
83 | 27.2k | boolean alloc = TRUE; |
84 | 27.2k | _JSAMPROW *row_pointer = NULL; |
85 | | |
86 | 27.2k | GET_CINSTANCE(handle) |
87 | 27.2k | if ((this->init & COMPRESS) == 0) |
88 | 27.2k | THROW("Instance has not been initialized for compression"); |
89 | | |
90 | 27.2k | if (srcBuf == NULL || width <= 0 || pitch < 0 || height <= 0 || |
91 | 27.2k | pixelFormat < 0 || pixelFormat >= TJ_NUMPF || jpegBuf == NULL || |
92 | 27.2k | jpegSize == NULL) |
93 | 27.2k | THROW("Invalid argument"); |
94 | | |
95 | 27.2k | if (!this->lossless && this->quality == -1) |
96 | 27.2k | THROW("TJPARAM_QUALITY must be specified"); |
97 | 27.2k | if (!this->lossless && this->subsamp == TJSAMP_UNKNOWN) |
98 | 27.2k | THROW("TJPARAM_SUBSAMP must be specified"); |
99 | | |
100 | 27.2k | if (pitch == 0) pitch = width * tjPixelSize[pixelFormat]; |
101 | 0 | else if (pitch < width * tjPixelSize[pixelFormat]) |
102 | 27.2k | THROW("Invalid argument"); |
103 | | |
104 | 27.2k | if ((row_pointer = (_JSAMPROW *)malloc(sizeof(_JSAMPROW) * height)) == NULL) |
105 | 27.2k | THROW("Memory allocation failure"); |
106 | | |
107 | 27.2k | CATCH_LIBJPEG(this); |
108 | | |
109 | 27.2k | cinfo->image_width = width; |
110 | 27.2k | cinfo->image_height = height; |
111 | 27.2k | cinfo->data_precision = BITS_IN_JSAMPLE; |
112 | | #if BITS_IN_JSAMPLE == 8 |
113 | 27.2k | if (this->lossless && this->precision >= 2 && |
114 | 0 | this->precision <= BITS_IN_JSAMPLE) |
115 | | #else |
116 | 0 | if (this->lossless && this->precision >= BITS_IN_JSAMPLE - 3 && |
117 | 0 | this->precision <= BITS_IN_JSAMPLE) |
118 | 0 | #endif |
119 | 0 | cinfo->data_precision = this->precision; |
120 | | |
121 | 27.2k | setCompDefaults(this, pixelFormat, FALSE); |
122 | 27.2k | if (this->noRealloc) alloc = FALSE; |
123 | 27.2k | jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc); |
124 | | |
125 | 27.2k | jpeg_start_compress(cinfo, TRUE); |
126 | 27.2k | if (this->iccBuf != NULL && this->iccSize != 0) |
127 | 24.2k | jpeg_write_icc_profile(cinfo, this->iccBuf, (unsigned int)this->iccSize); |
128 | 36.0M | for (i = 0; i < height; i++) { |
129 | 36.0M | if (this->bottomUp) |
130 | 5.39M | row_pointer[i] = (_JSAMPROW)&srcBuf[(height - i - 1) * (size_t)pitch]; |
131 | 30.6M | else |
132 | 30.6M | row_pointer[i] = (_JSAMPROW)&srcBuf[i * (size_t)pitch]; |
133 | 36.0M | } |
134 | 54.4k | while (cinfo->next_scanline < cinfo->image_height) |
135 | 27.2k | _jpeg_write_scanlines(cinfo, &row_pointer[cinfo->next_scanline], |
136 | 27.2k | cinfo->image_height - cinfo->next_scanline); |
137 | 27.2k | jpeg_finish_compress(cinfo); |
138 | | |
139 | 27.2k | bailout: |
140 | 27.2k | if (cinfo->global_state > CSTATE_START && alloc) |
141 | 0 | (*cinfo->dest->term_destination) (cinfo); |
142 | 27.2k | if (cinfo->global_state > CSTATE_START || retval == -1) |
143 | 0 | jpeg_abort_compress(cinfo); |
144 | 27.2k | free(row_pointer); |
145 | 27.2k | if (this->jerr.warning) retval = -1; |
146 | 27.2k | return retval; |
147 | 27.2k | } Line | Count | Source | 80 | 27.2k | { | 81 | 27.2k | static const char FUNCTION_NAME[] = GET_STRING(tj3Compress, BITS_IN_JSAMPLE); | 82 | 27.2k | int i, retval = 0; | 83 | 27.2k | boolean alloc = TRUE; | 84 | 27.2k | _JSAMPROW *row_pointer = NULL; | 85 | | | 86 | 27.2k | GET_CINSTANCE(handle) | 87 | 27.2k | if ((this->init & COMPRESS) == 0) | 88 | 27.2k | THROW("Instance has not been initialized for compression"); | 89 | | | 90 | 27.2k | if (srcBuf == NULL || width <= 0 || pitch < 0 || height <= 0 || | 91 | 27.2k | pixelFormat < 0 || pixelFormat >= TJ_NUMPF || jpegBuf == NULL || | 92 | 27.2k | jpegSize == NULL) | 93 | 27.2k | THROW("Invalid argument"); | 94 | | | 95 | 27.2k | if (!this->lossless && this->quality == -1) | 96 | 27.2k | THROW("TJPARAM_QUALITY must be specified"); | 97 | 27.2k | if (!this->lossless && this->subsamp == TJSAMP_UNKNOWN) | 98 | 27.2k | THROW("TJPARAM_SUBSAMP must be specified"); | 99 | | | 100 | 27.2k | if (pitch == 0) pitch = width * tjPixelSize[pixelFormat]; | 101 | 0 | else if (pitch < width * tjPixelSize[pixelFormat]) | 102 | 27.2k | THROW("Invalid argument"); | 103 | | | 104 | 27.2k | if ((row_pointer = (_JSAMPROW *)malloc(sizeof(_JSAMPROW) * height)) == NULL) | 105 | 27.2k | THROW("Memory allocation failure"); | 106 | | | 107 | 27.2k | CATCH_LIBJPEG(this); | 108 | | | 109 | 27.2k | cinfo->image_width = width; | 110 | 27.2k | cinfo->image_height = height; | 111 | 27.2k | cinfo->data_precision = BITS_IN_JSAMPLE; | 112 | 27.2k | #if BITS_IN_JSAMPLE == 8 | 113 | 27.2k | if (this->lossless && this->precision >= 2 && | 114 | 0 | this->precision <= BITS_IN_JSAMPLE) | 115 | | #else | 116 | | if (this->lossless && this->precision >= BITS_IN_JSAMPLE - 3 && | 117 | | this->precision <= BITS_IN_JSAMPLE) | 118 | | #endif | 119 | 0 | cinfo->data_precision = this->precision; | 120 | | | 121 | 27.2k | setCompDefaults(this, pixelFormat, FALSE); | 122 | 27.2k | if (this->noRealloc) alloc = FALSE; | 123 | 27.2k | jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc); | 124 | | | 125 | 27.2k | jpeg_start_compress(cinfo, TRUE); | 126 | 27.2k | if (this->iccBuf != NULL && this->iccSize != 0) | 127 | 24.2k | jpeg_write_icc_profile(cinfo, this->iccBuf, (unsigned int)this->iccSize); | 128 | 36.0M | for (i = 0; i < height; i++) { | 129 | 36.0M | if (this->bottomUp) | 130 | 5.39M | row_pointer[i] = (_JSAMPROW)&srcBuf[(height - i - 1) * (size_t)pitch]; | 131 | 30.6M | else | 132 | 30.6M | row_pointer[i] = (_JSAMPROW)&srcBuf[i * (size_t)pitch]; | 133 | 36.0M | } | 134 | 54.4k | while (cinfo->next_scanline < cinfo->image_height) | 135 | 27.2k | _jpeg_write_scanlines(cinfo, &row_pointer[cinfo->next_scanline], | 136 | 27.2k | cinfo->image_height - cinfo->next_scanline); | 137 | 27.2k | jpeg_finish_compress(cinfo); | 138 | | | 139 | 27.2k | bailout: | 140 | 27.2k | if (cinfo->global_state > CSTATE_START && alloc) | 141 | 0 | (*cinfo->dest->term_destination) (cinfo); | 142 | 27.2k | if (cinfo->global_state > CSTATE_START || retval == -1) | 143 | 0 | jpeg_abort_compress(cinfo); | 144 | 27.2k | free(row_pointer); | 145 | 27.2k | if (this->jerr.warning) retval = -1; | 146 | 27.2k | return retval; | 147 | 27.2k | } |
Unexecuted instantiation: tj3Compress12 Unexecuted instantiation: tj3Compress16 |
148 | | |
149 | | |
150 | | /******************************* Decompressor ********************************/ |
151 | | |
152 | | /* TurboJPEG 3.0+ */ |
153 | | DLLEXPORT int GET_NAME(tj3Decompress, BITS_IN_JSAMPLE) |
154 | | (tjhandle handle, const unsigned char *jpegBuf, size_t jpegSize, |
155 | | _JSAMPLE *dstBuf, int pitch, int pixelFormat) |
156 | 0 | { |
157 | 0 | static const char FUNCTION_NAME[] = |
158 | 0 | GET_STRING(tj3Decompress, BITS_IN_JSAMPLE); |
159 | 0 | _JSAMPROW *row_pointer = NULL; |
160 | 0 | int croppedHeight, i, retval = 0; |
161 | | #if BITS_IN_JSAMPLE != 16 |
162 | | int scaledWidth; |
163 | | #endif |
164 | 0 | struct my_progress_mgr progress; |
165 | |
|
166 | 0 | GET_DINSTANCE(handle); |
167 | 0 | if ((this->init & DECOMPRESS) == 0) |
168 | 0 | THROW("Instance has not been initialized for decompression"); |
169 | |
|
170 | 0 | if (jpegBuf == NULL || jpegSize <= 0 || dstBuf == NULL || pitch < 0 || |
171 | 0 | pixelFormat < 0 || pixelFormat >= TJ_NUMPF) |
172 | 0 | THROW("Invalid argument"); |
173 | |
|
174 | 0 | if (this->scanLimit) { |
175 | 0 | memset(&progress, 0, sizeof(struct my_progress_mgr)); |
176 | 0 | progress.pub.progress_monitor = my_progress_monitor; |
177 | 0 | progress.this = this; |
178 | 0 | dinfo->progress = &progress.pub; |
179 | 0 | } else |
180 | 0 | dinfo->progress = NULL; |
181 | |
|
182 | 0 | dinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; |
183 | |
|
184 | 0 | CATCH_LIBJPEG(this); |
185 | |
|
186 | 0 | if (dinfo->global_state <= DSTATE_INHEADER) { |
187 | 0 | jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); |
188 | 0 | jpeg_read_header(dinfo, TRUE); |
189 | 0 | } |
190 | 0 | setDecompParameters(this); |
191 | | #if BITS_IN_JSAMPLE == 12 |
192 | 0 | if (this->precision == 8 && !this->lossless) |
193 | 0 | dinfo->data_precision = 12; |
194 | | #endif |
195 | 0 | if (this->maxPixels && |
196 | 0 | (unsigned long long)this->jpegWidth * this->jpegHeight > |
197 | 0 | (unsigned long long)this->maxPixels) |
198 | 0 | THROW("Image is too large"); |
199 | 0 | this->dinfo.out_color_space = pf2cs[pixelFormat]; |
200 | | #if BITS_IN_JSAMPLE != 16 |
201 | 0 | scaledWidth = TJSCALED(dinfo->image_width, this->scalingFactor); |
202 | | #endif |
203 | 0 | dinfo->do_fancy_upsampling = !this->fastUpsample; |
204 | 0 | this->dinfo.dct_method = this->fastDCT ? JDCT_FASTEST : JDCT_ISLOW; |
205 | |
|
206 | 0 | dinfo->scale_num = this->scalingFactor.num; |
207 | 0 | dinfo->scale_denom = this->scalingFactor.denom; |
208 | |
|
209 | 0 | jpeg_start_decompress(dinfo); |
210 | |
|
211 | | #if BITS_IN_JSAMPLE != 16 |
212 | 0 | if (this->croppingRegion.x != 0 || |
213 | 0 | (this->croppingRegion.w != 0 && this->croppingRegion.w != scaledWidth)) { |
214 | 0 | JDIMENSION crop_x = this->croppingRegion.x; |
215 | 0 | JDIMENSION crop_w = this->croppingRegion.w; |
216 | |
|
217 | 0 | _jpeg_crop_scanline(dinfo, &crop_x, &crop_w); |
218 | 0 | if ((int)crop_x != this->croppingRegion.x) |
219 | 0 | THROWI("Unexplained mismatch between specified (%d) and\n" |
220 | 0 | "actual (%d) cropping region left boundary", |
221 | 0 | this->croppingRegion.x, (int)crop_x); |
222 | 0 | if ((int)crop_w != this->croppingRegion.w) |
223 | 0 | THROWI("Unexplained mismatch between specified (%d) and\n" |
224 | 0 | "actual (%d) cropping region width", |
225 | 0 | this->croppingRegion.w, (int)crop_w); |
226 | 0 | } |
227 | 0 | #endif |
228 | | |
229 | 0 | if (pitch == 0) pitch = dinfo->output_width * tjPixelSize[pixelFormat]; |
230 | 0 | else if ((JDIMENSION)pitch < dinfo->output_width * tjPixelSize[pixelFormat]) |
231 | 0 | THROW("Invalid argument"); |
232 | |
|
233 | 0 | croppedHeight = dinfo->output_height; |
234 | | #if BITS_IN_JSAMPLE != 16 |
235 | 0 | if (this->croppingRegion.y != 0 || this->croppingRegion.h != 0) |
236 | 0 | croppedHeight = this->croppingRegion.h; |
237 | | #endif |
238 | 0 | if ((row_pointer = |
239 | 0 | (_JSAMPROW *)malloc(sizeof(_JSAMPROW) * croppedHeight)) == NULL) |
240 | 0 | THROW("Memory allocation failure"); |
241 | 0 | CATCH_LIBJPEG(this); |
242 | 0 | for (i = 0; i < (int)croppedHeight; i++) { |
243 | 0 | if (this->bottomUp) |
244 | 0 | row_pointer[i] = &dstBuf[(croppedHeight - i - 1) * (size_t)pitch]; |
245 | 0 | else |
246 | 0 | row_pointer[i] = &dstBuf[i * (size_t)pitch]; |
247 | 0 | } |
248 | |
|
249 | | #if BITS_IN_JSAMPLE != 16 |
250 | 0 | if (this->croppingRegion.y != 0 || this->croppingRegion.h != 0) { |
251 | 0 | if (this->croppingRegion.y != 0) { |
252 | 0 | JDIMENSION lines = _jpeg_skip_scanlines(dinfo, this->croppingRegion.y); |
253 | | |
254 | 0 | if ((int)lines != this->croppingRegion.y) |
255 | 0 | THROWI("Unexplained mismatch between specified (%d) and\n" |
256 | | "actual (%d) cropping region upper boundary", |
257 | 0 | this->croppingRegion.y, (int)lines); |
258 | 0 | } |
259 | 0 | while ((int)dinfo->output_scanline < |
260 | 0 | this->croppingRegion.y + this->croppingRegion.h) |
261 | 0 | _jpeg_read_scanlines(dinfo, &row_pointer[dinfo->output_scanline - |
262 | 0 | this->croppingRegion.y], |
263 | 0 | this->croppingRegion.y + this->croppingRegion.h - |
264 | 0 | dinfo->output_scanline); |
265 | 0 | if (this->croppingRegion.y + this->croppingRegion.h != |
266 | 0 | (int)dinfo->output_height) { |
267 | 0 | JDIMENSION lines = _jpeg_skip_scanlines(dinfo, dinfo->output_height - |
268 | | this->croppingRegion.y - |
269 | | this->croppingRegion.h); |
270 | |
|
271 | 0 | if (lines != dinfo->output_height - this->croppingRegion.y - |
272 | 0 | this->croppingRegion.h) |
273 | 0 | THROWI("Unexplained mismatch between specified (%d) and\n" |
274 | 0 | "actual (%d) cropping region lower boundary", |
275 | 0 | this->croppingRegion.y + this->croppingRegion.h, |
276 | 0 | (int)(dinfo->output_height - lines)); |
277 | 0 | } |
278 | 0 | } else |
279 | 0 | #endif |
280 | 0 | { |
281 | 0 | while (dinfo->output_scanline < dinfo->output_height) |
282 | 0 | _jpeg_read_scanlines(dinfo, &row_pointer[dinfo->output_scanline], |
283 | 0 | dinfo->output_height - dinfo->output_scanline); |
284 | 0 | } |
285 | 0 | jpeg_finish_decompress(dinfo); |
286 | |
|
287 | 0 | bailout: |
288 | 0 | if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo); |
289 | 0 | free(row_pointer); |
290 | 0 | if (this->jerr.warning) retval = -1; |
291 | 0 | return retval; |
292 | 0 | } Unexecuted instantiation: tj3Decompress8 Unexecuted instantiation: tj3Decompress12 Unexecuted instantiation: tj3Decompress16 |
293 | | |
294 | | |
295 | | /*************************** Packed-Pixel Image I/O **************************/ |
296 | | |
297 | | #if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) |
298 | | |
299 | | /* TurboJPEG 3.0+ */ |
300 | | #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
301 | | static |
302 | | #endif |
303 | | _JSAMPLE *GET_NAME(_tj3LoadImageFromFileHandle, BITS_IN_JSAMPLE) |
304 | | (tjhandle handle, FILE *file, int *width, int align, int *height, |
305 | | int *pixelFormat) |
306 | 54.4k | { |
307 | 54.4k | static const char FUNCTION_NAME[] = |
308 | 54.4k | GET_STRING(tj3LoadImage, BITS_IN_JSAMPLE); |
309 | | |
310 | 54.4k | int retval = 0, tempc; |
311 | 54.4k | size_t pitch; |
312 | 54.4k | tjhandle handle2 = NULL; |
313 | 54.4k | tjinstance *this2; |
314 | 54.4k | j_compress_ptr cinfo = NULL; |
315 | 54.4k | cjpeg_source_ptr src = NULL; |
316 | 54.4k | _JSAMPLE *dstBuf = NULL; |
317 | 54.4k | boolean invert; |
318 | | |
319 | 54.4k | GET_TJINSTANCE(handle, NULL) |
320 | | |
321 | 54.4k | if (!file || !width || align < 1 || !height || !pixelFormat || |
322 | 54.4k | *pixelFormat < TJPF_UNKNOWN || *pixelFormat >= TJ_NUMPF) |
323 | 54.4k | THROW("Invalid argument"); |
324 | 54.4k | if ((align & (align - 1)) != 0) |
325 | 54.4k | THROW("Alignment must be a power of 2"); |
326 | | |
327 | | /* The instance handle passed to this function is used only for parameter |
328 | | retrieval. Create a new temporary instance to avoid interfering with the |
329 | | libjpeg state of the primary instance. */ |
330 | 54.4k | if ((handle2 = tj3Init(TJINIT_COMPRESS)) == NULL) return NULL; |
331 | 54.4k | this2 = (tjinstance *)handle2; |
332 | 54.4k | cinfo = &this2->cinfo; |
333 | | |
334 | 54.4k | if ((tempc = getc(file)) < 0 || ungetc(tempc, file) == EOF) |
335 | 0 | THROW_UNIX("Could not read input file") |
336 | 54.4k | else if (tempc == EOF) |
337 | 54.4k | THROW("Input file contains no data"); |
338 | | |
339 | 54.4k | CATCH_LIBJPEG2(); |
340 | | |
341 | 54.4k | cinfo->data_precision = BITS_IN_JSAMPLE; |
342 | 54.4k | if (*pixelFormat == TJPF_UNKNOWN) cinfo->in_color_space = JCS_UNKNOWN; |
343 | 54.4k | else cinfo->in_color_space = pf2cs[*pixelFormat]; |
344 | 54.4k | if (tempc == 'B') { |
345 | 6.78k | if ((src = jinit_read_bmp(cinfo, FALSE)) == NULL) |
346 | 6.78k | THROW("Could not initialize bitmap loader"); |
347 | 6.78k | invert = !this->bottomUp; |
348 | 47.6k | } else if (tempc == 0x89) { |
349 | | #if BITS_IN_JSAMPLE == 8 |
350 | 28.7k | if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE) |
351 | | #else |
352 | 0 | if (this->precision >= BITS_IN_JSAMPLE - 3 && |
353 | 0 | this->precision <= BITS_IN_JSAMPLE) |
354 | 0 | #endif |
355 | 28.7k | cinfo->data_precision = this->precision; |
356 | 28.7k | if ((src = _jinit_read_png(cinfo)) == NULL) |
357 | 28.7k | THROW("Could not initialize PNG loader"); |
358 | 28.7k | invert = this->bottomUp; |
359 | 28.7k | } else if (tempc == 'P') { |
360 | | #if BITS_IN_JSAMPLE == 8 |
361 | 18.3k | if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE) |
362 | | #else |
363 | 0 | if (this->precision >= BITS_IN_JSAMPLE - 3 && |
364 | 0 | this->precision <= BITS_IN_JSAMPLE) |
365 | 0 | #endif |
366 | 18.3k | cinfo->data_precision = this->precision; |
367 | 18.3k | if ((src = _jinit_read_ppm(cinfo)) == NULL) |
368 | 18.3k | THROW("Could not initialize PPM loader"); |
369 | 18.3k | invert = this->bottomUp; |
370 | 18.3k | } else |
371 | 53.9k | THROW("Unsupported file type"); |
372 | | |
373 | 53.9k | CATCH_LIBJPEG2(); |
374 | | |
375 | 22.6k | cinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; |
376 | | |
377 | 22.6k | src->input_file = file; |
378 | | /* Refuse to load images larger than the specified size. */ |
379 | 22.6k | src->max_pixels = this->maxPixels; |
380 | 22.6k | (*src->start_input) (cinfo, src); |
381 | 22.6k | if (tempc == 'B') { |
382 | 2.43k | if (cinfo->X_density && cinfo->Y_density) { |
383 | 297 | this->xDensity = cinfo->X_density; |
384 | 297 | this->yDensity = cinfo->Y_density; |
385 | 297 | this->densityUnits = cinfo->density_unit; |
386 | 297 | } |
387 | 20.2k | } else if (tempc == 0x89 && (this->init & COMPRESS) && |
388 | 4.11k | (this->saveMarkers == 2 || this->saveMarkers == 4)) { |
389 | 4.11k | JOCTET *iccBuf = NULL; |
390 | 4.11k | unsigned int iccLen = 0; |
391 | | |
392 | 4.11k | if ((*src->read_icc_profile) (cinfo, src, &iccBuf, &iccLen) && iccBuf && |
393 | 12 | iccLen) |
394 | 12 | tj3SetICCProfile(handle, (unsigned char *)iccBuf, iccLen); |
395 | 4.11k | } |
396 | 22.6k | (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo); |
397 | | |
398 | 22.6k | *width = cinfo->image_width; *height = cinfo->image_height; |
399 | 22.6k | *pixelFormat = cs2pf[cinfo->in_color_space]; |
400 | | |
401 | 22.6k | pitch = PAD((*width) * tjPixelSize[*pixelFormat], align); |
402 | | |
403 | 22.6k | if ( |
404 | | #if ULLONG_MAX > SIZE_MAX |
405 | | (unsigned long long)pitch * (unsigned long long)(*height) * |
406 | | (unsigned long long)sizeof(_JSAMPLE) > |
407 | | (unsigned long long)((size_t)-1) || |
408 | | #endif |
409 | 22.6k | (dstBuf = (_JSAMPLE *)malloc(pitch * (*height) * |
410 | 22.6k | sizeof(_JSAMPLE))) == NULL) |
411 | 22.6k | THROW("Memory allocation failure"); |
412 | | |
413 | 22.6k | CATCH_LIBJPEG2(); |
414 | | |
415 | 36.2M | while (cinfo->next_scanline < cinfo->image_height) { |
416 | 36.2M | int i, nlines = (*src->get_pixel_rows) (cinfo, src); |
417 | | |
418 | 72.4M | for (i = 0; i < nlines; i++) { |
419 | 36.2M | _JSAMPLE *dstptr; |
420 | 36.2M | int row; |
421 | | |
422 | 36.2M | row = cinfo->next_scanline + i; |
423 | 36.2M | if (invert) dstptr = &dstBuf[((*height) - row - 1) * pitch]; |
424 | 23.6M | else dstptr = &dstBuf[row * pitch]; |
425 | 36.2M | memcpy(dstptr, src->_buffer[i], |
426 | 36.2M | (*width) * tjPixelSize[*pixelFormat] * sizeof(_JSAMPLE)); |
427 | 36.2M | } |
428 | 36.2M | cinfo->next_scanline += nlines; |
429 | 36.2M | } |
430 | | |
431 | 54.4k | bailout: |
432 | 54.4k | if (src) |
433 | 53.9k | (*src->finish_input) (cinfo, src); |
434 | 54.4k | tj3Destroy(handle2); |
435 | 54.4k | if (retval < 0) { free(dstBuf); dstBuf = NULL; } |
436 | 54.4k | return dstBuf; |
437 | 13.6k | } _tj3LoadImageFromFileHandle8 Line | Count | Source | 306 | 54.4k | { | 307 | 54.4k | static const char FUNCTION_NAME[] = | 308 | 54.4k | GET_STRING(tj3LoadImage, BITS_IN_JSAMPLE); | 309 | | | 310 | 54.4k | int retval = 0, tempc; | 311 | 54.4k | size_t pitch; | 312 | 54.4k | tjhandle handle2 = NULL; | 313 | 54.4k | tjinstance *this2; | 314 | 54.4k | j_compress_ptr cinfo = NULL; | 315 | 54.4k | cjpeg_source_ptr src = NULL; | 316 | 54.4k | _JSAMPLE *dstBuf = NULL; | 317 | 54.4k | boolean invert; | 318 | | | 319 | 54.4k | GET_TJINSTANCE(handle, NULL) | 320 | | | 321 | 54.4k | if (!file || !width || align < 1 || !height || !pixelFormat || | 322 | 54.4k | *pixelFormat < TJPF_UNKNOWN || *pixelFormat >= TJ_NUMPF) | 323 | 54.4k | THROW("Invalid argument"); | 324 | 54.4k | if ((align & (align - 1)) != 0) | 325 | 54.4k | THROW("Alignment must be a power of 2"); | 326 | | | 327 | | /* The instance handle passed to this function is used only for parameter | 328 | | retrieval. Create a new temporary instance to avoid interfering with the | 329 | | libjpeg state of the primary instance. */ | 330 | 54.4k | if ((handle2 = tj3Init(TJINIT_COMPRESS)) == NULL) return NULL; | 331 | 54.4k | this2 = (tjinstance *)handle2; | 332 | 54.4k | cinfo = &this2->cinfo; | 333 | | | 334 | 54.4k | if ((tempc = getc(file)) < 0 || ungetc(tempc, file) == EOF) | 335 | 0 | THROW_UNIX("Could not read input file") | 336 | 54.4k | else if (tempc == EOF) | 337 | 54.4k | THROW("Input file contains no data"); | 338 | | | 339 | 54.4k | CATCH_LIBJPEG2(); | 340 | | | 341 | 54.4k | cinfo->data_precision = BITS_IN_JSAMPLE; | 342 | 54.4k | if (*pixelFormat == TJPF_UNKNOWN) cinfo->in_color_space = JCS_UNKNOWN; | 343 | 54.4k | else cinfo->in_color_space = pf2cs[*pixelFormat]; | 344 | 54.4k | if (tempc == 'B') { | 345 | 6.78k | if ((src = jinit_read_bmp(cinfo, FALSE)) == NULL) | 346 | 6.78k | THROW("Could not initialize bitmap loader"); | 347 | 6.78k | invert = !this->bottomUp; | 348 | 47.6k | } else if (tempc == 0x89) { | 349 | 28.7k | #if BITS_IN_JSAMPLE == 8 | 350 | 28.7k | if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE) | 351 | | #else | 352 | | if (this->precision >= BITS_IN_JSAMPLE - 3 && | 353 | | this->precision <= BITS_IN_JSAMPLE) | 354 | | #endif | 355 | 28.7k | cinfo->data_precision = this->precision; | 356 | 28.7k | if ((src = _jinit_read_png(cinfo)) == NULL) | 357 | 28.7k | THROW("Could not initialize PNG loader"); | 358 | 28.7k | invert = this->bottomUp; | 359 | 28.7k | } else if (tempc == 'P') { | 360 | 18.3k | #if BITS_IN_JSAMPLE == 8 | 361 | 18.3k | if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE) | 362 | | #else | 363 | | if (this->precision >= BITS_IN_JSAMPLE - 3 && | 364 | | this->precision <= BITS_IN_JSAMPLE) | 365 | | #endif | 366 | 18.3k | cinfo->data_precision = this->precision; | 367 | 18.3k | if ((src = _jinit_read_ppm(cinfo)) == NULL) | 368 | 18.3k | THROW("Could not initialize PPM loader"); | 369 | 18.3k | invert = this->bottomUp; | 370 | 18.3k | } else | 371 | 53.9k | THROW("Unsupported file type"); | 372 | | | 373 | 53.9k | CATCH_LIBJPEG2(); | 374 | | | 375 | 22.6k | cinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; | 376 | | | 377 | 22.6k | src->input_file = file; | 378 | | /* Refuse to load images larger than the specified size. */ | 379 | 22.6k | src->max_pixels = this->maxPixels; | 380 | 22.6k | (*src->start_input) (cinfo, src); | 381 | 22.6k | if (tempc == 'B') { | 382 | 2.43k | if (cinfo->X_density && cinfo->Y_density) { | 383 | 297 | this->xDensity = cinfo->X_density; | 384 | 297 | this->yDensity = cinfo->Y_density; | 385 | 297 | this->densityUnits = cinfo->density_unit; | 386 | 297 | } | 387 | 20.2k | } else if (tempc == 0x89 && (this->init & COMPRESS) && | 388 | 4.11k | (this->saveMarkers == 2 || this->saveMarkers == 4)) { | 389 | 4.11k | JOCTET *iccBuf = NULL; | 390 | 4.11k | unsigned int iccLen = 0; | 391 | | | 392 | 4.11k | if ((*src->read_icc_profile) (cinfo, src, &iccBuf, &iccLen) && iccBuf && | 393 | 12 | iccLen) | 394 | 12 | tj3SetICCProfile(handle, (unsigned char *)iccBuf, iccLen); | 395 | 4.11k | } | 396 | 22.6k | (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo); | 397 | | | 398 | 22.6k | *width = cinfo->image_width; *height = cinfo->image_height; | 399 | 22.6k | *pixelFormat = cs2pf[cinfo->in_color_space]; | 400 | | | 401 | 22.6k | pitch = PAD((*width) * tjPixelSize[*pixelFormat], align); | 402 | | | 403 | 22.6k | if ( | 404 | | #if ULLONG_MAX > SIZE_MAX | 405 | | (unsigned long long)pitch * (unsigned long long)(*height) * | 406 | | (unsigned long long)sizeof(_JSAMPLE) > | 407 | | (unsigned long long)((size_t)-1) || | 408 | | #endif | 409 | 22.6k | (dstBuf = (_JSAMPLE *)malloc(pitch * (*height) * | 410 | 22.6k | sizeof(_JSAMPLE))) == NULL) | 411 | 22.6k | THROW("Memory allocation failure"); | 412 | | | 413 | 22.6k | CATCH_LIBJPEG2(); | 414 | | | 415 | 36.2M | while (cinfo->next_scanline < cinfo->image_height) { | 416 | 36.2M | int i, nlines = (*src->get_pixel_rows) (cinfo, src); | 417 | | | 418 | 72.4M | for (i = 0; i < nlines; i++) { | 419 | 36.2M | _JSAMPLE *dstptr; | 420 | 36.2M | int row; | 421 | | | 422 | 36.2M | row = cinfo->next_scanline + i; | 423 | 36.2M | if (invert) dstptr = &dstBuf[((*height) - row - 1) * pitch]; | 424 | 23.6M | else dstptr = &dstBuf[row * pitch]; | 425 | 36.2M | memcpy(dstptr, src->_buffer[i], | 426 | 36.2M | (*width) * tjPixelSize[*pixelFormat] * sizeof(_JSAMPLE)); | 427 | 36.2M | } | 428 | 36.2M | cinfo->next_scanline += nlines; | 429 | 36.2M | } | 430 | | | 431 | 54.4k | bailout: | 432 | 54.4k | if (src) | 433 | 53.9k | (*src->finish_input) (cinfo, src); | 434 | 54.4k | tj3Destroy(handle2); | 435 | 54.4k | if (retval < 0) { free(dstBuf); dstBuf = NULL; } | 436 | 54.4k | return dstBuf; | 437 | 13.6k | } |
Unexecuted instantiation: _tj3LoadImageFromFileHandle12 Unexecuted instantiation: _tj3LoadImageFromFileHandle16 |
438 | | |
439 | | #endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */ |
440 | | |
441 | | DLLEXPORT _JSAMPLE *GET_NAME(tj3LoadImage, BITS_IN_JSAMPLE) |
442 | | (tjhandle handle, const char *filename, int *width, int align, int *height, |
443 | | int *pixelFormat) |
444 | 0 | { |
445 | 0 | static const char FUNCTION_NAME[] = |
446 | 0 | GET_STRING(tj3LoadImage, BITS_IN_JSAMPLE); |
447 | |
|
448 | 0 | #if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) |
449 | |
|
450 | 0 | int retval = 0; |
451 | 0 | _JSAMPLE *dstBuf = NULL; |
452 | 0 | FILE *file = NULL; |
453 | |
|
454 | 0 | GET_TJINSTANCE(handle, NULL) |
455 | |
|
456 | 0 | if (!filename) |
457 | 0 | THROW("Invalid argument"); |
458 | |
|
459 | | #ifdef _MSC_VER |
460 | | if (fopen_s(&file, filename, "rb") || file == NULL) |
461 | | #else |
462 | 0 | if ((file = fopen(filename, "rb")) == NULL) |
463 | 0 | #endif |
464 | 0 | THROW_UNIX("Cannot open input file"); |
465 | |
|
466 | 0 | dstBuf = GET_NAME(_tj3LoadImageFromFileHandle, BITS_IN_JSAMPLE) |
467 | 0 | (handle, file, width, align, height, pixelFormat); |
468 | |
|
469 | 0 | bailout: |
470 | 0 | if (file) fclose(file); |
471 | 0 | if (retval < 0) { free(dstBuf); dstBuf = NULL; } |
472 | 0 | return dstBuf; |
473 | |
|
474 | | #else /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */ |
475 | | |
476 | | static const char ERROR_MSG[] = |
477 | | "16-bit data precision requires lossless JPEG,\n" |
478 | | "which was disabled at build time."; |
479 | | _JSAMPLE *retval = NULL; |
480 | | |
481 | | GET_TJINSTANCE(handle, NULL) |
482 | | SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s(): %s", FUNCTION_NAME, |
483 | | ERROR_MSG); |
484 | | this->isInstanceError = TRUE; THROWG(ERROR_MSG, NULL) |
485 | | |
486 | | bailout: |
487 | | return retval; |
488 | | |
489 | | #endif |
490 | 0 | } Unexecuted instantiation: tj3LoadImage8 Unexecuted instantiation: tj3LoadImage12 Unexecuted instantiation: tj3LoadImage16 |
491 | | |
492 | | |
493 | | /* TurboJPEG 3.0+ */ |
494 | | DLLEXPORT int GET_NAME(tj3SaveImage, BITS_IN_JSAMPLE) |
495 | | (tjhandle handle, const char *filename, const _JSAMPLE *buffer, int width, |
496 | | int pitch, int height, int pixelFormat) |
497 | 0 | { |
498 | 0 | static const char FUNCTION_NAME[] = |
499 | 0 | GET_STRING(tj3SaveImage, BITS_IN_JSAMPLE); |
500 | 0 | int retval = 0; |
501 | |
|
502 | 0 | #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) |
503 | |
|
504 | 0 | tjhandle handle2 = NULL; |
505 | 0 | tjinstance *this2; |
506 | 0 | j_decompress_ptr dinfo = NULL; |
507 | 0 | djpeg_dest_ptr dst; |
508 | 0 | FILE *file = NULL; |
509 | 0 | const char *ptr = NULL; |
510 | 0 | boolean invert; |
511 | |
|
512 | 0 | GET_TJINSTANCE(handle, -1) |
513 | |
|
514 | 0 | if (!filename || !buffer || width < 1 || pitch < 0 || height < 1 || |
515 | 0 | pixelFormat < 0 || pixelFormat >= TJ_NUMPF) |
516 | 0 | THROW("Invalid argument"); |
517 | | |
518 | | /* The instance handle passed to this function is used only for parameter |
519 | | retrieval. Create a new temporary instance to avoid interfering with the |
520 | | libjpeg state of the primary instance. */ |
521 | 0 | if ((handle2 = tj3Init(TJINIT_DECOMPRESS)) == NULL) |
522 | 0 | return -1; |
523 | 0 | this2 = (tjinstance *)handle2; |
524 | 0 | dinfo = &this2->dinfo; |
525 | |
|
526 | | #ifdef _MSC_VER |
527 | | if (fopen_s(&file, filename, "wb") || file == NULL) |
528 | | #else |
529 | 0 | if ((file = fopen(filename, "wb")) == NULL) |
530 | 0 | #endif |
531 | 0 | THROW_UNIX("Cannot open output file"); |
532 | |
|
533 | 0 | CATCH_LIBJPEG2(); |
534 | |
|
535 | 0 | this2->dinfo.out_color_space = pf2cs[pixelFormat]; |
536 | 0 | dinfo->image_width = width; dinfo->image_height = height; |
537 | 0 | dinfo->global_state = DSTATE_READY; |
538 | 0 | dinfo->scale_num = dinfo->scale_denom = 1; |
539 | 0 | dinfo->data_precision = BITS_IN_JSAMPLE; |
540 | |
|
541 | 0 | ptr = strrchr(filename, '.'); |
542 | 0 | if (ptr && !strcasecmp(ptr, ".bmp")) { |
543 | 0 | if ((dst = jinit_write_bmp(dinfo, FALSE, FALSE)) == NULL) |
544 | 0 | THROW("Could not initialize bitmap writer"); |
545 | 0 | invert = !this->bottomUp; |
546 | 0 | dinfo->X_density = (UINT16)this->xDensity; |
547 | 0 | dinfo->Y_density = (UINT16)this->yDensity; |
548 | 0 | dinfo->density_unit = (UINT8)this->densityUnits; |
549 | 0 | } else if (ptr && !strcasecmp(ptr, ".png")) { |
550 | | #if BITS_IN_JSAMPLE == 8 |
551 | 0 | if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE) |
552 | | #else |
553 | 0 | if (this->precision >= BITS_IN_JSAMPLE - 3 && |
554 | 0 | this->precision <= BITS_IN_JSAMPLE) |
555 | 0 | #endif |
556 | 0 | dinfo->data_precision = this->precision; |
557 | 0 | if ((dst = _jinit_write_png(dinfo)) == NULL) |
558 | 0 | THROW("Could not initialize PNG writer"); |
559 | 0 | invert = this->bottomUp; |
560 | |
|
561 | 0 | if ((this->init & DECOMPRESS) && this->decompICCBuf && |
562 | 0 | this->decompICCSize) { |
563 | 0 | unsigned char *iccBuf = (unsigned char *)malloc(this->decompICCSize); |
564 | |
|
565 | 0 | if (!iccBuf) |
566 | 0 | THROW("Memory allocation failure"); |
567 | 0 | memcpy(iccBuf, this->decompICCBuf, this->decompICCSize); |
568 | 0 | (*dst->write_icc_profile) (dinfo, dst, iccBuf, |
569 | 0 | (unsigned int)this->decompICCSize); |
570 | 0 | } |
571 | 0 | } else { |
572 | | #if BITS_IN_JSAMPLE == 8 |
573 | 0 | if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE) |
574 | | #else |
575 | 0 | if (this->precision >= BITS_IN_JSAMPLE - 3 && |
576 | 0 | this->precision <= BITS_IN_JSAMPLE) |
577 | 0 | #endif |
578 | 0 | dinfo->data_precision = this->precision; |
579 | 0 | if ((dst = _jinit_write_ppm(dinfo)) == NULL) |
580 | 0 | THROW("Could not initialize PPM writer"); |
581 | 0 | invert = this->bottomUp; |
582 | 0 | } |
583 | | |
584 | 0 | dinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; |
585 | |
|
586 | 0 | dst->output_file = file; |
587 | 0 | (*dst->start_output) (dinfo, dst); |
588 | 0 | (*dinfo->mem->realize_virt_arrays) ((j_common_ptr)dinfo); |
589 | |
|
590 | 0 | if (pitch == 0) pitch = width * tjPixelSize[pixelFormat]; |
591 | 0 | else if (pitch < width * tjPixelSize[pixelFormat]) |
592 | 0 | THROW("Invalid argument"); |
593 | |
|
594 | 0 | while (dinfo->output_scanline < dinfo->output_height) { |
595 | 0 | _JSAMPLE *rowptr; |
596 | |
|
597 | 0 | if (invert) |
598 | 0 | rowptr = |
599 | 0 | (_JSAMPLE *)&buffer[(height - dinfo->output_scanline - 1) * pitch]; |
600 | 0 | else |
601 | 0 | rowptr = (_JSAMPLE *)&buffer[dinfo->output_scanline * pitch]; |
602 | 0 | memcpy(dst->_buffer[0], rowptr, |
603 | 0 | width * tjPixelSize[pixelFormat] * sizeof(_JSAMPLE)); |
604 | 0 | (*dst->put_pixel_rows) (dinfo, dst, 1); |
605 | 0 | dinfo->output_scanline++; |
606 | 0 | } |
607 | |
|
608 | 0 | (*dst->finish_output) (dinfo, dst); |
609 | |
|
610 | 0 | bailout: |
611 | 0 | tj3Destroy(handle2); |
612 | 0 | if (file) fclose(file); |
613 | 0 | return retval; |
614 | |
|
615 | | #else /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */ |
616 | | |
617 | | GET_TJINSTANCE(handle, -1) |
618 | | THROW("16-bit data precision requires lossless JPEG,\n" |
619 | | "which was disabled at build time.") |
620 | | bailout: |
621 | | return retval; |
622 | | |
623 | | #endif |
624 | 0 | } Unexecuted instantiation: tj3SaveImage8 Unexecuted instantiation: tj3SaveImage12 Unexecuted instantiation: tj3SaveImage16 |
625 | | |
626 | | |
627 | | #undef _JSAMPLE |
628 | | #undef _JSAMPROW |
629 | | #undef _buffer |
630 | | #undef _jinit_read_png |
631 | | #undef _jinit_write_png |
632 | | #undef _jinit_read_ppm |
633 | | #undef _jinit_write_ppm |
634 | | #undef _jpeg_crop_scanline |
635 | | #undef _jpeg_read_scanlines |
636 | | #undef _jpeg_skip_scanlines |
637 | | #undef _jpeg_write_scanlines |