Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libjpeg-turbo/patches/0003-remove-bmp-ppm-support.patch
9906 views
1
diff --git a/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c b/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c
2
index 1fa63b8185..72f99e236a 100644
3
--- a/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c
4
+++ b/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c
5
@@ -286,271 +286,6 @@ bailout:
6
return retval;
7
}
8
9
-
10
-/*************************** Packed-Pixel Image I/O **************************/
11
-
12
-/* TurboJPEG 3.0+ */
13
-DLLEXPORT _JSAMPLE *GET_NAME(tj3LoadImage, BITS_IN_JSAMPLE)
14
- (tjhandle handle, const char *filename, int *width, int align, int *height,
15
- int *pixelFormat)
16
-{
17
- static const char FUNCTION_NAME[] =
18
- GET_STRING(tj3LoadImage, BITS_IN_JSAMPLE);
19
-
20
-#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
21
-
22
- int retval = 0, tempc;
23
- size_t pitch;
24
- tjhandle handle2 = NULL;
25
- tjinstance *this2;
26
- j_compress_ptr cinfo = NULL;
27
- cjpeg_source_ptr src;
28
- _JSAMPLE *dstBuf = NULL;
29
- FILE *file = NULL;
30
- boolean invert;
31
-
32
- GET_TJINSTANCE(handle, NULL)
33
-
34
- if (!filename || !width || align < 1 || !height || !pixelFormat ||
35
- *pixelFormat < TJPF_UNKNOWN || *pixelFormat >= TJ_NUMPF)
36
- THROW("Invalid argument");
37
- if ((align & (align - 1)) != 0)
38
- THROW("Alignment must be a power of 2");
39
-
40
- /* The instance handle passed to this function is used only for parameter
41
- retrieval. Create a new temporary instance to avoid interfering with the
42
- libjpeg state of the primary instance. */
43
- if ((handle2 = tj3Init(TJINIT_COMPRESS)) == NULL) return NULL;
44
- this2 = (tjinstance *)handle2;
45
- cinfo = &this2->cinfo;
46
-
47
-#ifdef _MSC_VER
48
- if (fopen_s(&file, filename, "rb") || file == NULL)
49
-#else
50
- if ((file = fopen(filename, "rb")) == NULL)
51
-#endif
52
- THROW_UNIX("Cannot open input file");
53
-
54
- if ((tempc = getc(file)) < 0 || ungetc(tempc, file) == EOF)
55
- THROW_UNIX("Could not read input file")
56
- else if (tempc == EOF)
57
- THROW("Input file contains no data");
58
-
59
- if (setjmp(this2->jerr.setjmp_buffer)) {
60
- /* If we get here, the JPEG code has signaled an error. */
61
- retval = -1; goto bailout;
62
- }
63
-
64
- cinfo->data_precision = BITS_IN_JSAMPLE;
65
- if (*pixelFormat == TJPF_UNKNOWN) cinfo->in_color_space = JCS_UNKNOWN;
66
- else cinfo->in_color_space = pf2cs[*pixelFormat];
67
- if (tempc == 'B') {
68
- if ((src = jinit_read_bmp(cinfo, FALSE)) == NULL)
69
- THROW("Could not initialize bitmap loader");
70
- invert = !this->bottomUp;
71
- } else if (tempc == 'P') {
72
-#if BITS_IN_JSAMPLE == 8
73
- if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE)
74
-#else
75
- if (this->precision >= BITS_IN_JSAMPLE - 3 &&
76
- this->precision <= BITS_IN_JSAMPLE)
77
-#endif
78
- cinfo->data_precision = this->precision;
79
- if ((src = _jinit_read_ppm(cinfo)) == NULL)
80
- THROW("Could not initialize PPM loader");
81
- invert = this->bottomUp;
82
- } else
83
- THROW("Unsupported file type");
84
-
85
- cinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L;
86
-
87
- src->input_file = file;
88
- /* Refuse to load images larger than the specified size. */
89
- src->max_pixels = this->maxPixels;
90
- (*src->start_input) (cinfo, src);
91
- if (tempc == 'B') {
92
- if (cinfo->X_density && cinfo->Y_density) {
93
- this->xDensity = cinfo->X_density;
94
- this->yDensity = cinfo->Y_density;
95
- this->densityUnits = cinfo->density_unit;
96
- }
97
- }
98
- (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo);
99
-
100
- *width = cinfo->image_width; *height = cinfo->image_height;
101
- *pixelFormat = cs2pf[cinfo->in_color_space];
102
-
103
- pitch = PAD((*width) * tjPixelSize[*pixelFormat], align);
104
- if (
105
-#if ULLONG_MAX > SIZE_MAX
106
- (unsigned long long)pitch * (unsigned long long)(*height) >
107
- (unsigned long long)((size_t)-1) ||
108
-#endif
109
- (dstBuf = (_JSAMPLE *)malloc(pitch * (*height) *
110
- sizeof(_JSAMPLE))) == NULL)
111
- THROW("Memory allocation failure");
112
-
113
- if (setjmp(this2->jerr.setjmp_buffer)) {
114
- /* If we get here, the JPEG code has signaled an error. */
115
- retval = -1; goto bailout;
116
- }
117
-
118
- while (cinfo->next_scanline < cinfo->image_height) {
119
- int i, nlines = (*src->get_pixel_rows) (cinfo, src);
120
-
121
- for (i = 0; i < nlines; i++) {
122
- _JSAMPLE *dstptr;
123
- int row;
124
-
125
- row = cinfo->next_scanline + i;
126
- if (invert) dstptr = &dstBuf[((*height) - row - 1) * pitch];
127
- else dstptr = &dstBuf[row * pitch];
128
- memcpy(dstptr, src->_buffer[i],
129
- (*width) * tjPixelSize[*pixelFormat] * sizeof(_JSAMPLE));
130
- }
131
- cinfo->next_scanline += nlines;
132
- }
133
-
134
- (*src->finish_input) (cinfo, src);
135
-
136
-bailout:
137
- tj3Destroy(handle2);
138
- if (file) fclose(file);
139
- if (retval < 0) { free(dstBuf); dstBuf = NULL; }
140
- return dstBuf;
141
-
142
-#else /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */
143
-
144
- static const char ERROR_MSG[] =
145
- "16-bit data precision requires lossless JPEG,\n"
146
- "which was disabled at build time.";
147
- _JSAMPLE *retval = NULL;
148
-
149
- GET_TJINSTANCE(handle, NULL)
150
- SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s(): %s", FUNCTION_NAME,
151
- ERROR_MSG);
152
- this->isInstanceError = TRUE; THROWG(ERROR_MSG, NULL)
153
-
154
-bailout:
155
- return retval;
156
-
157
-#endif
158
-}
159
-
160
-
161
-/* TurboJPEG 3.0+ */
162
-DLLEXPORT int GET_NAME(tj3SaveImage, BITS_IN_JSAMPLE)
163
- (tjhandle handle, const char *filename, const _JSAMPLE *buffer, int width,
164
- int pitch, int height, int pixelFormat)
165
-{
166
- static const char FUNCTION_NAME[] =
167
- GET_STRING(tj3SaveImage, BITS_IN_JSAMPLE);
168
- int retval = 0;
169
-
170
-#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
171
-
172
- tjhandle handle2 = NULL;
173
- tjinstance *this2;
174
- j_decompress_ptr dinfo = NULL;
175
- djpeg_dest_ptr dst;
176
- FILE *file = NULL;
177
- char *ptr = NULL;
178
- boolean invert;
179
-
180
- GET_TJINSTANCE(handle, -1)
181
-
182
- if (!filename || !buffer || width < 1 || pitch < 0 || height < 1 ||
183
- pixelFormat < 0 || pixelFormat >= TJ_NUMPF)
184
- THROW("Invalid argument");
185
-
186
- /* The instance handle passed to this function is used only for parameter
187
- retrieval. Create a new temporary instance to avoid interfering with the
188
- libjpeg state of the primary instance. */
189
- if ((handle2 = tj3Init(TJINIT_DECOMPRESS)) == NULL)
190
- return -1;
191
- this2 = (tjinstance *)handle2;
192
- dinfo = &this2->dinfo;
193
-
194
-#ifdef _MSC_VER
195
- if (fopen_s(&file, filename, "wb") || file == NULL)
196
-#else
197
- if ((file = fopen(filename, "wb")) == NULL)
198
-#endif
199
- THROW_UNIX("Cannot open output file");
200
-
201
- if (setjmp(this2->jerr.setjmp_buffer)) {
202
- /* If we get here, the JPEG code has signaled an error. */
203
- retval = -1; goto bailout;
204
- }
205
-
206
- this2->dinfo.out_color_space = pf2cs[pixelFormat];
207
- dinfo->image_width = width; dinfo->image_height = height;
208
- dinfo->global_state = DSTATE_READY;
209
- dinfo->scale_num = dinfo->scale_denom = 1;
210
- dinfo->data_precision = BITS_IN_JSAMPLE;
211
-
212
- ptr = strrchr(filename, '.');
213
- if (ptr && !strcasecmp(ptr, ".bmp")) {
214
- if ((dst = jinit_write_bmp(dinfo, FALSE, FALSE)) == NULL)
215
- THROW("Could not initialize bitmap writer");
216
- invert = !this->bottomUp;
217
- dinfo->X_density = (UINT16)this->xDensity;
218
- dinfo->Y_density = (UINT16)this->yDensity;
219
- dinfo->density_unit = (UINT8)this->densityUnits;
220
- } else {
221
-#if BITS_IN_JSAMPLE == 8
222
- if (this->precision >= 2 && this->precision <= BITS_IN_JSAMPLE)
223
-#else
224
- if (this->precision >= BITS_IN_JSAMPLE - 3 &&
225
- this->precision <= BITS_IN_JSAMPLE)
226
-#endif
227
- dinfo->data_precision = this->precision;
228
- if ((dst = _jinit_write_ppm(dinfo)) == NULL)
229
- THROW("Could not initialize PPM writer");
230
- invert = this->bottomUp;
231
- }
232
-
233
- dinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L;
234
-
235
- dst->output_file = file;
236
- (*dst->start_output) (dinfo, dst);
237
- (*dinfo->mem->realize_virt_arrays) ((j_common_ptr)dinfo);
238
-
239
- if (pitch == 0) pitch = width * tjPixelSize[pixelFormat];
240
-
241
- while (dinfo->output_scanline < dinfo->output_height) {
242
- _JSAMPLE *rowptr;
243
-
244
- if (invert)
245
- rowptr =
246
- (_JSAMPLE *)&buffer[(height - dinfo->output_scanline - 1) * pitch];
247
- else
248
- rowptr = (_JSAMPLE *)&buffer[dinfo->output_scanline * pitch];
249
- memcpy(dst->_buffer[0], rowptr,
250
- width * tjPixelSize[pixelFormat] * sizeof(_JSAMPLE));
251
- (*dst->put_pixel_rows) (dinfo, dst, 1);
252
- dinfo->output_scanline++;
253
- }
254
-
255
- (*dst->finish_output) (dinfo, dst);
256
-
257
-bailout:
258
- tj3Destroy(handle2);
259
- if (file) fclose(file);
260
- return retval;
261
-
262
-#else /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */
263
-
264
- GET_TJINSTANCE(handle, -1)
265
- THROW("16-bit data precision requires lossless JPEG,\n"
266
- "which was disabled at build time.")
267
-bailout:
268
- return retval;
269
-
270
-#endif
271
-}
272
-
273
-
274
#undef _JSAMPLE
275
#undef _JSAMPROW
276
#undef _buffer
277
diff --git a/thirdparty/libjpeg-turbo/src/turbojpeg.c b/thirdparty/libjpeg-turbo/src/turbojpeg.c
278
index eec8e2a616..8ce446148a 100644
279
--- a/thirdparty/libjpeg-turbo/src/turbojpeg.c
280
+++ b/thirdparty/libjpeg-turbo/src/turbojpeg.c
281
@@ -3095,48 +3095,3 @@ bailout:
282
free(sizes);
283
return retval;
284
}
285
-
286
-
287
-/*************************** Packed-Pixel Image I/O **************************/
288
-
289
-/* tj3LoadImage*() is implemented in turbojpeg-mp.c */
290
-
291
-/* TurboJPEG 2.0+ */
292
-DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width,
293
- int align, int *height,
294
- int *pixelFormat, int flags)
295
-{
296
- tjhandle handle = NULL;
297
- unsigned char *dstBuf = NULL;
298
-
299
- if ((handle = tj3Init(TJINIT_COMPRESS)) == NULL) return NULL;
300
-
301
- processFlags(handle, flags, COMPRESS);
302
-
303
- dstBuf = tj3LoadImage8(handle, filename, width, align, height, pixelFormat);
304
-
305
- tj3Destroy(handle);
306
- return dstBuf;
307
-}
308
-
309
-
310
-/* tj3SaveImage*() is implemented in turbojpeg-mp.c */
311
-
312
-/* TurboJPEG 2.0+ */
313
-DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer,
314
- int width, int pitch, int height, int pixelFormat,
315
- int flags)
316
-{
317
- tjhandle handle = NULL;
318
- int retval = -1;
319
-
320
- if ((handle = tj3Init(TJINIT_DECOMPRESS)) == NULL) return -1;
321
-
322
- processFlags(handle, flags, DECOMPRESS);
323
-
324
- retval = tj3SaveImage8(handle, filename, buffer, width, pitch, height,
325
- pixelFormat);
326
-
327
- tj3Destroy(handle);
328
- return retval;
329
-}
330
331