From 6d161c25eff0b390e384bd77cae784cb761af78e Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Sat, 8 Mar 2025 23:25:54 +0300 Subject: [PATCH] Update libjpeg-turbo version:3.1.0 --- 3rdparty/libjpeg-turbo/CMakeLists.txt | 4 +- 3rdparty/libjpeg-turbo/LICENSE.md | 2 +- 3rdparty/libjpeg-turbo/README.ijg | 26 +- 3rdparty/libjpeg-turbo/README.md | 22 +- .../{src => }/simd/CMakeLists.txt | 48 +- .../simd/arm/aarch32/jccolext-neon.c | 0 .../{src => }/simd/arm/aarch32/jchuff-neon.c | 11 +- .../{src => }/simd/arm/aarch32/jsimd.c | 12 +- .../{src => }/simd/arm/aarch32/jsimd_neon.S | 0 .../simd/arm/aarch64/jccolext-neon.c | 0 .../{src => }/simd/arm/aarch64/jchuff-neon.c | 12 +- .../{src => }/simd/arm/aarch64/jsimd.c | 13 +- .../{src => }/simd/arm/aarch64/jsimd_neon.S | 0 .../libjpeg-turbo/{src => }/simd/arm/align.h | 0 .../{src => }/simd/arm/jccolor-neon.c | 12 +- .../{src => }/simd/arm/jcgray-neon.c | 12 +- .../{src => }/simd/arm/jcgryext-neon.c | 0 .../libjpeg-turbo/{src => }/simd/arm/jchuff.h | 0 .../{src => }/simd/arm/jcphuff-neon.c | 12 +- .../{src => }/simd/arm/jcsample-neon.c | 12 +- .../{src => }/simd/arm/jdcolext-neon.c | 0 .../{src => }/simd/arm/jdcolor-neon.c | 12 +- .../{src => }/simd/arm/jdmerge-neon.c | 12 +- .../{src => }/simd/arm/jdmrgext-neon.c | 0 .../{src => }/simd/arm/jdsample-neon.c | 13 +- .../{src => }/simd/arm/jfdctfst-neon.c | 12 +- .../{src => }/simd/arm/jfdctint-neon.c | 12 +- .../{src => }/simd/arm/jidctfst-neon.c | 12 +- .../{src => }/simd/arm/jidctint-neon.c | 12 +- .../{src => }/simd/arm/jidctred-neon.c | 12 +- .../{src => }/simd/arm/jquanti-neon.c | 12 +- .../{src => }/simd/arm/neon-compat.h.in | 10 +- .../{src => }/simd/i386/jccolext-avx2.asm | 6 +- .../{src => }/simd/i386/jccolext-mmx.asm | 6 +- .../{src => }/simd/i386/jccolext-sse2.asm | 6 +- .../{src => }/simd/i386/jccolor-avx2.asm | 6 +- .../{src => }/simd/i386/jccolor-mmx.asm | 6 +- .../{src => }/simd/i386/jccolor-sse2.asm | 6 +- .../{src => }/simd/i386/jcgray-avx2.asm | 6 +- .../{src => }/simd/i386/jcgray-mmx.asm | 6 +- .../{src => }/simd/i386/jcgray-sse2.asm | 6 +- .../{src => }/simd/i386/jcgryext-avx2.asm | 6 +- .../{src => }/simd/i386/jcgryext-mmx.asm | 6 +- .../{src => }/simd/i386/jcgryext-sse2.asm | 6 +- .../{src => }/simd/i386/jchuff-sse2.asm | 6 +- .../{src => }/simd/i386/jcphuff-sse2.asm | 6 +- .../{src => }/simd/i386/jcsample-avx2.asm | 6 +- .../{src => }/simd/i386/jcsample-mmx.asm | 6 +- .../{src => }/simd/i386/jcsample-sse2.asm | 6 +- .../{src => }/simd/i386/jdcolext-avx2.asm | 6 +- .../{src => }/simd/i386/jdcolext-mmx.asm | 6 +- .../{src => }/simd/i386/jdcolext-sse2.asm | 6 +- .../{src => }/simd/i386/jdcolor-avx2.asm | 6 +- .../{src => }/simd/i386/jdcolor-mmx.asm | 6 +- .../{src => }/simd/i386/jdcolor-sse2.asm | 6 +- .../{src => }/simd/i386/jdmerge-avx2.asm | 6 +- .../{src => }/simd/i386/jdmerge-mmx.asm | 6 +- .../{src => }/simd/i386/jdmerge-sse2.asm | 6 +- .../{src => }/simd/i386/jdmrgext-avx2.asm | 6 +- .../{src => }/simd/i386/jdmrgext-mmx.asm | 6 +- .../{src => }/simd/i386/jdmrgext-sse2.asm | 6 +- .../{src => }/simd/i386/jdsample-avx2.asm | 6 +- .../{src => }/simd/i386/jdsample-mmx.asm | 6 +- .../{src => }/simd/i386/jdsample-sse2.asm | 6 +- .../{src => }/simd/i386/jfdctflt-3dn.asm | 6 +- .../{src => }/simd/i386/jfdctflt-sse.asm | 6 +- .../{src => }/simd/i386/jfdctfst-mmx.asm | 6 +- .../{src => }/simd/i386/jfdctfst-sse2.asm | 6 +- .../{src => }/simd/i386/jfdctint-avx2.asm | 6 +- .../{src => }/simd/i386/jfdctint-mmx.asm | 6 +- .../{src => }/simd/i386/jfdctint-sse2.asm | 6 +- .../{src => }/simd/i386/jidctflt-3dn.asm | 6 +- .../{src => }/simd/i386/jidctflt-sse.asm | 6 +- .../{src => }/simd/i386/jidctflt-sse2.asm | 6 +- .../{src => }/simd/i386/jidctfst-mmx.asm | 6 +- .../{src => }/simd/i386/jidctfst-sse2.asm | 6 +- .../{src => }/simd/i386/jidctint-avx2.asm | 6 +- .../{src => }/simd/i386/jidctint-mmx.asm | 6 +- .../{src => }/simd/i386/jidctint-sse2.asm | 6 +- .../{src => }/simd/i386/jidctred-mmx.asm | 6 +- .../{src => }/simd/i386/jidctred-sse2.asm | 6 +- .../{src => }/simd/i386/jquant-3dn.asm | 6 +- .../{src => }/simd/i386/jquant-mmx.asm | 10 +- .../{src => }/simd/i386/jquant-sse.asm | 6 +- .../{src => }/simd/i386/jquantf-sse2.asm | 6 +- .../{src => }/simd/i386/jquanti-avx2.asm | 12 +- .../{src => }/simd/i386/jquanti-sse2.asm | 10 +- .../libjpeg-turbo/{src => }/simd/i386/jsimd.c | 12 +- .../{src => }/simd/i386/jsimdcpu.asm | 6 +- 3rdparty/libjpeg-turbo/{src => }/simd/jsimd.h | 0 .../libjpeg-turbo/{src => }/simd/mips/jsimd.c | 13 +- .../{src => }/simd/mips/jsimd_dspr2.S | 0 .../{src => }/simd/mips/jsimd_dspr2_asm.h | 0 .../{src => }/simd/mips64/jccolext-mmi.c | 0 .../{src => }/simd/mips64/jccolor-mmi.c | 0 .../{src => }/simd/mips64/jcgray-mmi.c | 0 .../{src => }/simd/mips64/jcgryext-mmi.c | 0 .../{src => }/simd/mips64/jcsample-mmi.c | 0 .../{src => }/simd/mips64/jcsample.h | 0 .../{src => }/simd/mips64/jdcolext-mmi.c | 0 .../{src => }/simd/mips64/jdcolor-mmi.c | 0 .../{src => }/simd/mips64/jdmerge-mmi.c | 0 .../{src => }/simd/mips64/jdmrgext-mmi.c | 0 .../{src => }/simd/mips64/jdsample-mmi.c | 0 .../{src => }/simd/mips64/jfdctfst-mmi.c | 0 .../{src => }/simd/mips64/jfdctint-mmi.c | 0 .../{src => }/simd/mips64/jidctfst-mmi.c | 0 .../{src => }/simd/mips64/jidctint-mmi.c | 0 .../{src => }/simd/mips64/jquanti-mmi.c | 0 .../{src => }/simd/mips64/jsimd.c | 12 +- .../{src => }/simd/mips64/jsimd_mmi.h | 7 +- .../{src => }/simd/mips64/loongson-mmintrin.h | 0 .../{src => }/simd/nasm/jcolsamp.inc | 0 .../{src => }/simd/nasm/jdct.inc | 0 .../{src => }/simd/nasm/jsimdcfg.inc | 0 .../{src => }/simd/nasm/jsimdcfg.inc.h | 4 +- .../{src => }/simd/nasm/jsimdext.inc | 0 .../{src => }/simd/powerpc/jccolext-altivec.c | 14 +- .../{src => }/simd/powerpc/jccolor-altivec.c | 0 .../{src => }/simd/powerpc/jcgray-altivec.c | 0 .../{src => }/simd/powerpc/jcgryext-altivec.c | 12 +- .../{src => }/simd/powerpc/jcsample-altivec.c | 6 +- .../{src => }/simd/powerpc/jcsample.h | 0 .../{src => }/simd/powerpc/jdcolext-altivec.c | 12 +- .../{src => }/simd/powerpc/jdcolor-altivec.c | 0 .../{src => }/simd/powerpc/jdmerge-altivec.c | 0 .../{src => }/simd/powerpc/jdmrgext-altivec.c | 12 +- .../{src => }/simd/powerpc/jdsample-altivec.c | 6 +- .../{src => }/simd/powerpc/jfdctfst-altivec.c | 0 .../{src => }/simd/powerpc/jfdctint-altivec.c | 0 .../{src => }/simd/powerpc/jidctfst-altivec.c | 6 +- .../{src => }/simd/powerpc/jidctint-altivec.c | 4 +- .../{src => }/simd/powerpc/jquanti-altivec.c | 6 +- .../{src => }/simd/powerpc/jsimd.c | 12 +- .../{src => }/simd/powerpc/jsimd_altivec.h | 23 +- .../{src => }/simd/x86_64/jccolext-avx2.asm | 6 +- .../{src => }/simd/x86_64/jccolext-sse2.asm | 6 +- .../{src => }/simd/x86_64/jccolor-avx2.asm | 6 +- .../{src => }/simd/x86_64/jccolor-sse2.asm | 6 +- .../{src => }/simd/x86_64/jcgray-avx2.asm | 6 +- .../{src => }/simd/x86_64/jcgray-sse2.asm | 6 +- .../{src => }/simd/x86_64/jcgryext-avx2.asm | 6 +- .../{src => }/simd/x86_64/jcgryext-sse2.asm | 6 +- .../{src => }/simd/x86_64/jchuff-sse2.asm | 6 +- .../{src => }/simd/x86_64/jcphuff-sse2.asm | 6 +- .../{src => }/simd/x86_64/jcsample-avx2.asm | 6 +- .../{src => }/simd/x86_64/jcsample-sse2.asm | 6 +- .../{src => }/simd/x86_64/jdcolext-avx2.asm | 6 +- .../{src => }/simd/x86_64/jdcolext-sse2.asm | 6 +- .../{src => }/simd/x86_64/jdcolor-avx2.asm | 6 +- .../{src => }/simd/x86_64/jdcolor-sse2.asm | 6 +- .../{src => }/simd/x86_64/jdmerge-avx2.asm | 6 +- .../{src => }/simd/x86_64/jdmerge-sse2.asm | 6 +- .../{src => }/simd/x86_64/jdmrgext-avx2.asm | 6 +- .../{src => }/simd/x86_64/jdmrgext-sse2.asm | 6 +- .../{src => }/simd/x86_64/jdsample-avx2.asm | 6 +- .../{src => }/simd/x86_64/jdsample-sse2.asm | 6 +- .../{src => }/simd/x86_64/jfdctflt-sse.asm | 6 +- .../{src => }/simd/x86_64/jfdctfst-sse2.asm | 6 +- .../{src => }/simd/x86_64/jfdctint-avx2.asm | 6 +- .../{src => }/simd/x86_64/jfdctint-sse2.asm | 6 +- .../{src => }/simd/x86_64/jidctflt-sse2.asm | 6 +- .../{src => }/simd/x86_64/jidctfst-sse2.asm | 6 +- .../{src => }/simd/x86_64/jidctint-avx2.asm | 6 +- .../{src => }/simd/x86_64/jidctint-sse2.asm | 6 +- .../{src => }/simd/x86_64/jidctred-sse2.asm | 6 +- .../{src => }/simd/x86_64/jquantf-sse2.asm | 6 +- .../{src => }/simd/x86_64/jquanti-avx2.asm | 10 +- .../{src => }/simd/x86_64/jquanti-sse2.asm | 10 +- .../{src => }/simd/x86_64/jsimd.c | 12 +- .../{src => }/simd/x86_64/jsimdcpu.asm | 6 +- 3rdparty/libjpeg-turbo/src/cjpeg.c | 841 ----- 3rdparty/libjpeg-turbo/src/cmyk.h | 61 - 3rdparty/libjpeg-turbo/src/djpeg.c | 932 ------ 3rdparty/libjpeg-turbo/src/example.c | 643 ---- 3rdparty/libjpeg-turbo/src/jcapimin.c | 16 +- 3rdparty/libjpeg-turbo/src/jcapistd.c | 19 +- 3rdparty/libjpeg-turbo/src/jccolor.c | 29 +- 3rdparty/libjpeg-turbo/src/jcdctmgr.c | 6 +- 3rdparty/libjpeg-turbo/src/jcdiffct.c | 10 +- 3rdparty/libjpeg-turbo/src/jchuff.c | 4 + 3rdparty/libjpeg-turbo/src/jcinit.c | 60 +- 3rdparty/libjpeg-turbo/src/jclossls.c | 10 +- 3rdparty/libjpeg-turbo/src/jcmainct.c | 19 +- 3rdparty/libjpeg-turbo/src/jcmaster.c | 49 +- 3rdparty/libjpeg-turbo/src/jcomapi.c | 5 +- 3rdparty/libjpeg-turbo/src/jcparam.c | 11 +- 3rdparty/libjpeg-turbo/src/jcphuff.c | 10 + 3rdparty/libjpeg-turbo/src/jcprepct.c | 19 +- 3rdparty/libjpeg-turbo/src/jcsample.c | 19 +- 3rdparty/libjpeg-turbo/src/jdapimin.c | 4 + 3rdparty/libjpeg-turbo/src/jdapistd.c | 44 +- 3rdparty/libjpeg-turbo/src/jdatadst-tj.c | 5 +- 3rdparty/libjpeg-turbo/src/jdcolor.c | 27 +- 3rdparty/libjpeg-turbo/src/jddiffct.c | 10 +- 3rdparty/libjpeg-turbo/src/jdinput.c | 19 +- 3rdparty/libjpeg-turbo/src/jdlossls.c | 10 +- 3rdparty/libjpeg-turbo/src/jdmainct.c | 19 +- 3rdparty/libjpeg-turbo/src/jdmarker.c | 18 +- 3rdparty/libjpeg-turbo/src/jdmaster.c | 170 +- 3rdparty/libjpeg-turbo/src/jdpostct.c | 19 +- 3rdparty/libjpeg-turbo/src/jdsample.c | 19 +- 3rdparty/libjpeg-turbo/src/jerror.c | 2 - 3rdparty/libjpeg-turbo/src/jmemmgr.c | 141 +- 3rdparty/libjpeg-turbo/src/jmemnobs.c | 6 +- 3rdparty/libjpeg-turbo/src/jpegint.h | 11 +- 3rdparty/libjpeg-turbo/src/jpeglib.h | 62 +- 3rdparty/libjpeg-turbo/src/jquant1.c | 32 +- 3rdparty/libjpeg-turbo/src/jsamplecomp.h | 3 - 3rdparty/libjpeg-turbo/src/jstdhuff.c | 4 +- 3rdparty/libjpeg-turbo/src/jversion.h.in | 56 - 3rdparty/libjpeg-turbo/src/libjpeg.map.in | 11 - 3rdparty/libjpeg-turbo/src/libjpeg.txt | 233 +- 3rdparty/libjpeg-turbo/src/rdbmp.c | 689 ---- 3rdparty/libjpeg-turbo/src/rdcolmap.c | 261 -- 3rdparty/libjpeg-turbo/src/rdgif.c | 720 ---- 3rdparty/libjpeg-turbo/src/rdjpgcom.c | 493 --- 3rdparty/libjpeg-turbo/src/rdppm.c | 890 ----- 3rdparty/libjpeg-turbo/src/rdswitch.c | 428 --- 3rdparty/libjpeg-turbo/src/rdtarga.c | 507 --- 3rdparty/libjpeg-turbo/src/tjbench.c | 1323 -------- 3rdparty/libjpeg-turbo/src/tjutil.c | 70 - 3rdparty/libjpeg-turbo/src/tjutil.h | 53 - 3rdparty/libjpeg-turbo/src/transupp.c | 2377 -------------- 3rdparty/libjpeg-turbo/src/transupp.h | 231 -- 3rdparty/libjpeg-turbo/src/turbojpeg-jni.c | 1400 -------- 3rdparty/libjpeg-turbo/src/turbojpeg-mapfile | 108 - .../libjpeg-turbo/src/turbojpeg-mapfile.jni | 142 - 3rdparty/libjpeg-turbo/src/turbojpeg-mp.c | 541 --- 3rdparty/libjpeg-turbo/src/turbojpeg.c | 2921 ----------------- 3rdparty/libjpeg-turbo/src/turbojpeg.h | 2328 ------------- 231 files changed, 1056 insertions(+), 19172 deletions(-) rename 3rdparty/libjpeg-turbo/{src => }/simd/CMakeLists.txt (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/aarch32/jccolext-neon.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/aarch32/jchuff-neon.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/aarch32/jsimd.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/aarch32/jsimd_neon.S (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/aarch64/jccolext-neon.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/aarch64/jchuff-neon.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/aarch64/jsimd.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/aarch64/jsimd_neon.S (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/align.h (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jccolor-neon.c (95%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jcgray-neon.c (93%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jcgryext-neon.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jchuff.h (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jcphuff-neon.c (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jcsample-neon.c (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jdcolext-neon.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jdcolor-neon.c (94%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jdmerge-neon.c (95%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jdmrgext-neon.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jdsample-neon.c (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jfdctfst-neon.c (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jfdctint-neon.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jidctfst-neon.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jidctint-neon.c (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jidctred-neon.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/jquanti-neon.c (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/arm/neon-compat.h.in (81%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jccolext-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jccolext-mmx.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jccolext-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jccolor-avx2.asm (92%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jccolor-mmx.asm (92%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jccolor-sse2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcgray-avx2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcgray-mmx.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcgray-sse2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcgryext-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcgryext-mmx.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcgryext-sse2.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jchuff-sse2.asm (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcphuff-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcsample-avx2.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcsample-mmx.asm (96%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jcsample-sse2.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdcolext-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdcolext-mmx.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdcolext-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdcolor-avx2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdcolor-mmx.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdcolor-sse2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdmerge-avx2.asm (92%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdmerge-mmx.asm (92%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdmerge-sse2.asm (92%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdmrgext-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdmrgext-mmx.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdmrgext-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdsample-avx2.asm (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdsample-mmx.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jdsample-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jfdctflt-3dn.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jfdctflt-sse.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jfdctfst-mmx.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jfdctfst-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jfdctint-avx2.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jfdctint-mmx.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jfdctint-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctflt-3dn.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctflt-sse.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctflt-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctfst-mmx.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctfst-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctint-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctint-mmx.asm (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctint-sse2.asm (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctred-mmx.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jidctred-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jquant-3dn.asm (96%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jquant-mmx.asm (95%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jquant-sse.asm (96%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jquantf-sse2.asm (95%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jquanti-avx2.asm (93%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jquanti-sse2.asm (94%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jsimd.c (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/i386/jsimdcpu.asm (92%) rename 3rdparty/libjpeg-turbo/{src => }/simd/jsimd.h (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips/jsimd.c (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips/jsimd_dspr2.S (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips/jsimd_dspr2_asm.h (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jccolext-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jccolor-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jcgray-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jcgryext-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jcsample-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jcsample.h (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jdcolext-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jdcolor-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jdmerge-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jdmrgext-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jdsample-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jfdctfst-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jfdctint-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jidctfst-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jidctint-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jquanti-mmi.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jsimd.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/jsimd_mmi.h (93%) rename 3rdparty/libjpeg-turbo/{src => }/simd/mips64/loongson-mmintrin.h (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/nasm/jcolsamp.inc (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/nasm/jdct.inc (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/nasm/jsimdcfg.inc (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/nasm/jsimdcfg.inc.h (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/nasm/jsimdext.inc (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jccolext-altivec.c (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jccolor-altivec.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jcgray-altivec.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jcgryext-altivec.c (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jcsample-altivec.c (96%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jcsample.h (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jdcolext-altivec.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jdcolor-altivec.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jdmerge-altivec.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jdmrgext-altivec.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jdsample-altivec.c (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jfdctfst-altivec.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jfdctint-altivec.c (100%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jidctfst-altivec.c (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jidctint-altivec.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jquanti-altivec.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jsimd.c (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/powerpc/jsimd_altivec.h (89%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jccolext-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jccolext-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jccolor-avx2.asm (92%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jccolor-sse2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jcgray-avx2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jcgray-sse2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jcgryext-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jcgryext-sse2.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jchuff-sse2.asm (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jcphuff-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jcsample-avx2.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jcsample-sse2.asm (96%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdcolext-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdcolext-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdcolor-avx2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdcolor-sse2.asm (91%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdmerge-avx2.asm (92%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdmerge-sse2.asm (92%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdmrgext-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdmrgext-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdsample-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jdsample-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jfdctflt-sse.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jfdctfst-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jfdctint-avx2.asm (97%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jfdctint-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jidctflt-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jidctfst-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jidctint-avx2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jidctint-sse2.asm (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jidctred-sse2.asm (98%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jquantf-sse2.asm (94%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jquanti-avx2.asm (93%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jquanti-sse2.asm (93%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jsimd.c (99%) rename 3rdparty/libjpeg-turbo/{src => }/simd/x86_64/jsimdcpu.asm (88%) delete mode 100644 3rdparty/libjpeg-turbo/src/cjpeg.c delete mode 100644 3rdparty/libjpeg-turbo/src/cmyk.h delete mode 100644 3rdparty/libjpeg-turbo/src/djpeg.c delete mode 100644 3rdparty/libjpeg-turbo/src/example.c delete mode 100644 3rdparty/libjpeg-turbo/src/jversion.h.in delete mode 100644 3rdparty/libjpeg-turbo/src/libjpeg.map.in delete mode 100644 3rdparty/libjpeg-turbo/src/rdbmp.c delete mode 100644 3rdparty/libjpeg-turbo/src/rdcolmap.c delete mode 100644 3rdparty/libjpeg-turbo/src/rdgif.c delete mode 100644 3rdparty/libjpeg-turbo/src/rdjpgcom.c delete mode 100644 3rdparty/libjpeg-turbo/src/rdppm.c delete mode 100644 3rdparty/libjpeg-turbo/src/rdswitch.c delete mode 100644 3rdparty/libjpeg-turbo/src/rdtarga.c delete mode 100644 3rdparty/libjpeg-turbo/src/tjbench.c delete mode 100644 3rdparty/libjpeg-turbo/src/tjutil.c delete mode 100644 3rdparty/libjpeg-turbo/src/tjutil.h delete mode 100644 3rdparty/libjpeg-turbo/src/transupp.c delete mode 100644 3rdparty/libjpeg-turbo/src/transupp.h delete mode 100644 3rdparty/libjpeg-turbo/src/turbojpeg-jni.c delete mode 100644 3rdparty/libjpeg-turbo/src/turbojpeg-mapfile delete mode 100644 3rdparty/libjpeg-turbo/src/turbojpeg-mapfile.jni delete mode 100644 3rdparty/libjpeg-turbo/src/turbojpeg-mp.c delete mode 100644 3rdparty/libjpeg-turbo/src/turbojpeg.c delete mode 100644 3rdparty/libjpeg-turbo/src/turbojpeg.h diff --git a/3rdparty/libjpeg-turbo/CMakeLists.txt b/3rdparty/libjpeg-turbo/CMakeLists.txt index f41665f329..b08fb266ec 100644 --- a/3rdparty/libjpeg-turbo/CMakeLists.txt +++ b/3rdparty/libjpeg-turbo/CMakeLists.txt @@ -18,7 +18,7 @@ if(CV_GCC AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13) ocv_warnings_disable(CMAKE_C_FLAGS -Wstringop-overflow) endif() -set(VERSION 3.0.3) +set(VERSION 3.1.0) set(COPYRIGHT_YEAR "1991-2024") string(REPLACE "." ";" VERSION_TRIPLET ${VERSION}) list(GET VERSION_TRIPLET 0 VERSION_MAJOR) @@ -203,7 +203,7 @@ check_type_size("size_t" SIZE_T) check_type_size("unsigned long" UNSIGNED_LONG) if(ENABLE_LIBJPEG_TURBO_SIMD) - add_subdirectory(src/simd) + add_subdirectory(simd) if(NEON_INTRINSICS) add_definitions(-DNEON_INTRINSICS) endif() diff --git a/3rdparty/libjpeg-turbo/LICENSE.md b/3rdparty/libjpeg-turbo/LICENSE.md index 2204864fa1..a785258bcd 100644 --- a/3rdparty/libjpeg-turbo/LICENSE.md +++ b/3rdparty/libjpeg-turbo/LICENSE.md @@ -94,7 +94,7 @@ intended solely for clarification. The Modified (3-clause) BSD License =================================== -Copyright (C)2009-2023 D. R. Commander. All Rights Reserved.
+Copyright (C)2009-2024 D. R. Commander. All Rights Reserved.
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved. Redistribution and use in source and binary forms, with or without diff --git a/3rdparty/libjpeg-turbo/README.ijg b/3rdparty/libjpeg-turbo/README.ijg index 8f3768265f..dbf8070cac 100644 --- a/3rdparty/libjpeg-turbo/README.ijg +++ b/3rdparty/libjpeg-turbo/README.ijg @@ -36,16 +36,18 @@ TO DO Plans for future IJG releases. Other documentation files in the distribution are: User documentation: - usage.txt Usage instructions for cjpeg, djpeg, jpegtran, - rdjpgcom, and wrjpgcom. - *.1 Unix-style man pages for programs (same info as usage.txt). - wizard.txt Advanced usage instructions for JPEG wizards only. - change.log Version-to-version change highlights. + doc/usage.txt Usage instructions for cjpeg, djpeg, jpegtran, + rdjpgcom, and wrjpgcom. + doc/*.1 Unix-style man pages for programs (same info as + usage.txt). + doc/wizard.txt Advanced usage instructions for JPEG wizards only. + doc/change.log Version-to-version change highlights. Programmer and internal documentation: - libjpeg.txt How to use the JPEG library in your own programs. - example.c Sample code for calling the JPEG library. - structure.txt Overview of the JPEG library's internal structure. - coderules.txt Coding style rules --- please read if you contribute code. + doc/libjpeg.txt How to use the JPEG library in your own programs. + src/example.c Sample code for calling the JPEG library. + doc/structure.txt Overview of the JPEG library's internal structure. + doc/coderules.txt Coding style rules --- please read if you contribute + code. Please read at least usage.txt. Some information can also be found in the JPEG FAQ (Frequently Asked Questions) article. See ARCHIVE LOCATIONS below to find @@ -89,9 +91,9 @@ The library is intended to be reused in other applications. In order to support file conversion and viewing software, we have included considerable functionality beyond the bare JPEG coding/decoding capability; for example, the color quantization modules are not strictly part of JPEG -decoding, but they are essential for output to colormapped file formats or -colormapped displays. These extra functions can be compiled out of the -library if not required for a particular application. +decoding, but they are essential for output to colormapped file formats. These +extra functions can be compiled out of the library if not required for a +particular application. We have also included "jpegtran", a utility for lossless transcoding between different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple diff --git a/3rdparty/libjpeg-turbo/README.md b/3rdparty/libjpeg-turbo/README.md index 923e61d231..86b5ea676a 100644 --- a/3rdparty/libjpeg-turbo/README.md +++ b/3rdparty/libjpeg-turbo/README.md @@ -69,9 +69,12 @@ JPEG images: generating planar YUV images and performing multiple simultaneous lossless transforms on an image. The Java interface for libjpeg-turbo is written on top of the TurboJPEG API. The TurboJPEG API is recommended for first-time - users of libjpeg-turbo. Refer to [tjexample.c](tjexample.c) and - [TJExample.java](java/TJExample.java) for examples of its usage and to - for API documentation. + users of libjpeg-turbo. Refer to [tjcomp.c](src/tjcomp.c), + [tjdecomp.c](src/tjdecomp.c), [tjtran.c](src/tjtran.c), + [TJComp.java](java/TJComp.java), [TJDecomp.java](java/TJDecomp.java), and + [TJTran.java](java/TJTran.java) for examples of its usage and to + for API + documentation. - **libjpeg API**
This is the de facto industry-standard API for compressing and decompressing @@ -79,8 +82,9 @@ JPEG images: more powerful. The libjpeg API implementation in libjpeg-turbo is both API/ABI-compatible and mathematically compatible with libjpeg v6b. It can also optionally be configured to be API/ABI-compatible with libjpeg v7 and v8 - (see below.) Refer to [cjpeg.c](cjpeg.c) and [djpeg.c](djpeg.c) for examples - of its usage and to [libjpeg.txt](libjpeg.txt) for API documentation. + (see below.) Refer to [cjpeg.c](src/cjpeg.c) and [djpeg.c](src/djpeg.c) for + examples of its usage and to [libjpeg.txt](doc/libjpeg.txt) for API + documentation. There is no significant performance advantage to either API when both are used to perform similar operations. @@ -132,9 +136,9 @@ extensions at compile time with: #ifdef JCS_ALPHA_EXTENSIONS -[jcstest.c](jcstest.c), located in the libjpeg-turbo source tree, demonstrates -how to check for the existence of the colorspace extensions at compile time and -run time. +[jcstest.c](src/jcstest.c), located in the libjpeg-turbo source tree, +demonstrates how to check for the existence of the colorspace extensions at +compile time and run time. libjpeg v7 and v8 API/ABI Emulation ----------------------------------- @@ -199,7 +203,7 @@ supported and which aren't. NOTE: As of this writing, extensive research has been conducted into the usefulness of DCT scaling as a means of data reduction and SmartScale as a means of quality improvement. Readers are invited to peruse the research at - and draw their own conclusions, + and draw their own conclusions, but it is the general belief of our project that these features have not demonstrated sufficient usefulness to justify inclusion in libjpeg-turbo. diff --git a/3rdparty/libjpeg-turbo/src/simd/CMakeLists.txt b/3rdparty/libjpeg-turbo/simd/CMakeLists.txt similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/CMakeLists.txt rename to 3rdparty/libjpeg-turbo/simd/CMakeLists.txt index 48944c6bfe..61349ca9e6 100644 --- a/3rdparty/libjpeg-turbo/src/simd/CMakeLists.txt +++ b/3rdparty/libjpeg-turbo/simd/CMakeLists.txt @@ -273,48 +273,33 @@ endif() check_c_source_compiles(" #include int main(int argc, char **argv) { - int16_t input[] = { - (int16_t)argc, (int16_t)argc, (int16_t)argc, (int16_t)argc, - (int16_t)argc, (int16_t)argc, (int16_t)argc, (int16_t)argc, - (int16_t)argc, (int16_t)argc, (int16_t)argc, (int16_t)argc - }; - int16x4x3_t output = vld1_s16_x3(input); + int16_t input[12]; + int16x4x3_t output; + int i; + for (i = 0; i < 12; i++) input[i] = (int16_t)argc; + output = vld1_s16_x3(input); vst3_s16(input, output); return (int)input[0]; }" HAVE_VLD1_S16_X3) check_c_source_compiles(" #include int main(int argc, char **argv) { - uint16_t input[] = { - (uint16_t)argc, (uint16_t)argc, (uint16_t)argc, (uint16_t)argc, - (uint16_t)argc, (uint16_t)argc, (uint16_t)argc, (uint16_t)argc - }; - uint16x4x2_t output = vld1_u16_x2(input); + uint16_t input[8]; + uint16x4x2_t output; + int i; + for (i = 0; i < 8; i++) input[i] = (uint16_t)argc; + output = vld1_u16_x2(input); vst2_u16(input, output); return (int)input[0]; }" HAVE_VLD1_U16_X2) check_c_source_compiles(" #include int main(int argc, char **argv) { - uint8_t input[] = { - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, - (uint8_t)argc, (uint8_t)argc, (uint8_t)argc, (uint8_t)argc - }; - uint8x16x4_t output = vld1q_u8_x4(input); + uint8_t input[64]; + uint8x16x4_t output; + int i; + for (i = 0; i < 64; i++) input[i] = (uint8_t)argc; + output = vld1q_u8_x4(input); vst4q_u8(input, output); return (int)input[0]; }" HAVE_VLD1Q_U8_X4) @@ -369,7 +354,8 @@ if(NOT NEON_INTRINSICS) separate_arguments(CMAKE_ASM_FLAGS_SEP UNIX_COMMAND "${CMAKE_ASM_FLAGS}") execute_process(COMMAND ${CMAKE_ASM_COMPILER} ${CMAKE_ASM_FLAGS_SEP} -x assembler-with-cpp -c ${CMAKE_CURRENT_BINARY_DIR}/gastest.S - RESULT_VARIABLE RESULT OUTPUT_VARIABLE OUTPUT ERROR_VARIABLE ERROR) + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} RESULT_VARIABLE RESULT + OUTPUT_VARIABLE OUTPUT ERROR_VARIABLE ERROR) if(NOT RESULT EQUAL 0) message(WARNING "GAS appears to be broken. Using the full Neon SIMD intrinsics implementation.") set(NEON_INTRINSICS 1 CACHE INTERNAL "" FORCE) diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jccolext-neon.c b/3rdparty/libjpeg-turbo/simd/arm/aarch32/jccolext-neon.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jccolext-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/aarch32/jccolext-neon.c diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jchuff-neon.c b/3rdparty/libjpeg-turbo/simd/arm/aarch32/jchuff-neon.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jchuff-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/aarch32/jchuff-neon.c index 19d94f720d..153da1f1c1 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jchuff-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/aarch32/jchuff-neon.c @@ -2,6 +2,7 @@ * jchuff-neon.c - Huffman entropy encoding (32-bit Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. + * Copyright (C) 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -24,11 +25,11 @@ */ #define JPEG_INTERNALS -#include "../../../jinclude.h" -#include "../../../jpeglib.h" -#include "../../../jsimd.h" -#include "../../../jdct.h" -#include "../../../jsimddct.h" +#include "../../../src/jinclude.h" +#include "../../../src/jpeglib.h" +#include "../../../src/jsimd.h" +#include "../../../src/jdct.h" +#include "../../../src/jsimddct.h" #include "../../jsimd.h" #include "../jchuff.h" #include "neon-compat.h" diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jsimd.c b/3rdparty/libjpeg-turbo/simd/arm/aarch32/jsimd.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jsimd.c rename to 3rdparty/libjpeg-turbo/simd/arm/aarch32/jsimd.c index 04d64526fb..7c8ea306bd 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jsimd.c +++ b/3rdparty/libjpeg-turbo/simd/arm/aarch32/jsimd.c @@ -3,7 +3,7 @@ * * Copyright 2009 Pierre Ossman for Cendio AB * Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies). - * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2022, D. R. Commander. + * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2022, 2024, D. R. Commander. * Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois. * Copyright (C) 2019, Google LLC. * Copyright (C) 2020, Arm Limited. @@ -18,11 +18,11 @@ */ #define JPEG_INTERNALS -#include "../../../jinclude.h" -#include "../../../jpeglib.h" -#include "../../../jsimd.h" -#include "../../../jdct.h" -#include "../../../jsimddct.h" +#include "../../../src/jinclude.h" +#include "../../../src/jpeglib.h" +#include "../../../src/jsimd.h" +#include "../../../src/jdct.h" +#include "../../../src/jsimddct.h" #include "../../jsimd.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jsimd_neon.S b/3rdparty/libjpeg-turbo/simd/arm/aarch32/jsimd_neon.S similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/arm/aarch32/jsimd_neon.S rename to 3rdparty/libjpeg-turbo/simd/arm/aarch32/jsimd_neon.S diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jccolext-neon.c b/3rdparty/libjpeg-turbo/simd/arm/aarch64/jccolext-neon.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jccolext-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/aarch64/jccolext-neon.c diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jchuff-neon.c b/3rdparty/libjpeg-turbo/simd/arm/aarch64/jchuff-neon.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jchuff-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/aarch64/jchuff-neon.c index 607a116070..11bf6dab13 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jchuff-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/aarch64/jchuff-neon.c @@ -2,7 +2,7 @@ * jchuff-neon.c - Huffman entropy encoding (64-bit Arm Neon) * * Copyright (C) 2020-2021, Arm Limited. All Rights Reserved. - * Copyright (C) 2020, 2022, D. R. Commander. All Rights Reserved. + * Copyright (C) 2020, 2022, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -25,11 +25,11 @@ */ #define JPEG_INTERNALS -#include "../../../jinclude.h" -#include "../../../jpeglib.h" -#include "../../../jsimd.h" -#include "../../../jdct.h" -#include "../../../jsimddct.h" +#include "../../../src/jinclude.h" +#include "../../../src/jpeglib.h" +#include "../../../src/jsimd.h" +#include "../../../src/jdct.h" +#include "../../../src/jsimddct.h" #include "../../jsimd.h" #include "../align.h" #include "../jchuff.h" diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jsimd.c b/3rdparty/libjpeg-turbo/simd/arm/aarch64/jsimd.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jsimd.c rename to 3rdparty/libjpeg-turbo/simd/arm/aarch64/jsimd.c index 358e1597b1..8a6f30a1a8 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jsimd.c +++ b/3rdparty/libjpeg-turbo/simd/arm/aarch64/jsimd.c @@ -3,7 +3,8 @@ * * Copyright 2009 Pierre Ossman for Cendio AB * Copyright (C) 2011, Nokia Corporation and/or its subsidiary(-ies). - * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2020, 2022, D. R. Commander. + * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2020, 2022, 2024, + * D. R. Commander. * Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois. * Copyright (C) 2020, Arm Limited. * @@ -17,11 +18,11 @@ */ #define JPEG_INTERNALS -#include "../../../jinclude.h" -#include "../../../jpeglib.h" -#include "../../../jsimd.h" -#include "../../../jdct.h" -#include "../../../jsimddct.h" +#include "../../../src/jinclude.h" +#include "../../../src/jpeglib.h" +#include "../../../src/jsimd.h" +#include "../../../src/jdct.h" +#include "../../../src/jsimddct.h" #include "../../jsimd.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jsimd_neon.S b/3rdparty/libjpeg-turbo/simd/arm/aarch64/jsimd_neon.S similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/arm/aarch64/jsimd_neon.S rename to 3rdparty/libjpeg-turbo/simd/arm/aarch64/jsimd_neon.S diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/align.h b/3rdparty/libjpeg-turbo/simd/arm/align.h similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/arm/align.h rename to 3rdparty/libjpeg-turbo/simd/arm/align.h diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jccolor-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jccolor-neon.c similarity index 95% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jccolor-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jccolor-neon.c index 9fcc62dd25..d14a7bf501 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jccolor-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jccolor-neon.c @@ -2,7 +2,7 @@ * jccolor-neon.c - colorspace conversion (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. - * Copyright (C) 2020, D. R. Commander. All Rights Reserved. + * Copyright (C) 2020, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -22,11 +22,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" #include "neon-compat.h" diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jcgray-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jcgray-neon.c similarity index 93% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jcgray-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jcgray-neon.c index 71c7b2de21..fbcf821405 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jcgray-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jcgray-neon.c @@ -2,6 +2,7 @@ * jcgray-neon.c - grayscale colorspace conversion (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. + * Copyright (C) 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -21,13 +22,14 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" +#include "neon-compat.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jcgryext-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jcgryext-neon.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jcgryext-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jcgryext-neon.c diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jchuff.h b/3rdparty/libjpeg-turbo/simd/arm/jchuff.h similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jchuff.h rename to 3rdparty/libjpeg-turbo/simd/arm/jchuff.h diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jcphuff-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jcphuff-neon.c similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jcphuff-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jcphuff-neon.c index 51db3c5f39..435f96ee96 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jcphuff-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jcphuff-neon.c @@ -3,7 +3,7 @@ * * Copyright (C) 2020-2021, Arm Limited. All Rights Reserved. * Copyright (C) 2022, Matthieu Darbois. All Rights Reserved. - * Copyright (C) 2022, D. R. Commander. All Rights Reserved. + * Copyright (C) 2022, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -23,11 +23,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "neon-compat.h" diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jcsample-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jcsample-neon.c similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jcsample-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jcsample-neon.c index 8a3e237838..fd8a93e520 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jcsample-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jcsample-neon.c @@ -2,6 +2,7 @@ * jcsample-neon.c - downsampling (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. + * Copyright (C) 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -21,13 +22,14 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" +#include "neon-compat.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jdcolext-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jdcolext-neon.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jdcolext-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jdcolext-neon.c diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jdcolor-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jdcolor-neon.c similarity index 94% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jdcolor-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jdcolor-neon.c index 28dbc57243..97bb02a1ed 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jdcolor-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jdcolor-neon.c @@ -2,6 +2,7 @@ * jdcolor-neon.c - colorspace conversion (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. + * Copyright (C) 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -21,13 +22,14 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" +#include "neon-compat.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jdmerge-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jdmerge-neon.c similarity index 95% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jdmerge-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jdmerge-neon.c index 18fb9d8a55..95e6d32830 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jdmerge-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jdmerge-neon.c @@ -2,6 +2,7 @@ * jdmerge-neon.c - merged upsampling/color conversion (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. + * Copyright (C) 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -21,13 +22,14 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" +#include "neon-compat.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jdmrgext-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jdmrgext-neon.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jdmrgext-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jdmrgext-neon.c diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jdsample-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jdsample-neon.c similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jdsample-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jdsample-neon.c index 90ec6782c4..a130b1a958 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jdsample-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jdsample-neon.c @@ -2,7 +2,7 @@ * jdsample-neon.c - upsampling (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. - * Copyright (C) 2020, D. R. Commander. All Rights Reserved. + * Copyright (C) 2020, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -22,12 +22,13 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" +#include "neon-compat.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jfdctfst-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jfdctfst-neon.c similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jfdctfst-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jfdctfst-neon.c index bb371be399..d6109f11d3 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jfdctfst-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jfdctfst-neon.c @@ -2,6 +2,7 @@ * jfdctfst-neon.c - fast integer FDCT (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. + * Copyright (C) 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -21,13 +22,14 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" +#include "neon-compat.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jfdctint-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jfdctint-neon.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jfdctint-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jfdctint-neon.c index ccfc07b15d..bb290ea45d 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jfdctint-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jfdctint-neon.c @@ -2,7 +2,7 @@ * jfdctint-neon.c - accurate integer FDCT (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. - * Copyright (C) 2020, D. R. Commander. All Rights Reserved. + * Copyright (C) 2020, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -22,11 +22,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" #include "neon-compat.h" diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jidctfst-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jidctfst-neon.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jidctfst-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jidctfst-neon.c index a91be5362e..e789125344 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jidctfst-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jidctfst-neon.c @@ -2,6 +2,7 @@ * jidctfst-neon.c - fast integer IDCT (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. + * Copyright (C) 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -21,13 +22,14 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" +#include "neon-compat.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jidctint-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jidctint-neon.c similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jidctint-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jidctint-neon.c index d25112ef7f..709e0eaf4e 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jidctint-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jidctint-neon.c @@ -2,7 +2,7 @@ * jidctint-neon.c - accurate integer IDCT (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. - * Copyright (C) 2020, D. R. Commander. All Rights Reserved. + * Copyright (C) 2020, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -22,11 +22,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" #include "neon-compat.h" diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jidctred-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jidctred-neon.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jidctred-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jidctred-neon.c index be9627e61d..25b1addc6a 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jidctred-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jidctred-neon.c @@ -2,7 +2,7 @@ * jidctred-neon.c - reduced-size IDCT (Arm Neon) * * Copyright (C) 2020, Arm Limited. All Rights Reserved. - * Copyright (C) 2020, D. R. Commander. All Rights Reserved. + * Copyright (C) 2020, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -22,11 +22,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include "align.h" #include "neon-compat.h" diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/jquanti-neon.c b/3rdparty/libjpeg-turbo/simd/arm/jquanti-neon.c similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/arm/jquanti-neon.c rename to 3rdparty/libjpeg-turbo/simd/arm/jquanti-neon.c index d5d95d89f6..e44fb3d413 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/jquanti-neon.c +++ b/3rdparty/libjpeg-turbo/simd/arm/jquanti-neon.c @@ -2,6 +2,7 @@ * jquanti-neon.c - sample data conversion and quantization (Arm Neon) * * Copyright (C) 2020-2021, Arm Limited. All Rights Reserved. + * Copyright (C) 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -21,12 +22,13 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" +#include "neon-compat.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/arm/neon-compat.h.in b/3rdparty/libjpeg-turbo/simd/arm/neon-compat.h.in similarity index 81% rename from 3rdparty/libjpeg-turbo/src/simd/arm/neon-compat.h.in rename to 3rdparty/libjpeg-turbo/simd/arm/neon-compat.h.in index d403f2289f..63583088ab 100644 --- a/3rdparty/libjpeg-turbo/src/simd/arm/neon-compat.h.in +++ b/3rdparty/libjpeg-turbo/simd/arm/neon-compat.h.in @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020, D. R. Commander. All Rights Reserved. + * Copyright (C) 2020, 2024, D. R. Commander. All Rights Reserved. * Copyright (C) 2020-2021, Arm Limited. All Rights Reserved. * * This software is provided 'as-is', without any express or implied @@ -35,3 +35,11 @@ #else #error "Unknown compiler" #endif + +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wdeclaration-after-statement" +#pragma clang diagnostic ignored "-Wc99-extensions" +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wdeclaration-after-statement" +#pragma GCC diagnostic ignored "-Wpedantic" +#endif diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jccolext-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jccolext-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jccolext-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jccolext-avx2.asm index af6418f0a6..28ac952807 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jccolext-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jccolext-avx2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jccolext-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jccolext-mmx.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jccolext-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jccolext-mmx.asm index dbec80e787..44b62512e9 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jccolext-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jccolext-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jccolext-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jccolext-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jccolext-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jccolext-sse2.asm index 8d41145178..1d8d5f5a20 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jccolext-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jccolext-sse2.asm @@ -7,11 +7,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jccolor-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jccolor-avx2.asm similarity index 92% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jccolor-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jccolor-avx2.asm index 3d6dfa6f8c..9ad5ea95f8 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jccolor-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jccolor-avx2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jccolor-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jccolor-mmx.asm similarity index 92% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jccolor-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jccolor-mmx.asm index 0527488500..0dbec54817 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jccolor-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jccolor-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jccolor-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jccolor-sse2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jccolor-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jccolor-sse2.asm index ff6a2ecd13..678306a10c 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jccolor-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jccolor-sse2.asm @@ -7,11 +7,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcgray-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jcgray-avx2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcgray-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcgray-avx2.asm index 564974f849..ded39567df 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcgray-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcgray-avx2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcgray-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jcgray-mmx.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcgray-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcgray-mmx.asm index e791ea4aa6..d6f031869a 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcgray-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcgray-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcgray-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jcgray-sse2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcgray-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcgray-sse2.asm index 70c0177db3..ecc7fa08ab 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcgray-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcgray-sse2.asm @@ -7,11 +7,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcgryext-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jcgryext-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcgryext-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcgryext-avx2.asm index 0fb284aaf9..70df8f80ba 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcgryext-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcgryext-avx2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcgryext-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jcgryext-mmx.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcgryext-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcgryext-mmx.asm index 1c69d38291..dd90c3dfb0 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcgryext-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcgryext-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcgryext-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jcgryext-sse2.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcgryext-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcgryext-sse2.asm index f710816a44..227295f307 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcgryext-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcgryext-sse2.asm @@ -7,11 +7,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jchuff-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jchuff-sse2.asm similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jchuff-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jchuff-sse2.asm index 4adf5eb514..ed194dd383 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jchuff-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jchuff-sse2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains an SSE2 implementation for Huffman coding of one block. ; The following code is based on jchuff.c; see jchuff.c for more details. diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcphuff-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jcphuff-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcphuff-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcphuff-sse2.asm index c26b48a47d..19a183fcd8 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcphuff-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcphuff-sse2.asm @@ -7,11 +7,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains an SSE2 implementation of data preparation for progressive ; Huffman encoding. See jcphuff.c for more details. diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcsample-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jcsample-avx2.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcsample-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcsample-avx2.asm index 3d40f1d9fb..5019829c9a 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcsample-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcsample-avx2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcsample-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jcsample-mmx.asm similarity index 96% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcsample-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcsample-mmx.asm index 38d5b322b6..94dd88870a 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcsample-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcsample-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jcsample-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jcsample-sse2.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jcsample-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jcsample-sse2.asm index 26c5d7407e..eb8808bea8 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jcsample-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jcsample-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolext-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdcolext-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdcolext-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdcolext-avx2.asm index 53ea3128fc..fd79b79568 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolext-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdcolext-avx2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolext-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jdcolext-mmx.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdcolext-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdcolext-mmx.asm index d97faee004..636bd6d3fd 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolext-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdcolext-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolext-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdcolext-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdcolext-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdcolext-sse2.asm index 682efc730f..0150f2cb69 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolext-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdcolext-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolor-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdcolor-avx2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdcolor-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdcolor-avx2.asm index 0f9baf840c..d3a30d63a7 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolor-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdcolor-avx2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolor-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jdcolor-mmx.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdcolor-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdcolor-mmx.asm index 21e833292c..6e67e4b72e 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolor-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdcolor-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolor-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdcolor-sse2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdcolor-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdcolor-sse2.asm index 481d0e4c95..79c9c6821a 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdcolor-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdcolor-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdmerge-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdmerge-avx2.asm similarity index 92% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdmerge-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdmerge-avx2.asm index 00201dc419..90493fd023 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdmerge-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdmerge-avx2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdmerge-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jdmerge-mmx.asm similarity index 92% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdmerge-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdmerge-mmx.asm index be28c63f53..0dc204aa8b 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdmerge-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdmerge-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdmerge-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdmerge-sse2.asm similarity index 92% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdmerge-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdmerge-sse2.asm index 9b40a67dbd..06f0762742 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdmerge-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdmerge-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdmrgext-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdmrgext-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdmrgext-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdmrgext-avx2.asm index 97988eb602..a7aa930e34 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdmrgext-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdmrgext-avx2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdmrgext-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jdmrgext-mmx.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdmrgext-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdmrgext-mmx.asm index 79cee73dbd..562758146c 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdmrgext-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdmrgext-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdmrgext-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdmrgext-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdmrgext-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdmrgext-sse2.asm index 331344358b..13e7d980fa 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdmrgext-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdmrgext-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdsample-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdsample-avx2.asm similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdsample-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdsample-avx2.asm index b0507aa5d6..eba53ef757 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdsample-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdsample-avx2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdsample-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jdsample-mmx.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdsample-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdsample-mmx.asm index 6f70499c97..01d09e62d1 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdsample-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdsample-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jdsample-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jdsample-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jdsample-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jdsample-sse2.asm index f68c5ea545..b10d922798 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jdsample-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jdsample-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctflt-3dn.asm b/3rdparty/libjpeg-turbo/simd/i386/jfdctflt-3dn.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jfdctflt-3dn.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jfdctflt-3dn.asm index 34af2bf0ba..0cedc6caf4 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctflt-3dn.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jfdctflt-3dn.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a floating-point implementation of the forward DCT ; (Discrete Cosine Transform). The following code is based directly on diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctflt-sse.asm b/3rdparty/libjpeg-turbo/simd/i386/jfdctflt-sse.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jfdctflt-sse.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jfdctflt-sse.asm index d247094b64..2cb9533586 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctflt-sse.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jfdctflt-sse.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a floating-point implementation of the forward DCT ; (Discrete Cosine Transform). The following code is based directly on diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctfst-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jfdctfst-mmx.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jfdctfst-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jfdctfst-mmx.asm index 8c55a9876d..fe16e83ee2 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctfst-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jfdctfst-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a fast, not so accurate integer implementation of ; the forward DCT (Discrete Cosine Transform). The following code is diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctfst-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jfdctfst-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jfdctfst-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jfdctfst-sse2.asm index c1ba533d6d..890482e006 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctfst-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jfdctfst-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a fast, not so accurate integer implementation of ; the forward DCT (Discrete Cosine Transform). The following code is diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctint-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jfdctint-avx2.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jfdctint-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jfdctint-avx2.asm index 21c3d5b223..05ea865485 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctint-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jfdctint-avx2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; forward DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctint-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jfdctint-mmx.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jfdctint-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jfdctint-mmx.asm index c2f308ed3b..7d4c61cd7d 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctint-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jfdctint-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; forward DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctint-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jfdctint-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jfdctint-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jfdctint-sse2.asm index b6e679918d..7ed5c9501a 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jfdctint-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jfdctint-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; forward DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctflt-3dn.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctflt-3dn.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctflt-3dn.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctflt-3dn.asm index 1f696cb59b..8612eee3a5 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctflt-3dn.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctflt-3dn.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a floating-point implementation of the inverse DCT ; (Discrete Cosine Transform). The following code is based directly on diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctflt-sse.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctflt-sse.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctflt-sse.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctflt-sse.asm index daeef22afc..caf636b510 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctflt-sse.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctflt-sse.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a floating-point implementation of the inverse DCT ; (Discrete Cosine Transform). The following code is based directly on diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctflt-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctflt-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctflt-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctflt-sse2.asm index c39ffbe71b..42703a8efd 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctflt-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctflt-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a floating-point implementation of the inverse DCT ; (Discrete Cosine Transform). The following code is based directly on diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctfst-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctfst-mmx.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctfst-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctfst-mmx.asm index 19de457f78..77d4613d23 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctfst-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctfst-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a fast, not so accurate integer implementation of ; the inverse DCT (Discrete Cosine Transform). The following code is diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctfst-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctfst-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctfst-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctfst-sse2.asm index 966311eda7..c2fe34ba8c 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctfst-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctfst-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a fast, not so accurate integer implementation of ; the inverse DCT (Discrete Cosine Transform). The following code is diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctint-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctint-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctint-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctint-avx2.asm index dd4a3d5e8c..cb119d3f06 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctint-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctint-avx2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; inverse DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctint-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctint-mmx.asm similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctint-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctint-mmx.asm index e2e1b3ff79..c2c17f441b 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctint-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctint-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; inverse DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctint-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctint-sse2.asm similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctint-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctint-sse2.asm index 42be940d72..70516cadce 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctint-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctint-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; inverse DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctred-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctred-mmx.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctred-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctred-mmx.asm index 920dad90bd..96cda65713 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctred-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctred-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains inverse-DCT routines that produce reduced-size ; output: either 4x4 or 2x2 pixels from an 8x8 DCT block. diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jidctred-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jidctred-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jidctred-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jidctred-sse2.asm index 9a6f9946e7..1fe967db19 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jidctred-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jidctred-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains inverse-DCT routines that produce reduced-size ; output: either 4x4 or 2x2 pixels from an 8x8 DCT block. diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jquant-3dn.asm b/3rdparty/libjpeg-turbo/simd/i386/jquant-3dn.asm similarity index 96% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jquant-3dn.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jquant-3dn.asm index 6436bad1ec..58e0011f70 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jquant-3dn.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jquant-3dn.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" %include "jdct.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jquant-mmx.asm b/3rdparty/libjpeg-turbo/simd/i386/jquant-mmx.asm similarity index 95% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jquant-mmx.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jquant-mmx.asm index e525ba9e7b..4eda95ce12 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jquant-mmx.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jquant-mmx.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" %include "jdct.inc" @@ -120,8 +116,8 @@ EXTN(jsimd_convsamp_mmx): ; Quantize/descale the coefficients, and store into coef_block ; ; This implementation is based on an algorithm described in -; "How to optimize for the Pentium family of microprocessors" -; (http://www.agner.org/assem/). +; "Optimizing subroutines in assembly language: +; An optimization guide for x86 platforms" (https://agner.org/optimize). ; ; GLOBAL(void) ; jsimd_quantize_mmx(JCOEFPTR coef_block, DCTELEM *divisors, diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jquant-sse.asm b/3rdparty/libjpeg-turbo/simd/i386/jquant-sse.asm similarity index 96% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jquant-sse.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jquant-sse.asm index 1cf2cc0ce5..6cb5f79c21 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jquant-sse.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jquant-sse.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" %include "jdct.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jquantf-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jquantf-sse2.asm similarity index 95% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jquantf-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jquantf-sse2.asm index 66efd3eeca..5668f8cb39 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jquantf-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jquantf-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" %include "jdct.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jquanti-avx2.asm b/3rdparty/libjpeg-turbo/simd/i386/jquanti-avx2.asm similarity index 93% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jquanti-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jquanti-avx2.asm index 5ed6bec246..60ae098e9c 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jquanti-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jquanti-avx2.asm @@ -2,18 +2,14 @@ ; jquanti.asm - sample data conversion and quantization (AVX2) ; ; Copyright 2009 Pierre Ossman for Cendio AB -; Copyright (C) 2016, 2018, D. R. Commander. +; Copyright (C) 2016, 2018, 2024, D. R. Commander. ; Copyright (C) 2016, Matthieu Darbois. ; ; Based on the x86 SIMD extension for IJG JPEG library ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" %include "jdct.inc" @@ -107,8 +103,8 @@ EXTN(jsimd_convsamp_avx2): ; Quantize/descale the coefficients, and store into coef_block ; ; This implementation is based on an algorithm described in -; "How to optimize for the Pentium family of microprocessors" -; (http://www.agner.org/assem/). +; "Optimizing subroutines in assembly language: +; An optimization guide for x86 platforms" (https://agner.org/optimize). ; ; GLOBAL(void) ; jsimd_quantize_avx2(JCOEFPTR coef_block, DCTELEM *divisors, diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jquanti-sse2.asm b/3rdparty/libjpeg-turbo/simd/i386/jquanti-sse2.asm similarity index 94% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jquanti-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jquanti-sse2.asm index 2a69af9c95..c1edde996e 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jquanti-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jquanti-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" %include "jdct.inc" @@ -98,8 +94,8 @@ EXTN(jsimd_convsamp_sse2): ; Quantize/descale the coefficients, and store into coef_block ; ; This implementation is based on an algorithm described in -; "How to optimize for the Pentium family of microprocessors" -; (http://www.agner.org/assem/). +; "Optimizing subroutines in assembly language: +; An optimization guide for x86 platforms" (https://agner.org/optimize). ; ; GLOBAL(void) ; jsimd_quantize_sse2(JCOEFPTR coef_block, DCTELEM *divisors, diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jsimd.c b/3rdparty/libjpeg-turbo/simd/i386/jsimd.c similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jsimd.c rename to 3rdparty/libjpeg-turbo/simd/i386/jsimd.c index b429b0a532..d4786b155b 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jsimd.c +++ b/3rdparty/libjpeg-turbo/simd/i386/jsimd.c @@ -2,7 +2,7 @@ * jsimd_i386.c * * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2022-2023, D. R. Commander. + * Copyright (C) 2009-2011, 2013-2014, 2016, 2018, 2022-2024, D. R. Commander. * Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois. * * Based on the x86 SIMD extension for IJG JPEG library, @@ -15,11 +15,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" /* diff --git a/3rdparty/libjpeg-turbo/src/simd/i386/jsimdcpu.asm b/3rdparty/libjpeg-turbo/simd/i386/jsimdcpu.asm similarity index 92% rename from 3rdparty/libjpeg-turbo/src/simd/i386/jsimdcpu.asm rename to 3rdparty/libjpeg-turbo/simd/i386/jsimdcpu.asm index ddcafa9e21..df80f17f5f 100644 --- a/3rdparty/libjpeg-turbo/src/simd/i386/jsimdcpu.asm +++ b/3rdparty/libjpeg-turbo/simd/i386/jsimdcpu.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/jsimd.h b/3rdparty/libjpeg-turbo/simd/jsimd.h similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/jsimd.h rename to 3rdparty/libjpeg-turbo/simd/jsimd.h diff --git a/3rdparty/libjpeg-turbo/src/simd/mips/jsimd.c b/3rdparty/libjpeg-turbo/simd/mips/jsimd.c similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/mips/jsimd.c rename to 3rdparty/libjpeg-turbo/simd/mips/jsimd.c index c6e789aa2f..6a1f1e0bcf 100644 --- a/3rdparty/libjpeg-turbo/src/simd/mips/jsimd.c +++ b/3rdparty/libjpeg-turbo/simd/mips/jsimd.c @@ -2,7 +2,8 @@ * jsimd_mips.c * * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2009-2011, 2014, 2016, 2018, 2020, 2022, D. R. Commander. + * Copyright (C) 2009-2011, 2014, 2016, 2018, 2020, 2022, 2024, + * D. R. Commander. * Copyright (C) 2013-2014, MIPS Technologies, Inc., California. * Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois. * @@ -16,11 +17,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/mips/jsimd_dspr2.S b/3rdparty/libjpeg-turbo/simd/mips/jsimd_dspr2.S similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips/jsimd_dspr2.S rename to 3rdparty/libjpeg-turbo/simd/mips/jsimd_dspr2.S diff --git a/3rdparty/libjpeg-turbo/src/simd/mips/jsimd_dspr2_asm.h b/3rdparty/libjpeg-turbo/simd/mips/jsimd_dspr2_asm.h similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips/jsimd_dspr2_asm.h rename to 3rdparty/libjpeg-turbo/simd/mips/jsimd_dspr2_asm.h diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jccolext-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jccolext-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jccolext-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jccolext-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jccolor-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jccolor-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jccolor-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jccolor-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jcgray-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jcgray-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jcgray-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jcgray-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jcgryext-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jcgryext-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jcgryext-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jcgryext-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jcsample-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jcsample-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jcsample-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jcsample-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jcsample.h b/3rdparty/libjpeg-turbo/simd/mips64/jcsample.h similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jcsample.h rename to 3rdparty/libjpeg-turbo/simd/mips64/jcsample.h diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jdcolext-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jdcolext-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jdcolext-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jdcolext-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jdcolor-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jdcolor-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jdcolor-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jdcolor-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jdmerge-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jdmerge-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jdmerge-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jdmerge-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jdmrgext-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jdmrgext-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jdmrgext-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jdmrgext-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jdsample-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jdsample-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jdsample-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jdsample-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jfdctfst-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jfdctfst-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jfdctfst-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jfdctfst-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jfdctint-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jfdctint-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jfdctint-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jfdctint-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jidctfst-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jidctfst-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jidctfst-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jidctfst-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jidctint-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jidctint-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jidctint-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jidctint-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jquanti-mmi.c b/3rdparty/libjpeg-turbo/simd/mips64/jquanti-mmi.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jquanti-mmi.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jquanti-mmi.c diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jsimd.c b/3rdparty/libjpeg-turbo/simd/mips64/jsimd.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jsimd.c rename to 3rdparty/libjpeg-turbo/simd/mips64/jsimd.c index 917440b43b..a2046d4620 100644 --- a/3rdparty/libjpeg-turbo/src/simd/mips64/jsimd.c +++ b/3rdparty/libjpeg-turbo/simd/mips64/jsimd.c @@ -2,7 +2,7 @@ * jsimd_mips64.c * * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2009-2011, 2014, 2016, 2018, 2022, D. R. Commander. + * Copyright (C) 2009-2011, 2014, 2016, 2018, 2022, 2024, D. R. Commander. * Copyright (C) 2013-2014, MIPS Technologies, Inc., California. * Copyright (C) 2015, 2018, 2022, Matthieu Darbois. * Copyright (C) 2016-2018, Loongson Technology Corporation Limited, BeiJing. @@ -17,11 +17,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/jsimd_mmi.h b/3rdparty/libjpeg-turbo/simd/mips64/jsimd_mmi.h similarity index 93% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/jsimd_mmi.h rename to 3rdparty/libjpeg-turbo/simd/mips64/jsimd_mmi.h index 5e4261c9d9..1ae71bfb0b 100644 --- a/3rdparty/libjpeg-turbo/src/simd/mips64/jsimd_mmi.h +++ b/3rdparty/libjpeg-turbo/simd/mips64/jsimd_mmi.h @@ -7,6 +7,7 @@ * CaiWanwei * SunZhangzhi * QingfaLiu + * Copyright (C) 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -26,9 +27,9 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jdct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jdct.h" #include "loongson-mmintrin.h" diff --git a/3rdparty/libjpeg-turbo/src/simd/mips64/loongson-mmintrin.h b/3rdparty/libjpeg-turbo/simd/mips64/loongson-mmintrin.h similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/mips64/loongson-mmintrin.h rename to 3rdparty/libjpeg-turbo/simd/mips64/loongson-mmintrin.h diff --git a/3rdparty/libjpeg-turbo/src/simd/nasm/jcolsamp.inc b/3rdparty/libjpeg-turbo/simd/nasm/jcolsamp.inc similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/nasm/jcolsamp.inc rename to 3rdparty/libjpeg-turbo/simd/nasm/jcolsamp.inc diff --git a/3rdparty/libjpeg-turbo/src/simd/nasm/jdct.inc b/3rdparty/libjpeg-turbo/simd/nasm/jdct.inc similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/nasm/jdct.inc rename to 3rdparty/libjpeg-turbo/simd/nasm/jdct.inc diff --git a/3rdparty/libjpeg-turbo/src/simd/nasm/jsimdcfg.inc b/3rdparty/libjpeg-turbo/simd/nasm/jsimdcfg.inc similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/nasm/jsimdcfg.inc rename to 3rdparty/libjpeg-turbo/simd/nasm/jsimdcfg.inc diff --git a/3rdparty/libjpeg-turbo/src/simd/nasm/jsimdcfg.inc.h b/3rdparty/libjpeg-turbo/simd/nasm/jsimdcfg.inc.h similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/nasm/jsimdcfg.inc.h rename to 3rdparty/libjpeg-turbo/simd/nasm/jsimdcfg.inc.h index bf2a45ad50..ed3f9c2a69 100644 --- a/3rdparty/libjpeg-turbo/src/simd/nasm/jsimdcfg.inc.h +++ b/3rdparty/libjpeg-turbo/simd/nasm/jsimdcfg.inc.h @@ -12,9 +12,9 @@ #define JPEG_INTERNALS -#include "../jpeglib.h" +#include "../src/jpeglib.h" #include "../jconfig.h" -#include "../jmorecfg.h" +#include "../src/jmorecfg.h" #include "jsimd.h" ; diff --git a/3rdparty/libjpeg-turbo/src/simd/nasm/jsimdext.inc b/3rdparty/libjpeg-turbo/simd/nasm/jsimdext.inc similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/nasm/jsimdext.inc rename to 3rdparty/libjpeg-turbo/simd/nasm/jsimdext.inc diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jccolext-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jccolext-altivec.c similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jccolext-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jccolext-altivec.c index 170f90ff80..a51b4be729 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jccolext-altivec.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jccolext-altivec.c @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2014-2015, D. R. Commander. All Rights Reserved. + * Copyright (C) 2014-2015, 2024, D. R. Commander. All Rights Reserved. * Copyright (C) 2014, Jay Foad. All Rights Reserved. * * This software is provided 'as-is', without any express or implied @@ -30,17 +30,17 @@ void jsimd_rgb_ycc_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf, { JSAMPROW inptr, outptr0, outptr1, outptr2; int pitch = img_width * RGB_PIXELSIZE, num_cols; -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ int offset; #endif unsigned char __attribute__((aligned(16))) tmpbuf[RGB_PIXELSIZE * 16]; __vector unsigned char rgb0, rgb1 = { 0 }, rgb2 = { 0 }, rgbg0, rgbg1, rgbg2, rgbg3, y, cb, cr; -#if __BIG_ENDIAN__ || RGB_PIXELSIZE == 4 +#if defined(__BIG_ENDIAN__) || RGB_PIXELSIZE == 4 __vector unsigned char rgb3 = { 0 }; #endif -#if __BIG_ENDIAN__ && RGB_PIXELSIZE == 4 +#if defined(__BIG_ENDIAN__) && RGB_PIXELSIZE == 4 __vector unsigned char rgb4 = { 0 }; #endif __vector short rg0, rg1, rg2, rg3, bg0, bg1, bg2, bg3; @@ -56,7 +56,7 @@ void jsimd_rgb_ycc_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf, __vector int pd_onehalf = { __4X(ONE_HALF) }, pd_onehalfm1_cj = { __4X(ONE_HALF - 1 + (CENTERJSAMPLE << SCALEBITS)) }; __vector unsigned char pb_zero = { __16X(0) }, -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ shift_pack_index = { 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 }; #else @@ -75,7 +75,7 @@ void jsimd_rgb_ycc_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf, num_cols -= RGB_PIXELSIZE * 16, inptr += RGB_PIXELSIZE * 16, outptr0 += 16, outptr1 += 16, outptr2 += 16) { -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ /* Load 16 pixels == 48 or 64 bytes */ offset = (size_t)inptr & 15; if (offset) { @@ -141,7 +141,7 @@ void jsimd_rgb_ycc_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf, rgb3 = VEC_LD(48, inptr); #endif } -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ } #endif diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jccolor-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jccolor-altivec.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jccolor-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jccolor-altivec.c diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jcgray-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jcgray-altivec.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jcgray-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jcgray-altivec.c diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jcgryext-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jcgryext-altivec.c similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jcgryext-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jcgryext-altivec.c index b280cbbded..550e239a7a 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jcgryext-altivec.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jcgryext-altivec.c @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2014-2015, D. R. Commander. All Rights Reserved. + * Copyright (C) 2014-2015, 2024, D. R. Commander. All Rights Reserved. * Copyright (C) 2014, Jay Foad. All Rights Reserved. * * This software is provided 'as-is', without any express or implied @@ -30,17 +30,17 @@ void jsimd_rgb_gray_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf, { JSAMPROW inptr, outptr; int pitch = img_width * RGB_PIXELSIZE, num_cols; -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ int offset; unsigned char __attribute__((aligned(16))) tmpbuf[RGB_PIXELSIZE * 16]; #endif __vector unsigned char rgb0, rgb1 = { 0 }, rgb2 = { 0 }, rgbg0, rgbg1, rgbg2, rgbg3, y; -#if __BIG_ENDIAN__ || RGB_PIXELSIZE == 4 +#if defined(__BIG_ENDIAN__) || RGB_PIXELSIZE == 4 __vector unsigned char rgb3 = { 0 }; #endif -#if __BIG_ENDIAN__ && RGB_PIXELSIZE == 4 +#if defined(__BIG_ENDIAN__) && RGB_PIXELSIZE == 4 __vector unsigned char rgb4 = { 0 }; #endif __vector short rg0, rg1, rg2, rg3, bg0, bg1, bg2, bg3; @@ -52,7 +52,7 @@ void jsimd_rgb_gray_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf, pw_f0114_f0250 = { __4X2(F_0_114, F_0_250) }; __vector int pd_onehalf = { __4X(ONE_HALF) }; __vector unsigned char pb_zero = { __16X(0) }, -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ shift_pack_index = { 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 }; #else @@ -69,7 +69,7 @@ void jsimd_rgb_gray_convert_altivec(JDIMENSION img_width, JSAMPARRAY input_buf, num_cols -= RGB_PIXELSIZE * 16, inptr += RGB_PIXELSIZE * 16, outptr += 16) { -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ /* Load 16 pixels == 48 or 64 bytes */ offset = (size_t)inptr & 15; if (offset) { diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jcsample-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jcsample-altivec.c similarity index 96% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jcsample-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jcsample-altivec.c index 6e25b8db90..6bda03a806 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jcsample-altivec.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jcsample-altivec.c @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2015, D. R. Commander. All Rights Reserved. + * Copyright (C) 2015, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -50,7 +50,7 @@ void jsimd_h2v1_downsample_altivec(JDIMENSION image_width, expand_right_edge(input_data, max_v_samp_factor, image_width, output_cols * 2); - for (outrow = 0; outrow < v_samp_factor; outrow++) { + for (outrow = 0; outrow < (int)v_samp_factor; outrow++) { outptr = output_data[outrow]; inptr = input_data[outrow]; @@ -107,7 +107,7 @@ jsimd_h2v2_downsample_altivec(JDIMENSION image_width, int max_v_samp_factor, expand_right_edge(input_data, max_v_samp_factor, image_width, output_cols * 2); - for (inrow = 0, outrow = 0; outrow < v_samp_factor; + for (inrow = 0, outrow = 0; outrow < (int)v_samp_factor; inrow += 2, outrow++) { inptr0 = input_data[inrow]; diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jcsample.h b/3rdparty/libjpeg-turbo/simd/powerpc/jcsample.h similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jcsample.h rename to 3rdparty/libjpeg-turbo/simd/powerpc/jcsample.h diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jdcolext-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jdcolext-altivec.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jdcolext-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jdcolext-altivec.c index 68d52bd8a2..7e3a2049f8 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jdcolext-altivec.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jdcolext-altivec.c @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2015, D. R. Commander. All Rights Reserved. + * Copyright (C) 2015, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -29,14 +29,14 @@ void jsimd_ycc_rgb_convert_altivec(JDIMENSION out_width, JSAMPIMAGE input_buf, { JSAMPROW outptr, inptr0, inptr1, inptr2; int pitch = out_width * RGB_PIXELSIZE, num_cols; -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ int offset; #endif unsigned char __attribute__((aligned(16))) tmpbuf[RGB_PIXELSIZE * 16]; __vector unsigned char rgb0, rgb1, rgb2, rgbx0, rgbx1, rgbx2, rgbx3, y, cb, cr; -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ __vector unsigned char edgel, edgeh, edges, out0, out1, out2, out3; #if RGB_PIXELSIZE == 4 __vector unsigned char out4; @@ -60,7 +60,7 @@ void jsimd_ycc_rgb_convert_altivec(JDIMENSION out_width, JSAMPIMAGE input_buf, pw_cj = { __8X(CENTERJSAMPLE) }; __vector int pd_onehalf = { __4X(ONE_HALF) }; __vector unsigned char pb_zero = { __16X(0) }, -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ shift_pack_index = { 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 }; #else @@ -196,7 +196,7 @@ void jsimd_ycc_rgb_convert_altivec(JDIMENSION out_width, JSAMPIMAGE input_buf, rgb3 = vec_perm(rgbx3, rgbx3, (__vector unsigned char)RGB_INDEX); #endif -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ offset = (size_t)outptr & 15; if (offset) { __vector unsigned char unaligned_shift_index; @@ -268,7 +268,7 @@ void jsimd_ycc_rgb_convert_altivec(JDIMENSION out_width, JSAMPIMAGE input_buf, VEC_ST(rgb3, 48, outptr); #endif } -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ } #endif } diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jdcolor-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jdcolor-altivec.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jdcolor-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jdcolor-altivec.c diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jdmerge-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jdmerge-altivec.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jdmerge-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jdmerge-altivec.c diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jdmrgext-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jdmrgext-altivec.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jdmrgext-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jdmrgext-altivec.c index 40f02c33ea..167b738091 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jdmrgext-altivec.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jdmrgext-altivec.c @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2015, D. R. Commander. All Rights Reserved. + * Copyright (C) 2015, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -30,14 +30,14 @@ void jsimd_h2v1_merged_upsample_altivec(JDIMENSION output_width, { JSAMPROW outptr, inptr0, inptr1, inptr2; int pitch = output_width * RGB_PIXELSIZE, num_cols, yloop; -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ int offset; #endif unsigned char __attribute__((aligned(16))) tmpbuf[RGB_PIXELSIZE * 16]; __vector unsigned char rgb0, rgb1, rgb2, rgbx0, rgbx1, rgbx2, rgbx3, y, cb, cr; -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ __vector unsigned char edgel, edgeh, edges, out0, out1, out2, out3; #if RGB_PIXELSIZE == 4 __vector unsigned char out4; @@ -62,7 +62,7 @@ void jsimd_h2v1_merged_upsample_altivec(JDIMENSION output_width, pw_cj = { __8X(CENTERJSAMPLE) }; __vector int pd_onehalf = { __4X(ONE_HALF) }; __vector unsigned char pb_zero = { __16X(0) }, -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ shift_pack_index = { 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29 }, even_index = @@ -225,7 +225,7 @@ void jsimd_h2v1_merged_upsample_altivec(JDIMENSION output_width, rgb3 = vec_perm(rgbx3, rgbx3, (__vector unsigned char)RGB_INDEX); #endif -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ offset = (size_t)outptr & 15; if (offset) { __vector unsigned char unaligned_shift_index; @@ -297,7 +297,7 @@ void jsimd_h2v1_merged_upsample_altivec(JDIMENSION output_width, VEC_ST(rgb3, 48, outptr); #endif } -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ } #endif } diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jdsample-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jdsample-altivec.c similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jdsample-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jdsample-altivec.c index 04df0cf108..b04f830b1d 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jdsample-altivec.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jdsample-altivec.c @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2015, D. R. Commander. All Rights Reserved. + * Copyright (C) 2015, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -49,7 +49,7 @@ void jsimd_h2v1_fancy_upsample_altivec(int max_v_samp_factor, { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, next_index_lastcol = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15 }, -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ merge_pack_index = { 1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31 }; #else @@ -155,7 +155,7 @@ void jsimd_h2v2_fancy_upsample_altivec(int max_v_samp_factor, { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }, next_index_lastcol = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 15 }, -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ merge_pack_index = { 1, 17, 3, 19, 5, 21, 7, 23, 9, 25, 11, 27, 13, 29, 15, 31 }; #else diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jfdctfst-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jfdctfst-altivec.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jfdctfst-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jfdctfst-altivec.c diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jfdctint-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jfdctint-altivec.c similarity index 100% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jfdctint-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jfdctint-altivec.c diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jidctfst-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jidctfst-altivec.c similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jidctfst-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jidctfst-altivec.c index 456c6c6174..06839c795c 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jidctfst-altivec.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jidctfst-altivec.c @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2014-2015, D. R. Commander. All Rights Reserved. + * Copyright (C) 2014-2015, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -127,12 +127,12 @@ void jsimd_idct_ifast_altivec(void *dct_table_, JCOEFPTR coef_block, __vector short pw_zero = { __8X(0) }, pw_F1414 = { __8X(F_1_414 << CONST_SHIFT) }, pw_F1847 = { __8X(F_1_847 << CONST_SHIFT) }, - pw_MF1613 = { __8X(-F_1_613 << CONST_SHIFT) }, + pw_MF1613 = { __8X((short)((unsigned short)(-F_1_613) << CONST_SHIFT)) }, pw_F1082 = { __8X(F_1_082 << CONST_SHIFT) }; __vector unsigned short pre_multiply_scale_bits = { __8X(PRE_MULTIPLY_SCALE_BITS) }, pass1_bits3 = { __8X(PASS1_BITS + 3) }; - __vector signed char pb_centerjsamp = { __16X(CENTERJSAMPLE) }; + __vector signed char pb_centerjsamp = { __16X((signed char)CENTERJSAMPLE) }; /* Pass 1: process columns */ diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jidctint-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jidctint-altivec.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jidctint-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jidctint-altivec.c index 60e619f11d..52e37d9012 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jidctint-altivec.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jidctint-altivec.c @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2014-2015, 2020, D. R. Commander. All Rights Reserved. + * Copyright (C) 2014-2015, 2020, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -241,7 +241,7 @@ void jsimd_idct_islow_altivec(void *dct_table_, JCOEFPTR coef_block, __vector unsigned int descale_p1 = { __4X(DESCALE_P1) }, descale_p2 = { __4X(DESCALE_P2) }, const_bits = { __4X(CONST_BITS) }; - __vector signed char pb_centerjsamp = { __16X(CENTERJSAMPLE) }; + __vector signed char pb_centerjsamp = { __16X((signed char)CENTERJSAMPLE) }; /* Pass 1: process columns */ diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jquanti-altivec.c b/3rdparty/libjpeg-turbo/simd/powerpc/jquanti-altivec.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jquanti-altivec.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jquanti-altivec.c index 7d6e32542b..05ea13e742 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jquanti-altivec.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jquanti-altivec.c @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2014-2015, D. R. Commander. All Rights Reserved. + * Copyright (C) 2014-2015, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -29,7 +29,7 @@ * always get the data we want by using a single vector load (although we may * have to permute the result.) */ -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ #define LOAD_ROW(row) { \ elemptr = sample_data[row] + start_col; \ @@ -125,7 +125,7 @@ void jsimd_quantize_altivec(JCOEFPTR coef_block, DCTELEM *divisors, /* Constants */ __vector unsigned short pw_word_bit_m1 = { __8X(WORD_BIT - 1) }; -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ __vector unsigned char shift_pack_index = { 0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29 }; #else diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jsimd.c b/3rdparty/libjpeg-turbo/simd/powerpc/jsimd.c similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jsimd.c rename to 3rdparty/libjpeg-turbo/simd/powerpc/jsimd.c index 461f603633..e8c6c51d94 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jsimd.c +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jsimd.c @@ -2,7 +2,7 @@ * jsimd_powerpc.c * * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2009-2011, 2014-2016, 2018, 2022, D. R. Commander. + * Copyright (C) 2009-2011, 2014-2016, 2018, 2022, 2024, D. R. Commander. * Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois. * * Based on the x86 SIMD extension for IJG JPEG library, @@ -20,11 +20,11 @@ #endif #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include diff --git a/3rdparty/libjpeg-turbo/src/simd/powerpc/jsimd_altivec.h b/3rdparty/libjpeg-turbo/simd/powerpc/jsimd_altivec.h similarity index 89% rename from 3rdparty/libjpeg-turbo/src/simd/powerpc/jsimd_altivec.h rename to 3rdparty/libjpeg-turbo/simd/powerpc/jsimd_altivec.h index e8bdb06a54..ae80ad297b 100644 --- a/3rdparty/libjpeg-turbo/src/simd/powerpc/jsimd_altivec.h +++ b/3rdparty/libjpeg-turbo/simd/powerpc/jsimd_altivec.h @@ -1,7 +1,7 @@ /* * AltiVec optimizations for libjpeg-turbo * - * Copyright (C) 2014-2015, D. R. Commander. All Rights Reserved. + * Copyright (C) 2014-2015, 2024, D. R. Commander. All Rights Reserved. * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -21,11 +21,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" #include @@ -81,7 +81,7 @@ /* Macros to abstract big/little endian bit twiddling */ -#if __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ #define VEC_LD(a, b) vec_ld(a, b) #define VEC_ST(a, b, c) vec_st(a, b, c) @@ -96,3 +96,12 @@ #define VEC_UNPACKLU(a) vec_mergel(a, pb_zero) #endif + + +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wc99-extensions" +#pragma clang diagnostic ignored "-Wshadow" +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wpedantic" +#pragma GCC diagnostic ignored "-Wshadow" +#endif diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jccolext-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jccolext-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jccolext-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jccolext-avx2.asm index 39e6f207ca..aeeda0a682 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jccolext-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jccolext-avx2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jccolext-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jccolext-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jccolext-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jccolext-sse2.asm index 2073988d33..f3a1244903 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jccolext-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jccolext-sse2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jccolor-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jccolor-avx2.asm similarity index 92% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jccolor-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jccolor-avx2.asm index 1f069caad9..e262891733 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jccolor-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jccolor-avx2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jccolor-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jccolor-sse2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jccolor-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jccolor-sse2.asm index c0c1526d8c..cc9edb4ceb 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jccolor-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jccolor-sse2.asm @@ -7,11 +7,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcgray-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jcgray-avx2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jcgray-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jcgray-avx2.asm index 354683ca42..267ec5142a 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcgray-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jcgray-avx2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcgray-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jcgray-sse2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jcgray-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jcgray-sse2.asm index d27c4b9a82..4b94d7b8a2 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcgray-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jcgray-sse2.asm @@ -7,11 +7,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcgryext-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jcgryext-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jcgryext-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jcgryext-avx2.asm index d2ae6d63a4..77e85f768f 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcgryext-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jcgryext-avx2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcgryext-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jcgryext-sse2.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jcgryext-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jcgryext-sse2.asm index 3c2834e964..3e8087c39b 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcgryext-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jcgryext-sse2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jchuff-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jchuff-sse2.asm similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jchuff-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jchuff-sse2.asm index 39aa24650c..b18b7f5d65 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jchuff-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jchuff-sse2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains an SSE2 implementation for Huffman coding of one block. ; The following code is based on jchuff.c; see jchuff.c for more details. diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcphuff-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jcphuff-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jcphuff-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jcphuff-sse2.asm index 0e2740462e..c9ac59f2f1 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcphuff-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jcphuff-sse2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains an SSE2 implementation of data preparation for progressive ; Huffman encoding. See jcphuff.c for more details. diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcsample-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jcsample-avx2.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jcsample-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jcsample-avx2.asm index fede6b38b4..53afc7d77f 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcsample-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jcsample-avx2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcsample-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jcsample-sse2.asm similarity index 96% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jcsample-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jcsample-sse2.asm index 0a0ee65e5a..d7ffa930e8 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jcsample-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jcsample-sse2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolext-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdcolext-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolext-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdcolext-avx2.asm index a8384cb560..7b8a084398 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolext-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdcolext-avx2.asm @@ -11,11 +11,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolext-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdcolext-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolext-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdcolext-sse2.asm index bfb59abf12..261f74da5d 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolext-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdcolext-sse2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolor-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdcolor-avx2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolor-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdcolor-avx2.asm index 4d52a0f16a..bd5aa00b95 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolor-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdcolor-avx2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolor-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdcolor-sse2.asm similarity index 91% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolor-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdcolor-sse2.asm index 93d3c8dd4a..40343fe789 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdcolor-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdcolor-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdmerge-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdmerge-avx2.asm similarity index 92% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdmerge-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdmerge-avx2.asm index 4be435624e..6a5f1daba5 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdmerge-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdmerge-avx2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdmerge-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdmerge-sse2.asm similarity index 92% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdmerge-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdmerge-sse2.asm index a22f6ac733..8c269b83d8 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdmerge-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdmerge-sse2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdmrgext-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdmrgext-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdmrgext-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdmrgext-avx2.asm index 3392f3a383..01826fb6ab 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdmrgext-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdmrgext-avx2.asm @@ -11,11 +11,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdmrgext-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdmrgext-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdmrgext-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdmrgext-sse2.asm index 901db984f9..abd22e21a7 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdmrgext-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdmrgext-sse2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jcolsamp.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdsample-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdsample-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdsample-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdsample-avx2.asm index 017427a158..6ae4cf812a 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdsample-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdsample-avx2.asm @@ -11,11 +11,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdsample-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jdsample-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jdsample-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jdsample-sse2.asm index 95c4d4c9ed..54c560fc28 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jdsample-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jdsample-sse2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctflt-sse.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jfdctflt-sse.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctflt-sse.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jfdctflt-sse.asm index cf46d93d61..58a1f5570d 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctflt-sse.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jfdctflt-sse.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a floating-point implementation of the forward DCT ; (Discrete Cosine Transform). The following code is based directly on diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctfst-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jfdctfst-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctfst-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jfdctfst-sse2.asm index cdc6236585..3b92d4edaa 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctfst-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jfdctfst-sse2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a fast, not so accurate integer implementation of ; the forward DCT (Discrete Cosine Transform). The following code is diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctint-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jfdctint-avx2.asm similarity index 97% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctint-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jfdctint-avx2.asm index b6b4c73a50..0c4528612c 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctint-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jfdctint-avx2.asm @@ -8,11 +8,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; forward DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctint-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jfdctint-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctint-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jfdctint-sse2.asm index 44e7cd0554..3a6be020cd 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jfdctint-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jfdctint-sse2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; forward DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctflt-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jidctflt-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jidctflt-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jidctflt-sse2.asm index c7cb39a072..1443734022 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctflt-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jidctflt-sse2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a floating-point implementation of the inverse DCT ; (Discrete Cosine Transform). The following code is based directly on diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctfst-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jidctfst-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jidctfst-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jidctfst-sse2.asm index fd3bc32c16..cffabb8378 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctfst-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jidctfst-sse2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a fast, not so accurate integer implementation of ; the inverse DCT (Discrete Cosine Transform). The following code is diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctint-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jidctint-avx2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jidctint-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jidctint-avx2.asm index 84d125bd43..be3b46888e 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctint-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jidctint-avx2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; inverse DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctint-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jidctint-sse2.asm similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jidctint-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jidctint-sse2.asm index 3f098b2c50..b186871ff2 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctint-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jidctint-sse2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains a slower but more accurate integer implementation of the ; inverse DCT (Discrete Cosine Transform). The following code is based diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctred-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jidctred-sse2.asm similarity index 98% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jidctred-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jidctred-sse2.asm index 2657cf3cb1..6fb7095612 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jidctred-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jidctred-sse2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. ; ; This file contains inverse-DCT routines that produce reduced-size ; output: either 4x4 or 2x2 pixels from an 8x8 DCT block. diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jquantf-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jquantf-sse2.asm similarity index 94% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jquantf-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jquantf-sse2.asm index 8bd79662e6..64763338f2 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jquantf-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jquantf-sse2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" %include "jdct.inc" diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jquanti-avx2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jquanti-avx2.asm similarity index 93% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jquanti-avx2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jquanti-avx2.asm index c8ebd7966b..7e126e88a8 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jquanti-avx2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jquanti-avx2.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" %include "jdct.inc" @@ -93,8 +89,8 @@ EXTN(jsimd_convsamp_avx2): ; Quantize/descale the coefficients, and store into coef_block ; ; This implementation is based on an algorithm described in -; "How to optimize for the Pentium family of microprocessors" -; (http://www.agner.org/assem/). +; "Optimizing subroutines in assembly language: +; An optimization guide for x86 platforms" (https://agner.org/optimize). ; ; GLOBAL(void) ; jsimd_quantize_avx2(JCOEFPTR coef_block, DCTELEM *divisors, diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jquanti-sse2.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jquanti-sse2.asm similarity index 93% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jquanti-sse2.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jquanti-sse2.asm index 352d74055c..284b9fea71 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jquanti-sse2.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jquanti-sse2.asm @@ -9,11 +9,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" %include "jdct.inc" @@ -93,8 +89,8 @@ EXTN(jsimd_convsamp_sse2): ; Quantize/descale the coefficients, and store into coef_block ; ; This implementation is based on an algorithm described in -; "How to optimize for the Pentium family of microprocessors" -; (http://www.agner.org/assem/). +; "Optimizing subroutines in assembly language: +; An optimization guide for x86 platforms" (https://agner.org/optimize). ; ; GLOBAL(void) ; jsimd_quantize_sse2(JCOEFPTR coef_block, DCTELEM *divisors, diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jsimd.c b/3rdparty/libjpeg-turbo/simd/x86_64/jsimd.c similarity index 99% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jsimd.c rename to 3rdparty/libjpeg-turbo/simd/x86_64/jsimd.c index 3f5ee77eb9..038cf0f8a3 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jsimd.c +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jsimd.c @@ -2,7 +2,7 @@ * jsimd_x86_64.c * * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2009-2011, 2014, 2016, 2018, 2022-2023, D. R. Commander. + * Copyright (C) 2009-2011, 2014, 2016, 2018, 2022-2024, D. R. Commander. * Copyright (C) 2015-2016, 2018, 2022, Matthieu Darbois. * * Based on the x86 SIMD extension for IJG JPEG library, @@ -15,11 +15,11 @@ */ #define JPEG_INTERNALS -#include "../../jinclude.h" -#include "../../jpeglib.h" -#include "../../jsimd.h" -#include "../../jdct.h" -#include "../../jsimddct.h" +#include "../../src/jinclude.h" +#include "../../src/jpeglib.h" +#include "../../src/jsimd.h" +#include "../../src/jdct.h" +#include "../../src/jsimddct.h" #include "../jsimd.h" /* diff --git a/3rdparty/libjpeg-turbo/src/simd/x86_64/jsimdcpu.asm b/3rdparty/libjpeg-turbo/simd/x86_64/jsimdcpu.asm similarity index 88% rename from 3rdparty/libjpeg-turbo/src/simd/x86_64/jsimdcpu.asm rename to 3rdparty/libjpeg-turbo/simd/x86_64/jsimdcpu.asm index 251bc4cdae..b72f3b0b39 100644 --- a/3rdparty/libjpeg-turbo/src/simd/x86_64/jsimdcpu.asm +++ b/3rdparty/libjpeg-turbo/simd/x86_64/jsimdcpu.asm @@ -10,11 +10,7 @@ ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; -; This file should be assembled with NASM (Netwide Assembler), -; can *not* be assembled with Microsoft's MASM or any compatible -; assembler (including Borland's Turbo Assembler). -; NASM is available from http://nasm.sourceforge.net/ or -; http://sourceforge.net/project/showfiles.php?group_id=6208 +; This file should be assembled with NASM (Netwide Assembler) or Yasm. %include "jsimdext.inc" diff --git a/3rdparty/libjpeg-turbo/src/cjpeg.c b/3rdparty/libjpeg-turbo/src/cjpeg.c deleted file mode 100644 index 44c39bec20..0000000000 --- a/3rdparty/libjpeg-turbo/src/cjpeg.c +++ /dev/null @@ -1,841 +0,0 @@ -/* - * cjpeg.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1991-1998, Thomas G. Lane. - * Modified 2003-2011 by Guido Vollbeding. - * Lossless JPEG Modifications: - * Copyright (C) 1999, Ken Murchison. - * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2013-2014, 2017, 2019-2022, 2024, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains a command-line user interface for the JPEG compressor. - * It should work on any system with Unix- or MS-DOS-style command lines. - * - * Two different command line styles are permitted, depending on the - * compile-time switch TWO_FILE_COMMANDLINE: - * cjpeg [options] inputfile outputfile - * cjpeg [options] [inputfile] - * In the second style, output is always to standard output, which you'd - * normally redirect to a file or pipe to some other program. Input is - * either from a named file or from standard input (typically redirected). - * The second style is convenient on Unix but is unhelpful on systems that - * don't support pipes. Also, you MUST use the first style if your system - * doesn't do binary I/O to stdin/stdout. - * To simplify script writing, the "-outfile" switch is provided. The syntax - * cjpeg [options] -outfile outputfile inputfile - * works regardless of which command line style is used. - */ - -#ifdef _MSC_VER -#define _CRT_SECURE_NO_DEPRECATE -#endif - -#ifdef CJPEG_FUZZER -#define JPEG_INTERNALS -#endif -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include "jversion.h" /* for version message */ -#include "jconfigint.h" - - -/* Create the add-on message string table. */ - -#define JMESSAGE(code, string) string, - -static const char * const cdjpeg_message_table[] = { -#include "cderror.h" - NULL -}; - - -/* - * This routine determines what format the input file is, - * and selects the appropriate input-reading module. - * - * To determine which family of input formats the file belongs to, - * we may look only at the first byte of the file, since C does not - * guarantee that more than one character can be pushed back with ungetc. - * Looking at additional bytes would require one of these approaches: - * 1) assume we can fseek() the input file (fails for piped input); - * 2) assume we can push back more than one character (works in - * some C implementations, but unportable); - * 3) provide our own buffering (breaks input readers that want to use - * stdio directly); - * or 4) don't put back the data, and modify the input_init methods to assume - * they start reading after the start of file. - * #1 is attractive for MS-DOS but is untenable on Unix. - * - * The most portable solution for file types that can't be identified by their - * first byte is to make the user tell us what they are. This is also the - * only approach for "raw" file types that contain only arbitrary values. - * We presently apply this method for Targa files. Most of the time Targa - * files start with 0x00, so we recognize that case. Potentially, however, - * a Targa file could start with any byte value (byte 0 is the length of the - * seldom-used ID field), so we provide a switch to force Targa input mode. - */ - -static boolean is_targa; /* records user -targa switch */ - - -LOCAL(cjpeg_source_ptr) -select_file_type(j_compress_ptr cinfo, FILE *infile) -{ - int c; - - if (is_targa) { -#ifdef TARGA_SUPPORTED - return jinit_read_targa(cinfo); -#else - ERREXIT(cinfo, JERR_TGA_NOTCOMP); -#endif - } - - if ((c = getc(infile)) == EOF) - ERREXIT(cinfo, JERR_INPUT_EMPTY); - if (ungetc(c, infile) == EOF) - ERREXIT(cinfo, JERR_UNGETC_FAILED); - - switch (c) { -#ifdef BMP_SUPPORTED - case 'B': - return jinit_read_bmp(cinfo, TRUE); -#endif -#ifdef GIF_SUPPORTED - case 'G': - if (cinfo->data_precision == 16) { -#ifdef C_LOSSLESS_SUPPORTED - return j16init_read_gif(cinfo); -#else - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); - break; -#endif - } else if (cinfo->data_precision == 12) - return j12init_read_gif(cinfo); - else - return jinit_read_gif(cinfo); -#endif -#ifdef PPM_SUPPORTED - case 'P': - if (cinfo->data_precision == 16) { -#ifdef C_LOSSLESS_SUPPORTED - return j16init_read_ppm(cinfo); -#else - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); - break; -#endif - } else if (cinfo->data_precision == 12) - return j12init_read_ppm(cinfo); - else - return jinit_read_ppm(cinfo); -#endif -#ifdef TARGA_SUPPORTED - case 0x00: - return jinit_read_targa(cinfo); -#endif - default: - ERREXIT(cinfo, JERR_UNKNOWN_FORMAT); - break; - } - - return NULL; /* suppress compiler warnings */ -} - - -/* - * Argument-parsing code. - * The switch parser is designed to be useful with DOS-style command line - * syntax, ie, intermixed switches and file names, where only the switches - * to the left of a given file name affect processing of that file. - * The main program in this file doesn't actually use this capability... - */ - - -static const char *progname; /* program name for error messages */ -static char *icc_filename; /* for -icc switch */ -static char *outfilename; /* for -outfile switch */ -static boolean memdst; /* for -memdst switch */ -static boolean report; /* for -report switch */ -static boolean strict; /* for -strict switch */ - - -#ifdef CJPEG_FUZZER - -#include - -struct my_error_mgr { - struct jpeg_error_mgr pub; - jmp_buf setjmp_buffer; -}; - -void my_error_exit(j_common_ptr cinfo) -{ - struct my_error_mgr *myerr = (struct my_error_mgr *)cinfo->err; - - longjmp(myerr->setjmp_buffer, 1); -} - -static void my_emit_message_fuzzer(j_common_ptr cinfo, int msg_level) -{ - if (msg_level < 0) - cinfo->err->num_warnings++; -} - -#define HANDLE_ERROR() { \ - if (cinfo.global_state > CSTATE_START) { \ - if (memdst && outbuffer) \ - (*cinfo.dest->term_destination) (&cinfo); \ - jpeg_abort_compress(&cinfo); \ - } \ - jpeg_destroy_compress(&cinfo); \ - if (input_file != stdin && input_file != NULL) \ - fclose(input_file); \ - if (memdst) \ - free(outbuffer); \ - return EXIT_FAILURE; \ -} - -#endif - - -LOCAL(void) -usage(void) -/* complain about bad command line */ -{ - fprintf(stderr, "usage: %s [switches] ", progname); -#ifdef TWO_FILE_COMMANDLINE - fprintf(stderr, "inputfile outputfile\n"); -#else - fprintf(stderr, "[inputfile]\n"); -#endif - - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is most useful range,\n"); - fprintf(stderr, " default is 75)\n"); - fprintf(stderr, " -grayscale Create monochrome JPEG file\n"); - fprintf(stderr, " -rgb Create RGB JPEG file\n"); -#ifdef ENTROPY_OPT_SUPPORTED - fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n"); -#endif -#ifdef C_PROGRESSIVE_SUPPORTED - fprintf(stderr, " -progressive Create progressive JPEG file\n"); -#endif -#ifdef TARGA_SUPPORTED - fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n"); -#endif - fprintf(stderr, "Switches for advanced users:\n"); - fprintf(stderr, " -precision N Create JPEG file with N-bit data precision\n"); -#ifdef C_LOSSLESS_SUPPORTED - fprintf(stderr, " (N is 8, 12, or 16; default is 8; if N is 16, then -lossless\n"); - fprintf(stderr, " must also be specified)\n"); -#else - fprintf(stderr, " (N is 8 or 12; default is 8)\n"); -#endif -#ifdef C_LOSSLESS_SUPPORTED - fprintf(stderr, " -lossless psv[,Pt] Create lossless JPEG file\n"); -#endif -#ifdef C_ARITH_CODING_SUPPORTED - fprintf(stderr, " -arithmetic Use arithmetic coding\n"); -#endif -#ifdef DCT_ISLOW_SUPPORTED - fprintf(stderr, " -dct int Use accurate integer DCT method%s\n", - (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); -#endif -#ifdef DCT_IFAST_SUPPORTED - fprintf(stderr, " -dct fast Use less accurate integer DCT method [legacy feature]%s\n", - (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); -#endif -#ifdef DCT_FLOAT_SUPPORTED - fprintf(stderr, " -dct float Use floating-point DCT method [legacy feature]%s\n", - (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); -#endif - fprintf(stderr, " -icc FILE Embed ICC profile contained in FILE\n"); - fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); -#ifdef INPUT_SMOOTHING_SUPPORTED - fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n"); -#endif - fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); - fprintf(stderr, " -outfile name Specify name for output file\n"); - fprintf(stderr, " -memdst Compress to memory instead of file (useful for benchmarking)\n"); - fprintf(stderr, " -report Report compression progress\n"); - fprintf(stderr, " -strict Treat all warnings as fatal\n"); - fprintf(stderr, " -verbose or -debug Emit debug output\n"); - fprintf(stderr, " -version Print version information and exit\n"); - fprintf(stderr, "Switches for wizards:\n"); - fprintf(stderr, " -baseline Force baseline quantization tables\n"); - fprintf(stderr, " -qtables FILE Use quantization tables given in FILE\n"); - fprintf(stderr, " -qslots N[,...] Set component quantization tables\n"); - fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n"); -#ifdef C_MULTISCAN_FILES_SUPPORTED - fprintf(stderr, " -scans FILE Create multi-scan JPEG per script FILE\n"); -#endif - exit(EXIT_FAILURE); -} - - -LOCAL(int) -parse_switches(j_compress_ptr cinfo, int argc, char **argv, - int last_file_arg_seen, boolean for_real) -/* Parse optional switches. - * Returns argv[] index of first file-name argument (== argc if none). - * Any file names with indexes <= last_file_arg_seen are ignored; - * they have presumably been processed in a previous iteration. - * (Pass 0 for last_file_arg_seen on the first or only iteration.) - * for_real is FALSE on the first (dummy) pass; we may skip any expensive - * processing. - */ -{ - int argn; - char *arg; -#ifdef C_LOSSLESS_SUPPORTED - int psv, pt = 0; -#endif - boolean force_baseline; - boolean simple_progressive; - char *qualityarg = NULL; /* saves -quality parm if any */ - char *qtablefile = NULL; /* saves -qtables filename if any */ - char *qslotsarg = NULL; /* saves -qslots parm if any */ - char *samplearg = NULL; /* saves -sample parm if any */ - char *scansarg = NULL; /* saves -scans parm if any */ - - /* Set up default JPEG parameters. */ - - force_baseline = FALSE; /* by default, allow 16-bit quantizers */ - simple_progressive = FALSE; - is_targa = FALSE; - icc_filename = NULL; - outfilename = NULL; - memdst = FALSE; - report = FALSE; - strict = FALSE; - cinfo->err->trace_level = 0; - - /* Scan command line options, adjust parameters */ - - for (argn = 1; argn < argc; argn++) { - arg = argv[argn]; - if (*arg != '-') { - /* Not a switch, must be a file name argument */ - if (argn <= last_file_arg_seen) { - outfilename = NULL; /* -outfile applies to just one input file */ - continue; /* ignore this name if previously processed */ - } - break; /* else done parsing switches */ - } - arg++; /* advance past switch marker character */ - - if (keymatch(arg, "arithmetic", 1)) { - /* Use arithmetic coding. */ -#ifdef C_ARITH_CODING_SUPPORTED - cinfo->arith_code = TRUE; -#else - fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "baseline", 1)) { - /* Force baseline-compatible output (8-bit quantizer values). */ - force_baseline = TRUE; - - } else if (keymatch(arg, "dct", 2)) { - /* Select DCT algorithm. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (keymatch(argv[argn], "int", 1)) { - cinfo->dct_method = JDCT_ISLOW; - } else if (keymatch(argv[argn], "fast", 2)) { - cinfo->dct_method = JDCT_IFAST; - } else if (keymatch(argv[argn], "float", 2)) { - cinfo->dct_method = JDCT_FLOAT; - } else - usage(); - - } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { - /* Enable debug printouts. */ - /* On first -d, print version identification */ - static boolean printed_version = FALSE; - - if (!printed_version) { - fprintf(stderr, "%s version %s (build %s)\n", - PACKAGE_NAME, VERSION, BUILD); - fprintf(stderr, JCOPYRIGHT1); - fprintf(stderr, JCOPYRIGHT2 "\n"); - fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n", - JVERSION); - printed_version = TRUE; - } - cinfo->err->trace_level++; - - } else if (keymatch(arg, "version", 4)) { - fprintf(stderr, "%s version %s (build %s)\n", - PACKAGE_NAME, VERSION, BUILD); - exit(EXIT_SUCCESS); - - } else if (keymatch(arg, "grayscale", 2) || - keymatch(arg, "greyscale", 2)) { - /* Force a monochrome JPEG file to be generated. */ - jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); - - } else if (keymatch(arg, "rgb", 3)) { - /* Force an RGB JPEG file to be generated. */ - jpeg_set_colorspace(cinfo, JCS_RGB); - - } else if (keymatch(arg, "icc", 1)) { - /* Set ICC filename. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - icc_filename = argv[argn]; - - } else if (keymatch(arg, "lossless", 1)) { - /* Enable lossless mode. */ -#ifdef C_LOSSLESS_SUPPORTED - char ch = ',', *ptr; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%d%c", &psv, &ch) < 1 || ch != ',') - usage(); - ptr = argv[argn]; - while (*ptr && *ptr++ != ','); /* advance to next segment of arg - string */ - if (*ptr) - sscanf(ptr, "%d", &pt); - jpeg_enable_lossless(cinfo, psv, pt); -#else - fprintf(stderr, "%s: sorry, lossless output was not compiled\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "maxmemory", 3)) { - /* Maximum memory in Kb (or Mb with 'm'). */ - long lval; - char ch = 'x'; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) - usage(); - if (ch == 'm' || ch == 'M') - lval *= 1000L; - cinfo->mem->max_memory_to_use = lval * 1000L; - - } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { - /* Enable entropy parm optimization. */ -#ifdef ENTROPY_OPT_SUPPORTED - cinfo->optimize_coding = TRUE; -#else - fprintf(stderr, "%s: sorry, entropy optimization was not compiled in\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "outfile", 4)) { - /* Set output file name. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - outfilename = argv[argn]; /* save it away for later use */ - - } else if (keymatch(arg, "precision", 3)) { - /* Set data precision. */ - int val; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%d", &val) != 1) - usage(); -#ifdef C_LOSSLESS_SUPPORTED - if (val != 8 && val != 12 && val != 16) -#else - if (val != 8 && val != 12) -#endif - usage(); - cinfo->data_precision = val; - - } else if (keymatch(arg, "progressive", 3)) { - /* Select simple progressive mode. */ -#ifdef C_PROGRESSIVE_SUPPORTED - simple_progressive = TRUE; - /* We must postpone execution until num_components is known. */ -#else - fprintf(stderr, "%s: sorry, progressive output was not compiled in\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "memdst", 2)) { - /* Use in-memory destination manager */ - memdst = TRUE; - - } else if (keymatch(arg, "quality", 1)) { - /* Quality ratings (quantization table scaling factors). */ - if (++argn >= argc) /* advance to next argument */ - usage(); - qualityarg = argv[argn]; - - } else if (keymatch(arg, "qslots", 2)) { - /* Quantization table slot numbers. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - qslotsarg = argv[argn]; - /* Must delay setting qslots until after we have processed any - * colorspace-determining switches, since jpeg_set_colorspace sets - * default quant table numbers. - */ - - } else if (keymatch(arg, "qtables", 2)) { - /* Quantization tables fetched from file. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - qtablefile = argv[argn]; - /* We postpone actually reading the file in case -quality comes later. */ - - } else if (keymatch(arg, "report", 3)) { - report = TRUE; - - } else if (keymatch(arg, "restart", 1)) { - /* Restart interval in MCU rows (or in MCUs with 'b'). */ - long lval; - char ch = 'x'; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) - usage(); - if (lval < 0 || lval > 65535L) - usage(); - if (ch == 'b' || ch == 'B') { - cinfo->restart_interval = (unsigned int)lval; - cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ - } else { - cinfo->restart_in_rows = (int)lval; - /* restart_interval will be computed during startup */ - } - - } else if (keymatch(arg, "sample", 2)) { - /* Set sampling factors. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - samplearg = argv[argn]; - /* Must delay setting sample factors until after we have processed any - * colorspace-determining switches, since jpeg_set_colorspace sets - * default sampling factors. - */ - - } else if (keymatch(arg, "scans", 4)) { - /* Set scan script. */ -#ifdef C_MULTISCAN_FILES_SUPPORTED - if (++argn >= argc) /* advance to next argument */ - usage(); - scansarg = argv[argn]; - /* We must postpone reading the file in case -progressive appears. */ -#else - fprintf(stderr, "%s: sorry, multi-scan output was not compiled in\n", - progname); - exit(EXIT_FAILURE); -#endif - - } else if (keymatch(arg, "smooth", 2)) { - /* Set input smoothing factor. */ - int val; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%d", &val) != 1) - usage(); - if (val < 0 || val > 100) - usage(); - cinfo->smoothing_factor = val; - - } else if (keymatch(arg, "strict", 2)) { - strict = TRUE; - - } else if (keymatch(arg, "targa", 1)) { - /* Input file is Targa format. */ - is_targa = TRUE; - - } else { - usage(); /* bogus switch */ - } - } - - /* Post-switch-scanning cleanup */ - - if (for_real) { - - /* Set quantization tables for selected quality. */ - /* Some or all may be overridden if -qtables is present. */ - if (qualityarg != NULL) /* process -quality if it was present */ - if (!set_quality_ratings(cinfo, qualityarg, force_baseline)) - usage(); - - if (qtablefile != NULL) /* process -qtables if it was present */ - if (!read_quant_tables(cinfo, qtablefile, force_baseline)) - usage(); - - if (qslotsarg != NULL) /* process -qslots if it was present */ - if (!set_quant_slots(cinfo, qslotsarg)) - usage(); - - if (samplearg != NULL) /* process -sample if it was present */ - if (!set_sample_factors(cinfo, samplearg)) - usage(); - -#ifdef C_PROGRESSIVE_SUPPORTED - if (simple_progressive) /* process -progressive; -scans can override */ - jpeg_simple_progression(cinfo); -#endif - -#ifdef C_MULTISCAN_FILES_SUPPORTED - if (scansarg != NULL) /* process -scans if it was present */ - if (!read_scan_script(cinfo, scansarg)) - usage(); -#endif - } - - return argn; /* return index of next arg (file name) */ -} - - -METHODDEF(void) -my_emit_message(j_common_ptr cinfo, int msg_level) -{ - if (msg_level < 0) { - /* Treat warning as fatal */ - cinfo->err->error_exit(cinfo); - } else { - if (cinfo->err->trace_level >= msg_level) - cinfo->err->output_message(cinfo); - } -} - - -/* - * The main program. - */ - -int -main(int argc, char **argv) -{ - struct jpeg_compress_struct cinfo; -#ifdef CJPEG_FUZZER - struct my_error_mgr myerr; - struct jpeg_error_mgr &jerr = myerr.pub; -#else - struct jpeg_error_mgr jerr; -#endif - struct cdjpeg_progress_mgr progress; - int file_index; - cjpeg_source_ptr src_mgr; - FILE *input_file = NULL; - FILE *icc_file; - JOCTET *icc_profile = NULL; - long icc_len = 0; - FILE *output_file = NULL; - unsigned char *outbuffer = NULL; - unsigned long outsize = 0; - JDIMENSION num_scanlines; - - progname = argv[0]; - if (progname == NULL || progname[0] == 0) - progname = "cjpeg"; /* in case C library doesn't provide it */ - - /* Initialize the JPEG compression object with default error handling. */ - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_compress(&cinfo); - /* Add some application-specific error messages (from cderror.h) */ - jerr.addon_message_table = cdjpeg_message_table; - jerr.first_addon_message = JMSG_FIRSTADDONCODE; - jerr.last_addon_message = JMSG_LASTADDONCODE; - - /* Initialize JPEG parameters. - * Much of this may be overridden later. - * In particular, we don't yet know the input file's color space, - * but we need to provide some value for jpeg_set_defaults() to work. - */ - - cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ - jpeg_set_defaults(&cinfo); - - /* Scan command line to find file names. - * It is convenient to use just one switch-parsing routine, but the switch - * values read here are ignored; we will rescan the switches after opening - * the input file. - */ - - file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); - - if (strict) - jerr.emit_message = my_emit_message; - -#ifdef TWO_FILE_COMMANDLINE - if (!memdst) { - /* Must have either -outfile switch or explicit output file name */ - if (outfilename == NULL) { - if (file_index != argc - 2) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - outfilename = argv[file_index + 1]; - } else { - if (file_index != argc - 1) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - } - } -#else - /* Unix style: expect zero or one file name */ - if (file_index < argc - 1) { - fprintf(stderr, "%s: only one input file\n", progname); - usage(); - } -#endif /* TWO_FILE_COMMANDLINE */ - - /* Open the input file. */ - if (file_index < argc) { - if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); - exit(EXIT_FAILURE); - } - } else { - /* default input file is stdin */ - input_file = read_stdin(); - } - - /* Open the output file. */ - if (outfilename != NULL) { - if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, outfilename); - exit(EXIT_FAILURE); - } - } else if (!memdst) { - /* default output file is stdout */ - output_file = write_stdout(); - } - - if (icc_filename != NULL) { - if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, icc_filename); - exit(EXIT_FAILURE); - } - if (fseek(icc_file, 0, SEEK_END) < 0 || - (icc_len = ftell(icc_file)) < 1 || - fseek(icc_file, 0, SEEK_SET) < 0) { - fprintf(stderr, "%s: can't determine size of %s\n", progname, - icc_filename); - exit(EXIT_FAILURE); - } - if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) { - fprintf(stderr, "%s: can't allocate memory for ICC profile\n", progname); - fclose(icc_file); - exit(EXIT_FAILURE); - } - if (fread(icc_profile, icc_len, 1, icc_file) < 1) { - fprintf(stderr, "%s: can't read ICC profile from %s\n", progname, - icc_filename); - free(icc_profile); - fclose(icc_file); - exit(EXIT_FAILURE); - } - fclose(icc_file); - } - -#ifdef CJPEG_FUZZER - jerr.error_exit = my_error_exit; - jerr.emit_message = my_emit_message_fuzzer; - if (setjmp(myerr.setjmp_buffer)) - HANDLE_ERROR() -#endif - - if (report) { - start_progress_monitor((j_common_ptr)&cinfo, &progress); - progress.report = report; - } - - /* Figure out the input file format, and set up to read it. */ - src_mgr = select_file_type(&cinfo, input_file); - src_mgr->input_file = input_file; -#ifdef CJPEG_FUZZER - src_mgr->max_pixels = 1048576; -#endif - - /* Read the input file header to obtain file size & colorspace. */ - (*src_mgr->start_input) (&cinfo, src_mgr); - - /* Now that we know input colorspace, fix colorspace-dependent defaults */ - jpeg_default_colorspace(&cinfo); - - /* Adjust default compression parameters by re-parsing the options */ - file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); - - /* Specify data destination for compression */ - if (memdst) - jpeg_mem_dest(&cinfo, &outbuffer, &outsize); - else - jpeg_stdio_dest(&cinfo, output_file); - -#ifdef CJPEG_FUZZER - if (setjmp(myerr.setjmp_buffer)) - HANDLE_ERROR() -#endif - - /* Start compressor */ - jpeg_start_compress(&cinfo, TRUE); - - if (icc_profile != NULL) - jpeg_write_icc_profile(&cinfo, icc_profile, (unsigned int)icc_len); - - /* Process data */ - if (cinfo.data_precision == 16) { -#ifdef C_LOSSLESS_SUPPORTED - while (cinfo.next_scanline < cinfo.image_height) { - num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); - (void)jpeg16_write_scanlines(&cinfo, src_mgr->buffer16, num_scanlines); - } -#else - ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision); -#endif - } else if (cinfo.data_precision == 12) { - while (cinfo.next_scanline < cinfo.image_height) { - num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); - (void)jpeg12_write_scanlines(&cinfo, src_mgr->buffer12, num_scanlines); - } - } else { - while (cinfo.next_scanline < cinfo.image_height) { - num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); - (void)jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines); - } - } - - /* Finish compression and release memory */ - (*src_mgr->finish_input) (&cinfo, src_mgr); - jpeg_finish_compress(&cinfo); - jpeg_destroy_compress(&cinfo); - - /* Close files, if we opened them */ - if (input_file != stdin) - fclose(input_file); - if (output_file != stdout && output_file != NULL) - fclose(output_file); - - if (report) - end_progress_monitor((j_common_ptr)&cinfo); - - if (memdst) { -#ifndef CJPEG_FUZZER - fprintf(stderr, "Compressed size: %lu bytes\n", outsize); -#endif - free(outbuffer); - } - - free(icc_profile); - - /* All done. */ - return (jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); -} diff --git a/3rdparty/libjpeg-turbo/src/cmyk.h b/3rdparty/libjpeg-turbo/src/cmyk.h deleted file mode 100644 index 23891249cf..0000000000 --- a/3rdparty/libjpeg-turbo/src/cmyk.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * cmyk.h - * - * Copyright (C) 2017-2018, 2022, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains convenience functions for performing quick & dirty - * CMYK<->RGB conversion. This algorithm is suitable for testing purposes - * only. Properly converting between CMYK and RGB requires a color management - * system. - */ - -#ifndef CMYK_H -#define CMYK_H - -#include -#define JPEG_INTERNALS -#include -#include "jsamplecomp.h" - - -/* Fully reversible */ - -INLINE -LOCAL(void) -rgb_to_cmyk(_JSAMPLE r, _JSAMPLE g, _JSAMPLE b, - _JSAMPLE *c, _JSAMPLE *m, _JSAMPLE *y, _JSAMPLE *k) -{ - double ctmp = 1.0 - ((double)r / (double)_MAXJSAMPLE); - double mtmp = 1.0 - ((double)g / (double)_MAXJSAMPLE); - double ytmp = 1.0 - ((double)b / (double)_MAXJSAMPLE); - double ktmp = MIN(MIN(ctmp, mtmp), ytmp); - - if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0; - else { - ctmp = (ctmp - ktmp) / (1.0 - ktmp); - mtmp = (mtmp - ktmp) / (1.0 - ktmp); - ytmp = (ytmp - ktmp) / (1.0 - ktmp); - } - *c = (_JSAMPLE)((double)_MAXJSAMPLE - ctmp * (double)_MAXJSAMPLE + 0.5); - *m = (_JSAMPLE)((double)_MAXJSAMPLE - mtmp * (double)_MAXJSAMPLE + 0.5); - *y = (_JSAMPLE)((double)_MAXJSAMPLE - ytmp * (double)_MAXJSAMPLE + 0.5); - *k = (_JSAMPLE)((double)_MAXJSAMPLE - ktmp * (double)_MAXJSAMPLE + 0.5); -} - - -/* Fully reversible only for C/M/Y/K values generated with rgb_to_cmyk() */ - -INLINE -LOCAL(void) -cmyk_to_rgb(_JSAMPLE c, _JSAMPLE m, _JSAMPLE y, _JSAMPLE k, - _JSAMPLE *r, _JSAMPLE *g, _JSAMPLE *b) -{ - *r = (_JSAMPLE)((double)c * (double)k / (double)_MAXJSAMPLE + 0.5); - *g = (_JSAMPLE)((double)m * (double)k / (double)_MAXJSAMPLE + 0.5); - *b = (_JSAMPLE)((double)y * (double)k / (double)_MAXJSAMPLE + 0.5); -} - - -#endif /* CMYK_H */ diff --git a/3rdparty/libjpeg-turbo/src/djpeg.c b/3rdparty/libjpeg-turbo/src/djpeg.c deleted file mode 100644 index 1baedddeff..0000000000 --- a/3rdparty/libjpeg-turbo/src/djpeg.c +++ /dev/null @@ -1,932 +0,0 @@ -/* - * djpeg.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1991-1997, Thomas G. Lane. - * Modified 2013-2019 by Guido Vollbeding. - * libjpeg-turbo Modifications: - * Copyright (C) 2010-2011, 2013-2017, 2019-2020, 2022-2024, D. R. Commander. - * Copyright (C) 2015, Google, Inc. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains a command-line user interface for the JPEG decompressor. - * It should work on any system with Unix- or MS-DOS-style command lines. - * - * Two different command line styles are permitted, depending on the - * compile-time switch TWO_FILE_COMMANDLINE: - * djpeg [options] inputfile outputfile - * djpeg [options] [inputfile] - * In the second style, output is always to standard output, which you'd - * normally redirect to a file or pipe to some other program. Input is - * either from a named file or from standard input (typically redirected). - * The second style is convenient on Unix but is unhelpful on systems that - * don't support pipes. Also, you MUST use the first style if your system - * doesn't do binary I/O to stdin/stdout. - * To simplify script writing, the "-outfile" switch is provided. The syntax - * djpeg [options] -outfile outputfile inputfile - * works regardless of which command line style is used. - */ - -#ifdef _MSC_VER -#define _CRT_SECURE_NO_DEPRECATE -#endif - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include "jversion.h" /* for version message */ -#include "jconfigint.h" - -#include /* to declare isprint() */ - - -/* Create the add-on message string table. */ - -#define JMESSAGE(code, string) string, - -static const char * const cdjpeg_message_table[] = { -#include "cderror.h" - NULL -}; - - -/* - * This list defines the known output image formats - * (not all of which need be supported by a given version). - * You can change the default output format by defining DEFAULT_FMT; - * indeed, you had better do so if you undefine PPM_SUPPORTED. - */ - -typedef enum { - FMT_BMP, /* BMP format (Windows flavor) */ - FMT_GIF, /* GIF format (LZW-compressed) */ - FMT_GIF0, /* GIF format (uncompressed) */ - FMT_OS2, /* BMP format (OS/2 flavor) */ - FMT_PPM, /* PPM/PGM (PBMPLUS formats) */ - FMT_TARGA, /* Targa format */ - FMT_TIFF /* TIFF format */ -} IMAGE_FORMATS; - -#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */ -#define DEFAULT_FMT FMT_PPM -#endif - -static IMAGE_FORMATS requested_fmt; - - -/* - * Argument-parsing code. - * The switch parser is designed to be useful with DOS-style command line - * syntax, ie, intermixed switches and file names, where only the switches - * to the left of a given file name affect processing of that file. - * The main program in this file doesn't actually use this capability... - */ - - -static const char *progname; /* program name for error messages */ -static char *icc_filename; /* for -icc switch */ -static JDIMENSION max_scans; /* for -maxscans switch */ -static char *outfilename; /* for -outfile switch */ -static boolean memsrc; /* for -memsrc switch */ -static boolean report; /* for -report switch */ -static boolean skip, crop; -static JDIMENSION skip_start, skip_end; -static JDIMENSION crop_x, crop_y, crop_width, crop_height; -static boolean strict; /* for -strict switch */ -#define INPUT_BUF_SIZE 4096 - - -LOCAL(void) -usage(void) -/* complain about bad command line */ -{ - fprintf(stderr, "usage: %s [switches] ", progname); -#ifdef TWO_FILE_COMMANDLINE - fprintf(stderr, "inputfile outputfile\n"); -#else - fprintf(stderr, "[inputfile]\n"); -#endif - - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -colors N Reduce image to no more than N colors\n"); - fprintf(stderr, " -fast Fast, low-quality processing\n"); - fprintf(stderr, " -grayscale Force grayscale output\n"); - fprintf(stderr, " -rgb Force RGB output\n"); - fprintf(stderr, " -rgb565 Force RGB565 output\n"); -#ifdef IDCT_SCALING_SUPPORTED - fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); -#endif -#ifdef BMP_SUPPORTED - fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n", - (DEFAULT_FMT == FMT_BMP ? " (default)" : "")); -#endif -#ifdef GIF_SUPPORTED - fprintf(stderr, " -gif Select GIF output format (LZW-compressed)%s\n", - (DEFAULT_FMT == FMT_GIF ? " (default)" : "")); - fprintf(stderr, " -gif0 Select GIF output format (uncompressed)%s\n", - (DEFAULT_FMT == FMT_GIF0 ? " (default)" : "")); -#endif -#ifdef BMP_SUPPORTED - fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n", - (DEFAULT_FMT == FMT_OS2 ? " (default)" : "")); -#endif -#ifdef PPM_SUPPORTED - fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n", - (DEFAULT_FMT == FMT_PPM ? " (default)" : "")); -#endif -#ifdef TARGA_SUPPORTED - fprintf(stderr, " -targa Select Targa output format%s\n", - (DEFAULT_FMT == FMT_TARGA ? " (default)" : "")); -#endif - fprintf(stderr, "Switches for advanced users:\n"); -#ifdef DCT_ISLOW_SUPPORTED - fprintf(stderr, " -dct int Use accurate integer DCT method%s\n", - (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); -#endif -#ifdef DCT_IFAST_SUPPORTED - fprintf(stderr, " -dct fast Use less accurate integer DCT method [legacy feature]%s\n", - (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); -#endif -#ifdef DCT_FLOAT_SUPPORTED - fprintf(stderr, " -dct float Use floating-point DCT method [legacy feature]%s\n", - (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); -#endif - fprintf(stderr, " -dither fs Use F-S dithering (default)\n"); - fprintf(stderr, " -dither none Don't use dithering in quantization\n"); - fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n"); - fprintf(stderr, " -icc FILE Extract ICC profile to FILE\n"); -#ifdef QUANT_2PASS_SUPPORTED - fprintf(stderr, " -map FILE Map to colors used in named image file\n"); -#endif - fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n"); -#ifdef QUANT_1PASS_SUPPORTED - fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n"); -#endif - fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); - fprintf(stderr, " -maxscans N Maximum number of scans to allow in input file\n"); - fprintf(stderr, " -outfile name Specify name for output file\n"); - fprintf(stderr, " -memsrc Load input file into memory before decompressing\n"); - fprintf(stderr, " -report Report decompression progress\n"); - fprintf(stderr, " -skip Y0,Y1 Decompress all rows except those between Y0 and Y1 (inclusive)\n"); - fprintf(stderr, " -crop WxH+X+Y Decompress only a rectangular subregion of the image\n"); - fprintf(stderr, " [requires PBMPLUS (PPM/PGM), GIF, or Targa output format]\n"); - fprintf(stderr, " -strict Treat all warnings as fatal\n"); - fprintf(stderr, " -verbose or -debug Emit debug output\n"); - fprintf(stderr, " -version Print version information and exit\n"); - exit(EXIT_FAILURE); -} - - -LOCAL(int) -parse_switches(j_decompress_ptr cinfo, int argc, char **argv, - int last_file_arg_seen, boolean for_real) -/* Parse optional switches. - * Returns argv[] index of first file-name argument (== argc if none). - * Any file names with indexes <= last_file_arg_seen are ignored; - * they have presumably been processed in a previous iteration. - * (Pass 0 for last_file_arg_seen on the first or only iteration.) - * for_real is FALSE on the first (dummy) pass; we may skip any expensive - * processing. - */ -{ - int argn; - char *arg; - - /* Set up default JPEG parameters. */ - requested_fmt = DEFAULT_FMT; /* set default output file format */ - icc_filename = NULL; - max_scans = 0; - outfilename = NULL; - memsrc = FALSE; - report = FALSE; - skip = FALSE; - crop = FALSE; - strict = FALSE; - cinfo->err->trace_level = 0; - - /* Scan command line options, adjust parameters */ - - for (argn = 1; argn < argc; argn++) { - arg = argv[argn]; - if (*arg != '-') { - /* Not a switch, must be a file name argument */ - if (argn <= last_file_arg_seen) { - outfilename = NULL; /* -outfile applies to just one input file */ - continue; /* ignore this name if previously processed */ - } - break; /* else done parsing switches */ - } - arg++; /* advance past switch marker character */ - - if (keymatch(arg, "bmp", 1)) { - /* BMP output format (Windows flavor). */ - requested_fmt = FMT_BMP; - - } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) || - keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) { - /* Do color quantization. */ - int val; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%d", &val) != 1) - usage(); - cinfo->desired_number_of_colors = val; - cinfo->quantize_colors = TRUE; - - } else if (keymatch(arg, "dct", 2)) { - /* Select IDCT algorithm. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (keymatch(argv[argn], "int", 1)) { - cinfo->dct_method = JDCT_ISLOW; - } else if (keymatch(argv[argn], "fast", 2)) { - cinfo->dct_method = JDCT_IFAST; - } else if (keymatch(argv[argn], "float", 2)) { - cinfo->dct_method = JDCT_FLOAT; - } else - usage(); - - } else if (keymatch(arg, "dither", 2)) { - /* Select dithering algorithm. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (keymatch(argv[argn], "fs", 2)) { - cinfo->dither_mode = JDITHER_FS; - } else if (keymatch(argv[argn], "none", 2)) { - cinfo->dither_mode = JDITHER_NONE; - } else if (keymatch(argv[argn], "ordered", 2)) { - cinfo->dither_mode = JDITHER_ORDERED; - } else - usage(); - - } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { - /* Enable debug printouts. */ - /* On first -d, print version identification */ - static boolean printed_version = FALSE; - - if (!printed_version) { - fprintf(stderr, "%s version %s (build %s)\n", - PACKAGE_NAME, VERSION, BUILD); - fprintf(stderr, JCOPYRIGHT1); - fprintf(stderr, JCOPYRIGHT2 "\n"); - fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n", - JVERSION); - printed_version = TRUE; - } - cinfo->err->trace_level++; - - } else if (keymatch(arg, "version", 4)) { - fprintf(stderr, "%s version %s (build %s)\n", - PACKAGE_NAME, VERSION, BUILD); - exit(EXIT_SUCCESS); - - } else if (keymatch(arg, "fast", 1)) { - /* Select recommended processing options for quick-and-dirty output. */ - cinfo->two_pass_quantize = FALSE; - cinfo->dither_mode = JDITHER_ORDERED; - if (!cinfo->quantize_colors) /* don't override an earlier -colors */ - cinfo->desired_number_of_colors = 216; - cinfo->dct_method = JDCT_FASTEST; - cinfo->do_fancy_upsampling = FALSE; - - } else if (keymatch(arg, "gif", 1)) { - /* GIF output format (LZW-compressed). */ - requested_fmt = FMT_GIF; - - } else if (keymatch(arg, "gif0", 4)) { - /* GIF output format (uncompressed). */ - requested_fmt = FMT_GIF0; - - } else if (keymatch(arg, "grayscale", 2) || - keymatch(arg, "greyscale", 2)) { - /* Force monochrome output. */ - cinfo->out_color_space = JCS_GRAYSCALE; - - } else if (keymatch(arg, "rgb", 2)) { - /* Force RGB output. */ - cinfo->out_color_space = JCS_RGB; - - } else if (keymatch(arg, "rgb565", 2)) { - /* Force RGB565 output. */ - cinfo->out_color_space = JCS_RGB565; - - } else if (keymatch(arg, "icc", 1)) { - /* Set ICC filename. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - icc_filename = argv[argn]; -#ifdef SAVE_MARKERS_SUPPORTED - jpeg_save_markers(cinfo, JPEG_APP0 + 2, 0xFFFF); -#endif - - } else if (keymatch(arg, "map", 3)) { - /* Quantize to a color map taken from an input file. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (for_real) { /* too expensive to do twice! */ -#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ - FILE *mapfile; - - if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); - exit(EXIT_FAILURE); - } - if (cinfo->data_precision == 12) - read_color_map_12(cinfo, mapfile); - else - read_color_map(cinfo, mapfile); - fclose(mapfile); - cinfo->quantize_colors = TRUE; -#else - ERREXIT(cinfo, JERR_NOT_COMPILED); -#endif - } - - } else if (keymatch(arg, "maxmemory", 3)) { - /* Maximum memory in Kb (or Mb with 'm'). */ - long lval; - char ch = 'x'; - - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) - usage(); - if (ch == 'm' || ch == 'M') - lval *= 1000L; - cinfo->mem->max_memory_to_use = lval * 1000L; - - } else if (keymatch(arg, "maxscans", 4)) { - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%u", &max_scans) != 1) - usage(); - - } else if (keymatch(arg, "nosmooth", 3)) { - /* Suppress fancy upsampling */ - cinfo->do_fancy_upsampling = FALSE; - - } else if (keymatch(arg, "onepass", 3)) { - /* Use fast one-pass quantization. */ - cinfo->two_pass_quantize = FALSE; - - } else if (keymatch(arg, "os2", 3)) { - /* BMP output format (OS/2 flavor). */ - requested_fmt = FMT_OS2; - - } else if (keymatch(arg, "outfile", 4)) { - /* Set output file name. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - outfilename = argv[argn]; /* save it away for later use */ - - } else if (keymatch(arg, "memsrc", 2)) { - /* Use in-memory source manager */ - memsrc = TRUE; - - } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) { - /* PPM/PGM output format. */ - requested_fmt = FMT_PPM; - - } else if (keymatch(arg, "report", 2)) { - report = TRUE; - - } else if (keymatch(arg, "scale", 2)) { - /* Scale the output image by a fraction M/N. */ - if (++argn >= argc) /* advance to next argument */ - usage(); - if (sscanf(argv[argn], "%u/%u", - &cinfo->scale_num, &cinfo->scale_denom) != 2) - usage(); - - } else if (keymatch(arg, "skip", 2)) { - if (++argn >= argc) - usage(); - if (sscanf(argv[argn], "%u,%u", &skip_start, &skip_end) != 2 || - skip_start > skip_end) - usage(); - skip = TRUE; - - } else if (keymatch(arg, "crop", 2)) { - char c; - if (++argn >= argc) - usage(); - if (sscanf(argv[argn], "%u%c%u+%u+%u", &crop_width, &c, &crop_height, - &crop_x, &crop_y) != 5 || - (c != 'X' && c != 'x') || crop_width < 1 || crop_height < 1) - usage(); - crop = TRUE; - - } else if (keymatch(arg, "strict", 2)) { - strict = TRUE; - - } else if (keymatch(arg, "targa", 1)) { - /* Targa output format. */ - requested_fmt = FMT_TARGA; - - } else { - usage(); /* bogus switch */ - } - } - - return argn; /* return index of next arg (file name) */ -} - - -/* - * Marker processor for COM and interesting APPn markers. - * This replaces the library's built-in processor, which just skips the marker. - * We want to print out the marker as text, to the extent possible. - * Note this code relies on a non-suspending data source. - */ - -LOCAL(unsigned int) -jpeg_getc(j_decompress_ptr cinfo) -/* Read next byte */ -{ - struct jpeg_source_mgr *datasrc = cinfo->src; - - if (datasrc->bytes_in_buffer == 0) { - if (!(*datasrc->fill_input_buffer) (cinfo)) - ERREXIT(cinfo, JERR_CANT_SUSPEND); - } - datasrc->bytes_in_buffer--; - return *datasrc->next_input_byte++; -} - - -METHODDEF(boolean) -print_text_marker(j_decompress_ptr cinfo) -{ - boolean traceit = (cinfo->err->trace_level >= 1); - long length; - unsigned int ch; - unsigned int lastch = 0; - - length = jpeg_getc(cinfo) << 8; - length += jpeg_getc(cinfo); - length -= 2; /* discount the length word itself */ - - if (traceit) { - if (cinfo->unread_marker == JPEG_COM) - fprintf(stderr, "Comment, length %ld:\n", (long)length); - else /* assume it is an APPn otherwise */ - fprintf(stderr, "APP%d, length %ld:\n", - cinfo->unread_marker - JPEG_APP0, (long)length); - } - - while (--length >= 0) { - ch = jpeg_getc(cinfo); - if (traceit) { - /* Emit the character in a readable form. - * Nonprintables are converted to \nnn form, - * while \ is converted to \\. - * Newlines in CR, CR/LF, or LF form will be printed as one newline. - */ - if (ch == '\r') { - fprintf(stderr, "\n"); - } else if (ch == '\n') { - if (lastch != '\r') - fprintf(stderr, "\n"); - } else if (ch == '\\') { - fprintf(stderr, "\\\\"); - } else if (isprint(ch)) { - putc(ch, stderr); - } else { - fprintf(stderr, "\\%03o", ch); - } - lastch = ch; - } - } - - if (traceit) - fprintf(stderr, "\n"); - - return TRUE; -} - - -METHODDEF(void) -my_emit_message(j_common_ptr cinfo, int msg_level) -{ - if (msg_level < 0) { - /* Treat warning as fatal */ - cinfo->err->error_exit(cinfo); - } else { - if (cinfo->err->trace_level >= msg_level) - cinfo->err->output_message(cinfo); - } -} - - -/* - * The main program. - */ - -int -main(int argc, char **argv) -{ - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - struct cdjpeg_progress_mgr progress; - int file_index; - djpeg_dest_ptr dest_mgr = NULL; - FILE *input_file; - FILE *output_file; - unsigned char *inbuffer = NULL; - unsigned long insize = 0; - JDIMENSION num_scanlines; - - progname = argv[0]; - if (progname == NULL || progname[0] == 0) - progname = "djpeg"; /* in case C library doesn't provide it */ - - /* Initialize the JPEG decompression object with default error handling. */ - cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress(&cinfo); - /* Add some application-specific error messages (from cderror.h) */ - jerr.addon_message_table = cdjpeg_message_table; - jerr.first_addon_message = JMSG_FIRSTADDONCODE; - jerr.last_addon_message = JMSG_LASTADDONCODE; - - /* Insert custom marker processor for COM and APP12. - * APP12 is used by some digital camera makers for textual info, - * so we provide the ability to display it as text. - * If you like, additional APPn marker types can be selected for display, - * but don't try to override APP0 or APP14 this way (see libjpeg.txt). - */ - jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker); - jpeg_set_marker_processor(&cinfo, JPEG_APP0 + 12, print_text_marker); - - /* Scan command line to find file names. */ - /* It is convenient to use just one switch-parsing routine, but the switch - * values read here are ignored; we will rescan the switches after opening - * the input file. - * (Exception: tracing level set here controls verbosity for COM markers - * found during jpeg_read_header...) - */ - - file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); - - if (strict) - jerr.emit_message = my_emit_message; - -#ifdef TWO_FILE_COMMANDLINE - /* Must have either -outfile switch or explicit output file name */ - if (outfilename == NULL) { - if (file_index != argc - 2) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - outfilename = argv[file_index + 1]; - } else { - if (file_index != argc - 1) { - fprintf(stderr, "%s: must name one input and one output file\n", - progname); - usage(); - } - } -#else - /* Unix style: expect zero or one file name */ - if (file_index < argc - 1) { - fprintf(stderr, "%s: only one input file\n", progname); - usage(); - } -#endif /* TWO_FILE_COMMANDLINE */ - - /* Open the input file. */ - if (file_index < argc) { - if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); - exit(EXIT_FAILURE); - } - } else { - /* default input file is stdin */ - input_file = read_stdin(); - } - - /* Open the output file. */ - if (outfilename != NULL) { - if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, outfilename); - exit(EXIT_FAILURE); - } - } else { - /* default output file is stdout */ - output_file = write_stdout(); - } - - if (report || max_scans != 0) { - start_progress_monitor((j_common_ptr)&cinfo, &progress); - progress.report = report; - progress.max_scans = max_scans; - } - - /* Specify data source for decompression */ - if (memsrc) { - size_t nbytes; - do { - inbuffer = (unsigned char *)realloc(inbuffer, insize + INPUT_BUF_SIZE); - if (inbuffer == NULL) { - fprintf(stderr, "%s: memory allocation failure\n", progname); - exit(EXIT_FAILURE); - } - nbytes = fread(&inbuffer[insize], 1, INPUT_BUF_SIZE, input_file); - if (nbytes < INPUT_BUF_SIZE && ferror(input_file)) { - if (file_index < argc) - fprintf(stderr, "%s: can't read from %s\n", progname, - argv[file_index]); - else - fprintf(stderr, "%s: can't read from stdin\n", progname); - } - insize += (unsigned long)nbytes; - } while (nbytes == INPUT_BUF_SIZE); - fprintf(stderr, "Compressed size: %lu bytes\n", insize); - jpeg_mem_src(&cinfo, inbuffer, insize); - } else - jpeg_stdio_src(&cinfo, input_file); - - /* Read file header, set default decompression parameters */ - (void)jpeg_read_header(&cinfo, TRUE); - - /* Adjust default decompression parameters by re-parsing the options */ - file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); - - /* Initialize the output module now to let it override any crucial - * option settings (for instance, GIF wants to force color quantization). - */ - switch (requested_fmt) { -#ifdef BMP_SUPPORTED - case FMT_BMP: - dest_mgr = jinit_write_bmp(&cinfo, FALSE, TRUE); - break; - case FMT_OS2: - dest_mgr = jinit_write_bmp(&cinfo, TRUE, TRUE); - break; -#endif -#ifdef GIF_SUPPORTED - case FMT_GIF: - if (cinfo.data_precision == 16) - ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision); - else if (cinfo.data_precision == 12) - dest_mgr = j12init_write_gif(&cinfo, TRUE); - else - dest_mgr = jinit_write_gif(&cinfo, TRUE); - break; - case FMT_GIF0: - dest_mgr = jinit_write_gif(&cinfo, FALSE); - break; -#endif -#ifdef PPM_SUPPORTED - case FMT_PPM: - if (cinfo.data_precision == 16) -#ifdef D_LOSSLESS_SUPPORTED - dest_mgr = j16init_write_ppm(&cinfo); -#else - ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision); -#endif - else if (cinfo.data_precision == 12) - dest_mgr = j12init_write_ppm(&cinfo); - else - dest_mgr = jinit_write_ppm(&cinfo); - break; -#endif -#ifdef TARGA_SUPPORTED - case FMT_TARGA: - dest_mgr = jinit_write_targa(&cinfo); - break; -#endif - default: - ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT); - break; - } - dest_mgr->output_file = output_file; - - /* Start decompressor */ - (void)jpeg_start_decompress(&cinfo); - - /* Skip rows */ - if (skip) { - JDIMENSION tmp; - - /* Check for valid skip_end. We cannot check this value until after - * jpeg_start_decompress() is called. Note that we have already verified - * that skip_start <= skip_end. - */ - if (skip_end > cinfo.output_height - 1) { - fprintf(stderr, "%s: skip region exceeds image height %u\n", progname, - cinfo.output_height); - exit(EXIT_FAILURE); - } - - /* Write output file header. This is a hack to ensure that the destination - * manager creates an output image of the proper size. - */ - tmp = cinfo.output_height; - cinfo.output_height -= (skip_end - skip_start + 1); - (*dest_mgr->start_output) (&cinfo, dest_mgr); - cinfo.output_height = tmp; - - if (cinfo.data_precision == 16) - ERREXIT(&cinfo, JERR_NOTIMPL); - else if (cinfo.data_precision == 12) { - /* Process data */ - while (cinfo.output_scanline < skip_start) { - num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } - if ((tmp = jpeg12_skip_scanlines(&cinfo, skip_end - skip_start + 1)) != - skip_end - skip_start + 1) { - fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n", - progname, tmp, skip_end - skip_start + 1); - exit(EXIT_FAILURE); - } - while (cinfo.output_scanline < cinfo.output_height) { - num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } - } else { - /* Process data */ - while (cinfo.output_scanline < skip_start) { - num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } - if ((tmp = jpeg_skip_scanlines(&cinfo, skip_end - skip_start + 1)) != - skip_end - skip_start + 1) { - fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n", - progname, tmp, skip_end - skip_start + 1); - exit(EXIT_FAILURE); - } - while (cinfo.output_scanline < cinfo.output_height) { - num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } - } - - /* Decompress a subregion */ - } else if (crop) { - JDIMENSION tmp; - - /* Check for valid crop dimensions. We cannot check these values until - * after jpeg_start_decompress() is called. - */ - if (crop_x + crop_width > cinfo.output_width || - crop_y + crop_height > cinfo.output_height) { - fprintf(stderr, "%s: crop dimensions exceed image dimensions %u x %u\n", - progname, cinfo.output_width, cinfo.output_height); - exit(EXIT_FAILURE); - } - - if (cinfo.data_precision == 16) - ERREXIT(&cinfo, JERR_NOTIMPL); - else if (cinfo.data_precision == 12) - jpeg12_crop_scanline(&cinfo, &crop_x, &crop_width); - else - jpeg_crop_scanline(&cinfo, &crop_x, &crop_width); - if (dest_mgr->calc_buffer_dimensions) - (*dest_mgr->calc_buffer_dimensions) (&cinfo, dest_mgr); - else - ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT); - - /* Write output file header. This is a hack to ensure that the destination - * manager creates an output image of the proper size. - */ - tmp = cinfo.output_height; - cinfo.output_height = crop_height; - (*dest_mgr->start_output) (&cinfo, dest_mgr); - cinfo.output_height = tmp; - - if (cinfo.data_precision == 16) - ERREXIT(&cinfo, JERR_NOTIMPL); - else if (cinfo.data_precision == 12) { - /* Process data */ - if ((tmp = jpeg12_skip_scanlines(&cinfo, crop_y)) != crop_y) { - fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n", - progname, tmp, crop_y); - exit(EXIT_FAILURE); - } - while (cinfo.output_scanline < crop_y + crop_height) { - num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } - if ((tmp = - jpeg12_skip_scanlines(&cinfo, cinfo.output_height - crop_y - - crop_height)) != - cinfo.output_height - crop_y - crop_height) { - fprintf(stderr, "%s: jpeg12_skip_scanlines() returned %u rather than %u\n", - progname, tmp, cinfo.output_height - crop_y - crop_height); - exit(EXIT_FAILURE); - } - } else { - /* Process data */ - if ((tmp = jpeg_skip_scanlines(&cinfo, crop_y)) != crop_y) { - fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n", - progname, tmp, crop_y); - exit(EXIT_FAILURE); - } - while (cinfo.output_scanline < crop_y + crop_height) { - num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } - if ((tmp = - jpeg_skip_scanlines(&cinfo, - cinfo.output_height - crop_y - crop_height)) != - cinfo.output_height - crop_y - crop_height) { - fprintf(stderr, "%s: jpeg_skip_scanlines() returned %u rather than %u\n", - progname, tmp, cinfo.output_height - crop_y - crop_height); - exit(EXIT_FAILURE); - } - } - - /* Normal full-image decompress */ - } else { - /* Write output file header */ - (*dest_mgr->start_output) (&cinfo, dest_mgr); - - if (cinfo.data_precision == 16) { -#ifdef D_LOSSLESS_SUPPORTED - /* Process data */ - while (cinfo.output_scanline < cinfo.output_height) { - num_scanlines = jpeg16_read_scanlines(&cinfo, dest_mgr->buffer16, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } -#else - ERREXIT1(&cinfo, JERR_BAD_PRECISION, cinfo.data_precision); -#endif - } else if (cinfo.data_precision == 12) { - /* Process data */ - while (cinfo.output_scanline < cinfo.output_height) { - num_scanlines = jpeg12_read_scanlines(&cinfo, dest_mgr->buffer12, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } - } else { - /* Process data */ - while (cinfo.output_scanline < cinfo.output_height) { - num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, - dest_mgr->buffer_height); - (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); - } - } - } - - /* Hack: count final pass as done in case finish_output does an extra pass. - * The library won't have updated completed_passes. - */ - if (report || max_scans != 0) - progress.pub.completed_passes = progress.pub.total_passes; - - if (icc_filename != NULL) { - FILE *icc_file; - JOCTET *icc_profile; - unsigned int icc_len; - - if ((icc_file = fopen(icc_filename, WRITE_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, icc_filename); - exit(EXIT_FAILURE); - } - if (jpeg_read_icc_profile(&cinfo, &icc_profile, &icc_len)) { - if (fwrite(icc_profile, icc_len, 1, icc_file) < 1) { - fprintf(stderr, "%s: can't read ICC profile from %s\n", progname, - icc_filename); - free(icc_profile); - fclose(icc_file); - exit(EXIT_FAILURE); - } - free(icc_profile); - fclose(icc_file); - } else if (cinfo.err->msg_code != JWRN_BOGUS_ICC) - fprintf(stderr, "%s: no ICC profile data in JPEG file\n", progname); - } - - /* Finish decompression and release memory. - * I must do it in this order because output module has allocated memory - * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory. - */ - (*dest_mgr->finish_output) (&cinfo, dest_mgr); - (void)jpeg_finish_decompress(&cinfo); - jpeg_destroy_decompress(&cinfo); - - /* Close files, if we opened them */ - if (input_file != stdin) - fclose(input_file); - if (output_file != stdout) - fclose(output_file); - - if (report || max_scans != 0) - end_progress_monitor((j_common_ptr)&cinfo); - - if (memsrc) - free(inbuffer); - - /* All done. */ - exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); - return 0; /* suppress no-return-value warnings */ -} diff --git a/3rdparty/libjpeg-turbo/src/example.c b/3rdparty/libjpeg-turbo/src/example.c deleted file mode 100644 index 78b658a0ab..0000000000 --- a/3rdparty/libjpeg-turbo/src/example.c +++ /dev/null @@ -1,643 +0,0 @@ -/* - * example.c - * - * This file was part of the Independent JPEG Group's software. - * Copyright (C) 1992-1996, Thomas G. Lane. - * libjpeg-turbo Modifications: - * Copyright (C) 2017, 2019, 2022-2023, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file illustrates how to use the IJG code as a subroutine library - * to read or write JPEG image files with 8-bit or 12-bit data precision. You - * should look at this code in conjunction with the documentation file - * libjpeg.txt. - * - * We present these routines in the same coding style used in the JPEG code - * (ANSI function definitions, etc); but you are of course free to code your - * routines in a different style if you prefer. - */ - -/* First-time users of libjpeg-turbo might be better served by looking at - * tjexample.c, which uses the more straightforward TurboJPEG API. Note that - * this example, like cjpeg and djpeg, interleaves disk I/O with JPEG - * compression/decompression, so it is not suitable for benchmarking purposes. - */ - -#ifdef _MSC_VER -#define _CRT_SECURE_NO_DEPRECATE -#endif - -#include -#include -#include - -#ifdef _WIN32 -#define strcasecmp stricmp -#define strncasecmp strnicmp -#endif - -/* - * Include file for users of JPEG library. - * You will need to have included system headers that define at least - * the typedefs FILE and size_t before you can include jpeglib.h. - * (stdio.h is sufficient on ANSI-conforming systems.) - * You may also wish to include "jerror.h". - */ - -#include "jpeglib.h" -#include "jerror.h" - -/* - * is used for the optional error recovery mechanism shown in - * the second part of the example. - */ - -#include - - - -/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/ - -/* This half of the example shows how to feed data into the JPEG compressor. - * We present a minimal version that does not worry about refinements such - * as error recovery (the JPEG code will just exit() if it gets an error). - */ - - -/* - * IMAGE DATA FORMATS: - * - * The standard input image format is a rectangular array of pixels, with - * each pixel having the same number of "component" values (color channels). - * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars) - * or J12SAMPLEs (which typically are shorts). If you are working with color - * data, then the color values for each pixel must be adjacent in the row; for - * example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color. - * - * For this example, we'll assume that this data structure matches the way - * our application has stored the image in memory, so we can just pass a - * pointer to our image buffer. In particular, let's say that the image is - * RGB color and is described by: - */ - -#define WIDTH 640 /* Number of columns in image */ -#define HEIGHT 480 /* Number of rows in image */ - - -/* - * Sample routine for JPEG compression. We assume that the target file name, - * a compression quality factor, and a data precision are passed in. - */ - -METHODDEF(void) -write_JPEG_file(char *filename, int quality, int data_precision) -{ - /* This struct contains the JPEG compression parameters and pointers to - * working space (which is allocated as needed by the JPEG library). - * It is possible to have several such structures, representing multiple - * compression/decompression processes, in existence at once. We refer - * to any one struct (and its associated working data) as a "JPEG object". - */ - struct jpeg_compress_struct cinfo; - /* This struct represents a JPEG error handler. It is declared separately - * because applications often want to supply a specialized error handler - * (see the second half of this file for an example). But here we just - * take the easy way out and use the standard error handler, which will - * print a message on stderr and call exit() if compression fails. - * Note that this struct must live as long as the main JPEG parameter - * struct, to avoid dangling-pointer problems. - */ - struct jpeg_error_mgr jerr; - /* More stuff */ - FILE *outfile; /* target file */ - JSAMPARRAY image_buffer = NULL; - /* Points to large array of R,G,B-order data */ - JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ - J12SAMPARRAY image_buffer12 = NULL; - /* Points to large array of R,G,B-order 12-bit - data */ - J12SAMPROW row_pointer12[1]; /* pointer to J12SAMPLE row[s] */ - int row_stride; /* physical row width in image buffer */ - int row, col; - - /* Step 1: allocate and initialize JPEG compression object */ - - /* We have to set up the error handler first, in case the initialization - * step fails. (Unlikely, but it could happen if you are out of memory.) - * This routine fills in the contents of struct jerr, and returns jerr's - * address which we place into the link field in cinfo. - */ - cinfo.err = jpeg_std_error(&jerr); - /* Now we can initialize the JPEG compression object. */ - jpeg_create_compress(&cinfo); - - /* Step 2: specify data destination (eg, a file) */ - /* Note: steps 2 and 3 can be done in either order. */ - - /* Here we use the library-supplied code to send compressed data to a - * stdio stream. You can also write your own code to do something else. - * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that - * requires it in order to write binary files. - */ - if ((outfile = fopen(filename, "wb")) == NULL) - ERREXIT(&cinfo, JERR_FILE_WRITE); - jpeg_stdio_dest(&cinfo, outfile); - - /* Step 3: set parameters for compression */ - - /* First we supply a description of the input image. - * Four fields of the cinfo struct must be filled in: - */ - cinfo.image_width = WIDTH; /* image width and height, in pixels */ - cinfo.image_height = HEIGHT; - cinfo.input_components = 3; /* # of color components per pixel */ - cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ - cinfo.data_precision = data_precision; /* data precision of input image */ - /* Now use the library's routine to set default compression parameters. - * (You must set at least cinfo.in_color_space before calling this, - * since the defaults depend on the source color space.) - */ - jpeg_set_defaults(&cinfo); - /* Now you can set any non-default parameters you wish to. - * Here we just illustrate the use of quality (quantization table) scaling: - */ - jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); - /* Use 4:4:4 subsampling (default is 4:2:0) */ - cinfo.comp_info[0].h_samp_factor = cinfo.comp_info[0].v_samp_factor = 1; - - /* Step 4: Start compressor */ - - /* TRUE ensures that we will write a complete interchange-JPEG file. - * Pass TRUE unless you are very sure of what you're doing. - */ - jpeg_start_compress(&cinfo, TRUE); - - /* Step 5: allocate and initialize image buffer */ - - row_stride = WIDTH * 3; /* J[12]SAMPLEs per row in image_buffer */ - /* Make a sample array that will go away when done with image. Note that, - * for the purposes of this example, we could also create a one-row-high - * sample array and initialize it for each successive scanline written in the - * scanline loop below. - */ - if (cinfo.data_precision == 12) { - image_buffer12 = (J12SAMPARRAY)(*cinfo.mem->alloc_sarray) - ((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT); - - /* Initialize image buffer with a repeating pattern */ - for (row = 0; row < HEIGHT; row++) { - for (col = 0; col < WIDTH; col++) { - image_buffer12[row][col * 3] = - (col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1); - image_buffer12[row][col * 3 + 1] = - (row * (MAXJ12SAMPLE + 1) / HEIGHT) % (MAXJ12SAMPLE + 1); - image_buffer12[row][col * 3 + 2] = - (row * (MAXJ12SAMPLE + 1) / HEIGHT + - col * (MAXJ12SAMPLE + 1) / WIDTH) % (MAXJ12SAMPLE + 1); - } - } - } else { - image_buffer = (*cinfo.mem->alloc_sarray) - ((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, HEIGHT); - - for (row = 0; row < HEIGHT; row++) { - for (col = 0; col < WIDTH; col++) { - image_buffer[row][col * 3] = - (col * (MAXJSAMPLE + 1) / WIDTH) % (MAXJSAMPLE + 1); - image_buffer[row][col * 3 + 1] = - (row * (MAXJSAMPLE + 1) / HEIGHT) % (MAXJSAMPLE + 1); - image_buffer[row][col * 3 + 2] = - (row * (MAXJSAMPLE + 1) / HEIGHT + col * (MAXJSAMPLE + 1) / WIDTH) % - (MAXJSAMPLE + 1); - } - } - } - - /* Step 6: while (scan lines remain to be written) */ - /* jpeg_write_scanlines(...); */ - - /* Here we use the library's state variable cinfo.next_scanline as the - * loop counter, so that we don't have to keep track ourselves. - * To keep things simple, we pass one scanline per call; you can pass - * more if you wish, though. - */ - if (cinfo.data_precision == 12) { - while (cinfo.next_scanline < cinfo.image_height) { - /* jpeg12_write_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could pass - * more than one scanline at a time if that's more convenient. - */ - row_pointer12[0] = image_buffer12[cinfo.next_scanline]; - (void)jpeg12_write_scanlines(&cinfo, row_pointer12, 1); - } - } else { - while (cinfo.next_scanline < cinfo.image_height) { - /* jpeg_write_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could pass - * more than one scanline at a time if that's more convenient. - */ - row_pointer[0] = image_buffer[cinfo.next_scanline]; - (void)jpeg_write_scanlines(&cinfo, row_pointer, 1); - } - } - - /* Step 7: Finish compression */ - - jpeg_finish_compress(&cinfo); - /* After finish_compress, we can close the output file. */ - fclose(outfile); - - /* Step 8: release JPEG compression object */ - - /* This is an important step since it will release a good deal of memory. */ - jpeg_destroy_compress(&cinfo); - - /* And we're done! */ -} - - -/* - * SOME FINE POINTS: - * - * In the above loop, we ignored the return value of jpeg_write_scanlines, - * which is the number of scanlines actually written. We could get away - * with this because we were only relying on the value of cinfo.next_scanline, - * which will be incremented correctly. If you maintain additional loop - * variables then you should be careful to increment them properly. - * Actually, for output to a stdio stream you needn't worry, because - * then jpeg_write_scanlines will write all the lines passed (or else exit - * with a fatal error). Partial writes can only occur if you use a data - * destination module that can demand suspension of the compressor. - * (If you don't know what that's for, you don't need it.) - * - * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG - * files to be compatible with everyone else's. If you cannot readily read - * your data in that order, you'll need an intermediate array to hold the - * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top - * source data using the JPEG code's internal virtual-array mechanisms. - */ - - - -/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/ - -/* This half of the example shows how to read data from the JPEG decompressor. - * It's a bit more refined than the above, in that we show: - * (a) how to modify the JPEG library's standard error-reporting behavior; - * (b) how to allocate workspace using the library's memory manager. - * - * Just to make this example a little different from the first one, we'll - * assume that we do not intend to put the whole image into an in-memory - * buffer, but to send it line-by-line someplace else. We need a one- - * scanline-high JSAMPLE or J12SAMPLE array as a work buffer, and we will let - * the JPEG memory manager allocate it for us. This approach is actually quite - * useful because we don't need to remember to deallocate the buffer - * separately: it will go away automatically when the JPEG object is cleaned - * up. - */ - - -/* - * ERROR HANDLING: - * - * The JPEG library's standard error handler (jerror.c) is divided into - * several "methods" which you can override individually. This lets you - * adjust the behavior without duplicating a lot of code, which you might - * have to update with each future release. - * - * Our example here shows how to override the "error_exit" method so that - * control is returned to the library's caller when a fatal error occurs, - * rather than calling exit() as the standard error_exit method does. - * - * We use C's setjmp/longjmp facility to return control. This means that the - * routine which calls the JPEG library must first execute a setjmp() call to - * establish the return point. We want the replacement error_exit to do a - * longjmp(). But we need to make the setjmp buffer accessible to the - * error_exit routine. To do this, we make a private extension of the - * standard JPEG error handler object. (If we were using C++, we'd say we - * were making a subclass of the regular error handler.) - * - * Here's the extended error handler struct: - */ - -struct my_error_mgr { - struct jpeg_error_mgr pub; /* "public" fields */ - - jmp_buf setjmp_buffer; /* for return to caller */ -}; - -typedef struct my_error_mgr *my_error_ptr; - -/* - * Here's the routine that will replace the standard error_exit method: - */ - -METHODDEF(void) -my_error_exit(j_common_ptr cinfo) -{ - /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ - my_error_ptr myerr = (my_error_ptr)cinfo->err; - - /* Always display the message. */ - /* We could postpone this until after returning, if we chose. */ - (*cinfo->err->output_message) (cinfo); - - /* Return control to the setjmp point */ - longjmp(myerr->setjmp_buffer, 1); -} - - -METHODDEF(int) do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, - char *infilename, char *outfilename); - -/* - * Sample routine for JPEG decompression. We assume that the source file name - * is passed in. We want to return 1 on success, 0 on error. - */ - -METHODDEF(int) -read_JPEG_file(char *infilename, char *outfilename) -{ - /* This struct contains the JPEG decompression parameters and pointers to - * working space (which is allocated as needed by the JPEG library). - */ - struct jpeg_decompress_struct cinfo; - - return do_read_JPEG_file(&cinfo, infilename, outfilename); -} - -/* - * We call the libjpeg API from within a separate function, because modifying - * the local non-volatile jpeg_decompress_struct instance below the setjmp() - * return point and then accessing the instance after setjmp() returns would - * result in undefined behavior that may potentially overwrite all or part of - * the structure. - */ - -METHODDEF(int) -do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *infilename, - char *outfilename) -{ - /* We use our private extension JPEG error handler. - * Note that this struct must live as long as the main JPEG parameter - * struct, to avoid dangling-pointer problems. - */ - struct my_error_mgr jerr; - /* More stuff */ - FILE *infile; /* source file */ - FILE *outfile; /* output file */ - JSAMPARRAY buffer = NULL; /* Output row buffer */ - J12SAMPARRAY buffer12 = NULL; /* 12-bit output row buffer */ - int col; - int row_stride; /* physical row width in output buffer */ - int little_endian = 1; - - /* In this example we want to open the input and output files before doing - * anything else, so that the setjmp() error recovery below can assume the - * files are open. - * - * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that - * requires it in order to read/write binary files. - */ - - if ((infile = fopen(infilename, "rb")) == NULL) { - fprintf(stderr, "can't open %s\n", infilename); - return 0; - } - if ((outfile = fopen(outfilename, "wb")) == NULL) { - fprintf(stderr, "can't open %s\n", outfilename); - fclose(infile); - return 0; - } - - /* Step 1: allocate and initialize JPEG decompression object */ - - /* We set up the normal JPEG error routines, then override error_exit. */ - cinfo->err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = my_error_exit; - /* Establish the setjmp return context for my_error_exit to use. */ - if (setjmp(jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. - * We need to clean up the JPEG object, close the input file, and return. - */ - jpeg_destroy_decompress(cinfo); - fclose(infile); - fclose(outfile); - return 0; - } - /* Now we can initialize the JPEG decompression object. */ - jpeg_create_decompress(cinfo); - - /* Step 2: specify data source (eg, a file) */ - - jpeg_stdio_src(cinfo, infile); - - /* Step 3: read file parameters with jpeg_read_header() */ - - (void)jpeg_read_header(cinfo, TRUE); - /* We can ignore the return value from jpeg_read_header since - * (a) suspension is not possible with the stdio data source, and - * (b) we passed TRUE to reject a tables-only JPEG file as an error. - * See libjpeg.txt for more info. - */ - - /* emit header for raw PPM format */ - fprintf(outfile, "P6\n%d %d\n%d\n", WIDTH, HEIGHT, - cinfo->data_precision == 12 ? MAXJ12SAMPLE : MAXJSAMPLE); - - /* Step 4: set parameters for decompression */ - - /* In this example, we don't need to change any of the defaults set by - * jpeg_read_header(), so we do nothing here. - */ - - /* Step 5: Start decompressor */ - - (void)jpeg_start_decompress(cinfo); - /* We can ignore the return value since suspension is not possible - * with the stdio data source. - */ - - /* We may need to do some setup of our own at this point before reading - * the data. After jpeg_start_decompress() we have the correct scaled - * output image dimensions available, as well as the output colormap - * if we asked for color quantization. - * In this example, we need to make an output work buffer of the right size. - */ - /* Samples per row in output buffer */ - row_stride = cinfo->output_width * cinfo->output_components; - /* Make a one-row-high sample array that will go away when done with image */ - if (cinfo->data_precision == 12) - buffer12 = (J12SAMPARRAY)(*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1); - else - buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, row_stride, 1); - - /* Step 6: while (scan lines remain to be read) */ - /* jpeg_read_scanlines(...); */ - - /* Here we use the library's state variable cinfo->output_scanline as the - * loop counter, so that we don't have to keep track ourselves. - */ - if (cinfo->data_precision == 12) { - while (cinfo->output_scanline < cinfo->output_height) { - /* jpeg12_read_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could ask for - * more than one scanline at a time if that's more convenient. - */ - (void)jpeg12_read_scanlines(cinfo, buffer12, 1); - if (*(char *)&little_endian == 1) { - /* Swap MSB and LSB in each sample */ - for (col = 0; col < row_stride; col++) - buffer12[0][col] = ((buffer12[0][col] & 0xFF) << 8) | - ((buffer12[0][col] >> 8) & 0xFF); - } - fwrite(buffer12[0], 1, row_stride * sizeof(J12SAMPLE), outfile); - } - } else { - while (cinfo->output_scanline < cinfo->output_height) { - /* jpeg_read_scanlines expects an array of pointers to scanlines. - * Here the array is only one element long, but you could ask for - * more than one scanline at a time if that's more convenient. - */ - (void)jpeg_read_scanlines(cinfo, buffer, 1); - fwrite(buffer[0], 1, row_stride, outfile); - } - } - - /* Step 7: Finish decompression */ - - (void)jpeg_finish_decompress(cinfo); - /* We can ignore the return value since suspension is not possible - * with the stdio data source. - */ - - /* Step 8: Release JPEG decompression object */ - - /* This is an important step since it will release a good deal of memory. */ - jpeg_destroy_decompress(cinfo); - - /* After finish_decompress, we can close the input and output files. - * Here we postpone it until after no more JPEG errors are possible, - * so as to simplify the setjmp error logic above. (Actually, I don't - * think that jpeg_destroy can do an error exit, but why assume anything...) - */ - fclose(infile); - fclose(outfile); - - /* At this point you may want to check to see whether any corrupt-data - * warnings occurred (test whether jerr.pub.num_warnings is nonzero). - */ - - /* And we're done! */ - return 1; -} - - -/* - * SOME FINE POINTS: - * - * In the above code, we ignored the return value of jpeg_read_scanlines, - * which is the number of scanlines actually read. We could get away with - * this because we asked for only one line at a time and we weren't using - * a suspending data source. See libjpeg.txt for more info. - * - * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress(); - * we should have done it beforehand to ensure that the space would be - * counted against the JPEG max_memory setting. In some systems the above - * code would risk an out-of-memory error. However, in general we don't - * know the output image dimensions before jpeg_start_decompress(), unless we - * call jpeg_calc_output_dimensions(). See libjpeg.txt for more about this. - * - * Scanlines are returned in the same order as they appear in the JPEG file, - * which is standardly top-to-bottom. If you must emit data bottom-to-top, - * you can use one of the virtual arrays provided by the JPEG memory manager - * to invert the data. See wrbmp.c for an example. - */ - - -LOCAL(void) -usage(const char *progname) -{ - fprintf(stderr, "usage: %s compress [switches] outputfile[.jpg]\n", - progname); - fprintf(stderr, " %s decompress inputfile[.jpg] outputfile[.ppm]\n", - progname); - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -precision N Create JPEG file with N-bit data precision\n"); - fprintf(stderr, " (N is 8 or 12; default is 8)\n"); - fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is most useful range,\n"); - fprintf(stderr, " default is 75)\n"); - - exit(EXIT_FAILURE); -} - - -typedef enum { - COMPRESS, - DECOMPRESS -} EXAMPLE_MODE; - - -int -main(int argc, char **argv) -{ - int argn, quality = 75; - int data_precision = 8; - EXAMPLE_MODE mode = -1; - char *arg, *filename = NULL; - - if (argc < 3) - usage(argv[0]); - - if (!strcasecmp(argv[1], "compress")) - mode = COMPRESS; - else if (!strcasecmp(argv[1], "decompress")) - mode = DECOMPRESS; - else - usage(argv[0]); - - for (argn = 2; argn < argc; argn++) { - arg = argv[argn]; - if (*arg != '-') { - filename = arg; - /* Not a switch, must be a file name argument */ - break; /* done parsing switches */ - } - arg++; /* advance past switch marker character */ - - if (!strncasecmp(arg, "p", 1)) { - /* Set data precision. */ - if (++argn >= argc) /* advance to next argument */ - usage(argv[0]); - if (sscanf(argv[argn], "%d", &data_precision) < 1 || - (data_precision != 8 && data_precision != 12)) - usage(argv[0]); - } else if (!strncasecmp(arg, "q", 1)) { - /* Quality rating (quantization table scaling factor). */ - if (++argn >= argc) /* advance to next argument */ - usage(argv[0]); - if (sscanf(argv[argn], "%d", &quality) < 1 || quality < 0 || - quality > 100) - usage(argv[0]); - if (quality < 1) - quality = 1; - } - } - - if (!filename) - usage(argv[0]); - - if (mode == COMPRESS) - write_JPEG_file(filename, quality, data_precision); - else if (mode == DECOMPRESS) { - if (argc - argn < 2) - usage(argv[0]); - - read_JPEG_file(argv[argn], argv[argn + 1]); - } - - return 0; -} diff --git a/3rdparty/libjpeg-turbo/src/jcapimin.c b/3rdparty/libjpeg-turbo/src/jcapimin.c index cbb3d13e1c..eb4599fbfa 100644 --- a/3rdparty/libjpeg-turbo/src/jcapimin.c +++ b/3rdparty/libjpeg-turbo/src/jcapimin.c @@ -5,7 +5,7 @@ * Copyright (C) 1994-1998, Thomas G. Lane. * Modified 2003-2010 by Guido Vollbeding. * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. + * Copyright (C) 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -194,19 +194,19 @@ jpeg_finish_compress(j_compress_ptr cinfo) /* We bypass the main controller and invoke coef controller directly; * all work is being done from the coefficient buffer. */ - if (cinfo->data_precision == 16) { + if (cinfo->data_precision <= 8) { + if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + } else if (cinfo->data_precision <= 12) { + if (!(*cinfo->coef->compress_data_12) (cinfo, (J12SAMPIMAGE)NULL)) + ERREXIT(cinfo, JERR_CANT_SUSPEND); + } else { #ifdef C_LOSSLESS_SUPPORTED if (!(*cinfo->coef->compress_data_16) (cinfo, (J16SAMPIMAGE)NULL)) ERREXIT(cinfo, JERR_CANT_SUSPEND); #else ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif - } else if (cinfo->data_precision == 12) { - if (!(*cinfo->coef->compress_data_12) (cinfo, (J12SAMPIMAGE)NULL)) - ERREXIT(cinfo, JERR_CANT_SUSPEND); - } else { - if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL)) - ERREXIT(cinfo, JERR_CANT_SUSPEND); } } (*cinfo->master->finish_pass) (cinfo); diff --git a/3rdparty/libjpeg-turbo/src/jcapistd.c b/3rdparty/libjpeg-turbo/src/jcapistd.c index 2053028f2b..2226094ba6 100644 --- a/3rdparty/libjpeg-turbo/src/jcapistd.c +++ b/3rdparty/libjpeg-turbo/src/jcapistd.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1996, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. + * Copyright (C) 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -88,8 +88,21 @@ _jpeg_write_scanlines(j_compress_ptr cinfo, _JSAMPARRAY scanlines, #if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) JDIMENSION row_ctr, rows_left; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef C_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } if (cinfo->global_state != CSTATE_SCANNING) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); diff --git a/3rdparty/libjpeg-turbo/src/jccolor.c b/3rdparty/libjpeg-turbo/src/jccolor.c index cd3a6a7a56..c19f6ff4e3 100644 --- a/3rdparty/libjpeg-turbo/src/jccolor.c +++ b/3rdparty/libjpeg-turbo/src/jccolor.c @@ -5,7 +5,7 @@ * Copyright (C) 1991-1996, Thomas G. Lane. * libjpeg-turbo Modifications: * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2009-2012, 2015, 2022, D. R. Commander. + * Copyright (C) 2009-2012, 2015, 2022, 2024, D. R. Commander. * Copyright (C) 2014, MIPS Technologies, Inc., California. * For conditions of distribution and use, see the accompanying README.ijg * file. @@ -552,8 +552,21 @@ _jinit_color_converter(j_compress_ptr cinfo) { my_cconvert_ptr cconvert; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef C_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } cconvert = (my_cconvert_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, @@ -607,9 +620,11 @@ _jinit_color_converter(j_compress_ptr cinfo) */ switch (cinfo->jpeg_color_space) { case JCS_GRAYSCALE: +#ifdef C_LOSSLESS_SUPPORTED if (cinfo->master->lossless && cinfo->in_color_space != cinfo->jpeg_color_space) ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); +#endif if (cinfo->num_components != 1) ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); if (cinfo->in_color_space == JCS_GRAYSCALE) @@ -631,8 +646,10 @@ _jinit_color_converter(j_compress_ptr cinfo) break; case JCS_RGB: +#ifdef C_LOSSLESS_SUPPORTED if (cinfo->master->lossless && !IsExtRGB(cinfo->in_color_space)) ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); +#endif if (cinfo->num_components != 3) ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); if (rgb_red[cinfo->in_color_space] == 0 && @@ -652,9 +669,11 @@ _jinit_color_converter(j_compress_ptr cinfo) break; case JCS_YCbCr: +#ifdef C_LOSSLESS_SUPPORTED if (cinfo->master->lossless && cinfo->in_color_space != cinfo->jpeg_color_space) ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); +#endif if (cinfo->num_components != 3) ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); if (IsExtRGB(cinfo->in_color_space)) { @@ -679,9 +698,11 @@ _jinit_color_converter(j_compress_ptr cinfo) break; case JCS_CMYK: +#ifdef C_LOSSLESS_SUPPORTED if (cinfo->master->lossless && cinfo->in_color_space != cinfo->jpeg_color_space) ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); +#endif if (cinfo->num_components != 4) ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); if (cinfo->in_color_space == JCS_CMYK) { @@ -696,9 +717,11 @@ _jinit_color_converter(j_compress_ptr cinfo) break; case JCS_YCCK: +#ifdef C_LOSSLESS_SUPPORTED if (cinfo->master->lossless && cinfo->in_color_space != cinfo->jpeg_color_space) ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); +#endif if (cinfo->num_components != 4) ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); if (cinfo->in_color_space == JCS_CMYK) { diff --git a/3rdparty/libjpeg-turbo/src/jcdctmgr.c b/3rdparty/libjpeg-turbo/src/jcdctmgr.c index 7191ee7316..dbdbad6a28 100644 --- a/3rdparty/libjpeg-turbo/src/jcdctmgr.c +++ b/3rdparty/libjpeg-turbo/src/jcdctmgr.c @@ -6,7 +6,7 @@ * libjpeg-turbo Modifications: * Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2011, 2014-2015, 2022, D. R. Commander. + * Copyright (C) 2011, 2014-2015, 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -114,8 +114,8 @@ flss(UINT16 val) * Compute values to do a division using reciprocal. * * This implementation is based on an algorithm described in - * "How to optimize for the Pentium family of microprocessors" - * (http://www.agner.org/assem/). + * "Optimizing subroutines in assembly language: + * An optimization guide for x86 platforms" (https://agner.org/optimize). * More information about the basic algorithm can be found in * the paper "Integer Division Using Reciprocals" by Robert Alverson. * diff --git a/3rdparty/libjpeg-turbo/src/jcdiffct.c b/3rdparty/libjpeg-turbo/src/jcdiffct.c index 0bae068919..d378202b51 100644 --- a/3rdparty/libjpeg-turbo/src/jcdiffct.c +++ b/3rdparty/libjpeg-turbo/src/jcdiffct.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. + * Copyright (C) 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -346,6 +346,14 @@ _jinit_c_diff_controller(j_compress_ptr cinfo, boolean need_full_buffer) int ci, row; jpeg_component_info *compptr; +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + diff = (my_diff_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, sizeof(my_diff_controller)); diff --git a/3rdparty/libjpeg-turbo/src/jchuff.c b/3rdparty/libjpeg-turbo/src/jchuff.c index 488c9b5c3a..8cdd5bd35d 100644 --- a/3rdparty/libjpeg-turbo/src/jchuff.c +++ b/3rdparty/libjpeg-turbo/src/jchuff.c @@ -542,6 +542,10 @@ encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val, JOCTET _buffer[BUFSIZE], *buffer; int localbuf = 0; +#ifdef ZERO_BUFFERS + memset(_buffer, 0, sizeof(_buffer)); +#endif + LOAD_BUFFER() buffer = jsimd_huff_encode_one_block(state, buffer, block, last_dc_val, diff --git a/3rdparty/libjpeg-turbo/src/jcinit.c b/3rdparty/libjpeg-turbo/src/jcinit.c index fe8a13a8d9..09ff6b3e43 100644 --- a/3rdparty/libjpeg-turbo/src/jcinit.c +++ b/3rdparty/libjpeg-turbo/src/jcinit.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2020, 2022, D. R. Commander. + * Copyright (C) 2020, 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -40,7 +40,16 @@ jinit_compress_master(j_compress_ptr cinfo) /* Preprocessing */ if (!cinfo->raw_data_in) { - if (cinfo->data_precision == 16) { + if (cinfo->data_precision <= 8) { + jinit_color_converter(cinfo); + jinit_downsampler(cinfo); + jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */); + } else if (cinfo->data_precision <= 12) { + j12init_color_converter(cinfo); + j12init_downsampler(cinfo); + j12init_c_prep_controller(cinfo, + FALSE /* never need full buffer here */); + } else { #ifdef C_LOSSLESS_SUPPORTED j16init_color_converter(cinfo); j16init_downsampler(cinfo); @@ -49,27 +58,18 @@ jinit_compress_master(j_compress_ptr cinfo) #else ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif - } else if (cinfo->data_precision == 12) { - j12init_color_converter(cinfo); - j12init_downsampler(cinfo); - j12init_c_prep_controller(cinfo, - FALSE /* never need full buffer here */); - } else { - jinit_color_converter(cinfo); - jinit_downsampler(cinfo); - jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */); } } if (cinfo->master->lossless) { #ifdef C_LOSSLESS_SUPPORTED /* Prediction, sample differencing, and point transform */ - if (cinfo->data_precision == 16) - j16init_lossless_compressor(cinfo); - else if (cinfo->data_precision == 12) + if (cinfo->data_precision <= 8) + jinit_lossless_compressor(cinfo); + else if (cinfo->data_precision <= 12) j12init_lossless_compressor(cinfo); else - jinit_lossless_compressor(cinfo); + j16init_lossless_compressor(cinfo); /* Entropy encoding: either Huffman or arithmetic coding. */ if (cinfo->arith_code) { ERREXIT(cinfo, JERR_ARITH_NOTIMPL); @@ -78,26 +78,26 @@ jinit_compress_master(j_compress_ptr cinfo) } /* Need a full-image difference buffer in any multi-pass mode. */ - if (cinfo->data_precision == 16) - j16init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 || - cinfo->optimize_coding)); - else if (cinfo->data_precision == 12) + if (cinfo->data_precision <= 8) + jinit_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 || + cinfo->optimize_coding)); + else if (cinfo->data_precision <= 12) j12init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 || cinfo->optimize_coding)); else - jinit_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 || - cinfo->optimize_coding)); + j16init_c_diff_controller(cinfo, (boolean)(cinfo->num_scans > 1 || + cinfo->optimize_coding)); #else ERREXIT(cinfo, JERR_NOT_COMPILED); #endif } else { - if (cinfo->data_precision == 16) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); /* Forward DCT */ - if (cinfo->data_precision == 12) + if (cinfo->data_precision == 8) + jinit_forward_dct(cinfo); + else if (cinfo->data_precision == 12) j12init_forward_dct(cinfo); else - jinit_forward_dct(cinfo); + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); /* Entropy encoding: either Huffman or arithmetic coding. */ if (cinfo->arith_code) { #ifdef C_ARITH_CODING_SUPPORTED @@ -125,16 +125,16 @@ jinit_compress_master(j_compress_ptr cinfo) cinfo->optimize_coding)); } - if (cinfo->data_precision == 16) + if (cinfo->data_precision <= 8) + jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); + else if (cinfo->data_precision <= 12) + j12init_c_main_controller(cinfo, FALSE /* never need full buffer here */); + else #ifdef C_LOSSLESS_SUPPORTED j16init_c_main_controller(cinfo, FALSE /* never need full buffer here */); #else ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif - else if (cinfo->data_precision == 12) - j12init_c_main_controller(cinfo, FALSE /* never need full buffer here */); - else - jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); jinit_marker_writer(cinfo); diff --git a/3rdparty/libjpeg-turbo/src/jclossls.c b/3rdparty/libjpeg-turbo/src/jclossls.c index e9ba92a7df..295c3e2a2b 100644 --- a/3rdparty/libjpeg-turbo/src/jclossls.c +++ b/3rdparty/libjpeg-turbo/src/jclossls.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. + * Copyright (C) 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -308,6 +308,14 @@ _jinit_lossless_compressor(j_compress_ptr cinfo) { lossless_comp_ptr losslessc; +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + /* Create subobject in permanent pool */ losslessc = (lossless_comp_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT, diff --git a/3rdparty/libjpeg-turbo/src/jcmainct.c b/3rdparty/libjpeg-turbo/src/jcmainct.c index fe8fc0b1ac..954e94017c 100644 --- a/3rdparty/libjpeg-turbo/src/jcmainct.c +++ b/3rdparty/libjpeg-turbo/src/jcmainct.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. + * Copyright (C) 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -140,8 +140,21 @@ _jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer) jpeg_component_info *compptr; int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef C_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } main_ptr = (my_main_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, diff --git a/3rdparty/libjpeg-turbo/src/jcmaster.c b/3rdparty/libjpeg-turbo/src/jcmaster.c index 161019763d..1dcd252b3c 100644 --- a/3rdparty/libjpeg-turbo/src/jcmaster.c +++ b/3rdparty/libjpeg-turbo/src/jcmaster.c @@ -190,13 +190,19 @@ initial_setup(j_compress_ptr cinfo, boolean transcode_only) if ((long)jd_samplesperrow != samplesperrow) ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); + /* Lossy JPEG images must have 8 or 12 bits per sample. Lossless JPEG images + * can have 2 to 16 bits per sample. + */ #ifdef C_LOSSLESS_SUPPORTED - if (cinfo->data_precision != 8 && cinfo->data_precision != 12 && - cinfo->data_precision != 16) -#else - if (cinfo->data_precision != 8 && cinfo->data_precision != 12) + if (cinfo->master->lossless) { + if (cinfo->data_precision < 2 || cinfo->data_precision > 16) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else #endif - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + { + if (cinfo->data_precision != 8 && cinfo->data_precision != 12) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } /* Check that number of components won't exceed internal array sizes */ if (cinfo->num_components > MAX_COMPONENTS) @@ -731,6 +737,7 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only) cinfo->num_scans = 1; } +#ifdef C_LOSSLESS_SUPPORTED /* Disable smoothing and subsampling in lossless mode, since those are lossy * algorithms. Set the JPEG colorspace to the input colorspace. Disable raw * (downsampled) data input, because it isn't particularly useful without @@ -747,26 +754,30 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only) ci++, compptr++) compptr->h_samp_factor = compptr->v_samp_factor = 1; } +#endif /* Validate parameters, determine derived values */ initial_setup(cinfo, transcode_only); - if (cinfo->master->lossless || /* TEMPORARY HACK ??? */ - (cinfo->progressive_mode && !cinfo->arith_code)) - cinfo->optimize_coding = TRUE; /* assume default tables no good for - progressive mode or lossless mode */ - for (i = 0; i < NUM_HUFF_TBLS; i++) { - if (cinfo->dc_huff_tbl_ptrs[i] != NULL || - cinfo->ac_huff_tbl_ptrs[i] != NULL) { - empty_huff_tables = FALSE; - break; + if (cinfo->arith_code) + cinfo->optimize_coding = FALSE; + else { + if (cinfo->master->lossless || /* TEMPORARY HACK ??? */ + cinfo->progressive_mode) + cinfo->optimize_coding = TRUE; /* assume default tables no good for + progressive mode or lossless mode */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + if (cinfo->dc_huff_tbl_ptrs[i] != NULL || + cinfo->ac_huff_tbl_ptrs[i] != NULL) { + empty_huff_tables = FALSE; + break; + } } + if (cinfo->data_precision == 12 && !cinfo->optimize_coding && + (empty_huff_tables || using_std_huff_tables(cinfo))) + cinfo->optimize_coding = TRUE; /* assume default tables no good for + 12-bit data precision */ } - if (cinfo->data_precision == 12 && !cinfo->arith_code && - !cinfo->optimize_coding && - (empty_huff_tables || using_std_huff_tables(cinfo))) - cinfo->optimize_coding = TRUE; /* assume default tables no good for 12-bit - data precision */ /* Initialize my private state */ if (transcode_only) { diff --git a/3rdparty/libjpeg-turbo/src/jcomapi.c b/3rdparty/libjpeg-turbo/src/jcomapi.c index efbb8357b0..84f37e172e 100644 --- a/3rdparty/libjpeg-turbo/src/jcomapi.c +++ b/3rdparty/libjpeg-turbo/src/jcomapi.c @@ -3,8 +3,8 @@ * * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1997, Thomas G. Lane. - * It was modified by The libjpeg-turbo Project to include only code relevant - * to libjpeg-turbo. + * libjpeg-turbo Modifications: + * Copyright (C) 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -51,6 +51,7 @@ jpeg_abort(j_common_ptr cinfo) * A bit kludgy to do it here, but this is the most central place. */ ((j_decompress_ptr)cinfo)->marker_list = NULL; + ((j_decompress_ptr)cinfo)->master->marker_list_end = NULL; } else { cinfo->global_state = CSTATE_START; } diff --git a/3rdparty/libjpeg-turbo/src/jcparam.c b/3rdparty/libjpeg-turbo/src/jcparam.c index d1dee4da3d..d74623c207 100644 --- a/3rdparty/libjpeg-turbo/src/jcparam.c +++ b/3rdparty/libjpeg-turbo/src/jcparam.c @@ -7,7 +7,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2009-2011, 2018, 2023, D. R. Commander. + * Copyright (C) 2009-2011, 2018, 2023-2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -220,6 +220,9 @@ jpeg_set_defaults(j_compress_ptr cinfo) cinfo->scan_info = NULL; cinfo->num_scans = 0; + /* Default is lossy output */ + cinfo->master->lossless = FALSE; + /* Expect normal source image, not raw downsampled data */ cinfo->raw_data_in = FALSE; @@ -233,7 +236,7 @@ jpeg_set_defaults(j_compress_ptr cinfo) * tables will be computed. This test can be removed if default tables * are supplied that are valid for the desired precision. */ - if (cinfo->data_precision == 12 && !cinfo->arith_code) + if (cinfo->data_precision == 12) cinfo->optimize_coding = TRUE; /* By default, use the simpler non-cosited sampling alignment */ @@ -297,9 +300,11 @@ jpeg_default_colorspace(j_compress_ptr cinfo) case JCS_EXT_BGRA: case JCS_EXT_ABGR: case JCS_EXT_ARGB: +#ifdef C_LOSSLESS_SUPPORTED if (cinfo->master->lossless) jpeg_set_colorspace(cinfo, JCS_RGB); else +#endif jpeg_set_colorspace(cinfo, JCS_YCbCr); break; case JCS_YCbCr: @@ -479,10 +484,12 @@ jpeg_simple_progression(j_compress_ptr cinfo) if (cinfo->global_state != CSTATE_START) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); +#ifdef C_LOSSLESS_SUPPORTED if (cinfo->master->lossless) { cinfo->master->lossless = FALSE; jpeg_default_colorspace(cinfo); } +#endif /* Figure space needed for script. Calculation must match code below! */ if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { diff --git a/3rdparty/libjpeg-turbo/src/jcphuff.c b/3rdparty/libjpeg-turbo/src/jcphuff.c index 484e2d857f..58287328d2 100644 --- a/3rdparty/libjpeg-turbo/src/jcphuff.c +++ b/3rdparty/libjpeg-turbo/src/jcphuff.c @@ -650,6 +650,11 @@ encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data) size_t bits[8 / SIZEOF_SIZE_T]; int max_coef_bits = cinfo->data_precision + 2; +#ifdef ZERO_BUFFERS + memset(values_unaligned, 0, sizeof(values_unaligned)); + memset(bits, 0, sizeof(bits)); +#endif + entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->free_in_buffer = cinfo->dest->free_in_buffer; @@ -915,6 +920,11 @@ encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data) size_t zerobits, signbits; size_t bits[16 / SIZEOF_SIZE_T]; +#ifdef ZERO_BUFFERS + memset(absvalues_unaligned, 0, sizeof(absvalues_unaligned)); + memset(bits, 0, sizeof(bits)); +#endif + entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->free_in_buffer = cinfo->dest->free_in_buffer; diff --git a/3rdparty/libjpeg-turbo/src/jcprepct.c b/3rdparty/libjpeg-turbo/src/jcprepct.c index ac2311c138..725856d738 100644 --- a/3rdparty/libjpeg-turbo/src/jcprepct.c +++ b/3rdparty/libjpeg-turbo/src/jcprepct.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. + * Copyright (C) 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -324,8 +324,21 @@ _jinit_c_prep_controller(j_compress_ptr cinfo, boolean need_full_buffer) jpeg_component_info *compptr; int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef C_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } if (need_full_buffer) /* safety check */ ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); diff --git a/3rdparty/libjpeg-turbo/src/jcsample.c b/3rdparty/libjpeg-turbo/src/jcsample.c index 30e6e54b40..ca3bea131f 100644 --- a/3rdparty/libjpeg-turbo/src/jcsample.c +++ b/3rdparty/libjpeg-turbo/src/jcsample.c @@ -8,7 +8,7 @@ * libjpeg-turbo Modifications: * Copyright 2009 Pierre Ossman for Cendio AB * Copyright (C) 2014, MIPS Technologies, Inc., California. - * Copyright (C) 2015, 2019, 2022, D. R. Commander. + * Copyright (C) 2015, 2019, 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -470,8 +470,21 @@ _jinit_downsampler(j_compress_ptr cinfo) jpeg_component_info *compptr; boolean smoothok = TRUE; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef C_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } downsample = (my_downsample_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, diff --git a/3rdparty/libjpeg-turbo/src/jdapimin.c b/3rdparty/libjpeg-turbo/src/jdapimin.c index 30d92841a8..f2419f8adb 100644 --- a/3rdparty/libjpeg-turbo/src/jdapimin.c +++ b/3rdparty/libjpeg-turbo/src/jdapimin.c @@ -161,17 +161,21 @@ default_decompress_parms(j_decompress_ptr cinfo) int cid2 = cinfo->comp_info[2].component_id; if (cid0 == 1 && cid1 == 2 && cid2 == 3) { +#ifdef D_LOSSLESS_SUPPORTED if (cinfo->master->lossless) cinfo->jpeg_color_space = JCS_RGB; /* assume RGB w/out marker */ else +#endif cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ } else if (cid0 == 82 && cid1 == 71 && cid2 == 66) cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ else { TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); +#ifdef D_LOSSLESS_SUPPORTED if (cinfo->master->lossless) cinfo->jpeg_color_space = JCS_RGB; /* assume it's RGB */ else +#endif cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ } } diff --git a/3rdparty/libjpeg-turbo/src/jdapistd.c b/3rdparty/libjpeg-turbo/src/jdapistd.c index 1f44927236..d0e5c0e5b9 100644 --- a/3rdparty/libjpeg-turbo/src/jdapistd.c +++ b/3rdparty/libjpeg-turbo/src/jdapistd.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1996, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2015-2020, 2022-2023, D. R. Commander. + * Copyright (C) 2010, 2015-2020, 2022-2024, D. R. Commander. * Copyright (C) 2015, Google, Inc. * For conditions of distribution and use, see the accompanying README.ijg * file. @@ -128,20 +128,19 @@ output_pass_setup(j_decompress_ptr cinfo) } /* Process some data */ last_scanline = cinfo->output_scanline; -#ifdef D_LOSSLESS_SUPPORTED - if (cinfo->data_precision == 16) - (*cinfo->main->process_data_16) (cinfo, (J16SAMPARRAY)NULL, - &cinfo->output_scanline, - (JDIMENSION)0); - else -#endif - if (cinfo->data_precision == 12) + if (cinfo->data_precision <= 8) + (*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL, + &cinfo->output_scanline, (JDIMENSION)0); + else if (cinfo->data_precision <= 12) (*cinfo->main->process_data_12) (cinfo, (J12SAMPARRAY)NULL, &cinfo->output_scanline, (JDIMENSION)0); +#ifdef D_LOSSLESS_SUPPORTED else - (*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL, - &cinfo->output_scanline, (JDIMENSION)0); + (*cinfo->main->process_data_16) (cinfo, (J16SAMPARRAY)NULL, + &cinfo->output_scanline, + (JDIMENSION)0); +#endif if (cinfo->output_scanline == last_scanline) return FALSE; /* No progress made, must suspend */ } @@ -200,7 +199,8 @@ _jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset, ERREXIT(cinfo, JERR_BAD_CROP_SPEC); /* xoffset and width must fall within the output image dimensions. */ - if (*width == 0 || *xoffset + *width > cinfo->output_width) + if (*width == 0 || + (unsigned long long)(*xoffset) + *width > cinfo->output_width) ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); /* No need to do anything if the caller wants the entire width. */ @@ -313,8 +313,21 @@ _jpeg_read_scanlines(j_decompress_ptr cinfo, _JSAMPARRAY scanlines, #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) JDIMENSION row_ctr; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef D_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } if (cinfo->global_state != DSTATE_SCANNING) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); @@ -482,7 +495,8 @@ _jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); /* Do not skip past the bottom of the image. */ - if (cinfo->output_scanline + num_lines >= cinfo->output_height) { + if ((unsigned long long)cinfo->output_scanline + num_lines >= + cinfo->output_height) { num_lines = cinfo->output_height - cinfo->output_scanline; cinfo->output_scanline = cinfo->output_height; (*cinfo->inputctl->finish_input_pass) (cinfo); diff --git a/3rdparty/libjpeg-turbo/src/jdatadst-tj.c b/3rdparty/libjpeg-turbo/src/jdatadst-tj.c index cce263af74..270b2c2c3e 100644 --- a/3rdparty/libjpeg-turbo/src/jdatadst-tj.c +++ b/3rdparty/libjpeg-turbo/src/jdatadst-tj.c @@ -19,6 +19,7 @@ */ /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ +#define JPEG_INTERNALS #include "jinclude.h" #include "jpeglib.h" #include "jerror.h" @@ -92,7 +93,7 @@ empty_mem_output_buffer(j_compress_ptr cinfo) /* Try to allocate new buffer with double size */ nextsize = dest->bufsize * 2; - nextbuffer = (JOCTET *)malloc(nextsize); + nextbuffer = (JOCTET *)MALLOC(nextsize); if (nextbuffer == NULL) ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); @@ -183,7 +184,7 @@ jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer, if (*outbuffer == NULL || *outsize == 0) { if (alloc) { /* Allocate initial buffer */ - dest->newbuffer = *outbuffer = (unsigned char *)malloc(OUTPUT_BUF_SIZE); + dest->newbuffer = *outbuffer = (unsigned char *)MALLOC(OUTPUT_BUF_SIZE); if (dest->newbuffer == NULL) ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); *outsize = OUTPUT_BUF_SIZE; diff --git a/3rdparty/libjpeg-turbo/src/jdcolor.c b/3rdparty/libjpeg-turbo/src/jdcolor.c index e5c7b58ebf..aecbd9dcd3 100644 --- a/3rdparty/libjpeg-turbo/src/jdcolor.c +++ b/3rdparty/libjpeg-turbo/src/jdcolor.c @@ -6,7 +6,7 @@ * Modified 2011 by Guido Vollbeding. * libjpeg-turbo Modifications: * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2009, 2011-2012, 2014-2015, 2022, D. R. Commander. + * Copyright (C) 2009, 2011-2012, 2014-2015, 2022, 2024, D. R. Commander. * Copyright (C) 2013, Linaro Limited. * For conditions of distribution and use, see the accompanying README.ijg * file. @@ -759,8 +759,21 @@ _jinit_color_deconverter(j_decompress_ptr cinfo) my_cconvert_ptr cconvert; int ci; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef D_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } cconvert = (my_cconvert_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, @@ -802,9 +815,11 @@ _jinit_color_deconverter(j_decompress_ptr cinfo) switch (cinfo->out_color_space) { case JCS_GRAYSCALE: +#ifdef D_LOSSLESS_SUPPORTED if (cinfo->master->lossless && cinfo->jpeg_color_space != cinfo->out_color_space) ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); +#endif cinfo->out_color_components = 1; if (cinfo->jpeg_color_space == JCS_GRAYSCALE || cinfo->jpeg_color_space == JCS_YCbCr) { @@ -830,8 +845,10 @@ _jinit_color_deconverter(j_decompress_ptr cinfo) case JCS_EXT_BGRA: case JCS_EXT_ABGR: case JCS_EXT_ARGB: +#ifdef D_LOSSLESS_SUPPORTED if (cinfo->master->lossless && cinfo->jpeg_color_space != JCS_RGB) ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); +#endif cinfo->out_color_components = rgb_pixelsize[cinfo->out_color_space]; if (cinfo->jpeg_color_space == JCS_YCbCr) { #ifdef WITH_SIMD @@ -858,8 +875,10 @@ _jinit_color_deconverter(j_decompress_ptr cinfo) break; case JCS_RGB565: +#ifdef D_LOSSLESS_SUPPORTED if (cinfo->master->lossless) ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); +#endif cinfo->out_color_components = 3; if (cinfo->dither_mode == JDITHER_NONE) { if (cinfo->jpeg_color_space == JCS_YCbCr) { @@ -893,9 +912,11 @@ _jinit_color_deconverter(j_decompress_ptr cinfo) break; case JCS_CMYK: +#ifdef D_LOSSLESS_SUPPORTED if (cinfo->master->lossless && cinfo->jpeg_color_space != cinfo->out_color_space) ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); +#endif cinfo->out_color_components = 4; if (cinfo->jpeg_color_space == JCS_YCCK) { cconvert->pub._color_convert = ycck_cmyk_convert; diff --git a/3rdparty/libjpeg-turbo/src/jddiffct.c b/3rdparty/libjpeg-turbo/src/jddiffct.c index f1d7f61b52..0a1ec5a9a8 100644 --- a/3rdparty/libjpeg-turbo/src/jddiffct.c +++ b/3rdparty/libjpeg-turbo/src/jddiffct.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. + * Copyright (C) 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -350,6 +350,14 @@ _jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer) int ci; jpeg_component_info *compptr; +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + diff = (my_diff_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, sizeof(my_diff_controller)); diff --git a/3rdparty/libjpeg-turbo/src/jdinput.c b/3rdparty/libjpeg-turbo/src/jdinput.c index 136bef59d7..33e3a820fd 100644 --- a/3rdparty/libjpeg-turbo/src/jdinput.c +++ b/3rdparty/libjpeg-turbo/src/jdinput.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2016, 2018, 2022, D. R. Commander. + * Copyright (C) 2010, 2016, 2018, 2022, 2024, D. R. Commander. * Copyright (C) 2015, Google, Inc. * For conditions of distribution and use, see the accompanying README.ijg * file. @@ -56,14 +56,19 @@ initial_setup(j_decompress_ptr cinfo) (long)cinfo->image_width > (long)JPEG_MAX_DIMENSION) ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int)JPEG_MAX_DIMENSION); - /* For now, precision must match compiled-in value... */ + /* Lossy JPEG images must have 8 or 12 bits per sample. Lossless JPEG images + * can have 2 to 16 bits per sample. + */ #ifdef D_LOSSLESS_SUPPORTED - if (cinfo->data_precision != 8 && cinfo->data_precision != 12 && - cinfo->data_precision != 16) -#else - if (cinfo->data_precision != 8 && cinfo->data_precision != 12) + if (cinfo->master->lossless) { + if (cinfo->data_precision < 2 || cinfo->data_precision > 16) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else #endif - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + { + if (cinfo->data_precision != 8 && cinfo->data_precision != 12) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } /* Check that number of components won't exceed internal array sizes */ if (cinfo->num_components > MAX_COMPONENTS) diff --git a/3rdparty/libjpeg-turbo/src/jdlossls.c b/3rdparty/libjpeg-turbo/src/jdlossls.c index 4d15e6bbaf..520755adc3 100644 --- a/3rdparty/libjpeg-turbo/src/jdlossls.c +++ b/3rdparty/libjpeg-turbo/src/jdlossls.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. + * Copyright (C) 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -278,6 +278,14 @@ _jinit_lossless_decompressor(j_decompress_ptr cinfo) { lossless_decomp_ptr losslessd; +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + /* Create subobject in permanent pool */ losslessd = (lossless_decomp_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT, diff --git a/3rdparty/libjpeg-turbo/src/jdmainct.c b/3rdparty/libjpeg-turbo/src/jdmainct.c index c672b4baf5..fed1866ee9 100644 --- a/3rdparty/libjpeg-turbo/src/jdmainct.c +++ b/3rdparty/libjpeg-turbo/src/jdmainct.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1996, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2016, 2022, D. R. Commander. + * Copyright (C) 2010, 2016, 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -431,8 +431,21 @@ _jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer) int ci, rgroup, ngroups; jpeg_component_info *compptr; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef D_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } main_ptr = (my_main_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, diff --git a/3rdparty/libjpeg-turbo/src/jdmarker.c b/3rdparty/libjpeg-turbo/src/jdmarker.c index acd28ce62c..f918ee4db5 100644 --- a/3rdparty/libjpeg-turbo/src/jdmarker.c +++ b/3rdparty/libjpeg-turbo/src/jdmarker.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2012, 2015, 2022, D. R. Commander. + * Copyright (C) 2012, 2015, 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -248,6 +248,9 @@ get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_lossless, jpeg_component_info *compptr; INPUT_VARS(cinfo); + if (cinfo->marker->saw_SOF) + ERREXIT(cinfo, JERR_SOF_DUPLICATE); + cinfo->progressive_mode = is_prog; cinfo->master->lossless = is_lossless; cinfo->arith_code = is_arith; @@ -265,9 +268,6 @@ get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_lossless, (int)cinfo->image_width, (int)cinfo->image_height, cinfo->num_components); - if (cinfo->marker->saw_SOF) - ERREXIT(cinfo, JERR_SOF_DUPLICATE); - /* We don't support files in which the image height is initially specified */ /* as 0 and is later redefined by DNL. As long as we have to check that, */ /* might as well have a general sanity check. */ @@ -819,13 +819,11 @@ save_marker(j_decompress_ptr cinfo) /* Done reading what we want to read */ if (cur_marker != NULL) { /* will be NULL if bogus length word */ /* Add new marker to end of list */ - if (cinfo->marker_list == NULL) { - cinfo->marker_list = cur_marker; + if (cinfo->marker_list == NULL || cinfo->master->marker_list_end == NULL) { + cinfo->marker_list = cinfo->master->marker_list_end = cur_marker; } else { - jpeg_saved_marker_ptr prev = cinfo->marker_list; - while (prev->next != NULL) - prev = prev->next; - prev->next = cur_marker; + cinfo->master->marker_list_end->next = cur_marker; + cinfo->master->marker_list_end = cur_marker; } /* Reset pointer & calc remaining data length */ data = cur_marker->data; diff --git a/3rdparty/libjpeg-turbo/src/jdmaster.c b/3rdparty/libjpeg-turbo/src/jdmaster.c index 80a4842ac1..4085c22918 100644 --- a/3rdparty/libjpeg-turbo/src/jdmaster.c +++ b/3rdparty/libjpeg-turbo/src/jdmaster.c @@ -7,7 +7,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2009-2011, 2016, 2019, 2022-2023, D. R. Commander. + * Copyright (C) 2009-2011, 2016, 2019, 2022-2024, D. R. Commander. * Copyright (C) 2013, Linaro Limited. * Copyright (C) 2015, Google, Inc. * For conditions of distribution and use, see the accompanying README.ijg @@ -422,7 +422,50 @@ prepare_range_limit_table(j_decompress_ptr cinfo) #endif int i; - if (cinfo->data_precision == 16) { + if (cinfo->data_precision <= 8) { + table = (JSAMPLE *) + (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, + (5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE)); + table += (MAXJSAMPLE + 1); /* allow negative subscripts of simple table */ + cinfo->sample_range_limit = table; + /* First segment of "simple" table: limit[x] = 0 for x < 0 */ + memset(table - (MAXJSAMPLE + 1), 0, (MAXJSAMPLE + 1) * sizeof(JSAMPLE)); + /* Main part of "simple" table: limit[x] = x */ + for (i = 0; i <= MAXJSAMPLE; i++) + table[i] = (JSAMPLE)i; + table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ + /* End of simple table, rest of first half of post-IDCT table */ + for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++) + table[i] = MAXJSAMPLE; + /* Second half of post-IDCT table */ + memset(table + (2 * (MAXJSAMPLE + 1)), 0, + (2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE)); + memcpy(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE), + cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE)); + } else if (cinfo->data_precision <= 12) { + table12 = (J12SAMPLE *) + (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, + (5 * (MAXJ12SAMPLE + 1) + CENTERJ12SAMPLE) * + sizeof(J12SAMPLE)); + table12 += (MAXJ12SAMPLE + 1); /* allow negative subscripts of simple + table */ + cinfo->sample_range_limit = (JSAMPLE *)table12; + /* First segment of "simple" table: limit[x] = 0 for x < 0 */ + memset(table12 - (MAXJ12SAMPLE + 1), 0, + (MAXJ12SAMPLE + 1) * sizeof(J12SAMPLE)); + /* Main part of "simple" table: limit[x] = x */ + for (i = 0; i <= MAXJ12SAMPLE; i++) + table12[i] = (J12SAMPLE)i; + table12 += CENTERJ12SAMPLE; /* Point to where post-IDCT table starts */ + /* End of simple table, rest of first half of post-IDCT table */ + for (i = CENTERJ12SAMPLE; i < 2 * (MAXJ12SAMPLE + 1); i++) + table12[i] = MAXJ12SAMPLE; + /* Second half of post-IDCT table */ + memset(table12 + (2 * (MAXJ12SAMPLE + 1)), 0, + (2 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE) * sizeof(J12SAMPLE)); + memcpy(table12 + (4 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE), + cinfo->sample_range_limit, CENTERJ12SAMPLE * sizeof(J12SAMPLE)); + } else { #ifdef D_LOSSLESS_SUPPORTED table16 = (J16SAMPLE *) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, @@ -449,49 +492,6 @@ prepare_range_limit_table(j_decompress_ptr cinfo) #else ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif - } else if (cinfo->data_precision == 12) { - table12 = (J12SAMPLE *) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - (5 * (MAXJ12SAMPLE + 1) + CENTERJ12SAMPLE) * - sizeof(J12SAMPLE)); - table12 += (MAXJ12SAMPLE + 1); /* allow negative subscripts of simple - table */ - cinfo->sample_range_limit = (JSAMPLE *)table12; - /* First segment of "simple" table: limit[x] = 0 for x < 0 */ - memset(table12 - (MAXJ12SAMPLE + 1), 0, - (MAXJ12SAMPLE + 1) * sizeof(J12SAMPLE)); - /* Main part of "simple" table: limit[x] = x */ - for (i = 0; i <= MAXJ12SAMPLE; i++) - table12[i] = (J12SAMPLE)i; - table12 += CENTERJ12SAMPLE; /* Point to where post-IDCT table starts */ - /* End of simple table, rest of first half of post-IDCT table */ - for (i = CENTERJ12SAMPLE; i < 2 * (MAXJ12SAMPLE + 1); i++) - table12[i] = MAXJ12SAMPLE; - /* Second half of post-IDCT table */ - memset(table12 + (2 * (MAXJ12SAMPLE + 1)), 0, - (2 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE) * sizeof(J12SAMPLE)); - memcpy(table12 + (4 * (MAXJ12SAMPLE + 1) - CENTERJ12SAMPLE), - cinfo->sample_range_limit, CENTERJ12SAMPLE * sizeof(J12SAMPLE)); - } else { - table = (JSAMPLE *) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - (5 * (MAXJSAMPLE + 1) + CENTERJSAMPLE) * sizeof(JSAMPLE)); - table += (MAXJSAMPLE + 1); /* allow negative subscripts of simple table */ - cinfo->sample_range_limit = table; - /* First segment of "simple" table: limit[x] = 0 for x < 0 */ - memset(table - (MAXJSAMPLE + 1), 0, (MAXJSAMPLE + 1) * sizeof(JSAMPLE)); - /* Main part of "simple" table: limit[x] = x */ - for (i = 0; i <= MAXJSAMPLE; i++) - table[i] = (JSAMPLE)i; - table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ - /* End of simple table, rest of first half of post-IDCT table */ - for (i = CENTERJSAMPLE; i < 2 * (MAXJSAMPLE + 1); i++) - table[i] = MAXJSAMPLE; - /* Second half of post-IDCT table */ - memset(table + (2 * (MAXJSAMPLE + 1)), 0, - (2 * (MAXJSAMPLE + 1) - CENTERJSAMPLE) * sizeof(JSAMPLE)); - memcpy(table + (4 * (MAXJSAMPLE + 1) - CENTERJSAMPLE), - cinfo->sample_range_limit, CENTERJSAMPLE * sizeof(JSAMPLE)); } } @@ -521,10 +521,12 @@ master_selection(j_decompress_ptr cinfo) * particularly useful without subsampling and has not been tested in * lossless mode. */ +#ifdef D_LOSSLESS_SUPPORTED if (cinfo->master->lossless) { cinfo->raw_data_out = FALSE; cinfo->scale_num = cinfo->scale_denom = 1; } +#endif /* Initialize dimensions and other stuff */ jpeg_calc_output_dimensions(cinfo); @@ -570,12 +572,12 @@ master_selection(j_decompress_ptr cinfo) if (cinfo->enable_1pass_quant) { #ifdef QUANT_1PASS_SUPPORTED - if (cinfo->data_precision == 16) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + if (cinfo->data_precision == 8) + jinit_1pass_quantizer(cinfo); else if (cinfo->data_precision == 12) j12init_1pass_quantizer(cinfo); else - jinit_1pass_quantizer(cinfo); + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); master->quantizer_1pass = cinfo->cquantize; #else ERREXIT(cinfo, JERR_NOT_COMPILED); @@ -585,12 +587,12 @@ master_selection(j_decompress_ptr cinfo) /* We use the 2-pass code to map to external colormaps. */ if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) { #ifdef QUANT_2PASS_SUPPORTED - if (cinfo->data_precision == 16) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + if (cinfo->data_precision == 8) + jinit_2pass_quantizer(cinfo); else if (cinfo->data_precision == 12) j12init_2pass_quantizer(cinfo); else - jinit_2pass_quantizer(cinfo); + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); master->quantizer_2pass = cinfo->cquantize; #else ERREXIT(cinfo, JERR_NOT_COMPILED); @@ -605,41 +607,41 @@ master_selection(j_decompress_ptr cinfo) if (!cinfo->raw_data_out) { if (master->using_merged_upsample) { #ifdef UPSAMPLE_MERGING_SUPPORTED - if (cinfo->data_precision == 16) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + if (cinfo->data_precision == 8) + jinit_merged_upsampler(cinfo); /* does color conversion too */ else if (cinfo->data_precision == 12) j12init_merged_upsampler(cinfo); /* does color conversion too */ else - jinit_merged_upsampler(cinfo); /* does color conversion too */ + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #else ERREXIT(cinfo, JERR_NOT_COMPILED); #endif } else { - if (cinfo->data_precision == 16) { + if (cinfo->data_precision <= 8) { + jinit_color_deconverter(cinfo); + jinit_upsampler(cinfo); + } else if (cinfo->data_precision <= 12) { + j12init_color_deconverter(cinfo); + j12init_upsampler(cinfo); + } else { #ifdef D_LOSSLESS_SUPPORTED j16init_color_deconverter(cinfo); j16init_upsampler(cinfo); #else ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif - } else if (cinfo->data_precision == 12) { - j12init_color_deconverter(cinfo); - j12init_upsampler(cinfo); - } else { - jinit_color_deconverter(cinfo); - jinit_upsampler(cinfo); } } - if (cinfo->data_precision == 16) + if (cinfo->data_precision <= 8) + jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant); + else if (cinfo->data_precision <= 12) + j12init_d_post_controller(cinfo, cinfo->enable_2pass_quant); + else #ifdef D_LOSSLESS_SUPPORTED j16init_d_post_controller(cinfo, cinfo->enable_2pass_quant); #else ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif - else if (cinfo->data_precision == 12) - j12init_d_post_controller(cinfo, cinfo->enable_2pass_quant); - else - jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant); } if (cinfo->master->lossless) { @@ -647,12 +649,12 @@ master_selection(j_decompress_ptr cinfo) /* Prediction, sample undifferencing, point transform, and sample size * scaling */ - if (cinfo->data_precision == 16) - j16init_lossless_decompressor(cinfo); - else if (cinfo->data_precision == 12) + if (cinfo->data_precision <= 8) + jinit_lossless_decompressor(cinfo); + else if (cinfo->data_precision <= 12) j12init_lossless_decompressor(cinfo); else - jinit_lossless_decompressor(cinfo); + j16init_lossless_decompressor(cinfo); /* Entropy decoding: either Huffman or arithmetic coding. */ if (cinfo->arith_code) { ERREXIT(cinfo, JERR_ARITH_NOTIMPL); @@ -663,23 +665,23 @@ master_selection(j_decompress_ptr cinfo) /* Initialize principal buffer controllers. */ use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image; - if (cinfo->data_precision == 16) - j16init_d_diff_controller(cinfo, use_c_buffer); - else if (cinfo->data_precision == 12) + if (cinfo->data_precision <= 8) + jinit_d_diff_controller(cinfo, use_c_buffer); + else if (cinfo->data_precision <= 12) j12init_d_diff_controller(cinfo, use_c_buffer); else - jinit_d_diff_controller(cinfo, use_c_buffer); + j16init_d_diff_controller(cinfo, use_c_buffer); #else ERREXIT(cinfo, JERR_NOT_COMPILED); #endif } else { - if (cinfo->data_precision == 16) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); /* Inverse DCT */ - if (cinfo->data_precision == 12) + if (cinfo->data_precision == 8) + jinit_inverse_dct(cinfo); + else if (cinfo->data_precision == 12) j12init_inverse_dct(cinfo); else - jinit_inverse_dct(cinfo); + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); /* Entropy decoding: either Huffman or arithmetic coding. */ if (cinfo->arith_code) { #ifdef D_ARITH_CODING_SUPPORTED @@ -708,18 +710,18 @@ master_selection(j_decompress_ptr cinfo) } if (!cinfo->raw_data_out) { - if (cinfo->data_precision == 16) + if (cinfo->data_precision <= 8) + jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */); + else if (cinfo->data_precision <= 12) + j12init_d_main_controller(cinfo, + FALSE /* never need full buffer here */); + else #ifdef D_LOSSLESS_SUPPORTED j16init_d_main_controller(cinfo, FALSE /* never need full buffer here */); #else ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); #endif - else if (cinfo->data_precision == 12) - j12init_d_main_controller(cinfo, - FALSE /* never need full buffer here */); - else - jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */); } /* We can now tell the memory manager to allocate virtual arrays. */ diff --git a/3rdparty/libjpeg-turbo/src/jdpostct.c b/3rdparty/libjpeg-turbo/src/jdpostct.c index d38495f5f3..9bc6210d17 100644 --- a/3rdparty/libjpeg-turbo/src/jdpostct.c +++ b/3rdparty/libjpeg-turbo/src/jdpostct.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1996, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2022-2023, D. R. Commander. + * Copyright (C) 2022-2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -267,8 +267,21 @@ _jinit_d_post_controller(j_decompress_ptr cinfo, boolean need_full_buffer) { my_post_ptr post; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef D_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } post = (my_post_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, diff --git a/3rdparty/libjpeg-turbo/src/jdsample.c b/3rdparty/libjpeg-turbo/src/jdsample.c index cc8015c97d..e5a127de42 100644 --- a/3rdparty/libjpeg-turbo/src/jdsample.c +++ b/3rdparty/libjpeg-turbo/src/jdsample.c @@ -5,7 +5,7 @@ * Copyright (C) 1991-1996, Thomas G. Lane. * libjpeg-turbo Modifications: * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2010, 2015-2016, 2022, D. R. Commander. + * Copyright (C) 2010, 2015-2016, 2022, 2024, D. R. Commander. * Copyright (C) 2014, MIPS Technologies, Inc., California. * Copyright (C) 2015, Google, Inc. * Copyright (C) 2019-2020, Arm Limited. @@ -421,8 +421,21 @@ _jinit_upsampler(j_decompress_ptr cinfo) boolean need_buffer, do_fancy; int h_in_group, v_in_group, h_out_group, v_out_group; - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); +#ifdef D_LOSSLESS_SUPPORTED + if (cinfo->master->lossless) { +#if BITS_IN_JSAMPLE == 8 + if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) +#else + if (cinfo->data_precision > BITS_IN_JSAMPLE || + cinfo->data_precision < BITS_IN_JSAMPLE - 3) +#endif + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } else +#endif + { + if (cinfo->data_precision != BITS_IN_JSAMPLE) + ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); + } if (!cinfo->master->jinit_upsampler_no_alloc) { upsample = (my_upsample_ptr) diff --git a/3rdparty/libjpeg-turbo/src/jerror.c b/3rdparty/libjpeg-turbo/src/jerror.c index 3a75fec02c..2133244f8a 100644 --- a/3rdparty/libjpeg-turbo/src/jerror.c +++ b/3rdparty/libjpeg-turbo/src/jerror.c @@ -40,8 +40,6 @@ * Create the message string table. * We do this from the master message list in jerror.h by re-reading * jerror.h with a suitable definition for macro JMESSAGE. - * The message table is made an external symbol just in case any applications - * want to refer to it directly. */ #define JMESSAGE(code, string) string, diff --git a/3rdparty/libjpeg-turbo/src/jmemmgr.c b/3rdparty/libjpeg-turbo/src/jmemmgr.c index dca8f5c22c..eb199c8b3d 100644 --- a/3rdparty/libjpeg-turbo/src/jmemmgr.c +++ b/3rdparty/libjpeg-turbo/src/jmemmgr.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1991-1997, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2016, 2021-2022, D. R. Commander. + * Copyright (C) 2016, 2021-2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -156,8 +156,9 @@ typedef my_memory_mgr *my_mem_ptr; struct jvirt_sarray_control { JSAMPARRAY mem_buffer; /* => the in-memory buffer (if - cinfo->data_precision is 12, then this is - actually a J12SAMPARRAY) */ + cinfo->data_precision > 8, then this is + actually a J12SAMPARRAY or a + J16SAMPARRAY) */ JDIMENSION rows_in_array; /* total virtual array height */ JDIMENSION samplesperrow; /* width of array (and of memory buffer) */ JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */ @@ -449,8 +450,8 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, int data_precision = cinfo->is_decompressor ? ((j_decompress_ptr)cinfo)->data_precision : ((j_compress_ptr)cinfo)->data_precision; - size_t sample_size = data_precision == 16 ? - sizeof(J16SAMPLE) : (data_precision == 12 ? + size_t sample_size = data_precision > 12 ? + sizeof(J16SAMPLE) : (data_precision > 8 ? sizeof(J12SAMPLE) : sizeof(JSAMPLE)); @@ -477,7 +478,44 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, rowsperchunk = numrows; mem->last_rowsperchunk = rowsperchunk; - if (data_precision == 16) { + if (data_precision <= 8) { + /* Get space for row pointers (small object) */ + result = (JSAMPARRAY)alloc_small(cinfo, pool_id, + (size_t)(numrows * sizeof(JSAMPROW))); + + /* Get the rows themselves (large objects) */ + currow = 0; + while (currow < numrows) { + rowsperchunk = MIN(rowsperchunk, numrows - currow); + workspace = (JSAMPROW)alloc_large(cinfo, pool_id, + (size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size)); + for (i = rowsperchunk; i > 0; i--) { + result[currow++] = workspace; + workspace += samplesperrow; + } + } + + return result; + } else if (data_precision <= 12) { + /* Get space for row pointers (small object) */ + result12 = (J12SAMPARRAY)alloc_small(cinfo, pool_id, + (size_t)(numrows * + sizeof(J12SAMPROW))); + + /* Get the rows themselves (large objects) */ + currow = 0; + while (currow < numrows) { + rowsperchunk = MIN(rowsperchunk, numrows - currow); + workspace12 = (J12SAMPROW)alloc_large(cinfo, pool_id, + (size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size)); + for (i = rowsperchunk; i > 0; i--) { + result12[currow++] = workspace12; + workspace12 += samplesperrow; + } + } + + return (JSAMPARRAY)result12; + } else { #if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED) /* Get space for row pointers (small object) */ result16 = (J16SAMPARRAY)alloc_small(cinfo, pool_id, @@ -501,43 +539,6 @@ alloc_sarray(j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, ERREXIT1(cinfo, JERR_BAD_PRECISION, data_precision); return NULL; #endif - } else if (data_precision == 12) { - /* Get space for row pointers (small object) */ - result12 = (J12SAMPARRAY)alloc_small(cinfo, pool_id, - (size_t)(numrows * - sizeof(J12SAMPROW))); - - /* Get the rows themselves (large objects) */ - currow = 0; - while (currow < numrows) { - rowsperchunk = MIN(rowsperchunk, numrows - currow); - workspace12 = (J12SAMPROW)alloc_large(cinfo, pool_id, - (size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size)); - for (i = rowsperchunk; i > 0; i--) { - result12[currow++] = workspace12; - workspace12 += samplesperrow; - } - } - - return (JSAMPARRAY)result12; - } else { - /* Get space for row pointers (small object) */ - result = (JSAMPARRAY)alloc_small(cinfo, pool_id, - (size_t)(numrows * sizeof(JSAMPROW))); - - /* Get the rows themselves (large objects) */ - currow = 0; - while (currow < numrows) { - rowsperchunk = MIN(rowsperchunk, numrows - currow); - workspace = (JSAMPROW)alloc_large(cinfo, pool_id, - (size_t)((size_t)rowsperchunk * (size_t)samplesperrow * sample_size)); - for (i = rowsperchunk; i > 0; i--) { - result[currow++] = workspace; - workspace += samplesperrow; - } - } - - return result; } } @@ -703,8 +704,8 @@ realize_virt_arrays(j_common_ptr cinfo) int data_precision = cinfo->is_decompressor ? ((j_decompress_ptr)cinfo)->data_precision : ((j_compress_ptr)cinfo)->data_precision; - size_t sample_size = data_precision == 16 ? - sizeof(J16SAMPLE) : (data_precision == 12 ? + size_t sample_size = data_precision > 12 ? + sizeof(J16SAMPLE) : (data_precision > 8 ? sizeof(J12SAMPLE) : sizeof(JSAMPLE)); @@ -821,8 +822,8 @@ do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing) int data_precision = cinfo->is_decompressor ? ((j_decompress_ptr)cinfo)->data_precision : ((j_compress_ptr)cinfo)->data_precision; - size_t sample_size = data_precision == 16 ? - sizeof(J16SAMPLE) : (data_precision == 12 ? + size_t sample_size = data_precision > 12 ? + sizeof(J16SAMPLE) : (data_precision > 8 ? sizeof(J12SAMPLE) : sizeof(JSAMPLE)); @@ -840,7 +841,27 @@ do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing) if (rows <= 0) /* this chunk might be past end of file! */ break; byte_count = rows * bytesperrow; - if (data_precision == 16) { + if (data_precision <= 8) { + if (writing) + (*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info, + (void *)ptr->mem_buffer[i], + file_offset, byte_count); + else + (*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info, + (void *)ptr->mem_buffer[i], + file_offset, byte_count); + } else if (data_precision <= 12) { + J12SAMPARRAY mem_buffer12 = (J12SAMPARRAY)ptr->mem_buffer; + + if (writing) + (*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info, + (void *)mem_buffer12[i], + file_offset, byte_count); + else + (*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info, + (void *)mem_buffer12[i], + file_offset, byte_count); + } else { #if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED) J16SAMPARRAY mem_buffer16 = (J16SAMPARRAY)ptr->mem_buffer; @@ -855,26 +876,6 @@ do_sarray_io(j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing) #else ERREXIT1(cinfo, JERR_BAD_PRECISION, data_precision); #endif - } else if (data_precision == 12) { - J12SAMPARRAY mem_buffer12 = (J12SAMPARRAY)ptr->mem_buffer; - - if (writing) - (*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info, - (void *)mem_buffer12[i], - file_offset, byte_count); - else - (*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info, - (void *)mem_buffer12[i], - file_offset, byte_count); - } else { - if (writing) - (*ptr->b_s_info.write_backing_store) (cinfo, &ptr->b_s_info, - (void *)ptr->mem_buffer[i], - file_offset, byte_count); - else - (*ptr->b_s_info.read_backing_store) (cinfo, &ptr->b_s_info, - (void *)ptr->mem_buffer[i], - file_offset, byte_count); } file_offset += byte_count; } @@ -926,8 +927,8 @@ access_virt_sarray(j_common_ptr cinfo, jvirt_sarray_ptr ptr, int data_precision = cinfo->is_decompressor ? ((j_decompress_ptr)cinfo)->data_precision : ((j_compress_ptr)cinfo)->data_precision; - size_t sample_size = data_precision == 16 ? - sizeof(J16SAMPLE) : (data_precision == 12 ? + size_t sample_size = data_precision > 12 ? + sizeof(J16SAMPLE) : (data_precision > 8 ? sizeof(J12SAMPLE) : sizeof(JSAMPLE)); diff --git a/3rdparty/libjpeg-turbo/src/jmemnobs.c b/3rdparty/libjpeg-turbo/src/jmemnobs.c index cd6571ba1c..692775f5a8 100644 --- a/3rdparty/libjpeg-turbo/src/jmemnobs.c +++ b/3rdparty/libjpeg-turbo/src/jmemnobs.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1992-1996, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2017-2018, D. R. Commander. + * Copyright (C) 2017-2018, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -31,7 +31,7 @@ GLOBAL(void *) jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject) { - return (void *)malloc(sizeofobject); + return (void *)MALLOC(sizeofobject); } GLOBAL(void) @@ -48,7 +48,7 @@ jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject) GLOBAL(void *) jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject) { - return (void *)malloc(sizeofobject); + return (void *)MALLOC(sizeofobject); } GLOBAL(void) diff --git a/3rdparty/libjpeg-turbo/src/jpegint.h b/3rdparty/libjpeg-turbo/src/jpegint.h index 6541420143..a90493f9e0 100644 --- a/3rdparty/libjpeg-turbo/src/jpegint.h +++ b/3rdparty/libjpeg-turbo/src/jpegint.h @@ -7,7 +7,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2015-2017, 2019, 2021-2022, D. R. Commander. + * Copyright (C) 2015-2017, 2019, 2021-2022, 2024, D. R. Commander. * Copyright (C) 2015, Google, Inc. * Copyright (C) 2021, Alex Richardson. * For conditions of distribution and use, see the accompanying README.ijg @@ -249,6 +249,9 @@ struct jpeg_decomp_master { /* Last iMCU row that was successfully decoded */ JDIMENSION last_good_iMCU_row; + + /* Tail of list of saved markers */ + jpeg_saved_marker_ptr marker_list_end; }; /* Input control module */ @@ -443,6 +446,12 @@ struct jpeg_color_quantizer { #undef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) +#ifdef ZERO_BUFFERS +#define MALLOC(size) calloc(1, size) +#else +#define MALLOC(size) malloc(size) +#endif + /* We assume that right shift corresponds to signed division by 2 with * rounding towards minus infinity. This is correct for typical "arithmetic diff --git a/3rdparty/libjpeg-turbo/src/jpeglib.h b/3rdparty/libjpeg-turbo/src/jpeglib.h index a59e98c25e..f7076a18d0 100644 --- a/3rdparty/libjpeg-turbo/src/jpeglib.h +++ b/3rdparty/libjpeg-turbo/src/jpeglib.h @@ -7,7 +7,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2009-2011, 2013-2014, 2016-2017, 2020, 2022-2023, + * Copyright (C) 2009-2011, 2013-2014, 2016-2017, 2020, 2022-2024, D. R. Commander. * Copyright (C) 2015, Google, Inc. * For conditions of distribution and use, see the accompanying README.ijg @@ -18,6 +18,16 @@ * and perhaps jerror.h if they want to know the exact error codes. */ +/* NOTE: This header file does not include stdio.h, despite the fact that it + * uses FILE and size_t. That is by design, since the libjpeg API predates the + * widespread adoption of ANSI/ISO C. Referring to libjpeg.txt, it is a + * documented requirement that calling programs "include system headers that + * define at least the typedefs FILE and size_t" before including jpeglib.h. + * Technically speaking, changing that requirement by including stdio.h here + * would break backward API compatibility. Please do not file bug reports, + * feature requests, or pull requests regarding this. + */ + #ifndef JPEGLIB_H #define JPEGLIB_H @@ -76,22 +86,26 @@ extern "C" { /* Data structures for images (arrays of samples and of DCT coefficients). */ -typedef JSAMPLE *JSAMPROW; /* ptr to one image row of pixel samples. */ -typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */ -typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */ +typedef JSAMPLE *JSAMPROW; /* ptr to one image row of pixel samples with + 2-bit through 8-bit data precision. */ +typedef JSAMPROW *JSAMPARRAY; /* ptr to some JSAMPLE rows (a 2-D JSAMPLE + array) */ +typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D JSAMPLE array: top index is color */ -typedef J12SAMPLE *J12SAMPROW; /* ptr to one image row of 12-bit pixel - samples. */ -typedef J12SAMPROW *J12SAMPARRAY; /* ptr to some 12-bit sample rows (a 2-D - 12-bit sample array) */ -typedef J12SAMPARRAY *J12SAMPIMAGE; /* a 3-D 12-bit sample array: top index is +typedef J12SAMPLE *J12SAMPROW; /* ptr to one image row of pixel samples + with 9-bit through 12-bit data + precision. */ +typedef J12SAMPROW *J12SAMPARRAY; /* ptr to some J12SAMPLE rows (a 2-D + J12SAMPLE array) */ +typedef J12SAMPARRAY *J12SAMPIMAGE; /* a 3-D J12SAMPLE array: top index is color */ -typedef J16SAMPLE *J16SAMPROW; /* ptr to one image row of 16-bit pixel - samples. */ -typedef J16SAMPROW *J16SAMPARRAY; /* ptr to some 16-bit sample rows (a 2-D - 16-bit sample array) */ -typedef J16SAMPARRAY *J16SAMPIMAGE; /* a 3-D 16-bit sample array: top index is +typedef J16SAMPLE *J16SAMPROW; /* ptr to one image row of pixel samples + with 13-bit through 16-bit data + precision. */ +typedef J16SAMPROW *J16SAMPARRAY; /* ptr to some J16SAMPLE rows (a 2-D + J16SAMPLE array) */ +typedef J16SAMPARRAY *J16SAMPIMAGE; /* a 3-D J16SAMPLE array: top index is color */ typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */ @@ -575,11 +589,10 @@ struct jpeg_decompress_struct { */ int actual_number_of_colors; /* number of entries in use */ JSAMPARRAY colormap; /* The color map as a 2-D pixel array - If data_precision is 12 or 16, then this is - actually a J12SAMPARRAY or a J16SAMPARRAY, - so callers must type-cast it in order to - read/write 12-bit or 16-bit samples from/to - the array. */ + If data_precision is 12, then this is + actually a J12SAMPARRAY, so callers must + type-cast it in order to read/write 12-bit + samples from/to the array. */ /* State variables: these variables indicate the progress of decompression. * The application may examine these but must not modify them. @@ -699,11 +712,12 @@ struct jpeg_decompress_struct { */ JSAMPLE *sample_range_limit; /* table for fast range-limiting - If data_precision is 12 or 16, then this is - actually a J12SAMPLE pointer or a J16SAMPLE - pointer, so callers must type-cast it in - order to read 12-bit or 16-bit samples from - the array. */ + If data_precision is 9 to 12, then this is + actually a J12SAMPLE pointer, and if + data_precision is 13 to 16, then this is + actually a J16SAMPLE pointer, so callers + must type-cast it in order to read samples + from the array. */ /* * These fields are valid during any one scan. diff --git a/3rdparty/libjpeg-turbo/src/jquant1.c b/3rdparty/libjpeg-turbo/src/jquant1.c index 2e914b919c..bd68dcb8c6 100644 --- a/3rdparty/libjpeg-turbo/src/jquant1.c +++ b/3rdparty/libjpeg-turbo/src/jquant1.c @@ -86,22 +86,22 @@ static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = { * Stephen Hawley's article "Ordered Dithering" in Graphics Gems I. * The values in this array must range from 0 to ODITHER_CELLS-1. */ - { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 }, - { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 }, - { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 }, - { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 }, - { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 }, - { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 }, - { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 }, - { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 }, - { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 }, - { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 }, - { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 }, - { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 }, - { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 }, - { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 }, - { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 }, - { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 } + { 0, 192, 48, 240, 12, 204, 60, 252, 3, 195, 51, 243, 15, 207, 63, 255 }, + { 128, 64, 176, 112, 140, 76, 188, 124, 131, 67, 179, 115, 143, 79, 191, 127 }, + { 32, 224, 16, 208, 44, 236, 28, 220, 35, 227, 19, 211, 47, 239, 31, 223 }, + { 160, 96, 144, 80, 172, 108, 156, 92, 163, 99, 147, 83, 175, 111, 159, 95 }, + { 8, 200, 56, 248, 4, 196, 52, 244, 11, 203, 59, 251, 7, 199, 55, 247 }, + { 136, 72, 184, 120, 132, 68, 180, 116, 139, 75, 187, 123, 135, 71, 183, 119 }, + { 40, 232, 24, 216, 36, 228, 20, 212, 43, 235, 27, 219, 39, 231, 23, 215 }, + { 168, 104, 152, 88, 164, 100, 148, 84, 171, 107, 155, 91, 167, 103, 151, 87 }, + { 2, 194, 50, 242, 14, 206, 62, 254, 1, 193, 49, 241, 13, 205, 61, 253 }, + { 130, 66, 178, 114, 142, 78, 190, 126, 129, 65, 177, 113, 141, 77, 189, 125 }, + { 34, 226, 18, 210, 46, 238, 30, 222, 33, 225, 17, 209, 45, 237, 29, 221 }, + { 162, 98, 146, 82, 174, 110, 158, 94, 161, 97, 145, 81, 173, 109, 157, 93 }, + { 10, 202, 58, 250, 6, 198, 54, 246, 9, 201, 57, 249, 5, 197, 53, 245 }, + { 138, 74, 186, 122, 134, 70, 182, 118, 137, 73, 185, 121, 133, 69, 181, 117 }, + { 42, 234, 26, 218, 38, 230, 22, 214, 41, 233, 25, 217, 37, 229, 21, 213 }, + { 170, 106, 154, 90, 166, 102, 150, 86, 169, 105, 153, 89, 165, 101, 149, 85 } }; diff --git a/3rdparty/libjpeg-turbo/src/jsamplecomp.h b/3rdparty/libjpeg-turbo/src/jsamplecomp.h index f3f275e6e2..3a1f296029 100644 --- a/3rdparty/libjpeg-turbo/src/jsamplecomp.h +++ b/3rdparty/libjpeg-turbo/src/jsamplecomp.h @@ -93,7 +93,6 @@ /* Image I/O functions (cdjpeg.h) */ #ifdef C_LOSSLESS_SUPPORTED -#define _jinit_read_gif j16init_read_gif #define _jinit_read_ppm j16init_read_ppm #endif @@ -209,7 +208,6 @@ #define _buffer buffer12 /* Image I/O functions (cdjpeg.h) */ -#define _jinit_read_gif j12init_read_gif #define _jinit_write_gif j12init_write_gif #define _jinit_read_ppm j12init_read_ppm #define _jinit_write_ppm j12init_write_ppm @@ -324,7 +322,6 @@ #define _buffer buffer /* Image I/O functions (cdjpeg.h) */ -#define _jinit_read_gif jinit_read_gif #define _jinit_write_gif jinit_write_gif #define _jinit_read_ppm jinit_read_ppm #define _jinit_write_ppm jinit_write_ppm diff --git a/3rdparty/libjpeg-turbo/src/jstdhuff.c b/3rdparty/libjpeg-turbo/src/jstdhuff.c index 345b513d4d..3945901205 100644 --- a/3rdparty/libjpeg-turbo/src/jstdhuff.c +++ b/3rdparty/libjpeg-turbo/src/jstdhuff.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1991-1998, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2013, 2022, D. R. Commander. + * Copyright (C) 2013, 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -25,7 +25,7 @@ add_huff_table(j_common_ptr cinfo, JHUFF_TBL **htblptr, const UINT8 *bits, if (*htblptr == NULL) *htblptr = jpeg_alloc_huff_table(cinfo); - else + else if (cinfo->is_decompressor) return; /* Copy the number-of-symbols-of-each-code-length counts */ diff --git a/3rdparty/libjpeg-turbo/src/jversion.h.in b/3rdparty/libjpeg-turbo/src/jversion.h.in deleted file mode 100644 index fc0ce3e09e..0000000000 --- a/3rdparty/libjpeg-turbo/src/jversion.h.in +++ /dev/null @@ -1,56 +0,0 @@ -/* - * jversion.h - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding. - * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2012-2024, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains software version identification. - */ - - -#if JPEG_LIB_VERSION >= 80 - -#define JVERSION "8d 15-Jan-2012" - -#elif JPEG_LIB_VERSION >= 70 - -#define JVERSION "7 27-Jun-2009" - -#else - -#define JVERSION "6b 27-Mar-1998" - -#endif - -/* - * NOTE: It is our convention to place the authors in the following order: - * - libjpeg-turbo authors (2009-) in descending order of the date of their - * most recent contribution to the project, then in ascending order of the - * date of their first contribution to the project, then in alphabetical - * order - * - Upstream authors in descending order of the date of the first inclusion of - * their code - */ - -#define JCOPYRIGHT1 \ - "Copyright (C) 2009-2024 D. R. Commander\n" \ - "Copyright (C) 2015, 2020 Google, Inc.\n" \ - "Copyright (C) 2019-2020 Arm Limited\n" \ - "Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \ - "Copyright (C) 2011-2016 Siarhei Siamashka\n" \ - "Copyright (C) 2015 Intel Corporation\n" -#define JCOPYRIGHT2 \ - "Copyright (C) 2013-2014 Linaro Limited\n" \ - "Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \ - "Copyright (C) 2009, 2012 Pierre Ossman for Cendio AB\n" \ - "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \ - "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ - "Copyright (C) 1999 Ken Murchison\n" \ - "Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding\n" - -#define JCOPYRIGHT_SHORT \ - "Copyright (C) @COPYRIGHT_YEAR@ The libjpeg-turbo Project and many others" diff --git a/3rdparty/libjpeg-turbo/src/libjpeg.map.in b/3rdparty/libjpeg-turbo/src/libjpeg.map.in deleted file mode 100644 index b4480d8347..0000000000 --- a/3rdparty/libjpeg-turbo/src/libjpeg.map.in +++ /dev/null @@ -1,11 +0,0 @@ -LIBJPEGTURBO_@JPEG_LIB_VERSION_DECIMAL@ { - @MEM_SRCDST_FUNCTIONS@ - local: - jsimd_*; - jconst_*; -}; - -LIBJPEG_@JPEG_LIB_VERSION_DECIMAL@ { - global: - *; -}; diff --git a/3rdparty/libjpeg-turbo/src/libjpeg.txt b/3rdparty/libjpeg-turbo/src/libjpeg.txt index 0fe95bb63c..50315535bf 100644 --- a/3rdparty/libjpeg-turbo/src/libjpeg.txt +++ b/3rdparty/libjpeg-turbo/src/libjpeg.txt @@ -5,7 +5,7 @@ Copyright (C) 1994-2013, Thomas G. Lane, Guido Vollbeding. Lossless JPEG Modifications: Copyright (C) 1999, Ken Murchison. libjpeg-turbo Modifications: -Copyright (C) 2010, 2014-2018, 2020, 2022-2023, D. R. Commander. +Copyright (C) 2010, 2014-2018, 2020, 2022-2024, D. R. Commander. Copyright (C) 2015, Google, Inc. For conditions of distribution and use, see the accompanying README.ijg file. @@ -31,7 +31,7 @@ TABLE OF CONTENTS Overview: Functions provided by the library - 12-bit and 16-bit Data Precision + Data Precision Outline of typical usage Basic library usage: Data formats @@ -101,8 +101,8 @@ use.) Unsupported ISO options include: * Hierarchical storage * DNL marker * Nonintegral subsampling ratios -We support 8-bit (lossy and lossless), 12-bit (lossy and lossless), and 16-bit -(lossless) data precision. +We support 8-bit and 12-bit data precision in lossy mode and 2-bit through +16-bit data precision in lossless mode. By itself, the library handles only interchange JPEG datastreams --- in particular the widely used JFIF file format. The library can be used by @@ -111,28 +111,34 @@ are embedded in more complex file formats. (For example, this library is used by the free LIBTIFF library to support JPEG compression in TIFF.) -12-bit and 16-bit Data Precision --------------------------------- +Data Precision +-------------- -The JPEG standard provides for baseline 8-bit and 12-bit DCT processes as well -as 8-bit, 12-bit, and 16-bit lossless (predictive) processes. This code -supports 12-bit-per-component lossy or lossless JPEG if you set -cinfo->data_precision to 12 and 16-bit-per-component lossless JPEG if you set -cinfo->data_precision to 16. Note that this causes the sample size to be -larger than a char, so it affects the surrounding application's image data. -The sample applications cjpeg and djpeg can support 12-bit mode only for PPM, -PGM, and GIF file formats and 16-bit mode only for PPM and PGM file formats. +The data precision is the number of bits in the maximum sample value (which may +not be the same as the width of the data type used to store the sample.) The +JPEG standard provides for, and this code supports, baseline (8-bit-per-sample) +and 12-bit-per-sample DCT processes as well as lossless (predictive) processes +with 2 to 16 bits of data precision per sample. To create a JPEG image with a +particular data precision, set cinfo->data_precision accordingly. Note that +9-bit and higher data precisions cause the sample size to be larger than a +char, which affects the surrounding application's image data. The sample +application djpeg can support 12-bit data precision only for PPM, PGM, and GIF +file formats. The sample applications cjpeg and djpeg can support 2-bit +through 7-bit and 9-bit through 16-bit data precision only for PPM and PGM file +formats. -Note that, when 12-bit data precision is enabled, the library always compresses -in Huffman optimization mode, in order to generate valid Huffman tables. This -is necessary because our default Huffman tables only cover 8-bit data. If you -need to output 12-bit files in one pass, you'll have to supply suitable default -Huffman tables. You may also want to supply your own DCT quantization tables; -the existing quality-scaling code has been developed for 8-bit use, and -probably doesn't generate especially good tables for 12-bit. +Note that, when 12-bit data precision is enabled in lossy mode, the library +compresses in Huffman optimization mode by default, in order to generate valid +Huffman tables. This is necessary because our default Huffman tables only +cover 8-bit data. If you need to output 12-bit-per-sample JPEG files in one +pass, you'll have to supply suitable default Huffman tables. You may also want +to supply your own DCT quantization tables; the existing quality-scaling code +has been developed for 8-bit data precision and probably doesn't generate +especially good tables for 12-bit data precision. -Functions that are specific to 12-bit data precision have a prefix of "jpeg12_" -instead of "jpeg_" and use the following data types and macros: +Functions that are specific to 9-bit through 12-bit data precision have a +prefix of "jpeg12_" instead of "jpeg_" and use the following data types and +macros: * J12SAMPLE instead of JSAMPLE * J12SAMPROW instead of JSAMPROW @@ -141,8 +147,9 @@ instead of "jpeg_" and use the following data types and macros: * MAXJ12SAMPLE instead of MAXJSAMPLE * CENTERJ12SAMPLE instead of CENTERJSAMPLE -Functions that are specific to 16-bit data precision have a prefix of "jpeg16_" -instead of "jpeg_" and use the following data types and macros: +Functions that are specific to 13-bit through 16-bit data precision have a +prefix of "jpeg16_" instead of "jpeg_" and use the following data types and +macros: * J16SAMPLE instead of JSAMPLE * J16SAMPROW instead of JSAMPROW @@ -151,16 +158,17 @@ instead of "jpeg_" and use the following data types and macros: * MAXJ16SAMPLE instead of MAXJSAMPLE * CENTERJ16SAMPLE instead of CENTERJSAMPLE -This allows 8-bit, 12-bit, and 16-bit data precision to be used in a single -application. (Refer to example.c). Arithmetic coding and SIMD acceleration -are not currently implemented for 12-bit data precision, nor are they -implemented for lossless mode with any data precision. +This allows multiple data precisions to be used in a single application. +(Refer to example.c). Arithmetic coding and SIMD acceleration are currently +only implemented for lossy mode with 8-bit data precision. Refer to the descriptions of the data_precision compression and decompression parameters below for further information. This documentation uses "J*SAMPLE", "J*SAMPROW", "J*SAMPARRAY", and -"J*SAMPIMAGE" to generically refer to the 8-bit, 12-bit, or 16-bit data types. +"J*SAMPIMAGE" to generically refer to the data types with 2 to 8 bits of data +precision per sample, 9 to 12 bits of data precision per sample, and 13 to 16 +bits of data precision per sample. Outline of typical usage @@ -174,9 +182,11 @@ The rough outline of a JPEG compression operation is: jpeg_start_compress(...); while (scan lines remain to be written) jpeg_write_scanlines(...); /* Use jpeg12_write_scanlines() for - 12-bit data precision and + 9-bit through 12-bit data + precision and jpeg16_write_scanlines() for - 16-bit data precision. */ + 13-bit through 16-bit data + precision. */ jpeg_finish_compress(...); Release the JPEG compression object @@ -204,9 +214,11 @@ Similarly, the rough outline of a JPEG decompression operation is: jpeg_start_decompress(...); while (scan lines remain to be read) jpeg_read_scanlines(...); /* Use jpeg12_read_scanlines() for - 12-bit data precision and + 9-bit through 12-bit data + precision and jpeg16_read_scanlines() for - 16-bit data precision. */ + 13-bit through 16-bit data + precision. */ jpeg_finish_decompress(...); Release the JPEG decompression object @@ -267,10 +279,9 @@ and the other references mentioned in the README.ijg file. Pixels are stored by scanlines, with each scanline running from left to right. The component values for each pixel are adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color. Each scanline is an -array of data type JSAMPLE or J12SAMPLE --- which is typically "unsigned char" -or "short" (respectively), unless you've changed jmorecfg.h. (You can also -change the RGB pixel layout, say to B,G,R order, by modifying jmorecfg.h. But -see the restrictions listed in that file before doing so.) +array of data type JSAMPLE, J12SAMPLE, or J16SAMPLE --- which is typically +"unsigned char", "short", or "unsigned short" (respectively) unless you've +changed jmorecfg.h. A 2-D array of pixels is formed by making a list of pointers to the starts of scanlines; so the scanlines need not be physically adjacent in memory. Even @@ -284,12 +295,6 @@ processed top-to-bottom. You can process an entire image in one call if you have it all in memory, but usually it's simplest to process one scanline at a time. -For best results, source data values should have the precision specified by -cinfo->data_precision (normally 8 bits). For instance, if you choose to -compress data that's only 6 bits/channel, you should left-justify each value in -a byte before passing it to the compressor. If you need to compress data -that has more than 8 bits/channel, set cinfo->data_precision = 12 or 16. - The data format returned by the decompressor is the same in all details, except that colormapped output is supported. (Again, a JPEG file is never @@ -301,8 +306,8 @@ a 2-D J*SAMPARRAY in which each row holds the values of one color component, that is, colormap[i][j] is the value of the i'th color component for pixel value (map index) j. Note that since the colormap indexes are stored in J*SAMPLEs, the maximum number of colors is limited by the size of J*SAMPLE -(ie, at most 256 colors for 8-bit data precision, 4096 colors for 12-bit data -precision, and 65536 colors for 16-bit data precision). +(ie, at most 256 colors for 8-bit data precision and 4096 colors for 12-bit +data precision). Compression details @@ -439,10 +444,10 @@ the compression cycle. 5. while (scan lines remain to be written) - jpeg_write_scanlines(...); /* Use jpeg12_write_scanlines() for 12-bit - data precision and - jpeg16_write_scanlines() for 16-bit data - precision. */ + jpeg_write_scanlines(...); /* Use jpeg12_write_scanlines() for 9-bit + through 12-bit data precision and + jpeg16_write_scanlines() for 13-bit + through 16-bit data precision. */ Now write all the required image data by calling jpeg*_write_scanlines() one or more times. You can pass one or more scanlines in each call, up @@ -468,17 +473,19 @@ example.c shows the following code for the case of a full-size 2-D source array containing 3-byte RGB pixels: JSAMPROW row_pointer[1]; /* pointer to a single row - Use J12SAMPROW for 12-bit data - precision and J16SAMPROW for 16-bit - data precision. */ + Use J12SAMPROW for 9-bit through + 12-bit data precision and J16SAMPROW + for 13-bit through 16-bit data + precision. */ while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0] = image_buffer[cinfo.next_scanline]; jpeg_write_scanlines(&cinfo, row_pointer, 1); /* Use jpeg12_write_scanlines() for - 12-bit data precision and - jpeg16_write_scanlines() for 16-bit - data precision. */ + 9-bit through 12-bit data precision + and jpeg16_write_scanlines() for + 13-bit through 16-bit data + precision. */ } jpeg*_write_scanlines() returns the number of scanlines actually written. @@ -722,10 +729,10 @@ relevant parameters (scaling, output color space, and quantization flag). 6. while (scan lines remain to be read) - jpeg_read_scanlines(...); /* Use jpeg12_read_scanlines() for 12-bit - data precision and - jpeg16_read_scanlines() for 16-bit data - precision. */ + jpeg_read_scanlines(...); /* Use jpeg12_read_scanlines() for 9-bit + through 12-bit data precision and + jpeg16_read_scanlines() for 13-bit + through 16-bit data precision. */ Now you can read the decompressed image data by calling jpeg*_read_scanlines() one or more times. At each call, you pass in the maximum number of scanlines @@ -972,7 +979,7 @@ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline) entries are constrained to the range 1..255 for full JPEG baseline compatibility. In the current implementation, this only makes a difference for quality settings below 25, and it effectively prevents - very small/low quality files from being generated. The IJG decoder + very small/low-quality files from being generated. The IJG decoder is capable of reading the non-baseline files generated at low quality settings when force_baseline is FALSE, but other decoders may not be. @@ -1079,14 +1086,14 @@ boolean arith_code If FALSE, use Huffman coding. int data_precision - To create a 12-bit-per-component JPEG file, set data_precision to 12 - prior to calling jpeg_start_compress() or using the memory manager, - then use jpeg12_write_scanlines() or jpeg12_write_raw_data() instead of - jpeg_write_scanlines() or jpeg_write_raw_data(). To create a - 16-bit-per-component lossless JPEG file, set data_precision to 16 prior - to calling jpeg_start_compress() or using the memory manager, then use - jpeg16_write_scanlines() instead of jpeg_write_scanlines(). Note that - 16-bit data precision requires lossless mode. (See + Prior to calling jpeg_start_compress() or using the memory manager, set + data_precision to the desired number of bits per sample (2 to 16) in + the JPEG file. To create a JPEG file with 9 to 12 bits per sample, use + jpeg12_write_scanlines() or jpeg12_write_raw_data() instead of + jpeg_write_scanlines() or jpeg_write_raw_data(). To create a lossless + JPEG file with 13 to 16 bits per sample, use jpeg16_write_scanlines() + instead of jpeg_write_scanlines(). Note that data precisions other + than 8-bit and 12-bit require lossless mode. (See jpeg_enable_lossless().) J_DCT_METHOD dct_method @@ -1138,20 +1145,23 @@ boolean optimize_coding Huffman tables. In most cases optimal tables save only a few percent of file size compared to the default tables. Note that when this is TRUE, you need not supply Huffman tables at all, and any you do - supply will be overwritten. + supply will be overwritten. Optimal Huffman tables are always + computed, and this parameter has no effect, in progressive mode or + lossless mode or with 12-bit data precision (unless Huffman tables have + been supplied.) This parameter also has no effect when using + arithmetic coding. unsigned int restart_interval int restart_in_rows To emit restart markers in the JPEG file, set one of these nonzero. - Set restart_interval to specify the exact interval in MCU blocks - (samples in lossless mode). Set restart_in_rows to specify the - interval in MCU rows. (If restart_in_rows is not 0, then - restart_interval is set after the image width in MCUs is computed.) - Defaults are zero (no restarts). One restart marker per MCU row is - often a good choice. NOTE: the overhead of restart markers is higher - in grayscale JPEG files than in color files, and MUCH higher in - progressive JPEGs. If you use restarts, you may want to use larger - intervals in those cases. + Set restart_interval to specify the exact interval in MCUs. Set + restart_in_rows to specify the interval in MCU rows. (If + restart_in_rows is not 0, then restart_interval is set after the image + width in MCUs is computed.) Defaults are zero (no restarts). One + restart marker per MCU row is often a good choice. NOTE: the overhead + of restart markers is higher in grayscale JPEG files than in color + files, and MUCH higher in progressive JPEGs. If you use restarts, you + may want to use larger intervals in those cases. const jpeg_scan_info *scan_info int num_scans @@ -1303,18 +1313,18 @@ recorded in the source file and need not be supplied by the application. the postprocessing done on the image to deliver it in a format suitable for the application's use. Many of the parameters control speed/quality tradeoffs, in which faster decompression may be obtained at the price of -a poorer-quality image. The defaults select the highest quality (slowest) +a poorer-quality image. The defaults select the highest-quality (slowest) processing. The following fields in the JPEG object are set by jpeg_read_header() and may be useful to the application in choosing decompression parameters: -int data_precision Data precision (bits per component) - If data_precision is 12, then use jpeg12_read_scanlines(), +int data_precision Data precision (bits per sample) + If data_precision is 9 to 12, then use jpeg12_read_scanlines(), jpeg12_skip_scanlines(), jpeg12_crop_scanline(), and/or jpeg12_read_raw_data() instead of jpeg_read_scanlines(), jpeg_skip_scanlines(), jpeg_crop_scanline(), and/or - jpeg_read_raw_data(). If data_precision is 16, then use + jpeg_read_raw_data(). If data_precision is 13 to 16, then use jpeg16_read_scanlines() instead of jpeg_read_scanlines(). JDIMENSION image_width Width and height of image @@ -1344,11 +1354,8 @@ J_COLOR_SPACE out_color_space based on jpeg_color_space; typically it will be RGB or grayscale. The application can change this field to request output in a different colorspace. For example, set it to JCS_GRAYSCALE to get grayscale - output from a color file. (This is useful for previewing: grayscale - output is faster than full color since the color components need not - be processed.) Note that not all possible color space transforms are - currently implemented; you may need to extend jdcolor.c if you want an - unusual conversion. + output from a color file. Note that not all possible color space + transforms are currently implemented. unsigned int scale_num, scale_denom Scale the image by the fraction scale_num/scale_denom. Default is @@ -1356,31 +1363,33 @@ unsigned int scale_num, scale_denom are M/8 with all M from 1 to 16, or any reduced fraction thereof (such as 1/2, 3/4, etc.) (The library design allows for arbitrary scaling ratios but this is not likely to be implemented any time soon.) - Smaller scaling ratios permit significantly faster decoding since - fewer pixels need be processed and a simpler IDCT method can be used. boolean quantize_colors + [legacy feature] If set TRUE, colormapped output will be delivered. Default is FALSE, meaning that full-color output will be delivered. The next three parameters are relevant only if quantize_colors is TRUE. int desired_number_of_colors + [legacy feature] Maximum number of colors to use in generating a library-supplied color map (the actual number of colors is returned in a different field). Default 256. Ignored when the application supplies its own color map. boolean two_pass_quantize + [legacy feature] If TRUE, an extra pass over the image is made to select a custom color map for the image. This usually looks a lot better than the one-size- fits-all colormap that is used otherwise. Default is TRUE. Ignored when the application supplies its own color map. J_DITHER_MODE dither_mode + [legacy feature] Selects color dithering method. Supported values are: - JDITHER_NONE no dithering: fast, very low quality + JDITHER_NONE no dithering: faster, very low quality JDITHER_ORDERED ordered dither: moderate speed and quality - JDITHER_FS Floyd-Steinberg dither: slow, high quality + JDITHER_FS Floyd-Steinberg dither: slower, high quality Default is JDITHER_FS. (At present, ordered dither is implemented only in the single-pass, standard-colormap case. If you ask for ordered dither when two_pass_quantize is TRUE or when you supply @@ -1395,16 +1404,18 @@ selects a suitable color map and sets these two fields itself. only accepted for 3-component output color spaces.] JSAMPARRAY colormap + [legacy feature] The color map, represented as a 2-D pixel array of out_color_components rows and actual_number_of_colors columns. Ignored if not quantizing. CAUTION: if the JPEG library creates its own colormap, the storage pointed to by this field is released by jpeg_finish_decompress(). Copy the colormap somewhere else first, if you want to save it. - CAUTION: if data_precision is 12 or 16, then this is actually a - J12SAMPARRAY or a J16SAMPARRAY, so it must be type-cast in order to - read/write 12-bit or 16-bit samples from/to the array. + CAUTION: if data_precision is 12, then this is actually a J12SAMPARRAY, + so it must be type-cast in order to read/write 12-bit samples from/to + the array. int actual_number_of_colors + [legacy feature] The number of colors in the color map. Additional decompression parameters that the application may set include: @@ -1461,6 +1472,7 @@ boolean do_block_smoothing boolean enable_1pass_quant boolean enable_external_quant boolean enable_2pass_quant + [legacy feature] These are significant only in buffered-image mode, which is described in its own section below. @@ -2112,9 +2124,10 @@ The basic control flow for buffered-image decoding is jpeg_start_output() /* start a new output pass */ for (all scanlines in image) { jpeg_read_scanlines() /* Use jpeg12_read_scanlines() for - 12-bit data precision and - jpeg16_read_scanlines() for 16-bit - data precision. */ + 9-bit through 12-bit data precision + and jpeg16_read_scanlines() for + 13-bit through 16-bit data + precision. */ display scanlines } jpeg_finish_output() /* terminate output pass */ @@ -2330,7 +2343,7 @@ limited changes of parameters. ONLY THE FOLLOWING parameter changes are allowed after jpeg_start_decompress() is called: * dct_method can be changed before each call to jpeg_start_output(). For example, one could use a fast DCT method for early scans, changing - to a higher quality method for the final scan. + to a higher-quality method for the final scan. * dither_mode can be changed before each call to jpeg_start_output(); of course this has no impact if not using color quantization. Typically one would use ordered dither for initial passes, then switch to @@ -3181,11 +3194,11 @@ As of v6b, the decompressor requires: This does not count any memory allocated by the application, such as a buffer to hold the final output image. -The above figures are valid for 8-bit JPEG data precision and a machine with -32-bit ints. For 12-bit and 16-bit JPEG data, double the size of the strip -buffers and quantization pixel buffer. The "fixed-size" data will be somewhat -smaller with 16-bit ints, larger with 64-bit ints. Also, CMYK or other unusual -color spaces will require different amounts of space. +The above figures are valid for 2-bit through 8-bit JPEG data precision and a +machine with 32-bit ints. For other data precisions, double the size of the +strip buffers and quantization pixel buffer. The "fixed-size" data will be +somewhat smaller with 16-bit ints, larger with 64-bit ints. Also, CMYK or +other unusual color spaces will require different amounts of space. The full-image coefficient and pixel buffers, if needed at all, do not have to be fully RAM resident; you can have the library use temporary @@ -3211,14 +3224,6 @@ The maximum number of components (color channels) in the image is determined by MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we expect that few applications will need more than four or so. -On machines with unusual data type sizes, you may be able to improve -performance or reduce memory space by tweaking the various typedefs in -jmorecfg.h. In particular, on some RISC CPUs, access to arrays of "short"s -is quite slow; consider trading memory for speed by making JCOEF, INT16, and -UINT16 be "int" or "unsigned int". UINT8 is also a candidate to become int. -You probably don't want to make J*SAMPLE be int unless you have lots of memory -to burn. - You can reduce the size of the library by compiling out various optional functions. To do this, undefine xxx_SUPPORTED symbols as necessary. @@ -3257,9 +3262,7 @@ than 8 bits or short is much bigger than 16 bits. The code should work equally well with 16- or 32-bit ints. In a system where these assumptions are not met, you may be able to make the -code work by modifying the typedefs in jmorecfg.h. However, you will probably -have difficulty if int is less than 16 bits wide, since references to plain -int abound in the code. +code work by modifying the typedefs in jmorecfg.h. char can be either signed or unsigned, although the code runs faster if an unsigned char type is available. If char is wider than 8 bits, you will need diff --git a/3rdparty/libjpeg-turbo/src/rdbmp.c b/3rdparty/libjpeg-turbo/src/rdbmp.c deleted file mode 100644 index c2c06fd001..0000000000 --- a/3rdparty/libjpeg-turbo/src/rdbmp.c +++ /dev/null @@ -1,689 +0,0 @@ -/* - * rdbmp.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1994-1996, Thomas G. Lane. - * Modified 2009-2017 by Guido Vollbeding. - * libjpeg-turbo Modifications: - * Modified 2011 by Siarhei Siamashka. - * Copyright (C) 2015, 2017-2018, 2021-2023, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains routines to read input images in Microsoft "BMP" - * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors). - * Currently, only 8-, 24-, and 32-bit images are supported, not 1-bit or - * 4-bit (feeding such low-depth images into JPEG would be silly anyway). - * Also, we don't support RLE-compressed files. - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume input from - * an ordinary stdio stream. They further assume that reading begins - * at the start of the file; start_input may need work if the - * user interface has already read some data (e.g., to determine that - * the file is indeed BMP format). - * - * This code contributed by James Arthur Boucher. - */ - -#include "cmyk.h" -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef BMP_SUPPORTED - - -/* Macros to deal with unsigned chars as efficiently as compiler allows */ - -typedef unsigned char U_CHAR; -#define UCH(x) ((int)(x)) - - -#define ReadOK(file, buffer, len) \ - (fread(buffer, 1, len, file) == ((size_t)(len))) - -static int alpha_index[JPEG_NUMCS] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1 -}; - - -/* Private version of data source object */ - -typedef struct _bmp_source_struct *bmp_source_ptr; - -typedef struct _bmp_source_struct { - struct cjpeg_source_struct pub; /* public fields */ - - j_compress_ptr cinfo; /* back link saves passing separate parm */ - - JSAMPARRAY colormap; /* BMP colormap (converted to my format) */ - - jvirt_sarray_ptr whole_image; /* Needed to reverse row order */ - JDIMENSION source_row; /* Current source row number */ - JDIMENSION row_width; /* Physical width of scanlines in file */ - - int bits_per_pixel; /* remembers 8-, 24-, or 32-bit format */ - int cmap_length; /* colormap length */ - - boolean use_inversion_array; /* TRUE = preload the whole image, which is - stored in bottom-up order, and feed it to - the calling program in top-down order - - FALSE = the calling program will maintain - its own image buffer and read the rows in - bottom-up order */ - - U_CHAR *iobuffer; /* I/O buffer (used to buffer a single row from - disk if use_inversion_array == FALSE) */ -} bmp_source_struct; - - -LOCAL(int) -read_byte(bmp_source_ptr sinfo) -/* Read next byte from BMP file */ -{ - register FILE *infile = sinfo->pub.input_file; - register int c; - - if ((c = getc(infile)) == EOF) - ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); - return c; -} - - -LOCAL(void) -read_colormap(bmp_source_ptr sinfo, int cmaplen, int mapentrysize) -/* Read the colormap from a BMP file */ -{ - int i, gray = 1; - - switch (mapentrysize) { - case 3: - /* BGR format (occurs in OS/2 files) */ - for (i = 0; i < cmaplen; i++) { - sinfo->colormap[2][i] = (JSAMPLE)read_byte(sinfo); - sinfo->colormap[1][i] = (JSAMPLE)read_byte(sinfo); - sinfo->colormap[0][i] = (JSAMPLE)read_byte(sinfo); - if (sinfo->colormap[2][i] != sinfo->colormap[1][i] || - sinfo->colormap[1][i] != sinfo->colormap[0][i]) - gray = 0; - } - break; - case 4: - /* BGR0 format (occurs in MS Windows files) */ - for (i = 0; i < cmaplen; i++) { - sinfo->colormap[2][i] = (JSAMPLE)read_byte(sinfo); - sinfo->colormap[1][i] = (JSAMPLE)read_byte(sinfo); - sinfo->colormap[0][i] = (JSAMPLE)read_byte(sinfo); - (void)read_byte(sinfo); - if (sinfo->colormap[2][i] != sinfo->colormap[1][i] || - sinfo->colormap[1][i] != sinfo->colormap[0][i]) - gray = 0; - } - break; - default: - ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP); - break; - } - - if ((sinfo->cinfo->in_color_space == JCS_UNKNOWN || - sinfo->cinfo->in_color_space == JCS_RGB) && gray) - sinfo->cinfo->in_color_space = JCS_GRAYSCALE; - - if (sinfo->cinfo->in_color_space == JCS_GRAYSCALE && !gray) - ERREXIT(sinfo->cinfo, JERR_BAD_IN_COLORSPACE); -} - - -/* - * Read one row of pixels. - * The image has been read into the whole_image array, but is otherwise - * unprocessed. We must read it out in top-to-bottom row order, and if - * it is an 8-bit image, we must expand colormapped pixels to 24bit format. - */ - -METHODDEF(JDIMENSION) -get_8bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 8-bit colormap indexes */ -{ - bmp_source_ptr source = (bmp_source_ptr)sinfo; - register JSAMPARRAY colormap = source->colormap; - int cmaplen = source->cmap_length; - JSAMPARRAY image_ptr; - register int t; - register JSAMPROW inptr, outptr; - register JDIMENSION col; - - if (source->use_inversion_array) { - /* Fetch next row from virtual array */ - source->source_row--; - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr)cinfo, source->whole_image, - source->source_row, (JDIMENSION)1, FALSE); - inptr = image_ptr[0]; - } else { - if (!ReadOK(source->pub.input_file, source->iobuffer, source->row_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - inptr = source->iobuffer; - } - - /* Expand the colormap indexes to real data */ - outptr = source->pub.buffer[0]; - if (cinfo->in_color_space == JCS_GRAYSCALE) { - for (col = cinfo->image_width; col > 0; col--) { - t = *inptr++; - if (t >= cmaplen) - ERREXIT(cinfo, JERR_BMP_OUTOFRANGE); - *outptr++ = colormap[0][t]; - } - } else if (cinfo->in_color_space == JCS_CMYK) { - for (col = cinfo->image_width; col > 0; col--) { - t = *inptr++; - if (t >= cmaplen) - ERREXIT(cinfo, JERR_BMP_OUTOFRANGE); - rgb_to_cmyk(colormap[0][t], colormap[1][t], colormap[2][t], outptr, - outptr + 1, outptr + 2, outptr + 3); - outptr += 4; - } - } else { - register int rindex = rgb_red[cinfo->in_color_space]; - register int gindex = rgb_green[cinfo->in_color_space]; - register int bindex = rgb_blue[cinfo->in_color_space]; - register int aindex = alpha_index[cinfo->in_color_space]; - register int ps = rgb_pixelsize[cinfo->in_color_space]; - - if (aindex >= 0) { - for (col = cinfo->image_width; col > 0; col--) { - t = *inptr++; - if (t >= cmaplen) - ERREXIT(cinfo, JERR_BMP_OUTOFRANGE); - outptr[rindex] = colormap[0][t]; - outptr[gindex] = colormap[1][t]; - outptr[bindex] = colormap[2][t]; - outptr[aindex] = 0xFF; - outptr += ps; - } - } else { - for (col = cinfo->image_width; col > 0; col--) { - t = *inptr++; - if (t >= cmaplen) - ERREXIT(cinfo, JERR_BMP_OUTOFRANGE); - outptr[rindex] = colormap[0][t]; - outptr[gindex] = colormap[1][t]; - outptr[bindex] = colormap[2][t]; - outptr += ps; - } - } - } - - return 1; -} - - -METHODDEF(JDIMENSION) -get_24bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 24-bit pixels */ -{ - bmp_source_ptr source = (bmp_source_ptr)sinfo; - JSAMPARRAY image_ptr; - register JSAMPROW inptr, outptr; - register JDIMENSION col; - - if (source->use_inversion_array) { - /* Fetch next row from virtual array */ - source->source_row--; - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr)cinfo, source->whole_image, - source->source_row, (JDIMENSION)1, FALSE); - inptr = image_ptr[0]; - } else { - if (!ReadOK(source->pub.input_file, source->iobuffer, source->row_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - inptr = source->iobuffer; - } - - /* Transfer data. Note source values are in BGR order - * (even though Microsoft's own documents say the opposite). - */ - outptr = source->pub.buffer[0]; - if (cinfo->in_color_space == JCS_EXT_BGR) { - memcpy(outptr, inptr, source->row_width); - } else if (cinfo->in_color_space == JCS_CMYK) { - for (col = cinfo->image_width; col > 0; col--) { - JSAMPLE b = *inptr++, g = *inptr++, r = *inptr++; - rgb_to_cmyk(r, g, b, outptr, outptr + 1, outptr + 2, outptr + 3); - outptr += 4; - } - } else { - register int rindex = rgb_red[cinfo->in_color_space]; - register int gindex = rgb_green[cinfo->in_color_space]; - register int bindex = rgb_blue[cinfo->in_color_space]; - register int aindex = alpha_index[cinfo->in_color_space]; - register int ps = rgb_pixelsize[cinfo->in_color_space]; - - if (aindex >= 0) { - for (col = cinfo->image_width; col > 0; col--) { - outptr[bindex] = *inptr++; - outptr[gindex] = *inptr++; - outptr[rindex] = *inptr++; - outptr[aindex] = 0xFF; - outptr += ps; - } - } else { - for (col = cinfo->image_width; col > 0; col--) { - outptr[bindex] = *inptr++; - outptr[gindex] = *inptr++; - outptr[rindex] = *inptr++; - outptr += ps; - } - } - } - - return 1; -} - - -METHODDEF(JDIMENSION) -get_32bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 32-bit pixels */ -{ - bmp_source_ptr source = (bmp_source_ptr)sinfo; - JSAMPARRAY image_ptr; - register JSAMPROW inptr, outptr; - register JDIMENSION col; - - if (source->use_inversion_array) { - /* Fetch next row from virtual array */ - source->source_row--; - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr)cinfo, source->whole_image, - source->source_row, (JDIMENSION)1, FALSE); - inptr = image_ptr[0]; - } else { - if (!ReadOK(source->pub.input_file, source->iobuffer, source->row_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - inptr = source->iobuffer; - } - - /* Transfer data. Note source values are in BGR order - * (even though Microsoft's own documents say the opposite). - */ - outptr = source->pub.buffer[0]; - if (cinfo->in_color_space == JCS_EXT_BGRX || - cinfo->in_color_space == JCS_EXT_BGRA) { - memcpy(outptr, inptr, source->row_width); - } else if (cinfo->in_color_space == JCS_CMYK) { - for (col = cinfo->image_width; col > 0; col--) { - JSAMPLE b = *inptr++, g = *inptr++, r = *inptr++; - rgb_to_cmyk(r, g, b, outptr, outptr + 1, outptr + 2, outptr + 3); - inptr++; /* skip the 4th byte (Alpha channel) */ - outptr += 4; - } - } else { - register int rindex = rgb_red[cinfo->in_color_space]; - register int gindex = rgb_green[cinfo->in_color_space]; - register int bindex = rgb_blue[cinfo->in_color_space]; - register int aindex = alpha_index[cinfo->in_color_space]; - register int ps = rgb_pixelsize[cinfo->in_color_space]; - - if (aindex >= 0) { - for (col = cinfo->image_width; col > 0; col--) { - outptr[bindex] = *inptr++; - outptr[gindex] = *inptr++; - outptr[rindex] = *inptr++; - outptr[aindex] = *inptr++; - outptr += ps; - } - } else { - for (col = cinfo->image_width; col > 0; col--) { - outptr[bindex] = *inptr++; - outptr[gindex] = *inptr++; - outptr[rindex] = *inptr++; - inptr++; /* skip the 4th byte (Alpha channel) */ - outptr += ps; - } - } - } - - return 1; -} - - -/* - * This method loads the image into whole_image during the first call on - * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call - * get_8bit_row, get_24bit_row, or get_32bit_row on subsequent calls. - */ - -METHODDEF(JDIMENSION) -preload_image(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - bmp_source_ptr source = (bmp_source_ptr)sinfo; - register FILE *infile = source->pub.input_file; - register JSAMPROW out_ptr; - JSAMPARRAY image_ptr; - JDIMENSION row; - cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress; - - /* Read the data into a virtual array in input-file row order. */ - for (row = 0; row < cinfo->image_height; row++) { - if (progress != NULL) { - progress->pub.pass_counter = (long)row; - progress->pub.pass_limit = (long)cinfo->image_height; - (*progress->pub.progress_monitor) ((j_common_ptr)cinfo); - } - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr)cinfo, source->whole_image, row, (JDIMENSION)1, TRUE); - out_ptr = image_ptr[0]; - if (fread(out_ptr, 1, source->row_width, infile) != source->row_width) { - if (feof(infile)) - ERREXIT(cinfo, JERR_INPUT_EOF); - else - ERREXIT(cinfo, JERR_FILE_READ); - } - } - if (progress != NULL) - progress->completed_extra_passes++; - - /* Set up to read from the virtual array in top-to-bottom order */ - switch (source->bits_per_pixel) { - case 8: - source->pub.get_pixel_rows = get_8bit_row; - break; - case 24: - source->pub.get_pixel_rows = get_24bit_row; - break; - case 32: - source->pub.get_pixel_rows = get_32bit_row; - break; - default: - ERREXIT(cinfo, JERR_BMP_BADDEPTH); - } - source->source_row = cinfo->image_height; - - /* And read the first row */ - return (*source->pub.get_pixel_rows) (cinfo, sinfo); -} - - -/* - * Read the file header; return image size and component count. - */ - -METHODDEF(void) -start_input_bmp(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - bmp_source_ptr source = (bmp_source_ptr)sinfo; - U_CHAR bmpfileheader[14]; - U_CHAR bmpinfoheader[64]; - -#define GET_2B(array, offset) \ - ((unsigned short)UCH(array[offset]) + \ - (((unsigned short)UCH(array[offset + 1])) << 8)) -#define GET_4B(array, offset) \ - ((unsigned int)UCH(array[offset]) + \ - (((unsigned int)UCH(array[offset + 1])) << 8) + \ - (((unsigned int)UCH(array[offset + 2])) << 16) + \ - (((unsigned int)UCH(array[offset + 3])) << 24)) - - int bfOffBits; - int headerSize; - int biWidth; - int biHeight; - unsigned short biPlanes; - unsigned int biCompression; - int biXPelsPerMeter, biYPelsPerMeter; - int biClrUsed = 0; - int mapentrysize = 0; /* 0 indicates no colormap */ - int bPad; - JDIMENSION row_width = 0; - - /* Read and verify the bitmap file header */ - if (!ReadOK(source->pub.input_file, bmpfileheader, 14)) - ERREXIT(cinfo, JERR_INPUT_EOF); - if (GET_2B(bmpfileheader, 0) != 0x4D42) /* 'BM' */ - ERREXIT(cinfo, JERR_BMP_NOT); - bfOffBits = GET_4B(bmpfileheader, 10); - /* We ignore the remaining fileheader fields */ - - /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows), - * or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which. - */ - if (!ReadOK(source->pub.input_file, bmpinfoheader, 4)) - ERREXIT(cinfo, JERR_INPUT_EOF); - headerSize = GET_4B(bmpinfoheader, 0); - if (headerSize < 12 || headerSize > 64 || (headerSize + 14) > bfOffBits) - ERREXIT(cinfo, JERR_BMP_BADHEADER); - if (!ReadOK(source->pub.input_file, bmpinfoheader + 4, headerSize - 4)) - ERREXIT(cinfo, JERR_INPUT_EOF); - - switch (headerSize) { - case 12: - /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */ - biWidth = (int)GET_2B(bmpinfoheader, 4); - biHeight = (int)GET_2B(bmpinfoheader, 6); - biPlanes = GET_2B(bmpinfoheader, 8); - source->bits_per_pixel = (int)GET_2B(bmpinfoheader, 10); - - switch (source->bits_per_pixel) { - case 8: /* colormapped image */ - mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */ - TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, biWidth, biHeight); - break; - case 24: /* RGB image */ - case 32: /* RGB image + Alpha channel */ - TRACEMS3(cinfo, 1, JTRC_BMP_OS2, biWidth, biHeight, - source->bits_per_pixel); - break; - default: - ERREXIT(cinfo, JERR_BMP_BADDEPTH); - break; - } - break; - case 40: - case 64: - /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */ - /* or OS/2 2.x header, which has additional fields that we ignore */ - biWidth = (int)GET_4B(bmpinfoheader, 4); - biHeight = (int)GET_4B(bmpinfoheader, 8); - biPlanes = GET_2B(bmpinfoheader, 12); - source->bits_per_pixel = (int)GET_2B(bmpinfoheader, 14); - biCompression = GET_4B(bmpinfoheader, 16); - biXPelsPerMeter = (int)GET_4B(bmpinfoheader, 24); - biYPelsPerMeter = (int)GET_4B(bmpinfoheader, 28); - biClrUsed = GET_4B(bmpinfoheader, 32); - /* biSizeImage, biClrImportant fields are ignored */ - - switch (source->bits_per_pixel) { - case 8: /* colormapped image */ - mapentrysize = 4; /* Windows uses RGBQUAD colormap */ - TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, biWidth, biHeight); - break; - case 24: /* RGB image */ - case 32: /* RGB image + Alpha channel */ - TRACEMS3(cinfo, 1, JTRC_BMP, biWidth, biHeight, source->bits_per_pixel); - break; - default: - ERREXIT(cinfo, JERR_BMP_BADDEPTH); - break; - } - if (biCompression != 0) - ERREXIT(cinfo, JERR_BMP_COMPRESSED); - - if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) { - /* Set JFIF density parameters from the BMP data */ - cinfo->X_density = (UINT16)(biXPelsPerMeter / 100); /* 100 cm per meter */ - cinfo->Y_density = (UINT16)(biYPelsPerMeter / 100); - cinfo->density_unit = 2; /* dots/cm */ - } - break; - default: - ERREXIT(cinfo, JERR_BMP_BADHEADER); - return; - } - - if (biWidth <= 0 || biHeight <= 0) - ERREXIT(cinfo, JERR_BMP_EMPTY); - if (sinfo->max_pixels && - (unsigned long long)biWidth * biHeight > sinfo->max_pixels) - ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); - if (biPlanes != 1) - ERREXIT(cinfo, JERR_BMP_BADPLANES); - - /* Compute distance to bitmap data --- will adjust for colormap below */ - bPad = bfOffBits - (headerSize + 14); - - /* Read the colormap, if any */ - if (mapentrysize > 0) { - if (biClrUsed <= 0) - biClrUsed = 256; /* assume it's 256 */ - else if (biClrUsed > 256) - ERREXIT(cinfo, JERR_BMP_BADCMAP); - /* Allocate space to store the colormap */ - source->colormap = (*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, (JDIMENSION)biClrUsed, (JDIMENSION)3); - source->cmap_length = (int)biClrUsed; - /* and read it from the file */ - read_colormap(source, (int)biClrUsed, mapentrysize); - /* account for size of colormap */ - bPad -= biClrUsed * mapentrysize; - } - - /* Skip any remaining pad bytes */ - if (bPad < 0) /* incorrect bfOffBits value? */ - ERREXIT(cinfo, JERR_BMP_BADHEADER); - while (--bPad >= 0) { - (void)read_byte(source); - } - - /* Compute row width in file, including padding to 4-byte boundary */ - switch (source->bits_per_pixel) { - case 8: - if (cinfo->in_color_space == JCS_UNKNOWN) - cinfo->in_color_space = JCS_EXT_RGB; - if (IsExtRGB(cinfo->in_color_space)) - cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; - else if (cinfo->in_color_space == JCS_GRAYSCALE) - cinfo->input_components = 1; - else if (cinfo->in_color_space == JCS_CMYK) - cinfo->input_components = 4; - else - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); - row_width = (JDIMENSION)biWidth; - break; - case 24: - if (cinfo->in_color_space == JCS_UNKNOWN) - cinfo->in_color_space = JCS_EXT_BGR; - if (IsExtRGB(cinfo->in_color_space)) - cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; - else if (cinfo->in_color_space == JCS_CMYK) - cinfo->input_components = 4; - else - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); - if ((unsigned long long)biWidth * 3ULL > 0xFFFFFFFFULL) - ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); - row_width = (JDIMENSION)biWidth * 3; - break; - case 32: - if (cinfo->in_color_space == JCS_UNKNOWN) - cinfo->in_color_space = JCS_EXT_BGRA; - if (IsExtRGB(cinfo->in_color_space)) - cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; - else if (cinfo->in_color_space == JCS_CMYK) - cinfo->input_components = 4; - else - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); - if ((unsigned long long)biWidth * 4ULL > 0xFFFFFFFFULL) - ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); - row_width = (JDIMENSION)biWidth * 4; - break; - default: - ERREXIT(cinfo, JERR_BMP_BADDEPTH); - } - while ((row_width & 3) != 0) row_width++; - source->row_width = row_width; - - if (source->use_inversion_array) { - /* Allocate space for inversion array, prepare for preload pass */ - source->whole_image = (*cinfo->mem->request_virt_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, - row_width, (JDIMENSION)biHeight, (JDIMENSION)1); - source->pub.get_pixel_rows = preload_image; - if (cinfo->progress != NULL) { - cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress; - progress->total_extra_passes++; /* count file input as separate pass */ - } - } else { - source->iobuffer = (U_CHAR *) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, row_width); - switch (source->bits_per_pixel) { - case 8: - source->pub.get_pixel_rows = get_8bit_row; - break; - case 24: - source->pub.get_pixel_rows = get_24bit_row; - break; - case 32: - source->pub.get_pixel_rows = get_32bit_row; - break; - default: - ERREXIT(cinfo, JERR_BMP_BADDEPTH); - } - } - - /* Ensure that biWidth * cinfo->input_components doesn't exceed the maximum - value of the JDIMENSION type. This is only a danger with BMP files, since - their width and height fields are 32-bit integers. */ - if ((unsigned long long)biWidth * - (unsigned long long)cinfo->input_components > 0xFFFFFFFFULL) - ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); - /* Allocate one-row buffer for returned data */ - source->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, - (JDIMENSION)biWidth * (JDIMENSION)cinfo->input_components, (JDIMENSION)1); - source->pub.buffer_height = 1; - - cinfo->data_precision = 8; - cinfo->image_width = (JDIMENSION)biWidth; - cinfo->image_height = (JDIMENSION)biHeight; -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_input_bmp(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - /* no work */ -} - - -/* - * The module selection routine for BMP format input. - */ - -GLOBAL(cjpeg_source_ptr) -jinit_read_bmp(j_compress_ptr cinfo, boolean use_inversion_array) -{ - bmp_source_ptr source; - - if (cinfo->data_precision != 8) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); - - /* Create module interface object */ - source = (bmp_source_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - sizeof(bmp_source_struct)); - source->cinfo = cinfo; /* make back link for subroutines */ - /* Fill in method ptrs, except get_pixel_rows which start_input sets */ - source->pub.start_input = start_input_bmp; - source->pub.finish_input = finish_input_bmp; - source->pub.max_pixels = 0; - - source->use_inversion_array = use_inversion_array; - - return (cjpeg_source_ptr)source; -} - -#endif /* BMP_SUPPORTED */ diff --git a/3rdparty/libjpeg-turbo/src/rdcolmap.c b/3rdparty/libjpeg-turbo/src/rdcolmap.c deleted file mode 100644 index 836685e1b8..0000000000 --- a/3rdparty/libjpeg-turbo/src/rdcolmap.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * rdcolmap.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1994-1996, Thomas G. Lane. - * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file implements djpeg's "-map file" switch. It reads a source image - * and constructs a colormap to be supplied to the JPEG decompressor. - * - * Currently, these file formats are supported for the map file: - * GIF: the contents of the GIF's global colormap are used. - * PPM (either text or raw flavor): the entire file is read and - * each unique pixel value is entered in the map. - * Note that reading a large PPM file will be horrendously slow. - * Typically, a PPM-format map file should contain just one pixel - * of each desired color. Such a file can be extracted from an - * ordinary image PPM file with ppmtomap(1). - * - * Rescaling a PPM that has a maxval unequal to _MAXJSAMPLE is not - * currently implemented. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include "jsamplecomp.h" - -#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ -#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) - -/* Portions of this code are based on the PBMPLUS library, which is: -** -** Copyright (C) 1988 by Jef Poskanzer. -** -** Permission to use, copy, modify, and distribute this software and its -** documentation for any purpose and without fee is hereby granted, provided -** that the above copyright notice appear in all copies and that both that -** copyright notice and this permission notice appear in supporting -** documentation. This software is provided "as is" without express or -** implied warranty. -*/ - - -/* - * Add a (potentially) new color to the color map. - */ - -LOCAL(void) -add_map_entry(j_decompress_ptr cinfo, int R, int G, int B) -{ - _JSAMPROW colormap0 = ((_JSAMPARRAY)cinfo->colormap)[0]; - _JSAMPROW colormap1 = ((_JSAMPARRAY)cinfo->colormap)[1]; - _JSAMPROW colormap2 = ((_JSAMPARRAY)cinfo->colormap)[2]; - int ncolors = cinfo->actual_number_of_colors; - int index; - - /* Check for duplicate color. */ - for (index = 0; index < ncolors; index++) { - if (colormap0[index] == R && colormap1[index] == G && - colormap2[index] == B) - return; /* color is already in map */ - } - - /* Check for map overflow. */ - if (ncolors >= (_MAXJSAMPLE + 1)) - ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (_MAXJSAMPLE + 1)); - - /* OK, add color to map. */ - colormap0[ncolors] = (_JSAMPLE)R; - colormap1[ncolors] = (_JSAMPLE)G; - colormap2[ncolors] = (_JSAMPLE)B; - cinfo->actual_number_of_colors++; -} - - -/* - * Extract color map from a GIF file. - */ - -LOCAL(void) -read_gif_map(j_decompress_ptr cinfo, FILE *infile) -{ - int header[13]; - int i, colormaplen; - int R, G, B; - - /* Initial 'G' has already been read by read_color_map */ - /* Read the rest of the GIF header and logical screen descriptor */ - for (i = 1; i < 13; i++) { - if ((header[i] = getc(infile)) == EOF) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - } - - /* Verify GIF Header */ - if (header[1] != 'I' || header[2] != 'F') - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - /* There must be a global color map. */ - if ((header[10] & 0x80) == 0) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - /* OK, fetch it. */ - colormaplen = 2 << (header[10] & 0x07); - - for (i = 0; i < colormaplen; i++) { - R = getc(infile); - G = getc(infile); - B = getc(infile); - if (R == EOF || G == EOF || B == EOF) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - add_map_entry(cinfo, - R << (BITS_IN_JSAMPLE - 8), - G << (BITS_IN_JSAMPLE - 8), - B << (BITS_IN_JSAMPLE - 8)); - } -} - - -/* Support routines for reading PPM */ - - -LOCAL(int) -pbm_getc(FILE *infile) -/* Read next char, skipping over any comments */ -/* A comment/newline sequence is returned as a newline */ -{ - register int ch; - - ch = getc(infile); - if (ch == '#') { - do { - ch = getc(infile); - } while (ch != '\n' && ch != EOF); - } - return ch; -} - - -LOCAL(unsigned int) -read_pbm_integer(j_decompress_ptr cinfo, FILE *infile) -/* Read an unsigned decimal integer from the PPM file */ -/* Swallows one trailing character after the integer */ -/* Note that on a 16-bit-int machine, only values up to 64k can be read. */ -/* This should not be a problem in practice. */ -{ - register int ch; - register unsigned int val; - - /* Skip any leading whitespace */ - do { - ch = pbm_getc(infile); - if (ch == EOF) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); - - if (ch < '0' || ch > '9') - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - val = ch - '0'; - while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { - val *= 10; - val += ch - '0'; - } - return val; -} - - -/* - * Extract color map from a PPM file. - */ - -LOCAL(void) -read_ppm_map(j_decompress_ptr cinfo, FILE *infile) -{ - int c; - unsigned int w, h, maxval, row, col; - int R, G, B; - - /* Initial 'P' has already been read by read_color_map */ - c = getc(infile); /* save format discriminator for a sec */ - - /* while we fetch the remaining header info */ - w = read_pbm_integer(cinfo, infile); - h = read_pbm_integer(cinfo, infile); - maxval = read_pbm_integer(cinfo, infile); - - if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - /* For now, we don't support rescaling from an unusual maxval. */ - if (maxval != (unsigned int)_MAXJSAMPLE) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - - switch (c) { - case '3': /* it's a text-format PPM file */ - for (row = 0; row < h; row++) { - for (col = 0; col < w; col++) { - R = read_pbm_integer(cinfo, infile); - G = read_pbm_integer(cinfo, infile); - B = read_pbm_integer(cinfo, infile); - add_map_entry(cinfo, R, G, B); - } - } - break; - - case '6': /* it's a raw-format PPM file */ - for (row = 0; row < h; row++) { - for (col = 0; col < w; col++) { - R = getc(infile); - G = getc(infile); - B = getc(infile); - if (R == EOF || G == EOF || B == EOF) - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - add_map_entry(cinfo, R, G, B); - } - } - break; - - default: - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - break; - } -} - - -/* - * Main entry point from djpeg.c. - * Input: opened input file (from file name argument on command line). - * Output: colormap and actual_number_of_colors fields are set in cinfo. - */ - -GLOBAL(void) -_read_color_map(j_decompress_ptr cinfo, FILE *infile) -{ - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); - - /* Allocate space for a color map of maximum supported size. */ - cinfo->colormap = (*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, - (JDIMENSION)(_MAXJSAMPLE + 1), (JDIMENSION)3); - cinfo->actual_number_of_colors = 0; /* initialize map to empty */ - - /* Read first byte to determine file format */ - switch (getc(infile)) { - case 'G': - read_gif_map(cinfo, infile); - break; - case 'P': - read_ppm_map(cinfo, infile); - break; - default: - ERREXIT(cinfo, JERR_BAD_CMAP_FILE); - break; - } -} - -#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */ -#endif /* QUANT_2PASS_SUPPORTED */ diff --git a/3rdparty/libjpeg-turbo/src/rdgif.c b/3rdparty/libjpeg-turbo/src/rdgif.c deleted file mode 100644 index 23e8b9e128..0000000000 --- a/3rdparty/libjpeg-turbo/src/rdgif.c +++ /dev/null @@ -1,720 +0,0 @@ -/* - * rdgif.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1991-1997, Thomas G. Lane. - * Modified 2019 by Guido Vollbeding. - * libjpeg-turbo Modifications: - * Copyright (C) 2021-2023, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains routines to read input images in GIF format. - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume input from - * an ordinary stdio stream. They further assume that reading begins - * at the start of the file; start_input may need work if the - * user interface has already read some data (e.g., to determine that - * the file is indeed GIF format). - */ - -/* - * This code is loosely based on giftoppm from the PBMPLUS distribution - * of Feb. 1991. That file contains the following copyright notice: - * +-------------------------------------------------------------------+ - * | Copyright 1990, David Koblas. | - * | Permission to use, copy, modify, and distribute this software | - * | and its documentation for any purpose and without fee is hereby | - * | granted, provided that the above copyright notice appear in all | - * | copies and that both that copyright notice and this permission | - * | notice appear in supporting documentation. This software is | - * | provided "as is" without express or implied warranty. | - * +-------------------------------------------------------------------+ - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include "jsamplecomp.h" - -#if defined(GIF_SUPPORTED) && \ - (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) - - -/* Macros to deal with unsigned chars as efficiently as compiler allows */ - -typedef unsigned char U_CHAR; -#define UCH(x) ((int)(x)) - - -#define ReadOK(file, buffer, len) \ - (fread(buffer, 1, len, file) == ((size_t)(len))) - - -#define MAXCOLORMAPSIZE 256 /* max # of colors in a GIF colormap */ -#define NUMCOLORS 3 /* # of colors */ -#define CM_RED 0 /* color component numbers */ -#define CM_GREEN 1 -#define CM_BLUE 2 - -#define MAX_LZW_BITS 12 /* maximum LZW code size */ -#define LZW_TABLE_SIZE (1 << MAX_LZW_BITS) /* # of possible LZW symbols */ - -/* Macros for extracting header data --- note we assume chars may be signed */ - -#define LM_to_uint(array, offset) \ - ((unsigned int)UCH(array[offset]) + \ - (((unsigned int)UCH(array[offset + 1])) << 8)) - -#define BitSet(byte, bit) ((byte) & (bit)) -#define INTERLACE 0x40 /* mask for bit signifying interlaced image */ -#define COLORMAPFLAG 0x80 /* mask for bit signifying colormap presence */ - - -/* - * LZW decompression tables look like this: - * symbol_head[K] = prefix symbol of any LZW symbol K (0..LZW_TABLE_SIZE-1) - * symbol_tail[K] = suffix byte of any LZW symbol K (0..LZW_TABLE_SIZE-1) - * Note that entries 0..end_code of the above tables are not used, - * since those symbols represent raw bytes or special codes. - * - * The stack represents the not-yet-used expansion of the last LZW symbol. - * In the worst case, a symbol could expand to as many bytes as there are - * LZW symbols, so we allocate LZW_TABLE_SIZE bytes for the stack. - * (This is conservative since that number includes the raw-byte symbols.) - */ - - -/* Private version of data source object */ - -typedef struct { - struct cjpeg_source_struct pub; /* public fields */ - - j_compress_ptr cinfo; /* back link saves passing separate parm */ - - _JSAMPARRAY colormap; /* GIF colormap (converted to my format) */ - - /* State for GetCode and LZWReadByte */ - U_CHAR code_buf[256 + 4]; /* current input data block */ - int last_byte; /* # of bytes in code_buf */ - int last_bit; /* # of bits in code_buf */ - int cur_bit; /* next bit index to read */ - boolean first_time; /* flags first call to GetCode */ - boolean out_of_blocks; /* TRUE if hit terminator data block */ - - int input_code_size; /* codesize given in GIF file */ - int clear_code, end_code; /* values for Clear and End codes */ - - int code_size; /* current actual code size */ - int limit_code; /* 2^code_size */ - int max_code; /* first unused code value */ - - /* Private state for LZWReadByte */ - int oldcode; /* previous LZW symbol */ - int firstcode; /* first byte of oldcode's expansion */ - - /* LZW symbol table and expansion stack */ - UINT16 *symbol_head; /* => table of prefix symbols */ - UINT8 *symbol_tail; /* => table of suffix bytes */ - UINT8 *symbol_stack; /* => stack for symbol expansions */ - UINT8 *sp; /* stack pointer */ - - /* State for interlaced image processing */ - boolean is_interlaced; /* TRUE if have interlaced image */ - jvirt_sarray_ptr interlaced_image; /* full image in interlaced order */ - JDIMENSION cur_row_number; /* need to know actual row number */ - JDIMENSION pass2_offset; /* # of pixel rows in pass 1 */ - JDIMENSION pass3_offset; /* # of pixel rows in passes 1&2 */ - JDIMENSION pass4_offset; /* # of pixel rows in passes 1,2,3 */ -} gif_source_struct; - -typedef gif_source_struct *gif_source_ptr; - - -/* Forward declarations */ -METHODDEF(JDIMENSION) get_pixel_rows(j_compress_ptr cinfo, - cjpeg_source_ptr sinfo); -METHODDEF(JDIMENSION) load_interlaced_image(j_compress_ptr cinfo, - cjpeg_source_ptr sinfo); -METHODDEF(JDIMENSION) get_interlaced_row(j_compress_ptr cinfo, - cjpeg_source_ptr sinfo); - - -LOCAL(int) -ReadByte(gif_source_ptr sinfo) -/* Read next byte from GIF file */ -{ - register FILE *infile = sinfo->pub.input_file; - register int c; - - if ((c = getc(infile)) == EOF) - ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); - return c; -} - - -LOCAL(int) -GetDataBlock(gif_source_ptr sinfo, U_CHAR *buf) -/* Read a GIF data block, which has a leading count byte */ -/* A zero-length block marks the end of a data block sequence */ -{ - int count; - - count = ReadByte(sinfo); - if (count > 0) { - if (!ReadOK(sinfo->pub.input_file, buf, count)) - ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); - } - return count; -} - - -LOCAL(void) -SkipDataBlocks(gif_source_ptr sinfo) -/* Skip a series of data blocks, until a block terminator is found */ -{ - U_CHAR buf[256]; - - while (GetDataBlock(sinfo, buf) > 0) - /* skip */; -} - - -LOCAL(void) -ReInitLZW(gif_source_ptr sinfo) -/* (Re)initialize LZW state; shared code for startup and Clear processing */ -{ - sinfo->code_size = sinfo->input_code_size + 1; - sinfo->limit_code = sinfo->clear_code << 1; /* 2^code_size */ - sinfo->max_code = sinfo->clear_code + 2; /* first unused code value */ - sinfo->sp = sinfo->symbol_stack; /* init stack to empty */ -} - - -LOCAL(void) -InitLZWCode(gif_source_ptr sinfo) -/* Initialize for a series of LZWReadByte (and hence GetCode) calls */ -{ - /* GetCode initialization */ - sinfo->last_byte = 2; /* make safe to "recopy last two bytes" */ - sinfo->code_buf[0] = 0; - sinfo->code_buf[1] = 0; - sinfo->last_bit = 0; /* nothing in the buffer */ - sinfo->cur_bit = 0; /* force buffer load on first call */ - sinfo->first_time = TRUE; - sinfo->out_of_blocks = FALSE; - - /* LZWReadByte initialization: */ - /* compute special code values (note that these do not change later) */ - sinfo->clear_code = 1 << sinfo->input_code_size; - sinfo->end_code = sinfo->clear_code + 1; - ReInitLZW(sinfo); -} - - -LOCAL(int) -GetCode(gif_source_ptr sinfo) -/* Fetch the next code_size bits from the GIF data */ -/* We assume code_size is less than 16 */ -{ - register int accum; - int offs, count; - - while (sinfo->cur_bit + sinfo->code_size > sinfo->last_bit) { - /* Time to reload the buffer */ - /* First time, share code with Clear case */ - if (sinfo->first_time) { - sinfo->first_time = FALSE; - return sinfo->clear_code; - } - if (sinfo->out_of_blocks) { - WARNMS(sinfo->cinfo, JWRN_GIF_NOMOREDATA); - return sinfo->end_code; /* fake something useful */ - } - /* preserve last two bytes of what we have -- assume code_size <= 16 */ - sinfo->code_buf[0] = sinfo->code_buf[sinfo->last_byte-2]; - sinfo->code_buf[1] = sinfo->code_buf[sinfo->last_byte-1]; - /* Load more bytes; set flag if we reach the terminator block */ - if ((count = GetDataBlock(sinfo, &sinfo->code_buf[2])) == 0) { - sinfo->out_of_blocks = TRUE; - WARNMS(sinfo->cinfo, JWRN_GIF_NOMOREDATA); - return sinfo->end_code; /* fake something useful */ - } - /* Reset counters */ - sinfo->cur_bit = (sinfo->cur_bit - sinfo->last_bit) + 16; - sinfo->last_byte = 2 + count; - sinfo->last_bit = sinfo->last_byte * 8; - } - - /* Form up next 24 bits in accum */ - offs = sinfo->cur_bit >> 3; /* byte containing cur_bit */ - accum = UCH(sinfo->code_buf[offs + 2]); - accum <<= 8; - accum |= UCH(sinfo->code_buf[offs + 1]); - accum <<= 8; - accum |= UCH(sinfo->code_buf[offs]); - - /* Right-align cur_bit in accum, then mask off desired number of bits */ - accum >>= (sinfo->cur_bit & 7); - sinfo->cur_bit += sinfo->code_size; - return accum & ((1 << sinfo->code_size) - 1); -} - - -LOCAL(int) -LZWReadByte(gif_source_ptr sinfo) -/* Read an LZW-compressed byte */ -{ - register int code; /* current working code */ - int incode; /* saves actual input code */ - - /* If any codes are stacked from a previously read symbol, return them */ - if (sinfo->sp > sinfo->symbol_stack) - return (int)(*(--sinfo->sp)); - - /* Time to read a new symbol */ - code = GetCode(sinfo); - - if (code == sinfo->clear_code) { - /* Reinit state, swallow any extra Clear codes, and */ - /* return next code, which is expected to be a raw byte. */ - ReInitLZW(sinfo); - do { - code = GetCode(sinfo); - } while (code == sinfo->clear_code); - if (code > sinfo->clear_code) { /* make sure it is a raw byte */ - WARNMS(sinfo->cinfo, JWRN_GIF_BADDATA); - code = 0; /* use something valid */ - } - /* make firstcode, oldcode valid! */ - sinfo->firstcode = sinfo->oldcode = code; - return code; - } - - if (code == sinfo->end_code) { - /* Skip the rest of the image, unless GetCode already read terminator */ - if (!sinfo->out_of_blocks) { - SkipDataBlocks(sinfo); - sinfo->out_of_blocks = TRUE; - } - /* Complain that there's not enough data */ - WARNMS(sinfo->cinfo, JWRN_GIF_ENDCODE); - /* Pad data with 0's */ - return 0; /* fake something usable */ - } - - /* Got normal raw byte or LZW symbol */ - incode = code; /* save for a moment */ - - if (code >= sinfo->max_code) { /* special case for not-yet-defined symbol */ - /* code == max_code is OK; anything bigger is bad data */ - if (code > sinfo->max_code) { - WARNMS(sinfo->cinfo, JWRN_GIF_BADDATA); - incode = 0; /* prevent creation of loops in symbol table */ - } - /* this symbol will be defined as oldcode/firstcode */ - *(sinfo->sp++) = (UINT8)sinfo->firstcode; - code = sinfo->oldcode; - } - - /* If it's a symbol, expand it into the stack */ - while (code >= sinfo->clear_code) { - *(sinfo->sp++) = sinfo->symbol_tail[code]; /* tail is a byte value */ - code = sinfo->symbol_head[code]; /* head is another LZW symbol */ - } - /* At this point code just represents a raw byte */ - sinfo->firstcode = code; /* save for possible future use */ - - /* If there's room in table... */ - if ((code = sinfo->max_code) < LZW_TABLE_SIZE) { - /* Define a new symbol = prev sym + head of this sym's expansion */ - sinfo->symbol_head[code] = (UINT16)sinfo->oldcode; - sinfo->symbol_tail[code] = (UINT8)sinfo->firstcode; - sinfo->max_code++; - /* Is it time to increase code_size? */ - if (sinfo->max_code >= sinfo->limit_code && - sinfo->code_size < MAX_LZW_BITS) { - sinfo->code_size++; - sinfo->limit_code <<= 1; /* keep equal to 2^code_size */ - } - } - - sinfo->oldcode = incode; /* save last input symbol for future use */ - return sinfo->firstcode; /* return first byte of symbol's expansion */ -} - - -LOCAL(void) -ReadColorMap(gif_source_ptr sinfo, int cmaplen, _JSAMPARRAY cmap) -/* Read a GIF colormap */ -{ - int i, gray = 1; - - for (i = 0; i < cmaplen; i++) { -#if BITS_IN_JSAMPLE == 8 -#define UPSCALE(x) (x) -#else -#define UPSCALE(x) ((x) << (BITS_IN_JSAMPLE - 8)) -#endif - cmap[CM_RED][i] = (_JSAMPLE)UPSCALE(ReadByte(sinfo)); - cmap[CM_GREEN][i] = (_JSAMPLE)UPSCALE(ReadByte(sinfo)); - cmap[CM_BLUE][i] = (_JSAMPLE)UPSCALE(ReadByte(sinfo)); - if (cmap[CM_RED][i] != cmap[CM_GREEN][i] || - cmap[CM_GREEN][i] != cmap[CM_BLUE][i]) - gray = 0; - } - - if (sinfo->cinfo->in_color_space == JCS_RGB && gray) { - sinfo->cinfo->in_color_space = JCS_GRAYSCALE; - sinfo->cinfo->input_components = 1; - } -} - - -LOCAL(void) -DoExtension(gif_source_ptr sinfo) -/* Process an extension block */ -/* Currently we ignore 'em all */ -{ - int extlabel; - - /* Read extension label byte */ - extlabel = ReadByte(sinfo); - TRACEMS1(sinfo->cinfo, 1, JTRC_GIF_EXTENSION, extlabel); - /* Skip the data block(s) associated with the extension */ - SkipDataBlocks(sinfo); -} - - -/* - * Read the file header; return image size and component count. - */ - -METHODDEF(void) -start_input_gif(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - gif_source_ptr source = (gif_source_ptr)sinfo; - U_CHAR hdrbuf[10]; /* workspace for reading control blocks */ - unsigned int width, height; /* image dimensions */ - int colormaplen, aspectRatio; - int c; - - /* Read and verify GIF Header */ - if (!ReadOK(source->pub.input_file, hdrbuf, 6)) - ERREXIT(cinfo, JERR_GIF_NOT); - if (hdrbuf[0] != 'G' || hdrbuf[1] != 'I' || hdrbuf[2] != 'F') - ERREXIT(cinfo, JERR_GIF_NOT); - /* Check for expected version numbers. - * If unknown version, give warning and try to process anyway; - * this is per recommendation in GIF89a standard. - */ - if ((hdrbuf[3] != '8' || hdrbuf[4] != '7' || hdrbuf[5] != 'a') && - (hdrbuf[3] != '8' || hdrbuf[4] != '9' || hdrbuf[5] != 'a')) - TRACEMS3(cinfo, 1, JTRC_GIF_BADVERSION, hdrbuf[3], hdrbuf[4], hdrbuf[5]); - - /* Read and decipher Logical Screen Descriptor */ - if (!ReadOK(source->pub.input_file, hdrbuf, 7)) - ERREXIT(cinfo, JERR_INPUT_EOF); - width = LM_to_uint(hdrbuf, 0); - height = LM_to_uint(hdrbuf, 2); - if (width == 0 || height == 0) - ERREXIT(cinfo, JERR_GIF_EMPTY); - if (sinfo->max_pixels && - (unsigned long long)width * height > sinfo->max_pixels) - ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); - /* we ignore the color resolution, sort flag, and background color index */ - aspectRatio = UCH(hdrbuf[6]); - if (aspectRatio != 0 && aspectRatio != 49) - TRACEMS(cinfo, 1, JTRC_GIF_NONSQUARE); - - /* Allocate space to store the colormap */ - source->colormap = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, (JDIMENSION)MAXCOLORMAPSIZE, - (JDIMENSION)NUMCOLORS); - colormaplen = 0; /* indicate initialization */ - - /* Read global colormap if header indicates it is present */ - if (BitSet(hdrbuf[4], COLORMAPFLAG)) { - colormaplen = 2 << (hdrbuf[4] & 0x07); - ReadColorMap(source, colormaplen, source->colormap); - } - - /* Scan until we reach start of desired image. - * We don't currently support skipping images, but could add it easily. - */ - for (;;) { - c = ReadByte(source); - - if (c == ';') /* GIF terminator?? */ - ERREXIT(cinfo, JERR_GIF_IMAGENOTFOUND); - - if (c == '!') { /* Extension */ - DoExtension(source); - continue; - } - - if (c != ',') { /* Not an image separator? */ - WARNMS1(cinfo, JWRN_GIF_CHAR, c); - continue; - } - - /* Read and decipher Local Image Descriptor */ - if (!ReadOK(source->pub.input_file, hdrbuf, 9)) - ERREXIT(cinfo, JERR_INPUT_EOF); - /* we ignore top/left position info, also sort flag */ - width = LM_to_uint(hdrbuf, 4); - height = LM_to_uint(hdrbuf, 6); - if (width == 0 || height == 0) - ERREXIT(cinfo, JERR_GIF_EMPTY); - if (sinfo->max_pixels && - (unsigned long long)width * height > sinfo->max_pixels) - ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); - source->is_interlaced = (BitSet(hdrbuf[8], INTERLACE) != 0); - - /* Read local colormap if header indicates it is present */ - /* Note: if we wanted to support skipping images, */ - /* we'd need to skip rather than read colormap for ignored images */ - if (BitSet(hdrbuf[8], COLORMAPFLAG)) { - colormaplen = 2 << (hdrbuf[8] & 0x07); - ReadColorMap(source, colormaplen, source->colormap); - } - - source->input_code_size = ReadByte(source); /* get min-code-size byte */ - if (source->input_code_size < 2 || source->input_code_size > 8) - ERREXIT1(cinfo, JERR_GIF_CODESIZE, source->input_code_size); - - /* Reached desired image, so break out of loop */ - /* If we wanted to skip this image, */ - /* we'd call SkipDataBlocks and then continue the loop */ - break; - } - - /* Prepare to read selected image: first initialize LZW decompressor */ - source->symbol_head = (UINT16 *) - (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, - LZW_TABLE_SIZE * sizeof(UINT16)); - source->symbol_tail = (UINT8 *) - (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, - LZW_TABLE_SIZE * sizeof(UINT8)); - source->symbol_stack = (UINT8 *) - (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, - LZW_TABLE_SIZE * sizeof(UINT8)); - InitLZWCode(source); - - /* - * If image is interlaced, we read it into a full-size sample array, - * decompressing as we go; then get_interlaced_row selects rows from the - * sample array in the proper order. - */ - if (source->is_interlaced) { - /* We request the virtual array now, but can't access it until virtual - * arrays have been allocated. Hence, the actual work of reading the - * image is postponed until the first call to get_pixel_rows. - */ - source->interlaced_image = (*cinfo->mem->request_virt_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, - (JDIMENSION)width, (JDIMENSION)height, (JDIMENSION)1); - if (cinfo->progress != NULL) { - cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress; - progress->total_extra_passes++; /* count file input as separate pass */ - } - source->pub.get_pixel_rows = load_interlaced_image; - } else { - source->pub.get_pixel_rows = get_pixel_rows; - } - - if (cinfo->in_color_space != JCS_GRAYSCALE) { - cinfo->in_color_space = JCS_RGB; - cinfo->input_components = NUMCOLORS; - } - - /* Create compressor input buffer. */ - source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, - (JDIMENSION)width * cinfo->input_components, (JDIMENSION)1); - source->pub.buffer_height = 1; - - /* Pad colormap for safety. */ - for (c = colormaplen; c < source->clear_code; c++) { - source->colormap[CM_RED][c] = - source->colormap[CM_GREEN][c] = - source->colormap[CM_BLUE][c] = _CENTERJSAMPLE; - } - - /* Return info about the image. */ - cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */ - cinfo->image_width = width; - cinfo->image_height = height; - - TRACEMS3(cinfo, 1, JTRC_GIF, width, height, colormaplen); -} - - -/* - * Read one row of pixels. - * This version is used for noninterlaced GIF images: - * we read directly from the GIF file. - */ - -METHODDEF(JDIMENSION) -get_pixel_rows(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - gif_source_ptr source = (gif_source_ptr)sinfo; - register int c; - register _JSAMPROW ptr; - register JDIMENSION col; - register _JSAMPARRAY colormap = source->colormap; - - ptr = source->pub._buffer[0]; - if (cinfo->in_color_space == JCS_GRAYSCALE) { - for (col = cinfo->image_width; col > 0; col--) { - c = LZWReadByte(source); - *ptr++ = colormap[CM_RED][c]; - } - } else { - for (col = cinfo->image_width; col > 0; col--) { - c = LZWReadByte(source); - *ptr++ = colormap[CM_RED][c]; - *ptr++ = colormap[CM_GREEN][c]; - *ptr++ = colormap[CM_BLUE][c]; - } - } - return 1; -} - - -/* - * Read one row of pixels. - * This version is used for the first call on get_pixel_rows when - * reading an interlaced GIF file: we read the whole image into memory. - */ - -METHODDEF(JDIMENSION) -load_interlaced_image(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - gif_source_ptr source = (gif_source_ptr)sinfo; - register _JSAMPROW sptr; - register JDIMENSION col; - JDIMENSION row; - cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress; - - /* Read the interlaced image into the virtual array we've created. */ - for (row = 0; row < cinfo->image_height; row++) { - if (progress != NULL) { - progress->pub.pass_counter = (long)row; - progress->pub.pass_limit = (long)cinfo->image_height; - (*progress->pub.progress_monitor) ((j_common_ptr)cinfo); - } - sptr = *(_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) - ((j_common_ptr)cinfo, source->interlaced_image, row, (JDIMENSION)1, - TRUE); - for (col = cinfo->image_width; col > 0; col--) { - *sptr++ = (_JSAMPLE)LZWReadByte(source); - } - } - if (progress != NULL) - progress->completed_extra_passes++; - - /* Replace method pointer so subsequent calls don't come here. */ - source->pub.get_pixel_rows = get_interlaced_row; - /* Initialize for get_interlaced_row, and perform first call on it. */ - source->cur_row_number = 0; - source->pass2_offset = (cinfo->image_height + 7) / 8; - source->pass3_offset = source->pass2_offset + (cinfo->image_height + 3) / 8; - source->pass4_offset = source->pass3_offset + (cinfo->image_height + 1) / 4; - - return get_interlaced_row(cinfo, sinfo); -} - - -/* - * Read one row of pixels. - * This version is used for interlaced GIF images: - * we read from the virtual array. - */ - -METHODDEF(JDIMENSION) -get_interlaced_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - gif_source_ptr source = (gif_source_ptr)sinfo; - register int c; - register _JSAMPROW sptr, ptr; - register JDIMENSION col; - register _JSAMPARRAY colormap = source->colormap; - JDIMENSION irow; - - /* Figure out which row of interlaced image is needed, and access it. */ - switch ((int)(source->cur_row_number & 7)) { - case 0: /* first-pass row */ - irow = source->cur_row_number >> 3; - break; - case 4: /* second-pass row */ - irow = (source->cur_row_number >> 3) + source->pass2_offset; - break; - case 2: /* third-pass row */ - case 6: - irow = (source->cur_row_number >> 2) + source->pass3_offset; - break; - default: /* fourth-pass row */ - irow = (source->cur_row_number >> 1) + source->pass4_offset; - } - sptr = *(_JSAMPARRAY)(*cinfo->mem->access_virt_sarray) - ((j_common_ptr)cinfo, source->interlaced_image, irow, (JDIMENSION)1, - FALSE); - /* Scan the row, expand colormap, and output */ - ptr = source->pub._buffer[0]; - if (cinfo->in_color_space == JCS_GRAYSCALE) { - for (col = cinfo->image_width; col > 0; col--) { - c = *sptr++; - *ptr++ = colormap[CM_RED][c]; - } - } else { - for (col = cinfo->image_width; col > 0; col--) { - c = *sptr++; - *ptr++ = colormap[CM_RED][c]; - *ptr++ = colormap[CM_GREEN][c]; - *ptr++ = colormap[CM_BLUE][c]; - } - } - source->cur_row_number++; /* for next time */ - return 1; -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_input_gif(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - /* no work */ -} - - -/* - * The module selection routine for GIF format input. - */ - -GLOBAL(cjpeg_source_ptr) -_jinit_read_gif(j_compress_ptr cinfo) -{ - gif_source_ptr source; - - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); - - /* Create module interface object */ - source = (gif_source_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - sizeof(gif_source_struct)); - source->cinfo = cinfo; /* make back link for subroutines */ - /* Fill in method ptrs, except get_pixel_rows which start_input sets */ - source->pub.start_input = start_input_gif; - source->pub.finish_input = finish_input_gif; - source->pub.max_pixels = 0; - - return (cjpeg_source_ptr)source; -} - -#endif /* defined(GIF_SUPPORTED) && - (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */ diff --git a/3rdparty/libjpeg-turbo/src/rdjpgcom.c b/3rdparty/libjpeg-turbo/src/rdjpgcom.c deleted file mode 100644 index d9a6f85a38..0000000000 --- a/3rdparty/libjpeg-turbo/src/rdjpgcom.c +++ /dev/null @@ -1,493 +0,0 @@ -/* - * rdjpgcom.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1994-1997, Thomas G. Lane. - * Modified 2009 by Bill Allombert, Guido Vollbeding. - * libjpeg-turbo Modifications: - * Copyright (C) 2022, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains a very simple stand-alone application that displays - * the text in COM (comment) markers in a JFIF file. - * This may be useful as an example of the minimum logic needed to parse - * JPEG markers. - */ - -#ifdef _MSC_VER -#define _CRT_SECURE_NO_DEPRECATE -#endif - -#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */ -#include "jinclude.h" /* get auto-config symbols, */ - -#include /* Bill Allombert: use locale for isprint */ -#include /* to declare isupper(), tolower() */ -#ifdef USE_SETMODE -#include /* to declare setmode()'s parameter macros */ -/* If you have setmode() but not , just delete this line: */ -#include /* to declare setmode() */ -#endif - -#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ -#define READ_BINARY "r" -#else -#define READ_BINARY "rb" -#endif - -#ifndef EXIT_FAILURE /* define exit() codes if not provided */ -#define EXIT_FAILURE 1 -#endif -#ifndef EXIT_SUCCESS -#define EXIT_SUCCESS 0 -#endif - - -/* - * These macros are used to read the input file. - * To reuse this code in another application, you might need to change these. - */ - -static FILE *infile; /* input JPEG file */ - -/* Return next input byte, or EOF if no more */ -#define NEXTBYTE() getc(infile) - - -/* Error exit handler */ -#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) - - -/* Read one byte, testing for EOF */ -static int -read_1_byte(void) -{ - int c; - - c = NEXTBYTE(); - if (c == EOF) - ERREXIT("Premature EOF in JPEG file"); - return c; -} - -/* Read 2 bytes, convert to unsigned int */ -/* All 2-byte quantities in JPEG markers are MSB first */ -static unsigned int -read_2_bytes(void) -{ - int c1, c2; - - c1 = NEXTBYTE(); - if (c1 == EOF) - ERREXIT("Premature EOF in JPEG file"); - c2 = NEXTBYTE(); - if (c2 == EOF) - ERREXIT("Premature EOF in JPEG file"); - return (((unsigned int)c1) << 8) + ((unsigned int)c2); -} - - -/* - * JPEG markers consist of one or more 0xFF bytes, followed by a marker - * code byte (which is not an FF). Here are the marker codes of interest - * in this program. (See jdmarker.c for a more complete list.) - */ - -#define M_SOF0 0xC0 /* Start Of Frame N */ -#define M_SOF1 0xC1 /* N indicates which compression process */ -#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ -#define M_SOF3 0xC3 -#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ -#define M_SOF6 0xC6 -#define M_SOF7 0xC7 -#define M_SOF9 0xC9 -#define M_SOF10 0xCA -#define M_SOF11 0xCB -#define M_SOF13 0xCD -#define M_SOF14 0xCE -#define M_SOF15 0xCF -#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ -#define M_EOI 0xD9 /* End Of Image (end of datastream) */ -#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ -#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */ -#define M_COM 0xFE /* COMment */ - - -/* - * Find the next JPEG marker and return its marker code. - * We expect at least one FF byte, possibly more if the compressor used FFs - * to pad the file. - * There could also be non-FF garbage between markers. The treatment of such - * garbage is unspecified; we choose to skip over it but emit a warning msg. - * NB: this routine must not be used after seeing SOS marker, since it will - * not deal correctly with FF/00 sequences in the compressed image data... - */ - -static int -next_marker(void) -{ - int c; - int discarded_bytes = 0; - - /* Find 0xFF byte; count and skip any non-FFs. */ - c = read_1_byte(); - while (c != 0xFF) { - discarded_bytes++; - c = read_1_byte(); - } - /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs - * are legal as pad bytes, so don't count them in discarded_bytes. - */ - do { - c = read_1_byte(); - } while (c == 0xFF); - - if (discarded_bytes != 0) { - fprintf(stderr, "Warning: garbage data found in JPEG file\n"); - } - - return c; -} - - -/* - * Read the initial marker, which should be SOI. - * For a JFIF file, the first two bytes of the file should be literally - * 0xFF M_SOI. To be more general, we could use next_marker, but if the - * input file weren't actually JPEG at all, next_marker might read the whole - * file and then return a misleading error message... - */ - -static int -first_marker(void) -{ - int c1, c2; - - c1 = NEXTBYTE(); - c2 = NEXTBYTE(); - if (c1 != 0xFF || c2 != M_SOI) - ERREXIT("Not a JPEG file"); - return c2; -} - - -/* - * Most types of marker are followed by a variable-length parameter segment. - * This routine skips over the parameters for any marker we don't otherwise - * want to process. - * Note that we MUST skip the parameter segment explicitly in order not to - * be fooled by 0xFF bytes that might appear within the parameter segment; - * such bytes do NOT introduce new markers. - */ - -static void -skip_variable(void) -/* Skip over an unknown or uninteresting variable-length marker */ -{ - unsigned int length; - - /* Get the marker parameter length count */ - length = read_2_bytes(); - /* Length includes itself, so must be at least 2 */ - if (length < 2) - ERREXIT("Erroneous JPEG marker length"); - length -= 2; - /* Skip over the remaining bytes */ - while (length > 0) { - (void)read_1_byte(); - length--; - } -} - - -/* - * Process a COM marker. - * We want to print out the marker contents as legible text; - * we must guard against non-text junk and varying newline representations. - */ - -static void -process_COM(int raw) -{ - unsigned int length; - int ch; - int lastch = 0; - - /* Bill Allombert: set locale properly for isprint */ - setlocale(LC_CTYPE, ""); - - /* Get the marker parameter length count */ - length = read_2_bytes(); - /* Length includes itself, so must be at least 2 */ - if (length < 2) - ERREXIT("Erroneous JPEG marker length"); - length -= 2; - - while (length > 0) { - ch = read_1_byte(); - if (raw) { - putc(ch, stdout); - /* Emit the character in a readable form. - * Nonprintables are converted to \nnn form, - * while \ is converted to \\. - * Newlines in CR, CR/LF, or LF form will be printed as one newline. - */ - } else if (ch == '\r') { - printf("\n"); - } else if (ch == '\n') { - if (lastch != '\r') - printf("\n"); - } else if (ch == '\\') { - printf("\\\\"); - } else if (isprint(ch)) { - putc(ch, stdout); - } else { - printf("\\%03o", (unsigned int)ch); - } - lastch = ch; - length--; - } - printf("\n"); - - /* Bill Allombert: revert to C locale */ - setlocale(LC_CTYPE, "C"); -} - - -/* - * Process a SOFn marker. - * This code is only needed if you want to know the image dimensions... - */ - -static void -process_SOFn(int marker) -{ - unsigned int length; - unsigned int image_height, image_width; - int data_precision, num_components; - const char *process; - int ci; - - length = read_2_bytes(); /* usual parameter length count */ - - data_precision = read_1_byte(); - image_height = read_2_bytes(); - image_width = read_2_bytes(); - num_components = read_1_byte(); - - switch (marker) { - case M_SOF0: process = "Baseline"; break; - case M_SOF1: process = "Extended sequential"; break; - case M_SOF2: process = "Progressive"; break; - case M_SOF3: process = "Lossless"; break; - case M_SOF5: process = "Differential sequential"; break; - case M_SOF6: process = "Differential progressive"; break; - case M_SOF7: process = "Differential lossless"; break; - case M_SOF9: process = "Extended sequential, arithmetic coding"; break; - case M_SOF10: process = "Progressive, arithmetic coding"; break; - case M_SOF11: process = "Lossless, arithmetic coding"; break; - case M_SOF13: process = "Differential sequential, arithmetic coding"; break; - case M_SOF14: - process = "Differential progressive, arithmetic coding"; break; - case M_SOF15: process = "Differential lossless, arithmetic coding"; break; - default: process = "Unknown"; break; - } - - printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n", - image_width, image_height, num_components, data_precision); - printf("JPEG process: %s\n", process); - - if (length != (unsigned int)(8 + num_components * 3)) - ERREXIT("Bogus SOF marker length"); - - for (ci = 0; ci < num_components; ci++) { - (void)read_1_byte(); /* Component ID code */ - (void)read_1_byte(); /* H, V sampling factors */ - (void)read_1_byte(); /* Quantization table number */ - } -} - - -/* - * Parse the marker stream until SOS or EOI is seen; - * display any COM markers. - * While the companion program wrjpgcom will always insert COM markers before - * SOFn, other implementations might not, so we scan to SOS before stopping. - * If we were only interested in the image dimensions, we would stop at SOFn. - * (Conversely, if we only cared about COM markers, there would be no need - * for special code to handle SOFn; we could treat it like other markers.) - */ - -static int -scan_JPEG_header(int verbose, int raw) -{ - int marker; - - /* Expect SOI at start of file */ - if (first_marker() != M_SOI) - ERREXIT("Expected SOI marker first"); - - /* Scan miscellaneous markers until we reach SOS. */ - for (;;) { - marker = next_marker(); - switch (marker) { - /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, - * treated as SOFn. C4 in particular is actually DHT. - */ - case M_SOF0: /* Baseline */ - case M_SOF1: /* Extended sequential, Huffman */ - case M_SOF2: /* Progressive, Huffman */ - case M_SOF3: /* Lossless, Huffman */ - case M_SOF5: /* Differential sequential, Huffman */ - case M_SOF6: /* Differential progressive, Huffman */ - case M_SOF7: /* Differential lossless, Huffman */ - case M_SOF9: /* Extended sequential, arithmetic */ - case M_SOF10: /* Progressive, arithmetic */ - case M_SOF11: /* Lossless, arithmetic */ - case M_SOF13: /* Differential sequential, arithmetic */ - case M_SOF14: /* Differential progressive, arithmetic */ - case M_SOF15: /* Differential lossless, arithmetic */ - if (verbose) - process_SOFn(marker); - else - skip_variable(); - break; - - case M_SOS: /* stop before hitting compressed data */ - return marker; - - case M_EOI: /* in case it's a tables-only JPEG stream */ - return marker; - - case M_COM: - process_COM(raw); - break; - - case M_APP12: - /* Some digital camera makers put useful textual information into - * APP12 markers, so we print those out too when in -verbose mode. - */ - if (verbose) { - printf("APP12 contains:\n"); - process_COM(raw); - } else - skip_variable(); - break; - - default: /* Anything else just gets skipped */ - skip_variable(); /* we assume it has a parameter count... */ - break; - } - } /* end loop */ -} - - -/* Command line parsing code */ - -static const char *progname; /* program name for error messages */ - - -static void -usage(void) -/* complain about bad command line */ -{ - fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n"); - - fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname); - - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -raw Display non-printable characters in comments (unsafe)\n"); - fprintf(stderr, " -verbose Also display dimensions of JPEG image\n"); - - exit(EXIT_FAILURE); -} - - -static int -keymatch(char *arg, const char *keyword, int minchars) -/* Case-insensitive matching of (possibly abbreviated) keyword switches. */ -/* keyword is the constant keyword (must be lower case already), */ -/* minchars is length of minimum legal abbreviation. */ -{ - register int ca, ck; - register int nmatched = 0; - - while ((ca = *arg++) != '\0') { - if ((ck = *keyword++) == '\0') - return 0; /* arg longer than keyword, no good */ - if (isupper(ca)) /* force arg to lcase (assume ck is already) */ - ca = tolower(ca); - if (ca != ck) - return 0; /* no good */ - nmatched++; /* count matched characters */ - } - /* reached end of argument; fail if it's too short for unique abbrev */ - if (nmatched < minchars) - return 0; - return 1; /* A-OK */ -} - - -/* - * The main program. - */ - -int -main(int argc, char **argv) -{ - int argn; - char *arg; - int verbose = 0, raw = 0; - - progname = argv[0]; - if (progname == NULL || progname[0] == 0) - progname = "rdjpgcom"; /* in case C library doesn't provide it */ - - /* Parse switches, if any */ - for (argn = 1; argn < argc; argn++) { - arg = argv[argn]; - if (arg[0] != '-') - break; /* not switch, must be file name */ - arg++; /* advance over '-' */ - if (keymatch(arg, "verbose", 1)) { - verbose++; - } else if (keymatch(arg, "raw", 1)) { - raw = 1; - } else - usage(); - } - - /* Open the input file. */ - /* Unix style: expect zero or one file name */ - if (argn < argc - 1) { - fprintf(stderr, "%s: only one input file\n", progname); - usage(); - } - if (argn < argc) { - if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); - exit(EXIT_FAILURE); - } - } else { - /* default input file is stdin */ -#ifdef USE_SETMODE /* need to hack file mode? */ - setmode(fileno(stdin), O_BINARY); -#endif -#ifdef USE_FDOPEN /* need to re-open in binary mode? */ - if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { - fprintf(stderr, "%s: can't open stdin\n", progname); - exit(EXIT_FAILURE); - } -#else - infile = stdin; -#endif - } - - /* Scan the JPEG headers. */ - (void)scan_JPEG_header(verbose, raw); - - /* All done. */ - exit(EXIT_SUCCESS); - return 0; /* suppress no-return-value warnings */ -} diff --git a/3rdparty/libjpeg-turbo/src/rdppm.c b/3rdparty/libjpeg-turbo/src/rdppm.c deleted file mode 100644 index 84e26f7b3f..0000000000 --- a/3rdparty/libjpeg-turbo/src/rdppm.c +++ /dev/null @@ -1,890 +0,0 @@ -/* - * rdppm.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1991-1997, Thomas G. Lane. - * Modified 2009 by Bill Allombert, Guido Vollbeding. - * libjpeg-turbo Modifications: - * Copyright (C) 2015-2017, 2020-2023, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains routines to read input images in PPM/PGM format. - * The extended 2-byte-per-sample raw PPM/PGM formats are supported. - * The PBMPLUS library is NOT required to compile this software - * (but it is highly useful as a set of PPM image manipulation programs). - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume input from - * an ordinary stdio stream. They further assume that reading begins - * at the start of the file; start_input may need work if the - * user interface has already read some data (e.g., to determine that - * the file is indeed PPM format). - */ - -#include "cmyk.h" -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#if defined(PPM_SUPPORTED) && \ - (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) - - -/* Portions of this code are based on the PBMPLUS library, which is: -** -** Copyright (C) 1988 by Jef Poskanzer. -** -** Permission to use, copy, modify, and distribute this software and its -** documentation for any purpose and without fee is hereby granted, provided -** that the above copyright notice appear in all copies and that both that -** copyright notice and this permission notice appear in supporting -** documentation. This software is provided "as is" without express or -** implied warranty. -*/ - - -/* Macros to deal with unsigned chars as efficiently as compiler allows */ - -typedef unsigned char U_CHAR; -#define UCH(x) ((int)(x)) - - -#define ReadOK(file, buffer, len) \ - (fread(buffer, 1, len, file) == ((size_t)(len))) - -static int alpha_index[JPEG_NUMCS] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1 -}; - - -/* Private version of data source object */ - -typedef struct { - struct cjpeg_source_struct pub; /* public fields */ - - /* Usually these two pointers point to the same place: */ - U_CHAR *iobuffer; /* fread's I/O buffer */ - _JSAMPROW pixrow; /* compressor input buffer */ - size_t buffer_width; /* width of I/O buffer */ - _JSAMPLE *rescale; /* => maxval-remapping array, or NULL */ - unsigned int maxval; -} ppm_source_struct; - -typedef ppm_source_struct *ppm_source_ptr; - - -LOCAL(int) -pbm_getc(FILE *infile) -/* Read next char, skipping over any comments */ -/* A comment/newline sequence is returned as a newline */ -{ - register int ch; - - ch = getc(infile); - if (ch == '#') { - do { - ch = getc(infile); - } while (ch != '\n' && ch != EOF); - } - return ch; -} - - -LOCAL(unsigned int) -read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval) -/* Read an unsigned decimal integer from the PPM file */ -/* Swallows one trailing character after the integer */ -/* Note that on a 16-bit-int machine, only values up to 64k can be read. */ -/* This should not be a problem in practice. */ -{ - register int ch; - register unsigned int val; - - /* Skip any leading whitespace */ - do { - ch = pbm_getc(infile); - if (ch == EOF) - ERREXIT(cinfo, JERR_INPUT_EOF); - } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); - - if (ch < '0' || ch > '9') - ERREXIT(cinfo, JERR_PPM_NONNUMERIC); - - val = ch - '0'; - while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { - val *= 10; - val += ch - '0'; - if (val > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - } - - return val; -} - - -/* - * Read one row of pixels. - * - * We provide several different versions depending on input file format. - * In all cases, input is scaled to the size of _JSAMPLE. - * - * A really fast path is provided for reading byte/sample raw files with - * maxval = _MAXJSAMPLE, which is the normal case for 8-bit data. - */ - - -METHODDEF(JDIMENSION) -get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading text-format PGM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - FILE *infile = source->pub.input_file; - register _JSAMPROW ptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - - ptr = source->pub._buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - *ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)]; - } - return 1; -} - - -#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \ - for (col = cinfo->image_width; col > 0; col--) { \ - ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \ - alpha_set_op \ - ptr += ps; \ - } \ -} - -METHODDEF(JDIMENSION) -get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading text-format PGM files with any maxval and - converting to extended RGB */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - FILE *infile = source->pub.input_file; - register _JSAMPROW ptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - register int rindex = rgb_red[cinfo->in_color_space]; - register int gindex = rgb_green[cinfo->in_color_space]; - register int bindex = rgb_blue[cinfo->in_color_space]; - register int aindex = alpha_index[cinfo->in_color_space]; - register int ps = rgb_pixelsize[cinfo->in_color_space]; - - ptr = source->pub._buffer[0]; - if (maxval == _MAXJSAMPLE) { - if (aindex >= 0) - GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), - ptr[aindex] = _MAXJSAMPLE;) - else - GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) - } else { - if (aindex >= 0) - GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], - ptr[aindex] = _MAXJSAMPLE;) - else - GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading text-format PGM files with any maxval and - converting to CMYK */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - FILE *infile = source->pub.input_file; - register _JSAMPROW ptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - - ptr = source->pub._buffer[0]; - if (maxval == _MAXJSAMPLE) { - for (col = cinfo->image_width; col > 0; col--) { - _JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); - rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); - ptr += 4; - } - } else { - for (col = cinfo->image_width; col > 0; col--) { - _JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)]; - rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); - ptr += 4; - } - } - return 1; -} - - -#define RGB_READ_LOOP(read_op, alpha_set_op) { \ - for (col = cinfo->image_width; col > 0; col--) { \ - ptr[rindex] = read_op; \ - ptr[gindex] = read_op; \ - ptr[bindex] = read_op; \ - alpha_set_op \ - ptr += ps; \ - } \ -} - -METHODDEF(JDIMENSION) -get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading text-format PPM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - FILE *infile = source->pub.input_file; - register _JSAMPROW ptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - register int rindex = rgb_red[cinfo->in_color_space]; - register int gindex = rgb_green[cinfo->in_color_space]; - register int bindex = rgb_blue[cinfo->in_color_space]; - register int aindex = alpha_index[cinfo->in_color_space]; - register int ps = rgb_pixelsize[cinfo->in_color_space]; - - ptr = source->pub._buffer[0]; - if (maxval == _MAXJSAMPLE) { - if (aindex >= 0) - RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), - ptr[aindex] = _MAXJSAMPLE;) - else - RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {}) - } else { - if (aindex >= 0) - RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], - ptr[aindex] = _MAXJSAMPLE;) - else - RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {}) - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading text-format PPM files with any maxval and - converting to CMYK */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - FILE *infile = source->pub.input_file; - register _JSAMPROW ptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - - ptr = source->pub._buffer[0]; - if (maxval == _MAXJSAMPLE) { - for (col = cinfo->image_width; col > 0; col--) { - _JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); - _JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); - _JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval); - rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); - ptr += 4; - } - } else { - for (col = cinfo->image_width; col > 0; col--) { - _JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)]; - _JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)]; - _JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)]; - rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); - ptr += 4; - } - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-byte-format PGM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - *ptr++ = rescale[UCH(*bufferptr++)]; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-byte-format PGM files with any maxval - and converting to extended RGB */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - register int rindex = rgb_red[cinfo->in_color_space]; - register int gindex = rgb_green[cinfo->in_color_space]; - register int bindex = rgb_blue[cinfo->in_color_space]; - register int aindex = alpha_index[cinfo->in_color_space]; - register int ps = rgb_pixelsize[cinfo->in_color_space]; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - if (maxval == _MAXJSAMPLE) { - if (aindex >= 0) - GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;) - else - GRAY_RGB_READ_LOOP(*bufferptr++, {}) - } else { - if (aindex >= 0) - GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], - ptr[aindex] = _MAXJSAMPLE;) - else - GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {}) - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-byte-format PGM files with any maxval - and converting to CMYK */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - if (maxval == _MAXJSAMPLE) { - for (col = cinfo->image_width; col > 0; col--) { - _JSAMPLE gray = *bufferptr++; - rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); - ptr += 4; - } - } else { - for (col = cinfo->image_width; col > 0; col--) { - _JSAMPLE gray = rescale[UCH(*bufferptr++)]; - rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3); - ptr += 4; - } - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-byte-format PPM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - register int rindex = rgb_red[cinfo->in_color_space]; - register int gindex = rgb_green[cinfo->in_color_space]; - register int bindex = rgb_blue[cinfo->in_color_space]; - register int aindex = alpha_index[cinfo->in_color_space]; - register int ps = rgb_pixelsize[cinfo->in_color_space]; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - if (maxval == _MAXJSAMPLE) { - if (aindex >= 0) - RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;) - else - RGB_READ_LOOP(*bufferptr++, {}) - } else { - if (aindex >= 0) - RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = _MAXJSAMPLE;) - else - RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {}) - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-byte-format PPM files with any maxval and - converting to CMYK */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - if (maxval == _MAXJSAMPLE) { - for (col = cinfo->image_width; col > 0; col--) { - _JSAMPLE r = *bufferptr++; - _JSAMPLE g = *bufferptr++; - _JSAMPLE b = *bufferptr++; - rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); - ptr += 4; - } - } else { - for (col = cinfo->image_width; col > 0; col--) { - _JSAMPLE r = rescale[UCH(*bufferptr++)]; - _JSAMPLE g = rescale[UCH(*bufferptr++)]; - _JSAMPLE b = rescale[UCH(*bufferptr++)]; - rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3); - ptr += 4; - } - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-byte-format files with maxval = _MAXJSAMPLE. - * In this case we just read right into the _JSAMPLE buffer! - * Note that same code works for PPM and PGM files. - */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - return 1; -} - - -METHODDEF(JDIMENSION) -get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-word-format PGM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - register unsigned int temp; - temp = UCH(*bufferptr++) << 8; - temp |= UCH(*bufferptr++); - if (temp > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - *ptr++ = rescale[temp]; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-word-format PGM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - register int rindex = rgb_red[cinfo->in_color_space]; - register int gindex = rgb_green[cinfo->in_color_space]; - register int bindex = rgb_blue[cinfo->in_color_space]; - register int aindex = alpha_index[cinfo->in_color_space]; - register int ps = rgb_pixelsize[cinfo->in_color_space]; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - register unsigned int temp; - temp = UCH(*bufferptr++) << 8; - temp |= UCH(*bufferptr++); - if (temp > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp]; - if (aindex >= 0) - ptr[aindex] = _MAXJSAMPLE; - ptr += ps; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-word-format PGM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - register unsigned int gray; - gray = UCH(*bufferptr++) << 8; - gray |= UCH(*bufferptr++); - if (gray > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - rgb_to_cmyk(rescale[gray], rescale[gray], rescale[gray], ptr, ptr + 1, - ptr + 2, ptr + 3); - ptr += 4; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-word-format PPM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - register int rindex = rgb_red[cinfo->in_color_space]; - register int gindex = rgb_green[cinfo->in_color_space]; - register int bindex = rgb_blue[cinfo->in_color_space]; - register int aindex = alpha_index[cinfo->in_color_space]; - register int ps = rgb_pixelsize[cinfo->in_color_space]; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - register unsigned int temp; - temp = UCH(*bufferptr++) << 8; - temp |= UCH(*bufferptr++); - if (temp > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - ptr[rindex] = rescale[temp]; - temp = UCH(*bufferptr++) << 8; - temp |= UCH(*bufferptr++); - if (temp > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - ptr[gindex] = rescale[temp]; - temp = UCH(*bufferptr++) << 8; - temp |= UCH(*bufferptr++); - if (temp > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - ptr[bindex] = rescale[temp]; - if (aindex >= 0) - ptr[aindex] = _MAXJSAMPLE; - ptr += ps; - } - return 1; -} - - -METHODDEF(JDIMENSION) -get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading raw-word-format PPM files with any maxval */ -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - register _JSAMPROW ptr; - register U_CHAR *bufferptr; - register _JSAMPLE *rescale = source->rescale; - JDIMENSION col; - unsigned int maxval = source->maxval; - - if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) - ERREXIT(cinfo, JERR_INPUT_EOF); - ptr = source->pub._buffer[0]; - bufferptr = source->iobuffer; - for (col = cinfo->image_width; col > 0; col--) { - register unsigned int r, g, b; - r = UCH(*bufferptr++) << 8; - r |= UCH(*bufferptr++); - if (r > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - g = UCH(*bufferptr++) << 8; - g |= UCH(*bufferptr++); - if (g > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - b = UCH(*bufferptr++) << 8; - b |= UCH(*bufferptr++); - if (b > maxval) - ERREXIT(cinfo, JERR_PPM_OUTOFRANGE); - rgb_to_cmyk(rescale[r], rescale[g], rescale[b], ptr, ptr + 1, ptr + 2, - ptr + 3); - ptr += 4; - } - return 1; -} - - -/* - * Read the file header; return image size and component count. - */ - -METHODDEF(void) -start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - ppm_source_ptr source = (ppm_source_ptr)sinfo; - int c; - unsigned int w, h, maxval; - boolean need_iobuffer, use_raw_buffer, need_rescale; - - if (getc(source->pub.input_file) != 'P') - ERREXIT(cinfo, JERR_PPM_NOT); - - c = getc(source->pub.input_file); /* subformat discriminator character */ - - /* detect unsupported variants (ie, PBM) before trying to read header */ - switch (c) { - case '2': /* it's a text-format PGM file */ - case '3': /* it's a text-format PPM file */ - case '5': /* it's a raw-format PGM file */ - case '6': /* it's a raw-format PPM file */ - break; - default: - ERREXIT(cinfo, JERR_PPM_NOT); - break; - } - - /* fetch the remaining header info */ - w = read_pbm_integer(cinfo, source->pub.input_file, 65535); - h = read_pbm_integer(cinfo, source->pub.input_file, 65535); - maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535); - - if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ - ERREXIT(cinfo, JERR_PPM_NOT); - if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels) - ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); - - cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */ - cinfo->image_width = (JDIMENSION)w; - cinfo->image_height = (JDIMENSION)h; - source->maxval = maxval; - - /* initialize flags to most common settings */ - need_iobuffer = TRUE; /* do we need an I/O buffer? */ - use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ - need_rescale = TRUE; /* do we need a rescale array? */ - - switch (c) { - case '2': /* it's a text-format PGM file */ - if (cinfo->in_color_space == JCS_UNKNOWN || - cinfo->in_color_space == JCS_RGB) - cinfo->in_color_space = JCS_GRAYSCALE; - TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h); - if (cinfo->in_color_space == JCS_GRAYSCALE) - source->pub.get_pixel_rows = get_text_gray_row; - else if (IsExtRGB(cinfo->in_color_space)) - source->pub.get_pixel_rows = get_text_gray_rgb_row; - else if (cinfo->in_color_space == JCS_CMYK) - source->pub.get_pixel_rows = get_text_gray_cmyk_row; - else - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); - need_iobuffer = FALSE; - break; - - case '3': /* it's a text-format PPM file */ - if (cinfo->in_color_space == JCS_UNKNOWN) - cinfo->in_color_space = JCS_EXT_RGB; - TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h); - if (IsExtRGB(cinfo->in_color_space)) - source->pub.get_pixel_rows = get_text_rgb_row; - else if (cinfo->in_color_space == JCS_CMYK) - source->pub.get_pixel_rows = get_text_rgb_cmyk_row; - else - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); - need_iobuffer = FALSE; - break; - - case '5': /* it's a raw-format PGM file */ - if (cinfo->in_color_space == JCS_UNKNOWN || - cinfo->in_color_space == JCS_RGB) - cinfo->in_color_space = JCS_GRAYSCALE; - TRACEMS2(cinfo, 1, JTRC_PGM, w, h); - if (maxval > 255) { - if (cinfo->in_color_space == JCS_GRAYSCALE) - source->pub.get_pixel_rows = get_word_gray_row; - else if (IsExtRGB(cinfo->in_color_space)) - source->pub.get_pixel_rows = get_word_gray_rgb_row; - else if (cinfo->in_color_space == JCS_CMYK) - source->pub.get_pixel_rows = get_word_gray_cmyk_row; - else - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); - } else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) && - cinfo->in_color_space == JCS_GRAYSCALE) { - source->pub.get_pixel_rows = get_raw_row; - use_raw_buffer = TRUE; - need_rescale = FALSE; - } else { - if (cinfo->in_color_space == JCS_GRAYSCALE) - source->pub.get_pixel_rows = get_scaled_gray_row; - else if (IsExtRGB(cinfo->in_color_space)) - source->pub.get_pixel_rows = get_gray_rgb_row; - else if (cinfo->in_color_space == JCS_CMYK) - source->pub.get_pixel_rows = get_gray_cmyk_row; - else - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); - } - break; - - case '6': /* it's a raw-format PPM file */ - if (cinfo->in_color_space == JCS_UNKNOWN) - cinfo->in_color_space = JCS_EXT_RGB; - TRACEMS2(cinfo, 1, JTRC_PPM, w, h); - if (maxval > 255) { - if (IsExtRGB(cinfo->in_color_space)) - source->pub.get_pixel_rows = get_word_rgb_row; - else if (cinfo->in_color_space == JCS_CMYK) - source->pub.get_pixel_rows = get_word_rgb_cmyk_row; - else - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); - } else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) && -#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 - (cinfo->in_color_space == JCS_EXT_RGB || - cinfo->in_color_space == JCS_RGB)) { -#else - cinfo->in_color_space == JCS_EXT_RGB) { -#endif - source->pub.get_pixel_rows = get_raw_row; - use_raw_buffer = TRUE; - need_rescale = FALSE; - } else { - if (IsExtRGB(cinfo->in_color_space)) - source->pub.get_pixel_rows = get_rgb_row; - else if (cinfo->in_color_space == JCS_CMYK) - source->pub.get_pixel_rows = get_rgb_cmyk_row; - else - ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); - } - break; - } - - if (IsExtRGB(cinfo->in_color_space)) - cinfo->input_components = rgb_pixelsize[cinfo->in_color_space]; - else if (cinfo->in_color_space == JCS_GRAYSCALE) - cinfo->input_components = 1; - else if (cinfo->in_color_space == JCS_CMYK) - cinfo->input_components = 4; - - /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ - if (need_iobuffer) { - if (c == '6') - source->buffer_width = (size_t)w * 3 * - ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR))); - else - source->buffer_width = (size_t)w * - ((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR))); - source->iobuffer = (U_CHAR *) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - source->buffer_width); - } - - /* Create compressor input buffer. */ - if (use_raw_buffer) { - /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ - /* Synthesize a _JSAMPARRAY pointer structure */ - source->pixrow = (_JSAMPROW)source->iobuffer; - source->pub._buffer = &source->pixrow; - source->pub.buffer_height = 1; - } else { - /* Need to translate anyway, so make a separate sample buffer. */ - source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, - (JDIMENSION)w * cinfo->input_components, (JDIMENSION)1); - source->pub.buffer_height = 1; - } - - /* Compute the rescaling array if required. */ - if (need_rescale) { - long val, half_maxval; - - /* On 16-bit-int machines we have to be careful of maxval = 65535 */ - source->rescale = (_JSAMPLE *) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - (size_t)(((long)MAX(maxval, 255) + 1L) * - sizeof(_JSAMPLE))); - memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) * - sizeof(_JSAMPLE))); - half_maxval = maxval / 2; - for (val = 0; val <= (long)maxval; val++) { - /* The multiplication here must be done in 32 bits to avoid overflow */ - source->rescale[val] = (_JSAMPLE)((val * _MAXJSAMPLE + half_maxval) / - maxval); - } - } -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - /* no work */ -} - - -/* - * The module selection routine for PPM format input. - */ - -GLOBAL(cjpeg_source_ptr) -_jinit_read_ppm(j_compress_ptr cinfo) -{ - ppm_source_ptr source; - - if (cinfo->data_precision != BITS_IN_JSAMPLE) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); - - /* Create module interface object */ - source = (ppm_source_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - sizeof(ppm_source_struct)); - /* Fill in method ptrs, except get_pixel_rows which start_input sets */ - source->pub.start_input = start_input_ppm; - source->pub.finish_input = finish_input_ppm; - source->pub.max_pixels = 0; - - return (cjpeg_source_ptr)source; -} - -#endif /* defined(PPM_SUPPORTED) && - (BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */ diff --git a/3rdparty/libjpeg-turbo/src/rdswitch.c b/3rdparty/libjpeg-turbo/src/rdswitch.c deleted file mode 100644 index 33449c86ba..0000000000 --- a/3rdparty/libjpeg-turbo/src/rdswitch.c +++ /dev/null @@ -1,428 +0,0 @@ -/* - * rdswitch.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1991-1996, Thomas G. Lane. - * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2018, 2022, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains routines to process some of cjpeg's more complicated - * command-line switches. Switches processed here are: - * -qtables file Read quantization tables from text file - * -scans file Read scan script from text file - * -quality N[,N,...] Set quality ratings - * -qslots N[,N,...] Set component quantization table selectors - * -sample HxV[,HxV,...] Set component sampling factors - */ - -#ifdef _MSC_VER -#define _CRT_SECURE_NO_DEPRECATE -#endif - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ -#include /* to declare isdigit(), isspace() */ - - -LOCAL(int) -text_getc(FILE *file) -/* Read next char, skipping over any comments (# to end of line) */ -/* A comment/newline sequence is returned as a newline */ -{ - register int ch; - - ch = getc(file); - if (ch == '#') { - do { - ch = getc(file); - } while (ch != '\n' && ch != EOF); - } - return ch; -} - - -LOCAL(boolean) -read_text_integer(FILE *file, long *result, int *termchar) -/* Read an unsigned decimal integer from a file, store it in result */ -/* Reads one trailing character after the integer; returns it in termchar */ -{ - register int ch; - register long val; - - /* Skip any leading whitespace, detect EOF */ - do { - ch = text_getc(file); - if (ch == EOF) { - *termchar = ch; - return FALSE; - } - } while (isspace(ch)); - - if (!isdigit(ch)) { - *termchar = ch; - return FALSE; - } - - val = ch - '0'; - while ((ch = text_getc(file)) != EOF) { - if (!isdigit(ch)) - break; - val *= 10; - val += ch - '0'; - } - *result = val; - *termchar = ch; - return TRUE; -} - - -#if JPEG_LIB_VERSION < 70 -static int q_scale_factor[NUM_QUANT_TBLS] = { 100, 100, 100, 100 }; -#endif - -GLOBAL(boolean) -read_quant_tables(j_compress_ptr cinfo, char *filename, boolean force_baseline) -/* Read a set of quantization tables from the specified file. - * The file is plain ASCII text: decimal numbers with whitespace between. - * Comments preceded by '#' may be included in the file. - * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values. - * The tables are implicitly numbered 0,1,etc. - * NOTE: does not affect the qslots mapping, which will default to selecting - * table 0 for luminance (or primary) components, 1 for chrominance components. - * You must use -qslots if you want a different component->table mapping. - */ -{ - FILE *fp; - int tblno, i, termchar; - long val; - unsigned int table[DCTSIZE2]; - - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr, "Can't open table file %s\n", filename); - return FALSE; - } - tblno = 0; - - while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */ - if (tblno >= NUM_QUANT_TBLS) { - fprintf(stderr, "Too many tables in file %s\n", filename); - fclose(fp); - return FALSE; - } - table[0] = (unsigned int)val; - for (i = 1; i < DCTSIZE2; i++) { - if (!read_text_integer(fp, &val, &termchar)) { - fprintf(stderr, "Invalid table data in file %s\n", filename); - fclose(fp); - return FALSE; - } - table[i] = (unsigned int)val; - } -#if JPEG_LIB_VERSION >= 70 - jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno], - force_baseline); -#else - jpeg_add_quant_table(cinfo, tblno, table, q_scale_factor[tblno], - force_baseline); -#endif - tblno++; - } - - if (termchar != EOF) { - fprintf(stderr, "Non-numeric data in file %s\n", filename); - fclose(fp); - return FALSE; - } - - fclose(fp); - return TRUE; -} - - -#ifdef C_MULTISCAN_FILES_SUPPORTED - -LOCAL(boolean) -read_scan_integer(FILE *file, long *result, int *termchar) -/* Variant of read_text_integer that always looks for a non-space termchar; - * this simplifies parsing of punctuation in scan scripts. - */ -{ - register int ch; - - if (!read_text_integer(file, result, termchar)) - return FALSE; - ch = *termchar; - while (ch != EOF && isspace(ch)) - ch = text_getc(file); - if (isdigit(ch)) { /* oops, put it back */ - if (ungetc(ch, file) == EOF) - return FALSE; - ch = ' '; - } else { - /* Any separators other than ';' and ':' are ignored; - * this allows user to insert commas, etc, if desired. - */ - if (ch != EOF && ch != ';' && ch != ':') - ch = ' '; - } - *termchar = ch; - return TRUE; -} - - -GLOBAL(boolean) -read_scan_script(j_compress_ptr cinfo, char *filename) -/* Read a scan script from the specified text file. - * Each entry in the file defines one scan to be emitted. - * Entries are separated by semicolons ';'. - * An entry contains one to four component indexes, - * optionally followed by a colon ':' and four progressive-JPEG parameters. - * The component indexes denote which component(s) are to be transmitted - * in the current scan. The first component has index 0. - * Sequential JPEG is used if the progressive-JPEG parameters are omitted. - * The file is free format text: any whitespace may appear between numbers - * and the ':' and ';' punctuation marks. Also, other punctuation (such - * as commas or dashes) can be placed between numbers if desired. - * Comments preceded by '#' may be included in the file. - * Note: we do very little validity checking here; - * jcmaster.c will validate the script parameters. - */ -{ - FILE *fp; - int scanno, ncomps, termchar; - long val; - jpeg_scan_info *scanptr; -#define MAX_SCANS 100 /* quite arbitrary limit */ - jpeg_scan_info scans[MAX_SCANS]; - - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr, "Can't open scan definition file %s\n", filename); - return FALSE; - } - scanptr = scans; - scanno = 0; - - while (read_scan_integer(fp, &val, &termchar)) { - if (scanno >= MAX_SCANS) { - fprintf(stderr, "Too many scans defined in file %s\n", filename); - fclose(fp); - return FALSE; - } - scanptr->component_index[0] = (int)val; - ncomps = 1; - while (termchar == ' ') { - if (ncomps >= MAX_COMPS_IN_SCAN) { - fprintf(stderr, "Too many components in one scan in file %s\n", - filename); - fclose(fp); - return FALSE; - } - if (!read_scan_integer(fp, &val, &termchar)) - goto bogus; - scanptr->component_index[ncomps] = (int)val; - ncomps++; - } - scanptr->comps_in_scan = ncomps; - if (termchar == ':') { - if (!read_scan_integer(fp, &val, &termchar) || termchar != ' ') - goto bogus; - scanptr->Ss = (int)val; - if (!read_scan_integer(fp, &val, &termchar) || termchar != ' ') - goto bogus; - scanptr->Se = (int)val; - if (!read_scan_integer(fp, &val, &termchar) || termchar != ' ') - goto bogus; - scanptr->Ah = (int)val; - if (!read_scan_integer(fp, &val, &termchar)) - goto bogus; - scanptr->Al = (int)val; - } else { - /* set non-progressive parameters */ - scanptr->Ss = 0; - scanptr->Se = DCTSIZE2 - 1; - scanptr->Ah = 0; - scanptr->Al = 0; - } - if (termchar != ';' && termchar != EOF) { -bogus: - fprintf(stderr, "Invalid scan entry format in file %s\n", filename); - fclose(fp); - return FALSE; - } - scanptr++, scanno++; - } - - if (termchar != EOF) { - fprintf(stderr, "Non-numeric data in file %s\n", filename); - fclose(fp); - return FALSE; - } - - if (scanno > 0) { - /* Stash completed scan list in cinfo structure. - * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data, - * but if you want to compress multiple images you'd want JPOOL_PERMANENT. - */ - scanptr = (jpeg_scan_info *) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - scanno * sizeof(jpeg_scan_info)); - memcpy(scanptr, scans, scanno * sizeof(jpeg_scan_info)); - cinfo->scan_info = scanptr; - cinfo->num_scans = scanno; - } - - fclose(fp); - return TRUE; -} - -#endif /* C_MULTISCAN_FILES_SUPPORTED */ - - -#if JPEG_LIB_VERSION < 70 -/* These are the sample quantization tables given in Annex K (Clause K.1) of - * Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994. - * The spec says that the values given produce "good" quality, and - * when divided by 2, "very good" quality. - */ -static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { - 16, 11, 10, 16, 24, 40, 51, 61, - 12, 12, 14, 19, 26, 58, 60, 55, - 14, 13, 16, 24, 40, 57, 69, 56, - 14, 17, 22, 29, 51, 87, 80, 62, - 18, 22, 37, 56, 68, 109, 103, 77, - 24, 35, 55, 64, 81, 104, 113, 92, - 49, 64, 78, 87, 103, 121, 120, 101, - 72, 92, 95, 98, 112, 100, 103, 99 -}; -static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = { - 17, 18, 24, 47, 99, 99, 99, 99, - 18, 21, 26, 66, 99, 99, 99, 99, - 24, 26, 56, 99, 99, 99, 99, 99, - 47, 66, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99 -}; - - -LOCAL(void) -jpeg_default_qtables(j_compress_ptr cinfo, boolean force_baseline) -{ - jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, q_scale_factor[0], - force_baseline); - jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, q_scale_factor[1], - force_baseline); -} -#endif - - -GLOBAL(boolean) -set_quality_ratings(j_compress_ptr cinfo, char *arg, boolean force_baseline) -/* Process a quality-ratings parameter string, of the form - * N[,N,...] - * If there are more q-table slots than parameters, the last value is replicated. - */ -{ - int val = 75; /* default value */ - int tblno; - char ch; - - for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { - if (*arg) { - ch = ','; /* if not set by sscanf, will be ',' */ - if (sscanf(arg, "%d%c", &val, &ch) < 1) - return FALSE; - if (ch != ',') /* syntax check */ - return FALSE; - /* Convert user 0-100 rating to percentage scaling */ -#if JPEG_LIB_VERSION >= 70 - cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); -#else - q_scale_factor[tblno] = jpeg_quality_scaling(val); -#endif - while (*arg && *arg++ != ','); /* advance to next segment of arg - string */ - } else { - /* reached end of parameter, set remaining factors to last value */ -#if JPEG_LIB_VERSION >= 70 - cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); -#else - q_scale_factor[tblno] = jpeg_quality_scaling(val); -#endif - } - } - jpeg_default_qtables(cinfo, force_baseline); - return TRUE; -} - - -GLOBAL(boolean) -set_quant_slots(j_compress_ptr cinfo, char *arg) -/* Process a quantization-table-selectors parameter string, of the form - * N[,N,...] - * If there are more components than parameters, the last value is replicated. - */ -{ - int val = 0; /* default table # */ - int ci; - char ch; - - for (ci = 0; ci < MAX_COMPONENTS; ci++) { - if (*arg) { - ch = ','; /* if not set by sscanf, will be ',' */ - if (sscanf(arg, "%d%c", &val, &ch) < 1) - return FALSE; - if (ch != ',') /* syntax check */ - return FALSE; - if (val < 0 || val >= NUM_QUANT_TBLS) { - fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", - NUM_QUANT_TBLS - 1); - return FALSE; - } - cinfo->comp_info[ci].quant_tbl_no = val; - while (*arg && *arg++ != ','); /* advance to next segment of arg - string */ - } else { - /* reached end of parameter, set remaining components to last table */ - cinfo->comp_info[ci].quant_tbl_no = val; - } - } - return TRUE; -} - - -GLOBAL(boolean) -set_sample_factors(j_compress_ptr cinfo, char *arg) -/* Process a sample-factors parameter string, of the form - * HxV[,HxV,...] - * If there are more components than parameters, "1x1" is assumed for the rest. - */ -{ - int ci, val1, val2; - char ch1, ch2; - - for (ci = 0; ci < MAX_COMPONENTS; ci++) { - if (*arg) { - ch2 = ','; /* if not set by sscanf, will be ',' */ - if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) - return FALSE; - if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ - return FALSE; - if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) { - fprintf(stderr, "JPEG sampling factors must be 1..4\n"); - return FALSE; - } - cinfo->comp_info[ci].h_samp_factor = val1; - cinfo->comp_info[ci].v_samp_factor = val2; - while (*arg && *arg++ != ','); /* advance to next segment of arg - string */ - } else { - /* reached end of parameter, set remaining components to 1x1 sampling */ - cinfo->comp_info[ci].h_samp_factor = 1; - cinfo->comp_info[ci].v_samp_factor = 1; - } - } - return TRUE; -} diff --git a/3rdparty/libjpeg-turbo/src/rdtarga.c b/3rdparty/libjpeg-turbo/src/rdtarga.c deleted file mode 100644 index b78a16539e..0000000000 --- a/3rdparty/libjpeg-turbo/src/rdtarga.c +++ /dev/null @@ -1,507 +0,0 @@ -/* - * rdtarga.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1991-1996, Thomas G. Lane. - * Modified 2017 by Guido Vollbeding. - * libjpeg-turbo Modifications: - * Copyright (C) 2018, 2021-2023, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains routines to read input images in Targa format. - * - * These routines may need modification for non-Unix environments or - * specialized applications. As they stand, they assume input from - * an ordinary stdio stream. They further assume that reading begins - * at the start of the file; start_input may need work if the - * user interface has already read some data (e.g., to determine that - * the file is indeed Targa format). - * - * Based on code contributed by Lee Daniel Crocker. - */ - -#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ - -#ifdef TARGA_SUPPORTED - - -/* Macros to deal with unsigned chars as efficiently as compiler allows */ - -typedef unsigned char U_CHAR; -#define UCH(x) ((int)(x)) - - -#define ReadOK(file, buffer, len) \ - (fread(buffer, 1, len, file) == ((size_t)(len))) - - -/* Private version of data source object */ - -typedef struct _tga_source_struct *tga_source_ptr; - -typedef struct _tga_source_struct { - struct cjpeg_source_struct pub; /* public fields */ - - j_compress_ptr cinfo; /* back link saves passing separate parm */ - - JSAMPARRAY colormap; /* Targa colormap (converted to my format) */ - - jvirt_sarray_ptr whole_image; /* Needed if funny input row order */ - JDIMENSION current_row; /* Current logical row number to read */ - - /* Pointer to routine to extract next Targa pixel from input file */ - void (*read_pixel) (tga_source_ptr sinfo); - - /* Result of read_pixel is delivered here: */ - U_CHAR tga_pixel[4]; - - int pixel_size; /* Bytes per Targa pixel (1 to 4) */ - int cmap_length; /* colormap length */ - - /* State info for reading RLE-coded pixels; both counts must be init to 0 */ - int block_count; /* # of pixels remaining in RLE block */ - int dup_pixel_count; /* # of times to duplicate previous pixel */ - - /* This saves the correct pixel-row-expansion method for preload_image */ - JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo); -} tga_source_struct; - - -/* For expanding 5-bit pixel values to 8-bit with best rounding */ - -static const UINT8 c5to8bits[32] = { - 0, 8, 16, 25, 33, 41, 49, 58, - 66, 74, 82, 90, 99, 107, 115, 123, - 132, 140, 148, 156, 165, 173, 181, 189, - 197, 206, 214, 222, 230, 239, 247, 255 -}; - - - -LOCAL(int) -read_byte(tga_source_ptr sinfo) -/* Read next byte from Targa file */ -{ - register FILE *infile = sinfo->pub.input_file; - register int c; - - if ((c = getc(infile)) == EOF) - ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); - return c; -} - - -LOCAL(void) -read_colormap(tga_source_ptr sinfo, int cmaplen, int mapentrysize) -/* Read the colormap from a Targa file */ -{ - int i; - - /* Presently only handles 24-bit BGR format */ - if (mapentrysize != 24) - ERREXIT(sinfo->cinfo, JERR_TGA_BADCMAP); - - for (i = 0; i < cmaplen; i++) { - sinfo->colormap[2][i] = (JSAMPLE)read_byte(sinfo); - sinfo->colormap[1][i] = (JSAMPLE)read_byte(sinfo); - sinfo->colormap[0][i] = (JSAMPLE)read_byte(sinfo); - } -} - - -/* - * read_pixel methods: get a single pixel from Targa file into tga_pixel[] - */ - -METHODDEF(void) -read_non_rle_pixel(tga_source_ptr sinfo) -/* Read one Targa pixel from the input file; no RLE expansion */ -{ - register int i; - - for (i = 0; i < sinfo->pixel_size; i++) { - sinfo->tga_pixel[i] = (U_CHAR)read_byte(sinfo); - } -} - - -METHODDEF(void) -read_rle_pixel(tga_source_ptr sinfo) -/* Read one Targa pixel from the input file, expanding RLE data as needed */ -{ - register int i; - - /* Duplicate previously read pixel? */ - if (sinfo->dup_pixel_count > 0) { - sinfo->dup_pixel_count--; - return; - } - - /* Time to read RLE block header? */ - if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */ - i = read_byte(sinfo); - if (i & 0x80) { /* Start of duplicate-pixel block? */ - sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */ - sinfo->block_count = 0; /* then read new block header */ - } else { - sinfo->block_count = i & 0x7F; /* number of pixels after this one */ - } - } - - /* Read next pixel */ - for (i = 0; i < sinfo->pixel_size; i++) { - sinfo->tga_pixel[i] = (U_CHAR)read_byte(sinfo); - } -} - - -/* - * Read one row of pixels. - * - * We provide several different versions depending on input file format. - */ - - -METHODDEF(JDIMENSION) -get_8bit_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 8-bit grayscale pixels */ -{ - tga_source_ptr source = (tga_source_ptr)sinfo; - register JSAMPROW ptr; - register JDIMENSION col; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ - *ptr++ = (JSAMPLE)UCH(source->tga_pixel[0]); - } - return 1; -} - -METHODDEF(JDIMENSION) -get_8bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 8-bit colormap indexes */ -{ - tga_source_ptr source = (tga_source_ptr)sinfo; - register int t; - register JSAMPROW ptr; - register JDIMENSION col; - register JSAMPARRAY colormap = source->colormap; - int cmaplen = source->cmap_length; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ - t = UCH(source->tga_pixel[0]); - if (t >= cmaplen) - ERREXIT(cinfo, JERR_TGA_BADPARMS); - *ptr++ = colormap[0][t]; - *ptr++ = colormap[1][t]; - *ptr++ = colormap[2][t]; - } - return 1; -} - -METHODDEF(JDIMENSION) -get_16bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 16-bit pixels */ -{ - tga_source_ptr source = (tga_source_ptr)sinfo; - register int t; - register JSAMPROW ptr; - register JDIMENSION col; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ - t = UCH(source->tga_pixel[0]); - t += UCH(source->tga_pixel[1]) << 8; - /* We expand 5 bit data to 8 bit sample width. - * The format of the 16-bit (LSB first) input word is - * xRRRRRGGGGGBBBBB - */ - ptr[2] = (JSAMPLE)c5to8bits[t & 0x1F]; - t >>= 5; - ptr[1] = (JSAMPLE)c5to8bits[t & 0x1F]; - t >>= 5; - ptr[0] = (JSAMPLE)c5to8bits[t & 0x1F]; - ptr += 3; - } - return 1; -} - -METHODDEF(JDIMENSION) -get_24bit_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -/* This version is for reading 24-bit pixels */ -{ - tga_source_ptr source = (tga_source_ptr)sinfo; - register JSAMPROW ptr; - register JDIMENSION col; - - ptr = source->pub.buffer[0]; - for (col = cinfo->image_width; col > 0; col--) { - (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ - *ptr++ = (JSAMPLE)UCH(source->tga_pixel[2]); /* change BGR to RGB order */ - *ptr++ = (JSAMPLE)UCH(source->tga_pixel[1]); - *ptr++ = (JSAMPLE)UCH(source->tga_pixel[0]); - } - return 1; -} - -/* - * Targa also defines a 32-bit pixel format with order B,G,R,A. - * We presently ignore the attribute byte, so the code for reading - * these pixels is identical to the 24-bit routine above. - * This works because the actual pixel length is only known to read_pixel. - */ - -#define get_32bit_row get_24bit_row - - -/* - * This method is for re-reading the input data in standard top-down - * row order. The entire image has already been read into whole_image - * with proper conversion of pixel format, but it's in a funny row order. - */ - -METHODDEF(JDIMENSION) -get_memory_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - tga_source_ptr source = (tga_source_ptr)sinfo; - JDIMENSION source_row; - - /* Compute row of source that maps to current_row of normal order */ - /* For now, assume image is bottom-up and not interlaced. */ - /* NEEDS WORK to support interlaced images! */ - source_row = cinfo->image_height - source->current_row - 1; - - /* Fetch that row from virtual array */ - source->pub.buffer = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr)cinfo, source->whole_image, - source_row, (JDIMENSION)1, FALSE); - - source->current_row++; - return 1; -} - - -/* - * This method loads the image into whole_image during the first call on - * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call - * get_memory_row on subsequent calls. - */ - -METHODDEF(JDIMENSION) -preload_image(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - tga_source_ptr source = (tga_source_ptr)sinfo; - JDIMENSION row; - cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress; - - /* Read the data into a virtual array in input-file row order. */ - for (row = 0; row < cinfo->image_height; row++) { - if (progress != NULL) { - progress->pub.pass_counter = (long)row; - progress->pub.pass_limit = (long)cinfo->image_height; - (*progress->pub.progress_monitor) ((j_common_ptr)cinfo); - } - source->pub.buffer = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr)cinfo, source->whole_image, row, (JDIMENSION)1, TRUE); - (*source->get_pixel_rows) (cinfo, sinfo); - } - if (progress != NULL) - progress->completed_extra_passes++; - - /* Set up to read from the virtual array in unscrambled order */ - source->pub.get_pixel_rows = get_memory_row; - source->current_row = 0; - /* And read the first row */ - return get_memory_row(cinfo, sinfo); -} - - -/* - * Read the file header; return image size and component count. - */ - -METHODDEF(void) -start_input_tga(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - tga_source_ptr source = (tga_source_ptr)sinfo; - U_CHAR targaheader[18]; - int idlen, cmaptype, subtype, flags, interlace_type, components; - unsigned int width, height, maplen; - boolean is_bottom_up; - -#define GET_2B(offset) \ - ((unsigned int)UCH(targaheader[offset]) + \ - (((unsigned int)UCH(targaheader[offset + 1])) << 8)) - - if (!ReadOK(source->pub.input_file, targaheader, 18)) - ERREXIT(cinfo, JERR_INPUT_EOF); - - /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */ - if (targaheader[16] == 15) - targaheader[16] = 16; - - idlen = UCH(targaheader[0]); - cmaptype = UCH(targaheader[1]); - subtype = UCH(targaheader[2]); - maplen = GET_2B(5); - width = GET_2B(12); - height = GET_2B(14); - source->pixel_size = UCH(targaheader[16]) >> 3; - flags = UCH(targaheader[17]); /* Image Descriptor byte */ - - is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */ - interlace_type = flags >> 6; /* bits 6/7 are interlace code */ - - if (cmaptype > 1 || /* cmaptype must be 0 or 1 */ - source->pixel_size < 1 || source->pixel_size > 4 || - (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */ - interlace_type != 0 || /* currently don't allow interlaced image */ - width == 0 || height == 0) /* image width/height must be non-zero */ - ERREXIT(cinfo, JERR_TGA_BADPARMS); - if (sinfo->max_pixels && - (unsigned long long)width * height > sinfo->max_pixels) - ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, sinfo->max_pixels); - - if (subtype > 8) { - /* It's an RLE-coded file */ - source->read_pixel = read_rle_pixel; - source->block_count = source->dup_pixel_count = 0; - subtype -= 8; - } else { - /* Non-RLE file */ - source->read_pixel = read_non_rle_pixel; - } - - /* Now should have subtype 1, 2, or 3 */ - components = 3; /* until proven different */ - cinfo->in_color_space = JCS_RGB; - - switch (subtype) { - case 1: /* Colormapped image */ - if (source->pixel_size == 1 && cmaptype == 1) - source->get_pixel_rows = get_8bit_row; - else - ERREXIT(cinfo, JERR_TGA_BADPARMS); - TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height); - break; - case 2: /* RGB image */ - switch (source->pixel_size) { - case 2: - source->get_pixel_rows = get_16bit_row; - break; - case 3: - source->get_pixel_rows = get_24bit_row; - break; - case 4: - source->get_pixel_rows = get_32bit_row; - break; - default: - ERREXIT(cinfo, JERR_TGA_BADPARMS); - break; - } - TRACEMS2(cinfo, 1, JTRC_TGA, width, height); - break; - case 3: /* Grayscale image */ - components = 1; - cinfo->in_color_space = JCS_GRAYSCALE; - if (source->pixel_size == 1) - source->get_pixel_rows = get_8bit_gray_row; - else - ERREXIT(cinfo, JERR_TGA_BADPARMS); - TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height); - break; - default: - ERREXIT(cinfo, JERR_TGA_BADPARMS); - break; - } - - if (is_bottom_up) { - /* Create a virtual array to buffer the upside-down image. */ - source->whole_image = (*cinfo->mem->request_virt_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE, - (JDIMENSION)width * components, (JDIMENSION)height, (JDIMENSION)1); - if (cinfo->progress != NULL) { - cd_progress_ptr progress = (cd_progress_ptr)cinfo->progress; - progress->total_extra_passes++; /* count file input as separate pass */ - } - /* source->pub.buffer will point to the virtual array. */ - source->pub.buffer_height = 1; /* in case anyone looks at it */ - source->pub.get_pixel_rows = preload_image; - } else { - /* Don't need a virtual array, but do need a one-row input buffer. */ - source->whole_image = NULL; - source->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, - (JDIMENSION)width * components, (JDIMENSION)1); - source->pub.buffer_height = 1; - source->pub.get_pixel_rows = source->get_pixel_rows; - } - - while (idlen--) /* Throw away ID field */ - (void)read_byte(source); - - if (maplen > 0) { - if (maplen > 256 || GET_2B(3) != 0) - ERREXIT(cinfo, JERR_TGA_BADCMAP); - /* Allocate space to store the colormap */ - source->colormap = (*cinfo->mem->alloc_sarray) - ((j_common_ptr)cinfo, JPOOL_IMAGE, (JDIMENSION)maplen, (JDIMENSION)3); - source->cmap_length = (int)maplen; - /* and read it from the file */ - read_colormap(source, (int)maplen, UCH(targaheader[7])); - } else { - if (cmaptype) /* but you promised a cmap! */ - ERREXIT(cinfo, JERR_TGA_BADPARMS); - source->colormap = NULL; - source->cmap_length = 0; - } - - cinfo->input_components = components; - cinfo->data_precision = 8; - cinfo->image_width = width; - cinfo->image_height = height; -} - - -/* - * Finish up at the end of the file. - */ - -METHODDEF(void) -finish_input_tga(j_compress_ptr cinfo, cjpeg_source_ptr sinfo) -{ - /* no work */ -} - - -/* - * The module selection routine for Targa format input. - */ - -GLOBAL(cjpeg_source_ptr) -jinit_read_targa(j_compress_ptr cinfo) -{ - tga_source_ptr source; - - if (cinfo->data_precision != 8) - ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); - - /* Create module interface object */ - source = (tga_source_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, - sizeof(tga_source_struct)); - source->cinfo = cinfo; /* make back link for subroutines */ - /* Fill in method ptrs, except get_pixel_rows which start_input sets */ - source->pub.start_input = start_input_tga; - source->pub.finish_input = finish_input_tga; - source->pub.max_pixels = 0; - - return (cjpeg_source_ptr)source; -} - -#endif /* TARGA_SUPPORTED */ diff --git a/3rdparty/libjpeg-turbo/src/tjbench.c b/3rdparty/libjpeg-turbo/src/tjbench.c deleted file mode 100644 index 9dc6427880..0000000000 --- a/3rdparty/libjpeg-turbo/src/tjbench.c +++ /dev/null @@ -1,1323 +0,0 @@ -/* - * Copyright (C)2009-2019, 2021-2024 D. R. Commander. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the libjpeg-turbo Project nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _MSC_VER -#define _CRT_SECURE_NO_DEPRECATE -#endif - -#include -#include -#include -#include -#include -#include -#include -#if !defined(_MSC_VER) || _MSC_VER > 1600 -#include -#endif -#include -#include "./tjutil.h" -#include "./turbojpeg.h" - - -#define THROW(op, err) { \ - printf("ERROR in line %d while %s:\n%s\n", __LINE__, op, err); \ - retval = -1; goto bailout; \ -} -#define THROW_UNIX(m) THROW(m, strerror(errno)) - -static char tjErrorStr[JMSG_LENGTH_MAX] = "\0"; -static int tjErrorLine = -1, tjErrorCode = -1; - -#define THROW_TJG() { \ - printf("ERROR in line %d\n%s\n", __LINE__, tj3GetErrorStr(NULL)); \ - retval = -1; goto bailout; \ -} - -#define THROW_TJ() { \ - int _tjErrorCode = tj3GetErrorCode(handle); \ - char *_tjErrorStr = tj3GetErrorStr(handle); \ - \ - if (!tj3Get(handle, TJPARAM_STOPONWARNING) && \ - _tjErrorCode == TJERR_WARNING) { \ - if (strncmp(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX) || \ - tjErrorCode != _tjErrorCode || tjErrorLine != __LINE__) { \ - strncpy(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX); \ - tjErrorStr[JMSG_LENGTH_MAX - 1] = '\0'; \ - tjErrorCode = _tjErrorCode; \ - tjErrorLine = __LINE__; \ - printf("WARNING in line %d:\n%s\n", __LINE__, _tjErrorStr); \ - } \ - } else { \ - printf("%s in line %d:\n%s\n", \ - _tjErrorCode == TJERR_WARNING ? "WARNING" : "ERROR", __LINE__, \ - _tjErrorStr); \ - retval = -1; goto bailout; \ - } \ -} - -#define IS_CROPPED(cr) (cr.x != 0 || cr.y != 0 || cr.w != 0 || cr.h != 0) - -#define CROPPED_WIDTH(width) \ - (IS_CROPPED(cr) ? (cr.w != 0 ? cr.w : TJSCALED(width, sf) - cr.x) : \ - TJSCALED(width, sf)) - -#define CROPPED_HEIGHT(height) \ - (IS_CROPPED(cr) ? (cr.h != 0 ? cr.h : TJSCALED(height, sf) - cr.y) : \ - TJSCALED(height, sf)) - -static int stopOnWarning = 0, bottomUp = 0, noRealloc = 1, fastUpsample = 0, - fastDCT = 0, optimize = 0, progressive = 0, limitScans = 0, maxMemory = 0, - maxPixels = 0, arithmetic = 0, lossless = 0, restartIntervalBlocks = 0, - restartIntervalRows = 0; -static int precision = 8, sampleSize, compOnly = 0, decompOnly = 0, doYUV = 0, - quiet = 0, doTile = 0, pf = TJPF_BGR, yuvAlign = 1, doWrite = 1; -static char *ext = "ppm"; -static const char *pixFormatStr[TJ_NUMPF] = { - "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY", "", "", "", "", "CMYK" -}; -static const char *subNameLong[TJ_NUMSAMP] = { - "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1", "4:4:1" -}; -static const char *csName[TJ_NUMCS] = { - "RGB", "YCbCr", "GRAY", "CMYK", "YCCK" -}; -static const char *subName[TJ_NUMSAMP] = { - "444", "422", "420", "GRAY", "440", "411", "441" -}; -static tjscalingfactor *scalingFactors = NULL, sf = { 1, 1 }; -static tjregion cr = { 0, 0, 0, 0 }; -static int nsf = 0, xformOp = TJXOP_NONE, xformOpt = 0; -static int (*customFilter) (short *, tjregion, tjregion, int, int, - tjtransform *); -static double benchTime = 5.0, warmup = 1.0; - - -static char *formatName(int subsamp, int cs, char *buf) -{ - if (quiet == 1) { - if (lossless) - SNPRINTF(buf, 80, "%-2d/LOSSLESS ", precision); - else if (subsamp == TJSAMP_UNKNOWN) - SNPRINTF(buf, 80, "%-2d/%-5s ", precision, csName[cs]); - else - SNPRINTF(buf, 80, "%-2d/%-5s/%-5s", precision, csName[cs], - subNameLong[subsamp]); - return buf; - } else { - if (lossless) - return (char *)"Lossless"; - else if (subsamp == TJSAMP_UNKNOWN) - return (char *)csName[cs]; - else { - SNPRINTF(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]); - return buf; - } - } -} - - -static char *sigfig(double val, int figs, char *buf, int len) -{ - char format[80]; - int digitsAfterDecimal = figs - (int)ceil(log10(fabs(val))); - - if (digitsAfterDecimal < 1) - SNPRINTF(format, 80, "%%.0f"); - else - SNPRINTF(format, 80, "%%.%df", digitsAfterDecimal); - SNPRINTF(buf, len, format, val); - return buf; -} - - -/* Custom DCT filter which produces a negative of the image */ -static int dummyDCTFilter(short *coeffs, tjregion arrayRegion, - tjregion planeRegion, int componentIndex, - int transformIndex, tjtransform *transform) -{ - int i; - - for (i = 0; i < arrayRegion.w * arrayRegion.h; i++) - coeffs[i] = -coeffs[i]; - return 0; -} - - -/* Decompression test */ -static int decomp(unsigned char **jpegBufs, size_t *jpegSizes, void *dstBuf, - int w, int h, int subsamp, int jpegQual, char *fileName, - int tilew, int tileh) -{ - char tempStr[1024], sizeStr[24] = "\0", qualStr[16] = "\0"; - FILE *file = NULL; - tjhandle handle = NULL; - int i, row, col, iter = 0, dstBufAlloc = 0, retval = 0; - double elapsed, elapsedDecode; - int ps = tjPixelSize[pf]; - int scaledw, scaledh, pitch; - int ntilesw = (w + tilew - 1) / tilew, ntilesh = (h + tileh - 1) / tileh; - unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL; - - if (lossless) sf = TJUNSCALED; - - scaledw = TJSCALED(w, sf); - scaledh = TJSCALED(h, sf); - - if (jpegQual > 0) { - SNPRINTF(qualStr, 16, "_%s%d", lossless ? "PSV" : "Q", jpegQual); - qualStr[15] = 0; - } - - if ((handle = tj3Init(TJINIT_DECOMPRESS)) == NULL) - THROW_TJG(); - if (tj3Set(handle, TJPARAM_STOPONWARNING, stopOnWarning) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_BOTTOMUP, bottomUp) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_FASTUPSAMPLE, fastUpsample) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_FASTDCT, fastDCT) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_SCANLIMIT, limitScans ? 500 : 0) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_MAXMEMORY, maxMemory) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_MAXPIXELS, maxPixels) == -1) - THROW_TJ(); - - if (IS_CROPPED(cr)) { - if (tj3DecompressHeader(handle, jpegBufs[0], jpegSizes[0]) == -1) - THROW_TJ(); - } - if (tj3SetScalingFactor(handle, sf) == -1) - THROW_TJ(); - if (tj3SetCroppingRegion(handle, cr) == -1) - THROW_TJ(); - if (IS_CROPPED(cr)) { - scaledw = cr.w ? cr.w : scaledw - cr.x; - scaledh = cr.h ? cr.h : scaledh - cr.y; - } - pitch = scaledw * ps; - - if (dstBuf == NULL) { -#if ULLONG_MAX > SIZE_MAX - if ((unsigned long long)pitch * (unsigned long long)scaledh * - (unsigned long long)sampleSize > (unsigned long long)((size_t)-1)) - THROW("allocating destination buffer", "Image is too large"); -#endif - if ((dstBuf = malloc((size_t)pitch * scaledh * sampleSize)) == NULL) - THROW_UNIX("allocating destination buffer"); - dstBufAlloc = 1; - } - - /* Set the destination buffer to gray so we know whether the decompressor - attempted to write to it */ - if (precision == 8) - memset((unsigned char *)dstBuf, 127, (size_t)pitch * scaledh); - else if (precision == 12) { - for (i = 0; i < pitch * scaledh; i++) - ((short *)dstBuf)[i] = (short)2047; - } else { - for (i = 0; i < pitch * scaledh; i++) - ((unsigned short *)dstBuf)[i] = (unsigned short)32767; - } - - if (doYUV) { - int width = doTile ? tilew : scaledw; - int height = doTile ? tileh : scaledh; - size_t yuvSize = tj3YUVBufSize(width, yuvAlign, height, subsamp); - - if (yuvSize == 0) - THROW_TJG(); - if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL) - THROW_UNIX("allocating YUV buffer"); - memset(yuvBuf, 127, yuvSize); - } - - /* Benchmark */ - iter = -1; - elapsed = elapsedDecode = 0.; - while (1) { - int tile = 0; - double start = getTime(); - - for (row = 0, dstPtr = dstBuf; row < ntilesh; - row++, dstPtr += (size_t)pitch * tileh * sampleSize) { - for (col = 0, dstPtr2 = dstPtr; col < ntilesw; - col++, tile++, dstPtr2 += ps * tilew * sampleSize) { - int width = doTile ? min(tilew, w - col * tilew) : scaledw; - int height = doTile ? min(tileh, h - row * tileh) : scaledh; - - if (doYUV) { - double startDecode; - - if (tj3DecompressToYUV8(handle, jpegBufs[tile], jpegSizes[tile], - yuvBuf, yuvAlign) == -1) - THROW_TJ(); - startDecode = getTime(); - if (tj3DecodeYUV8(handle, yuvBuf, yuvAlign, dstPtr2, width, pitch, - height, pf) == -1) - THROW_TJ(); - if (iter >= 0) elapsedDecode += getTime() - startDecode; - } else { - if (precision == 8) { - if (tj3Decompress8(handle, jpegBufs[tile], jpegSizes[tile], - dstPtr2, pitch, pf) == -1) - THROW_TJ(); - } else if (precision == 12) { - if (tj3Decompress12(handle, jpegBufs[tile], jpegSizes[tile], - (short *)dstPtr2, pitch, pf) == -1) - THROW_TJ(); - } else { - if (tj3Decompress16(handle, jpegBufs[tile], jpegSizes[tile], - (unsigned short *)dstPtr2, pitch, pf) == -1) - THROW_TJ(); - } - } - } - } - elapsed += getTime() - start; - if (iter >= 0) { - iter++; - if (elapsed >= benchTime) break; - } else if (elapsed >= warmup) { - iter = 0; - elapsed = elapsedDecode = 0.; - } - } - if (doYUV) elapsed -= elapsedDecode; - - if (quiet) { - printf("%-6s%s", - sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4, - tempStr, 1024), - quiet == 2 ? "\n" : " "); - if (doYUV) - printf("%s\n", - sigfig((double)(w * h) / 1000000. * (double)iter / elapsedDecode, - 4, tempStr, 1024)); - else if (quiet != 2) printf("\n"); - } else { - printf("%s --> Frame rate: %f fps\n", - doYUV ? "Decomp to YUV" : "Decompress ", (double)iter / elapsed); - printf(" Throughput: %f Megapixels/sec\n", - (double)(w * h) / 1000000. * (double)iter / elapsed); - if (doYUV) { - printf("YUV Decode --> Frame rate: %f fps\n", - (double)iter / elapsedDecode); - printf(" Throughput: %f Megapixels/sec\n", - (double)(w * h) / 1000000. * (double)iter / elapsedDecode); - } - } - - if (!doWrite) goto bailout; - - if (sf.num != 1 || sf.denom != 1) - SNPRINTF(sizeStr, 24, "%d_%d", sf.num, sf.denom); - else if (tilew != w || tileh != h) - SNPRINTF(sizeStr, 24, "%dx%d", tilew, tileh); - else SNPRINTF(sizeStr, 24, "full"); - if (decompOnly) - SNPRINTF(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext); - else - SNPRINTF(tempStr, 1024, "%s_%s%s_%s.%s", fileName, - lossless ? "LOSSLS" : subName[subsamp], qualStr, sizeStr, ext); - - if (precision == 8) { - if (tj3SaveImage8(handle, tempStr, (unsigned char *)dstBuf, scaledw, 0, - scaledh, pf) == -1) - THROW_TJ(); - } else if (precision == 12) { - if (tj3SaveImage12(handle, tempStr, (short *)dstBuf, scaledw, 0, scaledh, - pf) == -1) - THROW_TJ(); - } else { - if (tj3SaveImage16(handle, tempStr, (unsigned short *)dstBuf, scaledw, 0, - scaledh, pf) == -1) - THROW_TJ(); - } - -bailout: - if (file) fclose(file); - tj3Destroy(handle); - if (dstBufAlloc) free(dstBuf); - free(yuvBuf); - return retval; -} - - -static int fullTest(tjhandle handle, void *srcBuf, int w, int h, int subsamp, - int jpegQual, char *fileName) -{ - char tempStr[1024], tempStr2[80]; - FILE *file = NULL; - unsigned char **jpegBufs = NULL, *yuvBuf = NULL, *srcPtr, *srcPtr2; - void *tmpBuf = NULL; - double start, elapsed, elapsedEncode; - int row, col, i, tilew = w, tileh = h, retval = 0; - int iter; - size_t totalJpegSize = 0, *jpegSizes = NULL, yuvSize = 0; - int ps = tjPixelSize[pf]; - int ntilesw = 1, ntilesh = 1, pitch = w * ps; - const char *pfStr = pixFormatStr[pf]; - -#if ULLONG_MAX > SIZE_MAX - if ((unsigned long long)pitch * (unsigned long long)h * - (unsigned long long)sampleSize > (unsigned long long)((size_t)-1)) - THROW("allocating temporary image buffer", "Image is too large"); -#endif - if ((tmpBuf = malloc((size_t)pitch * h * sampleSize)) == NULL) - THROW_UNIX("allocating temporary image buffer"); - - if (!quiet) - printf(">>>>> %s (%s) <--> %d-bit JPEG (%s %s%d) <<<<<\n", pfStr, - bottomUp ? "Bottom-up" : "Top-down", precision, - lossless ? "Lossless" : subNameLong[subsamp], - lossless ? "PSV" : "Q", jpegQual); - - for (tilew = doTile ? 8 : w, tileh = doTile ? 8 : h; ; - tilew *= 2, tileh *= 2) { - if (tilew > w) tilew = w; - if (tileh > h) tileh = h; - ntilesw = (w + tilew - 1) / tilew; - ntilesh = (h + tileh - 1) / tileh; - - if ((jpegBufs = (unsigned char **)malloc(sizeof(unsigned char *) * - ntilesw * ntilesh)) == NULL) - THROW_UNIX("allocating JPEG tile array"); - memset(jpegBufs, 0, sizeof(unsigned char *) * ntilesw * ntilesh); - if ((jpegSizes = (size_t *)malloc(sizeof(size_t) * ntilesw * - ntilesh)) == NULL) - THROW_UNIX("allocating JPEG size array"); - memset(jpegSizes, 0, sizeof(size_t) * ntilesw * ntilesh); - - if (noRealloc) { - for (i = 0; i < ntilesw * ntilesh; i++) { - size_t jpegBufSize = tj3JPEGBufSize(tilew, tileh, subsamp); - - if (jpegBufSize == 0) - THROW_TJG(); - if ((jpegBufs[i] = tj3Alloc(jpegBufSize)) == NULL) - THROW_UNIX("allocating JPEG tiles"); - } - } - - /* Compression test */ - if (quiet == 1) - printf("%-4s(%s) %-2d/%-6s %-3d ", pfStr, bottomUp ? "BU" : "TD", - precision, lossless ? "LOSSLS" : subNameLong[subsamp], jpegQual); - if (precision == 8) { - for (i = 0; i < h; i++) - memcpy(&((unsigned char *)tmpBuf)[pitch * i], - &((unsigned char *)srcBuf)[w * ps * i], w * ps); - } else { - for (i = 0; i < h; i++) - memcpy(&((unsigned short *)tmpBuf)[pitch * i], - &((unsigned short *)srcBuf)[w * ps * i], w * ps * sampleSize); - } - - if (tj3Set(handle, TJPARAM_NOREALLOC, noRealloc) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_SUBSAMP, subsamp) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_FASTDCT, fastDCT) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_OPTIMIZE, optimize) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_PROGRESSIVE, progressive) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_ARITHMETIC, arithmetic) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_LOSSLESS, lossless) == -1) - THROW_TJ(); - if (lossless) { - if (tj3Set(handle, TJPARAM_LOSSLESSPSV, jpegQual) == -1) - THROW_TJ(); - } else { - if (tj3Set(handle, TJPARAM_QUALITY, jpegQual) == -1) - THROW_TJ(); - } - if (tj3Set(handle, TJPARAM_RESTARTBLOCKS, restartIntervalBlocks) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_RESTARTROWS, restartIntervalRows) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_MAXMEMORY, maxMemory) == -1) - THROW_TJ(); - - if (doYUV) { - yuvSize = tj3YUVBufSize(tilew, yuvAlign, tileh, subsamp); - if (yuvSize == 0) - THROW_TJG(); - if ((yuvBuf = (unsigned char *)malloc(yuvSize)) == NULL) - THROW_UNIX("allocating YUV buffer"); - memset(yuvBuf, 127, yuvSize); - } - - /* Benchmark */ - iter = -1; - elapsed = elapsedEncode = 0.; - while (1) { - int tile = 0; - - totalJpegSize = 0; - start = getTime(); - for (row = 0, srcPtr = srcBuf; row < ntilesh; - row++, srcPtr += pitch * tileh * sampleSize) { - for (col = 0, srcPtr2 = srcPtr; col < ntilesw; - col++, tile++, srcPtr2 += ps * tilew * sampleSize) { - int width = min(tilew, w - col * tilew); - int height = min(tileh, h - row * tileh); - - if (doYUV) { - double startEncode = getTime(); - - if (tj3EncodeYUV8(handle, srcPtr2, width, pitch, height, pf, - yuvBuf, yuvAlign) == -1) - THROW_TJ(); - if (iter >= 0) elapsedEncode += getTime() - startEncode; - if (tj3CompressFromYUV8(handle, yuvBuf, width, yuvAlign, height, - &jpegBufs[tile], &jpegSizes[tile]) == -1) - THROW_TJ(); - } else { - if (precision == 8) { - if (tj3Compress8(handle, srcPtr2, width, pitch, height, pf, - &jpegBufs[tile], &jpegSizes[tile]) == -1) - THROW_TJ(); - } else if (precision == 12) { - if (tj3Compress12(handle, (short *)srcPtr2, width, pitch, height, - pf, &jpegBufs[tile], &jpegSizes[tile]) == -1) - THROW_TJ(); - } else { - if (tj3Compress16(handle, (unsigned short *)srcPtr2, width, - pitch, height, pf, &jpegBufs[tile], - &jpegSizes[tile]) == -1) - THROW_TJ(); - } - } - totalJpegSize += jpegSizes[tile]; - } - } - elapsed += getTime() - start; - if (iter >= 0) { - iter++; - if (elapsed >= benchTime) break; - } else if (elapsed >= warmup) { - iter = 0; - elapsed = elapsedEncode = 0.; - } - } - if (doYUV) elapsed -= elapsedEncode; - - if (quiet == 1) printf("%-5d %-5d ", tilew, tileh); - if (quiet) { - if (doYUV) - printf("%-6s%s", - sigfig((double)(w * h) / 1000000. * - (double)iter / elapsedEncode, 4, tempStr, 1024), - quiet == 2 ? "\n" : " "); - printf("%-6s%s", - sigfig((double)(w * h) / 1000000. * (double)iter / elapsed, 4, - tempStr, 1024), - quiet == 2 ? "\n" : " "); - printf("%-6s%s", - sigfig((double)(w * h * ps) / (double)totalJpegSize, 4, tempStr2, - 80), - quiet == 2 ? "\n" : " "); - } else { - printf("\n%s size: %d x %d\n", doTile ? "Tile" : "Image", tilew, tileh); - if (doYUV) { - printf("Encode YUV --> Frame rate: %f fps\n", - (double)iter / elapsedEncode); - printf(" Output image size: %lu bytes\n", - (unsigned long)yuvSize); - printf(" Compression ratio: %f:1\n", - (double)(w * h * ps) / (double)yuvSize); - printf(" Throughput: %f Megapixels/sec\n", - (double)(w * h) / 1000000. * (double)iter / elapsedEncode); - printf(" Output bit stream: %f Megabits/sec\n", - (double)yuvSize * 8. / 1000000. * (double)iter / elapsedEncode); - } - printf("%s --> Frame rate: %f fps\n", - doYUV ? "Comp from YUV" : "Compress ", - (double)iter / elapsed); - printf(" Output image size: %lu bytes\n", - (unsigned long)totalJpegSize); - printf(" Compression ratio: %f:1\n", - (double)(w * h * ps) / (double)totalJpegSize); - printf(" Throughput: %f Megapixels/sec\n", - (double)(w * h) / 1000000. * (double)iter / elapsed); - printf(" Output bit stream: %f Megabits/sec\n", - (double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed); - } - if (tilew == w && tileh == h && doWrite) { - SNPRINTF(tempStr, 1024, "%s_%s_%s%d.jpg", fileName, - lossless ? "LOSSLS" : subName[subsamp], - lossless ? "PSV" : "Q", jpegQual); - if ((file = fopen(tempStr, "wb")) == NULL) - THROW_UNIX("opening reference image"); - if (fwrite(jpegBufs[0], jpegSizes[0], 1, file) != 1) - THROW_UNIX("writing reference image"); - fclose(file); file = NULL; - if (!quiet) printf("Reference image written to %s\n", tempStr); - } - - /* Decompression test */ - if (!compOnly) { - if (decomp(jpegBufs, jpegSizes, tmpBuf, w, h, subsamp, jpegQual, - fileName, tilew, tileh) == -1) - goto bailout; - } else if (quiet == 1) printf("N/A\n"); - - for (i = 0; i < ntilesw * ntilesh; i++) { - tj3Free(jpegBufs[i]); - jpegBufs[i] = NULL; - } - free(jpegBufs); jpegBufs = NULL; - free(jpegSizes); jpegSizes = NULL; - if (doYUV) { - free(yuvBuf); yuvBuf = NULL; - } - - if (tilew == w && tileh == h) break; - } - -bailout: - if (file) fclose(file); - if (jpegBufs) { - for (i = 0; i < ntilesw * ntilesh; i++) - tj3Free(jpegBufs[i]); - } - free(jpegBufs); - free(yuvBuf); - free(jpegSizes); - free(tmpBuf); - return retval; -} - - -static int decompTest(char *fileName) -{ - FILE *file = NULL; - tjhandle handle = NULL; - unsigned char **jpegBufs = NULL, *srcBuf = NULL; - size_t *jpegSizes = NULL, srcSize, totalJpegSize; - tjtransform *t = NULL; - double start, elapsed; - int ps = tjPixelSize[pf], tile, row, col, i, iter, retval = 0, decompsrc = 0; - char *temp = NULL, tempStr[80], tempStr2[80]; - /* Original image */ - int w = 0, h = 0, minTile = 16, tilew, tileh, ntilesw = 1, ntilesh = 1, - subsamp = -1, cs = -1; - /* Transformed image */ - int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp; - - if ((file = fopen(fileName, "rb")) == NULL) - THROW_UNIX("opening file"); - if (fseek(file, 0, SEEK_END) < 0 || - (srcSize = ftell(file)) == (size_t)-1) - THROW_UNIX("determining file size"); - if ((srcBuf = (unsigned char *)malloc(srcSize)) == NULL) - THROW_UNIX("allocating memory"); - if (fseek(file, 0, SEEK_SET) < 0) - THROW_UNIX("setting file position"); - if (fread(srcBuf, srcSize, 1, file) < 1) - THROW_UNIX("reading JPEG data"); - fclose(file); file = NULL; - - temp = strrchr(fileName, '.'); - if (temp != NULL) *temp = '\0'; - - if ((handle = tj3Init(TJINIT_TRANSFORM)) == NULL) - THROW_TJG(); - if (tj3Set(handle, TJPARAM_STOPONWARNING, stopOnWarning) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_BOTTOMUP, bottomUp) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_NOREALLOC, noRealloc) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_FASTUPSAMPLE, fastUpsample) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_FASTDCT, fastDCT) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_SCANLIMIT, limitScans ? 500 : 0) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_MAXMEMORY, maxMemory) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_MAXPIXELS, maxPixels) == -1) - THROW_TJ(); - - if (tj3DecompressHeader(handle, srcBuf, srcSize) == -1) - THROW_TJ(); - w = tj3Get(handle, TJPARAM_JPEGWIDTH); - h = tj3Get(handle, TJPARAM_JPEGHEIGHT); - subsamp = tj3Get(handle, TJPARAM_SUBSAMP); - precision = tj3Get(handle, TJPARAM_PRECISION); - if (tj3Get(handle, TJPARAM_PROGRESSIVE) == 1) - printf("JPEG image uses progressive entropy coding\n\n"); - if (tj3Get(handle, TJPARAM_ARITHMETIC) == 1) - printf("JPEG image uses arithmetic entropy coding\n\n"); - if (tj3Set(handle, TJPARAM_PROGRESSIVE, progressive) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_ARITHMETIC, arithmetic) == -1) - THROW_TJ(); - - lossless = tj3Get(handle, TJPARAM_LOSSLESS); - sampleSize = (precision == 8 ? sizeof(unsigned char) : sizeof(short)); - cs = tj3Get(handle, TJPARAM_COLORSPACE); - if (w < 1 || h < 1) - THROW("reading JPEG header", "Invalid image dimensions"); - if (cs == TJCS_YCCK || cs == TJCS_CMYK) { - pf = TJPF_CMYK; ps = tjPixelSize[pf]; - } - if (lossless) sf = TJUNSCALED; - - if (tj3SetScalingFactor(handle, sf) == -1) - THROW_TJ(); - if (tj3SetCroppingRegion(handle, cr) == -1) - THROW_TJ(); - - if (quiet == 1) { - printf("All performance values in Mpixels/sec\n\n"); - printf("Pixel JPEG %s %s Xform Comp Decomp ", - doTile ? "Tile " : "Image", doTile ? "Tile " : "Image"); - if (doYUV) printf("Decode"); - printf("\n"); - printf("Format Format Width Height Perf Ratio Perf "); - if (doYUV) printf("Perf"); - printf("\n\n"); - } else if (!quiet) - printf(">>>>> %d-bit JPEG (%s) --> %s (%s) <<<<<\n", precision, - formatName(subsamp, cs, tempStr), pixFormatStr[pf], - bottomUp ? "Bottom-up" : "Top-down"); - - if (doTile) { - if (subsamp == TJSAMP_UNKNOWN) - THROW("transforming", - "Could not determine subsampling level of JPEG image"); - minTile = max(tjMCUWidth[subsamp], tjMCUHeight[subsamp]); - } - for (tilew = doTile ? minTile : w, tileh = doTile ? minTile : h; ; - tilew *= 2, tileh *= 2) { - if (tilew > w) tilew = w; - if (tileh > h) tileh = h; - ntilesw = (w + tilew - 1) / tilew; - ntilesh = (h + tileh - 1) / tileh; - - if ((jpegBufs = (unsigned char **)malloc(sizeof(unsigned char *) * - ntilesw * ntilesh)) == NULL) - THROW_UNIX("allocating JPEG tile array"); - memset(jpegBufs, 0, sizeof(unsigned char *) * ntilesw * ntilesh); - if ((jpegSizes = (size_t *)malloc(sizeof(size_t) * ntilesw * - ntilesh)) == NULL) - THROW_UNIX("allocating JPEG size array"); - memset(jpegSizes, 0, sizeof(size_t) * ntilesw * ntilesh); - - if (noRealloc && - (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter)) { - for (i = 0; i < ntilesw * ntilesh; i++) { - size_t jpegBufSize; - - if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE || - xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) - jpegBufSize = tj3JPEGBufSize(tileh, tilew, subsamp); - else - jpegBufSize = tj3JPEGBufSize(tilew, tileh, subsamp); - if (jpegBufSize == 0) - THROW_TJG(); - if ((jpegBufs[i] = tj3Alloc(jpegBufSize)) == NULL) - THROW_UNIX("allocating JPEG tiles"); - } - } - - tw = w; th = h; ttilew = tilew; ttileh = tileh; - if (!quiet) { - printf("\n%s size: %d x %d", doTile ? "Tile" : "Image", ttilew, ttileh); - if (sf.num != 1 || sf.denom != 1 || IS_CROPPED(cr)) - printf(" --> %d x %d", CROPPED_WIDTH(tw), CROPPED_HEIGHT(th)); - printf("\n"); - } else if (quiet == 1) { - printf("%-4s(%s) %-14s ", pixFormatStr[pf], - bottomUp ? "BU" : "TD", formatName(subsamp, cs, tempStr)); - printf("%-5d %-5d ", CROPPED_WIDTH(tilew), CROPPED_HEIGHT(tileh)); - } - - tsubsamp = subsamp; - if (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter) { - if ((t = (tjtransform *)malloc(sizeof(tjtransform) * ntilesw * - ntilesh)) == NULL) - THROW_UNIX("allocating image transform array"); - - if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE || - xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) { - tw = h; th = w; ttilew = tileh; ttileh = tilew; - } - - if (xformOp != TJXOP_NONE && xformOp != TJXOP_TRANSPOSE && - subsamp == TJSAMP_UNKNOWN) - THROW("transforming", - "Could not determine subsampling level of JPEG image"); - if (xformOpt & TJXOPT_GRAY) tsubsamp = TJSAMP_GRAY; - if (xformOp == TJXOP_HFLIP || xformOp == TJXOP_ROT180) - tw = tw - (tw % tjMCUWidth[tsubsamp]); - if (xformOp == TJXOP_VFLIP || xformOp == TJXOP_ROT180) - th = th - (th % tjMCUHeight[tsubsamp]); - if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT90) - tw = tw - (tw % tjMCUHeight[tsubsamp]); - if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT270) - th = th - (th % tjMCUWidth[tsubsamp]); - tntilesw = (tw + ttilew - 1) / ttilew; - tntilesh = (th + ttileh - 1) / ttileh; - - if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE || - xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) { - if (tsubsamp == TJSAMP_422) tsubsamp = TJSAMP_440; - else if (tsubsamp == TJSAMP_440) tsubsamp = TJSAMP_422; - else if (tsubsamp == TJSAMP_411) tsubsamp = TJSAMP_441; - else if (tsubsamp == TJSAMP_441) tsubsamp = TJSAMP_411; - } - - for (row = 0, tile = 0; row < tntilesh; row++) { - for (col = 0; col < tntilesw; col++, tile++) { - t[tile].r.w = min(ttilew, tw - col * ttilew); - t[tile].r.h = min(ttileh, th - row * ttileh); - t[tile].r.x = col * ttilew; - t[tile].r.y = row * ttileh; - t[tile].op = xformOp; - t[tile].options = xformOpt | TJXOPT_TRIM; - t[tile].customFilter = customFilter; - if (t[tile].options & TJXOPT_NOOUTPUT && jpegBufs[tile]) { - tj3Free(jpegBufs[tile]); jpegBufs[tile] = NULL; - } - } - } - - iter = -1; - elapsed = 0.; - while (1) { - start = getTime(); - if (tj3Transform(handle, srcBuf, srcSize, tntilesw * tntilesh, - jpegBufs, jpegSizes, t) == -1) - THROW_TJ(); - elapsed += getTime() - start; - if (iter >= 0) { - iter++; - if (elapsed >= benchTime) break; - } else if (elapsed >= warmup) { - iter = 0; - elapsed = 0.; - } - } - - free(t); t = NULL; - - for (tile = 0, totalJpegSize = 0; tile < tntilesw * tntilesh; tile++) - totalJpegSize += jpegSizes[tile]; - - if (quiet) { - printf("%-6s%s%-6s%s", - sigfig((double)(w * h) / 1000000. / elapsed, 4, tempStr, 80), - quiet == 2 ? "\n" : " ", - sigfig((double)(w * h * ps) / (double)totalJpegSize, 4, - tempStr2, 80), - quiet == 2 ? "\n" : " "); - } else { - printf("Transform --> Frame rate: %f fps\n", - 1.0 / elapsed); - printf(" Output image size: %lu bytes\n", - (unsigned long)totalJpegSize); - printf(" Compression ratio: %f:1\n", - (double)(w * h * ps) / (double)totalJpegSize); - printf(" Throughput: %f Megapixels/sec\n", - (double)(w * h) / 1000000. / elapsed); - printf(" Output bit stream: %f Megabits/sec\n", - (double)totalJpegSize * 8. / 1000000. / elapsed); - } - } else { - if (quiet == 1) printf("N/A N/A "); - tj3Free(jpegBufs[0]); - jpegBufs[0] = NULL; - decompsrc = 1; - } - - if (w == tilew) ttilew = tw; - if (h == tileh) ttileh = th; - if (!(xformOpt & TJXOPT_NOOUTPUT)) { - if (decomp(decompsrc ? &srcBuf : jpegBufs, - decompsrc ? &srcSize : jpegSizes, NULL, tw, th, tsubsamp, 0, - fileName, ttilew, ttileh) == -1) - goto bailout; - } else if (quiet == 1) printf("N/A\n"); - - for (i = 0; i < ntilesw * ntilesh; i++) { - tj3Free(jpegBufs[i]); - jpegBufs[i] = NULL; - } - free(jpegBufs); jpegBufs = NULL; - free(jpegSizes); jpegSizes = NULL; - - if (tilew == w && tileh == h) break; - } - -bailout: - if (file) fclose(file); - if (jpegBufs) { - for (i = 0; i < ntilesw * ntilesh; i++) - tj3Free(jpegBufs[i]); - } - free(jpegBufs); - free(jpegSizes); - free(srcBuf); - free(t); - tj3Destroy(handle); - return retval; -} - - -static void usage(char *progName) -{ - int i; - - printf("USAGE: %s\n", progName); - printf(" [options]\n\n"); - printf(" %s\n", progName); - printf(" [options]\n"); - - printf("\nGENERAL OPTIONS\n"); - printf("---------------\n"); - printf("-alloc = Dynamically allocate JPEG buffers\n"); - printf("-benchtime T = Run each benchmark for at least T seconds [default = 5.0]\n"); - printf("-bmp = Use Windows Bitmap format for output images [default = PPM]\n"); - printf(" ** 8-bit data precision only **\n"); - printf("-bottomup = Use bottom-up row order for packed-pixel source/destination buffers\n"); - printf("-componly = Stop after running compression tests. Do not test decompression.\n"); - printf("-lossless = Generate lossless JPEG images when compressing (implies\n"); - printf(" -subsamp 444). PSV is the predictor selection value (1-7).\n"); - printf("-maxmemory = Memory limit (in megabytes) for intermediate buffers used with\n"); - printf(" progressive JPEG compression and decompression, optimized baseline entropy\n"); - printf(" coding, lossless JPEG compression, and lossless transformation\n"); - printf(" [default = no limit]\n"); - printf("-maxpixels = Input image size limit (in pixels) [default = no limit]\n"); - printf("-nowrite = Do not write reference or output images (improves consistency of\n"); - printf(" benchmark results)\n"); - printf("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb =\n"); - printf(" Use the specified pixel format for packed-pixel source/destination buffers\n"); - printf(" [default = BGR]\n"); - printf("-cmyk = Indirectly test YCCK JPEG compression/decompression\n"); - printf(" (use the CMYK pixel format for packed-pixel source/destination buffers)\n"); - printf("-precision N = Use N-bit data precision when compressing [N is 8, 12, or 16;\n"); - printf(" default = 8; if N is 16, then -lossless must also be specified]\n"); - printf(" (-precision 12 implies -optimize unless -arithmetic is also specified)\n"); - printf("-quiet = Output results in tabular rather than verbose format\n"); - printf("-restart N = When compressing, add a restart marker every N MCU rows (lossy) or\n"); - printf(" N sample rows (lossless) [default = 0 (no restart markers)]. Append 'B'\n"); - printf(" to specify the restart marker interval in MCU blocks (lossy) or samples\n"); - printf(" (lossless).\n"); - printf("-stoponwarning = Immediately discontinue the current\n"); - printf(" compression/decompression/transform operation if a warning (non-fatal\n"); - printf(" error) occurs\n"); - printf("-tile = Compress/transform the input image into separate JPEG tiles of varying\n"); - printf(" sizes (useful for measuring JPEG overhead)\n"); - printf("-warmup T = Run each benchmark for T seconds [default = 1.0] prior to starting\n"); - printf(" the timer, in order to prime the caches and thus improve the consistency\n"); - printf(" of the benchmark results\n"); - - printf("\nLOSSY JPEG OPTIONS\n"); - printf("------------------\n"); - printf("-arithmetic = Use arithmetic entropy coding in JPEG images generated by\n"); - printf(" compression and transform operations (can be combined with -progressive)\n"); - printf("-crop WxH+X+Y = Decompress only the specified region of the JPEG image, where W\n"); - printf(" and H are the width and height of the region (0 = maximum possible width\n"); - printf(" or height) and X and Y are the left and upper boundary of the region, all\n"); - printf(" specified relative to the scaled image dimensions. X must be divible by\n"); - printf(" the scaled MCU width.\n"); - printf("-fastdct = Use the fastest DCT/IDCT algorithm available\n"); - printf("-fastupsample = Use the fastest chrominance upsampling algorithm available\n"); - printf("-optimize = Use optimized baseline entropy coding in JPEG images generated by\n"); - printf(" compession and transform operations\n"); - printf("-progressive = Use progressive entropy coding in JPEG images generated by\n"); - printf(" compression and transform operations (can be combined with -arithmetic;\n"); - printf(" implies -optimize unless -arithmetic is also specified)\n"); - printf("-limitscans = Refuse to decompress or transform progressive JPEG images that\n"); - printf(" have an unreasonably large number of scans\n"); - printf("-scale M/N = When decompressing, scale the width/height of the JPEG image by a\n"); - printf(" factor of M/N (M/N = "); - for (i = 0; i < nsf; i++) { - printf("%d/%d", scalingFactors[i].num, scalingFactors[i].denom); - if (nsf == 2 && i != nsf - 1) printf(" or "); - else if (nsf > 2) { - if (i != nsf - 1) printf(", "); - if (i == nsf - 2) printf("or "); - } - if (i % 8 == 0 && i != 0) printf("\n "); - } - printf(")\n"); - printf("-subsamp S = When compressing, use the specified level of chrominance\n"); - printf(" subsampling (S = 444, 422, 440, 420, 411, 441, or GRAY) [default = test\n"); - printf(" Grayscale, 4:2:0, 4:2:2, and 4:4:4 in sequence]\n"); - printf("-hflip, -vflip, -transpose, -transverse, -rot90, -rot180, -rot270 =\n"); - printf(" Perform the specified lossless transform operation on the input image\n"); - printf(" prior to decompression (these operations are mutually exclusive)\n"); - printf("-grayscale = Transform the input image into a grayscale JPEG image prior to\n"); - printf(" decompression (can be combined with the other transform operations above)\n"); - printf("-copynone = Do not copy any extra markers (including EXIF and ICC profile data)\n"); - printf(" when transforming the input image\n"); - printf("-yuv = Compress from/decompress to intermediate planar YUV images\n"); - printf(" ** 8-bit data precision only **\n"); - printf("-yuvpad N = The number of bytes by which each row in each plane of an\n"); - printf(" intermediate YUV image is evenly divisible (N must be a power of 2)\n"); - printf(" [default = 1]\n"); - - printf("\nNOTE: If the quality/PSV is specified as a range (e.g. 90-100 or 1-4), a\n"); - printf("separate test will be performed for all values in the range.\n\n"); - exit(1); -} - - -int main(int argc, char *argv[]) -{ - void *srcBuf = NULL; - int w = 0, h = 0, i, j, minQual = -1, maxQual = -1; - char *temp; - int minArg = 2, retval = 0, subsamp = -1; - tjhandle handle = NULL; - - if ((scalingFactors = tj3GetScalingFactors(&nsf)) == NULL || nsf == 0) - THROW("executing tj3GetScalingFactors()", tj3GetErrorStr(NULL)); - - if (argc < minArg) usage(argv[0]); - - temp = strrchr(argv[1], '.'); - if (temp != NULL) { - if (!strcasecmp(temp, ".bmp")) ext = "bmp"; - if (!strcasecmp(temp, ".jpg") || !strcasecmp(temp, ".jpeg")) - decompOnly = 1; - } - - printf("\n"); - - if (!decompOnly) { - minArg = 3; - if (argc < minArg) usage(argv[0]); - minQual = atoi(argv[2]); - if ((temp = strchr(argv[2], '-')) != NULL && strlen(temp) > 1 && - sscanf(&temp[1], "%d", &maxQual) == 1 && maxQual > minQual) {} - else maxQual = minQual; - } - - if (argc > minArg) { - for (i = minArg; i < argc; i++) { - if (!strcasecmp(argv[i], "-tile")) { - doTile = 1; xformOpt |= TJXOPT_CROP; - } else if (!strcasecmp(argv[i], "-precision") && i < argc - 1) { - int tempi = atoi(argv[++i]); - - if (tempi != 8 && tempi != 12 && tempi != 16) - usage(argv[0]); - precision = tempi; - } else if (!strcasecmp(argv[i], "-fastupsample")) { - printf("Using fastest upsampling algorithm\n\n"); - fastUpsample = 1; - } else if (!strcasecmp(argv[i], "-fastdct")) { - printf("Using fastest DCT/IDCT algorithm\n\n"); - fastDCT = 1; - } else if (!strcasecmp(argv[i], "-optimize")) { - printf("Using optimized baseline entropy coding\n\n"); - optimize = 1; - xformOpt |= TJXOPT_OPTIMIZE; - } else if (!strcasecmp(argv[i], "-progressive")) { - printf("Using progressive entropy coding\n\n"); - progressive = 1; - xformOpt |= TJXOPT_PROGRESSIVE; - } else if (!strcasecmp(argv[i], "-arithmetic")) { - printf("Using arithmetic entropy coding\n\n"); - arithmetic = 1; - xformOpt |= TJXOPT_ARITHMETIC; - } else if (!strcasecmp(argv[i], "-lossless")) { - lossless = 1; - subsamp = TJSAMP_444; - } else if (!strcasecmp(argv[i], "-rgb")) - pf = TJPF_RGB; - else if (!strcasecmp(argv[i], "-rgbx")) - pf = TJPF_RGBX; - else if (!strcasecmp(argv[i], "-bgr")) - pf = TJPF_BGR; - else if (!strcasecmp(argv[i], "-bgrx")) - pf = TJPF_BGRX; - else if (!strcasecmp(argv[i], "-xbgr")) - pf = TJPF_XBGR; - else if (!strcasecmp(argv[i], "-xrgb")) - pf = TJPF_XRGB; - else if (!strcasecmp(argv[i], "-cmyk")) - pf = TJPF_CMYK; - else if (!strcasecmp(argv[i], "-bottomup")) - bottomUp = 1; - else if (!strcasecmp(argv[i], "-quiet")) - quiet = 1; - else if (!strcasecmp(argv[i], "-qq")) - quiet = 2; - else if (!strcasecmp(argv[i], "-scale") && i < argc - 1) { - int temp1 = 0, temp2 = 0, match = 0; - - if (sscanf(argv[++i], "%d/%d", &temp1, &temp2) == 2) { - for (j = 0; j < nsf; j++) { - if (temp1 == scalingFactors[j].num && - temp2 == scalingFactors[j].denom) { - sf = scalingFactors[j]; - match = 1; break; - } - } - if (!match) usage(argv[0]); - } else usage(argv[0]); - } else if (!strcasecmp(argv[i], "-crop") && i < argc - 1) { - int temp1 = -1, temp2 = -1, temp3 = -1, temp4 = -1; - - if (sscanf(argv[++i], "%dx%d+%d+%d", &temp1, &temp2, &temp3, - &temp4) == 4 && temp1 >= 0 && temp2 >= 0 && temp3 >= 0 && - temp4 >= 0) { - cr.w = temp1; cr.h = temp2; cr.x = temp3; cr.y = temp4; - } else usage(argv[0]); - } else if (!strcasecmp(argv[i], "-hflip")) - xformOp = TJXOP_HFLIP; - else if (!strcasecmp(argv[i], "-vflip")) - xformOp = TJXOP_VFLIP; - else if (!strcasecmp(argv[i], "-transpose")) - xformOp = TJXOP_TRANSPOSE; - else if (!strcasecmp(argv[i], "-transverse")) - xformOp = TJXOP_TRANSVERSE; - else if (!strcasecmp(argv[i], "-rot90")) - xformOp = TJXOP_ROT90; - else if (!strcasecmp(argv[i], "-rot180")) - xformOp = TJXOP_ROT180; - else if (!strcasecmp(argv[i], "-rot270")) - xformOp = TJXOP_ROT270; - else if (!strcasecmp(argv[i], "-grayscale")) - xformOpt |= TJXOPT_GRAY; - else if (!strcasecmp(argv[i], "-custom")) - customFilter = dummyDCTFilter; - else if (!strcasecmp(argv[i], "-nooutput")) - xformOpt |= TJXOPT_NOOUTPUT; - else if (!strcasecmp(argv[i], "-copynone")) - xformOpt |= TJXOPT_COPYNONE; - else if (!strcasecmp(argv[i], "-benchtime") && i < argc - 1) { - double tempd = atof(argv[++i]); - - if (tempd > 0.0) benchTime = tempd; - else usage(argv[0]); - } else if (!strcasecmp(argv[i], "-warmup") && i < argc - 1) { - double tempd = atof(argv[++i]); - - if (tempd >= 0.0) warmup = tempd; - else usage(argv[0]); - printf("Warmup time = %.1f seconds\n\n", warmup); - } else if (!strcasecmp(argv[i], "-alloc")) - noRealloc = 0; - else if (!strcasecmp(argv[i], "-bmp")) - ext = "bmp"; - else if (!strcasecmp(argv[i], "-yuv")) { - printf("Testing planar YUV encoding/decoding\n\n"); - doYUV = 1; - } else if (!strcasecmp(argv[i], "-yuvpad") && i < argc - 1) { - int tempi = atoi(argv[++i]); - - if (tempi >= 1 && (tempi & (tempi - 1)) == 0) yuvAlign = tempi; - else usage(argv[0]); - } else if (!strcasecmp(argv[i], "-subsamp") && i < argc - 1) { - i++; - if (toupper(argv[i][0]) == 'G') subsamp = TJSAMP_GRAY; - else { - int tempi = atoi(argv[i]); - - switch (tempi) { - case 444: subsamp = TJSAMP_444; break; - case 422: subsamp = TJSAMP_422; break; - case 440: subsamp = TJSAMP_440; break; - case 420: subsamp = TJSAMP_420; break; - case 411: subsamp = TJSAMP_411; break; - case 441: subsamp = TJSAMP_441; break; - default: usage(argv[0]); - } - } - } else if (!strcasecmp(argv[i], "-componly")) - compOnly = 1; - else if (!strcasecmp(argv[i], "-nowrite")) - doWrite = 0; - else if (!strcasecmp(argv[i], "-limitscans")) - limitScans = 1; - else if (!strcasecmp(argv[i], "-maxmemory") && i < argc - 1) { - int tempi = atoi(argv[++i]); - - if (tempi < 0) usage(argv[0]); - maxMemory = tempi; - } else if (!strcasecmp(argv[i], "-maxpixels") && i < argc - 1) { - int tempi = atoi(argv[++i]); - - if (tempi < 0) usage(argv[0]); - maxPixels = tempi; - } else if (!strcasecmp(argv[i], "-restart") && i < argc - 1) { - int tempi = -1, nscan; char tempc = 0; - - if ((nscan = sscanf(argv[++i], "%d%c", &tempi, &tempc)) < 1 || - tempi < 0 || tempi > 65535 || - (nscan == 2 && tempc != 'B' && tempc != 'b')) - usage(argv[0]); - - if (tempc == 'B' || tempc == 'b') - restartIntervalBlocks = tempi; - else - restartIntervalRows = tempi; - } else if (!strcasecmp(argv[i], "-stoponwarning")) - stopOnWarning = 1; - else usage(argv[0]); - } - } - - if (precision == 16 && !lossless) { - printf("ERROR: -lossless must be specified along with -precision 16\n"); - retval = -1; goto bailout; - } - if (precision != 8 && doYUV) { - printf("ERROR: -yuv requires 8-bit data precision\n"); - retval = -1; goto bailout; - } - if (lossless && doYUV) { - printf("ERROR: -lossless and -yuv are incompatible\n"); - retval = -1; goto bailout; - } - sampleSize = (precision == 8 ? sizeof(unsigned char) : sizeof(short)); - - if ((sf.num != 1 || sf.denom != 1) && doTile) { - printf("Disabling tiled compression/decompression tests, because those tests do not\n"); - printf("work when scaled decompression is enabled.\n\n"); - doTile = 0; xformOpt &= (~TJXOPT_CROP); - } - - if (IS_CROPPED(cr)) { - if (!decompOnly) { - printf("ERROR: Partial image decompression can only be enabled for JPEG input images\n"); - retval = -1; goto bailout; - } - if (doTile) { - printf("Disabling tiled compression/decompression tests, because those tests do not\n"); - printf("work when partial image decompression is enabled.\n\n"); - doTile = 0; xformOpt &= (~TJXOPT_CROP); - } - if (doYUV) { - printf("ERROR: -crop and -yuv are incompatible\n"); - retval = -1; goto bailout; - } - } - - if (!noRealloc && doTile) { - printf("Disabling tiled compression/decompression tests, because those tests do not\n"); - printf("work when dynamic JPEG buffer allocation is enabled.\n\n"); - doTile = 0; xformOpt &= (~TJXOPT_CROP); - } - - if (!decompOnly) { - if ((handle = tj3Init(TJINIT_COMPRESS)) == NULL) - THROW_TJG(); - if (tj3Set(handle, TJPARAM_STOPONWARNING, stopOnWarning) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_BOTTOMUP, bottomUp) == -1) - THROW_TJ(); - if (tj3Set(handle, TJPARAM_MAXPIXELS, maxPixels) == -1) - THROW_TJ(); - - if (precision == 8) { - if ((srcBuf = tj3LoadImage8(handle, argv[1], &w, 1, &h, &pf)) == NULL) - THROW_TJ(); - } else if (precision == 12) { - if ((srcBuf = tj3LoadImage12(handle, argv[1], &w, 1, &h, &pf)) == NULL) - THROW_TJ(); - } else { - if ((srcBuf = tj3LoadImage16(handle, argv[1], &w, 1, &h, &pf)) == NULL) - THROW_TJ(); - } - temp = strrchr(argv[1], '.'); - if (temp != NULL) *temp = '\0'; - } - - if (quiet == 1 && !decompOnly) { - printf("All performance values in Mpixels/sec\n\n"); - printf("Pixel JPEG JPEG %s %s ", - doTile ? "Tile " : "Image", doTile ? "Tile " : "Image"); - if (doYUV) printf("Encode "); - printf("Comp Comp Decomp "); - if (doYUV) printf("Decode"); - printf("\n"); - printf("Format Format %s Width Height ", - lossless ? "PSV " : "Qual"); - if (doYUV) printf("Perf "); - printf("Perf Ratio Perf "); - if (doYUV) printf("Perf"); - printf("\n\n"); - } - - if (decompOnly) { - decompTest(argv[1]); - printf("\n"); - goto bailout; - } - if (lossless) { - if (minQual < 1 || minQual > 7 || maxQual < 1 || maxQual > 7) { - puts("ERROR: PSV must be between 1 and 7."); - exit(1); - } - } else { - if (minQual < 1 || minQual > 100 || maxQual < 1 || maxQual > 100) { - puts("ERROR: Quality must be between 1 and 100."); - exit(1); - } - } - if (subsamp >= 0 && subsamp < TJ_NUMSAMP) { - for (i = maxQual; i >= minQual; i--) - fullTest(handle, srcBuf, w, h, subsamp, i, argv[1]); - printf("\n"); - } else { - if (pf != TJPF_CMYK) { - for (i = maxQual; i >= minQual; i--) - fullTest(handle, srcBuf, w, h, TJSAMP_GRAY, i, argv[1]); - printf("\n"); - } - for (i = maxQual; i >= minQual; i--) - fullTest(handle, srcBuf, w, h, TJSAMP_420, i, argv[1]); - printf("\n"); - for (i = maxQual; i >= minQual; i--) - fullTest(handle, srcBuf, w, h, TJSAMP_422, i, argv[1]); - printf("\n"); - for (i = maxQual; i >= minQual; i--) - fullTest(handle, srcBuf, w, h, TJSAMP_444, i, argv[1]); - printf("\n"); - } - -bailout: - tj3Destroy(handle); - tj3Free(srcBuf); - return retval; -} diff --git a/3rdparty/libjpeg-turbo/src/tjutil.c b/3rdparty/libjpeg-turbo/src/tjutil.c deleted file mode 100644 index 2018160b16..0000000000 --- a/3rdparty/libjpeg-turbo/src/tjutil.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C)2011, 2019 D. R. Commander. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the libjpeg-turbo Project nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _WIN32 - -#include -#include "tjutil.h" - -static double getFreq(void) -{ - LARGE_INTEGER freq; - - if (!QueryPerformanceFrequency(&freq)) return 0.0; - return (double)freq.QuadPart; -} - -static double f = -1.0; - -double getTime(void) -{ - LARGE_INTEGER t; - - if (f < 0.0) f = getFreq(); - if (f == 0.0) return (double)GetTickCount() / 1000.; - else { - QueryPerformanceCounter(&t); - return (double)t.QuadPart / f; - } -} - -#else - -#include -#include -#include "tjutil.h" - -double getTime(void) -{ - struct timeval tv; - - if (gettimeofday(&tv, NULL) < 0) return 0.0; - else return (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.); -} - -#endif diff --git a/3rdparty/libjpeg-turbo/src/tjutil.h b/3rdparty/libjpeg-turbo/src/tjutil.h deleted file mode 100644 index 10272e9886..0000000000 --- a/3rdparty/libjpeg-turbo/src/tjutil.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C)2011, 2022 D. R. Commander. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the libjpeg-turbo Project nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _WIN32 -#ifndef strcasecmp -#define strcasecmp stricmp -#endif -#ifndef strncasecmp -#define strncasecmp strnicmp -#endif -#endif - -#ifdef _MSC_VER -#define SNPRINTF(str, n, format, ...) \ - _snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__) -#else -#define SNPRINTF snprintf -#endif - -#ifndef min -#define min(a, b) ((a) < (b) ? (a) : (b)) -#endif - -#ifndef max -#define max(a, b) ((a) > (b) ? (a) : (b)) -#endif - -extern double getTime(void); diff --git a/3rdparty/libjpeg-turbo/src/transupp.c b/3rdparty/libjpeg-turbo/src/transupp.c deleted file mode 100644 index 62587d3865..0000000000 --- a/3rdparty/libjpeg-turbo/src/transupp.c +++ /dev/null @@ -1,2377 +0,0 @@ -/* - * transupp.c - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1997-2019, Thomas G. Lane, Guido Vollbeding. - * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2017, 2021-2022, 2024, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains image transformation routines and other utility code - * used by the jpegtran sample application. These are NOT part of the core - * JPEG library. But we keep these routines separate from jpegtran.c to - * ease the task of maintaining jpegtran-like programs that have other user - * interfaces. - */ - -/* Although this file really shouldn't have access to the library internals, - * it's helpful to let it call jround_up() and jcopy_block_row(). - */ -#define JPEG_INTERNALS - -#include "jinclude.h" -#include "jpeglib.h" -#include "transupp.h" /* My own external interface */ -#include "jpegapicomp.h" -#include /* to declare isdigit() */ - - -#if JPEG_LIB_VERSION >= 70 -#define dstinfo_min_DCT_h_scaled_size dstinfo->min_DCT_h_scaled_size -#define dstinfo_min_DCT_v_scaled_size dstinfo->min_DCT_v_scaled_size -#else -#define dstinfo_min_DCT_h_scaled_size DCTSIZE -#define dstinfo_min_DCT_v_scaled_size DCTSIZE -#endif - - -#if TRANSFORMS_SUPPORTED - -/* - * Lossless image transformation routines. These routines work on DCT - * coefficient arrays and thus do not require any lossy decompression - * or recompression of the image. - * Thanks to Guido Vollbeding for the initial design and code of this feature, - * and to Ben Jackson for introducing the cropping feature. - * - * Horizontal flipping is done in-place, using a single top-to-bottom - * pass through the virtual source array. It will thus be much the - * fastest option for images larger than main memory. - * - * The other routines require a set of destination virtual arrays, so they - * need twice as much memory as jpegtran normally does. The destination - * arrays are always written in normal scan order (top to bottom) because - * the virtual array manager expects this. The source arrays will be scanned - * in the corresponding order, which means multiple passes through the source - * arrays for most of the transforms. That could result in much thrashing - * if the image is larger than main memory. - * - * If cropping or trimming is involved, the destination arrays may be smaller - * than the source arrays. Note it is not possible to do horizontal flip - * in-place when a nonzero Y crop offset is specified, since we'd have to move - * data from one block row to another but the virtual array manager doesn't - * guarantee we can touch more than one row at a time. So in that case, - * we have to use a separate destination array. - * - * Some notes about the operating environment of the individual transform - * routines: - * 1. Both the source and destination virtual arrays are allocated from the - * source JPEG object, and therefore should be manipulated by calling the - * source's memory manager. - * 2. The destination's component count should be used. It may be smaller - * than the source's when forcing to grayscale. - * 3. Likewise the destination's sampling factors should be used. When - * forcing to grayscale the destination's sampling factors will be all 1, - * and we may as well take that as the effective iMCU size. - * 4. When "trim" is in effect, the destination's dimensions will be the - * trimmed values but the source's will be untrimmed. - * 5. When "crop" is in effect, the destination's dimensions will be the - * cropped values but the source's will be uncropped. Each transform - * routine is responsible for picking up source data starting at the - * correct X and Y offset for the crop region. (The X and Y offsets - * passed to the transform routines are measured in iMCU blocks of the - * destination.) - * 6. All the routines assume that the source and destination buffers are - * padded out to a full iMCU boundary. This is true, although for the - * source buffer it is an undocumented property of jdcoefct.c. - */ - - -LOCAL(void) -dequant_comp(j_decompress_ptr cinfo, jpeg_component_info *compptr, - jvirt_barray_ptr coef_array, JQUANT_TBL *qtblptr1) -{ - JDIMENSION blk_x, blk_y; - int offset_y, k; - JQUANT_TBL *qtblptr; - JBLOCKARRAY buffer; - JBLOCKROW block; - JCOEFPTR ptr; - - qtblptr = compptr->quant_table; - for (blk_y = 0; blk_y < compptr->height_in_blocks; - blk_y += compptr->v_samp_factor) { - buffer = (*cinfo->mem->access_virt_barray) - ((j_common_ptr)cinfo, coef_array, blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - block = buffer[offset_y]; - for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) { - ptr = block[blk_x]; - for (k = 0; k < DCTSIZE2; k++) - if (qtblptr->quantval[k] != qtblptr1->quantval[k]) - ptr[k] *= qtblptr->quantval[k] / qtblptr1->quantval[k]; - } - } - } -} - - -LOCAL(void) -requant_comp(j_decompress_ptr cinfo, jpeg_component_info *compptr, - jvirt_barray_ptr coef_array, JQUANT_TBL *qtblptr1) -{ - JDIMENSION blk_x, blk_y; - int offset_y, k; - JQUANT_TBL *qtblptr; - JBLOCKARRAY buffer; - JBLOCKROW block; - JCOEFPTR ptr; - JCOEF temp, qval; - - qtblptr = compptr->quant_table; - for (blk_y = 0; blk_y < compptr->height_in_blocks; - blk_y += compptr->v_samp_factor) { - buffer = (*cinfo->mem->access_virt_barray) - ((j_common_ptr)cinfo, coef_array, blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - block = buffer[offset_y]; - for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) { - ptr = block[blk_x]; - for (k = 0; k < DCTSIZE2; k++) { - temp = qtblptr->quantval[k]; - qval = qtblptr1->quantval[k]; - if (temp != qval && qval != 0) { - temp *= ptr[k]; - /* The following quantization code is copied from jcdctmgr.c */ -#ifdef FAST_DIVIDE -#define DIVIDE_BY(a, b) a /= b -#else -#define DIVIDE_BY(a, b) if (a >= b) a /= b; else a = 0 -#endif - if (temp < 0) { - temp = -temp; - temp += qval >> 1; /* for rounding */ - DIVIDE_BY(temp, qval); - temp = -temp; - } else { - temp += qval >> 1; /* for rounding */ - DIVIDE_BY(temp, qval); - } - ptr[k] = temp; - } - } - } - } - } -} - - -/* - * Calculate largest common denominator using Euclid's algorithm. - */ -LOCAL(JCOEF) -largest_common_denominator(JCOEF a, JCOEF b) -{ - JCOEF c; - - do { - c = a % b; - a = b; - b = c; - } while (c); - - return a; -} - - -LOCAL(void) -adjust_quant(j_decompress_ptr srcinfo, jvirt_barray_ptr *src_coef_arrays, - j_decompress_ptr dropinfo, jvirt_barray_ptr *drop_coef_arrays, - boolean trim, j_compress_ptr dstinfo) -{ - jpeg_component_info *compptr1, *compptr2; - JQUANT_TBL *qtblptr1, *qtblptr2, *qtblptr3; - int ci, k; - - for (ci = 0; ci < dstinfo->num_components && ci < dropinfo->num_components; - ci++) { - compptr1 = srcinfo->comp_info + ci; - compptr2 = dropinfo->comp_info + ci; - qtblptr1 = compptr1->quant_table; - if (qtblptr1 == NULL) - ERREXIT1(srcinfo, JERR_NO_QUANT_TABLE, compptr1->quant_tbl_no); - qtblptr2 = compptr2->quant_table; - if (qtblptr2 == NULL) - ERREXIT1(dropinfo, JERR_NO_QUANT_TABLE, compptr2->quant_tbl_no); - for (k = 0; k < DCTSIZE2; k++) { - if (qtblptr1->quantval[k] != qtblptr2->quantval[k]) { - if (trim) - requant_comp(dropinfo, compptr2, drop_coef_arrays[ci], qtblptr1); - else { - qtblptr3 = dstinfo->quant_tbl_ptrs[compptr1->quant_tbl_no]; - for (k = 0; k < DCTSIZE2; k++) - if (qtblptr1->quantval[k] != qtblptr2->quantval[k]) - qtblptr3->quantval[k] = - largest_common_denominator(qtblptr1->quantval[k], - qtblptr2->quantval[k]); - dequant_comp(srcinfo, compptr1, src_coef_arrays[ci], qtblptr3); - dequant_comp(dropinfo, compptr2, drop_coef_arrays[ci], qtblptr3); - } - break; - } - } - } -} - - -LOCAL(void) -do_drop(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - j_decompress_ptr dropinfo, jvirt_barray_ptr *drop_coef_arrays, - JDIMENSION drop_width, JDIMENSION drop_height) -/* Drop (insert) the contents of another image into the source image. If the - * number of components in the drop image is smaller than the number of - * components in the destination image, then we fill in the remaining - * components with zero. This allows for dropping the contents of grayscale - * images into (arbitrarily sampled) color images. - */ -{ - JDIMENSION comp_width, comp_height; - JDIMENSION blk_y, x_drop_blocks, y_drop_blocks; - int ci, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - jpeg_component_info *compptr; - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_width = drop_width * compptr->h_samp_factor; - comp_height = drop_height * compptr->v_samp_factor; - x_drop_blocks = x_crop_offset * compptr->h_samp_factor; - y_drop_blocks = y_crop_offset * compptr->v_samp_factor; - for (blk_y = 0; blk_y < comp_height; blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], blk_y + y_drop_blocks, - (JDIMENSION)compptr->v_samp_factor, TRUE); - if (ci < dropinfo->num_components) { - src_buffer = (*dropinfo->mem->access_virt_barray) - ((j_common_ptr)dropinfo, drop_coef_arrays[ci], blk_y, - (JDIMENSION)compptr->v_samp_factor, FALSE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - jcopy_block_row(src_buffer[offset_y], - dst_buffer[offset_y] + x_drop_blocks, comp_width); - } - } else { - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - memset(dst_buffer[offset_y] + x_drop_blocks, 0, - comp_width * sizeof(JBLOCK)); - } - } - } - } -} - - -LOCAL(void) -do_crop(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* Crop. This is only used when no rotate/flip is requested with the crop. */ -{ - JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks; - int ci, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - jpeg_component_info *compptr; - - /* We simply have to copy the right amount of data (the destination's - * image size) starting at the given X and Y offsets in the source. - */ - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], dst_blk_y + y_crop_blocks, - (JDIMENSION)compptr->v_samp_factor, FALSE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - jcopy_block_row(src_buffer[offset_y] + x_crop_blocks, - dst_buffer[offset_y], compptr->width_in_blocks); - } - } - } -} - - -LOCAL(void) -do_crop_ext_zero(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* Crop. This is only used when no rotate/flip is requested with the crop. - * Extension: If the destination size is larger than the source, we fill in the - * expanded region with zero (neutral gray). Note that we also have to zero - * partial iMCUs at the right and bottom edge of the source image area in this - * case. - */ -{ - JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height; - JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks; - int ci, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - jpeg_component_info *compptr; - - MCU_cols = srcinfo->output_width / - (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); - MCU_rows = srcinfo->output_height / - (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_width = MCU_cols * compptr->h_samp_factor; - comp_height = MCU_rows * compptr->v_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - if (dstinfo->_jpeg_height > srcinfo->output_height) { - if (dst_blk_y < y_crop_blocks || - dst_blk_y >= y_crop_blocks + comp_height) { - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - memset(dst_buffer[offset_y], 0, - compptr->width_in_blocks * sizeof(JBLOCK)); - } - continue; - } - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_y - y_crop_blocks, (JDIMENSION)compptr->v_samp_factor, - FALSE); - } else { - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_y + y_crop_blocks, (JDIMENSION)compptr->v_samp_factor, - FALSE); - } - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - if (dstinfo->_jpeg_width > srcinfo->output_width) { - if (x_crop_blocks > 0) { - memset(dst_buffer[offset_y], 0, x_crop_blocks * sizeof(JBLOCK)); - } - jcopy_block_row(src_buffer[offset_y], - dst_buffer[offset_y] + x_crop_blocks, comp_width); - if (compptr->width_in_blocks > x_crop_blocks + comp_width) { - memset(dst_buffer[offset_y] + x_crop_blocks + comp_width, 0, - (compptr->width_in_blocks - x_crop_blocks - comp_width) * - sizeof(JBLOCK)); - } - } else { - jcopy_block_row(src_buffer[offset_y] + x_crop_blocks, - dst_buffer[offset_y], compptr->width_in_blocks); - } - } - } - } -} - - -LOCAL(void) -do_crop_ext_flat(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* Crop. This is only used when no rotate/flip is requested with the crop. - * Extension: The destination width is larger than the source, and we fill in - * the expanded region with the DC coefficient of the adjacent block. Note - * that we also have to fill partial iMCUs at the right and bottom edge of the - * source image area in this case. - */ -{ - JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height; - JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks; - int ci, offset_y; - JCOEF dc; - JBLOCKARRAY src_buffer, dst_buffer; - jpeg_component_info *compptr; - - MCU_cols = srcinfo->output_width / - (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); - MCU_rows = srcinfo->output_height / - (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_width = MCU_cols * compptr->h_samp_factor; - comp_height = MCU_rows * compptr->v_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - if (dstinfo->_jpeg_height > srcinfo->output_height) { - if (dst_blk_y < y_crop_blocks || - dst_blk_y >= y_crop_blocks + comp_height) { - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - memset(dst_buffer[offset_y], 0, - compptr->width_in_blocks * sizeof(JBLOCK)); - } - continue; - } - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_y - y_crop_blocks, (JDIMENSION)compptr->v_samp_factor, - FALSE); - } else { - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_y + y_crop_blocks, (JDIMENSION)compptr->v_samp_factor, - FALSE); - } - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - if (x_crop_blocks > 0) { - memset(dst_buffer[offset_y], 0, x_crop_blocks * sizeof(JBLOCK)); - dc = src_buffer[offset_y][0][0]; - for (dst_blk_x = 0; dst_blk_x < x_crop_blocks; dst_blk_x++) { - dst_buffer[offset_y][dst_blk_x][0] = dc; - } - } - jcopy_block_row(src_buffer[offset_y], - dst_buffer[offset_y] + x_crop_blocks, comp_width); - if (compptr->width_in_blocks > x_crop_blocks + comp_width) { - memset(dst_buffer[offset_y] + x_crop_blocks + comp_width, 0, - (compptr->width_in_blocks - x_crop_blocks - comp_width) * - sizeof(JBLOCK)); - dc = src_buffer[offset_y][comp_width - 1][0]; - for (dst_blk_x = x_crop_blocks + comp_width; - dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { - dst_buffer[offset_y][dst_blk_x][0] = dc; - } - } - } - } - } -} - - -LOCAL(void) -do_crop_ext_reflect(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* Crop. This is only used when no rotate/flip is requested with the crop. - * Extension: The destination width is larger than the source, and we fill in - * the expanded region with repeated reflections of the source image. Note - * that we also have to fill partial iMCUs at the right and bottom edge of the - * source image area in this case. - */ -{ - JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, src_blk_x; - JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks; - int ci, k, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - JBLOCKROW src_row_ptr, dst_row_ptr; - JCOEFPTR src_ptr, dst_ptr; - jpeg_component_info *compptr; - - MCU_cols = srcinfo->output_width / - (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); - MCU_rows = srcinfo->output_height / - (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_width = MCU_cols * compptr->h_samp_factor; - comp_height = MCU_rows * compptr->v_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - if (dstinfo->_jpeg_height > srcinfo->output_height) { - if (dst_blk_y < y_crop_blocks || - dst_blk_y >= y_crop_blocks + comp_height) { - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - memset(dst_buffer[offset_y], 0, - compptr->width_in_blocks * sizeof(JBLOCK)); - } - continue; - } - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_y - y_crop_blocks, (JDIMENSION)compptr->v_samp_factor, - FALSE); - } else { - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_y + y_crop_blocks, (JDIMENSION)compptr->v_samp_factor, - FALSE); - } - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - /* Copy source region */ - jcopy_block_row(src_buffer[offset_y], - dst_buffer[offset_y] + x_crop_blocks, comp_width); - if (x_crop_blocks > 0) { - /* Reflect to left */ - dst_row_ptr = dst_buffer[offset_y] + x_crop_blocks; - for (dst_blk_x = x_crop_blocks; dst_blk_x > 0;) { - src_row_ptr = dst_row_ptr; /* (re)set axis of reflection */ - for (src_blk_x = comp_width; src_blk_x > 0 && dst_blk_x > 0; - src_blk_x--, dst_blk_x--) { - dst_ptr = *(--dst_row_ptr); /* destination goes left */ - src_ptr = *src_row_ptr++; /* source goes right */ - /* This unrolled loop doesn't need to know which row it's on. */ - for (k = 0; k < DCTSIZE2; k += 2) { - *dst_ptr++ = *src_ptr++; /* copy even column */ - *dst_ptr++ = -(*src_ptr++); /* copy odd column with sign - change */ - } - } - } - } - if (compptr->width_in_blocks > x_crop_blocks + comp_width) { - /* Reflect to right */ - dst_row_ptr = dst_buffer[offset_y] + x_crop_blocks + comp_width; - for (dst_blk_x = compptr->width_in_blocks - x_crop_blocks - comp_width; - dst_blk_x > 0;) { - src_row_ptr = dst_row_ptr; /* (re)set axis of reflection */ - for (src_blk_x = comp_width; src_blk_x > 0 && dst_blk_x > 0; - src_blk_x--, dst_blk_x--) { - dst_ptr = *dst_row_ptr++; /* destination goes right */ - src_ptr = *(--src_row_ptr); /* source goes left */ - /* This unrolled loop doesn't need to know which row it's on. */ - for (k = 0; k < DCTSIZE2; k += 2) { - *dst_ptr++ = *src_ptr++; /* copy even column */ - *dst_ptr++ = -(*src_ptr++); /* copy odd column with sign - change */ - } - } - } - } - } - } - } -} - - -LOCAL(void) -do_wipe(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - JDIMENSION drop_width, JDIMENSION drop_height) -/* Wipe - discard image contents of specified region and fill with zero - * (neutral gray) - */ -{ - JDIMENSION x_wipe_blocks, wipe_width; - JDIMENSION y_wipe_blocks, wipe_bottom; - int ci, offset_y; - JBLOCKARRAY buffer; - jpeg_component_info *compptr; - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - x_wipe_blocks = x_crop_offset * compptr->h_samp_factor; - wipe_width = drop_width * compptr->h_samp_factor; - y_wipe_blocks = y_crop_offset * compptr->v_samp_factor; - wipe_bottom = drop_height * compptr->v_samp_factor + y_wipe_blocks; - for (; y_wipe_blocks < wipe_bottom; - y_wipe_blocks += compptr->v_samp_factor) { - buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], y_wipe_blocks, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - memset(buffer[offset_y] + x_wipe_blocks, 0, - wipe_width * sizeof(JBLOCK)); - } - } - } -} - - -LOCAL(void) -do_flatten(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - JDIMENSION drop_width, JDIMENSION drop_height) -/* Flatten - discard image contents of specified region, similarly to wipe, - * but fill with the average of adjacent blocks instead of zero. - */ -{ - JDIMENSION x_wipe_blocks, wipe_width, wipe_right; - JDIMENSION y_wipe_blocks, wipe_bottom, blk_x; - int ci, offset_y, dc_left_value, dc_right_value, average; - JBLOCKARRAY buffer; - jpeg_component_info *compptr; - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - x_wipe_blocks = x_crop_offset * compptr->h_samp_factor; - wipe_width = drop_width * compptr->h_samp_factor; - wipe_right = wipe_width + x_wipe_blocks; - y_wipe_blocks = y_crop_offset * compptr->v_samp_factor; - wipe_bottom = drop_height * compptr->v_samp_factor + y_wipe_blocks; - for (; y_wipe_blocks < wipe_bottom; - y_wipe_blocks += compptr->v_samp_factor) { - buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], y_wipe_blocks, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - memset(buffer[offset_y] + x_wipe_blocks, 0, - wipe_width * sizeof(JBLOCK)); - if (x_wipe_blocks > 0) { - dc_left_value = buffer[offset_y][x_wipe_blocks - 1][0]; - if (wipe_right < compptr->width_in_blocks) { - dc_right_value = buffer[offset_y][wipe_right][0]; - average = (dc_left_value + dc_right_value) >> 1; - } else { - average = dc_left_value; - } - } else if (wipe_right < compptr->width_in_blocks) { - average = buffer[offset_y][wipe_right][0]; - } else continue; - for (blk_x = x_wipe_blocks; blk_x < wipe_right; blk_x++) { - buffer[offset_y][blk_x][0] = (JCOEF)average; - } - } - } - } -} - - -LOCAL(void) -do_reflect(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, jvirt_barray_ptr *src_coef_arrays, - JDIMENSION drop_width, JDIMENSION drop_height) -/* Reflect - discard image contents of specified region, similarly to wipe, - * but fill with repeated reflections of the outside region instead of zero. - * NB: y_crop_offset is assumed to be zero. - */ -{ - JDIMENSION x_wipe_blocks, wipe_width; - JDIMENSION y_wipe_blocks, wipe_bottom; - JDIMENSION src_blk_x, dst_blk_x; - int ci, k, offset_y; - JBLOCKARRAY buffer; - JBLOCKROW src_row_ptr, dst_row_ptr; - JCOEFPTR src_ptr, dst_ptr; - jpeg_component_info *compptr; - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - x_wipe_blocks = x_crop_offset * compptr->h_samp_factor; - wipe_width = drop_width * compptr->h_samp_factor; - wipe_bottom = drop_height * compptr->v_samp_factor; - for (y_wipe_blocks = 0; y_wipe_blocks < wipe_bottom; - y_wipe_blocks += compptr->v_samp_factor) { - buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], y_wipe_blocks, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - if (x_wipe_blocks > 0) { - /* Reflect from left */ - dst_row_ptr = buffer[offset_y] + x_wipe_blocks; - for (dst_blk_x = wipe_width; dst_blk_x > 0;) { - src_row_ptr = dst_row_ptr; /* (re)set axis of reflection */ - for (src_blk_x = x_wipe_blocks; - src_blk_x > 0 && dst_blk_x > 0; src_blk_x--, dst_blk_x--) { - dst_ptr = *dst_row_ptr++; /* destination goes right */ - src_ptr = *(--src_row_ptr); /* source goes left */ - /* this unrolled loop doesn't need to know which row it's on... */ - for (k = 0; k < DCTSIZE2; k += 2) { - *dst_ptr++ = *src_ptr++; /* copy even column */ - *dst_ptr++ = -(*src_ptr++); /* copy odd column with sign change */ - } - } - } - } else if (compptr->width_in_blocks > x_wipe_blocks + wipe_width) { - /* Reflect from right */ - dst_row_ptr = buffer[offset_y] + x_wipe_blocks + wipe_width; - for (dst_blk_x = wipe_width; dst_blk_x > 0;) { - src_row_ptr = dst_row_ptr; /* (re)set axis of reflection */ - src_blk_x = compptr->width_in_blocks - x_wipe_blocks - wipe_width; - for (; src_blk_x > 0 && dst_blk_x > 0; src_blk_x--, dst_blk_x--) { - dst_ptr = *(--dst_row_ptr); /* destination goes left */ - src_ptr = *src_row_ptr++; /* source goes right */ - /* this unrolled loop doesn't need to know which row it's on... */ - for (k = 0; k < DCTSIZE2; k += 2) { - *dst_ptr++ = *src_ptr++; /* copy even column */ - *dst_ptr++ = -(*src_ptr++); /* copy odd column with sign change */ - } - } - } - } else { - memset(buffer[offset_y] + x_wipe_blocks, 0, - wipe_width * sizeof(JBLOCK)); - } - } - } - } -} - - -LOCAL(void) -do_flip_h_no_crop(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, jvirt_barray_ptr *src_coef_arrays) -/* Horizontal flip; done in-place, so no separate dest array is required. - * NB: this only works when y_crop_offset is zero. - */ -{ - JDIMENSION MCU_cols, comp_width, blk_x, blk_y, x_crop_blocks; - int ci, k, offset_y; - JBLOCKARRAY buffer; - JCOEFPTR ptr1, ptr2; - JCOEF temp1, temp2; - jpeg_component_info *compptr; - - /* Horizontal mirroring of DCT blocks is accomplished by swapping - * pairs of blocks in-place. Within a DCT block, we perform horizontal - * mirroring by changing the signs of odd-numbered columns. - * Partial iMCUs at the right edge are left untouched. - */ - MCU_cols = srcinfo->output_width / - (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_width = MCU_cols * compptr->h_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - for (blk_y = 0; blk_y < compptr->height_in_blocks; - blk_y += compptr->v_samp_factor) { - buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - /* Do the mirroring */ - for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) { - ptr1 = buffer[offset_y][blk_x]; - ptr2 = buffer[offset_y][comp_width - blk_x - 1]; - /* this unrolled loop doesn't need to know which row it's on... */ - for (k = 0; k < DCTSIZE2; k += 2) { - temp1 = *ptr1; /* swap even column */ - temp2 = *ptr2; - *ptr1++ = temp2; - *ptr2++ = temp1; - temp1 = *ptr1; /* swap odd column with sign change */ - temp2 = *ptr2; - *ptr1++ = -temp2; - *ptr2++ = -temp1; - } - } - if (x_crop_blocks > 0) { - /* Now left-justify the portion of the data to be kept. - * We can't use a single jcopy_block_row() call because that routine - * depends on memcpy(), whose behavior is unspecified for overlapping - * source and destination areas. Sigh. - */ - for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) { - jcopy_block_row(buffer[offset_y] + blk_x + x_crop_blocks, - buffer[offset_y] + blk_x, (JDIMENSION)1); - } - } - } - } - } -} - - -LOCAL(void) -do_flip_h(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* Horizontal flip in general cropping case */ -{ - JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; - JDIMENSION x_crop_blocks, y_crop_blocks; - int ci, k, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - JBLOCKROW src_row_ptr, dst_row_ptr; - JCOEFPTR src_ptr, dst_ptr; - jpeg_component_info *compptr; - - /* Here we must output into a separate array because we can't touch - * different rows of a single virtual array simultaneously. Otherwise, - * this is essentially the same as the routine above. - */ - MCU_cols = srcinfo->output_width / - (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_width = MCU_cols * compptr->h_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], dst_blk_y + y_crop_blocks, - (JDIMENSION)compptr->v_samp_factor, FALSE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - dst_row_ptr = dst_buffer[offset_y]; - src_row_ptr = src_buffer[offset_y]; - for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; - dst_blk_x++) { - if (x_crop_blocks + dst_blk_x < comp_width) { - /* Do the mirrorable blocks */ - dst_ptr = dst_row_ptr[dst_blk_x]; - src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; - /* this unrolled loop doesn't need to know which row it's on... */ - for (k = 0; k < DCTSIZE2; k += 2) { - *dst_ptr++ = *src_ptr++; /* copy even column */ - *dst_ptr++ = -(*src_ptr++); /* copy odd column with sign - change */ - } - } else { - /* Copy last partial block(s) verbatim */ - jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks, - dst_row_ptr + dst_blk_x, (JDIMENSION)1); - } - } - } - } - } -} - - -LOCAL(void) -do_flip_v(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* Vertical flip */ -{ - JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; - JDIMENSION x_crop_blocks, y_crop_blocks; - int ci, i, j, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - JBLOCKROW src_row_ptr, dst_row_ptr; - JCOEFPTR src_ptr, dst_ptr; - jpeg_component_info *compptr; - - /* We output into a separate array because we can't touch different - * rows of the source virtual array simultaneously. Otherwise, this - * is a pretty straightforward analog of horizontal flip. - * Within a DCT block, vertical mirroring is done by changing the signs - * of odd-numbered rows. - * Partial iMCUs at the bottom edge are copied verbatim. - */ - MCU_rows = srcinfo->output_height / - (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_height = MCU_rows * compptr->v_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - if (y_crop_blocks + dst_blk_y < comp_height) { - /* Row is within the mirrorable area. */ - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - comp_height - y_crop_blocks - dst_blk_y - - (JDIMENSION)compptr->v_samp_factor, - (JDIMENSION)compptr->v_samp_factor, FALSE); - } else { - /* Bottom-edge blocks will be copied verbatim. */ - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_y + y_crop_blocks, - (JDIMENSION)compptr->v_samp_factor, FALSE); - } - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - if (y_crop_blocks + dst_blk_y < comp_height) { - /* Row is within the mirrorable area. */ - dst_row_ptr = dst_buffer[offset_y]; - src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; - src_row_ptr += x_crop_blocks; - for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; - dst_blk_x++) { - dst_ptr = dst_row_ptr[dst_blk_x]; - src_ptr = src_row_ptr[dst_blk_x]; - for (i = 0; i < DCTSIZE; i += 2) { - /* copy even row */ - for (j = 0; j < DCTSIZE; j++) - *dst_ptr++ = *src_ptr++; - /* copy odd row with sign change */ - for (j = 0; j < DCTSIZE; j++) - *dst_ptr++ = -(*src_ptr++); - } - } - } else { - /* Just copy row verbatim. */ - jcopy_block_row(src_buffer[offset_y] + x_crop_blocks, - dst_buffer[offset_y], compptr->width_in_blocks); - } - } - } - } -} - - -LOCAL(void) -do_transpose(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* Transpose source into destination */ -{ - JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks; - int ci, i, j, offset_x, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - JCOEFPTR src_ptr, dst_ptr; - jpeg_component_info *compptr; - - /* Transposing pixels within a block just requires transposing the - * DCT coefficients. - * Partial iMCUs at the edges require no special treatment; we simply - * process all the available DCT blocks for every component. - */ - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; - dst_blk_x += compptr->h_samp_factor) { - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_x + x_crop_blocks, - (JDIMENSION)compptr->h_samp_factor, FALSE); - for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { - dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; - src_ptr = - src_buffer[offset_x][dst_blk_y + offset_y + y_crop_blocks]; - for (i = 0; i < DCTSIZE; i++) - for (j = 0; j < DCTSIZE; j++) - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - } - } - } - } - } -} - - -LOCAL(void) -do_rot_90(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* 90 degree rotation is equivalent to - * 1. Transposing the image; - * 2. Horizontal mirroring. - * These two steps are merged into a single processing routine. - */ -{ - JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; - JDIMENSION x_crop_blocks, y_crop_blocks; - int ci, i, j, offset_x, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - JCOEFPTR src_ptr, dst_ptr; - jpeg_component_info *compptr; - - /* Because of the horizontal mirror step, we can't process partial iMCUs - * at the (output) right edge properly. They just get transposed and - * not mirrored. - */ - MCU_cols = srcinfo->output_height / - (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_width = MCU_cols * compptr->h_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; - dst_blk_x += compptr->h_samp_factor) { - if (x_crop_blocks + dst_blk_x < comp_width) { - /* Block is within the mirrorable area. */ - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - comp_width - x_crop_blocks - dst_blk_x - - (JDIMENSION)compptr->h_samp_factor, - (JDIMENSION)compptr->h_samp_factor, FALSE); - } else { - /* Edge blocks are transposed but not mirrored. */ - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_x + x_crop_blocks, - (JDIMENSION)compptr->h_samp_factor, FALSE); - } - for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { - dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; - if (x_crop_blocks + dst_blk_x < comp_width) { - /* Block is within the mirrorable area. */ - src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] - [dst_blk_y + offset_y + y_crop_blocks]; - for (i = 0; i < DCTSIZE; i++) { - for (j = 0; j < DCTSIZE; j++) - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - i++; - for (j = 0; j < DCTSIZE; j++) - dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j]; - } - } else { - /* Edge blocks are transposed but not mirrored. */ - src_ptr = src_buffer[offset_x] - [dst_blk_y + offset_y + y_crop_blocks]; - for (i = 0; i < DCTSIZE; i++) - for (j = 0; j < DCTSIZE; j++) - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - } - } - } - } - } - } -} - - -LOCAL(void) -do_rot_270(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* 270 degree rotation is equivalent to - * 1. Horizontal mirroring; - * 2. Transposing the image. - * These two steps are merged into a single processing routine. - */ -{ - JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; - JDIMENSION x_crop_blocks, y_crop_blocks; - int ci, i, j, offset_x, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - JCOEFPTR src_ptr, dst_ptr; - jpeg_component_info *compptr; - - /* Because of the horizontal mirror step, we can't process partial iMCUs - * at the (output) bottom edge properly. They just get transposed and - * not mirrored. - */ - MCU_rows = srcinfo->output_width / - (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_height = MCU_rows * compptr->v_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; - dst_blk_x += compptr->h_samp_factor) { - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_x + x_crop_blocks, - (JDIMENSION)compptr->h_samp_factor, FALSE); - for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { - dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; - if (y_crop_blocks + dst_blk_y < comp_height) { - /* Block is within the mirrorable area. */ - src_ptr = src_buffer[offset_x] - [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; - for (i = 0; i < DCTSIZE; i++) { - for (j = 0; j < DCTSIZE; j++) { - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - j++; - dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j]; - } - } - } else { - /* Edge blocks are transposed but not mirrored. */ - src_ptr = src_buffer[offset_x] - [dst_blk_y + offset_y + y_crop_blocks]; - for (i = 0; i < DCTSIZE; i++) - for (j = 0; j < DCTSIZE; j++) - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - } - } - } - } - } - } -} - - -LOCAL(void) -do_rot_180(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* 180 degree rotation is equivalent to - * 1. Vertical mirroring; - * 2. Horizontal mirroring. - * These two steps are merged into a single processing routine. - */ -{ - JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; - JDIMENSION x_crop_blocks, y_crop_blocks; - int ci, i, j, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - JBLOCKROW src_row_ptr, dst_row_ptr; - JCOEFPTR src_ptr, dst_ptr; - jpeg_component_info *compptr; - - MCU_cols = srcinfo->output_width / - (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); - MCU_rows = srcinfo->output_height / - (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_width = MCU_cols * compptr->h_samp_factor; - comp_height = MCU_rows * compptr->v_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - if (y_crop_blocks + dst_blk_y < comp_height) { - /* Row is within the vertically mirrorable area. */ - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - comp_height - y_crop_blocks - dst_blk_y - - (JDIMENSION)compptr->v_samp_factor, - (JDIMENSION)compptr->v_samp_factor, FALSE); - } else { - /* Bottom-edge rows are only mirrored horizontally. */ - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_y + y_crop_blocks, - (JDIMENSION)compptr->v_samp_factor, FALSE); - } - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - dst_row_ptr = dst_buffer[offset_y]; - if (y_crop_blocks + dst_blk_y < comp_height) { - /* Row is within the mirrorable area. */ - src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; - for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; - dst_blk_x++) { - dst_ptr = dst_row_ptr[dst_blk_x]; - if (x_crop_blocks + dst_blk_x < comp_width) { - /* Process the blocks that can be mirrored both ways. */ - src_ptr = - src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; - for (i = 0; i < DCTSIZE; i += 2) { - /* For even row, negate every odd column. */ - for (j = 0; j < DCTSIZE; j += 2) { - *dst_ptr++ = *src_ptr++; - *dst_ptr++ = -(*src_ptr++); - } - /* For odd row, negate every even column. */ - for (j = 0; j < DCTSIZE; j += 2) { - *dst_ptr++ = -(*src_ptr++); - *dst_ptr++ = *src_ptr++; - } - } - } else { - /* Any remaining right-edge blocks are only mirrored vertically. */ - src_ptr = src_row_ptr[x_crop_blocks + dst_blk_x]; - for (i = 0; i < DCTSIZE; i += 2) { - for (j = 0; j < DCTSIZE; j++) - *dst_ptr++ = *src_ptr++; - for (j = 0; j < DCTSIZE; j++) - *dst_ptr++ = -(*src_ptr++); - } - } - } - } else { - /* Remaining rows are just mirrored horizontally. */ - src_row_ptr = src_buffer[offset_y]; - for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; - dst_blk_x++) { - if (x_crop_blocks + dst_blk_x < comp_width) { - /* Process the blocks that can be mirrored. */ - dst_ptr = dst_row_ptr[dst_blk_x]; - src_ptr = - src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; - for (i = 0; i < DCTSIZE2; i += 2) { - *dst_ptr++ = *src_ptr++; - *dst_ptr++ = -(*src_ptr++); - } - } else { - /* Any remaining right-edge blocks are only copied. */ - jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks, - dst_row_ptr + dst_blk_x, (JDIMENSION)1); - } - } - } - } - } - } -} - - -LOCAL(void) -do_transverse(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, - jvirt_barray_ptr *src_coef_arrays, - jvirt_barray_ptr *dst_coef_arrays) -/* Transverse transpose is equivalent to - * 1. 180 degree rotation; - * 2. Transposition; - * or - * 1. Horizontal mirroring; - * 2. Transposition; - * 3. Horizontal mirroring. - * These steps are merged into a single processing routine. - */ -{ - JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; - JDIMENSION x_crop_blocks, y_crop_blocks; - int ci, i, j, offset_x, offset_y; - JBLOCKARRAY src_buffer, dst_buffer; - JCOEFPTR src_ptr, dst_ptr; - jpeg_component_info *compptr; - - MCU_cols = srcinfo->output_height / - (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); - MCU_rows = srcinfo->output_width / - (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); - - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - comp_width = MCU_cols * compptr->h_samp_factor; - comp_height = MCU_rows * compptr->v_samp_factor; - x_crop_blocks = x_crop_offset * compptr->h_samp_factor; - y_crop_blocks = y_crop_offset * compptr->v_samp_factor; - for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; - dst_blk_y += compptr->v_samp_factor) { - dst_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, dst_coef_arrays[ci], dst_blk_y, - (JDIMENSION)compptr->v_samp_factor, TRUE); - for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { - for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; - dst_blk_x += compptr->h_samp_factor) { - if (x_crop_blocks + dst_blk_x < comp_width) { - /* Block is within the mirrorable area. */ - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - comp_width - x_crop_blocks - dst_blk_x - - (JDIMENSION)compptr->h_samp_factor, - (JDIMENSION)compptr->h_samp_factor, FALSE); - } else { - src_buffer = (*srcinfo->mem->access_virt_barray) - ((j_common_ptr)srcinfo, src_coef_arrays[ci], - dst_blk_x + x_crop_blocks, - (JDIMENSION)compptr->h_samp_factor, FALSE); - } - for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { - dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; - if (y_crop_blocks + dst_blk_y < comp_height) { - if (x_crop_blocks + dst_blk_x < comp_width) { - /* Block is within the mirrorable area. */ - src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] - [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; - for (i = 0; i < DCTSIZE; i++) { - for (j = 0; j < DCTSIZE; j++) { - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - j++; - dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j]; - } - i++; - for (j = 0; j < DCTSIZE; j++) { - dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j]; - j++; - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - } - } - } else { - /* Right-edge blocks are mirrored in y only */ - src_ptr = src_buffer[offset_x] - [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; - for (i = 0; i < DCTSIZE; i++) { - for (j = 0; j < DCTSIZE; j++) { - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - j++; - dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j]; - } - } - } - } else { - if (x_crop_blocks + dst_blk_x < comp_width) { - /* Bottom-edge blocks are mirrored in x only */ - src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] - [dst_blk_y + offset_y + y_crop_blocks]; - for (i = 0; i < DCTSIZE; i++) { - for (j = 0; j < DCTSIZE; j++) - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - i++; - for (j = 0; j < DCTSIZE; j++) - dst_ptr[j * DCTSIZE + i] = -src_ptr[i * DCTSIZE + j]; - } - } else { - /* At lower right corner, just transpose, no mirroring */ - src_ptr = src_buffer[offset_x] - [dst_blk_y + offset_y + y_crop_blocks]; - for (i = 0; i < DCTSIZE; i++) - for (j = 0; j < DCTSIZE; j++) - dst_ptr[j * DCTSIZE + i] = src_ptr[i * DCTSIZE + j]; - } - } - } - } - } - } - } -} - - -/* Parse an unsigned integer: subroutine for jtransform_parse_crop_spec. - * Returns TRUE if valid integer found, FALSE if not. - * *strptr is advanced over the digit string, and *result is set to its value. - */ - -LOCAL(boolean) -jt_read_integer(const char **strptr, JDIMENSION *result) -{ - const char *ptr = *strptr; - JDIMENSION val = 0; - - for (; isdigit(*ptr); ptr++) { - val = val * 10 + (JDIMENSION)(*ptr - '0'); - } - *result = val; - if (ptr == *strptr) - return FALSE; /* oops, no digits */ - *strptr = ptr; - return TRUE; -} - - -/* Parse a crop specification (written in X11 geometry style). - * The routine returns TRUE if the spec string is valid, FALSE if not. - * - * The crop spec string should have the format - * [{fr}]x[{fr}]{+-}{+-} - * where width, height, xoffset, and yoffset are unsigned integers. - * Each of the elements can be omitted to indicate a default value. - * (A weakness of this style is that it is not possible to omit xoffset - * while specifying yoffset, since they look alike.) - * - * This code is loosely based on XParseGeometry from the X11 distribution. - */ - -GLOBAL(boolean) -jtransform_parse_crop_spec(jpeg_transform_info *info, const char *spec) -{ - info->crop = FALSE; - info->crop_width_set = JCROP_UNSET; - info->crop_height_set = JCROP_UNSET; - info->crop_xoffset_set = JCROP_UNSET; - info->crop_yoffset_set = JCROP_UNSET; - - if (isdigit(*spec)) { - /* fetch width */ - if (!jt_read_integer(&spec, &info->crop_width)) - return FALSE; - if (*spec == 'f' || *spec == 'F') { - spec++; - info->crop_width_set = JCROP_FORCE; - } else if (*spec == 'r' || *spec == 'R') { - spec++; - info->crop_width_set = JCROP_REFLECT; - } else - info->crop_width_set = JCROP_POS; - } - if (*spec == 'x' || *spec == 'X') { - /* fetch height */ - spec++; - if (!jt_read_integer(&spec, &info->crop_height)) - return FALSE; - if (*spec == 'f' || *spec == 'F') { - spec++; - info->crop_height_set = JCROP_FORCE; - } else if (*spec == 'r' || *spec == 'R') { - spec++; - info->crop_height_set = JCROP_REFLECT; - } else - info->crop_height_set = JCROP_POS; - } - if (*spec == '+' || *spec == '-') { - /* fetch xoffset */ - info->crop_xoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS; - spec++; - if (!jt_read_integer(&spec, &info->crop_xoffset)) - return FALSE; - } - if (*spec == '+' || *spec == '-') { - /* fetch yoffset */ - info->crop_yoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS; - spec++; - if (!jt_read_integer(&spec, &info->crop_yoffset)) - return FALSE; - } - /* We had better have gotten to the end of the string. */ - if (*spec != '\0') - return FALSE; - info->crop = TRUE; - return TRUE; -} - - -/* Trim off any partial iMCUs on the indicated destination edge */ - -LOCAL(void) -trim_right_edge(jpeg_transform_info *info, JDIMENSION full_width) -{ - JDIMENSION MCU_cols; - - MCU_cols = info->output_width / info->iMCU_sample_width; - if (MCU_cols > 0 && info->x_crop_offset + MCU_cols == - full_width / info->iMCU_sample_width) - info->output_width = MCU_cols * info->iMCU_sample_width; -} - -LOCAL(void) -trim_bottom_edge(jpeg_transform_info *info, JDIMENSION full_height) -{ - JDIMENSION MCU_rows; - - MCU_rows = info->output_height / info->iMCU_sample_height; - if (MCU_rows > 0 && info->y_crop_offset + MCU_rows == - full_height / info->iMCU_sample_height) - info->output_height = MCU_rows * info->iMCU_sample_height; -} - - -/* Request any required workspace. - * - * This routine figures out the size that the output image will be - * (which implies that all the transform parameters must be set before - * it is called). - * - * We allocate the workspace virtual arrays from the source decompression - * object, so that all the arrays (both the original data and the workspace) - * will be taken into account while making memory management decisions. - * Hence, this routine must be called after jpeg_read_header (which reads - * the image dimensions) and before jpeg_read_coefficients (which realizes - * the source's virtual arrays). - * - * This function returns FALSE right away if -perfect is given - * and transformation is not perfect. Otherwise returns TRUE. - */ - -GLOBAL(boolean) -jtransform_request_workspace(j_decompress_ptr srcinfo, - jpeg_transform_info *info) -{ - jvirt_barray_ptr *coef_arrays; - boolean need_workspace, transpose_it; - jpeg_component_info *compptr; - JDIMENSION xoffset, yoffset, dtemp; - JDIMENSION width_in_iMCUs, height_in_iMCUs; - JDIMENSION width_in_blocks, height_in_blocks; - int itemp, ci, h_samp_factor, v_samp_factor; - - /* Determine number of components in output image */ - if (info->force_grayscale && - srcinfo->jpeg_color_space == JCS_YCbCr && - srcinfo->num_components == 3) - /* We'll only process the first component */ - info->num_components = 1; - else - /* Process all the components */ - info->num_components = srcinfo->num_components; - - /* Compute output image dimensions and related values. */ -#if JPEG_LIB_VERSION >= 80 - jpeg_core_output_dimensions(srcinfo); -#else - srcinfo->output_width = srcinfo->image_width; - srcinfo->output_height = srcinfo->image_height; -#endif - - /* Return right away if -perfect is given and transformation is not perfect. - */ - if (info->perfect) { - if (info->num_components == 1) { - if (!jtransform_perfect_transform(srcinfo->output_width, - srcinfo->output_height, - srcinfo->_min_DCT_h_scaled_size, - srcinfo->_min_DCT_v_scaled_size, - info->transform)) - return FALSE; - } else { - if (!jtransform_perfect_transform(srcinfo->output_width, - srcinfo->output_height, - srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size, - srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size, - info->transform)) - return FALSE; - } - } - - /* If there is only one output component, force the iMCU size to be 1; - * else use the source iMCU size. (This allows us to do the right thing - * when reducing color to grayscale, and also provides a handy way of - * cleaning up "funny" grayscale images whose sampling factors are not 1x1.) - */ - switch (info->transform) { - case JXFORM_TRANSPOSE: - case JXFORM_TRANSVERSE: - case JXFORM_ROT_90: - case JXFORM_ROT_270: - info->output_width = srcinfo->output_height; - info->output_height = srcinfo->output_width; - if (info->num_components == 1) { - info->iMCU_sample_width = srcinfo->_min_DCT_v_scaled_size; - info->iMCU_sample_height = srcinfo->_min_DCT_h_scaled_size; - } else { - info->iMCU_sample_width = - srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; - info->iMCU_sample_height = - srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; - } - break; - default: - info->output_width = srcinfo->output_width; - info->output_height = srcinfo->output_height; - if (info->num_components == 1) { - info->iMCU_sample_width = srcinfo->_min_DCT_h_scaled_size; - info->iMCU_sample_height = srcinfo->_min_DCT_v_scaled_size; - } else { - info->iMCU_sample_width = - srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; - info->iMCU_sample_height = - srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; - } - break; - } - - /* If cropping has been requested, compute the crop area's position and - * dimensions, ensuring that its upper left corner falls at an iMCU boundary. - */ - if (info->crop) { - /* Insert default values for unset crop parameters */ - if (info->crop_xoffset_set == JCROP_UNSET) - info->crop_xoffset = 0; /* default to +0 */ - if (info->crop_yoffset_set == JCROP_UNSET) - info->crop_yoffset = 0; /* default to +0 */ - if (info->crop_width_set == JCROP_UNSET) { - if (info->crop_xoffset >= info->output_width) - ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); - info->crop_width = info->output_width - info->crop_xoffset; - } else { - /* Check for crop extension */ - if (info->crop_width > info->output_width) { - /* Crop extension does not work when transforming! */ - if (info->transform != JXFORM_NONE || - info->crop_xoffset >= info->crop_width || - info->crop_xoffset > info->crop_width - info->output_width) - ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); - } else { - if (info->crop_xoffset >= info->output_width || - info->crop_width <= 0 || - info->crop_xoffset > info->output_width - info->crop_width) - ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); - } - } - if (info->crop_height_set == JCROP_UNSET) { - if (info->crop_yoffset >= info->output_height) - ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); - info->crop_height = info->output_height - info->crop_yoffset; - } else { - /* Check for crop extension */ - if (info->crop_height > info->output_height) { - /* Crop extension does not work when transforming! */ - if (info->transform != JXFORM_NONE || - info->crop_yoffset >= info->crop_height || - info->crop_yoffset > info->crop_height - info->output_height) - ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); - } else { - if (info->crop_yoffset >= info->output_height || - info->crop_height <= 0 || - info->crop_yoffset > info->output_height - info->crop_height) - ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); - } - } - /* Convert negative crop offsets into regular offsets */ - if (info->crop_xoffset_set != JCROP_NEG) - xoffset = info->crop_xoffset; - else if (info->crop_width > info->output_width) /* crop extension */ - xoffset = info->crop_width - info->output_width - info->crop_xoffset; - else - xoffset = info->output_width - info->crop_width - info->crop_xoffset; - if (info->crop_yoffset_set != JCROP_NEG) - yoffset = info->crop_yoffset; - else if (info->crop_height > info->output_height) /* crop extension */ - yoffset = info->crop_height - info->output_height - info->crop_yoffset; - else - yoffset = info->output_height - info->crop_height - info->crop_yoffset; - /* Now adjust so that upper left corner falls at an iMCU boundary */ - switch (info->transform) { - case JXFORM_DROP: - /* Ensure the effective drop region will not exceed the requested */ - itemp = info->iMCU_sample_width; - dtemp = itemp - 1 - ((xoffset + itemp - 1) % itemp); - xoffset += dtemp; - if (info->crop_width <= dtemp) - info->drop_width = 0; - else if (xoffset + info->crop_width - dtemp == info->output_width) - /* Matching right edge: include partial iMCU */ - info->drop_width = (info->crop_width - dtemp + itemp - 1) / itemp; - else - info->drop_width = (info->crop_width - dtemp) / itemp; - itemp = info->iMCU_sample_height; - dtemp = itemp - 1 - ((yoffset + itemp - 1) % itemp); - yoffset += dtemp; - if (info->crop_height <= dtemp) - info->drop_height = 0; - else if (yoffset + info->crop_height - dtemp == info->output_height) - /* Matching bottom edge: include partial iMCU */ - info->drop_height = (info->crop_height - dtemp + itemp - 1) / itemp; - else - info->drop_height = (info->crop_height - dtemp) / itemp; - /* Check if sampling factors match for dropping */ - if (info->drop_width != 0 && info->drop_height != 0) - for (ci = 0; ci < info->num_components && - ci < info->drop_ptr->num_components; ci++) { - if (info->drop_ptr->comp_info[ci].h_samp_factor * - srcinfo->max_h_samp_factor != - srcinfo->comp_info[ci].h_samp_factor * - info->drop_ptr->max_h_samp_factor) - ERREXIT6(srcinfo, JERR_BAD_DROP_SAMPLING, ci, - info->drop_ptr->comp_info[ci].h_samp_factor, - info->drop_ptr->max_h_samp_factor, - srcinfo->comp_info[ci].h_samp_factor, - srcinfo->max_h_samp_factor, 'h'); - if (info->drop_ptr->comp_info[ci].v_samp_factor * - srcinfo->max_v_samp_factor != - srcinfo->comp_info[ci].v_samp_factor * - info->drop_ptr->max_v_samp_factor) - ERREXIT6(srcinfo, JERR_BAD_DROP_SAMPLING, ci, - info->drop_ptr->comp_info[ci].v_samp_factor, - info->drop_ptr->max_v_samp_factor, - srcinfo->comp_info[ci].v_samp_factor, - srcinfo->max_v_samp_factor, 'v'); - } - break; - case JXFORM_WIPE: - /* Ensure the effective wipe region will cover the requested */ - info->drop_width = (JDIMENSION)jdiv_round_up - ((long)(info->crop_width + (xoffset % info->iMCU_sample_width)), - (long)info->iMCU_sample_width); - info->drop_height = (JDIMENSION)jdiv_round_up - ((long)(info->crop_height + (yoffset % info->iMCU_sample_height)), - (long)info->iMCU_sample_height); - break; - default: - /* Ensure the effective crop region will cover the requested */ - if (info->crop_width_set == JCROP_FORCE || - info->crop_width > info->output_width) - info->output_width = info->crop_width; - else - info->output_width = - info->crop_width + (xoffset % info->iMCU_sample_width); - if (info->crop_height_set == JCROP_FORCE || - info->crop_height > info->output_height) - info->output_height = info->crop_height; - else - info->output_height = - info->crop_height + (yoffset % info->iMCU_sample_height); - } - /* Save x/y offsets measured in iMCUs */ - info->x_crop_offset = xoffset / info->iMCU_sample_width; - info->y_crop_offset = yoffset / info->iMCU_sample_height; - } else { - info->x_crop_offset = 0; - info->y_crop_offset = 0; - } - - /* Figure out whether we need workspace arrays, - * and if so whether they are transposed relative to the source. - */ - need_workspace = FALSE; - transpose_it = FALSE; - switch (info->transform) { - case JXFORM_NONE: - if (info->x_crop_offset != 0 || info->y_crop_offset != 0 || - info->output_width > srcinfo->output_width || - info->output_height > srcinfo->output_height) - need_workspace = TRUE; - /* No workspace needed if neither cropping nor transforming */ - break; - case JXFORM_FLIP_H: - if (info->trim) - trim_right_edge(info, srcinfo->output_width); - if (info->y_crop_offset != 0 || info->slow_hflip) - need_workspace = TRUE; - /* do_flip_h_no_crop doesn't need a workspace array */ - break; - case JXFORM_FLIP_V: - if (info->trim) - trim_bottom_edge(info, srcinfo->output_height); - /* Need workspace arrays having same dimensions as source image. */ - need_workspace = TRUE; - break; - case JXFORM_TRANSPOSE: - /* transpose does NOT have to trim anything */ - /* Need workspace arrays having transposed dimensions. */ - need_workspace = TRUE; - transpose_it = TRUE; - break; - case JXFORM_TRANSVERSE: - if (info->trim) { - trim_right_edge(info, srcinfo->output_height); - trim_bottom_edge(info, srcinfo->output_width); - } - /* Need workspace arrays having transposed dimensions. */ - need_workspace = TRUE; - transpose_it = TRUE; - break; - case JXFORM_ROT_90: - if (info->trim) - trim_right_edge(info, srcinfo->output_height); - /* Need workspace arrays having transposed dimensions. */ - need_workspace = TRUE; - transpose_it = TRUE; - break; - case JXFORM_ROT_180: - if (info->trim) { - trim_right_edge(info, srcinfo->output_width); - trim_bottom_edge(info, srcinfo->output_height); - } - /* Need workspace arrays having same dimensions as source image. */ - need_workspace = TRUE; - break; - case JXFORM_ROT_270: - if (info->trim) - trim_bottom_edge(info, srcinfo->output_width); - /* Need workspace arrays having transposed dimensions. */ - need_workspace = TRUE; - transpose_it = TRUE; - break; - case JXFORM_WIPE: - break; - case JXFORM_DROP: - break; - } - - /* Allocate workspace if needed. - * Note that we allocate arrays padded out to the next iMCU boundary, - * so that transform routines need not worry about missing edge blocks. - */ - if (need_workspace) { - coef_arrays = (jvirt_barray_ptr *) - (*srcinfo->mem->alloc_small) ((j_common_ptr)srcinfo, JPOOL_IMAGE, - sizeof(jvirt_barray_ptr) * info->num_components); - width_in_iMCUs = (JDIMENSION) - jdiv_round_up((long)info->output_width, (long)info->iMCU_sample_width); - height_in_iMCUs = (JDIMENSION) - jdiv_round_up((long)info->output_height, (long)info->iMCU_sample_height); - for (ci = 0; ci < info->num_components; ci++) { - compptr = srcinfo->comp_info + ci; - if (info->num_components == 1) { - /* we're going to force samp factors to 1x1 in this case */ - h_samp_factor = v_samp_factor = 1; - } else if (transpose_it) { - h_samp_factor = compptr->v_samp_factor; - v_samp_factor = compptr->h_samp_factor; - } else { - h_samp_factor = compptr->h_samp_factor; - v_samp_factor = compptr->v_samp_factor; - } - width_in_blocks = width_in_iMCUs * h_samp_factor; - height_in_blocks = height_in_iMCUs * v_samp_factor; - coef_arrays[ci] = (*srcinfo->mem->request_virt_barray) - ((j_common_ptr)srcinfo, JPOOL_IMAGE, FALSE, - width_in_blocks, height_in_blocks, (JDIMENSION)v_samp_factor); - } - info->workspace_coef_arrays = coef_arrays; - } else - info->workspace_coef_arrays = NULL; - - return TRUE; -} - - -/* Transpose destination image parameters */ - -LOCAL(void) -transpose_critical_parameters(j_compress_ptr dstinfo) -{ - int tblno, i, j, ci, itemp; - jpeg_component_info *compptr; - JQUANT_TBL *qtblptr; - JDIMENSION jtemp; - UINT16 qtemp; - - /* Transpose image dimensions */ - jtemp = dstinfo->image_width; - dstinfo->image_width = dstinfo->image_height; - dstinfo->image_height = jtemp; -#if JPEG_LIB_VERSION >= 70 - itemp = dstinfo->min_DCT_h_scaled_size; - dstinfo->min_DCT_h_scaled_size = dstinfo->min_DCT_v_scaled_size; - dstinfo->min_DCT_v_scaled_size = itemp; -#endif - - /* Transpose sampling factors */ - for (ci = 0; ci < dstinfo->num_components; ci++) { - compptr = dstinfo->comp_info + ci; - itemp = compptr->h_samp_factor; - compptr->h_samp_factor = compptr->v_samp_factor; - compptr->v_samp_factor = itemp; - } - - /* Transpose quantization tables */ - for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { - qtblptr = dstinfo->quant_tbl_ptrs[tblno]; - if (qtblptr != NULL) { - for (i = 0; i < DCTSIZE; i++) { - for (j = 0; j < i; j++) { - qtemp = qtblptr->quantval[i * DCTSIZE + j]; - qtblptr->quantval[i * DCTSIZE + j] = - qtblptr->quantval[j * DCTSIZE + i]; - qtblptr->quantval[j * DCTSIZE + i] = qtemp; - } - } - } - } -} - - -/* Adjust Exif image parameters. - * - * We try to adjust the Tags ExifImageWidth and ExifImageHeight if possible. - */ - -LOCAL(void) -adjust_exif_parameters(JOCTET *data, unsigned int length, JDIMENSION new_width, - JDIMENSION new_height) -{ - boolean is_motorola; /* Flag for byte order */ - unsigned int number_of_tags, tagnum; - unsigned int firstoffset, offset; - JDIMENSION new_value; - - if (length < 12) return; /* Length of an IFD entry */ - - /* Discover byte order */ - if (data[0] == 0x49 && data[1] == 0x49) - is_motorola = FALSE; - else if (data[0] == 0x4D && data[1] == 0x4D) - is_motorola = TRUE; - else - return; - - /* Check Tag Mark */ - if (is_motorola) { - if (data[2] != 0) return; - if (data[3] != 0x2A) return; - } else { - if (data[3] != 0) return; - if (data[2] != 0x2A) return; - } - - /* Get first IFD offset (offset to IFD0) */ - if (is_motorola) { - if (data[4] != 0) return; - if (data[5] != 0) return; - firstoffset = data[6]; - firstoffset <<= 8; - firstoffset += data[7]; - } else { - if (data[7] != 0) return; - if (data[6] != 0) return; - firstoffset = data[5]; - firstoffset <<= 8; - firstoffset += data[4]; - } - if (firstoffset > length - 2) return; /* check end of data segment */ - - /* Get the number of directory entries contained in this IFD */ - if (is_motorola) { - number_of_tags = data[firstoffset]; - number_of_tags <<= 8; - number_of_tags += data[firstoffset + 1]; - } else { - number_of_tags = data[firstoffset + 1]; - number_of_tags <<= 8; - number_of_tags += data[firstoffset]; - } - if (number_of_tags == 0) return; - firstoffset += 2; - - /* Search for ExifSubIFD offset Tag in IFD0 */ - for (;;) { - if (firstoffset > length - 12) return; /* check end of data segment */ - /* Get Tag number */ - if (is_motorola) { - tagnum = data[firstoffset]; - tagnum <<= 8; - tagnum += data[firstoffset + 1]; - } else { - tagnum = data[firstoffset + 1]; - tagnum <<= 8; - tagnum += data[firstoffset]; - } - if (tagnum == 0x8769) break; /* found ExifSubIFD offset Tag */ - if (--number_of_tags == 0) return; - firstoffset += 12; - } - - /* Get the ExifSubIFD offset */ - if (is_motorola) { - if (data[firstoffset + 8] != 0) return; - if (data[firstoffset + 9] != 0) return; - offset = data[firstoffset + 10]; - offset <<= 8; - offset += data[firstoffset + 11]; - } else { - if (data[firstoffset + 11] != 0) return; - if (data[firstoffset + 10] != 0) return; - offset = data[firstoffset + 9]; - offset <<= 8; - offset += data[firstoffset + 8]; - } - if (offset > length - 2) return; /* check end of data segment */ - - /* Get the number of directory entries contained in this SubIFD */ - if (is_motorola) { - number_of_tags = data[offset]; - number_of_tags <<= 8; - number_of_tags += data[offset + 1]; - } else { - number_of_tags = data[offset + 1]; - number_of_tags <<= 8; - number_of_tags += data[offset]; - } - if (number_of_tags < 2) return; - offset += 2; - - /* Search for ExifImageWidth and ExifImageHeight Tags in this SubIFD */ - do { - if (offset > length - 12) return; /* check end of data segment */ - /* Get Tag number */ - if (is_motorola) { - tagnum = data[offset]; - tagnum <<= 8; - tagnum += data[offset + 1]; - } else { - tagnum = data[offset + 1]; - tagnum <<= 8; - tagnum += data[offset]; - } - if (tagnum == 0xA002 || tagnum == 0xA003) { - if (tagnum == 0xA002) - new_value = new_width; /* ExifImageWidth Tag */ - else - new_value = new_height; /* ExifImageHeight Tag */ - if (is_motorola) { - data[offset + 2] = 0; /* Format = unsigned long (4 octets) */ - data[offset + 3] = 4; - data[offset + 4] = 0; /* Number Of Components = 1 */ - data[offset + 5] = 0; - data[offset + 6] = 0; - data[offset + 7] = 1; - data[offset + 8] = 0; - data[offset + 9] = 0; - data[offset + 10] = (JOCTET)((new_value >> 8) & 0xFF); - data[offset + 11] = (JOCTET)(new_value & 0xFF); - } else { - data[offset + 2] = 4; /* Format = unsigned long (4 octets) */ - data[offset + 3] = 0; - data[offset + 4] = 1; /* Number Of Components = 1 */ - data[offset + 5] = 0; - data[offset + 6] = 0; - data[offset + 7] = 0; - data[offset + 8] = (JOCTET)(new_value & 0xFF); - data[offset + 9] = (JOCTET)((new_value >> 8) & 0xFF); - data[offset + 10] = 0; - data[offset + 11] = 0; - } - } - offset += 12; - } while (--number_of_tags); -} - - -/* Adjust output image parameters as needed. - * - * This must be called after jpeg_copy_critical_parameters() - * and before jpeg_write_coefficients(). - * - * The return value is the set of virtual coefficient arrays to be written - * (either the ones allocated by jtransform_request_workspace, or the - * original source data arrays). The caller will need to pass this value - * to jpeg_write_coefficients(). - */ - -GLOBAL(jvirt_barray_ptr *) -jtransform_adjust_parameters(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - jvirt_barray_ptr *src_coef_arrays, - jpeg_transform_info *info) -{ - /* If force-to-grayscale is requested, adjust destination parameters */ - if (info->force_grayscale) { - /* First, ensure we have YCbCr or grayscale data, and that the source's - * Y channel is full resolution. (No reasonable person would make Y - * be less than full resolution, so actually coping with that case - * isn't worth extra code space. But we check it to avoid crashing.) - */ - if (((dstinfo->jpeg_color_space == JCS_YCbCr && - dstinfo->num_components == 3) || - (dstinfo->jpeg_color_space == JCS_GRAYSCALE && - dstinfo->num_components == 1)) && - srcinfo->comp_info[0].h_samp_factor == srcinfo->max_h_samp_factor && - srcinfo->comp_info[0].v_samp_factor == srcinfo->max_v_samp_factor) { - /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed - * properly. Among other things, it sets the target h_samp_factor & - * v_samp_factor to 1, which typically won't match the source. - * We have to preserve the source's quantization table number, however. - */ - int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no; - jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE); - dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no; - } else { - /* Sorry, can't do it */ - ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL); - } - } else if (info->num_components == 1) { - /* For a single-component source, we force the destination sampling factors - * to 1x1, with or without force_grayscale. This is useful because some - * decoders choke on grayscale images with other sampling factors. - */ - dstinfo->comp_info[0].h_samp_factor = 1; - dstinfo->comp_info[0].v_samp_factor = 1; - } - - /* Correct the destination's image dimensions as necessary - * for rotate/flip, resize, and crop operations. - */ -#if JPEG_LIB_VERSION >= 80 - dstinfo->jpeg_width = info->output_width; - dstinfo->jpeg_height = info->output_height; -#endif - - /* Transpose destination image parameters, adjust quantization */ - switch (info->transform) { - case JXFORM_TRANSPOSE: - case JXFORM_TRANSVERSE: - case JXFORM_ROT_90: - case JXFORM_ROT_270: -#if JPEG_LIB_VERSION < 80 - dstinfo->image_width = info->output_height; - dstinfo->image_height = info->output_width; -#endif - transpose_critical_parameters(dstinfo); - break; - case JXFORM_DROP: - if (info->drop_width != 0 && info->drop_height != 0) - adjust_quant(srcinfo, src_coef_arrays, - info->drop_ptr, info->drop_coef_arrays, - info->trim, dstinfo); - break; - default: -#if JPEG_LIB_VERSION < 80 - dstinfo->image_width = info->output_width; - dstinfo->image_height = info->output_height; -#endif - break; - } - - /* Adjust Exif properties */ - if (srcinfo->marker_list != NULL && - srcinfo->marker_list->marker == JPEG_APP0 + 1 && - srcinfo->marker_list->data_length >= 6 && - srcinfo->marker_list->data[0] == 0x45 && - srcinfo->marker_list->data[1] == 0x78 && - srcinfo->marker_list->data[2] == 0x69 && - srcinfo->marker_list->data[3] == 0x66 && - srcinfo->marker_list->data[4] == 0 && - srcinfo->marker_list->data[5] == 0) { - /* Suppress output of JFIF marker */ - dstinfo->write_JFIF_header = FALSE; - /* Adjust Exif image parameters */ -#if JPEG_LIB_VERSION >= 80 - if (dstinfo->jpeg_width != srcinfo->image_width || - dstinfo->jpeg_height != srcinfo->image_height) - /* Align data segment to start of TIFF structure for parsing */ - adjust_exif_parameters(srcinfo->marker_list->data + 6, - srcinfo->marker_list->data_length - 6, - dstinfo->jpeg_width, dstinfo->jpeg_height); -#else - if (dstinfo->image_width != srcinfo->image_width || - dstinfo->image_height != srcinfo->image_height) - /* Align data segment to start of TIFF structure for parsing */ - adjust_exif_parameters(srcinfo->marker_list->data + 6, - srcinfo->marker_list->data_length - 6, - dstinfo->image_width, dstinfo->image_height); -#endif - } - - /* Return the appropriate output data set */ - if (info->workspace_coef_arrays != NULL) - return info->workspace_coef_arrays; - return src_coef_arrays; -} - - -/* Execute the actual transformation, if any. - * - * This must be called *after* jpeg_write_coefficients, because it depends - * on jpeg_write_coefficients to have computed subsidiary values such as - * the per-component width and height fields in the destination object. - * - * Note that some transformations will modify the source data arrays! - */ - -GLOBAL(void) -jtransform_execute_transform(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - jvirt_barray_ptr *src_coef_arrays, - jpeg_transform_info *info) -{ - jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays; - - /* Note: conditions tested here should match those in switch statement - * in jtransform_request_workspace() - */ - switch (info->transform) { - case JXFORM_NONE: - if (info->output_width > srcinfo->output_width || - info->output_height > srcinfo->output_height) { - if (info->output_width > srcinfo->output_width && - info->crop_width_set == JCROP_REFLECT) - do_crop_ext_reflect(srcinfo, dstinfo, - info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - else if (info->output_width > srcinfo->output_width && - info->crop_width_set == JCROP_FORCE) - do_crop_ext_flat(srcinfo, dstinfo, - info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - else - do_crop_ext_zero(srcinfo, dstinfo, - info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - } else if (info->x_crop_offset != 0 || info->y_crop_offset != 0) - do_crop(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - break; - case JXFORM_FLIP_H: - if (info->y_crop_offset != 0 || info->slow_hflip) - do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - else - do_flip_h_no_crop(srcinfo, dstinfo, info->x_crop_offset, - src_coef_arrays); - break; - case JXFORM_FLIP_V: - do_flip_v(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - break; - case JXFORM_TRANSPOSE: - do_transpose(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - break; - case JXFORM_TRANSVERSE: - do_transverse(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - break; - case JXFORM_ROT_90: - do_rot_90(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - break; - case JXFORM_ROT_180: - do_rot_180(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - break; - case JXFORM_ROT_270: - do_rot_270(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, dst_coef_arrays); - break; - case JXFORM_WIPE: - if (info->crop_width_set == JCROP_REFLECT && - info->y_crop_offset == 0 && info->drop_height == - (JDIMENSION)jdiv_round_up - ((long)info->output_height, (long)info->iMCU_sample_height) && - (info->x_crop_offset == 0 || - info->x_crop_offset + info->drop_width == - (JDIMENSION)jdiv_round_up - ((long)info->output_width, (long)info->iMCU_sample_width))) - do_reflect(srcinfo, dstinfo, info->x_crop_offset, - src_coef_arrays, info->drop_width, info->drop_height); - else if (info->crop_width_set == JCROP_FORCE) - do_flatten(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, info->drop_width, info->drop_height); - else - do_wipe(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, info->drop_width, info->drop_height); - break; - case JXFORM_DROP: - if (info->drop_width != 0 && info->drop_height != 0) - do_drop(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, - src_coef_arrays, info->drop_ptr, info->drop_coef_arrays, - info->drop_width, info->drop_height); - break; - } -} - -/* jtransform_perfect_transform - * - * Determine whether lossless transformation is perfectly - * possible for a specified image and transformation. - * - * Inputs: - * image_width, image_height: source image dimensions. - * MCU_width, MCU_height: pixel dimensions of MCU. - * transform: transformation identifier. - * Parameter sources from initialized jpeg_struct - * (after reading source header): - * image_width = cinfo.image_width - * image_height = cinfo.image_height - * MCU_width = cinfo.max_h_samp_factor * cinfo.block_size - * MCU_height = cinfo.max_v_samp_factor * cinfo.block_size - * Result: - * TRUE = perfect transformation possible - * FALSE = perfect transformation not possible - * (may use custom action then) - */ - -GLOBAL(boolean) -jtransform_perfect_transform(JDIMENSION image_width, JDIMENSION image_height, - int MCU_width, int MCU_height, - JXFORM_CODE transform) -{ - boolean result = TRUE; /* initialize TRUE */ - - switch (transform) { - case JXFORM_FLIP_H: - case JXFORM_ROT_270: - if (image_width % (JDIMENSION)MCU_width) - result = FALSE; - break; - case JXFORM_FLIP_V: - case JXFORM_ROT_90: - if (image_height % (JDIMENSION)MCU_height) - result = FALSE; - break; - case JXFORM_TRANSVERSE: - case JXFORM_ROT_180: - if (image_width % (JDIMENSION)MCU_width) - result = FALSE; - if (image_height % (JDIMENSION)MCU_height) - result = FALSE; - break; - default: - break; - } - - return result; -} - -#endif /* TRANSFORMS_SUPPORTED */ - - -/* Setup decompression object to save desired markers in memory. - * This must be called before jpeg_read_header() to have the desired effect. - */ - -GLOBAL(void) -jcopy_markers_setup(j_decompress_ptr srcinfo, JCOPY_OPTION option) -{ -#ifdef SAVE_MARKERS_SUPPORTED - int m; - - /* Save comments except under NONE option */ - if (option != JCOPYOPT_NONE && option != JCOPYOPT_ICC) { - jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF); - } - /* Save all types of APPn markers iff ALL option */ - if (option == JCOPYOPT_ALL || option == JCOPYOPT_ALL_EXCEPT_ICC) { - for (m = 0; m < 16; m++) { - if (option == JCOPYOPT_ALL_EXCEPT_ICC && m == 2) - continue; - jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF); - } - } - /* Save only APP2 markers if ICC option selected */ - if (option == JCOPYOPT_ICC) { - jpeg_save_markers(srcinfo, JPEG_APP0 + 2, 0xFFFF); - } -#endif /* SAVE_MARKERS_SUPPORTED */ -} - -/* Copy markers saved in the given source object to the destination object. - * This should be called just after jpeg_start_compress() or - * jpeg_write_coefficients(). - * Note that those routines will have written the SOI, and also the - * JFIF APP0 or Adobe APP14 markers if selected. - */ - -GLOBAL(void) -jcopy_markers_execute(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - JCOPY_OPTION option) -{ - jpeg_saved_marker_ptr marker; - - /* In the current implementation, we don't actually need to examine the - * option flag here; we just copy everything that got saved. - * But to avoid confusion, we do not output JFIF and Adobe APP14 markers - * if the encoder library already wrote one. - */ - for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) { - if (dstinfo->write_JFIF_header && - marker->marker == JPEG_APP0 && - marker->data_length >= 5 && - marker->data[0] == 0x4A && - marker->data[1] == 0x46 && - marker->data[2] == 0x49 && - marker->data[3] == 0x46 && - marker->data[4] == 0) - continue; /* reject duplicate JFIF */ - if (dstinfo->write_Adobe_marker && - marker->marker == JPEG_APP0 + 14 && - marker->data_length >= 5 && - marker->data[0] == 0x41 && - marker->data[1] == 0x64 && - marker->data[2] == 0x6F && - marker->data[3] == 0x62 && - marker->data[4] == 0x65) - continue; /* reject duplicate Adobe */ - jpeg_write_marker(dstinfo, marker->marker, - marker->data, marker->data_length); - } -} diff --git a/3rdparty/libjpeg-turbo/src/transupp.h b/3rdparty/libjpeg-turbo/src/transupp.h deleted file mode 100644 index cea1f40921..0000000000 --- a/3rdparty/libjpeg-turbo/src/transupp.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * transupp.h - * - * This file was part of the Independent JPEG Group's software: - * Copyright (C) 1997-2019, Thomas G. Lane, Guido Vollbeding. - * libjpeg-turbo Modifications: - * Copyright (C) 2017, 2021, D. R. Commander. - * For conditions of distribution and use, see the accompanying README.ijg - * file. - * - * This file contains declarations for image transformation routines and - * other utility code used by the jpegtran sample application. These are - * NOT part of the core JPEG library. But we keep these routines separate - * from jpegtran.c to ease the task of maintaining jpegtran-like programs - * that have other user interfaces. - * - * NOTE: all the routines declared here have very specific requirements - * about when they are to be executed during the reading and writing of the - * source and destination files. See the comments in transupp.c, or see - * jpegtran.c for an example of correct usage. - */ - -/* If you happen not to want the image transform support, disable it here */ -#ifndef TRANSFORMS_SUPPORTED -#define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */ -#endif - -/* - * Although rotating and flipping data expressed as DCT coefficients is not - * hard, there is an asymmetry in the JPEG format specification for images - * whose dimensions aren't multiples of the iMCU size. The right and bottom - * image edges are padded out to the next iMCU boundary with junk data; but - * no padding is possible at the top and left edges. If we were to flip - * the whole image including the pad data, then pad garbage would become - * visible at the top and/or left, and real pixels would disappear into the - * pad margins --- perhaps permanently, since encoders & decoders may not - * bother to preserve DCT blocks that appear to be completely outside the - * nominal image area. So, we have to exclude any partial iMCUs from the - * basic transformation. - * - * Transpose is the only transformation that can handle partial iMCUs at the - * right and bottom edges completely cleanly. flip_h can flip partial iMCUs - * at the bottom, but leaves any partial iMCUs at the right edge untouched. - * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched. - * The other transforms are defined as combinations of these basic transforms - * and process edge blocks in a way that preserves the equivalence. - * - * The "trim" option causes untransformable partial iMCUs to be dropped; - * this is not strictly lossless, but it usually gives the best-looking - * result for odd-size images. Note that when this option is active, - * the expected mathematical equivalences between the transforms may not hold. - * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim - * followed by -rot 180 -trim trims both edges.) - * - * We also offer a lossless-crop option, which discards data outside a given - * image region but losslessly preserves what is inside. Like the rotate and - * flip transforms, lossless crop is restricted by the JPEG format: the upper - * left corner of the selected region must fall on an iMCU boundary. If this - * does not hold for the given crop parameters, we silently move the upper left - * corner up and/or left to make it so, simultaneously increasing the region - * dimensions to keep the lower right crop corner unchanged. (Thus, the - * output image covers at least the requested region, but may cover more.) - * The adjustment of the region dimensions may be optionally disabled. - * - * A complementary lossless wipe option is provided to discard (gray out) data - * inside a given image region while losslessly preserving what is outside. - * A lossless drop option is also provided, which allows another JPEG image to - * be inserted ("dropped") into the source image data at a given position, - * replacing the existing image data at that position. Both the source image - * and the drop image must have the same subsampling level. It is best if they - * also have the same quantization (quality.) Otherwise, the quantization of - * the output image will be adapted to accommodate the higher of the source - * image quality and the drop image quality. The trim option can be used with - * the drop option to requantize the drop image to match the source image. - * - * We also provide a lossless-resize option, which is kind of a lossless-crop - * operation in the DCT coefficient block domain - it discards higher-order - * coefficients and losslessly preserves lower-order coefficients of a - * sub-block. - * - * Rotate/flip transform, resize, and crop can be requested together in a - * single invocation. The crop is applied last --- that is, the crop region - * is specified in terms of the destination image after transform/resize. - * - * We also offer a "force to grayscale" option, which simply discards the - * chrominance channels of a YCbCr image. This is lossless in the sense that - * the luminance channel is preserved exactly. It's not the same kind of - * thing as the rotate/flip transformations, but it's convenient to handle it - * as part of this package, mainly because the transformation routines have to - * be aware of the option to know how many components to work on. - */ - - -/* - * Codes for supported types of image transformations. - */ - -typedef enum { - JXFORM_NONE, /* no transformation */ - JXFORM_FLIP_H, /* horizontal flip */ - JXFORM_FLIP_V, /* vertical flip */ - JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */ - JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */ - JXFORM_ROT_90, /* 90-degree clockwise rotation */ - JXFORM_ROT_180, /* 180-degree rotation */ - JXFORM_ROT_270, /* 270-degree clockwise (or 90 ccw) */ - JXFORM_WIPE, /* wipe */ - JXFORM_DROP /* drop */ -} JXFORM_CODE; - -/* - * Codes for crop parameters, which can individually be unspecified, - * positive or negative for xoffset or yoffset, - * positive or force or reflect for width or height. - */ - -typedef enum { - JCROP_UNSET, - JCROP_POS, - JCROP_NEG, - JCROP_FORCE, - JCROP_REFLECT -} JCROP_CODE; - -/* - * Transform parameters struct. - * NB: application must not change any elements of this struct after - * calling jtransform_request_workspace. - */ - -typedef struct { - /* Options: set by caller */ - JXFORM_CODE transform; /* image transform operator */ - boolean perfect; /* if TRUE, fail if partial MCUs are requested */ - boolean trim; /* if TRUE, trim partial MCUs as needed */ - boolean force_grayscale; /* if TRUE, convert color image to grayscale */ - boolean crop; /* if TRUE, crop or wipe source image, or drop */ - boolean slow_hflip; /* For best performance, the JXFORM_FLIP_H transform - normally modifies the source coefficients in place. - Setting this to TRUE will instead use a slower, - double-buffered algorithm, which leaves the source - coefficients in tact (necessary if other transformed - images must be generated from the same set of - coefficients. */ - - /* Crop parameters: application need not set these unless crop is TRUE. - * These can be filled in by jtransform_parse_crop_spec(). - */ - JDIMENSION crop_width; /* Width of selected region */ - JCROP_CODE crop_width_set; /* (force-disables adjustment) */ - JDIMENSION crop_height; /* Height of selected region */ - JCROP_CODE crop_height_set; /* (force-disables adjustment) */ - JDIMENSION crop_xoffset; /* X offset of selected region */ - JCROP_CODE crop_xoffset_set; /* (negative measures from right edge) */ - JDIMENSION crop_yoffset; /* Y offset of selected region */ - JCROP_CODE crop_yoffset_set; /* (negative measures from bottom edge) */ - - /* Drop parameters: set by caller for drop request */ - j_decompress_ptr drop_ptr; - jvirt_barray_ptr *drop_coef_arrays; - - /* Internal workspace: caller should not touch these */ - int num_components; /* # of components in workspace */ - jvirt_barray_ptr *workspace_coef_arrays; /* workspace for transformations */ - JDIMENSION output_width; /* cropped destination dimensions */ - JDIMENSION output_height; - JDIMENSION x_crop_offset; /* destination crop offsets measured in iMCUs */ - JDIMENSION y_crop_offset; - JDIMENSION drop_width; /* drop/wipe dimensions measured in iMCUs */ - JDIMENSION drop_height; - int iMCU_sample_width; /* destination iMCU size */ - int iMCU_sample_height; -} jpeg_transform_info; - - -#if TRANSFORMS_SUPPORTED - -/* Parse a crop specification (written in X11 geometry style) */ -EXTERN(boolean) jtransform_parse_crop_spec(jpeg_transform_info *info, - const char *spec); -/* Request any required workspace */ -EXTERN(boolean) jtransform_request_workspace(j_decompress_ptr srcinfo, - jpeg_transform_info *info); -/* Adjust output image parameters */ -EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters - (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, - jvirt_barray_ptr *src_coef_arrays, jpeg_transform_info *info); -/* Execute the actual transformation, if any */ -EXTERN(void) jtransform_execute_transform(j_decompress_ptr srcinfo, - j_compress_ptr dstinfo, - jvirt_barray_ptr *src_coef_arrays, - jpeg_transform_info *info); -/* Determine whether lossless transformation is perfectly - * possible for a specified image and transformation. - */ -EXTERN(boolean) jtransform_perfect_transform(JDIMENSION image_width, - JDIMENSION image_height, - int MCU_width, int MCU_height, - JXFORM_CODE transform); - -/* jtransform_execute_transform used to be called - * jtransform_execute_transformation, but some compilers complain about - * routine names that long. This macro is here to avoid breaking any - * old source code that uses the original name... - */ -#define jtransform_execute_transformation jtransform_execute_transform - -#endif /* TRANSFORMS_SUPPORTED */ - - -/* - * Support for copying optional markers from source to destination file. - */ - -typedef enum { - JCOPYOPT_NONE, /* copy no optional markers */ - JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */ - JCOPYOPT_ALL, /* copy all optional markers */ - JCOPYOPT_ALL_EXCEPT_ICC, /* copy all optional markers except APP2 */ - JCOPYOPT_ICC /* copy only ICC profile (APP2) markers */ -} JCOPY_OPTION; - -#define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */ - -/* Setup decompression object to save desired markers in memory */ -EXTERN(void) jcopy_markers_setup(j_decompress_ptr srcinfo, - JCOPY_OPTION option); -/* Copy markers saved in the given source object to the destination object */ -EXTERN(void) jcopy_markers_execute(j_decompress_ptr srcinfo, - j_compress_ptr dstinfo, - JCOPY_OPTION option); diff --git a/3rdparty/libjpeg-turbo/src/turbojpeg-jni.c b/3rdparty/libjpeg-turbo/src/turbojpeg-jni.c deleted file mode 100644 index 32186f3fa0..0000000000 --- a/3rdparty/libjpeg-turbo/src/turbojpeg-jni.c +++ /dev/null @@ -1,1400 +0,0 @@ -/* - * Copyright (C)2011-2023 D. R. Commander. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the libjpeg-turbo Project nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include "turbojpeg.h" -#include "jinclude.h" -#include -#include "java/org_libjpegturbo_turbojpeg_TJCompressor.h" -#include "java/org_libjpegturbo_turbojpeg_TJDecompressor.h" -#include "java/org_libjpegturbo_turbojpeg_TJTransformer.h" -#include "java/org_libjpegturbo_turbojpeg_TJ.h" - -#define BAILIF0(f) { \ - if (!(f) || (*env)->ExceptionCheck(env)) { \ - goto bailout; \ - } \ -} - -#define BAILIF0NOEC(f) { \ - if (!(f)) { \ - goto bailout; \ - } \ -} - -#define THROW(msg, exceptionClass) { \ - jclass _exccls = (*env)->FindClass(env, exceptionClass); \ - \ - BAILIF0(_exccls); \ - (*env)->ThrowNew(env, _exccls, msg); \ - goto bailout; \ -} - -#define THROW_TJ() { \ - jclass _exccls; \ - jmethodID _excid; \ - jobject _excobj; \ - jstring _errstr; \ - \ - BAILIF0(_errstr = (*env)->NewStringUTF(env, tj3GetErrorStr(handle))); \ - BAILIF0(_exccls = (*env)->FindClass(env, \ - "org/libjpegturbo/turbojpeg/TJException")); \ - BAILIF0(_excid = (*env)->GetMethodID(env, _exccls, "", \ - "(Ljava/lang/String;I)V")); \ - BAILIF0(_excobj = (*env)->NewObject(env, _exccls, _excid, _errstr, \ - tj3GetErrorCode(handle))); \ - (*env)->Throw(env, _excobj); \ - goto bailout; \ -} - -#define THROW_ARG(msg) THROW(msg, "java/lang/IllegalArgumentException") - -#define THROW_MEM() \ - THROW("Memory allocation failure", "java/lang/OutOfMemoryError"); - -#define GET_HANDLE() \ - jclass _cls = (*env)->GetObjectClass(env, obj); \ - jfieldID _fid; \ - \ - BAILIF0(_cls); \ - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "handle", "J")); \ - handle = (tjhandle)(size_t)(*env)->GetLongField(env, obj, _fid); - -#define SAFE_RELEASE(javaArray, cArray) { \ - if (javaArray && cArray) \ - (*env)->ReleasePrimitiveArrayCritical(env, javaArray, (void *)cArray, 0); \ - cArray = NULL; \ -} - -/* TurboJPEG 1.2.x: TJ::bufSize() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSize - (JNIEnv *env, jclass cls, jint width, jint height, jint jpegSubsamp) -{ - size_t retval = tj3JPEGBufSize(width, height, jpegSubsamp); - - if (retval == 0) THROW_ARG(tj3GetErrorStr(NULL)); - if (retval > (size_t)INT_MAX) - THROW_ARG("Image is too large"); - -bailout: - return (jint)retval; -} - -/* TurboJPEG 1.4.x: TJ::bufSizeYUV() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII - (JNIEnv *env, jclass cls, jint width, jint align, jint height, jint subsamp) -{ - size_t retval = tj3YUVBufSize(width, align, height, subsamp); - - if (retval == 0) THROW_ARG(tj3GetErrorStr(NULL)); - if (retval > (size_t)INT_MAX) - THROW_ARG("Image is too large"); - -bailout: - return (jint)retval; -} - -/* TurboJPEG 1.4.x: TJ::planeSizeYUV() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeSizeYUV__IIIII - (JNIEnv *env, jclass cls, jint componentID, jint width, jint stride, - jint height, jint subsamp) -{ - size_t retval = tj3YUVPlaneSize(componentID, width, stride, height, subsamp); - - if (retval == 0) THROW_ARG(tj3GetErrorStr(NULL)); - if (retval > (size_t)INT_MAX) - THROW_ARG("Image is too large"); - -bailout: - return (jint)retval; -} - -/* TurboJPEG 1.4.x: TJ::planeWidth() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeWidth__III - (JNIEnv *env, jclass cls, jint componentID, jint width, jint subsamp) -{ - jint retval = (jint)tj3YUVPlaneWidth(componentID, width, subsamp); - - if (retval == 0) THROW_ARG(tj3GetErrorStr(NULL)); - -bailout: - return retval; -} - -/* TurboJPEG 1.4.x: TJ::planeHeight() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_planeHeight__III - (JNIEnv *env, jclass cls, jint componentID, jint height, jint subsamp) -{ - jint retval = (jint)tj3YUVPlaneHeight(componentID, height, subsamp); - - if (retval == 0) THROW_ARG(tj3GetErrorStr(NULL)); - -bailout: - return retval; -} - -/* TurboJPEG 1.2.x: TJCompressor::init() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_init - (JNIEnv *env, jobject obj) -{ - jclass cls; - jfieldID fid; - tjhandle handle; - - if ((handle = tj3Init(TJINIT_COMPRESS)) == NULL) - THROW(tj3GetErrorStr(NULL), "org/libjpegturbo/turbojpeg/TJException"); - - BAILIF0(cls = (*env)->GetObjectClass(env, obj)); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "handle", "J")); - (*env)->SetLongField(env, obj, fid, (size_t)handle); - -bailout: - return; -} - -/* TurboJPEG 3: TJCompressor::set() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_set - (JNIEnv *env, jobject obj, jint param, jint value) -{ - tjhandle handle = 0; - - GET_HANDLE(); - - if (tj3Set(handle, param, value) == -1) - THROW_TJ(); - -bailout: - return; -} - -/* TurboJPEG 3: TJCompressor::get() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_get - (JNIEnv *env, jobject obj, jint param) -{ - tjhandle handle = 0; - - GET_HANDLE(); - - return tj3Get(handle, param); - -bailout: - return -1; -} - -static jint TJCompressor_compress - (JNIEnv *env, jobject obj, jarray src, jint srcElementSize, jint precision, - jint x, jint y, jint width, jint pitch, jint height, jint pf, - jbyteArray dst) -{ - tjhandle handle = 0; - size_t jpegSize = 0; - jsize arraySize = 0, actualPitch; - void *srcBuf = NULL; - unsigned char *jpegBuf = NULL; - int jpegSubsamp; - - GET_HANDLE(); - - if (pf < 0 || pf >= org_libjpegturbo_turbojpeg_TJ_NUMPF || width < 1 || - height < 1 || pitch < 0) - THROW_ARG("Invalid argument in compress*()"); - if (org_libjpegturbo_turbojpeg_TJ_NUMPF != TJ_NUMPF) - THROW_ARG("Mismatch between Java and C API"); - - actualPitch = (pitch == 0) ? width * tjPixelSize[pf] : pitch; - arraySize = (y + height - 1) * actualPitch + (x + width) * tjPixelSize[pf]; - if ((*env)->GetArrayLength(env, src) * srcElementSize < arraySize) - THROW_ARG("Source buffer is not large enough"); - jpegSubsamp = tj3Get(handle, TJPARAM_SUBSAMP); - if (tj3Get(handle, TJPARAM_LOSSLESS) && jpegSubsamp != TJSAMP_GRAY) - jpegSubsamp = TJSAMP_444; - else if (jpegSubsamp == TJSAMP_UNKNOWN) - THROW_ARG("TJPARAM_SUBSAMP must be specified"); - jpegSize = tj3JPEGBufSize(width, height, jpegSubsamp); - if ((*env)->GetArrayLength(env, dst) < (jsize)jpegSize) - THROW_ARG("Destination buffer is not large enough"); - - if (tj3Set(handle, TJPARAM_NOREALLOC, 1) == -1) - THROW_TJ(); - - BAILIF0NOEC(srcBuf = (*env)->GetPrimitiveArrayCritical(env, src, 0)); - BAILIF0NOEC(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, dst, 0)); - - if (precision == 8) { - if (tj3Compress8(handle, &((unsigned char *)srcBuf)[y * actualPitch + - x * tjPixelSize[pf]], - width, pitch, height, pf, &jpegBuf, &jpegSize) == -1) { - SAFE_RELEASE(dst, jpegBuf); - SAFE_RELEASE(src, srcBuf); - THROW_TJ(); - } - } else if (precision == 12) { - if (tj3Compress12(handle, &((short *)srcBuf)[y * actualPitch + - x * tjPixelSize[pf]], - width, pitch, height, pf, &jpegBuf, &jpegSize) == -1) { - SAFE_RELEASE(dst, jpegBuf); - SAFE_RELEASE(src, srcBuf); - THROW_TJ(); - } - } else { - if (tj3Compress16(handle, &((unsigned short *)srcBuf)[y * actualPitch + - x * tjPixelSize[pf]], - width, pitch, height, pf, &jpegBuf, &jpegSize) == -1) { - SAFE_RELEASE(dst, jpegBuf); - SAFE_RELEASE(src, srcBuf); - THROW_TJ(); - } - } - -bailout: - SAFE_RELEASE(dst, jpegBuf); - SAFE_RELEASE(src, srcBuf); - return (jint)jpegSize; -} - -/* TurboJPEG 3: TJCompressor::compress8() byte source */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress8___3BIIIIII_3B - (JNIEnv *env, jobject obj, jbyteArray src, jint x, jint y, jint width, - jint pitch, jint height, jint pf, jbyteArray dst) -{ - return TJCompressor_compress(env, obj, src, 1, 8, x, y, width, pitch, height, - pf, dst); -} - -/* TurboJPEG 3: TJCompressor::compress12() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress12 - (JNIEnv *env, jobject obj, jshortArray src, jint x, jint y, jint width, - jint pitch, jint height, jint pf, jbyteArray dst) -{ - return TJCompressor_compress(env, obj, src, 1, 12, x, y, width, pitch, - height, pf, dst); -} - -/* TurboJPEG 3: TJCompressor::compress16() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress16 - (JNIEnv *env, jobject obj, jshortArray src, jint x, jint y, jint width, - jint pitch, jint height, jint pf, jbyteArray dst) -{ - return TJCompressor_compress(env, obj, src, 1, 16, x, y, width, pitch, - height, pf, dst); -} - -/* TurboJPEG 3: TJCompressor::compress8() int source */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress8___3IIIIIII_3B - (JNIEnv *env, jobject obj, jintArray src, jint x, jint y, jint width, - jint stride, jint height, jint pf, jbyteArray dst) -{ - if (pf < 0 || pf >= org_libjpegturbo_turbojpeg_TJ_NUMPF) - THROW_ARG("Invalid argument in compress8()"); - if (tjPixelSize[pf] != sizeof(jint)) - THROW_ARG("Pixel format must be 32-bit when compressing from an integer buffer."); - - return TJCompressor_compress(env, obj, src, sizeof(jint), 8, x, y, width, - stride * sizeof(jint), height, pf, dst); - -bailout: - return 0; -} - -/* TurboJPEG 3: TJCompressor::compressFromYUV8() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFromYUV8 - (JNIEnv *env, jobject obj, jobjectArray srcobjs, jintArray jSrcOffsets, - jint width, jintArray jSrcStrides, jint height, jbyteArray dst) -{ - tjhandle handle = 0; - size_t jpegSize = 0; - jbyteArray jSrcPlanes[3] = { NULL, NULL, NULL }; - const unsigned char *srcPlanesTmp[3] = { NULL, NULL, NULL }; - const unsigned char *srcPlanes[3] = { NULL, NULL, NULL }; - jint srcOffsetsTmp[3] = { 0, 0, 0 }, srcStridesTmp[3] = { 0, 0, 0 }; - int srcOffsets[3] = { 0, 0, 0 }, srcStrides[3] = { 0, 0, 0 }; - unsigned char *jpegBuf = NULL; - int nc = 0, i, subsamp; - - GET_HANDLE(); - - if (org_libjpegturbo_turbojpeg_TJ_NUMSAMP != TJ_NUMSAMP) - THROW_ARG("Mismatch between Java and C API"); - - if ((subsamp = tj3Get(handle, TJPARAM_SUBSAMP)) == TJSAMP_UNKNOWN) - THROW_ARG("TJPARAM_SUBSAMP must be specified"); - nc = subsamp == TJSAMP_GRAY ? 1 : 3; - if ((*env)->GetArrayLength(env, srcobjs) < nc) - THROW_ARG("Planes array is too small for the subsampling type"); - if ((*env)->GetArrayLength(env, jSrcOffsets) < nc) - THROW_ARG("Offsets array is too small for the subsampling type"); - if ((*env)->GetArrayLength(env, jSrcStrides) < nc) - THROW_ARG("Strides array is too small for the subsampling type"); - - jpegSize = tj3JPEGBufSize(width, height, subsamp); - if ((*env)->GetArrayLength(env, dst) < (jsize)jpegSize) - THROW_ARG("Destination buffer is not large enough"); - - if (tj3Set(handle, TJPARAM_NOREALLOC, 1) == -1) - THROW_TJ(); - - (*env)->GetIntArrayRegion(env, jSrcOffsets, 0, nc, srcOffsetsTmp); - if ((*env)->ExceptionCheck(env)) goto bailout; - for (i = 0; i < 3; i++) - srcOffsets[i] = srcOffsetsTmp[i]; - - (*env)->GetIntArrayRegion(env, jSrcStrides, 0, nc, srcStridesTmp); - if ((*env)->ExceptionCheck(env)) goto bailout; - for (i = 0; i < 3; i++) - srcStrides[i] = srcStridesTmp[i]; - - for (i = 0; i < nc; i++) { - size_t planeSize = tj3YUVPlaneSize(i, width, srcStrides[i], height, - subsamp); - int pw = tj3YUVPlaneWidth(i, width, subsamp); - - if (planeSize == 0 || pw == 0) - THROW_ARG(tj3GetErrorStr(NULL)); - - if (planeSize > (size_t)INT_MAX) - THROW_ARG("Source plane is too large"); - if (srcOffsets[i] < 0) - THROW_ARG("Invalid argument in compressFromYUV8()"); - if (srcStrides[i] < 0 && srcOffsets[i] - (int)planeSize + pw < 0) - THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary"); - - BAILIF0(jSrcPlanes[i] = (*env)->GetObjectArrayElement(env, srcobjs, i)); - if ((*env)->GetArrayLength(env, jSrcPlanes[i]) < - srcOffsets[i] + (int)planeSize) - THROW_ARG("Source plane is not large enough"); - } - for (i = 0; i < nc; i++) { - BAILIF0NOEC(srcPlanesTmp[i] = - (*env)->GetPrimitiveArrayCritical(env, jSrcPlanes[i], 0)); - srcPlanes[i] = &srcPlanesTmp[i][srcOffsets[i]]; - } - BAILIF0NOEC(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, dst, 0)); - - if (tj3CompressFromYUVPlanes8(handle, srcPlanes, width, srcStrides, height, - &jpegBuf, &jpegSize) == -1) { - SAFE_RELEASE(dst, jpegBuf); - for (i = 0; i < nc; i++) - SAFE_RELEASE(jSrcPlanes[i], srcPlanesTmp[i]); - THROW_TJ(); - } - -bailout: - SAFE_RELEASE(dst, jpegBuf); - for (i = 0; i < nc; i++) - SAFE_RELEASE(jSrcPlanes[i], srcPlanesTmp[i]); - return (jint)jpegSize; -} - -static void TJCompressor_encodeYUV8 - (JNIEnv *env, jobject obj, jarray src, jint srcElementSize, jint x, jint y, - jint width, jint pitch, jint height, jint pf, jobjectArray dstobjs, - jintArray jDstOffsets, jintArray jDstStrides) -{ - tjhandle handle = 0; - jsize arraySize = 0, actualPitch; - unsigned char *srcBuf = NULL; - jbyteArray jDstPlanes[3] = { NULL, NULL, NULL }; - unsigned char *dstPlanesTmp[3] = { NULL, NULL, NULL }; - unsigned char *dstPlanes[3] = { NULL, NULL, NULL }; - jint dstOffsetsTmp[3] = { 0, 0, 0 }, dstStridesTmp[3] = { 0, 0, 0 }; - int dstOffsets[3] = { 0, 0, 0 }, dstStrides[3] = { 0, 0, 0 }; - int nc = 0, i, subsamp; - - GET_HANDLE(); - - if (pf < 0 || pf >= org_libjpegturbo_turbojpeg_TJ_NUMPF || width < 1 || - height < 1 || pitch < 0) - THROW_ARG("Invalid argument in encodeYUV8()"); - if (org_libjpegturbo_turbojpeg_TJ_NUMPF != TJ_NUMPF || - org_libjpegturbo_turbojpeg_TJ_NUMSAMP != TJ_NUMSAMP) - THROW_ARG("Mismatch between Java and C API"); - - if ((subsamp = tj3Get(handle, TJPARAM_SUBSAMP)) == TJSAMP_UNKNOWN) - THROW_ARG("TJPARAM_SUBSAMP must be specified"); - nc = subsamp == TJSAMP_GRAY ? 1 : 3; - if ((*env)->GetArrayLength(env, dstobjs) < nc) - THROW_ARG("Planes array is too small for the subsampling type"); - if ((*env)->GetArrayLength(env, jDstOffsets) < nc) - THROW_ARG("Offsets array is too small for the subsampling type"); - if ((*env)->GetArrayLength(env, jDstStrides) < nc) - THROW_ARG("Strides array is too small for the subsampling type"); - - actualPitch = (pitch == 0) ? width * tjPixelSize[pf] : pitch; - arraySize = (y + height - 1) * actualPitch + (x + width) * tjPixelSize[pf]; - if ((*env)->GetArrayLength(env, src) * srcElementSize < arraySize) - THROW_ARG("Source buffer is not large enough"); - - (*env)->GetIntArrayRegion(env, jDstOffsets, 0, nc, dstOffsetsTmp); - if ((*env)->ExceptionCheck(env)) goto bailout; - for (i = 0; i < 3; i++) - dstOffsets[i] = dstOffsetsTmp[i]; - - (*env)->GetIntArrayRegion(env, jDstStrides, 0, nc, dstStridesTmp); - if ((*env)->ExceptionCheck(env)) goto bailout; - for (i = 0; i < 3; i++) - dstStrides[i] = dstStridesTmp[i]; - - for (i = 0; i < nc; i++) { - size_t planeSize = tj3YUVPlaneSize(i, width, dstStrides[i], height, - subsamp); - int pw = tj3YUVPlaneWidth(i, width, subsamp); - - if (planeSize == 0 || pw == 0) - THROW_ARG(tj3GetErrorStr(NULL)); - - if (planeSize > (size_t)INT_MAX) - THROW_ARG("Destination plane is too large"); - if (dstOffsets[i] < 0) - THROW_ARG("Invalid argument in encodeYUV8()"); - if (dstStrides[i] < 0 && dstOffsets[i] - (int)planeSize + pw < 0) - THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary"); - - BAILIF0(jDstPlanes[i] = (*env)->GetObjectArrayElement(env, dstobjs, i)); - if ((*env)->GetArrayLength(env, jDstPlanes[i]) < - dstOffsets[i] + (int)planeSize) - THROW_ARG("Destination plane is not large enough"); - } - for (i = 0; i < nc; i++) { - BAILIF0NOEC(dstPlanesTmp[i] = - (*env)->GetPrimitiveArrayCritical(env, jDstPlanes[i], 0)); - dstPlanes[i] = &dstPlanesTmp[i][dstOffsets[i]]; - } - BAILIF0NOEC(srcBuf = (*env)->GetPrimitiveArrayCritical(env, src, 0)); - - if (tj3EncodeYUVPlanes8(handle, - &srcBuf[y * actualPitch + x * tjPixelSize[pf]], - width, pitch, height, pf, dstPlanes, - dstStrides) == -1) { - SAFE_RELEASE(src, srcBuf); - for (i = 0; i < nc; i++) - SAFE_RELEASE(jDstPlanes[i], dstPlanesTmp[i]); - THROW_TJ(); - } - -bailout: - SAFE_RELEASE(src, srcBuf); - for (i = 0; i < nc; i++) - SAFE_RELEASE(jDstPlanes[i], dstPlanesTmp[i]); -} - -/* TurboJPEG 3: TJCompressor::encodeYUV8() byte source */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV8___3BIIIIII_3_3B_3I_3I - (JNIEnv *env, jobject obj, jbyteArray src, jint x, jint y, jint width, - jint pitch, jint height, jint pf, jobjectArray dstobjs, - jintArray jDstOffsets, jintArray jDstStrides) -{ - TJCompressor_encodeYUV8(env, obj, src, 1, x, y, width, pitch, height, pf, - dstobjs, jDstOffsets, jDstStrides); -} - -/* TurboJPEG 3: TJCompressor::encodeYUV8() int source */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV8___3IIIIIII_3_3B_3I_3I - (JNIEnv *env, jobject obj, jintArray src, jint x, jint y, jint width, - jint stride, jint height, jint pf, jobjectArray dstobjs, - jintArray jDstOffsets, jintArray jDstStrides) -{ - if (pf < 0 || pf >= org_libjpegturbo_turbojpeg_TJ_NUMPF) - THROW_ARG("Invalid argument in encodeYUV8()"); - if (tjPixelSize[pf] != sizeof(jint)) - THROW_ARG("Pixel format must be 32-bit when encoding from an integer buffer."); - - TJCompressor_encodeYUV8(env, obj, src, sizeof(jint), x, y, width, - stride * sizeof(jint), height, pf, dstobjs, - jDstOffsets, jDstStrides); - -bailout: - return; -} - -/* TurboJPEG 1.2.x: TJCompressor::destroy() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_destroy - (JNIEnv *env, jobject obj) -{ - tjhandle handle = 0; - - GET_HANDLE(); - - tj3Destroy(handle); - (*env)->SetLongField(env, obj, _fid, 0); - -bailout: - return; -} - -/* TurboJPEG 1.2.x: TJDecompressor::init() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_init - (JNIEnv *env, jobject obj) -{ - jclass cls; - jfieldID fid; - tjhandle handle; - - if ((handle = tj3Init(TJINIT_DECOMPRESS)) == NULL) - THROW(tj3GetErrorStr(NULL), "org/libjpegturbo/turbojpeg/TJException"); - - BAILIF0(cls = (*env)->GetObjectClass(env, obj)); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "handle", "J")); - (*env)->SetLongField(env, obj, fid, (size_t)handle); - -bailout: - return; -} - -/* TurboJPEG 3: TJDecompressor::set() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_set - (JNIEnv *env, jobject obj, jint param, jint value) -{ - Java_org_libjpegturbo_turbojpeg_TJCompressor_set(env, obj, param, value); -} - -/* TurboJPEG 3: TJDecompressor::get() */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_get - (JNIEnv *env, jobject obj, jint param) -{ - return Java_org_libjpegturbo_turbojpeg_TJCompressor_get(env, obj, param); -} - -/* TurboJPEG 1.2.x: TJDecompressor::getScalingFactors() */ -JNIEXPORT jobjectArray JNICALL Java_org_libjpegturbo_turbojpeg_TJ_getScalingFactors - (JNIEnv *env, jclass cls) -{ - jclass sfcls = NULL; - jfieldID fid = 0; - tjscalingfactor *sf = NULL; - int n = 0, i; - jobject sfobj = NULL; - jobjectArray sfjava = NULL; - - if ((sf = tj3GetScalingFactors(&n)) == NULL || n == 0) - THROW_ARG(tj3GetErrorStr(NULL)); - - BAILIF0(sfcls = (*env)->FindClass(env, - "org/libjpegturbo/turbojpeg/TJScalingFactor")); - BAILIF0(sfjava = (jobjectArray)(*env)->NewObjectArray(env, n, sfcls, 0)); - - for (i = 0; i < n; i++) { - BAILIF0(sfobj = (*env)->AllocObject(env, sfcls)); - BAILIF0(fid = (*env)->GetFieldID(env, sfcls, "num", "I")); - (*env)->SetIntField(env, sfobj, fid, sf[i].num); - BAILIF0(fid = (*env)->GetFieldID(env, sfcls, "denom", "I")); - (*env)->SetIntField(env, sfobj, fid, sf[i].denom); - (*env)->SetObjectArrayElement(env, sfjava, i, sfobj); - } - -bailout: - return sfjava; -} - -/* TurboJPEG 1.2.x: TJDecompressor::decompressHeader() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressHeader - (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize) -{ - tjhandle handle = 0; - unsigned char *jpegBuf = NULL; - - GET_HANDLE(); - - if ((*env)->GetArrayLength(env, src) < jpegSize) - THROW_ARG("Source buffer is not large enough"); - - BAILIF0NOEC(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, src, 0)); - - if (tj3DecompressHeader(handle, jpegBuf, (size_t)jpegSize) == -1) { - SAFE_RELEASE(src, jpegBuf); - THROW_TJ(); - } - -bailout: - SAFE_RELEASE(src, jpegBuf); -} - -/* TurboJPEG 3: TJDecompressor::setCroppingRegion() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_setCroppingRegion - (JNIEnv *env, jobject obj) -{ - tjhandle handle = 0; - jclass sfcls, crcls; - jobject sfobj, crobj; - tjregion croppingRegion; - tjscalingfactor scalingFactor; - - GET_HANDLE(); - - BAILIF0(sfcls = (*env)->FindClass(env, - "org/libjpegturbo/turbojpeg/TJScalingFactor")); - BAILIF0(_fid = - (*env)->GetFieldID(env, _cls, "scalingFactor", - "Lorg/libjpegturbo/turbojpeg/TJScalingFactor;")); - BAILIF0(sfobj = (*env)->GetObjectField(env, obj, _fid)); - BAILIF0(_fid = (*env)->GetFieldID(env, sfcls, "num", "I")); - scalingFactor.num = (*env)->GetIntField(env, sfobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, sfcls, "denom", "I")); - scalingFactor.denom = (*env)->GetIntField(env, sfobj, _fid); - - if (tj3SetScalingFactor(handle, scalingFactor) == -1) - THROW_TJ(); - - BAILIF0(crcls = (*env)->FindClass(env, "java/awt/Rectangle")); - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "croppingRegion", - "Ljava/awt/Rectangle;")); - BAILIF0(crobj = (*env)->GetObjectField(env, obj, _fid)); - BAILIF0(_fid = (*env)->GetFieldID(env, crcls, "x", "I")); - croppingRegion.x = (*env)->GetIntField(env, crobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, crcls, "y", "I")); - croppingRegion.y = (*env)->GetIntField(env, crobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, crcls, "width", "I")); - croppingRegion.w = (*env)->GetIntField(env, crobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, crcls, "height", "I")); - croppingRegion.h = (*env)->GetIntField(env, crobj, _fid); - - if (tj3SetCroppingRegion(handle, croppingRegion) == -1) - THROW_TJ(); - -bailout: - return; -} - -static void TJDecompressor_decompress - (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jarray dst, - jint dstElementSize, int precision, jint x, jint y, jint pitch, jint pf) -{ - tjhandle handle = 0; - jsize arraySize = 0, actualPitch; - unsigned char *jpegBuf = NULL; - void *dstBuf = NULL; - jclass sfcls, crcls; - jobject sfobj, crobj; - tjscalingfactor scalingFactor; - tjregion cr; - int jpegWidth, jpegHeight, scaledWidth, scaledHeight; - - GET_HANDLE(); - - if (pf < 0 || pf >= org_libjpegturbo_turbojpeg_TJ_NUMPF) - THROW_ARG("Invalid argument in decompress*()"); - if (org_libjpegturbo_turbojpeg_TJ_NUMPF != TJ_NUMPF) - THROW_ARG("Mismatch between Java and C API"); - - if ((*env)->GetArrayLength(env, src) < jpegSize) - THROW_ARG("Source buffer is not large enough"); - if ((jpegWidth = tj3Get(handle, TJPARAM_JPEGWIDTH)) == -1) - THROW_ARG("JPEG header has not yet been read"); - if ((jpegHeight = tj3Get(handle, TJPARAM_JPEGHEIGHT)) == -1) - THROW_ARG("JPEG header has not yet been read"); - - BAILIF0(sfcls = (*env)->FindClass(env, - "org/libjpegturbo/turbojpeg/TJScalingFactor")); - BAILIF0(_fid = - (*env)->GetFieldID(env, _cls, "scalingFactor", - "Lorg/libjpegturbo/turbojpeg/TJScalingFactor;")); - BAILIF0(sfobj = (*env)->GetObjectField(env, obj, _fid)); - BAILIF0(_fid = (*env)->GetFieldID(env, sfcls, "num", "I")); - scalingFactor.num = (*env)->GetIntField(env, sfobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, sfcls, "denom", "I")); - scalingFactor.denom = (*env)->GetIntField(env, sfobj, _fid); - - if (tj3SetScalingFactor(handle, scalingFactor) == -1) - THROW_TJ(); - scaledWidth = TJSCALED(jpegWidth, scalingFactor); - scaledHeight = TJSCALED(jpegHeight, scalingFactor); - - BAILIF0(crcls = (*env)->FindClass(env, "java/awt/Rectangle")); - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "croppingRegion", - "Ljava/awt/Rectangle;")); - BAILIF0(crobj = (*env)->GetObjectField(env, obj, _fid)); - BAILIF0(_fid = (*env)->GetFieldID(env, crcls, "x", "I")); - cr.x = (*env)->GetIntField(env, crobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, crcls, "y", "I")); - cr.y = (*env)->GetIntField(env, crobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, crcls, "width", "I")); - cr.w = (*env)->GetIntField(env, crobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, crcls, "height", "I")); - cr.h = (*env)->GetIntField(env, crobj, _fid); - if (cr.x != 0 || cr.y != 0 || cr.w != 0 || cr.h != 0) { - scaledWidth = cr.w ? cr.w : scaledWidth - cr.x; - scaledHeight = cr.h ? cr.h : scaledHeight - cr.y; - } - - actualPitch = (pitch == 0) ? scaledWidth * tjPixelSize[pf] : pitch; - arraySize = (y + scaledHeight - 1) * actualPitch + - (x + scaledWidth) * tjPixelSize[pf]; - if ((*env)->GetArrayLength(env, dst) * dstElementSize < arraySize) - THROW_ARG("Destination buffer is not large enough"); - - BAILIF0NOEC(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, src, 0)); - BAILIF0NOEC(dstBuf = (*env)->GetPrimitiveArrayCritical(env, dst, 0)); - - if (precision == 8) { - if (tj3Decompress8(handle, jpegBuf, (size_t)jpegSize, - &((unsigned char *)dstBuf)[y * actualPitch + - x * tjPixelSize[pf]], - pitch, pf) == -1) { - SAFE_RELEASE(dst, dstBuf); - SAFE_RELEASE(src, jpegBuf); - THROW_TJ(); - } - } else if (precision == 12) { - if (tj3Decompress12(handle, jpegBuf, (size_t)jpegSize, - &((short *)dstBuf)[y * actualPitch + - x * tjPixelSize[pf]], - pitch, pf) == -1) { - SAFE_RELEASE(dst, dstBuf); - SAFE_RELEASE(src, jpegBuf); - THROW_TJ(); - } - } else { - if (tj3Decompress16(handle, jpegBuf, (size_t)jpegSize, - &((unsigned short *)dstBuf)[y * actualPitch + - x * tjPixelSize[pf]], - pitch, pf) == -1) { - SAFE_RELEASE(dst, dstBuf); - SAFE_RELEASE(src, jpegBuf); - THROW_TJ(); - } - } - -bailout: - SAFE_RELEASE(dst, dstBuf); - SAFE_RELEASE(src, jpegBuf); -} - -/* TurboJPEG 3: TJDecompressor::decompress8() byte destination */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress8___3BI_3BIIII - (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, - jint x, jint y, jint pitch, jint pf) -{ - TJDecompressor_decompress(env, obj, src, jpegSize, dst, 1, 8, x, y, pitch, - pf); -} - -/* TurboJPEG 3: TJDecompressor::decompress12() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress12 - (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jshortArray dst, - jint x, jint y, jint pitch, jint pf) -{ - TJDecompressor_decompress(env, obj, src, jpegSize, dst, 1, 12, x, y, pitch, - pf); -} - -/* TurboJPEG 3: TJDecompressor::decompress16() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress16 - (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jshortArray dst, - jint x, jint y, jint pitch, jint pf) -{ - TJDecompressor_decompress(env, obj, src, jpegSize, dst, 1, 16, x, y, pitch, - pf); -} - -/* TurboJPEG 3: TJDecompressor::decompress8() int destination */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress8___3BI_3IIIII - (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jintArray dst, - jint x, jint y, jint stride, jint pf) -{ - if (pf < 0 || pf >= org_libjpegturbo_turbojpeg_TJ_NUMPF) - THROW_ARG("Invalid argument in decompress8()"); - if (tjPixelSize[pf] != sizeof(jint)) - THROW_ARG("Pixel format must be 32-bit when decompressing to an integer buffer."); - - TJDecompressor_decompress(env, obj, src, jpegSize, dst, sizeof(jint), 8, x, - y, stride * sizeof(jint), pf); - -bailout: - return; -} - -/* TurboJPEG 3: TJDecompressor::decompressToYUV8() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV8 - (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, - jobjectArray dstobjs, jintArray jDstOffsets, jintArray jDstStrides) -{ - tjhandle handle = 0; - unsigned char *jpegBuf = NULL; - jbyteArray jDstPlanes[3] = { NULL, NULL, NULL }; - unsigned char *dstPlanesTmp[3] = { NULL, NULL, NULL }; - unsigned char *dstPlanes[3] = { NULL, NULL, NULL }; - jint dstOffsetsTmp[3] = { 0, 0, 0 }, dstStridesTmp[3] = { 0, 0, 0 }; - int dstOffsets[3] = { 0, 0, 0 }, dstStrides[3] = { 0, 0, 0 }; - jclass sfcls; - jobject sfobj; - int jpegSubsamp, jpegWidth = 0, jpegHeight = 0; - int nc = 0, i, scaledWidth, scaledHeight; - tjscalingfactor scalingFactor; - - GET_HANDLE(); - - if ((*env)->GetArrayLength(env, src) < jpegSize) - THROW_ARG("Source buffer is not large enough"); - if ((jpegWidth = tj3Get(handle, TJPARAM_JPEGWIDTH)) == -1) - THROW_ARG("JPEG header has not yet been read"); - if ((jpegHeight = tj3Get(handle, TJPARAM_JPEGHEIGHT)) == -1) - THROW_ARG("JPEG header has not yet been read"); - - BAILIF0(sfcls = (*env)->FindClass(env, - "org/libjpegturbo/turbojpeg/TJScalingFactor")); - BAILIF0(_fid = - (*env)->GetFieldID(env, _cls, "scalingFactor", - "Lorg/libjpegturbo/turbojpeg/TJScalingFactor;")); - BAILIF0(sfobj = (*env)->GetObjectField(env, obj, _fid)); - BAILIF0(_fid = (*env)->GetFieldID(env, sfcls, "num", "I")); - scalingFactor.num = (*env)->GetIntField(env, sfobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, sfcls, "denom", "I")); - scalingFactor.denom = (*env)->GetIntField(env, sfobj, _fid); - - if (tj3SetScalingFactor(handle, scalingFactor) == -1) - THROW_TJ(); - scaledWidth = TJSCALED(jpegWidth, scalingFactor); - scaledHeight = TJSCALED(jpegHeight, scalingFactor); - - if ((jpegSubsamp = tj3Get(handle, TJPARAM_SUBSAMP)) == TJSAMP_UNKNOWN) - THROW_ARG("TJPARAM_SUBSAMP must be specified"); - nc = jpegSubsamp == TJSAMP_GRAY ? 1 : 3; - - (*env)->GetIntArrayRegion(env, jDstOffsets, 0, nc, dstOffsetsTmp); - if ((*env)->ExceptionCheck(env)) goto bailout; - for (i = 0; i < 3; i++) - dstOffsets[i] = dstOffsetsTmp[i]; - - (*env)->GetIntArrayRegion(env, jDstStrides, 0, nc, dstStridesTmp); - if ((*env)->ExceptionCheck(env)) goto bailout; - for (i = 0; i < 3; i++) - dstStrides[i] = dstStridesTmp[i]; - - for (i = 0; i < nc; i++) { - size_t planeSize = tj3YUVPlaneSize(i, scaledWidth, dstStrides[i], - scaledHeight, jpegSubsamp); - int pw = tj3YUVPlaneWidth(i, scaledWidth, jpegSubsamp); - - if (planeSize == 0 || pw == 0) - THROW_ARG(tj3GetErrorStr(NULL)); - - if (planeSize > (size_t)INT_MAX) - THROW_ARG("Destination plane is too large"); - if (dstOffsets[i] < 0) - THROW_ARG("Invalid argument in decompressToYUV8()"); - if (dstStrides[i] < 0 && dstOffsets[i] - (int)planeSize + pw < 0) - THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary"); - - BAILIF0(jDstPlanes[i] = (*env)->GetObjectArrayElement(env, dstobjs, i)); - if ((*env)->GetArrayLength(env, jDstPlanes[i]) < - dstOffsets[i] + (int)planeSize) - THROW_ARG("Destination plane is not large enough"); - } - for (i = 0; i < nc; i++) { - BAILIF0NOEC(dstPlanesTmp[i] = - (*env)->GetPrimitiveArrayCritical(env, jDstPlanes[i], 0)); - dstPlanes[i] = &dstPlanesTmp[i][dstOffsets[i]]; - } - BAILIF0NOEC(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, src, 0)); - - if (tj3DecompressToYUVPlanes8(handle, jpegBuf, (size_t)jpegSize, dstPlanes, - dstStrides) == -1) { - SAFE_RELEASE(src, jpegBuf); - for (i = 0; i < nc; i++) - SAFE_RELEASE(jDstPlanes[i], dstPlanesTmp[i]); - THROW_TJ(); - } - -bailout: - SAFE_RELEASE(src, jpegBuf); - for (i = 0; i < nc; i++) - SAFE_RELEASE(jDstPlanes[i], dstPlanesTmp[i]); -} - -static void TJDecompressor_decodeYUV8 - (JNIEnv *env, jobject obj, jobjectArray srcobjs, jintArray jSrcOffsets, - jintArray jSrcStrides, jarray dst, jint dstElementSize, jint x, jint y, - jint width, jint pitch, jint height, jint pf) -{ - tjhandle handle = 0; - jsize arraySize = 0, actualPitch; - jbyteArray jSrcPlanes[3] = { NULL, NULL, NULL }; - const unsigned char *srcPlanesTmp[3] = { NULL, NULL, NULL }; - const unsigned char *srcPlanes[3] = { NULL, NULL, NULL }; - jint srcOffsetsTmp[3] = { 0, 0, 0 }, srcStridesTmp[3] = { 0, 0, 0 }; - int srcOffsets[3] = { 0, 0, 0 }, srcStrides[3] = { 0, 0, 0 }; - unsigned char *dstBuf = NULL; - int nc = 0, i, subsamp; - - GET_HANDLE(); - - if (pf < 0 || pf >= org_libjpegturbo_turbojpeg_TJ_NUMPF) - THROW_ARG("Invalid argument in decodeYUV8()"); - if (org_libjpegturbo_turbojpeg_TJ_NUMPF != TJ_NUMPF || - org_libjpegturbo_turbojpeg_TJ_NUMSAMP != TJ_NUMSAMP) - THROW_ARG("Mismatch between Java and C API"); - - if ((subsamp = tj3Get(handle, TJPARAM_SUBSAMP)) == TJSAMP_UNKNOWN) - THROW_ARG("TJPARAM_SUBSAMP must be specified"); - nc = subsamp == TJSAMP_GRAY ? 1 : 3; - if ((*env)->GetArrayLength(env, srcobjs) < nc) - THROW_ARG("Planes array is too small for the subsampling type"); - if ((*env)->GetArrayLength(env, jSrcOffsets) < nc) - THROW_ARG("Offsets array is too small for the subsampling type"); - if ((*env)->GetArrayLength(env, jSrcStrides) < nc) - THROW_ARG("Strides array is too small for the subsampling type"); - - actualPitch = (pitch == 0) ? width * tjPixelSize[pf] : pitch; - arraySize = (y + height - 1) * actualPitch + (x + width) * tjPixelSize[pf]; - if ((*env)->GetArrayLength(env, dst) * dstElementSize < arraySize) - THROW_ARG("Destination buffer is not large enough"); - - (*env)->GetIntArrayRegion(env, jSrcOffsets, 0, nc, srcOffsetsTmp); - if ((*env)->ExceptionCheck(env)) goto bailout; - for (i = 0; i < 3; i++) - srcOffsets[i] = srcOffsetsTmp[i]; - - (*env)->GetIntArrayRegion(env, jSrcStrides, 0, nc, srcStridesTmp); - if ((*env)->ExceptionCheck(env)) goto bailout; - for (i = 0; i < 3; i++) - srcStrides[i] = srcStridesTmp[i]; - - for (i = 0; i < nc; i++) { - size_t planeSize = tj3YUVPlaneSize(i, width, srcStrides[i], height, - subsamp); - int pw = tj3YUVPlaneWidth(i, width, subsamp); - - if (planeSize == 0 || pw == 0) - THROW_ARG(tj3GetErrorStr(NULL)); - - if (planeSize > (size_t)INT_MAX) - THROW_ARG("Source plane is too large"); - if (srcOffsets[i] < 0) - THROW_ARG("Invalid argument in decodeYUV8()"); - if (srcStrides[i] < 0 && srcOffsets[i] - (int)planeSize + pw < 0) - THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary"); - - BAILIF0(jSrcPlanes[i] = (*env)->GetObjectArrayElement(env, srcobjs, i)); - if ((*env)->GetArrayLength(env, jSrcPlanes[i]) < - srcOffsets[i] + (int)planeSize) - THROW_ARG("Source plane is not large enough"); - } - for (i = 0; i < nc; i++) { - BAILIF0NOEC(srcPlanesTmp[i] = - (*env)->GetPrimitiveArrayCritical(env, jSrcPlanes[i], 0)); - srcPlanes[i] = &srcPlanesTmp[i][srcOffsets[i]]; - } - BAILIF0NOEC(dstBuf = (*env)->GetPrimitiveArrayCritical(env, dst, 0)); - - if (tj3DecodeYUVPlanes8(handle, srcPlanes, srcStrides, - &dstBuf[y * actualPitch + x * tjPixelSize[pf]], - width, pitch, height, pf) == -1) { - SAFE_RELEASE(dst, dstBuf); - for (i = 0; i < nc; i++) - SAFE_RELEASE(jSrcPlanes[i], srcPlanesTmp[i]); - THROW_TJ(); - } - -bailout: - SAFE_RELEASE(dst, dstBuf); - for (i = 0; i < nc; i++) - SAFE_RELEASE(jSrcPlanes[i], srcPlanesTmp[i]); -} - -/* TurboJPEG 3: TJDecompressor::decodeYUV8() byte destination */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV8___3_3B_3I_3I_3BIIIIII - (JNIEnv *env, jobject obj, jobjectArray srcobjs, jintArray jSrcOffsets, - jintArray jSrcStrides, jbyteArray dst, jint x, jint y, jint width, - jint pitch, jint height, jint pf) -{ - TJDecompressor_decodeYUV8(env, obj, srcobjs, jSrcOffsets, jSrcStrides, dst, - 1, x, y, width, pitch, height, pf); -} - -/* TurboJPEG 3: TJDecompressor::decodeYUV8() int destination */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV8___3_3B_3I_3I_3IIIIIII - (JNIEnv *env, jobject obj, jobjectArray srcobjs, jintArray jSrcOffsets, - jintArray jSrcStrides, jintArray dst, jint x, jint y, jint width, - jint stride, jint height, jint pf) -{ - if (pf < 0 || pf >= org_libjpegturbo_turbojpeg_TJ_NUMPF) - THROW_ARG("Invalid argument in decodeYUV8()"); - if (tjPixelSize[pf] != sizeof(jint)) - THROW_ARG("Pixel format must be 32-bit when decoding to an integer buffer."); - - TJDecompressor_decodeYUV8(env, obj, srcobjs, jSrcOffsets, jSrcStrides, dst, - sizeof(jint), x, y, width, stride * sizeof(jint), - height, pf); - -bailout: - return; -} - -/* TurboJPEG 1.2.x: TJTransformer::init() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_init - (JNIEnv *env, jobject obj) -{ - jclass cls; - jfieldID fid; - tjhandle handle; - - if ((handle = tj3Init(TJINIT_TRANSFORM)) == NULL) - THROW(tj3GetErrorStr(NULL), "org/libjpegturbo/turbojpeg/TJException"); - - BAILIF0(cls = (*env)->GetObjectClass(env, obj)); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "handle", "J")); - (*env)->SetLongField(env, obj, fid, (size_t)handle); - -bailout: - return; -} - -typedef struct _JNICustomFilterParams { - JNIEnv *env; - jobject tobj; - jobject cfobj; -} JNICustomFilterParams; - -static int JNICustomFilter(short *coeffs, tjregion arrayRegion, - tjregion planeRegion, int componentIndex, - int transformIndex, tjtransform *transform) -{ - JNICustomFilterParams *params = (JNICustomFilterParams *)transform->data; - JNIEnv *env = params->env; - jobject tobj = params->tobj, cfobj = params->cfobj; - jobject arrayRegionObj, planeRegionObj, bufobj, borobj; - jclass cls; - jmethodID mid; - jfieldID fid; - - BAILIF0(bufobj = (*env)->NewDirectByteBuffer(env, coeffs, - sizeof(short) * arrayRegion.w * arrayRegion.h)); - BAILIF0(cls = (*env)->FindClass(env, "java/nio/ByteOrder")); - BAILIF0(mid = (*env)->GetStaticMethodID(env, cls, "nativeOrder", - "()Ljava/nio/ByteOrder;")); - BAILIF0(borobj = (*env)->CallStaticObjectMethod(env, cls, mid)); - BAILIF0(cls = (*env)->GetObjectClass(env, bufobj)); - BAILIF0(mid = (*env)->GetMethodID(env, cls, "order", - "(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;")); - (*env)->CallObjectMethod(env, bufobj, mid, borobj); - BAILIF0(mid = (*env)->GetMethodID(env, cls, "asShortBuffer", - "()Ljava/nio/ShortBuffer;")); - BAILIF0(bufobj = (*env)->CallObjectMethod(env, bufobj, mid)); - - BAILIF0(cls = (*env)->FindClass(env, "java/awt/Rectangle")); - BAILIF0(arrayRegionObj = (*env)->AllocObject(env, cls)); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "x", "I")); - (*env)->SetIntField(env, arrayRegionObj, fid, arrayRegion.x); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "y", "I")); - (*env)->SetIntField(env, arrayRegionObj, fid, arrayRegion.y); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "width", "I")); - (*env)->SetIntField(env, arrayRegionObj, fid, arrayRegion.w); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "height", "I")); - (*env)->SetIntField(env, arrayRegionObj, fid, arrayRegion.h); - - BAILIF0(planeRegionObj = (*env)->AllocObject(env, cls)); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "x", "I")); - (*env)->SetIntField(env, planeRegionObj, fid, planeRegion.x); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "y", "I")); - (*env)->SetIntField(env, planeRegionObj, fid, planeRegion.y); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "width", "I")); - (*env)->SetIntField(env, planeRegionObj, fid, planeRegion.w); - BAILIF0(fid = (*env)->GetFieldID(env, cls, "height", "I")); - (*env)->SetIntField(env, planeRegionObj, fid, planeRegion.h); - - BAILIF0(cls = (*env)->GetObjectClass(env, cfobj)); - BAILIF0(mid = (*env)->GetMethodID(env, cls, "customFilter", - "(Ljava/nio/ShortBuffer;Ljava/awt/Rectangle;Ljava/awt/Rectangle;IILorg/libjpegturbo/turbojpeg/TJTransform;)V")); - (*env)->CallVoidMethod(env, cfobj, mid, bufobj, arrayRegionObj, - planeRegionObj, componentIndex, transformIndex, tobj); - - return 0; - -bailout: - return -1; -} - -/* TurboJPEG 1.2.x: TJTransformer::transform() */ -JNIEXPORT jintArray JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_transform - (JNIEnv *env, jobject obj, jbyteArray jsrcBuf, jint jpegSize, - jobjectArray dstobjs, jobjectArray tobjs) -{ - tjhandle handle = 0; - unsigned char *jpegBuf = NULL, **dstBufs = NULL; - jsize n = 0; - size_t *dstSizes = NULL; - tjtransform *t = NULL; - jbyteArray *jdstBufs = NULL; - int i, jpegWidth = 0, jpegHeight = 0, jpegSubsamp; - jintArray jdstSizes = 0; - jint *dstSizesi = NULL; - JNICustomFilterParams *params = NULL; - - GET_HANDLE(); - - if ((*env)->GetArrayLength(env, jsrcBuf) < jpegSize) - THROW_ARG("Source buffer is not large enough"); - if ((jpegWidth = tj3Get(handle, TJPARAM_JPEGWIDTH)) == -1) - THROW_ARG("JPEG header has not yet been read"); - if ((jpegHeight = tj3Get(handle, TJPARAM_JPEGHEIGHT)) == -1) - THROW_ARG("JPEG header has not yet been read"); - if ((jpegSubsamp = tj3Get(handle, TJPARAM_SUBSAMP)) == TJSAMP_UNKNOWN) - THROW_ARG("TJPARAM_SUBSAMP must be specified"); - - n = (*env)->GetArrayLength(env, dstobjs); - if (n != (*env)->GetArrayLength(env, tobjs)) - THROW_ARG("Mismatch between size of transforms array and destination buffers array"); - - if ((dstBufs = - (unsigned char **)malloc(sizeof(unsigned char *) * n)) == NULL) - THROW_MEM(); - if ((jdstBufs = (jbyteArray *)malloc(sizeof(jbyteArray) * n)) == NULL) - THROW_MEM(); - if ((dstSizes = (size_t *)malloc(sizeof(size_t) * n)) == NULL) - THROW_MEM(); - if ((t = (tjtransform *)malloc(sizeof(tjtransform) * n)) == NULL) - THROW_MEM(); - if ((params = (JNICustomFilterParams *)malloc(sizeof(JNICustomFilterParams) * - n)) == NULL) - THROW_MEM(); - for (i = 0; i < n; i++) { - dstBufs[i] = NULL; jdstBufs[i] = NULL; dstSizes[i] = 0; - memset(&t[i], 0, sizeof(tjtransform)); - memset(¶ms[i], 0, sizeof(JNICustomFilterParams)); - } - - for (i = 0; i < n; i++) { - jobject tobj, cfobj; - - BAILIF0(tobj = (*env)->GetObjectArrayElement(env, tobjs, i)); - BAILIF0(_cls = (*env)->GetObjectClass(env, tobj)); - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "op", "I")); - t[i].op = (*env)->GetIntField(env, tobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "options", "I")); - t[i].options = (*env)->GetIntField(env, tobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "x", "I")); - t[i].r.x = (*env)->GetIntField(env, tobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "y", "I")); - t[i].r.y = (*env)->GetIntField(env, tobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "width", "I")); - t[i].r.w = (*env)->GetIntField(env, tobj, _fid); - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "height", "I")); - t[i].r.h = (*env)->GetIntField(env, tobj, _fid); - - BAILIF0(_fid = (*env)->GetFieldID(env, _cls, "cf", - "Lorg/libjpegturbo/turbojpeg/TJCustomFilter;")); - cfobj = (*env)->GetObjectField(env, tobj, _fid); - if (cfobj) { - params[i].env = env; - params[i].tobj = tobj; - params[i].cfobj = cfobj; - t[i].customFilter = JNICustomFilter; - t[i].data = (void *)¶ms[i]; - } - } - - if (tj3Set(handle, TJPARAM_NOREALLOC, 1) == -1) - THROW_TJ(); - - for (i = 0; i < n; i++) { - int w = jpegWidth, h = jpegHeight; - - if (t[i].op == TJXOP_TRANSPOSE || t[i].op == TJXOP_TRANSVERSE || - t[i].op == TJXOP_ROT90 || t[i].op == TJXOP_ROT270) { - w = jpegHeight; h = jpegWidth; - } - if (t[i].r.w != 0) w = t[i].r.w; - if (t[i].r.h != 0) h = t[i].r.h; - BAILIF0(jdstBufs[i] = (*env)->GetObjectArrayElement(env, dstobjs, i)); - if ((size_t)(*env)->GetArrayLength(env, jdstBufs[i]) < - tj3JPEGBufSize(w, h, jpegSubsamp)) - THROW_ARG("Destination buffer is not large enough"); - } - BAILIF0NOEC(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, jsrcBuf, 0)); - for (i = 0; i < n; i++) - BAILIF0NOEC(dstBufs[i] = - (*env)->GetPrimitiveArrayCritical(env, jdstBufs[i], 0)); - - if (tj3Transform(handle, jpegBuf, jpegSize, n, dstBufs, dstSizes, t) == -1) { - for (i = 0; i < n; i++) - SAFE_RELEASE(jdstBufs[i], dstBufs[i]); - SAFE_RELEASE(jsrcBuf, jpegBuf); - THROW_TJ(); - } - - for (i = 0; i < n; i++) - SAFE_RELEASE(jdstBufs[i], dstBufs[i]); - SAFE_RELEASE(jsrcBuf, jpegBuf); - - jdstSizes = (*env)->NewIntArray(env, n); - BAILIF0(dstSizesi = (*env)->GetIntArrayElements(env, jdstSizes, 0)); - for (i = 0; i < n; i++) dstSizesi[i] = (int)dstSizes[i]; - -bailout: - if (dstSizesi) (*env)->ReleaseIntArrayElements(env, jdstSizes, dstSizesi, 0); - if (dstBufs) { - for (i = 0; i < n; i++) { - if (dstBufs[i] && jdstBufs && jdstBufs[i]) - (*env)->ReleasePrimitiveArrayCritical(env, jdstBufs[i], dstBufs[i], 0); - } - free(dstBufs); - } - SAFE_RELEASE(jsrcBuf, jpegBuf); - free(jdstBufs); - free(dstSizes); - free(t); - return jdstSizes; -} - -/* TurboJPEG 1.2.x: TJDecompressor::destroy() */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_destroy - (JNIEnv *env, jobject obj) -{ - Java_org_libjpegturbo_turbojpeg_TJCompressor_destroy(env, obj); -} - -/* Private image I/O routines (used only by TJBench) */ -JNIEXPORT jobject JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_loadImage - (JNIEnv *env, jobject obj, jint precision, jstring jfilename, - jintArray jwidth, jint align, jintArray jheight, jintArray jpixelFormat) -{ - tjhandle handle = NULL; - void *dstBuf = NULL, *jdstPtr; - int width, *warr, height, *harr, pixelFormat, *pfarr, n; - const char *filename = NULL; - jboolean isCopy; - jobject jdstBuf = NULL; - - GET_HANDLE(); - - if ((precision != 8 && precision != 12 && precision != 16) || - jfilename == NULL || jwidth == NULL || - (*env)->GetArrayLength(env, jwidth) < 1 || jheight == NULL || - (*env)->GetArrayLength(env, jheight) < 1 || jpixelFormat == NULL || - (*env)->GetArrayLength(env, jpixelFormat) < 1) - THROW_ARG("Invalid argument in loadImage()"); - - BAILIF0NOEC(warr = (*env)->GetPrimitiveArrayCritical(env, jwidth, 0)); - width = warr[0]; - (*env)->ReleasePrimitiveArrayCritical(env, jwidth, warr, 0); - BAILIF0NOEC(harr = (*env)->GetPrimitiveArrayCritical(env, jheight, 0)); - height = harr[0]; - (*env)->ReleasePrimitiveArrayCritical(env, jheight, harr, 0); - BAILIF0NOEC(pfarr = (*env)->GetPrimitiveArrayCritical(env, jpixelFormat, 0)); - pixelFormat = pfarr[0]; - (*env)->ReleasePrimitiveArrayCritical(env, jpixelFormat, pfarr, 0); - BAILIF0(filename = (*env)->GetStringUTFChars(env, jfilename, &isCopy)); - - if (precision == 8) { - if ((dstBuf = tj3LoadImage8(handle, filename, &width, align, &height, - &pixelFormat)) == NULL) - THROW_TJ(); - } else if (precision == 12) { - if ((dstBuf = tj3LoadImage12(handle, filename, &width, align, &height, - &pixelFormat)) == NULL) - THROW_TJ(); - } else { - if ((dstBuf = tj3LoadImage16(handle, filename, &width, align, &height, - &pixelFormat)) == NULL) - THROW_TJ(); - } - - (*env)->ReleaseStringUTFChars(env, jfilename, filename); - filename = NULL; - - if ((unsigned long long)width * (unsigned long long)height * - (unsigned long long)tjPixelSize[pixelFormat] > - (unsigned long long)((unsigned int)-1)) - THROW_ARG("Image is too large"); - - BAILIF0NOEC(warr = (*env)->GetPrimitiveArrayCritical(env, jwidth, 0)); - warr[0] = width; - (*env)->ReleasePrimitiveArrayCritical(env, jwidth, warr, 0); - BAILIF0NOEC(harr = (*env)->GetPrimitiveArrayCritical(env, jheight, 0)); - harr[0] = height; - (*env)->ReleasePrimitiveArrayCritical(env, jheight, harr, 0); - BAILIF0NOEC(pfarr = (*env)->GetPrimitiveArrayCritical(env, jpixelFormat, 0)); - pfarr[0] = pixelFormat; - (*env)->ReleasePrimitiveArrayCritical(env, jpixelFormat, pfarr, 0); - - n = width * height * tjPixelSize[pixelFormat]; - if (precision == 8) - jdstBuf = (*env)->NewByteArray(env, n); - else - jdstBuf = (*env)->NewShortArray(env, n); - BAILIF0NOEC(jdstPtr = (*env)->GetPrimitiveArrayCritical(env, jdstBuf, 0)); - memcpy(jdstPtr, dstBuf, n * (precision > 8 ? 2 : 1)); - (*env)->ReleasePrimitiveArrayCritical(env, jdstBuf, jdstPtr, 0); - -bailout: - if (filename) (*env)->ReleaseStringUTFChars(env, jfilename, filename); - tj3Free(dstBuf); - return jdstBuf; -} - - -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_saveImage - (JNIEnv *env, jobject obj, jint precision, jstring jfilename, - jobject jsrcBuf, jint width, jint pitch, jint height, jint pixelFormat) -{ - tjhandle handle = NULL; - void *srcBuf = NULL, *jsrcPtr; - const char *filename = NULL; - int n; - jboolean isCopy; - - GET_HANDLE(); - - if ((precision != 8 && precision != 12 && precision != 16) || - jfilename == NULL || jsrcBuf == NULL || width < 1 || height < 1 || - pixelFormat < 0 || pixelFormat >= TJ_NUMPF) - THROW_ARG("Invalid argument in saveImage()"); - - if ((unsigned long long)width * (unsigned long long)height * - (unsigned long long)tjPixelSize[pixelFormat] > - (unsigned long long)((unsigned int)-1)) - THROW_ARG("Image is too large"); - n = width * height * tjPixelSize[pixelFormat]; - if ((*env)->GetArrayLength(env, jsrcBuf) < n) - THROW_ARG("Source buffer is not large enough"); - - if ((srcBuf = malloc(n * (precision > 8 ? 2 : 1))) == NULL) - THROW_MEM(); - - BAILIF0NOEC(jsrcPtr = (*env)->GetPrimitiveArrayCritical(env, jsrcBuf, 0)); - memcpy(srcBuf, jsrcPtr, n * (precision > 8 ? 2 : 1)); - (*env)->ReleasePrimitiveArrayCritical(env, jsrcBuf, jsrcPtr, 0); - BAILIF0(filename = (*env)->GetStringUTFChars(env, jfilename, &isCopy)); - - if (precision == 8) { - if (tj3SaveImage8(handle, filename, srcBuf, width, pitch, height, - pixelFormat) == -1) - THROW_TJ(); - } else if (precision == 12) { - if (tj3SaveImage12(handle, filename, srcBuf, width, pitch, height, - pixelFormat) == -1) - THROW_TJ(); - } else { - if (tj3SaveImage16(handle, filename, srcBuf, width, pitch, height, - pixelFormat) == -1) - THROW_TJ(); - } - -bailout: - if (filename) (*env)->ReleaseStringUTFChars(env, jfilename, filename); - free(srcBuf); -} diff --git a/3rdparty/libjpeg-turbo/src/turbojpeg-mapfile b/3rdparty/libjpeg-turbo/src/turbojpeg-mapfile deleted file mode 100644 index 6aab87132a..0000000000 --- a/3rdparty/libjpeg-turbo/src/turbojpeg-mapfile +++ /dev/null @@ -1,108 +0,0 @@ -TURBOJPEG_1.0 -{ - global: - TJBUFSIZE; - tjCompress; - tjDecompress; - tjDecompressHeader; - tjDestroy; - tjGetErrorStr; - tjInitCompress; - tjInitDecompress; - local: - *; -}; - -TURBOJPEG_1.1 -{ - global: - TJBUFSIZEYUV; - tjDecompressHeader2; - tjDecompressToYUV; - tjEncodeYUV; -} TURBOJPEG_1.0; - -TURBOJPEG_1.2 -{ - global: - tjAlloc; - tjBufSize; - tjBufSizeYUV; - tjCompress2; - tjDecompress2; - tjEncodeYUV2; - tjFree; - tjGetScalingFactors; - tjInitTransform; - tjTransform; -} TURBOJPEG_1.1; - -TURBOJPEG_1.4 -{ - global: - tjBufSizeYUV2; - tjCompressFromYUV; - tjCompressFromYUVPlanes; - tjDecodeYUV; - tjDecodeYUVPlanes; - tjDecompressHeader3; - tjDecompressToYUV2; - tjDecompressToYUVPlanes; - tjEncodeYUV3; - tjEncodeYUVPlanes; - tjPlaneHeight; - tjPlaneSizeYUV; - tjPlaneWidth; -} TURBOJPEG_1.2; - -TURBOJPEG_2.0 -{ - global: - tjGetErrorCode; - tjGetErrorStr2; - tjLoadImage; - tjSaveImage; -} TURBOJPEG_1.4; - -TURBOJPEG_3 -{ - global: - tj3Alloc; - tj3Compress8; - tj3Compress12; - tj3Compress16; - tj3CompressFromYUV8; - tj3CompressFromYUVPlanes8; - tj3DecodeYUV8; - tj3DecodeYUVPlanes8; - tj3Decompress8; - tj3Decompress12; - tj3Decompress16; - tj3DecompressHeader; - tj3DecompressToYUV8; - tj3DecompressToYUVPlanes8; - tj3Destroy; - tj3EncodeYUV8; - tj3EncodeYUVPlanes8; - tj3Free; - tj3Get; - tj3GetErrorCode; - tj3GetErrorStr; - tj3GetScalingFactors; - tj3Init; - tj3JPEGBufSize; - tj3LoadImage8; - tj3LoadImage12; - tj3LoadImage16; - tj3SaveImage8; - tj3SaveImage12; - tj3SaveImage16; - tj3Set; - tj3SetCroppingRegion; - tj3SetScalingFactor; - tj3Transform; - tj3YUVBufSize; - tj3YUVPlaneHeight; - tj3YUVPlaneSize; - tj3YUVPlaneWidth; -} TURBOJPEG_2.0; diff --git a/3rdparty/libjpeg-turbo/src/turbojpeg-mapfile.jni b/3rdparty/libjpeg-turbo/src/turbojpeg-mapfile.jni deleted file mode 100644 index 31be750858..0000000000 --- a/3rdparty/libjpeg-turbo/src/turbojpeg-mapfile.jni +++ /dev/null @@ -1,142 +0,0 @@ -TURBOJPEG_1.0 -{ - global: - TJBUFSIZE; - tjCompress; - tjDecompress; - tjDecompressHeader; - tjDestroy; - tjGetErrorStr; - tjInitCompress; - tjInitDecompress; - local: - *; -}; - -TURBOJPEG_1.1 -{ - global: - TJBUFSIZEYUV; - tjDecompressHeader2; - tjDecompressToYUV; - tjEncodeYUV; -} TURBOJPEG_1.0; - -TURBOJPEG_1.2 -{ - global: - tjAlloc; - tjBufSize; - tjBufSizeYUV; - tjCompress2; - tjDecompress2; - tjEncodeYUV2; - tjFree; - tjGetScalingFactors; - tjInitTransform; - tjTransform; - Java_org_libjpegturbo_turbojpeg_TJ_bufSize; - Java_org_libjpegturbo_turbojpeg_TJ_getScalingFactors; - Java_org_libjpegturbo_turbojpeg_TJCompressor_init; - Java_org_libjpegturbo_turbojpeg_TJCompressor_destroy; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_init; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressHeader; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_destroy; - Java_org_libjpegturbo_turbojpeg_TJTransformer_init; - Java_org_libjpegturbo_turbojpeg_TJTransformer_transform; -} TURBOJPEG_1.1; - -TURBOJPEG_1.4 -{ - global: - tjBufSizeYUV2; - tjCompressFromYUV; - tjCompressFromYUVPlanes; - tjDecodeYUV; - tjDecodeYUVPlanes; - tjDecompressHeader3; - tjDecompressToYUV2; - tjDecompressToYUVPlanes; - tjEncodeYUV3; - tjEncodeYUVPlanes; - tjPlaneHeight; - tjPlaneSizeYUV; - tjPlaneWidth; - Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII; - Java_org_libjpegturbo_turbojpeg_TJ_planeHeight__III; - Java_org_libjpegturbo_turbojpeg_TJ_planeSizeYUV__IIIII; - Java_org_libjpegturbo_turbojpeg_TJ_planeWidth__III; -} TURBOJPEG_1.2; - -TURBOJPEG_2.0 -{ - global: - tjGetErrorCode; - tjGetErrorStr2; - tjLoadImage; - tjSaveImage; -} TURBOJPEG_1.4; - -TURBOJPEG_3 -{ - global: - tj3Alloc; - tj3Compress8; - tj3Compress12; - tj3Compress16; - tj3CompressFromYUV8; - tj3CompressFromYUVPlanes8; - tj3DecodeYUV8; - tj3DecodeYUVPlanes8; - tj3Decompress8; - tj3Decompress12; - tj3Decompress16; - tj3DecompressHeader; - tj3DecompressToYUV8; - tj3DecompressToYUVPlanes8; - tj3Destroy; - tj3EncodeYUV8; - tj3EncodeYUVPlanes8; - tj3Free; - tj3Get; - tj3GetErrorCode; - tj3GetErrorStr; - tj3GetScalingFactors; - tj3Init; - tj3JPEGBufSize; - tj3LoadImage8; - tj3LoadImage12; - tj3LoadImage16; - tj3SaveImage8; - tj3SaveImage12; - tj3SaveImage16; - tj3Set; - tj3SetCroppingRegion; - tj3SetScalingFactor; - tj3Transform; - tj3YUVBufSize; - tj3YUVPlaneHeight; - tj3YUVPlaneSize; - tj3YUVPlaneWidth; - Java_org_libjpegturbo_turbojpeg_TJCompressor_compress8___3BIIIIII_3B; - Java_org_libjpegturbo_turbojpeg_TJCompressor_compress8___3IIIIIII_3B; - Java_org_libjpegturbo_turbojpeg_TJCompressor_compress12; - Java_org_libjpegturbo_turbojpeg_TJCompressor_compress16; - Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFromYUV8; - Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV8___3BIIIIII_3_3B_3I_3I; - Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV8___3IIIIIII_3_3B_3I_3I; - Java_org_libjpegturbo_turbojpeg_TJCompressor_get; - Java_org_libjpegturbo_turbojpeg_TJCompressor_loadImage; - Java_org_libjpegturbo_turbojpeg_TJCompressor_set; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV8___3_3B_3I_3I_3BIIIIII; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV8___3_3B_3I_3I_3IIIIIII; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress8___3BI_3BIIII; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress8___3BI_3IIIII; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress12; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress16; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV8; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_get; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_saveImage; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_set; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_setCroppingRegion; -} TURBOJPEG_2.0; diff --git a/3rdparty/libjpeg-turbo/src/turbojpeg-mp.c b/3rdparty/libjpeg-turbo/src/turbojpeg-mp.c deleted file mode 100644 index d4b3c74c39..0000000000 --- a/3rdparty/libjpeg-turbo/src/turbojpeg-mp.c +++ /dev/null @@ -1,541 +0,0 @@ -/* - * Copyright (C)2009-2024 D. R. Commander. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the libjpeg-turbo Project nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* TurboJPEG API functions that must be compiled for multiple data - precisions */ - -#if BITS_IN_JSAMPLE == 8 -#define _JSAMPLE JSAMPLE -#define _JSAMPROW JSAMPROW -#define _buffer buffer -#define _jinit_read_ppm jinit_read_ppm -#define _jinit_write_ppm jinit_write_ppm -#define _jpeg_crop_scanline jpeg_crop_scanline -#define _jpeg_read_scanlines jpeg_read_scanlines -#define _jpeg_skip_scanlines jpeg_skip_scanlines -#define _jpeg_write_scanlines jpeg_write_scanlines -#elif BITS_IN_JSAMPLE == 12 -#define _JSAMPLE J12SAMPLE -#define _JSAMPROW J12SAMPROW -#define _buffer buffer12 -#define _jinit_read_ppm j12init_read_ppm -#define _jinit_write_ppm j12init_write_ppm -#define _jpeg_crop_scanline jpeg12_crop_scanline -#define _jpeg_read_scanlines jpeg12_read_scanlines -#define _jpeg_skip_scanlines jpeg12_skip_scanlines -#define _jpeg_write_scanlines jpeg12_write_scanlines -#elif BITS_IN_JSAMPLE == 16 -#define _JSAMPLE J16SAMPLE -#define _JSAMPROW J16SAMPROW -#define _buffer buffer16 -#define _jinit_read_ppm j16init_read_ppm -#define _jinit_write_ppm j16init_write_ppm -#define _jpeg_read_scanlines jpeg16_read_scanlines -#define _jpeg_write_scanlines jpeg16_write_scanlines -#endif - -#define _GET_NAME(name, suffix) name##suffix -#define GET_NAME(name, suffix) _GET_NAME(name, suffix) -#define _GET_STRING(name, suffix) #name #suffix -#define GET_STRING(name, suffix) _GET_STRING(name, suffix) - - -/******************************** Compressor *********************************/ - -/* TurboJPEG 3+ */ -DLLEXPORT int GET_NAME(tj3Compress, BITS_IN_JSAMPLE) - (tjhandle handle, const _JSAMPLE *srcBuf, int width, int pitch, int height, - int pixelFormat, unsigned char **jpegBuf, size_t *jpegSize) -{ - static const char FUNCTION_NAME[] = GET_STRING(tj3Compress, BITS_IN_JSAMPLE); - int i, retval = 0; - boolean alloc = TRUE; - _JSAMPROW *row_pointer = NULL; - - GET_CINSTANCE(handle) - if ((this->init & COMPRESS) == 0) - THROW("Instance has not been initialized for compression"); - - if (srcBuf == NULL || width <= 0 || pitch < 0 || height <= 0 || - pixelFormat < 0 || pixelFormat >= TJ_NUMPF || jpegBuf == NULL || - jpegSize == NULL) - THROW("Invalid argument"); - - if (!this->lossless && this->quality == -1) - THROW("TJPARAM_QUALITY must be specified"); - if (!this->lossless && this->subsamp == TJSAMP_UNKNOWN) - THROW("TJPARAM_SUBSAMP must be specified"); - - if (pitch == 0) pitch = width * tjPixelSize[pixelFormat]; - - if ((row_pointer = (_JSAMPROW *)malloc(sizeof(_JSAMPROW) * height)) == NULL) - THROW("Memory allocation failure"); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - cinfo->image_width = width; - cinfo->image_height = height; - cinfo->data_precision = BITS_IN_JSAMPLE; - - setCompDefaults(this, pixelFormat); - if (this->noRealloc) { - alloc = FALSE; - *jpegSize = tj3JPEGBufSize(width, height, this->subsamp); - } - jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc); - - jpeg_start_compress(cinfo, TRUE); - for (i = 0; i < height; i++) { - if (this->bottomUp) - row_pointer[i] = (_JSAMPROW)&srcBuf[(height - i - 1) * (size_t)pitch]; - else - row_pointer[i] = (_JSAMPROW)&srcBuf[i * (size_t)pitch]; - } - while (cinfo->next_scanline < cinfo->image_height) - _jpeg_write_scanlines(cinfo, &row_pointer[cinfo->next_scanline], - cinfo->image_height - cinfo->next_scanline); - jpeg_finish_compress(cinfo); - -bailout: - if (cinfo->global_state > CSTATE_START && alloc) - (*cinfo->dest->term_destination) (cinfo); - if (cinfo->global_state > CSTATE_START || retval == -1) - jpeg_abort_compress(cinfo); - free(row_pointer); - if (this->jerr.warning) retval = -1; - return retval; -} - - -/******************************* Decompressor ********************************/ - -/* TurboJPEG 3+ */ -DLLEXPORT int GET_NAME(tj3Decompress, BITS_IN_JSAMPLE) - (tjhandle handle, const unsigned char *jpegBuf, size_t jpegSize, - _JSAMPLE *dstBuf, int pitch, int pixelFormat) -{ - static const char FUNCTION_NAME[] = - GET_STRING(tj3Decompress, BITS_IN_JSAMPLE); - _JSAMPROW *row_pointer = NULL; - int croppedHeight, i, retval = 0; -#if BITS_IN_JSAMPLE != 16 - int scaledWidth; -#endif - struct my_progress_mgr progress; - - GET_DINSTANCE(handle); - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - if (jpegBuf == NULL || jpegSize <= 0 || dstBuf == NULL || pitch < 0 || - pixelFormat < 0 || pixelFormat >= TJ_NUMPF) - THROW("Invalid argument"); - - if (this->scanLimit) { - memset(&progress, 0, sizeof(struct my_progress_mgr)); - progress.pub.progress_monitor = my_progress_monitor; - progress.this = this; - dinfo->progress = &progress.pub; - } else - dinfo->progress = NULL; - - dinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - if (dinfo->global_state <= DSTATE_INHEADER) { - jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - jpeg_read_header(dinfo, TRUE); - } - setDecompParameters(this); - if (this->maxPixels && - (unsigned long long)this->jpegWidth * this->jpegHeight > - (unsigned long long)this->maxPixels) - THROW("Image is too large"); - this->dinfo.out_color_space = pf2cs[pixelFormat]; -#if BITS_IN_JSAMPLE != 16 - scaledWidth = TJSCALED(dinfo->image_width, this->scalingFactor); -#endif - dinfo->do_fancy_upsampling = !this->fastUpsample; - this->dinfo.dct_method = this->fastDCT ? JDCT_FASTEST : JDCT_ISLOW; - - dinfo->scale_num = this->scalingFactor.num; - dinfo->scale_denom = this->scalingFactor.denom; - - jpeg_start_decompress(dinfo); - -#if BITS_IN_JSAMPLE != 16 - if (this->croppingRegion.x != 0 || - (this->croppingRegion.w != 0 && this->croppingRegion.w != scaledWidth)) { - JDIMENSION crop_x = this->croppingRegion.x; - JDIMENSION crop_w = this->croppingRegion.w; - - _jpeg_crop_scanline(dinfo, &crop_x, &crop_w); - if ((int)crop_x != this->croppingRegion.x) - THROWI("Unexplained mismatch between specified (%d) and\n" - "actual (%d) cropping region left boundary", - this->croppingRegion.x, (int)crop_x); - if ((int)crop_w != this->croppingRegion.w) - THROWI("Unexplained mismatch between specified (%d) and\n" - "actual (%d) cropping region width", - this->croppingRegion.w, (int)crop_w); - } -#endif - - if (pitch == 0) pitch = dinfo->output_width * tjPixelSize[pixelFormat]; - - croppedHeight = dinfo->output_height; -#if BITS_IN_JSAMPLE != 16 - if (this->croppingRegion.y != 0 || this->croppingRegion.h != 0) - croppedHeight = this->croppingRegion.h; -#endif - if ((row_pointer = - (_JSAMPROW *)malloc(sizeof(_JSAMPROW) * croppedHeight)) == NULL) - THROW("Memory allocation failure"); - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - for (i = 0; i < (int)croppedHeight; i++) { - if (this->bottomUp) - row_pointer[i] = &dstBuf[(croppedHeight - i - 1) * (size_t)pitch]; - else - row_pointer[i] = &dstBuf[i * (size_t)pitch]; - } - -#if BITS_IN_JSAMPLE != 16 - if (this->croppingRegion.y != 0 || this->croppingRegion.h != 0) { - if (this->croppingRegion.y != 0) { - JDIMENSION lines = _jpeg_skip_scanlines(dinfo, this->croppingRegion.y); - - if ((int)lines != this->croppingRegion.y) - THROWI("Unexplained mismatch between specified (%d) and\n" - "actual (%d) cropping region upper boundary", - this->croppingRegion.y, (int)lines); - } - while ((int)dinfo->output_scanline < - this->croppingRegion.y + this->croppingRegion.h) - _jpeg_read_scanlines(dinfo, &row_pointer[dinfo->output_scanline - - this->croppingRegion.y], - this->croppingRegion.y + this->croppingRegion.h - - dinfo->output_scanline); - if (this->croppingRegion.y + this->croppingRegion.h != - (int)dinfo->output_height) { - JDIMENSION lines = _jpeg_skip_scanlines(dinfo, dinfo->output_height - - this->croppingRegion.y - - this->croppingRegion.h); - - if (lines != dinfo->output_height - this->croppingRegion.y - - this->croppingRegion.h) - THROWI("Unexplained mismatch between specified (%d) and\n" - "actual (%d) cropping region lower boundary", - this->croppingRegion.y + this->croppingRegion.h, - (int)(dinfo->output_height - lines)); - } - } else -#endif - { - while (dinfo->output_scanline < dinfo->output_height) - _jpeg_read_scanlines(dinfo, &row_pointer[dinfo->output_scanline], - dinfo->output_height - dinfo->output_scanline); - } - jpeg_finish_decompress(dinfo); - -bailout: - if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo); - free(row_pointer); - if (this->jerr.warning) retval = -1; - return retval; -} - - -/*************************** Packed-Pixel Image I/O **************************/ - -/* TurboJPEG 3+ */ -DLLEXPORT _JSAMPLE *GET_NAME(tj3LoadImage, BITS_IN_JSAMPLE) - (tjhandle handle, const char *filename, int *width, int align, int *height, - int *pixelFormat) -{ - static const char FUNCTION_NAME[] = - GET_STRING(tj3LoadImage, BITS_IN_JSAMPLE); - -#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) - - int retval = 0, tempc; - size_t pitch; - tjhandle handle2 = NULL; - tjinstance *this2; - j_compress_ptr cinfo = NULL; - cjpeg_source_ptr src; - _JSAMPLE *dstBuf = NULL; - FILE *file = NULL; - boolean invert; - - GET_TJINSTANCE(handle, NULL) - - if (!filename || !width || align < 1 || !height || !pixelFormat || - *pixelFormat < TJPF_UNKNOWN || *pixelFormat >= TJ_NUMPF) - THROW("Invalid argument"); - if ((align & (align - 1)) != 0) - THROW("Alignment must be a power of 2"); - - /* The instance handle passed to this function is used only for parameter - retrieval. Create a new temporary instance to avoid interfering with the - libjpeg state of the primary instance. */ - if ((handle2 = tj3Init(TJINIT_COMPRESS)) == NULL) return NULL; - this2 = (tjinstance *)handle2; - cinfo = &this2->cinfo; - -#ifdef _MSC_VER - if (fopen_s(&file, filename, "rb") || file == NULL) -#else - if ((file = fopen(filename, "rb")) == NULL) -#endif - THROW_UNIX("Cannot open input file"); - - if ((tempc = getc(file)) < 0 || ungetc(tempc, file) == EOF) - THROW_UNIX("Could not read input file") - else if (tempc == EOF) - THROW("Input file contains no data"); - - if (setjmp(this2->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - cinfo->data_precision = BITS_IN_JSAMPLE; - if (*pixelFormat == TJPF_UNKNOWN) cinfo->in_color_space = JCS_UNKNOWN; - else cinfo->in_color_space = pf2cs[*pixelFormat]; - if (tempc == 'B') { - if ((src = jinit_read_bmp(cinfo, FALSE)) == NULL) - THROW("Could not initialize bitmap loader"); - invert = !this->bottomUp; - } else if (tempc == 'P') { - if ((src = _jinit_read_ppm(cinfo)) == NULL) - THROW("Could not initialize PPM loader"); - invert = this->bottomUp; - } else - THROW("Unsupported file type"); - - cinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; - - src->input_file = file; - /* Refuse to load images larger than the specified size. */ - src->max_pixels = this->maxPixels; - (*src->start_input) (cinfo, src); - if (tempc == 'B') { - if (cinfo->X_density && cinfo->Y_density) { - this->xDensity = cinfo->X_density; - this->yDensity = cinfo->Y_density; - this->densityUnits = cinfo->density_unit; - } - } - (*cinfo->mem->realize_virt_arrays) ((j_common_ptr)cinfo); - - *width = cinfo->image_width; *height = cinfo->image_height; - *pixelFormat = cs2pf[cinfo->in_color_space]; - - pitch = PAD((*width) * tjPixelSize[*pixelFormat], align); - if ( -#if ULLONG_MAX > SIZE_MAX - (unsigned long long)pitch * (unsigned long long)(*height) > - (unsigned long long)((size_t)-1) || -#endif - (dstBuf = (_JSAMPLE *)malloc(pitch * (*height) * - sizeof(_JSAMPLE))) == NULL) - THROW("Memory allocation failure"); - - if (setjmp(this2->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - while (cinfo->next_scanline < cinfo->image_height) { - int i, nlines = (*src->get_pixel_rows) (cinfo, src); - - for (i = 0; i < nlines; i++) { - _JSAMPLE *dstptr; - int row; - - row = cinfo->next_scanline + i; - if (invert) dstptr = &dstBuf[((*height) - row - 1) * pitch]; - else dstptr = &dstBuf[row * pitch]; - memcpy(dstptr, src->_buffer[i], - (*width) * tjPixelSize[*pixelFormat] * sizeof(_JSAMPLE)); - } - cinfo->next_scanline += nlines; - } - - (*src->finish_input) (cinfo, src); - -bailout: - tj3Destroy(handle2); - if (file) fclose(file); - if (retval < 0) { free(dstBuf); dstBuf = NULL; } - return dstBuf; - -#else /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */ - - static const char ERROR_MSG[] = - "16-bit data precision requires lossless JPEG,\n" - "which was disabled at build time."; - _JSAMPLE *retval = NULL; - - GET_TJINSTANCE(handle, NULL) - SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s(): %s", FUNCTION_NAME, - ERROR_MSG); - this->isInstanceError = TRUE; THROWG(ERROR_MSG, NULL) - -bailout: - return retval; - -#endif -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int GET_NAME(tj3SaveImage, BITS_IN_JSAMPLE) - (tjhandle handle, const char *filename, const _JSAMPLE *buffer, int width, - int pitch, int height, int pixelFormat) -{ - static const char FUNCTION_NAME[] = - GET_STRING(tj3SaveImage, BITS_IN_JSAMPLE); - int retval = 0; - -#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) - - tjhandle handle2 = NULL; - tjinstance *this2; - j_decompress_ptr dinfo = NULL; - djpeg_dest_ptr dst; - FILE *file = NULL; - char *ptr = NULL; - boolean invert; - - GET_TJINSTANCE(handle, -1) - - if (!filename || !buffer || width < 1 || pitch < 0 || height < 1 || - pixelFormat < 0 || pixelFormat >= TJ_NUMPF) - THROW("Invalid argument"); - - /* The instance handle passed to this function is used only for parameter - retrieval. Create a new temporary instance to avoid interfering with the - libjpeg state of the primary instance. */ - if ((handle2 = tj3Init(TJINIT_DECOMPRESS)) == NULL) - return -1; - this2 = (tjinstance *)handle2; - dinfo = &this2->dinfo; - -#ifdef _MSC_VER - if (fopen_s(&file, filename, "wb") || file == NULL) -#else - if ((file = fopen(filename, "wb")) == NULL) -#endif - THROW_UNIX("Cannot open output file"); - - if (setjmp(this2->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - this2->dinfo.out_color_space = pf2cs[pixelFormat]; - dinfo->image_width = width; dinfo->image_height = height; - dinfo->global_state = DSTATE_READY; - dinfo->scale_num = dinfo->scale_denom = 1; - dinfo->data_precision = BITS_IN_JSAMPLE; - - ptr = strrchr(filename, '.'); - if (ptr && !strcasecmp(ptr, ".bmp")) { - if ((dst = jinit_write_bmp(dinfo, FALSE, FALSE)) == NULL) - THROW("Could not initialize bitmap writer"); - invert = !this->bottomUp; - dinfo->X_density = (UINT16)this->xDensity; - dinfo->Y_density = (UINT16)this->yDensity; - dinfo->density_unit = (UINT8)this->densityUnits; - } else { - if ((dst = _jinit_write_ppm(dinfo)) == NULL) - THROW("Could not initialize PPM writer"); - invert = this->bottomUp; - } - - dinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; - - dst->output_file = file; - (*dst->start_output) (dinfo, dst); - (*dinfo->mem->realize_virt_arrays) ((j_common_ptr)dinfo); - - if (pitch == 0) pitch = width * tjPixelSize[pixelFormat]; - - while (dinfo->output_scanline < dinfo->output_height) { - _JSAMPLE *rowptr; - - if (invert) - rowptr = - (_JSAMPLE *)&buffer[(height - dinfo->output_scanline - 1) * pitch]; - else - rowptr = (_JSAMPLE *)&buffer[dinfo->output_scanline * pitch]; - memcpy(dst->_buffer[0], rowptr, - width * tjPixelSize[pixelFormat] * sizeof(_JSAMPLE)); - (*dst->put_pixel_rows) (dinfo, dst, 1); - dinfo->output_scanline++; - } - - (*dst->finish_output) (dinfo, dst); - -bailout: - tj3Destroy(handle2); - if (file) fclose(file); - return retval; - -#else /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */ - - GET_TJINSTANCE(handle, -1) - THROW("16-bit data precision requires lossless JPEG,\n" - "which was disabled at build time.") -bailout: - return retval; - -#endif -} - - -#undef _JSAMPLE -#undef _JSAMPROW -#undef _buffer -#undef _jinit_read_ppm -#undef _jinit_write_ppm -#undef _jpeg_crop_scanline -#undef _jpeg_read_scanlines -#undef _jpeg_skip_scanlines -#undef _jpeg_write_scanlines diff --git a/3rdparty/libjpeg-turbo/src/turbojpeg.c b/3rdparty/libjpeg-turbo/src/turbojpeg.c deleted file mode 100644 index 3c936160df..0000000000 --- a/3rdparty/libjpeg-turbo/src/turbojpeg.c +++ /dev/null @@ -1,2921 +0,0 @@ -/* - * Copyright (C)2009-2024 D. R. Commander. All Rights Reserved. - * Copyright (C)2021 Alex Richardson. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the libjpeg-turbo Project nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* TurboJPEG/LJT: this implements the TurboJPEG API using libjpeg or - libjpeg-turbo */ - -#include -#include -#if !defined(_MSC_VER) || _MSC_VER > 1600 -#include -#endif -#include -#define JPEG_INTERNALS -#include -#include -#include -#include -#include "./turbojpeg.h" -#include "./tjutil.h" -#include "transupp.h" -#include "./jpegapicomp.h" -#include "./cdjpeg.h" - -extern void jpeg_mem_dest_tj(j_compress_ptr, unsigned char **, size_t *, - boolean); -extern void jpeg_mem_src_tj(j_decompress_ptr, const unsigned char *, size_t); - -#define PAD(v, p) ((v + (p) - 1) & (~((p) - 1))) -#define IS_POW2(x) (((x) & (x - 1)) == 0) - - -/* Error handling (based on example in example.c) */ - -static THREAD_LOCAL char errStr[JMSG_LENGTH_MAX] = "No error"; - -struct my_error_mgr { - struct jpeg_error_mgr pub; - jmp_buf setjmp_buffer; - void (*emit_message) (j_common_ptr, int); - boolean warning, stopOnWarning; -}; -typedef struct my_error_mgr *my_error_ptr; - -#define JMESSAGE(code, string) string, -static const char *turbojpeg_message_table[] = { -#include "cderror.h" - NULL -}; - -static void my_error_exit(j_common_ptr cinfo) -{ - my_error_ptr myerr = (my_error_ptr)cinfo->err; - - (*cinfo->err->output_message) (cinfo); - longjmp(myerr->setjmp_buffer, 1); -} - -/* Based on output_message() in jerror.c */ - -static void my_output_message(j_common_ptr cinfo) -{ - (*cinfo->err->format_message) (cinfo, errStr); -} - -static void my_emit_message(j_common_ptr cinfo, int msg_level) -{ - my_error_ptr myerr = (my_error_ptr)cinfo->err; - - myerr->emit_message(cinfo, msg_level); - if (msg_level < 0) { - myerr->warning = TRUE; - if (myerr->stopOnWarning) longjmp(myerr->setjmp_buffer, 1); - } -} - - -/********************** Global structures, macros, etc. **********************/ - -enum { COMPRESS = 1, DECOMPRESS = 2 }; - -typedef struct _tjinstance { - struct jpeg_compress_struct cinfo; - struct jpeg_decompress_struct dinfo; - struct my_error_mgr jerr; - int init; - char errStr[JMSG_LENGTH_MAX]; - boolean isInstanceError; - /* Parameters */ - boolean bottomUp; - boolean noRealloc; - int quality; - int subsamp; - int jpegWidth; - int jpegHeight; - int precision; - int colorspace; - boolean fastUpsample; - boolean fastDCT; - boolean optimize; - boolean progressive; - int scanLimit; - boolean arithmetic; - boolean lossless; - int losslessPSV; - int losslessPt; - int restartIntervalBlocks; - int restartIntervalRows; - int xDensity; - int yDensity; - int densityUnits; - tjscalingfactor scalingFactor; - tjregion croppingRegion; - int maxMemory; - int maxPixels; -} tjinstance; - -static tjhandle _tjInitCompress(tjinstance *this); -static tjhandle _tjInitDecompress(tjinstance *this); - -struct my_progress_mgr { - struct jpeg_progress_mgr pub; - tjinstance *this; -}; -typedef struct my_progress_mgr *my_progress_ptr; - -static void my_progress_monitor(j_common_ptr dinfo) -{ - my_error_ptr myerr = (my_error_ptr)dinfo->err; - my_progress_ptr myprog = (my_progress_ptr)dinfo->progress; - - if (dinfo->is_decompressor) { - int scan_no = ((j_decompress_ptr)dinfo)->input_scan_number; - - if (scan_no > myprog->this->scanLimit) { - SNPRINTF(myprog->this->errStr, JMSG_LENGTH_MAX, - "Progressive JPEG image has more than %d scans", - myprog->this->scanLimit); - SNPRINTF(errStr, JMSG_LENGTH_MAX, - "Progressive JPEG image has more than %d scans", - myprog->this->scanLimit); - myprog->this->isInstanceError = TRUE; - myerr->warning = FALSE; - longjmp(myerr->setjmp_buffer, 1); - } - } -} - -static const JXFORM_CODE xformtypes[TJ_NUMXOP] = { - JXFORM_NONE, JXFORM_FLIP_H, JXFORM_FLIP_V, JXFORM_TRANSPOSE, - JXFORM_TRANSVERSE, JXFORM_ROT_90, JXFORM_ROT_180, JXFORM_ROT_270 -}; - -#define NUMSF 16 -static const tjscalingfactor sf[NUMSF] = { - { 2, 1 }, - { 15, 8 }, - { 7, 4 }, - { 13, 8 }, - { 3, 2 }, - { 11, 8 }, - { 5, 4 }, - { 9, 8 }, - { 1, 1 }, - { 7, 8 }, - { 3, 4 }, - { 5, 8 }, - { 1, 2 }, - { 3, 8 }, - { 1, 4 }, - { 1, 8 } -}; - -static J_COLOR_SPACE pf2cs[TJ_NUMPF] = { - JCS_EXT_RGB, JCS_EXT_BGR, JCS_EXT_RGBX, JCS_EXT_BGRX, JCS_EXT_XBGR, - JCS_EXT_XRGB, JCS_GRAYSCALE, JCS_EXT_RGBA, JCS_EXT_BGRA, JCS_EXT_ABGR, - JCS_EXT_ARGB, JCS_CMYK -}; - -static int cs2pf[JPEG_NUMCS] = { - TJPF_UNKNOWN, TJPF_GRAY, -#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3 - TJPF_RGB, -#elif RGB_RED == 2 && RGB_GREEN == 1 && RGB_BLUE == 0 && RGB_PIXELSIZE == 3 - TJPF_BGR, -#elif RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 4 - TJPF_RGBX, -#elif RGB_RED == 2 && RGB_GREEN == 1 && RGB_BLUE == 0 && RGB_PIXELSIZE == 4 - TJPF_BGRX, -#elif RGB_RED == 3 && RGB_GREEN == 2 && RGB_BLUE == 1 && RGB_PIXELSIZE == 4 - TJPF_XBGR, -#elif RGB_RED == 1 && RGB_GREEN == 2 && RGB_BLUE == 3 && RGB_PIXELSIZE == 4 - TJPF_XRGB, -#endif - TJPF_UNKNOWN, TJPF_CMYK, TJPF_UNKNOWN, TJPF_RGB, TJPF_RGBX, TJPF_BGR, - TJPF_BGRX, TJPF_XBGR, TJPF_XRGB, TJPF_RGBA, TJPF_BGRA, TJPF_ABGR, TJPF_ARGB, - TJPF_UNKNOWN -}; - -#define THROWG(m, rv) { \ - SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): %s", FUNCTION_NAME, m); \ - retval = rv; goto bailout; \ -} -#ifdef _MSC_VER -#define THROW_UNIX(m) { \ - char strerrorBuf[80] = { 0 }; \ - strerror_s(strerrorBuf, 80, errno); \ - SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s(): %s\n%s", FUNCTION_NAME, m, \ - strerrorBuf); \ - this->isInstanceError = TRUE; \ - SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): %s\n%s", FUNCTION_NAME, m, \ - strerrorBuf); \ - retval = -1; goto bailout; \ -} -#else -#define THROW_UNIX(m) { \ - SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s(): %s\n%s", FUNCTION_NAME, m, \ - strerror(errno)); \ - this->isInstanceError = TRUE; \ - SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): %s\n%s", FUNCTION_NAME, m, \ - strerror(errno)); \ - retval = -1; goto bailout; \ -} -#endif -#define THROW(m) { \ - SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s(): %s", FUNCTION_NAME, m); \ - this->isInstanceError = TRUE; THROWG(m, -1) \ -} -#define THROWI(format, val1, val2) { \ - SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s(): " format, FUNCTION_NAME, \ - val1, val2); \ - this->isInstanceError = TRUE; \ - SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): " format, FUNCTION_NAME, val1, \ - val2); \ - retval = -1; goto bailout; \ -} - -#define GET_INSTANCE(handle) \ - tjinstance *this = (tjinstance *)handle; \ - j_compress_ptr cinfo = NULL; \ - j_decompress_ptr dinfo = NULL; \ - \ - if (!this) { \ - SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): Invalid handle", FUNCTION_NAME); \ - return -1; \ - } \ - cinfo = &this->cinfo; dinfo = &this->dinfo; \ - this->jerr.warning = FALSE; \ - this->isInstanceError = FALSE; - -#define GET_CINSTANCE(handle) \ - tjinstance *this = (tjinstance *)handle; \ - j_compress_ptr cinfo = NULL; \ - \ - if (!this) { \ - SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): Invalid handle", FUNCTION_NAME); \ - return -1; \ - } \ - cinfo = &this->cinfo; \ - this->jerr.warning = FALSE; \ - this->isInstanceError = FALSE; - -#define GET_DINSTANCE(handle) \ - tjinstance *this = (tjinstance *)handle; \ - j_decompress_ptr dinfo = NULL; \ - \ - if (!this) { \ - SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): Invalid handle", FUNCTION_NAME); \ - return -1; \ - } \ - dinfo = &this->dinfo; \ - this->jerr.warning = FALSE; \ - this->isInstanceError = FALSE; - -#define GET_TJINSTANCE(handle, errorReturn) \ - tjinstance *this = (tjinstance *)handle; \ - \ - if (!this) { \ - SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s(): Invalid handle", FUNCTION_NAME); \ - return errorReturn; \ - } \ - this->jerr.warning = FALSE; \ - this->isInstanceError = FALSE; - -static int getPixelFormat(int pixelSize, int flags) -{ - if (pixelSize == 1) return TJPF_GRAY; - if (pixelSize == 3) { - if (flags & TJ_BGR) return TJPF_BGR; - else return TJPF_RGB; - } - if (pixelSize == 4) { - if (flags & TJ_ALPHAFIRST) { - if (flags & TJ_BGR) return TJPF_XBGR; - else return TJPF_XRGB; - } else { - if (flags & TJ_BGR) return TJPF_BGRX; - else return TJPF_RGBX; - } - } - return -1; -} - -static void setCompDefaults(tjinstance *this, int pixelFormat) -{ - this->cinfo.in_color_space = pf2cs[pixelFormat]; - this->cinfo.input_components = tjPixelSize[pixelFormat]; - jpeg_set_defaults(&this->cinfo); - - this->cinfo.restart_interval = this->restartIntervalBlocks; - this->cinfo.restart_in_rows = this->restartIntervalRows; - this->cinfo.X_density = (UINT16)this->xDensity; - this->cinfo.Y_density = (UINT16)this->yDensity; - this->cinfo.density_unit = (UINT8)this->densityUnits; - this->cinfo.mem->max_memory_to_use = (long)this->maxMemory * 1048576L; - - if (this->lossless) { -#ifdef C_LOSSLESS_SUPPORTED - jpeg_enable_lossless(&this->cinfo, this->losslessPSV, this->losslessPt); -#endif - if (pixelFormat == TJPF_GRAY) - this->subsamp = TJSAMP_GRAY; - else if (this->subsamp != TJSAMP_GRAY) - this->subsamp = TJSAMP_444; - return; - } - - jpeg_set_quality(&this->cinfo, this->quality, TRUE); - this->cinfo.dct_method = this->fastDCT ? JDCT_FASTEST : JDCT_ISLOW; - - switch (this->colorspace) { - case TJCS_RGB: - jpeg_set_colorspace(&this->cinfo, JCS_RGB); break; - case TJCS_YCbCr: - jpeg_set_colorspace(&this->cinfo, JCS_YCbCr); break; - case TJCS_GRAY: - jpeg_set_colorspace(&this->cinfo, JCS_GRAYSCALE); break; - case TJCS_CMYK: - jpeg_set_colorspace(&this->cinfo, JCS_CMYK); break; - case TJCS_YCCK: - jpeg_set_colorspace(&this->cinfo, JCS_YCCK); break; - default: - if (this->subsamp == TJSAMP_GRAY) - jpeg_set_colorspace(&this->cinfo, JCS_GRAYSCALE); - else if (pixelFormat == TJPF_CMYK) - jpeg_set_colorspace(&this->cinfo, JCS_YCCK); - else - jpeg_set_colorspace(&this->cinfo, JCS_YCbCr); - } - - if (this->cinfo.data_precision == 8) - this->cinfo.optimize_coding = this->optimize; -#ifdef C_PROGRESSIVE_SUPPORTED - if (this->progressive) jpeg_simple_progression(&this->cinfo); -#endif - this->cinfo.arith_code = this->arithmetic; - - this->cinfo.comp_info[0].h_samp_factor = tjMCUWidth[this->subsamp] / 8; - this->cinfo.comp_info[1].h_samp_factor = 1; - this->cinfo.comp_info[2].h_samp_factor = 1; - if (this->cinfo.num_components > 3) - this->cinfo.comp_info[3].h_samp_factor = tjMCUWidth[this->subsamp] / 8; - this->cinfo.comp_info[0].v_samp_factor = tjMCUHeight[this->subsamp] / 8; - this->cinfo.comp_info[1].v_samp_factor = 1; - this->cinfo.comp_info[2].v_samp_factor = 1; - if (this->cinfo.num_components > 3) - this->cinfo.comp_info[3].v_samp_factor = tjMCUHeight[this->subsamp] / 8; -} - - -static int getSubsamp(j_decompress_ptr dinfo) -{ - int retval = TJSAMP_UNKNOWN, i, k; - - /* The sampling factors actually have no meaning with grayscale JPEG files, - and in fact it's possible to generate grayscale JPEGs with sampling - factors > 1 (even though those sampling factors are ignored by the - decompressor.) Thus, we need to treat grayscale as a special case. */ - if (dinfo->num_components == 1 && dinfo->jpeg_color_space == JCS_GRAYSCALE) - return TJSAMP_GRAY; - - for (i = 0; i < TJ_NUMSAMP; i++) { - if (i == TJSAMP_GRAY) continue; - - if (dinfo->num_components == 3 || - ((dinfo->jpeg_color_space == JCS_YCCK || - dinfo->jpeg_color_space == JCS_CMYK) && - dinfo->num_components == 4)) { - if (dinfo->comp_info[0].h_samp_factor == tjMCUWidth[i] / 8 && - dinfo->comp_info[0].v_samp_factor == tjMCUHeight[i] / 8) { - int match = 0; - - for (k = 1; k < dinfo->num_components; k++) { - int href = 1, vref = 1; - - if ((dinfo->jpeg_color_space == JCS_YCCK || - dinfo->jpeg_color_space == JCS_CMYK) && k == 3) { - href = tjMCUWidth[i] / 8; vref = tjMCUHeight[i] / 8; - } - if (dinfo->comp_info[k].h_samp_factor == href && - dinfo->comp_info[k].v_samp_factor == vref) - match++; - } - if (match == dinfo->num_components - 1) { - retval = i; break; - } - } - /* Handle 4:2:2 and 4:4:0 images whose sampling factors are specified - in non-standard ways. */ - if (dinfo->comp_info[0].h_samp_factor == 2 && - dinfo->comp_info[0].v_samp_factor == 2 && - (i == TJSAMP_422 || i == TJSAMP_440)) { - int match = 0; - - for (k = 1; k < dinfo->num_components; k++) { - int href = tjMCUHeight[i] / 8, vref = tjMCUWidth[i] / 8; - - if ((dinfo->jpeg_color_space == JCS_YCCK || - dinfo->jpeg_color_space == JCS_CMYK) && k == 3) { - href = vref = 2; - } - if (dinfo->comp_info[k].h_samp_factor == href && - dinfo->comp_info[k].v_samp_factor == vref) - match++; - } - if (match == dinfo->num_components - 1) { - retval = i; break; - } - } - /* Handle 4:4:4 images whose sampling factors are specified in - non-standard ways. */ - if (dinfo->comp_info[0].h_samp_factor * - dinfo->comp_info[0].v_samp_factor <= - D_MAX_BLOCKS_IN_MCU / 3 && i == TJSAMP_444) { - int match = 0; - for (k = 1; k < dinfo->num_components; k++) { - if (dinfo->comp_info[k].h_samp_factor == - dinfo->comp_info[0].h_samp_factor && - dinfo->comp_info[k].v_samp_factor == - dinfo->comp_info[0].v_samp_factor) - match++; - if (match == dinfo->num_components - 1) { - retval = i; break; - } - } - } - } - } - return retval; -} - - -static void setDecompParameters(tjinstance *this) -{ - this->subsamp = getSubsamp(&this->dinfo); - this->jpegWidth = this->dinfo.image_width; - this->jpegHeight = this->dinfo.image_height; - this->precision = this->dinfo.data_precision; - switch (this->dinfo.jpeg_color_space) { - case JCS_GRAYSCALE: this->colorspace = TJCS_GRAY; break; - case JCS_RGB: this->colorspace = TJCS_RGB; break; - case JCS_YCbCr: this->colorspace = TJCS_YCbCr; break; - case JCS_CMYK: this->colorspace = TJCS_CMYK; break; - case JCS_YCCK: this->colorspace = TJCS_YCCK; break; - default: this->colorspace = -1; break; - } - this->progressive = this->dinfo.progressive_mode; - this->arithmetic = this->dinfo.arith_code; - this->lossless = this->dinfo.master->lossless; - this->losslessPSV = this->dinfo.Ss; - this->losslessPt = this->dinfo.Al; - this->xDensity = this->dinfo.X_density; - this->yDensity = this->dinfo.Y_density; - this->densityUnits = this->dinfo.density_unit; -} - - -static void processFlags(tjhandle handle, int flags, int operation) -{ - tjinstance *this = (tjinstance *)handle; - - this->bottomUp = !!(flags & TJFLAG_BOTTOMUP); - -#ifndef NO_PUTENV - if (flags & TJFLAG_FORCEMMX) PUTENV_S("JSIMD_FORCEMMX", "1"); - else if (flags & TJFLAG_FORCESSE) PUTENV_S("JSIMD_FORCESSE", "1"); - else if (flags & TJFLAG_FORCESSE2) PUTENV_S("JSIMD_FORCESSE2", "1"); -#endif - - this->fastUpsample = !!(flags & TJFLAG_FASTUPSAMPLE); - this->noRealloc = !!(flags & TJFLAG_NOREALLOC); - - if (operation == COMPRESS) { - if (this->quality >= 96 || flags & TJFLAG_ACCURATEDCT) - this->fastDCT = FALSE; - else - this->fastDCT = TRUE; - } else - this->fastDCT = !!(flags & TJFLAG_FASTDCT); - - this->jerr.stopOnWarning = !!(flags & TJFLAG_STOPONWARNING); - this->progressive = !!(flags & TJFLAG_PROGRESSIVE); - - if (flags & TJFLAG_LIMITSCANS) this->scanLimit = 500; -} - - -/*************************** General API functions ***************************/ - -/* TurboJPEG 3+ */ -DLLEXPORT tjhandle tj3Init(int initType) -{ - static const char FUNCTION_NAME[] = "tj3Init"; - tjinstance *this = NULL; - tjhandle retval = NULL; - - if (initType < 0 || initType >= TJ_NUMINIT) - THROWG("Invalid argument", NULL); - - if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) - THROWG("Memory allocation failure", NULL); - memset(this, 0, sizeof(tjinstance)); - SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error"); - - this->quality = -1; - this->subsamp = TJSAMP_UNKNOWN; - this->jpegWidth = -1; - this->jpegHeight = -1; - this->precision = 8; - this->colorspace = -1; - this->losslessPSV = 1; - this->xDensity = 1; - this->yDensity = 1; - this->scalingFactor = TJUNSCALED; - - switch (initType) { - case TJINIT_COMPRESS: return _tjInitCompress(this); - case TJINIT_DECOMPRESS: return _tjInitDecompress(this); - case TJINIT_TRANSFORM: - retval = _tjInitCompress(this); - if (!retval) return NULL; - retval = _tjInitDecompress(this); - return retval; - } - -bailout: - return retval; -} - - -#define SET_PARAM(field, minValue, maxValue) { \ - if (value < minValue || (maxValue > 0 && value > maxValue)) \ - THROW("Parameter value out of range"); \ - this->field = value; \ -} - -#define SET_BOOL_PARAM(field) { \ - if (value < 0 || value > 1) \ - THROW("Parameter value out of range"); \ - this->field = (boolean)value; \ -} - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3Set(tjhandle handle, int param, int value) -{ - static const char FUNCTION_NAME[] = "tj3Set"; - int retval = 0; - - GET_TJINSTANCE(handle, -1); - - switch (param) { - case TJPARAM_STOPONWARNING: - SET_BOOL_PARAM(jerr.stopOnWarning); - break; - case TJPARAM_BOTTOMUP: - SET_BOOL_PARAM(bottomUp); - break; - case TJPARAM_NOREALLOC: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_NOREALLOC is not applicable to decompression instances."); - SET_BOOL_PARAM(noRealloc); - break; - case TJPARAM_QUALITY: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_QUALITY is not applicable to decompression instances."); - SET_PARAM(quality, 1, 100); - break; - case TJPARAM_SUBSAMP: - SET_PARAM(subsamp, 0, TJ_NUMSAMP - 1); - break; - case TJPARAM_JPEGWIDTH: - if (!(this->init & DECOMPRESS)) - THROW("TJPARAM_JPEGWIDTH is not applicable to compression instances."); - THROW("TJPARAM_JPEGWIDTH is read-only in decompression instances."); - break; - case TJPARAM_JPEGHEIGHT: - if (!(this->init & DECOMPRESS)) - THROW("TJPARAM_JPEGHEIGHT is not applicable to compression instances."); - THROW("TJPARAM_JPEGHEIGHT is read-only in decompression instances."); - break; - case TJPARAM_PRECISION: - if (!(this->init & DECOMPRESS)) - THROW("TJPARAM_PRECISION is not applicable to compression instances."); - THROW("TJPARAM_PRECISION is read-only in decompression instances."); - break; - case TJPARAM_COLORSPACE: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_COLORSPACE is read-only in decompression instances."); - SET_PARAM(colorspace, 0, TJ_NUMCS - 1); - break; - case TJPARAM_FASTUPSAMPLE: - if (!(this->init & DECOMPRESS)) - THROW("TJPARAM_FASTUPSAMPLE is not applicable to compression instances."); - SET_BOOL_PARAM(fastUpsample); - break; - case TJPARAM_FASTDCT: - SET_BOOL_PARAM(fastDCT); - break; - case TJPARAM_OPTIMIZE: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_OPTIMIZE is not applicable to decompression instances."); - SET_BOOL_PARAM(optimize); - break; - case TJPARAM_PROGRESSIVE: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_PROGRESSIVE is read-only in decompression instances."); - SET_BOOL_PARAM(progressive); - break; - case TJPARAM_SCANLIMIT: - if (!(this->init & DECOMPRESS)) - THROW("TJPARAM_SCANLIMIT is not applicable to compression instances."); - SET_PARAM(scanLimit, 0, -1); - break; - case TJPARAM_ARITHMETIC: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_ARITHMETIC is read-only in decompression instances."); - SET_BOOL_PARAM(arithmetic); - break; - case TJPARAM_LOSSLESS: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_LOSSLESS is read-only in decompression instances."); - SET_BOOL_PARAM(lossless); - break; - case TJPARAM_LOSSLESSPSV: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_LOSSLESSPSV is read-only in decompression instances."); - SET_PARAM(losslessPSV, 1, 7); - break; - case TJPARAM_LOSSLESSPT: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_LOSSLESSPT is read-only in decompression instances."); - SET_PARAM(losslessPt, 0, this->precision - 1); - break; - case TJPARAM_RESTARTBLOCKS: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_RESTARTBLOCKS is not applicable to decompression instances."); - SET_PARAM(restartIntervalBlocks, 0, 65535); - if (value != 0) this->restartIntervalRows = 0; - break; - case TJPARAM_RESTARTROWS: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_RESTARTROWS is not applicable to decompression instances."); - SET_PARAM(restartIntervalRows, 0, 65535); - if (value != 0) this->restartIntervalBlocks = 0; - break; - case TJPARAM_XDENSITY: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_XDENSITY is read-only in decompression instances."); - SET_PARAM(xDensity, 1, 65535); - break; - case TJPARAM_YDENSITY: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_YDENSITY is read-only in decompression instances."); - SET_PARAM(yDensity, 1, 65535); - break; - case TJPARAM_DENSITYUNITS: - if (!(this->init & COMPRESS)) - THROW("TJPARAM_DENSITYUNITS is read-only in decompression instances."); - SET_PARAM(densityUnits, 0, 2); - break; - case TJPARAM_MAXMEMORY: - SET_PARAM(maxMemory, 0, (int)(min(LONG_MAX / 1048576L, (long)INT_MAX))); - break; - case TJPARAM_MAXPIXELS: - SET_PARAM(maxPixels, 0, -1); - break; - default: - THROW("Invalid parameter"); - } - -bailout: - return retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3Get(tjhandle handle, int param) -{ - tjinstance *this = (tjinstance *)handle; - if (!this) return -1; - - switch (param) { - case TJPARAM_STOPONWARNING: - return this->jerr.stopOnWarning; - case TJPARAM_BOTTOMUP: - return this->bottomUp; - case TJPARAM_NOREALLOC: - return this->noRealloc; - case TJPARAM_QUALITY: - return this->quality; - case TJPARAM_SUBSAMP: - return this->subsamp; - case TJPARAM_JPEGWIDTH: - return this->jpegWidth; - case TJPARAM_JPEGHEIGHT: - return this->jpegHeight; - case TJPARAM_PRECISION: - return this->precision; - case TJPARAM_COLORSPACE: - return this->colorspace; - case TJPARAM_FASTUPSAMPLE: - return this->fastUpsample; - case TJPARAM_FASTDCT: - return this->fastDCT; - case TJPARAM_OPTIMIZE: - return this->optimize; - case TJPARAM_PROGRESSIVE: - return this->progressive; - case TJPARAM_SCANLIMIT: - return this->scanLimit; - case TJPARAM_ARITHMETIC: - return this->arithmetic; - case TJPARAM_LOSSLESS: - return this->lossless; - case TJPARAM_LOSSLESSPSV: - return this->losslessPSV; - case TJPARAM_LOSSLESSPT: - return this->losslessPt; - case TJPARAM_RESTARTBLOCKS: - return this->restartIntervalBlocks; - case TJPARAM_RESTARTROWS: - return this->restartIntervalRows; - case TJPARAM_XDENSITY: - return this->xDensity; - case TJPARAM_YDENSITY: - return this->yDensity; - case TJPARAM_DENSITYUNITS: - return this->densityUnits; - case TJPARAM_MAXMEMORY: - return this->maxMemory; - case TJPARAM_MAXPIXELS: - return this->maxPixels; - } - - return -1; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT char *tj3GetErrorStr(tjhandle handle) -{ - tjinstance *this = (tjinstance *)handle; - - if (this && this->isInstanceError) { - this->isInstanceError = FALSE; - return this->errStr; - } else - return errStr; -} - -/* TurboJPEG 2.0+ */ -DLLEXPORT char *tjGetErrorStr2(tjhandle handle) -{ - return tj3GetErrorStr(handle); -} - -/* TurboJPEG 1.0+ */ -DLLEXPORT char *tjGetErrorStr(void) -{ - return errStr; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3GetErrorCode(tjhandle handle) -{ - tjinstance *this = (tjinstance *)handle; - - if (this && this->jerr.warning) return TJERR_WARNING; - else return TJERR_FATAL; -} - -/* TurboJPEG 2.0+ */ -DLLEXPORT int tjGetErrorCode(tjhandle handle) -{ - return tj3GetErrorCode(handle); -} - - -/* TurboJPEG 3+ */ -DLLEXPORT void tj3Destroy(tjhandle handle) -{ - tjinstance *this = (tjinstance *)handle; - j_compress_ptr cinfo = NULL; - j_decompress_ptr dinfo = NULL; - - if (!this) return; - - cinfo = &this->cinfo; dinfo = &this->dinfo; - this->jerr.warning = FALSE; - this->isInstanceError = FALSE; - - if (setjmp(this->jerr.setjmp_buffer)) return; - if (this->init & COMPRESS) jpeg_destroy_compress(cinfo); - if (this->init & DECOMPRESS) jpeg_destroy_decompress(dinfo); - free(this); -} - -/* TurboJPEG 1.0+ */ -DLLEXPORT int tjDestroy(tjhandle handle) -{ - static const char FUNCTION_NAME[] = "tjDestroy"; - int retval = 0; - - if (!handle) THROWG("Invalid handle", -1); - - SNPRINTF(errStr, JMSG_LENGTH_MAX, "No error"); - tj3Destroy(handle); - if (strcmp(errStr, "No error")) retval = -1; - -bailout: - return retval; -} - - -/* These are exposed mainly because Windows can't malloc() and free() across - DLL boundaries except when the CRT DLL is used, and we don't use the CRT DLL - with turbojpeg.dll for compatibility reasons. However, these functions - can potentially be used for other purposes by different implementations. */ - -/* TurboJPEG 3+ */ -DLLEXPORT void tj3Free(void *buf) -{ - free(buf); -} - -/* TurboJPEG 1.2+ */ -DLLEXPORT void tjFree(unsigned char *buf) -{ - tj3Free(buf); -} - - -/* TurboJPEG 3+ */ -DLLEXPORT void *tj3Alloc(size_t bytes) -{ - return malloc(bytes); -} - -/* TurboJPEG 1.2+ */ -DLLEXPORT unsigned char *tjAlloc(int bytes) -{ - return (unsigned char *)tj3Alloc((size_t)bytes); -} - - -/******************************** Compressor *********************************/ - -static tjhandle _tjInitCompress(tjinstance *this) -{ - static unsigned char buffer[1]; - unsigned char *buf = buffer; - size_t size = 1; - - /* This is also straight out of example.c */ - this->cinfo.err = jpeg_std_error(&this->jerr.pub); - this->jerr.pub.error_exit = my_error_exit; - this->jerr.pub.output_message = my_output_message; - this->jerr.emit_message = this->jerr.pub.emit_message; - this->jerr.pub.emit_message = my_emit_message; - this->jerr.pub.addon_message_table = turbojpeg_message_table; - this->jerr.pub.first_addon_message = JMSG_FIRSTADDONCODE; - this->jerr.pub.last_addon_message = JMSG_LASTADDONCODE; - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - free(this); - return NULL; - } - - jpeg_create_compress(&this->cinfo); - /* Make an initial call so it will create the destination manager */ - jpeg_mem_dest_tj(&this->cinfo, &buf, &size, 0); - - this->init |= COMPRESS; - return (tjhandle)this; -} - -/* TurboJPEG 1.0+ */ -DLLEXPORT tjhandle tjInitCompress(void) -{ - return tj3Init(TJINIT_COMPRESS); -} - - -/* TurboJPEG 3+ */ -DLLEXPORT size_t tj3JPEGBufSize(int width, int height, int jpegSubsamp) -{ - static const char FUNCTION_NAME[] = "tj3JPEGBufSize"; - unsigned long long retval = 0; - int mcuw, mcuh, chromasf; - - if (width < 1 || height < 1 || jpegSubsamp < TJSAMP_UNKNOWN || - jpegSubsamp >= TJ_NUMSAMP) - THROWG("Invalid argument", 0); - - if (jpegSubsamp == TJSAMP_UNKNOWN) - jpegSubsamp = TJSAMP_444; - - /* This allows for rare corner cases in which a JPEG image can actually be - larger than the uncompressed input (we wouldn't mention it if it hadn't - happened before.) */ - mcuw = tjMCUWidth[jpegSubsamp]; - mcuh = tjMCUHeight[jpegSubsamp]; - chromasf = jpegSubsamp == TJSAMP_GRAY ? 0 : 4 * 64 / (mcuw * mcuh); - retval = PAD(width, mcuw) * PAD(height, mcuh) * (2ULL + chromasf) + 2048ULL; -#if ULLONG_MAX > ULONG_MAX - if (retval > (unsigned long long)((unsigned long)-1)) - THROWG("Image is too large", 0); -#endif - -bailout: - return (size_t)retval; -} - -/* TurboJPEG 1.2+ */ -DLLEXPORT unsigned long tjBufSize(int width, int height, int jpegSubsamp) -{ - static const char FUNCTION_NAME[] = "tjBufSize"; - size_t retval; - - if (jpegSubsamp < 0) - THROWG("Invalid argument", 0); - - retval = tj3JPEGBufSize(width, height, jpegSubsamp); - -bailout: - return (retval == 0) ? (unsigned long)-1 : (unsigned long)retval; -} - -/* TurboJPEG 1.0+ */ -DLLEXPORT unsigned long TJBUFSIZE(int width, int height) -{ - static const char FUNCTION_NAME[] = "TJBUFSIZE"; - unsigned long long retval = 0; - - if (width < 1 || height < 1) - THROWG("Invalid argument", (unsigned long)-1); - - /* This allows for rare corner cases in which a JPEG image can actually be - larger than the uncompressed input (we wouldn't mention it if it hadn't - happened before.) */ - retval = PAD(width, 16) * PAD(height, 16) * 6ULL + 2048ULL; -#if ULLONG_MAX > ULONG_MAX - if (retval > (unsigned long long)((unsigned long)-1)) - THROWG("Image is too large", (unsigned long)-1); -#endif - -bailout: - return (unsigned long)retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT size_t tj3YUVBufSize(int width, int align, int height, int subsamp) -{ - static const char FUNCTION_NAME[] = "tj3YUVBufSize"; - unsigned long long retval = 0; - int nc, i; - - if (align < 1 || !IS_POW2(align) || subsamp < 0 || subsamp >= TJ_NUMSAMP) - THROWG("Invalid argument", 0); - - nc = (subsamp == TJSAMP_GRAY ? 1 : 3); - for (i = 0; i < nc; i++) { - int pw = tj3YUVPlaneWidth(i, width, subsamp); - int stride = PAD(pw, align); - int ph = tj3YUVPlaneHeight(i, height, subsamp); - - if (pw == 0 || ph == 0) return 0; - else retval += (unsigned long long)stride * ph; - } -#if ULLONG_MAX > ULONG_MAX - if (retval > (unsigned long long)((unsigned long)-1)) - THROWG("Image is too large", 0); -#endif - -bailout: - return (size_t)retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT unsigned long tjBufSizeYUV2(int width, int align, int height, - int subsamp) -{ - size_t retval = tj3YUVBufSize(width, align, height, subsamp); - return (retval == 0) ? (unsigned long)-1 : (unsigned long)retval; -} - -/* TurboJPEG 1.2+ */ -DLLEXPORT unsigned long tjBufSizeYUV(int width, int height, int subsamp) -{ - return tjBufSizeYUV2(width, 4, height, subsamp); -} - -/* TurboJPEG 1.1+ */ -DLLEXPORT unsigned long TJBUFSIZEYUV(int width, int height, int subsamp) -{ - return tjBufSizeYUV(width, height, subsamp); -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3YUVPlaneWidth(int componentID, int width, int subsamp) -{ - static const char FUNCTION_NAME[] = "tj3YUVPlaneWidth"; - unsigned long long pw, retval = 0; - int nc; - - if (width < 1 || subsamp < 0 || subsamp >= TJ_NUMSAMP) - THROWG("Invalid argument", 0); - nc = (subsamp == TJSAMP_GRAY ? 1 : 3); - if (componentID < 0 || componentID >= nc) - THROWG("Invalid argument", 0); - - pw = PAD((unsigned long long)width, tjMCUWidth[subsamp] / 8); - if (componentID == 0) - retval = pw; - else - retval = pw * 8 / tjMCUWidth[subsamp]; - - if (retval > (unsigned long long)INT_MAX) - THROWG("Width is too large", 0); - -bailout: - return (int)retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp) -{ - int retval = tj3YUVPlaneWidth(componentID, width, subsamp); - return (retval == 0) ? -1 : retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3YUVPlaneHeight(int componentID, int height, int subsamp) -{ - static const char FUNCTION_NAME[] = "tj3YUVPlaneHeight"; - unsigned long long ph, retval = 0; - int nc; - - if (height < 1 || subsamp < 0 || subsamp >= TJ_NUMSAMP) - THROWG("Invalid argument", 0); - nc = (subsamp == TJSAMP_GRAY ? 1 : 3); - if (componentID < 0 || componentID >= nc) - THROWG("Invalid argument", 0); - - ph = PAD((unsigned long long)height, tjMCUHeight[subsamp] / 8); - if (componentID == 0) - retval = ph; - else - retval = ph * 8 / tjMCUHeight[subsamp]; - - if (retval > (unsigned long long)INT_MAX) - THROWG("Height is too large", 0); - -bailout: - return (int)retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp) -{ - int retval = tj3YUVPlaneHeight(componentID, height, subsamp); - return (retval == 0) ? -1 : retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT size_t tj3YUVPlaneSize(int componentID, int width, int stride, - int height, int subsamp) -{ - static const char FUNCTION_NAME[] = "tj3YUVPlaneSize"; - unsigned long long retval = 0; - int pw, ph; - - if (width < 1 || height < 1 || subsamp < 0 || subsamp >= TJ_NUMSAMP) - THROWG("Invalid argument", 0); - - pw = tj3YUVPlaneWidth(componentID, width, subsamp); - ph = tj3YUVPlaneHeight(componentID, height, subsamp); - if (pw == 0 || ph == 0) return 0; - - if (stride == 0) stride = pw; - else stride = abs(stride); - - retval = (unsigned long long)stride * (ph - 1) + pw; -#if ULLONG_MAX > ULONG_MAX - if (retval > (unsigned long long)((unsigned long)-1)) - THROWG("Image is too large", 0); -#endif - -bailout: - return (size_t)retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT unsigned long tjPlaneSizeYUV(int componentID, int width, int stride, - int height, int subsamp) -{ - size_t retval = tj3YUVPlaneSize(componentID, width, stride, height, subsamp); - return (retval == 0) ? -1 : (unsigned long)retval; -} - - -/* tj3Compress*() is implemented in turbojpeg-mp.c */ -#define BITS_IN_JSAMPLE 8 -#include "turbojpeg-mp.c" -#undef BITS_IN_JSAMPLE -#define BITS_IN_JSAMPLE 12 -#include "turbojpeg-mp.c" -#undef BITS_IN_JSAMPLE -#define BITS_IN_JSAMPLE 16 -#include "turbojpeg-mp.c" -#undef BITS_IN_JSAMPLE - -/* TurboJPEG 1.2+ */ -DLLEXPORT int tjCompress2(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, int pixelFormat, - unsigned char **jpegBuf, unsigned long *jpegSize, - int jpegSubsamp, int jpegQual, int flags) -{ - static const char FUNCTION_NAME[] = "tjCompress2"; - int retval = 0; - size_t size; - - GET_TJINSTANCE(handle, -1); - - if (jpegSize == NULL || jpegSubsamp < 0 || jpegSubsamp >= TJ_NUMSAMP || - jpegQual < 0 || jpegQual > 100) - THROW("Invalid argument"); - - this->quality = jpegQual; - this->subsamp = jpegSubsamp; - processFlags(handle, flags, COMPRESS); - - size = (size_t)(*jpegSize); - retval = tj3Compress8(handle, srcBuf, width, pitch, height, pixelFormat, - jpegBuf, &size); - *jpegSize = (unsigned long)size; - -bailout: - return retval; -} - -/* TurboJPEG 1.0+ */ -DLLEXPORT int tjCompress(tjhandle handle, unsigned char *srcBuf, int width, - int pitch, int height, int pixelSize, - unsigned char *jpegBuf, unsigned long *jpegSize, - int jpegSubsamp, int jpegQual, int flags) -{ - int retval = 0; - unsigned long size = jpegSize ? *jpegSize : 0; - - if (flags & TJ_YUV) { - size = tjBufSizeYUV(width, height, jpegSubsamp); - retval = tjEncodeYUV2(handle, srcBuf, width, pitch, height, - getPixelFormat(pixelSize, flags), jpegBuf, - jpegSubsamp, flags); - } else { - retval = tjCompress2(handle, srcBuf, width, pitch, height, - getPixelFormat(pixelSize, flags), &jpegBuf, &size, - jpegSubsamp, jpegQual, flags | TJFLAG_NOREALLOC); - } - *jpegSize = size; - return retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3EncodeYUVPlanes8(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, - int pixelFormat, unsigned char **dstPlanes, - int *strides) -{ - static const char FUNCTION_NAME[] = "tj3EncodeYUVPlanes8"; - JSAMPROW *row_pointer = NULL; - JSAMPLE *_tmpbuf[MAX_COMPONENTS], *_tmpbuf2[MAX_COMPONENTS]; - JSAMPROW *tmpbuf[MAX_COMPONENTS], *tmpbuf2[MAX_COMPONENTS]; - JSAMPROW *outbuf[MAX_COMPONENTS]; - int i, retval = 0, row, pw0, ph0, pw[MAX_COMPONENTS], ph[MAX_COMPONENTS]; - JSAMPLE *ptr; - jpeg_component_info *compptr; - - GET_CINSTANCE(handle) - - for (i = 0; i < MAX_COMPONENTS; i++) { - tmpbuf[i] = NULL; _tmpbuf[i] = NULL; - tmpbuf2[i] = NULL; _tmpbuf2[i] = NULL; outbuf[i] = NULL; - } - - if ((this->init & COMPRESS) == 0) - THROW("Instance has not been initialized for compression"); - - if (srcBuf == NULL || width <= 0 || pitch < 0 || height <= 0 || - pixelFormat < 0 || pixelFormat >= TJ_NUMPF || !dstPlanes || - !dstPlanes[0]) - THROW("Invalid argument"); - if (this->subsamp != TJSAMP_GRAY && (!dstPlanes[1] || !dstPlanes[2])) - THROW("Invalid argument"); - - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("TJPARAM_SUBSAMP must be specified"); - if (pixelFormat == TJPF_CMYK) - THROW("Cannot generate YUV images from packed-pixel CMYK images"); - - if (pitch == 0) pitch = width * tjPixelSize[pixelFormat]; - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - cinfo->image_width = width; - cinfo->image_height = height; - cinfo->data_precision = 8; - - setCompDefaults(this, pixelFormat); - - /* Execute only the parts of jpeg_start_compress() that we need. If we - were to call the whole jpeg_start_compress() function, then it would try - to write the file headers, which could overflow the output buffer if the - YUV image were very small. */ - if (cinfo->global_state != CSTATE_START) - THROW("libjpeg API is in the wrong state"); - (*cinfo->err->reset_error_mgr) ((j_common_ptr)cinfo); - jinit_c_master_control(cinfo, FALSE); - jinit_color_converter(cinfo); - jinit_downsampler(cinfo); - (*cinfo->cconvert->start_pass) (cinfo); - - pw0 = PAD(width, cinfo->max_h_samp_factor); - ph0 = PAD(height, cinfo->max_v_samp_factor); - - if ((row_pointer = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph0)) == NULL) - THROW("Memory allocation failure"); - for (i = 0; i < height; i++) { - if (this->bottomUp) - row_pointer[i] = (JSAMPROW)&srcBuf[(height - i - 1) * (size_t)pitch]; - else - row_pointer[i] = (JSAMPROW)&srcBuf[i * (size_t)pitch]; - } - if (height < ph0) - for (i = height; i < ph0; i++) row_pointer[i] = row_pointer[height - 1]; - - for (i = 0; i < cinfo->num_components; i++) { - compptr = &cinfo->comp_info[i]; - _tmpbuf[i] = (JSAMPLE *)malloc( - PAD((compptr->width_in_blocks * cinfo->max_h_samp_factor * DCTSIZE) / - compptr->h_samp_factor, 32) * - cinfo->max_v_samp_factor + 32); - if (!_tmpbuf[i]) - THROW("Memory allocation failure"); - tmpbuf[i] = - (JSAMPROW *)malloc(sizeof(JSAMPROW) * cinfo->max_v_samp_factor); - if (!tmpbuf[i]) - THROW("Memory allocation failure"); - for (row = 0; row < cinfo->max_v_samp_factor; row++) { - unsigned char *_tmpbuf_aligned = - (unsigned char *)PAD((JUINTPTR)_tmpbuf[i], 32); - - tmpbuf[i][row] = &_tmpbuf_aligned[ - PAD((compptr->width_in_blocks * cinfo->max_h_samp_factor * DCTSIZE) / - compptr->h_samp_factor, 32) * row]; - } - _tmpbuf2[i] = - (JSAMPLE *)malloc(PAD(compptr->width_in_blocks * DCTSIZE, 32) * - compptr->v_samp_factor + 32); - if (!_tmpbuf2[i]) - THROW("Memory allocation failure"); - tmpbuf2[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * compptr->v_samp_factor); - if (!tmpbuf2[i]) - THROW("Memory allocation failure"); - for (row = 0; row < compptr->v_samp_factor; row++) { - unsigned char *_tmpbuf2_aligned = - (unsigned char *)PAD((JUINTPTR)_tmpbuf2[i], 32); - - tmpbuf2[i][row] = - &_tmpbuf2_aligned[PAD(compptr->width_in_blocks * DCTSIZE, 32) * row]; - } - pw[i] = pw0 * compptr->h_samp_factor / cinfo->max_h_samp_factor; - ph[i] = ph0 * compptr->v_samp_factor / cinfo->max_v_samp_factor; - outbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph[i]); - if (!outbuf[i]) - THROW("Memory allocation failure"); - ptr = dstPlanes[i]; - for (row = 0; row < ph[i]; row++) { - outbuf[i][row] = ptr; - ptr += (strides && strides[i] != 0) ? strides[i] : pw[i]; - } - } - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - for (row = 0; row < ph0; row += cinfo->max_v_samp_factor) { - (*cinfo->cconvert->color_convert) (cinfo, &row_pointer[row], tmpbuf, 0, - cinfo->max_v_samp_factor); - (cinfo->downsample->downsample) (cinfo, tmpbuf, 0, tmpbuf2, 0); - for (i = 0, compptr = cinfo->comp_info; i < cinfo->num_components; - i++, compptr++) - jcopy_sample_rows(tmpbuf2[i], 0, outbuf[i], - row * compptr->v_samp_factor / cinfo->max_v_samp_factor, - compptr->v_samp_factor, pw[i]); - } - cinfo->next_scanline += height; - jpeg_abort_compress(cinfo); - -bailout: - if (cinfo->global_state > CSTATE_START) jpeg_abort_compress(cinfo); - free(row_pointer); - for (i = 0; i < MAX_COMPONENTS; i++) { - free(tmpbuf[i]); - free(_tmpbuf[i]); - free(tmpbuf2[i]); - free(_tmpbuf2[i]); - free(outbuf[i]); - } - if (this->jerr.warning) retval = -1; - return retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjEncodeYUVPlanes(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, - int pixelFormat, unsigned char **dstPlanes, - int *strides, int subsamp, int flags) -{ - static const char FUNCTION_NAME[] = "tjEncodeYUVPlanes"; - int retval = 0; - - GET_TJINSTANCE(handle, -1); - - if (subsamp < 0 || subsamp >= TJ_NUMSAMP) - THROW("Invalid argument"); - - this->subsamp = subsamp; - processFlags(handle, flags, COMPRESS); - - return tj3EncodeYUVPlanes8(handle, srcBuf, width, pitch, height, pixelFormat, - dstPlanes, strides); - -bailout: - return retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3EncodeYUV8(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, int pixelFormat, - unsigned char *dstBuf, int align) -{ - static const char FUNCTION_NAME[] = "tj3EncodeYUV8"; - unsigned char *dstPlanes[3]; - int pw0, ph0, strides[3], retval = -1; - - GET_TJINSTANCE(handle, -1); - - if (width <= 0 || height <= 0 || dstBuf == NULL || align < 1 || - !IS_POW2(align)) - THROW("Invalid argument"); - - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("TJPARAM_SUBSAMP must be specified"); - - pw0 = tj3YUVPlaneWidth(0, width, this->subsamp); - ph0 = tj3YUVPlaneHeight(0, height, this->subsamp); - dstPlanes[0] = dstBuf; - strides[0] = PAD(pw0, align); - if (this->subsamp == TJSAMP_GRAY) { - strides[1] = strides[2] = 0; - dstPlanes[1] = dstPlanes[2] = NULL; - } else { - int pw1 = tj3YUVPlaneWidth(1, width, this->subsamp); - int ph1 = tj3YUVPlaneHeight(1, height, this->subsamp); - - strides[1] = strides[2] = PAD(pw1, align); - if ((unsigned long long)strides[0] * (unsigned long long)ph0 > - (unsigned long long)INT_MAX || - (unsigned long long)strides[1] * (unsigned long long)ph1 > - (unsigned long long)INT_MAX) - THROW("Image or row alignment is too large"); - dstPlanes[1] = dstPlanes[0] + strides[0] * ph0; - dstPlanes[2] = dstPlanes[1] + strides[1] * ph1; - } - - return tj3EncodeYUVPlanes8(handle, srcBuf, width, pitch, height, pixelFormat, - dstPlanes, strides); - -bailout: - return retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjEncodeYUV3(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, int pixelFormat, - unsigned char *dstBuf, int align, int subsamp, - int flags) -{ - static const char FUNCTION_NAME[] = "tjEncodeYUV3"; - int retval = 0; - - GET_TJINSTANCE(handle, -1); - - if (subsamp < 0 || subsamp >= TJ_NUMSAMP) - THROW("Invalid argument"); - - this->subsamp = subsamp; - processFlags(handle, flags, COMPRESS); - - return tj3EncodeYUV8(handle, srcBuf, width, pitch, height, pixelFormat, - dstBuf, align); - -bailout: - return retval; -} - -/* TurboJPEG 1.2+ */ -DLLEXPORT int tjEncodeYUV2(tjhandle handle, unsigned char *srcBuf, int width, - int pitch, int height, int pixelFormat, - unsigned char *dstBuf, int subsamp, int flags) -{ - return tjEncodeYUV3(handle, srcBuf, width, pitch, height, pixelFormat, - dstBuf, 4, subsamp, flags); -} - -/* TurboJPEG 1.1+ */ -DLLEXPORT int tjEncodeYUV(tjhandle handle, unsigned char *srcBuf, int width, - int pitch, int height, int pixelSize, - unsigned char *dstBuf, int subsamp, int flags) -{ - return tjEncodeYUV2(handle, srcBuf, width, pitch, height, - getPixelFormat(pixelSize, flags), dstBuf, subsamp, - flags); -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3CompressFromYUVPlanes8(tjhandle handle, - const unsigned char * const *srcPlanes, - int width, const int *strides, - int height, unsigned char **jpegBuf, - size_t *jpegSize) -{ - static const char FUNCTION_NAME[] = "tj3CompressFromYUVPlanes8"; - int i, row, retval = 0; - boolean alloc = TRUE; - int pw[MAX_COMPONENTS], ph[MAX_COMPONENTS], iw[MAX_COMPONENTS], - tmpbufsize = 0, usetmpbuf = 0, th[MAX_COMPONENTS]; - JSAMPLE *_tmpbuf = NULL, *ptr; - JSAMPROW *inbuf[MAX_COMPONENTS], *tmpbuf[MAX_COMPONENTS]; - - GET_CINSTANCE(handle) - - for (i = 0; i < MAX_COMPONENTS; i++) { - tmpbuf[i] = NULL; inbuf[i] = NULL; - } - - if ((this->init & COMPRESS) == 0) - THROW("Instance has not been initialized for compression"); - - if (!srcPlanes || !srcPlanes[0] || width <= 0 || height <= 0 || - jpegBuf == NULL || jpegSize == NULL) - THROW("Invalid argument"); - if (this->subsamp != TJSAMP_GRAY && (!srcPlanes[1] || !srcPlanes[2])) - THROW("Invalid argument"); - - if (this->quality == -1) - THROW("TJPARAM_QUALITY must be specified"); - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("TJPARAM_SUBSAMP must be specified"); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - cinfo->image_width = width; - cinfo->image_height = height; - cinfo->data_precision = 8; - - if (this->noRealloc) { - alloc = FALSE; *jpegSize = tj3JPEGBufSize(width, height, this->subsamp); - } - jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc); - setCompDefaults(this, TJPF_RGB); - cinfo->raw_data_in = TRUE; - - jpeg_start_compress(cinfo, TRUE); - for (i = 0; i < cinfo->num_components; i++) { - jpeg_component_info *compptr = &cinfo->comp_info[i]; - int ih; - - iw[i] = compptr->width_in_blocks * DCTSIZE; - ih = compptr->height_in_blocks * DCTSIZE; - pw[i] = PAD(cinfo->image_width, cinfo->max_h_samp_factor) * - compptr->h_samp_factor / cinfo->max_h_samp_factor; - ph[i] = PAD(cinfo->image_height, cinfo->max_v_samp_factor) * - compptr->v_samp_factor / cinfo->max_v_samp_factor; - if (iw[i] != pw[i] || ih != ph[i]) usetmpbuf = 1; - th[i] = compptr->v_samp_factor * DCTSIZE; - tmpbufsize += iw[i] * th[i]; - if ((inbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph[i])) == NULL) - THROW("Memory allocation failure"); - ptr = (JSAMPLE *)srcPlanes[i]; - for (row = 0; row < ph[i]; row++) { - inbuf[i][row] = ptr; - ptr += (strides && strides[i] != 0) ? strides[i] : pw[i]; - } - } - if (usetmpbuf) { - if ((_tmpbuf = (JSAMPLE *)malloc(sizeof(JSAMPLE) * tmpbufsize)) == NULL) - THROW("Memory allocation failure"); - ptr = _tmpbuf; - for (i = 0; i < cinfo->num_components; i++) { - if ((tmpbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * th[i])) == NULL) - THROW("Memory allocation failure"); - for (row = 0; row < th[i]; row++) { - tmpbuf[i][row] = ptr; - ptr += iw[i]; - } - } - } - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - for (row = 0; row < (int)cinfo->image_height; - row += cinfo->max_v_samp_factor * DCTSIZE) { - JSAMPARRAY yuvptr[MAX_COMPONENTS]; - int crow[MAX_COMPONENTS]; - - for (i = 0; i < cinfo->num_components; i++) { - jpeg_component_info *compptr = &cinfo->comp_info[i]; - - crow[i] = row * compptr->v_samp_factor / cinfo->max_v_samp_factor; - if (usetmpbuf) { - int j, k; - - for (j = 0; j < MIN(th[i], ph[i] - crow[i]); j++) { - memcpy(tmpbuf[i][j], inbuf[i][crow[i] + j], pw[i]); - /* Duplicate last sample in row to fill out MCU */ - for (k = pw[i]; k < iw[i]; k++) - tmpbuf[i][j][k] = tmpbuf[i][j][pw[i] - 1]; - } - /* Duplicate last row to fill out MCU */ - for (j = ph[i] - crow[i]; j < th[i]; j++) - memcpy(tmpbuf[i][j], tmpbuf[i][ph[i] - crow[i] - 1], iw[i]); - yuvptr[i] = tmpbuf[i]; - } else - yuvptr[i] = &inbuf[i][crow[i]]; - } - jpeg_write_raw_data(cinfo, yuvptr, cinfo->max_v_samp_factor * DCTSIZE); - } - jpeg_finish_compress(cinfo); - -bailout: - if (cinfo->global_state > CSTATE_START && alloc) - (*cinfo->dest->term_destination) (cinfo); - if (cinfo->global_state > CSTATE_START || retval == -1) - jpeg_abort_compress(cinfo); - for (i = 0; i < MAX_COMPONENTS; i++) { - free(tmpbuf[i]); - free(inbuf[i]); - } - free(_tmpbuf); - if (this->jerr.warning) retval = -1; - return retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjCompressFromYUVPlanes(tjhandle handle, - const unsigned char **srcPlanes, - int width, const int *strides, - int height, int subsamp, - unsigned char **jpegBuf, - unsigned long *jpegSize, int jpegQual, - int flags) -{ - static const char FUNCTION_NAME[] = "tjCompressFromYUVPlanes"; - int retval = 0; - size_t size; - - GET_TJINSTANCE(handle, -1); - - if (subsamp < 0 || subsamp >= TJ_NUMSAMP || jpegSize == NULL || - jpegQual < 0 || jpegQual > 100) - THROW("Invalid argument"); - - this->quality = jpegQual; - this->subsamp = subsamp; - processFlags(handle, flags, COMPRESS); - - size = (size_t)(*jpegSize); - retval = tj3CompressFromYUVPlanes8(handle, srcPlanes, width, strides, height, - jpegBuf, &size); - *jpegSize = (unsigned long)size; - -bailout: - return retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3CompressFromYUV8(tjhandle handle, - const unsigned char *srcBuf, int width, - int align, int height, - unsigned char **jpegBuf, size_t *jpegSize) -{ - static const char FUNCTION_NAME[] = "tj3CompressFromYUV8"; - const unsigned char *srcPlanes[3]; - int pw0, ph0, strides[3], retval = -1; - - GET_TJINSTANCE(handle, -1); - - if (srcBuf == NULL || width <= 0 || align < 1 || !IS_POW2(align) || - height <= 0) - THROW("Invalid argument"); - - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("TJPARAM_SUBSAMP must be specified"); - - pw0 = tj3YUVPlaneWidth(0, width, this->subsamp); - ph0 = tj3YUVPlaneHeight(0, height, this->subsamp); - srcPlanes[0] = srcBuf; - strides[0] = PAD(pw0, align); - if (this->subsamp == TJSAMP_GRAY) { - strides[1] = strides[2] = 0; - srcPlanes[1] = srcPlanes[2] = NULL; - } else { - int pw1 = tjPlaneWidth(1, width, this->subsamp); - int ph1 = tjPlaneHeight(1, height, this->subsamp); - - strides[1] = strides[2] = PAD(pw1, align); - if ((unsigned long long)strides[0] * (unsigned long long)ph0 > - (unsigned long long)INT_MAX || - (unsigned long long)strides[1] * (unsigned long long)ph1 > - (unsigned long long)INT_MAX) - THROW("Image or row alignment is too large"); - srcPlanes[1] = srcPlanes[0] + strides[0] * ph0; - srcPlanes[2] = srcPlanes[1] + strides[1] * ph1; - } - - return tj3CompressFromYUVPlanes8(handle, srcPlanes, width, strides, height, - jpegBuf, jpegSize); - -bailout: - return retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjCompressFromYUV(tjhandle handle, const unsigned char *srcBuf, - int width, int align, int height, int subsamp, - unsigned char **jpegBuf, - unsigned long *jpegSize, int jpegQual, - int flags) -{ - static const char FUNCTION_NAME[] = "tjCompressFromYUV"; - int retval = -1; - size_t size; - - GET_TJINSTANCE(handle, -1); - - if (subsamp < 0 || subsamp >= TJ_NUMSAMP) - THROW("Invalid argument"); - - this->quality = jpegQual; - this->subsamp = subsamp; - processFlags(handle, flags, COMPRESS); - - size = (size_t)(*jpegSize); - retval = tj3CompressFromYUV8(handle, srcBuf, width, align, height, jpegBuf, - &size); - *jpegSize = (unsigned long)size; - -bailout: - return retval; -} - - -/******************************* Decompressor ********************************/ - -static tjhandle _tjInitDecompress(tjinstance *this) -{ - static unsigned char buffer[1]; - - /* This is also straight out of example.c */ - this->dinfo.err = jpeg_std_error(&this->jerr.pub); - this->jerr.pub.error_exit = my_error_exit; - this->jerr.pub.output_message = my_output_message; - this->jerr.emit_message = this->jerr.pub.emit_message; - this->jerr.pub.emit_message = my_emit_message; - this->jerr.pub.addon_message_table = turbojpeg_message_table; - this->jerr.pub.first_addon_message = JMSG_FIRSTADDONCODE; - this->jerr.pub.last_addon_message = JMSG_LASTADDONCODE; - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - free(this); - return NULL; - } - - jpeg_create_decompress(&this->dinfo); - /* Make an initial call so it will create the source manager */ - jpeg_mem_src_tj(&this->dinfo, buffer, 1); - - this->init |= DECOMPRESS; - return (tjhandle)this; -} - -/* TurboJPEG 1.0+ */ -DLLEXPORT tjhandle tjInitDecompress(void) -{ - return tj3Init(TJINIT_DECOMPRESS); -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3DecompressHeader(tjhandle handle, - const unsigned char *jpegBuf, - size_t jpegSize) -{ - static const char FUNCTION_NAME[] = "tj3DecompressHeader"; - int retval = 0; - - GET_DINSTANCE(handle); - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - if (jpegBuf == NULL || jpegSize <= 0) - THROW("Invalid argument"); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - return -1; - } - - jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - - /* jpeg_read_header() calls jpeg_abort() and returns JPEG_HEADER_TABLES_ONLY - if the datastream is a tables-only datastream. Since we aren't using a - suspending data source, the only other value it can return is - JPEG_HEADER_OK. */ - if (jpeg_read_header(dinfo, FALSE) == JPEG_HEADER_TABLES_ONLY) - return 0; - - setDecompParameters(this); - - jpeg_abort_decompress(dinfo); - - if (this->colorspace < 0) - THROW("Could not determine colorspace of JPEG image"); - if (this->jpegWidth < 1 || this->jpegHeight < 1) - THROW("Invalid data returned in header"); - -bailout: - if (this->jerr.warning) retval = -1; - return retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjDecompressHeader3(tjhandle handle, - const unsigned char *jpegBuf, - unsigned long jpegSize, int *width, - int *height, int *jpegSubsamp, - int *jpegColorspace) -{ - static const char FUNCTION_NAME[] = "tjDecompressHeader3"; - int retval = 0; - - GET_TJINSTANCE(handle, -1); - - if (width == NULL || height == NULL || jpegSubsamp == NULL || - jpegColorspace == NULL) - THROW("Invalid argument"); - - retval = tj3DecompressHeader(handle, jpegBuf, jpegSize); - - *width = tj3Get(handle, TJPARAM_JPEGWIDTH); - *height = tj3Get(handle, TJPARAM_JPEGHEIGHT); - *jpegSubsamp = tj3Get(handle, TJPARAM_SUBSAMP); - if (*jpegSubsamp == TJSAMP_UNKNOWN) - THROW("Could not determine subsampling level of JPEG image"); - *jpegColorspace = tj3Get(handle, TJPARAM_COLORSPACE); - -bailout: - return retval; -} - -/* TurboJPEG 1.1+ */ -DLLEXPORT int tjDecompressHeader2(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, int *width, - int *height, int *jpegSubsamp) -{ - int jpegColorspace; - - return tjDecompressHeader3(handle, jpegBuf, jpegSize, width, height, - jpegSubsamp, &jpegColorspace); -} - -/* TurboJPEG 1.0+ */ -DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, int *width, - int *height) -{ - int jpegSubsamp; - - return tjDecompressHeader2(handle, jpegBuf, jpegSize, width, height, - &jpegSubsamp); -} - - -/* TurboJPEG 3+ */ -DLLEXPORT tjscalingfactor *tj3GetScalingFactors(int *numScalingFactors) -{ - static const char FUNCTION_NAME[] = "tj3GetScalingFactors"; - tjscalingfactor *retval = (tjscalingfactor *)sf; - - if (numScalingFactors == NULL) - THROWG("Invalid argument", NULL); - - *numScalingFactors = NUMSF; - -bailout: - return retval; -} - -/* TurboJPEG 1.2+ */ -DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numScalingFactors) -{ - return tj3GetScalingFactors(numScalingFactors); -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3SetScalingFactor(tjhandle handle, - tjscalingfactor scalingFactor) -{ - static const char FUNCTION_NAME[] = "tj3SetScalingFactor"; - int i, retval = 0; - - GET_TJINSTANCE(handle, -1); - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - for (i = 0; i < NUMSF; i++) { - if (scalingFactor.num == sf[i].num && scalingFactor.denom == sf[i].denom) - break; - } - if (i >= NUMSF) - THROW("Unsupported scaling factor"); - - this->scalingFactor = scalingFactor; - -bailout: - return retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3SetCroppingRegion(tjhandle handle, tjregion croppingRegion) -{ - static const char FUNCTION_NAME[] = "tj3SetCroppingRegion"; - int retval = 0, scaledWidth, scaledHeight; - - GET_TJINSTANCE(handle, -1); - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - if (croppingRegion.x == 0 && croppingRegion.y == 0 && - croppingRegion.w == 0 && croppingRegion.h == 0) { - this->croppingRegion = croppingRegion; - return 0; - } - - if (croppingRegion.x < 0 || croppingRegion.y < 0 || croppingRegion.w < 0 || - croppingRegion.h < 0) - THROW("Invalid cropping region"); - if (this->jpegWidth < 0 || this->jpegHeight < 0) - THROW("JPEG header has not yet been read"); - if (this->precision == 16 || this->lossless) - THROW("Cannot partially decompress lossless JPEG images"); - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("Could not determine subsampling level of JPEG image"); - - scaledWidth = TJSCALED(this->jpegWidth, this->scalingFactor); - scaledHeight = TJSCALED(this->jpegHeight, this->scalingFactor); - - if (croppingRegion.x % - TJSCALED(tjMCUWidth[this->subsamp], this->scalingFactor) != 0) - THROWI("The left boundary of the cropping region (%d) is not\n" - "divisible by the scaled MCU width (%d)", - croppingRegion.x, - TJSCALED(tjMCUWidth[this->subsamp], this->scalingFactor)); - if (croppingRegion.w == 0) - croppingRegion.w = scaledWidth - croppingRegion.x; - if (croppingRegion.h == 0) - croppingRegion.h = scaledHeight - croppingRegion.y; - if (croppingRegion.w < 0 || croppingRegion.h < 0 || - croppingRegion.x + croppingRegion.w > scaledWidth || - croppingRegion.y + croppingRegion.h > scaledHeight) - THROW("The cropping region exceeds the scaled image dimensions"); - - this->croppingRegion = croppingRegion; - -bailout: - return retval; -} - - -/* tj3Decompress*() is implemented in turbojpeg-mp.c */ - -/* TurboJPEG 1.2+ */ -DLLEXPORT int tjDecompress2(tjhandle handle, const unsigned char *jpegBuf, - unsigned long jpegSize, unsigned char *dstBuf, - int width, int pitch, int height, int pixelFormat, - int flags) -{ - static const char FUNCTION_NAME[] = "tjDecompress2"; - int i, retval = 0, jpegwidth, jpegheight, scaledw, scaledh; - - GET_DINSTANCE(handle); - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - if (jpegBuf == NULL || jpegSize <= 0 || width < 0 || height < 0) - THROW("Invalid argument"); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - jpeg_read_header(dinfo, TRUE); - jpegwidth = dinfo->image_width; jpegheight = dinfo->image_height; - if (width == 0) width = jpegwidth; - if (height == 0) height = jpegheight; - for (i = 0; i < NUMSF; i++) { - scaledw = TJSCALED(jpegwidth, sf[i]); - scaledh = TJSCALED(jpegheight, sf[i]); - if (scaledw <= width && scaledh <= height) - break; - } - if (i >= NUMSF) - THROW("Could not scale down to desired image dimensions"); - - processFlags(handle, flags, DECOMPRESS); - - if (tj3SetScalingFactor(handle, sf[i]) == -1) - return -1; - if (tj3SetCroppingRegion(handle, TJUNCROPPED) == -1) - return -1; - return tj3Decompress8(handle, jpegBuf, jpegSize, dstBuf, pitch, pixelFormat); - -bailout: - if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo); - if (this->jerr.warning) retval = -1; - return retval; -} - -/* TurboJPEG 1.0+ */ -DLLEXPORT int tjDecompress(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, unsigned char *dstBuf, - int width, int pitch, int height, int pixelSize, - int flags) -{ - if (flags & TJ_YUV) - return tjDecompressToYUV(handle, jpegBuf, jpegSize, dstBuf, flags); - else - return tjDecompress2(handle, jpegBuf, jpegSize, dstBuf, width, pitch, - height, getPixelFormat(pixelSize, flags), flags); -} - - -static void setDecodeDefaults(tjinstance *this, int pixelFormat) -{ - int i; - - this->dinfo.scale_num = this->dinfo.scale_denom = 1; - - if (this->subsamp == TJSAMP_GRAY) { - this->dinfo.num_components = this->dinfo.comps_in_scan = 1; - this->dinfo.jpeg_color_space = JCS_GRAYSCALE; - } else { - this->dinfo.num_components = this->dinfo.comps_in_scan = 3; - this->dinfo.jpeg_color_space = JCS_YCbCr; - } - - this->dinfo.comp_info = (jpeg_component_info *) - (*this->dinfo.mem->alloc_small) ((j_common_ptr)&this->dinfo, JPOOL_IMAGE, - this->dinfo.num_components * - sizeof(jpeg_component_info)); - - for (i = 0; i < this->dinfo.num_components; i++) { - jpeg_component_info *compptr = &this->dinfo.comp_info[i]; - - compptr->h_samp_factor = (i == 0) ? tjMCUWidth[this->subsamp] / 8 : 1; - compptr->v_samp_factor = (i == 0) ? tjMCUHeight[this->subsamp] / 8 : 1; - compptr->component_index = i; - compptr->component_id = i + 1; - compptr->quant_tbl_no = compptr->dc_tbl_no = - compptr->ac_tbl_no = (i == 0) ? 0 : 1; - this->dinfo.cur_comp_info[i] = compptr; - } - this->dinfo.data_precision = 8; - for (i = 0; i < 2; i++) { - if (this->dinfo.quant_tbl_ptrs[i] == NULL) - this->dinfo.quant_tbl_ptrs[i] = - jpeg_alloc_quant_table((j_common_ptr)&this->dinfo); - } - - this->dinfo.mem->max_memory_to_use = (long)this->maxMemory * 1048576L; -} - - -static int my_read_markers(j_decompress_ptr dinfo) -{ - return JPEG_REACHED_SOS; -} - -static void my_reset_marker_reader(j_decompress_ptr dinfo) -{ -} - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3DecodeYUVPlanes8(tjhandle handle, - const unsigned char * const *srcPlanes, - const int *strides, unsigned char *dstBuf, - int width, int pitch, int height, - int pixelFormat) -{ - static const char FUNCTION_NAME[] = "tj3DecodeYUVPlanes8"; - JSAMPROW *row_pointer = NULL; - JSAMPLE *_tmpbuf[MAX_COMPONENTS]; - JSAMPROW *tmpbuf[MAX_COMPONENTS], *inbuf[MAX_COMPONENTS]; - int i, retval = 0, row, pw0, ph0, pw[MAX_COMPONENTS], ph[MAX_COMPONENTS]; - JSAMPLE *ptr; - jpeg_component_info *compptr; - int (*old_read_markers) (j_decompress_ptr); - void (*old_reset_marker_reader) (j_decompress_ptr); - - GET_DINSTANCE(handle); - - for (i = 0; i < MAX_COMPONENTS; i++) { - tmpbuf[i] = NULL; _tmpbuf[i] = NULL; inbuf[i] = NULL; - } - - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - if (!srcPlanes || !srcPlanes[0] || dstBuf == NULL || width <= 0 || - pitch < 0 || height <= 0 || pixelFormat < 0 || pixelFormat >= TJ_NUMPF) - THROW("Invalid argument"); - if (this->subsamp != TJSAMP_GRAY && (!srcPlanes[1] || !srcPlanes[2])) - THROW("Invalid argument"); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("TJPARAM_SUBSAMP must be specified"); - if (pixelFormat == TJPF_CMYK) - THROW("Cannot decode YUV images into packed-pixel CMYK images."); - - if (pitch == 0) pitch = width * tjPixelSize[pixelFormat]; - dinfo->image_width = width; - dinfo->image_height = height; - - dinfo->progressive_mode = dinfo->inputctl->has_multiple_scans = FALSE; - dinfo->Ss = dinfo->Ah = dinfo->Al = 0; - dinfo->Se = DCTSIZE2 - 1; - setDecodeDefaults(this, pixelFormat); - old_read_markers = dinfo->marker->read_markers; - dinfo->marker->read_markers = my_read_markers; - old_reset_marker_reader = dinfo->marker->reset_marker_reader; - dinfo->marker->reset_marker_reader = my_reset_marker_reader; - jpeg_read_header(dinfo, TRUE); - dinfo->marker->read_markers = old_read_markers; - dinfo->marker->reset_marker_reader = old_reset_marker_reader; - - this->dinfo.out_color_space = pf2cs[pixelFormat]; - this->dinfo.dct_method = this->fastDCT ? JDCT_FASTEST : JDCT_ISLOW; - dinfo->do_fancy_upsampling = FALSE; - dinfo->Se = DCTSIZE2 - 1; - jinit_master_decompress(dinfo); - (*dinfo->upsample->start_pass) (dinfo); - - pw0 = PAD(width, dinfo->max_h_samp_factor); - ph0 = PAD(height, dinfo->max_v_samp_factor); - - if (pitch == 0) pitch = dinfo->output_width * tjPixelSize[pixelFormat]; - - if ((row_pointer = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph0)) == NULL) - THROW("Memory allocation failure"); - for (i = 0; i < height; i++) { - if (this->bottomUp) - row_pointer[i] = &dstBuf[(height - i - 1) * (size_t)pitch]; - else - row_pointer[i] = &dstBuf[i * (size_t)pitch]; - } - if (height < ph0) - for (i = height; i < ph0; i++) row_pointer[i] = row_pointer[height - 1]; - - for (i = 0; i < dinfo->num_components; i++) { - compptr = &dinfo->comp_info[i]; - _tmpbuf[i] = - (JSAMPLE *)malloc(PAD(compptr->width_in_blocks * DCTSIZE, 32) * - compptr->v_samp_factor + 32); - if (!_tmpbuf[i]) - THROW("Memory allocation failure"); - tmpbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * compptr->v_samp_factor); - if (!tmpbuf[i]) - THROW("Memory allocation failure"); - for (row = 0; row < compptr->v_samp_factor; row++) { - unsigned char *_tmpbuf_aligned = - (unsigned char *)PAD((JUINTPTR)_tmpbuf[i], 32); - - tmpbuf[i][row] = - &_tmpbuf_aligned[PAD(compptr->width_in_blocks * DCTSIZE, 32) * row]; - } - pw[i] = pw0 * compptr->h_samp_factor / dinfo->max_h_samp_factor; - ph[i] = ph0 * compptr->v_samp_factor / dinfo->max_v_samp_factor; - inbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph[i]); - if (!inbuf[i]) - THROW("Memory allocation failure"); - ptr = (JSAMPLE *)srcPlanes[i]; - for (row = 0; row < ph[i]; row++) { - inbuf[i][row] = ptr; - ptr += (strides && strides[i] != 0) ? strides[i] : pw[i]; - } - } - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - for (row = 0; row < ph0; row += dinfo->max_v_samp_factor) { - JDIMENSION inrow = 0, outrow = 0; - - for (i = 0, compptr = dinfo->comp_info; i < dinfo->num_components; - i++, compptr++) - jcopy_sample_rows(inbuf[i], - row * compptr->v_samp_factor / dinfo->max_v_samp_factor, tmpbuf[i], 0, - compptr->v_samp_factor, pw[i]); - (dinfo->upsample->upsample) (dinfo, tmpbuf, &inrow, - dinfo->max_v_samp_factor, &row_pointer[row], - &outrow, dinfo->max_v_samp_factor); - } - jpeg_abort_decompress(dinfo); - -bailout: - if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo); - free(row_pointer); - for (i = 0; i < MAX_COMPONENTS; i++) { - free(tmpbuf[i]); - free(_tmpbuf[i]); - free(inbuf[i]); - } - if (this->jerr.warning) retval = -1; - return retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjDecodeYUVPlanes(tjhandle handle, - const unsigned char **srcPlanes, - const int *strides, int subsamp, - unsigned char *dstBuf, int width, int pitch, - int height, int pixelFormat, int flags) -{ - static const char FUNCTION_NAME[] = "tjDecodeYUVPlanes"; - int retval = 0; - - GET_TJINSTANCE(handle, -1); - - if (subsamp < 0 || subsamp >= TJ_NUMSAMP) - THROW("Invalid argument"); - - this->subsamp = subsamp; - processFlags(handle, flags, DECOMPRESS); - - return tj3DecodeYUVPlanes8(handle, srcPlanes, strides, dstBuf, width, pitch, - height, pixelFormat); - -bailout: - return retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3DecodeYUV8(tjhandle handle, const unsigned char *srcBuf, - int align, unsigned char *dstBuf, int width, - int pitch, int height, int pixelFormat) -{ - static const char FUNCTION_NAME[] = "tj3DecodeYUV8"; - const unsigned char *srcPlanes[3]; - int pw0, ph0, strides[3], retval = -1; - - GET_TJINSTANCE(handle, -1); - - if (srcBuf == NULL || align < 1 || !IS_POW2(align) || width <= 0 || - height <= 0) - THROW("Invalid argument"); - - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("TJPARAM_SUBSAMP must be specified"); - - pw0 = tj3YUVPlaneWidth(0, width, this->subsamp); - ph0 = tj3YUVPlaneHeight(0, height, this->subsamp); - srcPlanes[0] = srcBuf; - strides[0] = PAD(pw0, align); - if (this->subsamp == TJSAMP_GRAY) { - strides[1] = strides[2] = 0; - srcPlanes[1] = srcPlanes[2] = NULL; - } else { - int pw1 = tj3YUVPlaneWidth(1, width, this->subsamp); - int ph1 = tj3YUVPlaneHeight(1, height, this->subsamp); - - strides[1] = strides[2] = PAD(pw1, align); - if ((unsigned long long)strides[0] * (unsigned long long)ph0 > - (unsigned long long)INT_MAX || - (unsigned long long)strides[1] * (unsigned long long)ph1 > - (unsigned long long)INT_MAX) - THROW("Image or row alignment is too large"); - srcPlanes[1] = srcPlanes[0] + strides[0] * ph0; - srcPlanes[2] = srcPlanes[1] + strides[1] * ph1; - } - - return tj3DecodeYUVPlanes8(handle, srcPlanes, strides, dstBuf, width, pitch, - height, pixelFormat); - -bailout: - return retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf, - int align, int subsamp, unsigned char *dstBuf, - int width, int pitch, int height, int pixelFormat, - int flags) -{ - static const char FUNCTION_NAME[] = "tjDecodeYUV"; - int retval = -1; - - GET_TJINSTANCE(handle, -1); - - if (subsamp < 0 || subsamp >= TJ_NUMSAMP) - THROW("Invalid argument"); - - this->subsamp = subsamp; - processFlags(handle, flags, DECOMPRESS); - - return tj3DecodeYUV8(handle, srcBuf, align, dstBuf, width, pitch, height, - pixelFormat); - -bailout: - return retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3DecompressToYUVPlanes8(tjhandle handle, - const unsigned char *jpegBuf, - size_t jpegSize, - unsigned char **dstPlanes, - int *strides) -{ - static const char FUNCTION_NAME[] = "tj3DecompressToYUVPlanes8"; - int i, row, retval = 0; - int pw[MAX_COMPONENTS], ph[MAX_COMPONENTS], iw[MAX_COMPONENTS], - tmpbufsize = 0, usetmpbuf = 0, th[MAX_COMPONENTS]; - JSAMPLE *_tmpbuf = NULL, *ptr; - JSAMPROW *outbuf[MAX_COMPONENTS], *tmpbuf[MAX_COMPONENTS]; - int dctsize; - struct my_progress_mgr progress; - - GET_DINSTANCE(handle); - - for (i = 0; i < MAX_COMPONENTS; i++) { - tmpbuf[i] = NULL; outbuf[i] = NULL; - } - - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - if (jpegBuf == NULL || jpegSize <= 0 || !dstPlanes || !dstPlanes[0]) - THROW("Invalid argument"); - - if (this->scanLimit) { - memset(&progress, 0, sizeof(struct my_progress_mgr)); - progress.pub.progress_monitor = my_progress_monitor; - progress.this = this; - dinfo->progress = &progress.pub; - } else - dinfo->progress = NULL; - - dinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - if (dinfo->global_state <= DSTATE_INHEADER) { - jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - jpeg_read_header(dinfo, TRUE); - } - setDecompParameters(this); - if (this->maxPixels && - (unsigned long long)this->jpegWidth * this->jpegHeight > - (unsigned long long)this->maxPixels) - THROW("Image is too large"); - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("Could not determine subsampling level of JPEG image"); - - if (this->subsamp != TJSAMP_GRAY && (!dstPlanes[1] || !dstPlanes[2])) - THROW("Invalid argument"); - - if (dinfo->num_components > 3) - THROW("JPEG image must have 3 or fewer components"); - - dinfo->scale_num = this->scalingFactor.num; - dinfo->scale_denom = this->scalingFactor.denom; - jpeg_calc_output_dimensions(dinfo); - - dctsize = DCTSIZE * this->scalingFactor.num / this->scalingFactor.denom; - - for (i = 0; i < dinfo->num_components; i++) { - jpeg_component_info *compptr = &dinfo->comp_info[i]; - int ih; - - iw[i] = compptr->width_in_blocks * dctsize; - ih = compptr->height_in_blocks * dctsize; - pw[i] = tj3YUVPlaneWidth(i, dinfo->output_width, this->subsamp); - ph[i] = tj3YUVPlaneHeight(i, dinfo->output_height, this->subsamp); - if (iw[i] != pw[i] || ih != ph[i]) usetmpbuf = 1; - th[i] = compptr->v_samp_factor * dctsize; - tmpbufsize += iw[i] * th[i]; - if ((outbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * ph[i])) == NULL) - THROW("Memory allocation failure"); - ptr = dstPlanes[i]; - for (row = 0; row < ph[i]; row++) { - outbuf[i][row] = ptr; - ptr += (strides && strides[i] != 0) ? strides[i] : pw[i]; - } - } - if (usetmpbuf) { - if ((_tmpbuf = (JSAMPLE *)malloc(sizeof(JSAMPLE) * tmpbufsize)) == NULL) - THROW("Memory allocation failure"); - ptr = _tmpbuf; - for (i = 0; i < dinfo->num_components; i++) { - if ((tmpbuf[i] = (JSAMPROW *)malloc(sizeof(JSAMPROW) * th[i])) == NULL) - THROW("Memory allocation failure"); - for (row = 0; row < th[i]; row++) { - tmpbuf[i][row] = ptr; - ptr += iw[i]; - } - } - } - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - dinfo->do_fancy_upsampling = !this->fastUpsample; - dinfo->dct_method = this->fastDCT ? JDCT_FASTEST : JDCT_ISLOW; - dinfo->raw_data_out = TRUE; - - dinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; - - jpeg_start_decompress(dinfo); - for (row = 0; row < (int)dinfo->output_height; - row += dinfo->max_v_samp_factor * dinfo->_min_DCT_scaled_size) { - JSAMPARRAY yuvptr[MAX_COMPONENTS]; - int crow[MAX_COMPONENTS]; - - for (i = 0; i < dinfo->num_components; i++) { - jpeg_component_info *compptr = &dinfo->comp_info[i]; - - if (this->subsamp == TJSAMP_420) { - /* When 4:2:0 subsampling is used with IDCT scaling, libjpeg will try - to be clever and use the IDCT to perform upsampling on the U and V - planes. For instance, if the output image is to be scaled by 1/2 - relative to the JPEG image, then the scaling factor and upsampling - effectively cancel each other, so a normal 8x8 IDCT can be used. - However, this is not desirable when using the decompress-to-YUV - functionality in TurboJPEG, since we want to output the U and V - planes in their subsampled form. Thus, we have to override some - internal libjpeg parameters to force it to use the "scaled" IDCT - functions on the U and V planes. */ - compptr->_DCT_scaled_size = dctsize; - compptr->MCU_sample_width = tjMCUWidth[this->subsamp] * - this->scalingFactor.num / this->scalingFactor.denom * - compptr->v_samp_factor / dinfo->max_v_samp_factor; - dinfo->idct->inverse_DCT[i] = dinfo->idct->inverse_DCT[0]; - } - crow[i] = row * compptr->v_samp_factor / dinfo->max_v_samp_factor; - if (usetmpbuf) yuvptr[i] = tmpbuf[i]; - else yuvptr[i] = &outbuf[i][crow[i]]; - } - jpeg_read_raw_data(dinfo, yuvptr, - dinfo->max_v_samp_factor * dinfo->_min_DCT_scaled_size); - if (usetmpbuf) { - int j; - - for (i = 0; i < dinfo->num_components; i++) { - for (j = 0; j < MIN(th[i], ph[i] - crow[i]); j++) { - memcpy(outbuf[i][crow[i] + j], tmpbuf[i][j], pw[i]); - } - } - } - } - jpeg_finish_decompress(dinfo); - -bailout: - if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo); - for (i = 0; i < MAX_COMPONENTS; i++) { - free(tmpbuf[i]); - free(outbuf[i]); - } - free(_tmpbuf); - if (this->jerr.warning) retval = -1; - return retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjDecompressToYUVPlanes(tjhandle handle, - const unsigned char *jpegBuf, - unsigned long jpegSize, - unsigned char **dstPlanes, int width, - int *strides, int height, int flags) -{ - static const char FUNCTION_NAME[] = "tjDecompressToYUVPlanes"; - int i, retval = 0, jpegwidth, jpegheight, scaledw, scaledh; - - GET_DINSTANCE(handle); - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - if (jpegBuf == NULL || jpegSize <= 0 || width < 0 || height < 0) - THROW("Invalid argument"); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - jpeg_read_header(dinfo, TRUE); - jpegwidth = dinfo->image_width; jpegheight = dinfo->image_height; - if (width == 0) width = jpegwidth; - if (height == 0) height = jpegheight; - for (i = 0; i < NUMSF; i++) { - scaledw = TJSCALED(jpegwidth, sf[i]); - scaledh = TJSCALED(jpegheight, sf[i]); - if (scaledw <= width && scaledh <= height) - break; - } - if (i >= NUMSF) - THROW("Could not scale down to desired image dimensions"); - - processFlags(handle, flags, DECOMPRESS); - - if (tj3SetScalingFactor(handle, sf[i]) == -1) - return -1; - return tj3DecompressToYUVPlanes8(handle, jpegBuf, jpegSize, dstPlanes, - strides); - -bailout: - if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo); - if (this->jerr.warning) retval = -1; - return retval; -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3DecompressToYUV8(tjhandle handle, - const unsigned char *jpegBuf, - size_t jpegSize, - unsigned char *dstBuf, int align) -{ - static const char FUNCTION_NAME[] = "tj3DecompressToYUV8"; - unsigned char *dstPlanes[3]; - int pw0, ph0, strides[3], retval = -1; - int width, height; - - GET_DINSTANCE(handle); - - if (jpegBuf == NULL || jpegSize <= 0 || dstBuf == NULL || align < 1 || - !IS_POW2(align)) - THROW("Invalid argument"); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - if (dinfo->global_state <= DSTATE_INHEADER) { - jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - jpeg_read_header(dinfo, TRUE); - } - setDecompParameters(this); - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("Could not determine subsampling level of JPEG image"); - - width = TJSCALED(dinfo->image_width, this->scalingFactor); - height = TJSCALED(dinfo->image_height, this->scalingFactor); - - pw0 = tj3YUVPlaneWidth(0, width, this->subsamp); - ph0 = tj3YUVPlaneHeight(0, height, this->subsamp); - dstPlanes[0] = dstBuf; - strides[0] = PAD(pw0, align); - if (this->subsamp == TJSAMP_GRAY) { - strides[1] = strides[2] = 0; - dstPlanes[1] = dstPlanes[2] = NULL; - } else { - int pw1 = tj3YUVPlaneWidth(1, width, this->subsamp); - int ph1 = tj3YUVPlaneHeight(1, height, this->subsamp); - - strides[1] = strides[2] = PAD(pw1, align); - if ((unsigned long long)strides[0] * (unsigned long long)ph0 > - (unsigned long long)INT_MAX || - (unsigned long long)strides[1] * (unsigned long long)ph1 > - (unsigned long long)INT_MAX) - THROW("Image or row alignment is too large"); - dstPlanes[1] = dstPlanes[0] + strides[0] * ph0; - dstPlanes[2] = dstPlanes[1] + strides[1] * ph1; - } - - return tj3DecompressToYUVPlanes8(handle, jpegBuf, jpegSize, dstPlanes, - strides); - -bailout: - if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo); - if (this->jerr.warning) retval = -1; - return retval; -} - -/* TurboJPEG 1.4+ */ -DLLEXPORT int tjDecompressToYUV2(tjhandle handle, const unsigned char *jpegBuf, - unsigned long jpegSize, unsigned char *dstBuf, - int width, int align, int height, int flags) -{ - static const char FUNCTION_NAME[] = "tjDecompressToYUV2"; - int i, retval = 0, jpegwidth, jpegheight, scaledw, scaledh; - - GET_DINSTANCE(handle); - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - if (jpegBuf == NULL || jpegSize <= 0 || width < 0 || height < 0) - THROW("Invalid argument"); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - jpeg_read_header(dinfo, TRUE); - jpegwidth = dinfo->image_width; jpegheight = dinfo->image_height; - if (width == 0) width = jpegwidth; - if (height == 0) height = jpegheight; - for (i = 0; i < NUMSF; i++) { - scaledw = TJSCALED(jpegwidth, sf[i]); - scaledh = TJSCALED(jpegheight, sf[i]); - if (scaledw <= width && scaledh <= height) - break; - } - if (i >= NUMSF) - THROW("Could not scale down to desired image dimensions"); - - width = scaledw; height = scaledh; - - processFlags(handle, flags, DECOMPRESS); - - if (tj3SetScalingFactor(handle, sf[i]) == -1) - return -1; - return tj3DecompressToYUV8(handle, jpegBuf, (size_t)jpegSize, dstBuf, align); - -bailout: - if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo); - if (this->jerr.warning) retval = -1; - return retval; -} - -/* TurboJPEG 1.1+ */ -DLLEXPORT int tjDecompressToYUV(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, unsigned char *dstBuf, - int flags) -{ - return tjDecompressToYUV2(handle, jpegBuf, jpegSize, dstBuf, 0, 4, 0, flags); -} - - -/******************************** Transformer ********************************/ - -/* TurboJPEG 1.2+ */ -DLLEXPORT tjhandle tjInitTransform(void) -{ - return tj3Init(TJINIT_TRANSFORM); -} - - -/* TurboJPEG 3+ */ -DLLEXPORT int tj3Transform(tjhandle handle, const unsigned char *jpegBuf, - size_t jpegSize, int n, unsigned char **dstBufs, - size_t *dstSizes, const tjtransform *t) -{ - static const char FUNCTION_NAME[] = "tj3Transform"; - jpeg_transform_info *xinfo = NULL; - jvirt_barray_ptr *srccoefs, *dstcoefs; - int retval = 0, i, saveMarkers = 0; - boolean alloc = TRUE; - struct my_progress_mgr progress; - - GET_INSTANCE(handle); - if ((this->init & COMPRESS) == 0 || (this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for transformation"); - - if (jpegBuf == NULL || jpegSize <= 0 || n < 1 || dstBufs == NULL || - dstSizes == NULL || t == NULL) - THROW("Invalid argument"); - - if (this->scanLimit) { - memset(&progress, 0, sizeof(struct my_progress_mgr)); - progress.pub.progress_monitor = my_progress_monitor; - progress.this = this; - dinfo->progress = &progress.pub; - } else - dinfo->progress = NULL; - - dinfo->mem->max_memory_to_use = (long)this->maxMemory * 1048576L; - - if ((xinfo = - (jpeg_transform_info *)malloc(sizeof(jpeg_transform_info) * n)) == NULL) - THROW("Memory allocation failure"); - memset(xinfo, 0, sizeof(jpeg_transform_info) * n); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - if (dinfo->global_state <= DSTATE_INHEADER) - jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - - for (i = 0; i < n; i++) { - if (t[i].op < 0 || t[i].op >= TJ_NUMXOP) - THROW("Invalid transform operation"); - xinfo[i].transform = xformtypes[t[i].op]; - xinfo[i].perfect = (t[i].options & TJXOPT_PERFECT) ? 1 : 0; - xinfo[i].trim = (t[i].options & TJXOPT_TRIM) ? 1 : 0; - xinfo[i].force_grayscale = (t[i].options & TJXOPT_GRAY) ? 1 : 0; - xinfo[i].crop = (t[i].options & TJXOPT_CROP) ? 1 : 0; - if (n != 1 && t[i].op == TJXOP_HFLIP) xinfo[i].slow_hflip = 1; - else xinfo[i].slow_hflip = 0; - - if (xinfo[i].crop) { - xinfo[i].crop_xoffset = t[i].r.x; xinfo[i].crop_xoffset_set = JCROP_POS; - xinfo[i].crop_yoffset = t[i].r.y; xinfo[i].crop_yoffset_set = JCROP_POS; - if (t[i].r.w != 0) { - xinfo[i].crop_width = t[i].r.w; xinfo[i].crop_width_set = JCROP_POS; - } else - xinfo[i].crop_width = JCROP_UNSET; - if (t[i].r.h != 0) { - xinfo[i].crop_height = t[i].r.h; xinfo[i].crop_height_set = JCROP_POS; - } else - xinfo[i].crop_height = JCROP_UNSET; - } - if (!(t[i].options & TJXOPT_COPYNONE)) saveMarkers = 1; - } - - jcopy_markers_setup(dinfo, saveMarkers ? JCOPYOPT_ALL : JCOPYOPT_NONE); - if (dinfo->global_state <= DSTATE_INHEADER) - jpeg_read_header(dinfo, TRUE); - if (this->maxPixels && - (unsigned long long)dinfo->image_width * dinfo->image_height > - (unsigned long long)this->maxPixels) - THROW("Image is too large"); - this->subsamp = getSubsamp(&this->dinfo); - - for (i = 0; i < n; i++) { - if (!jtransform_request_workspace(dinfo, &xinfo[i])) - THROW("Transform is not perfect"); - - if (xinfo[i].crop) { - if (this->subsamp == TJSAMP_UNKNOWN) - THROW("Could not determine subsampling level of JPEG image"); - if ((t[i].r.x % tjMCUWidth[this->subsamp]) != 0 || - (t[i].r.y % tjMCUHeight[this->subsamp]) != 0) - THROWI("To crop this JPEG image, x must be a multiple of %d\n" - "and y must be a multiple of %d.", tjMCUWidth[this->subsamp], - tjMCUHeight[this->subsamp]); - } - } - - srccoefs = jpeg_read_coefficients(dinfo); - - for (i = 0; i < n; i++) { - int w, h; - - if (!xinfo[i].crop) { - w = dinfo->image_width; h = dinfo->image_height; - if (t[i].op == TJXOP_TRANSPOSE || t[i].op == TJXOP_TRANSVERSE || - t[i].op == TJXOP_ROT90 || t[i].op == TJXOP_ROT270) { - w = dinfo->image_height; h = dinfo->image_width; - } - } else { - w = xinfo[i].crop_width; h = xinfo[i].crop_height; - } - if (this->noRealloc) { - alloc = FALSE; dstSizes[i] = tj3JPEGBufSize(w, h, this->subsamp); - } - if (!(t[i].options & TJXOPT_NOOUTPUT)) - jpeg_mem_dest_tj(cinfo, &dstBufs[i], &dstSizes[i], alloc); - jpeg_copy_critical_parameters(dinfo, cinfo); - dstcoefs = jtransform_adjust_parameters(dinfo, cinfo, srccoefs, &xinfo[i]); - if (this->optimize || t[i].options & TJXOPT_OPTIMIZE) - cinfo->optimize_coding = TRUE; -#ifdef C_PROGRESSIVE_SUPPORTED - if (this->progressive || t[i].options & TJXOPT_PROGRESSIVE) - jpeg_simple_progression(cinfo); -#endif - if (this->arithmetic || t[i].options & TJXOPT_ARITHMETIC) { - cinfo->arith_code = TRUE; - cinfo->optimize_coding = FALSE; - } - if (!(t[i].options & TJXOPT_NOOUTPUT)) { - jpeg_write_coefficients(cinfo, dstcoefs); - jcopy_markers_execute(dinfo, cinfo, t[i].options & TJXOPT_COPYNONE ? - JCOPYOPT_NONE : JCOPYOPT_ALL); - } else - jinit_c_master_control(cinfo, TRUE); - jtransform_execute_transformation(dinfo, cinfo, srccoefs, &xinfo[i]); - if (t[i].customFilter) { - int ci, y; - JDIMENSION by; - - for (ci = 0; ci < cinfo->num_components; ci++) { - jpeg_component_info *compptr = &cinfo->comp_info[ci]; - tjregion arrayRegion = { 0, 0, 0, 0 }; - tjregion planeRegion = { 0, 0, 0, 0 }; - - arrayRegion.w = compptr->width_in_blocks * DCTSIZE; - arrayRegion.h = DCTSIZE; - planeRegion.w = compptr->width_in_blocks * DCTSIZE; - planeRegion.h = compptr->height_in_blocks * DCTSIZE; - - for (by = 0; by < compptr->height_in_blocks; - by += compptr->v_samp_factor) { - JBLOCKARRAY barray = (dinfo->mem->access_virt_barray) - ((j_common_ptr)dinfo, dstcoefs[ci], by, compptr->v_samp_factor, - TRUE); - - for (y = 0; y < compptr->v_samp_factor; y++) { - if (t[i].customFilter(barray[y][0], arrayRegion, planeRegion, ci, - i, (tjtransform *)&t[i]) == -1) - THROW("Error in custom filter"); - arrayRegion.y += DCTSIZE; - } - } - } - } - if (!(t[i].options & TJXOPT_NOOUTPUT)) jpeg_finish_compress(cinfo); - } - - jpeg_finish_decompress(dinfo); - -bailout: - if (cinfo->global_state > CSTATE_START) { - if (alloc) (*cinfo->dest->term_destination) (cinfo); - jpeg_abort_compress(cinfo); - } - if (dinfo->global_state > DSTATE_START) jpeg_abort_decompress(dinfo); - free(xinfo); - if (this->jerr.warning) retval = -1; - return retval; -} - -/* TurboJPEG 1.2+ */ -DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf, - unsigned long jpegSize, int n, - unsigned char **dstBufs, unsigned long *dstSizes, - tjtransform *t, int flags) -{ - static const char FUNCTION_NAME[] = "tjTransform"; - int i, retval = 0; - size_t *sizes = NULL; - - GET_DINSTANCE(handle); - if ((this->init & DECOMPRESS) == 0) - THROW("Instance has not been initialized for decompression"); - - if (n < 1 || dstSizes == NULL) - THROW("Invalid argument"); - - if (setjmp(this->jerr.setjmp_buffer)) { - /* If we get here, the JPEG code has signaled an error. */ - retval = -1; goto bailout; - } - - jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize); - jpeg_read_header(dinfo, TRUE); - if (getSubsamp(dinfo) == TJSAMP_UNKNOWN) - THROW("Could not determine subsampling level of JPEG image"); - processFlags(handle, flags, COMPRESS); - - if ((sizes = (size_t *)malloc(n * sizeof(size_t))) == NULL) - THROW("Memory allocation failure"); - for (i = 0; i < n; i++) - sizes[i] = (size_t)dstSizes[i]; - retval = tj3Transform(handle, jpegBuf, (size_t)jpegSize, n, dstBufs, sizes, - t); - for (i = 0; i < n; i++) - dstSizes[i] = (unsigned long)sizes[i]; - -bailout: - free(sizes); - return retval; -} - - -/*************************** Packed-Pixel Image I/O **************************/ - -/* tj3LoadImage*() is implemented in turbojpeg-mp.c */ - -/* TurboJPEG 2.0+ */ -DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width, - int align, int *height, - int *pixelFormat, int flags) -{ - tjhandle handle = NULL; - unsigned char *dstBuf = NULL; - - if ((handle = tj3Init(TJINIT_COMPRESS)) == NULL) return NULL; - - processFlags(handle, flags, COMPRESS); - - dstBuf = tj3LoadImage8(handle, filename, width, align, height, pixelFormat); - - tj3Destroy(handle); - return dstBuf; -} - - -/* tj3SaveImage*() is implemented in turbojpeg-mp.c */ - -/* TurboJPEG 2.0+ */ -DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer, - int width, int pitch, int height, int pixelFormat, - int flags) -{ - tjhandle handle = NULL; - int retval = -1; - - if ((handle = tj3Init(TJINIT_DECOMPRESS)) == NULL) return -1; - - processFlags(handle, flags, DECOMPRESS); - - retval = tj3SaveImage8(handle, filename, buffer, width, pitch, height, - pixelFormat); - - tj3Destroy(handle); - return retval; -} diff --git a/3rdparty/libjpeg-turbo/src/turbojpeg.h b/3rdparty/libjpeg-turbo/src/turbojpeg.h deleted file mode 100644 index 68b88a4104..0000000000 --- a/3rdparty/libjpeg-turbo/src/turbojpeg.h +++ /dev/null @@ -1,2328 +0,0 @@ -/* - * Copyright (C)2009-2015, 2017, 2020-2023 D. R. Commander. - * All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the libjpeg-turbo Project nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __TURBOJPEG_H__ -#define __TURBOJPEG_H__ - -#include - -#if defined(_WIN32) && defined(DLLDEFINE) -#define DLLEXPORT __declspec(dllexport) -#else -#define DLLEXPORT -#endif -#define DLLCALL - - -/** - * @addtogroup TurboJPEG - * TurboJPEG API. This API provides an interface for generating, decoding, and - * transforming planar YUV and JPEG images in memory. - * - * @anchor YUVnotes - * YUV Image Format Notes - * ---------------------- - * Technically, the JPEG format uses the YCbCr colorspace (which is technically - * not a colorspace but a color transform), but per the convention of the - * digital video community, the TurboJPEG API uses "YUV" to refer to an image - * format consisting of Y, Cb, and Cr image planes. - * - * Each plane is simply a 2D array of bytes, each byte representing the value - * of one of the components (Y, Cb, or Cr) at a particular location in the - * image. The width and height of each plane are determined by the image - * width, height, and level of chrominance subsampling. The luminance plane - * width is the image width padded to the nearest multiple of the horizontal - * subsampling factor (1 in the case of 4:4:4, grayscale, 4:4:0, or 4:4:1; 2 in - * the case of 4:2:2 or 4:2:0; 4 in the case of 4:1:1.) Similarly, the - * luminance plane height is the image height padded to the nearest multiple of - * the vertical subsampling factor (1 in the case of 4:4:4, 4:2:2, grayscale, - * or 4:1:1; 2 in the case of 4:2:0 or 4:4:0; 4 in the case of 4:4:1.) This is - * irrespective of any additional padding that may be specified as an argument - * to the various YUV functions. The chrominance plane width is equal to the - * luminance plane width divided by the horizontal subsampling factor, and the - * chrominance plane height is equal to the luminance plane height divided by - * the vertical subsampling factor. - * - * For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is - * used, then the luminance plane would be 36 x 35 bytes, and each of the - * chrominance planes would be 18 x 35 bytes. If you specify a row alignment - * of 4 bytes on top of this, then the luminance plane would be 36 x 35 bytes, - * and each of the chrominance planes would be 20 x 35 bytes. - * - * @{ - */ - - -/** - * The number of initialization options - */ -#define TJ_NUMINIT 3 - -/** - * Initialization options. - */ -enum TJINIT { - /** - * Initialize the TurboJPEG instance for compression. - */ - TJINIT_COMPRESS, - /** - * Initialize the TurboJPEG instance for decompression. - */ - TJINIT_DECOMPRESS, - /** - * Initialize the TurboJPEG instance for lossless transformation (both - * compression and decompression.) - */ - TJINIT_TRANSFORM -}; - - -/** - * The number of chrominance subsampling options - */ -#define TJ_NUMSAMP 7 - -/** - * Chrominance subsampling options. - * When pixels are converted from RGB to YCbCr (see #TJCS_YCbCr) or from CMYK - * to YCCK (see #TJCS_YCCK) as part of the JPEG compression process, some of - * the Cb and Cr (chrominance) components can be discarded or averaged together - * to produce a smaller image with little perceptible loss of image clarity. - * (The human eye is more sensitive to small changes in brightness than to - * small changes in color.) This is called "chrominance subsampling". - */ -enum TJSAMP { - /** - * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or - * YUV image will contain one chrominance component for every pixel in the - * source image. - */ - TJSAMP_444, - /** - * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one - * chrominance component for every 2x1 block of pixels in the source image. - */ - TJSAMP_422, - /** - * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one - * chrominance component for every 2x2 block of pixels in the source image. - */ - TJSAMP_420, - /** - * Grayscale. The JPEG or YUV image will contain no chrominance components. - */ - TJSAMP_GRAY, - /** - * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one - * chrominance component for every 1x2 block of pixels in the source image. - * - * @note 4:4:0 subsampling is not fully accelerated in libjpeg-turbo. - */ - TJSAMP_440, - /** - * 4:1:1 chrominance subsampling. The JPEG or YUV image will contain one - * chrominance component for every 4x1 block of pixels in the source image. - * JPEG images compressed with 4:1:1 subsampling will be almost exactly the - * same size as those compressed with 4:2:0 subsampling, and in the - * aggregate, both subsampling methods produce approximately the same - * perceptual quality. However, 4:1:1 is better able to reproduce sharp - * horizontal features. - * - * @note 4:1:1 subsampling is not fully accelerated in libjpeg-turbo. - */ - TJSAMP_411, - /** - * 4:4:1 chrominance subsampling. The JPEG or YUV image will contain one - * chrominance component for every 1x4 block of pixels in the source image. - * JPEG images compressed with 4:4:1 subsampling will be almost exactly the - * same size as those compressed with 4:2:0 subsampling, and in the - * aggregate, both subsampling methods produce approximately the same - * perceptual quality. However, 4:4:1 is better able to reproduce sharp - * vertical features. - * - * @note 4:4:1 subsampling is not fully accelerated in libjpeg-turbo. - */ - TJSAMP_441, - /** - * Unknown subsampling. The JPEG image uses an unusual type of chrominance - * subsampling. Such images can be decompressed into packed-pixel images, - * but they cannot be - * - decompressed into planar YUV images, - * - losslessly transformed if #TJXOPT_CROP is specified, or - * - partially decompressed using a cropping region. - */ - TJSAMP_UNKNOWN = -1 -}; - -/** - * MCU block width (in pixels) for a given level of chrominance subsampling. - * MCU block sizes: - * - 8x8 for no subsampling or grayscale - * - 16x8 for 4:2:2 - * - 8x16 for 4:4:0 - * - 16x16 for 4:2:0 - * - 32x8 for 4:1:1 - * - 8x32 for 4:4:1 - */ -static const int tjMCUWidth[TJ_NUMSAMP] = { 8, 16, 16, 8, 8, 32, 8 }; - -/** - * MCU block height (in pixels) for a given level of chrominance subsampling. - * MCU block sizes: - * - 8x8 for no subsampling or grayscale - * - 16x8 for 4:2:2 - * - 8x16 for 4:4:0 - * - 16x16 for 4:2:0 - * - 32x8 for 4:1:1 - * - 8x32 for 4:4:1 - */ -static const int tjMCUHeight[TJ_NUMSAMP] = { 8, 8, 16, 8, 16, 8, 32 }; - - -/** - * The number of pixel formats - */ -#define TJ_NUMPF 12 - -/** - * Pixel formats - */ -enum TJPF { - /** - * RGB pixel format. The red, green, and blue components in the image are - * stored in 3-sample pixels in the order R, G, B from lowest to highest - * memory address within each pixel. - */ - TJPF_RGB, - /** - * BGR pixel format. The red, green, and blue components in the image are - * stored in 3-sample pixels in the order B, G, R from lowest to highest - * memory address within each pixel. - */ - TJPF_BGR, - /** - * RGBX pixel format. The red, green, and blue components in the image are - * stored in 4-sample pixels in the order R, G, B from lowest to highest - * memory address within each pixel. The X component is ignored when - * compressing and undefined when decompressing. - */ - TJPF_RGBX, - /** - * BGRX pixel format. The red, green, and blue components in the image are - * stored in 4-sample pixels in the order B, G, R from lowest to highest - * memory address within each pixel. The X component is ignored when - * compressing and undefined when decompressing. - */ - TJPF_BGRX, - /** - * XBGR pixel format. The red, green, and blue components in the image are - * stored in 4-sample pixels in the order R, G, B from highest to lowest - * memory address within each pixel. The X component is ignored when - * compressing and undefined when decompressing. - */ - TJPF_XBGR, - /** - * XRGB pixel format. The red, green, and blue components in the image are - * stored in 4-sample pixels in the order B, G, R from highest to lowest - * memory address within each pixel. The X component is ignored when - * compressing and undefined when decompressing. - */ - TJPF_XRGB, - /** - * Grayscale pixel format. Each 1-sample pixel represents a luminance - * (brightness) level from 0 to the maximum sample value (255 for 8-bit - * samples, 4095 for 12-bit samples, and 65535 for 16-bit samples.) - */ - TJPF_GRAY, - /** - * RGBA pixel format. This is the same as @ref TJPF_RGBX, except that when - * decompressing, the X component is guaranteed to be equal to the maximum - * sample value, which can be interpreted as an opaque alpha channel. - */ - TJPF_RGBA, - /** - * BGRA pixel format. This is the same as @ref TJPF_BGRX, except that when - * decompressing, the X component is guaranteed to be equal to the maximum - * sample value, which can be interpreted as an opaque alpha channel. - */ - TJPF_BGRA, - /** - * ABGR pixel format. This is the same as @ref TJPF_XBGR, except that when - * decompressing, the X component is guaranteed to be equal to the maximum - * sample value, which can be interpreted as an opaque alpha channel. - */ - TJPF_ABGR, - /** - * ARGB pixel format. This is the same as @ref TJPF_XRGB, except that when - * decompressing, the X component is guaranteed to be equal to the maximum - * sample value, which can be interpreted as an opaque alpha channel. - */ - TJPF_ARGB, - /** - * CMYK pixel format. Unlike RGB, which is an additive color model used - * primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive - * color model used primarily for printing. In the CMYK color model, the - * value of each color component typically corresponds to an amount of cyan, - * magenta, yellow, or black ink that is applied to a white background. In - * order to convert between CMYK and RGB, it is necessary to use a color - * management system (CMS.) A CMS will attempt to map colors within the - * printer's gamut to perceptually similar colors in the display's gamut and - * vice versa, but the mapping is typically not 1:1 or reversible, nor can it - * be defined with a simple formula. Thus, such a conversion is out of scope - * for a codec library. However, the TurboJPEG API allows for compressing - * packed-pixel CMYK images into YCCK JPEG images (see #TJCS_YCCK) and - * decompressing YCCK JPEG images into packed-pixel CMYK images. - */ - TJPF_CMYK, - /** - * Unknown pixel format. Currently this is only used by #tj3LoadImage8(), - * #tj3LoadImage12(), and #tj3LoadImage16(). - */ - TJPF_UNKNOWN = -1 -}; - -/** - * Red offset (in samples) for a given pixel format. This specifies the number - * of samples that the red component is offset from the start of the pixel. - * For instance, if an 8-bit-per-component pixel of format TJPF_BGRX is stored - * in `unsigned char pixel[]`, then the red component will be - * `pixel[tjRedOffset[TJPF_BGRX]]`. This will be -1 if the pixel format does - * not have a red component. - */ -static const int tjRedOffset[TJ_NUMPF] = { - 0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1 -}; -/** - * Green offset (in samples) for a given pixel format. This specifies the - * number of samples that the green component is offset from the start of the - * pixel. For instance, if an 8-bit-per-component pixel of format TJPF_BGRX is - * stored in `unsigned char pixel[]`, then the green component will be - * `pixel[tjGreenOffset[TJPF_BGRX]]`. This will be -1 if the pixel format does - * not have a green component. - */ -static const int tjGreenOffset[TJ_NUMPF] = { - 1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1 -}; -/** - * Blue offset (in samples) for a given pixel format. This specifies the - * number of samples that the blue component is offset from the start of the - * pixel. For instance, if an 8-bit-per-component pixel of format TJPF_BGRX is - * stored in `unsigned char pixel[]`, then the blue component will be - * `pixel[tjBlueOffset[TJPF_BGRX]]`. This will be -1 if the pixel format does - * not have a blue component. - */ -static const int tjBlueOffset[TJ_NUMPF] = { - 2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1 -}; -/** - * Alpha offset (in samples) for a given pixel format. This specifies the - * number of samples that the alpha component is offset from the start of the - * pixel. For instance, if an 8-bit-per-component pixel of format TJPF_BGRA is - * stored in `unsigned char pixel[]`, then the alpha component will be - * `pixel[tjAlphaOffset[TJPF_BGRA]]`. This will be -1 if the pixel format does - * not have an alpha component. - */ -static const int tjAlphaOffset[TJ_NUMPF] = { - -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1 -}; -/** - * Pixel size (in samples) for a given pixel format - */ -static const int tjPixelSize[TJ_NUMPF] = { - 3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4 -}; - - -/** - * The number of JPEG colorspaces - */ -#define TJ_NUMCS 5 - -/** - * JPEG colorspaces - */ -enum TJCS { - /** - * RGB colorspace. When compressing the JPEG image, the R, G, and B - * components in the source image are reordered into image planes, but no - * colorspace conversion or subsampling is performed. RGB JPEG images can be - * compressed from and decompressed to packed-pixel images with any of the - * extended RGB or grayscale pixel formats, but they cannot be compressed - * from or decompressed to planar YUV images. - */ - TJCS_RGB, - /** - * YCbCr colorspace. YCbCr is not an absolute colorspace but rather a - * mathematical transformation of RGB designed solely for storage and - * transmission. YCbCr images must be converted to RGB before they can - * actually be displayed. In the YCbCr colorspace, the Y (luminance) - * component represents the black & white portion of the original image, and - * the Cb and Cr (chrominance) components represent the color portion of the - * original image. Originally, the analog equivalent of this transformation - * allowed the same signal to drive both black & white and color televisions, - * but JPEG images use YCbCr primarily because it allows the color data to be - * optionally subsampled for the purposes of reducing network or disk usage. - * YCbCr is the most common JPEG colorspace, and YCbCr JPEG images can be - * compressed from and decompressed to packed-pixel images with any of the - * extended RGB or grayscale pixel formats. YCbCr JPEG images can also be - * compressed from and decompressed to planar YUV images. - */ - TJCS_YCbCr, - /** - * Grayscale colorspace. The JPEG image retains only the luminance data (Y - * component), and any color data from the source image is discarded. - * Grayscale JPEG images can be compressed from and decompressed to - * packed-pixel images with any of the extended RGB or grayscale pixel - * formats, or they can be compressed from and decompressed to planar YUV - * images. - */ - TJCS_GRAY, - /** - * CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K - * components in the source image are reordered into image planes, but no - * colorspace conversion or subsampling is performed. CMYK JPEG images can - * only be compressed from and decompressed to packed-pixel images with the - * CMYK pixel format. - */ - TJCS_CMYK, - /** - * YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but - * rather a mathematical transformation of CMYK designed solely for storage - * and transmission. It is to CMYK as YCbCr is to RGB. CMYK pixels can be - * reversibly transformed into YCCK, and as with YCbCr, the chrominance - * components in the YCCK pixels can be subsampled without incurring major - * perceptual loss. YCCK JPEG images can only be compressed from and - * decompressed to packed-pixel images with the CMYK pixel format. - */ - TJCS_YCCK -}; - - -/** - * Parameters - */ -enum TJPARAM { - /** - * Error handling behavior - * - * **Value** - * - `0` *[default]* Allow the current compression/decompression/transform - * operation to complete unless a fatal error is encountered. - * - `1` Immediately discontinue the current - * compression/decompression/transform operation if a warning (non-fatal - * error) occurs. - */ - TJPARAM_STOPONWARNING, - /** - * Row order in packed-pixel source/destination images - * - * **Value** - * - `0` *[default]* top-down (X11) order - * - `1` bottom-up (Windows, OpenGL) order - */ - TJPARAM_BOTTOMUP, - /** - * JPEG destination buffer (re)allocation [compression, lossless - * transformation] - * - * **Value** - * - `0` *[default]* Attempt to allocate or reallocate the JPEG destination - * buffer as needed. - * - `1` Generate an error if the JPEG destination buffer is invalid or too - * small. - */ - TJPARAM_NOREALLOC, - /** - * Perceptual quality of lossy JPEG images [compression only] - * - * **Value** - * - `1`-`100` (`1` = worst quality but best compression, `100` = best - * quality but worst compression) *[no default; must be explicitly - * specified]* - */ - TJPARAM_QUALITY, - /** - * Chrominance subsampling level - * - * The JPEG or YUV image uses (decompression, decoding) or will use (lossy - * compression, encoding) the specified level of chrominance subsampling. - * - * **Value** - * - One of the @ref TJSAMP "chrominance subsampling options" *[no default; - * must be explicitly specified for lossy compression, encoding, and - * decoding]* - */ - TJPARAM_SUBSAMP, - /** - * JPEG width (in pixels) [decompression only, read-only] - */ - TJPARAM_JPEGWIDTH, - /** - * JPEG height (in pixels) [decompression only, read-only] - */ - TJPARAM_JPEGHEIGHT, - /** - * JPEG data precision (bits per sample) [decompression only, read-only] - * - * The JPEG image uses the specified number of bits per sample. - * - * **Value** - * - `8`, `12`, or `16` - * - * 12-bit data precision implies #TJPARAM_OPTIMIZE unless #TJPARAM_ARITHMETIC - * is set. - */ - TJPARAM_PRECISION, - /** - * JPEG colorspace - * - * The JPEG image uses (decompression) or will use (lossy compression) the - * specified colorspace. - * - * **Value** - * - One of the @ref TJCS "JPEG colorspaces" *[default for lossy compression: - * automatically selected based on the subsampling level and pixel format]* - */ - TJPARAM_COLORSPACE, - /** - * Chrominance upsampling algorithm [lossy decompression only] - * - * **Value** - * - `0` *[default]* Use smooth upsampling when decompressing a JPEG image - * that was compressed using chrominance subsampling. This creates a smooth - * transition between neighboring chrominance components in order to reduce - * upsampling artifacts in the decompressed image. - * - `1` Use the fastest chrominance upsampling algorithm available, which - * may combine upsampling with color conversion. - */ - TJPARAM_FASTUPSAMPLE, - /** - * DCT/IDCT algorithm [lossy compression and decompression] - * - * **Value** - * - `0` *[default]* Use the most accurate DCT/IDCT algorithm available. - * - `1` Use the fastest DCT/IDCT algorithm available. - * - * This parameter is provided mainly for backward compatibility with libjpeg, - * which historically implemented several different DCT/IDCT algorithms - * because of performance limitations with 1990s CPUs. In the libjpeg-turbo - * implementation of the TurboJPEG API: - * - The "fast" and "accurate" DCT/IDCT algorithms perform similarly on - * modern x86/x86-64 CPUs that support AVX2 instructions. - * - The "fast" algorithm is generally only about 5-15% faster than the - * "accurate" algorithm on other types of CPUs. - * - The difference in accuracy between the "fast" and "accurate" algorithms - * is the most pronounced at JPEG quality levels above 90 and tends to be - * more pronounced with decompression than with compression. - * - The "fast" algorithm degrades and is not fully accelerated for JPEG - * quality levels above 97, so it will be slower than the "accurate" - * algorithm. - */ - TJPARAM_FASTDCT, - /** - * Optimized baseline entropy coding [lossy compression only] - * - * **Value** - * - `0` *[default]* The JPEG image will use the default Huffman tables. - * - `1` Optimal Huffman tables will be computed for the JPEG image. For - * lossless transformation, this can also be specified using - * #TJXOPT_OPTIMIZE. - * - * Optimized baseline entropy coding will improve compression slightly - * (generally 5% or less), but it will reduce compression performance - * considerably. - */ - TJPARAM_OPTIMIZE, - /** - * Progressive entropy coding - * - * **Value** - * - `0` *[default for compression, lossless transformation]* The lossy JPEG - * image uses (decompression) or will use (compression, lossless - * transformation) baseline entropy coding. - * - `1` The lossy JPEG image uses (decompression) or will use (compression, - * lossless transformation) progressive entropy coding. For lossless - * transformation, this can also be specified using #TJXOPT_PROGRESSIVE. - * - * Progressive entropy coding will generally improve compression relative to - * baseline entropy coding, but it will reduce compression and decompression - * performance considerably. Can be combined with #TJPARAM_ARITHMETIC. - * Implies #TJPARAM_OPTIMIZE unless #TJPARAM_ARITHMETIC is also set. - */ - TJPARAM_PROGRESSIVE, - /** - * Progressive JPEG scan limit for lossy JPEG images [decompression, lossless - * transformation] - * - * Setting this parameter will cause the decompression and transform - * functions to return an error if the number of scans in a progressive JPEG - * image exceeds the specified limit. The primary purpose of this is to - * allow security-critical applications to guard against an exploit of the - * progressive JPEG format described in - * this report. - * - * **Value** - * - maximum number of progressive JPEG scans that the decompression and - * transform functions will process *[default: `0` (no limit)]* - * - * @see #TJPARAM_PROGRESSIVE - */ - TJPARAM_SCANLIMIT, - /** - * Arithmetic entropy coding - * - * **Value** - * - `0` *[default for compression, lossless transformation]* The lossy JPEG - * image uses (decompression) or will use (compression, lossless - * transformation) Huffman entropy coding. - * - `1` The lossy JPEG image uses (decompression) or will use (compression, - * lossless transformation) arithmetic entropy coding. For lossless - * transformation, this can also be specified using #TJXOPT_ARITHMETIC. - * - * Arithmetic entropy coding will generally improve compression relative to - * Huffman entropy coding, but it will reduce compression and decompression - * performance considerably. Can be combined with #TJPARAM_PROGRESSIVE. - */ - TJPARAM_ARITHMETIC, - /** - * Lossless JPEG - * - * **Value** - * - `0` *[default for compression]* The JPEG image is (decompression) or - * will be (compression) lossy/DCT-based. - * - `1` The JPEG image is (decompression) or will be (compression) - * lossless/predictive. - * - * In most cases, compressing and decompressing lossless JPEG images is - * considerably slower than compressing and decompressing lossy JPEG images, - * and lossless JPEG images are much larger than lossy JPEG images. Thus, - * lossless JPEG images are typically used only for applications that require - * mathematically lossless compression. Also note that the following - * features are not available with lossless JPEG images: - * - Colorspace conversion (lossless JPEG images always use #TJCS_RGB, - * #TJCS_GRAY, or #TJCS_CMYK, depending on the pixel format of the source - * image) - * - Chrominance subsampling (lossless JPEG images always use #TJSAMP_444) - * - JPEG quality selection - * - DCT/IDCT algorithm selection - * - Progressive entropy coding - * - Arithmetic entropy coding - * - Compression from/decompression to planar YUV images - * - Decompression scaling - * - Lossless transformation - * - * @see #TJPARAM_LOSSLESSPSV, #TJPARAM_LOSSLESSPT - */ - TJPARAM_LOSSLESS, - /** - * Lossless JPEG predictor selection value (PSV) - * - * **Value** - * - `1`-`7` *[default for compression: `1`]* - * - * Lossless JPEG compression shares no algorithms with lossy JPEG - * compression. Instead, it uses differential pulse-code modulation (DPCM), - * an algorithm whereby each sample is encoded as the difference between the - * sample's value and a "predictor", which is based on the values of - * neighboring samples. If Ra is the sample immediately to the left of the - * current sample, Rb is the sample immediately above the current sample, and - * Rc is the sample diagonally to the left and above the current sample, then - * the relationship between the predictor selection value and the predictor - * is as follows: - * - * PSV | Predictor - * ----|---------- - * 1 | Ra - * 2 | Rb - * 3 | Rc - * 4 | Ra + Rb – Rc - * 5 | Ra + (Rb – Rc) / 2 - * 6 | Rb + (Ra – Rc) / 2 - * 7 | (Ra + Rb) / 2 - * - * Predictors 1-3 are 1-dimensional predictors, whereas Predictors 4-7 are - * 2-dimensional predictors. The best predictor for a particular image - * depends on the image. - * - * @see #TJPARAM_LOSSLESS - */ - TJPARAM_LOSSLESSPSV, - /** - * Lossless JPEG point transform (Pt) - * - * **Value** - * - `0` through ***precision*** *- 1*, where ***precision*** is the JPEG - * data precision in bits *[default for compression: `0`]* - * - * A point transform value of `0` is necessary in order to generate a fully - * lossless JPEG image. (A non-zero point transform value right-shifts the - * input samples by the specified number of bits, which is effectively a form - * of lossy color quantization.) - * - * @see #TJPARAM_LOSSLESS, #TJPARAM_PRECISION - */ - TJPARAM_LOSSLESSPT, - /** - * JPEG restart marker interval in MCU blocks (lossy) or samples (lossless) - * [compression only] - * - * The nature of entropy coding is such that a corrupt JPEG image cannot - * be decompressed beyond the point of corruption unless it contains restart - * markers. A restart marker stops and restarts the entropy coding algorithm - * so that, if a JPEG image is corrupted, decompression can resume at the - * next marker. Thus, adding more restart markers improves the fault - * tolerance of the JPEG image, but adding too many restart markers can - * adversely affect the compression ratio and performance. - * - * **Value** - * - the number of MCU blocks or samples between each restart marker - * *[default: `0` (no restart markers)]* - * - * Setting this parameter to a non-zero value sets #TJPARAM_RESTARTROWS to 0. - */ - TJPARAM_RESTARTBLOCKS, - /** - * JPEG restart marker interval in MCU rows (lossy) or sample rows (lossless) - * [compression only] - * - * See #TJPARAM_RESTARTBLOCKS for a description of restart markers. - * - * **Value** - * - the number of MCU rows or sample rows between each restart marker - * *[default: `0` (no restart markers)]* - * - * Setting this parameter to a non-zero value sets #TJPARAM_RESTARTBLOCKS to - * 0. - */ - TJPARAM_RESTARTROWS, - /** - * JPEG horizontal pixel density - * - * **Value** - * - The JPEG image has (decompression) or will have (compression) the - * specified horizontal pixel density *[default for compression: `1`]*. - * - * This value is stored in or read from the JPEG header. It does not affect - * the contents of the JPEG image. Note that this parameter is set by - * #tj3LoadImage8() when loading a Windows BMP file that contains pixel - * density information, and the value of this parameter is stored to a - * Windows BMP file by #tj3SaveImage8() if the value of #TJPARAM_DENSITYUNITS - * is `2`. - * - * @see TJPARAM_DENSITYUNITS - */ - TJPARAM_XDENSITY, - /** - * JPEG vertical pixel density - * - * **Value** - * - The JPEG image has (decompression) or will have (compression) the - * specified vertical pixel density *[default for compression: `1`]*. - * - * This value is stored in or read from the JPEG header. It does not affect - * the contents of the JPEG image. Note that this parameter is set by - * #tj3LoadImage8() when loading a Windows BMP file that contains pixel - * density information, and the value of this parameter is stored to a - * Windows BMP file by #tj3SaveImage8() if the value of #TJPARAM_DENSITYUNITS - * is `2`. - * - * @see TJPARAM_DENSITYUNITS - */ - TJPARAM_YDENSITY, - /** - * JPEG pixel density units - * - * **Value** - * - `0` *[default for compression]* The pixel density of the JPEG image is - * expressed (decompression) or will be expressed (compression) in unknown - * units. - * - `1` The pixel density of the JPEG image is expressed (decompression) or - * will be expressed (compression) in units of pixels/inch. - * - `2` The pixel density of the JPEG image is expressed (decompression) or - * will be expressed (compression) in units of pixels/cm. - * - * This value is stored in or read from the JPEG header. It does not affect - * the contents of the JPEG image. Note that this parameter is set by - * #tj3LoadImage8() when loading a Windows BMP file that contains pixel - * density information, and the value of this parameter is stored to a - * Windows BMP file by #tj3SaveImage8() if the value is `2`. - * - * @see TJPARAM_XDENSITY, TJPARAM_YDENSITY - */ - TJPARAM_DENSITYUNITS, - /** - * Memory limit for intermediate buffers - * - * **Value** - * - the maximum amount of memory (in megabytes) that will be allocated for - * intermediate buffers, which are used with progressive JPEG compression and - * decompression, optimized baseline entropy coding, lossless JPEG - * compression, and lossless transformation *[default: `0` (no limit)]* - */ - TJPARAM_MAXMEMORY, - /** - * Image size limit [decompression, lossless transformation, packed-pixel - * image loading] - * - * Setting this parameter will cause the decompression, transform, and image - * loading functions to return an error if the number of pixels in the source - * image exceeds the specified limit. This allows security-critical - * applications to guard against excessive memory consumption. - * - * **Value** - * - maximum number of pixels that the decompression, transform, and image - * loading functions will process *[default: `0` (no limit)]* - */ - TJPARAM_MAXPIXELS -}; - - -/** - * The number of error codes - */ -#define TJ_NUMERR 2 - -/** - * Error codes - */ -enum TJERR { - /** - * The error was non-fatal and recoverable, but the destination image may - * still be corrupt. - */ - TJERR_WARNING, - /** - * The error was fatal and non-recoverable. - */ - TJERR_FATAL -}; - - -/** - * The number of transform operations - */ -#define TJ_NUMXOP 8 - -/** - * Transform operations for #tj3Transform() - */ -enum TJXOP { - /** - * Do not transform the position of the image pixels - */ - TJXOP_NONE, - /** - * Flip (mirror) image horizontally. This transform is imperfect if there - * are any partial MCU blocks on the right edge (see #TJXOPT_PERFECT.) - */ - TJXOP_HFLIP, - /** - * Flip (mirror) image vertically. This transform is imperfect if there are - * any partial MCU blocks on the bottom edge (see #TJXOPT_PERFECT.) - */ - TJXOP_VFLIP, - /** - * Transpose image (flip/mirror along upper left to lower right axis.) This - * transform is always perfect. - */ - TJXOP_TRANSPOSE, - /** - * Transverse transpose image (flip/mirror along upper right to lower left - * axis.) This transform is imperfect if there are any partial MCU blocks in - * the image (see #TJXOPT_PERFECT.) - */ - TJXOP_TRANSVERSE, - /** - * Rotate image clockwise by 90 degrees. This transform is imperfect if - * there are any partial MCU blocks on the bottom edge (see - * #TJXOPT_PERFECT.) - */ - TJXOP_ROT90, - /** - * Rotate image 180 degrees. This transform is imperfect if there are any - * partial MCU blocks in the image (see #TJXOPT_PERFECT.) - */ - TJXOP_ROT180, - /** - * Rotate image counter-clockwise by 90 degrees. This transform is imperfect - * if there are any partial MCU blocks on the right edge (see - * #TJXOPT_PERFECT.) - */ - TJXOP_ROT270 -}; - - -/** - * This option will cause #tj3Transform() to return an error if the transform - * is not perfect. Lossless transforms operate on MCU blocks, whose size - * depends on the level of chrominance subsampling used (see #tjMCUWidth and - * #tjMCUHeight.) If the image's width or height is not evenly divisible by - * the MCU block size, then there will be partial MCU blocks on the right - * and/or bottom edges. It is not possible to move these partial MCU blocks to - * the top or left of the image, so any transform that would require that is - * "imperfect." If this option is not specified, then any partial MCU blocks - * that cannot be transformed will be left in place, which will create - * odd-looking strips on the right or bottom edge of the image. - */ -#define TJXOPT_PERFECT (1 << 0) -/** - * This option will cause #tj3Transform() to discard any partial MCU blocks - * that cannot be transformed. - */ -#define TJXOPT_TRIM (1 << 1) -/** - * This option will enable lossless cropping. See #tj3Transform() for more - * information. - */ -#define TJXOPT_CROP (1 << 2) -/** - * This option will discard the color data in the source image and produce a - * grayscale destination image. - */ -#define TJXOPT_GRAY (1 << 3) -/** - * This option will prevent #tj3Transform() from outputting a JPEG image for - * this particular transform. (This can be used in conjunction with a custom - * filter to capture the transformed DCT coefficients without transcoding - * them.) - */ -#define TJXOPT_NOOUTPUT (1 << 4) -/** - * This option will enable progressive entropy coding in the JPEG image - * generated by this particular transform. Progressive entropy coding will - * generally improve compression relative to baseline entropy coding (the - * default), but it will reduce decompression performance considerably. - * Can be combined with #TJXOPT_ARITHMETIC. Implies #TJXOPT_OPTIMIZE unless - * #TJXOPT_ARITHMETIC is also specified. - */ -#define TJXOPT_PROGRESSIVE (1 << 5) -/** - * This option will prevent #tj3Transform() from copying any extra markers - * (including EXIF and ICC profile data) from the source image to the - * destination image. - */ -#define TJXOPT_COPYNONE (1 << 6) -/** - * This option will enable arithmetic entropy coding in the JPEG image - * generated by this particular transform. Arithmetic entropy coding will - * generally improve compression relative to Huffman entropy coding (the - * default), but it will reduce decompression performance considerably. Can be - * combined with #TJXOPT_PROGRESSIVE. - */ -#define TJXOPT_ARITHMETIC (1 << 7) -/** - * This option will enable optimized baseline entropy coding in the JPEG image - * generated by this particular transform. Optimized baseline entropy coding - * will improve compression slightly (generally 5% or less.) - */ -#define TJXOPT_OPTIMIZE (1 << 8) - - -/** - * Scaling factor - */ -typedef struct { - /** - * Numerator - */ - int num; - /** - * Denominator - */ - int denom; -} tjscalingfactor; - -/** - * Cropping region - */ -typedef struct { - /** - * The left boundary of the cropping region. This must be evenly divisible - * by the MCU block width (see #tjMCUWidth.) - */ - int x; - /** - * The upper boundary of the cropping region. For lossless transformation, - * this must be evenly divisible by the MCU block height (see #tjMCUHeight.) - */ - int y; - /** - * The width of the cropping region. Setting this to 0 is the equivalent of - * setting it to the width of the source JPEG image - x. - */ - int w; - /** - * The height of the cropping region. Setting this to 0 is the equivalent of - * setting it to the height of the source JPEG image - y. - */ - int h; -} tjregion; - -/** - * A #tjregion structure that specifies no cropping - */ -static const tjregion TJUNCROPPED = { 0, 0, 0, 0 }; - -/** - * Lossless transform - */ -typedef struct tjtransform { - /** - * Cropping region - */ - tjregion r; - /** - * One of the @ref TJXOP "transform operations" - */ - int op; - /** - * The bitwise OR of one of more of the @ref TJXOPT_ARITHMETIC - * "transform options" - */ - int options; - /** - * Arbitrary data that can be accessed within the body of the callback - * function - */ - void *data; - /** - * A callback function that can be used to modify the DCT coefficients after - * they are losslessly transformed but before they are transcoded to a new - * JPEG image. This allows for custom filters or other transformations to be - * applied in the frequency domain. - * - * @param coeffs pointer to an array of transformed DCT coefficients. (NOTE: - * this pointer is not guaranteed to be valid once the callback returns, so - * applications wishing to hand off the DCT coefficients to another function - * or library should make a copy of them within the body of the callback.) - * - * @param arrayRegion #tjregion structure containing the width and height of - * the array pointed to by `coeffs` as well as its offset relative to the - * component plane. TurboJPEG implementations may choose to split each - * component plane into multiple DCT coefficient arrays and call the callback - * function once for each array. - * - * @param planeRegion #tjregion structure containing the width and height of - * the component plane to which `coeffs` belongs - * - * @param componentID ID number of the component plane to which `coeffs` - * belongs. (Y, Cb, and Cr have, respectively, ID's of 0, 1, and 2 in - * typical JPEG images.) - * - * @param transformID ID number of the transformed image to which `coeffs` - * belongs. This is the same as the index of the transform in the - * `transforms` array that was passed to #tj3Transform(). - * - * @param transform a pointer to a #tjtransform structure that specifies the - * parameters and/or cropping region for this transform - * - * @return 0 if the callback was successful, or -1 if an error occurred. - */ - int (*customFilter) (short *coeffs, tjregion arrayRegion, - tjregion planeRegion, int componentID, int transformID, - struct tjtransform *transform); -} tjtransform; - -/** - * TurboJPEG instance handle - */ -typedef void *tjhandle; - - -/** - * Compute the scaled value of `dimension` using the given scaling factor. - * This macro performs the integer equivalent of `ceil(dimension * - * scalingFactor)`. - */ -#define TJSCALED(dimension, scalingFactor) \ - (((dimension) * scalingFactor.num + scalingFactor.denom - 1) / \ - scalingFactor.denom) - -/** - * A #tjscalingfactor structure that specifies a scaling factor of 1/1 (no - * scaling) - */ -static const tjscalingfactor TJUNSCALED = { 1, 1 }; - - -#ifdef __cplusplus -extern "C" { -#endif - - -/** - * Create a new TurboJPEG instance. - * - * @param initType one of the @ref TJINIT "initialization options" - * - * @return a handle to the newly-created instance, or NULL if an error occurred - * (see #tj3GetErrorStr().) - */ -DLLEXPORT tjhandle tj3Init(int initType); - - -/** - * Set the value of a parameter. - * - * @param handle handle to a TurboJPEG instance - * - * @param param one of the @ref TJPARAM "parameters" - * - * @param value value of the parameter (refer to @ref TJPARAM - * "parameter documentation") - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr().) - */ -DLLEXPORT int tj3Set(tjhandle handle, int param, int value); - - -/** - * Get the value of a parameter. - * - * @param handle handle to a TurboJPEG instance - * - * @param param one of the @ref TJPARAM "parameters" - * - * @return the value of the specified parameter, or -1 if the value is unknown. - */ -DLLEXPORT int tj3Get(tjhandle handle, int param); - - -/** - * Compress an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into - * an 8-bit-per-sample JPEG image. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * compression - * - * @param srcBuf pointer to a buffer containing a packed-pixel RGB, grayscale, - * or CMYK source image to be compressed. This buffer should normally be - * `pitch * height` samples in size. However, you can also use this parameter - * to compress from a specific region of a larger buffer. - * - * @param width width (in pixels) of the source image - * - * @param pitch samples per row in the source image. Normally this should be - * width * #tjPixelSize[pixelFormat], if the image is unpadded. - * (Setting this parameter to 0 is the equivalent of setting it to - * width * #tjPixelSize[pixelFormat].) However, you can also use this - * parameter to specify the row alignment/padding of the source image, to skip - * rows, or to compress from a specific region of a larger buffer. - * - * @param height height (in pixels) of the source image - * - * @param pixelFormat pixel format of the source image (see @ref TJPF - * "Pixel formats".) - * - * @param jpegBuf address of a pointer to a byte buffer that will receive the - * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to - * accommodate the size of the JPEG image. Thus, you can choose to: - * -# pre-allocate the JPEG buffer with an arbitrary size using #tj3Alloc() and - * let TurboJPEG grow the buffer as needed, - * -# set `*jpegBuf` to NULL to tell TurboJPEG to allocate the buffer for you, - * or - * -# pre-allocate the buffer to a "worst case" size determined by calling - * #tj3JPEGBufSize(). This should ensure that the buffer never has to be - * re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.) - * . - * If you choose option 1, then `*jpegSize` should be set to the size of your - * pre-allocated buffer. In any case, unless you have set #TJPARAM_NOREALLOC, - * you should always check `*jpegBuf` upon return from this function, as it may - * have changed. - * - * @param jpegSize pointer to a size_t variable that holds the size of the JPEG - * buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize` - * should be set to the size of the buffer. Upon return, `*jpegSize` will - * contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a - * JPEG buffer that is being reused from a previous call to one of the JPEG - * compression functions, then `*jpegSize` is ignored. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3Compress8(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, int pixelFormat, - unsigned char **jpegBuf, size_t *jpegSize); - -/** - * Compress a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into - * a 12-bit-per-sample JPEG image. - * - * \details \copydetails tj3Compress8() - */ -DLLEXPORT int tj3Compress12(tjhandle handle, const short *srcBuf, int width, - int pitch, int height, int pixelFormat, - unsigned char **jpegBuf, size_t *jpegSize); - -/** - * Compress a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK image into - * a 16-bit-per-sample lossless JPEG image. - * - * \details \copydetails tj3Compress8() - */ -DLLEXPORT int tj3Compress16(tjhandle handle, const unsigned short *srcBuf, - int width, int pitch, int height, int pixelFormat, - unsigned char **jpegBuf, size_t *jpegSize); - - -/** - * Compress an 8-bit-per-sample unified planar YUV image into an - * 8-bit-per-sample JPEG image. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * compression - * - * @param srcBuf pointer to a buffer containing a unified planar YUV source - * image to be compressed. The size of this buffer should match the value - * returned by #tj3YUVBufSize() for the given image width, height, row - * alignment, and level of chrominance subsampling (see #TJPARAM_SUBSAMP.) The - * Y, U (Cb), and V (Cr) image planes should be stored sequentially in the - * buffer. (Refer to @ref YUVnotes "YUV Image Format Notes".) - * - * @param width width (in pixels) of the source image. If the width is not an - * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate - * buffer copy will be performed. - * - * @param align row alignment (in bytes) of the source image (must be a power - * of 2.) Setting this parameter to n indicates that each row in each plane of - * the source image is padded to the nearest multiple of n bytes - * (1 = unpadded.) - * - * @param height height (in pixels) of the source image. If the height is not - * an even multiple of the MCU block height (see #tjMCUHeight), then an - * intermediate buffer copy will be performed. - * - * @param jpegBuf address of a pointer to a byte buffer that will receive the - * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to - * accommodate the size of the JPEG image. Thus, you can choose to: - * -# pre-allocate the JPEG buffer with an arbitrary size using #tj3Alloc() and - * let TurboJPEG grow the buffer as needed, - * -# set `*jpegBuf` to NULL to tell TurboJPEG to allocate the buffer for you, - * or - * -# pre-allocate the buffer to a "worst case" size determined by calling - * #tj3JPEGBufSize(). This should ensure that the buffer never has to be - * re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.) - * . - * If you choose option 1, then `*jpegSize` should be set to the size of your - * pre-allocated buffer. In any case, unless you have set #TJPARAM_NOREALLOC, - * you should always check `*jpegBuf` upon return from this function, as it may - * have changed. - * - * @param jpegSize pointer to a size_t variable that holds the size of the JPEG - * buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize` - * should be set to the size of the buffer. Upon return, `*jpegSize` will - * contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a - * JPEG buffer that is being reused from a previous call to one of the JPEG - * compression functions, then `*jpegSize` is ignored. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3CompressFromYUV8(tjhandle handle, - const unsigned char *srcBuf, int width, - int align, int height, - unsigned char **jpegBuf, size_t *jpegSize); - - -/** - * Compress a set of 8-bit-per-sample Y, U (Cb), and V (Cr) image planes into - * an 8-bit-per-sample JPEG image. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * compression - * - * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes - * (or just a Y plane, if compressing a grayscale image) that contain a YUV - * source image to be compressed. These planes can be contiguous or - * non-contiguous in memory. The size of each plane should match the value - * returned by #tj3YUVPlaneSize() for the given image width, height, strides, - * and level of chrominance subsampling (see #TJPARAM_SUBSAMP.) Refer to - * @ref YUVnotes "YUV Image Format Notes" for more details. - * - * @param width width (in pixels) of the source image. If the width is not an - * even multiple of the MCU block width (see #tjMCUWidth), then an intermediate - * buffer copy will be performed. - * - * @param strides an array of integers, each specifying the number of bytes per - * row in the corresponding plane of the YUV source image. Setting the stride - * for any plane to 0 is the same as setting it to the plane width (see - * @ref YUVnotes "YUV Image Format Notes".) If `strides` is NULL, then the - * strides for all planes will be set to their respective plane widths. You - * can adjust the strides in order to specify an arbitrary amount of row - * padding in each plane or to create a JPEG image from a subregion of a larger - * planar YUV image. - * - * @param height height (in pixels) of the source image. If the height is not - * an even multiple of the MCU block height (see #tjMCUHeight), then an - * intermediate buffer copy will be performed. - * - * @param jpegBuf address of a pointer to a byte buffer that will receive the - * JPEG image. TurboJPEG has the ability to reallocate the JPEG buffer to - * accommodate the size of the JPEG image. Thus, you can choose to: - * -# pre-allocate the JPEG buffer with an arbitrary size using #tj3Alloc() and - * let TurboJPEG grow the buffer as needed, - * -# set `*jpegBuf` to NULL to tell TurboJPEG to allocate the buffer for you, - * or - * -# pre-allocate the buffer to a "worst case" size determined by calling - * #tj3JPEGBufSize(). This should ensure that the buffer never has to be - * re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.) - * . - * If you choose option 1, then `*jpegSize` should be set to the size of your - * pre-allocated buffer. In any case, unless you have set #TJPARAM_NOREALLOC, - * you should always check `*jpegBuf` upon return from this function, as it may - * have changed. - * - * @param jpegSize pointer to a size_t variable that holds the size of the JPEG - * buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize` - * should be set to the size of the buffer. Upon return, `*jpegSize` will - * contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a - * JPEG buffer that is being reused from a previous call to one of the JPEG - * compression functions, then `*jpegSize` is ignored. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3CompressFromYUVPlanes8(tjhandle handle, - const unsigned char * const *srcPlanes, - int width, const int *strides, - int height, unsigned char **jpegBuf, - size_t *jpegSize); - - -/** - * The maximum size of the buffer (in bytes) required to hold a JPEG image with - * the given parameters. The number of bytes returned by this function is - * larger than the size of the uncompressed source image. The reason for this - * is that the JPEG format uses 16-bit coefficients, so it is possible for a - * very high-quality source image with very high-frequency content to expand - * rather than compress when converted to the JPEG format. Such images - * represent very rare corner cases, but since there is no way to predict the - * size of a JPEG image prior to compression, the corner cases have to be - * handled. - * - * @param width width (in pixels) of the image - * - * @param height height (in pixels) of the image - * - * @param jpegSubsamp the level of chrominance subsampling to be used when - * generating the JPEG image (see @ref TJSAMP - * "Chrominance subsampling options".) #TJSAMP_UNKNOWN is treated like - * #TJSAMP_444, since a buffer large enough to hold a JPEG image with no - * subsampling should also be large enough to hold a JPEG image with an - * arbitrary level of subsampling. Note that lossless JPEG images always - * use #TJSAMP_444. - * - * @return the maximum size of the buffer (in bytes) required to hold the - * image, or 0 if the arguments are out of bounds. - */ -DLLEXPORT size_t tj3JPEGBufSize(int width, int height, int jpegSubsamp); - - -/** - * The size of the buffer (in bytes) required to hold a unified planar YUV - * image with the given parameters. - * - * @param width width (in pixels) of the image - * - * @param align row alignment (in bytes) of the image (must be a power of 2.) - * Setting this parameter to n specifies that each row in each plane of the - * image will be padded to the nearest multiple of n bytes (1 = unpadded.) - * - * @param height height (in pixels) of the image - * - * @param subsamp level of chrominance subsampling in the image (see - * @ref TJSAMP "Chrominance subsampling options".) - * - * @return the size of the buffer (in bytes) required to hold the image, or 0 - * if the arguments are out of bounds. - */ -DLLEXPORT size_t tj3YUVBufSize(int width, int align, int height, int subsamp); - - -/** - * The size of the buffer (in bytes) required to hold a YUV image plane with - * the given parameters. - * - * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) - * - * @param width width (in pixels) of the YUV image. NOTE: this is the width of - * the whole image, not the plane width. - * - * @param stride bytes per row in the image plane. Setting this to 0 is the - * equivalent of setting it to the plane width. - * - * @param height height (in pixels) of the YUV image. NOTE: this is the height - * of the whole image, not the plane height. - * - * @param subsamp level of chrominance subsampling in the image (see - * @ref TJSAMP "Chrominance subsampling options".) - * - * @return the size of the buffer (in bytes) required to hold the YUV image - * plane, or 0 if the arguments are out of bounds. - */ -DLLEXPORT size_t tj3YUVPlaneSize(int componentID, int width, int stride, - int height, int subsamp); - - -/** - * The plane width of a YUV image plane with the given parameters. Refer to - * @ref YUVnotes "YUV Image Format Notes" for a description of plane width. - * - * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) - * - * @param width width (in pixels) of the YUV image - * - * @param subsamp level of chrominance subsampling in the image (see - * @ref TJSAMP "Chrominance subsampling options".) - * - * @return the plane width of a YUV image plane with the given parameters, or 0 - * if the arguments are out of bounds. - */ -DLLEXPORT int tj3YUVPlaneWidth(int componentID, int width, int subsamp); - - -/** - * The plane height of a YUV image plane with the given parameters. Refer to - * @ref YUVnotes "YUV Image Format Notes" for a description of plane height. - * - * @param componentID ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr) - * - * @param height height (in pixels) of the YUV image - * - * @param subsamp level of chrominance subsampling in the image (see - * @ref TJSAMP "Chrominance subsampling options".) - * - * @return the plane height of a YUV image plane with the given parameters, or - * 0 if the arguments are out of bounds. - */ -DLLEXPORT int tj3YUVPlaneHeight(int componentID, int height, int subsamp); - - -/** - * Encode an 8-bit-per-sample packed-pixel RGB or grayscale image into an - * 8-bit-per-sample unified planar YUV image. This function performs color - * conversion (which is accelerated in the libjpeg-turbo implementation) but - * does not execute any of the other steps in the JPEG compression process. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * compression - * - * @param srcBuf pointer to a buffer containing a packed-pixel RGB or grayscale - * source image to be encoded. This buffer should normally be `pitch * height` - * bytes in size. However, you can also use this parameter to encode from a - * specific region of a larger buffer. - * - * @param width width (in pixels) of the source image - * - * @param pitch bytes per row in the source image. Normally this should be - * width * #tjPixelSize[pixelFormat], if the image is unpadded. - * (Setting this parameter to 0 is the equivalent of setting it to - * width * #tjPixelSize[pixelFormat].) However, you can also use this - * parameter to specify the row alignment/padding of the source image, to skip - * rows, or to encode from a specific region of a larger packed-pixel image. - * - * @param height height (in pixels) of the source image - * - * @param pixelFormat pixel format of the source image (see @ref TJPF - * "Pixel formats".) - * - * @param dstBuf pointer to a buffer that will receive the unified planar YUV - * image. Use #tj3YUVBufSize() to determine the appropriate size for this - * buffer based on the image width, height, row alignment, and level of - * chrominance subsampling (see #TJPARAM_SUBSAMP.) The Y, U (Cb), and V (Cr) - * image planes will be stored sequentially in the buffer. (Refer to - * @ref YUVnotes "YUV Image Format Notes".) - * - * @param align row alignment (in bytes) of the YUV image (must be a power of - * 2.) Setting this parameter to n will cause each row in each plane of the - * YUV image to be padded to the nearest multiple of n bytes (1 = unpadded.) - * To generate images suitable for X Video, `align` should be set to 4. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3EncodeYUV8(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, int pixelFormat, - unsigned char *dstBuf, int align); - - -/** - * Encode an 8-bit-per-sample packed-pixel RGB or grayscale image into separate - * 8-bit-per-sample Y, U (Cb), and V (Cr) image planes. This function performs - * color conversion (which is accelerated in the libjpeg-turbo implementation) - * but does not execute any of the other steps in the JPEG compression process. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * compression - * - * @param srcBuf pointer to a buffer containing a packed-pixel RGB or grayscale - * source image to be encoded. This buffer should normally be `pitch * height` - * bytes in size. However, you can also use this parameter to encode from a - * specific region of a larger buffer. - * - * - * @param width width (in pixels) of the source image - * - * @param pitch bytes per row in the source image. Normally this should be - * width * #tjPixelSize[pixelFormat], if the image is unpadded. - * (Setting this parameter to 0 is the equivalent of setting it to - * width * #tjPixelSize[pixelFormat].) However, you can also use this - * parameter to specify the row alignment/padding of the source image, to skip - * rows, or to encode from a specific region of a larger packed-pixel image. - * - * @param height height (in pixels) of the source image - * - * @param pixelFormat pixel format of the source image (see @ref TJPF - * "Pixel formats".) - * - * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes - * (or just a Y plane, if generating a grayscale image) that will receive the - * encoded image. These planes can be contiguous or non-contiguous in memory. - * Use #tj3YUVPlaneSize() to determine the appropriate size for each plane - * based on the image width, height, strides, and level of chrominance - * subsampling (see #TJPARAM_SUBSAMP.) Refer to @ref YUVnotes - * "YUV Image Format Notes" for more details. - * - * @param strides an array of integers, each specifying the number of bytes per - * row in the corresponding plane of the YUV image. Setting the stride for any - * plane to 0 is the same as setting it to the plane width (see @ref YUVnotes - * "YUV Image Format Notes".) If `strides` is NULL, then the strides for all - * planes will be set to their respective plane widths. You can adjust the - * strides in order to add an arbitrary amount of row padding to each plane or - * to encode an RGB or grayscale image into a subregion of a larger planar YUV - * image. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3EncodeYUVPlanes8(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, - int pixelFormat, unsigned char **dstPlanes, - int *strides); - - -/** - * Retrieve information about a JPEG image without decompressing it, or prime - * the decompressor with quantization and Huffman tables. If a JPEG image is - * passed to this function, then the @ref TJPARAM "parameters" that describe - * the JPEG image will be set when the function returns. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * decompression - * - * @param jpegBuf pointer to a byte buffer containing a JPEG image or an - * "abbreviated table specification" (AKA "tables-only") datastream. Passing a - * tables-only datastream to this function primes the decompressor with - * quantization and Huffman tables that can be used when decompressing - * subsequent "abbreviated image" datastreams. This is useful, for instance, - * when decompressing video streams in which all frames share the same - * quantization and Huffman tables. - * - * @param jpegSize size of the JPEG image or tables-only datastream (in bytes) - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3DecompressHeader(tjhandle handle, - const unsigned char *jpegBuf, - size_t jpegSize); - - -/** - * Returns a list of fractional scaling factors that the JPEG decompressor - * supports. - * - * @param numScalingFactors pointer to an integer variable that will receive - * the number of elements in the list - * - * @return a pointer to a list of fractional scaling factors, or NULL if an - * error is encountered (see #tj3GetErrorStr().) - */ -DLLEXPORT tjscalingfactor *tj3GetScalingFactors(int *numScalingFactors); - - -/** - * Set the scaling factor for subsequent lossy decompression operations. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * decompression - * - * @param scalingFactor #tjscalingfactor structure that specifies a fractional - * scaling factor that the decompressor supports (see #tj3GetScalingFactors()), - * or #TJUNSCALED for no scaling. Decompression scaling is a function - * of the IDCT algorithm, so scaling factors are generally limited to multiples - * of 1/8. If the entire JPEG image will be decompressed, then the width and - * height of the scaled destination image can be determined by calling - * #TJSCALED() with the JPEG width and height (see #TJPARAM_JPEGWIDTH and - * #TJPARAM_JPEGHEIGHT) and the specified scaling factor. When decompressing - * into a planar YUV image, an intermediate buffer copy will be performed if - * the width or height of the scaled destination image is not an even multiple - * of the MCU block size (see #tjMCUWidth and #tjMCUHeight.) Note that - * decompression scaling is not available (and the specified scaling factor is - * ignored) when decompressing lossless JPEG images (see #TJPARAM_LOSSLESS), - * since the IDCT algorithm is not used with those images. Note also that - * #TJPARAM_FASTDCT is ignored when decompression scaling is enabled. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr().) - */ -DLLEXPORT int tj3SetScalingFactor(tjhandle handle, - tjscalingfactor scalingFactor); - - -/** - * Set the cropping region for partially decompressing a lossy JPEG image into - * a packed-pixel image - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * decompression - * - * @param croppingRegion #tjregion structure that specifies a subregion of the - * JPEG image to decompress, or #TJUNCROPPED for no cropping. The - * left boundary of the cropping region must be evenly divisible by the scaled - * MCU block width (#TJSCALED(#tjMCUWidth[subsamp], scalingFactor), - * where `subsamp` is the level of chrominance subsampling in the JPEG image - * (see #TJPARAM_SUBSAMP) and `scalingFactor` is the decompression scaling - * factor (see #tj3SetScalingFactor().) The cropping region should be - * specified relative to the scaled image dimensions. Unless `croppingRegion` - * is #TJUNCROPPED, the JPEG header must be read (see - * #tj3DecompressHeader()) prior to calling this function. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr().) - */ -DLLEXPORT int tj3SetCroppingRegion(tjhandle handle, tjregion croppingRegion); - - -/** - * Decompress an 8-bit-per-sample JPEG image into an 8-bit-per-sample - * packed-pixel RGB, grayscale, or CMYK image. The @ref TJPARAM "parameters" - * that describe the JPEG image will be set when this function returns. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * decompression - * - * @param jpegBuf pointer to a byte buffer containing the JPEG image to - * decompress - * - * @param jpegSize size of the JPEG image (in bytes) - * - * @param dstBuf pointer to a buffer that will receive the packed-pixel - * decompressed image. This buffer should normally be - * `pitch * destinationHeight` samples in size. However, you can also use this - * parameter to decompress into a specific region of a larger buffer. NOTE: - * If the JPEG image is lossy, then `destinationHeight` is either the scaled - * JPEG height (see #TJSCALED(), #TJPARAM_JPEGHEIGHT, and - * #tj3SetScalingFactor()) or the height of the cropping region (see - * #tj3SetCroppingRegion().) If the JPEG image is lossless, then - * `destinationHeight` is the JPEG height. - * - * @param pitch samples per row in the destination image. Normally this should - * be set to destinationWidth * #tjPixelSize[pixelFormat], if the - * destination image should be unpadded. (Setting this parameter to 0 is the - * equivalent of setting it to - * destinationWidth * #tjPixelSize[pixelFormat].) However, you can - * also use this parameter to specify the row alignment/padding of the - * destination image, to skip rows, or to decompress into a specific region of - * a larger buffer. NOTE: If the JPEG image is lossy, then `destinationWidth` - * is either the scaled JPEG width (see #TJSCALED(), #TJPARAM_JPEGWIDTH, and - * #tj3SetScalingFactor()) or the width of the cropping region (see - * #tj3SetCroppingRegion().) If the JPEG image is lossless, then - * `destinationWidth` is the JPEG width. - * - * @param pixelFormat pixel format of the destination image (see @ref - * TJPF "Pixel formats".) - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3Decompress8(tjhandle handle, const unsigned char *jpegBuf, - size_t jpegSize, unsigned char *dstBuf, int pitch, - int pixelFormat); - -/** - * Decompress a 12-bit-per-sample JPEG image into a 12-bit-per-sample - * packed-pixel RGB, grayscale, or CMYK image. - * - * \details \copydetails tj3Decompress8() - */ -DLLEXPORT int tj3Decompress12(tjhandle handle, const unsigned char *jpegBuf, - size_t jpegSize, short *dstBuf, int pitch, - int pixelFormat); - -/** - * Decompress a 16-bit-per-sample lossless JPEG image into a 16-bit-per-sample - * packed-pixel RGB, grayscale, or CMYK image. - * - * \details \copydetails tj3Decompress8() - */ -DLLEXPORT int tj3Decompress16(tjhandle handle, const unsigned char *jpegBuf, - size_t jpegSize, unsigned short *dstBuf, - int pitch, int pixelFormat); - - -/** - * Decompress an 8-bit-per-sample JPEG image into an 8-bit-per-sample unified - * planar YUV image. This function performs JPEG decompression but leaves out - * the color conversion step, so a planar YUV image is generated instead of a - * packed-pixel image. The @ref TJPARAM "parameters" that describe the JPEG - * image will be set when this function returns. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * decompression - * - * @param jpegBuf pointer to a byte buffer containing the JPEG image to - * decompress - * - * @param jpegSize size of the JPEG image (in bytes) - * - * @param dstBuf pointer to a buffer that will receive the unified planar YUV - * decompressed image. Use #tj3YUVBufSize() to determine the appropriate size - * for this buffer based on the scaled JPEG width and height (see #TJSCALED(), - * #TJPARAM_JPEGWIDTH, #TJPARAM_JPEGHEIGHT, and #tj3SetScalingFactor()), row - * alignment, and level of chrominance subsampling (see #TJPARAM_SUBSAMP.) The - * Y, U (Cb), and V (Cr) image planes will be stored sequentially in the - * buffer. (Refer to @ref YUVnotes "YUV Image Format Notes".) - * - * @param align row alignment (in bytes) of the YUV image (must be a power of - * 2.) Setting this parameter to n will cause each row in each plane of the - * YUV image to be padded to the nearest multiple of n bytes (1 = unpadded.) - * To generate images suitable for X Video, `align` should be set to 4. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3DecompressToYUV8(tjhandle handle, - const unsigned char *jpegBuf, - size_t jpegSize, - unsigned char *dstBuf, int align); - - -/** - * Decompress an 8-bit-per-sample JPEG image into separate 8-bit-per-sample Y, - * U (Cb), and V (Cr) image planes. This function performs JPEG decompression - * but leaves out the color conversion step, so a planar YUV image is generated - * instead of a packed-pixel image. The @ref TJPARAM "parameters" that - * describe the JPEG image will be set when this function returns. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * decompression - * - * @param jpegBuf pointer to a byte buffer containing the JPEG image to - * decompress - * - * @param jpegSize size of the JPEG image (in bytes) - * - * @param dstPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes - * (or just a Y plane, if decompressing a grayscale image) that will receive - * the decompressed image. These planes can be contiguous or non-contiguous in - * memory. Use #tj3YUVPlaneSize() to determine the appropriate size for each - * plane based on the scaled JPEG width and height (see #TJSCALED(), - * #TJPARAM_JPEGWIDTH, #TJPARAM_JPEGHEIGHT, and #tj3SetScalingFactor()), - * strides, and level of chrominance subsampling (see #TJPARAM_SUBSAMP.) Refer - * to @ref YUVnotes "YUV Image Format Notes" for more details. - * - * @param strides an array of integers, each specifying the number of bytes per - * row in the corresponding plane of the YUV image. Setting the stride for any - * plane to 0 is the same as setting it to the scaled plane width (see - * @ref YUVnotes "YUV Image Format Notes".) If `strides` is NULL, then the - * strides for all planes will be set to their respective scaled plane widths. - * You can adjust the strides in order to add an arbitrary amount of row - * padding to each plane or to decompress the JPEG image into a subregion of a - * larger planar YUV image. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3DecompressToYUVPlanes8(tjhandle handle, - const unsigned char *jpegBuf, - size_t jpegSize, - unsigned char **dstPlanes, - int *strides); - - -/** - * Decode an 8-bit-per-sample unified planar YUV image into an 8-bit-per-sample - * packed-pixel RGB or grayscale image. This function performs color - * conversion (which is accelerated in the libjpeg-turbo implementation) but - * does not execute any of the other steps in the JPEG decompression process. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * decompression - * - * @param srcBuf pointer to a buffer containing a unified planar YUV source - * image to be decoded. The size of this buffer should match the value - * returned by #tj3YUVBufSize() for the given image width, height, row - * alignment, and level of chrominance subsampling (see #TJPARAM_SUBSAMP.) The - * Y, U (Cb), and V (Cr) image planes should be stored sequentially in the - * source buffer. (Refer to @ref YUVnotes "YUV Image Format Notes".) - * - * @param align row alignment (in bytes) of the YUV source image (must be a - * power of 2.) Setting this parameter to n indicates that each row in each - * plane of the YUV source image is padded to the nearest multiple of n bytes - * (1 = unpadded.) - * - * @param dstBuf pointer to a buffer that will receive the packed-pixel decoded - * image. This buffer should normally be `pitch * height` bytes in size. - * However, you can also use this parameter to decode into a specific region of - * a larger buffer. - * - * @param width width (in pixels) of the source and destination images - * - * @param pitch bytes per row in the destination image. Normally this should - * be set to width * #tjPixelSize[pixelFormat], if the destination - * image should be unpadded. (Setting this parameter to 0 is the equivalent of - * setting it to width * #tjPixelSize[pixelFormat].) However, you can - * also use this parameter to specify the row alignment/padding of the - * destination image, to skip rows, or to decode into a specific region of a - * larger buffer. - * - * @param height height (in pixels) of the source and destination images - * - * @param pixelFormat pixel format of the destination image (see @ref TJPF - * "Pixel formats".) - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3DecodeYUV8(tjhandle handle, const unsigned char *srcBuf, - int align, unsigned char *dstBuf, int width, - int pitch, int height, int pixelFormat); - - -/** - * Decode a set of 8-bit-per-sample Y, U (Cb), and V (Cr) image planes into an - * 8-bit-per-sample packed-pixel RGB or grayscale image. This function - * performs color conversion (which is accelerated in the libjpeg-turbo - * implementation) but does not execute any of the other steps in the JPEG - * decompression process. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * decompression - * - * @param srcPlanes an array of pointers to Y, U (Cb), and V (Cr) image planes - * (or just a Y plane, if decoding a grayscale image) that contain a YUV image - * to be decoded. These planes can be contiguous or non-contiguous in memory. - * The size of each plane should match the value returned by #tj3YUVPlaneSize() - * for the given image width, height, strides, and level of chrominance - * subsampling (see #TJPARAM_SUBSAMP.) Refer to @ref YUVnotes - * "YUV Image Format Notes" for more details. - * - * @param strides an array of integers, each specifying the number of bytes per - * row in the corresponding plane of the YUV source image. Setting the stride - * for any plane to 0 is the same as setting it to the plane width (see - * @ref YUVnotes "YUV Image Format Notes".) If `strides` is NULL, then the - * strides for all planes will be set to their respective plane widths. You - * can adjust the strides in order to specify an arbitrary amount of row - * padding in each plane or to decode a subregion of a larger planar YUV image. - * - * @param dstBuf pointer to a buffer that will receive the packed-pixel decoded - * image. This buffer should normally be `pitch * height` bytes in size. - * However, you can also use this parameter to decode into a specific region of - * a larger buffer. - * - * @param width width (in pixels) of the source and destination images - * - * @param pitch bytes per row in the destination image. Normally this should - * be set to width * #tjPixelSize[pixelFormat], if the destination - * image should be unpadded. (Setting this parameter to 0 is the equivalent of - * setting it to width * #tjPixelSize[pixelFormat].) However, you can - * also use this parameter to specify the row alignment/padding of the - * destination image, to skip rows, or to decode into a specific region of a - * larger buffer. - * - * @param height height (in pixels) of the source and destination images - * - * @param pixelFormat pixel format of the destination image (see @ref TJPF - * "Pixel formats".) - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3DecodeYUVPlanes8(tjhandle handle, - const unsigned char * const *srcPlanes, - const int *strides, unsigned char *dstBuf, - int width, int pitch, int height, - int pixelFormat); - - -/** - * Losslessly transform a JPEG image into another JPEG image. Lossless - * transforms work by moving the raw DCT coefficients from one JPEG image - * structure to another without altering the values of the coefficients. While - * this is typically faster than decompressing the image, transforming it, and - * re-compressing it, lossless transforms are not free. Each lossless - * transform requires reading and performing entropy decoding on all of the - * coefficients in the source image, regardless of the size of the destination - * image. Thus, this function provides a means of generating multiple - * transformed images from the same source or applying multiple transformations - * simultaneously, in order to eliminate the need to read the source - * coefficients multiple times. - * - * @param handle handle to a TurboJPEG instance that has been initialized for - * lossless transformation - * - * @param jpegBuf pointer to a byte buffer containing the JPEG source image to - * transform - * - * @param jpegSize size of the JPEG source image (in bytes) - * - * @param n the number of transformed JPEG images to generate - * - * @param dstBufs pointer to an array of n byte buffers. `dstBufs[i]` will - * receive a JPEG image that has been transformed using the parameters in - * `transforms[i]`. TurboJPEG has the ability to reallocate the JPEG - * destination buffer to accommodate the size of the transformed JPEG image. - * Thus, you can choose to: - * -# pre-allocate the JPEG destination buffer with an arbitrary size using - * #tj3Alloc() and let TurboJPEG grow the buffer as needed, - * -# set `dstBufs[i]` to NULL to tell TurboJPEG to allocate the buffer for - * you, or - * -# pre-allocate the buffer to a "worst case" size determined by calling - * #tj3JPEGBufSize() with the transformed or cropped width and height and the - * level of subsampling used in the source image. Under normal circumstances, - * this should ensure that the buffer never has to be re-allocated. (Setting - * #TJPARAM_NOREALLOC guarantees that it won't be.) Note, however, that there - * are some rare cases (such as transforming images with a large amount of - * embedded EXIF or ICC profile data) in which the transformed JPEG image will - * be larger than the worst-case size, and #TJPARAM_NOREALLOC cannot be used in - * those cases. - * . - * If you choose option 1, then `dstSizes[i]` should be set to the size of your - * pre-allocated buffer. In any case, unless you have set #TJPARAM_NOREALLOC, - * you should always check `dstBufs[i]` upon return from this function, as it - * may have changed. - * - * @param dstSizes pointer to an array of n size_t variables that will receive - * the actual sizes (in bytes) of each transformed JPEG image. If `dstBufs[i]` - * points to a pre-allocated buffer, then `dstSizes[i]` should be set to the - * size of the buffer. Upon return, `dstSizes[i]` will contain the size of the - * transformed JPEG image (in bytes.) - * - * @param transforms pointer to an array of n #tjtransform structures, each of - * which specifies the transform parameters and/or cropping region for the - * corresponding transformed JPEG image. - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr() - * and #tj3GetErrorCode().) - */ -DLLEXPORT int tj3Transform(tjhandle handle, const unsigned char *jpegBuf, - size_t jpegSize, int n, unsigned char **dstBufs, - size_t *dstSizes, const tjtransform *transforms); - - -/** - * Destroy a TurboJPEG instance. - * - * @param handle handle to a TurboJPEG instance. If the handle is NULL, then - * this function has no effect. - */ -DLLEXPORT void tj3Destroy(tjhandle handle); - - -/** - * Allocate a byte buffer for use with TurboJPEG. You should always use this - * function to allocate the JPEG destination buffer(s) for the compression and - * transform functions unless you are disabling automatic buffer (re)allocation - * (by setting #TJPARAM_NOREALLOC.) - * - * @param bytes the number of bytes to allocate - * - * @return a pointer to a newly-allocated buffer with the specified number of - * bytes. - * - * @see tj3Free() - */ -DLLEXPORT void *tj3Alloc(size_t bytes); - - -/** - * Load an 8-bit-per-sample packed-pixel image from disk into memory. - * - * @param handle handle to a TurboJPEG instance - * - * @param filename name of a file containing a packed-pixel image in Windows - * BMP or PBMPLUS (PPM/PGM) format. Windows BMP files require 8-bit-per-sample - * data precision. If the data precision of the PBMPLUS file does not match - * the target data precision, then upconverting or downconverting will be - * performed. - * - * @param width pointer to an integer variable that will receive the width (in - * pixels) of the packed-pixel image - * - * @param align row alignment (in samples) of the packed-pixel buffer to be - * returned (must be a power of 2.) Setting this parameter to n will cause all - * rows in the buffer to be padded to the nearest multiple of n samples - * (1 = unpadded.) - * - * @param height pointer to an integer variable that will receive the height - * (in pixels) of the packed-pixel image - * - * @param pixelFormat pointer to an integer variable that specifies or will - * receive the pixel format of the packed-pixel buffer. The behavior of this - * function will vary depending on the value of `*pixelFormat` passed to the - * function: - * - @ref TJPF_UNKNOWN : The packed-pixel buffer returned by this function will - * use the most optimal pixel format for the file type, and `*pixelFormat` will - * contain the ID of that pixel format upon successful return from this - * function. - * - @ref TJPF_GRAY : Only PGM files and 8-bit-per-pixel BMP files with a - * grayscale colormap can be loaded. - * - @ref TJPF_CMYK : The RGB or grayscale pixels stored in the file will be - * converted using a quick & dirty algorithm that is suitable only for testing - * purposes. (Proper conversion between CMYK and other formats requires a - * color management system.) - * - Other @ref TJPF "pixel formats" : The packed-pixel buffer will use the - * specified pixel format, and pixel format conversion will be performed if - * necessary. - * - * @return a pointer to a newly-allocated buffer containing the packed-pixel - * image, converted to the chosen pixel format and with the chosen row - * alignment, or NULL if an error occurred (see #tj3GetErrorStr().) This - * buffer should be freed using #tj3Free(). - */ -DLLEXPORT unsigned char *tj3LoadImage8(tjhandle handle, const char *filename, - int *width, int align, int *height, - int *pixelFormat); - -/** - * Load a 12-bit-per-sample packed-pixel image from disk into memory. - * - * \details \copydetails tj3LoadImage8() - */ -DLLEXPORT short *tj3LoadImage12(tjhandle handle, const char *filename, - int *width, int align, int *height, - int *pixelFormat); - -/** - * Load a 16-bit-per-sample packed-pixel image from disk into memory. - * - * \details \copydetails tj3LoadImage8() - */ -DLLEXPORT unsigned short *tj3LoadImage16(tjhandle handle, const char *filename, - int *width, int align, int *height, - int *pixelFormat); - - -/** - * Save an 8-bit-per-sample packed-pixel image from memory to disk. - * - * @param handle handle to a TurboJPEG instance - * - * @param filename name of a file to which to save the packed-pixel image. The - * image will be stored in Windows BMP or PBMPLUS (PPM/PGM) format, depending - * on the file extension. Windows BMP files require 8-bit-per-sample data - * precision. - * - * @param buffer pointer to a buffer containing a packed-pixel RGB, grayscale, - * or CMYK image to be saved - * - * @param width width (in pixels) of the packed-pixel image - * - * @param pitch samples per row in the packed-pixel image. Setting this - * parameter to 0 is the equivalent of setting it to - * width * #tjPixelSize[pixelFormat]. - * - * @param height height (in pixels) of the packed-pixel image - * - * @param pixelFormat pixel format of the packed-pixel image (see @ref TJPF - * "Pixel formats".) If this parameter is set to @ref TJPF_GRAY, then the - * image will be stored in PGM or 8-bit-per-pixel (indexed color) BMP format. - * Otherwise, the image will be stored in PPM or 24-bit-per-pixel BMP format. - * If this parameter is set to @ref TJPF_CMYK, then the CMYK pixels will be - * converted to RGB using a quick & dirty algorithm that is suitable only for - * testing purposes. (Proper conversion between CMYK and other formats - * requires a color management system.) - * - * @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr().) - */ -DLLEXPORT int tj3SaveImage8(tjhandle handle, const char *filename, - const unsigned char *buffer, int width, int pitch, - int height, int pixelFormat); - -/** - * Save a 12-bit-per-sample packed-pixel image from memory to disk. - * - * \details \copydetails tj3SaveImage8() - */ -DLLEXPORT int tj3SaveImage12(tjhandle handle, const char *filename, - const short *buffer, int width, int pitch, - int height, int pixelFormat); - -/** - * Save a 16-bit-per-sample packed-pixel image from memory to disk. - * - * \details \copydetails tj3SaveImage8() - */ -DLLEXPORT int tj3SaveImage16(tjhandle handle, const char *filename, - const unsigned short *buffer, int width, - int pitch, int height, int pixelFormat); - - -/** - * Free a byte buffer previously allocated by TurboJPEG. You should always use - * this function to free JPEG destination buffer(s) that were automatically - * (re)allocated by the compression and transform functions or that were - * manually allocated using #tj3Alloc(). - * - * @param buffer address of the buffer to free. If the address is NULL, then - * this function has no effect. - * - * @see tj3Alloc() - */ -DLLEXPORT void tj3Free(void *buffer); - - -/** - * Returns a descriptive error message explaining why the last command failed. - * - * @param handle handle to a TurboJPEG instance, or NULL if the error was - * generated by a global function (but note that retrieving the error message - * for a global function is thread-safe only on platforms that support - * thread-local storage.) - * - * @return a descriptive error message explaining why the last command failed. - */ -DLLEXPORT char *tj3GetErrorStr(tjhandle handle); - - -/** - * Returns a code indicating the severity of the last error. See - * @ref TJERR "Error codes". - * - * @param handle handle to a TurboJPEG instance - * - * @return a code indicating the severity of the last error. See - * @ref TJERR "Error codes". - */ -DLLEXPORT int tj3GetErrorCode(tjhandle handle); - - -/* Backward compatibility functions and macros (nothing to see here) */ - -/* TurboJPEG 1.0+ */ - -#define NUMSUBOPT TJ_NUMSAMP -#define TJ_444 TJSAMP_444 -#define TJ_422 TJSAMP_422 -#define TJ_420 TJSAMP_420 -#define TJ_411 TJSAMP_420 -#define TJ_GRAYSCALE TJSAMP_GRAY - -#define TJ_BGR 1 -#define TJ_BOTTOMUP TJFLAG_BOTTOMUP -#define TJ_FORCEMMX TJFLAG_FORCEMMX -#define TJ_FORCESSE TJFLAG_FORCESSE -#define TJ_FORCESSE2 TJFLAG_FORCESSE2 -#define TJ_ALPHAFIRST 64 -#define TJ_FORCESSE3 TJFLAG_FORCESSE3 -#define TJ_FASTUPSAMPLE TJFLAG_FASTUPSAMPLE - -#define TJPAD(width) (((width) + 3) & (~3)) - -DLLEXPORT unsigned long TJBUFSIZE(int width, int height); - -DLLEXPORT int tjCompress(tjhandle handle, unsigned char *srcBuf, int width, - int pitch, int height, int pixelSize, - unsigned char *dstBuf, unsigned long *compressedSize, - int jpegSubsamp, int jpegQual, int flags); - -DLLEXPORT int tjDecompress(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, unsigned char *dstBuf, - int width, int pitch, int height, int pixelSize, - int flags); - -DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, int *width, - int *height); - -DLLEXPORT int tjDestroy(tjhandle handle); - -DLLEXPORT char *tjGetErrorStr(void); - -DLLEXPORT tjhandle tjInitCompress(void); - -DLLEXPORT tjhandle tjInitDecompress(void); - -/* TurboJPEG 1.1+ */ - -#define TJ_YUV 512 - -DLLEXPORT unsigned long TJBUFSIZEYUV(int width, int height, int jpegSubsamp); - -DLLEXPORT int tjDecompressHeader2(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, int *width, - int *height, int *jpegSubsamp); - -DLLEXPORT int tjDecompressToYUV(tjhandle handle, unsigned char *jpegBuf, - unsigned long jpegSize, unsigned char *dstBuf, - int flags); - -DLLEXPORT int tjEncodeYUV(tjhandle handle, unsigned char *srcBuf, int width, - int pitch, int height, int pixelSize, - unsigned char *dstBuf, int subsamp, int flags); - -/* TurboJPEG 1.2+ */ - -#define TJFLAG_BOTTOMUP 2 -#define TJFLAG_FORCEMMX 8 -#define TJFLAG_FORCESSE 16 -#define TJFLAG_FORCESSE2 32 -#define TJFLAG_FORCESSE3 128 -#define TJFLAG_FASTUPSAMPLE 256 -#define TJFLAG_NOREALLOC 1024 - -DLLEXPORT unsigned char *tjAlloc(int bytes); - -DLLEXPORT unsigned long tjBufSize(int width, int height, int jpegSubsamp); - -DLLEXPORT unsigned long tjBufSizeYUV(int width, int height, int subsamp); - -DLLEXPORT int tjCompress2(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, int pixelFormat, - unsigned char **jpegBuf, unsigned long *jpegSize, - int jpegSubsamp, int jpegQual, int flags); - -DLLEXPORT int tjDecompress2(tjhandle handle, const unsigned char *jpegBuf, - unsigned long jpegSize, unsigned char *dstBuf, - int width, int pitch, int height, int pixelFormat, - int flags); - -DLLEXPORT int tjEncodeYUV2(tjhandle handle, unsigned char *srcBuf, int width, - int pitch, int height, int pixelFormat, - unsigned char *dstBuf, int subsamp, int flags); - -DLLEXPORT void tjFree(unsigned char *buffer); - -DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numscalingfactors); - -DLLEXPORT tjhandle tjInitTransform(void); - -DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf, - unsigned long jpegSize, int n, - unsigned char **dstBufs, unsigned long *dstSizes, - tjtransform *transforms, int flags); - -/* TurboJPEG 1.2.1+ */ - -#define TJFLAG_FASTDCT 2048 -#define TJFLAG_ACCURATEDCT 4096 - -/* TurboJPEG 1.4+ */ - -DLLEXPORT unsigned long tjBufSizeYUV2(int width, int align, int height, - int subsamp); - -DLLEXPORT int tjCompressFromYUV(tjhandle handle, const unsigned char *srcBuf, - int width, int align, int height, int subsamp, - unsigned char **jpegBuf, - unsigned long *jpegSize, int jpegQual, - int flags); - -DLLEXPORT int tjCompressFromYUVPlanes(tjhandle handle, - const unsigned char **srcPlanes, - int width, const int *strides, - int height, int subsamp, - unsigned char **jpegBuf, - unsigned long *jpegSize, int jpegQual, - int flags); - -DLLEXPORT int tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf, - int align, int subsamp, unsigned char *dstBuf, - int width, int pitch, int height, int pixelFormat, - int flags); - -DLLEXPORT int tjDecodeYUVPlanes(tjhandle handle, - const unsigned char **srcPlanes, - const int *strides, int subsamp, - unsigned char *dstBuf, int width, int pitch, - int height, int pixelFormat, int flags); - -DLLEXPORT int tjDecompressHeader3(tjhandle handle, - const unsigned char *jpegBuf, - unsigned long jpegSize, int *width, - int *height, int *jpegSubsamp, - int *jpegColorspace); - -DLLEXPORT int tjDecompressToYUV2(tjhandle handle, const unsigned char *jpegBuf, - unsigned long jpegSize, unsigned char *dstBuf, - int width, int align, int height, int flags); - -DLLEXPORT int tjDecompressToYUVPlanes(tjhandle handle, - const unsigned char *jpegBuf, - unsigned long jpegSize, - unsigned char **dstPlanes, int width, - int *strides, int height, int flags); - -DLLEXPORT int tjEncodeYUV3(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, int pixelFormat, - unsigned char *dstBuf, int align, int subsamp, - int flags); - -DLLEXPORT int tjEncodeYUVPlanes(tjhandle handle, const unsigned char *srcBuf, - int width, int pitch, int height, - int pixelFormat, unsigned char **dstPlanes, - int *strides, int subsamp, int flags); - -DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp); - -DLLEXPORT unsigned long tjPlaneSizeYUV(int componentID, int width, int stride, - int height, int subsamp); - -DLLEXPORT int tjPlaneWidth(int componentID, int width, int subsamp); - -/* TurboJPEG 2.0+ */ - -#define TJFLAG_STOPONWARNING 8192 -#define TJFLAG_PROGRESSIVE 16384 - -DLLEXPORT int tjGetErrorCode(tjhandle handle); - -DLLEXPORT char *tjGetErrorStr2(tjhandle handle); - -DLLEXPORT unsigned char *tjLoadImage(const char *filename, int *width, - int align, int *height, int *pixelFormat, - int flags); - -DLLEXPORT int tjSaveImage(const char *filename, unsigned char *buffer, - int width, int pitch, int height, int pixelFormat, - int flags); - -/* TurboJPEG 2.1+ */ - -#define TJFLAG_LIMITSCANS 32768 - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif