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