Upgrade libjpeg 8c -> 9e
This commit is contained in:
@@ -25,6 +25,7 @@ extern/libjpeg/jconfig.h
|
|||||||
___*
|
___*
|
||||||
*~
|
*~
|
||||||
*.log
|
*.log
|
||||||
|
!change.log
|
||||||
*.sublime-project
|
*.sublime-project
|
||||||
*.sublime-workspace
|
*.sublime-workspace
|
||||||
*.old
|
*.old
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
/* Borrowed from Wikipedia: Function prototype page. */
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int myfunction(int n);
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
printf("%d\n", myfunction()); /* Intentional: we want this to fail. */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int myfunction(int n) {
|
|
||||||
if (n == 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return n * myfunction(n - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -169,18 +169,6 @@ else()
|
|||||||
set(ENDIAN_LITTLE 1)
|
set(ENDIAN_LITTLE 1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
check_compile_features("${SM_CMAKE_DIR}/TestCode"
|
|
||||||
"${SM_CMAKE_DIR}/TestCode/test_prototype.c"
|
|
||||||
"Checking for function prototype capabilities"
|
|
||||||
"found"
|
|
||||||
"not found"
|
|
||||||
SM_IGNORED_PROTOTYPE_CALL
|
|
||||||
FALSE)
|
|
||||||
|
|
||||||
if(NOT SM_IGNORED_PROTOTYPE_CALL)
|
|
||||||
set(HAVE_PROTOTYPES TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
check_compile_features("${SM_CMAKE_DIR}/TestCode"
|
check_compile_features("${SM_CMAKE_DIR}/TestCode"
|
||||||
"${SM_CMAKE_DIR}/TestCode/test_external.c"
|
"${SM_CMAKE_DIR}/TestCode/test_external.c"
|
||||||
"Checking for external name shortening requirements"
|
"Checking for external name shortening requirements"
|
||||||
|
|||||||
Vendored
+79
-67
@@ -2,76 +2,85 @@ if(WITH_SYSTEM_JPEG)
|
|||||||
find_package(JPEG REQUIRED)
|
find_package(JPEG REQUIRED)
|
||||||
set(JPEG_LIBRARIES ${JPEG_LIBRARIES} PARENT_SCOPE)
|
set(JPEG_LIBRARIES ${JPEG_LIBRARIES} PARENT_SCOPE)
|
||||||
else()
|
else()
|
||||||
set(JPEG_DIR "${SM_EXTERN_DIR}/libjpeg")
|
configure_file("config.jpeg.in.h" "libjpeg/jconfig.h")
|
||||||
|
|
||||||
configure_file("${SM_EXTERN_DIR}/config.jpeg.in.h" "${JPEG_DIR}/jconfig.h")
|
set(JPEG_SRC "libjpeg/cjpegalt.c"
|
||||||
|
"libjpeg/djpegalt.c"
|
||||||
|
"libjpeg/jaricom.c"
|
||||||
|
"libjpeg/jcapimin.c"
|
||||||
|
"libjpeg/jcapistd.c"
|
||||||
|
"libjpeg/jcarith.c"
|
||||||
|
"libjpeg/jccoefct.c"
|
||||||
|
"libjpeg/jccolor.c"
|
||||||
|
"libjpeg/jcdctmgr.c"
|
||||||
|
"libjpeg/jchuff.c"
|
||||||
|
"libjpeg/jcinit.c"
|
||||||
|
"libjpeg/jcmainct.c"
|
||||||
|
"libjpeg/jcmarker.c"
|
||||||
|
"libjpeg/jcmaster.c"
|
||||||
|
"libjpeg/jcomapi.c"
|
||||||
|
"libjpeg/jcparam.c"
|
||||||
|
"libjpeg/jcprepct.c"
|
||||||
|
"libjpeg/jcsample.c"
|
||||||
|
"libjpeg/jctrans.c"
|
||||||
|
"libjpeg/jdapimin.c"
|
||||||
|
"libjpeg/jdapistd.c"
|
||||||
|
"libjpeg/jdarith.c"
|
||||||
|
"libjpeg/jdatadst.c"
|
||||||
|
"libjpeg/jdcoefct.c"
|
||||||
|
"libjpeg/jdcolor.c"
|
||||||
|
"libjpeg/jddctmgr.c"
|
||||||
|
"libjpeg/jdhuff.c"
|
||||||
|
"libjpeg/jdinput.c"
|
||||||
|
"libjpeg/jdmainct.c"
|
||||||
|
"libjpeg/jdmarker.c"
|
||||||
|
"libjpeg/jdmaster.c"
|
||||||
|
"libjpeg/jdmerge.c"
|
||||||
|
"libjpeg/jdpostct.c"
|
||||||
|
"libjpeg/jdsample.c"
|
||||||
|
"libjpeg/jdtrans.c"
|
||||||
|
"libjpeg/jerror.c"
|
||||||
|
"libjpeg/jfdctflt.c"
|
||||||
|
"libjpeg/jfdctfst.c"
|
||||||
|
"libjpeg/jfdctint.c"
|
||||||
|
"libjpeg/jidctflt.c"
|
||||||
|
"libjpeg/jidctfst.c"
|
||||||
|
"libjpeg/jidctint.c"
|
||||||
|
"libjpeg/jmemmgr.c"
|
||||||
|
"libjpeg/jmemnobs.c"
|
||||||
|
"libjpeg/jquant1.c"
|
||||||
|
"libjpeg/jquant2.c"
|
||||||
|
"libjpeg/jutils.c"
|
||||||
|
"libjpeg/rdbmp.c"
|
||||||
|
"libjpeg/rdcolmap.c"
|
||||||
|
"libjpeg/rdgif.c"
|
||||||
|
"libjpeg/rdjpgcom.c"
|
||||||
|
"libjpeg/rdppm.c"
|
||||||
|
"libjpeg/rdrle.c"
|
||||||
|
"libjpeg/rdswitch.c"
|
||||||
|
"libjpeg/rdtarga.c"
|
||||||
|
"libjpeg/transupp.c"
|
||||||
|
"libjpeg/wrbmp.c"
|
||||||
|
"libjpeg/wrgif.c"
|
||||||
|
"libjpeg/wrjpgcom.c"
|
||||||
|
"libjpeg/wrppm.c"
|
||||||
|
"libjpeg/wrrle.c"
|
||||||
|
"libjpeg/wrtarga.c")
|
||||||
|
|
||||||
if(NOT HAVE_PROTOTYPES)
|
set(JPEG_HPP "libjpeg/jconfig.h"
|
||||||
list(APPEND JPEG_SRC "${JPEG_DIR}/ansi2knr.c")
|
"libjpeg/jdct.h"
|
||||||
endif()
|
"libjpeg/jerror.h"
|
||||||
|
"libjpeg/jinclude.h"
|
||||||
|
"libjpeg/jmemsys.h"
|
||||||
|
"libjpeg/jmorecfg.h"
|
||||||
|
"libjpeg/jpegint.h"
|
||||||
|
"libjpeg/jpeglib.h"
|
||||||
|
"libjpeg/jversion.h"
|
||||||
|
"libjpeg/transupp.h")
|
||||||
|
|
||||||
list(APPEND JPEG_SRC
|
source_group("" FILES ${JPEG_SRC} ${JPEG_HPP})
|
||||||
"${JPEG_DIR}/jaricom.c"
|
|
||||||
"${JPEG_DIR}/jcapimin.c"
|
|
||||||
"${JPEG_DIR}/jcapistd.c"
|
|
||||||
"${JPEG_DIR}/jcarith.c"
|
|
||||||
"${JPEG_DIR}/jccoefct.c"
|
|
||||||
"${JPEG_DIR}/jccolor.c"
|
|
||||||
"${JPEG_DIR}/jcdctmgr.c"
|
|
||||||
"${JPEG_DIR}/jchuff.c"
|
|
||||||
"${JPEG_DIR}/jcinit.c"
|
|
||||||
"${JPEG_DIR}/jcmainct.c"
|
|
||||||
"${JPEG_DIR}/jcmarker.c"
|
|
||||||
"${JPEG_DIR}/jcmaster.c"
|
|
||||||
"${JPEG_DIR}/jcomapi.c"
|
|
||||||
"${JPEG_DIR}/jcparam.c"
|
|
||||||
"${JPEG_DIR}/jcprepct.c"
|
|
||||||
"${JPEG_DIR}/jcsample.c"
|
|
||||||
"${JPEG_DIR}/jctrans.c"
|
|
||||||
"${JPEG_DIR}/jdapimin.c"
|
|
||||||
"${JPEG_DIR}/jdapistd.c"
|
|
||||||
"${JPEG_DIR}/jdarith.c"
|
|
||||||
"${JPEG_DIR}/jdatadst.c"
|
|
||||||
"${JPEG_DIR}/jdcoefct.c"
|
|
||||||
"${JPEG_DIR}/jdcolor.c"
|
|
||||||
"${JPEG_DIR}/jddctmgr.c"
|
|
||||||
"${JPEG_DIR}/jdhuff.c"
|
|
||||||
"${JPEG_DIR}/jdinput.c"
|
|
||||||
"${JPEG_DIR}/jdmainct.c"
|
|
||||||
"${JPEG_DIR}/jdmarker.c"
|
|
||||||
"${JPEG_DIR}/jdmaster.c"
|
|
||||||
"${JPEG_DIR}/jdmerge.c"
|
|
||||||
"${JPEG_DIR}/jdpostct.c"
|
|
||||||
"${JPEG_DIR}/jdsample.c"
|
|
||||||
"${JPEG_DIR}/jdtrans.c"
|
|
||||||
"${JPEG_DIR}/jerror.c"
|
|
||||||
"${JPEG_DIR}/jfdctflt.c"
|
|
||||||
"${JPEG_DIR}/jfdctfst.c"
|
|
||||||
"${JPEG_DIR}/jfdctint.c"
|
|
||||||
"${JPEG_DIR}/jutils.c"
|
|
||||||
"${JPEG_DIR}/jidctflt.c"
|
|
||||||
"${JPEG_DIR}/jidctfst.c"
|
|
||||||
"${JPEG_DIR}/jidctint.c"
|
|
||||||
"${JPEG_DIR}/jmemmgr.c"
|
|
||||||
"${JPEG_DIR}/jmemnobs.c"
|
|
||||||
"${JPEG_DIR}/jquant1.c"
|
|
||||||
"${JPEG_DIR}/jquant2.c")
|
|
||||||
|
|
||||||
list(APPEND JPEG_HPP
|
add_library("jpeg" STATIC ${JPEG_SRC} ${JPEG_HPP})
|
||||||
"${JPEG_DIR}/jconfig.h"
|
|
||||||
"${JPEG_DIR}/jdct.h"
|
|
||||||
"${JPEG_DIR}/jerror.h"
|
|
||||||
"${JPEG_DIR}/jinclude.h"
|
|
||||||
"${JPEG_DIR}/jmemsys.h"
|
|
||||||
"${JPEG_DIR}/jmorecfg.h"
|
|
||||||
"${JPEG_DIR}/jpegint.h"
|
|
||||||
"${JPEG_DIR}/jpeglib.h"
|
|
||||||
"${JPEG_DIR}/jversion.h")
|
|
||||||
|
|
||||||
source_group("Source Files" FILES ${JPEG_SRC})
|
|
||||||
source_group("Header Files" FILES ${JPEG_HPP})
|
|
||||||
|
|
||||||
add_library("jpeg" ${JPEG_SRC} ${JPEG_HPP})
|
|
||||||
|
|
||||||
disable_project_warnings("jpeg")
|
disable_project_warnings("jpeg")
|
||||||
|
|
||||||
@@ -81,5 +90,8 @@ else()
|
|||||||
target_compile_definitions("jpeg" PRIVATE _CRT_SECURE_NO_WARNINGS)
|
target_compile_definitions("jpeg" PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||||
endif(MSVC)
|
endif(MSVC)
|
||||||
|
|
||||||
target_include_directories("jpeg" PUBLIC "${JPEG_DIR}")
|
target_include_directories("jpeg" PUBLIC
|
||||||
|
"libjpeg"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/libjpeg"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Vendored
+1
-10
@@ -1,7 +1,7 @@
|
|||||||
/* Auto-generated config.h file powered by cmake. */
|
/* Auto-generated config.h file powered by cmake. */
|
||||||
|
|
||||||
/* Defined to 1 if the compiler supports prototype functions. */
|
/* Defined to 1 if the compiler supports prototype functions. */
|
||||||
#cmakedefine HAVE_PROTOTYPES 1
|
#define HAVE_PROTOTYPES 1
|
||||||
|
|
||||||
/* Defined to 1 if we have access to stddef.h */
|
/* Defined to 1 if we have access to stddef.h */
|
||||||
#cmakedefine HAVE_STDDEF_H 1
|
#cmakedefine HAVE_STDDEF_H 1
|
||||||
@@ -42,12 +42,3 @@
|
|||||||
|
|
||||||
/* Defined to 1 if incomplete types are broken. */
|
/* Defined to 1 if incomplete types are broken. */
|
||||||
#cmakedefine INCOMPLETE_TYPES_BROKEN 1
|
#cmakedefine INCOMPLETE_TYPES_BROKEN 1
|
||||||
|
|
||||||
/* Windows gets a special definition of boolean for some reason. */
|
|
||||||
#if defined(WIN32)
|
|
||||||
#if !defined(__RPCNDR_H__)
|
|
||||||
typedef unsigned char boolean;
|
|
||||||
#endif
|
|
||||||
#define HAVE_BOOLEAN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|||||||
Vendored
+143
@@ -0,0 +1,143 @@
|
|||||||
|
## Process this file with automake to produce Makefile.in
|
||||||
|
#
|
||||||
|
# Automake Makefile for the JPEG library
|
||||||
|
#
|
||||||
|
# This file is written by Bob Friesenhahn, Guido Vollbeding
|
||||||
|
#
|
||||||
|
|
||||||
|
# Sources to build library
|
||||||
|
LIBSOURCES = jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \
|
||||||
|
jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \
|
||||||
|
jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \
|
||||||
|
jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \
|
||||||
|
jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \
|
||||||
|
jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \
|
||||||
|
jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \
|
||||||
|
jquant2.c jutils.c jmemmgr.c @[email protected]
|
||||||
|
|
||||||
|
# System dependent sources
|
||||||
|
SYSDEPSOURCES = jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c
|
||||||
|
|
||||||
|
# Headers which are installed to support the library
|
||||||
|
INSTINCLUDES = jerror.h jmorecfg.h jpeglib.h
|
||||||
|
|
||||||
|
# Headers which are not installed
|
||||||
|
OTHERINCLUDES = cderror.h cdjpeg.h jdct.h jinclude.h jmemsys.h jpegint.h \
|
||||||
|
jversion.h transupp.h
|
||||||
|
|
||||||
|
# Manual pages (Automake uses 'MANS' for itself)
|
||||||
|
DISTMANS= cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 wrjpgcom.1
|
||||||
|
|
||||||
|
# Other documentation files
|
||||||
|
DOCS= README install.txt usage.txt wizard.txt example.c libjpeg.txt \
|
||||||
|
structure.txt coderules.txt filelist.txt cdaltui.txt change.log
|
||||||
|
|
||||||
|
# Makefiles for various systems
|
||||||
|
MKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \
|
||||||
|
makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \
|
||||||
|
makefile.vs makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 \
|
||||||
|
makejmak.vc6 makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 \
|
||||||
|
makeddsp.vc6 makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 \
|
||||||
|
makerdep.vc6 makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 \
|
||||||
|
makewmak.vc6 makejsln.v16 makeasln.v16 makejvcx.v16 makejfil.v16 \
|
||||||
|
makecvcx.v16 makecfil.v16 makedvcx.v16 makedfil.v16 maketvcx.v16 \
|
||||||
|
maketfil.v16 makervcx.v16 makerfil.v16 makewvcx.v16 makewfil.v16 \
|
||||||
|
makejvcx.v17 makecvcx.v17 makedvcx.v17 maketvcx.v17 makervcx.v17 \
|
||||||
|
makewvcx.v17 makeproj.mac makcjpeg.st makdjpeg.st makljpeg.st \
|
||||||
|
maktjpeg.st makefile.manx makefile.sas makefile.mms makefile.vms \
|
||||||
|
makvms.opt
|
||||||
|
|
||||||
|
# Configuration files
|
||||||
|
CONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \
|
||||||
|
jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \
|
||||||
|
jconfig.vms
|
||||||
|
|
||||||
|
# Support scripts for configure
|
||||||
|
CONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \
|
||||||
|
missing ar-lib
|
||||||
|
|
||||||
|
# Miscellaneous support files
|
||||||
|
OTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map libjpeg.pc.in \
|
||||||
|
cjpegalt.c djpegalt.c
|
||||||
|
|
||||||
|
# Test support files
|
||||||
|
TESTFILES= testorig.jpg testimg.ppm testimg.gif testimg.bmp testimg.jpg \
|
||||||
|
testprog.jpg testimgp.jpg
|
||||||
|
|
||||||
|
# libtool libraries to build
|
||||||
|
lib_LTLIBRARIES = libjpeg.la
|
||||||
|
|
||||||
|
# Library sources for libjpeg.la
|
||||||
|
libjpeg_la_SOURCES = $(LIBSOURCES)
|
||||||
|
|
||||||
|
# LDFLAGS for libjpeg.la
|
||||||
|
libjpeg_la_LDFLAGS = -no-undefined \
|
||||||
|
-version-info $(JPEG_LIB_VERSION)
|
||||||
|
|
||||||
|
if HAVE_LD_VERSION_SCRIPT
|
||||||
|
libjpeg_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libjpeg.map
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Executables to build
|
||||||
|
bin_PROGRAMS = cjpeg djpeg jpegtran rdjpgcom wrjpgcom
|
||||||
|
|
||||||
|
# Executable sources & libs
|
||||||
|
cjpeg_SOURCES = cjpeg.c rdppm.c rdgif.c rdtarga.c rdrle.c rdbmp.c \
|
||||||
|
rdswitch.c cdjpeg.c
|
||||||
|
cjpeg_LDADD = libjpeg.la
|
||||||
|
djpeg_SOURCES = djpeg.c wrppm.c wrgif.c wrtarga.c wrrle.c wrbmp.c \
|
||||||
|
rdcolmap.c cdjpeg.c
|
||||||
|
djpeg_LDADD = libjpeg.la
|
||||||
|
jpegtran_SOURCES = jpegtran.c rdswitch.c cdjpeg.c transupp.c
|
||||||
|
jpegtran_LDADD = libjpeg.la
|
||||||
|
rdjpgcom_SOURCES = rdjpgcom.c
|
||||||
|
wrjpgcom_SOURCES = wrjpgcom.c
|
||||||
|
|
||||||
|
# Manual pages to install
|
||||||
|
man_MANS = $(DISTMANS)
|
||||||
|
|
||||||
|
# Headers to install
|
||||||
|
include_HEADERS = $(INSTINCLUDES)
|
||||||
|
|
||||||
|
# Other distributed headers
|
||||||
|
noinst_HEADERS = $(OTHERINCLUDES)
|
||||||
|
|
||||||
|
# Other distributed files
|
||||||
|
EXTRA_DIST = $(DOCS) $(DISTMANS) $(MKFILES) $(CONFIGFILES) $(SYSDEPSOURCES) \
|
||||||
|
$(OTHERFILES) $(TESTFILES)
|
||||||
|
|
||||||
|
# pkg-config file
|
||||||
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
|
nodist_pkgconfig_DATA = libjpeg.pc
|
||||||
|
|
||||||
|
# Files to be cleaned
|
||||||
|
CLEANFILES = testout.ppm testout.gif testout.bmp testout.jpg testoutp.ppm \
|
||||||
|
testoutp.jpg testoutt.jpg
|
||||||
|
|
||||||
|
# Install jconfig.h
|
||||||
|
install-data-local:
|
||||||
|
$(mkinstalldirs) $(DESTDIR)$(includedir)
|
||||||
|
$(INSTALL_HEADER) jconfig.h $(DESTDIR)$(includedir)/jconfig.h
|
||||||
|
|
||||||
|
# Uninstall jconfig.h
|
||||||
|
uninstall-local:
|
||||||
|
rm -f $(DESTDIR)$(includedir)/jconfig.h
|
||||||
|
|
||||||
|
# Run tests
|
||||||
|
test: check-local
|
||||||
|
check-local:
|
||||||
|
rm -f testout*
|
||||||
|
./djpeg -dct int -ppm -outfile testout.ppm $(srcdir)/testorig.jpg
|
||||||
|
./djpeg -dct int -gif -outfile testout.gif $(srcdir)/testorig.jpg
|
||||||
|
./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testorig.jpg
|
||||||
|
./cjpeg -dct int -outfile testout.jpg $(srcdir)/testimg.ppm
|
||||||
|
./djpeg -dct int -ppm -outfile testoutp.ppm $(srcdir)/testprog.jpg
|
||||||
|
./cjpeg -dct int -progressive -opt -outfile testoutp.jpg $(srcdir)/testimg.ppm
|
||||||
|
./jpegtran -outfile testoutt.jpg $(srcdir)/testprog.jpg
|
||||||
|
cmp $(srcdir)/testimg.ppm testout.ppm
|
||||||
|
cmp $(srcdir)/testimg.gif testout.gif
|
||||||
|
cmp $(srcdir)/testimg.bmp testout.bmp
|
||||||
|
cmp $(srcdir)/testimg.jpg testout.jpg
|
||||||
|
cmp $(srcdir)/testimg.ppm testoutp.ppm
|
||||||
|
cmp $(srcdir)/testimgp.jpg testoutp.jpg
|
||||||
|
cmp $(srcdir)/testorig.jpg testoutt.jpg
|
||||||
Vendored
+1249
File diff suppressed because it is too large
Load Diff
Vendored
+106
-58
@@ -1,19 +1,20 @@
|
|||||||
The Independent JPEG Group's JPEG software
|
The Independent JPEG Group's JPEG software
|
||||||
==========================================
|
==========================================
|
||||||
|
|
||||||
README for release 8c of 16-Jan-2011
|
README for release 9e of 16-Jan-2022
|
||||||
====================================
|
====================================
|
||||||
|
|
||||||
This distribution contains the eighth public release of the Independent JPEG
|
This distribution contains the ninth public release of the Independent JPEG
|
||||||
Group's free JPEG software. You are welcome to redistribute this software and
|
Group's free JPEG software. You are welcome to redistribute this software and
|
||||||
to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
|
to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
|
||||||
|
|
||||||
This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone,
|
This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone,
|
||||||
Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson,
|
Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson,
|
||||||
Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers,
|
John Korejwa, Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi,
|
||||||
and other members of the Independent JPEG Group.
|
Ge' Weijers, and other members of the Independent JPEG Group.
|
||||||
|
|
||||||
IJG is not affiliated with the official ISO JPEG standards committee.
|
IJG is not affiliated with the ISO/IEC JTC1/SC29/WG1 standards committee
|
||||||
|
(previously known as JPEG, together with ITU-T SG16).
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION ROADMAP
|
DOCUMENTATION ROADMAP
|
||||||
@@ -37,6 +38,7 @@ User documentation:
|
|||||||
rdjpgcom, and wrjpgcom.
|
rdjpgcom, and wrjpgcom.
|
||||||
*.1 Unix-style man pages for programs (same info as usage.txt).
|
*.1 Unix-style man pages for programs (same info as usage.txt).
|
||||||
wizard.txt Advanced usage instructions for JPEG wizards only.
|
wizard.txt Advanced usage instructions for JPEG wizards only.
|
||||||
|
cdaltui.txt Description of alternate user interface for cjpeg/djpeg.
|
||||||
change.log Version-to-version change highlights.
|
change.log Version-to-version change highlights.
|
||||||
Programmer and internal documentation:
|
Programmer and internal documentation:
|
||||||
libjpeg.txt How to use the JPEG library in your own programs.
|
libjpeg.txt How to use the JPEG library in your own programs.
|
||||||
@@ -59,7 +61,7 @@ OVERVIEW
|
|||||||
|
|
||||||
This package contains C software to implement JPEG image encoding, decoding,
|
This package contains C software to implement JPEG image encoding, decoding,
|
||||||
and transcoding. JPEG (pronounced "jay-peg") is a standardized compression
|
and transcoding. JPEG (pronounced "jay-peg") is a standardized compression
|
||||||
method for full-color and gray-scale images.
|
method for full-color and grayscale images.
|
||||||
|
|
||||||
This software implements JPEG baseline, extended-sequential, and progressive
|
This software implements JPEG baseline, extended-sequential, and progressive
|
||||||
compression processes. Provision is made for supporting all variants of these
|
compression processes. Provision is made for supporting all variants of these
|
||||||
@@ -114,7 +116,7 @@ with respect to this software, its quality, accuracy, merchantability, or
|
|||||||
fitness for a particular purpose. This software is provided "AS IS", and you,
|
fitness for a particular purpose. This software is provided "AS IS", and you,
|
||||||
its user, assume the entire risk as to its quality and accuracy.
|
its user, assume the entire risk as to its quality and accuracy.
|
||||||
|
|
||||||
This software is copyright (C) 1991-2011, Thomas G. Lane, Guido Vollbeding.
|
This software is copyright (C) 1991-2022, Thomas G. Lane, Guido Vollbeding.
|
||||||
All Rights Reserved except as specified below.
|
All Rights Reserved except as specified below.
|
||||||
|
|
||||||
Permission is hereby granted to use, copy, modify, and distribute this
|
Permission is hereby granted to use, copy, modify, and distribute this
|
||||||
@@ -145,33 +147,12 @@ commercial products, provided that all warranty or liability claims are
|
|||||||
assumed by the product vendor.
|
assumed by the product vendor.
|
||||||
|
|
||||||
|
|
||||||
ansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
|
|
||||||
sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
|
|
||||||
ansi2knr.c is NOT covered by the above copyright and conditions, but instead
|
|
||||||
by the usual distribution terms of the Free Software Foundation; principally,
|
|
||||||
that you must include source code if you redistribute it. (See the file
|
|
||||||
ansi2knr.c for full details.) However, since ansi2knr.c is not needed as part
|
|
||||||
of any program generated from the IJG code, this does not limit you more than
|
|
||||||
the foregoing paragraphs do.
|
|
||||||
|
|
||||||
The Unix configuration script "configure" was produced with GNU Autoconf.
|
The Unix configuration script "configure" was produced with GNU Autoconf.
|
||||||
It is copyright by the Free Software Foundation but is freely distributable.
|
It is copyright by the Free Software Foundation but is freely distributable.
|
||||||
The same holds for its supporting scripts (config.guess, config.sub,
|
The same holds for its supporting scripts (config.guess, config.sub,
|
||||||
ltmain.sh). Another support script, install-sh, is copyright by X Consortium
|
ltmain.sh). Another support script, install-sh, is copyright by X Consortium
|
||||||
but is also freely distributable.
|
but is also freely distributable.
|
||||||
|
|
||||||
The IJG distribution formerly included code to read and write GIF files.
|
|
||||||
To avoid entanglement with the Unisys LZW patent, GIF reading support has
|
|
||||||
been removed altogether, and the GIF writer has been simplified to produce
|
|
||||||
"uncompressed GIFs". This technique does not use the LZW algorithm; the
|
|
||||||
resulting GIF files are larger than usual, but are readable by all standard
|
|
||||||
GIF decoders.
|
|
||||||
|
|
||||||
We are required to state that
|
|
||||||
"The Graphics Interchange Format(c) is the Copyright property of
|
|
||||||
CompuServe Incorporated. GIF(sm) is a Service Mark property of
|
|
||||||
CompuServe Incorporated."
|
|
||||||
|
|
||||||
|
|
||||||
REFERENCES
|
REFERENCES
|
||||||
==========
|
==========
|
||||||
@@ -184,8 +165,8 @@ The best short technical introduction to the JPEG compression algorithm is
|
|||||||
Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
|
Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
|
||||||
(Adjacent articles in that issue discuss MPEG motion picture compression,
|
(Adjacent articles in that issue discuss MPEG motion picture compression,
|
||||||
applications of JPEG, and related topics.) If you don't have the CACM issue
|
applications of JPEG, and related topics.) If you don't have the CACM issue
|
||||||
handy, a PostScript file containing a revised version of Wallace's article is
|
handy, a PDF file containing a revised version of Wallace's article is
|
||||||
available at http://www.ijg.org/files/wallace.ps.gz. The file (actually
|
available at https://www.ijg.org/files/Wallace.JPEG.pdf. The file (actually
|
||||||
a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
|
a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
|
||||||
omits the sample images that appeared in CACM, but it includes corrections
|
omits the sample images that appeared in CACM, but it includes corrections
|
||||||
and some added material. Note: the Wallace article is copyright ACM and IEEE,
|
and some added material. Note: the Wallace article is copyright ACM and IEEE,
|
||||||
@@ -221,20 +202,24 @@ Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS
|
|||||||
10918-1, ITU-T T.81. Part 2 is titled "Digital Compression and Coding of
|
10918-1, ITU-T T.81. Part 2 is titled "Digital Compression and Coding of
|
||||||
Continuous-tone Still Images, Part 2: Compliance testing" and has document
|
Continuous-tone Still Images, Part 2: Compliance testing" and has document
|
||||||
numbers ISO/IEC IS 10918-2, ITU-T T.83.
|
numbers ISO/IEC IS 10918-2, ITU-T T.83.
|
||||||
IJG JPEG 8 introduces an implementation of the JPEG SmartScale extension
|
IJG JPEG 8 introduced an implementation of the JPEG SmartScale extension
|
||||||
which is specified in a contributed document at ITU and ISO with title "ITU-T
|
which is specified in two documents: A contributed document at ITU and ISO
|
||||||
JPEG-Plus Proposal for Extending ITU-T T.81 for Advanced Image Coding", April
|
with title "ITU-T JPEG-Plus Proposal for Extending ITU-T T.81 for Advanced
|
||||||
2006, Geneva, Switzerland. The latest version of the document is Revision 3.
|
Image Coding", April 2006, Geneva, Switzerland. The latest version of this
|
||||||
|
document is Revision 3. And a contributed document ISO/IEC JTC1/SC29/WG1 N
|
||||||
|
5799 with title "Evolution of JPEG", June/July 2011, Berlin, Germany.
|
||||||
|
IJG JPEG 9 introduces a reversible color transform for improved lossless
|
||||||
|
compression which is described in a contributed document ISO/IEC JTC1/SC29/
|
||||||
|
WG1 N 6080 with title "JPEG 9 Lossless Coding", June/July 2012, Paris, France.
|
||||||
|
|
||||||
The JPEG standard does not specify all details of an interchangeable file
|
The JPEG standard does not specify all details of an interchangeable file
|
||||||
format. For the omitted details we follow the "JFIF" conventions, revision
|
format. For the omitted details we follow the "JFIF" conventions, version 2.
|
||||||
1.02. JFIF 1.02 has been adopted as an Ecma International Technical Report
|
JFIF version 1 has been adopted as Recommendation ITU-T T.871 (05/2011) :
|
||||||
and thus received a formal publication status. It is available as a free
|
Information technology - Digital compression and coding of continuous-tone
|
||||||
download in PDF format from
|
still images: JPEG File Interchange Format (JFIF). It is available as a
|
||||||
http://www.ecma-international.org/publications/techreports/E-TR-098.htm.
|
free download in PDF file format from https://www.itu.int/rec/T-REC-T.871.
|
||||||
A PostScript version of the JFIF document is available at
|
A PDF file of the older JFIF document is available at
|
||||||
http://www.ijg.org/files/jfif.ps.gz. There is also a plain text version at
|
https://www.w3.org/Graphics/JPEG/jfif3.pdf.
|
||||||
http://www.ijg.org/files/jfif.txt.gz, but it is missing the figures.
|
|
||||||
|
|
||||||
The TIFF 6.0 file format specification can be obtained by FTP from
|
The TIFF 6.0 file format specification can be obtained by FTP from
|
||||||
ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme
|
ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme
|
||||||
@@ -242,7 +227,7 @@ found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.
|
|||||||
IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
|
IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
|
||||||
Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
|
Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
|
||||||
(Compression tag 7). Copies of this Note can be obtained from
|
(Compression tag 7). Copies of this Note can be obtained from
|
||||||
http://www.ijg.org/files/. It is expected that the next revision
|
https://www.ijg.org/files/. It is expected that the next revision
|
||||||
of the TIFF spec will replace the 6.0 JPEG design with the Note's design.
|
of the TIFF spec will replace the 6.0 JPEG design with the Note's design.
|
||||||
Although IJG's own code does not support TIFF/JPEG, the free libtiff library
|
Although IJG's own code does not support TIFF/JPEG, the free libtiff library
|
||||||
uses our library to implement TIFF/JPEG per the Note.
|
uses our library to implement TIFF/JPEG per the Note.
|
||||||
@@ -253,9 +238,11 @@ ARCHIVE LOCATIONS
|
|||||||
|
|
||||||
The "official" archive site for this software is www.ijg.org.
|
The "official" archive site for this software is www.ijg.org.
|
||||||
The most recent released version can always be found there in
|
The most recent released version can always be found there in
|
||||||
directory "files". This particular version will be archived as
|
directory "files". This particular version will be archived
|
||||||
http://www.ijg.org/files/jpegsrc.v8c.tar.gz, and in Windows-compatible
|
in Windows-compatible "zip" archive format as
|
||||||
"zip" archive format as http://www.ijg.org/files/jpegsr8c.zip.
|
https://www.ijg.org/files/jpegsr9e.zip, and
|
||||||
|
in Unix-compatible "tar.gz" archive format as
|
||||||
|
https://www.ijg.org/files/jpegsrc.v9e.tar.gz.
|
||||||
|
|
||||||
The JPEG FAQ (Frequently Asked Questions) article is a source of some
|
The JPEG FAQ (Frequently Asked Questions) article is a source of some
|
||||||
general information about JPEG.
|
general information about JPEG.
|
||||||
@@ -281,6 +268,10 @@ ITU JPEG (Study Group 16) meeting in Geneva, Switzerland.
|
|||||||
Thank to Thomas Wiegand and Gary Sullivan for inviting me to the
|
Thank to Thomas Wiegand and Gary Sullivan for inviting me to the
|
||||||
Joint Video Team (MPEG & ITU) meeting in Geneva, Switzerland.
|
Joint Video Team (MPEG & ITU) meeting in Geneva, Switzerland.
|
||||||
|
|
||||||
|
Thank to Thomas Richter and Daniel Lee for inviting me to the
|
||||||
|
ISO/IEC JTC1/SC29/WG1 (previously known as JPEG, together with ITU-T SG16)
|
||||||
|
meeting in Berlin, Germany.
|
||||||
|
|
||||||
Thank to John Korejwa and Massimo Ballerini for inviting me to
|
Thank to John Korejwa and Massimo Ballerini for inviting me to
|
||||||
fruitful consultations in Boston, MA and Milan, Italy.
|
fruitful consultations in Boston, MA and Milan, Italy.
|
||||||
|
|
||||||
@@ -297,30 +288,87 @@ communication about JPEG configuration in Sigma Photo Pro software.
|
|||||||
|
|
||||||
Thank to Andrew Finkenstadt for hosting the ijg.org site.
|
Thank to Andrew Finkenstadt for hosting the ijg.org site.
|
||||||
|
|
||||||
Last but not least special thank to Thomas G. Lane for the original
|
Thank to Thomas G. Lane for the original design and development
|
||||||
design and development of this singular software package.
|
of this singular software package.
|
||||||
|
|
||||||
|
Thank to Lars Goehler, Andreas Heinecke, Sebastian Fuss,
|
||||||
|
Yvonne Roebert, Andrej Werner, Ulf-Dietrich Braumann,
|
||||||
|
and Nina Ssymank for support and public relations.
|
||||||
|
|
||||||
|
|
||||||
FILE FORMAT WARS
|
FILE FORMAT WARS
|
||||||
================
|
================
|
||||||
|
|
||||||
The ISO JPEG standards committee actually promotes different formats like
|
The ISO/IEC JTC1/SC29/WG1 standards committee (previously known as JPEG,
|
||||||
"JPEG 2000" or "JPEG XR" which are incompatible with original DCT-based
|
together with ITU-T SG16) currently promotes different formats containing
|
||||||
JPEG and which are based on faulty technologies. IJG therefore does not
|
the name "JPEG" which is misleading because these formats are incompatible
|
||||||
and will not support such momentary mistakes (see REFERENCES).
|
with original DCT-based JPEG and are based on faulty technologies.
|
||||||
We have little or no sympathy for the promotion of these formats. Indeed,
|
IJG therefore does not and will not support such momentary mistakes
|
||||||
one of the original reasons for developing this free software was to help
|
(see REFERENCES).
|
||||||
force convergence on common, interoperable format standards for JPEG files.
|
There exist also distributions under the name "OpenJPEG" promoting such
|
||||||
|
kind of formats which is misleading because they don't support original
|
||||||
|
JPEG images.
|
||||||
|
We have no sympathy for the promotion of inferior formats. Indeed, one of
|
||||||
|
the original reasons for developing this free software was to help force
|
||||||
|
convergence on common, interoperable format standards for JPEG files.
|
||||||
Don't use an incompatible file format!
|
Don't use an incompatible file format!
|
||||||
(In any case, our decoder will remain capable of reading existing JPEG
|
(In any case, our decoder will remain capable of reading existing JPEG
|
||||||
image files indefinitely.)
|
image files indefinitely.)
|
||||||
|
|
||||||
|
The ISO committee pretends to be "responsible for the popular JPEG" in their
|
||||||
|
public reports which is not true because they don't respond to actual
|
||||||
|
requirements for the maintenance of the original JPEG specification.
|
||||||
|
Furthermore, the ISO committee pretends to "ensure interoperability" with
|
||||||
|
their standards which is not true because their "standards" support only
|
||||||
|
application-specific and proprietary use cases and contain mathematically
|
||||||
|
incorrect code.
|
||||||
|
|
||||||
|
There are currently different distributions in circulation containing the
|
||||||
|
name "libjpeg" which is misleading because they don't have the features and
|
||||||
|
are incompatible with formats supported by actual IJG libjpeg distributions.
|
||||||
|
One of those fakes is released by members of the ISO committee and just uses
|
||||||
|
the name of libjpeg for misdirection of people, similar to the abuse of the
|
||||||
|
name JPEG as described above, while having nothing in common with actual IJG
|
||||||
|
libjpeg distributions and containing mathematically incorrect code.
|
||||||
|
The other one claims to be a "derivative" or "fork" of the original libjpeg,
|
||||||
|
but violates the license conditions as described under LEGAL ISSUES above
|
||||||
|
and violates basic C programming properties.
|
||||||
|
We have no sympathy for the release of misleading, incorrect and illegal
|
||||||
|
distributions derived from obsolete code bases.
|
||||||
|
Don't use an obsolete code base!
|
||||||
|
|
||||||
|
According to the UCC (Uniform Commercial Code) law, IJG has the lawful and
|
||||||
|
legal right to foreclose on certain standardization bodies and other
|
||||||
|
institutions or corporations that knowingly perform substantial and
|
||||||
|
systematic deceptive acts and practices, fraud, theft, and damaging of the
|
||||||
|
value of the people of this planet without their knowing, willing and
|
||||||
|
intentional consent.
|
||||||
|
The titles, ownership, and rights of these institutions and all their assets
|
||||||
|
are now duly secured and held in trust for the free people of this planet.
|
||||||
|
People of the planet, on every country, may have a financial interest in
|
||||||
|
the assets of these former principals, agents, and beneficiaries of the
|
||||||
|
foreclosed institutions and corporations.
|
||||||
|
IJG asserts what is: that each man, woman, and child has unalienable value
|
||||||
|
and rights granted and deposited in them by the Creator and not any one of
|
||||||
|
the people is subordinate to any artificial principality, corporate fiction
|
||||||
|
or the special interest of another without their appropriate knowing,
|
||||||
|
willing and intentional consent made by contract or accommodation agreement.
|
||||||
|
IJG expresses that which already was.
|
||||||
|
The people have already determined and demanded that public administration
|
||||||
|
entities, national governments, and their supporting judicial systems must
|
||||||
|
be fully transparent, accountable, and liable.
|
||||||
|
IJG has secured the value for all concerned free people of the planet.
|
||||||
|
|
||||||
|
A partial list of foreclosed institutions and corporations ("Hall of Shame")
|
||||||
|
is currently prepared and will be published later.
|
||||||
|
|
||||||
|
|
||||||
TO DO
|
TO DO
|
||||||
=====
|
=====
|
||||||
|
|
||||||
Version 8 is the first release of a new generation JPEG standard
|
Version 9 is the second release of a new generation JPEG standard
|
||||||
to overcome the limitations of the original JPEG specification.
|
to overcome the limitations of the original JPEG specification,
|
||||||
|
and is the first true source reference JPEG codec.
|
||||||
More features are being prepared for coming releases...
|
More features are being prepared for coming releases...
|
||||||
|
|
||||||
Please send bug reports, offers of help, etc. to jpeg-info@uc.ag.
|
Please send bug reports, offers of help, etc. to jpeg-info@jpegclub.org.
|
||||||
|
|||||||
Vendored
+10275
File diff suppressed because it is too large
Load Diff
Vendored
-739
@@ -1,739 +0,0 @@
|
|||||||
/* Copyright (C) 1989, 2000 Aladdin Enterprises. All rights reserved. */
|
|
||||||
|
|
||||||
/*$Id: ansi2knr.c,v 1.14 2003/09/06 05:36:56 eggert Exp $*/
|
|
||||||
/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
|
|
||||||
|
|
||||||
/*
|
|
||||||
ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
||||||
WARRANTY. No author or distributor accepts responsibility to anyone for the
|
|
||||||
consequences of using it or for whether it serves any particular purpose or
|
|
||||||
works at all, unless he says so in writing. Refer to the GNU General Public
|
|
||||||
License (the "GPL") for full details.
|
|
||||||
|
|
||||||
Everyone is granted permission to copy, modify and redistribute ansi2knr,
|
|
||||||
but only under the conditions described in the GPL. A copy of this license
|
|
||||||
is supposed to have been given to you along with ansi2knr so you can know
|
|
||||||
your rights and responsibilities. It should be in a file named COPYLEFT,
|
|
||||||
or, if there is no file named COPYLEFT, a file named COPYING. Among other
|
|
||||||
things, the copyright notice and this notice must be preserved on all
|
|
||||||
copies.
|
|
||||||
|
|
||||||
We explicitly state here what we believe is already implied by the GPL: if
|
|
||||||
the ansi2knr program is distributed as a separate set of sources and a
|
|
||||||
separate executable file which are aggregated on a storage medium together
|
|
||||||
with another program, this in itself does not bring the other program under
|
|
||||||
the GPL, nor does the mere fact that such a program or the procedures for
|
|
||||||
constructing it invoke the ansi2knr executable bring any other part of the
|
|
||||||
program under the GPL.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Usage:
|
|
||||||
ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]
|
|
||||||
* --filename provides the file name for the #line directive in the output,
|
|
||||||
* overriding input_file (if present).
|
|
||||||
* If no input_file is supplied, input is read from stdin.
|
|
||||||
* If no output_file is supplied, output goes to stdout.
|
|
||||||
* There are no error messages.
|
|
||||||
*
|
|
||||||
* ansi2knr recognizes function definitions by seeing a non-keyword
|
|
||||||
* identifier at the left margin, followed by a left parenthesis, with a
|
|
||||||
* right parenthesis as the last character on the line, and with a left
|
|
||||||
* brace as the first token on the following line (ignoring possible
|
|
||||||
* intervening comments and/or preprocessor directives), except that a line
|
|
||||||
* consisting of only
|
|
||||||
* identifier1(identifier2)
|
|
||||||
* will not be considered a function definition unless identifier2 is
|
|
||||||
* the word "void", and a line consisting of
|
|
||||||
* identifier1(identifier2, <<arbitrary>>)
|
|
||||||
* will not be considered a function definition.
|
|
||||||
* ansi2knr will recognize a multi-line header provided that no intervening
|
|
||||||
* line ends with a left or right brace or a semicolon. These algorithms
|
|
||||||
* ignore whitespace, comments, and preprocessor directives, except that
|
|
||||||
* the function name must be the first thing on the line. The following
|
|
||||||
* constructs will confuse it:
|
|
||||||
* - Any other construct that starts at the left margin and
|
|
||||||
* follows the above syntax (such as a macro or function call).
|
|
||||||
* - Some macros that tinker with the syntax of function headers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The original and principal author of ansi2knr is L. Peter Deutsch
|
|
||||||
* <[email protected]>. Other authors are noted in the change history
|
|
||||||
* that follows (in reverse chronological order):
|
|
||||||
|
|
||||||
lpd 2000-04-12 backs out Eggert's changes because of bugs:
|
|
||||||
- concatlits didn't declare the type of its bufend argument;
|
|
||||||
- concatlits didn't recognize when it was inside a comment;
|
|
||||||
- scanstring could scan backward past the beginning of the string; when
|
|
||||||
- the check for \ + newline in scanstring was unnecessary.
|
|
||||||
|
|
||||||
2000-03-05 Paul Eggert <[email protected]>
|
|
||||||
|
|
||||||
Add support for concatenated string literals.
|
|
||||||
* ansi2knr.c (concatlits): New decl.
|
|
||||||
(main): Invoke concatlits to concatenate string literals.
|
|
||||||
(scanstring): Handle backslash-newline correctly. Work with
|
|
||||||
character constants. Fix bug when scanning backwards through
|
|
||||||
backslash-quote. Check for unterminated strings.
|
|
||||||
(convert1): Parse character constants, too.
|
|
||||||
(appendline, concatlits): New functions.
|
|
||||||
* ansi2knr.1: Document this.
|
|
||||||
|
|
||||||
lpd 1999-08-17 added code to allow preprocessor directives
|
|
||||||
wherever comments are allowed
|
|
||||||
lpd 1999-04-12 added minor fixes from Pavel Roskin
|
|
||||||
<[email protected]> for clean compilation with
|
|
||||||
gcc -W -Wall
|
|
||||||
lpd 1999-03-22 added hack to recognize lines consisting of
|
|
||||||
identifier1(identifier2, xxx) as *not* being procedures
|
|
||||||
lpd 1999-02-03 made indentation of preprocessor commands consistent
|
|
||||||
lpd 1999-01-28 fixed two bugs: a '/' in an argument list caused an
|
|
||||||
endless loop; quoted strings within an argument list
|
|
||||||
confused the parser
|
|
||||||
lpd 1999-01-24 added a check for write errors on the output,
|
|
||||||
suggested by Jim Meyering <[email protected]>
|
|
||||||
lpd 1998-11-09 added further hack to recognize identifier(void)
|
|
||||||
as being a procedure
|
|
||||||
lpd 1998-10-23 added hack to recognize lines consisting of
|
|
||||||
identifier1(identifier2) as *not* being procedures
|
|
||||||
lpd 1997-12-08 made input_file optional; only closes input and/or
|
|
||||||
output file if not stdin or stdout respectively; prints
|
|
||||||
usage message on stderr rather than stdout; adds
|
|
||||||
--filename switch (changes suggested by
|
|
||||||
<[email protected]>)
|
|
||||||
lpd 1996-01-21 added code to cope with not HAVE_CONFIG_H and with
|
|
||||||
compilers that don't understand void, as suggested by
|
|
||||||
Tom Lane
|
|
||||||
lpd 1996-01-15 changed to require that the first non-comment token
|
|
||||||
on the line following a function header be a left brace,
|
|
||||||
to reduce sensitivity to macros, as suggested by Tom Lane
|
|
||||||
<[email protected]>
|
|
||||||
lpd 1995-06-22 removed #ifndefs whose sole purpose was to define
|
|
||||||
undefined preprocessor symbols as 0; changed all #ifdefs
|
|
||||||
for configuration symbols to #ifs
|
|
||||||
lpd 1995-04-05 changed copyright notice to make it clear that
|
|
||||||
including ansi2knr in a program does not bring the entire
|
|
||||||
program under the GPL
|
|
||||||
lpd 1994-12-18 added conditionals for systems where ctype macros
|
|
||||||
don't handle 8-bit characters properly, suggested by
|
|
||||||
Francois Pinard <[email protected]>;
|
|
||||||
removed --varargs switch (this is now the default)
|
|
||||||
lpd 1994-10-10 removed CONFIG_BROKETS conditional
|
|
||||||
lpd 1994-07-16 added some conditionals to help GNU `configure',
|
|
||||||
suggested by Francois Pinard <[email protected]>;
|
|
||||||
properly erase prototype args in function parameters,
|
|
||||||
contributed by Jim Avera <[email protected]>;
|
|
||||||
correct error in writeblanks (it shouldn't erase EOLs)
|
|
||||||
lpd 1989-xx-xx original version
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Most of the conditionals here are to make ansi2knr work with */
|
|
||||||
/* or without the GNU configure machinery. */
|
|
||||||
|
|
||||||
#if HAVE_CONFIG_H
|
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#if HAVE_CONFIG_H
|
|
||||||
|
|
||||||
/*
|
|
||||||
For properly autoconfiguring ansi2knr, use AC_CONFIG_HEADER(config.h).
|
|
||||||
This will define HAVE_CONFIG_H and so, activate the following lines.
|
|
||||||
*/
|
|
||||||
|
|
||||||
# if STDC_HEADERS || HAVE_STRING_H
|
|
||||||
# include <string.h>
|
|
||||||
# else
|
|
||||||
# include <strings.h>
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#else /* not HAVE_CONFIG_H */
|
|
||||||
|
|
||||||
/* Otherwise do it the hard way */
|
|
||||||
|
|
||||||
# ifdef BSD
|
|
||||||
# include <strings.h>
|
|
||||||
# else
|
|
||||||
# ifdef VMS
|
|
||||||
extern int strlen(), strncmp();
|
|
||||||
# else
|
|
||||||
# include <string.h>
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#endif /* not HAVE_CONFIG_H */
|
|
||||||
|
|
||||||
#if STDC_HEADERS
|
|
||||||
# include <stdlib.h>
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
malloc and free should be declared in stdlib.h,
|
|
||||||
but if you've got a K&R compiler, they probably aren't.
|
|
||||||
*/
|
|
||||||
# ifdef MSDOS
|
|
||||||
# include <malloc.h>
|
|
||||||
# else
|
|
||||||
# ifdef VMS
|
|
||||||
extern char *malloc();
|
|
||||||
extern void free();
|
|
||||||
# else
|
|
||||||
extern char *malloc();
|
|
||||||
extern int free();
|
|
||||||
# endif
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define NULL (for *very* old compilers). */
|
|
||||||
#ifndef NULL
|
|
||||||
# define NULL (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The ctype macros don't always handle 8-bit characters correctly.
|
|
||||||
* Compensate for this here.
|
|
||||||
*/
|
|
||||||
#ifdef isascii
|
|
||||||
# undef HAVE_ISASCII /* just in case */
|
|
||||||
# define HAVE_ISASCII 1
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
#if STDC_HEADERS || !HAVE_ISASCII
|
|
||||||
# define is_ascii(c) 1
|
|
||||||
#else
|
|
||||||
# define is_ascii(c) isascii(c)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define is_space(c) (is_ascii(c) && isspace(c))
|
|
||||||
#define is_alpha(c) (is_ascii(c) && isalpha(c))
|
|
||||||
#define is_alnum(c) (is_ascii(c) && isalnum(c))
|
|
||||||
|
|
||||||
/* Scanning macros */
|
|
||||||
#define isidchar(ch) (is_alnum(ch) || (ch) == '_')
|
|
||||||
#define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_')
|
|
||||||
|
|
||||||
/* Forward references */
|
|
||||||
char *ppdirforward();
|
|
||||||
char *ppdirbackward();
|
|
||||||
char *skipspace();
|
|
||||||
char *scanstring();
|
|
||||||
int writeblanks();
|
|
||||||
int test1();
|
|
||||||
int convert1();
|
|
||||||
|
|
||||||
/* The main program */
|
|
||||||
int
|
|
||||||
main(argc, argv)
|
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{ FILE *in = stdin;
|
|
||||||
FILE *out = stdout;
|
|
||||||
char *filename = 0;
|
|
||||||
char *program_name = argv[0];
|
|
||||||
char *output_name = 0;
|
|
||||||
#define bufsize 5000 /* arbitrary size */
|
|
||||||
char *buf;
|
|
||||||
char *line;
|
|
||||||
char *more;
|
|
||||||
char *usage =
|
|
||||||
"Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n";
|
|
||||||
/*
|
|
||||||
* In previous versions, ansi2knr recognized a --varargs switch.
|
|
||||||
* If this switch was supplied, ansi2knr would attempt to convert
|
|
||||||
* a ... argument to va_alist and va_dcl; if this switch was not
|
|
||||||
* supplied, ansi2knr would simply drop any such arguments.
|
|
||||||
* Now, ansi2knr always does this conversion, and we only
|
|
||||||
* check for this switch for backward compatibility.
|
|
||||||
*/
|
|
||||||
int convert_varargs = 1;
|
|
||||||
int output_error;
|
|
||||||
|
|
||||||
while ( argc > 1 && argv[1][0] == '-' ) {
|
|
||||||
if ( !strcmp(argv[1], "--varargs") ) {
|
|
||||||
convert_varargs = 1;
|
|
||||||
argc--;
|
|
||||||
argv++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( !strcmp(argv[1], "--filename") && argc > 2 ) {
|
|
||||||
filename = argv[2];
|
|
||||||
argc -= 2;
|
|
||||||
argv += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name,
|
|
||||||
argv[1]);
|
|
||||||
fprintf(stderr, usage);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
switch ( argc )
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
fprintf(stderr, usage);
|
|
||||||
exit(0);
|
|
||||||
case 3:
|
|
||||||
output_name = argv[2];
|
|
||||||
out = fopen(output_name, "w");
|
|
||||||
if ( out == NULL ) {
|
|
||||||
fprintf(stderr, "%s: Cannot open output file %s\n",
|
|
||||||
program_name, output_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
/* falls through */
|
|
||||||
case 2:
|
|
||||||
in = fopen(argv[1], "r");
|
|
||||||
if ( in == NULL ) {
|
|
||||||
fprintf(stderr, "%s: Cannot open input file %s\n",
|
|
||||||
program_name, argv[1]);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if ( filename == 0 )
|
|
||||||
filename = argv[1];
|
|
||||||
/* falls through */
|
|
||||||
case 1:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ( filename )
|
|
||||||
fprintf(out, "#line 1 \"%s\"\n", filename);
|
|
||||||
buf = malloc(bufsize);
|
|
||||||
if ( buf == NULL )
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Unable to allocate read buffer!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
line = buf;
|
|
||||||
while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
|
|
||||||
{
|
|
||||||
test: line += strlen(line);
|
|
||||||
switch ( test1(buf) )
|
|
||||||
{
|
|
||||||
case 2: /* a function header */
|
|
||||||
convert1(buf, out, 1, convert_varargs);
|
|
||||||
break;
|
|
||||||
case 1: /* a function */
|
|
||||||
/* Check for a { at the start of the next line. */
|
|
||||||
more = ++line;
|
|
||||||
f: if ( line >= buf + (bufsize - 1) ) /* overflow check */
|
|
||||||
goto wl;
|
|
||||||
if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL )
|
|
||||||
goto wl;
|
|
||||||
switch ( *skipspace(ppdirforward(more), 1) )
|
|
||||||
{
|
|
||||||
case '{':
|
|
||||||
/* Definitely a function header. */
|
|
||||||
convert1(buf, out, 0, convert_varargs);
|
|
||||||
fputs(more, out);
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
/* The next line was blank or a comment: */
|
|
||||||
/* keep scanning for a non-comment. */
|
|
||||||
line += strlen(line);
|
|
||||||
goto f;
|
|
||||||
default:
|
|
||||||
/* buf isn't a function header, but */
|
|
||||||
/* more might be. */
|
|
||||||
fputs(buf, out);
|
|
||||||
strcpy(buf, more);
|
|
||||||
line = buf;
|
|
||||||
goto test;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case -1: /* maybe the start of a function */
|
|
||||||
if ( line != buf + (bufsize - 1) ) /* overflow check */
|
|
||||||
continue;
|
|
||||||
/* falls through */
|
|
||||||
default: /* not a function */
|
|
||||||
wl: fputs(buf, out);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
line = buf;
|
|
||||||
}
|
|
||||||
if ( line != buf )
|
|
||||||
fputs(buf, out);
|
|
||||||
free(buf);
|
|
||||||
if ( output_name ) {
|
|
||||||
output_error = ferror(out);
|
|
||||||
output_error |= fclose(out);
|
|
||||||
} else { /* out == stdout */
|
|
||||||
fflush(out);
|
|
||||||
output_error = ferror(out);
|
|
||||||
}
|
|
||||||
if ( output_error ) {
|
|
||||||
fprintf(stderr, "%s: error writing to %s\n", program_name,
|
|
||||||
(output_name ? output_name : "stdout"));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if ( in != stdin )
|
|
||||||
fclose(in);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Skip forward or backward over one or more preprocessor directives.
|
|
||||||
*/
|
|
||||||
char *
|
|
||||||
ppdirforward(p)
|
|
||||||
char *p;
|
|
||||||
{
|
|
||||||
for (; *p == '#'; ++p) {
|
|
||||||
for (; *p != '\r' && *p != '\n'; ++p)
|
|
||||||
if (*p == 0)
|
|
||||||
return p;
|
|
||||||
if (*p == '\r' && p[1] == '\n')
|
|
||||||
++p;
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
char *
|
|
||||||
ppdirbackward(p, limit)
|
|
||||||
char *p;
|
|
||||||
char *limit;
|
|
||||||
{
|
|
||||||
char *np = p;
|
|
||||||
|
|
||||||
for (;; p = --np) {
|
|
||||||
if (*np == '\n' && np[-1] == '\r')
|
|
||||||
--np;
|
|
||||||
for (; np > limit && np[-1] != '\r' && np[-1] != '\n'; --np)
|
|
||||||
if (np[-1] == 0)
|
|
||||||
return np;
|
|
||||||
if (*np != '#')
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Skip over whitespace, comments, and preprocessor directives,
|
|
||||||
* in either direction.
|
|
||||||
*/
|
|
||||||
char *
|
|
||||||
skipspace(p, dir)
|
|
||||||
char *p;
|
|
||||||
int dir; /* 1 for forward, -1 for backward */
|
|
||||||
{
|
|
||||||
for ( ; ; ) {
|
|
||||||
while ( is_space(*p) )
|
|
||||||
p += dir;
|
|
||||||
if ( !(*p == '/' && p[dir] == '*') )
|
|
||||||
break;
|
|
||||||
p += dir; p += dir;
|
|
||||||
while ( !(*p == '*' && p[dir] == '/') ) {
|
|
||||||
if ( *p == 0 )
|
|
||||||
return p; /* multi-line comment?? */
|
|
||||||
p += dir;
|
|
||||||
}
|
|
||||||
p += dir; p += dir;
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Scan over a quoted string, in either direction. */
|
|
||||||
char *
|
|
||||||
scanstring(p, dir)
|
|
||||||
char *p;
|
|
||||||
int dir;
|
|
||||||
{
|
|
||||||
for (p += dir; ; p += dir)
|
|
||||||
if (*p == '"' && p[-dir] != '\\')
|
|
||||||
return p + dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write blanks over part of a string.
|
|
||||||
* Don't overwrite end-of-line characters.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
writeblanks(start, end)
|
|
||||||
char *start;
|
|
||||||
char *end;
|
|
||||||
{ char *p;
|
|
||||||
for ( p = start; p < end; p++ )
|
|
||||||
if ( *p != '\r' && *p != '\n' )
|
|
||||||
*p = ' ';
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test whether the string in buf is a function definition.
|
|
||||||
* The string may contain and/or end with a newline.
|
|
||||||
* Return as follows:
|
|
||||||
* 0 - definitely not a function definition;
|
|
||||||
* 1 - definitely a function definition;
|
|
||||||
* 2 - definitely a function prototype (NOT USED);
|
|
||||||
* -1 - may be the beginning of a function definition,
|
|
||||||
* append another line and look again.
|
|
||||||
* The reason we don't attempt to convert function prototypes is that
|
|
||||||
* Ghostscript's declaration-generating macros look too much like
|
|
||||||
* prototypes, and confuse the algorithms.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
test1(buf)
|
|
||||||
char *buf;
|
|
||||||
{ char *p = buf;
|
|
||||||
char *bend;
|
|
||||||
char *endfn;
|
|
||||||
int contin;
|
|
||||||
|
|
||||||
if ( !isidfirstchar(*p) )
|
|
||||||
return 0; /* no name at left margin */
|
|
||||||
bend = skipspace(ppdirbackward(buf + strlen(buf) - 1, buf), -1);
|
|
||||||
switch ( *bend )
|
|
||||||
{
|
|
||||||
case ';': contin = 0 /*2*/; break;
|
|
||||||
case ')': contin = 1; break;
|
|
||||||
case '{': return 0; /* not a function */
|
|
||||||
case '}': return 0; /* not a function */
|
|
||||||
default: contin = -1;
|
|
||||||
}
|
|
||||||
while ( isidchar(*p) )
|
|
||||||
p++;
|
|
||||||
endfn = p;
|
|
||||||
p = skipspace(p, 1);
|
|
||||||
if ( *p++ != '(' )
|
|
||||||
return 0; /* not a function */
|
|
||||||
p = skipspace(p, 1);
|
|
||||||
if ( *p == ')' )
|
|
||||||
return 0; /* no parameters */
|
|
||||||
/* Check that the apparent function name isn't a keyword. */
|
|
||||||
/* We only need to check for keywords that could be followed */
|
|
||||||
/* by a left parenthesis (which, unfortunately, is most of them). */
|
|
||||||
{ static char *words[] =
|
|
||||||
{ "asm", "auto", "case", "char", "const", "double",
|
|
||||||
"extern", "float", "for", "if", "int", "long",
|
|
||||||
"register", "return", "short", "signed", "sizeof",
|
|
||||||
"static", "switch", "typedef", "unsigned",
|
|
||||||
"void", "volatile", "while", 0
|
|
||||||
};
|
|
||||||
char **key = words;
|
|
||||||
char *kp;
|
|
||||||
unsigned len = endfn - buf;
|
|
||||||
|
|
||||||
while ( (kp = *key) != 0 )
|
|
||||||
{ if ( strlen(kp) == len && !strncmp(kp, buf, len) )
|
|
||||||
return 0; /* name is a keyword */
|
|
||||||
key++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
char *id = p;
|
|
||||||
int len;
|
|
||||||
/*
|
|
||||||
* Check for identifier1(identifier2) and not
|
|
||||||
* identifier1(void), or identifier1(identifier2, xxxx).
|
|
||||||
*/
|
|
||||||
|
|
||||||
while ( isidchar(*p) )
|
|
||||||
p++;
|
|
||||||
len = p - id;
|
|
||||||
p = skipspace(p, 1);
|
|
||||||
if (*p == ',' ||
|
|
||||||
(*p == ')' && (len != 4 || strncmp(id, "void", 4)))
|
|
||||||
)
|
|
||||||
return 0; /* not a function */
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* If the last significant character was a ), we need to count
|
|
||||||
* parentheses, because it might be part of a formal parameter
|
|
||||||
* that is a procedure.
|
|
||||||
*/
|
|
||||||
if (contin > 0) {
|
|
||||||
int level = 0;
|
|
||||||
|
|
||||||
for (p = skipspace(buf, 1); *p; p = skipspace(p + 1, 1))
|
|
||||||
level += (*p == '(' ? 1 : *p == ')' ? -1 : 0);
|
|
||||||
if (level > 0)
|
|
||||||
contin = -1;
|
|
||||||
}
|
|
||||||
return contin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Convert a recognized function definition or header to K&R syntax. */
|
|
||||||
int
|
|
||||||
convert1(buf, out, header, convert_varargs)
|
|
||||||
char *buf;
|
|
||||||
FILE *out;
|
|
||||||
int header; /* Boolean */
|
|
||||||
int convert_varargs; /* Boolean */
|
|
||||||
{ char *endfn;
|
|
||||||
char *p;
|
|
||||||
/*
|
|
||||||
* The breaks table contains pointers to the beginning and end
|
|
||||||
* of each argument.
|
|
||||||
*/
|
|
||||||
char **breaks;
|
|
||||||
unsigned num_breaks = 2; /* for testing */
|
|
||||||
char **btop;
|
|
||||||
char **bp;
|
|
||||||
char **ap;
|
|
||||||
char *vararg = 0;
|
|
||||||
|
|
||||||
/* Pre-ANSI implementations don't agree on whether strchr */
|
|
||||||
/* is called strchr or index, so we open-code it here. */
|
|
||||||
for ( endfn = buf; *(endfn++) != '('; )
|
|
||||||
;
|
|
||||||
top: p = endfn;
|
|
||||||
breaks = (char **)malloc(sizeof(char *) * num_breaks * 2);
|
|
||||||
if ( breaks == NULL )
|
|
||||||
{ /* Couldn't allocate break table, give up */
|
|
||||||
fprintf(stderr, "Unable to allocate break table!\n");
|
|
||||||
fputs(buf, out);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
btop = breaks + num_breaks * 2 - 2;
|
|
||||||
bp = breaks;
|
|
||||||
/* Parse the argument list */
|
|
||||||
do
|
|
||||||
{ int level = 0;
|
|
||||||
char *lp = NULL;
|
|
||||||
char *rp = NULL;
|
|
||||||
char *end = NULL;
|
|
||||||
|
|
||||||
if ( bp >= btop )
|
|
||||||
{ /* Filled up break table. */
|
|
||||||
/* Allocate a bigger one and start over. */
|
|
||||||
free((char *)breaks);
|
|
||||||
num_breaks <<= 1;
|
|
||||||
goto top;
|
|
||||||
}
|
|
||||||
*bp++ = p;
|
|
||||||
/* Find the end of the argument */
|
|
||||||
for ( ; end == NULL; p++ )
|
|
||||||
{ switch(*p)
|
|
||||||
{
|
|
||||||
case ',':
|
|
||||||
if ( !level ) end = p;
|
|
||||||
break;
|
|
||||||
case '(':
|
|
||||||
if ( !level ) lp = p;
|
|
||||||
level++;
|
|
||||||
break;
|
|
||||||
case ')':
|
|
||||||
if ( --level < 0 ) end = p;
|
|
||||||
else rp = p;
|
|
||||||
break;
|
|
||||||
case '/':
|
|
||||||
if (p[1] == '*')
|
|
||||||
p = skipspace(p, 1) - 1;
|
|
||||||
break;
|
|
||||||
case '"':
|
|
||||||
p = scanstring(p, 1) - 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Erase any embedded prototype parameters. */
|
|
||||||
if ( lp && rp )
|
|
||||||
writeblanks(lp + 1, rp);
|
|
||||||
p--; /* back up over terminator */
|
|
||||||
/* Find the name being declared. */
|
|
||||||
/* This is complicated because of procedure and */
|
|
||||||
/* array modifiers. */
|
|
||||||
for ( ; ; )
|
|
||||||
{ p = skipspace(p - 1, -1);
|
|
||||||
switch ( *p )
|
|
||||||
{
|
|
||||||
case ']': /* skip array dimension(s) */
|
|
||||||
case ')': /* skip procedure args OR name */
|
|
||||||
{ int level = 1;
|
|
||||||
while ( level )
|
|
||||||
switch ( *--p )
|
|
||||||
{
|
|
||||||
case ']': case ')':
|
|
||||||
level++;
|
|
||||||
break;
|
|
||||||
case '[': case '(':
|
|
||||||
level--;
|
|
||||||
break;
|
|
||||||
case '/':
|
|
||||||
if (p > buf && p[-1] == '*')
|
|
||||||
p = skipspace(p, -1) + 1;
|
|
||||||
break;
|
|
||||||
case '"':
|
|
||||||
p = scanstring(p, -1) + 1;
|
|
||||||
break;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( *p == '(' && *skipspace(p + 1, 1) == '*' )
|
|
||||||
{ /* We found the name being declared */
|
|
||||||
while ( !isidfirstchar(*p) )
|
|
||||||
p = skipspace(p, 1) + 1;
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
goto found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
found: if ( *p == '.' && p[-1] == '.' && p[-2] == '.' )
|
|
||||||
{ if ( convert_varargs )
|
|
||||||
{ *bp++ = "va_alist";
|
|
||||||
vararg = p-2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ p++;
|
|
||||||
if ( bp == breaks + 1 ) /* sole argument */
|
|
||||||
writeblanks(breaks[0], p);
|
|
||||||
else
|
|
||||||
writeblanks(bp[-1] - 1, p);
|
|
||||||
bp--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ while ( isidchar(*p) ) p--;
|
|
||||||
*bp++ = p+1;
|
|
||||||
}
|
|
||||||
p = end;
|
|
||||||
}
|
|
||||||
while ( *p++ == ',' );
|
|
||||||
*bp = p;
|
|
||||||
/* Make a special check for 'void' arglist */
|
|
||||||
if ( bp == breaks+2 )
|
|
||||||
{ p = skipspace(breaks[0], 1);
|
|
||||||
if ( !strncmp(p, "void", 4) )
|
|
||||||
{ p = skipspace(p+4, 1);
|
|
||||||
if ( p == breaks[2] - 1 )
|
|
||||||
{ bp = breaks; /* yup, pretend arglist is empty */
|
|
||||||
writeblanks(breaks[0], p + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Put out the function name and left parenthesis. */
|
|
||||||
p = buf;
|
|
||||||
while ( p != endfn ) putc(*p, out), p++;
|
|
||||||
/* Put out the declaration. */
|
|
||||||
if ( header )
|
|
||||||
{ fputs(");", out);
|
|
||||||
for ( p = breaks[0]; *p; p++ )
|
|
||||||
if ( *p == '\r' || *p == '\n' )
|
|
||||||
putc(*p, out);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ for ( ap = breaks+1; ap < bp; ap += 2 )
|
|
||||||
{ p = *ap;
|
|
||||||
while ( isidchar(*p) )
|
|
||||||
putc(*p, out), p++;
|
|
||||||
if ( ap < bp - 1 )
|
|
||||||
fputs(", ", out);
|
|
||||||
}
|
|
||||||
fputs(") ", out);
|
|
||||||
/* Put out the argument declarations */
|
|
||||||
for ( ap = breaks+2; ap <= bp; ap += 2 )
|
|
||||||
(*ap)[-1] = ';';
|
|
||||||
if ( vararg != 0 )
|
|
||||||
{ *vararg = 0;
|
|
||||||
fputs(breaks[0], out); /* any prior args */
|
|
||||||
fputs("va_dcl", out); /* the final arg */
|
|
||||||
fputs(bp[0], out);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fputs(breaks[0], out);
|
|
||||||
}
|
|
||||||
free((char *)breaks);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
+271
@@ -0,0 +1,271 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Wrapper for Microsoft lib.exe
|
||||||
|
|
||||||
|
me=ar-lib
|
||||||
|
scriptversion=2019-07-04.01; # UTC
|
||||||
|
|
||||||
|
# Copyright (C) 2010-2021 Free Software Foundation, Inc.
|
||||||
|
# Written by Peter Rosin <[email protected]>.
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# As a special exception to the GNU General Public License, if you
|
||||||
|
# distribute this file as part of a program that contains a
|
||||||
|
# configuration script generated by Autoconf, you may include it under
|
||||||
|
# the same distribution terms that you use for the rest of that program.
|
||||||
|
|
||||||
|
# This file is maintained in Automake, please report
|
||||||
|
# bugs to <[email protected]> or send patches to
|
||||||
|
# <[email protected]>.
|
||||||
|
|
||||||
|
|
||||||
|
# func_error message
|
||||||
|
func_error ()
|
||||||
|
{
|
||||||
|
echo "$me: $1" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
file_conv=
|
||||||
|
|
||||||
|
# func_file_conv build_file
|
||||||
|
# Convert a $build file to $host form and store it in $file
|
||||||
|
# Currently only supports Windows hosts.
|
||||||
|
func_file_conv ()
|
||||||
|
{
|
||||||
|
file=$1
|
||||||
|
case $file in
|
||||||
|
/ | /[!/]*) # absolute file, and not a UNC file
|
||||||
|
if test -z "$file_conv"; then
|
||||||
|
# lazily determine how to convert abs files
|
||||||
|
case `uname -s` in
|
||||||
|
MINGW*)
|
||||||
|
file_conv=mingw
|
||||||
|
;;
|
||||||
|
CYGWIN* | MSYS*)
|
||||||
|
file_conv=cygwin
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
file_conv=wine
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
case $file_conv in
|
||||||
|
mingw)
|
||||||
|
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
|
||||||
|
;;
|
||||||
|
cygwin | msys)
|
||||||
|
file=`cygpath -m "$file" || echo "$file"`
|
||||||
|
;;
|
||||||
|
wine)
|
||||||
|
file=`winepath -w "$file" || echo "$file"`
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# func_at_file at_file operation archive
|
||||||
|
# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
|
||||||
|
# for each of them.
|
||||||
|
# When interpreting the content of the @FILE, do NOT use func_file_conv,
|
||||||
|
# since the user would need to supply preconverted file names to
|
||||||
|
# binutils ar, at least for MinGW.
|
||||||
|
func_at_file ()
|
||||||
|
{
|
||||||
|
operation=$2
|
||||||
|
archive=$3
|
||||||
|
at_file_contents=`cat "$1"`
|
||||||
|
eval set x "$at_file_contents"
|
||||||
|
shift
|
||||||
|
|
||||||
|
for member
|
||||||
|
do
|
||||||
|
$AR -NOLOGO $operation:"$member" "$archive" || exit $?
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
'')
|
||||||
|
func_error "no command. Try '$0 --help' for more information."
|
||||||
|
;;
|
||||||
|
-h | --h*)
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]
|
||||||
|
|
||||||
|
Members may be specified in a file named with @FILE.
|
||||||
|
EOF
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
-v | --v*)
|
||||||
|
echo "$me, version $scriptversion"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test $# -lt 3; then
|
||||||
|
func_error "you must specify a program, an action and an archive"
|
||||||
|
fi
|
||||||
|
|
||||||
|
AR=$1
|
||||||
|
shift
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
if test $# -lt 2; then
|
||||||
|
func_error "you must specify a program, an action and an archive"
|
||||||
|
fi
|
||||||
|
case $1 in
|
||||||
|
-lib | -LIB \
|
||||||
|
| -ltcg | -LTCG \
|
||||||
|
| -machine* | -MACHINE* \
|
||||||
|
| -subsystem* | -SUBSYSTEM* \
|
||||||
|
| -verbose | -VERBOSE \
|
||||||
|
| -wx* | -WX* )
|
||||||
|
AR="$AR $1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
action=$1
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
orig_archive=$1
|
||||||
|
shift
|
||||||
|
func_file_conv "$orig_archive"
|
||||||
|
archive=$file
|
||||||
|
|
||||||
|
# strip leading dash in $action
|
||||||
|
action=${action#-}
|
||||||
|
|
||||||
|
delete=
|
||||||
|
extract=
|
||||||
|
list=
|
||||||
|
quick=
|
||||||
|
replace=
|
||||||
|
index=
|
||||||
|
create=
|
||||||
|
|
||||||
|
while test -n "$action"
|
||||||
|
do
|
||||||
|
case $action in
|
||||||
|
d*) delete=yes ;;
|
||||||
|
x*) extract=yes ;;
|
||||||
|
t*) list=yes ;;
|
||||||
|
q*) quick=yes ;;
|
||||||
|
r*) replace=yes ;;
|
||||||
|
s*) index=yes ;;
|
||||||
|
S*) ;; # the index is always updated implicitly
|
||||||
|
c*) create=yes ;;
|
||||||
|
u*) ;; # TODO: don't ignore the update modifier
|
||||||
|
v*) ;; # TODO: don't ignore the verbose modifier
|
||||||
|
*)
|
||||||
|
func_error "unknown action specified"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
action=${action#?}
|
||||||
|
done
|
||||||
|
|
||||||
|
case $delete$extract$list$quick$replace,$index in
|
||||||
|
yes,* | ,yes)
|
||||||
|
;;
|
||||||
|
yesyes*)
|
||||||
|
func_error "more than one action specified"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
func_error "no action specified"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test -n "$delete"; then
|
||||||
|
if test ! -f "$orig_archive"; then
|
||||||
|
func_error "archive not found"
|
||||||
|
fi
|
||||||
|
for member
|
||||||
|
do
|
||||||
|
case $1 in
|
||||||
|
@*)
|
||||||
|
func_at_file "${1#@}" -REMOVE "$archive"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
func_file_conv "$1"
|
||||||
|
$AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
elif test -n "$extract"; then
|
||||||
|
if test ! -f "$orig_archive"; then
|
||||||
|
func_error "archive not found"
|
||||||
|
fi
|
||||||
|
if test $# -gt 0; then
|
||||||
|
for member
|
||||||
|
do
|
||||||
|
case $1 in
|
||||||
|
@*)
|
||||||
|
func_at_file "${1#@}" -EXTRACT "$archive"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
func_file_conv "$1"
|
||||||
|
$AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
else
|
||||||
|
$AR -NOLOGO -LIST "$archive" | tr -d '\r' | sed -e 's/\\/\\\\/g' \
|
||||||
|
| while read member
|
||||||
|
do
|
||||||
|
$AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif test -n "$quick$replace"; then
|
||||||
|
if test ! -f "$orig_archive"; then
|
||||||
|
if test -z "$create"; then
|
||||||
|
echo "$me: creating $orig_archive"
|
||||||
|
fi
|
||||||
|
orig_archive=
|
||||||
|
else
|
||||||
|
orig_archive=$archive
|
||||||
|
fi
|
||||||
|
|
||||||
|
for member
|
||||||
|
do
|
||||||
|
case $1 in
|
||||||
|
@*)
|
||||||
|
func_file_conv "${1#@}"
|
||||||
|
set x "$@" "@$file"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
func_file_conv "$1"
|
||||||
|
set x "$@" "$file"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if test -n "$orig_archive"; then
|
||||||
|
$AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
|
||||||
|
else
|
||||||
|
$AR -NOLOGO -OUT:"$archive" "$@" || exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif test -n "$list"; then
|
||||||
|
if test ! -f "$orig_archive"; then
|
||||||
|
func_error "archive not found"
|
||||||
|
fi
|
||||||
|
$AR -NOLOGO -LIST "$archive" || exit $?
|
||||||
|
fi
|
||||||
Vendored
+138
@@ -0,0 +1,138 @@
|
|||||||
|
IJG JPEG LIBRARY: ALTERNATE USER INTERFACE FOR CJPEG/DJPEG
|
||||||
|
|
||||||
|
Copyright (C) 2020, Guido Vollbeding.
|
||||||
|
This file is part of the Independent JPEG Group's software.
|
||||||
|
For conditions of distribution and use, see the accompanying README file.
|
||||||
|
|
||||||
|
|
||||||
|
There is an alternate command-line user interface for the IJG JPEG software.
|
||||||
|
It is designed for use under MS-DOS, and may also be useful on other non-Unix
|
||||||
|
operating systems. (For that matter, this code works fine on Unix, but the
|
||||||
|
standard command-line syntax is better on Unix because it is pipe-friendly.)
|
||||||
|
|
||||||
|
With this user interface, cjpeg and djpeg accept multiple input file names
|
||||||
|
on the command line; output file names are generated by substituting
|
||||||
|
appropriate extensions. The user is prompted before any already-existing
|
||||||
|
file will be overwritten.
|
||||||
|
|
||||||
|
Expansion of wild-card file specifications is useful but is not directly
|
||||||
|
provided by this code. Most DOS C compilers have the ability to do wild-card
|
||||||
|
expansion "behind the scenes", and we rely on that feature. On other systems,
|
||||||
|
the shell may do it for you, as is done on Unix.
|
||||||
|
|
||||||
|
Also, a DOS-specific routine is provided to determine available memory;
|
||||||
|
this makes the -maxmemory switch unnecessary except in unusual cases.
|
||||||
|
If you know how to determine available memory on a different system,
|
||||||
|
you can easily add the necessary code. (And please send it along to
|
||||||
|
[email protected] so we can include it in future releases!)
|
||||||
|
|
||||||
|
|
||||||
|
INSTALLATION
|
||||||
|
============
|
||||||
|
|
||||||
|
Rename the standard cjpeg.c file to cjpegstd.c, then rename cjpegalt.c to
|
||||||
|
cjpeg.c.
|
||||||
|
Rename the standard djpeg.c file to djpegstd.c, then rename djpegalt.c to
|
||||||
|
djpeg.c.
|
||||||
|
Then build the software as described in install.txt, with these exceptions:
|
||||||
|
|
||||||
|
* Define PROGRESS_REPORT in jconfig.h if you want the percent-done display.
|
||||||
|
* Define NO_OVERWRITE_CHECK if you *don't* want overwrite confirmation.
|
||||||
|
* You may ignore the USE_SETMODE and TWO_FILE_COMMANDLINE symbols discussed
|
||||||
|
in install.txt; these files do not use them.
|
||||||
|
* As given, djpegalt.c defaults to BMP output (not PPM output as in the
|
||||||
|
standard djpeg.c). If you want something different, modify DEFAULT_FMT.
|
||||||
|
|
||||||
|
You may also need to do something special to enable filename wild-card
|
||||||
|
expansion, assuming your compiler has that capability at all.
|
||||||
|
|
||||||
|
Modify the standard usage.txt file as described below. (If you want to use
|
||||||
|
the Unix-style manual pages cjpeg.1 and djpeg.1, better fix them too.)
|
||||||
|
|
||||||
|
To restore the standard user interface:
|
||||||
|
Rename cjpeg.c to cjpegalt.c, then rename cjpegstd.c to cjpeg.c.
|
||||||
|
Rename djpeg.c to djpegalt.c, then rename djpegstd.c to djpeg.c.
|
||||||
|
Then recompile/rebuild.
|
||||||
|
|
||||||
|
|
||||||
|
Here are some specific notes for popular MS-DOS compilers:
|
||||||
|
|
||||||
|
Borland C:
|
||||||
|
Add "-DMSDOS" to CFLAGS to enable use of the DOS memory determination code.
|
||||||
|
Link with the standard library file WILDARGS.OBJ to get wild-card expansion.
|
||||||
|
|
||||||
|
Microsoft C:
|
||||||
|
Add "-DMSDOS" to CFLAGS to enable use of the DOS memory determination code.
|
||||||
|
Link with the standard library file SETARGV.OBJ to get wild-card expansion.
|
||||||
|
In the versions I've used, you must also add /NOE to the linker switches to
|
||||||
|
avoid a duplicate-symbol error from including SETARGV.
|
||||||
|
|
||||||
|
DJGPP (we recommend version 2.0 or later):
|
||||||
|
Add "-DFREE_MEM_ESTIMATE=0" to CFLAGS. Wild-card expansion is automatic.
|
||||||
|
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
=====
|
||||||
|
|
||||||
|
Most of the standard usage.txt file also applies to the alternate version,
|
||||||
|
but replace its "GENERAL USAGE" section with the text below. Edit the text
|
||||||
|
as necessary if you don't support wildcards or overwrite checking. Be sure
|
||||||
|
to fix the djpeg switch descriptions if you are not defaulting to PPM output.
|
||||||
|
Also, if you've provided an accurate memory-estimation procedure, you can
|
||||||
|
probably eliminate the HINTS related to the -maxmemory switch.
|
||||||
|
|
||||||
|
|
||||||
|
GENERAL USAGE
|
||||||
|
|
||||||
|
We provide two programs, cjpeg to compress an image file into JPEG format,
|
||||||
|
and djpeg to decompress a JPEG file back into a conventional image format.
|
||||||
|
|
||||||
|
The basic command line is:
|
||||||
|
cjpeg [switches] list of image files
|
||||||
|
or
|
||||||
|
djpeg [switches] list of jpeg files
|
||||||
|
|
||||||
|
Each file named is compressed or decompressed. The input file(s) are not
|
||||||
|
modified; the output data is written to files which have the same names
|
||||||
|
except for extension. cjpeg always uses ".jpg" for the output file name's
|
||||||
|
extension; djpeg uses one of ".bmp", ".gif", ".ppm", ".rle", or ".tga",
|
||||||
|
depending on what output format is selected by the switches.
|
||||||
|
|
||||||
|
For example, to convert xxx.bmp to xxx.jpg and yyy.ppm to yyy.jpg, say:
|
||||||
|
cjpeg xxx.bmp yyy.ppm
|
||||||
|
|
||||||
|
On most systems you can use standard wildcards to specify the list of input
|
||||||
|
files; for example, on DOS "djpeg *.jpg" decompresses all the JPEG files in
|
||||||
|
the current directory.
|
||||||
|
|
||||||
|
If an intended output file already exists, you'll be asked whether or not to
|
||||||
|
overwrite it. If you say no, the program skips that input file and goes on
|
||||||
|
to the next one.
|
||||||
|
|
||||||
|
You can intermix switches and file names; for example
|
||||||
|
djpeg -gif file1.jpg -targa file2.jpg
|
||||||
|
decompresses file1.jpg into GIF format (file1.gif) and file2.jpg into Targa
|
||||||
|
format (file2.tga). Only switches to the left of a given file name affect
|
||||||
|
processing of that file; when there are conflicting switches, the rightmost
|
||||||
|
one takes precedence.
|
||||||
|
|
||||||
|
You can override the program's choice of output file name by using the
|
||||||
|
-outfile switch, as in
|
||||||
|
cjpeg -outfile output.jpg input.ppm
|
||||||
|
-outfile only affects the first input file name to its right.
|
||||||
|
|
||||||
|
The currently supported image file formats are: PPM (PBMPLUS color format),
|
||||||
|
PGM (PBMPLUS grayscale format), BMP, GIF, Targa, and RLE (Utah Raster Toolkit
|
||||||
|
format). (RLE is supported only if the URT library is available, which it
|
||||||
|
isn't on most non-Unix systems.) cjpeg recognizes the input image format
|
||||||
|
automatically, with the exception of some Targa-format files. You have to
|
||||||
|
tell djpeg which format to generate.
|
||||||
|
|
||||||
|
JPEG files are in the standard JFIF file format. There are other,
|
||||||
|
less widely used JPEG-based file formats, but we don't support them.
|
||||||
|
|
||||||
|
All switch names may be abbreviated; for example, -grayscale may be written
|
||||||
|
-gray or -gr. Most of the "basic" switches can be abbreviated to as little as
|
||||||
|
one letter. Upper and lower case are equivalent (-BMP is the same as -bmp).
|
||||||
|
British spellings are also accepted (e.g., -greyscale), though for brevity
|
||||||
|
these are not mentioned below.
|
||||||
Vendored
+7
-5
@@ -2,7 +2,7 @@
|
|||||||
* cderror.h
|
* cderror.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||||
* Modified 2009 by Guido Vollbeding.
|
* Modified 2009-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -41,16 +41,16 @@ JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */
|
|||||||
|
|
||||||
#ifdef BMP_SUPPORTED
|
#ifdef BMP_SUPPORTED
|
||||||
JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
|
JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
|
||||||
JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported")
|
JMESSAGE(JERR_BMP_BADDEPTH, "Only 8-, 24-, and 32-bit BMP files are supported")
|
||||||
JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
|
JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
|
||||||
JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
|
JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
|
||||||
JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
|
JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
|
||||||
JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
|
JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
|
||||||
JMESSAGE(JERR_BMP_EMPTY, "Empty BMP image")
|
|
||||||
JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
|
JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
|
||||||
JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image")
|
JMESSAGE(JERR_BMP_OUTOFRANGE, "Numeric value out of range in BMP file")
|
||||||
|
JMESSAGE(JTRC_BMP, "%ux%u %d-bit BMP image")
|
||||||
JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
|
JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
|
||||||
JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image")
|
JMESSAGE(JTRC_BMP_OS2, "%ux%u %d-bit OS2 BMP image")
|
||||||
JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
|
JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
|
||||||
#endif /* BMP_SUPPORTED */
|
#endif /* BMP_SUPPORTED */
|
||||||
|
|
||||||
@@ -60,6 +60,7 @@ JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d")
|
|||||||
JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB")
|
JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB")
|
||||||
JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
|
JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
|
||||||
JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
|
JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
|
||||||
|
JMESSAGE(JERR_GIF_OUTOFRANGE, "Numeric value out of range in GIF file")
|
||||||
JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
|
JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
|
||||||
JMESSAGE(JTRC_GIF_BADVERSION,
|
JMESSAGE(JTRC_GIF_BADVERSION,
|
||||||
"Warning: unexpected GIF version number '%c%c%c'")
|
"Warning: unexpected GIF version number '%c%c%c'")
|
||||||
@@ -75,6 +76,7 @@ JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits")
|
|||||||
JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
|
JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
|
||||||
JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
|
JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
|
||||||
JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file")
|
JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file")
|
||||||
|
JMESSAGE(JERR_PPM_OUTOFRANGE, "Numeric value out of range in PPM file")
|
||||||
JMESSAGE(JTRC_PGM, "%ux%u PGM image")
|
JMESSAGE(JTRC_PGM, "%ux%u PGM image")
|
||||||
JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
|
JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
|
||||||
JMESSAGE(JTRC_PPM, "%ux%u PPM image")
|
JMESSAGE(JTRC_PPM, "%ux%u PPM image")
|
||||||
|
|||||||
Vendored
+3
-1
@@ -2,6 +2,7 @@
|
|||||||
* cdjpeg.h
|
* cdjpeg.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||||
|
* Modified 2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -121,7 +122,8 @@ EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));
|
|||||||
EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
|
EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
|
||||||
boolean is_os2));
|
boolean is_os2));
|
||||||
EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
|
EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
|
||||||
EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));
|
EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo,
|
||||||
|
boolean is_lzw));
|
||||||
EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
|
EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
|
||||||
EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
|
EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
|
||||||
EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
|
EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
|
||||||
|
|||||||
Vendored
+190
@@ -1,6 +1,196 @@
|
|||||||
CHANGE LOG for Independent JPEG Group's JPEG software
|
CHANGE LOG for Independent JPEG Group's JPEG software
|
||||||
|
|
||||||
|
|
||||||
|
Version 9e 16-Jan-2022
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
Include alternate user interface files for cjpeg/djpeg.
|
||||||
|
|
||||||
|
jcparam.c: change default chrominance DC quantization factor
|
||||||
|
for lossless support. Note: Requires rebuild of test images.
|
||||||
|
|
||||||
|
rdgif.c, cderror.h: add sanity check for GIF image dimensions.
|
||||||
|
Thank to Casper Sun for cjpeg potential vulnerability report.
|
||||||
|
|
||||||
|
Add ARM and ARM64 platform support in the Visual Studio build.
|
||||||
|
|
||||||
|
|
||||||
|
Version 9d 12-Jan-2020
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
Optimize the optimal Huffman code table generation to produce
|
||||||
|
slightly smaller files. Thank to John Korejwa for suggestion.
|
||||||
|
Note: Requires rebuild of testimgp.jpg.
|
||||||
|
|
||||||
|
Decoding Huffman: Use default tables if tables are not defined.
|
||||||
|
Thank to Simone Azzalin for report (Motion JPEG),
|
||||||
|
and to Martin Strunz for hint.
|
||||||
|
|
||||||
|
Add sanity check in optimal Huffman code table generation.
|
||||||
|
Thank to Adam Farley for suggestion.
|
||||||
|
|
||||||
|
rdtarga.c: use read_byte(), with EOF check, instead of getc()
|
||||||
|
in read_*_pixel().
|
||||||
|
Thank to Chijin Zhou for cjpeg potential vulnerability report.
|
||||||
|
|
||||||
|
jmemnobs.c: respect the max_memory_to_use setting in
|
||||||
|
jpeg_mem_available() computation. Thank to Sheng Shu and
|
||||||
|
Dongdong She for djpeg potential vulnerability report.
|
||||||
|
|
||||||
|
jdarith.c, jdhuff.c: avoid left shift of negative value
|
||||||
|
compiler warning in decode_mcu_AC_refine().
|
||||||
|
Thank to Indu Bhagat for suggestion.
|
||||||
|
|
||||||
|
Add x64 (64-bit) platform support, avoid compiler warnings.
|
||||||
|
Thank to Jonathan Potter, Feiyun Wang, and Sheng Shu for suggestion.
|
||||||
|
|
||||||
|
Adjust libjpeg version specification for pkg-config file.
|
||||||
|
Thank to Chen Chen for suggestion.
|
||||||
|
|
||||||
|
Restore GIF read and write support from libjpeg version 6a.
|
||||||
|
Thank to Wolfgang Werner (W.W.) Heinz for suggestion.
|
||||||
|
|
||||||
|
Improve consistency in raw (downsampled) image data processing mode.
|
||||||
|
Thank to Zhongyuan Zhou for hint.
|
||||||
|
|
||||||
|
Avoid out of bounds array read (AC derived table pointers)
|
||||||
|
in start pass in jdhuff.c. Thank to Peng Li for report.
|
||||||
|
|
||||||
|
Improve code sanity (jdhuff.c).
|
||||||
|
Thank to Reza Mirzazade farkhani for reports.
|
||||||
|
|
||||||
|
Add jpegtran -drop option; add options to the crop extension and wipe
|
||||||
|
to fill the extra area with content from the source image region,
|
||||||
|
instead of gray out.
|
||||||
|
|
||||||
|
|
||||||
|
Version 9c 14-Jan-2018
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
jpegtran: add an option to the -wipe switch to fill the region
|
||||||
|
with the average of adjacent blocks, instead of gray out.
|
||||||
|
Thank to Caitlyn Feddock and Maddie Ziegler for inspiration.
|
||||||
|
|
||||||
|
Make range extension bits adjustable (in jpegint.h).
|
||||||
|
Thank to Robin Watts for suggestion.
|
||||||
|
|
||||||
|
Provide macros for fflush() and ferror() in jinclude.h in order
|
||||||
|
to facilitate adaption by applications using an own FILE class.
|
||||||
|
Thank to Gerhard Huber for suggestion.
|
||||||
|
|
||||||
|
Add libjpeg pkg-config file. Thank to Mark Lavi, Vincent Torri,
|
||||||
|
Patrick McMunn, and Huw Davies for suggestion.
|
||||||
|
|
||||||
|
Add sanity checks in cjpeg image reader modules.
|
||||||
|
Thank to Bingchang, Liu for reports.
|
||||||
|
|
||||||
|
|
||||||
|
Version 9b 17-Jan-2016
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
Improvements and optimizations in DCT and color calculations.
|
||||||
|
Normalize range limit array composition and access pattern.
|
||||||
|
Thank to Sia Furler and Maddie Ziegler for inspiration.
|
||||||
|
|
||||||
|
Use merged upsample with scaled DCT sizes larger than 8.
|
||||||
|
Thank to Taylor Hatala for inspiration.
|
||||||
|
|
||||||
|
Check for excessive comment lengths in argument parsing in wrjpgcom.c.
|
||||||
|
Thank to Julian Cohen for hint.
|
||||||
|
|
||||||
|
Add makefile.b32 for use with Borland C++ 32-bit (bcc32).
|
||||||
|
Thank to Joe Slater for contribution.
|
||||||
|
|
||||||
|
Document 'f' specifier for jpegtran -crop specification.
|
||||||
|
Thank to Michele Martone for suggestion.
|
||||||
|
|
||||||
|
Use defined value from header instead of hardwired number in rdswitch.c.
|
||||||
|
Thank to Robert Sprowson for hint.
|
||||||
|
|
||||||
|
|
||||||
|
Version 9a 19-Jan-2014
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
Add support for wide gamut color spaces (JFIF version 2).
|
||||||
|
Improve clarity and accuracy in color conversion modules.
|
||||||
|
Note: Requires rebuild of test images.
|
||||||
|
|
||||||
|
Extend the bit depth support to all values from 8 to 12
|
||||||
|
(BITS_IN_JSAMPLE configuration option in jmorecfg.h).
|
||||||
|
jpegtran now supports N bits sample data precision with all N from 8 to 12
|
||||||
|
in a single instance. Thank to Roland Fassauer for inspiration.
|
||||||
|
|
||||||
|
Try to resolve issues with new boolean type definition.
|
||||||
|
Thank also to v4hn for suggestion.
|
||||||
|
|
||||||
|
Enable option to use default Huffman tables for lossless compression
|
||||||
|
(for hardware solution), and in this case improve lossless RGB compression
|
||||||
|
with reversible color transform. Thank to Benny Alexandar for hint.
|
||||||
|
|
||||||
|
Extend the entropy decoding structure, so that extraneous bytes between
|
||||||
|
compressed scan data and following marker can be reported correctly.
|
||||||
|
Thank to Nigel Tao for hint.
|
||||||
|
|
||||||
|
Add jpegtran -wipe option and extension for -crop.
|
||||||
|
Thank to Andrew Senior, David Clunie, and Josef Schmid for suggestion.
|
||||||
|
|
||||||
|
|
||||||
|
Version 9 13-Jan-2013
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
Add cjpeg -rgb1 option to create an RGB JPEG file, and insert
|
||||||
|
a simple reversible color transform into the processing which
|
||||||
|
significantly improves the compression.
|
||||||
|
The recommended command for lossless coding of RGB images is now
|
||||||
|
cjpeg -rgb1 -block 1 -arithmetic.
|
||||||
|
As said, this option improves the compression significantly, but
|
||||||
|
the files are not compatible with JPEG decoders prior to IJG v9
|
||||||
|
due to the included color transform.
|
||||||
|
The used color transform and marker signaling is compatible with
|
||||||
|
other JPEG standards (e.g., JPEG-LS part 2).
|
||||||
|
|
||||||
|
Remove the automatic de-ANSI-fication support (Automake 1.12).
|
||||||
|
Thank also to Nitin A Kamble for suggestion.
|
||||||
|
|
||||||
|
Add remark for jpeg_mem_dest() in jdatadst.c.
|
||||||
|
Thank to Elie-Gregoire Khoury for the hint.
|
||||||
|
|
||||||
|
Support files with invalid component identifiers (created
|
||||||
|
by Adobe PDF). Thank to Robin Watts for the suggestion.
|
||||||
|
|
||||||
|
Adapt full buffer case in jcmainct.c for use with scaled DCT.
|
||||||
|
Thank to Sergii Biloshytskyi for the suggestion.
|
||||||
|
|
||||||
|
Add type identifier for declaration of noreturn functions.
|
||||||
|
Thank to Brett L. Moore for the suggestion.
|
||||||
|
|
||||||
|
Correct argument type in format string, avoid compiler warnings.
|
||||||
|
Thank to Vincent Torri for hint.
|
||||||
|
|
||||||
|
Add missing #include directives in configuration checks, avoid
|
||||||
|
configuration errors. Thank to John Spencer for the hint.
|
||||||
|
|
||||||
|
|
||||||
|
Version 8d 15-Jan-2012
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
Add cjpeg -rgb option to create RGB JPEG files.
|
||||||
|
Using this switch suppresses the conversion from RGB
|
||||||
|
colorspace input to the default YCbCr JPEG colorspace.
|
||||||
|
This feature allows true lossless JPEG coding of RGB color images.
|
||||||
|
The recommended command for this purpose is currently
|
||||||
|
cjpeg -rgb -block 1 -arithmetic.
|
||||||
|
SmartScale capable decoder (introduced with IJG JPEG 8) required.
|
||||||
|
Thank to Michael Koch for the initial suggestion.
|
||||||
|
|
||||||
|
Add option to disable the region adjustment in the transupp crop code.
|
||||||
|
Thank to Jeffrey Friedl for the suggestion.
|
||||||
|
|
||||||
|
Thank to Richard Jones and Edd Dawson for various minor corrections.
|
||||||
|
|
||||||
|
Thank to Akim Demaille for configure.ac cleanup.
|
||||||
|
|
||||||
|
|
||||||
Version 8c 16-Jan-2011
|
Version 8c 16-Jan-2011
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
|||||||
Vendored
+384
@@ -0,0 +1,384 @@
|
|||||||
|
.TH CJPEG 1 "28 April 2019"
|
||||||
|
.SH NAME
|
||||||
|
cjpeg \- compress an image file to a JPEG file
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B cjpeg
|
||||||
|
[
|
||||||
|
.I options
|
||||||
|
]
|
||||||
|
[
|
||||||
|
.I filename
|
||||||
|
]
|
||||||
|
.LP
|
||||||
|
.SH DESCRIPTION
|
||||||
|
.LP
|
||||||
|
.B cjpeg
|
||||||
|
compresses the named image file, or the standard input if no file is
|
||||||
|
named, and produces a JPEG/JFIF file on the standard output.
|
||||||
|
The currently supported input file formats are: PPM (PBMPLUS color
|
||||||
|
format), PGM (PBMPLUS grayscale format), BMP, GIF, Targa, and RLE (Utah Raster
|
||||||
|
Toolkit format). (RLE is supported only if the URT library is available,
|
||||||
|
which it isn't on most non-Unix systems.)
|
||||||
|
.SH OPTIONS
|
||||||
|
All switch names may be abbreviated; for example,
|
||||||
|
.B \-grayscale
|
||||||
|
may be written
|
||||||
|
.B \-gray
|
||||||
|
or
|
||||||
|
.BR \-gr .
|
||||||
|
Most of the "basic" switches can be abbreviated to as little as one letter.
|
||||||
|
Upper and lower case are equivalent (thus
|
||||||
|
.B \-BMP
|
||||||
|
is the same as
|
||||||
|
.BR \-bmp ).
|
||||||
|
British spellings are also accepted (e.g.,
|
||||||
|
.BR \-greyscale ),
|
||||||
|
though for brevity these are not mentioned below.
|
||||||
|
.PP
|
||||||
|
The basic switches are:
|
||||||
|
.TP
|
||||||
|
.BI \-quality " N[,...]"
|
||||||
|
Scale quantization tables to adjust image quality. Quality is 0 (worst) to
|
||||||
|
100 (best); default is 75. (See below for more info.)
|
||||||
|
.TP
|
||||||
|
.B \-grayscale
|
||||||
|
Create monochrome JPEG file from color input. Be sure to use this switch when
|
||||||
|
compressing a grayscale BMP or GIF file, because
|
||||||
|
.B cjpeg
|
||||||
|
isn't bright enough to notice whether a BMP or GIF file uses only shades of
|
||||||
|
gray. By saying
|
||||||
|
.BR \-grayscale ,
|
||||||
|
you'll get a smaller JPEG file that takes less time to process.
|
||||||
|
.TP
|
||||||
|
.B \-rgb
|
||||||
|
Create RGB JPEG file.
|
||||||
|
Using this switch suppresses the conversion from RGB
|
||||||
|
colorspace input to the default YCbCr JPEG colorspace.
|
||||||
|
You can use this switch in combination with the
|
||||||
|
.BI \-block " N"
|
||||||
|
switch (see below) for lossless JPEG coding.
|
||||||
|
See also the
|
||||||
|
.B \-rgb1
|
||||||
|
switch below.
|
||||||
|
.TP
|
||||||
|
.B \-optimize
|
||||||
|
Perform optimization of entropy encoding parameters. Without this, default
|
||||||
|
encoding parameters are used.
|
||||||
|
.B \-optimize
|
||||||
|
usually makes the JPEG file a little smaller, but
|
||||||
|
.B cjpeg
|
||||||
|
runs somewhat slower and needs much more memory. Image quality and speed of
|
||||||
|
decompression are unaffected by
|
||||||
|
.BR \-optimize .
|
||||||
|
.TP
|
||||||
|
.B \-progressive
|
||||||
|
Create progressive JPEG file (see below).
|
||||||
|
.TP
|
||||||
|
.BI \-scale " M/N"
|
||||||
|
Scale the output image by a factor M/N. Currently supported scale factors are
|
||||||
|
M/N with all N from 1 to 16, where M is the destination DCT size, which is 8
|
||||||
|
by default (see
|
||||||
|
.BI \-block " N"
|
||||||
|
switch below).
|
||||||
|
.TP
|
||||||
|
.B \-targa
|
||||||
|
Input file is Targa format. Targa files that contain an "identification"
|
||||||
|
field will not be automatically recognized by
|
||||||
|
.BR cjpeg ;
|
||||||
|
for such files you must specify
|
||||||
|
.B \-targa
|
||||||
|
to make
|
||||||
|
.B cjpeg
|
||||||
|
treat the input as Targa format.
|
||||||
|
For most Targa files, you won't need this switch.
|
||||||
|
.PP
|
||||||
|
The
|
||||||
|
.B \-quality
|
||||||
|
switch lets you trade off compressed file size against quality of the
|
||||||
|
reconstructed image: the higher the quality setting, the larger the JPEG file,
|
||||||
|
and the closer the output image will be to the original input. Normally you
|
||||||
|
want to use the lowest quality setting (smallest file) that decompresses into
|
||||||
|
something visually indistinguishable from the original image. For this
|
||||||
|
purpose the quality setting should be between 50 and 95; the default of 75 is
|
||||||
|
often about right. If you see defects at
|
||||||
|
.B \-quality
|
||||||
|
75, then go up 5 or 10 counts at a time until you are happy with the output
|
||||||
|
image. (The optimal setting will vary from one image to another.)
|
||||||
|
.PP
|
||||||
|
.B \-quality
|
||||||
|
100 will generate a quantization table of all 1's, minimizing loss in the
|
||||||
|
quantization step (but there is still information loss in subsampling, as well
|
||||||
|
as roundoff error). This setting is mainly of interest for experimental
|
||||||
|
purposes. Quality values above about 95 are
|
||||||
|
.B not
|
||||||
|
recommended for normal use; the compressed file size goes up dramatically for
|
||||||
|
hardly any gain in output image quality.
|
||||||
|
.PP
|
||||||
|
In the other direction, quality values below 50 will produce very small files
|
||||||
|
of low image quality. Settings around 5 to 10 might be useful in preparing an
|
||||||
|
index of a large image library, for example. Try
|
||||||
|
.B \-quality
|
||||||
|
2 (or so) for some amusing Cubist effects. (Note: quality
|
||||||
|
values below about 25 generate 2-byte quantization tables, which are
|
||||||
|
considered optional in the JPEG standard.
|
||||||
|
.B cjpeg
|
||||||
|
emits a warning message when you give such a quality value, because some
|
||||||
|
other JPEG programs may be unable to decode the resulting file. Use
|
||||||
|
.B \-baseline
|
||||||
|
if you need to ensure compatibility at low quality values.)
|
||||||
|
.PP
|
||||||
|
The
|
||||||
|
.B \-quality
|
||||||
|
option has been extended in IJG version 7 for support of separate quality
|
||||||
|
settings for luminance and chrominance (or in general, for every provided
|
||||||
|
quantization table slot). This feature is useful for high-quality
|
||||||
|
applications which cannot accept the damage of color data by coarse
|
||||||
|
subsampling settings. You can now easily reduce the color data amount more
|
||||||
|
smoothly with finer control without separate subsampling. The resulting file
|
||||||
|
is fully compliant with standard JPEG decoders.
|
||||||
|
Note that the
|
||||||
|
.B \-quality
|
||||||
|
ratings refer to the quantization table slots, and that the last value is
|
||||||
|
replicated if there are more q-table slots than parameters. The default
|
||||||
|
q-table slots are 0 for luminance and 1 for chrominance with default tables as
|
||||||
|
given in the JPEG standard. This is compatible with the old behaviour in case
|
||||||
|
that only one parameter is given, which is then used for both luminance and
|
||||||
|
chrominance (slots 0 and 1). More or custom quantization tables can be set
|
||||||
|
with
|
||||||
|
.B \-qtables
|
||||||
|
and assigned to components with
|
||||||
|
.B \-qslots
|
||||||
|
parameter (see the "wizard" switches below).
|
||||||
|
.B Caution:
|
||||||
|
You must explicitly add
|
||||||
|
.BI \-sample " 1x1"
|
||||||
|
for efficient separate color
|
||||||
|
quality selection, since the default value used by library is 2x2!
|
||||||
|
.PP
|
||||||
|
The
|
||||||
|
.B \-progressive
|
||||||
|
switch creates a "progressive JPEG" file. In this type of JPEG file, the data
|
||||||
|
is stored in multiple scans of increasing quality. If the file is being
|
||||||
|
transmitted over a slow communications link, the decoder can use the first
|
||||||
|
scan to display a low-quality image very quickly, and can then improve the
|
||||||
|
display with each subsequent scan. The final image is exactly equivalent to a
|
||||||
|
standard JPEG file of the same quality setting, and the total file size is
|
||||||
|
about the same --- often a little smaller.
|
||||||
|
.PP
|
||||||
|
Switches for advanced users:
|
||||||
|
.TP
|
||||||
|
.B \-arithmetic
|
||||||
|
Use arithmetic coding.
|
||||||
|
.B Caution:
|
||||||
|
arithmetic coded JPEG is not yet widely implemented, so many decoders will
|
||||||
|
be unable to view an arithmetic coded JPEG file at all.
|
||||||
|
.TP
|
||||||
|
.BI \-block " N"
|
||||||
|
Set DCT block size. All N from 1 to 16 are possible.
|
||||||
|
Default is 8 (baseline format).
|
||||||
|
Larger values produce higher compression,
|
||||||
|
smaller values produce higher quality
|
||||||
|
(exact DCT stage possible with 1 or 2; with the default quality of 75 and
|
||||||
|
default Luminance qtable the DCT+Quantization stage is lossless for N=1).
|
||||||
|
.B Caution:
|
||||||
|
An implementation of the JPEG SmartScale extension is required for this
|
||||||
|
feature. SmartScale enabled JPEG is not yet widely implemented, so many
|
||||||
|
decoders will be unable to view a SmartScale extended JPEG file at all.
|
||||||
|
.TP
|
||||||
|
.B \-rgb1
|
||||||
|
Create RGB JPEG file with reversible color transform.
|
||||||
|
Works like the
|
||||||
|
.B \-rgb
|
||||||
|
switch (see above) and inserts a simple reversible color transform
|
||||||
|
into the processing which significantly improves the compression.
|
||||||
|
Use this switch in combination with the
|
||||||
|
.BI \-block " N"
|
||||||
|
switch (see above) for lossless JPEG coding.
|
||||||
|
.B Caution:
|
||||||
|
A decoder with inverse color transform support is required for
|
||||||
|
this feature. Reversible color transform support is not yet
|
||||||
|
widely implemented, so many decoders will be unable to view
|
||||||
|
a reversible color transformed JPEG file at all.
|
||||||
|
.TP
|
||||||
|
.B \-bgycc
|
||||||
|
Create big gamut YCC JPEG file.
|
||||||
|
In this type of encoding the color difference components are quantized
|
||||||
|
further by a factor of 2 compared to the normal Cb/Cr values, thus creating
|
||||||
|
space to allow larger color values with higher saturation than the normal
|
||||||
|
gamut limits to be encoded. In order to compensate for the loss of color
|
||||||
|
fidelity compared to a normal YCC encoded file, the color quantization
|
||||||
|
tables can be adjusted accordingly. For example,
|
||||||
|
.B cjpeg \-bgycc \-quality
|
||||||
|
80,90 will give similar results as
|
||||||
|
.B cjpeg \-quality
|
||||||
|
80.
|
||||||
|
.B Caution:
|
||||||
|
For correct decompression a decoder with big gamut YCC support (JFIF
|
||||||
|
version 2) is required. An old decoder may or may not display a big
|
||||||
|
gamut YCC encoded JPEG file, depending on JFIF version check and
|
||||||
|
corresponding warning/error configuration. In case of a granted
|
||||||
|
decompression the old decoder will display the image with half
|
||||||
|
saturated colors.
|
||||||
|
.TP
|
||||||
|
.B \-dct int
|
||||||
|
Use integer DCT method (default).
|
||||||
|
.TP
|
||||||
|
.B \-dct fast
|
||||||
|
Use fast integer DCT (less accurate).
|
||||||
|
.TP
|
||||||
|
.B \-dct float
|
||||||
|
Use floating-point DCT method.
|
||||||
|
The float method is very slightly more accurate than the int method, but is
|
||||||
|
much slower unless your machine has very fast floating-point hardware. Also
|
||||||
|
note that results of the floating-point method may vary slightly across
|
||||||
|
machines, while the integer methods should give the same results everywhere.
|
||||||
|
The fast integer method is much less accurate than the other two.
|
||||||
|
.TP
|
||||||
|
.B \-nosmooth
|
||||||
|
Don't use high-quality downsampling.
|
||||||
|
.TP
|
||||||
|
.BI \-restart " N"
|
||||||
|
Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
|
||||||
|
attached to the number.
|
||||||
|
.B \-restart 0
|
||||||
|
(the default) means no restart markers.
|
||||||
|
.TP
|
||||||
|
.BI \-smooth " N"
|
||||||
|
Smooth the input image to eliminate dithering noise. N, ranging from 1 to
|
||||||
|
100, indicates the strength of smoothing. 0 (the default) means no smoothing.
|
||||||
|
.TP
|
||||||
|
.BI \-maxmemory " N"
|
||||||
|
Set limit for amount of memory to use in processing large images. Value is
|
||||||
|
in thousands of bytes, or millions of bytes if "M" is attached to the
|
||||||
|
number. For example,
|
||||||
|
.B \-max 4m
|
||||||
|
selects 4000000 bytes. If more space is needed, temporary files will be used.
|
||||||
|
.TP
|
||||||
|
.BI \-outfile " name"
|
||||||
|
Send output image to the named file, not to standard output.
|
||||||
|
.TP
|
||||||
|
.B \-verbose
|
||||||
|
Enable debug printout. More
|
||||||
|
.BR \-v 's
|
||||||
|
give more output. Also, version information is printed at startup.
|
||||||
|
.TP
|
||||||
|
.B \-debug
|
||||||
|
Same as
|
||||||
|
.BR \-verbose .
|
||||||
|
.PP
|
||||||
|
The
|
||||||
|
.B \-restart
|
||||||
|
option inserts extra markers that allow a JPEG decoder to resynchronize after
|
||||||
|
a transmission error. Without restart markers, any damage to a compressed
|
||||||
|
file will usually ruin the image from the point of the error to the end of the
|
||||||
|
image; with restart markers, the damage is usually confined to the portion of
|
||||||
|
the image up to the next restart marker. Of course, the restart markers
|
||||||
|
occupy extra space. We recommend
|
||||||
|
.B \-restart 1
|
||||||
|
for images that will be transmitted across unreliable networks such as Usenet.
|
||||||
|
.PP
|
||||||
|
The
|
||||||
|
.B \-smooth
|
||||||
|
option filters the input to eliminate fine-scale noise. This is often useful
|
||||||
|
when converting dithered images to JPEG: a moderate smoothing factor of 10 to
|
||||||
|
50 gets rid of dithering patterns in the input file, resulting in a smaller
|
||||||
|
JPEG file and a better-looking image. Too large a smoothing factor will
|
||||||
|
visibly blur the image, however.
|
||||||
|
.PP
|
||||||
|
Switches for wizards:
|
||||||
|
.TP
|
||||||
|
.B \-baseline
|
||||||
|
Force baseline-compatible quantization tables to be generated. This clamps
|
||||||
|
quantization values to 8 bits even at low quality settings. (This switch is
|
||||||
|
poorly named, since it does not ensure that the output is actually baseline
|
||||||
|
JPEG. For example, you can use
|
||||||
|
.B \-baseline
|
||||||
|
and
|
||||||
|
.B \-progressive
|
||||||
|
together.)
|
||||||
|
.TP
|
||||||
|
.BI \-qtables " file"
|
||||||
|
Use the quantization tables given in the specified text file.
|
||||||
|
.TP
|
||||||
|
.BI \-qslots " N[,...]"
|
||||||
|
Select which quantization table to use for each color component.
|
||||||
|
.TP
|
||||||
|
.BI \-sample " HxV[,...]"
|
||||||
|
Set JPEG sampling factors for each color component.
|
||||||
|
.TP
|
||||||
|
.BI \-scans " file"
|
||||||
|
Use the scan script given in the specified text file.
|
||||||
|
.PP
|
||||||
|
The "wizard" switches are intended for experimentation with JPEG. If you
|
||||||
|
don't know what you are doing, \fBdon't use them\fR. These switches are
|
||||||
|
documented further in the file wizard.txt.
|
||||||
|
.SH EXAMPLES
|
||||||
|
.LP
|
||||||
|
This example compresses the PPM file foo.ppm with a quality factor of
|
||||||
|
60 and saves the output as foo.jpg:
|
||||||
|
.IP
|
||||||
|
.B cjpeg \-quality
|
||||||
|
.I 60 foo.ppm
|
||||||
|
.B >
|
||||||
|
.I foo.jpg
|
||||||
|
.SH HINTS
|
||||||
|
Color GIF files are not the ideal input for JPEG; JPEG is really intended for
|
||||||
|
compressing full-color (24-bit) images. In particular, don't try to convert
|
||||||
|
cartoons, line drawings, and other images that have only a few distinct
|
||||||
|
colors. GIF works great on these, JPEG does not. If you want to convert a
|
||||||
|
GIF to JPEG, you should experiment with
|
||||||
|
.BR cjpeg 's
|
||||||
|
.B \-quality
|
||||||
|
and
|
||||||
|
.B \-smooth
|
||||||
|
options to get a satisfactory conversion.
|
||||||
|
.B \-smooth 10
|
||||||
|
or so is often helpful.
|
||||||
|
.PP
|
||||||
|
Avoid running an image through a series of JPEG compression/decompression
|
||||||
|
cycles. Image quality loss will accumulate; after ten or so cycles the image
|
||||||
|
may be noticeably worse than it was after one cycle. It's best to use a
|
||||||
|
lossless format while manipulating an image, then convert to JPEG format when
|
||||||
|
you are ready to file the image away.
|
||||||
|
.PP
|
||||||
|
The
|
||||||
|
.B \-optimize
|
||||||
|
option to
|
||||||
|
.B cjpeg
|
||||||
|
is worth using when you are making a "final" version for posting or archiving.
|
||||||
|
It's also a win when you are using low quality settings to make very small
|
||||||
|
JPEG files; the percentage improvement is often a lot more than it is on
|
||||||
|
larger files. (At present,
|
||||||
|
.B \-optimize
|
||||||
|
mode is always selected when generating progressive JPEG files.)
|
||||||
|
.SH ENVIRONMENT
|
||||||
|
.TP
|
||||||
|
.B JPEGMEM
|
||||||
|
If this environment variable is set, its value is the default memory limit.
|
||||||
|
The value is specified as described for the
|
||||||
|
.B \-maxmemory
|
||||||
|
switch.
|
||||||
|
.B JPEGMEM
|
||||||
|
overrides the default value specified when the program was compiled, and
|
||||||
|
itself is overridden by an explicit
|
||||||
|
.BR \-maxmemory .
|
||||||
|
.SH SEE ALSO
|
||||||
|
.BR djpeg (1),
|
||||||
|
.BR jpegtran (1),
|
||||||
|
.BR rdjpgcom (1),
|
||||||
|
.BR wrjpgcom (1)
|
||||||
|
.br
|
||||||
|
.BR ppm (5),
|
||||||
|
.BR pgm (5)
|
||||||
|
.br
|
||||||
|
Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
|
||||||
|
Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
|
||||||
|
.SH AUTHOR
|
||||||
|
Independent JPEG Group
|
||||||
|
.SH BUGS
|
||||||
|
Not all variants of BMP and Targa file formats are supported.
|
||||||
|
.PP
|
||||||
|
The
|
||||||
|
.B \-targa
|
||||||
|
switch is not a bug, it's a feature. (It would be a bug if the Targa format
|
||||||
|
designers had not been clueless.)
|
||||||
Vendored
+34
-9
@@ -2,7 +2,7 @@
|
|||||||
* cjpeg.c
|
* cjpeg.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||||
* Modified 2003-2010 by Guido Vollbeding.
|
* Modified 2003-2013 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -152,6 +152,7 @@ usage (void)
|
|||||||
fprintf(stderr, "Switches (names may be abbreviated):\n");
|
fprintf(stderr, "Switches (names may be abbreviated):\n");
|
||||||
fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is useful range)\n");
|
fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is useful range)\n");
|
||||||
fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
|
fprintf(stderr, " -grayscale Create monochrome JPEG file\n");
|
||||||
|
fprintf(stderr, " -rgb Create RGB JPEG file\n");
|
||||||
#ifdef ENTROPY_OPT_SUPPORTED
|
#ifdef ENTROPY_OPT_SUPPORTED
|
||||||
fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
|
fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n");
|
||||||
#endif
|
#endif
|
||||||
@@ -165,9 +166,16 @@ usage (void)
|
|||||||
fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
|
fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n");
|
||||||
#endif
|
#endif
|
||||||
fprintf(stderr, "Switches for advanced users:\n");
|
fprintf(stderr, "Switches for advanced users:\n");
|
||||||
|
#ifdef C_ARITH_CODING_SUPPORTED
|
||||||
|
fprintf(stderr, " -arithmetic Use arithmetic coding\n");
|
||||||
|
#endif
|
||||||
#ifdef DCT_SCALING_SUPPORTED
|
#ifdef DCT_SCALING_SUPPORTED
|
||||||
fprintf(stderr, " -block N DCT block size (1..16; default is 8)\n");
|
fprintf(stderr, " -block N DCT block size (1..16; default is 8)\n");
|
||||||
#endif
|
#endif
|
||||||
|
#if JPEG_LIB_VERSION_MAJOR >= 9
|
||||||
|
fprintf(stderr, " -rgb1 Create RGB JPEG file with reversible color transform\n");
|
||||||
|
fprintf(stderr, " -bgycc Create big gamut YCC JPEG file\n");
|
||||||
|
#endif
|
||||||
#ifdef DCT_ISLOW_SUPPORTED
|
#ifdef DCT_ISLOW_SUPPORTED
|
||||||
fprintf(stderr, " -dct int Use integer DCT method%s\n",
|
fprintf(stderr, " -dct int Use integer DCT method%s\n",
|
||||||
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
|
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
|
||||||
@@ -189,9 +197,6 @@ usage (void)
|
|||||||
fprintf(stderr, " -outfile name Specify name for output file\n");
|
fprintf(stderr, " -outfile name Specify name for output file\n");
|
||||||
fprintf(stderr, " -verbose or -debug Emit debug output\n");
|
fprintf(stderr, " -verbose or -debug Emit debug output\n");
|
||||||
fprintf(stderr, "Switches for wizards:\n");
|
fprintf(stderr, "Switches for wizards:\n");
|
||||||
#ifdef C_ARITH_CODING_SUPPORTED
|
|
||||||
fprintf(stderr, " -arithmetic Use arithmetic coding\n");
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, " -baseline Force baseline quantization tables\n");
|
fprintf(stderr, " -baseline Force baseline quantization tables\n");
|
||||||
fprintf(stderr, " -qtables file Use quantization tables given in file\n");
|
fprintf(stderr, " -qtables file Use quantization tables given in file\n");
|
||||||
fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
|
fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
|
||||||
@@ -263,9 +268,8 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
|||||||
|
|
||||||
} else if (keymatch(arg, "block", 2)) {
|
} else if (keymatch(arg, "block", 2)) {
|
||||||
/* Set DCT block size. */
|
/* Set DCT block size. */
|
||||||
#if defined(DCT_SCALING_SUPPORTED) && defined(JPEG_LIB_VERSION_MAJOR) && \
|
#if defined DCT_SCALING_SUPPORTED && JPEG_LIB_VERSION_MAJOR >= 8 && \
|
||||||
(JPEG_LIB_VERSION_MAJOR > 8 || (JPEG_LIB_VERSION_MAJOR == 8 && \
|
(JPEG_LIB_VERSION_MAJOR > 8 || JPEG_LIB_VERSION_MINOR >= 3)
|
||||||
defined(JPEG_LIB_VERSION_MINOR) && JPEG_LIB_VERSION_MINOR >= 3))
|
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
if (++argn >= argc) /* advance to next argument */
|
if (++argn >= argc) /* advance to next argument */
|
||||||
@@ -310,6 +314,27 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
|||||||
/* Force a monochrome JPEG file to be generated. */
|
/* Force a monochrome JPEG file to be generated. */
|
||||||
jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
|
jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
|
||||||
|
|
||||||
|
} else if (keymatch(arg, "rgb", 3) || keymatch(arg, "rgb1", 4)) {
|
||||||
|
/* Force an RGB JPEG file to be generated. */
|
||||||
|
#if JPEG_LIB_VERSION_MAJOR >= 9
|
||||||
|
/* Note: Entropy table assignment in jpeg_set_colorspace depends
|
||||||
|
* on color_transform.
|
||||||
|
*/
|
||||||
|
cinfo->color_transform = arg[3] ? JCT_SUBTRACT_GREEN : JCT_NONE;
|
||||||
|
#endif
|
||||||
|
jpeg_set_colorspace(cinfo, JCS_RGB);
|
||||||
|
|
||||||
|
} else if (keymatch(arg, "bgycc", 5)) {
|
||||||
|
/* Force a big gamut YCC JPEG file to be generated. */
|
||||||
|
#if JPEG_LIB_VERSION_MAJOR >= 9 && \
|
||||||
|
(JPEG_LIB_VERSION_MAJOR > 9 || JPEG_LIB_VERSION_MINOR >= 1)
|
||||||
|
jpeg_set_colorspace(cinfo, JCS_BG_YCC);
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "%s: sorry, BG_YCC colorspace not supported\n",
|
||||||
|
progname);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
#endif
|
||||||
|
|
||||||
} else if (keymatch(arg, "maxmemory", 3)) {
|
} else if (keymatch(arg, "maxmemory", 3)) {
|
||||||
/* Maximum memory in Kb (or Mb with 'm'). */
|
/* Maximum memory in Kb (or Mb with 'm'). */
|
||||||
long lval;
|
long lval;
|
||||||
@@ -324,7 +349,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
|||||||
cinfo->mem->max_memory_to_use = lval * 1000L;
|
cinfo->mem->max_memory_to_use = lval * 1000L;
|
||||||
|
|
||||||
} else if (keymatch(arg, "nosmooth", 3)) {
|
} else if (keymatch(arg, "nosmooth", 3)) {
|
||||||
/* Suppress fancy downsampling */
|
/* Suppress fancy downsampling. */
|
||||||
cinfo->do_fancy_downsampling = FALSE;
|
cinfo->do_fancy_downsampling = FALSE;
|
||||||
|
|
||||||
} else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
|
} else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
|
||||||
@@ -410,7 +435,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
|||||||
/* Scale the image by a fraction M/N. */
|
/* Scale the image by a fraction M/N. */
|
||||||
if (++argn >= argc) /* advance to next argument */
|
if (++argn >= argc) /* advance to next argument */
|
||||||
usage();
|
usage();
|
||||||
if (sscanf(argv[argn], "%d/%d",
|
if (sscanf(argv[argn], "%u/%u",
|
||||||
&cinfo->scale_num, &cinfo->scale_denom) != 2)
|
&cinfo->scale_num, &cinfo->scale_denom) != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
|||||||
Vendored
+791
@@ -0,0 +1,791 @@
|
|||||||
|
/*
|
||||||
|
* alternate cjpeg.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||||
|
* Modified 2009-2020 by Guido Vollbeding.
|
||||||
|
* This file is part of the Independent JPEG Group's software.
|
||||||
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
|
*
|
||||||
|
* This file contains an alternate user interface for the JPEG compressor.
|
||||||
|
* One or more input files are named on the command line, and output file
|
||||||
|
* names are created by substituting ".jpg" for the input file's extension.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
||||||
|
#include "jversion.h" /* for version message */
|
||||||
|
|
||||||
|
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
|
||||||
|
#ifdef __MWERKS__
|
||||||
|
#include <SIOUX.h> /* Metrowerks needs this */
|
||||||
|
#include <console.h> /* ... and this */
|
||||||
|
#endif
|
||||||
|
#ifdef THINK_C
|
||||||
|
#include <console.h> /* Think declares it here */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PATH_MAX /* ANSI maximum-pathname-length constant */
|
||||||
|
#define PATH_MAX 256
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Create the add-on message string table. */
|
||||||
|
|
||||||
|
#define JMESSAGE(code,string) string ,
|
||||||
|
|
||||||
|
static const char * const cdjpeg_message_table[] = {
|
||||||
|
#include "cderror.h"
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Automatic determination of available memory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static long default_maxmem; /* saves value determined at startup, or 0 */
|
||||||
|
|
||||||
|
#ifndef FREE_MEM_ESTIMATE /* may be defined from command line */
|
||||||
|
|
||||||
|
#ifdef MSDOS /* For MS-DOS (unless flat-memory model) */
|
||||||
|
|
||||||
|
#include <dos.h> /* for access to intdos() call */
|
||||||
|
|
||||||
|
LOCAL(long)
|
||||||
|
unused_dos_memory (void)
|
||||||
|
/* Obtain total amount of unallocated DOS memory */
|
||||||
|
{
|
||||||
|
union REGS regs;
|
||||||
|
long nparas;
|
||||||
|
|
||||||
|
regs.h.ah = 0x48; /* DOS function Allocate Memory Block */
|
||||||
|
regs.x.bx = 0xFFFF; /* Ask for more memory than DOS can have */
|
||||||
|
(void) intdos(®s, ®s);
|
||||||
|
/* DOS will fail and return # of paragraphs actually available in BX. */
|
||||||
|
nparas = (unsigned int) regs.x.bx;
|
||||||
|
/* Times 16 to convert to bytes. */
|
||||||
|
return nparas << 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The default memory setting is 95% of the available space. */
|
||||||
|
#define FREE_MEM_ESTIMATE ((unused_dos_memory() * 95L) / 100L)
|
||||||
|
|
||||||
|
#endif /* MSDOS */
|
||||||
|
|
||||||
|
#ifdef ATARI /* For Atari ST/STE/TT, Pure C or Turbo C */
|
||||||
|
|
||||||
|
#include <ext.h>
|
||||||
|
|
||||||
|
/* The default memory setting is 90% of the available space. */
|
||||||
|
#define FREE_MEM_ESTIMATE (((long) coreleft() * 90L) / 100L)
|
||||||
|
|
||||||
|
#endif /* ATARI */
|
||||||
|
|
||||||
|
/* Add memory-estimation procedures for other operating systems here,
|
||||||
|
* with appropriate #ifdef's around them.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* !FREE_MEM_ESTIMATE */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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, such as the RLE library);
|
||||||
|
* or 4) don't put back the data, and modify the input_init methods to assume
|
||||||
|
* they start reading after the start of file (also breaks RLE library).
|
||||||
|
* #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);
|
||||||
|
#endif
|
||||||
|
#ifdef GIF_SUPPORTED
|
||||||
|
case 'G':
|
||||||
|
return jinit_read_gif(cinfo);
|
||||||
|
#endif
|
||||||
|
#ifdef PPM_SUPPORTED
|
||||||
|
case 'P':
|
||||||
|
return jinit_read_ppm(cinfo);
|
||||||
|
#endif
|
||||||
|
#ifdef RLE_SUPPORTED
|
||||||
|
case 'R':
|
||||||
|
return jinit_read_rle(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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
static const char * progname; /* program name for error messages */
|
||||||
|
static char * outfilename; /* for -outfile switch */
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL(void)
|
||||||
|
usage (void)
|
||||||
|
/* complain about bad command line */
|
||||||
|
{
|
||||||
|
fprintf(stderr, "usage: %s [switches] inputfile(s)\n", progname);
|
||||||
|
fprintf(stderr, "List of input files may use wildcards (* and ?)\n");
|
||||||
|
fprintf(stderr, "Output filename is same as input filename, but extension .jpg\n");
|
||||||
|
|
||||||
|
fprintf(stderr, "Switches (names may be abbreviated):\n");
|
||||||
|
fprintf(stderr, " -quality N[,...] Compression quality (0..100; 5-95 is useful range)\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 DCT_SCALING_SUPPORTED
|
||||||
|
fprintf(stderr, " -scale M/N Scale image by fraction M/N, eg, 1/2\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");
|
||||||
|
#ifdef C_ARITH_CODING_SUPPORTED
|
||||||
|
fprintf(stderr, " -arithmetic Use arithmetic coding\n");
|
||||||
|
#endif
|
||||||
|
#ifdef DCT_SCALING_SUPPORTED
|
||||||
|
fprintf(stderr, " -block N DCT block size (1..16; default is 8)\n");
|
||||||
|
#endif
|
||||||
|
#if JPEG_LIB_VERSION_MAJOR >= 9
|
||||||
|
fprintf(stderr, " -rgb1 Create RGB JPEG file with reversible color transform\n");
|
||||||
|
fprintf(stderr, " -bgycc Create big gamut YCC JPEG file\n");
|
||||||
|
#endif
|
||||||
|
#ifdef DCT_ISLOW_SUPPORTED
|
||||||
|
fprintf(stderr, " -dct int Use integer DCT method%s\n",
|
||||||
|
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
|
||||||
|
#endif
|
||||||
|
#ifdef DCT_IFAST_SUPPORTED
|
||||||
|
fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
|
||||||
|
(JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
|
||||||
|
#endif
|
||||||
|
#ifdef DCT_FLOAT_SUPPORTED
|
||||||
|
fprintf(stderr, " -dct float Use floating-point DCT method%s\n",
|
||||||
|
(JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : ""));
|
||||||
|
#endif
|
||||||
|
fprintf(stderr, " -nosmooth Don't use high-quality downsampling\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
|
||||||
|
#ifndef FREE_MEM_ESTIMATE
|
||||||
|
fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
|
||||||
|
#endif
|
||||||
|
fprintf(stderr, " -outfile name Specify name for output file\n");
|
||||||
|
fprintf(stderr, " -verbose or -debug Emit debug output\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;
|
||||||
|
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;
|
||||||
|
outfilename = NULL;
|
||||||
|
cinfo->err->trace_level = 0;
|
||||||
|
if (default_maxmem > 0) /* override library's default value */
|
||||||
|
cinfo->mem->max_memory_to_use = default_maxmem;
|
||||||
|
|
||||||
|
/* 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", 2)) {
|
||||||
|
/* Force baseline-compatible output (8-bit quantizer values). */
|
||||||
|
force_baseline = TRUE;
|
||||||
|
|
||||||
|
} else if (keymatch(arg, "block", 2)) {
|
||||||
|
/* Set DCT block size. */
|
||||||
|
#if defined DCT_SCALING_SUPPORTED && JPEG_LIB_VERSION_MAJOR >= 8 && \
|
||||||
|
(JPEG_LIB_VERSION_MAJOR > 8 || JPEG_LIB_VERSION_MINOR >= 3)
|
||||||
|
int val;
|
||||||
|
|
||||||
|
if (++argn >= argc) /* advance to next argument */
|
||||||
|
usage();
|
||||||
|
if (sscanf(argv[argn], "%d", &val) != 1)
|
||||||
|
usage();
|
||||||
|
if (val < 1 || val > 16)
|
||||||
|
usage();
|
||||||
|
cinfo->block_size = val;
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "%s: sorry, block size setting not supported\n",
|
||||||
|
progname);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} 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, "Independent JPEG Group's CJPEG, version %s\n%s\n",
|
||||||
|
JVERSION, JCOPYRIGHT);
|
||||||
|
printed_version = TRUE;
|
||||||
|
}
|
||||||
|
cinfo->err->trace_level++;
|
||||||
|
|
||||||
|
} 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) || keymatch(arg, "rgb1", 4)) {
|
||||||
|
/* Force an RGB JPEG file to be generated. */
|
||||||
|
#if JPEG_LIB_VERSION_MAJOR >= 9
|
||||||
|
/* Note: Entropy table assignment in jpeg_set_colorspace depends
|
||||||
|
* on color_transform.
|
||||||
|
*/
|
||||||
|
cinfo->color_transform = arg[3] ? JCT_SUBTRACT_GREEN : JCT_NONE;
|
||||||
|
#endif
|
||||||
|
jpeg_set_colorspace(cinfo, JCS_RGB);
|
||||||
|
|
||||||
|
} else if (keymatch(arg, "bgycc", 5)) {
|
||||||
|
/* Force a big gamut YCC JPEG file to be generated. */
|
||||||
|
#if JPEG_LIB_VERSION_MAJOR >= 9 && \
|
||||||
|
(JPEG_LIB_VERSION_MAJOR > 9 || JPEG_LIB_VERSION_MINOR >= 1)
|
||||||
|
jpeg_set_colorspace(cinfo, JCS_BG_YCC);
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "%s: sorry, BG_YCC colorspace not supported\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, "nosmooth", 3)) {
|
||||||
|
/* Suppress fancy downsampling. */
|
||||||
|
cinfo->do_fancy_downsampling = FALSE;
|
||||||
|
|
||||||
|
} 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\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, "progressive", 1)) {
|
||||||
|
/* 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\n",
|
||||||
|
progname);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} 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, "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, "scale", 4)) {
|
||||||
|
/* Scale the image by a fraction M/N. */
|
||||||
|
if (++argn >= argc) /* advance to next argument */
|
||||||
|
usage();
|
||||||
|
if (sscanf(argv[argn], "%d/%d",
|
||||||
|
&cinfo->scale_num, &cinfo->scale_denom) != 2)
|
||||||
|
usage();
|
||||||
|
|
||||||
|
} 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\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, "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) */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for overwrite of an existing file; clear it with user
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NO_OVERWRITE_CHECK
|
||||||
|
|
||||||
|
LOCAL(boolean)
|
||||||
|
is_write_ok (char * outfname)
|
||||||
|
{
|
||||||
|
FILE * ofile;
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
ofile = fopen(outfname, READ_BINARY);
|
||||||
|
if (ofile == NULL)
|
||||||
|
return TRUE; /* not present */
|
||||||
|
fclose(ofile); /* oops, it is present */
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
fprintf(stderr, "%s already exists, overwrite it? [y/n] ",
|
||||||
|
outfname);
|
||||||
|
fflush(stderr);
|
||||||
|
ch = getc(stdin);
|
||||||
|
if (ch != '\n') /* flush rest of line */
|
||||||
|
while (getc(stdin) != '\n')
|
||||||
|
/* nothing */;
|
||||||
|
|
||||||
|
switch (ch) {
|
||||||
|
case 'Y':
|
||||||
|
case 'y':
|
||||||
|
return TRUE;
|
||||||
|
case 'N':
|
||||||
|
case 'n':
|
||||||
|
return FALSE;
|
||||||
|
/* otherwise, ask again */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Process a single input file name, and return its index in argv[].
|
||||||
|
* File names at or to left of old_file_index have been processed already.
|
||||||
|
*/
|
||||||
|
|
||||||
|
LOCAL(int)
|
||||||
|
process_one_file (int argc, char **argv, int old_file_index)
|
||||||
|
{
|
||||||
|
struct jpeg_compress_struct cinfo;
|
||||||
|
struct jpeg_error_mgr jerr;
|
||||||
|
char *infilename;
|
||||||
|
char workfilename[PATH_MAX];
|
||||||
|
#ifdef PROGRESS_REPORT
|
||||||
|
struct cdjpeg_progress_mgr progress;
|
||||||
|
#endif
|
||||||
|
int file_index;
|
||||||
|
cjpeg_source_ptr src_mgr;
|
||||||
|
FILE * input_file = NULL;
|
||||||
|
FILE * output_file = NULL;
|
||||||
|
JDIMENSION num_scanlines;
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
|
/* Now safe to enable signal catcher. */
|
||||||
|
#ifdef NEED_SIGNAL_CATCHER
|
||||||
|
enable_signal_catcher((j_common_ptr) &cinfo);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* 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 next file name.
|
||||||
|
* 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, old_file_index, FALSE);
|
||||||
|
if (file_index >= argc) {
|
||||||
|
fprintf(stderr, "%s: missing input file name\n", progname);
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the input file. */
|
||||||
|
infilename = argv[file_index];
|
||||||
|
if ((input_file = fopen(infilename, READ_BINARY)) == NULL) {
|
||||||
|
fprintf(stderr, "%s: can't open %s\n", progname, infilename);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PROGRESS_REPORT
|
||||||
|
start_progress_monitor((j_common_ptr) &cinfo, &progress);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
|
/* 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, old_file_index, TRUE);
|
||||||
|
|
||||||
|
/* If user didn't supply -outfile switch, select output file name. */
|
||||||
|
if (outfilename == NULL) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
outfilename = workfilename;
|
||||||
|
/* Make outfilename be infilename with .jpg substituted for extension */
|
||||||
|
strcpy(outfilename, infilename);
|
||||||
|
for (i = (int)strlen(outfilename)-1; i >= 0; i--) {
|
||||||
|
switch (outfilename[i]) {
|
||||||
|
case ':':
|
||||||
|
case '/':
|
||||||
|
case '\\':
|
||||||
|
i = 0; /* stop scanning */
|
||||||
|
break;
|
||||||
|
case '.':
|
||||||
|
outfilename[i] = '\0'; /* lop off existing extension */
|
||||||
|
i = 0; /* stop scanning */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break; /* keep scanning */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strcat(outfilename, ".jpg");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "Compressing %s => %s\n", infilename, outfilename);
|
||||||
|
#ifndef NO_OVERWRITE_CHECK
|
||||||
|
if (! is_write_ok(outfilename))
|
||||||
|
goto fail;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Open the output file. */
|
||||||
|
if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
|
||||||
|
fprintf(stderr, "%s: can't create %s\n", progname, outfilename);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Specify data destination for compression */
|
||||||
|
jpeg_stdio_dest(&cinfo, output_file);
|
||||||
|
|
||||||
|
/* Start compressor */
|
||||||
|
jpeg_start_compress(&cinfo, TRUE);
|
||||||
|
|
||||||
|
/* Process data */
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* Clean up and exit */
|
||||||
|
fail:
|
||||||
|
jpeg_destroy_compress(&cinfo);
|
||||||
|
|
||||||
|
if (input_file != NULL) fclose(input_file);
|
||||||
|
if (output_file != NULL) fclose(output_file);
|
||||||
|
|
||||||
|
#ifdef PROGRESS_REPORT
|
||||||
|
end_progress_monitor((j_common_ptr) &cinfo);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Disable signal catcher. */
|
||||||
|
#ifdef NEED_SIGNAL_CATCHER
|
||||||
|
enable_signal_catcher((j_common_ptr) NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return file_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The main program.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int file_index;
|
||||||
|
|
||||||
|
/* On Mac, fetch a command line. */
|
||||||
|
#ifdef USE_CCOMMAND
|
||||||
|
argc = ccommand(&argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MSDOS
|
||||||
|
progname = "cjpeg"; /* DOS tends to be too verbose about argv[0] */
|
||||||
|
#else
|
||||||
|
progname = argv[0];
|
||||||
|
if (progname == NULL || progname[0] == 0)
|
||||||
|
progname = "cjpeg"; /* in case C library doesn't provide it */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The default maxmem must be computed only once at program startup,
|
||||||
|
* since releasing memory with free() won't give it back to the OS.
|
||||||
|
*/
|
||||||
|
#ifdef FREE_MEM_ESTIMATE
|
||||||
|
default_maxmem = FREE_MEM_ESTIMATE;
|
||||||
|
#else
|
||||||
|
default_maxmem = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Scan command line, parse switches and locate input file names */
|
||||||
|
|
||||||
|
if (argc < 2)
|
||||||
|
usage(); /* nothing on the command line?? */
|
||||||
|
|
||||||
|
file_index = 0;
|
||||||
|
|
||||||
|
while (file_index < argc-1)
|
||||||
|
file_index = process_one_file(argc, argv, file_index);
|
||||||
|
|
||||||
|
/* All done. */
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
return 0; /* suppress no-return-value warnings */
|
||||||
|
}
|
||||||
+348
@@ -0,0 +1,348 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Wrapper for compilers which do not understand '-c -o'.
|
||||||
|
|
||||||
|
scriptversion=2018-03-07.03; # UTC
|
||||||
|
|
||||||
|
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||||
|
# Written by Tom Tromey <[email protected]>.
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# As a special exception to the GNU General Public License, if you
|
||||||
|
# distribute this file as part of a program that contains a
|
||||||
|
# configuration script generated by Autoconf, you may include it under
|
||||||
|
# the same distribution terms that you use for the rest of that program.
|
||||||
|
|
||||||
|
# This file is maintained in Automake, please report
|
||||||
|
# bugs to <[email protected]> or send patches to
|
||||||
|
# <[email protected]>.
|
||||||
|
|
||||||
|
nl='
|
||||||
|
'
|
||||||
|
|
||||||
|
# We need space, tab and new line, in precisely that order. Quoting is
|
||||||
|
# there to prevent tools from complaining about whitespace usage.
|
||||||
|
IFS=" "" $nl"
|
||||||
|
|
||||||
|
file_conv=
|
||||||
|
|
||||||
|
# func_file_conv build_file lazy
|
||||||
|
# Convert a $build file to $host form and store it in $file
|
||||||
|
# Currently only supports Windows hosts. If the determined conversion
|
||||||
|
# type is listed in (the comma separated) LAZY, no conversion will
|
||||||
|
# take place.
|
||||||
|
func_file_conv ()
|
||||||
|
{
|
||||||
|
file=$1
|
||||||
|
case $file in
|
||||||
|
/ | /[!/]*) # absolute file, and not a UNC file
|
||||||
|
if test -z "$file_conv"; then
|
||||||
|
# lazily determine how to convert abs files
|
||||||
|
case `uname -s` in
|
||||||
|
MINGW*)
|
||||||
|
file_conv=mingw
|
||||||
|
;;
|
||||||
|
CYGWIN* | MSYS*)
|
||||||
|
file_conv=cygwin
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
file_conv=wine
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
case $file_conv/,$2, in
|
||||||
|
*,$file_conv,*)
|
||||||
|
;;
|
||||||
|
mingw/*)
|
||||||
|
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
|
||||||
|
;;
|
||||||
|
cygwin/* | msys/*)
|
||||||
|
file=`cygpath -m "$file" || echo "$file"`
|
||||||
|
;;
|
||||||
|
wine/*)
|
||||||
|
file=`winepath -w "$file" || echo "$file"`
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# func_cl_dashL linkdir
|
||||||
|
# Make cl look for libraries in LINKDIR
|
||||||
|
func_cl_dashL ()
|
||||||
|
{
|
||||||
|
func_file_conv "$1"
|
||||||
|
if test -z "$lib_path"; then
|
||||||
|
lib_path=$file
|
||||||
|
else
|
||||||
|
lib_path="$lib_path;$file"
|
||||||
|
fi
|
||||||
|
linker_opts="$linker_opts -LIBPATH:$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
# func_cl_dashl library
|
||||||
|
# Do a library search-path lookup for cl
|
||||||
|
func_cl_dashl ()
|
||||||
|
{
|
||||||
|
lib=$1
|
||||||
|
found=no
|
||||||
|
save_IFS=$IFS
|
||||||
|
IFS=';'
|
||||||
|
for dir in $lib_path $LIB
|
||||||
|
do
|
||||||
|
IFS=$save_IFS
|
||||||
|
if $shared && test -f "$dir/$lib.dll.lib"; then
|
||||||
|
found=yes
|
||||||
|
lib=$dir/$lib.dll.lib
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if test -f "$dir/$lib.lib"; then
|
||||||
|
found=yes
|
||||||
|
lib=$dir/$lib.lib
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if test -f "$dir/lib$lib.a"; then
|
||||||
|
found=yes
|
||||||
|
lib=$dir/lib$lib.a
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
IFS=$save_IFS
|
||||||
|
|
||||||
|
if test "$found" != yes; then
|
||||||
|
lib=$lib.lib
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# func_cl_wrapper cl arg...
|
||||||
|
# Adjust compile command to suit cl
|
||||||
|
func_cl_wrapper ()
|
||||||
|
{
|
||||||
|
# Assume a capable shell
|
||||||
|
lib_path=
|
||||||
|
shared=:
|
||||||
|
linker_opts=
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
if test -n "$eat"; then
|
||||||
|
eat=
|
||||||
|
else
|
||||||
|
case $1 in
|
||||||
|
-o)
|
||||||
|
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||||
|
eat=1
|
||||||
|
case $2 in
|
||||||
|
*.o | *.[oO][bB][jJ])
|
||||||
|
func_file_conv "$2"
|
||||||
|
set x "$@" -Fo"$file"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
func_file_conv "$2"
|
||||||
|
set x "$@" -Fe"$file"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
-I)
|
||||||
|
eat=1
|
||||||
|
func_file_conv "$2" mingw
|
||||||
|
set x "$@" -I"$file"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-I*)
|
||||||
|
func_file_conv "${1#-I}" mingw
|
||||||
|
set x "$@" -I"$file"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-l)
|
||||||
|
eat=1
|
||||||
|
func_cl_dashl "$2"
|
||||||
|
set x "$@" "$lib"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-l*)
|
||||||
|
func_cl_dashl "${1#-l}"
|
||||||
|
set x "$@" "$lib"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-L)
|
||||||
|
eat=1
|
||||||
|
func_cl_dashL "$2"
|
||||||
|
;;
|
||||||
|
-L*)
|
||||||
|
func_cl_dashL "${1#-L}"
|
||||||
|
;;
|
||||||
|
-static)
|
||||||
|
shared=false
|
||||||
|
;;
|
||||||
|
-Wl,*)
|
||||||
|
arg=${1#-Wl,}
|
||||||
|
save_ifs="$IFS"; IFS=','
|
||||||
|
for flag in $arg; do
|
||||||
|
IFS="$save_ifs"
|
||||||
|
linker_opts="$linker_opts $flag"
|
||||||
|
done
|
||||||
|
IFS="$save_ifs"
|
||||||
|
;;
|
||||||
|
-Xlinker)
|
||||||
|
eat=1
|
||||||
|
linker_opts="$linker_opts $2"
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
set x "$@" "$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
|
||||||
|
func_file_conv "$1"
|
||||||
|
set x "$@" -Tp"$file"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
|
||||||
|
func_file_conv "$1" mingw
|
||||||
|
set x "$@" "$file"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set x "$@" "$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
if test -n "$linker_opts"; then
|
||||||
|
linker_opts="-link$linker_opts"
|
||||||
|
fi
|
||||||
|
exec "$@" $linker_opts
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
eat=
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
'')
|
||||||
|
echo "$0: No command. Try '$0 --help' for more information." 1>&2
|
||||||
|
exit 1;
|
||||||
|
;;
|
||||||
|
-h | --h*)
|
||||||
|
cat <<\EOF
|
||||||
|
Usage: compile [--help] [--version] PROGRAM [ARGS]
|
||||||
|
|
||||||
|
Wrapper for compilers which do not understand '-c -o'.
|
||||||
|
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
|
||||||
|
arguments, and rename the output as expected.
|
||||||
|
|
||||||
|
If you are trying to build a whole package this is not the
|
||||||
|
right script to run: please start by reading the file 'INSTALL'.
|
||||||
|
|
||||||
|
Report bugs to <[email protected]>.
|
||||||
|
EOF
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
-v | --v*)
|
||||||
|
echo "compile $scriptversion"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
|
||||||
|
icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
|
||||||
|
func_cl_wrapper "$@" # Doesn't return...
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
ofile=
|
||||||
|
cfile=
|
||||||
|
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
if test -n "$eat"; then
|
||||||
|
eat=
|
||||||
|
else
|
||||||
|
case $1 in
|
||||||
|
-o)
|
||||||
|
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||||
|
# So we strip '-o arg' only if arg is an object.
|
||||||
|
eat=1
|
||||||
|
case $2 in
|
||||||
|
*.o | *.obj)
|
||||||
|
ofile=$2
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set x "$@" -o "$2"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*.c)
|
||||||
|
cfile=$1
|
||||||
|
set x "$@" "$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set x "$@" "$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if test -z "$ofile" || test -z "$cfile"; then
|
||||||
|
# If no '-o' option was seen then we might have been invoked from a
|
||||||
|
# pattern rule where we don't need one. That is ok -- this is a
|
||||||
|
# normal compilation that the losing compiler can handle. If no
|
||||||
|
# '.c' file was seen then we are probably linking. That is also
|
||||||
|
# ok.
|
||||||
|
exec "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Name of file we expect compiler to create.
|
||||||
|
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
|
||||||
|
|
||||||
|
# Create the lock directory.
|
||||||
|
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
|
||||||
|
# that we are using for the .o file. Also, base the name on the expected
|
||||||
|
# object file name, since that is what matters with a parallel build.
|
||||||
|
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
|
||||||
|
while true; do
|
||||||
|
if mkdir "$lockdir" >/dev/null 2>&1; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
# FIXME: race condition here if user kills between mkdir and trap.
|
||||||
|
trap "rmdir '$lockdir'; exit 1" 1 2 15
|
||||||
|
|
||||||
|
# Run the compile.
|
||||||
|
"$@"
|
||||||
|
ret=$?
|
||||||
|
|
||||||
|
if test -f "$cofile"; then
|
||||||
|
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
|
||||||
|
elif test -f "${cofile}bj"; then
|
||||||
|
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rmdir "$lockdir"
|
||||||
|
exit $ret
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# mode: shell-script
|
||||||
|
# sh-indentation: 2
|
||||||
|
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-time-zone: "UTC0"
|
||||||
|
# time-stamp-end: "; # UTC"
|
||||||
|
# End:
|
||||||
+1748
File diff suppressed because it is too large
Load Diff
+1884
File diff suppressed because it is too large
Load Diff
+16365
File diff suppressed because it is too large
Load Diff
Vendored
+365
@@ -0,0 +1,365 @@
|
|||||||
|
# IJG auto-configuration source file.
|
||||||
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
|
#
|
||||||
|
# Configure script for IJG libjpeg
|
||||||
|
#
|
||||||
|
|
||||||
|
AC_INIT([libjpeg], [9.5.0])
|
||||||
|
|
||||||
|
# Directory where autotools helper scripts lives.
|
||||||
|
AC_CONFIG_AUX_DIR([.])
|
||||||
|
|
||||||
|
# Generate configuration headers.
|
||||||
|
AC_CONFIG_HEADERS([jconfig.h:jconfig.cfg])
|
||||||
|
|
||||||
|
# Hack: disable autoheader so that it doesn't overwrite our cfg template.
|
||||||
|
AUTOHEADER="echo autoheader ignored"
|
||||||
|
|
||||||
|
# Check system type
|
||||||
|
AC_CANONICAL_TARGET
|
||||||
|
|
||||||
|
# Initialize Automake
|
||||||
|
# Don't require all the GNU mandated files
|
||||||
|
AM_INIT_AUTOMAKE([-Wall -Werror no-dist foreign])
|
||||||
|
|
||||||
|
# Make --enable-silent-rules the default.
|
||||||
|
# To get verbose build output you may configure
|
||||||
|
# with --disable-silent-rules or use "make V=1".
|
||||||
|
AM_SILENT_RULES([yes])
|
||||||
|
|
||||||
|
# Add configure option --enable-maintainer-mode which enables
|
||||||
|
# dependency checking and generation useful to package maintainers.
|
||||||
|
# This is made an option to avoid confusing end users.
|
||||||
|
AM_MAINTAINER_MODE
|
||||||
|
|
||||||
|
# Check for programs
|
||||||
|
AC_PROG_CC
|
||||||
|
AC_PROG_CPP
|
||||||
|
AC_PROG_INSTALL
|
||||||
|
AC_PROG_MAKE_SET
|
||||||
|
AC_PROG_LN_S
|
||||||
|
AC_PROG_EGREP
|
||||||
|
AM_PROG_AR
|
||||||
|
|
||||||
|
# Check if LD supports linker scripts,
|
||||||
|
# and define automake conditional HAVE_LD_VERSION_SCRIPT if so.
|
||||||
|
AC_ARG_ENABLE([ld-version-script],
|
||||||
|
AS_HELP_STRING([--enable-ld-version-script],
|
||||||
|
[enable linker version script (default is enabled when possible)]),
|
||||||
|
[have_ld_version_script=$enableval], [])
|
||||||
|
if test -z "$have_ld_version_script"; then
|
||||||
|
AC_MSG_CHECKING([if LD -Wl,--version-script works])
|
||||||
|
save_LDFLAGS="$LDFLAGS"
|
||||||
|
LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
|
||||||
|
cat > conftest.map <<EOF
|
||||||
|
VERS_1 {
|
||||||
|
global: sym;
|
||||||
|
};
|
||||||
|
|
||||||
|
VERS_2 {
|
||||||
|
global: sym;
|
||||||
|
} VERS_1;
|
||||||
|
EOF
|
||||||
|
AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
|
||||||
|
[have_ld_version_script=yes], [have_ld_version_script=no])
|
||||||
|
rm -f conftest.map
|
||||||
|
LDFLAGS="$save_LDFLAGS"
|
||||||
|
AC_MSG_RESULT($have_ld_version_script)
|
||||||
|
fi
|
||||||
|
AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
|
||||||
|
|
||||||
|
# See if compiler supports prototypes.
|
||||||
|
AC_MSG_CHECKING([for function prototypes])
|
||||||
|
AC_CACHE_VAL([ijg_cv_have_prototypes],
|
||||||
|
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
|
||||||
|
int testfunction (int arg1, int * arg2); /* check prototypes */
|
||||||
|
struct methods_struct { /* check method-pointer declarations */
|
||||||
|
int (*error_exit) (char *msgtext);
|
||||||
|
int (*trace_message) (char *msgtext);
|
||||||
|
int (*another_method) (void);
|
||||||
|
};
|
||||||
|
int testfunction (int arg1, int * arg2) /* check definitions */
|
||||||
|
{ return arg2[arg1]; }
|
||||||
|
int test2function (void) /* check void arg list */
|
||||||
|
{ return 0; }
|
||||||
|
]])],
|
||||||
|
[ijg_cv_have_prototypes=yes],
|
||||||
|
[ijg_cv_have_prototypes=no])])
|
||||||
|
AC_MSG_RESULT([$ijg_cv_have_prototypes])
|
||||||
|
if test $ijg_cv_have_prototypes = yes; then
|
||||||
|
AC_DEFINE([HAVE_PROTOTYPES],[1],[Compiler supports function prototypes.])
|
||||||
|
else
|
||||||
|
AC_MSG_WARN([Your compiler does not seem to know about function prototypes.
|
||||||
|
Perhaps it needs a special switch to enable ANSI C mode.
|
||||||
|
If so, we recommend running configure like this:
|
||||||
|
./configure CC='cc -switch'
|
||||||
|
where -switch is the proper switch.])
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check header files
|
||||||
|
AC_CHECK_HEADERS([stddef.h stdlib.h locale.h])
|
||||||
|
AC_CHECK_HEADER([string.h], [],
|
||||||
|
[AC_DEFINE([NEED_BSD_STRINGS], [1],
|
||||||
|
[Compiler has <strings.h> rather than standard <string.h>.])])
|
||||||
|
|
||||||
|
# See whether type size_t is defined in any ANSI-standard places;
|
||||||
|
# if not, perhaps it is defined in <sys/types.h>.
|
||||||
|
AC_MSG_CHECKING([for size_t])
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||||
|
#ifdef HAVE_STDDEF_H
|
||||||
|
#include <stddef.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
#ifdef NEED_BSD_STRINGS
|
||||||
|
#include <strings.h>
|
||||||
|
#else
|
||||||
|
#include <string.h>
|
||||||
|
#endif
|
||||||
|
typedef size_t my_size_t;
|
||||||
|
]], [[ my_size_t foovar; ]])],
|
||||||
|
[ijg_size_t_ok=yes],
|
||||||
|
[ijg_size_t_ok="not ANSI, perhaps it is in sys/types.h"])
|
||||||
|
AC_MSG_RESULT([$ijg_size_t_ok])
|
||||||
|
if test "$ijg_size_t_ok" != yes; then
|
||||||
|
AC_CHECK_HEADER([sys/types.h],
|
||||||
|
[AC_DEFINE([NEED_SYS_TYPES_H], [1],
|
||||||
|
[Need to include <sys/types.h> in order to obtain size_t.])
|
||||||
|
AC_EGREP_CPP([size_t], [#include <sys/types.h>],
|
||||||
|
[ijg_size_t_ok="size_t is in sys/types.h"],
|
||||||
|
[ijg_size_t_ok=no])],
|
||||||
|
[ijg_size_t_ok=no])
|
||||||
|
AC_MSG_RESULT([$ijg_size_t_ok])
|
||||||
|
if test "$ijg_size_t_ok" = no; then
|
||||||
|
AC_MSG_WARN([Type size_t is not defined in any of the usual places.
|
||||||
|
Try putting '"typedef unsigned int size_t;"' in jconfig.h.])
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check compiler characteristics
|
||||||
|
AC_MSG_CHECKING([for type unsigned char])
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ unsigned char un_char; ]])],
|
||||||
|
[AC_MSG_RESULT(yes)
|
||||||
|
AC_DEFINE([HAVE_UNSIGNED_CHAR], [1],
|
||||||
|
[Compiler supports 'unsigned char'.])],
|
||||||
|
[AC_MSG_RESULT(no)])
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([for type unsigned short])
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ unsigned short un_short; ]])],
|
||||||
|
[AC_MSG_RESULT(yes)
|
||||||
|
AC_DEFINE([HAVE_UNSIGNED_SHORT], [1],
|
||||||
|
[Compiler supports 'unsigned short'.])],
|
||||||
|
[AC_MSG_RESULT(no)])
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([for type void])
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||||
|
/* Caution: a C++ compiler will insist on valid prototypes */
|
||||||
|
typedef void * void_ptr; /* check void * */
|
||||||
|
#ifdef HAVE_PROTOTYPES /* check ptr to function returning void */
|
||||||
|
typedef void (*void_func) (int a, int b);
|
||||||
|
#else
|
||||||
|
typedef void (*void_func) ();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_PROTOTYPES /* check void function result */
|
||||||
|
void test3function (void_ptr arg1, void_func arg2)
|
||||||
|
#else
|
||||||
|
void test3function (arg1, arg2)
|
||||||
|
void_ptr arg1;
|
||||||
|
void_func arg2;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
char * locptr = (char *) arg1; /* check casting to and from void * */
|
||||||
|
arg1 = (void *) locptr;
|
||||||
|
(*arg2) (1, 2); /* check call of fcn returning void */
|
||||||
|
}
|
||||||
|
]], [[ ]])],
|
||||||
|
[AC_MSG_RESULT(yes)],
|
||||||
|
[AC_MSG_RESULT(no)
|
||||||
|
AC_DEFINE([void], [char],
|
||||||
|
[Define 'void' as 'char' for archaic compilers
|
||||||
|
that don't understand it.])])
|
||||||
|
AC_C_CONST
|
||||||
|
|
||||||
|
# Check for non-broken inline under various spellings
|
||||||
|
AC_MSG_CHECKING([for inline])
|
||||||
|
ijg_cv_inline=""
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[} __inline__ int foo() { return 0; }
|
||||||
|
int bar() { return foo();]])], ijg_cv_inline="__inline__",
|
||||||
|
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [[} __inline int foo() { return 0; }
|
||||||
|
int bar() { return foo();]])], ijg_cv_inline="__inline",
|
||||||
|
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [[} inline int foo() { return 0; }
|
||||||
|
int bar() { return foo();]])], ijg_cv_inline="inline")])])
|
||||||
|
AC_MSG_RESULT($ijg_cv_inline)
|
||||||
|
AC_DEFINE_UNQUOTED([INLINE], [$ijg_cv_inline],
|
||||||
|
[How to obtain function inlining.])
|
||||||
|
|
||||||
|
# We cannot check for bogus warnings, but at least we can check for errors
|
||||||
|
AC_MSG_CHECKING([for broken incomplete types])
|
||||||
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||||
|
typedef struct undefined_structure * undef_struct_ptr;
|
||||||
|
]], [[]])],
|
||||||
|
[AC_MSG_RESULT(ok)],
|
||||||
|
[AC_MSG_RESULT(broken)
|
||||||
|
AC_DEFINE([INCOMPLETE_TYPES_BROKEN], [1],
|
||||||
|
[Compiler does not support pointers to unspecified
|
||||||
|
structures.])])
|
||||||
|
|
||||||
|
# Test whether global names are unique to at least 15 chars
|
||||||
|
AC_MSG_CHECKING([for short external names])
|
||||||
|
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
|
||||||
|
int possibly_duplicate_function () { return 0; }
|
||||||
|
int possibly_dupli_function () { return 1; }
|
||||||
|
]], [[]])],
|
||||||
|
[AC_MSG_RESULT(ok)],
|
||||||
|
[AC_MSG_RESULT(short)
|
||||||
|
AC_DEFINE([NEED_SHORT_EXTERNAL_NAMES], [1],
|
||||||
|
[Linker requires that global names be unique in
|
||||||
|
first 15 characters.])])
|
||||||
|
|
||||||
|
# Run-time checks
|
||||||
|
AC_MSG_CHECKING([to see if char is signed])
|
||||||
|
AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
#ifdef HAVE_PROTOTYPES
|
||||||
|
int is_char_signed (int arg)
|
||||||
|
#else
|
||||||
|
int is_char_signed (arg)
|
||||||
|
int arg;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
if (arg == 189) { /* expected result for unsigned char */
|
||||||
|
return 0; /* type char is unsigned */
|
||||||
|
}
|
||||||
|
else if (arg != -67) { /* expected result for signed char */
|
||||||
|
printf("Hmm, it seems 'char' is not eight bits wide on your machine.\n");
|
||||||
|
printf("I fear the JPEG software will not work at all.\n\n");
|
||||||
|
}
|
||||||
|
return 1; /* assume char is signed otherwise */
|
||||||
|
}
|
||||||
|
char signed_char_check = (char) (-67);
|
||||||
|
int main() {
|
||||||
|
exit(is_char_signed((int) signed_char_check));
|
||||||
|
}]])], [AC_MSG_RESULT(no)
|
||||||
|
AC_DEFINE([CHAR_IS_UNSIGNED], [1],
|
||||||
|
[Characters are unsigned])],
|
||||||
|
[AC_MSG_RESULT(yes)],
|
||||||
|
[AC_MSG_WARN([Assuming that char is signed on target machine.
|
||||||
|
If it is unsigned, this will be a little bit inefficient.])
|
||||||
|
])
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([to see if right shift is signed])
|
||||||
|
AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
#ifdef HAVE_PROTOTYPES
|
||||||
|
int is_shifting_signed (long arg)
|
||||||
|
#else
|
||||||
|
int is_shifting_signed (arg)
|
||||||
|
long arg;
|
||||||
|
#endif
|
||||||
|
/* See whether right-shift on a long is signed or not. */
|
||||||
|
{
|
||||||
|
long res = arg >> 4;
|
||||||
|
|
||||||
|
if (res == -0x7F7E80CL) { /* expected result for signed shift */
|
||||||
|
return 1; /* right shift is signed */
|
||||||
|
}
|
||||||
|
/* see if unsigned-shift hack will fix it. */
|
||||||
|
/* we can't just test exact value since it depends on width of long... */
|
||||||
|
res |= (~0L) << (32-4);
|
||||||
|
if (res == -0x7F7E80CL) { /* expected result now? */
|
||||||
|
return 0; /* right shift is unsigned */
|
||||||
|
}
|
||||||
|
printf("Right shift isn't acting as I expect it to.\n");
|
||||||
|
printf("I fear the JPEG software will not work at all.\n\n");
|
||||||
|
return 0; /* try it with unsigned anyway */
|
||||||
|
}
|
||||||
|
int main() {
|
||||||
|
exit(is_shifting_signed(-0x7F7E80B1L));
|
||||||
|
}]])],
|
||||||
|
[AC_MSG_RESULT(no)
|
||||||
|
AC_DEFINE([RIGHT_SHIFT_IS_UNSIGNED], [1],
|
||||||
|
[Broken compiler shifts signed values as an unsigned shift.])],
|
||||||
|
[AC_MSG_RESULT(yes)],
|
||||||
|
[AC_MSG_RESULT(Assuming that right shift is signed on target machine.)])
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([to see if fopen accepts b spec])
|
||||||
|
AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
||||||
|
#ifdef HAVE_STDLIB_H
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
int main() {
|
||||||
|
if (fopen("conftestdata", "wb") != NULL)
|
||||||
|
exit(0);
|
||||||
|
exit(1);
|
||||||
|
}]])],
|
||||||
|
[AC_MSG_RESULT(yes)],
|
||||||
|
[AC_MSG_RESULT(no)
|
||||||
|
AC_DEFINE([DONT_USE_B_MODE], [1],
|
||||||
|
[Don't open files in binary mode.])],
|
||||||
|
[AC_MSG_RESULT(Assuming that it does.)])
|
||||||
|
|
||||||
|
# Configure libtool
|
||||||
|
LT_INIT([win32-dll])
|
||||||
|
|
||||||
|
# Select memory manager depending on user input.
|
||||||
|
# If no "-enable-maxmem", use jmemnobs
|
||||||
|
MEMORYMGR='jmemnobs'
|
||||||
|
MAXMEM="no"
|
||||||
|
AC_ARG_ENABLE([maxmem],
|
||||||
|
[ --enable-maxmem[=N] enable use of temp files, set max mem usage to N MB],
|
||||||
|
[MAXMEM="$enableval"])
|
||||||
|
dnl [# support --with-maxmem for backwards compatibility with IJG V5.]
|
||||||
|
dnl AC_ARG_WITH(maxmem, , MAXMEM="$withval")
|
||||||
|
if test "x$MAXMEM" = xyes; then
|
||||||
|
MAXMEM=1
|
||||||
|
fi
|
||||||
|
if test "x$MAXMEM" != xno; then
|
||||||
|
if test -n "`echo $MAXMEM | sed 's/[[0-9]]//g'`"; then
|
||||||
|
AC_MSG_ERROR(non-numeric argument to --enable-maxmem)
|
||||||
|
fi
|
||||||
|
DEFAULTMAXMEM=`expr $MAXMEM \* 1048576`
|
||||||
|
AC_DEFINE_UNQUOTED([DEFAULT_MAX_MEM], [${DEFAULTMAXMEM}],
|
||||||
|
[Maximum data space library will allocate.])
|
||||||
|
AC_MSG_CHECKING([for 'tmpfile()'])
|
||||||
|
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[ FILE * tfile = tmpfile(); ]])],
|
||||||
|
[AC_MSG_RESULT(yes)
|
||||||
|
MEMORYMGR='jmemansi'],
|
||||||
|
[AC_MSG_RESULT(no)
|
||||||
|
dnl if tmpfile is not present, must use jmemname.
|
||||||
|
MEMORYMGR='jmemname'
|
||||||
|
|
||||||
|
# Test for the need to remove temporary files using a signal handler
|
||||||
|
# (for cjpeg/djpeg)
|
||||||
|
AC_DEFINE([NEED_SIGNAL_CATCHER], [1],
|
||||||
|
[Need signal handler to clean up temporary files.])
|
||||||
|
AC_MSG_CHECKING([for 'mktemp()'])
|
||||||
|
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[ char fname[80]; mktemp(fname); ]])],
|
||||||
|
[AC_MSG_RESULT(yes)],
|
||||||
|
[AC_MSG_RESULT(no)
|
||||||
|
AC_DEFINE([NO_MKTEMP], [1],
|
||||||
|
[The mktemp() function is not available.])])])
|
||||||
|
fi
|
||||||
|
AC_SUBST([MEMORYMGR])
|
||||||
|
|
||||||
|
# Extract the library version IDs from jpeglib.h.
|
||||||
|
AC_MSG_CHECKING([libjpeg version number])
|
||||||
|
[major=`sed -ne 's/^#define JPEG_LIB_VERSION_MAJOR *\([0-9][0-9]*\).*$/\1/p' $srcdir/jpeglib.h`
|
||||||
|
minor=`sed -ne 's/^#define JPEG_LIB_VERSION_MINOR *\([0-9][0-9]*\).*$/\1/p' $srcdir/jpeglib.h`]
|
||||||
|
AC_SUBST([JPEG_LIB_VERSION], [`expr $major + $minor`:0:$minor])
|
||||||
|
AC_SUBST([JPEG_LIB_VERSION_MAJOR], [$major])
|
||||||
|
AC_SUBST([JPEG_LIB_VERSION_MINOR], [$minor])
|
||||||
|
AC_MSG_RESULT([$major.$minor.0])
|
||||||
|
|
||||||
|
AC_CONFIG_FILES([Makefile libjpeg.pc])
|
||||||
|
AC_OUTPUT
|
||||||
+791
@@ -0,0 +1,791 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# depcomp - compile a program generating dependencies as side-effects
|
||||||
|
|
||||||
|
scriptversion=2018-03-07.03; # UTC
|
||||||
|
|
||||||
|
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# As a special exception to the GNU General Public License, if you
|
||||||
|
# distribute this file as part of a program that contains a
|
||||||
|
# configuration script generated by Autoconf, you may include it under
|
||||||
|
# the same distribution terms that you use for the rest of that program.
|
||||||
|
|
||||||
|
# Originally written by Alexandre Oliva <[email protected]>.
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
'')
|
||||||
|
echo "$0: No command. Try '$0 --help' for more information." 1>&2
|
||||||
|
exit 1;
|
||||||
|
;;
|
||||||
|
-h | --h*)
|
||||||
|
cat <<\EOF
|
||||||
|
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
|
||||||
|
|
||||||
|
Run PROGRAMS ARGS to compile a file, generating dependencies
|
||||||
|
as side-effects.
|
||||||
|
|
||||||
|
Environment variables:
|
||||||
|
depmode Dependency tracking mode.
|
||||||
|
source Source file read by 'PROGRAMS ARGS'.
|
||||||
|
object Object file output by 'PROGRAMS ARGS'.
|
||||||
|
DEPDIR directory where to store dependencies.
|
||||||
|
depfile Dependency file to output.
|
||||||
|
tmpdepfile Temporary file to use when outputting dependencies.
|
||||||
|
libtool Whether libtool is used (yes/no).
|
||||||
|
|
||||||
|
Report bugs to <[email protected]>.
|
||||||
|
EOF
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
-v | --v*)
|
||||||
|
echo "depcomp $scriptversion"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Get the directory component of the given path, and save it in the
|
||||||
|
# global variables '$dir'. Note that this directory component will
|
||||||
|
# be either empty or ending with a '/' character. This is deliberate.
|
||||||
|
set_dir_from ()
|
||||||
|
{
|
||||||
|
case $1 in
|
||||||
|
*/*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
|
||||||
|
*) dir=;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get the suffix-stripped basename of the given path, and save it the
|
||||||
|
# global variable '$base'.
|
||||||
|
set_base_from ()
|
||||||
|
{
|
||||||
|
base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
|
||||||
|
}
|
||||||
|
|
||||||
|
# If no dependency file was actually created by the compiler invocation,
|
||||||
|
# we still have to create a dummy depfile, to avoid errors with the
|
||||||
|
# Makefile "include basename.Plo" scheme.
|
||||||
|
make_dummy_depfile ()
|
||||||
|
{
|
||||||
|
echo "#dummy" > "$depfile"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Factor out some common post-processing of the generated depfile.
|
||||||
|
# Requires the auxiliary global variable '$tmpdepfile' to be set.
|
||||||
|
aix_post_process_depfile ()
|
||||||
|
{
|
||||||
|
# If the compiler actually managed to produce a dependency file,
|
||||||
|
# post-process it.
|
||||||
|
if test -f "$tmpdepfile"; then
|
||||||
|
# Each line is of the form 'foo.o: dependency.h'.
|
||||||
|
# Do two passes, one to just change these to
|
||||||
|
# $object: dependency.h
|
||||||
|
# and one to simply output
|
||||||
|
# dependency.h:
|
||||||
|
# which is needed to avoid the deleted-header problem.
|
||||||
|
{ sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
|
||||||
|
sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
|
||||||
|
} > "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
else
|
||||||
|
make_dummy_depfile
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# A tabulation character.
|
||||||
|
tab=' '
|
||||||
|
# A newline character.
|
||||||
|
nl='
|
||||||
|
'
|
||||||
|
# Character ranges might be problematic outside the C locale.
|
||||||
|
# These definitions help.
|
||||||
|
upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
|
lower=abcdefghijklmnopqrstuvwxyz
|
||||||
|
digits=0123456789
|
||||||
|
alpha=${upper}${lower}
|
||||||
|
|
||||||
|
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
|
||||||
|
echo "depcomp: Variables source, object and depmode must be set" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
|
||||||
|
depfile=${depfile-`echo "$object" |
|
||||||
|
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
|
||||||
|
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
|
||||||
|
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
|
||||||
|
# Avoid interferences from the environment.
|
||||||
|
gccflag= dashmflag=
|
||||||
|
|
||||||
|
# Some modes work just like other modes, but use different flags. We
|
||||||
|
# parameterize here, but still list the modes in the big case below,
|
||||||
|
# to make depend.m4 easier to write. Note that we *cannot* use a case
|
||||||
|
# here, because this file can only contain one case statement.
|
||||||
|
if test "$depmode" = hp; then
|
||||||
|
# HP compiler uses -M and no extra arg.
|
||||||
|
gccflag=-M
|
||||||
|
depmode=gcc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$depmode" = dashXmstdout; then
|
||||||
|
# This is just like dashmstdout with a different argument.
|
||||||
|
dashmflag=-xM
|
||||||
|
depmode=dashmstdout
|
||||||
|
fi
|
||||||
|
|
||||||
|
cygpath_u="cygpath -u -f -"
|
||||||
|
if test "$depmode" = msvcmsys; then
|
||||||
|
# This is just like msvisualcpp but w/o cygpath translation.
|
||||||
|
# Just convert the backslash-escaped backslashes to single forward
|
||||||
|
# slashes to satisfy depend.m4
|
||||||
|
cygpath_u='sed s,\\\\,/,g'
|
||||||
|
depmode=msvisualcpp
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$depmode" = msvc7msys; then
|
||||||
|
# This is just like msvc7 but w/o cygpath translation.
|
||||||
|
# Just convert the backslash-escaped backslashes to single forward
|
||||||
|
# slashes to satisfy depend.m4
|
||||||
|
cygpath_u='sed s,\\\\,/,g'
|
||||||
|
depmode=msvc7
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test "$depmode" = xlc; then
|
||||||
|
# IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
|
||||||
|
gccflag=-qmakedep=gcc,-MF
|
||||||
|
depmode=gcc
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$depmode" in
|
||||||
|
gcc3)
|
||||||
|
## gcc 3 implements dependency tracking that does exactly what
|
||||||
|
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
|
||||||
|
## it if -MD -MP comes after the -MF stuff. Hmm.
|
||||||
|
## Unfortunately, FreeBSD c89 acceptance of flags depends upon
|
||||||
|
## the command line argument order; so add the flags where they
|
||||||
|
## appear in depend2.am. Note that the slowdown incurred here
|
||||||
|
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
|
||||||
|
*) set fnord "$@" "$arg" ;;
|
||||||
|
esac
|
||||||
|
shift # fnord
|
||||||
|
shift # $arg
|
||||||
|
done
|
||||||
|
"$@"
|
||||||
|
stat=$?
|
||||||
|
if test $stat -ne 0; then
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
mv "$tmpdepfile" "$depfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
gcc)
|
||||||
|
## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
|
||||||
|
## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
|
||||||
|
## (see the conditional assignment to $gccflag above).
|
||||||
|
## There are various ways to get dependency output from gcc. Here's
|
||||||
|
## why we pick this rather obscure method:
|
||||||
|
## - Don't want to use -MD because we'd like the dependencies to end
|
||||||
|
## up in a subdir. Having to rename by hand is ugly.
|
||||||
|
## (We might end up doing this anyway to support other compilers.)
|
||||||
|
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
|
||||||
|
## -MM, not -M (despite what the docs say). Also, it might not be
|
||||||
|
## supported by the other compilers which use the 'gcc' depmode.
|
||||||
|
## - Using -M directly means running the compiler twice (even worse
|
||||||
|
## than renaming).
|
||||||
|
if test -z "$gccflag"; then
|
||||||
|
gccflag=-MD,
|
||||||
|
fi
|
||||||
|
"$@" -Wp,"$gccflag$tmpdepfile"
|
||||||
|
stat=$?
|
||||||
|
if test $stat -ne 0; then
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
# The second -e expression handles DOS-style file names with drive
|
||||||
|
# letters.
|
||||||
|
sed -e 's/^[^:]*: / /' \
|
||||||
|
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
|
||||||
|
## This next piece of magic avoids the "deleted header file" problem.
|
||||||
|
## The problem is that when a header file which appears in a .P file
|
||||||
|
## is deleted, the dependency causes make to die (because there is
|
||||||
|
## typically no way to rebuild the header). We avoid this by adding
|
||||||
|
## dummy dependencies for each header file. Too bad gcc doesn't do
|
||||||
|
## this for us directly.
|
||||||
|
## Some versions of gcc put a space before the ':'. On the theory
|
||||||
|
## that the space means something, we add a space to the output as
|
||||||
|
## well. hp depmode also adds that space, but also prefixes the VPATH
|
||||||
|
## to the object. Take care to not repeat it in the output.
|
||||||
|
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
## correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
tr ' ' "$nl" < "$tmpdepfile" \
|
||||||
|
| sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
|
||||||
|
| sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
hp)
|
||||||
|
# This case exists only to let depend.m4 do its work. It works by
|
||||||
|
# looking at the text of this script. This case will never be run,
|
||||||
|
# since it is checked for above.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
sgi)
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
"$@" "-Wp,-MDupdate,$tmpdepfile"
|
||||||
|
else
|
||||||
|
"$@" -MDupdate "$tmpdepfile"
|
||||||
|
fi
|
||||||
|
stat=$?
|
||||||
|
if test $stat -ne 0; then
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
|
||||||
|
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
# Clip off the initial element (the dependent). Don't try to be
|
||||||
|
# clever and replace this with sed code, as IRIX sed won't handle
|
||||||
|
# lines with more than a fixed number of characters (4096 in
|
||||||
|
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
|
||||||
|
# the IRIX cc adds comments like '#:fec' to the end of the
|
||||||
|
# dependency line.
|
||||||
|
tr ' ' "$nl" < "$tmpdepfile" \
|
||||||
|
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
|
||||||
|
| tr "$nl" ' ' >> "$depfile"
|
||||||
|
echo >> "$depfile"
|
||||||
|
# The second pass generates a dummy entry for each header file.
|
||||||
|
tr ' ' "$nl" < "$tmpdepfile" \
|
||||||
|
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
|
||||||
|
>> "$depfile"
|
||||||
|
else
|
||||||
|
make_dummy_depfile
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
xlc)
|
||||||
|
# This case exists only to let depend.m4 do its work. It works by
|
||||||
|
# looking at the text of this script. This case will never be run,
|
||||||
|
# since it is checked for above.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
aix)
|
||||||
|
# The C for AIX Compiler uses -M and outputs the dependencies
|
||||||
|
# in a .u file. In older versions, this file always lives in the
|
||||||
|
# current directory. Also, the AIX compiler puts '$object:' at the
|
||||||
|
# start of each line; $object doesn't have directory information.
|
||||||
|
# Version 6 uses the directory in both cases.
|
||||||
|
set_dir_from "$object"
|
||||||
|
set_base_from "$object"
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
tmpdepfile1=$dir$base.u
|
||||||
|
tmpdepfile2=$base.u
|
||||||
|
tmpdepfile3=$dir.libs/$base.u
|
||||||
|
"$@" -Wc,-M
|
||||||
|
else
|
||||||
|
tmpdepfile1=$dir$base.u
|
||||||
|
tmpdepfile2=$dir$base.u
|
||||||
|
tmpdepfile3=$dir$base.u
|
||||||
|
"$@" -M
|
||||||
|
fi
|
||||||
|
stat=$?
|
||||||
|
if test $stat -ne 0; then
|
||||||
|
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
|
||||||
|
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||||
|
do
|
||||||
|
test -f "$tmpdepfile" && break
|
||||||
|
done
|
||||||
|
aix_post_process_depfile
|
||||||
|
;;
|
||||||
|
|
||||||
|
tcc)
|
||||||
|
# tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
|
||||||
|
# FIXME: That version still under development at the moment of writing.
|
||||||
|
# Make that this statement remains true also for stable, released
|
||||||
|
# versions.
|
||||||
|
# It will wrap lines (doesn't matter whether long or short) with a
|
||||||
|
# trailing '\', as in:
|
||||||
|
#
|
||||||
|
# foo.o : \
|
||||||
|
# foo.c \
|
||||||
|
# foo.h \
|
||||||
|
#
|
||||||
|
# It will put a trailing '\' even on the last line, and will use leading
|
||||||
|
# spaces rather than leading tabs (at least since its commit 0394caf7
|
||||||
|
# "Emit spaces for -MD").
|
||||||
|
"$@" -MD -MF "$tmpdepfile"
|
||||||
|
stat=$?
|
||||||
|
if test $stat -ne 0; then
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
# Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
|
||||||
|
# We have to change lines of the first kind to '$object: \'.
|
||||||
|
sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
|
||||||
|
# And for each line of the second kind, we have to emit a 'dep.h:'
|
||||||
|
# dummy dependency, to avoid the deleted-header problem.
|
||||||
|
sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
## The order of this option in the case statement is important, since the
|
||||||
|
## shell code in configure will try each of these formats in the order
|
||||||
|
## listed in this file. A plain '-MD' option would be understood by many
|
||||||
|
## compilers, so we must ensure this comes after the gcc and icc options.
|
||||||
|
pgcc)
|
||||||
|
# Portland's C compiler understands '-MD'.
|
||||||
|
# Will always output deps to 'file.d' where file is the root name of the
|
||||||
|
# source file under compilation, even if file resides in a subdirectory.
|
||||||
|
# The object file name does not affect the name of the '.d' file.
|
||||||
|
# pgcc 10.2 will output
|
||||||
|
# foo.o: sub/foo.c sub/foo.h
|
||||||
|
# and will wrap long lines using '\' :
|
||||||
|
# foo.o: sub/foo.c ... \
|
||||||
|
# sub/foo.h ... \
|
||||||
|
# ...
|
||||||
|
set_dir_from "$object"
|
||||||
|
# Use the source, not the object, to determine the base name, since
|
||||||
|
# that's sadly what pgcc will do too.
|
||||||
|
set_base_from "$source"
|
||||||
|
tmpdepfile=$base.d
|
||||||
|
|
||||||
|
# For projects that build the same source file twice into different object
|
||||||
|
# files, the pgcc approach of using the *source* file root name can cause
|
||||||
|
# problems in parallel builds. Use a locking strategy to avoid stomping on
|
||||||
|
# the same $tmpdepfile.
|
||||||
|
lockdir=$base.d-lock
|
||||||
|
trap "
|
||||||
|
echo '$0: caught signal, cleaning up...' >&2
|
||||||
|
rmdir '$lockdir'
|
||||||
|
exit 1
|
||||||
|
" 1 2 13 15
|
||||||
|
numtries=100
|
||||||
|
i=$numtries
|
||||||
|
while test $i -gt 0; do
|
||||||
|
# mkdir is a portable test-and-set.
|
||||||
|
if mkdir "$lockdir" 2>/dev/null; then
|
||||||
|
# This process acquired the lock.
|
||||||
|
"$@" -MD
|
||||||
|
stat=$?
|
||||||
|
# Release the lock.
|
||||||
|
rmdir "$lockdir"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
# If the lock is being held by a different process, wait
|
||||||
|
# until the winning process is done or we timeout.
|
||||||
|
while test -d "$lockdir" && test $i -gt 0; do
|
||||||
|
sleep 1
|
||||||
|
i=`expr $i - 1`
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
i=`expr $i - 1`
|
||||||
|
done
|
||||||
|
trap - 1 2 13 15
|
||||||
|
if test $i -le 0; then
|
||||||
|
echo "$0: failed to acquire lock after $numtries attempts" >&2
|
||||||
|
echo "$0: check lockdir '$lockdir'" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $stat -ne 0; then
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
# Each line is of the form `foo.o: dependent.h',
|
||||||
|
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
|
||||||
|
# Do two passes, one to just change these to
|
||||||
|
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||||
|
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
|
||||||
|
# Some versions of the HPUX 10.20 sed can't process this invocation
|
||||||
|
# correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
|
||||||
|
| sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
hp2)
|
||||||
|
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
|
||||||
|
# compilers, which have integrated preprocessors. The correct option
|
||||||
|
# to use with these is +Maked; it writes dependencies to a file named
|
||||||
|
# 'foo.d', which lands next to the object file, wherever that
|
||||||
|
# happens to be.
|
||||||
|
# Much of this is similar to the tru64 case; see comments there.
|
||||||
|
set_dir_from "$object"
|
||||||
|
set_base_from "$object"
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
tmpdepfile1=$dir$base.d
|
||||||
|
tmpdepfile2=$dir.libs/$base.d
|
||||||
|
"$@" -Wc,+Maked
|
||||||
|
else
|
||||||
|
tmpdepfile1=$dir$base.d
|
||||||
|
tmpdepfile2=$dir$base.d
|
||||||
|
"$@" +Maked
|
||||||
|
fi
|
||||||
|
stat=$?
|
||||||
|
if test $stat -ne 0; then
|
||||||
|
rm -f "$tmpdepfile1" "$tmpdepfile2"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
|
||||||
|
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
|
||||||
|
do
|
||||||
|
test -f "$tmpdepfile" && break
|
||||||
|
done
|
||||||
|
if test -f "$tmpdepfile"; then
|
||||||
|
sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
|
||||||
|
# Add 'dependent.h:' lines.
|
||||||
|
sed -ne '2,${
|
||||||
|
s/^ *//
|
||||||
|
s/ \\*$//
|
||||||
|
s/$/:/
|
||||||
|
p
|
||||||
|
}' "$tmpdepfile" >> "$depfile"
|
||||||
|
else
|
||||||
|
make_dummy_depfile
|
||||||
|
fi
|
||||||
|
rm -f "$tmpdepfile" "$tmpdepfile2"
|
||||||
|
;;
|
||||||
|
|
||||||
|
tru64)
|
||||||
|
# The Tru64 compiler uses -MD to generate dependencies as a side
|
||||||
|
# effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
|
||||||
|
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
|
||||||
|
# dependencies in 'foo.d' instead, so we check for that too.
|
||||||
|
# Subdirectories are respected.
|
||||||
|
set_dir_from "$object"
|
||||||
|
set_base_from "$object"
|
||||||
|
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
# Libtool generates 2 separate objects for the 2 libraries. These
|
||||||
|
# two compilations output dependencies in $dir.libs/$base.o.d and
|
||||||
|
# in $dir$base.o.d. We have to check for both files, because
|
||||||
|
# one of the two compilations can be disabled. We should prefer
|
||||||
|
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is
|
||||||
|
# automatically cleaned when .libs/ is deleted, while ignoring
|
||||||
|
# the former would cause a distcleancheck panic.
|
||||||
|
tmpdepfile1=$dir$base.o.d # libtool 1.5
|
||||||
|
tmpdepfile2=$dir.libs/$base.o.d # Likewise.
|
||||||
|
tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504
|
||||||
|
"$@" -Wc,-MD
|
||||||
|
else
|
||||||
|
tmpdepfile1=$dir$base.d
|
||||||
|
tmpdepfile2=$dir$base.d
|
||||||
|
tmpdepfile3=$dir$base.d
|
||||||
|
"$@" -MD
|
||||||
|
fi
|
||||||
|
|
||||||
|
stat=$?
|
||||||
|
if test $stat -ne 0; then
|
||||||
|
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
|
||||||
|
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||||
|
do
|
||||||
|
test -f "$tmpdepfile" && break
|
||||||
|
done
|
||||||
|
# Same post-processing that is required for AIX mode.
|
||||||
|
aix_post_process_depfile
|
||||||
|
;;
|
||||||
|
|
||||||
|
msvc7)
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
showIncludes=-Wc,-showIncludes
|
||||||
|
else
|
||||||
|
showIncludes=-showIncludes
|
||||||
|
fi
|
||||||
|
"$@" $showIncludes > "$tmpdepfile"
|
||||||
|
stat=$?
|
||||||
|
grep -v '^Note: including file: ' "$tmpdepfile"
|
||||||
|
if test $stat -ne 0; then
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
exit $stat
|
||||||
|
fi
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
# The first sed program below extracts the file names and escapes
|
||||||
|
# backslashes for cygpath. The second sed program outputs the file
|
||||||
|
# name when reading, but also accumulates all include files in the
|
||||||
|
# hold buffer in order to output them again at the end. This only
|
||||||
|
# works with sed implementations that can handle large buffers.
|
||||||
|
sed < "$tmpdepfile" -n '
|
||||||
|
/^Note: including file: *\(.*\)/ {
|
||||||
|
s//\1/
|
||||||
|
s/\\/\\\\/g
|
||||||
|
p
|
||||||
|
}' | $cygpath_u | sort -u | sed -n '
|
||||||
|
s/ /\\ /g
|
||||||
|
s/\(.*\)/'"$tab"'\1 \\/p
|
||||||
|
s/.\(.*\) \\/\1:/
|
||||||
|
H
|
||||||
|
$ {
|
||||||
|
s/.*/'"$tab"'/
|
||||||
|
G
|
||||||
|
p
|
||||||
|
}' >> "$depfile"
|
||||||
|
echo >> "$depfile" # make sure the fragment doesn't end with a backslash
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
msvc7msys)
|
||||||
|
# This case exists only to let depend.m4 do its work. It works by
|
||||||
|
# looking at the text of this script. This case will never be run,
|
||||||
|
# since it is checked for above.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
#nosideeffect)
|
||||||
|
# This comment above is used by automake to tell side-effect
|
||||||
|
# dependency tracking mechanisms from slower ones.
|
||||||
|
|
||||||
|
dashmstdout)
|
||||||
|
# Important note: in order to support this mode, a compiler *must*
|
||||||
|
# always write the preprocessed file to stdout, regardless of -o.
|
||||||
|
"$@" || exit $?
|
||||||
|
|
||||||
|
# Remove the call to Libtool.
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test "X$1" != 'X--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove '-o $object'.
|
||||||
|
IFS=" "
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
-o)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
$object)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"
|
||||||
|
shift # fnord
|
||||||
|
shift # $arg
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
test -z "$dashmflag" && dashmflag=-M
|
||||||
|
# Require at least two characters before searching for ':'
|
||||||
|
# in the target name. This is to cope with DOS-style filenames:
|
||||||
|
# a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
|
||||||
|
"$@" $dashmflag |
|
||||||
|
sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
|
||||||
|
rm -f "$depfile"
|
||||||
|
cat < "$tmpdepfile" > "$depfile"
|
||||||
|
# Some versions of the HPUX 10.20 sed can't process this sed invocation
|
||||||
|
# correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
tr ' ' "$nl" < "$tmpdepfile" \
|
||||||
|
| sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
|
||||||
|
| sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
dashXmstdout)
|
||||||
|
# This case only exists to satisfy depend.m4. It is never actually
|
||||||
|
# run, as this mode is specially recognized in the preamble.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
makedepend)
|
||||||
|
"$@" || exit $?
|
||||||
|
# Remove any Libtool call
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test "X$1" != 'X--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
# X makedepend
|
||||||
|
shift
|
||||||
|
cleared=no eat=no
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $cleared in
|
||||||
|
no)
|
||||||
|
set ""; shift
|
||||||
|
cleared=yes ;;
|
||||||
|
esac
|
||||||
|
if test $eat = yes; then
|
||||||
|
eat=no
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
case "$arg" in
|
||||||
|
-D*|-I*)
|
||||||
|
set fnord "$@" "$arg"; shift ;;
|
||||||
|
# Strip any option that makedepend may not understand. Remove
|
||||||
|
# the object too, otherwise makedepend will parse it as a source file.
|
||||||
|
-arch)
|
||||||
|
eat=yes ;;
|
||||||
|
-*|$object)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"; shift ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
obj_suffix=`echo "$object" | sed 's/^.*\././'`
|
||||||
|
touch "$tmpdepfile"
|
||||||
|
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
|
||||||
|
rm -f "$depfile"
|
||||||
|
# makedepend may prepend the VPATH from the source file name to the object.
|
||||||
|
# No need to regex-escape $object, excess matching of '.' is harmless.
|
||||||
|
sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
|
||||||
|
# Some versions of the HPUX 10.20 sed can't process the last invocation
|
||||||
|
# correctly. Breaking it into two sed invocations is a workaround.
|
||||||
|
sed '1,2d' "$tmpdepfile" \
|
||||||
|
| tr ' ' "$nl" \
|
||||||
|
| sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
|
||||||
|
| sed -e 's/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile" "$tmpdepfile".bak
|
||||||
|
;;
|
||||||
|
|
||||||
|
cpp)
|
||||||
|
# Important note: in order to support this mode, a compiler *must*
|
||||||
|
# always write the preprocessed file to stdout.
|
||||||
|
"$@" || exit $?
|
||||||
|
|
||||||
|
# Remove the call to Libtool.
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test "X$1" != 'X--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove '-o $object'.
|
||||||
|
IFS=" "
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
-o)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
$object)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"
|
||||||
|
shift # fnord
|
||||||
|
shift # $arg
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
"$@" -E \
|
||||||
|
| sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
|
||||||
|
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
|
||||||
|
| sed '$ s: \\$::' > "$tmpdepfile"
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
cat < "$tmpdepfile" >> "$depfile"
|
||||||
|
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
msvisualcpp)
|
||||||
|
# Important note: in order to support this mode, a compiler *must*
|
||||||
|
# always write the preprocessed file to stdout.
|
||||||
|
"$@" || exit $?
|
||||||
|
|
||||||
|
# Remove the call to Libtool.
|
||||||
|
if test "$libtool" = yes; then
|
||||||
|
while test "X$1" != 'X--mode=compile'; do
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
IFS=" "
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
case "$arg" in
|
||||||
|
-o)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
$object)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
|
||||||
|
set fnord "$@"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
set fnord "$@" "$arg"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
"$@" -E 2>/dev/null |
|
||||||
|
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
|
||||||
|
rm -f "$depfile"
|
||||||
|
echo "$object : \\" > "$depfile"
|
||||||
|
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
|
||||||
|
echo "$tab" >> "$depfile"
|
||||||
|
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
|
||||||
|
rm -f "$tmpdepfile"
|
||||||
|
;;
|
||||||
|
|
||||||
|
msvcmsys)
|
||||||
|
# This case exists only to let depend.m4 do its work. It works by
|
||||||
|
# looking at the text of this script. This case will never be run,
|
||||||
|
# since it is checked for above.
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
|
||||||
|
none)
|
||||||
|
exec "$@"
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "Unknown depmode $depmode" 1>&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# mode: shell-script
|
||||||
|
# sh-indentation: 2
|
||||||
|
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-time-zone: "UTC0"
|
||||||
|
# time-stamp-end: "; # UTC"
|
||||||
|
# End:
|
||||||
Vendored
+264
@@ -0,0 +1,264 @@
|
|||||||
|
.TH DJPEG 1 "28 April 2019"
|
||||||
|
.SH NAME
|
||||||
|
djpeg \- decompress a JPEG file to an image file
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B djpeg
|
||||||
|
[
|
||||||
|
.I options
|
||||||
|
]
|
||||||
|
[
|
||||||
|
.I filename
|
||||||
|
]
|
||||||
|
.LP
|
||||||
|
.SH DESCRIPTION
|
||||||
|
.LP
|
||||||
|
.B djpeg
|
||||||
|
decompresses the named JPEG file, or the standard input if no file is named,
|
||||||
|
and produces an image file on the standard output. PBMPLUS (PPM/PGM), BMP,
|
||||||
|
GIF, Targa, or RLE (Utah Raster Toolkit) output format can be selected.
|
||||||
|
(RLE is supported only if the URT library is available, which it isn't
|
||||||
|
on most non-Unix systems.)
|
||||||
|
.SH OPTIONS
|
||||||
|
All switch names may be abbreviated; for example,
|
||||||
|
.B \-grayscale
|
||||||
|
may be written
|
||||||
|
.B \-gray
|
||||||
|
or
|
||||||
|
.BR \-gr .
|
||||||
|
Most of the "basic" switches can be abbreviated to as little as one letter.
|
||||||
|
Upper and lower case are equivalent (thus
|
||||||
|
.B \-BMP
|
||||||
|
is the same as
|
||||||
|
.BR \-bmp ).
|
||||||
|
British spellings are also accepted (e.g.,
|
||||||
|
.BR \-greyscale ),
|
||||||
|
though for brevity these are not mentioned below.
|
||||||
|
.PP
|
||||||
|
The basic switches are:
|
||||||
|
.TP
|
||||||
|
.BI \-colors " N"
|
||||||
|
Reduce image to at most N colors. This reduces the number of colors used in
|
||||||
|
the output image, so that it can be displayed on a colormapped display or
|
||||||
|
stored in a colormapped file format. For example, if you have an 8-bit
|
||||||
|
display, you'd need to reduce to 256 or fewer colors.
|
||||||
|
.TP
|
||||||
|
.BI \-quantize " N"
|
||||||
|
Same as
|
||||||
|
.BR \-colors .
|
||||||
|
.B \-colors
|
||||||
|
is the recommended name,
|
||||||
|
.B \-quantize
|
||||||
|
is provided only for backwards compatibility.
|
||||||
|
.TP
|
||||||
|
.B \-fast
|
||||||
|
Select recommended processing options for fast, low quality output. (The
|
||||||
|
default options are chosen for highest quality output.) Currently, this is
|
||||||
|
equivalent to \fB\-dct fast \-nosmooth \-onepass \-dither ordered\fR.
|
||||||
|
.TP
|
||||||
|
.B \-grayscale
|
||||||
|
Force grayscale output even if JPEG file is color.
|
||||||
|
Useful for viewing on monochrome displays; also,
|
||||||
|
.B djpeg
|
||||||
|
runs noticeably faster in this mode.
|
||||||
|
.TP
|
||||||
|
.B \-rgb
|
||||||
|
Force RGB output even if JPEG file is grayscale.
|
||||||
|
This is provided to support applications that don't
|
||||||
|
want to cope with grayscale as a separate case.
|
||||||
|
.TP
|
||||||
|
.BI \-scale " M/N"
|
||||||
|
Scale the output image by a factor M/N. Currently supported scale factors are
|
||||||
|
M/N with all M from 1 to 16, where N is the source DCT size, which is 8 for
|
||||||
|
baseline JPEG. If the /N part is omitted, then M specifies the DCT scaled
|
||||||
|
size to be applied on the given input. For baseline JPEG this is equivalent
|
||||||
|
to M/8 scaling, since the source DCT size for baseline JPEG is 8.
|
||||||
|
Scaling is handy if the image is larger than your screen; also,
|
||||||
|
.B djpeg
|
||||||
|
runs much faster when scaling down the output.
|
||||||
|
.TP
|
||||||
|
.B \-bmp
|
||||||
|
Select BMP output format (Windows flavor).
|
||||||
|
8-bit colormapped format is emitted if
|
||||||
|
.B \-colors
|
||||||
|
or
|
||||||
|
.B \-grayscale
|
||||||
|
is specified, or if the JPEG file is grayscale; otherwise, 24-bit full-color
|
||||||
|
format is emitted.
|
||||||
|
.TP
|
||||||
|
.B \-gif
|
||||||
|
Select GIF output format (LZW compressed).
|
||||||
|
Since GIF does not support more than 256 colors,
|
||||||
|
.B \-colors 256
|
||||||
|
is assumed (unless you specify a smaller number of colors). If you specify
|
||||||
|
.BR \-fast ,
|
||||||
|
the default number of colors is 216.
|
||||||
|
.TP
|
||||||
|
.B \-gif0
|
||||||
|
Select GIF output format (uncompressed).
|
||||||
|
Since GIF does not support more than 256 colors,
|
||||||
|
.B \-colors 256
|
||||||
|
is assumed (unless you specify a smaller number of colors). If you specify
|
||||||
|
.BR \-fast ,
|
||||||
|
the default number of colors is 216.
|
||||||
|
.TP
|
||||||
|
.B \-os2
|
||||||
|
Select BMP output format (OS/2 1.x flavor).
|
||||||
|
8-bit colormapped format is emitted if
|
||||||
|
.B \-colors
|
||||||
|
or
|
||||||
|
.B \-grayscale
|
||||||
|
is specified, or if the JPEG file is grayscale; otherwise, 24-bit full-color
|
||||||
|
format is emitted.
|
||||||
|
.TP
|
||||||
|
.B \-pnm
|
||||||
|
Select PBMPLUS (PPM/PGM) output format (this is the default format).
|
||||||
|
PGM is emitted if the JPEG file is grayscale or if
|
||||||
|
.B \-grayscale
|
||||||
|
is specified; otherwise PPM is emitted.
|
||||||
|
.TP
|
||||||
|
.B \-rle
|
||||||
|
Select RLE output format. (Requires URT library.)
|
||||||
|
.TP
|
||||||
|
.B \-targa
|
||||||
|
Select Targa output format. Grayscale format is emitted if the JPEG file is
|
||||||
|
grayscale or if
|
||||||
|
.B \-grayscale
|
||||||
|
is specified; otherwise, colormapped format is emitted if
|
||||||
|
.B \-colors
|
||||||
|
is specified; otherwise, 24-bit full-color format is emitted.
|
||||||
|
.PP
|
||||||
|
Switches for advanced users:
|
||||||
|
.TP
|
||||||
|
.B \-dct int
|
||||||
|
Use integer DCT method (default).
|
||||||
|
.TP
|
||||||
|
.B \-dct fast
|
||||||
|
Use fast integer DCT (less accurate).
|
||||||
|
.TP
|
||||||
|
.B \-dct float
|
||||||
|
Use floating-point DCT method.
|
||||||
|
The float method is very slightly more accurate than the int method, but is
|
||||||
|
much slower unless your machine has very fast floating-point hardware. Also
|
||||||
|
note that results of the floating-point method may vary slightly across
|
||||||
|
machines, while the integer methods should give the same results everywhere.
|
||||||
|
The fast integer method is much less accurate than the other two.
|
||||||
|
.TP
|
||||||
|
.B \-dither fs
|
||||||
|
Use Floyd-Steinberg dithering in color quantization.
|
||||||
|
.TP
|
||||||
|
.B \-dither ordered
|
||||||
|
Use ordered dithering in color quantization.
|
||||||
|
.TP
|
||||||
|
.B \-dither none
|
||||||
|
Do not use dithering in color quantization.
|
||||||
|
By default, Floyd-Steinberg dithering is applied when quantizing colors; this
|
||||||
|
is slow but usually produces the best results. Ordered dither is a compromise
|
||||||
|
between speed and quality; no dithering is fast but usually looks awful. Note
|
||||||
|
that these switches have no effect unless color quantization is being done.
|
||||||
|
Ordered dither is only available in
|
||||||
|
.B \-onepass
|
||||||
|
mode.
|
||||||
|
.TP
|
||||||
|
.BI \-map " file"
|
||||||
|
Quantize to the colors used in the specified image file. This is useful for
|
||||||
|
producing multiple files with identical color maps, or for forcing a
|
||||||
|
predefined set of colors to be used. The
|
||||||
|
.I file
|
||||||
|
must be a GIF or PPM file. This option overrides
|
||||||
|
.B \-colors
|
||||||
|
and
|
||||||
|
.BR \-onepass .
|
||||||
|
.TP
|
||||||
|
.B \-nosmooth
|
||||||
|
Don't use high-quality upsampling.
|
||||||
|
.TP
|
||||||
|
.B \-onepass
|
||||||
|
Use one-pass instead of two-pass color quantization. The one-pass method is
|
||||||
|
faster and needs less memory, but it produces a lower-quality image.
|
||||||
|
.B \-onepass
|
||||||
|
is ignored unless you also say
|
||||||
|
.B \-colors
|
||||||
|
.IR N .
|
||||||
|
Also, the one-pass method is always used for grayscale output (the two-pass
|
||||||
|
method is no improvement then).
|
||||||
|
.TP
|
||||||
|
.BI \-maxmemory " N"
|
||||||
|
Set limit for amount of memory to use in processing large images. Value is
|
||||||
|
in thousands of bytes, or millions of bytes if "M" is attached to the
|
||||||
|
number. For example,
|
||||||
|
.B \-max 4m
|
||||||
|
selects 4000000 bytes. If more space is needed, temporary files will be used.
|
||||||
|
.TP
|
||||||
|
.BI \-outfile " name"
|
||||||
|
Send output image to the named file, not to standard output.
|
||||||
|
.TP
|
||||||
|
.B \-verbose
|
||||||
|
Enable debug printout. More
|
||||||
|
.BR \-v 's
|
||||||
|
give more output. Also, version information is printed at startup.
|
||||||
|
.TP
|
||||||
|
.B \-debug
|
||||||
|
Same as
|
||||||
|
.BR \-verbose .
|
||||||
|
.SH EXAMPLES
|
||||||
|
.LP
|
||||||
|
This example decompresses the JPEG file foo.jpg, quantizes it to
|
||||||
|
256 colors, and saves the output in 8-bit BMP format in foo.bmp:
|
||||||
|
.IP
|
||||||
|
.B djpeg \-colors 256 \-bmp
|
||||||
|
.I foo.jpg
|
||||||
|
.B >
|
||||||
|
.I foo.bmp
|
||||||
|
.SH HINTS
|
||||||
|
To get a quick preview of an image, use the
|
||||||
|
.B \-grayscale
|
||||||
|
and/or
|
||||||
|
.B \-scale
|
||||||
|
switches.
|
||||||
|
.B \-grayscale \-scale 1/8
|
||||||
|
is the fastest case.
|
||||||
|
.PP
|
||||||
|
Several options are available that trade off image quality to gain speed.
|
||||||
|
.B \-fast
|
||||||
|
turns on the recommended settings.
|
||||||
|
.PP
|
||||||
|
.B \-dct fast
|
||||||
|
and/or
|
||||||
|
.B \-nosmooth
|
||||||
|
gain speed at a small sacrifice in quality.
|
||||||
|
When producing a color-quantized image,
|
||||||
|
.B \-onepass \-dither ordered
|
||||||
|
is fast but much lower quality than the default behavior.
|
||||||
|
.B \-dither none
|
||||||
|
may give acceptable results in two-pass mode, but is seldom tolerable in
|
||||||
|
one-pass mode.
|
||||||
|
.PP
|
||||||
|
If you are fortunate enough to have very fast floating point hardware,
|
||||||
|
\fB\-dct float\fR may be even faster than \fB\-dct fast\fR. But on most
|
||||||
|
machines \fB\-dct float\fR is slower than \fB\-dct int\fR; in this case it is
|
||||||
|
not worth using, because its theoretical accuracy advantage is too small to be
|
||||||
|
significant in practice.
|
||||||
|
.SH ENVIRONMENT
|
||||||
|
.TP
|
||||||
|
.B JPEGMEM
|
||||||
|
If this environment variable is set, its value is the default memory limit.
|
||||||
|
The value is specified as described for the
|
||||||
|
.B \-maxmemory
|
||||||
|
switch.
|
||||||
|
.B JPEGMEM
|
||||||
|
overrides the default value specified when the program was compiled, and
|
||||||
|
itself is overridden by an explicit
|
||||||
|
.BR \-maxmemory .
|
||||||
|
.SH SEE ALSO
|
||||||
|
.BR cjpeg (1),
|
||||||
|
.BR jpegtran (1),
|
||||||
|
.BR rdjpgcom (1),
|
||||||
|
.BR wrjpgcom (1)
|
||||||
|
.br
|
||||||
|
.BR ppm (5),
|
||||||
|
.BR pgm (5)
|
||||||
|
.br
|
||||||
|
Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
|
||||||
|
Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
|
||||||
|
.SH AUTHOR
|
||||||
|
Independent JPEG Group
|
||||||
Vendored
+24
-10
@@ -2,7 +2,7 @@
|
|||||||
* djpeg.c
|
* djpeg.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
* Modified 2009 by Guido Vollbeding.
|
* Modified 2009-2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -59,7 +59,8 @@ static const char * const cdjpeg_message_table[] = {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FMT_BMP, /* BMP format (Windows flavor) */
|
FMT_BMP, /* BMP format (Windows flavor) */
|
||||||
FMT_GIF, /* GIF format */
|
FMT_GIF, /* GIF format (LZW compressed) */
|
||||||
|
FMT_GIF0, /* GIF format (uncompressed) */
|
||||||
FMT_OS2, /* BMP format (OS/2 flavor) */
|
FMT_OS2, /* BMP format (OS/2 flavor) */
|
||||||
FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
|
FMT_PPM, /* PPM/PGM (PBMPLUS formats) */
|
||||||
FMT_RLE, /* RLE format */
|
FMT_RLE, /* RLE format */
|
||||||
@@ -102,6 +103,7 @@ usage (void)
|
|||||||
fprintf(stderr, " -colors N Reduce image to no more than N colors\n");
|
fprintf(stderr, " -colors N Reduce image to no more than N colors\n");
|
||||||
fprintf(stderr, " -fast Fast, low-quality processing\n");
|
fprintf(stderr, " -fast Fast, low-quality processing\n");
|
||||||
fprintf(stderr, " -grayscale Force grayscale output\n");
|
fprintf(stderr, " -grayscale Force grayscale output\n");
|
||||||
|
fprintf(stderr, " -rgb Force RGB output\n");
|
||||||
#ifdef IDCT_SCALING_SUPPORTED
|
#ifdef IDCT_SCALING_SUPPORTED
|
||||||
fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n");
|
fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n");
|
||||||
#endif
|
#endif
|
||||||
@@ -110,8 +112,10 @@ usage (void)
|
|||||||
(DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
|
(DEFAULT_FMT == FMT_BMP ? " (default)" : ""));
|
||||||
#endif
|
#endif
|
||||||
#ifdef GIF_SUPPORTED
|
#ifdef GIF_SUPPORTED
|
||||||
fprintf(stderr, " -gif Select GIF output format%s\n",
|
fprintf(stderr, " -gif Select GIF output format (LZW compressed)%s\n",
|
||||||
(DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
|
(DEFAULT_FMT == FMT_GIF ? " (default)" : ""));
|
||||||
|
fprintf(stderr, " -gif0 Select GIF output format (uncompressed)%s\n",
|
||||||
|
(DEFAULT_FMT == FMT_GIF0 ? " (default)" : ""));
|
||||||
#endif
|
#endif
|
||||||
#ifdef BMP_SUPPORTED
|
#ifdef BMP_SUPPORTED
|
||||||
fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
|
fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n",
|
||||||
@@ -194,7 +198,7 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
|
|||||||
arg++; /* advance past switch marker character */
|
arg++; /* advance past switch marker character */
|
||||||
|
|
||||||
if (keymatch(arg, "bmp", 1)) {
|
if (keymatch(arg, "bmp", 1)) {
|
||||||
/* BMP output format. */
|
/* BMP output format (Windows flavor). */
|
||||||
requested_fmt = FMT_BMP;
|
requested_fmt = FMT_BMP;
|
||||||
|
|
||||||
} else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
|
} else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) ||
|
||||||
@@ -257,13 +261,21 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
|
|||||||
cinfo->do_fancy_upsampling = FALSE;
|
cinfo->do_fancy_upsampling = FALSE;
|
||||||
|
|
||||||
} else if (keymatch(arg, "gif", 1)) {
|
} else if (keymatch(arg, "gif", 1)) {
|
||||||
/* GIF output format. */
|
/* GIF output format (LZW compressed). */
|
||||||
requested_fmt = FMT_GIF;
|
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)) {
|
} else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) {
|
||||||
/* Force monochrome output. */
|
/* Force monochrome output. */
|
||||||
cinfo->out_color_space = JCS_GRAYSCALE;
|
cinfo->out_color_space = JCS_GRAYSCALE;
|
||||||
|
|
||||||
|
} else if (keymatch(arg, "rgb", 3)) {
|
||||||
|
/* Force RGB output. */
|
||||||
|
cinfo->out_color_space = JCS_RGB;
|
||||||
|
|
||||||
} else if (keymatch(arg, "map", 3)) {
|
} else if (keymatch(arg, "map", 3)) {
|
||||||
/* Quantize to a color map taken from an input file. */
|
/* Quantize to a color map taken from an input file. */
|
||||||
if (++argn >= argc) /* advance to next argument */
|
if (++argn >= argc) /* advance to next argument */
|
||||||
@@ -298,7 +310,7 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
|
|||||||
cinfo->mem->max_memory_to_use = lval * 1000L;
|
cinfo->mem->max_memory_to_use = lval * 1000L;
|
||||||
|
|
||||||
} else if (keymatch(arg, "nosmooth", 3)) {
|
} else if (keymatch(arg, "nosmooth", 3)) {
|
||||||
/* Suppress fancy upsampling */
|
/* Suppress fancy upsampling. */
|
||||||
cinfo->do_fancy_upsampling = FALSE;
|
cinfo->do_fancy_upsampling = FALSE;
|
||||||
|
|
||||||
} else if (keymatch(arg, "onepass", 3)) {
|
} else if (keymatch(arg, "onepass", 3)) {
|
||||||
@@ -327,7 +339,7 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
|
|||||||
/* Scale the output image by a fraction M/N. */
|
/* Scale the output image by a fraction M/N. */
|
||||||
if (++argn >= argc) /* advance to next argument */
|
if (++argn >= argc) /* advance to next argument */
|
||||||
usage();
|
usage();
|
||||||
if (sscanf(argv[argn], "%d/%d",
|
if (sscanf(argv[argn], "%u/%u",
|
||||||
&cinfo->scale_num, &cinfo->scale_denom) < 1)
|
&cinfo->scale_num, &cinfo->scale_denom) < 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
@@ -456,7 +468,7 @@ main (int argc, char **argv)
|
|||||||
* APP12 is used by some digital camera makers for textual info,
|
* APP12 is used by some digital camera makers for textual info,
|
||||||
* so we provide the ability to display it as text.
|
* so we provide the ability to display it as text.
|
||||||
* If you like, additional APPn marker types can be selected for display,
|
* 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.doc).
|
* 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_COM, print_text_marker);
|
||||||
jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
|
jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
|
||||||
@@ -549,7 +561,10 @@ main (int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef GIF_SUPPORTED
|
#ifdef GIF_SUPPORTED
|
||||||
case FMT_GIF:
|
case FMT_GIF:
|
||||||
dest_mgr = jinit_write_gif(&cinfo);
|
dest_mgr = jinit_write_gif(&cinfo, TRUE);
|
||||||
|
break;
|
||||||
|
case FMT_GIF0:
|
||||||
|
dest_mgr = jinit_write_gif(&cinfo, FALSE);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef PPM_SUPPORTED
|
#ifdef PPM_SUPPORTED
|
||||||
@@ -569,7 +584,6 @@ main (int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
|
ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
dest_mgr->output_file = output_file;
|
dest_mgr->output_file = output_file;
|
||||||
|
|
||||||
|
|||||||
Vendored
+766
@@ -0,0 +1,766 @@
|
|||||||
|
/*
|
||||||
|
* alternate djpeg.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
|
* Modified 2009-2020 by Guido Vollbeding.
|
||||||
|
* This file is part of the Independent JPEG Group's software.
|
||||||
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
|
*
|
||||||
|
* This file contains an alternate user interface for the JPEG decompressor.
|
||||||
|
* One or more input files are named on the command line, and output file
|
||||||
|
* names are created by substituting an appropriate extension.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
||||||
|
#include "jversion.h" /* for version message */
|
||||||
|
|
||||||
|
#include <ctype.h> /* to declare isprint() */
|
||||||
|
|
||||||
|
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
|
||||||
|
#ifdef __MWERKS__
|
||||||
|
#include <SIOUX.h> /* Metrowerks needs this */
|
||||||
|
#include <console.h> /* ... and this */
|
||||||
|
#endif
|
||||||
|
#ifdef THINK_C
|
||||||
|
#include <console.h> /* Think declares it here */
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PATH_MAX /* ANSI maximum-pathname-length constant */
|
||||||
|
#define PATH_MAX 256
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Create the add-on message string table. */
|
||||||
|
|
||||||
|
#define JMESSAGE(code,string) string ,
|
||||||
|
|
||||||
|
static const char * const cdjpeg_message_table[] = {
|
||||||
|
#include "cderror.h"
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Automatic determination of available memory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static long default_maxmem; /* saves value determined at startup, or 0 */
|
||||||
|
|
||||||
|
#ifndef FREE_MEM_ESTIMATE /* may be defined from command line */
|
||||||
|
|
||||||
|
#ifdef MSDOS /* For MS-DOS (unless flat-memory model) */
|
||||||
|
|
||||||
|
#include <dos.h> /* for access to intdos() call */
|
||||||
|
|
||||||
|
LOCAL(long)
|
||||||
|
unused_dos_memory (void)
|
||||||
|
/* Obtain total amount of unallocated DOS memory */
|
||||||
|
{
|
||||||
|
union REGS regs;
|
||||||
|
long nparas;
|
||||||
|
|
||||||
|
regs.h.ah = 0x48; /* DOS function Allocate Memory Block */
|
||||||
|
regs.x.bx = 0xFFFF; /* Ask for more memory than DOS can have */
|
||||||
|
(void) intdos(®s, ®s);
|
||||||
|
/* DOS will fail and return # of paragraphs actually available in BX. */
|
||||||
|
nparas = (unsigned int) regs.x.bx;
|
||||||
|
/* Times 16 to convert to bytes. */
|
||||||
|
return nparas << 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The default memory setting is 95% of the available space. */
|
||||||
|
#define FREE_MEM_ESTIMATE ((unused_dos_memory() * 95L) / 100L)
|
||||||
|
|
||||||
|
#endif /* MSDOS */
|
||||||
|
|
||||||
|
#ifdef ATARI /* For Atari ST/STE/TT, Pure C or Turbo C */
|
||||||
|
|
||||||
|
#include <ext.h>
|
||||||
|
|
||||||
|
/* The default memory setting is 90% of the available space. */
|
||||||
|
#define FREE_MEM_ESTIMATE (((long) coreleft() * 90L) / 100L)
|
||||||
|
|
||||||
|
#endif /* ATARI */
|
||||||
|
|
||||||
|
/* Add memory-estimation procedures for other operating systems here,
|
||||||
|
* with appropriate #ifdef's around them.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* !FREE_MEM_ESTIMATE */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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_RLE, /* RLE format */
|
||||||
|
FMT_TARGA, /* Targa format */
|
||||||
|
FMT_TIFF /* TIFF format */
|
||||||
|
} IMAGE_FORMATS;
|
||||||
|
|
||||||
|
#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */
|
||||||
|
#define DEFAULT_FMT FMT_BMP
|
||||||
|
#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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
static const char * progname; /* program name for error messages */
|
||||||
|
static char * outfilename; /* for -outfile switch */
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL(void)
|
||||||
|
usage (void)
|
||||||
|
/* complain about bad command line */
|
||||||
|
{
|
||||||
|
fprintf(stderr, "usage: %s [switches] inputfile(s)\n", progname);
|
||||||
|
fprintf(stderr, "List of input files may use wildcards (* and ?)\n");
|
||||||
|
fprintf(stderr, "Output filename is same as input filename except for extension\n");
|
||||||
|
|
||||||
|
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");
|
||||||
|
#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 RLE_SUPPORTED
|
||||||
|
fprintf(stderr, " -rle Select Utah RLE output format%s\n",
|
||||||
|
(DEFAULT_FMT == FMT_RLE ? " (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 integer DCT method%s\n",
|
||||||
|
(JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : ""));
|
||||||
|
#endif
|
||||||
|
#ifdef DCT_IFAST_SUPPORTED
|
||||||
|
fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n",
|
||||||
|
(JDCT_DEFAULT == JDCT_IFAST ? " (default)" : ""));
|
||||||
|
#endif
|
||||||
|
#ifdef DCT_FLOAT_SUPPORTED
|
||||||
|
fprintf(stderr, " -dct float Use floating-point DCT method%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");
|
||||||
|
#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
|
||||||
|
#ifndef FREE_MEM_ESTIMATE
|
||||||
|
fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
|
||||||
|
#endif
|
||||||
|
fprintf(stderr, " -outfile name Specify name for output file\n");
|
||||||
|
fprintf(stderr, " -verbose or -debug Emit debug output\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 */
|
||||||
|
outfilename = NULL;
|
||||||
|
cinfo->err->trace_level = 0;
|
||||||
|
if (default_maxmem > 0) /* override library's default value */
|
||||||
|
cinfo->mem->max_memory_to_use = default_maxmem;
|
||||||
|
|
||||||
|
/* 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, "Independent JPEG Group's DJPEG, version %s\n%s\n",
|
||||||
|
JVERSION, JCOPYRIGHT);
|
||||||
|
printed_version = TRUE;
|
||||||
|
}
|
||||||
|
cinfo->err->trace_level++;
|
||||||
|
|
||||||
|
} 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", 3)) {
|
||||||
|
/* Force RGB output. */
|
||||||
|
cinfo->out_color_space = JCS_RGB;
|
||||||
|
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
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, "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, "pnm", 1) || keymatch(arg, "ppm", 1)) {
|
||||||
|
/* PPM/PGM output format. */
|
||||||
|
requested_fmt = FMT_PPM;
|
||||||
|
|
||||||
|
} else if (keymatch(arg, "rle", 1)) {
|
||||||
|
/* RLE output format. */
|
||||||
|
requested_fmt = FMT_RLE;
|
||||||
|
|
||||||
|
} else if (keymatch(arg, "scale", 1)) {
|
||||||
|
/* 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) < 1)
|
||||||
|
usage();
|
||||||
|
|
||||||
|
} 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 GETJOCTET(*datasrc->next_input_byte++);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
METHODDEF(boolean)
|
||||||
|
print_text_marker (j_decompress_ptr cinfo)
|
||||||
|
{
|
||||||
|
boolean traceit = (cinfo->err->trace_level >= 1);
|
||||||
|
INT32 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for overwrite of an existing file; clear it with user
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NO_OVERWRITE_CHECK
|
||||||
|
|
||||||
|
LOCAL(boolean)
|
||||||
|
is_write_ok (char * outfname)
|
||||||
|
{
|
||||||
|
FILE * ofile;
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
ofile = fopen(outfname, READ_BINARY);
|
||||||
|
if (ofile == NULL)
|
||||||
|
return TRUE; /* not present */
|
||||||
|
fclose(ofile); /* oops, it is present */
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
fprintf(stderr, "%s already exists, overwrite it? [y/n] ",
|
||||||
|
outfname);
|
||||||
|
fflush(stderr);
|
||||||
|
ch = getc(stdin);
|
||||||
|
if (ch != '\n') /* flush rest of line */
|
||||||
|
while (getc(stdin) != '\n')
|
||||||
|
/* nothing */;
|
||||||
|
|
||||||
|
switch (ch) {
|
||||||
|
case 'Y':
|
||||||
|
case 'y':
|
||||||
|
return TRUE;
|
||||||
|
case 'N':
|
||||||
|
case 'n':
|
||||||
|
return FALSE;
|
||||||
|
/* otherwise, ask again */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Process a single input file name, and return its index in argv[].
|
||||||
|
* File names at or to left of old_file_index have been processed already.
|
||||||
|
*/
|
||||||
|
|
||||||
|
LOCAL(int)
|
||||||
|
process_one_file (int argc, char **argv, int old_file_index)
|
||||||
|
{
|
||||||
|
struct jpeg_decompress_struct cinfo;
|
||||||
|
struct jpeg_error_mgr jerr;
|
||||||
|
char *infilename;
|
||||||
|
char workfilename[PATH_MAX];
|
||||||
|
const char *default_extension = NULL;
|
||||||
|
#ifdef PROGRESS_REPORT
|
||||||
|
struct cdjpeg_progress_mgr progress;
|
||||||
|
#endif
|
||||||
|
int file_index;
|
||||||
|
djpeg_dest_ptr dest_mgr = NULL;
|
||||||
|
FILE * input_file = NULL;
|
||||||
|
FILE * output_file = NULL;
|
||||||
|
JDIMENSION num_scanlines;
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
|
/* Now safe to enable signal catcher. */
|
||||||
|
#ifdef NEED_SIGNAL_CATCHER
|
||||||
|
enable_signal_catcher((j_common_ptr) &cinfo);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Scan command line to find next file name.
|
||||||
|
* 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, old_file_index, FALSE);
|
||||||
|
if (file_index >= argc) {
|
||||||
|
fprintf(stderr, "%s: missing input file name\n", progname);
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open the input file. */
|
||||||
|
infilename = argv[file_index];
|
||||||
|
if ((input_file = fopen(infilename, READ_BINARY)) == NULL) {
|
||||||
|
fprintf(stderr, "%s: can't open %s\n", progname, infilename);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PROGRESS_REPORT
|
||||||
|
start_progress_monitor((j_common_ptr) &cinfo, &progress);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Specify data source for decompression */
|
||||||
|
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, old_file_index, 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);
|
||||||
|
default_extension = ".bmp";
|
||||||
|
break;
|
||||||
|
case FMT_OS2:
|
||||||
|
dest_mgr = jinit_write_bmp(&cinfo, TRUE);
|
||||||
|
default_extension = ".bmp";
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef GIF_SUPPORTED
|
||||||
|
case FMT_GIF:
|
||||||
|
dest_mgr = jinit_write_gif(&cinfo, TRUE);
|
||||||
|
default_extension = ".gif";
|
||||||
|
break;
|
||||||
|
case FMT_GIF0:
|
||||||
|
dest_mgr = jinit_write_gif(&cinfo, FALSE);
|
||||||
|
default_extension = ".gif";
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef PPM_SUPPORTED
|
||||||
|
case FMT_PPM:
|
||||||
|
dest_mgr = jinit_write_ppm(&cinfo);
|
||||||
|
default_extension = ".ppm";
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef RLE_SUPPORTED
|
||||||
|
case FMT_RLE:
|
||||||
|
dest_mgr = jinit_write_rle(&cinfo);
|
||||||
|
default_extension = ".rle";
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef TARGA_SUPPORTED
|
||||||
|
case FMT_TARGA:
|
||||||
|
dest_mgr = jinit_write_targa(&cinfo);
|
||||||
|
default_extension = ".tga";
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If user didn't supply -outfile switch, select output file name. */
|
||||||
|
if (outfilename == NULL) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
outfilename = workfilename;
|
||||||
|
/* Make outfilename be infilename with appropriate extension */
|
||||||
|
strcpy(outfilename, infilename);
|
||||||
|
for (i = (int)strlen(outfilename)-1; i >= 0; i--) {
|
||||||
|
switch (outfilename[i]) {
|
||||||
|
case ':':
|
||||||
|
case '/':
|
||||||
|
case '\\':
|
||||||
|
i = 0; /* stop scanning */
|
||||||
|
break;
|
||||||
|
case '.':
|
||||||
|
outfilename[i] = '\0'; /* lop off existing extension */
|
||||||
|
i = 0; /* stop scanning */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break; /* keep scanning */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strcat(outfilename, default_extension);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "Decompressing %s => %s\n", infilename, outfilename);
|
||||||
|
#ifndef NO_OVERWRITE_CHECK
|
||||||
|
if (! is_write_ok(outfilename))
|
||||||
|
goto fail;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Open the output file. */
|
||||||
|
if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {
|
||||||
|
fprintf(stderr, "%s: can't create %s\n", progname, outfilename);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
dest_mgr->output_file = output_file;
|
||||||
|
|
||||||
|
/* Start decompressor */
|
||||||
|
(void) jpeg_start_decompress(&cinfo);
|
||||||
|
|
||||||
|
/* Write output file header */
|
||||||
|
(*dest_mgr->start_output) (&cinfo, dest_mgr);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PROGRESS_REPORT
|
||||||
|
/* Hack: count final pass as done in case finish_output does an extra pass.
|
||||||
|
* The library won't have updated completed_passes.
|
||||||
|
*/
|
||||||
|
progress.pub.completed_passes = progress.pub.total_passes;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
|
/* Clean up and exit */
|
||||||
|
fail:
|
||||||
|
jpeg_destroy_decompress(&cinfo);
|
||||||
|
|
||||||
|
if (input_file != NULL) fclose(input_file);
|
||||||
|
if (output_file != NULL) fclose(output_file);
|
||||||
|
|
||||||
|
#ifdef PROGRESS_REPORT
|
||||||
|
end_progress_monitor((j_common_ptr) &cinfo);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Disable signal catcher. */
|
||||||
|
#ifdef NEED_SIGNAL_CATCHER
|
||||||
|
enable_signal_catcher((j_common_ptr) NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return file_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The main program.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int file_index;
|
||||||
|
|
||||||
|
/* On Mac, fetch a command line. */
|
||||||
|
#ifdef USE_CCOMMAND
|
||||||
|
argc = ccommand(&argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MSDOS
|
||||||
|
progname = "djpeg"; /* DOS tends to be too verbose about argv[0] */
|
||||||
|
#else
|
||||||
|
progname = argv[0];
|
||||||
|
if (progname == NULL || progname[0] == 0)
|
||||||
|
progname = "djpeg"; /* in case C library doesn't provide it */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The default maxmem must be computed only once at program startup,
|
||||||
|
* since releasing memory with free() won't give it back to the OS.
|
||||||
|
*/
|
||||||
|
#ifdef FREE_MEM_ESTIMATE
|
||||||
|
default_maxmem = FREE_MEM_ESTIMATE;
|
||||||
|
#else
|
||||||
|
default_maxmem = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Scan command line, parse switches and locate input file names */
|
||||||
|
|
||||||
|
if (argc < 2)
|
||||||
|
usage(); /* nothing on the command line?? */
|
||||||
|
|
||||||
|
file_index = 0;
|
||||||
|
|
||||||
|
while (file_index < argc-1)
|
||||||
|
file_index = process_one_file(argc, argv, file_index);
|
||||||
|
|
||||||
|
/* All done. */
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
return 0; /* suppress no-return-value warnings */
|
||||||
|
}
|
||||||
Vendored
+8
-5
@@ -1,6 +1,6 @@
|
|||||||
IJG JPEG LIBRARY: FILE LIST
|
IJG JPEG LIBRARY: FILE LIST
|
||||||
|
|
||||||
Copyright (C) 1994-2009, Thomas G. Lane, Guido Vollbeding.
|
Copyright (C) 1994-2020, Thomas G. Lane, Guido Vollbeding.
|
||||||
This file is part of the Independent JPEG Group's software.
|
This file is part of the Independent JPEG Group's software.
|
||||||
For conditions of distribution and use, see the accompanying README file.
|
For conditions of distribution and use, see the accompanying README file.
|
||||||
|
|
||||||
@@ -140,7 +140,9 @@ transupp.h Declarations for jpegtran support routines in transupp.c.
|
|||||||
C source code files:
|
C source code files:
|
||||||
|
|
||||||
cjpeg.c Main program for cjpeg.
|
cjpeg.c Main program for cjpeg.
|
||||||
|
cjpegalt.c Main program for cjpeg with alternate user interface.
|
||||||
djpeg.c Main program for djpeg.
|
djpeg.c Main program for djpeg.
|
||||||
|
djpegalt.c Main program for djpeg with alternate user interface.
|
||||||
jpegtran.c Main program for jpegtran.
|
jpegtran.c Main program for jpegtran.
|
||||||
cdjpeg.c Utility routines used by all three programs.
|
cdjpeg.c Utility routines used by all three programs.
|
||||||
rdcolmap.c Code to read a colormap file for djpeg's "-map" switch.
|
rdcolmap.c Code to read a colormap file for djpeg's "-map" switch.
|
||||||
@@ -151,7 +153,7 @@ transupp.c Support code for jpegtran: lossless image manipulations.
|
|||||||
Image file reader modules for cjpeg:
|
Image file reader modules for cjpeg:
|
||||||
|
|
||||||
rdbmp.c BMP file input.
|
rdbmp.c BMP file input.
|
||||||
rdgif.c GIF file input (now just a stub).
|
rdgif.c GIF file input.
|
||||||
rdppm.c PPM/PGM file input.
|
rdppm.c PPM/PGM file input.
|
||||||
rdrle.c Utah RLE file input.
|
rdrle.c Utah RLE file input.
|
||||||
rdtarga.c Targa file input.
|
rdtarga.c Targa file input.
|
||||||
@@ -159,7 +161,7 @@ rdtarga.c Targa file input.
|
|||||||
Image file writer modules for djpeg:
|
Image file writer modules for djpeg:
|
||||||
|
|
||||||
wrbmp.c BMP file output.
|
wrbmp.c BMP file output.
|
||||||
wrgif.c GIF file output (a mere shadow of its former self).
|
wrgif.c GIF file output.
|
||||||
wrppm.c PPM/PGM file output.
|
wrppm.c PPM/PGM file output.
|
||||||
wrrle.c Utah RLE file output.
|
wrrle.c Utah RLE file output.
|
||||||
wrtarga.c Targa file output.
|
wrtarga.c Targa file output.
|
||||||
@@ -197,6 +199,8 @@ config.guess
|
|||||||
config.sub
|
config.sub
|
||||||
depcomp
|
depcomp
|
||||||
missing
|
missing
|
||||||
|
ar-lib
|
||||||
|
compile
|
||||||
install-sh Install shell script for those Unix systems lacking one.
|
install-sh Install shell script for those Unix systems lacking one.
|
||||||
Makefile.in Makefile input for configure.
|
Makefile.in Makefile input for configure.
|
||||||
Makefile.am Source file for use with Automake to generate Makefile.in.
|
Makefile.am Source file for use with Automake to generate Makefile.in.
|
||||||
@@ -205,9 +209,8 @@ jconfig.txt Template for making jconfig.h by hand.
|
|||||||
mak*.* Sample makefiles for particular systems.
|
mak*.* Sample makefiles for particular systems.
|
||||||
jconfig.* Sample jconfig.h for particular systems.
|
jconfig.* Sample jconfig.h for particular systems.
|
||||||
libjpeg.map Script to generate shared library with versioned symbols.
|
libjpeg.map Script to generate shared library with versioned symbols.
|
||||||
|
libjpeg.pc.in libjpeg.pc pkg-config file input for configure.
|
||||||
aclocal.m4 M4 macro definitions for use with Autoconf.
|
aclocal.m4 M4 macro definitions for use with Autoconf.
|
||||||
ansi2knr.c De-ANSIfier for pre-ANSI C compilers (courtesy of
|
|
||||||
L. Peter Deutsch and Aladdin Enterprises).
|
|
||||||
|
|
||||||
Test files (see install.txt for test procedure):
|
Test files (see install.txt for test procedure):
|
||||||
|
|
||||||
|
|||||||
+541
@@ -0,0 +1,541 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# install - install a program, script, or datafile
|
||||||
|
|
||||||
|
scriptversion=2020-11-14.01; # UTC
|
||||||
|
|
||||||
|
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||||
|
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||||
|
# following copyright and license.
|
||||||
|
#
|
||||||
|
# Copyright (C) 1994 X Consortium
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to
|
||||||
|
# deal in the Software without restriction, including without limitation the
|
||||||
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
# sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||||
|
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
#
|
||||||
|
# Except as contained in this notice, the name of the X Consortium shall not
|
||||||
|
# be used in advertising or otherwise to promote the sale, use or other deal-
|
||||||
|
# ings in this Software without prior written authorization from the X Consor-
|
||||||
|
# tium.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# FSF changes to this file are in the public domain.
|
||||||
|
#
|
||||||
|
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||||
|
# 'make' implicit rules from creating a file called install from it
|
||||||
|
# when there is no Makefile.
|
||||||
|
#
|
||||||
|
# This script is compatible with the BSD install script, but was written
|
||||||
|
# from scratch.
|
||||||
|
|
||||||
|
tab=' '
|
||||||
|
nl='
|
||||||
|
'
|
||||||
|
IFS=" $tab$nl"
|
||||||
|
|
||||||
|
# Set DOITPROG to "echo" to test this script.
|
||||||
|
|
||||||
|
doit=${DOITPROG-}
|
||||||
|
doit_exec=${doit:-exec}
|
||||||
|
|
||||||
|
# Put in absolute file names if you don't have them in your path;
|
||||||
|
# or use environment vars.
|
||||||
|
|
||||||
|
chgrpprog=${CHGRPPROG-chgrp}
|
||||||
|
chmodprog=${CHMODPROG-chmod}
|
||||||
|
chownprog=${CHOWNPROG-chown}
|
||||||
|
cmpprog=${CMPPROG-cmp}
|
||||||
|
cpprog=${CPPROG-cp}
|
||||||
|
mkdirprog=${MKDIRPROG-mkdir}
|
||||||
|
mvprog=${MVPROG-mv}
|
||||||
|
rmprog=${RMPROG-rm}
|
||||||
|
stripprog=${STRIPPROG-strip}
|
||||||
|
|
||||||
|
posix_mkdir=
|
||||||
|
|
||||||
|
# Desired mode of installed file.
|
||||||
|
mode=0755
|
||||||
|
|
||||||
|
# Create dirs (including intermediate dirs) using mode 755.
|
||||||
|
# This is like GNU 'install' as of coreutils 8.32 (2020).
|
||||||
|
mkdir_umask=22
|
||||||
|
|
||||||
|
backupsuffix=
|
||||||
|
chgrpcmd=
|
||||||
|
chmodcmd=$chmodprog
|
||||||
|
chowncmd=
|
||||||
|
mvcmd=$mvprog
|
||||||
|
rmcmd="$rmprog -f"
|
||||||
|
stripcmd=
|
||||||
|
|
||||||
|
src=
|
||||||
|
dst=
|
||||||
|
dir_arg=
|
||||||
|
dst_arg=
|
||||||
|
|
||||||
|
copy_on_change=false
|
||||||
|
is_target_a_directory=possibly
|
||||||
|
|
||||||
|
usage="\
|
||||||
|
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
|
||||||
|
or: $0 [OPTION]... SRCFILES... DIRECTORY
|
||||||
|
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
|
||||||
|
or: $0 [OPTION]... -d DIRECTORIES...
|
||||||
|
|
||||||
|
In the 1st form, copy SRCFILE to DSTFILE.
|
||||||
|
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
|
||||||
|
In the 4th, create DIRECTORIES.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--help display this help and exit.
|
||||||
|
--version display version info and exit.
|
||||||
|
|
||||||
|
-c (ignored)
|
||||||
|
-C install only if different (preserve data modification time)
|
||||||
|
-d create directories instead of installing files.
|
||||||
|
-g GROUP $chgrpprog installed files to GROUP.
|
||||||
|
-m MODE $chmodprog installed files to MODE.
|
||||||
|
-o USER $chownprog installed files to USER.
|
||||||
|
-p pass -p to $cpprog.
|
||||||
|
-s $stripprog installed files.
|
||||||
|
-S SUFFIX attempt to back up existing files, with suffix SUFFIX.
|
||||||
|
-t DIRECTORY install into DIRECTORY.
|
||||||
|
-T report an error if DSTFILE is a directory.
|
||||||
|
|
||||||
|
Environment variables override the default commands:
|
||||||
|
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
|
||||||
|
RMPROG STRIPPROG
|
||||||
|
|
||||||
|
By default, rm is invoked with -f; when overridden with RMPROG,
|
||||||
|
it's up to you to specify -f if you want it.
|
||||||
|
|
||||||
|
If -S is not specified, no backups are attempted.
|
||||||
|
|
||||||
|
Email bug reports to [email protected].
|
||||||
|
Automake home page: https://www.gnu.org/software/automake/
|
||||||
|
"
|
||||||
|
|
||||||
|
while test $# -ne 0; do
|
||||||
|
case $1 in
|
||||||
|
-c) ;;
|
||||||
|
|
||||||
|
-C) copy_on_change=true;;
|
||||||
|
|
||||||
|
-d) dir_arg=true;;
|
||||||
|
|
||||||
|
-g) chgrpcmd="$chgrpprog $2"
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
--help) echo "$usage"; exit $?;;
|
||||||
|
|
||||||
|
-m) mode=$2
|
||||||
|
case $mode in
|
||||||
|
*' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
|
||||||
|
echo "$0: invalid mode: $mode" >&2
|
||||||
|
exit 1;;
|
||||||
|
esac
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
-o) chowncmd="$chownprog $2"
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
-p) cpprog="$cpprog -p";;
|
||||||
|
|
||||||
|
-s) stripcmd=$stripprog;;
|
||||||
|
|
||||||
|
-S) backupsuffix="$2"
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
-t)
|
||||||
|
is_target_a_directory=always
|
||||||
|
dst_arg=$2
|
||||||
|
# Protect names problematic for 'test' and other utilities.
|
||||||
|
case $dst_arg in
|
||||||
|
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
||||||
|
esac
|
||||||
|
shift;;
|
||||||
|
|
||||||
|
-T) is_target_a_directory=never;;
|
||||||
|
|
||||||
|
--version) echo "$0 $scriptversion"; exit $?;;
|
||||||
|
|
||||||
|
--) shift
|
||||||
|
break;;
|
||||||
|
|
||||||
|
-*) echo "$0: invalid option: $1" >&2
|
||||||
|
exit 1;;
|
||||||
|
|
||||||
|
*) break;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
# We allow the use of options -d and -T together, by making -d
|
||||||
|
# take the precedence; this is for compatibility with GNU install.
|
||||||
|
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
if test -n "$dst_arg"; then
|
||||||
|
echo "$0: target directory not allowed when installing a directory." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
|
||||||
|
# When -d is used, all remaining arguments are directories to create.
|
||||||
|
# When -t is used, the destination is already specified.
|
||||||
|
# Otherwise, the last argument is the destination. Remove it from $@.
|
||||||
|
for arg
|
||||||
|
do
|
||||||
|
if test -n "$dst_arg"; then
|
||||||
|
# $@ is not empty: it contains at least $arg.
|
||||||
|
set fnord "$@" "$dst_arg"
|
||||||
|
shift # fnord
|
||||||
|
fi
|
||||||
|
shift # arg
|
||||||
|
dst_arg=$arg
|
||||||
|
# Protect names problematic for 'test' and other utilities.
|
||||||
|
case $dst_arg in
|
||||||
|
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $# -eq 0; then
|
||||||
|
if test -z "$dir_arg"; then
|
||||||
|
echo "$0: no input file specified." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# It's OK to call 'install-sh -d' without argument.
|
||||||
|
# This can happen when creating conditional directories.
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$dir_arg"; then
|
||||||
|
if test $# -gt 1 || test "$is_target_a_directory" = always; then
|
||||||
|
if test ! -d "$dst_arg"; then
|
||||||
|
echo "$0: $dst_arg: Is not a directory." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$dir_arg"; then
|
||||||
|
do_exit='(exit $ret); exit $ret'
|
||||||
|
trap "ret=129; $do_exit" 1
|
||||||
|
trap "ret=130; $do_exit" 2
|
||||||
|
trap "ret=141; $do_exit" 13
|
||||||
|
trap "ret=143; $do_exit" 15
|
||||||
|
|
||||||
|
# Set umask so as not to create temps with too-generous modes.
|
||||||
|
# However, 'strip' requires both read and write access to temps.
|
||||||
|
case $mode in
|
||||||
|
# Optimize common cases.
|
||||||
|
*644) cp_umask=133;;
|
||||||
|
*755) cp_umask=22;;
|
||||||
|
|
||||||
|
*[0-7])
|
||||||
|
if test -z "$stripcmd"; then
|
||||||
|
u_plus_rw=
|
||||||
|
else
|
||||||
|
u_plus_rw='% 200'
|
||||||
|
fi
|
||||||
|
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
|
||||||
|
*)
|
||||||
|
if test -z "$stripcmd"; then
|
||||||
|
u_plus_rw=
|
||||||
|
else
|
||||||
|
u_plus_rw=,u+rw
|
||||||
|
fi
|
||||||
|
cp_umask=$mode$u_plus_rw;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
for src
|
||||||
|
do
|
||||||
|
# Protect names problematic for 'test' and other utilities.
|
||||||
|
case $src in
|
||||||
|
-* | [=\(\)!]) src=./$src;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
dst=$src
|
||||||
|
dstdir=$dst
|
||||||
|
test -d "$dstdir"
|
||||||
|
dstdir_status=$?
|
||||||
|
# Don't chown directories that already exist.
|
||||||
|
if test $dstdir_status = 0; then
|
||||||
|
chowncmd=""
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
|
||||||
|
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
|
||||||
|
# might cause directories to be created, which would be especially bad
|
||||||
|
# if $src (and thus $dsttmp) contains '*'.
|
||||||
|
if test ! -f "$src" && test ! -d "$src"; then
|
||||||
|
echo "$0: $src does not exist." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$dst_arg"; then
|
||||||
|
echo "$0: no destination specified." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
dst=$dst_arg
|
||||||
|
|
||||||
|
# If destination is a directory, append the input filename.
|
||||||
|
if test -d "$dst"; then
|
||||||
|
if test "$is_target_a_directory" = never; then
|
||||||
|
echo "$0: $dst_arg: Is a directory" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
dstdir=$dst
|
||||||
|
dstbase=`basename "$src"`
|
||||||
|
case $dst in
|
||||||
|
*/) dst=$dst$dstbase;;
|
||||||
|
*) dst=$dst/$dstbase;;
|
||||||
|
esac
|
||||||
|
dstdir_status=0
|
||||||
|
else
|
||||||
|
dstdir=`dirname "$dst"`
|
||||||
|
test -d "$dstdir"
|
||||||
|
dstdir_status=$?
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $dstdir in
|
||||||
|
*/) dstdirslash=$dstdir;;
|
||||||
|
*) dstdirslash=$dstdir/;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
obsolete_mkdir_used=false
|
||||||
|
|
||||||
|
if test $dstdir_status != 0; then
|
||||||
|
case $posix_mkdir in
|
||||||
|
'')
|
||||||
|
# With -d, create the new directory with the user-specified mode.
|
||||||
|
# Otherwise, rely on $mkdir_umask.
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
mkdir_mode=-m$mode
|
||||||
|
else
|
||||||
|
mkdir_mode=
|
||||||
|
fi
|
||||||
|
|
||||||
|
posix_mkdir=false
|
||||||
|
# The $RANDOM variable is not portable (e.g., dash). Use it
|
||||||
|
# here however when possible just to lower collision chance.
|
||||||
|
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
||||||
|
|
||||||
|
trap '
|
||||||
|
ret=$?
|
||||||
|
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
|
||||||
|
exit $ret
|
||||||
|
' 0
|
||||||
|
|
||||||
|
# Because "mkdir -p" follows existing symlinks and we likely work
|
||||||
|
# directly in world-writeable /tmp, make sure that the '$tmpdir'
|
||||||
|
# directory is successfully created first before we actually test
|
||||||
|
# 'mkdir -p'.
|
||||||
|
if (umask $mkdir_umask &&
|
||||||
|
$mkdirprog $mkdir_mode "$tmpdir" &&
|
||||||
|
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
if test -z "$dir_arg" || {
|
||||||
|
# Check for POSIX incompatibilities with -m.
|
||||||
|
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||||
|
# other-writable bit of parent directory when it shouldn't.
|
||||||
|
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||||
|
test_tmpdir="$tmpdir/a"
|
||||||
|
ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
|
||||||
|
case $ls_ld_tmpdir in
|
||||||
|
d????-?r-*) different_mode=700;;
|
||||||
|
d????-?--*) different_mode=755;;
|
||||||
|
*) false;;
|
||||||
|
esac &&
|
||||||
|
$mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
|
||||||
|
ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
|
||||||
|
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
then posix_mkdir=:
|
||||||
|
fi
|
||||||
|
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
|
||||||
|
else
|
||||||
|
# Remove any dirs left behind by ancient mkdir implementations.
|
||||||
|
rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
|
||||||
|
fi
|
||||||
|
trap '' 0;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if
|
||||||
|
$posix_mkdir && (
|
||||||
|
umask $mkdir_umask &&
|
||||||
|
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
|
||||||
|
)
|
||||||
|
then :
|
||||||
|
else
|
||||||
|
|
||||||
|
# mkdir does not conform to POSIX,
|
||||||
|
# or it failed possibly due to a race condition. Create the
|
||||||
|
# directory the slow way, step by step, checking for races as we go.
|
||||||
|
|
||||||
|
case $dstdir in
|
||||||
|
/*) prefix='/';;
|
||||||
|
[-=\(\)!]*) prefix='./';;
|
||||||
|
*) prefix='';;
|
||||||
|
esac
|
||||||
|
|
||||||
|
oIFS=$IFS
|
||||||
|
IFS=/
|
||||||
|
set -f
|
||||||
|
set fnord $dstdir
|
||||||
|
shift
|
||||||
|
set +f
|
||||||
|
IFS=$oIFS
|
||||||
|
|
||||||
|
prefixes=
|
||||||
|
|
||||||
|
for d
|
||||||
|
do
|
||||||
|
test X"$d" = X && continue
|
||||||
|
|
||||||
|
prefix=$prefix$d
|
||||||
|
if test -d "$prefix"; then
|
||||||
|
prefixes=
|
||||||
|
else
|
||||||
|
if $posix_mkdir; then
|
||||||
|
(umask $mkdir_umask &&
|
||||||
|
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
|
||||||
|
# Don't fail if two instances are running concurrently.
|
||||||
|
test -d "$prefix" || exit 1
|
||||||
|
else
|
||||||
|
case $prefix in
|
||||||
|
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
|
||||||
|
*) qprefix=$prefix;;
|
||||||
|
esac
|
||||||
|
prefixes="$prefixes '$qprefix'"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
prefix=$prefix/
|
||||||
|
done
|
||||||
|
|
||||||
|
if test -n "$prefixes"; then
|
||||||
|
# Don't fail if two instances are running concurrently.
|
||||||
|
(umask $mkdir_umask &&
|
||||||
|
eval "\$doit_exec \$mkdirprog $prefixes") ||
|
||||||
|
test -d "$dstdir" || exit 1
|
||||||
|
obsolete_mkdir_used=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -n "$dir_arg"; then
|
||||||
|
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
|
||||||
|
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
|
||||||
|
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
|
||||||
|
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
|
||||||
|
else
|
||||||
|
|
||||||
|
# Make a couple of temp file names in the proper directory.
|
||||||
|
dsttmp=${dstdirslash}_inst.$$_
|
||||||
|
rmtmp=${dstdirslash}_rm.$$_
|
||||||
|
|
||||||
|
# Trap to clean up those temp files at exit.
|
||||||
|
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
|
||||||
|
|
||||||
|
# Copy the file name to the temp name.
|
||||||
|
(umask $cp_umask &&
|
||||||
|
{ test -z "$stripcmd" || {
|
||||||
|
# Create $dsttmp read-write so that cp doesn't create it read-only,
|
||||||
|
# which would cause strip to fail.
|
||||||
|
if test -z "$doit"; then
|
||||||
|
: >"$dsttmp" # No need to fork-exec 'touch'.
|
||||||
|
else
|
||||||
|
$doit touch "$dsttmp"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
} &&
|
||||||
|
$doit_exec $cpprog "$src" "$dsttmp") &&
|
||||||
|
|
||||||
|
# and set any options; do chmod last to preserve setuid bits.
|
||||||
|
#
|
||||||
|
# If any of these fail, we abort the whole thing. If we want to
|
||||||
|
# ignore errors from any of these, just make sure not to ignore
|
||||||
|
# errors from the above "$doit $cpprog $src $dsttmp" command.
|
||||||
|
#
|
||||||
|
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
|
||||||
|
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
|
||||||
|
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
|
||||||
|
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
|
||||||
|
|
||||||
|
# If -C, don't bother to copy if it wouldn't change the file.
|
||||||
|
if $copy_on_change &&
|
||||||
|
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
|
||||||
|
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
|
||||||
|
set -f &&
|
||||||
|
set X $old && old=:$2:$4:$5:$6 &&
|
||||||
|
set X $new && new=:$2:$4:$5:$6 &&
|
||||||
|
set +f &&
|
||||||
|
test "$old" = "$new" &&
|
||||||
|
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
rm -f "$dsttmp"
|
||||||
|
else
|
||||||
|
# If $backupsuffix is set, and the file being installed
|
||||||
|
# already exists, attempt a backup. Don't worry if it fails,
|
||||||
|
# e.g., if mv doesn't support -f.
|
||||||
|
if test -n "$backupsuffix" && test -f "$dst"; then
|
||||||
|
$doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Rename the file to the real destination.
|
||||||
|
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
|
||||||
|
|
||||||
|
# The rename failed, perhaps because mv can't rename something else
|
||||||
|
# to itself, or perhaps because mv is so ancient that it does not
|
||||||
|
# support -f.
|
||||||
|
{
|
||||||
|
# Now remove or move aside any old file at destination location.
|
||||||
|
# We try this two ways since rm can't unlink itself on some
|
||||||
|
# systems and the destination file might be busy for other
|
||||||
|
# reasons. In this case, the final cleanup might fail but the new
|
||||||
|
# file should still install successfully.
|
||||||
|
{
|
||||||
|
test ! -f "$dst" ||
|
||||||
|
$doit $rmcmd "$dst" 2>/dev/null ||
|
||||||
|
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
|
||||||
|
{ $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
|
||||||
|
} ||
|
||||||
|
{ echo "$0: cannot unlink or rename $dst" >&2
|
||||||
|
(exit 1); exit 1
|
||||||
|
}
|
||||||
|
} &&
|
||||||
|
|
||||||
|
# Now rename the file to the real destination.
|
||||||
|
$doit $mvcmd "$dsttmp" "$dst"
|
||||||
|
}
|
||||||
|
fi || exit 1
|
||||||
|
|
||||||
|
trap '' 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Local variables:
|
||||||
|
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||||
|
# time-stamp-start: "scriptversion="
|
||||||
|
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||||
|
# time-stamp-time-zone: "UTC0"
|
||||||
|
# time-stamp-end: "; # UTC"
|
||||||
|
# End:
|
||||||
Vendored
+184
-82
@@ -1,6 +1,6 @@
|
|||||||
INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software
|
INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software
|
||||||
|
|
||||||
Copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding.
|
Copyright (C) 1991-2021, Thomas G. Lane, Guido Vollbeding.
|
||||||
This file is part of the Independent JPEG Group's software.
|
This file is part of the Independent JPEG Group's software.
|
||||||
For conditions of distribution and use, see the accompanying README file.
|
For conditions of distribution and use, see the accompanying README file.
|
||||||
|
|
||||||
@@ -147,9 +147,15 @@ makefile.bcc jconfig.bcc MS-DOS or OS/2, Borland C
|
|||||||
makefile.dj jconfig.dj MS-DOS, DJGPP (Delorie's port of GNU C)
|
makefile.dj jconfig.dj MS-DOS, DJGPP (Delorie's port of GNU C)
|
||||||
makefile.mc6 jconfig.mc6 MS-DOS, Microsoft C (16-bit only)
|
makefile.mc6 jconfig.mc6 MS-DOS, Microsoft C (16-bit only)
|
||||||
makefile.wat jconfig.wat MS-DOS, OS/2, or Windows NT, Watcom C
|
makefile.wat jconfig.wat MS-DOS, OS/2, or Windows NT, Watcom C
|
||||||
makefile.vc jconfig.vc Windows NT/95, MS Visual C++
|
makefile.vc jconfig.vc Windows, MS Visual C++
|
||||||
make*.vc6 jconfig.vc Windows NT/95, MS Visual C++ 6
|
makefile.vs jconfig.vc Windows, MS Visual C++ 6 Developer Studio
|
||||||
make*.v10 jconfig.vc Windows NT/95, MS Visual C++ 2010 (v10)
|
make*.vc6
|
||||||
|
makefile.vs jconfig.vc Windows, Visual Studio 2019 Version 16
|
||||||
|
make*.v16
|
||||||
|
makefile.vs jconfig.vc Windows, Visual Studio 2022 Version 17
|
||||||
|
make*.v16
|
||||||
|
make*.v17
|
||||||
|
makefile.b32 jconfig.vc Windows, Borland C++ 32-bit (bcc32)
|
||||||
makefile.mms jconfig.vms Digital VMS, with MMS software
|
makefile.mms jconfig.vms Digital VMS, with MMS software
|
||||||
makefile.vms jconfig.vms Digital VMS, without MMS software
|
makefile.vms jconfig.vms Digital VMS, without MMS software
|
||||||
|
|
||||||
@@ -317,13 +323,14 @@ As a quick test of functionality we've included a small sample image in
|
|||||||
several forms:
|
several forms:
|
||||||
testorig.jpg Starting point for the djpeg tests.
|
testorig.jpg Starting point for the djpeg tests.
|
||||||
testimg.ppm The output of djpeg testorig.jpg
|
testimg.ppm The output of djpeg testorig.jpg
|
||||||
|
testimg.gif The output of djpeg -gif testorig.jpg
|
||||||
testimg.bmp The output of djpeg -bmp -colors 256 testorig.jpg
|
testimg.bmp The output of djpeg -bmp -colors 256 testorig.jpg
|
||||||
testimg.jpg The output of cjpeg testimg.ppm
|
testimg.jpg The output of cjpeg testimg.ppm
|
||||||
testprog.jpg Progressive-mode equivalent of testorig.jpg.
|
testprog.jpg Progressive-mode equivalent of testorig.jpg.
|
||||||
testimgp.jpg The output of cjpeg -progressive -optimize testimg.ppm
|
testimgp.jpg The output of cjpeg -progressive -optimize testimg.ppm
|
||||||
(The first- and second-generation .jpg files aren't identical since JPEG is
|
(The first- and second-generation .jpg files aren't identical since the
|
||||||
lossy.) If you can generate duplicates of the testimg* files then you
|
default compression parameters are lossy.) If you can generate duplicates
|
||||||
probably have working programs.
|
of the testimg* files then you probably have working programs.
|
||||||
|
|
||||||
With most of the makefiles, "make test" will perform the necessary
|
With most of the makefiles, "make test" will perform the necessary
|
||||||
comparisons.
|
comparisons.
|
||||||
@@ -418,54 +425,58 @@ support as follows:
|
|||||||
the directory containing the URT "librle.a" file (typically the
|
the directory containing the URT "librle.a" file (typically the
|
||||||
"lib" subdirectory of the URT distribution).
|
"lib" subdirectory of the URT distribution).
|
||||||
|
|
||||||
Support for 12-bit-deep pixel data:
|
Support for 9-bit to 12-bit deep pixel data:
|
||||||
|
|
||||||
The JPEG standard allows either 8-bit or 12-bit data precision. (For color,
|
The IJG code currently allows 8, 9, 10, 11, or 12 bits sample data precision.
|
||||||
this means 8 or 12 bits per channel, of course.) If you need to work with
|
(For color, this means 8 to 12 bits per channel, of course.) If you need to
|
||||||
deeper than 8-bit data, you can compile the IJG code for 12-bit operation.
|
work with deeper than 8-bit data, you can compile the IJG code for 9-bit to
|
||||||
|
12-bit operation.
|
||||||
To do so:
|
To do so:
|
||||||
1. In jmorecfg.h, define BITS_IN_JSAMPLE as 12 rather than 8.
|
1. In jmorecfg.h, define BITS_IN_JSAMPLE as 9, 10, 11, or 12 rather than 8.
|
||||||
2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED,
|
2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED,
|
||||||
because the code for those formats doesn't handle 12-bit data and won't
|
because the code for those formats doesn't handle deeper than 8-bit data
|
||||||
even compile. (The PPM code does work, as explained below. The GIF
|
and won't even compile. (The PPM code does work, as explained below.
|
||||||
code works too; it scales 8-bit GIF data to and from 12-bit depth
|
The GIF code works too; it scales 8-bit GIF data to and from 12-bit
|
||||||
automatically.)
|
depth automatically.)
|
||||||
3. Compile. Don't expect "make test" to pass, since the supplied test
|
3. Compile. Don't expect "make test" to pass, since the supplied test
|
||||||
files are for 8-bit data.
|
files are for 8-bit data.
|
||||||
|
|
||||||
Currently, 12-bit support does not work on 16-bit-int machines.
|
Currently, 9-bit to 12-bit support does not work on 16-bit-int machines.
|
||||||
|
|
||||||
Note that a 12-bit version will not read 8-bit JPEG files, nor vice versa;
|
Run-time selection and conversion of data precision are currently not
|
||||||
so you'll want to keep around a regular 8-bit compilation as well.
|
supported and may be added later.
|
||||||
(Run-time selection of data depth, to allow a single copy that does both,
|
Exception: The transcoding part (jpegtran) supports all settings in a
|
||||||
is possible but would probably slow things down considerably; it's very low
|
single instance, since it operates on the level of DCT coefficients and
|
||||||
on our to-do list.)
|
not sample values.
|
||||||
|
|
||||||
The PPM reader (rdppm.c) can read 12-bit data from either text-format or
|
The PPM reader (rdppm.c) can read deeper than 8-bit data from either
|
||||||
binary-format PPM and PGM files. Binary-format PPM/PGM files which have a
|
text-format or binary-format PPM and PGM files. Binary-format PPM/PGM files
|
||||||
maxval greater than 255 are assumed to use 2 bytes per sample, MSB first
|
which have a maxval greater than 255 are assumed to use 2 bytes per sample,
|
||||||
(big-endian order). As of early 1995, 2-byte binary format is not
|
MSB first (big-endian order). As of early 1995, 2-byte binary format is not
|
||||||
officially supported by the PBMPLUS library, but it is expected that a
|
officially supported by the PBMPLUS library, but it is expected that a
|
||||||
future release of PBMPLUS will support it. Note that the PPM reader will
|
future release of PBMPLUS will support it. Note that the PPM reader will
|
||||||
read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming
|
read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming
|
||||||
data is automatically rescaled to either maxval=255 or maxval=4095 as
|
data is automatically rescaled to maxval=MAXJSAMPLE as appropriate for the
|
||||||
appropriate for the cjpeg bit depth.
|
cjpeg bit depth.
|
||||||
|
|
||||||
The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM
|
The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM
|
||||||
format, maxval 4095, when compiled with BITS_IN_JSAMPLE=12. Since this
|
format, maxval=MAXJSAMPLE, when compiled with BITS_IN_JSAMPLE>8. Since this
|
||||||
format is not yet widely supported, you can disable it by compiling wrppm.c
|
format is not yet widely supported, you can disable it by compiling wrppm.c
|
||||||
with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a
|
with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a
|
||||||
standard 1-byte/sample PPM or PGM file. (Yes, this means still another copy
|
standard 1-byte/sample PPM or PGM file. (Yes, this means still another copy
|
||||||
of djpeg to keep around. But hopefully you won't need it for very long.
|
of djpeg to keep around. But hopefully you won't need it for very long.
|
||||||
Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.)
|
Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.)
|
||||||
|
|
||||||
Of course, if you are working with 12-bit data, you probably have it stored
|
Of course, if you are working with 9-bit to 12-bit data, you probably have
|
||||||
in some other, nonstandard format. In that case you'll probably want to
|
it stored in some other, nonstandard format. In that case you'll probably
|
||||||
write your own I/O modules to read and write your format.
|
want to write your own I/O modules to read and write your format.
|
||||||
|
|
||||||
Note that a 12-bit version of cjpeg always runs in "-optimize" mode, in
|
Note:
|
||||||
order to generate valid Huffman tables. This is necessary because our
|
The standard Huffman tables are only valid for 8-bit data precision. If
|
||||||
default Huffman tables only cover 8-bit data.
|
you selected more than 8-bit data precision, cjpeg uses arithmetic coding
|
||||||
|
by default. The Huffman encoder normally uses entropy optimization to
|
||||||
|
compute usable tables for higher precision. Otherwise, you'll have to
|
||||||
|
supply different default Huffman tables.
|
||||||
|
|
||||||
Removing code:
|
Removing code:
|
||||||
|
|
||||||
@@ -534,17 +545,17 @@ In general, it's worth trying the maximum optimization level of your compiler,
|
|||||||
and experimenting with any optional optimizations such as loop unrolling.
|
and experimenting with any optional optimizations such as loop unrolling.
|
||||||
(Unfortunately, far too many compilers have optimizer bugs ... be prepared to
|
(Unfortunately, far too many compilers have optimizer bugs ... be prepared to
|
||||||
back off if the code fails self-test.) If you do any experimentation along
|
back off if the code fails self-test.) If you do any experimentation along
|
||||||
these lines, please report the optimal settings to jpeg-info@uc.ag so we
|
these lines, please report the optimal settings to jpeg-info@jpegclub.org so
|
||||||
can mention them in future releases. Be sure to specify your machine
|
we can mention them in future releases. Be sure to specify your machine and
|
||||||
and compiler version.
|
compiler version.
|
||||||
|
|
||||||
|
|
||||||
HINTS FOR SPECIFIC SYSTEMS
|
HINTS FOR SPECIFIC SYSTEMS
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
We welcome reports on changes needed for systems not mentioned here. Submit
|
We welcome reports on changes needed for systems not mentioned here. Submit
|
||||||
'em to jpeg-info@uc.ag. Also, if configure or ckconfig.c is wrong about how
|
'em to jpeg-info@jpegclub.org. Also, if configure or ckconfig.c is wrong
|
||||||
to configure the JPEG software for your system, please let us know.
|
about how to configure the JPEG software for your system, please let us know.
|
||||||
|
|
||||||
|
|
||||||
Acorn RISC OS:
|
Acorn RISC OS:
|
||||||
@@ -848,17 +859,23 @@ with /Oo-.
|
|||||||
Microsoft Windows (all versions), generic comments:
|
Microsoft Windows (all versions), generic comments:
|
||||||
|
|
||||||
Some Windows system include files define typedef boolean as "unsigned char".
|
Some Windows system include files define typedef boolean as "unsigned char".
|
||||||
The IJG code also defines typedef boolean, but we make it "int" by default.
|
The IJG code also defines typedef boolean, but we make it an "enum" by default.
|
||||||
This doesn't affect the IJG programs because we don't import those Windows
|
This doesn't affect the IJG programs because we don't import those Windows
|
||||||
include files. But if you use the JPEG library in your own program, and some
|
include files. But if you use the JPEG library in your own program, and some
|
||||||
of your program's files import one definition of boolean while some import the
|
of your program's files import one definition of boolean while some import the
|
||||||
other, you can get all sorts of mysterious problems. A good preventive step
|
other, you can get all sorts of mysterious problems. A good preventive step
|
||||||
is to make the IJG library use "unsigned char" for boolean. To do that,
|
is to make the IJG library use "unsigned char" for boolean. To do that,
|
||||||
add something like this to your jconfig.h file:
|
add something like this to your jconfig.h file:
|
||||||
/* Define "boolean" as unsigned char, not int, per Windows custom */
|
/* Define "boolean" as unsigned char, not enum, per Windows custom */
|
||||||
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
||||||
typedef unsigned char boolean;
|
typedef unsigned char boolean;
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef FALSE /* in case these macros already exist */
|
||||||
|
#define FALSE 0 /* values of boolean */
|
||||||
|
#endif
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE 1
|
||||||
|
#endif
|
||||||
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
||||||
(This is already in jconfig.vc, by the way.)
|
(This is already in jconfig.vc, by the way.)
|
||||||
|
|
||||||
@@ -1008,57 +1025,142 @@ the configuration to prevent jpeglib.h from using extern "C".
|
|||||||
|
|
||||||
Microsoft Windows, Microsoft Visual C++ 6 Developer Studio:
|
Microsoft Windows, Microsoft Visual C++ 6 Developer Studio:
|
||||||
|
|
||||||
We include makefiles that should work as project files in DevStudio 6.0 or
|
We include makefiles that should work as project files in Developer Studio
|
||||||
later. There is a library makefile that builds the IJG library as a static
|
6.0 or later. There is a library makefile that builds the IJG library as
|
||||||
Win32 library, and application makefiles that build the sample applications
|
a static Win32 library, and application makefiles that build the sample
|
||||||
as Win32 console applications. (Even if you only want the library, we
|
|
||||||
recommend building the applications so that you can run the self-test.)
|
|
||||||
|
|
||||||
To use:
|
|
||||||
1. Open the command prompt, change to the main directory and execute the
|
|
||||||
command line
|
|
||||||
NMAKE /f makefile.vc setup-vc6
|
|
||||||
This will move jconfig.vc to jconfig.h and makefiles to project files.
|
|
||||||
(Note that the renaming is critical!)
|
|
||||||
2. Open the workspace file jpeg.dsw, build the library project.
|
|
||||||
(If you are using DevStudio more recent than 6.0, you'll probably
|
|
||||||
get a message saying that the project files are being updated.)
|
|
||||||
3. Open the workspace file apps.dsw, build the application projects.
|
|
||||||
4. To perform the self-test, execute the command line
|
|
||||||
NMAKE /f makefile.vc test-build
|
|
||||||
5. Move the application .exe files from `app`\Release to an
|
|
||||||
appropriate location on your path.
|
|
||||||
|
|
||||||
|
|
||||||
Microsoft Windows, Microsoft Visual C++ 2010 Developer Studio (v10):
|
|
||||||
|
|
||||||
We include makefiles that should work as project files in Visual Studio
|
|
||||||
2010 or later. There is a library makefile that builds the IJG library
|
|
||||||
as a static Win32 library, and application makefiles that build the sample
|
|
||||||
applications as Win32 console applications. (Even if you only want the
|
applications as Win32 console applications. (Even if you only want the
|
||||||
library, we recommend building the applications so that you can run the
|
library, we recommend building the applications so that you can run the
|
||||||
self-test.)
|
self-test.)
|
||||||
|
|
||||||
To use:
|
To use:
|
||||||
1. Open the command prompt, change to the main directory and execute the
|
1. Open the Windows Command Prompt, change to the source directory and
|
||||||
command line
|
execute the command line
|
||||||
NMAKE /f makefile.vc setup-v10
|
nmake /f makefile.vs setup-vc6
|
||||||
|
If you get an error message saying that the "nmake" command could
|
||||||
|
not be found, execute the command
|
||||||
|
"%ProgramFiles%\Microsoft Visual Studio\VC98\Bin\VCVARS32"
|
||||||
|
to set the environment for using Microsoft Visual C++ tools,
|
||||||
|
and repeat the nmake call.
|
||||||
This will move jconfig.vc to jconfig.h and makefiles to project files.
|
This will move jconfig.vc to jconfig.h and makefiles to project files.
|
||||||
(Note that the renaming is critical!)
|
(Note that the renaming is critical!)
|
||||||
2. Open the solution file jpeg.sln, build the library project.
|
Alternatively you can use
|
||||||
(If you are using Visual Studio more recent than 2010 (v10), you'll
|
nmake /f makefile.vs setupcopy-vc6
|
||||||
|
This will create renamed copies of the files, which allows to repeat
|
||||||
|
the setup later.
|
||||||
|
2. Open the workspace file jpeg.dsw, build the library project.
|
||||||
|
(If you are using Developer Studio more recent than 6.0, you'll
|
||||||
probably get a message saying that the project files are being updated.)
|
probably get a message saying that the project files are being updated.)
|
||||||
3. Open the solution file apps.sln, build the application projects.
|
3. Open the workspace file apps.dsw, build the application projects.
|
||||||
4. To perform the self-test, execute the command line
|
4. To perform the self-test, execute the command line
|
||||||
NMAKE /f makefile.vc test-build
|
nmake /f makefile.vs test-build
|
||||||
5. Move the application .exe files from `app`\Release to an
|
5. Move the application .exe files from the Release folder to an
|
||||||
appropriate location on your path.
|
appropriate location on your path.
|
||||||
|
|
||||||
Note:
|
|
||||||
There seems to be an optimization bug in the compiler which causes the
|
Microsoft Windows, Visual Studio 2019 Version 16:
|
||||||
self-test to fail with the color quantization option.
|
|
||||||
We have disabled optimization for the file jquant2.c in the library
|
We include makefiles that should work as project files in Visual Studio
|
||||||
project file which causes the self-test to pass properly.
|
2019 Version 16 or later. There is a library makefile that builds the
|
||||||
|
IJG library as a static Win32/x64/ARM/ARM64 library, and application
|
||||||
|
makefiles that build the sample applications as Win32/x64/ARM/ARM64
|
||||||
|
console applications. (Even if you only want the library, we recommend
|
||||||
|
building the applications so that you can run the self-test.)
|
||||||
|
|
||||||
|
To use:
|
||||||
|
1. Ensure you’ve checked the item "Desktop development with C++" in the
|
||||||
|
Workloads tab of Visual Studio Installer.
|
||||||
|
Open the Developer Command Prompt for VS 2019, change to the source
|
||||||
|
directory and execute the command line
|
||||||
|
nmake /f makefile.vs setup-v16
|
||||||
|
This will move jconfig.vc to jconfig.h and makefiles to project files.
|
||||||
|
(Note that the renaming is critical!)
|
||||||
|
Alternatively you can use
|
||||||
|
nmake /f makefile.vs setupcopy-v16
|
||||||
|
This will create renamed copies of the files, which allows to repeat
|
||||||
|
the setup later.
|
||||||
|
2. Open the solution file jpeg.sln, build the library project.
|
||||||
|
a) If you are using Visual Studio more recent than
|
||||||
|
2019 Version 16, you'll probably get a message
|
||||||
|
saying that the project files are being updated.
|
||||||
|
b) If necessary, open the project properties and
|
||||||
|
adapt the Windows Target Platform Version in
|
||||||
|
the Configuration Properties, General section;
|
||||||
|
we support the latest version at the time of release.
|
||||||
|
c) If you get a warning saying that a platform cannot be found,
|
||||||
|
you can either
|
||||||
|
* forgo the platform and ignore the warning, or
|
||||||
|
* remove the platform in the Configuration Manager, or
|
||||||
|
* install the corresponding platform Buildtools in
|
||||||
|
Visual Studio Installer (Workloads tab Optional components
|
||||||
|
or Individual components tab).
|
||||||
|
d) If you want to build x64 code, change the platform setting from
|
||||||
|
Win32 to x64. You can build Win32 and x64 versions side by side.
|
||||||
|
e) If you want to build ARM/ARM64 code, change the platform setting
|
||||||
|
to ARM/ARM64. Ensure you've installed the ARM/ARM64-Buildtools
|
||||||
|
in Visual Studio Installer (Workloads tab Optional components
|
||||||
|
or Individual components tab).
|
||||||
|
You can build Win32/x64/ARM/ARM64 versions side by side.
|
||||||
|
3. Open the solution file apps.sln, build the application projects.
|
||||||
|
4. To perform the self-test, execute the command line
|
||||||
|
nmake /f makefile.vs test-32
|
||||||
|
for the Win32 build, or on a 64-bit system
|
||||||
|
nmake /f makefile.vs test-64
|
||||||
|
for the x64 build.
|
||||||
|
5. Move the application .exe files from the Release folder to an
|
||||||
|
appropriate location on your path.
|
||||||
|
|
||||||
|
|
||||||
|
Microsoft Windows, Visual Studio 2022 Version 17:
|
||||||
|
|
||||||
|
We include makefiles that should work as project files in Visual Studio
|
||||||
|
2022 Version 17 or later. There is a library makefile that builds the
|
||||||
|
IJG library as a static Win32/x64/ARM/ARM64 library, and application
|
||||||
|
makefiles that build the sample applications as Win32/x64/ARM/ARM64
|
||||||
|
console applications. (Even if you only want the library, we recommend
|
||||||
|
building the applications so that you can run the self-test.)
|
||||||
|
|
||||||
|
To use:
|
||||||
|
1. Ensure you’ve checked the item "Desktop development with C++" in the
|
||||||
|
Workloads tab of Visual Studio Installer.
|
||||||
|
Open the Developer Command Prompt for VS 2022, change to the source
|
||||||
|
directory and execute the command line
|
||||||
|
nmake /f makefile.vs setup-v17
|
||||||
|
This will move jconfig.vc to jconfig.h and makefiles to project files.
|
||||||
|
(Note that the renaming is critical!)
|
||||||
|
Alternatively you can use
|
||||||
|
nmake /f makefile.vs setupcopy-v17
|
||||||
|
This will create renamed copies of the files, which allows to repeat
|
||||||
|
the setup later.
|
||||||
|
2. Open the solution file jpeg.sln, build the library project.
|
||||||
|
a) If you are using Visual Studio more recent than
|
||||||
|
2022 Version 17, you'll probably get a message
|
||||||
|
saying that the project files are being updated.
|
||||||
|
b) If necessary, open the project properties and
|
||||||
|
adapt the Windows Target Platform Version in
|
||||||
|
the Configuration Properties, General section;
|
||||||
|
we support the latest version at the time of release.
|
||||||
|
c) If you get a warning saying that a platform cannot be found,
|
||||||
|
you can either
|
||||||
|
* forgo the platform and ignore the warning, or
|
||||||
|
* remove the platform in the Configuration Manager, or
|
||||||
|
* install the corresponding platform Buildtools in
|
||||||
|
Visual Studio Installer (Workloads tab Optional components
|
||||||
|
or Individual components tab).
|
||||||
|
d) If you want to build x64 code, change the platform setting from
|
||||||
|
Win32 to x64. You can build Win32 and x64 versions side by side.
|
||||||
|
e) If you want to build ARM/ARM64 code, change the platform setting
|
||||||
|
to ARM/ARM64. Ensure you've installed the ARM/ARM64-Buildtools
|
||||||
|
in Visual Studio Installer (Workloads tab Optional components
|
||||||
|
or Individual components tab).
|
||||||
|
You can build Win32/x64/ARM/ARM64 versions side by side.
|
||||||
|
3. Open the solution file apps.sln, build the application projects.
|
||||||
|
4. To perform the self-test, execute the command line
|
||||||
|
nmake /f makefile.vs test-32
|
||||||
|
for the Win32 build, or on a 64-bit system
|
||||||
|
nmake /f makefile.vs test-64
|
||||||
|
for the x64 build.
|
||||||
|
5. Move the application .exe files from the Release folder to an
|
||||||
|
appropriate location on your path.
|
||||||
|
|
||||||
|
|
||||||
OS/2, Borland C++:
|
OS/2, Borland C++:
|
||||||
|
|||||||
Vendored
+5
-5
@@ -1,16 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* jaricom.c
|
* jaricom.c
|
||||||
*
|
*
|
||||||
* Developed 1997-2009 by Guido Vollbeding.
|
* Developed 1997-2011 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
* This file contains probability estimation tables for common use in
|
* This file contains probability estimation tables for common use in
|
||||||
* arithmetic entropy encoding and decoding routines.
|
* arithmetic entropy encoding and decoding routines.
|
||||||
*
|
*
|
||||||
* This data represents Table D.2 in the JPEG spec (ISO/IEC IS 10918-1
|
* This data represents Table D.3 in the JPEG spec (D.2 in the draft),
|
||||||
* and CCITT Recommendation ITU-T T.81) and Table 24 in the JBIG spec
|
* ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81, and Table 24
|
||||||
* (ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82).
|
* in the JBIG spec, ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define JPEG_INTERNALS
|
#define JPEG_INTERNALS
|
||||||
@@ -147,7 +147,7 @@ const INT32 jpeg_aritab[113+1] = {
|
|||||||
V( 112, 0x59eb, 112, 111, 1 ),
|
V( 112, 0x59eb, 112, 111, 1 ),
|
||||||
/*
|
/*
|
||||||
* This last entry is used for fixed probability estimate of 0.5
|
* This last entry is used for fixed probability estimate of 0.5
|
||||||
* as recommended in Section 10.3 Table 5 of ITU-T Rec. T.851.
|
* as suggested in Section 10.3 Table 5 of ITU-T Rec. T.851.
|
||||||
*/
|
*/
|
||||||
V( 113, 0x5a1d, 113, 113, 0 )
|
V( 113, 0x5a1d, 113, 113, 0 )
|
||||||
};
|
};
|
||||||
|
|||||||
Vendored
+2
-1
@@ -2,6 +2,7 @@
|
|||||||
* jcapistd.c
|
* jcapistd.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
|
* Modified 2013 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -145,7 +146,7 @@ jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
|
|||||||
(*cinfo->master->pass_startup) (cinfo);
|
(*cinfo->master->pass_startup) (cinfo);
|
||||||
|
|
||||||
/* Verify that at least one iMCU row has been passed. */
|
/* Verify that at least one iMCU row has been passed. */
|
||||||
lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
|
lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size;
|
||||||
if (num_lines < lines_per_iMCU_row)
|
if (num_lines < lines_per_iMCU_row)
|
||||||
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||||
|
|
||||||
|
|||||||
Vendored
+59
-48
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* jcarith.c
|
* jcarith.c
|
||||||
*
|
*
|
||||||
* Developed 1997-2009 by Guido Vollbeding.
|
* Developed 1997-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -181,11 +181,11 @@ finish_pass (j_compress_ptr cinfo)
|
|||||||
if (e->zc) /* output final pending zero bytes */
|
if (e->zc) /* output final pending zero bytes */
|
||||||
do emit_byte(0x00, cinfo);
|
do emit_byte(0x00, cinfo);
|
||||||
while (--e->zc);
|
while (--e->zc);
|
||||||
emit_byte((e->c >> 19) & 0xFF, cinfo);
|
emit_byte((int) ((e->c >> 19) & 0xFF), cinfo);
|
||||||
if (((e->c >> 19) & 0xFF) == 0xFF)
|
if (((e->c >> 19) & 0xFF) == 0xFF)
|
||||||
emit_byte(0x00, cinfo);
|
emit_byte(0x00, cinfo);
|
||||||
if (e->c & 0x7F800L) {
|
if (e->c & 0x7F800L) {
|
||||||
emit_byte((e->c >> 11) & 0xFF, cinfo);
|
emit_byte((int) ((e->c >> 11) & 0xFF), cinfo);
|
||||||
if (((e->c >> 11) & 0xFF) == 0xFF)
|
if (((e->c >> 11) & 0xFF) == 0xFF)
|
||||||
emit_byte(0x00, cinfo);
|
emit_byte(0x00, cinfo);
|
||||||
}
|
}
|
||||||
@@ -223,7 +223,7 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
|
|||||||
register INT32 qe, temp;
|
register INT32 qe, temp;
|
||||||
register int sv;
|
register int sv;
|
||||||
|
|
||||||
/* Fetch values from our compact representation of Table D.2:
|
/* Fetch values from our compact representation of Table D.3(D.2):
|
||||||
* Qe values and probability estimation state machine
|
* Qe values and probability estimation state machine
|
||||||
*/
|
*/
|
||||||
sv = *st;
|
sv = *st;
|
||||||
@@ -280,7 +280,8 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
|
|||||||
/* Note: The 3 spacer bits in the C register guarantee
|
/* Note: The 3 spacer bits in the C register guarantee
|
||||||
* that the new buffer byte can't be 0xFF here
|
* that the new buffer byte can't be 0xFF here
|
||||||
* (see page 160 in the P&M JPEG book). */
|
* (see page 160 in the P&M JPEG book). */
|
||||||
e->buffer = temp & 0xFF; /* new output byte, might overflow later */
|
/* New output byte, might overflow later */
|
||||||
|
e->buffer = (int) (temp & 0xFF);
|
||||||
} else if (temp == 0xFF) {
|
} else if (temp == 0xFF) {
|
||||||
++e->sc; /* stack 0xFF byte (which might overflow later) */
|
++e->sc; /* stack 0xFF byte (which might overflow later) */
|
||||||
} else {
|
} else {
|
||||||
@@ -302,7 +303,8 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
|
|||||||
emit_byte(0x00, cinfo);
|
emit_byte(0x00, cinfo);
|
||||||
} while (--e->sc);
|
} while (--e->sc);
|
||||||
}
|
}
|
||||||
e->buffer = temp & 0xFF; /* new output byte (can still overflow) */
|
/* New output byte (can still overflow) */
|
||||||
|
e->buffer = (int) (temp & 0xFF);
|
||||||
}
|
}
|
||||||
e->c &= 0x7FFFFL;
|
e->c &= 0x7FFFFL;
|
||||||
e->ct += 8;
|
e->ct += 8;
|
||||||
@@ -359,10 +361,9 @@ emit_restart (j_compress_ptr cinfo, int restart_num)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
JBLOCKROW block;
|
|
||||||
unsigned char *st;
|
unsigned char *st;
|
||||||
int blkn, ci, tbl;
|
int blkn, ci, tbl;
|
||||||
int v, v2, m;
|
int v, v2, m;
|
||||||
@@ -381,14 +382,13 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/* Encode the MCU data blocks */
|
/* Encode the MCU data blocks */
|
||||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||||
block = MCU_data[blkn];
|
|
||||||
ci = cinfo->MCU_membership[blkn];
|
ci = cinfo->MCU_membership[blkn];
|
||||||
tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
|
tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
|
||||||
|
|
||||||
/* Compute the DC value after the required point transform by Al.
|
/* Compute the DC value after the required point transform by Al.
|
||||||
* This is simply an arithmetic right shift.
|
* This is simply an arithmetic right shift.
|
||||||
*/
|
*/
|
||||||
m = IRIGHT_SHIFT((int) ((*block)[0]), cinfo->Al);
|
m = IRIGHT_SHIFT((int) (MCU_data[blkn][0][0]), cinfo->Al);
|
||||||
|
|
||||||
/* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */
|
/* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */
|
||||||
|
|
||||||
@@ -450,14 +450,14 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
|
const int * natural_order;
|
||||||
JBLOCKROW block;
|
JBLOCKROW block;
|
||||||
unsigned char *st;
|
unsigned char *st;
|
||||||
int tbl, k, ke;
|
int tbl, k, ke;
|
||||||
int v, v2, m;
|
int v, v2, m;
|
||||||
const int * natural_order;
|
|
||||||
|
|
||||||
/* Emit restart marker if needed */
|
/* Emit restart marker if needed */
|
||||||
if (cinfo->restart_interval) {
|
if (cinfo->restart_interval) {
|
||||||
@@ -479,7 +479,8 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
|
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
|
||||||
|
|
||||||
/* Establish EOB (end-of-block) index */
|
/* Establish EOB (end-of-block) index */
|
||||||
for (ke = cinfo->Se; ke > 0; ke--)
|
ke = cinfo->Se;
|
||||||
|
do {
|
||||||
/* We must apply the point transform by Al. For AC coefficients this
|
/* We must apply the point transform by Al. For AC coefficients this
|
||||||
* is an integer division with rounding towards 0. To do this portably
|
* is an integer division with rounding towards 0. To do this portably
|
||||||
* in C, we shift after obtaining the absolute value.
|
* in C, we shift after obtaining the absolute value.
|
||||||
@@ -490,13 +491,14 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
v = -v;
|
v = -v;
|
||||||
if (v >>= cinfo->Al) break;
|
if (v >>= cinfo->Al) break;
|
||||||
}
|
}
|
||||||
|
} while (--ke);
|
||||||
|
|
||||||
/* Figure F.5: Encode_AC_Coefficients */
|
/* Figure F.5: Encode_AC_Coefficients */
|
||||||
for (k = cinfo->Ss; k <= ke; k++) {
|
for (k = cinfo->Ss - 1; k < ke;) {
|
||||||
st = entropy->ac_stats[tbl] + 3 * (k - 1);
|
st = entropy->ac_stats[tbl] + 3 * k;
|
||||||
arith_encode(cinfo, st, 0); /* EOB decision */
|
arith_encode(cinfo, st, 0); /* EOB decision */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((v = (*block)[natural_order[k]]) >= 0) {
|
if ((v = (*block)[natural_order[++k]]) >= 0) {
|
||||||
if (v >>= cinfo->Al) {
|
if (v >>= cinfo->Al) {
|
||||||
arith_encode(cinfo, st + 1, 1);
|
arith_encode(cinfo, st + 1, 1);
|
||||||
arith_encode(cinfo, entropy->fixed_bin, 0);
|
arith_encode(cinfo, entropy->fixed_bin, 0);
|
||||||
@@ -510,7 +512,8 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arith_encode(cinfo, st + 1, 0); st += 3; k++;
|
arith_encode(cinfo, st + 1, 0);
|
||||||
|
st += 3;
|
||||||
}
|
}
|
||||||
st += 2;
|
st += 2;
|
||||||
/* Figure F.8: Encoding the magnitude category of v */
|
/* Figure F.8: Encoding the magnitude category of v */
|
||||||
@@ -537,9 +540,9 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
while (m >>= 1)
|
while (m >>= 1)
|
||||||
arith_encode(cinfo, st, (m & v) ? 1 : 0);
|
arith_encode(cinfo, st, (m & v) ? 1 : 0);
|
||||||
}
|
}
|
||||||
/* Encode EOB decision only if k <= cinfo->Se */
|
/* Encode EOB decision only if k < cinfo->Se */
|
||||||
if (k <= cinfo->Se) {
|
if (k < cinfo->Se) {
|
||||||
st = entropy->ac_stats[tbl] + 3 * (k - 1);
|
st = entropy->ac_stats[tbl] + 3 * k;
|
||||||
arith_encode(cinfo, st, 1);
|
arith_encode(cinfo, st, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,10 +552,12 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* MCU encoding for DC successive approximation refinement scan.
|
* MCU encoding for DC successive approximation refinement scan.
|
||||||
|
* Note: we assume such scans can be multi-component,
|
||||||
|
* although the spec is not very clear on the point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
unsigned char *st;
|
unsigned char *st;
|
||||||
@@ -587,14 +592,14 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
|
const int * natural_order;
|
||||||
JBLOCKROW block;
|
JBLOCKROW block;
|
||||||
unsigned char *st;
|
unsigned char *st;
|
||||||
int tbl, k, ke, kex;
|
int tbl, k, ke, kex;
|
||||||
int v;
|
int v;
|
||||||
const int * natural_order;
|
|
||||||
|
|
||||||
/* Emit restart marker if needed */
|
/* Emit restart marker if needed */
|
||||||
if (cinfo->restart_interval) {
|
if (cinfo->restart_interval) {
|
||||||
@@ -616,7 +621,8 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
/* Section G.1.3.3: Encoding of AC coefficients */
|
/* Section G.1.3.3: Encoding of AC coefficients */
|
||||||
|
|
||||||
/* Establish EOB (end-of-block) index */
|
/* Establish EOB (end-of-block) index */
|
||||||
for (ke = cinfo->Se; ke > 0; ke--)
|
ke = cinfo->Se;
|
||||||
|
do {
|
||||||
/* We must apply the point transform by Al. For AC coefficients this
|
/* We must apply the point transform by Al. For AC coefficients this
|
||||||
* is an integer division with rounding towards 0. To do this portably
|
* is an integer division with rounding towards 0. To do this portably
|
||||||
* in C, we shift after obtaining the absolute value.
|
* in C, we shift after obtaining the absolute value.
|
||||||
@@ -627,6 +633,7 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
v = -v;
|
v = -v;
|
||||||
if (v >>= cinfo->Al) break;
|
if (v >>= cinfo->Al) break;
|
||||||
}
|
}
|
||||||
|
} while (--ke);
|
||||||
|
|
||||||
/* Establish EOBx (previous stage end-of-block) index */
|
/* Establish EOBx (previous stage end-of-block) index */
|
||||||
for (kex = ke; kex > 0; kex--)
|
for (kex = ke; kex > 0; kex--)
|
||||||
@@ -638,12 +645,12 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Figure G.10: Encode_AC_Coefficients_SA */
|
/* Figure G.10: Encode_AC_Coefficients_SA */
|
||||||
for (k = cinfo->Ss; k <= ke; k++) {
|
for (k = cinfo->Ss - 1; k < ke;) {
|
||||||
st = entropy->ac_stats[tbl] + 3 * (k - 1);
|
st = entropy->ac_stats[tbl] + 3 * k;
|
||||||
if (k > kex)
|
if (k >= kex)
|
||||||
arith_encode(cinfo, st, 0); /* EOB decision */
|
arith_encode(cinfo, st, 0); /* EOB decision */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((v = (*block)[natural_order[k]]) >= 0) {
|
if ((v = (*block)[natural_order[++k]]) >= 0) {
|
||||||
if (v >>= cinfo->Al) {
|
if (v >>= cinfo->Al) {
|
||||||
if (v >> 1) /* previously nonzero coef */
|
if (v >> 1) /* previously nonzero coef */
|
||||||
arith_encode(cinfo, st + 2, (v & 1));
|
arith_encode(cinfo, st + 2, (v & 1));
|
||||||
@@ -665,12 +672,13 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
arith_encode(cinfo, st + 1, 0); st += 3; k++;
|
arith_encode(cinfo, st + 1, 0);
|
||||||
|
st += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Encode EOB decision only if k <= cinfo->Se */
|
/* Encode EOB decision only if k < cinfo->Se */
|
||||||
if (k <= cinfo->Se) {
|
if (k < cinfo->Se) {
|
||||||
st = entropy->ac_stats[tbl] + 3 * (k - 1);
|
st = entropy->ac_stats[tbl] + 3 * k;
|
||||||
arith_encode(cinfo, st, 1);
|
arith_encode(cinfo, st, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,15 +691,16 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
jpeg_component_info * compptr;
|
const int * natural_order;
|
||||||
JBLOCKROW block;
|
JBLOCKROW block;
|
||||||
unsigned char *st;
|
unsigned char *st;
|
||||||
int blkn, ci, tbl, k, ke;
|
int tbl, k, ke;
|
||||||
int v, v2, m;
|
int v, v2, m;
|
||||||
const int * natural_order;
|
int blkn, ci;
|
||||||
|
jpeg_component_info * compptr;
|
||||||
|
|
||||||
/* Emit restart marker if needed */
|
/* Emit restart marker if needed */
|
||||||
if (cinfo->restart_interval) {
|
if (cinfo->restart_interval) {
|
||||||
@@ -765,18 +774,21 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
|
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
|
||||||
|
|
||||||
|
if ((ke = cinfo->lim_Se) == 0) continue;
|
||||||
tbl = compptr->ac_tbl_no;
|
tbl = compptr->ac_tbl_no;
|
||||||
|
|
||||||
/* Establish EOB (end-of-block) index */
|
/* Establish EOB (end-of-block) index */
|
||||||
for (ke = cinfo->lim_Se; ke > 0; ke--)
|
do {
|
||||||
if ((*block)[natural_order[ke]]) break;
|
if ((*block)[natural_order[ke]]) break;
|
||||||
|
} while (--ke);
|
||||||
|
|
||||||
/* Figure F.5: Encode_AC_Coefficients */
|
/* Figure F.5: Encode_AC_Coefficients */
|
||||||
for (k = 1; k <= ke; k++) {
|
for (k = 0; k < ke;) {
|
||||||
st = entropy->ac_stats[tbl] + 3 * (k - 1);
|
st = entropy->ac_stats[tbl] + 3 * k;
|
||||||
arith_encode(cinfo, st, 0); /* EOB decision */
|
arith_encode(cinfo, st, 0); /* EOB decision */
|
||||||
while ((v = (*block)[natural_order[k]]) == 0) {
|
while ((v = (*block)[natural_order[++k]]) == 0) {
|
||||||
arith_encode(cinfo, st + 1, 0); st += 3; k++;
|
arith_encode(cinfo, st + 1, 0);
|
||||||
|
st += 3;
|
||||||
}
|
}
|
||||||
arith_encode(cinfo, st + 1, 1);
|
arith_encode(cinfo, st + 1, 1);
|
||||||
/* Figure F.6: Encoding nonzero value v */
|
/* Figure F.6: Encoding nonzero value v */
|
||||||
@@ -812,9 +824,9 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
while (m >>= 1)
|
while (m >>= 1)
|
||||||
arith_encode(cinfo, st, (m & v) ? 1 : 0);
|
arith_encode(cinfo, st, (m & v) ? 1 : 0);
|
||||||
}
|
}
|
||||||
/* Encode EOB decision only if k <= cinfo->lim_Se */
|
/* Encode EOB decision only if k < cinfo->lim_Se */
|
||||||
if (k <= cinfo->lim_Se) {
|
if (k < cinfo->lim_Se) {
|
||||||
st = entropy->ac_stats[tbl] + 3 * (k - 1);
|
st = entropy->ac_stats[tbl] + 3 * k;
|
||||||
arith_encode(cinfo, st, 1);
|
arith_encode(cinfo, st, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -916,10 +928,9 @@ jinit_arith_encoder (j_compress_ptr cinfo)
|
|||||||
arith_entropy_ptr entropy;
|
arith_entropy_ptr entropy;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
entropy = (arith_entropy_ptr)
|
entropy = (arith_entropy_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(arith_entropy_encoder));
|
||||||
SIZEOF(arith_entropy_encoder));
|
cinfo->entropy = &entropy->pub;
|
||||||
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
|
|
||||||
entropy->pub.start_pass = start_pass;
|
entropy->pub.start_pass = start_pass;
|
||||||
entropy->pub.finish_pass = finish_pass;
|
entropy->pub.finish_pass = finish_pass;
|
||||||
|
|
||||||
|
|||||||
Vendored
+76
-73
@@ -2,6 +2,7 @@
|
|||||||
* jccoefct.c
|
* jccoefct.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||||
|
* Modified 2003-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -35,16 +36,14 @@ typedef struct {
|
|||||||
struct jpeg_c_coef_controller pub; /* public fields */
|
struct jpeg_c_coef_controller pub; /* public fields */
|
||||||
|
|
||||||
JDIMENSION iMCU_row_num; /* iMCU row # within image */
|
JDIMENSION iMCU_row_num; /* iMCU row # within image */
|
||||||
JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
|
JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
|
||||||
int MCU_vert_offset; /* counts MCU rows within iMCU row */
|
int MCU_vert_offset; /* counts MCU rows within iMCU row */
|
||||||
int MCU_rows_per_iMCU_row; /* number of such rows needed */
|
int MCU_rows_per_iMCU_row; /* number of such rows needed */
|
||||||
|
|
||||||
/* For single-pass compression, it's sufficient to buffer just one MCU
|
/* For single-pass compression, it's sufficient to buffer just one MCU
|
||||||
* (although this may prove a bit slow in practice). We allocate a
|
* (although this may prove a bit slow in practice). We append a
|
||||||
* workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each
|
* workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it
|
||||||
* MCU constructed and sent. (On 80x86, the workspace is FAR even though
|
* for each MCU constructed and sent.
|
||||||
* it's not really very big; this is to keep the module interfaces unchanged
|
|
||||||
* when a large coefficient buffer is necessary.)
|
|
||||||
* In multi-pass modes, this array points to the current MCU's blocks
|
* In multi-pass modes, this array points to the current MCU's blocks
|
||||||
* within the virtual arrays.
|
* within the virtual arrays.
|
||||||
*/
|
*/
|
||||||
@@ -52,6 +51,9 @@ typedef struct {
|
|||||||
|
|
||||||
/* In multi-pass modes, we need a virtual block array for each component. */
|
/* In multi-pass modes, we need a virtual block array for each component. */
|
||||||
jvirt_barray_ptr whole_image[MAX_COMPONENTS];
|
jvirt_barray_ptr whole_image[MAX_COMPONENTS];
|
||||||
|
|
||||||
|
/* Workspace for single-pass compression (omitted otherwise). */
|
||||||
|
JBLOCK blk_buffer[C_MAX_BLOCKS_IN_MCU];
|
||||||
} my_coef_controller;
|
} my_coef_controller;
|
||||||
|
|
||||||
typedef my_coef_controller * my_coef_ptr;
|
typedef my_coef_controller * my_coef_ptr;
|
||||||
@@ -87,7 +89,7 @@ start_iMCU_row (j_compress_ptr cinfo)
|
|||||||
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
|
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
coef->mcu_ctr = 0;
|
coef->MCU_ctr = 0;
|
||||||
coef->MCU_vert_offset = 0;
|
coef->MCU_vert_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +126,6 @@ start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
|||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,59 +147,56 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||||
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
|
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
|
||||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||||
int blkn, bi, ci, yindex, yoffset, blockcnt;
|
int ci, xindex, yindex, yoffset, blockcnt;
|
||||||
JDIMENSION ypos, xpos;
|
JBLOCKROW blkp;
|
||||||
|
JSAMPARRAY input_ptr;
|
||||||
|
JDIMENSION xpos;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
forward_DCT_ptr forward_DCT;
|
forward_DCT_ptr forward_DCT;
|
||||||
|
|
||||||
/* Loop to write as much as one whole iMCU row */
|
/* Loop to write as much as one whole iMCU row */
|
||||||
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
||||||
yoffset++) {
|
yoffset++) {
|
||||||
for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
|
for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
|
||||||
MCU_col_num++) {
|
MCU_col_num++) {
|
||||||
/* Determine where data comes from in input_buf and do the DCT thing.
|
/* Determine where data comes from in input_buf and do the DCT thing.
|
||||||
* Each call on forward_DCT processes a horizontal row of DCT blocks
|
* Each call on forward_DCT processes a horizontal row of DCT blocks as
|
||||||
* as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
|
* wide as an MCU. Dummy blocks at the right or bottom edge are filled in
|
||||||
* sequentially. Dummy blocks at the right or bottom edge are filled in
|
|
||||||
* specially. The data in them does not matter for image reconstruction,
|
* specially. The data in them does not matter for image reconstruction,
|
||||||
* so we fill them with values that will encode to the smallest amount of
|
* so we fill them with values that will encode to the smallest amount of
|
||||||
* data, viz: all zeroes in the AC entries, DC entries equal to previous
|
* data, viz: all zeroes in the AC entries, DC entries equal to previous
|
||||||
* block's DC value. (Thanks to Thomas Kinsman for this idea.)
|
* block's DC value. (Thanks to Thomas Kinsman for this idea.)
|
||||||
*/
|
*/
|
||||||
blkn = 0;
|
blkp = coef->blk_buffer; /* pointer to current DCT block within MCU */
|
||||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||||
compptr = cinfo->cur_comp_info[ci];
|
compptr = cinfo->cur_comp_info[ci];
|
||||||
forward_DCT = cinfo->fdct->forward_DCT[compptr->component_index];
|
forward_DCT = cinfo->fdct->forward_DCT[compptr->component_index];
|
||||||
|
input_ptr = input_buf[compptr->component_index] +
|
||||||
|
yoffset * compptr->DCT_v_scaled_size;
|
||||||
|
/* ypos == (yoffset + yindex) * compptr->DCT_v_scaled_size */
|
||||||
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
||||||
: compptr->last_col_width;
|
: compptr->last_col_width;
|
||||||
xpos = MCU_col_num * compptr->MCU_sample_width;
|
xpos = MCU_col_num * compptr->MCU_sample_width;
|
||||||
ypos = yoffset * compptr->DCT_v_scaled_size;
|
|
||||||
/* ypos == (yoffset+yindex) * DCTSIZE */
|
|
||||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||||
if (coef->iMCU_row_num < last_iMCU_row ||
|
if (coef->iMCU_row_num < last_iMCU_row ||
|
||||||
yoffset+yindex < compptr->last_row_height) {
|
yoffset + yindex < compptr->last_row_height) {
|
||||||
(*forward_DCT) (cinfo, compptr,
|
(*forward_DCT) (cinfo, compptr, input_ptr, blkp,
|
||||||
input_buf[compptr->component_index],
|
xpos, (JDIMENSION) blockcnt);
|
||||||
coef->MCU_buffer[blkn],
|
input_ptr += compptr->DCT_v_scaled_size;
|
||||||
ypos, xpos, (JDIMENSION) blockcnt);
|
blkp += blockcnt;
|
||||||
if (blockcnt < compptr->MCU_width) {
|
/* Dummy blocks at right edge */
|
||||||
/* Create some dummy blocks at the right edge of the image. */
|
if ((xindex = compptr->MCU_width - blockcnt) == 0)
|
||||||
jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
|
continue;
|
||||||
(compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
|
|
||||||
for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
|
|
||||||
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* Create a row of dummy blocks at the bottom of the image. */
|
/* At bottom of image, need a whole row of dummy blocks */
|
||||||
jzero_far((void FAR *) coef->MCU_buffer[blkn],
|
xindex = compptr->MCU_width;
|
||||||
compptr->MCU_width * SIZEOF(JBLOCK));
|
|
||||||
for (bi = 0; bi < compptr->MCU_width; bi++) {
|
|
||||||
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
blkn += compptr->MCU_width;
|
/* Fill in any dummy blocks needed in this row */
|
||||||
ypos += compptr->DCT_v_scaled_size;
|
MEMZERO(blkp, xindex * SIZEOF(JBLOCK));
|
||||||
|
do {
|
||||||
|
blkp[0][0] = blkp[-1][0];
|
||||||
|
blkp++;
|
||||||
|
} while (--xindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Try to write the MCU. In event of a suspension failure, we will
|
/* Try to write the MCU. In event of a suspension failure, we will
|
||||||
@@ -207,12 +205,12 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
|
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
|
||||||
/* Suspension forced; update state counters and exit */
|
/* Suspension forced; update state counters and exit */
|
||||||
coef->MCU_vert_offset = yoffset;
|
coef->MCU_vert_offset = yoffset;
|
||||||
coef->mcu_ctr = MCU_col_num;
|
coef->MCU_ctr = MCU_col_num;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||||
coef->mcu_ctr = 0;
|
coef->MCU_ctr = 0;
|
||||||
}
|
}
|
||||||
/* Completed the iMCU row, advance counters for next one */
|
/* Completed the iMCU row, advance counters for next one */
|
||||||
coef->iMCU_row_num++;
|
coef->iMCU_row_num++;
|
||||||
@@ -255,6 +253,7 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
JBLOCKARRAY buffer;
|
JBLOCKARRAY buffer;
|
||||||
JBLOCKROW thisblockrow, lastblockrow;
|
JBLOCKROW thisblockrow, lastblockrow;
|
||||||
|
JSAMPARRAY input_ptr;
|
||||||
forward_DCT_ptr forward_DCT;
|
forward_DCT_ptr forward_DCT;
|
||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
@@ -279,18 +278,19 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
if (ndummy > 0)
|
if (ndummy > 0)
|
||||||
ndummy = h_samp_factor - ndummy;
|
ndummy = h_samp_factor - ndummy;
|
||||||
forward_DCT = cinfo->fdct->forward_DCT[ci];
|
forward_DCT = cinfo->fdct->forward_DCT[ci];
|
||||||
|
input_ptr = input_buf[ci];
|
||||||
/* Perform DCT for all non-dummy blocks in this iMCU row. Each call
|
/* Perform DCT for all non-dummy blocks in this iMCU row. Each call
|
||||||
* on forward_DCT processes a complete horizontal row of DCT blocks.
|
* on forward_DCT processes a complete horizontal row of DCT blocks.
|
||||||
*/
|
*/
|
||||||
for (block_row = 0; block_row < block_rows; block_row++) {
|
for (block_row = 0; block_row < block_rows; block_row++) {
|
||||||
thisblockrow = buffer[block_row];
|
thisblockrow = buffer[block_row];
|
||||||
(*forward_DCT) (cinfo, compptr, input_buf[ci], thisblockrow,
|
(*forward_DCT) (cinfo, compptr, input_ptr, thisblockrow,
|
||||||
(JDIMENSION) (block_row * compptr->DCT_v_scaled_size),
|
|
||||||
(JDIMENSION) 0, blocks_across);
|
(JDIMENSION) 0, blocks_across);
|
||||||
|
input_ptr += compptr->DCT_v_scaled_size;
|
||||||
if (ndummy > 0) {
|
if (ndummy > 0) {
|
||||||
/* Create dummy blocks at the right edge of the image. */
|
/* Create dummy blocks at the right edge of the image. */
|
||||||
thisblockrow += blocks_across; /* => first dummy block */
|
thisblockrow += blocks_across; /* => first dummy block */
|
||||||
jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
|
FMEMZERO((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
|
||||||
lastDC = thisblockrow[-1][0];
|
lastDC = thisblockrow[-1][0];
|
||||||
for (bi = 0; bi < ndummy; bi++) {
|
for (bi = 0; bi < ndummy; bi++) {
|
||||||
thisblockrow[bi][0] = lastDC;
|
thisblockrow[bi][0] = lastDC;
|
||||||
@@ -302,15 +302,14 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
* of the dummy blocks to match the last real block's DC value.
|
* of the dummy blocks to match the last real block's DC value.
|
||||||
* This squeezes a few more bytes out of the resulting file...
|
* This squeezes a few more bytes out of the resulting file...
|
||||||
*/
|
*/
|
||||||
if (coef->iMCU_row_num == last_iMCU_row) {
|
if (block_row < compptr->v_samp_factor) {
|
||||||
blocks_across += ndummy; /* include lower right corner */
|
blocks_across += ndummy; /* include lower right corner */
|
||||||
MCUs_across = blocks_across / h_samp_factor;
|
MCUs_across = blocks_across / h_samp_factor;
|
||||||
for (block_row = block_rows; block_row < compptr->v_samp_factor;
|
do {
|
||||||
block_row++) {
|
|
||||||
thisblockrow = buffer[block_row];
|
thisblockrow = buffer[block_row];
|
||||||
lastblockrow = buffer[block_row-1];
|
lastblockrow = buffer[block_row-1];
|
||||||
jzero_far((void FAR *) thisblockrow,
|
FMEMZERO((void FAR *) thisblockrow,
|
||||||
(size_t) (blocks_across * SIZEOF(JBLOCK)));
|
(size_t) blocks_across * SIZEOF(JBLOCK));
|
||||||
for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
|
for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
|
||||||
lastDC = lastblockrow[h_samp_factor-1][0];
|
lastDC = lastblockrow[h_samp_factor-1][0];
|
||||||
for (bi = 0; bi < h_samp_factor; bi++) {
|
for (bi = 0; bi < h_samp_factor; bi++) {
|
||||||
@@ -319,7 +318,7 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
thisblockrow += h_samp_factor; /* advance to next MCU in row */
|
thisblockrow += h_samp_factor; /* advance to next MCU in row */
|
||||||
lastblockrow += h_samp_factor;
|
lastblockrow += h_samp_factor;
|
||||||
}
|
}
|
||||||
}
|
} while (++block_row < compptr->v_samp_factor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* NB: compress_output will increment iMCU_row_num if successful.
|
/* NB: compress_output will increment iMCU_row_num if successful.
|
||||||
@@ -346,8 +345,9 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
{
|
{
|
||||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||||
int blkn, ci, xindex, yindex, yoffset;
|
int ci, xindex, yindex, yoffset;
|
||||||
JDIMENSION start_col;
|
JDIMENSION start_col;
|
||||||
|
JBLOCKARRAY blkp;
|
||||||
JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
|
JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
|
||||||
JBLOCKROW buffer_ptr;
|
JBLOCKROW buffer_ptr;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
@@ -367,30 +367,31 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
/* Loop to process one whole iMCU row */
|
/* Loop to process one whole iMCU row */
|
||||||
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
||||||
yoffset++) {
|
yoffset++) {
|
||||||
for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
|
for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
|
||||||
MCU_col_num++) {
|
MCU_col_num++) {
|
||||||
/* Construct list of pointers to DCT blocks belonging to this MCU */
|
/* Construct list of pointers to DCT blocks belonging to this MCU */
|
||||||
blkn = 0; /* index of current DCT block within MCU */
|
blkp = coef->MCU_buffer; /* pointer to current DCT block within MCU */
|
||||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||||
compptr = cinfo->cur_comp_info[ci];
|
compptr = cinfo->cur_comp_info[ci];
|
||||||
start_col = MCU_col_num * compptr->MCU_width;
|
start_col = MCU_col_num * compptr->MCU_width;
|
||||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||||
buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
|
buffer_ptr = buffer[ci][yoffset + yindex] + start_col;
|
||||||
for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
|
xindex = compptr->MCU_width;
|
||||||
coef->MCU_buffer[blkn++] = buffer_ptr++;
|
do {
|
||||||
}
|
*blkp++ = buffer_ptr++;
|
||||||
|
} while (--xindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Try to write the MCU. */
|
/* Try to write the MCU. */
|
||||||
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
|
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
|
||||||
/* Suspension forced; update state counters and exit */
|
/* Suspension forced; update state counters and exit */
|
||||||
coef->MCU_vert_offset = yoffset;
|
coef->MCU_vert_offset = yoffset;
|
||||||
coef->mcu_ctr = MCU_col_num;
|
coef->MCU_ctr = MCU_col_num;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||||
coef->mcu_ctr = 0;
|
coef->MCU_ctr = 0;
|
||||||
}
|
}
|
||||||
/* Completed the iMCU row, advance counters for next one */
|
/* Completed the iMCU row, advance counters for next one */
|
||||||
coef->iMCU_row_num++;
|
coef->iMCU_row_num++;
|
||||||
@@ -410,13 +411,6 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
|||||||
{
|
{
|
||||||
my_coef_ptr coef;
|
my_coef_ptr coef;
|
||||||
|
|
||||||
coef = (my_coef_ptr)
|
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
||||||
SIZEOF(my_coef_controller));
|
|
||||||
cinfo->coef = (struct jpeg_c_coef_controller *) coef;
|
|
||||||
coef->pub.start_pass = start_pass_coef;
|
|
||||||
|
|
||||||
/* Create the coefficient buffer. */
|
|
||||||
if (need_full_buffer) {
|
if (need_full_buffer) {
|
||||||
#ifdef FULL_COEF_BUFFER_SUPPORTED
|
#ifdef FULL_COEF_BUFFER_SUPPORTED
|
||||||
/* Allocate a full-image virtual array for each component, */
|
/* Allocate a full-image virtual array for each component, */
|
||||||
@@ -424,6 +418,9 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
|||||||
int ci;
|
int ci;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
|
|
||||||
|
coef = (my_coef_ptr) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
|
SIZEOF(my_coef_controller) - SIZEOF(coef->blk_buffer));
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
|
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
|
||||||
@@ -439,15 +436,21 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* We only need a single-MCU buffer. */
|
/* We only need a single-MCU buffer. */
|
||||||
JBLOCKROW buffer;
|
JBLOCKARRAY blkp;
|
||||||
int i;
|
JBLOCKROW buffer_ptr;
|
||||||
|
int bi;
|
||||||
|
|
||||||
buffer = (JBLOCKROW)
|
coef = (my_coef_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_coef_controller));
|
||||||
C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
blkp = coef->MCU_buffer;
|
||||||
for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
|
buffer_ptr = coef->blk_buffer;
|
||||||
coef->MCU_buffer[i] = buffer + i;
|
bi = C_MAX_BLOCKS_IN_MCU;
|
||||||
}
|
do {
|
||||||
|
*blkp++ = buffer_ptr++;
|
||||||
|
} while (--bi);
|
||||||
coef->whole_image[0] = NULL; /* flag for no virtual arrays */
|
coef->whole_image[0] = NULL; /* flag for no virtual arrays */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coef->pub.start_pass = start_pass_coef;
|
||||||
|
cinfo->coef = &coef->pub;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+208
-66
@@ -2,6 +2,7 @@
|
|||||||
* jccolor.c
|
* jccolor.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||||
|
* Modified 2011-2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -28,13 +29,25 @@ typedef my_color_converter * my_cconvert_ptr;
|
|||||||
/**************** RGB -> YCbCr conversion: most common case **************/
|
/**************** RGB -> YCbCr conversion: most common case **************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are
|
* YCbCr is defined per Recommendation ITU-R BT.601-7 (03/2011),
|
||||||
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
|
* previously known as Recommendation CCIR 601-1, except that Cb and Cr
|
||||||
* The conversion equations to be implemented are therefore
|
* are normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
|
||||||
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
|
* sRGB (standard RGB color space) is defined per IEC 61966-2-1:1999.
|
||||||
* Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
|
* sYCC (standard luma-chroma-chroma color space with extended gamut)
|
||||||
* Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
|
* is defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex F.
|
||||||
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
|
* bg-sRGB and bg-sYCC (big gamut standard color spaces)
|
||||||
|
* are defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex G.
|
||||||
|
* Note that the derived conversion coefficients given in some of these
|
||||||
|
* documents are imprecise. The general conversion equations are
|
||||||
|
* Y = Kr * R + (1 - Kr - Kb) * G + Kb * B
|
||||||
|
* Cb = 0.5 * (B - Y) / (1 - Kb)
|
||||||
|
* Cr = 0.5 * (R - Y) / (1 - Kr)
|
||||||
|
* With Kr = 0.299 and Kb = 0.114 (derived according to SMPTE RP 177-1993
|
||||||
|
* from the 1953 FCC NTSC primaries and CIE Illuminant C),
|
||||||
|
* the conversion equations to be implemented are therefore
|
||||||
|
* Y = 0.299 * R + 0.587 * G + 0.114 * B
|
||||||
|
* Cb = -0.168735892 * R - 0.331264108 * G + 0.5 * B + CENTERJSAMPLE
|
||||||
|
* Cr = 0.5 * R - 0.418687589 * G - 0.081312411 * B + CENTERJSAMPLE
|
||||||
* Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
|
* Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
|
||||||
* rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
|
* rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
|
||||||
* negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
|
* negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
|
||||||
@@ -48,9 +61,9 @@ typedef my_color_converter * my_cconvert_ptr;
|
|||||||
* For even more speed, we avoid doing any multiplications in the inner loop
|
* For even more speed, we avoid doing any multiplications in the inner loop
|
||||||
* by precalculating the constants times R,G,B for all possible values.
|
* by precalculating the constants times R,G,B for all possible values.
|
||||||
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
|
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
|
||||||
* for 12-bit samples it is still acceptable. It's not very reasonable for
|
* for 9-bit to 12-bit samples it is still acceptable. It's not very
|
||||||
* 16-bit samples, but if you want lossless storage you shouldn't be changing
|
* reasonable for 16-bit samples, but if you want lossless storage you
|
||||||
* colorspace anyway.
|
* shouldn't be changing colorspace anyway.
|
||||||
* The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
|
* The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
|
||||||
* in the tables to save adding them separately in the inner loop.
|
* in the tables to save adding them separately in the inner loop.
|
||||||
*/
|
*/
|
||||||
@@ -92,24 +105,24 @@ rgb_ycc_start (j_compress_ptr cinfo)
|
|||||||
/* Allocate and fill in the conversion tables. */
|
/* Allocate and fill in the conversion tables. */
|
||||||
cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
|
cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
(TABLE_SIZE * SIZEOF(INT32)));
|
TABLE_SIZE * SIZEOF(INT32));
|
||||||
|
|
||||||
for (i = 0; i <= MAXJSAMPLE; i++) {
|
for (i = 0; i <= MAXJSAMPLE; i++) {
|
||||||
rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
|
rgb_ycc_tab[i+R_Y_OFF] = FIX(0.299) * i;
|
||||||
rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
|
rgb_ycc_tab[i+G_Y_OFF] = FIX(0.587) * i;
|
||||||
rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
|
rgb_ycc_tab[i+B_Y_OFF] = FIX(0.114) * i + ONE_HALF;
|
||||||
rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
|
rgb_ycc_tab[i+R_CB_OFF] = (- FIX(0.168735892)) * i;
|
||||||
rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
|
rgb_ycc_tab[i+G_CB_OFF] = (- FIX(0.331264108)) * i;
|
||||||
/* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
|
/* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
|
||||||
* This ensures that the maximum output will round to MAXJSAMPLE
|
* This ensures that the maximum output will round to MAXJSAMPLE
|
||||||
* not MAXJSAMPLE+1, and thus that we don't have to range-limit.
|
* not MAXJSAMPLE+1, and thus that we don't have to range-limit.
|
||||||
*/
|
*/
|
||||||
rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
|
rgb_ycc_tab[i+B_CB_OFF] = FIX(0.5) * i + CBCR_OFFSET + ONE_HALF-1;
|
||||||
/* B=>Cb and R=>Cr tables are the same
|
/* B=>Cb and R=>Cr tables are the same
|
||||||
rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
|
rgb_ycc_tab[i+R_CR_OFF] = FIX(0.5) * i + CBCR_OFFSET + ONE_HALF-1;
|
||||||
*/
|
*/
|
||||||
rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
|
rgb_ycc_tab[i+G_CR_OFF] = (- FIX(0.418687589)) * i;
|
||||||
rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
|
rgb_ycc_tab[i+B_CR_OFF] = (- FIX(0.081312411)) * i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,12 +131,12 @@ rgb_ycc_start (j_compress_ptr cinfo)
|
|||||||
* Convert some rows of samples to the JPEG colorspace.
|
* Convert some rows of samples to the JPEG colorspace.
|
||||||
*
|
*
|
||||||
* Note that we change from the application's interleaved-pixel format
|
* Note that we change from the application's interleaved-pixel format
|
||||||
* to our internal noninterleaved, one-plane-per-component format.
|
* to our internal noninterleaved, one-plane-per-component format. The
|
||||||
* The input buffer is therefore three times as wide as the output buffer.
|
* input buffer is therefore three times as wide as the output buffer.
|
||||||
*
|
*
|
||||||
* A starting row offset is provided only for the output buffer. The caller
|
* A starting row offset is provided only for the output buffer. The
|
||||||
* can easily adjust the passed input_buf value to accommodate any row
|
* caller can easily adjust the passed input_buf value to accommodate
|
||||||
* offset required on that side.
|
* any row offset required on that side.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
@@ -197,8 +210,7 @@ rgb_gray_convert (j_compress_ptr cinfo,
|
|||||||
|
|
||||||
while (--num_rows >= 0) {
|
while (--num_rows >= 0) {
|
||||||
inptr = *input_buf++;
|
inptr = *input_buf++;
|
||||||
outptr = output_buf[0][output_row];
|
outptr = output_buf[0][output_row++];
|
||||||
output_row++;
|
|
||||||
for (col = 0; col < num_cols; col++) {
|
for (col = 0; col < num_cols; col++) {
|
||||||
r = GETJSAMPLE(inptr[RGB_RED]);
|
r = GETJSAMPLE(inptr[RGB_RED]);
|
||||||
g = GETJSAMPLE(inptr[RGB_GREEN]);
|
g = GETJSAMPLE(inptr[RGB_GREEN]);
|
||||||
@@ -216,8 +228,8 @@ rgb_gray_convert (j_compress_ptr cinfo,
|
|||||||
/*
|
/*
|
||||||
* Convert some rows of samples to the JPEG colorspace.
|
* Convert some rows of samples to the JPEG colorspace.
|
||||||
* This version handles Adobe-style CMYK->YCCK conversion,
|
* This version handles Adobe-style CMYK->YCCK conversion,
|
||||||
* where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
|
* where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the
|
||||||
* conversion as above, while passing K (black) unchanged.
|
* same conversion as above, while passing K (black) unchanged.
|
||||||
* We assume rgb_ycc_start has been called.
|
* We assume rgb_ycc_start has been called.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -270,10 +282,52 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert some rows of samples to the JPEG colorspace.
|
||||||
|
* [R,G,B] to [R-G,G,B-G] conversion with modulo calculation
|
||||||
|
* (forward reversible color transform).
|
||||||
|
* This can be seen as an adaption of the general RGB->YCbCr
|
||||||
|
* conversion equation with Kr = Kb = 0, while replacing the
|
||||||
|
* normalization by modulo calculation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
METHODDEF(void)
|
||||||
|
rgb_rgb1_convert (j_compress_ptr cinfo,
|
||||||
|
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||||
|
JDIMENSION output_row, int num_rows)
|
||||||
|
{
|
||||||
|
register int r, g, b;
|
||||||
|
register JSAMPROW inptr;
|
||||||
|
register JSAMPROW outptr0, outptr1, outptr2;
|
||||||
|
register JDIMENSION col;
|
||||||
|
JDIMENSION num_cols = cinfo->image_width;
|
||||||
|
|
||||||
|
while (--num_rows >= 0) {
|
||||||
|
inptr = *input_buf++;
|
||||||
|
outptr0 = output_buf[0][output_row];
|
||||||
|
outptr1 = output_buf[1][output_row];
|
||||||
|
outptr2 = output_buf[2][output_row];
|
||||||
|
output_row++;
|
||||||
|
for (col = 0; col < num_cols; col++) {
|
||||||
|
r = GETJSAMPLE(inptr[RGB_RED]);
|
||||||
|
g = GETJSAMPLE(inptr[RGB_GREEN]);
|
||||||
|
b = GETJSAMPLE(inptr[RGB_BLUE]);
|
||||||
|
inptr += RGB_PIXELSIZE;
|
||||||
|
/* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD
|
||||||
|
* (modulo) operator is equivalent to the bitmask operator AND.
|
||||||
|
*/
|
||||||
|
outptr0[col] = (JSAMPLE) ((r - g + CENTERJSAMPLE) & MAXJSAMPLE);
|
||||||
|
outptr1[col] = (JSAMPLE) g;
|
||||||
|
outptr2[col] = (JSAMPLE) ((b - g + CENTERJSAMPLE) & MAXJSAMPLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convert some rows of samples to the JPEG colorspace.
|
* Convert some rows of samples to the JPEG colorspace.
|
||||||
* This version handles grayscale output with no conversion.
|
* This version handles grayscale output with no conversion.
|
||||||
* The source can be either plain grayscale or YCbCr (since Y == gray).
|
* The source can be either plain grayscale or YCC (since Y == gray).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
@@ -283,17 +337,49 @@ grayscale_convert (j_compress_ptr cinfo,
|
|||||||
{
|
{
|
||||||
register JSAMPROW inptr;
|
register JSAMPROW inptr;
|
||||||
register JSAMPROW outptr;
|
register JSAMPROW outptr;
|
||||||
register JDIMENSION col;
|
register JDIMENSION count;
|
||||||
|
register int instride = cinfo->input_components;
|
||||||
JDIMENSION num_cols = cinfo->image_width;
|
JDIMENSION num_cols = cinfo->image_width;
|
||||||
int instride = cinfo->input_components;
|
|
||||||
|
|
||||||
while (--num_rows >= 0) {
|
while (--num_rows >= 0) {
|
||||||
inptr = *input_buf++;
|
inptr = *input_buf++;
|
||||||
outptr = output_buf[0][output_row];
|
outptr = output_buf[0][output_row++];
|
||||||
|
for (count = num_cols; count > 0; count--) {
|
||||||
|
*outptr++ = *inptr; /* don't need GETJSAMPLE() here */
|
||||||
|
inptr += instride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert some rows of samples to the JPEG colorspace.
|
||||||
|
* No colorspace conversion, but change from interleaved
|
||||||
|
* to separate-planes representation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
METHODDEF(void)
|
||||||
|
rgb_convert (j_compress_ptr cinfo,
|
||||||
|
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||||
|
JDIMENSION output_row, int num_rows)
|
||||||
|
{
|
||||||
|
register JSAMPROW inptr;
|
||||||
|
register JSAMPROW outptr0, outptr1, outptr2;
|
||||||
|
register JDIMENSION col;
|
||||||
|
JDIMENSION num_cols = cinfo->image_width;
|
||||||
|
|
||||||
|
while (--num_rows >= 0) {
|
||||||
|
inptr = *input_buf++;
|
||||||
|
outptr0 = output_buf[0][output_row];
|
||||||
|
outptr1 = output_buf[1][output_row];
|
||||||
|
outptr2 = output_buf[2][output_row];
|
||||||
output_row++;
|
output_row++;
|
||||||
for (col = 0; col < num_cols; col++) {
|
for (col = 0; col < num_cols; col++) {
|
||||||
outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
|
/* We can dispense with GETJSAMPLE() here */
|
||||||
inptr += instride;
|
outptr0[col] = inptr[RGB_RED];
|
||||||
|
outptr1[col] = inptr[RGB_GREEN];
|
||||||
|
outptr2[col] = inptr[RGB_BLUE];
|
||||||
|
inptr += RGB_PIXELSIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,19 +398,19 @@ null_convert (j_compress_ptr cinfo,
|
|||||||
{
|
{
|
||||||
register JSAMPROW inptr;
|
register JSAMPROW inptr;
|
||||||
register JSAMPROW outptr;
|
register JSAMPROW outptr;
|
||||||
register JDIMENSION col;
|
register JDIMENSION count;
|
||||||
register int ci;
|
register int num_comps = cinfo->num_components;
|
||||||
int nc = cinfo->num_components;
|
|
||||||
JDIMENSION num_cols = cinfo->image_width;
|
JDIMENSION num_cols = cinfo->image_width;
|
||||||
|
int ci;
|
||||||
|
|
||||||
while (--num_rows >= 0) {
|
while (--num_rows >= 0) {
|
||||||
/* It seems fastest to make a separate pass for each component. */
|
/* It seems fastest to make a separate pass for each component. */
|
||||||
for (ci = 0; ci < nc; ci++) {
|
for (ci = 0; ci < num_comps; ci++) {
|
||||||
inptr = *input_buf;
|
inptr = input_buf[0] + ci;
|
||||||
outptr = output_buf[ci][output_row];
|
outptr = output_buf[ci][output_row];
|
||||||
for (col = 0; col < num_cols; col++) {
|
for (count = num_cols; count > 0; count--) {
|
||||||
outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
|
*outptr++ = *inptr; /* don't need GETJSAMPLE() here */
|
||||||
inptr += nc;
|
inptr += num_comps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
input_buf++;
|
input_buf++;
|
||||||
@@ -353,10 +439,9 @@ jinit_color_converter (j_compress_ptr cinfo)
|
|||||||
{
|
{
|
||||||
my_cconvert_ptr cconvert;
|
my_cconvert_ptr cconvert;
|
||||||
|
|
||||||
cconvert = (my_cconvert_ptr)
|
cconvert = (my_cconvert_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_color_converter));
|
||||||
SIZEOF(my_color_converter));
|
cinfo->cconvert = &cconvert->pub;
|
||||||
cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
|
|
||||||
/* set start_pass to null method until we find out differently */
|
/* set start_pass to null method until we find out differently */
|
||||||
cconvert->pub.start_pass = null_method;
|
cconvert->pub.start_pass = null_method;
|
||||||
|
|
||||||
@@ -368,6 +453,7 @@ jinit_color_converter (j_compress_ptr cinfo)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case JCS_RGB:
|
case JCS_RGB:
|
||||||
|
case JCS_BG_RGB:
|
||||||
#if RGB_PIXELSIZE != 3
|
#if RGB_PIXELSIZE != 3
|
||||||
if (cinfo->input_components != RGB_PIXELSIZE)
|
if (cinfo->input_components != RGB_PIXELSIZE)
|
||||||
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
||||||
@@ -375,6 +461,7 @@ jinit_color_converter (j_compress_ptr cinfo)
|
|||||||
#endif /* else share code with YCbCr */
|
#endif /* else share code with YCbCr */
|
||||||
|
|
||||||
case JCS_YCbCr:
|
case JCS_YCbCr:
|
||||||
|
case JCS_BG_YCC:
|
||||||
if (cinfo->input_components != 3)
|
if (cinfo->input_components != 3)
|
||||||
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
||||||
break;
|
break;
|
||||||
@@ -388,65 +475,121 @@ jinit_color_converter (j_compress_ptr cinfo)
|
|||||||
default: /* JCS_UNKNOWN can be anything */
|
default: /* JCS_UNKNOWN can be anything */
|
||||||
if (cinfo->input_components < 1)
|
if (cinfo->input_components < 1)
|
||||||
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Support color transform only for RGB colorspaces */
|
||||||
|
if (cinfo->color_transform &&
|
||||||
|
cinfo->jpeg_color_space != JCS_RGB &&
|
||||||
|
cinfo->jpeg_color_space != JCS_BG_RGB)
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
|
||||||
/* Check num_components, set conversion method based on requested space */
|
/* Check num_components, set conversion method based on requested space */
|
||||||
switch (cinfo->jpeg_color_space) {
|
switch (cinfo->jpeg_color_space) {
|
||||||
case JCS_GRAYSCALE:
|
case JCS_GRAYSCALE:
|
||||||
if (cinfo->num_components != 1)
|
if (cinfo->num_components != 1)
|
||||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||||
if (cinfo->in_color_space == JCS_GRAYSCALE)
|
switch (cinfo->in_color_space) {
|
||||||
|
case JCS_GRAYSCALE:
|
||||||
|
case JCS_YCbCr:
|
||||||
|
case JCS_BG_YCC:
|
||||||
cconvert->pub.color_convert = grayscale_convert;
|
cconvert->pub.color_convert = grayscale_convert;
|
||||||
else if (cinfo->in_color_space == JCS_RGB) {
|
break;
|
||||||
|
case JCS_RGB:
|
||||||
cconvert->pub.start_pass = rgb_ycc_start;
|
cconvert->pub.start_pass = rgb_ycc_start;
|
||||||
cconvert->pub.color_convert = rgb_gray_convert;
|
cconvert->pub.color_convert = rgb_gray_convert;
|
||||||
} else if (cinfo->in_color_space == JCS_YCbCr)
|
break;
|
||||||
cconvert->pub.color_convert = grayscale_convert;
|
default:
|
||||||
else
|
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JCS_RGB:
|
case JCS_RGB:
|
||||||
|
case JCS_BG_RGB:
|
||||||
if (cinfo->num_components != 3)
|
if (cinfo->num_components != 3)
|
||||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||||
if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
|
if (cinfo->in_color_space != cinfo->jpeg_color_space)
|
||||||
cconvert->pub.color_convert = null_convert;
|
|
||||||
else
|
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
switch (cinfo->color_transform) {
|
||||||
|
case JCT_NONE:
|
||||||
|
cconvert->pub.color_convert = rgb_convert;
|
||||||
|
break;
|
||||||
|
case JCT_SUBTRACT_GREEN:
|
||||||
|
cconvert->pub.color_convert = rgb_rgb1_convert;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JCS_YCbCr:
|
case JCS_YCbCr:
|
||||||
if (cinfo->num_components != 3)
|
if (cinfo->num_components != 3)
|
||||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||||
if (cinfo->in_color_space == JCS_RGB) {
|
switch (cinfo->in_color_space) {
|
||||||
|
case JCS_RGB:
|
||||||
cconvert->pub.start_pass = rgb_ycc_start;
|
cconvert->pub.start_pass = rgb_ycc_start;
|
||||||
cconvert->pub.color_convert = rgb_ycc_convert;
|
cconvert->pub.color_convert = rgb_ycc_convert;
|
||||||
} else if (cinfo->in_color_space == JCS_YCbCr)
|
break;
|
||||||
|
case JCS_YCbCr:
|
||||||
cconvert->pub.color_convert = null_convert;
|
cconvert->pub.color_convert = null_convert;
|
||||||
else
|
break;
|
||||||
|
default:
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JCS_BG_YCC:
|
||||||
|
if (cinfo->num_components != 3)
|
||||||
|
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||||
|
switch (cinfo->in_color_space) {
|
||||||
|
case JCS_RGB:
|
||||||
|
/* For conversion from normal RGB input to BG_YCC representation,
|
||||||
|
* the Cb/Cr values are first computed as usual, and then
|
||||||
|
* quantized further after DCT processing by a factor of
|
||||||
|
* 2 in reference to the nominal quantization factor.
|
||||||
|
*/
|
||||||
|
/* need quantization scale by factor of 2 after DCT */
|
||||||
|
cinfo->comp_info[1].component_needed = TRUE;
|
||||||
|
cinfo->comp_info[2].component_needed = TRUE;
|
||||||
|
/* compute normal YCC first */
|
||||||
|
cconvert->pub.start_pass = rgb_ycc_start;
|
||||||
|
cconvert->pub.color_convert = rgb_ycc_convert;
|
||||||
|
break;
|
||||||
|
case JCS_YCbCr:
|
||||||
|
/* need quantization scale by factor of 2 after DCT */
|
||||||
|
cinfo->comp_info[1].component_needed = TRUE;
|
||||||
|
cinfo->comp_info[2].component_needed = TRUE;
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
case JCS_BG_YCC:
|
||||||
|
/* Pass through for BG_YCC input */
|
||||||
|
cconvert->pub.color_convert = null_convert;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JCS_CMYK:
|
case JCS_CMYK:
|
||||||
if (cinfo->num_components != 4)
|
if (cinfo->num_components != 4)
|
||||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||||
if (cinfo->in_color_space == JCS_CMYK)
|
if (cinfo->in_color_space != JCS_CMYK)
|
||||||
cconvert->pub.color_convert = null_convert;
|
|
||||||
else
|
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
cconvert->pub.color_convert = null_convert;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JCS_YCCK:
|
case JCS_YCCK:
|
||||||
if (cinfo->num_components != 4)
|
if (cinfo->num_components != 4)
|
||||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||||
if (cinfo->in_color_space == JCS_CMYK) {
|
switch (cinfo->in_color_space) {
|
||||||
|
case JCS_CMYK:
|
||||||
cconvert->pub.start_pass = rgb_ycc_start;
|
cconvert->pub.start_pass = rgb_ycc_start;
|
||||||
cconvert->pub.color_convert = cmyk_ycck_convert;
|
cconvert->pub.color_convert = cmyk_ycck_convert;
|
||||||
} else if (cinfo->in_color_space == JCS_YCCK)
|
break;
|
||||||
|
case JCS_YCCK:
|
||||||
cconvert->pub.color_convert = null_convert;
|
cconvert->pub.color_convert = null_convert;
|
||||||
else
|
break;
|
||||||
|
default:
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: /* allow null conversion of JCS_UNKNOWN */
|
default: /* allow null conversion of JCS_UNKNOWN */
|
||||||
@@ -454,6 +597,5 @@ jinit_color_converter (j_compress_ptr cinfo)
|
|||||||
cinfo->num_components != cinfo->input_components)
|
cinfo->num_components != cinfo->input_components)
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
cconvert->pub.color_convert = null_convert;
|
cconvert->pub.color_convert = null_convert;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+42
-58
@@ -2,6 +2,7 @@
|
|||||||
* jcdctmgr.c
|
* jcdctmgr.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
|
* Modified 2003-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -25,22 +26,30 @@ typedef struct {
|
|||||||
/* Pointer to the DCT routine actually in use */
|
/* Pointer to the DCT routine actually in use */
|
||||||
forward_DCT_method_ptr do_dct[MAX_COMPONENTS];
|
forward_DCT_method_ptr do_dct[MAX_COMPONENTS];
|
||||||
|
|
||||||
/* The actual post-DCT divisors --- not identical to the quant table
|
|
||||||
* entries, because of scaling (especially for an unnormalized DCT).
|
|
||||||
* Each table is given in normal array order.
|
|
||||||
*/
|
|
||||||
DCTELEM * divisors[NUM_QUANT_TBLS];
|
|
||||||
|
|
||||||
#ifdef DCT_FLOAT_SUPPORTED
|
#ifdef DCT_FLOAT_SUPPORTED
|
||||||
/* Same as above for the floating-point case. */
|
/* Same as above for the floating-point case. */
|
||||||
float_DCT_method_ptr do_float_dct[MAX_COMPONENTS];
|
float_DCT_method_ptr do_float_dct[MAX_COMPONENTS];
|
||||||
FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
|
|
||||||
#endif
|
#endif
|
||||||
} my_fdct_controller;
|
} my_fdct_controller;
|
||||||
|
|
||||||
typedef my_fdct_controller * my_fdct_ptr;
|
typedef my_fdct_controller * my_fdct_ptr;
|
||||||
|
|
||||||
|
|
||||||
|
/* The allocated post-DCT divisor tables -- big enough for any
|
||||||
|
* supported variant and not identical to the quant table entries,
|
||||||
|
* because of scaling (especially for an unnormalized DCT) --
|
||||||
|
* are pointed to by dct_table in the per-component comp_info
|
||||||
|
* structures. Each table is given in normal array order.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
DCTELEM int_array[DCTSIZE2];
|
||||||
|
#ifdef DCT_FLOAT_SUPPORTED
|
||||||
|
FAST_FLOAT float_array[DCTSIZE2];
|
||||||
|
#endif
|
||||||
|
} divisor_table;
|
||||||
|
|
||||||
|
|
||||||
/* The current scaled-DCT routines require ISLOW-style divisor tables,
|
/* The current scaled-DCT routines require ISLOW-style divisor tables,
|
||||||
* so be sure to compile that code if either ISLOW or SCALING is requested.
|
* so be sure to compile that code if either ISLOW or SCALING is requested.
|
||||||
*/
|
*/
|
||||||
@@ -57,26 +66,23 @@ typedef my_fdct_controller * my_fdct_ptr;
|
|||||||
* Perform forward DCT on one or more blocks of a component.
|
* Perform forward DCT on one or more blocks of a component.
|
||||||
*
|
*
|
||||||
* The input samples are taken from the sample_data[] array starting at
|
* The input samples are taken from the sample_data[] array starting at
|
||||||
* position start_row/start_col, and moving to the right for any additional
|
* position start_col, and moving to the right for any additional blocks.
|
||||||
* blocks. The quantized coefficients are returned in coef_blocks[].
|
* The quantized coefficients are returned in coef_blocks[].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||||
JDIMENSION start_row, JDIMENSION start_col,
|
JDIMENSION start_col, JDIMENSION num_blocks)
|
||||||
JDIMENSION num_blocks)
|
|
||||||
/* This version is used for integer DCT implementations. */
|
/* This version is used for integer DCT implementations. */
|
||||||
{
|
{
|
||||||
/* This routine is heavily used, so it's worth coding it tightly. */
|
/* This routine is heavily used, so it's worth coding it tightly. */
|
||||||
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
||||||
forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index];
|
forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index];
|
||||||
DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
|
DCTELEM * divisors = (DCTELEM *) compptr->dct_table;
|
||||||
DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
||||||
JDIMENSION bi;
|
JDIMENSION bi;
|
||||||
|
|
||||||
sample_data += start_row; /* fold in the vertical offset once */
|
|
||||||
|
|
||||||
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
|
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
|
||||||
/* Perform the DCT */
|
/* Perform the DCT */
|
||||||
(*do_dct) (workspace, sample_data, start_col);
|
(*do_dct) (workspace, sample_data, start_col);
|
||||||
@@ -127,19 +133,16 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||||
JDIMENSION start_row, JDIMENSION start_col,
|
JDIMENSION start_col, JDIMENSION num_blocks)
|
||||||
JDIMENSION num_blocks)
|
|
||||||
/* This version is used for floating-point DCT implementations. */
|
/* This version is used for floating-point DCT implementations. */
|
||||||
{
|
{
|
||||||
/* This routine is heavily used, so it's worth coding it tightly. */
|
/* This routine is heavily used, so it's worth coding it tightly. */
|
||||||
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
||||||
float_DCT_method_ptr do_dct = fdct->do_float_dct[compptr->component_index];
|
float_DCT_method_ptr do_dct = fdct->do_float_dct[compptr->component_index];
|
||||||
FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
|
FAST_FLOAT * divisors = (FAST_FLOAT *) compptr->dct_table;
|
||||||
FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
||||||
JDIMENSION bi;
|
JDIMENSION bi;
|
||||||
|
|
||||||
sample_data += start_row; /* fold in the vertical offset once */
|
|
||||||
|
|
||||||
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
|
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
|
||||||
/* Perform the DCT */
|
/* Perform the DCT */
|
||||||
(*do_dct) (workspace, sample_data, start_col);
|
(*do_dct) (workspace, sample_data, start_col);
|
||||||
@@ -338,13 +341,11 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
|||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
|
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
|
||||||
compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size);
|
compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
qtblno = compptr->quant_tbl_no;
|
qtblno = compptr->quant_tbl_no;
|
||||||
/* Make sure specified quantization table is present */
|
/* Make sure specified quantization table is present */
|
||||||
@@ -352,22 +353,17 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
|||||||
cinfo->quant_tbl_ptrs[qtblno] == NULL)
|
cinfo->quant_tbl_ptrs[qtblno] == NULL)
|
||||||
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
|
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
|
||||||
qtbl = cinfo->quant_tbl_ptrs[qtblno];
|
qtbl = cinfo->quant_tbl_ptrs[qtblno];
|
||||||
/* Compute divisors for this quant table */
|
/* Create divisor table from quant table */
|
||||||
/* We may do this more than once for same table, but it's not a big deal */
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
#ifdef PROVIDE_ISLOW_TABLES
|
#ifdef PROVIDE_ISLOW_TABLES
|
||||||
case JDCT_ISLOW:
|
case JDCT_ISLOW:
|
||||||
/* For LL&M IDCT method, divisors are equal to raw quantization
|
/* For LL&M IDCT method, divisors are equal to raw quantization
|
||||||
* coefficients multiplied by 8 (to counteract scaling).
|
* coefficients multiplied by 8 (to counteract scaling).
|
||||||
*/
|
*/
|
||||||
if (fdct->divisors[qtblno] == NULL) {
|
dtbl = (DCTELEM *) compptr->dct_table;
|
||||||
fdct->divisors[qtblno] = (DCTELEM *)
|
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
||||||
DCTSIZE2 * SIZEOF(DCTELEM));
|
|
||||||
}
|
|
||||||
dtbl = fdct->divisors[qtblno];
|
|
||||||
for (i = 0; i < DCTSIZE2; i++) {
|
for (i = 0; i < DCTSIZE2; i++) {
|
||||||
dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
|
dtbl[i] =
|
||||||
|
((DCTELEM) qtbl->quantval[i]) << (compptr->component_needed ? 4 : 3);
|
||||||
}
|
}
|
||||||
fdct->pub.forward_DCT[ci] = forward_DCT;
|
fdct->pub.forward_DCT[ci] = forward_DCT;
|
||||||
break;
|
break;
|
||||||
@@ -395,17 +391,12 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
|||||||
};
|
};
|
||||||
SHIFT_TEMPS
|
SHIFT_TEMPS
|
||||||
|
|
||||||
if (fdct->divisors[qtblno] == NULL) {
|
dtbl = (DCTELEM *) compptr->dct_table;
|
||||||
fdct->divisors[qtblno] = (DCTELEM *)
|
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
||||||
DCTSIZE2 * SIZEOF(DCTELEM));
|
|
||||||
}
|
|
||||||
dtbl = fdct->divisors[qtblno];
|
|
||||||
for (i = 0; i < DCTSIZE2; i++) {
|
for (i = 0; i < DCTSIZE2; i++) {
|
||||||
dtbl[i] = (DCTELEM)
|
dtbl[i] = (DCTELEM)
|
||||||
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
|
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
|
||||||
(INT32) aanscales[i]),
|
(INT32) aanscales[i]),
|
||||||
CONST_BITS-3);
|
compptr->component_needed ? CONST_BITS-4 : CONST_BITS-3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fdct->pub.forward_DCT[ci] = forward_DCT;
|
fdct->pub.forward_DCT[ci] = forward_DCT;
|
||||||
@@ -422,25 +413,20 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
|||||||
* What's actually stored is 1/divisor so that the inner loop can
|
* What's actually stored is 1/divisor so that the inner loop can
|
||||||
* use a multiplication rather than a division.
|
* use a multiplication rather than a division.
|
||||||
*/
|
*/
|
||||||
FAST_FLOAT * fdtbl;
|
FAST_FLOAT * fdtbl = (FAST_FLOAT *) compptr->dct_table;
|
||||||
int row, col;
|
int row, col;
|
||||||
static const double aanscalefactor[DCTSIZE] = {
|
static const double aanscalefactor[DCTSIZE] = {
|
||||||
1.0, 1.387039845, 1.306562965, 1.175875602,
|
1.0, 1.387039845, 1.306562965, 1.175875602,
|
||||||
1.0, 0.785694958, 0.541196100, 0.275899379
|
1.0, 0.785694958, 0.541196100, 0.275899379
|
||||||
};
|
};
|
||||||
|
|
||||||
if (fdct->float_divisors[qtblno] == NULL) {
|
|
||||||
fdct->float_divisors[qtblno] = (FAST_FLOAT *)
|
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
||||||
DCTSIZE2 * SIZEOF(FAST_FLOAT));
|
|
||||||
}
|
|
||||||
fdtbl = fdct->float_divisors[qtblno];
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (row = 0; row < DCTSIZE; row++) {
|
for (row = 0; row < DCTSIZE; row++) {
|
||||||
for (col = 0; col < DCTSIZE; col++) {
|
for (col = 0; col < DCTSIZE; col++) {
|
||||||
fdtbl[i] = (FAST_FLOAT)
|
fdtbl[i] = (FAST_FLOAT)
|
||||||
(1.0 / (((double) qtbl->quantval[i] *
|
(1.0 / ((double) qtbl->quantval[i] *
|
||||||
aanscalefactor[row] * aanscalefactor[col] * 8.0)));
|
aanscalefactor[row] * aanscalefactor[col] *
|
||||||
|
(compptr->component_needed ? 16.0 : 8.0)));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,7 +436,6 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
|||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -464,19 +449,18 @@ GLOBAL(void)
|
|||||||
jinit_forward_dct (j_compress_ptr cinfo)
|
jinit_forward_dct (j_compress_ptr cinfo)
|
||||||
{
|
{
|
||||||
my_fdct_ptr fdct;
|
my_fdct_ptr fdct;
|
||||||
int i;
|
int ci;
|
||||||
|
jpeg_component_info *compptr;
|
||||||
|
|
||||||
fdct = (my_fdct_ptr)
|
fdct = (my_fdct_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_fdct_controller));
|
||||||
SIZEOF(my_fdct_controller));
|
cinfo->fdct = &fdct->pub;
|
||||||
cinfo->fdct = (struct jpeg_forward_dct *) fdct;
|
|
||||||
fdct->pub.start_pass = start_pass_fdctmgr;
|
fdct->pub.start_pass = start_pass_fdctmgr;
|
||||||
|
|
||||||
/* Mark divisor tables unallocated */
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
for (i = 0; i < NUM_QUANT_TBLS; i++) {
|
ci++, compptr++) {
|
||||||
fdct->divisors[i] = NULL;
|
/* Allocate a divisor table for each component */
|
||||||
#ifdef DCT_FLOAT_SUPPORTED
|
compptr->dct_table = (*cinfo->mem->alloc_small)
|
||||||
fdct->float_divisors[i] = NULL;
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(divisor_table));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+147
-83
@@ -2,7 +2,7 @@
|
|||||||
* jchuff.c
|
* jchuff.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
* Modified 2006-2009 by Guido Vollbeding.
|
* Modified 2006-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -178,13 +178,12 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
|
|||||||
htbl =
|
htbl =
|
||||||
isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
|
isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
|
||||||
if (htbl == NULL)
|
if (htbl == NULL)
|
||||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
|
htbl = jpeg_std_huff_table((j_common_ptr) cinfo, isDC, tblno);
|
||||||
|
|
||||||
/* Allocate a workspace if we haven't already done so. */
|
/* Allocate a workspace if we haven't already done so. */
|
||||||
if (*pdtbl == NULL)
|
if (*pdtbl == NULL)
|
||||||
*pdtbl = (c_derived_tbl *)
|
*pdtbl = (c_derived_tbl *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(c_derived_tbl));
|
||||||
SIZEOF(c_derived_tbl));
|
|
||||||
dtbl = *pdtbl;
|
dtbl = *pdtbl;
|
||||||
|
|
||||||
/* Figure C.1: make table of Huffman code length for each symbol */
|
/* Figure C.1: make table of Huffman code length for each symbol */
|
||||||
@@ -308,20 +307,23 @@ emit_bits_s (working_state * state, unsigned int code, int size)
|
|||||||
/* Emit some bits; return TRUE if successful, FALSE if must suspend */
|
/* Emit some bits; return TRUE if successful, FALSE if must suspend */
|
||||||
{
|
{
|
||||||
/* This routine is heavily used, so it's worth coding tightly. */
|
/* This routine is heavily used, so it's worth coding tightly. */
|
||||||
register INT32 put_buffer = (INT32) code;
|
register INT32 put_buffer;
|
||||||
register int put_bits = state->cur.put_bits;
|
register int put_bits;
|
||||||
|
|
||||||
/* if size is 0, caller used an invalid Huffman table entry */
|
/* if size is 0, caller used an invalid Huffman table entry */
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
|
ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
|
||||||
|
|
||||||
put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
|
/* mask off any extra bits in code */
|
||||||
|
put_buffer = ((INT32) code) & ((((INT32) 1) << size) - 1);
|
||||||
|
|
||||||
put_bits += size; /* new number of bits in buffer */
|
/* new number of bits in buffer */
|
||||||
|
put_bits = size + state->cur.put_bits;
|
||||||
|
|
||||||
put_buffer <<= 24 - put_bits; /* align incoming bits */
|
put_buffer <<= 24 - put_bits; /* align incoming bits */
|
||||||
|
|
||||||
put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
|
/* and merge with old buffer contents */
|
||||||
|
put_buffer |= state->cur.put_buffer;
|
||||||
|
|
||||||
while (put_bits >= 8) {
|
while (put_bits >= 8) {
|
||||||
int c = (int) ((put_buffer >> 16) & 0xFF);
|
int c = (int) ((put_buffer >> 16) & 0xFF);
|
||||||
@@ -347,8 +349,8 @@ emit_bits_e (huff_entropy_ptr entropy, unsigned int code, int size)
|
|||||||
/* Emit some bits, unless we are in gather mode */
|
/* Emit some bits, unless we are in gather mode */
|
||||||
{
|
{
|
||||||
/* This routine is heavily used, so it's worth coding tightly. */
|
/* This routine is heavily used, so it's worth coding tightly. */
|
||||||
register INT32 put_buffer = (INT32) code;
|
register INT32 put_buffer;
|
||||||
register int put_bits = entropy->saved.put_bits;
|
register int put_bits;
|
||||||
|
|
||||||
/* if size is 0, caller used an invalid Huffman table entry */
|
/* if size is 0, caller used an invalid Huffman table entry */
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
@@ -357,9 +359,11 @@ emit_bits_e (huff_entropy_ptr entropy, unsigned int code, int size)
|
|||||||
if (entropy->gather_statistics)
|
if (entropy->gather_statistics)
|
||||||
return; /* do nothing if we're only getting stats */
|
return; /* do nothing if we're only getting stats */
|
||||||
|
|
||||||
put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
|
/* mask off any extra bits in code */
|
||||||
|
put_buffer = ((INT32) code) & ((((INT32) 1) << size) - 1);
|
||||||
|
|
||||||
put_bits += size; /* new number of bits in buffer */
|
/* new number of bits in buffer */
|
||||||
|
put_bits = size + entropy->saved.put_bits;
|
||||||
|
|
||||||
put_buffer <<= 24 - put_bits; /* align incoming bits */
|
put_buffer <<= 24 - put_bits; /* align incoming bits */
|
||||||
|
|
||||||
@@ -538,15 +542,12 @@ emit_restart_e (huff_entropy_ptr entropy, int restart_num)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
register int temp, temp2;
|
register int temp, temp2;
|
||||||
register int nbits;
|
register int nbits;
|
||||||
int blkn, ci;
|
int blkn, ci, tbl;
|
||||||
int Al = cinfo->Al;
|
|
||||||
JBLOCKROW block;
|
|
||||||
jpeg_component_info * compptr;
|
|
||||||
ISHIFT_TEMPS
|
ISHIFT_TEMPS
|
||||||
|
|
||||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||||
@@ -559,21 +560,20 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/* Encode the MCU data blocks */
|
/* Encode the MCU data blocks */
|
||||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||||
block = MCU_data[blkn];
|
|
||||||
ci = cinfo->MCU_membership[blkn];
|
ci = cinfo->MCU_membership[blkn];
|
||||||
compptr = cinfo->cur_comp_info[ci];
|
tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
|
||||||
|
|
||||||
/* Compute the DC value after the required point transform by Al.
|
/* Compute the DC value after the required point transform by Al.
|
||||||
* This is simply an arithmetic right shift.
|
* This is simply an arithmetic right shift.
|
||||||
*/
|
*/
|
||||||
temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
|
temp = IRIGHT_SHIFT((int) (MCU_data[blkn][0][0]), cinfo->Al);
|
||||||
|
|
||||||
/* DC differences are figured on the point-transformed values. */
|
/* DC differences are figured on the point-transformed values. */
|
||||||
temp = temp2 - entropy->saved.last_dc_val[ci];
|
temp2 = temp - entropy->saved.last_dc_val[ci];
|
||||||
entropy->saved.last_dc_val[ci] = temp2;
|
entropy->saved.last_dc_val[ci] = temp;
|
||||||
|
|
||||||
/* Encode the DC coefficient difference per section G.1.2.1 */
|
/* Encode the DC coefficient difference per section G.1.2.1 */
|
||||||
temp2 = temp;
|
temp = temp2;
|
||||||
if (temp < 0) {
|
if (temp < 0) {
|
||||||
temp = -temp; /* temp is abs value of input */
|
temp = -temp; /* temp is abs value of input */
|
||||||
/* For a negative input, want temp2 = bitwise complement of abs(input) */
|
/* For a negative input, want temp2 = bitwise complement of abs(input) */
|
||||||
@@ -594,7 +594,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
|
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
|
||||||
|
|
||||||
/* Count/emit the Huffman-coded symbol for the number of bits */
|
/* Count/emit the Huffman-coded symbol for the number of bits */
|
||||||
emit_dc_symbol(entropy, compptr->dc_tbl_no, nbits);
|
emit_dc_symbol(entropy, tbl, nbits);
|
||||||
|
|
||||||
/* Emit that number of bits of the value, if positive, */
|
/* Emit that number of bits of the value, if positive, */
|
||||||
/* or the complement of its magnitude, if negative. */
|
/* or the complement of its magnitude, if negative. */
|
||||||
@@ -625,15 +625,15 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
|
const int * natural_order;
|
||||||
|
JBLOCKROW block;
|
||||||
register int temp, temp2;
|
register int temp, temp2;
|
||||||
register int nbits;
|
register int nbits;
|
||||||
register int r, k;
|
register int r, k;
|
||||||
int Se, Al;
|
int Se, Al;
|
||||||
const int * natural_order;
|
|
||||||
JBLOCKROW block;
|
|
||||||
|
|
||||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||||
@@ -731,18 +731,15 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* MCU encoding for DC successive approximation refinement scan.
|
* MCU encoding for DC successive approximation refinement scan.
|
||||||
* Note: we assume such scans can be multi-component, although the spec
|
* Note: we assume such scans can be multi-component,
|
||||||
* is not very clear on the point.
|
* although the spec is not very clear on the point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
register int temp;
|
int Al, blkn;
|
||||||
int blkn;
|
|
||||||
int Al = cinfo->Al;
|
|
||||||
JBLOCKROW block;
|
|
||||||
|
|
||||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||||
@@ -752,13 +749,12 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
if (entropy->restarts_to_go == 0)
|
if (entropy->restarts_to_go == 0)
|
||||||
emit_restart_e(entropy, entropy->next_restart_num);
|
emit_restart_e(entropy, entropy->next_restart_num);
|
||||||
|
|
||||||
|
Al = cinfo->Al;
|
||||||
|
|
||||||
/* Encode the MCU data blocks */
|
/* Encode the MCU data blocks */
|
||||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||||
block = MCU_data[blkn];
|
|
||||||
|
|
||||||
/* We simply emit the Al'th bit of the DC coefficient value. */
|
/* We simply emit the Al'th bit of the DC coefficient value. */
|
||||||
temp = (*block)[0];
|
emit_bits_e(entropy, (unsigned int) (MCU_data[blkn][0][0] >> Al), 1);
|
||||||
emit_bits_e(entropy, (unsigned int) (temp >> Al), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cinfo->dest->next_output_byte = entropy->next_output_byte;
|
cinfo->dest->next_output_byte = entropy->next_output_byte;
|
||||||
@@ -783,17 +779,17 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
|
const int * natural_order;
|
||||||
|
JBLOCKROW block;
|
||||||
register int temp;
|
register int temp;
|
||||||
register int r, k;
|
register int r, k;
|
||||||
|
int Se, Al;
|
||||||
int EOB;
|
int EOB;
|
||||||
char *BR_buffer;
|
char *BR_buffer;
|
||||||
unsigned int BR;
|
unsigned int BR;
|
||||||
int Se, Al;
|
|
||||||
const int * natural_order;
|
|
||||||
JBLOCKROW block;
|
|
||||||
int absvalues[DCTSIZE2];
|
int absvalues[DCTSIZE2];
|
||||||
|
|
||||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||||
@@ -918,7 +914,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
|
|||||||
{
|
{
|
||||||
register int temp, temp2;
|
register int temp, temp2;
|
||||||
register int nbits;
|
register int nbits;
|
||||||
register int k, r, i;
|
register int r, k;
|
||||||
int Se = state->cinfo->lim_Se;
|
int Se = state->cinfo->lim_Se;
|
||||||
const int * natural_order = state->cinfo->natural_order;
|
const int * natural_order = state->cinfo->natural_order;
|
||||||
|
|
||||||
@@ -960,7 +956,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
|
|||||||
r = 0; /* r = run length of zeros */
|
r = 0; /* r = run length of zeros */
|
||||||
|
|
||||||
for (k = 1; k <= Se; k++) {
|
for (k = 1; k <= Se; k++) {
|
||||||
if ((temp = block[natural_order[k]]) == 0) {
|
if ((temp2 = block[natural_order[k]]) == 0) {
|
||||||
r++;
|
r++;
|
||||||
} else {
|
} else {
|
||||||
/* if run length > 15, must emit special run-length-16 codes (0xF0) */
|
/* if run length > 15, must emit special run-length-16 codes (0xF0) */
|
||||||
@@ -970,7 +966,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
|
|||||||
r -= 16;
|
r -= 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
temp2 = temp;
|
temp = temp2;
|
||||||
if (temp < 0) {
|
if (temp < 0) {
|
||||||
temp = -temp; /* temp is abs value of input */
|
temp = -temp; /* temp is abs value of input */
|
||||||
/* This code assumes we are on a two's complement machine */
|
/* This code assumes we are on a two's complement machine */
|
||||||
@@ -986,8 +982,8 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
|
|||||||
ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
|
ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
|
||||||
|
|
||||||
/* Emit Huffman symbol for run length / number of bits */
|
/* Emit Huffman symbol for run length / number of bits */
|
||||||
i = (r << 4) + nbits;
|
temp = (r << 4) + nbits;
|
||||||
if (! emit_bits_s(state, actbl->ehufco[i], actbl->ehufsi[i]))
|
if (! emit_bits_s(state, actbl->ehufco[temp], actbl->ehufsi[temp]))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Emit that number of bits of the value, if positive, */
|
/* Emit that number of bits of the value, if positive, */
|
||||||
@@ -1013,7 +1009,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_huff (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
working_state state;
|
working_state state;
|
||||||
@@ -1124,7 +1120,7 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
|
|||||||
{
|
{
|
||||||
register int temp;
|
register int temp;
|
||||||
register int nbits;
|
register int nbits;
|
||||||
register int k, r;
|
register int r, k;
|
||||||
int Se = cinfo->lim_Se;
|
int Se = cinfo->lim_Se;
|
||||||
const int * natural_order = cinfo->natural_order;
|
const int * natural_order = cinfo->natural_order;
|
||||||
|
|
||||||
@@ -1194,7 +1190,7 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
encode_mcu_gather (j_compress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
int blkn, ci;
|
int blkn, ci;
|
||||||
@@ -1259,10 +1255,82 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
|
|||||||
UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
|
UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
|
||||||
int codesize[257]; /* codesize[k] = code length of symbol k */
|
int codesize[257]; /* codesize[k] = code length of symbol k */
|
||||||
int others[257]; /* next symbol in current branch of tree */
|
int others[257]; /* next symbol in current branch of tree */
|
||||||
int c1, c2;
|
int c1, c2, i, j;
|
||||||
int p, i, j;
|
UINT8 *p;
|
||||||
long v;
|
long v;
|
||||||
|
|
||||||
|
freq[256] = 1; /* make sure 256 has a nonzero count */
|
||||||
|
/* Including the pseudo-symbol 256 in the Huffman procedure guarantees
|
||||||
|
* that no real symbol is given code-value of all ones, because 256
|
||||||
|
* will be placed last in the largest codeword category.
|
||||||
|
* In the symbol list build procedure this element serves as sentinel
|
||||||
|
* for the zero run loop.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DONT_USE_FANCY_HUFF_OPT
|
||||||
|
|
||||||
|
/* Build list of symbols sorted in order of descending frequency */
|
||||||
|
/* This approach has several benefits (thank to John Korejwa for the idea):
|
||||||
|
* 1.
|
||||||
|
* If a codelength category is split during the length limiting procedure
|
||||||
|
* below, the feature that more frequent symbols are assigned shorter
|
||||||
|
* codewords remains valid for the adjusted code.
|
||||||
|
* 2.
|
||||||
|
* To reduce consecutive ones in a Huffman data stream (thus reducing the
|
||||||
|
* number of stuff bytes in JPEG) it is preferable to follow 0 branches
|
||||||
|
* (and avoid 1 branches) as much as possible. This is easily done by
|
||||||
|
* assigning symbols to leaves of the Huffman tree in order of decreasing
|
||||||
|
* frequency, with no secondary sort based on codelengths.
|
||||||
|
* 3.
|
||||||
|
* The symbol list can be built independently from the assignment of code
|
||||||
|
* lengths by the Huffman procedure below.
|
||||||
|
* Note: The symbol list build procedure must be performed first, because
|
||||||
|
* the Huffman procedure assigning the codelengths clobbers the frequency
|
||||||
|
* counts!
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Here we use the others array as a linked list of nonzero frequencies
|
||||||
|
* to be sorted. Already sorted elements are removed from the list.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Building list */
|
||||||
|
|
||||||
|
/* This item does not correspond to a valid symbol frequency and is used
|
||||||
|
* as starting index.
|
||||||
|
*/
|
||||||
|
j = 256;
|
||||||
|
|
||||||
|
for (i = 0;; i++) {
|
||||||
|
if (freq[i] == 0) /* skip zero frequencies */
|
||||||
|
continue;
|
||||||
|
if (i > 255)
|
||||||
|
break;
|
||||||
|
others[j] = i; /* this symbol value */
|
||||||
|
j = i; /* previous symbol value */
|
||||||
|
}
|
||||||
|
others[j] = -1; /* mark end of list */
|
||||||
|
|
||||||
|
/* Sorting list */
|
||||||
|
|
||||||
|
p = htbl->huffval;
|
||||||
|
while ((c1 = others[256]) >= 0) {
|
||||||
|
v = freq[c1];
|
||||||
|
i = c1; /* first symbol value */
|
||||||
|
j = 256; /* pseudo symbol value for starting index */
|
||||||
|
while ((c2 = others[c1]) >= 0) {
|
||||||
|
if (freq[c2] > v) {
|
||||||
|
v = freq[c2];
|
||||||
|
i = c2; /* this symbol value */
|
||||||
|
j = c1; /* previous symbol value */
|
||||||
|
}
|
||||||
|
c1 = c2;
|
||||||
|
}
|
||||||
|
others[j] = others[i]; /* remove this symbol i from list */
|
||||||
|
*p++ = (UINT8) i;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* DONT_USE_FANCY_HUFF_OPT */
|
||||||
|
|
||||||
/* This algorithm is explained in section K.2 of the JPEG standard */
|
/* This algorithm is explained in section K.2 of the JPEG standard */
|
||||||
|
|
||||||
MEMZERO(bits, SIZEOF(bits));
|
MEMZERO(bits, SIZEOF(bits));
|
||||||
@@ -1270,12 +1338,6 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
|
|||||||
for (i = 0; i < 257; i++)
|
for (i = 0; i < 257; i++)
|
||||||
others[i] = -1; /* init links to empty */
|
others[i] = -1; /* init links to empty */
|
||||||
|
|
||||||
freq[256] = 1; /* make sure 256 has a nonzero count */
|
|
||||||
/* Including the pseudo-symbol 256 in the Huffman procedure guarantees
|
|
||||||
* that no real symbol is given code-value of all ones, because 256
|
|
||||||
* will be placed last in the largest codeword category.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Huffman's basic algorithm to assign optimal code lengths to symbols */
|
/* Huffman's basic algorithm to assign optimal code lengths to symbols */
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -1332,7 +1394,7 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
|
|||||||
/* The JPEG standard seems to think that this can't happen, */
|
/* The JPEG standard seems to think that this can't happen, */
|
||||||
/* but I'm paranoid... */
|
/* but I'm paranoid... */
|
||||||
if (codesize[i] > MAX_CLEN)
|
if (codesize[i] > MAX_CLEN)
|
||||||
ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
|
ERREXIT(cinfo, JERR_HUFF_CLEN_OUTOFBOUNDS);
|
||||||
|
|
||||||
bits[codesize[i]]++;
|
bits[codesize[i]]++;
|
||||||
}
|
}
|
||||||
@@ -1352,8 +1414,11 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
|
|||||||
for (i = MAX_CLEN; i > 16; i--) {
|
for (i = MAX_CLEN; i > 16; i--) {
|
||||||
while (bits[i] > 0) {
|
while (bits[i] > 0) {
|
||||||
j = i - 2; /* find length of new prefix to be used */
|
j = i - 2; /* find length of new prefix to be used */
|
||||||
while (bits[j] == 0)
|
while (bits[j] == 0) {
|
||||||
|
if (j == 0)
|
||||||
|
ERREXIT(cinfo, JERR_HUFF_CLEN_OUTOFBOUNDS);
|
||||||
j--;
|
j--;
|
||||||
|
}
|
||||||
|
|
||||||
bits[i] -= 2; /* remove two symbols */
|
bits[i] -= 2; /* remove two symbols */
|
||||||
bits[i-1]++; /* one goes in this length */
|
bits[i-1]++; /* one goes in this length */
|
||||||
@@ -1370,20 +1435,23 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
|
|||||||
/* Return final symbol counts (only for lengths 0..16) */
|
/* Return final symbol counts (only for lengths 0..16) */
|
||||||
MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
|
MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
|
||||||
|
|
||||||
|
#ifdef DONT_USE_FANCY_HUFF_OPT
|
||||||
|
|
||||||
/* Return a list of the symbols sorted by code length */
|
/* Return a list of the symbols sorted by code length */
|
||||||
/* It's not real clear to me why we don't need to consider the codelength
|
/* Note: Due to the codelength changes made above, it can happen
|
||||||
* changes made above, but the JPEG spec seems to think this works.
|
* that more frequent symbols are assigned longer codewords.
|
||||||
*/
|
*/
|
||||||
p = 0;
|
p = htbl->huffval;
|
||||||
for (i = 1; i <= MAX_CLEN; i++) {
|
for (i = 1; i <= MAX_CLEN; i++) {
|
||||||
for (j = 0; j <= 255; j++) {
|
for (j = 0; j <= 255; j++) {
|
||||||
if (codesize[j] == i) {
|
if (codesize[j] == i) {
|
||||||
htbl->huffval[p] = (UINT8) j;
|
*p++ = (UINT8) j;
|
||||||
p++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* DONT_USE_FANCY_HUFF_OPT */
|
||||||
|
|
||||||
/* Set sent_table FALSE so updated table will be written to JPEG file. */
|
/* Set sent_table FALSE so updated table will be written to JPEG file. */
|
||||||
htbl->sent_table = FALSE;
|
htbl->sent_table = FALSE;
|
||||||
}
|
}
|
||||||
@@ -1403,13 +1471,13 @@ finish_pass_gather (j_compress_ptr cinfo)
|
|||||||
boolean did_dc[NUM_HUFF_TBLS];
|
boolean did_dc[NUM_HUFF_TBLS];
|
||||||
boolean did_ac[NUM_HUFF_TBLS];
|
boolean did_ac[NUM_HUFF_TBLS];
|
||||||
|
|
||||||
/* It's important not to apply jpeg_gen_optimal_table more than once
|
|
||||||
* per table, because it clobbers the input frequency counts!
|
|
||||||
*/
|
|
||||||
if (cinfo->progressive_mode)
|
if (cinfo->progressive_mode)
|
||||||
/* Flush out buffered data (all we care about is counting the EOB symbol) */
|
/* Flush out buffered data (all we care about is counting the EOB symbol) */
|
||||||
emit_eobrun(entropy);
|
emit_eobrun(entropy);
|
||||||
|
|
||||||
|
/* It's important not to apply jpeg_gen_optimal_table more than once
|
||||||
|
* per table, because it clobbers the input frequency counts!
|
||||||
|
*/
|
||||||
MEMZERO(did_dc, SIZEOF(did_dc));
|
MEMZERO(did_dc, SIZEOF(did_dc));
|
||||||
MEMZERO(did_ac, SIZEOF(did_ac));
|
MEMZERO(did_ac, SIZEOF(did_ac));
|
||||||
|
|
||||||
@@ -1478,9 +1546,8 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
|
|||||||
entropy->pub.encode_mcu = encode_mcu_AC_refine;
|
entropy->pub.encode_mcu = encode_mcu_AC_refine;
|
||||||
/* AC refinement needs a correction bit buffer */
|
/* AC refinement needs a correction bit buffer */
|
||||||
if (entropy->bit_buffer == NULL)
|
if (entropy->bit_buffer == NULL)
|
||||||
entropy->bit_buffer = (char *)
|
entropy->bit_buffer = (char *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, MAX_CORR_BITS * SIZEOF(char));
|
||||||
MAX_CORR_BITS * SIZEOF(char));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1508,9 +1575,8 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
|
|||||||
/* Allocate and zero the statistics tables */
|
/* Allocate and zero the statistics tables */
|
||||||
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
|
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
|
||||||
if (entropy->dc_count_ptrs[tbl] == NULL)
|
if (entropy->dc_count_ptrs[tbl] == NULL)
|
||||||
entropy->dc_count_ptrs[tbl] = (long *)
|
entropy->dc_count_ptrs[tbl] = (long *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, 257 * SIZEOF(long));
|
||||||
257 * SIZEOF(long));
|
|
||||||
MEMZERO(entropy->dc_count_ptrs[tbl], 257 * SIZEOF(long));
|
MEMZERO(entropy->dc_count_ptrs[tbl], 257 * SIZEOF(long));
|
||||||
} else {
|
} else {
|
||||||
/* Compute derived values for Huffman tables */
|
/* Compute derived values for Huffman tables */
|
||||||
@@ -1528,9 +1594,8 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
|
|||||||
if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
|
if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
|
||||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
|
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
|
||||||
if (entropy->ac_count_ptrs[tbl] == NULL)
|
if (entropy->ac_count_ptrs[tbl] == NULL)
|
||||||
entropy->ac_count_ptrs[tbl] = (long *)
|
entropy->ac_count_ptrs[tbl] = (long *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, 257 * SIZEOF(long));
|
||||||
257 * SIZEOF(long));
|
|
||||||
MEMZERO(entropy->ac_count_ptrs[tbl], 257 * SIZEOF(long));
|
MEMZERO(entropy->ac_count_ptrs[tbl], 257 * SIZEOF(long));
|
||||||
} else {
|
} else {
|
||||||
jpeg_make_c_derived_tbl(cinfo, FALSE, tbl,
|
jpeg_make_c_derived_tbl(cinfo, FALSE, tbl,
|
||||||
@@ -1559,10 +1624,9 @@ jinit_huff_encoder (j_compress_ptr cinfo)
|
|||||||
huff_entropy_ptr entropy;
|
huff_entropy_ptr entropy;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
entropy = (huff_entropy_ptr)
|
entropy = (huff_entropy_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(huff_entropy_encoder));
|
||||||
SIZEOF(huff_entropy_encoder));
|
cinfo->entropy = &entropy->pub;
|
||||||
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
|
|
||||||
entropy->pub.start_pass = start_pass_huff;
|
entropy->pub.start_pass = start_pass_huff;
|
||||||
|
|
||||||
/* Mark tables unallocated */
|
/* Mark tables unallocated */
|
||||||
|
|||||||
Vendored
+184
@@ -2,6 +2,7 @@
|
|||||||
* jcinit.c
|
* jcinit.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
|
* Modified 2003-2017 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -20,6 +21,168 @@
|
|||||||
#include "jpeglib.h"
|
#include "jpeglib.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compute JPEG image dimensions and related values.
|
||||||
|
* NOTE: this is exported for possible use by application.
|
||||||
|
* Hence it mustn't do anything that can't be done twice.
|
||||||
|
*/
|
||||||
|
|
||||||
|
GLOBAL(void)
|
||||||
|
jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)
|
||||||
|
/* Do computations that are needed before master selection phase */
|
||||||
|
{
|
||||||
|
/* Sanity check on input image dimensions to prevent overflow in
|
||||||
|
* following calculations.
|
||||||
|
* We do check jpeg_width and jpeg_height in initial_setup in jcmaster.c,
|
||||||
|
* but image_width and image_height can come from arbitrary data,
|
||||||
|
* and we need some space for multiplication by block_size.
|
||||||
|
*/
|
||||||
|
if (((long) cinfo->image_width >> 24) || ((long) cinfo->image_height >> 24))
|
||||||
|
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
|
||||||
|
|
||||||
|
#ifdef DCT_SCALING_SUPPORTED
|
||||||
|
|
||||||
|
/* Compute actual JPEG image dimensions and DCT scaling choices. */
|
||||||
|
if (cinfo->scale_num >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/1 scaling */
|
||||||
|
cinfo->jpeg_width = cinfo->image_width * cinfo->block_size;
|
||||||
|
cinfo->jpeg_height = cinfo->image_height * cinfo->block_size;
|
||||||
|
cinfo->min_DCT_h_scaled_size = 1;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 1;
|
||||||
|
} else if (cinfo->scale_num * 2 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/2 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 2L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 2L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 2;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 2;
|
||||||
|
} else if (cinfo->scale_num * 3 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/3 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 3L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 3L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 3;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 3;
|
||||||
|
} else if (cinfo->scale_num * 4 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/4 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 4L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 4L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 4;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 4;
|
||||||
|
} else if (cinfo->scale_num * 5 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/5 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 5L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 5L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 5;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 5;
|
||||||
|
} else if (cinfo->scale_num * 6 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/6 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 6L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 6L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 6;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 6;
|
||||||
|
} else if (cinfo->scale_num * 7 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/7 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 7L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 7L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 7;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 7;
|
||||||
|
} else if (cinfo->scale_num * 8 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/8 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 8L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 8L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 8;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 8;
|
||||||
|
} else if (cinfo->scale_num * 9 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/9 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 9L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 9L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 9;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 9;
|
||||||
|
} else if (cinfo->scale_num * 10 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/10 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 10L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 10L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 10;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 10;
|
||||||
|
} else if (cinfo->scale_num * 11 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/11 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 11L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 11L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 11;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 11;
|
||||||
|
} else if (cinfo->scale_num * 12 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/12 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 12L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 12L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 12;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 12;
|
||||||
|
} else if (cinfo->scale_num * 13 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/13 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 13L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 13L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 13;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 13;
|
||||||
|
} else if (cinfo->scale_num * 14 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/14 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 14L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 14L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 14;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 14;
|
||||||
|
} else if (cinfo->scale_num * 15 >= cinfo->scale_denom * cinfo->block_size) {
|
||||||
|
/* Provide block_size/15 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 15L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 15L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 15;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 15;
|
||||||
|
} else {
|
||||||
|
/* Provide block_size/16 scaling */
|
||||||
|
cinfo->jpeg_width = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 16L);
|
||||||
|
cinfo->jpeg_height = (JDIMENSION)
|
||||||
|
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 16L);
|
||||||
|
cinfo->min_DCT_h_scaled_size = 16;
|
||||||
|
cinfo->min_DCT_v_scaled_size = 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* !DCT_SCALING_SUPPORTED */
|
||||||
|
|
||||||
|
/* Hardwire it to "no scaling" */
|
||||||
|
cinfo->jpeg_width = cinfo->image_width;
|
||||||
|
cinfo->jpeg_height = cinfo->image_height;
|
||||||
|
cinfo->min_DCT_h_scaled_size = DCTSIZE;
|
||||||
|
cinfo->min_DCT_v_scaled_size = DCTSIZE;
|
||||||
|
|
||||||
|
#endif /* DCT_SCALING_SUPPORTED */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Master selection of compression modules.
|
* Master selection of compression modules.
|
||||||
* This is done once at the start of processing an image. We determine
|
* This is done once at the start of processing an image. We determine
|
||||||
@@ -29,6 +192,27 @@
|
|||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
jinit_compress_master (j_compress_ptr cinfo)
|
jinit_compress_master (j_compress_ptr cinfo)
|
||||||
{
|
{
|
||||||
|
long samplesperrow;
|
||||||
|
JDIMENSION jd_samplesperrow;
|
||||||
|
|
||||||
|
/* For now, precision must match compiled-in value... */
|
||||||
|
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||||
|
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||||
|
|
||||||
|
/* Sanity check on input image dimensions */
|
||||||
|
if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||
|
||||||
|
cinfo->input_components <= 0)
|
||||||
|
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
|
||||||
|
|
||||||
|
/* Width of an input scanline must be representable as JDIMENSION. */
|
||||||
|
samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
|
||||||
|
jd_samplesperrow = (JDIMENSION) samplesperrow;
|
||||||
|
if ((long) jd_samplesperrow != samplesperrow)
|
||||||
|
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||||
|
|
||||||
|
/* Compute JPEG image dimensions and related values. */
|
||||||
|
jpeg_calc_jpeg_dimensions(cinfo);
|
||||||
|
|
||||||
/* Initialize master control (includes parameter checking/processing) */
|
/* Initialize master control (includes parameter checking/processing) */
|
||||||
jinit_c_master_control(cinfo, FALSE /* full compression */);
|
jinit_c_master_control(cinfo, FALSE /* full compression */);
|
||||||
|
|
||||||
|
|||||||
Vendored
+57
-53
@@ -2,6 +2,7 @@
|
|||||||
* jcmainct.c
|
* jcmainct.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
|
* Modified 2003-2012 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -68,32 +69,32 @@ METHODDEF(void) process_data_buffer_main
|
|||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
|
|
||||||
/* Do nothing in raw-data mode. */
|
/* Do nothing in raw-data mode. */
|
||||||
if (cinfo->raw_data_in)
|
if (cinfo->raw_data_in)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
main->cur_iMCU_row = 0; /* initialize counters */
|
mainp->cur_iMCU_row = 0; /* initialize counters */
|
||||||
main->rowgroup_ctr = 0;
|
mainp->rowgroup_ctr = 0;
|
||||||
main->suspended = FALSE;
|
mainp->suspended = FALSE;
|
||||||
main->pass_mode = pass_mode; /* save mode for use by process_data */
|
mainp->pass_mode = pass_mode; /* save mode for use by process_data */
|
||||||
|
|
||||||
switch (pass_mode) {
|
switch (pass_mode) {
|
||||||
case JBUF_PASS_THRU:
|
case JBUF_PASS_THRU:
|
||||||
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
||||||
if (main->whole_image[0] != NULL)
|
if (mainp->whole_image[0] != NULL)
|
||||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||||
#endif
|
#endif
|
||||||
main->pub.process_data = process_data_simple_main;
|
mainp->pub.process_data = process_data_simple_main;
|
||||||
break;
|
break;
|
||||||
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
||||||
case JBUF_SAVE_SOURCE:
|
case JBUF_SAVE_SOURCE:
|
||||||
case JBUF_CRANK_DEST:
|
case JBUF_CRANK_DEST:
|
||||||
case JBUF_SAVE_AND_PASS:
|
case JBUF_SAVE_AND_PASS:
|
||||||
if (main->whole_image[0] == NULL)
|
if (mainp->whole_image[0] == NULL)
|
||||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||||
main->pub.process_data = process_data_buffer_main;
|
mainp->pub.process_data = process_data_buffer_main;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
@@ -114,46 +115,46 @@ process_data_simple_main (j_compress_ptr cinfo,
|
|||||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||||
JDIMENSION in_rows_avail)
|
JDIMENSION in_rows_avail)
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
|
|
||||||
while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
|
while (mainp->cur_iMCU_row < cinfo->total_iMCU_rows) {
|
||||||
/* Read input data if we haven't filled the main buffer yet */
|
/* Read input data if we haven't filled the main buffer yet */
|
||||||
if (main->rowgroup_ctr < (JDIMENSION) cinfo->min_DCT_v_scaled_size)
|
if (mainp->rowgroup_ctr < (JDIMENSION) cinfo->min_DCT_v_scaled_size)
|
||||||
(*cinfo->prep->pre_process_data) (cinfo,
|
(*cinfo->prep->pre_process_data) (cinfo,
|
||||||
input_buf, in_row_ctr, in_rows_avail,
|
input_buf, in_row_ctr, in_rows_avail,
|
||||||
main->buffer, &main->rowgroup_ctr,
|
mainp->buffer, &mainp->rowgroup_ctr,
|
||||||
(JDIMENSION) cinfo->min_DCT_v_scaled_size);
|
(JDIMENSION) cinfo->min_DCT_v_scaled_size);
|
||||||
|
|
||||||
/* If we don't have a full iMCU row buffered, return to application for
|
/* If we don't have a full iMCU row buffered, return to application for
|
||||||
* more data. Note that preprocessor will always pad to fill the iMCU row
|
* more data. Note that preprocessor will always pad to fill the iMCU row
|
||||||
* at the bottom of the image.
|
* at the bottom of the image.
|
||||||
*/
|
*/
|
||||||
if (main->rowgroup_ctr != (JDIMENSION) cinfo->min_DCT_v_scaled_size)
|
if (mainp->rowgroup_ctr != (JDIMENSION) cinfo->min_DCT_v_scaled_size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Send the completed row to the compressor */
|
/* Send the completed row to the compressor */
|
||||||
if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
|
if (! (*cinfo->coef->compress_data) (cinfo, mainp->buffer)) {
|
||||||
/* If compressor did not consume the whole row, then we must need to
|
/* If compressor did not consume the whole row, then we must need to
|
||||||
* suspend processing and return to the application. In this situation
|
* suspend processing and return to the application. In this situation
|
||||||
* we pretend we didn't yet consume the last input row; otherwise, if
|
* we pretend we didn't yet consume the last input row; otherwise, if
|
||||||
* it happened to be the last row of the image, the application would
|
* it happened to be the last row of the image, the application would
|
||||||
* think we were done.
|
* think we were done.
|
||||||
*/
|
*/
|
||||||
if (! main->suspended) {
|
if (! mainp->suspended) {
|
||||||
(*in_row_ctr)--;
|
(*in_row_ctr)--;
|
||||||
main->suspended = TRUE;
|
mainp->suspended = TRUE;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* We did finish the row. Undo our little suspension hack if a previous
|
/* We did finish the row. Undo our little suspension hack if a previous
|
||||||
* call suspended; then mark the main buffer empty.
|
* call suspended; then mark the main buffer empty.
|
||||||
*/
|
*/
|
||||||
if (main->suspended) {
|
if (mainp->suspended) {
|
||||||
(*in_row_ctr)++;
|
(*in_row_ctr)++;
|
||||||
main->suspended = FALSE;
|
mainp->suspended = FALSE;
|
||||||
}
|
}
|
||||||
main->rowgroup_ctr = 0;
|
mainp->rowgroup_ctr = 0;
|
||||||
main->cur_iMCU_row++;
|
mainp->cur_iMCU_row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,25 +171,27 @@ process_data_buffer_main (j_compress_ptr cinfo,
|
|||||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||||
JDIMENSION in_rows_avail)
|
JDIMENSION in_rows_avail)
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
int ci;
|
int ci;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
|
boolean writing = (mainp->pass_mode != JBUF_CRANK_DEST);
|
||||||
|
|
||||||
while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
|
while (mainp->cur_iMCU_row < cinfo->total_iMCU_rows) {
|
||||||
/* Realign the virtual buffers if at the start of an iMCU row. */
|
/* Realign the virtual buffers if at the start of an iMCU row. */
|
||||||
if (main->rowgroup_ctr == 0) {
|
if (mainp->rowgroup_ctr == 0) {
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
|
mainp->buffer[ci] = (*cinfo->mem->access_virt_sarray)
|
||||||
((j_common_ptr) cinfo, main->whole_image[ci],
|
((j_common_ptr) cinfo, mainp->whole_image[ci], mainp->cur_iMCU_row *
|
||||||
main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
|
((JDIMENSION) (compptr->v_samp_factor * cinfo->min_DCT_v_scaled_size)),
|
||||||
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
|
(JDIMENSION) (compptr->v_samp_factor * cinfo->min_DCT_v_scaled_size),
|
||||||
|
writing);
|
||||||
}
|
}
|
||||||
/* In a read pass, pretend we just read some source data. */
|
/* In a read pass, pretend we just read some source data. */
|
||||||
if (! writing) {
|
if (! writing) {
|
||||||
*in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
|
*in_row_ctr += (JDIMENSION)
|
||||||
main->rowgroup_ctr = DCTSIZE;
|
(cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size);
|
||||||
|
mainp->rowgroup_ctr = (JDIMENSION) cinfo->min_DCT_v_scaled_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,40 +200,40 @@ process_data_buffer_main (j_compress_ptr cinfo,
|
|||||||
if (writing) {
|
if (writing) {
|
||||||
(*cinfo->prep->pre_process_data) (cinfo,
|
(*cinfo->prep->pre_process_data) (cinfo,
|
||||||
input_buf, in_row_ctr, in_rows_avail,
|
input_buf, in_row_ctr, in_rows_avail,
|
||||||
main->buffer, &main->rowgroup_ctr,
|
mainp->buffer, &mainp->rowgroup_ctr,
|
||||||
(JDIMENSION) DCTSIZE);
|
(JDIMENSION) cinfo->min_DCT_v_scaled_size);
|
||||||
/* Return to application if we need more data to fill the iMCU row. */
|
/* Return to application if we need more data to fill the iMCU row. */
|
||||||
if (main->rowgroup_ctr < DCTSIZE)
|
if (mainp->rowgroup_ctr < (JDIMENSION) cinfo->min_DCT_v_scaled_size)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit data, unless this is a sink-only pass. */
|
/* Emit data, unless this is a sink-only pass. */
|
||||||
if (main->pass_mode != JBUF_SAVE_SOURCE) {
|
if (mainp->pass_mode != JBUF_SAVE_SOURCE) {
|
||||||
if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
|
if (! (*cinfo->coef->compress_data) (cinfo, mainp->buffer)) {
|
||||||
/* If compressor did not consume the whole row, then we must need to
|
/* If compressor did not consume the whole row, then we must need to
|
||||||
* suspend processing and return to the application. In this situation
|
* suspend processing and return to the application. In this situation
|
||||||
* we pretend we didn't yet consume the last input row; otherwise, if
|
* we pretend we didn't yet consume the last input row; otherwise, if
|
||||||
* it happened to be the last row of the image, the application would
|
* it happened to be the last row of the image, the application would
|
||||||
* think we were done.
|
* think we were done.
|
||||||
*/
|
*/
|
||||||
if (! main->suspended) {
|
if (! mainp->suspended) {
|
||||||
(*in_row_ctr)--;
|
(*in_row_ctr)--;
|
||||||
main->suspended = TRUE;
|
mainp->suspended = TRUE;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* We did finish the row. Undo our little suspension hack if a previous
|
/* We did finish the row. Undo our little suspension hack if a previous
|
||||||
* call suspended; then mark the main buffer empty.
|
* call suspended; then mark the main buffer empty.
|
||||||
*/
|
*/
|
||||||
if (main->suspended) {
|
if (mainp->suspended) {
|
||||||
(*in_row_ctr)++;
|
(*in_row_ctr)++;
|
||||||
main->suspended = FALSE;
|
mainp->suspended = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If get here, we are done with this iMCU row. Mark buffer empty. */
|
/* If get here, we are done with this iMCU row. Mark buffer empty. */
|
||||||
main->rowgroup_ctr = 0;
|
mainp->rowgroup_ctr = 0;
|
||||||
main->cur_iMCU_row++;
|
mainp->cur_iMCU_row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,15 +247,15 @@ process_data_buffer_main (j_compress_ptr cinfo,
|
|||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||||
{
|
{
|
||||||
my_main_ptr main;
|
my_main_ptr mainp;
|
||||||
int ci;
|
int ci;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
|
|
||||||
main = (my_main_ptr)
|
mainp = (my_main_ptr)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
SIZEOF(my_main_controller));
|
SIZEOF(my_main_controller));
|
||||||
cinfo->main = (struct jpeg_c_main_controller *) main;
|
cinfo->main = &mainp->pub;
|
||||||
main->pub.start_pass = start_pass_main;
|
mainp->pub.start_pass = start_pass_main;
|
||||||
|
|
||||||
/* We don't need to create a buffer in raw-data mode. */
|
/* We don't need to create a buffer in raw-data mode. */
|
||||||
if (cinfo->raw_data_in)
|
if (cinfo->raw_data_in)
|
||||||
@@ -267,11 +270,12 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
|||||||
/* Note we pad the bottom to a multiple of the iMCU height */
|
/* Note we pad the bottom to a multiple of the iMCU height */
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
|
mainp->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
|
||||||
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
||||||
compptr->width_in_blocks * compptr->DCT_h_scaled_size,
|
compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
|
||||||
(JDIMENSION) jround_up((long) compptr->height_in_blocks,
|
((JDIMENSION) jround_up((long) compptr->height_in_blocks,
|
||||||
(long) compptr->v_samp_factor) * DCTSIZE,
|
(long) compptr->v_samp_factor)) *
|
||||||
|
((JDIMENSION) cinfo->min_DCT_v_scaled_size),
|
||||||
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
|
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -279,14 +283,14 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
||||||
main->whole_image[0] = NULL; /* flag for no virtual arrays */
|
mainp->whole_image[0] = NULL; /* flag for no virtual arrays */
|
||||||
#endif
|
#endif
|
||||||
/* Allocate a strip buffer for each component */
|
/* Allocate a strip buffer for each component */
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
main->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
||||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
compptr->width_in_blocks * compptr->DCT_h_scaled_size,
|
compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
|
||||||
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
|
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+44
-9
@@ -2,7 +2,7 @@
|
|||||||
* jcmarker.c
|
* jcmarker.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||||
* Modified 2003-2010 by Guido Vollbeding.
|
* Modified 2003-2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -73,6 +73,7 @@ typedef enum { /* JPEG marker codes */
|
|||||||
M_APP15 = 0xef,
|
M_APP15 = 0xef,
|
||||||
|
|
||||||
M_JPG0 = 0xf0,
|
M_JPG0 = 0xf0,
|
||||||
|
M_JPG8 = 0xf8,
|
||||||
M_JPG13 = 0xfd,
|
M_JPG13 = 0xfd,
|
||||||
M_COM = 0xfe,
|
M_COM = 0xfe,
|
||||||
|
|
||||||
@@ -281,6 +282,37 @@ emit_dri (j_compress_ptr cinfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL(void)
|
||||||
|
emit_lse_ict (j_compress_ptr cinfo)
|
||||||
|
/* Emit an LSE inverse color transform specification marker */
|
||||||
|
{
|
||||||
|
/* Support only 1 transform */
|
||||||
|
if (cinfo->color_transform != JCT_SUBTRACT_GREEN ||
|
||||||
|
cinfo->num_components < 3)
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
|
||||||
|
emit_marker(cinfo, M_JPG8);
|
||||||
|
|
||||||
|
emit_2bytes(cinfo, 24); /* fixed length */
|
||||||
|
|
||||||
|
emit_byte(cinfo, 0x0D); /* ID inverse transform specification */
|
||||||
|
emit_2bytes(cinfo, MAXJSAMPLE); /* MAXTRANS */
|
||||||
|
emit_byte(cinfo, 3); /* Nt=3 */
|
||||||
|
emit_byte(cinfo, cinfo->comp_info[1].component_id);
|
||||||
|
emit_byte(cinfo, cinfo->comp_info[0].component_id);
|
||||||
|
emit_byte(cinfo, cinfo->comp_info[2].component_id);
|
||||||
|
emit_byte(cinfo, 0x80); /* F1: CENTER1=1, NORM1=0 */
|
||||||
|
emit_2bytes(cinfo, 0); /* A(1,1)=0 */
|
||||||
|
emit_2bytes(cinfo, 0); /* A(1,2)=0 */
|
||||||
|
emit_byte(cinfo, 0); /* F2: CENTER2=0, NORM2=0 */
|
||||||
|
emit_2bytes(cinfo, 1); /* A(2,1)=1 */
|
||||||
|
emit_2bytes(cinfo, 0); /* A(2,2)=0 */
|
||||||
|
emit_byte(cinfo, 0); /* F3: CENTER3=0, NORM3=0 */
|
||||||
|
emit_2bytes(cinfo, 1); /* A(3,1)=1 */
|
||||||
|
emit_2bytes(cinfo, 0); /* A(3,2)=0 */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LOCAL(void)
|
LOCAL(void)
|
||||||
emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
|
emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
|
||||||
/* Emit a SOF marker */
|
/* Emit a SOF marker */
|
||||||
@@ -439,7 +471,6 @@ emit_adobe_app14 (j_compress_ptr cinfo)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
emit_byte(cinfo, 0); /* Color transform = 0 */
|
emit_byte(cinfo, 0); /* Color transform = 0 */
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,8 +507,8 @@ write_marker_byte (j_compress_ptr cinfo, int val)
|
|||||||
* Write datastream header.
|
* Write datastream header.
|
||||||
* This consists of an SOI and optional APPn markers.
|
* This consists of an SOI and optional APPn markers.
|
||||||
* We recommend use of the JFIF marker, but not the Adobe marker,
|
* We recommend use of the JFIF marker, but not the Adobe marker,
|
||||||
* when using YCbCr or grayscale data. The JFIF marker should NOT
|
* when using YCbCr or grayscale data. The JFIF marker is also used
|
||||||
* be used for any other JPEG colorspace. The Adobe marker is helpful
|
* for other standard JPEG colorspaces. The Adobe marker is helpful
|
||||||
* to distinguish RGB, CMYK, and YCCK colorspaces.
|
* to distinguish RGB, CMYK, and YCCK colorspaces.
|
||||||
* Note that an application can write additional header markers after
|
* Note that an application can write additional header markers after
|
||||||
* jpeg_start_compress returns.
|
* jpeg_start_compress returns.
|
||||||
@@ -502,7 +533,8 @@ write_file_header (j_compress_ptr cinfo)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Write frame header.
|
* Write frame header.
|
||||||
* This consists of DQT and SOFn markers, and a conditional pseudo SOS marker.
|
* This consists of DQT and SOFn markers,
|
||||||
|
* a conditional LSE marker and a conditional pseudo SOS marker.
|
||||||
* Note that we do not emit the SOF until we have emitted the DQT(s).
|
* Note that we do not emit the SOF until we have emitted the DQT(s).
|
||||||
* This avoids compatibility problems with incorrect implementations that
|
* This avoids compatibility problems with incorrect implementations that
|
||||||
* try to error-check the quant table numbers as soon as they see the SOF.
|
* try to error-check the quant table numbers as soon as they see the SOF.
|
||||||
@@ -560,6 +592,10 @@ write_frame_header (j_compress_ptr cinfo)
|
|||||||
emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
|
emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check to emit LSE inverse color transform specification marker */
|
||||||
|
if (cinfo->color_transform)
|
||||||
|
emit_lse_ict(cinfo);
|
||||||
|
|
||||||
/* Check to emit pseudo SOS marker */
|
/* Check to emit pseudo SOS marker */
|
||||||
if (cinfo->progressive_mode && cinfo->block_size != DCTSIZE)
|
if (cinfo->progressive_mode && cinfo->block_size != DCTSIZE)
|
||||||
emit_pseudo_sos(cinfo);
|
emit_pseudo_sos(cinfo);
|
||||||
@@ -665,10 +701,9 @@ jinit_marker_writer (j_compress_ptr cinfo)
|
|||||||
my_marker_ptr marker;
|
my_marker_ptr marker;
|
||||||
|
|
||||||
/* Create the subobject */
|
/* Create the subobject */
|
||||||
marker = (my_marker_ptr)
|
marker = (my_marker_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_marker_writer));
|
||||||
SIZEOF(my_marker_writer));
|
cinfo->marker = &marker->pub;
|
||||||
cinfo->marker = (struct jpeg_marker_writer *) marker;
|
|
||||||
/* Initialize method pointers */
|
/* Initialize method pointers */
|
||||||
marker->pub.write_file_header = write_file_header;
|
marker->pub.write_file_header = write_file_header;
|
||||||
marker->pub.write_frame_header = write_frame_header;
|
marker->pub.write_frame_header = write_frame_header;
|
||||||
|
|||||||
Vendored
+39
-222
@@ -2,7 +2,7 @@
|
|||||||
* jcmaster.c
|
* jcmaster.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
* Modified 2003-2011 by Guido Vollbeding.
|
* Modified 2003-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -43,192 +43,12 @@ typedef my_comp_master * my_master_ptr;
|
|||||||
* Support routines that do various essential calculations.
|
* Support routines that do various essential calculations.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Compute JPEG image dimensions and related values.
|
|
||||||
* NOTE: this is exported for possible use by application.
|
|
||||||
* Hence it mustn't do anything that can't be done twice.
|
|
||||||
*/
|
|
||||||
|
|
||||||
GLOBAL(void)
|
|
||||||
jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)
|
|
||||||
/* Do computations that are needed before master selection phase */
|
|
||||||
{
|
|
||||||
#ifdef DCT_SCALING_SUPPORTED
|
|
||||||
|
|
||||||
/* Sanity check on input image dimensions to prevent overflow in
|
|
||||||
* following calculation.
|
|
||||||
* We do check jpeg_width and jpeg_height in initial_setup below,
|
|
||||||
* but image_width and image_height can come from arbitrary data,
|
|
||||||
* and we need some space for multiplication by block_size.
|
|
||||||
*/
|
|
||||||
if (((long) cinfo->image_width >> 24) || ((long) cinfo->image_height >> 24))
|
|
||||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
|
|
||||||
|
|
||||||
/* Compute actual JPEG image dimensions and DCT scaling choices. */
|
|
||||||
if (cinfo->scale_num >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/1 scaling */
|
|
||||||
cinfo->jpeg_width = cinfo->image_width * cinfo->block_size;
|
|
||||||
cinfo->jpeg_height = cinfo->image_height * cinfo->block_size;
|
|
||||||
cinfo->min_DCT_h_scaled_size = 1;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 1;
|
|
||||||
} else if (cinfo->scale_num * 2 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/2 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 2L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 2L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 2;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 2;
|
|
||||||
} else if (cinfo->scale_num * 3 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/3 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 3L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 3L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 3;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 3;
|
|
||||||
} else if (cinfo->scale_num * 4 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/4 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 4L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 4L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 4;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 4;
|
|
||||||
} else if (cinfo->scale_num * 5 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/5 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 5L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 5L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 5;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 5;
|
|
||||||
} else if (cinfo->scale_num * 6 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/6 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 6L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 6L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 6;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 6;
|
|
||||||
} else if (cinfo->scale_num * 7 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/7 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 7L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 7L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 7;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 7;
|
|
||||||
} else if (cinfo->scale_num * 8 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/8 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 8L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 8L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 8;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 8;
|
|
||||||
} else if (cinfo->scale_num * 9 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/9 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 9L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 9L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 9;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 9;
|
|
||||||
} else if (cinfo->scale_num * 10 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/10 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 10L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 10L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 10;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 10;
|
|
||||||
} else if (cinfo->scale_num * 11 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/11 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 11L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 11L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 11;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 11;
|
|
||||||
} else if (cinfo->scale_num * 12 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/12 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 12L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 12L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 12;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 12;
|
|
||||||
} else if (cinfo->scale_num * 13 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/13 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 13L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 13L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 13;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 13;
|
|
||||||
} else if (cinfo->scale_num * 14 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/14 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 14L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 14L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 14;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 14;
|
|
||||||
} else if (cinfo->scale_num * 15 >= cinfo->scale_denom * cinfo->block_size) {
|
|
||||||
/* Provide block_size/15 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 15L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 15L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 15;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 15;
|
|
||||||
} else {
|
|
||||||
/* Provide block_size/16 scaling */
|
|
||||||
cinfo->jpeg_width = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 16L);
|
|
||||||
cinfo->jpeg_height = (JDIMENSION)
|
|
||||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 16L);
|
|
||||||
cinfo->min_DCT_h_scaled_size = 16;
|
|
||||||
cinfo->min_DCT_v_scaled_size = 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else /* !DCT_SCALING_SUPPORTED */
|
|
||||||
|
|
||||||
/* Hardwire it to "no scaling" */
|
|
||||||
cinfo->jpeg_width = cinfo->image_width;
|
|
||||||
cinfo->jpeg_height = cinfo->image_height;
|
|
||||||
cinfo->min_DCT_h_scaled_size = DCTSIZE;
|
|
||||||
cinfo->min_DCT_v_scaled_size = DCTSIZE;
|
|
||||||
|
|
||||||
#endif /* DCT_SCALING_SUPPORTED */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL(void)
|
LOCAL(void)
|
||||||
jpeg_calc_trans_dimensions (j_compress_ptr cinfo)
|
initial_setup (j_compress_ptr cinfo)
|
||||||
{
|
|
||||||
if (cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size)
|
|
||||||
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
|
|
||||||
cinfo->min_DCT_h_scaled_size, cinfo->min_DCT_v_scaled_size);
|
|
||||||
|
|
||||||
cinfo->block_size = cinfo->min_DCT_h_scaled_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL(void)
|
|
||||||
initial_setup (j_compress_ptr cinfo, boolean transcode_only)
|
|
||||||
/* Do computations that are needed before master selection phase */
|
/* Do computations that are needed before master selection phase */
|
||||||
{
|
{
|
||||||
int ci, ssize;
|
int ci, ssize;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
long samplesperrow;
|
|
||||||
JDIMENSION jd_samplesperrow;
|
|
||||||
|
|
||||||
if (transcode_only)
|
|
||||||
jpeg_calc_trans_dimensions(cinfo);
|
|
||||||
else
|
|
||||||
jpeg_calc_jpeg_dimensions(cinfo);
|
|
||||||
|
|
||||||
/* Sanity check on block_size */
|
/* Sanity check on block_size */
|
||||||
if (cinfo->block_size < 1 || cinfo->block_size > 16)
|
if (cinfo->block_size < 1 || cinfo->block_size > 16)
|
||||||
@@ -242,7 +62,7 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
|
|||||||
case 5: cinfo->natural_order = jpeg_natural_order5; break;
|
case 5: cinfo->natural_order = jpeg_natural_order5; break;
|
||||||
case 6: cinfo->natural_order = jpeg_natural_order6; break;
|
case 6: cinfo->natural_order = jpeg_natural_order6; break;
|
||||||
case 7: cinfo->natural_order = jpeg_natural_order7; break;
|
case 7: cinfo->natural_order = jpeg_natural_order7; break;
|
||||||
default: cinfo->natural_order = jpeg_natural_order; break;
|
default: cinfo->natural_order = jpeg_natural_order;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Derive lim_Se from block_size */
|
/* Derive lim_Se from block_size */
|
||||||
@@ -251,7 +71,7 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
|
|||||||
|
|
||||||
/* Sanity check on image dimensions */
|
/* Sanity check on image dimensions */
|
||||||
if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 ||
|
if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 ||
|
||||||
cinfo->num_components <= 0 || cinfo->input_components <= 0)
|
cinfo->num_components <= 0)
|
||||||
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
|
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
|
||||||
|
|
||||||
/* Make sure image isn't bigger than I can handle */
|
/* Make sure image isn't bigger than I can handle */
|
||||||
@@ -259,14 +79,8 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
|
|||||||
(long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION)
|
(long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION)
|
||||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
|
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
|
||||||
|
|
||||||
/* Width of an input scanline must be representable as JDIMENSION. */
|
/* Only 8 to 12 bits data precision are supported for DCT based JPEG */
|
||||||
samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
|
if (cinfo->data_precision < 8 || cinfo->data_precision > 12)
|
||||||
jd_samplesperrow = (JDIMENSION) samplesperrow;
|
|
||||||
if ((long) jd_samplesperrow != samplesperrow)
|
|
||||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
|
||||||
|
|
||||||
/* For now, precision must match compiled-in value... */
|
|
||||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
|
||||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||||
|
|
||||||
/* Check that number of components won't exceed internal array sizes */
|
/* Check that number of components won't exceed internal array sizes */
|
||||||
@@ -300,20 +114,24 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
|
|||||||
*/
|
*/
|
||||||
ssize = 1;
|
ssize = 1;
|
||||||
#ifdef DCT_SCALING_SUPPORTED
|
#ifdef DCT_SCALING_SUPPORTED
|
||||||
while (cinfo->min_DCT_h_scaled_size * ssize <=
|
if (! cinfo->raw_data_in)
|
||||||
(cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
|
while (cinfo->min_DCT_h_scaled_size * ssize <=
|
||||||
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
|
(cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
|
||||||
ssize = ssize * 2;
|
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) ==
|
||||||
}
|
0) {
|
||||||
|
ssize = ssize * 2;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
|
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
|
||||||
ssize = 1;
|
ssize = 1;
|
||||||
#ifdef DCT_SCALING_SUPPORTED
|
#ifdef DCT_SCALING_SUPPORTED
|
||||||
while (cinfo->min_DCT_v_scaled_size * ssize <=
|
if (! cinfo->raw_data_in)
|
||||||
(cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
|
while (cinfo->min_DCT_v_scaled_size * ssize <=
|
||||||
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
|
(cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
|
||||||
ssize = ssize * 2;
|
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) ==
|
||||||
}
|
0) {
|
||||||
|
ssize = ssize * 2;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
|
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
|
||||||
|
|
||||||
@@ -339,8 +157,10 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
|
|||||||
jdiv_round_up((long) cinfo->jpeg_height *
|
jdiv_round_up((long) cinfo->jpeg_height *
|
||||||
(long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),
|
(long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),
|
||||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
||||||
/* Mark component needed (this flag isn't actually used for compression) */
|
/* Don't need quantization scale after DCT,
|
||||||
compptr->component_needed = TRUE;
|
* until color conversion says otherwise.
|
||||||
|
*/
|
||||||
|
compptr->component_needed = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute number of fully interleaved MCU rows (number of times that
|
/* Compute number of fully interleaved MCU rows (number of times that
|
||||||
@@ -420,13 +240,9 @@ validate_script (j_compress_ptr cinfo)
|
|||||||
* out-of-range reconstructed DC values during the first DC scan,
|
* out-of-range reconstructed DC values during the first DC scan,
|
||||||
* which might cause problems for some decoders.
|
* which might cause problems for some decoders.
|
||||||
*/
|
*/
|
||||||
#if BITS_IN_JSAMPLE == 8
|
|
||||||
#define MAX_AH_AL 10
|
|
||||||
#else
|
|
||||||
#define MAX_AH_AL 13
|
|
||||||
#endif
|
|
||||||
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
|
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
|
||||||
Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
|
Ah < 0 || Ah > (cinfo->data_precision > 8 ? 13 : 10) ||
|
||||||
|
Al < 0 || Al > (cinfo->data_precision > 8 ? 13 : 10))
|
||||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||||
if (Ss == 0) {
|
if (Ss == 0) {
|
||||||
if (Se != 0) /* DC and AC together not OK */
|
if (Se != 0) /* DC and AC together not OK */
|
||||||
@@ -613,9 +429,7 @@ per_scan_setup (j_compress_ptr cinfo)
|
|||||||
cinfo->MCUs_per_row = (JDIMENSION)
|
cinfo->MCUs_per_row = (JDIMENSION)
|
||||||
jdiv_round_up((long) cinfo->jpeg_width,
|
jdiv_round_up((long) cinfo->jpeg_width,
|
||||||
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
||||||
cinfo->MCU_rows_in_scan = (JDIMENSION)
|
cinfo->MCU_rows_in_scan = cinfo->total_iMCU_rows;
|
||||||
jdiv_round_up((long) cinfo->jpeg_height,
|
|
||||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
|
||||||
|
|
||||||
cinfo->blocks_in_MCU = 0;
|
cinfo->blocks_in_MCU = 0;
|
||||||
|
|
||||||
@@ -808,17 +622,16 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
|
|||||||
{
|
{
|
||||||
my_master_ptr master;
|
my_master_ptr master;
|
||||||
|
|
||||||
master = (my_master_ptr)
|
master = (my_master_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_comp_master));
|
||||||
SIZEOF(my_comp_master));
|
cinfo->master = &master->pub;
|
||||||
cinfo->master = (struct jpeg_comp_master *) master;
|
|
||||||
master->pub.prepare_for_pass = prepare_for_pass;
|
master->pub.prepare_for_pass = prepare_for_pass;
|
||||||
master->pub.pass_startup = pass_startup;
|
master->pub.pass_startup = pass_startup;
|
||||||
master->pub.finish_pass = finish_pass_master;
|
master->pub.finish_pass = finish_pass_master;
|
||||||
master->pub.is_last_pass = FALSE;
|
master->pub.is_last_pass = FALSE;
|
||||||
|
|
||||||
/* Validate parameters, determine derived values */
|
/* Validate parameters, determine derived values */
|
||||||
initial_setup(cinfo, transcode_only);
|
initial_setup(cinfo);
|
||||||
|
|
||||||
if (cinfo->scan_info != NULL) {
|
if (cinfo->scan_info != NULL) {
|
||||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||||
@@ -833,10 +646,14 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
|
|||||||
cinfo->num_scans = 1;
|
cinfo->num_scans = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cinfo->progressive_mode || cinfo->block_size < DCTSIZE) &&
|
if (cinfo->optimize_coding)
|
||||||
!cinfo->arith_code) /* TEMPORARY HACK ??? */
|
cinfo->arith_code = FALSE; /* disable arithmetic coding */
|
||||||
/* assume default tables no good for progressive or downscale mode */
|
else if (! cinfo->arith_code &&
|
||||||
cinfo->optimize_coding = TRUE;
|
(cinfo->progressive_mode ||
|
||||||
|
(cinfo->block_size > 1 && cinfo->block_size < DCTSIZE)))
|
||||||
|
/* TEMPORARY HACK ??? */
|
||||||
|
/* assume default tables no good for progressive or reduced AC mode */
|
||||||
|
cinfo->optimize_coding = TRUE; /* force Huffman optimization */
|
||||||
|
|
||||||
/* Initialize my private state */
|
/* Initialize my private state */
|
||||||
if (transcode_only) {
|
if (transcode_only) {
|
||||||
|
|||||||
Vendored
+138
@@ -2,6 +2,7 @@
|
|||||||
* jcomapi.c
|
* jcomapi.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||||
|
* Modified 2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -104,3 +105,140 @@ jpeg_alloc_huff_table (j_common_ptr cinfo)
|
|||||||
tbl->sent_table = FALSE; /* make sure this is false in any new table */
|
tbl->sent_table = FALSE; /* make sure this is false in any new table */
|
||||||
return tbl;
|
return tbl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set up the standard Huffman tables (cf. JPEG standard section K.3).
|
||||||
|
* IMPORTANT: these are only valid for 8-bit data precision!
|
||||||
|
* (Would jutils.c be a more reasonable place to put this?)
|
||||||
|
*/
|
||||||
|
|
||||||
|
GLOBAL(JHUFF_TBL *)
|
||||||
|
jpeg_std_huff_table (j_common_ptr cinfo, boolean isDC, int tblno)
|
||||||
|
{
|
||||||
|
JHUFF_TBL **htblptr, *htbl;
|
||||||
|
const UINT8 *bits, *val;
|
||||||
|
int nsymbols, len;
|
||||||
|
|
||||||
|
static const UINT8 bits_dc_luminance[17] =
|
||||||
|
{ /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
|
static const UINT8 val_dc_luminance[] =
|
||||||
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
|
||||||
|
|
||||||
|
static const UINT8 bits_dc_chrominance[17] =
|
||||||
|
{ /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
|
||||||
|
static const UINT8 val_dc_chrominance[] =
|
||||||
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
|
||||||
|
|
||||||
|
static const UINT8 bits_ac_luminance[17] =
|
||||||
|
{ /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
|
||||||
|
static const UINT8 val_ac_luminance[] =
|
||||||
|
{ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
|
||||||
|
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
|
||||||
|
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
|
||||||
|
0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
|
||||||
|
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
|
||||||
|
0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
|
||||||
|
0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
|
||||||
|
0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
|
||||||
|
0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
|
||||||
|
0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
|
||||||
|
0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
|
||||||
|
0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
|
||||||
|
0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
|
||||||
|
0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||||
|
0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
|
||||||
|
0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
|
||||||
|
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
|
||||||
|
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
|
||||||
|
0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
|
||||||
|
0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
||||||
|
0xf9, 0xfa };
|
||||||
|
|
||||||
|
static const UINT8 bits_ac_chrominance[17] =
|
||||||
|
{ /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
|
||||||
|
static const UINT8 val_ac_chrominance[] =
|
||||||
|
{ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
|
||||||
|
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
|
||||||
|
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
|
||||||
|
0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
|
||||||
|
0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
|
||||||
|
0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
|
||||||
|
0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
|
||||||
|
0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
|
||||||
|
0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
|
||||||
|
0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
|
||||||
|
0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
|
||||||
|
0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||||
|
0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||||
|
0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
|
||||||
|
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
|
||||||
|
0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
|
||||||
|
0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
|
||||||
|
0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
|
||||||
|
0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
|
||||||
|
0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
||||||
|
0xf9, 0xfa };
|
||||||
|
|
||||||
|
if (cinfo->is_decompressor) {
|
||||||
|
if (isDC)
|
||||||
|
htblptr = ((j_decompress_ptr) cinfo)->dc_huff_tbl_ptrs;
|
||||||
|
else
|
||||||
|
htblptr = ((j_decompress_ptr) cinfo)->ac_huff_tbl_ptrs;
|
||||||
|
} else {
|
||||||
|
if (isDC)
|
||||||
|
htblptr = ((j_compress_ptr) cinfo)->dc_huff_tbl_ptrs;
|
||||||
|
else
|
||||||
|
htblptr = ((j_compress_ptr) cinfo)->ac_huff_tbl_ptrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (tblno) {
|
||||||
|
case 0:
|
||||||
|
if (isDC) {
|
||||||
|
bits = bits_dc_luminance;
|
||||||
|
val = val_dc_luminance;
|
||||||
|
} else {
|
||||||
|
bits = bits_ac_luminance;
|
||||||
|
val = val_ac_luminance;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (isDC) {
|
||||||
|
bits = bits_dc_chrominance;
|
||||||
|
val = val_dc_chrominance;
|
||||||
|
} else {
|
||||||
|
bits = bits_ac_chrominance;
|
||||||
|
val = val_ac_chrominance;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
|
||||||
|
return NULL; /* avoid compiler warnings for uninitialized variables */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (htblptr[tblno] == NULL)
|
||||||
|
htblptr[tblno] = jpeg_alloc_huff_table(cinfo);
|
||||||
|
|
||||||
|
htbl = htblptr[tblno];
|
||||||
|
|
||||||
|
/* Copy the number-of-symbols-of-each-code-length counts */
|
||||||
|
MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
|
||||||
|
|
||||||
|
/* Validate the counts. We do this here mainly so we can copy the right
|
||||||
|
* number of symbols from the val[] array, without risking marching off
|
||||||
|
* the end of memory. jxhuff.c will do a more thorough test later.
|
||||||
|
*/
|
||||||
|
nsymbols = 0;
|
||||||
|
for (len = 1; len <= 16; len++)
|
||||||
|
nsymbols += bits[len];
|
||||||
|
if (nsymbols > 256)
|
||||||
|
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||||
|
|
||||||
|
if (nsymbols > 0)
|
||||||
|
MEMCOPY(htbl->huffval, val, nsymbols * SIZEOF(UINT8));
|
||||||
|
|
||||||
|
/* Initialize sent_table FALSE so table will be written to JPEG file. */
|
||||||
|
htbl->sent_table = FALSE;
|
||||||
|
|
||||||
|
return htbl;
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+48
@@ -0,0 +1,48 @@
|
|||||||
|
/* jconfig.bcc --- jconfig.h for Borland C (Turbo C) on MS-DOS or OS/2. */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#ifdef __MSDOS__
|
||||||
|
#define NEED_FAR_POINTERS /* for small or medium memory model */
|
||||||
|
#endif
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN /* this assumes you have -w-stu in CFLAGS */
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#ifdef __MSDOS__
|
||||||
|
#define USE_MSDOS_MEMMGR /* Define this if you use jmemdos.c */
|
||||||
|
#define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */
|
||||||
|
#define USE_FMEM /* Borland has _fmemcpy() and _fmemset() */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#define TWO_FILE_COMMANDLINE
|
||||||
|
#define USE_SETMODE /* Borland has setmode() */
|
||||||
|
#ifdef __MSDOS__
|
||||||
|
#define NEED_SIGNAL_CATCHER /* Define this if you use jmemdos.c */
|
||||||
|
#endif
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+59
@@ -0,0 +1,59 @@
|
|||||||
|
/* jconfig.cfg --- source file edited by configure script */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#undef HAVE_PROTOTYPES
|
||||||
|
#undef HAVE_UNSIGNED_CHAR
|
||||||
|
#undef HAVE_UNSIGNED_SHORT
|
||||||
|
#undef void
|
||||||
|
#undef const
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#undef HAVE_STDDEF_H
|
||||||
|
#undef HAVE_STDLIB_H
|
||||||
|
#undef HAVE_LOCALE_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#undef NEED_FAR_POINTERS
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
/* Define this if you get warnings about undefined structures. */
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
|
/* Define "boolean" as unsigned char, not enum, on Windows systems. */
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
||||||
|
typedef unsigned char boolean;
|
||||||
|
#endif
|
||||||
|
#ifndef FALSE /* in case these macros already exist */
|
||||||
|
#define FALSE 0 /* values of boolean */
|
||||||
|
#endif
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE 1
|
||||||
|
#endif
|
||||||
|
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
#undef INLINE
|
||||||
|
/* These are for configuring the JPEG memory manager. */
|
||||||
|
#undef DEFAULT_MAX_MEM
|
||||||
|
#undef NO_MKTEMP
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#undef TWO_FILE_COMMANDLINE
|
||||||
|
#undef NEED_SIGNAL_CATCHER
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
|
||||||
|
/* Define this if you want percent-done progress reports from cjpeg/djpeg. */
|
||||||
|
#undef PROGRESS_REPORT
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+38
@@ -0,0 +1,38 @@
|
|||||||
|
/* jconfig.dj --- jconfig.h for DJGPP (Delorie's GNU C port) on MS-DOS. */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#undef NEED_FAR_POINTERS /* DJGPP uses flat 32-bit addressing */
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#undef TWO_FILE_COMMANDLINE /* optional */
|
||||||
|
#define USE_SETMODE /* Needed to make one-file style work in DJGPP */
|
||||||
|
#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/* jconfig.mac --- jconfig.h for CodeWarrior on Apple Macintosh */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#undef NEED_FAR_POINTERS
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#define USE_MAC_MEMMGR /* Define this if you use jmemmac.c */
|
||||||
|
|
||||||
|
#define ALIGN_TYPE long /* Needed for 680x0 Macs */
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#define USE_CCOMMAND /* Command line reader for Macintosh */
|
||||||
|
#define TWO_FILE_COMMANDLINE /* Binary I/O thru stdin/stdout doesn't work */
|
||||||
|
|
||||||
|
#undef NEED_SIGNAL_CATCHER
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/* jconfig.manx --- jconfig.h for Amiga systems using Manx Aztec C ver 5.x. */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#undef NEED_FAR_POINTERS
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#define TEMP_DIRECTORY "JPEGTMP:" /* recommended setting for Amiga */
|
||||||
|
|
||||||
|
#define SHORTxSHORT_32 /* produces better DCT code with Aztec C */
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#define TWO_FILE_COMMANDLINE
|
||||||
|
#define NEED_SIGNAL_CATCHER
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#define signal_catcher _abort /* hack for Aztec C naming requirements */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/* jconfig.mc6 --- jconfig.h for Microsoft C on MS-DOS, version 6.00A & up. */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#define NEED_FAR_POINTERS /* for small or medium memory model */
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#define USE_MSDOS_MEMMGR /* Define this if you use jmemdos.c */
|
||||||
|
|
||||||
|
#define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */
|
||||||
|
|
||||||
|
#define USE_FMEM /* Microsoft has _fmemcpy() and _fmemset() */
|
||||||
|
|
||||||
|
#define NEED_FHEAPMIN /* far heap management routines are broken */
|
||||||
|
|
||||||
|
#define SHORTxLCONST_32 /* enable compiler-specific DCT optimization */
|
||||||
|
/* Note: the above define is known to improve the code with Microsoft C 6.00A.
|
||||||
|
* I do not know whether it is good for later compiler versions.
|
||||||
|
* Please report any info on this point to [email protected].
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#define TWO_FILE_COMMANDLINE
|
||||||
|
#define USE_SETMODE /* Microsoft has setmode() */
|
||||||
|
#define NEED_SIGNAL_CATCHER /* Define this if you use jmemdos.c */
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/* jconfig.sas --- jconfig.h for Amiga systems using SAS C 6.0 and up. */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#undef NEED_FAR_POINTERS
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#define TEMP_DIRECTORY "JPEGTMP:" /* recommended setting for Amiga */
|
||||||
|
|
||||||
|
#define NO_MKTEMP /* SAS C doesn't have mktemp() */
|
||||||
|
|
||||||
|
#define SHORTxSHORT_32 /* produces better DCT code with SAS C */
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#define TWO_FILE_COMMANDLINE
|
||||||
|
#define NEED_SIGNAL_CATCHER
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/* jconfig.st --- jconfig.h for Atari ST/STE/TT using Pure C or Turbo C. */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#undef NEED_FAR_POINTERS
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#define INCOMPLETE_TYPES_BROKEN /* suppress undefined-structure warnings */
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#define ALIGN_TYPE long /* apparently double is a weird size? */
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#define TWO_FILE_COMMANDLINE /* optional -- undef if you like Unix style */
|
||||||
|
/* Note: if you undef TWO_FILE_COMMANDLINE, you may need to define
|
||||||
|
* USE_SETMODE. Some Atari compilers require it, some do not.
|
||||||
|
*/
|
||||||
|
#define NEED_SIGNAL_CATCHER /* needed if you use jmemname.c */
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+8
-1
@@ -2,6 +2,7 @@
|
|||||||
* jconfig.txt
|
* jconfig.txt
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1994, Thomas G. Lane.
|
* Copyright (C) 1991-1994, Thomas G. Lane.
|
||||||
|
* Modified 2009-2013 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -91,12 +92,18 @@
|
|||||||
*/
|
*/
|
||||||
#undef INCOMPLETE_TYPES_BROKEN
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
/* Define "boolean" as unsigned char, not int, on Windows systems.
|
/* Define "boolean" as unsigned char, not enum, on Windows systems.
|
||||||
*/
|
*/
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
||||||
typedef unsigned char boolean;
|
typedef unsigned char boolean;
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef FALSE /* in case these macros already exist */
|
||||||
|
#define FALSE 0 /* values of boolean */
|
||||||
|
#endif
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE 1
|
||||||
|
#endif
|
||||||
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Vendored
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/* jconfig.vc --- jconfig.h for Microsoft Visual C++ on Windows 9x or NT. */
|
||||||
|
/* This file also works for Borland C++ 32-bit (bcc32) on Windows 9x or NT. */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
|
/* Define "boolean" as unsigned char, not enum, per Windows custom */
|
||||||
|
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
||||||
|
typedef unsigned char boolean;
|
||||||
|
#endif
|
||||||
|
#ifndef FALSE /* in case these macros already exist */
|
||||||
|
#define FALSE 0 /* values of boolean */
|
||||||
|
#endif
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE 1
|
||||||
|
#endif
|
||||||
|
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#define TWO_FILE_COMMANDLINE /* optional */
|
||||||
|
#define USE_SETMODE /* Microsoft has setmode() */
|
||||||
|
#undef NEED_SIGNAL_CATCHER
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+37
@@ -0,0 +1,37 @@
|
|||||||
|
/* jconfig.vms --- jconfig.h for use on Digital VMS. */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#undef CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#undef NEED_FAR_POINTERS
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#define TWO_FILE_COMMANDLINE /* Needed on VMS */
|
||||||
|
#undef NEED_SIGNAL_CATCHER
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+38
@@ -0,0 +1,38 @@
|
|||||||
|
/* jconfig.wat --- jconfig.h for Watcom C/C++ on MS-DOS or OS/2. */
|
||||||
|
/* see jconfig.txt for explanations */
|
||||||
|
|
||||||
|
#define HAVE_PROTOTYPES
|
||||||
|
#define HAVE_UNSIGNED_CHAR
|
||||||
|
#define HAVE_UNSIGNED_SHORT
|
||||||
|
/* #define void char */
|
||||||
|
/* #define const */
|
||||||
|
#define CHAR_IS_UNSIGNED
|
||||||
|
#define HAVE_STDDEF_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#undef NEED_BSD_STRINGS
|
||||||
|
#undef NEED_SYS_TYPES_H
|
||||||
|
#undef NEED_FAR_POINTERS /* Watcom uses flat 32-bit addressing */
|
||||||
|
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||||
|
#undef INCOMPLETE_TYPES_BROKEN
|
||||||
|
|
||||||
|
#ifdef JPEG_INTERNALS
|
||||||
|
|
||||||
|
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
|
||||||
|
#endif /* JPEG_INTERNALS */
|
||||||
|
|
||||||
|
#ifdef JPEG_CJPEG_DJPEG
|
||||||
|
|
||||||
|
#define BMP_SUPPORTED /* BMP image file format */
|
||||||
|
#define GIF_SUPPORTED /* GIF image file format */
|
||||||
|
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||||
|
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||||
|
#define TARGA_SUPPORTED /* Targa image file format */
|
||||||
|
|
||||||
|
#undef TWO_FILE_COMMANDLINE /* optional */
|
||||||
|
#define USE_SETMODE /* Needed to make one-file style work in Watcom */
|
||||||
|
#undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */
|
||||||
|
#undef DONT_USE_B_MODE
|
||||||
|
#undef PROGRESS_REPORT /* optional */
|
||||||
|
|
||||||
|
#endif /* JPEG_CJPEG_DJPEG */
|
||||||
Vendored
+97
-138
@@ -2,7 +2,7 @@
|
|||||||
* jcparam.c
|
* jcparam.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||||
* Modified 2003-2008 by Guido Vollbeding.
|
* Modified 2003-2022 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -62,8 +62,9 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
|
|||||||
|
|
||||||
|
|
||||||
/* These are the sample quantization tables given in JPEG spec section K.1.
|
/* These are the sample quantization tables given in JPEG spec section K.1.
|
||||||
* The spec says that the values given produce "good" quality, and
|
* NOTE: chrominance DC value is changed from 17 to 16 for lossless support.
|
||||||
* when divided by 2, "very good" quality.
|
* 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] = {
|
static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
|
||||||
16, 11, 10, 16, 24, 40, 51, 61,
|
16, 11, 10, 16, 24, 40, 51, 61,
|
||||||
@@ -76,7 +77,7 @@ static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
|
|||||||
72, 92, 95, 98, 112, 100, 103, 99
|
72, 92, 95, 98, 112, 100, 103, 99
|
||||||
};
|
};
|
||||||
static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
|
static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
|
||||||
17, 18, 24, 47, 99, 99, 99, 99,
|
16, 18, 24, 47, 99, 99, 99, 99,
|
||||||
18, 21, 26, 66, 99, 99, 99, 99,
|
18, 21, 26, 66, 99, 99, 99, 99,
|
||||||
24, 26, 56, 99, 99, 99, 99, 99,
|
24, 26, 56, 99, 99, 99, 99, 99,
|
||||||
47, 66, 99, 99, 99, 99, 99, 99,
|
47, 66, 99, 99, 99, 99, 99, 99,
|
||||||
@@ -150,7 +151,7 @@ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
|
|||||||
/* Set or change the 'quality' (quantization) setting, using default tables.
|
/* Set or change the 'quality' (quantization) setting, using default tables.
|
||||||
* This is the standard quality-adjusting entry point for typical user
|
* This is the standard quality-adjusting entry point for typical user
|
||||||
* interfaces; only those who want detailed control over quantization tables
|
* interfaces; only those who want detailed control over quantization tables
|
||||||
* would use the preceding three routines directly.
|
* would use the preceding routines directly.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
/* Convert user 0-100 rating to percentage scaling */
|
/* Convert user 0-100 rating to percentage scaling */
|
||||||
@@ -162,112 +163,23 @@ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Huffman table setup routines
|
* Reset standard Huffman tables
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LOCAL(void)
|
|
||||||
add_huff_table (j_compress_ptr cinfo,
|
|
||||||
JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
|
|
||||||
/* Define a Huffman table */
|
|
||||||
{
|
|
||||||
int nsymbols, len;
|
|
||||||
|
|
||||||
if (*htblptr == NULL)
|
|
||||||
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
|
|
||||||
|
|
||||||
/* Copy the number-of-symbols-of-each-code-length counts */
|
|
||||||
MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
|
|
||||||
|
|
||||||
/* Validate the counts. We do this here mainly so we can copy the right
|
|
||||||
* number of symbols from the val[] array, without risking marching off
|
|
||||||
* the end of memory. jchuff.c will do a more thorough test later.
|
|
||||||
*/
|
|
||||||
nsymbols = 0;
|
|
||||||
for (len = 1; len <= 16; len++)
|
|
||||||
nsymbols += bits[len];
|
|
||||||
if (nsymbols < 1 || nsymbols > 256)
|
|
||||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
|
||||||
|
|
||||||
MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
|
|
||||||
|
|
||||||
/* Initialize sent_table FALSE so table will be written to JPEG file. */
|
|
||||||
(*htblptr)->sent_table = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LOCAL(void)
|
LOCAL(void)
|
||||||
std_huff_tables (j_compress_ptr cinfo)
|
std_huff_tables (j_compress_ptr cinfo)
|
||||||
/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
|
|
||||||
/* IMPORTANT: these are only valid for 8-bit data precision! */
|
|
||||||
{
|
{
|
||||||
static const UINT8 bits_dc_luminance[17] =
|
if (cinfo->dc_huff_tbl_ptrs[0] != NULL)
|
||||||
{ /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
|
(void) jpeg_std_huff_table((j_common_ptr) cinfo, TRUE, 0);
|
||||||
static const UINT8 val_dc_luminance[] =
|
|
||||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
|
|
||||||
|
|
||||||
static const UINT8 bits_dc_chrominance[17] =
|
if (cinfo->ac_huff_tbl_ptrs[0] != NULL)
|
||||||
{ /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
|
(void) jpeg_std_huff_table((j_common_ptr) cinfo, FALSE, 0);
|
||||||
static const UINT8 val_dc_chrominance[] =
|
|
||||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
|
|
||||||
|
|
||||||
static const UINT8 bits_ac_luminance[17] =
|
if (cinfo->dc_huff_tbl_ptrs[1] != NULL)
|
||||||
{ /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
|
(void) jpeg_std_huff_table((j_common_ptr) cinfo, TRUE, 1);
|
||||||
static const UINT8 val_ac_luminance[] =
|
|
||||||
{ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
|
|
||||||
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
|
|
||||||
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
|
|
||||||
0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
|
|
||||||
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
|
|
||||||
0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
|
|
||||||
0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
|
|
||||||
0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
|
|
||||||
0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
|
|
||||||
0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
|
|
||||||
0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
|
|
||||||
0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
|
|
||||||
0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
|
|
||||||
0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
|
||||||
0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
|
|
||||||
0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
|
|
||||||
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
|
|
||||||
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
|
|
||||||
0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
|
|
||||||
0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
|
||||||
0xf9, 0xfa };
|
|
||||||
|
|
||||||
static const UINT8 bits_ac_chrominance[17] =
|
if (cinfo->ac_huff_tbl_ptrs[1] != NULL)
|
||||||
{ /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
|
(void) jpeg_std_huff_table((j_common_ptr) cinfo, FALSE, 1);
|
||||||
static const UINT8 val_ac_chrominance[] =
|
|
||||||
{ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
|
|
||||||
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
|
|
||||||
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
|
|
||||||
0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
|
|
||||||
0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
|
|
||||||
0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
|
|
||||||
0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
|
|
||||||
0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
|
|
||||||
0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
|
|
||||||
0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
|
|
||||||
0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
|
|
||||||
0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
|
||||||
0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
|
|
||||||
0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
|
|
||||||
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
|
|
||||||
0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
|
|
||||||
0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
|
|
||||||
0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
|
|
||||||
0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
|
|
||||||
0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
|
|
||||||
0xf9, 0xfa };
|
|
||||||
|
|
||||||
add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
|
|
||||||
bits_dc_luminance, val_dc_luminance);
|
|
||||||
add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
|
|
||||||
bits_ac_luminance, val_ac_luminance);
|
|
||||||
add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
|
|
||||||
bits_dc_chrominance, val_dc_chrominance);
|
|
||||||
add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
|
|
||||||
bits_ac_chrominance, val_ac_chrominance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -306,7 +218,7 @@ jpeg_set_defaults (j_compress_ptr cinfo)
|
|||||||
cinfo->data_precision = BITS_IN_JSAMPLE;
|
cinfo->data_precision = BITS_IN_JSAMPLE;
|
||||||
/* Set up two quantization tables using default quality of 75 */
|
/* Set up two quantization tables using default quality of 75 */
|
||||||
jpeg_set_quality(cinfo, 75, TRUE);
|
jpeg_set_quality(cinfo, 75, TRUE);
|
||||||
/* Set up two Huffman tables */
|
/* Reset standard Huffman tables */
|
||||||
std_huff_tables(cinfo);
|
std_huff_tables(cinfo);
|
||||||
|
|
||||||
/* Initialize default arithmetic coding conditioning */
|
/* Initialize default arithmetic coding conditioning */
|
||||||
@@ -323,18 +235,17 @@ jpeg_set_defaults (j_compress_ptr cinfo)
|
|||||||
/* Expect normal source image, not raw downsampled data */
|
/* Expect normal source image, not raw downsampled data */
|
||||||
cinfo->raw_data_in = FALSE;
|
cinfo->raw_data_in = FALSE;
|
||||||
|
|
||||||
/* Use Huffman coding, not arithmetic coding, by default */
|
/* The standard Huffman tables are only valid for 8-bit data precision.
|
||||||
cinfo->arith_code = FALSE;
|
* If the precision is higher, use arithmetic coding.
|
||||||
|
* (Alternatively, using Huffman coding would be possible with forcing
|
||||||
|
* optimization on so that usable tables will be computed, or by
|
||||||
|
* supplying default tables that are valid for the desired precision.)
|
||||||
|
* Otherwise, use Huffman coding by default.
|
||||||
|
*/
|
||||||
|
cinfo->arith_code = cinfo->data_precision > 8 ? TRUE : FALSE;
|
||||||
|
|
||||||
/* By default, don't do extra passes to optimize entropy coding */
|
/* By default, don't do extra passes to optimize entropy coding */
|
||||||
cinfo->optimize_coding = FALSE;
|
cinfo->optimize_coding = FALSE;
|
||||||
/* The standard Huffman tables are only valid for 8-bit data precision.
|
|
||||||
* If the precision is higher, force optimization on so that usable
|
|
||||||
* 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 > 8)
|
|
||||||
cinfo->optimize_coding = TRUE;
|
|
||||||
|
|
||||||
/* By default, use the simpler non-cosited sampling alignment */
|
/* By default, use the simpler non-cosited sampling alignment */
|
||||||
cinfo->CCIR601_sampling = FALSE;
|
cinfo->CCIR601_sampling = FALSE;
|
||||||
@@ -360,6 +271,9 @@ jpeg_set_defaults (j_compress_ptr cinfo)
|
|||||||
* JFIF_minor_version to 2. We could probably get away with just defaulting
|
* JFIF_minor_version to 2. We could probably get away with just defaulting
|
||||||
* to 1.02, but there may still be some decoders in use that will complain
|
* to 1.02, but there may still be some decoders in use that will complain
|
||||||
* about that; saying 1.01 should minimize compatibility problems.
|
* about that; saying 1.01 should minimize compatibility problems.
|
||||||
|
*
|
||||||
|
* For wide gamut colorspaces (BG_RGB and BG_YCC), the major version will be
|
||||||
|
* overridden by jpeg_set_colorspace and set to 2.
|
||||||
*/
|
*/
|
||||||
cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
|
cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
|
||||||
cinfo->JFIF_minor_version = 1;
|
cinfo->JFIF_minor_version = 1;
|
||||||
@@ -367,6 +281,9 @@ jpeg_set_defaults (j_compress_ptr cinfo)
|
|||||||
cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
|
cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
|
||||||
cinfo->Y_density = 1;
|
cinfo->Y_density = 1;
|
||||||
|
|
||||||
|
/* No color transform */
|
||||||
|
cinfo->color_transform = JCT_NONE;
|
||||||
|
|
||||||
/* Choose JPEG colorspace based on input space, set defaults accordingly */
|
/* Choose JPEG colorspace based on input space, set defaults accordingly */
|
||||||
|
|
||||||
jpeg_default_colorspace(cinfo);
|
jpeg_default_colorspace(cinfo);
|
||||||
@@ -381,6 +298,9 @@ GLOBAL(void)
|
|||||||
jpeg_default_colorspace (j_compress_ptr cinfo)
|
jpeg_default_colorspace (j_compress_ptr cinfo)
|
||||||
{
|
{
|
||||||
switch (cinfo->in_color_space) {
|
switch (cinfo->in_color_space) {
|
||||||
|
case JCS_UNKNOWN:
|
||||||
|
jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
|
||||||
|
break;
|
||||||
case JCS_GRAYSCALE:
|
case JCS_GRAYSCALE:
|
||||||
jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
|
jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
|
||||||
break;
|
break;
|
||||||
@@ -396,8 +316,12 @@ jpeg_default_colorspace (j_compress_ptr cinfo)
|
|||||||
case JCS_YCCK:
|
case JCS_YCCK:
|
||||||
jpeg_set_colorspace(cinfo, JCS_YCCK);
|
jpeg_set_colorspace(cinfo, JCS_YCCK);
|
||||||
break;
|
break;
|
||||||
case JCS_UNKNOWN:
|
case JCS_BG_RGB:
|
||||||
jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
|
/* No translation for now -- conversion to BG_YCC not yet supportet */
|
||||||
|
jpeg_set_colorspace(cinfo, JCS_BG_RGB);
|
||||||
|
break;
|
||||||
|
case JCS_BG_YCC:
|
||||||
|
jpeg_set_colorspace(cinfo, JCS_BG_YCC);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
||||||
@@ -438,27 +362,42 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
|
|||||||
cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
|
cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
|
||||||
|
|
||||||
switch (colorspace) {
|
switch (colorspace) {
|
||||||
|
case JCS_UNKNOWN:
|
||||||
|
cinfo->num_components = cinfo->input_components;
|
||||||
|
if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
|
||||||
|
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
|
||||||
|
MAX_COMPONENTS);
|
||||||
|
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||||
|
SET_COMP(ci, ci, 1,1, 0, 0,0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case JCS_GRAYSCALE:
|
case JCS_GRAYSCALE:
|
||||||
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
|
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
|
||||||
cinfo->num_components = 1;
|
cinfo->num_components = 1;
|
||||||
/* JFIF specifies component ID 1 */
|
/* JFIF specifies component ID 1 */
|
||||||
SET_COMP(0, 1, 1,1, 0, 0,0);
|
SET_COMP(0, 0x01, 1,1, 0, 0,0);
|
||||||
break;
|
break;
|
||||||
case JCS_RGB:
|
case JCS_RGB:
|
||||||
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
|
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
|
||||||
cinfo->num_components = 3;
|
cinfo->num_components = 3;
|
||||||
SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
|
SET_COMP(0, 0x52 /* 'R' */, 1,1,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
|
||||||
SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
|
SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
|
||||||
SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
|
SET_COMP(2, 0x42 /* 'B' */, 1,1,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
case JCS_YCbCr:
|
case JCS_YCbCr:
|
||||||
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
|
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
|
||||||
cinfo->num_components = 3;
|
cinfo->num_components = 3;
|
||||||
/* JFIF specifies component IDs 1,2,3 */
|
/* JFIF specifies component IDs 1,2,3 */
|
||||||
/* We default to 2x2 subsamples of chrominance */
|
/* We default to 2x2 subsamples of chrominance */
|
||||||
SET_COMP(0, 1, 2,2, 0, 0,0);
|
SET_COMP(0, 0x01, 2,2, 0, 0,0);
|
||||||
SET_COMP(1, 2, 1,1, 1, 1,1);
|
SET_COMP(1, 0x02, 1,1, 1, 1,1);
|
||||||
SET_COMP(2, 3, 1,1, 1, 1,1);
|
SET_COMP(2, 0x03, 1,1, 1, 1,1);
|
||||||
break;
|
break;
|
||||||
case JCS_CMYK:
|
case JCS_CMYK:
|
||||||
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
|
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
|
||||||
@@ -471,19 +410,35 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
|
|||||||
case JCS_YCCK:
|
case JCS_YCCK:
|
||||||
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
|
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
|
||||||
cinfo->num_components = 4;
|
cinfo->num_components = 4;
|
||||||
SET_COMP(0, 1, 2,2, 0, 0,0);
|
SET_COMP(0, 0x01, 2,2, 0, 0,0);
|
||||||
SET_COMP(1, 2, 1,1, 1, 1,1);
|
SET_COMP(1, 0x02, 1,1, 1, 1,1);
|
||||||
SET_COMP(2, 3, 1,1, 1, 1,1);
|
SET_COMP(2, 0x03, 1,1, 1, 1,1);
|
||||||
SET_COMP(3, 4, 2,2, 0, 0,0);
|
SET_COMP(3, 0x04, 2,2, 0, 0,0);
|
||||||
break;
|
break;
|
||||||
case JCS_UNKNOWN:
|
case JCS_BG_RGB:
|
||||||
cinfo->num_components = cinfo->input_components;
|
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
|
||||||
if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
|
cinfo->JFIF_major_version = 2; /* Set JFIF major version = 2 */
|
||||||
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
|
cinfo->num_components = 3;
|
||||||
MAX_COMPONENTS);
|
/* Add offset 0x20 to the normal R/G/B component IDs */
|
||||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
SET_COMP(0, 0x72 /* 'r' */, 1,1,
|
||||||
SET_COMP(ci, ci, 1,1, 0, 0,0);
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
|
||||||
}
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
|
||||||
|
SET_COMP(1, 0x67 /* 'g' */, 1,1, 0, 0,0);
|
||||||
|
SET_COMP(2, 0x62 /* 'b' */, 1,1,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
|
||||||
|
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case JCS_BG_YCC:
|
||||||
|
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
|
||||||
|
cinfo->JFIF_major_version = 2; /* Set JFIF major version = 2 */
|
||||||
|
cinfo->num_components = 3;
|
||||||
|
/* Add offset 0x20 to the normal Cb/Cr component IDs */
|
||||||
|
/* We default to 2x2 subsamples of chrominance */
|
||||||
|
SET_COMP(0, 0x01, 2,2, 0, 0,0);
|
||||||
|
SET_COMP(1, 0x22, 1,1, 1, 1,1);
|
||||||
|
SET_COMP(2, 0x23, 1,1, 1, 1,1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||||
@@ -567,8 +522,10 @@ jpeg_simple_progression (j_compress_ptr cinfo)
|
|||||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||||
|
|
||||||
/* Figure space needed for script. Calculation must match code below! */
|
/* Figure space needed for script. Calculation must match code below! */
|
||||||
if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
|
if (ncomps == 3 &&
|
||||||
/* Custom script for YCbCr color images. */
|
(cinfo->jpeg_color_space == JCS_YCbCr ||
|
||||||
|
cinfo->jpeg_color_space == JCS_BG_YCC)) {
|
||||||
|
/* Custom script for YCC color images. */
|
||||||
nscans = 10;
|
nscans = 10;
|
||||||
} else {
|
} else {
|
||||||
/* All-purpose script for other color spaces. */
|
/* All-purpose script for other color spaces. */
|
||||||
@@ -583,7 +540,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
|
|||||||
* multiple compressions without changing the settings. To avoid a memory
|
* multiple compressions without changing the settings. To avoid a memory
|
||||||
* leak if jpeg_simple_progression is called repeatedly for the same JPEG
|
* leak if jpeg_simple_progression is called repeatedly for the same JPEG
|
||||||
* object, we try to re-use previously allocated space, and we allocate
|
* object, we try to re-use previously allocated space, and we allocate
|
||||||
* enough space to handle YCbCr even if initially asked for grayscale.
|
* enough space to handle YCC even if initially asked for grayscale.
|
||||||
*/
|
*/
|
||||||
if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
|
if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
|
||||||
cinfo->script_space_size = MAX(nscans, 10);
|
cinfo->script_space_size = MAX(nscans, 10);
|
||||||
@@ -595,8 +552,10 @@ jpeg_simple_progression (j_compress_ptr cinfo)
|
|||||||
cinfo->scan_info = scanptr;
|
cinfo->scan_info = scanptr;
|
||||||
cinfo->num_scans = nscans;
|
cinfo->num_scans = nscans;
|
||||||
|
|
||||||
if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
|
if (ncomps == 3 &&
|
||||||
/* Custom script for YCbCr color images. */
|
(cinfo->jpeg_color_space == JCS_YCbCr ||
|
||||||
|
cinfo->jpeg_color_space == JCS_BG_YCC)) {
|
||||||
|
/* Custom script for YCC color images. */
|
||||||
/* Initial DC scan */
|
/* Initial DC scan */
|
||||||
scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
|
scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
|
||||||
/* Initial AC scan: get some luma data out in a hurry */
|
/* Initial AC scan: get some luma data out in a hurry */
|
||||||
|
|||||||
Vendored
+11
-11
@@ -2,6 +2,7 @@
|
|||||||
* jcprepct.c
|
* jcprepct.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
|
* Modified 2003-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -109,7 +110,8 @@ expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
|
|||||||
register int row;
|
register int row;
|
||||||
|
|
||||||
for (row = input_rows; row < output_rows; row++) {
|
for (row = input_rows; row < output_rows; row++) {
|
||||||
jcopy_sample_rows(image_data, input_rows-1, image_data, row,
|
jcopy_sample_rows(image_data + input_rows - 1,
|
||||||
|
image_data + row,
|
||||||
1, num_cols);
|
1, num_cols);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,8 +222,8 @@ pre_process_context (j_compress_ptr cinfo,
|
|||||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||||
int row;
|
int row;
|
||||||
for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
|
for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
|
||||||
jcopy_sample_rows(prep->color_buf[ci], 0,
|
jcopy_sample_rows(prep->color_buf[ci],
|
||||||
prep->color_buf[ci], -row,
|
prep->color_buf[ci] - row,
|
||||||
1, cinfo->image_width);
|
1, cinfo->image_width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,10 +279,9 @@ create_context_buffer (j_compress_ptr cinfo)
|
|||||||
/* Grab enough space for fake row pointers for all the components;
|
/* Grab enough space for fake row pointers for all the components;
|
||||||
* we need five row groups' worth of pointers for each component.
|
* we need five row groups' worth of pointers for each component.
|
||||||
*/
|
*/
|
||||||
fake_buffer = (JSAMPARRAY)
|
fake_buffer = (JSAMPARRAY) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
(cinfo->num_components * 5 * rgroup_height) *
|
(cinfo->num_components * 5 * rgroup_height) * SIZEOF(JSAMPROW));
|
||||||
SIZEOF(JSAMPROW));
|
|
||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
@@ -324,10 +325,9 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
|||||||
if (need_full_buffer) /* safety check */
|
if (need_full_buffer) /* safety check */
|
||||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||||
|
|
||||||
prep = (my_prep_ptr)
|
prep = (my_prep_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_prep_controller));
|
||||||
SIZEOF(my_prep_controller));
|
cinfo->prep = &prep->pub;
|
||||||
cinfo->prep = (struct jpeg_c_prep_controller *) prep;
|
|
||||||
prep->pub.start_pass = start_pass_prep;
|
prep->pub.start_pass = start_pass_prep;
|
||||||
|
|
||||||
/* Allocate the color conversion buffer.
|
/* Allocate the color conversion buffer.
|
||||||
|
|||||||
Vendored
+5
-5
@@ -2,6 +2,7 @@
|
|||||||
* jcsample.c
|
* jcsample.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||||
|
* Modified 2003-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -200,7 +201,7 @@ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||||
{
|
{
|
||||||
/* Copy the data */
|
/* Copy the data */
|
||||||
jcopy_sample_rows(input_data, 0, output_data, 0,
|
jcopy_sample_rows(input_data, output_data,
|
||||||
cinfo->max_v_samp_factor, cinfo->image_width);
|
cinfo->max_v_samp_factor, cinfo->image_width);
|
||||||
/* Edge-expand */
|
/* Edge-expand */
|
||||||
expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
|
expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
|
||||||
@@ -483,10 +484,9 @@ jinit_downsampler (j_compress_ptr cinfo)
|
|||||||
boolean smoothok = TRUE;
|
boolean smoothok = TRUE;
|
||||||
int h_in_group, v_in_group, h_out_group, v_out_group;
|
int h_in_group, v_in_group, h_out_group, v_out_group;
|
||||||
|
|
||||||
downsample = (my_downsample_ptr)
|
downsample = (my_downsample_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_downsampler));
|
||||||
SIZEOF(my_downsampler));
|
cinfo->downsample = &downsample->pub;
|
||||||
cinfo->downsample = (struct jpeg_downsampler *) downsample;
|
|
||||||
downsample->pub.start_pass = start_pass_downsample;
|
downsample->pub.start_pass = start_pass_downsample;
|
||||||
downsample->pub.downsample = sep_downsample;
|
downsample->pub.downsample = sep_downsample;
|
||||||
downsample->pub.need_context_rows = FALSE;
|
downsample->pub.need_context_rows = FALSE;
|
||||||
|
|||||||
Vendored
+51
-34
@@ -2,7 +2,7 @@
|
|||||||
* jctrans.c
|
* jctrans.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1995-1998, Thomas G. Lane.
|
* Copyright (C) 1995-1998, Thomas G. Lane.
|
||||||
* Modified 2000-2009 by Guido Vollbeding.
|
* Modified 2000-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -85,9 +85,15 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
|||||||
jpeg_set_defaults(dstinfo);
|
jpeg_set_defaults(dstinfo);
|
||||||
/* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
|
/* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
|
||||||
* Fix it to get the right header markers for the image colorspace.
|
* Fix it to get the right header markers for the image colorspace.
|
||||||
|
* Note: Entropy table assignment in jpeg_set_colorspace
|
||||||
|
* depends on color_transform.
|
||||||
|
* Adaption is also required for setting the appropriate
|
||||||
|
* entropy coding mode dependent on image data precision.
|
||||||
*/
|
*/
|
||||||
|
dstinfo->color_transform = srcinfo->color_transform;
|
||||||
jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
|
jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
|
||||||
dstinfo->data_precision = srcinfo->data_precision;
|
dstinfo->data_precision = srcinfo->data_precision;
|
||||||
|
dstinfo->arith_code = srcinfo->data_precision > 8 ? TRUE : FALSE;
|
||||||
dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
|
dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
|
||||||
/* Copy the source's quantization tables. */
|
/* Copy the source's quantization tables. */
|
||||||
for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
|
for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
|
||||||
@@ -130,7 +136,7 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
|||||||
ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
|
ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Note: we do not copy the source's Huffman table assignments;
|
/* Note: we do not copy the source's entropy table assignments;
|
||||||
* instead we rely on jpeg_set_colorspace to have made a suitable choice.
|
* instead we rely on jpeg_set_colorspace to have made a suitable choice.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
@@ -140,10 +146,10 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
|||||||
* if the application chooses to copy JFIF 1.02 extension markers from
|
* if the application chooses to copy JFIF 1.02 extension markers from
|
||||||
* the source file, we need to copy the version to make sure we don't
|
* the source file, we need to copy the version to make sure we don't
|
||||||
* emit a file that has 1.02 extensions but a claimed version of 1.01.
|
* emit a file that has 1.02 extensions but a claimed version of 1.01.
|
||||||
* We will *not*, however, copy version info from mislabeled "2.01" files.
|
|
||||||
*/
|
*/
|
||||||
if (srcinfo->saw_JFIF_marker) {
|
if (srcinfo->saw_JFIF_marker) {
|
||||||
if (srcinfo->JFIF_major_version == 1) {
|
if (srcinfo->JFIF_major_version == 1 ||
|
||||||
|
srcinfo->JFIF_major_version == 2) {
|
||||||
dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
|
dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
|
||||||
dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
|
dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
|
||||||
}
|
}
|
||||||
@@ -154,6 +160,18 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL(void)
|
||||||
|
jpeg_calc_trans_dimensions (j_compress_ptr cinfo)
|
||||||
|
/* Do computations that are needed before master selection phase */
|
||||||
|
{
|
||||||
|
if (cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size)
|
||||||
|
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
|
||||||
|
cinfo->min_DCT_h_scaled_size, cinfo->min_DCT_v_scaled_size);
|
||||||
|
|
||||||
|
cinfo->block_size = cinfo->min_DCT_h_scaled_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Master selection of compression modules for transcoding.
|
* Master selection of compression modules for transcoding.
|
||||||
* This substitutes for jcinit.c's initialization of the full compressor.
|
* This substitutes for jcinit.c's initialization of the full compressor.
|
||||||
@@ -163,6 +181,9 @@ LOCAL(void)
|
|||||||
transencode_master_selection (j_compress_ptr cinfo,
|
transencode_master_selection (j_compress_ptr cinfo,
|
||||||
jvirt_barray_ptr * coef_arrays)
|
jvirt_barray_ptr * coef_arrays)
|
||||||
{
|
{
|
||||||
|
/* Do computations that are needed before master selection phase */
|
||||||
|
jpeg_calc_trans_dimensions(cinfo);
|
||||||
|
|
||||||
/* Initialize master control (includes parameter checking/processing) */
|
/* Initialize master control (includes parameter checking/processing) */
|
||||||
jinit_c_master_control(cinfo, TRUE /* transcode only */);
|
jinit_c_master_control(cinfo, TRUE /* transcode only */);
|
||||||
|
|
||||||
@@ -203,7 +224,7 @@ typedef struct {
|
|||||||
struct jpeg_c_coef_controller pub; /* public fields */
|
struct jpeg_c_coef_controller pub; /* public fields */
|
||||||
|
|
||||||
JDIMENSION iMCU_row_num; /* iMCU row # within image */
|
JDIMENSION iMCU_row_num; /* iMCU row # within image */
|
||||||
JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
|
JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
|
||||||
int MCU_vert_offset; /* counts MCU rows within iMCU row */
|
int MCU_vert_offset; /* counts MCU rows within iMCU row */
|
||||||
int MCU_rows_per_iMCU_row; /* number of such rows needed */
|
int MCU_rows_per_iMCU_row; /* number of such rows needed */
|
||||||
|
|
||||||
@@ -211,7 +232,7 @@ typedef struct {
|
|||||||
jvirt_barray_ptr * whole_image;
|
jvirt_barray_ptr * whole_image;
|
||||||
|
|
||||||
/* Workspace for constructing dummy blocks at right/bottom edges. */
|
/* Workspace for constructing dummy blocks at right/bottom edges. */
|
||||||
JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
|
JBLOCK dummy_buffer[C_MAX_BLOCKS_IN_MCU];
|
||||||
} my_coef_controller;
|
} my_coef_controller;
|
||||||
|
|
||||||
typedef my_coef_controller * my_coef_ptr;
|
typedef my_coef_controller * my_coef_ptr;
|
||||||
@@ -236,7 +257,7 @@ start_iMCU_row (j_compress_ptr cinfo)
|
|||||||
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
|
coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
coef->mcu_ctr = 0;
|
coef->MCU_ctr = 0;
|
||||||
coef->MCU_vert_offset = 0;
|
coef->MCU_vert_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,25 +315,30 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
/* Loop to process one whole iMCU row */
|
/* Loop to process one whole iMCU row */
|
||||||
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
||||||
yoffset++) {
|
yoffset++) {
|
||||||
for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
|
for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
|
||||||
MCU_col_num++) {
|
MCU_col_num++) {
|
||||||
/* Construct list of pointers to DCT blocks belonging to this MCU */
|
/* Construct list of pointers to DCT blocks belonging to this MCU */
|
||||||
blkn = 0; /* index of current DCT block within MCU */
|
blkn = 0; /* index of current DCT block within MCU */
|
||||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||||
compptr = cinfo->cur_comp_info[ci];
|
compptr = cinfo->cur_comp_info[ci];
|
||||||
start_col = MCU_col_num * compptr->MCU_width;
|
|
||||||
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
||||||
: compptr->last_col_width;
|
: compptr->last_col_width;
|
||||||
|
start_col = MCU_col_num * compptr->MCU_width;
|
||||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||||
if (coef->iMCU_row_num < last_iMCU_row ||
|
if (coef->iMCU_row_num < last_iMCU_row ||
|
||||||
yindex+yoffset < compptr->last_row_height) {
|
yoffset + yindex < compptr->last_row_height) {
|
||||||
/* Fill in pointers to real blocks in this row */
|
/* Fill in pointers to real blocks in this row */
|
||||||
buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
|
buffer_ptr = buffer[ci][yoffset + yindex] + start_col;
|
||||||
for (xindex = 0; xindex < blockcnt; xindex++)
|
xindex = blockcnt;
|
||||||
|
do {
|
||||||
MCU_buffer[blkn++] = buffer_ptr++;
|
MCU_buffer[blkn++] = buffer_ptr++;
|
||||||
|
} while (--xindex);
|
||||||
|
/* Dummy blocks at right edge */
|
||||||
|
if ((xindex = compptr->MCU_width - blockcnt) == 0)
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
/* At bottom of image, need a whole row of dummy blocks */
|
/* At bottom of image, need a whole row of dummy blocks */
|
||||||
xindex = 0;
|
xindex = compptr->MCU_width;
|
||||||
}
|
}
|
||||||
/* Fill in any dummy blocks needed in this row.
|
/* Fill in any dummy blocks needed in this row.
|
||||||
* Dummy blocks are filled in the same way as in jccoefct.c:
|
* Dummy blocks are filled in the same way as in jccoefct.c:
|
||||||
@@ -320,23 +346,23 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
|||||||
* block's DC value. The init routine has already zeroed the
|
* block's DC value. The init routine has already zeroed the
|
||||||
* AC entries, so we need only set the DC entries correctly.
|
* AC entries, so we need only set the DC entries correctly.
|
||||||
*/
|
*/
|
||||||
for (; xindex < compptr->MCU_width; xindex++) {
|
buffer_ptr = coef->dummy_buffer + blkn;
|
||||||
MCU_buffer[blkn] = coef->dummy_buffer[blkn];
|
do {
|
||||||
MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
|
buffer_ptr[0][0] = MCU_buffer[blkn-1][0][0];
|
||||||
blkn++;
|
MCU_buffer[blkn++] = buffer_ptr++;
|
||||||
}
|
} while (--xindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Try to write the MCU. */
|
/* Try to write the MCU. */
|
||||||
if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
|
if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
|
||||||
/* Suspension forced; update state counters and exit */
|
/* Suspension forced; update state counters and exit */
|
||||||
coef->MCU_vert_offset = yoffset;
|
coef->MCU_vert_offset = yoffset;
|
||||||
coef->mcu_ctr = MCU_col_num;
|
coef->MCU_ctr = MCU_col_num;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||||
coef->mcu_ctr = 0;
|
coef->MCU_ctr = 0;
|
||||||
}
|
}
|
||||||
/* Completed the iMCU row, advance counters for next one */
|
/* Completed the iMCU row, advance counters for next one */
|
||||||
coef->iMCU_row_num++;
|
coef->iMCU_row_num++;
|
||||||
@@ -358,25 +384,16 @@ transencode_coef_controller (j_compress_ptr cinfo,
|
|||||||
jvirt_barray_ptr * coef_arrays)
|
jvirt_barray_ptr * coef_arrays)
|
||||||
{
|
{
|
||||||
my_coef_ptr coef;
|
my_coef_ptr coef;
|
||||||
JBLOCKROW buffer;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
coef = (my_coef_ptr)
|
coef = (my_coef_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_coef_controller));
|
||||||
SIZEOF(my_coef_controller));
|
cinfo->coef = &coef->pub;
|
||||||
cinfo->coef = (struct jpeg_c_coef_controller *) coef;
|
|
||||||
coef->pub.start_pass = start_pass_coef;
|
coef->pub.start_pass = start_pass_coef;
|
||||||
coef->pub.compress_data = compress_output;
|
coef->pub.compress_data = compress_output;
|
||||||
|
|
||||||
/* Save pointer to virtual arrays */
|
/* Save pointer to virtual arrays */
|
||||||
coef->whole_image = coef_arrays;
|
coef->whole_image = coef_arrays;
|
||||||
|
|
||||||
/* Allocate and pre-zero space for dummy DCT blocks. */
|
/* Pre-zero space for dummy DCT blocks */
|
||||||
buffer = (JBLOCKROW)
|
MEMZERO(coef->dummy_buffer, SIZEOF(coef->dummy_buffer));
|
||||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
||||||
C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
|
||||||
jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
|
||||||
for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
|
|
||||||
coef->dummy_buffer[i] = buffer + i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+41
-25
@@ -2,7 +2,7 @@
|
|||||||
* jdapimin.c
|
* jdapimin.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||||
* Modified 2009 by Guido Vollbeding.
|
* Modified 2009-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -114,8 +114,9 @@ jpeg_abort_decompress (j_decompress_ptr cinfo)
|
|||||||
LOCAL(void)
|
LOCAL(void)
|
||||||
default_decompress_parms (j_decompress_ptr cinfo)
|
default_decompress_parms (j_decompress_ptr cinfo)
|
||||||
{
|
{
|
||||||
|
int cid0, cid1, cid2, cid3;
|
||||||
|
|
||||||
/* Guess the input colorspace, and set output colorspace accordingly. */
|
/* Guess the input colorspace, and set output colorspace accordingly. */
|
||||||
/* (Wish JPEG committee had provided a real way to specify this...) */
|
|
||||||
/* Note application may override our guesses. */
|
/* Note application may override our guesses. */
|
||||||
switch (cinfo->num_components) {
|
switch (cinfo->num_components) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -124,9 +125,25 @@ default_decompress_parms (j_decompress_ptr cinfo)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
if (cinfo->saw_JFIF_marker) {
|
cid0 = cinfo->comp_info[0].component_id;
|
||||||
cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
|
cid1 = cinfo->comp_info[1].component_id;
|
||||||
} else if (cinfo->saw_Adobe_marker) {
|
cid2 = cinfo->comp_info[2].component_id;
|
||||||
|
|
||||||
|
/* For robust detection of standard colorspaces
|
||||||
|
* regardless of the presence of special markers,
|
||||||
|
* check component IDs from SOF marker first.
|
||||||
|
*/
|
||||||
|
if (cid0 == 0x01 && cid1 == 0x02 && cid2 == 0x03)
|
||||||
|
cinfo->jpeg_color_space = JCS_YCbCr;
|
||||||
|
else if (cid0 == 0x01 && cid1 == 0x22 && cid2 == 0x23)
|
||||||
|
cinfo->jpeg_color_space = JCS_BG_YCC;
|
||||||
|
else if (cid0 == 0x52 && cid1 == 0x47 && cid2 == 0x42)
|
||||||
|
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
|
||||||
|
else if (cid0 == 0x72 && cid1 == 0x67 && cid2 == 0x62)
|
||||||
|
cinfo->jpeg_color_space = JCS_BG_RGB; /* ASCII 'r', 'g', 'b' */
|
||||||
|
else if (cinfo->saw_JFIF_marker)
|
||||||
|
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
||||||
|
else if (cinfo->saw_Adobe_marker) {
|
||||||
switch (cinfo->Adobe_transform) {
|
switch (cinfo->Adobe_transform) {
|
||||||
case 0:
|
case 0:
|
||||||
cinfo->jpeg_color_space = JCS_RGB;
|
cinfo->jpeg_color_space = JCS_RGB;
|
||||||
@@ -136,30 +153,31 @@ default_decompress_parms (j_decompress_ptr cinfo)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
||||||
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Saw no special markers, try to guess from the component IDs */
|
TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
|
||||||
int cid0 = cinfo->comp_info[0].component_id;
|
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
||||||
int cid1 = cinfo->comp_info[1].component_id;
|
|
||||||
int cid2 = cinfo->comp_info[2].component_id;
|
|
||||||
|
|
||||||
if (cid0 == 1 && cid1 == 2 && cid2 == 3)
|
|
||||||
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);
|
|
||||||
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* Always guess RGB is proper output colorspace. */
|
/* Always guess RGB is proper output colorspace. */
|
||||||
cinfo->out_color_space = JCS_RGB;
|
cinfo->out_color_space = JCS_RGB;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
if (cinfo->saw_Adobe_marker) {
|
cid0 = cinfo->comp_info[0].component_id;
|
||||||
|
cid1 = cinfo->comp_info[1].component_id;
|
||||||
|
cid2 = cinfo->comp_info[2].component_id;
|
||||||
|
cid3 = cinfo->comp_info[3].component_id;
|
||||||
|
|
||||||
|
/* For robust detection of standard colorspaces
|
||||||
|
* regardless of the presence of special markers,
|
||||||
|
* check component IDs from SOF marker first.
|
||||||
|
*/
|
||||||
|
if (cid0 == 0x01 && cid1 == 0x02 && cid2 == 0x03 && cid3 == 0x04)
|
||||||
|
cinfo->jpeg_color_space = JCS_YCCK;
|
||||||
|
else if (cid0 == 0x43 && cid1 == 0x4D && cid2 == 0x59 && cid3 == 0x4B)
|
||||||
|
cinfo->jpeg_color_space = JCS_CMYK; /* ASCII 'C', 'M', 'Y', 'K' */
|
||||||
|
else if (cinfo->saw_Adobe_marker) {
|
||||||
switch (cinfo->Adobe_transform) {
|
switch (cinfo->Adobe_transform) {
|
||||||
case 0:
|
case 0:
|
||||||
cinfo->jpeg_color_space = JCS_CMYK;
|
cinfo->jpeg_color_space = JCS_CMYK;
|
||||||
@@ -169,11 +187,10 @@ default_decompress_parms (j_decompress_ptr cinfo)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
||||||
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
|
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* No special markers, assume straight CMYK. */
|
/* Unknown IDs and no special markers, assume straight CMYK. */
|
||||||
cinfo->jpeg_color_space = JCS_CMYK;
|
cinfo->jpeg_color_space = JCS_CMYK;
|
||||||
}
|
}
|
||||||
cinfo->out_color_space = JCS_CMYK;
|
cinfo->out_color_space = JCS_CMYK;
|
||||||
@@ -182,7 +199,6 @@ default_decompress_parms (j_decompress_ptr cinfo)
|
|||||||
default:
|
default:
|
||||||
cinfo->jpeg_color_space = JCS_UNKNOWN;
|
cinfo->jpeg_color_space = JCS_UNKNOWN;
|
||||||
cinfo->out_color_space = JCS_UNKNOWN;
|
cinfo->out_color_space = JCS_UNKNOWN;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set defaults for other decompression parameters. */
|
/* Set defaults for other decompression parameters. */
|
||||||
|
|||||||
Vendored
+1
@@ -2,6 +2,7 @@
|
|||||||
* jdapistd.c
|
* jdapistd.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
|
* Modified 2002-2013 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
|
|||||||
Vendored
+66
-42
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* jdarith.c
|
* jdarith.c
|
||||||
*
|
*
|
||||||
* Developed 1997-2009 by Guido Vollbeding.
|
* Developed 1997-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -94,7 +94,7 @@ get_byte (j_decompress_ptr cinfo)
|
|||||||
* (instead of fixed) with the bit shift counter CT.
|
* (instead of fixed) with the bit shift counter CT.
|
||||||
* Thus, we also need only one (variable instead of
|
* Thus, we also need only one (variable instead of
|
||||||
* fixed size) shift for the LPS/MPS decision, and
|
* fixed size) shift for the LPS/MPS decision, and
|
||||||
* we can get away with any renormalization update
|
* we can do away with any renormalization update
|
||||||
* of C (except for new data insertion, of course).
|
* of C (except for new data insertion, of course).
|
||||||
*
|
*
|
||||||
* I've also introduced a new scheme for accessing
|
* I've also introduced a new scheme for accessing
|
||||||
@@ -145,7 +145,7 @@ arith_decode (j_decompress_ptr cinfo, unsigned char *st)
|
|||||||
e->a <<= 1;
|
e->a <<= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fetch values from our compact representation of Table D.2:
|
/* Fetch values from our compact representation of Table D.3(D.2):
|
||||||
* Qe values and probability estimation state machine
|
* Qe values and probability estimation state machine
|
||||||
*/
|
*/
|
||||||
sv = *st;
|
sv = *st;
|
||||||
@@ -239,7 +239,7 @@ process_restart (j_decompress_ptr cinfo)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
JBLOCKROW block;
|
JBLOCKROW block;
|
||||||
@@ -280,7 +280,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
if ((m = arith_decode(cinfo, st)) != 0) {
|
if ((m = arith_decode(cinfo, st)) != 0) {
|
||||||
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
|
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
|
||||||
while (arith_decode(cinfo, st)) {
|
while (arith_decode(cinfo, st)) {
|
||||||
if ((m <<= 1) == 0x8000) {
|
if ((m <<= 1) == (int) 0x8000U) {
|
||||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||||
entropy->ct = -1; /* magnitude overflow */
|
entropy->ct = -1; /* magnitude overflow */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -318,7 +318,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
JBLOCKROW block;
|
JBLOCKROW block;
|
||||||
@@ -345,12 +345,15 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
/* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
|
/* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
|
||||||
|
|
||||||
/* Figure F.20: Decode_AC_coefficients */
|
/* Figure F.20: Decode_AC_coefficients */
|
||||||
for (k = cinfo->Ss; k <= cinfo->Se; k++) {
|
k = cinfo->Ss - 1;
|
||||||
st = entropy->ac_stats[tbl] + 3 * (k - 1);
|
do {
|
||||||
|
st = entropy->ac_stats[tbl] + 3 * k;
|
||||||
if (arith_decode(cinfo, st)) break; /* EOB flag */
|
if (arith_decode(cinfo, st)) break; /* EOB flag */
|
||||||
while (arith_decode(cinfo, st + 1) == 0) {
|
for (;;) {
|
||||||
st += 3; k++;
|
k++;
|
||||||
if (k > cinfo->Se) {
|
if (arith_decode(cinfo, st + 1)) break;
|
||||||
|
st += 3;
|
||||||
|
if (k >= cinfo->Se) {
|
||||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||||
entropy->ct = -1; /* spectral overflow */
|
entropy->ct = -1; /* spectral overflow */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -367,7 +370,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
st = entropy->ac_stats[tbl] +
|
st = entropy->ac_stats[tbl] +
|
||||||
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
|
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
|
||||||
while (arith_decode(cinfo, st)) {
|
while (arith_decode(cinfo, st)) {
|
||||||
if ((m <<= 1) == 0x8000) {
|
if ((m <<= 1) == (int) 0x8000U) {
|
||||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||||
entropy->ct = -1; /* magnitude overflow */
|
entropy->ct = -1; /* magnitude overflow */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -384,7 +387,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
v += 1; if (sign) v = -v;
|
v += 1; if (sign) v = -v;
|
||||||
/* Scale and output coefficient in natural (dezigzagged) order */
|
/* Scale and output coefficient in natural (dezigzagged) order */
|
||||||
(*block)[natural_order[k]] = (JCOEF) (v << cinfo->Al);
|
(*block)[natural_order[k]] = (JCOEF) (v << cinfo->Al);
|
||||||
}
|
} while (k < cinfo->Se);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -392,14 +395,17 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* MCU decoding for DC successive approximation refinement scan.
|
* MCU decoding for DC successive approximation refinement scan.
|
||||||
|
* Note: we assume such scans can be multi-component,
|
||||||
|
* although the spec is not very clear on the point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
unsigned char *st;
|
unsigned char *st;
|
||||||
int p1, blkn;
|
JCOEF p1;
|
||||||
|
int blkn;
|
||||||
|
|
||||||
/* Process restart marker if needed */
|
/* Process restart marker if needed */
|
||||||
if (cinfo->restart_interval) {
|
if (cinfo->restart_interval) {
|
||||||
@@ -428,14 +434,14 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
JBLOCKROW block;
|
JBLOCKROW block;
|
||||||
JCOEFPTR thiscoef;
|
JCOEFPTR thiscoef;
|
||||||
unsigned char *st;
|
unsigned char *st;
|
||||||
int tbl, k, kex;
|
int tbl, k, kex;
|
||||||
int p1, m1;
|
JCOEF p1, m1;
|
||||||
const int * natural_order;
|
const int * natural_order;
|
||||||
|
|
||||||
/* Process restart marker if needed */
|
/* Process restart marker if needed */
|
||||||
@@ -454,18 +460,21 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
|
tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
|
||||||
|
|
||||||
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
||||||
m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
|
m1 = -p1; /* -1 in the bit position being coded */
|
||||||
|
|
||||||
/* Establish EOBx (previous stage end-of-block) index */
|
/* Establish EOBx (previous stage end-of-block) index */
|
||||||
for (kex = cinfo->Se; kex > 0; kex--)
|
kex = cinfo->Se;
|
||||||
|
do {
|
||||||
if ((*block)[natural_order[kex]]) break;
|
if ((*block)[natural_order[kex]]) break;
|
||||||
|
} while (--kex);
|
||||||
|
|
||||||
for (k = cinfo->Ss; k <= cinfo->Se; k++) {
|
k = cinfo->Ss - 1;
|
||||||
st = entropy->ac_stats[tbl] + 3 * (k - 1);
|
do {
|
||||||
if (k > kex)
|
st = entropy->ac_stats[tbl] + 3 * k;
|
||||||
|
if (k >= kex)
|
||||||
if (arith_decode(cinfo, st)) break; /* EOB flag */
|
if (arith_decode(cinfo, st)) break; /* EOB flag */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
thiscoef = *block + natural_order[k];
|
thiscoef = *block + natural_order[++k];
|
||||||
if (*thiscoef) { /* previously nonzero coef */
|
if (*thiscoef) { /* previously nonzero coef */
|
||||||
if (arith_decode(cinfo, st + 2)) {
|
if (arith_decode(cinfo, st + 2)) {
|
||||||
if (*thiscoef < 0)
|
if (*thiscoef < 0)
|
||||||
@@ -482,14 +491,14 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*thiscoef = p1;
|
*thiscoef = p1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
st += 3; k++;
|
st += 3;
|
||||||
if (k > cinfo->Se) {
|
if (k >= cinfo->Se) {
|
||||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||||
entropy->ct = -1; /* spectral overflow */
|
entropy->ct = -1; /* spectral overflow */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (k < cinfo->Se);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -500,7 +509,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||||
jpeg_component_info * compptr;
|
jpeg_component_info * compptr;
|
||||||
@@ -547,7 +556,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
if ((m = arith_decode(cinfo, st)) != 0) {
|
if ((m = arith_decode(cinfo, st)) != 0) {
|
||||||
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
|
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
|
||||||
while (arith_decode(cinfo, st)) {
|
while (arith_decode(cinfo, st)) {
|
||||||
if ((m <<= 1) == 0x8000) {
|
if ((m <<= 1) == (int) 0x8000U) {
|
||||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||||
entropy->ct = -1; /* magnitude overflow */
|
entropy->ct = -1; /* magnitude overflow */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -575,15 +584,19 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
|
/* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
|
||||||
|
|
||||||
|
if (cinfo->lim_Se == 0) continue;
|
||||||
tbl = compptr->ac_tbl_no;
|
tbl = compptr->ac_tbl_no;
|
||||||
|
k = 0;
|
||||||
|
|
||||||
/* Figure F.20: Decode_AC_coefficients */
|
/* Figure F.20: Decode_AC_coefficients */
|
||||||
for (k = 1; k <= cinfo->lim_Se; k++) {
|
do {
|
||||||
st = entropy->ac_stats[tbl] + 3 * (k - 1);
|
st = entropy->ac_stats[tbl] + 3 * k;
|
||||||
if (arith_decode(cinfo, st)) break; /* EOB flag */
|
if (arith_decode(cinfo, st)) break; /* EOB flag */
|
||||||
while (arith_decode(cinfo, st + 1) == 0) {
|
for (;;) {
|
||||||
st += 3; k++;
|
k++;
|
||||||
if (k > cinfo->lim_Se) {
|
if (arith_decode(cinfo, st + 1)) break;
|
||||||
|
st += 3;
|
||||||
|
if (k >= cinfo->lim_Se) {
|
||||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||||
entropy->ct = -1; /* spectral overflow */
|
entropy->ct = -1; /* spectral overflow */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -600,7 +613,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
st = entropy->ac_stats[tbl] +
|
st = entropy->ac_stats[tbl] +
|
||||||
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
|
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
|
||||||
while (arith_decode(cinfo, st)) {
|
while (arith_decode(cinfo, st)) {
|
||||||
if ((m <<= 1) == 0x8000) {
|
if ((m <<= 1) == (int) 0x8000U) {
|
||||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||||
entropy->ct = -1; /* magnitude overflow */
|
entropy->ct = -1; /* magnitude overflow */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -616,7 +629,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
if (arith_decode(cinfo, st)) v |= m;
|
if (arith_decode(cinfo, st)) v |= m;
|
||||||
v += 1; if (sign) v = -v;
|
v += 1; if (sign) v = -v;
|
||||||
(*block)[natural_order[k]] = (JCOEF) v;
|
(*block)[natural_order[k]] = (JCOEF) v;
|
||||||
}
|
} while (k < cinfo->lim_Se);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -733,6 +746,17 @@ start_pass (j_decompress_ptr cinfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Finish up at the end of an arithmetic-compressed scan.
|
||||||
|
*/
|
||||||
|
|
||||||
|
METHODDEF(void)
|
||||||
|
finish_pass (j_decompress_ptr cinfo)
|
||||||
|
{
|
||||||
|
/* no work necessary here */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Module initialization routine for arithmetic entropy decoding.
|
* Module initialization routine for arithmetic entropy decoding.
|
||||||
*/
|
*/
|
||||||
@@ -743,11 +767,11 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
|
|||||||
arith_entropy_ptr entropy;
|
arith_entropy_ptr entropy;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
entropy = (arith_entropy_ptr)
|
entropy = (arith_entropy_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(arith_entropy_decoder));
|
||||||
SIZEOF(arith_entropy_decoder));
|
cinfo->entropy = &entropy->pub;
|
||||||
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
|
|
||||||
entropy->pub.start_pass = start_pass;
|
entropy->pub.start_pass = start_pass;
|
||||||
|
entropy->pub.finish_pass = finish_pass;
|
||||||
|
|
||||||
/* Mark tables unallocated */
|
/* Mark tables unallocated */
|
||||||
for (i = 0; i < NUM_ARITH_TBLS; i++) {
|
for (i = 0; i < NUM_ARITH_TBLS; i++) {
|
||||||
@@ -761,9 +785,9 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
|
|||||||
if (cinfo->progressive_mode) {
|
if (cinfo->progressive_mode) {
|
||||||
/* Create progression status table */
|
/* Create progression status table */
|
||||||
int *coef_bit_ptr, ci;
|
int *coef_bit_ptr, ci;
|
||||||
cinfo->coef_bits = (int (*)[DCTSIZE2])
|
cinfo->coef_bits = (int (*)[DCTSIZE2]) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
cinfo->num_components*DCTSIZE2*SIZEOF(int));
|
cinfo->num_components * DCTSIZE2 * SIZEOF(int));
|
||||||
coef_bit_ptr = & cinfo->coef_bits[0][0];
|
coef_bit_ptr = & cinfo->coef_bits[0][0];
|
||||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||||
for (i = 0; i < DCTSIZE2; i++)
|
for (i = 0; i < DCTSIZE2; i++)
|
||||||
|
|||||||
Vendored
+17
-17
@@ -2,7 +2,7 @@
|
|||||||
* jdatadst.c
|
* jdatadst.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
* Modified 2009 by Guido Vollbeding.
|
* Modified 2009-2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -46,7 +46,7 @@ typedef struct {
|
|||||||
struct jpeg_destination_mgr pub; /* public fields */
|
struct jpeg_destination_mgr pub; /* public fields */
|
||||||
|
|
||||||
unsigned char ** outbuffer; /* target buffer */
|
unsigned char ** outbuffer; /* target buffer */
|
||||||
unsigned long * outsize;
|
size_t * outsize;
|
||||||
unsigned char * newbuffer; /* newly allocated buffer */
|
unsigned char * newbuffer; /* newly allocated buffer */
|
||||||
JOCTET * buffer; /* start of buffer */
|
JOCTET * buffer; /* start of buffer */
|
||||||
size_t bufsize;
|
size_t bufsize;
|
||||||
@@ -66,9 +66,8 @@ init_destination (j_compress_ptr cinfo)
|
|||||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||||
|
|
||||||
/* Allocate the output buffer --- it will be released when done with image */
|
/* Allocate the output buffer --- it will be released when done with image */
|
||||||
dest->buffer = (JOCTET *)
|
dest->buffer = (JOCTET *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
|
||||||
OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
|
|
||||||
|
|
||||||
dest->pub.next_output_byte = dest->buffer;
|
dest->pub.next_output_byte = dest->buffer;
|
||||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
||||||
@@ -128,10 +127,10 @@ empty_mem_output_buffer (j_compress_ptr cinfo)
|
|||||||
|
|
||||||
/* Try to allocate new buffer with double size */
|
/* Try to allocate new buffer with double size */
|
||||||
nextsize = dest->bufsize * 2;
|
nextsize = dest->bufsize * 2;
|
||||||
nextbuffer = malloc(nextsize);
|
nextbuffer = (JOCTET *) malloc(nextsize);
|
||||||
|
|
||||||
if (nextbuffer == NULL)
|
if (nextbuffer == NULL)
|
||||||
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
|
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 11);
|
||||||
|
|
||||||
MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
|
MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
|
||||||
|
|
||||||
@@ -170,9 +169,9 @@ term_destination (j_compress_ptr cinfo)
|
|||||||
if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
|
if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
|
||||||
ERREXIT(cinfo, JERR_FILE_WRITE);
|
ERREXIT(cinfo, JERR_FILE_WRITE);
|
||||||
}
|
}
|
||||||
fflush(dest->outfile);
|
JFFLUSH(dest->outfile);
|
||||||
/* Make sure we wrote the output file OK */
|
/* Make sure we wrote the output file OK */
|
||||||
if (ferror(dest->outfile))
|
if (JFERROR(dest->outfile))
|
||||||
ERREXIT(cinfo, JERR_FILE_WRITE);
|
ERREXIT(cinfo, JERR_FILE_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,9 +203,8 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
|
|||||||
* sizes may be different. Caveat programmer.
|
* sizes may be different. Caveat programmer.
|
||||||
*/
|
*/
|
||||||
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
||||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
cinfo->dest = (struct jpeg_destination_mgr *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_destination_mgr));
|
||||||
SIZEOF(my_destination_mgr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = (my_dest_ptr) cinfo->dest;
|
dest = (my_dest_ptr) cinfo->dest;
|
||||||
@@ -226,11 +224,14 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
|
|||||||
* larger memory, so the buffer is available to the application after
|
* larger memory, so the buffer is available to the application after
|
||||||
* finishing compression, and then the application is responsible for
|
* finishing compression, and then the application is responsible for
|
||||||
* freeing the requested memory.
|
* freeing the requested memory.
|
||||||
|
* Note: An initial buffer supplied by the caller is expected to be
|
||||||
|
* managed by the application. The library does not free such buffer
|
||||||
|
* when allocating a larger buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
jpeg_mem_dest (j_compress_ptr cinfo,
|
jpeg_mem_dest (j_compress_ptr cinfo,
|
||||||
unsigned char ** outbuffer, unsigned long * outsize)
|
unsigned char ** outbuffer, size_t * outsize)
|
||||||
{
|
{
|
||||||
my_mem_dest_ptr dest;
|
my_mem_dest_ptr dest;
|
||||||
|
|
||||||
@@ -241,9 +242,8 @@ jpeg_mem_dest (j_compress_ptr cinfo,
|
|||||||
* can be written to the same buffer without re-executing jpeg_mem_dest.
|
* can be written to the same buffer without re-executing jpeg_mem_dest.
|
||||||
*/
|
*/
|
||||||
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
||||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
cinfo->dest = (struct jpeg_destination_mgr *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_mem_destination_mgr));
|
||||||
SIZEOF(my_mem_destination_mgr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dest = (my_mem_dest_ptr) cinfo->dest;
|
dest = (my_mem_dest_ptr) cinfo->dest;
|
||||||
@@ -256,7 +256,7 @@ jpeg_mem_dest (j_compress_ptr cinfo,
|
|||||||
|
|
||||||
if (*outbuffer == NULL || *outsize == 0) {
|
if (*outbuffer == NULL || *outsize == 0) {
|
||||||
/* Allocate initial buffer */
|
/* Allocate initial buffer */
|
||||||
dest->newbuffer = *outbuffer = malloc(OUTPUT_BUF_SIZE);
|
dest->newbuffer = *outbuffer = (unsigned char *) malloc(OUTPUT_BUF_SIZE);
|
||||||
if (dest->newbuffer == NULL)
|
if (dest->newbuffer == NULL)
|
||||||
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
|
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
|
||||||
*outsize = OUTPUT_BUF_SIZE;
|
*outsize = OUTPUT_BUF_SIZE;
|
||||||
|
|||||||
Vendored
+20
-20
@@ -2,7 +2,7 @@
|
|||||||
* jdatasrc.c
|
* jdatasrc.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
* Modified 2009-2010 by Guido Vollbeding.
|
* Modified 2009-2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -121,16 +121,17 @@ fill_input_buffer (j_decompress_ptr cinfo)
|
|||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
fill_mem_input_buffer (j_decompress_ptr cinfo)
|
fill_mem_input_buffer (j_decompress_ptr cinfo)
|
||||||
{
|
{
|
||||||
static JOCTET mybuffer[4];
|
static const JOCTET mybuffer[4] = {
|
||||||
|
(JOCTET) 0xFF, (JOCTET) JPEG_EOI, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
/* The whole JPEG data is expected to reside in the supplied memory
|
/* The whole JPEG data is expected to reside in the supplied memory
|
||||||
* buffer, so any request for more data beyond the given buffer size
|
* buffer, so any request for more data beyond the given buffer size
|
||||||
* is treated as an error.
|
* is treated as an error.
|
||||||
*/
|
*/
|
||||||
WARNMS(cinfo, JWRN_JPEG_EOF);
|
WARNMS(cinfo, JWRN_JPEG_EOF);
|
||||||
|
|
||||||
/* Insert a fake EOI marker */
|
/* Insert a fake EOI marker */
|
||||||
mybuffer[0] = (JOCTET) 0xFF;
|
|
||||||
mybuffer[1] = (JOCTET) JPEG_EOI;
|
|
||||||
|
|
||||||
cinfo->src->next_input_byte = mybuffer;
|
cinfo->src->next_input_byte = mybuffer;
|
||||||
cinfo->src->bytes_in_buffer = 2;
|
cinfo->src->bytes_in_buffer = 2;
|
||||||
@@ -155,21 +156,23 @@ METHODDEF(void)
|
|||||||
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
||||||
{
|
{
|
||||||
struct jpeg_source_mgr * src = cinfo->src;
|
struct jpeg_source_mgr * src = cinfo->src;
|
||||||
|
size_t nbytes;
|
||||||
|
|
||||||
/* Just a dumb implementation for now. Could use fseek() except
|
/* Just a dumb implementation for now. Could use fseek() except
|
||||||
* it doesn't work on pipes. Not clear that being smart is worth
|
* it doesn't work on pipes. Not clear that being smart is worth
|
||||||
* any trouble anyway --- large skips are infrequent.
|
* any trouble anyway --- large skips are infrequent.
|
||||||
*/
|
*/
|
||||||
if (num_bytes > 0) {
|
if (num_bytes > 0) {
|
||||||
while (num_bytes > (long) src->bytes_in_buffer) {
|
nbytes = (size_t) num_bytes;
|
||||||
num_bytes -= (long) src->bytes_in_buffer;
|
while (nbytes > src->bytes_in_buffer) {
|
||||||
|
nbytes -= src->bytes_in_buffer;
|
||||||
(void) (*src->fill_input_buffer) (cinfo);
|
(void) (*src->fill_input_buffer) (cinfo);
|
||||||
/* note we assume that fill_input_buffer will never return FALSE,
|
/* note we assume that fill_input_buffer will never return FALSE,
|
||||||
* so suspension need not be handled.
|
* so suspension need not be handled.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
src->next_input_byte += (size_t) num_bytes;
|
src->next_input_byte += nbytes;
|
||||||
src->bytes_in_buffer -= (size_t) num_bytes;
|
src->bytes_in_buffer -= nbytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,13 +221,11 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
|
|||||||
* manager serially with the same JPEG object. Caveat programmer.
|
* manager serially with the same JPEG object. Caveat programmer.
|
||||||
*/
|
*/
|
||||||
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
||||||
cinfo->src = (struct jpeg_source_mgr *)
|
cinfo->src = (struct jpeg_source_mgr *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_source_mgr));
|
||||||
SIZEOF(my_source_mgr));
|
|
||||||
src = (my_src_ptr) cinfo->src;
|
src = (my_src_ptr) cinfo->src;
|
||||||
src->buffer = (JOCTET *)
|
src->buffer = (JOCTET *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
((j_common_ptr) cinfo, JPOOL_PERMANENT, INPUT_BUF_SIZE * SIZEOF(JOCTET));
|
||||||
INPUT_BUF_SIZE * SIZEOF(JOCTET));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
src = (my_src_ptr) cinfo->src;
|
src = (my_src_ptr) cinfo->src;
|
||||||
@@ -246,7 +247,7 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
|
|||||||
|
|
||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
jpeg_mem_src (j_decompress_ptr cinfo,
|
jpeg_mem_src (j_decompress_ptr cinfo,
|
||||||
unsigned char * inbuffer, unsigned long insize)
|
const unsigned char * inbuffer, size_t insize)
|
||||||
{
|
{
|
||||||
struct jpeg_source_mgr * src;
|
struct jpeg_source_mgr * src;
|
||||||
|
|
||||||
@@ -258,9 +259,8 @@ jpeg_mem_src (j_decompress_ptr cinfo,
|
|||||||
* the first one.
|
* the first one.
|
||||||
*/
|
*/
|
||||||
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
||||||
cinfo->src = (struct jpeg_source_mgr *)
|
cinfo->src = (struct jpeg_source_mgr *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(struct jpeg_source_mgr));
|
||||||
SIZEOF(struct jpeg_source_mgr));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
src = cinfo->src;
|
src = cinfo->src;
|
||||||
@@ -269,6 +269,6 @@ jpeg_mem_src (j_decompress_ptr cinfo,
|
|||||||
src->skip_input_data = skip_input_data;
|
src->skip_input_data = skip_input_data;
|
||||||
src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
|
src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
|
||||||
src->term_source = term_source;
|
src->term_source = term_source;
|
||||||
src->bytes_in_buffer = (size_t) insize;
|
src->bytes_in_buffer = insize;
|
||||||
src->next_input_byte = (JOCTET *) inbuffer;
|
src->next_input_byte = (const JOCTET *) inbuffer;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+59
-51
@@ -2,6 +2,7 @@
|
|||||||
* jdcoefct.c
|
* jdcoefct.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||||
|
* Modified 2002-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -18,11 +19,13 @@
|
|||||||
#include "jinclude.h"
|
#include "jinclude.h"
|
||||||
#include "jpeglib.h"
|
#include "jpeglib.h"
|
||||||
|
|
||||||
|
|
||||||
/* Block smoothing is only applicable for progressive JPEG, so: */
|
/* Block smoothing is only applicable for progressive JPEG, so: */
|
||||||
#ifndef D_PROGRESSIVE_SUPPORTED
|
#ifndef D_PROGRESSIVE_SUPPORTED
|
||||||
#undef BLOCK_SMOOTHING_SUPPORTED
|
#undef BLOCK_SMOOTHING_SUPPORTED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Private buffer controller object */
|
/* Private buffer controller object */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -37,11 +40,8 @@ typedef struct {
|
|||||||
/* The output side's location is represented by cinfo->output_iMCU_row. */
|
/* The output side's location is represented by cinfo->output_iMCU_row. */
|
||||||
|
|
||||||
/* In single-pass modes, it's sufficient to buffer just one MCU.
|
/* In single-pass modes, it's sufficient to buffer just one MCU.
|
||||||
* We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
|
* We append a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
|
||||||
* and let the entropy decoder write into that workspace each time.
|
* and let the entropy decoder write into that workspace each time.
|
||||||
* (On 80x86, the workspace is FAR even though it's not really very big;
|
|
||||||
* this is to keep the module interfaces unchanged when a large coefficient
|
|
||||||
* buffer is necessary.)
|
|
||||||
* In multi-pass modes, this array points to the current MCU's blocks
|
* In multi-pass modes, this array points to the current MCU's blocks
|
||||||
* within the virtual arrays; it is used only by the input side.
|
* within the virtual arrays; it is used only by the input side.
|
||||||
*/
|
*/
|
||||||
@@ -57,10 +57,14 @@ typedef struct {
|
|||||||
int * coef_bits_latch;
|
int * coef_bits_latch;
|
||||||
#define SAVED_COEFS 6 /* we save coef_bits[0..5] */
|
#define SAVED_COEFS 6 /* we save coef_bits[0..5] */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Workspace for single-pass modes (omitted otherwise). */
|
||||||
|
JBLOCK blk_buffer[D_MAX_BLOCKS_IN_MCU];
|
||||||
} my_coef_controller;
|
} my_coef_controller;
|
||||||
|
|
||||||
typedef my_coef_controller * my_coef_ptr;
|
typedef my_coef_controller * my_coef_ptr;
|
||||||
|
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
METHODDEF(int) decompress_onepass
|
METHODDEF(int) decompress_onepass
|
||||||
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
||||||
@@ -150,7 +154,8 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
|||||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||||
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
|
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
|
||||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||||
int blkn, ci, xindex, yindex, yoffset, useful_width;
|
int ci, xindex, yindex, yoffset, useful_width;
|
||||||
|
JBLOCKROW blkp;
|
||||||
JSAMPARRAY output_ptr;
|
JSAMPARRAY output_ptr;
|
||||||
JDIMENSION start_col, output_col;
|
JDIMENSION start_col, output_col;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
@@ -161,9 +166,10 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
|||||||
yoffset++) {
|
yoffset++) {
|
||||||
for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
|
for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
|
||||||
MCU_col_num++) {
|
MCU_col_num++) {
|
||||||
|
blkp = coef->blk_buffer; /* pointer to current DCT block within MCU */
|
||||||
/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
|
/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
|
||||||
jzero_far((void FAR *) coef->MCU_buffer[0],
|
if (cinfo->lim_Se) /* can bypass in DC only case */
|
||||||
(size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
|
MEMZERO(blkp, cinfo->blocks_in_MCU * SIZEOF(JBLOCK));
|
||||||
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
|
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
|
||||||
/* Suspension forced; update state counters and exit */
|
/* Suspension forced; update state counters and exit */
|
||||||
coef->MCU_vert_offset = yoffset;
|
coef->MCU_vert_offset = yoffset;
|
||||||
@@ -171,37 +177,34 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
|||||||
return JPEG_SUSPENDED;
|
return JPEG_SUSPENDED;
|
||||||
}
|
}
|
||||||
/* Determine where data should go in output_buf and do the IDCT thing.
|
/* Determine where data should go in output_buf and do the IDCT thing.
|
||||||
* We skip dummy blocks at the right and bottom edges (but blkn gets
|
* We skip dummy blocks at the right and bottom edges (but blkp gets
|
||||||
* incremented past them!). Note the inner loop relies on having
|
* incremented past them!).
|
||||||
* allocated the MCU_buffer[] blocks sequentially.
|
|
||||||
*/
|
*/
|
||||||
blkn = 0; /* index of current DCT block within MCU */
|
|
||||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||||
compptr = cinfo->cur_comp_info[ci];
|
compptr = cinfo->cur_comp_info[ci];
|
||||||
/* Don't bother to IDCT an uninteresting component. */
|
/* Don't bother to IDCT an uninteresting component. */
|
||||||
if (! compptr->component_needed) {
|
if (! compptr->component_needed) {
|
||||||
blkn += compptr->MCU_blocks;
|
blkp += compptr->MCU_blocks;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
|
inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
|
||||||
useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
|
||||||
: compptr->last_col_width;
|
|
||||||
output_ptr = output_buf[compptr->component_index] +
|
output_ptr = output_buf[compptr->component_index] +
|
||||||
yoffset * compptr->DCT_v_scaled_size;
|
yoffset * compptr->DCT_v_scaled_size;
|
||||||
|
useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
||||||
|
: compptr->last_col_width;
|
||||||
start_col = MCU_col_num * compptr->MCU_sample_width;
|
start_col = MCU_col_num * compptr->MCU_sample_width;
|
||||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||||
if (cinfo->input_iMCU_row < last_iMCU_row ||
|
if (cinfo->input_iMCU_row < last_iMCU_row ||
|
||||||
yoffset+yindex < compptr->last_row_height) {
|
yoffset + yindex < compptr->last_row_height) {
|
||||||
output_col = start_col;
|
output_col = start_col;
|
||||||
for (xindex = 0; xindex < useful_width; xindex++) {
|
for (xindex = 0; xindex < useful_width; xindex++) {
|
||||||
(*inverse_DCT) (cinfo, compptr,
|
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) (blkp + xindex),
|
||||||
(JCOEFPTR) coef->MCU_buffer[blkn+xindex],
|
|
||||||
output_ptr, output_col);
|
output_ptr, output_col);
|
||||||
output_col += compptr->DCT_h_scaled_size;
|
output_col += compptr->DCT_h_scaled_size;
|
||||||
}
|
}
|
||||||
|
output_ptr += compptr->DCT_v_scaled_size;
|
||||||
}
|
}
|
||||||
blkn += compptr->MCU_width;
|
blkp += compptr->MCU_width;
|
||||||
output_ptr += compptr->DCT_v_scaled_size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +213,7 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
|||||||
}
|
}
|
||||||
/* Completed the iMCU row, advance counters for next one */
|
/* Completed the iMCU row, advance counters for next one */
|
||||||
cinfo->output_iMCU_row++;
|
cinfo->output_iMCU_row++;
|
||||||
if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
|
if (++(cinfo->input_iMCU_row) <= last_iMCU_row) {
|
||||||
start_iMCU_row(cinfo);
|
start_iMCU_row(cinfo);
|
||||||
return JPEG_ROW_COMPLETED;
|
return JPEG_ROW_COMPLETED;
|
||||||
}
|
}
|
||||||
@@ -245,8 +248,9 @@ consume_data (j_decompress_ptr cinfo)
|
|||||||
{
|
{
|
||||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||||
int blkn, ci, xindex, yindex, yoffset;
|
int ci, xindex, yindex, yoffset;
|
||||||
JDIMENSION start_col;
|
JDIMENSION start_col;
|
||||||
|
JBLOCKARRAY blkp;
|
||||||
JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
|
JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
|
||||||
JBLOCKROW buffer_ptr;
|
JBLOCKROW buffer_ptr;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
@@ -270,15 +274,16 @@ consume_data (j_decompress_ptr cinfo)
|
|||||||
for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
|
for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
|
||||||
MCU_col_num++) {
|
MCU_col_num++) {
|
||||||
/* Construct list of pointers to DCT blocks belonging to this MCU */
|
/* Construct list of pointers to DCT blocks belonging to this MCU */
|
||||||
blkn = 0; /* index of current DCT block within MCU */
|
blkp = coef->MCU_buffer; /* pointer to current DCT block within MCU */
|
||||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||||
compptr = cinfo->cur_comp_info[ci];
|
compptr = cinfo->cur_comp_info[ci];
|
||||||
start_col = MCU_col_num * compptr->MCU_width;
|
start_col = MCU_col_num * compptr->MCU_width;
|
||||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||||
buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
|
buffer_ptr = buffer[ci][yoffset + yindex] + start_col;
|
||||||
for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
|
xindex = compptr->MCU_width;
|
||||||
coef->MCU_buffer[blkn++] = buffer_ptr++;
|
do {
|
||||||
}
|
*blkp++ = buffer_ptr++;
|
||||||
|
} while (--xindex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Try to fetch the MCU. */
|
/* Try to fetch the MCU. */
|
||||||
@@ -368,7 +373,7 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
|
if (++(cinfo->output_iMCU_row) <= last_iMCU_row)
|
||||||
return JPEG_ROW_COMPLETED;
|
return JPEG_ROW_COMPLETED;
|
||||||
return JPEG_SCAN_COMPLETED;
|
return JPEG_SCAN_COMPLETED;
|
||||||
}
|
}
|
||||||
@@ -417,10 +422,9 @@ smoothing_ok (j_decompress_ptr cinfo)
|
|||||||
|
|
||||||
/* Allocate latch area if not already done */
|
/* Allocate latch area if not already done */
|
||||||
if (coef->coef_bits_latch == NULL)
|
if (coef->coef_bits_latch == NULL)
|
||||||
coef->coef_bits_latch = (int *)
|
coef->coef_bits_latch = (int *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
cinfo->num_components *
|
cinfo->num_components * (SAVED_COEFS * SIZEOF(int)));
|
||||||
(SAVED_COEFS * SIZEOF(int)));
|
|
||||||
coef_bits_latch = coef->coef_bits_latch;
|
coef_bits_latch = coef->coef_bits_latch;
|
||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
@@ -660,7 +664,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
|
if (++(cinfo->output_iMCU_row) <= last_iMCU_row)
|
||||||
return JPEG_ROW_COMPLETED;
|
return JPEG_ROW_COMPLETED;
|
||||||
return JPEG_SCAN_COMPLETED;
|
return JPEG_SCAN_COMPLETED;
|
||||||
}
|
}
|
||||||
@@ -677,17 +681,6 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
|||||||
{
|
{
|
||||||
my_coef_ptr coef;
|
my_coef_ptr coef;
|
||||||
|
|
||||||
coef = (my_coef_ptr)
|
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
||||||
SIZEOF(my_coef_controller));
|
|
||||||
cinfo->coef = (struct jpeg_d_coef_controller *) coef;
|
|
||||||
coef->pub.start_input_pass = start_input_pass;
|
|
||||||
coef->pub.start_output_pass = start_output_pass;
|
|
||||||
#ifdef BLOCK_SMOOTHING_SUPPORTED
|
|
||||||
coef->coef_bits_latch = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Create the coefficient buffer. */
|
|
||||||
if (need_full_buffer) {
|
if (need_full_buffer) {
|
||||||
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
||||||
/* Allocate a full-image virtual array for each component, */
|
/* Allocate a full-image virtual array for each component, */
|
||||||
@@ -696,6 +689,9 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
|||||||
int ci, access_rows;
|
int ci, access_rows;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
|
|
||||||
|
coef = (my_coef_ptr) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
|
SIZEOF(my_coef_controller) - SIZEOF(coef->blk_buffer));
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
access_rows = compptr->v_samp_factor;
|
access_rows = compptr->v_samp_factor;
|
||||||
@@ -720,17 +716,29 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
/* We only need a single-MCU buffer. */
|
/* We only need a single-MCU buffer. */
|
||||||
JBLOCKROW buffer;
|
JBLOCKARRAY blkp;
|
||||||
int i;
|
JBLOCKROW buffer_ptr;
|
||||||
|
int bi;
|
||||||
|
|
||||||
buffer = (JBLOCKROW)
|
coef = (my_coef_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_coef_controller));
|
||||||
D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
buffer_ptr = coef->blk_buffer;
|
||||||
for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
|
if (cinfo->lim_Se == 0) /* DC only case: want to bypass later */
|
||||||
coef->MCU_buffer[i] = buffer + i;
|
MEMZERO(buffer_ptr, SIZEOF(coef->blk_buffer));
|
||||||
}
|
blkp = coef->MCU_buffer;
|
||||||
|
bi = D_MAX_BLOCKS_IN_MCU;
|
||||||
|
do {
|
||||||
|
*blkp++ = buffer_ptr++;
|
||||||
|
} while (--bi);
|
||||||
coef->pub.consume_data = dummy_consume_data;
|
coef->pub.consume_data = dummy_consume_data;
|
||||||
coef->pub.decompress_data = decompress_onepass;
|
coef->pub.decompress_data = decompress_onepass;
|
||||||
coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
|
coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coef->pub.start_input_pass = start_input_pass;
|
||||||
|
coef->pub.start_output_pass = start_output_pass;
|
||||||
|
#ifdef BLOCK_SMOOTHING_SUPPORTED
|
||||||
|
coef->coef_bits_latch = NULL;
|
||||||
|
#endif
|
||||||
|
cinfo->coef = &coef->pub;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+465
-83
@@ -2,6 +2,7 @@
|
|||||||
* jdcolor.c
|
* jdcolor.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
|
* Modified 2011-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -13,32 +14,68 @@
|
|||||||
#include "jpeglib.h"
|
#include "jpeglib.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if RANGE_BITS < 2
|
||||||
|
/* Deliberate syntax err */
|
||||||
|
Sorry, this code requires 2 or more range extension bits.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Private subobject */
|
/* Private subobject */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct jpeg_color_deconverter pub; /* public fields */
|
struct jpeg_color_deconverter pub; /* public fields */
|
||||||
|
|
||||||
/* Private state for YCC->RGB conversion */
|
/* Private state for YCbCr->RGB and BG_YCC->RGB conversion */
|
||||||
int * Cr_r_tab; /* => table for Cr to R conversion */
|
int * Cr_r_tab; /* => table for Cr to R conversion */
|
||||||
int * Cb_b_tab; /* => table for Cb to B conversion */
|
int * Cb_b_tab; /* => table for Cb to B conversion */
|
||||||
INT32 * Cr_g_tab; /* => table for Cr to G conversion */
|
INT32 * Cr_g_tab; /* => table for Cr to G conversion */
|
||||||
INT32 * Cb_g_tab; /* => table for Cb to G conversion */
|
INT32 * Cb_g_tab; /* => table for Cb to G conversion */
|
||||||
|
|
||||||
|
/* Private state for RGB->Y conversion */
|
||||||
|
INT32 * rgb_y_tab; /* => table for RGB to Y conversion */
|
||||||
} my_color_deconverter;
|
} my_color_deconverter;
|
||||||
|
|
||||||
typedef my_color_deconverter * my_cconvert_ptr;
|
typedef my_color_deconverter * my_cconvert_ptr;
|
||||||
|
|
||||||
|
|
||||||
/**************** YCbCr -> RGB conversion: most common case **************/
|
/*************** YCbCr -> RGB conversion: most common case **************/
|
||||||
|
/*************** BG_YCC -> RGB conversion: less common case **************/
|
||||||
|
/*************** RGB -> Y conversion: less common case **************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are
|
* YCbCr is defined per Recommendation ITU-R BT.601-7 (03/2011),
|
||||||
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
|
* previously known as Recommendation CCIR 601-1, except that Cb and Cr
|
||||||
* The conversion equations to be implemented are therefore
|
* are normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
|
||||||
* R = Y + 1.40200 * Cr
|
* sRGB (standard RGB color space) is defined per IEC 61966-2-1:1999.
|
||||||
* G = Y - 0.34414 * Cb - 0.71414 * Cr
|
* sYCC (standard luma-chroma-chroma color space with extended gamut)
|
||||||
* B = Y + 1.77200 * Cb
|
* is defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex F.
|
||||||
|
* bg-sRGB and bg-sYCC (big gamut standard color spaces)
|
||||||
|
* are defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex G.
|
||||||
|
* Note that the derived conversion coefficients given in some of these
|
||||||
|
* documents are imprecise. The general conversion equations are
|
||||||
|
*
|
||||||
|
* R = Y + K * (1 - Kr) * Cr
|
||||||
|
* G = Y - K * (Kb * (1 - Kb) * Cb + Kr * (1 - Kr) * Cr) / (1 - Kr - Kb)
|
||||||
|
* B = Y + K * (1 - Kb) * Cb
|
||||||
|
*
|
||||||
|
* Y = Kr * R + (1 - Kr - Kb) * G + Kb * B
|
||||||
|
*
|
||||||
|
* With Kr = 0.299 and Kb = 0.114 (derived according to SMPTE RP 177-1993
|
||||||
|
* from the 1953 FCC NTSC primaries and CIE Illuminant C), K = 2 for sYCC,
|
||||||
|
* the conversion equations to be implemented are therefore
|
||||||
|
*
|
||||||
|
* R = Y + 1.402 * Cr
|
||||||
|
* G = Y - 0.344136286 * Cb - 0.714136286 * Cr
|
||||||
|
* B = Y + 1.772 * Cb
|
||||||
|
*
|
||||||
|
* Y = 0.299 * R + 0.587 * G + 0.114 * B
|
||||||
|
*
|
||||||
* where Cb and Cr represent the incoming values less CENTERJSAMPLE.
|
* where Cb and Cr represent the incoming values less CENTERJSAMPLE.
|
||||||
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
|
* For bg-sYCC, with K = 4, the equations are
|
||||||
|
*
|
||||||
|
* R = Y + 2.804 * Cr
|
||||||
|
* G = Y - 0.688272572 * Cb - 1.428272572 * Cr
|
||||||
|
* B = Y + 3.544 * Cb
|
||||||
*
|
*
|
||||||
* To avoid floating-point arithmetic, we represent the fractional constants
|
* To avoid floating-point arithmetic, we represent the fractional constants
|
||||||
* as integers scaled up by 2^16 (about 4 digits precision); we have to divide
|
* as integers scaled up by 2^16 (about 4 digits precision); we have to divide
|
||||||
@@ -49,9 +86,9 @@ typedef my_color_deconverter * my_cconvert_ptr;
|
|||||||
* For even more speed, we avoid doing any multiplications in the inner loop
|
* For even more speed, we avoid doing any multiplications in the inner loop
|
||||||
* by precalculating the constants times Cb and Cr for all possible values.
|
* by precalculating the constants times Cb and Cr for all possible values.
|
||||||
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
|
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
|
||||||
* for 12-bit samples it is still acceptable. It's not very reasonable for
|
* for 9-bit to 12-bit samples it is still acceptable. It's not very
|
||||||
* 16-bit samples, but if you want lossless storage you shouldn't be changing
|
* reasonable for 16-bit samples, but if you want lossless storage you
|
||||||
* colorspace anyway.
|
* shouldn't be changing colorspace anyway.
|
||||||
* The Cr=>R and Cb=>B values can be rounded to integers in advance; the
|
* The Cr=>R and Cb=>B values can be rounded to integers in advance; the
|
||||||
* values for the G calculation are left scaled up, since we must add them
|
* values for the G calculation are left scaled up, since we must add them
|
||||||
* together before rounding.
|
* together before rounding.
|
||||||
@@ -61,46 +98,87 @@ typedef my_color_deconverter * my_cconvert_ptr;
|
|||||||
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
|
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
|
||||||
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
|
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
|
||||||
|
|
||||||
|
/* We allocate one big table for RGB->Y conversion and divide it up into
|
||||||
|
* three parts, instead of doing three alloc_small requests. This lets us
|
||||||
|
* use a single table base address, which can be held in a register in the
|
||||||
|
* inner loops on many machines (more than can hold all three addresses,
|
||||||
|
* anyway).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define R_Y_OFF 0 /* offset to R => Y section */
|
||||||
|
#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
|
||||||
|
#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
|
||||||
|
#define TABLE_SIZE (3*(MAXJSAMPLE+1))
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize tables for YCC->RGB colorspace conversion.
|
* Initialize tables for YCbCr->RGB and BG_YCC->RGB colorspace conversion.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LOCAL(void)
|
LOCAL(void)
|
||||||
build_ycc_rgb_table (j_decompress_ptr cinfo)
|
build_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||||
|
/* Normal case, sYCC */
|
||||||
{
|
{
|
||||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||||
int i;
|
int i;
|
||||||
INT32 x;
|
INT32 x;
|
||||||
SHIFT_TEMPS
|
SHIFT_TEMPS
|
||||||
|
|
||||||
cconvert->Cr_r_tab = (int *)
|
cconvert->Cr_r_tab = (int *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int));
|
||||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
cconvert->Cb_b_tab = (int *) (*cinfo->mem->alloc_small)
|
||||||
cconvert->Cb_b_tab = (int *)
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int));
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
cconvert->Cr_g_tab = (INT32 *) (*cinfo->mem->alloc_small)
|
||||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||||
cconvert->Cr_g_tab = (INT32 *)
|
cconvert->Cb_g_tab = (INT32 *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
|
||||||
cconvert->Cb_g_tab = (INT32 *)
|
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
||||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
|
||||||
|
|
||||||
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
||||||
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
||||||
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
||||||
/* Cr=>R value is nearest int to 1.40200 * x */
|
/* Cr=>R value is nearest int to 1.402 * x */
|
||||||
cconvert->Cr_r_tab[i] = (int)
|
cconvert->Cr_r_tab[i] = (int) DESCALE(FIX(1.402) * x, SCALEBITS);
|
||||||
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
/* Cb=>B value is nearest int to 1.772 * x */
|
||||||
/* Cb=>B value is nearest int to 1.77200 * x */
|
cconvert->Cb_b_tab[i] = (int) DESCALE(FIX(1.772) * x, SCALEBITS);
|
||||||
cconvert->Cb_b_tab[i] = (int)
|
/* Cr=>G value is scaled-up -0.714136286 * x */
|
||||||
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
cconvert->Cr_g_tab[i] = (- FIX(0.714136286)) * x;
|
||||||
/* Cr=>G value is scaled-up -0.71414 * x */
|
/* Cb=>G value is scaled-up -0.344136286 * x */
|
||||||
cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
|
|
||||||
/* Cb=>G value is scaled-up -0.34414 * x */
|
|
||||||
/* We also add in ONE_HALF so that need not do it in inner loop */
|
/* We also add in ONE_HALF so that need not do it in inner loop */
|
||||||
cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
|
cconvert->Cb_g_tab[i] = (- FIX(0.344136286)) * x + ONE_HALF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL(void)
|
||||||
|
build_bg_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||||
|
/* Wide gamut case, bg-sYCC */
|
||||||
|
{
|
||||||
|
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||||
|
int i;
|
||||||
|
INT32 x;
|
||||||
|
SHIFT_TEMPS
|
||||||
|
|
||||||
|
cconvert->Cr_r_tab = (int *) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int));
|
||||||
|
cconvert->Cb_b_tab = (int *) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int));
|
||||||
|
cconvert->Cr_g_tab = (INT32 *) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||||
|
cconvert->Cb_g_tab = (INT32 *) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||||
|
|
||||||
|
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
||||||
|
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
||||||
|
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
||||||
|
/* Cr=>R value is nearest int to 2.804 * x */
|
||||||
|
cconvert->Cr_r_tab[i] = (int) DESCALE(FIX(2.804) * x, SCALEBITS);
|
||||||
|
/* Cb=>B value is nearest int to 3.544 * x */
|
||||||
|
cconvert->Cb_b_tab[i] = (int) DESCALE(FIX(3.544) * x, SCALEBITS);
|
||||||
|
/* Cr=>G value is scaled-up -1.428272572 * x */
|
||||||
|
cconvert->Cr_g_tab[i] = (- FIX(1.428272572)) * x;
|
||||||
|
/* Cb=>G value is scaled-up -0.688272572 * x */
|
||||||
|
/* We also add in ONE_HALF so that need not do it in inner loop */
|
||||||
|
cconvert->Cb_g_tab[i] = (- FIX(0.688272572)) * x + ONE_HALF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +189,7 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
|
|||||||
* Note that we change from noninterleaved, one-plane-per-component format
|
* Note that we change from noninterleaved, one-plane-per-component format
|
||||||
* to interleaved-pixel format. The output buffer is therefore three times
|
* to interleaved-pixel format. The output buffer is therefore three times
|
||||||
* as wide as the input buffer.
|
* as wide as the input buffer.
|
||||||
|
*
|
||||||
* A starting row offset is provided only for the input buffer. The caller
|
* A starting row offset is provided only for the input buffer. The caller
|
||||||
* can easily adjust the passed output_buf value to accommodate any row
|
* can easily adjust the passed output_buf value to accommodate any row
|
||||||
* offset required on that side.
|
* offset required on that side.
|
||||||
@@ -145,24 +224,203 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
|
|||||||
y = GETJSAMPLE(inptr0[col]);
|
y = GETJSAMPLE(inptr0[col]);
|
||||||
cb = GETJSAMPLE(inptr1[col]);
|
cb = GETJSAMPLE(inptr1[col]);
|
||||||
cr = GETJSAMPLE(inptr2[col]);
|
cr = GETJSAMPLE(inptr2[col]);
|
||||||
/* Range-limiting is essential due to noise introduced by DCT losses. */
|
/* Range-limiting is essential due to noise introduced by DCT losses,
|
||||||
outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
|
* for extended gamut (sYCC) and wide gamut (bg-sYCC) encodings.
|
||||||
|
*/
|
||||||
|
outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
|
||||||
outptr[RGB_GREEN] = range_limit[y +
|
outptr[RGB_GREEN] = range_limit[y +
|
||||||
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
||||||
SCALEBITS))];
|
SCALEBITS))];
|
||||||
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
|
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
|
||||||
outptr += RGB_PIXELSIZE;
|
outptr += RGB_PIXELSIZE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************** Cases other than YCbCr -> RGB **************/
|
/**************** Cases other than YCC -> RGB ****************/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize for RGB->grayscale colorspace conversion.
|
||||||
|
*/
|
||||||
|
|
||||||
|
LOCAL(void)
|
||||||
|
build_rgb_y_table (j_decompress_ptr cinfo)
|
||||||
|
{
|
||||||
|
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||||
|
INT32 * rgb_y_tab;
|
||||||
|
INT32 i;
|
||||||
|
|
||||||
|
/* Allocate and fill in the conversion tables. */
|
||||||
|
cconvert->rgb_y_tab = rgb_y_tab = (INT32 *) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE, TABLE_SIZE * SIZEOF(INT32));
|
||||||
|
|
||||||
|
for (i = 0; i <= MAXJSAMPLE; i++) {
|
||||||
|
rgb_y_tab[i+R_Y_OFF] = FIX(0.299) * i;
|
||||||
|
rgb_y_tab[i+G_Y_OFF] = FIX(0.587) * i;
|
||||||
|
rgb_y_tab[i+B_Y_OFF] = FIX(0.114) * i + ONE_HALF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert RGB to grayscale.
|
||||||
|
*/
|
||||||
|
|
||||||
|
METHODDEF(void)
|
||||||
|
rgb_gray_convert (j_decompress_ptr cinfo,
|
||||||
|
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||||
|
JSAMPARRAY output_buf, int num_rows)
|
||||||
|
{
|
||||||
|
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||||
|
register int r, g, b;
|
||||||
|
register INT32 * ctab = cconvert->rgb_y_tab;
|
||||||
|
register JSAMPROW outptr;
|
||||||
|
register JSAMPROW inptr0, inptr1, inptr2;
|
||||||
|
register JDIMENSION col;
|
||||||
|
JDIMENSION num_cols = cinfo->output_width;
|
||||||
|
|
||||||
|
while (--num_rows >= 0) {
|
||||||
|
inptr0 = input_buf[0][input_row];
|
||||||
|
inptr1 = input_buf[1][input_row];
|
||||||
|
inptr2 = input_buf[2][input_row];
|
||||||
|
input_row++;
|
||||||
|
outptr = *output_buf++;
|
||||||
|
for (col = 0; col < num_cols; col++) {
|
||||||
|
r = GETJSAMPLE(inptr0[col]);
|
||||||
|
g = GETJSAMPLE(inptr1[col]);
|
||||||
|
b = GETJSAMPLE(inptr2[col]);
|
||||||
|
/* Y */
|
||||||
|
outptr[col] = (JSAMPLE)
|
||||||
|
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
||||||
|
>> SCALEBITS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert some rows of samples to the output colorspace.
|
||||||
|
* [R-G,G,B-G] to [R,G,B] conversion with modulo calculation
|
||||||
|
* (inverse color transform).
|
||||||
|
* This can be seen as an adaption of the general YCbCr->RGB
|
||||||
|
* conversion equation with Kr = Kb = 0, while replacing the
|
||||||
|
* normalization by modulo calculation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
METHODDEF(void)
|
||||||
|
rgb1_rgb_convert (j_decompress_ptr cinfo,
|
||||||
|
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||||
|
JSAMPARRAY output_buf, int num_rows)
|
||||||
|
{
|
||||||
|
register int r, g, b;
|
||||||
|
register JSAMPROW outptr;
|
||||||
|
register JSAMPROW inptr0, inptr1, inptr2;
|
||||||
|
register JDIMENSION col;
|
||||||
|
JDIMENSION num_cols = cinfo->output_width;
|
||||||
|
|
||||||
|
while (--num_rows >= 0) {
|
||||||
|
inptr0 = input_buf[0][input_row];
|
||||||
|
inptr1 = input_buf[1][input_row];
|
||||||
|
inptr2 = input_buf[2][input_row];
|
||||||
|
input_row++;
|
||||||
|
outptr = *output_buf++;
|
||||||
|
for (col = 0; col < num_cols; col++) {
|
||||||
|
r = GETJSAMPLE(inptr0[col]);
|
||||||
|
g = GETJSAMPLE(inptr1[col]);
|
||||||
|
b = GETJSAMPLE(inptr2[col]);
|
||||||
|
/* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD
|
||||||
|
* (modulo) operator is equivalent to the bitmask operator AND.
|
||||||
|
*/
|
||||||
|
outptr[RGB_RED] = (JSAMPLE) ((r + g - CENTERJSAMPLE) & MAXJSAMPLE);
|
||||||
|
outptr[RGB_GREEN] = (JSAMPLE) g;
|
||||||
|
outptr[RGB_BLUE] = (JSAMPLE) ((b + g - CENTERJSAMPLE) & MAXJSAMPLE);
|
||||||
|
outptr += RGB_PIXELSIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* [R-G,G,B-G] to grayscale conversion with modulo calculation
|
||||||
|
* (inverse color transform).
|
||||||
|
*/
|
||||||
|
|
||||||
|
METHODDEF(void)
|
||||||
|
rgb1_gray_convert (j_decompress_ptr cinfo,
|
||||||
|
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||||
|
JSAMPARRAY output_buf, int num_rows)
|
||||||
|
{
|
||||||
|
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||||
|
register int r, g, b;
|
||||||
|
register INT32 * ctab = cconvert->rgb_y_tab;
|
||||||
|
register JSAMPROW outptr;
|
||||||
|
register JSAMPROW inptr0, inptr1, inptr2;
|
||||||
|
register JDIMENSION col;
|
||||||
|
JDIMENSION num_cols = cinfo->output_width;
|
||||||
|
|
||||||
|
while (--num_rows >= 0) {
|
||||||
|
inptr0 = input_buf[0][input_row];
|
||||||
|
inptr1 = input_buf[1][input_row];
|
||||||
|
inptr2 = input_buf[2][input_row];
|
||||||
|
input_row++;
|
||||||
|
outptr = *output_buf++;
|
||||||
|
for (col = 0; col < num_cols; col++) {
|
||||||
|
r = GETJSAMPLE(inptr0[col]);
|
||||||
|
g = GETJSAMPLE(inptr1[col]);
|
||||||
|
b = GETJSAMPLE(inptr2[col]);
|
||||||
|
/* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD
|
||||||
|
* (modulo) operator is equivalent to the bitmask operator AND.
|
||||||
|
*/
|
||||||
|
r = (r + g - CENTERJSAMPLE) & MAXJSAMPLE;
|
||||||
|
b = (b + g - CENTERJSAMPLE) & MAXJSAMPLE;
|
||||||
|
/* Y */
|
||||||
|
outptr[col] = (JSAMPLE)
|
||||||
|
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
||||||
|
>> SCALEBITS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert some rows of samples to the output colorspace.
|
||||||
|
* No colorspace change, but conversion from separate-planes
|
||||||
|
* to interleaved representation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
METHODDEF(void)
|
||||||
|
rgb_convert (j_decompress_ptr cinfo,
|
||||||
|
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||||
|
JSAMPARRAY output_buf, int num_rows)
|
||||||
|
{
|
||||||
|
register JSAMPROW outptr;
|
||||||
|
register JSAMPROW inptr0, inptr1, inptr2;
|
||||||
|
register JDIMENSION col;
|
||||||
|
JDIMENSION num_cols = cinfo->output_width;
|
||||||
|
|
||||||
|
while (--num_rows >= 0) {
|
||||||
|
inptr0 = input_buf[0][input_row];
|
||||||
|
inptr1 = input_buf[1][input_row];
|
||||||
|
inptr2 = input_buf[2][input_row];
|
||||||
|
input_row++;
|
||||||
|
outptr = *output_buf++;
|
||||||
|
for (col = 0; col < num_cols; col++) {
|
||||||
|
/* We can dispense with GETJSAMPLE() here */
|
||||||
|
outptr[RGB_RED] = inptr0[col];
|
||||||
|
outptr[RGB_GREEN] = inptr1[col];
|
||||||
|
outptr[RGB_BLUE] = inptr2[col];
|
||||||
|
outptr += RGB_PIXELSIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Color conversion for no colorspace change: just copy the data,
|
* Color conversion for no colorspace change: just copy the data,
|
||||||
* converting from separate-planes to interleaved representation.
|
* converting from separate-planes to interleaved representation.
|
||||||
|
* Note: Omit uninteresting components in output buffer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
@@ -170,30 +428,37 @@ null_convert (j_decompress_ptr cinfo,
|
|||||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||||
JSAMPARRAY output_buf, int num_rows)
|
JSAMPARRAY output_buf, int num_rows)
|
||||||
{
|
{
|
||||||
register JSAMPROW inptr, outptr;
|
register JSAMPROW outptr;
|
||||||
|
register JSAMPROW inptr;
|
||||||
register JDIMENSION count;
|
register JDIMENSION count;
|
||||||
register int num_components = cinfo->num_components;
|
register int out_comps = cinfo->out_color_components;
|
||||||
JDIMENSION num_cols = cinfo->output_width;
|
JDIMENSION num_cols = cinfo->output_width;
|
||||||
|
JSAMPROW startptr;
|
||||||
int ci;
|
int ci;
|
||||||
|
jpeg_component_info *compptr;
|
||||||
|
|
||||||
while (--num_rows >= 0) {
|
while (--num_rows >= 0) {
|
||||||
for (ci = 0; ci < num_components; ci++) {
|
/* It seems fastest to make a separate pass for each component. */
|
||||||
|
startptr = *output_buf++;
|
||||||
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
|
ci++, compptr++) {
|
||||||
|
if (! compptr->component_needed)
|
||||||
|
continue; /* skip uninteresting component */
|
||||||
inptr = input_buf[ci][input_row];
|
inptr = input_buf[ci][input_row];
|
||||||
outptr = output_buf[0] + ci;
|
outptr = startptr++;
|
||||||
for (count = num_cols; count > 0; count--) {
|
for (count = num_cols; count > 0; count--) {
|
||||||
*outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
|
*outptr = *inptr++; /* don't need GETJSAMPLE() here */
|
||||||
outptr += num_components;
|
outptr += out_comps;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
input_row++;
|
input_row++;
|
||||||
output_buf++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Color conversion for grayscale: just copy the data.
|
* Color conversion for grayscale: just copy the data.
|
||||||
* This also works for YCbCr -> grayscale conversion, in which
|
* This also works for YCC -> grayscale conversion, in which
|
||||||
* we just copy the Y (luminance) component and ignore chrominance.
|
* we just copy the Y (luminance) component and ignore chrominance.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -202,7 +467,7 @@ grayscale_convert (j_decompress_ptr cinfo,
|
|||||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||||
JSAMPARRAY output_buf, int num_rows)
|
JSAMPARRAY output_buf, int num_rows)
|
||||||
{
|
{
|
||||||
jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
|
jcopy_sample_rows(input_buf[0] + input_row, output_buf,
|
||||||
num_rows, cinfo->output_width);
|
num_rows, cinfo->output_width);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +483,8 @@ gray_rgb_convert (j_decompress_ptr cinfo,
|
|||||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||||
JSAMPARRAY output_buf, int num_rows)
|
JSAMPARRAY output_buf, int num_rows)
|
||||||
{
|
{
|
||||||
register JSAMPROW inptr, outptr;
|
register JSAMPROW outptr;
|
||||||
|
register JSAMPROW inptr;
|
||||||
register JDIMENSION col;
|
register JDIMENSION col;
|
||||||
JDIMENSION num_cols = cinfo->output_width;
|
JDIMENSION num_cols = cinfo->output_width;
|
||||||
|
|
||||||
@@ -235,9 +501,10 @@ gray_rgb_convert (j_decompress_ptr cinfo,
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adobe-style YCCK->CMYK conversion.
|
* Convert some rows of samples to the output colorspace.
|
||||||
* We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
|
* This version handles Adobe-style YCCK->CMYK conversion,
|
||||||
* conversion as above, while passing K (black) unchanged.
|
* where we convert YCbCr to R=1-C, G=1-M, and B=1-Y using the
|
||||||
|
* same conversion as above, while passing K (black) unchanged.
|
||||||
* We assume build_ycc_rgb_table has been called.
|
* We assume build_ycc_rgb_table has been called.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -271,7 +538,9 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
|
|||||||
y = GETJSAMPLE(inptr0[col]);
|
y = GETJSAMPLE(inptr0[col]);
|
||||||
cb = GETJSAMPLE(inptr1[col]);
|
cb = GETJSAMPLE(inptr1[col]);
|
||||||
cr = GETJSAMPLE(inptr2[col]);
|
cr = GETJSAMPLE(inptr2[col]);
|
||||||
/* Range-limiting is essential due to noise introduced by DCT losses. */
|
/* Range-limiting is essential due to noise introduced by DCT losses,
|
||||||
|
* and for extended gamut encodings (sYCC).
|
||||||
|
*/
|
||||||
outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
|
outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
|
||||||
outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
|
outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
|
||||||
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
||||||
@@ -285,6 +554,47 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert CMYK to YK part of YCCK for colorless output.
|
||||||
|
* We assume build_rgb_y_table has been called.
|
||||||
|
*/
|
||||||
|
|
||||||
|
METHODDEF(void)
|
||||||
|
cmyk_yk_convert (j_decompress_ptr cinfo,
|
||||||
|
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||||
|
JSAMPARRAY output_buf, int num_rows)
|
||||||
|
{
|
||||||
|
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||||
|
register int r, g, b;
|
||||||
|
register INT32 * ctab = cconvert->rgb_y_tab;
|
||||||
|
register JSAMPROW outptr;
|
||||||
|
register JSAMPROW inptr0, inptr1, inptr2, inptr3;
|
||||||
|
register JDIMENSION col;
|
||||||
|
JDIMENSION num_cols = cinfo->output_width;
|
||||||
|
|
||||||
|
while (--num_rows >= 0) {
|
||||||
|
inptr0 = input_buf[0][input_row];
|
||||||
|
inptr1 = input_buf[1][input_row];
|
||||||
|
inptr2 = input_buf[2][input_row];
|
||||||
|
inptr3 = input_buf[3][input_row];
|
||||||
|
input_row++;
|
||||||
|
outptr = *output_buf++;
|
||||||
|
for (col = 0; col < num_cols; col++) {
|
||||||
|
r = MAXJSAMPLE - GETJSAMPLE(inptr0[col]);
|
||||||
|
g = MAXJSAMPLE - GETJSAMPLE(inptr1[col]);
|
||||||
|
b = MAXJSAMPLE - GETJSAMPLE(inptr2[col]);
|
||||||
|
/* Y */
|
||||||
|
outptr[0] = (JSAMPLE)
|
||||||
|
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
||||||
|
>> SCALEBITS);
|
||||||
|
/* K passes through unchanged */
|
||||||
|
outptr[1] = inptr3[col]; /* don't need GETJSAMPLE here */
|
||||||
|
outptr += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Empty method for start_pass.
|
* Empty method for start_pass.
|
||||||
*/
|
*/
|
||||||
@@ -304,12 +614,11 @@ GLOBAL(void)
|
|||||||
jinit_color_deconverter (j_decompress_ptr cinfo)
|
jinit_color_deconverter (j_decompress_ptr cinfo)
|
||||||
{
|
{
|
||||||
my_cconvert_ptr cconvert;
|
my_cconvert_ptr cconvert;
|
||||||
int ci;
|
int ci, i;
|
||||||
|
|
||||||
cconvert = (my_cconvert_ptr)
|
cconvert = (my_cconvert_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_color_deconverter));
|
||||||
SIZEOF(my_color_deconverter));
|
cinfo->cconvert = &cconvert->pub;
|
||||||
cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
|
|
||||||
cconvert->pub.start_pass = start_pass_dcolor;
|
cconvert->pub.start_pass = start_pass_dcolor;
|
||||||
|
|
||||||
/* Make sure num_components agrees with jpeg_color_space */
|
/* Make sure num_components agrees with jpeg_color_space */
|
||||||
@@ -321,6 +630,8 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
|||||||
|
|
||||||
case JCS_RGB:
|
case JCS_RGB:
|
||||||
case JCS_YCbCr:
|
case JCS_YCbCr:
|
||||||
|
case JCS_BG_RGB:
|
||||||
|
case JCS_BG_YCC:
|
||||||
if (cinfo->num_components != 3)
|
if (cinfo->num_components != 3)
|
||||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||||
break;
|
break;
|
||||||
@@ -334,59 +645,130 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
|||||||
default: /* JCS_UNKNOWN can be anything */
|
default: /* JCS_UNKNOWN can be anything */
|
||||||
if (cinfo->num_components < 1)
|
if (cinfo->num_components < 1)
|
||||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Support color transform only for RGB colorspaces */
|
||||||
|
if (cinfo->color_transform &&
|
||||||
|
cinfo->jpeg_color_space != JCS_RGB &&
|
||||||
|
cinfo->jpeg_color_space != JCS_BG_RGB)
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
|
||||||
/* Set out_color_components and conversion method based on requested space.
|
/* Set out_color_components and conversion method based on requested space.
|
||||||
* Also clear the component_needed flags for any unused components,
|
* Also adjust the component_needed flags for any unused components,
|
||||||
* so that earlier pipeline stages can avoid useless computation.
|
* so that earlier pipeline stages can avoid useless computation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch (cinfo->out_color_space) {
|
switch (cinfo->out_color_space) {
|
||||||
case JCS_GRAYSCALE:
|
case JCS_GRAYSCALE:
|
||||||
cinfo->out_color_components = 1;
|
cinfo->out_color_components = 1;
|
||||||
if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
|
switch (cinfo->jpeg_color_space) {
|
||||||
cinfo->jpeg_color_space == JCS_YCbCr) {
|
case JCS_GRAYSCALE:
|
||||||
|
case JCS_YCbCr:
|
||||||
|
case JCS_BG_YCC:
|
||||||
cconvert->pub.color_convert = grayscale_convert;
|
cconvert->pub.color_convert = grayscale_convert;
|
||||||
/* For color->grayscale conversion, only the Y (0) component is needed */
|
/* For color->grayscale conversion, only the Y (0) component is needed */
|
||||||
for (ci = 1; ci < cinfo->num_components; ci++)
|
for (ci = 1; ci < cinfo->num_components; ci++)
|
||||||
cinfo->comp_info[ci].component_needed = FALSE;
|
cinfo->comp_info[ci].component_needed = FALSE;
|
||||||
} else
|
break;
|
||||||
|
case JCS_RGB:
|
||||||
|
switch (cinfo->color_transform) {
|
||||||
|
case JCT_NONE:
|
||||||
|
cconvert->pub.color_convert = rgb_gray_convert;
|
||||||
|
break;
|
||||||
|
case JCT_SUBTRACT_GREEN:
|
||||||
|
cconvert->pub.color_convert = rgb1_gray_convert;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
|
build_rgb_y_table(cinfo);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JCS_RGB:
|
case JCS_RGB:
|
||||||
cinfo->out_color_components = RGB_PIXELSIZE;
|
cinfo->out_color_components = RGB_PIXELSIZE;
|
||||||
if (cinfo->jpeg_color_space == JCS_YCbCr) {
|
switch (cinfo->jpeg_color_space) {
|
||||||
|
case JCS_GRAYSCALE:
|
||||||
|
cconvert->pub.color_convert = gray_rgb_convert;
|
||||||
|
break;
|
||||||
|
case JCS_YCbCr:
|
||||||
cconvert->pub.color_convert = ycc_rgb_convert;
|
cconvert->pub.color_convert = ycc_rgb_convert;
|
||||||
build_ycc_rgb_table(cinfo);
|
build_ycc_rgb_table(cinfo);
|
||||||
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
|
break;
|
||||||
cconvert->pub.color_convert = gray_rgb_convert;
|
case JCS_BG_YCC:
|
||||||
} else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
|
cconvert->pub.color_convert = ycc_rgb_convert;
|
||||||
cconvert->pub.color_convert = null_convert;
|
build_bg_ycc_rgb_table(cinfo);
|
||||||
} else
|
break;
|
||||||
|
case JCS_RGB:
|
||||||
|
switch (cinfo->color_transform) {
|
||||||
|
case JCT_NONE:
|
||||||
|
cconvert->pub.color_convert = rgb_convert;
|
||||||
|
break;
|
||||||
|
case JCT_SUBTRACT_GREEN:
|
||||||
|
cconvert->pub.color_convert = rgb1_rgb_convert;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case JCS_BG_RGB:
|
||||||
|
if (cinfo->jpeg_color_space != JCS_BG_RGB)
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
cinfo->out_color_components = RGB_PIXELSIZE;
|
||||||
|
switch (cinfo->color_transform) {
|
||||||
|
case JCT_NONE:
|
||||||
|
cconvert->pub.color_convert = rgb_convert;
|
||||||
|
break;
|
||||||
|
case JCT_SUBTRACT_GREEN:
|
||||||
|
cconvert->pub.color_convert = rgb1_rgb_convert;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JCS_CMYK:
|
case JCS_CMYK:
|
||||||
|
if (cinfo->jpeg_color_space != JCS_YCCK)
|
||||||
|
goto def_label;
|
||||||
cinfo->out_color_components = 4;
|
cinfo->out_color_components = 4;
|
||||||
if (cinfo->jpeg_color_space == JCS_YCCK) {
|
cconvert->pub.color_convert = ycck_cmyk_convert;
|
||||||
cconvert->pub.color_convert = ycck_cmyk_convert;
|
build_ycc_rgb_table(cinfo);
|
||||||
build_ycc_rgb_table(cinfo);
|
|
||||||
} else if (cinfo->jpeg_color_space == JCS_CMYK) {
|
|
||||||
cconvert->pub.color_convert = null_convert;
|
|
||||||
} else
|
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case JCS_YCCK:
|
||||||
/* Permit null conversion to same output space */
|
if (cinfo->jpeg_color_space != JCS_CMYK ||
|
||||||
if (cinfo->out_color_space == cinfo->jpeg_color_space) {
|
/* Support only YK part of YCCK for colorless output */
|
||||||
cinfo->out_color_components = cinfo->num_components;
|
! cinfo->comp_info[0].component_needed ||
|
||||||
cconvert->pub.color_convert = null_convert;
|
cinfo->comp_info[1].component_needed ||
|
||||||
} else /* unsupported non-null conversion */
|
cinfo->comp_info[2].component_needed ||
|
||||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
! cinfo->comp_info[3].component_needed)
|
||||||
|
goto def_label;
|
||||||
|
cinfo->out_color_components = 2;
|
||||||
|
/* Need all components on input side */
|
||||||
|
cinfo->comp_info[1].component_needed = TRUE;
|
||||||
|
cinfo->comp_info[2].component_needed = TRUE;
|
||||||
|
cconvert->pub.color_convert = cmyk_yk_convert;
|
||||||
|
build_rgb_y_table(cinfo);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default: def_label: /* permit null conversion to same output space */
|
||||||
|
if (cinfo->out_color_space != cinfo->jpeg_color_space)
|
||||||
|
/* unsupported non-null conversion */
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
i = 0;
|
||||||
|
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||||
|
if (cinfo->comp_info[ci].component_needed)
|
||||||
|
i++; /* count output color components */
|
||||||
|
cinfo->out_color_components = i;
|
||||||
|
cconvert->pub.color_convert = null_convert;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cinfo->quantize_colors)
|
if (cinfo->quantize_colors)
|
||||||
|
|||||||
Vendored
+26
-10
@@ -2,6 +2,7 @@
|
|||||||
* jdct.h
|
* jdct.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
|
* Modified 2002-2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -78,13 +79,15 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
|
|||||||
* converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
|
* converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could
|
||||||
* be quite far out of range if the input data is corrupt, so a bulletproof
|
* be quite far out of range if the input data is corrupt, so a bulletproof
|
||||||
* range-limiting step is required. We use a mask-and-table-lookup method
|
* range-limiting step is required. We use a mask-and-table-lookup method
|
||||||
* to do the combined operations quickly. See the comments with
|
* to do the combined operations quickly, assuming that RANGE_CENTER
|
||||||
|
* (defined in jpegint.h) is a power of 2. See the comments with
|
||||||
* prepare_range_limit_table (in jdmaster.c) for more info.
|
* prepare_range_limit_table (in jdmaster.c) for more info.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
|
#define RANGE_MASK (RANGE_CENTER * 2 - 1)
|
||||||
|
#define RANGE_SUBSET (RANGE_CENTER - CENTERJSAMPLE)
|
||||||
|
|
||||||
#define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
|
#define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit - RANGE_SUBSET)
|
||||||
|
|
||||||
|
|
||||||
/* Short forms of external names for systems with brain-damaged linkers. */
|
/* Short forms of external names for systems with brain-damaged linkers. */
|
||||||
@@ -355,13 +358,6 @@ EXTERN(void) jpeg_idct_1x2
|
|||||||
|
|
||||||
#define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
|
#define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
|
||||||
|
|
||||||
/* Descale and correctly round an INT32 value that's scaled by N bits.
|
|
||||||
* We assume RIGHT_SHIFT rounds towards minus infinity, so adding
|
|
||||||
* the fudge factor is correct for either sign of X.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
|
|
||||||
|
|
||||||
/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
|
/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
|
||||||
* This macro is used only when the two inputs will actually be no more than
|
* This macro is used only when the two inputs will actually be no more than
|
||||||
* 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a
|
* 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a
|
||||||
@@ -391,3 +387,23 @@ EXTERN(void) jpeg_idct_1x2
|
|||||||
#ifndef MULTIPLY16V16 /* default definition */
|
#ifndef MULTIPLY16V16 /* default definition */
|
||||||
#define MULTIPLY16V16(var1,var2) ((var1) * (var2))
|
#define MULTIPLY16V16(var1,var2) ((var1) * (var2))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Like RIGHT_SHIFT, but applies to a DCTELEM.
|
||||||
|
* We assume that int right shift is unsigned if INT32 right shift is.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef RIGHT_SHIFT_IS_UNSIGNED
|
||||||
|
#define ISHIFT_TEMPS DCTELEM ishift_temp;
|
||||||
|
#if BITS_IN_JSAMPLE == 8
|
||||||
|
#define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
|
||||||
|
#else
|
||||||
|
#define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
|
||||||
|
#endif
|
||||||
|
#define IRIGHT_SHIFT(x,shft) \
|
||||||
|
((ishift_temp = (x)) < 0 ? \
|
||||||
|
(ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
|
||||||
|
(ishift_temp >> (shft)))
|
||||||
|
#else
|
||||||
|
#define ISHIFT_TEMPS
|
||||||
|
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
|
||||||
|
#endif
|
||||||
|
|||||||
Vendored
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
* jddctmgr.c
|
* jddctmgr.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
* Modified 2002-2010 by Guido Vollbeding.
|
* Modified 2002-2013 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -368,7 +368,7 @@ jinit_inverse_dct (j_decompress_ptr cinfo)
|
|||||||
idct = (my_idct_ptr)
|
idct = (my_idct_ptr)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
SIZEOF(my_idct_controller));
|
SIZEOF(my_idct_controller));
|
||||||
cinfo->idct = (struct jpeg_inverse_dct *) idct;
|
cinfo->idct = &idct->pub;
|
||||||
idct->pub.start_pass = start_pass;
|
idct->pub.start_pass = start_pass;
|
||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
|
|||||||
Vendored
+99
-81
@@ -2,7 +2,7 @@
|
|||||||
* jdhuff.c
|
* jdhuff.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
* Modified 2006-2009 by Guido Vollbeding.
|
* Modified 2006-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -341,13 +341,12 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
|
|||||||
htbl =
|
htbl =
|
||||||
isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
|
isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
|
||||||
if (htbl == NULL)
|
if (htbl == NULL)
|
||||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
|
htbl = jpeg_std_huff_table((j_common_ptr) cinfo, isDC, tblno);
|
||||||
|
|
||||||
/* Allocate a workspace if we haven't already done so. */
|
/* Allocate a workspace if we haven't already done so. */
|
||||||
if (*pdtbl == NULL)
|
if (*pdtbl == NULL)
|
||||||
*pdtbl = (d_derived_tbl *)
|
*pdtbl = (d_derived_tbl *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(d_derived_tbl));
|
||||||
SIZEOF(d_derived_tbl));
|
|
||||||
dtbl = *pdtbl;
|
dtbl = *pdtbl;
|
||||||
dtbl->pub = htbl; /* fill in back link */
|
dtbl->pub = htbl; /* fill in back link */
|
||||||
|
|
||||||
@@ -627,6 +626,22 @@ jpeg_huff_decode (bitread_working_state * state,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Finish up at the end of a Huffman-compressed scan.
|
||||||
|
*/
|
||||||
|
|
||||||
|
METHODDEF(void)
|
||||||
|
finish_pass_huff (j_decompress_ptr cinfo)
|
||||||
|
{
|
||||||
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
|
|
||||||
|
/* Throw away any unused bits remaining in bit buffer; */
|
||||||
|
/* include any full bytes in next_marker's count of discarded bytes */
|
||||||
|
cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
|
||||||
|
entropy->bitstate.bits_left = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for a restart marker & resynchronize decoder.
|
* Check for a restart marker & resynchronize decoder.
|
||||||
* Returns FALSE if must suspend.
|
* Returns FALSE if must suspend.
|
||||||
@@ -638,10 +653,7 @@ process_restart (j_decompress_ptr cinfo)
|
|||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
int ci;
|
int ci;
|
||||||
|
|
||||||
/* Throw away any unused bits remaining in bit buffer; */
|
finish_pass_huff(cinfo);
|
||||||
/* include any full bytes in next_marker's count of discarded bytes */
|
|
||||||
cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
|
|
||||||
entropy->bitstate.bits_left = 0;
|
|
||||||
|
|
||||||
/* Advance past the RSTn marker */
|
/* Advance past the RSTn marker */
|
||||||
if (! (*cinfo->marker->read_restart_marker) (cinfo))
|
if (! (*cinfo->marker->read_restart_marker) (cinfo))
|
||||||
@@ -692,7 +704,7 @@ process_restart (j_decompress_ptr cinfo)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
int Al = cinfo->Al;
|
int Al = cinfo->Al;
|
||||||
@@ -717,7 +729,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
if (! entropy->insufficient_data) {
|
if (! entropy->insufficient_data) {
|
||||||
|
|
||||||
/* Load up working state */
|
/* Load up working state */
|
||||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(state, entropy->saved);
|
ASSIGN_STATE(state, entropy->saved);
|
||||||
|
|
||||||
/* Outer loop handles each block in the MCU */
|
/* Outer loop handles each block in the MCU */
|
||||||
@@ -746,12 +758,13 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Completed MCU, so update state */
|
/* Completed MCU, so update state */
|
||||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(entropy->saved, state);
|
ASSIGN_STATE(entropy->saved, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Account for restart interval (no-op if not using restarts) */
|
/* Account for restart interval if using restarts */
|
||||||
entropy->restarts_to_go--;
|
if (cinfo->restart_interval)
|
||||||
|
entropy->restarts_to_go--;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -763,7 +776,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
register int s, k, r;
|
register int s, k, r;
|
||||||
@@ -786,10 +799,6 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
if (! entropy->insufficient_data) {
|
if (! entropy->insufficient_data) {
|
||||||
|
|
||||||
Se = cinfo->Se;
|
|
||||||
Al = cinfo->Al;
|
|
||||||
natural_order = cinfo->natural_order;
|
|
||||||
|
|
||||||
/* Load up working state.
|
/* Load up working state.
|
||||||
* We can avoid loading/saving bitread state if in an EOB run.
|
* We can avoid loading/saving bitread state if in an EOB run.
|
||||||
*/
|
*/
|
||||||
@@ -797,10 +806,13 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/* There is always only one block per MCU */
|
/* There is always only one block per MCU */
|
||||||
|
|
||||||
if (EOBRUN > 0) /* if it's a band of zeroes... */
|
if (EOBRUN) /* if it's a band of zeroes... */
|
||||||
EOBRUN--; /* ...process it now (we do nothing) */
|
EOBRUN--; /* ...process it now (we do nothing) */
|
||||||
else {
|
else {
|
||||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||||
|
Se = cinfo->Se;
|
||||||
|
Al = cinfo->Al;
|
||||||
|
natural_order = cinfo->natural_order;
|
||||||
block = MCU_data[0];
|
block = MCU_data[0];
|
||||||
tbl = entropy->ac_derived_tbl;
|
tbl = entropy->ac_derived_tbl;
|
||||||
|
|
||||||
@@ -816,30 +828,30 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
/* Scale and output coefficient in natural (dezigzagged) order */
|
/* Scale and output coefficient in natural (dezigzagged) order */
|
||||||
(*block)[natural_order[k]] = (JCOEF) (s << Al);
|
(*block)[natural_order[k]] = (JCOEF) (s << Al);
|
||||||
} else {
|
} else {
|
||||||
if (r == 15) { /* ZRL */
|
if (r != 15) { /* EOBr, run length is 2^r + appended bits */
|
||||||
k += 15; /* skip 15 zeroes in band */
|
|
||||||
} else { /* EOBr, run length is 2^r + appended bits */
|
|
||||||
EOBRUN = 1 << r;
|
|
||||||
if (r) { /* EOBr, r > 0 */
|
if (r) { /* EOBr, r > 0 */
|
||||||
|
EOBRUN = 1 << r;
|
||||||
CHECK_BIT_BUFFER(br_state, r, return FALSE);
|
CHECK_BIT_BUFFER(br_state, r, return FALSE);
|
||||||
r = GET_BITS(r);
|
r = GET_BITS(r);
|
||||||
EOBRUN += r;
|
EOBRUN += r;
|
||||||
|
EOBRUN--; /* this band is processed at this moment */
|
||||||
}
|
}
|
||||||
EOBRUN--; /* this band is processed at this moment */
|
|
||||||
break; /* force end-of-band */
|
break; /* force end-of-band */
|
||||||
}
|
}
|
||||||
|
k += 15; /* ZRL: skip 15 zeroes in band */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Completed MCU, so update state */
|
/* Completed MCU, so update state */
|
||||||
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
|
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Account for restart interval (no-op if not using restarts) */
|
/* Account for restart interval if using restarts */
|
||||||
entropy->restarts_to_go--;
|
if (cinfo->restart_interval)
|
||||||
|
entropy->restarts_to_go--;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -847,17 +859,16 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* MCU decoding for DC successive approximation refinement scan.
|
* MCU decoding for DC successive approximation refinement scan.
|
||||||
* Note: we assume such scans can be multi-component, although the spec
|
* Note: we assume such scans can be multi-component,
|
||||||
* is not very clear on the point.
|
* although the spec is not very clear on the point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
JCOEF p1;
|
||||||
int blkn;
|
int blkn;
|
||||||
JBLOCKROW block;
|
|
||||||
BITREAD_STATE_VARS;
|
BITREAD_STATE_VARS;
|
||||||
|
|
||||||
/* Process restart marker if needed; may have to suspend */
|
/* Process restart marker if needed; may have to suspend */
|
||||||
@@ -872,25 +883,26 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Load up working state */
|
/* Load up working state */
|
||||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||||
|
|
||||||
|
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
||||||
|
|
||||||
/* Outer loop handles each block in the MCU */
|
/* Outer loop handles each block in the MCU */
|
||||||
|
|
||||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||||
block = MCU_data[blkn];
|
|
||||||
|
|
||||||
/* Encoded data is simply the next bit of the two's-complement DC value */
|
/* Encoded data is simply the next bit of the two's-complement DC value */
|
||||||
CHECK_BIT_BUFFER(br_state, 1, return FALSE);
|
CHECK_BIT_BUFFER(br_state, 1, return FALSE);
|
||||||
if (GET_BITS(1))
|
if (GET_BITS(1))
|
||||||
(*block)[0] |= p1;
|
MCU_data[blkn][0][0] |= p1;
|
||||||
/* Note: since we use |=, repeating the assignment later is safe */
|
/* Note: since we use |=, repeating the assignment later is safe */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Completed MCU, so update state */
|
/* Completed MCU, so update state */
|
||||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||||
|
|
||||||
/* Account for restart interval (no-op if not using restarts) */
|
/* Account for restart interval if using restarts */
|
||||||
entropy->restarts_to_go--;
|
if (cinfo->restart_interval)
|
||||||
|
entropy->restarts_to_go--;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -901,12 +913,13 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
register int s, k, r;
|
register int s, k, r;
|
||||||
unsigned int EOBRUN;
|
unsigned int EOBRUN;
|
||||||
int Se, p1, m1;
|
int Se;
|
||||||
|
JCOEF p1, m1;
|
||||||
const int * natural_order;
|
const int * natural_order;
|
||||||
JBLOCKROW block;
|
JBLOCKROW block;
|
||||||
JCOEFPTR thiscoef;
|
JCOEFPTR thiscoef;
|
||||||
@@ -928,11 +941,11 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
|
|
||||||
Se = cinfo->Se;
|
Se = cinfo->Se;
|
||||||
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
||||||
m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
|
m1 = -p1; /* -1 in the bit position being coded */
|
||||||
natural_order = cinfo->natural_order;
|
natural_order = cinfo->natural_order;
|
||||||
|
|
||||||
/* Load up working state */
|
/* Load up working state */
|
||||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||||
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
|
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
|
||||||
|
|
||||||
/* There is always only one block per MCU */
|
/* There is always only one block per MCU */
|
||||||
@@ -951,7 +964,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
k = cinfo->Ss;
|
k = cinfo->Ss;
|
||||||
|
|
||||||
if (EOBRUN == 0) {
|
if (EOBRUN == 0) {
|
||||||
for (; k <= Se; k++) {
|
do {
|
||||||
HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
|
HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
|
||||||
r = s >> 4;
|
r = s >> 4;
|
||||||
s &= 15;
|
s &= 15;
|
||||||
@@ -981,7 +994,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
do {
|
do {
|
||||||
thiscoef = *block + natural_order[k];
|
thiscoef = *block + natural_order[k];
|
||||||
if (*thiscoef != 0) {
|
if (*thiscoef) {
|
||||||
CHECK_BIT_BUFFER(br_state, 1, goto undoit);
|
CHECK_BIT_BUFFER(br_state, 1, goto undoit);
|
||||||
if (GET_BITS(1)) {
|
if (GET_BITS(1)) {
|
||||||
if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
|
if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
|
||||||
@@ -1004,18 +1017,19 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
/* Remember its position in case we have to suspend */
|
/* Remember its position in case we have to suspend */
|
||||||
newnz_pos[num_newnz++] = pos;
|
newnz_pos[num_newnz++] = pos;
|
||||||
}
|
}
|
||||||
}
|
k++;
|
||||||
|
} while (k <= Se);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EOBRUN > 0) {
|
if (EOBRUN) {
|
||||||
/* Scan any remaining coefficient positions after the end-of-band
|
/* Scan any remaining coefficient positions after the end-of-band
|
||||||
* (the last newly nonzero coefficient, if any). Append a correction
|
* (the last newly nonzero coefficient, if any). Append a correction
|
||||||
* bit to each already-nonzero coefficient. A correction bit is 1
|
* bit to each already-nonzero coefficient. A correction bit is 1
|
||||||
* if the absolute value of the coefficient must be increased.
|
* if the absolute value of the coefficient must be increased.
|
||||||
*/
|
*/
|
||||||
for (; k <= Se; k++) {
|
do {
|
||||||
thiscoef = *block + natural_order[k];
|
thiscoef = *block + natural_order[k];
|
||||||
if (*thiscoef != 0) {
|
if (*thiscoef) {
|
||||||
CHECK_BIT_BUFFER(br_state, 1, goto undoit);
|
CHECK_BIT_BUFFER(br_state, 1, goto undoit);
|
||||||
if (GET_BITS(1)) {
|
if (GET_BITS(1)) {
|
||||||
if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
|
if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
|
||||||
@@ -1026,24 +1040,26 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
k++;
|
||||||
|
} while (k <= Se);
|
||||||
/* Count one block completed in EOB run */
|
/* Count one block completed in EOB run */
|
||||||
EOBRUN--;
|
EOBRUN--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Completed MCU, so update state */
|
/* Completed MCU, so update state */
|
||||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||||
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
|
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Account for restart interval (no-op if not using restarts) */
|
/* Account for restart interval if using restarts */
|
||||||
entropy->restarts_to_go--;
|
if (cinfo->restart_interval)
|
||||||
|
entropy->restarts_to_go--;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
undoit:
|
undoit:
|
||||||
/* Re-zero any output coefficients that we made newly nonzero */
|
/* Re-zero any output coefficients that we made newly nonzero */
|
||||||
while (num_newnz > 0)
|
while (num_newnz)
|
||||||
(*block)[newnz_pos[--num_newnz]] = 0;
|
(*block)[newnz_pos[--num_newnz]] = 0;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -1056,7 +1072,7 @@ undoit:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
const int * natural_order;
|
const int * natural_order;
|
||||||
@@ -1080,7 +1096,7 @@ decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
Se = cinfo->lim_Se;
|
Se = cinfo->lim_Se;
|
||||||
|
|
||||||
/* Load up working state */
|
/* Load up working state */
|
||||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(state, entropy->saved);
|
ASSIGN_STATE(state, entropy->saved);
|
||||||
|
|
||||||
/* Outer loop handles each block in the MCU */
|
/* Outer loop handles each block in the MCU */
|
||||||
@@ -1167,12 +1183,13 @@ decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Completed MCU, so update state */
|
/* Completed MCU, so update state */
|
||||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(entropy->saved, state);
|
ASSIGN_STATE(entropy->saved, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Account for restart interval (no-op if not using restarts) */
|
/* Account for restart interval if using restarts */
|
||||||
entropy->restarts_to_go--;
|
if (cinfo->restart_interval)
|
||||||
|
entropy->restarts_to_go--;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -1184,7 +1201,7 @@ decode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(boolean)
|
METHODDEF(boolean)
|
||||||
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
decode_mcu (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data)
|
||||||
{
|
{
|
||||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||||
int blkn;
|
int blkn;
|
||||||
@@ -1204,7 +1221,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
if (! entropy->insufficient_data) {
|
if (! entropy->insufficient_data) {
|
||||||
|
|
||||||
/* Load up working state */
|
/* Load up working state */
|
||||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
BITREAD_LOAD_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(state, entropy->saved);
|
ASSIGN_STATE(state, entropy->saved);
|
||||||
|
|
||||||
/* Outer loop handles each block in the MCU */
|
/* Outer loop handles each block in the MCU */
|
||||||
@@ -1291,12 +1308,13 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Completed MCU, so update state */
|
/* Completed MCU, so update state */
|
||||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
BITREAD_SAVE_STATE(cinfo, entropy->bitstate);
|
||||||
ASSIGN_STATE(entropy->saved, state);
|
ASSIGN_STATE(entropy->saved, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Account for restart interval (no-op if not using restarts) */
|
/* Account for restart interval if using restarts */
|
||||||
entropy->restarts_to_go--;
|
if (cinfo->restart_interval)
|
||||||
|
entropy->restarts_to_go--;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -1332,11 +1350,11 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
|
|||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
if (cinfo->Al > 13) { /* need not check for < 0 */
|
if (cinfo->Al > 13) { /* need not check for < 0 */
|
||||||
/* Arguably the maximum Al value should be less than 13 for 8-bit precision,
|
/* Arguably the maximum Al value should be less than 13 for 8-bit
|
||||||
* but the spec doesn't say so, and we try to be liberal about what we
|
* precision, but the spec doesn't say so, and we try to be liberal
|
||||||
* accept. Note: large Al values could result in out-of-range DC
|
* about what we accept. Note: large Al values could result in
|
||||||
* coefficients during early scans, leading to bizarre displays due to
|
* out-of-range DC coefficients during early scans, leading to bizarre
|
||||||
* overflows in the IDCT math. But we won't crash.
|
* displays due to overflows in the IDCT math. But we won't crash.
|
||||||
*/
|
*/
|
||||||
bad:
|
bad:
|
||||||
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
|
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
|
||||||
@@ -1440,7 +1458,8 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
|
|||||||
compptr = cinfo->cur_comp_info[ci];
|
compptr = cinfo->cur_comp_info[ci];
|
||||||
/* Precalculate which table to use for each block */
|
/* Precalculate which table to use for each block */
|
||||||
entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
|
entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
|
||||||
entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
|
entropy->ac_cur_tbls[blkn] = /* AC needs no table when not present */
|
||||||
|
cinfo->lim_Se ? entropy->ac_derived_tbls[compptr->ac_tbl_no] : NULL;
|
||||||
/* Decide whether we really care about the coefficient values */
|
/* Decide whether we really care about the coefficient values */
|
||||||
if (compptr->component_needed) {
|
if (compptr->component_needed) {
|
||||||
ci = compptr->DCT_v_scaled_size;
|
ci = compptr->DCT_v_scaled_size;
|
||||||
@@ -1483,7 +1502,6 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
|
|||||||
if (ci <= 0 || ci > 8) ci = 8;
|
if (ci <= 0 || ci > 8) ci = 8;
|
||||||
if (i <= 0 || i > 8) i = 8;
|
if (i <= 0 || i > 8) i = 8;
|
||||||
entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order[ci - 1][i - 1];
|
entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order[ci - 1][i - 1];
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
entropy->coef_limit[blkn] = 0;
|
entropy->coef_limit[blkn] = 0;
|
||||||
@@ -1511,18 +1529,18 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
|
|||||||
huff_entropy_ptr entropy;
|
huff_entropy_ptr entropy;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
entropy = (huff_entropy_ptr)
|
entropy = (huff_entropy_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(huff_entropy_decoder));
|
||||||
SIZEOF(huff_entropy_decoder));
|
cinfo->entropy = &entropy->pub;
|
||||||
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
|
|
||||||
entropy->pub.start_pass = start_pass_huff_decoder;
|
entropy->pub.start_pass = start_pass_huff_decoder;
|
||||||
|
entropy->pub.finish_pass = finish_pass_huff;
|
||||||
|
|
||||||
if (cinfo->progressive_mode) {
|
if (cinfo->progressive_mode) {
|
||||||
/* Create progression status table */
|
/* Create progression status table */
|
||||||
int *coef_bit_ptr, ci;
|
int *coef_bit_ptr, ci;
|
||||||
cinfo->coef_bits = (int (*)[DCTSIZE2])
|
cinfo->coef_bits = (int (*)[DCTSIZE2]) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
cinfo->num_components*DCTSIZE2*SIZEOF(int));
|
cinfo->num_components * DCTSIZE2 * SIZEOF(int));
|
||||||
coef_bit_ptr = & cinfo->coef_bits[0][0];
|
coef_bit_ptr = & cinfo->coef_bits[0][0];
|
||||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||||
for (i = 0; i < DCTSIZE2; i++)
|
for (i = 0; i < DCTSIZE2; i++)
|
||||||
@@ -1533,7 +1551,7 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
|
|||||||
entropy->derived_tbls[i] = NULL;
|
entropy->derived_tbls[i] = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Mark tables unallocated */
|
/* Mark derived tables unallocated */
|
||||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||||
entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
|
entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+11
-15
@@ -2,7 +2,7 @@
|
|||||||
* jdinput.c
|
* jdinput.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
* Modified 2002-2009 by Guido Vollbeding.
|
* Modified 2002-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -196,7 +196,7 @@ jpeg_core_output_dimensions (j_decompress_ptr cinfo)
|
|||||||
/* Hardwire it to "no scaling" */
|
/* Hardwire it to "no scaling" */
|
||||||
cinfo->output_width = cinfo->image_width;
|
cinfo->output_width = cinfo->image_width;
|
||||||
cinfo->output_height = cinfo->image_height;
|
cinfo->output_height = cinfo->image_height;
|
||||||
/* jdinput.c has already initialized DCT_scaled_size,
|
/* initial_setup has already initialized DCT_scaled_size,
|
||||||
* and has computed unscaled downsampled_width and downsampled_height.
|
* and has computed unscaled downsampled_width and downsampled_height.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -216,8 +216,8 @@ initial_setup (j_decompress_ptr cinfo)
|
|||||||
(long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
|
(long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
|
||||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
|
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
|
||||||
|
|
||||||
/* For now, precision must match compiled-in value... */
|
/* Only 8 to 12 bits data precision are supported for DCT based JPEG */
|
||||||
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
if (cinfo->data_precision < 8 || cinfo->data_precision > 12)
|
||||||
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||||
|
|
||||||
/* Check that number of components won't exceed internal array sizes */
|
/* Check that number of components won't exceed internal array sizes */
|
||||||
@@ -330,7 +330,6 @@ initial_setup (j_decompress_ptr cinfo)
|
|||||||
default:
|
default:
|
||||||
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
|
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
|
||||||
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
|
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size.
|
/* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size.
|
||||||
@@ -429,9 +428,7 @@ per_scan_setup (j_decompress_ptr cinfo)
|
|||||||
cinfo->MCUs_per_row = (JDIMENSION)
|
cinfo->MCUs_per_row = (JDIMENSION)
|
||||||
jdiv_round_up((long) cinfo->image_width,
|
jdiv_round_up((long) cinfo->image_width,
|
||||||
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
||||||
cinfo->MCU_rows_in_scan = (JDIMENSION)
|
cinfo->MCU_rows_in_scan = cinfo->total_iMCU_rows;
|
||||||
jdiv_round_up((long) cinfo->image_height,
|
|
||||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
|
||||||
|
|
||||||
cinfo->blocks_in_MCU = 0;
|
cinfo->blocks_in_MCU = 0;
|
||||||
|
|
||||||
@@ -501,9 +498,8 @@ latch_quant_tables (j_decompress_ptr cinfo)
|
|||||||
cinfo->quant_tbl_ptrs[qtblno] == NULL)
|
cinfo->quant_tbl_ptrs[qtblno] == NULL)
|
||||||
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
|
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
|
||||||
/* OK, save away the quantization table */
|
/* OK, save away the quantization table */
|
||||||
qtbl = (JQUANT_TBL *)
|
qtbl = (JQUANT_TBL *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(JQUANT_TBL));
|
||||||
SIZEOF(JQUANT_TBL));
|
|
||||||
MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
|
MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
|
||||||
compptr->quant_table = qtbl;
|
compptr->quant_table = qtbl;
|
||||||
}
|
}
|
||||||
@@ -537,6 +533,7 @@ start_input_pass (j_decompress_ptr cinfo)
|
|||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
finish_input_pass (j_decompress_ptr cinfo)
|
finish_input_pass (j_decompress_ptr cinfo)
|
||||||
{
|
{
|
||||||
|
(*cinfo->entropy->finish_pass) (cinfo);
|
||||||
cinfo->inputctl->consume_input = consume_markers;
|
cinfo->inputctl->consume_input = consume_markers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,10 +640,9 @@ jinit_input_controller (j_decompress_ptr cinfo)
|
|||||||
my_inputctl_ptr inputctl;
|
my_inputctl_ptr inputctl;
|
||||||
|
|
||||||
/* Create subobject in permanent pool */
|
/* Create subobject in permanent pool */
|
||||||
inputctl = (my_inputctl_ptr)
|
inputctl = (my_inputctl_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_input_controller));
|
||||||
SIZEOF(my_input_controller));
|
cinfo->inputctl = &inputctl->pub;
|
||||||
cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
|
|
||||||
/* Initialize method pointers */
|
/* Initialize method pointers */
|
||||||
inputctl->pub.consume_input = consume_markers;
|
inputctl->pub.consume_input = consume_markers;
|
||||||
inputctl->pub.reset_input_controller = reset_input_controller;
|
inputctl->pub.reset_input_controller = reset_input_controller;
|
||||||
|
|||||||
Vendored
+99
-100
@@ -2,6 +2,7 @@
|
|||||||
* jdmainct.c
|
* jdmainct.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
|
* Modified 2002-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -25,8 +26,8 @@
|
|||||||
* trivial. Its responsibility is to provide context rows for upsampling/
|
* trivial. Its responsibility is to provide context rows for upsampling/
|
||||||
* rescaling, and doing this in an efficient fashion is a bit tricky.
|
* rescaling, and doing this in an efficient fashion is a bit tricky.
|
||||||
*
|
*
|
||||||
* Postprocessor input data is counted in "row groups". A row group
|
* Postprocessor input data is counted in "row groups". A row group is
|
||||||
* is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
|
* defined to be (v_samp_factor * DCT_v_scaled_size / min_DCT_v_scaled_size)
|
||||||
* sample rows of each component. (We require DCT_scaled_size values to be
|
* sample rows of each component. (We require DCT_scaled_size values to be
|
||||||
* chosen such that these numbers are integers. In practice DCT_scaled_size
|
* chosen such that these numbers are integers. In practice DCT_scaled_size
|
||||||
* values will likely be powers of two, so we actually have the stronger
|
* values will likely be powers of two, so we actually have the stronger
|
||||||
@@ -36,8 +37,8 @@
|
|||||||
* applying).
|
* applying).
|
||||||
*
|
*
|
||||||
* The coefficient controller will deliver data to us one iMCU row at a time;
|
* The coefficient controller will deliver data to us one iMCU row at a time;
|
||||||
* each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or
|
* each iMCU row contains v_samp_factor * DCT_v_scaled_size sample rows, or
|
||||||
* exactly min_DCT_scaled_size row groups. (This amount of data corresponds
|
* exactly min_DCT_v_scaled_size row groups. (This amount of data corresponds
|
||||||
* to one row of MCUs when the image is fully interleaved.) Note that the
|
* to one row of MCUs when the image is fully interleaved.) Note that the
|
||||||
* number of sample rows varies across components, but the number of row
|
* number of sample rows varies across components, but the number of row
|
||||||
* groups does not. Some garbage sample rows may be included in the last iMCU
|
* groups does not. Some garbage sample rows may be included in the last iMCU
|
||||||
@@ -74,7 +75,7 @@
|
|||||||
* We could do this most simply by copying data around in our buffer, but
|
* We could do this most simply by copying data around in our buffer, but
|
||||||
* that'd be very slow. We can avoid copying any data by creating a rather
|
* that'd be very slow. We can avoid copying any data by creating a rather
|
||||||
* strange pointer structure. Here's how it works. We allocate a workspace
|
* strange pointer structure. Here's how it works. We allocate a workspace
|
||||||
* consisting of M+2 row groups (where M = min_DCT_scaled_size is the number
|
* consisting of M+2 row groups (where M = min_DCT_v_scaled_size is the number
|
||||||
* of row groups per iMCU row). We create two sets of redundant pointers to
|
* of row groups per iMCU row). We create two sets of redundant pointers to
|
||||||
* the workspace. Labeling the physical row groups 0 to M+1, the synthesized
|
* the workspace. Labeling the physical row groups 0 to M+1, the synthesized
|
||||||
* pointer lists look like this:
|
* pointer lists look like this:
|
||||||
@@ -99,11 +100,11 @@
|
|||||||
* the first or last sample row as necessary (this is cheaper than copying
|
* the first or last sample row as necessary (this is cheaper than copying
|
||||||
* sample rows around).
|
* sample rows around).
|
||||||
*
|
*
|
||||||
* This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that
|
* This scheme breaks down if M < 2, ie, min_DCT_v_scaled_size is 1. In that
|
||||||
* situation each iMCU row provides only one row group so the buffering logic
|
* situation each iMCU row provides only one row group so the buffering logic
|
||||||
* must be different (eg, we must read two iMCU rows before we can emit the
|
* must be different (eg, we must read two iMCU rows before we can emit the
|
||||||
* first row group). For now, we simply do not support providing context
|
* first row group). For now, we simply do not support providing context
|
||||||
* rows when min_DCT_scaled_size is 1. That combination seems unlikely to
|
* rows when min_DCT_v_scaled_size is 1. That combination seems unlikely to
|
||||||
* be worth providing --- if someone wants a 1/8th-size preview, they probably
|
* be worth providing --- if someone wants a 1/8th-size preview, they probably
|
||||||
* want it quick and dirty, so a context-free upsampler is sufficient.
|
* want it quick and dirty, so a context-free upsampler is sufficient.
|
||||||
*/
|
*/
|
||||||
@@ -117,17 +118,18 @@ typedef struct {
|
|||||||
/* Pointer to allocated workspace (M or M+2 row groups). */
|
/* Pointer to allocated workspace (M or M+2 row groups). */
|
||||||
JSAMPARRAY buffer[MAX_COMPONENTS];
|
JSAMPARRAY buffer[MAX_COMPONENTS];
|
||||||
|
|
||||||
boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
|
|
||||||
JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
|
JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
|
||||||
|
JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
|
||||||
|
|
||||||
/* Remaining fields are only used in the context case. */
|
/* Remaining fields are only used in the context case. */
|
||||||
|
|
||||||
|
boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
|
||||||
|
|
||||||
/* These are the master pointers to the funny-order pointer lists. */
|
/* These are the master pointers to the funny-order pointer lists. */
|
||||||
JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
|
JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
|
||||||
|
|
||||||
int whichptr; /* indicates which pointer set is now in use */
|
int whichptr; /* indicates which pointer set is now in use */
|
||||||
int context_state; /* process_data state machine status */
|
int context_state; /* process_data state machine status */
|
||||||
JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
|
|
||||||
JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
|
JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
|
||||||
} my_main_controller;
|
} my_main_controller;
|
||||||
|
|
||||||
@@ -159,7 +161,7 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
|
|||||||
* This is done only once, not once per pass.
|
* This is done only once, not once per pass.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
int ci, rgroup;
|
int ci, rgroup;
|
||||||
int M = cinfo->min_DCT_v_scaled_size;
|
int M = cinfo->min_DCT_v_scaled_size;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
@@ -168,25 +170,26 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
|
|||||||
/* Get top-level space for component array pointers.
|
/* Get top-level space for component array pointers.
|
||||||
* We alloc both arrays with one call to save a few cycles.
|
* We alloc both arrays with one call to save a few cycles.
|
||||||
*/
|
*/
|
||||||
main->xbuffer[0] = (JSAMPIMAGE)
|
mainp->xbuffer[0] = (JSAMPIMAGE) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
|
cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
|
||||||
main->xbuffer[1] = main->xbuffer[0] + cinfo->num_components;
|
mainp->xbuffer[1] = mainp->xbuffer[0] + cinfo->num_components;
|
||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
|
if (! compptr->component_needed)
|
||||||
|
continue; /* skip uninteresting component */
|
||||||
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||||
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
||||||
/* Get space for pointer lists --- M+4 row groups in each list.
|
/* Get space for pointer lists --- M+4 row groups in each list.
|
||||||
* We alloc both pointer lists with one call to save a few cycles.
|
* We alloc both pointer lists with one call to save a few cycles.
|
||||||
*/
|
*/
|
||||||
xbuf = (JSAMPARRAY)
|
xbuf = (JSAMPARRAY) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
JPOOL_IMAGE, 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
|
||||||
2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
|
|
||||||
xbuf += rgroup; /* want one row group at negative offsets */
|
xbuf += rgroup; /* want one row group at negative offsets */
|
||||||
main->xbuffer[0][ci] = xbuf;
|
mainp->xbuffer[0][ci] = xbuf;
|
||||||
xbuf += rgroup * (M + 4);
|
xbuf += rgroup * (M + 4);
|
||||||
main->xbuffer[1][ci] = xbuf;
|
mainp->xbuffer[1][ci] = xbuf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,13 +197,13 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
|
|||||||
LOCAL(void)
|
LOCAL(void)
|
||||||
make_funny_pointers (j_decompress_ptr cinfo)
|
make_funny_pointers (j_decompress_ptr cinfo)
|
||||||
/* Create the funny pointer lists discussed in the comments above.
|
/* Create the funny pointer lists discussed in the comments above.
|
||||||
* The actual workspace is already allocated (in main->buffer),
|
* The actual workspace is already allocated (in mainp->buffer),
|
||||||
* and the space for the pointer lists is allocated too.
|
* and the space for the pointer lists is allocated too.
|
||||||
* This routine just fills in the curiously ordered lists.
|
* This routine just fills in the curiously ordered lists.
|
||||||
* This will be repeated at the beginning of each pass.
|
* This will be repeated at the beginning of each pass.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
int ci, i, rgroup;
|
int ci, i, rgroup;
|
||||||
int M = cinfo->min_DCT_v_scaled_size;
|
int M = cinfo->min_DCT_v_scaled_size;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
@@ -208,12 +211,14 @@ make_funny_pointers (j_decompress_ptr cinfo)
|
|||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
|
if (! compptr->component_needed)
|
||||||
|
continue; /* skip uninteresting component */
|
||||||
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||||
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
||||||
xbuf0 = main->xbuffer[0][ci];
|
xbuf0 = mainp->xbuffer[0][ci];
|
||||||
xbuf1 = main->xbuffer[1][ci];
|
xbuf1 = mainp->xbuffer[1][ci];
|
||||||
/* First copy the workspace pointers as-is */
|
/* First copy the workspace pointers as-is */
|
||||||
buf = main->buffer[ci];
|
buf = mainp->buffer[ci];
|
||||||
for (i = 0; i < rgroup * (M + 2); i++) {
|
for (i = 0; i < rgroup * (M + 2); i++) {
|
||||||
xbuf0[i] = xbuf1[i] = buf[i];
|
xbuf0[i] = xbuf1[i] = buf[i];
|
||||||
}
|
}
|
||||||
@@ -240,7 +245,7 @@ set_wraparound_pointers (j_decompress_ptr cinfo)
|
|||||||
* This changes the pointer list state from top-of-image to the normal state.
|
* This changes the pointer list state from top-of-image to the normal state.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
int ci, i, rgroup;
|
int ci, i, rgroup;
|
||||||
int M = cinfo->min_DCT_v_scaled_size;
|
int M = cinfo->min_DCT_v_scaled_size;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
@@ -248,10 +253,12 @@ set_wraparound_pointers (j_decompress_ptr cinfo)
|
|||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
|
if (! compptr->component_needed)
|
||||||
|
continue; /* skip uninteresting component */
|
||||||
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||||
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
||||||
xbuf0 = main->xbuffer[0][ci];
|
xbuf0 = mainp->xbuffer[0][ci];
|
||||||
xbuf1 = main->xbuffer[1][ci];
|
xbuf1 = mainp->xbuffer[1][ci];
|
||||||
for (i = 0; i < rgroup; i++) {
|
for (i = 0; i < rgroup; i++) {
|
||||||
xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
|
xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
|
||||||
xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
|
xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
|
||||||
@@ -269,13 +276,15 @@ set_bottom_pointers (j_decompress_ptr cinfo)
|
|||||||
* Also sets rowgroups_avail to indicate number of nondummy row groups in row.
|
* Also sets rowgroups_avail to indicate number of nondummy row groups in row.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
int ci, i, rgroup, iMCUheight, rows_left;
|
int ci, i, rgroup, iMCUheight, rows_left;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
JSAMPARRAY xbuf;
|
JSAMPARRAY xbuf;
|
||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
|
if (! compptr->component_needed)
|
||||||
|
continue; /* skip uninteresting component */
|
||||||
/* Count sample rows in one iMCU row and in one row group */
|
/* Count sample rows in one iMCU row and in one row group */
|
||||||
iMCUheight = compptr->v_samp_factor * compptr->DCT_v_scaled_size;
|
iMCUheight = compptr->v_samp_factor * compptr->DCT_v_scaled_size;
|
||||||
rgroup = iMCUheight / cinfo->min_DCT_v_scaled_size;
|
rgroup = iMCUheight / cinfo->min_DCT_v_scaled_size;
|
||||||
@@ -286,12 +295,12 @@ set_bottom_pointers (j_decompress_ptr cinfo)
|
|||||||
* so we need only do it once.
|
* so we need only do it once.
|
||||||
*/
|
*/
|
||||||
if (ci == 0) {
|
if (ci == 0) {
|
||||||
main->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
|
mainp->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
|
||||||
}
|
}
|
||||||
/* Duplicate the last real sample row rgroup*2 times; this pads out the
|
/* Duplicate the last real sample row rgroup*2 times; this pads out the
|
||||||
* last partial rowgroup and ensures at least one full rowgroup of context.
|
* last partial rowgroup and ensures at least one full rowgroup of context.
|
||||||
*/
|
*/
|
||||||
xbuf = main->xbuffer[main->whichptr][ci];
|
xbuf = mainp->xbuffer[mainp->whichptr][ci];
|
||||||
for (i = 0; i < rgroup * 2; i++) {
|
for (i = 0; i < rgroup * 2; i++) {
|
||||||
xbuf[rows_left + i] = xbuf[rows_left-1];
|
xbuf[rows_left + i] = xbuf[rows_left-1];
|
||||||
}
|
}
|
||||||
@@ -306,32 +315,31 @@ set_bottom_pointers (j_decompress_ptr cinfo)
|
|||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
|
|
||||||
switch (pass_mode) {
|
switch (pass_mode) {
|
||||||
case JBUF_PASS_THRU:
|
case JBUF_PASS_THRU:
|
||||||
if (cinfo->upsample->need_context_rows) {
|
if (cinfo->upsample->need_context_rows) {
|
||||||
main->pub.process_data = process_data_context_main;
|
mainp->pub.process_data = process_data_context_main;
|
||||||
make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
|
make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
|
||||||
main->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
|
mainp->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
|
||||||
main->context_state = CTX_PREPARE_FOR_IMCU;
|
mainp->context_state = CTX_PREPARE_FOR_IMCU;
|
||||||
main->iMCU_row_ctr = 0;
|
mainp->iMCU_row_ctr = 0;
|
||||||
|
mainp->buffer_full = FALSE; /* Mark buffer empty */
|
||||||
} else {
|
} else {
|
||||||
/* Simple case with no context needed */
|
/* Simple case with no context needed */
|
||||||
main->pub.process_data = process_data_simple_main;
|
mainp->pub.process_data = process_data_simple_main;
|
||||||
|
mainp->rowgroup_ctr = mainp->rowgroups_avail; /* Mark buffer empty */
|
||||||
}
|
}
|
||||||
main->buffer_full = FALSE; /* Mark buffer empty */
|
|
||||||
main->rowgroup_ctr = 0;
|
|
||||||
break;
|
break;
|
||||||
#ifdef QUANT_2PASS_SUPPORTED
|
#ifdef QUANT_2PASS_SUPPORTED
|
||||||
case JBUF_CRANK_DEST:
|
case JBUF_CRANK_DEST:
|
||||||
/* For last pass of 2-pass quantization, just crank the postprocessor */
|
/* For last pass of 2-pass quantization, just crank the postprocessor */
|
||||||
main->pub.process_data = process_data_crank_post;
|
mainp->pub.process_data = process_data_crank_post;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,37 +350,27 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
process_data_simple_main (j_decompress_ptr cinfo,
|
process_data_simple_main (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||||
JDIMENSION out_rows_avail)
|
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
JDIMENSION rowgroups_avail;
|
|
||||||
|
|
||||||
/* Read input data if we haven't filled the main buffer yet */
|
/* Read input data if we haven't filled the main buffer yet */
|
||||||
if (! main->buffer_full) {
|
if (mainp->rowgroup_ctr >= mainp->rowgroups_avail) {
|
||||||
if (! (*cinfo->coef->decompress_data) (cinfo, main->buffer))
|
if (! (*cinfo->coef->decompress_data) (cinfo, mainp->buffer))
|
||||||
return; /* suspension forced, can do nothing more */
|
return; /* suspension forced, can do nothing more */
|
||||||
main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
|
mainp->rowgroup_ctr = 0; /* OK, we have an iMCU row to work with */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* There are always min_DCT_scaled_size row groups in an iMCU row. */
|
|
||||||
rowgroups_avail = (JDIMENSION) cinfo->min_DCT_v_scaled_size;
|
|
||||||
/* Note: at the bottom of the image, we may pass extra garbage row groups
|
/* Note: at the bottom of the image, we may pass extra garbage row groups
|
||||||
* to the postprocessor. The postprocessor has to check for bottom
|
* to the postprocessor. The postprocessor has to check for bottom
|
||||||
* of image anyway (at row resolution), so no point in us doing it too.
|
* of image anyway (at row resolution), so no point in us doing it too.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Feed the postprocessor */
|
/* Feed the postprocessor */
|
||||||
(*cinfo->post->post_process_data) (cinfo, main->buffer,
|
(*cinfo->post->post_process_data) (cinfo, mainp->buffer,
|
||||||
&main->rowgroup_ctr, rowgroups_avail,
|
&mainp->rowgroup_ctr, mainp->rowgroups_avail,
|
||||||
output_buf, out_row_ctr, out_rows_avail);
|
output_buf, out_row_ctr, out_rows_avail);
|
||||||
|
|
||||||
/* Has postprocessor consumed all the data yet? If so, mark buffer empty */
|
|
||||||
if (main->rowgroup_ctr >= rowgroups_avail) {
|
|
||||||
main->buffer_full = FALSE;
|
|
||||||
main->rowgroup_ctr = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -382,19 +380,18 @@ process_data_simple_main (j_decompress_ptr cinfo,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
process_data_context_main (j_decompress_ptr cinfo,
|
process_data_context_main (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||||
JDIMENSION out_rows_avail)
|
|
||||||
{
|
{
|
||||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||||
|
|
||||||
/* Read input data if we haven't filled the main buffer yet */
|
/* Read input data if we haven't filled the main buffer yet */
|
||||||
if (! main->buffer_full) {
|
if (! mainp->buffer_full) {
|
||||||
if (! (*cinfo->coef->decompress_data) (cinfo,
|
if (! (*cinfo->coef->decompress_data) (cinfo,
|
||||||
main->xbuffer[main->whichptr]))
|
mainp->xbuffer[mainp->whichptr]))
|
||||||
return; /* suspension forced, can do nothing more */
|
return; /* suspension forced, can do nothing more */
|
||||||
main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
|
mainp->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
|
||||||
main->iMCU_row_ctr++; /* count rows received */
|
mainp->iMCU_row_ctr++; /* count rows received */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Postprocessor typically will not swallow all the input data it is handed
|
/* Postprocessor typically will not swallow all the input data it is handed
|
||||||
@@ -402,47 +399,47 @@ process_data_context_main (j_decompress_ptr cinfo,
|
|||||||
* to exit and restart. This switch lets us keep track of how far we got.
|
* to exit and restart. This switch lets us keep track of how far we got.
|
||||||
* Note that each case falls through to the next on successful completion.
|
* Note that each case falls through to the next on successful completion.
|
||||||
*/
|
*/
|
||||||
switch (main->context_state) {
|
switch (mainp->context_state) {
|
||||||
case CTX_POSTPONED_ROW:
|
case CTX_POSTPONED_ROW:
|
||||||
/* Call postprocessor using previously set pointers for postponed row */
|
/* Call postprocessor using previously set pointers for postponed row */
|
||||||
(*cinfo->post->post_process_data) (cinfo, main->xbuffer[main->whichptr],
|
(*cinfo->post->post_process_data) (cinfo, mainp->xbuffer[mainp->whichptr],
|
||||||
&main->rowgroup_ctr, main->rowgroups_avail,
|
&mainp->rowgroup_ctr, mainp->rowgroups_avail,
|
||||||
output_buf, out_row_ctr, out_rows_avail);
|
output_buf, out_row_ctr, out_rows_avail);
|
||||||
if (main->rowgroup_ctr < main->rowgroups_avail)
|
if (mainp->rowgroup_ctr < mainp->rowgroups_avail)
|
||||||
return; /* Need to suspend */
|
return; /* Need to suspend */
|
||||||
main->context_state = CTX_PREPARE_FOR_IMCU;
|
mainp->context_state = CTX_PREPARE_FOR_IMCU;
|
||||||
if (*out_row_ctr >= out_rows_avail)
|
if (*out_row_ctr >= out_rows_avail)
|
||||||
return; /* Postprocessor exactly filled output buf */
|
return; /* Postprocessor exactly filled output buf */
|
||||||
/*FALLTHROUGH*/
|
/*FALLTHROUGH*/
|
||||||
case CTX_PREPARE_FOR_IMCU:
|
case CTX_PREPARE_FOR_IMCU:
|
||||||
/* Prepare to process first M-1 row groups of this iMCU row */
|
/* Prepare to process first M-1 row groups of this iMCU row */
|
||||||
main->rowgroup_ctr = 0;
|
mainp->rowgroup_ctr = 0;
|
||||||
main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size - 1);
|
mainp->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size - 1);
|
||||||
/* Check for bottom of image: if so, tweak pointers to "duplicate"
|
/* Check for bottom of image: if so, tweak pointers to "duplicate"
|
||||||
* the last sample row, and adjust rowgroups_avail to ignore padding rows.
|
* the last sample row, and adjust rowgroups_avail to ignore padding rows.
|
||||||
*/
|
*/
|
||||||
if (main->iMCU_row_ctr == cinfo->total_iMCU_rows)
|
if (mainp->iMCU_row_ctr == cinfo->total_iMCU_rows)
|
||||||
set_bottom_pointers(cinfo);
|
set_bottom_pointers(cinfo);
|
||||||
main->context_state = CTX_PROCESS_IMCU;
|
mainp->context_state = CTX_PROCESS_IMCU;
|
||||||
/*FALLTHROUGH*/
|
/*FALLTHROUGH*/
|
||||||
case CTX_PROCESS_IMCU:
|
case CTX_PROCESS_IMCU:
|
||||||
/* Call postprocessor using previously set pointers */
|
/* Call postprocessor using previously set pointers */
|
||||||
(*cinfo->post->post_process_data) (cinfo, main->xbuffer[main->whichptr],
|
(*cinfo->post->post_process_data) (cinfo, mainp->xbuffer[mainp->whichptr],
|
||||||
&main->rowgroup_ctr, main->rowgroups_avail,
|
&mainp->rowgroup_ctr, mainp->rowgroups_avail,
|
||||||
output_buf, out_row_ctr, out_rows_avail);
|
output_buf, out_row_ctr, out_rows_avail);
|
||||||
if (main->rowgroup_ctr < main->rowgroups_avail)
|
if (mainp->rowgroup_ctr < mainp->rowgroups_avail)
|
||||||
return; /* Need to suspend */
|
return; /* Need to suspend */
|
||||||
/* After the first iMCU, change wraparound pointers to normal state */
|
/* After the first iMCU, change wraparound pointers to normal state */
|
||||||
if (main->iMCU_row_ctr == 1)
|
if (mainp->iMCU_row_ctr == 1)
|
||||||
set_wraparound_pointers(cinfo);
|
set_wraparound_pointers(cinfo);
|
||||||
/* Prepare to load new iMCU row using other xbuffer list */
|
/* Prepare to load new iMCU row using other xbuffer list */
|
||||||
main->whichptr ^= 1; /* 0=>1 or 1=>0 */
|
mainp->whichptr ^= 1; /* 0=>1 or 1=>0 */
|
||||||
main->buffer_full = FALSE;
|
mainp->buffer_full = FALSE;
|
||||||
/* Still need to process last row group of this iMCU row, */
|
/* Still need to process last row group of this iMCU row, */
|
||||||
/* which is saved at index M+1 of the other xbuffer */
|
/* which is saved at index M+1 of the other xbuffer */
|
||||||
main->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 1);
|
mainp->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 1);
|
||||||
main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 2);
|
mainp->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 2);
|
||||||
main->context_state = CTX_POSTPONED_ROW;
|
mainp->context_state = CTX_POSTPONED_ROW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -456,13 +453,12 @@ process_data_context_main (j_decompress_ptr cinfo,
|
|||||||
#ifdef QUANT_2PASS_SUPPORTED
|
#ifdef QUANT_2PASS_SUPPORTED
|
||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
process_data_crank_post (j_decompress_ptr cinfo,
|
process_data_crank_post (j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
|
||||||
JDIMENSION out_rows_avail)
|
|
||||||
{
|
{
|
||||||
(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
|
(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
|
||||||
(JDIMENSION *) NULL, (JDIMENSION) 0,
|
(JDIMENSION *) NULL, (JDIMENSION) 0,
|
||||||
output_buf, out_row_ctr, out_rows_avail);
|
output_buf, out_row_ctr, out_rows_avail);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* QUANT_2PASS_SUPPORTED */
|
#endif /* QUANT_2PASS_SUPPORTED */
|
||||||
@@ -475,15 +471,14 @@ process_data_crank_post (j_decompress_ptr cinfo,
|
|||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||||
{
|
{
|
||||||
my_main_ptr main;
|
my_main_ptr mainp;
|
||||||
int ci, rgroup, ngroups;
|
int ci, rgroup, ngroups;
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
|
|
||||||
main = (my_main_ptr)
|
mainp = (my_main_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_main_controller));
|
||||||
SIZEOF(my_main_controller));
|
cinfo->main = &mainp->pub;
|
||||||
cinfo->main = (struct jpeg_d_main_controller *) main;
|
mainp->pub.start_pass = start_pass_main;
|
||||||
main->pub.start_pass = start_pass_main;
|
|
||||||
|
|
||||||
if (need_full_buffer) /* shouldn't happen */
|
if (need_full_buffer) /* shouldn't happen */
|
||||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||||
@@ -497,16 +492,20 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
|||||||
alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
|
alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
|
||||||
ngroups = cinfo->min_DCT_v_scaled_size + 2;
|
ngroups = cinfo->min_DCT_v_scaled_size + 2;
|
||||||
} else {
|
} else {
|
||||||
|
/* There are always min_DCT_v_scaled_size row groups in an iMCU row. */
|
||||||
ngroups = cinfo->min_DCT_v_scaled_size;
|
ngroups = cinfo->min_DCT_v_scaled_size;
|
||||||
|
mainp->rowgroups_avail = (JDIMENSION) ngroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
|
if (! compptr->component_needed)
|
||||||
|
continue; /* skip uninteresting component */
|
||||||
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||||
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
||||||
main->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
||||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
compptr->width_in_blocks * compptr->DCT_h_scaled_size,
|
compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
|
||||||
(JDIMENSION) (rgroup * ngroups));
|
(JDIMENSION) (rgroup * ngroups));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+125
-26
@@ -2,7 +2,7 @@
|
|||||||
* jdmarker.c
|
* jdmarker.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||||
* Modified 2009 by Guido Vollbeding.
|
* Modified 2009-2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -77,6 +77,7 @@ typedef enum { /* JPEG marker codes */
|
|||||||
M_APP15 = 0xef,
|
M_APP15 = 0xef,
|
||||||
|
|
||||||
M_JPG0 = 0xf0,
|
M_JPG0 = 0xf0,
|
||||||
|
M_JPG8 = 0xf8,
|
||||||
M_JPG13 = 0xfd,
|
M_JPG13 = 0xfd,
|
||||||
M_COM = 0xfe,
|
M_COM = 0xfe,
|
||||||
|
|
||||||
@@ -217,6 +218,7 @@ get_soi (j_decompress_ptr cinfo)
|
|||||||
/* Set initial assumptions for colorspace etc */
|
/* Set initial assumptions for colorspace etc */
|
||||||
|
|
||||||
cinfo->jpeg_color_space = JCS_UNKNOWN;
|
cinfo->jpeg_color_space = JCS_UNKNOWN;
|
||||||
|
cinfo->color_transform = JCT_NONE;
|
||||||
cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
|
cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
|
||||||
|
|
||||||
cinfo->saw_JFIF_marker = FALSE;
|
cinfo->saw_JFIF_marker = FALSE;
|
||||||
@@ -240,7 +242,7 @@ get_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog,
|
|||||||
/* Process a SOFn marker */
|
/* Process a SOFn marker */
|
||||||
{
|
{
|
||||||
INT32 length;
|
INT32 length;
|
||||||
int c, ci;
|
int c, ci, i;
|
||||||
jpeg_component_info * compptr;
|
jpeg_component_info * compptr;
|
||||||
INPUT_VARS(cinfo);
|
INPUT_VARS(cinfo);
|
||||||
|
|
||||||
@@ -267,8 +269,8 @@ get_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog,
|
|||||||
/* We don't support files in which the image height is initially specified */
|
/* 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, */
|
/* as 0 and is later redefined by DNL. As long as we have to check that, */
|
||||||
/* might as well have a general sanity check. */
|
/* might as well have a general sanity check. */
|
||||||
if (cinfo->image_height <= 0 || cinfo->image_width <= 0
|
if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||
|
||||||
|| cinfo->num_components <= 0)
|
cinfo->num_components <= 0)
|
||||||
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
|
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
|
||||||
|
|
||||||
if (length != (cinfo->num_components * 3))
|
if (length != (cinfo->num_components * 3))
|
||||||
@@ -279,10 +281,26 @@ get_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog,
|
|||||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
cinfo->num_components * SIZEOF(jpeg_component_info));
|
cinfo->num_components * SIZEOF(jpeg_component_info));
|
||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||||
ci++, compptr++) {
|
INPUT_BYTE(cinfo, c, return FALSE);
|
||||||
|
/* Check to see whether component id has already been seen */
|
||||||
|
/* (in violation of the spec, but unfortunately seen in some */
|
||||||
|
/* files). If so, create "fake" component id equal to the */
|
||||||
|
/* max id seen so far + 1. */
|
||||||
|
for (i = 0, compptr = cinfo->comp_info; i < ci; i++, compptr++) {
|
||||||
|
if (c == compptr->component_id) {
|
||||||
|
compptr = cinfo->comp_info;
|
||||||
|
c = compptr->component_id;
|
||||||
|
compptr++;
|
||||||
|
for (i = 1; i < ci; i++, compptr++) {
|
||||||
|
if (compptr->component_id > c) c = compptr->component_id;
|
||||||
|
}
|
||||||
|
c++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compptr->component_id = c;
|
||||||
compptr->component_index = ci;
|
compptr->component_index = ci;
|
||||||
INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
|
|
||||||
INPUT_BYTE(cinfo, c, return FALSE);
|
INPUT_BYTE(cinfo, c, return FALSE);
|
||||||
compptr->h_samp_factor = (c >> 4) & 15;
|
compptr->h_samp_factor = (c >> 4) & 15;
|
||||||
compptr->v_samp_factor = (c ) & 15;
|
compptr->v_samp_factor = (c ) & 15;
|
||||||
@@ -305,12 +323,12 @@ get_sos (j_decompress_ptr cinfo)
|
|||||||
/* Process a SOS marker */
|
/* Process a SOS marker */
|
||||||
{
|
{
|
||||||
INT32 length;
|
INT32 length;
|
||||||
int i, ci, n, c, cc;
|
int c, ci, i, n;
|
||||||
jpeg_component_info * compptr;
|
jpeg_component_info * compptr;
|
||||||
INPUT_VARS(cinfo);
|
INPUT_VARS(cinfo);
|
||||||
|
|
||||||
if (! cinfo->marker->saw_SOF)
|
if (! cinfo->marker->saw_SOF)
|
||||||
ERREXIT(cinfo, JERR_SOS_NO_SOF);
|
ERREXITS(cinfo, JERR_SOF_BEFORE, "SOS");
|
||||||
|
|
||||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||||
|
|
||||||
@@ -328,24 +346,41 @@ get_sos (j_decompress_ptr cinfo)
|
|||||||
/* Collect the component-spec parameters */
|
/* Collect the component-spec parameters */
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
INPUT_BYTE(cinfo, cc, return FALSE);
|
|
||||||
INPUT_BYTE(cinfo, c, return FALSE);
|
INPUT_BYTE(cinfo, c, return FALSE);
|
||||||
|
|
||||||
|
/* Detect the case where component id's are not unique, and, if so, */
|
||||||
|
/* create a fake component id using the same logic as in get_sof. */
|
||||||
|
/* Note: This also ensures that all of the SOF components are */
|
||||||
|
/* referenced in the single scan case, which prevents access to */
|
||||||
|
/* uninitialized memory in later decoding stages. */
|
||||||
|
for (ci = 0; ci < i; ci++) {
|
||||||
|
if (c == cinfo->cur_comp_info[ci]->component_id) {
|
||||||
|
c = cinfo->cur_comp_info[0]->component_id;
|
||||||
|
for (ci = 1; ci < i; ci++) {
|
||||||
|
compptr = cinfo->cur_comp_info[ci];
|
||||||
|
if (compptr->component_id > c) c = compptr->component_id;
|
||||||
|
}
|
||||||
|
c++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
if (cc == compptr->component_id)
|
if (c == compptr->component_id)
|
||||||
goto id_found;
|
goto id_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
|
ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, c);
|
||||||
|
|
||||||
id_found:
|
id_found:
|
||||||
|
|
||||||
cinfo->cur_comp_info[i] = compptr;
|
cinfo->cur_comp_info[i] = compptr;
|
||||||
|
INPUT_BYTE(cinfo, c, return FALSE);
|
||||||
compptr->dc_tbl_no = (c >> 4) & 15;
|
compptr->dc_tbl_no = (c >> 4) & 15;
|
||||||
compptr->ac_tbl_no = (c ) & 15;
|
compptr->ac_tbl_no = (c ) & 15;
|
||||||
|
|
||||||
TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
|
TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, compptr->component_id,
|
||||||
compptr->dc_tbl_no, compptr->ac_tbl_no);
|
compptr->dc_tbl_no, compptr->ac_tbl_no);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,7 +515,8 @@ get_dht (j_decompress_ptr cinfo)
|
|||||||
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
|
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
|
||||||
|
|
||||||
MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
|
MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
|
||||||
MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
|
if (count > 0)
|
||||||
|
MEMCOPY((*htblptr)->huffval, huffval, count * SIZEOF(UINT8));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length != 0)
|
if (length != 0)
|
||||||
@@ -540,14 +576,14 @@ get_dqt (j_decompress_ptr cinfo)
|
|||||||
count = DCTSIZE2;
|
count = DCTSIZE2;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (count) {
|
switch ((int) count) {
|
||||||
case (2*2): natural_order = jpeg_natural_order2; break;
|
case (2*2): natural_order = jpeg_natural_order2; break;
|
||||||
case (3*3): natural_order = jpeg_natural_order3; break;
|
case (3*3): natural_order = jpeg_natural_order3; break;
|
||||||
case (4*4): natural_order = jpeg_natural_order4; break;
|
case (4*4): natural_order = jpeg_natural_order4; break;
|
||||||
case (5*5): natural_order = jpeg_natural_order5; break;
|
case (5*5): natural_order = jpeg_natural_order5; break;
|
||||||
case (6*6): natural_order = jpeg_natural_order6; break;
|
case (6*6): natural_order = jpeg_natural_order6; break;
|
||||||
case (7*7): natural_order = jpeg_natural_order7; break;
|
case (7*7): natural_order = jpeg_natural_order7; break;
|
||||||
default: natural_order = jpeg_natural_order; break;
|
default: natural_order = jpeg_natural_order;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
@@ -605,6 +641,68 @@ get_dri (j_decompress_ptr cinfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL(boolean)
|
||||||
|
get_lse (j_decompress_ptr cinfo)
|
||||||
|
/* Process an LSE marker */
|
||||||
|
{
|
||||||
|
INT32 length;
|
||||||
|
unsigned int tmp;
|
||||||
|
int cid;
|
||||||
|
INPUT_VARS(cinfo);
|
||||||
|
|
||||||
|
if (! cinfo->marker->saw_SOF)
|
||||||
|
ERREXITS(cinfo, JERR_SOF_BEFORE, "LSE");
|
||||||
|
|
||||||
|
if (cinfo->num_components < 3) goto bad;
|
||||||
|
|
||||||
|
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||||
|
|
||||||
|
if (length != 24)
|
||||||
|
ERREXIT(cinfo, JERR_BAD_LENGTH);
|
||||||
|
|
||||||
|
INPUT_BYTE(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 0x0D) /* ID inverse transform specification */
|
||||||
|
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
|
||||||
|
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != MAXJSAMPLE) goto bad; /* MAXTRANS */
|
||||||
|
INPUT_BYTE(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 3) goto bad; /* Nt=3 */
|
||||||
|
INPUT_BYTE(cinfo, cid, return FALSE);
|
||||||
|
if (cid != cinfo->comp_info[1].component_id) goto bad;
|
||||||
|
INPUT_BYTE(cinfo, cid, return FALSE);
|
||||||
|
if (cid != cinfo->comp_info[0].component_id) goto bad;
|
||||||
|
INPUT_BYTE(cinfo, cid, return FALSE);
|
||||||
|
if (cid != cinfo->comp_info[2].component_id) goto bad;
|
||||||
|
INPUT_BYTE(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 0x80) goto bad; /* F1: CENTER1=1, NORM1=0 */
|
||||||
|
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 0) goto bad; /* A(1,1)=0 */
|
||||||
|
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 0) goto bad; /* A(1,2)=0 */
|
||||||
|
INPUT_BYTE(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 0) goto bad; /* F2: CENTER2=0, NORM2=0 */
|
||||||
|
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 1) goto bad; /* A(2,1)=1 */
|
||||||
|
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 0) goto bad; /* A(2,2)=0 */
|
||||||
|
INPUT_BYTE(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 0) goto bad; /* F3: CENTER3=0, NORM3=0 */
|
||||||
|
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 1) goto bad; /* A(3,1)=1 */
|
||||||
|
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||||
|
if (tmp != 0) { /* A(3,2)=0 */
|
||||||
|
bad:
|
||||||
|
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* OK, valid transform that we can handle. */
|
||||||
|
cinfo->color_transform = JCT_SUBTRACT_GREEN;
|
||||||
|
|
||||||
|
INPUT_SYNC(cinfo);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Routines for processing APPn and COM markers.
|
* Routines for processing APPn and COM markers.
|
||||||
* These are either saved in memory or discarded, per application request.
|
* These are either saved in memory or discarded, per application request.
|
||||||
@@ -641,12 +739,13 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
|
|||||||
cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
|
cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
|
||||||
cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
|
cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
|
||||||
/* Check version.
|
/* Check version.
|
||||||
* Major version must be 1, anything else signals an incompatible change.
|
* Major version must be 1 or 2, anything else signals an incompatible
|
||||||
|
* change.
|
||||||
* (We used to treat this as an error, but now it's a nonfatal warning,
|
* (We used to treat this as an error, but now it's a nonfatal warning,
|
||||||
* because some bozo at Hijaak couldn't read the spec.)
|
* because some bozo at Hijaak couldn't read the spec.)
|
||||||
* Minor version should be 0..2, but process anyway if newer.
|
* Minor version should be 0..2, but process anyway if newer.
|
||||||
*/
|
*/
|
||||||
if (cinfo->JFIF_major_version != 1)
|
if (cinfo->JFIF_major_version != 1 && cinfo->JFIF_major_version != 2)
|
||||||
WARNMS2(cinfo, JWRN_JFIF_MAJOR,
|
WARNMS2(cinfo, JWRN_JFIF_MAJOR,
|
||||||
cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
|
cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
|
||||||
/* Generate trace messages */
|
/* Generate trace messages */
|
||||||
@@ -684,7 +783,6 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
|
|||||||
default:
|
default:
|
||||||
TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
|
TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
|
||||||
GETJOCTET(data[5]), (int) totallen);
|
GETJOCTET(data[5]), (int) totallen);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Start of APP0 does not match "JFIF" or "JFXX", or too short */
|
/* Start of APP0 does not match "JFIF" or "JFXX", or too short */
|
||||||
@@ -758,7 +856,6 @@ get_interesting_appn (j_decompress_ptr cinfo)
|
|||||||
default:
|
default:
|
||||||
/* can't get here unless jpeg_save_markers chooses wrong processor */
|
/* can't get here unless jpeg_save_markers chooses wrong processor */
|
||||||
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
|
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* skip any remaining data -- could be lots */
|
/* skip any remaining data -- could be lots */
|
||||||
@@ -864,7 +961,6 @@ save_marker (j_decompress_ptr cinfo)
|
|||||||
default:
|
default:
|
||||||
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
|
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
|
||||||
(int) (data_length + length));
|
(int) (data_length + length));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* skip any remaining data -- could be lots */
|
/* skip any remaining data -- could be lots */
|
||||||
@@ -1085,6 +1181,11 @@ read_markers (j_decompress_ptr cinfo)
|
|||||||
return JPEG_SUSPENDED;
|
return JPEG_SUSPENDED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case M_JPG8:
|
||||||
|
if (! get_lse(cinfo))
|
||||||
|
return JPEG_SUSPENDED;
|
||||||
|
break;
|
||||||
|
|
||||||
case M_APP0:
|
case M_APP0:
|
||||||
case M_APP1:
|
case M_APP1:
|
||||||
case M_APP2:
|
case M_APP2:
|
||||||
@@ -1135,7 +1236,6 @@ read_markers (j_decompress_ptr cinfo)
|
|||||||
* ought to change!
|
* ought to change!
|
||||||
*/
|
*/
|
||||||
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
|
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
/* Successfully processed marker, so reset state variable */
|
/* Successfully processed marker, so reset state variable */
|
||||||
cinfo->unread_marker = 0;
|
cinfo->unread_marker = 0;
|
||||||
@@ -1311,10 +1411,9 @@ jinit_marker_reader (j_decompress_ptr cinfo)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Create subobject in permanent pool */
|
/* Create subobject in permanent pool */
|
||||||
marker = (my_marker_ptr)
|
marker = (my_marker_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
((j_common_ptr) cinfo, JPOOL_PERMANENT, SIZEOF(my_marker_reader));
|
||||||
SIZEOF(my_marker_reader));
|
cinfo->marker = &marker->pub;
|
||||||
cinfo->marker = (struct jpeg_marker_reader *) marker;
|
|
||||||
/* Initialize public method pointers */
|
/* Initialize public method pointers */
|
||||||
marker->pub.reset_marker_reader = reset_marker_reader;
|
marker->pub.reset_marker_reader = reset_marker_reader;
|
||||||
marker->pub.read_markers = read_markers;
|
marker->pub.read_markers = read_markers;
|
||||||
|
|||||||
Vendored
+71
-72
@@ -2,7 +2,7 @@
|
|||||||
* jdmaster.c
|
* jdmaster.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
* Modified 2002-2009 by Guido Vollbeding.
|
* Modified 2002-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -45,13 +45,26 @@ LOCAL(boolean)
|
|||||||
use_merged_upsample (j_decompress_ptr cinfo)
|
use_merged_upsample (j_decompress_ptr cinfo)
|
||||||
{
|
{
|
||||||
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
||||||
/* Merging is the equivalent of plain box-filter upsampling */
|
/* Merging is the equivalent of plain box-filter upsampling. */
|
||||||
if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
|
/* The following condition is only needed if fancy shall select
|
||||||
|
* a different upsampling method. In our current implementation
|
||||||
|
* fancy only affects the DCT scaling, thus we can use fancy
|
||||||
|
* upsampling and merged upsample simultaneously, in particular
|
||||||
|
* with scaled DCT sizes larger than the default DCTSIZE.
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
|
if (cinfo->do_fancy_upsampling)
|
||||||
|
return FALSE;
|
||||||
|
#endif
|
||||||
|
if (cinfo->CCIR601_sampling)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* jdmerge.c only supports YCC=>RGB color conversion */
|
/* jdmerge.c only supports YCC=>RGB color conversion */
|
||||||
if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
|
if ((cinfo->jpeg_color_space != JCS_YCbCr &&
|
||||||
|
cinfo->jpeg_color_space != JCS_BG_YCC) ||
|
||||||
|
cinfo->num_components != 3 ||
|
||||||
cinfo->out_color_space != JCS_RGB ||
|
cinfo->out_color_space != JCS_RGB ||
|
||||||
cinfo->out_color_components != RGB_PIXELSIZE)
|
cinfo->out_color_components != RGB_PIXELSIZE ||
|
||||||
|
cinfo->color_transform)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* and it only handles 2h1v or 2h2v sampling ratios */
|
/* and it only handles 2h1v or 2h2v sampling ratios */
|
||||||
if (cinfo->comp_info[0].h_samp_factor != 2 ||
|
if (cinfo->comp_info[0].h_samp_factor != 2 ||
|
||||||
@@ -90,10 +103,8 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
|||||||
* This function is used for full decompression.
|
* This function is used for full decompression.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
#ifdef IDCT_SCALING_SUPPORTED
|
int ci, i;
|
||||||
int ci;
|
|
||||||
jpeg_component_info *compptr;
|
jpeg_component_info *compptr;
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Prevent application from calling me at wrong times */
|
/* Prevent application from calling me at wrong times */
|
||||||
if (cinfo->global_state != DSTATE_READY)
|
if (cinfo->global_state != DSTATE_READY)
|
||||||
@@ -112,18 +123,22 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
|||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
int ssize = 1;
|
int ssize = 1;
|
||||||
while (cinfo->min_DCT_h_scaled_size * ssize <=
|
if (! cinfo->raw_data_out)
|
||||||
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
|
while (cinfo->min_DCT_h_scaled_size * ssize <=
|
||||||
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
|
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
|
||||||
ssize = ssize * 2;
|
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) ==
|
||||||
}
|
0) {
|
||||||
|
ssize = ssize * 2;
|
||||||
|
}
|
||||||
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
|
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
|
||||||
ssize = 1;
|
ssize = 1;
|
||||||
while (cinfo->min_DCT_v_scaled_size * ssize <=
|
if (! cinfo->raw_data_out)
|
||||||
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
|
while (cinfo->min_DCT_v_scaled_size * ssize <=
|
||||||
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
|
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
|
||||||
ssize = ssize * 2;
|
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) ==
|
||||||
}
|
0) {
|
||||||
|
ssize = ssize * 2;
|
||||||
|
}
|
||||||
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
|
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
|
||||||
|
|
||||||
/* We don't support IDCT ratios larger than 2. */
|
/* We don't support IDCT ratios larger than 2. */
|
||||||
@@ -131,13 +146,10 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
|||||||
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
|
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
|
||||||
else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
|
else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
|
||||||
compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
|
compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
|
||||||
}
|
|
||||||
|
|
||||||
/* Recompute downsampled dimensions of components;
|
/* Recompute downsampled dimensions of components;
|
||||||
* application needs to know these if using raw downsampled data.
|
* application needs to know these if using raw downsampled data.
|
||||||
*/
|
*/
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
|
||||||
ci++, compptr++) {
|
|
||||||
/* Size in samples, after IDCT scaling */
|
/* Size in samples, after IDCT scaling */
|
||||||
compptr->downsampled_width = (JDIMENSION)
|
compptr->downsampled_width = (JDIMENSION)
|
||||||
jdiv_round_up((long) cinfo->image_width *
|
jdiv_round_up((long) cinfo->image_width *
|
||||||
@@ -152,26 +164,22 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
|||||||
#endif /* IDCT_SCALING_SUPPORTED */
|
#endif /* IDCT_SCALING_SUPPORTED */
|
||||||
|
|
||||||
/* Report number of components in selected colorspace. */
|
/* Report number of components in selected colorspace. */
|
||||||
/* Probably this should be in the color conversion module... */
|
/* This should correspond to the actual code in the color conversion module. */
|
||||||
switch (cinfo->out_color_space) {
|
switch (cinfo->out_color_space) {
|
||||||
case JCS_GRAYSCALE:
|
case JCS_GRAYSCALE:
|
||||||
cinfo->out_color_components = 1;
|
cinfo->out_color_components = 1;
|
||||||
break;
|
break;
|
||||||
case JCS_RGB:
|
case JCS_RGB:
|
||||||
#if RGB_PIXELSIZE != 3
|
case JCS_BG_RGB:
|
||||||
cinfo->out_color_components = RGB_PIXELSIZE;
|
cinfo->out_color_components = RGB_PIXELSIZE;
|
||||||
break;
|
break;
|
||||||
#endif /* else share code with YCbCr */
|
default: /* YCCK <=> CMYK conversion or same colorspace as in file */
|
||||||
case JCS_YCbCr:
|
i = 0;
|
||||||
cinfo->out_color_components = 3;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
break;
|
ci++, compptr++)
|
||||||
case JCS_CMYK:
|
if (compptr->component_needed)
|
||||||
case JCS_YCCK:
|
i++; /* count output color components */
|
||||||
cinfo->out_color_components = 4;
|
cinfo->out_color_components = i;
|
||||||
break;
|
|
||||||
default: /* else must be same colorspace as in file */
|
|
||||||
cinfo->out_color_components = cinfo->num_components;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
cinfo->output_components = (cinfo->quantize_colors ? 1 :
|
cinfo->output_components = (cinfo->quantize_colors ? 1 :
|
||||||
cinfo->out_color_components);
|
cinfo->out_color_components);
|
||||||
@@ -198,30 +206,20 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
|||||||
* These processes all use a common table prepared by the routine below.
|
* These processes all use a common table prepared by the routine below.
|
||||||
*
|
*
|
||||||
* For most steps we can mathematically guarantee that the initial value
|
* For most steps we can mathematically guarantee that the initial value
|
||||||
* of x is within MAXJSAMPLE+1 of the legal range, so a table running from
|
* of x is within 2*(MAXJSAMPLE+1) of the legal range, so a table running
|
||||||
* -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial
|
* from -2*(MAXJSAMPLE+1) to 3*MAXJSAMPLE+2 is sufficient. But for the
|
||||||
* limiting step (just after the IDCT), a wildly out-of-range value is
|
* initial limiting step (just after the IDCT), a wildly out-of-range value
|
||||||
* possible if the input data is corrupt. To avoid any chance of indexing
|
* is possible if the input data is corrupt. To avoid any chance of indexing
|
||||||
* off the end of memory and getting a bad-pointer trap, we perform the
|
* off the end of memory and getting a bad-pointer trap, we perform the
|
||||||
* post-IDCT limiting thus:
|
* post-IDCT limiting thus:
|
||||||
* x = range_limit[x & MASK];
|
* x = (sample_range_limit - SUBSET)[(x + CENTER) & MASK];
|
||||||
* where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
|
* where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
|
||||||
* samples. Under normal circumstances this is more than enough range and
|
* samples. Under normal circumstances this is more than enough range and
|
||||||
* a correct output will be generated; with bogus input data the mask will
|
* a correct output will be generated; with bogus input data the mask will
|
||||||
* cause wraparound, and we will safely generate a bogus-but-in-range output.
|
* cause wraparound, and we will safely generate a bogus-but-in-range output.
|
||||||
* For the post-IDCT step, we want to convert the data from signed to unsigned
|
* For the post-IDCT step, we want to convert the data from signed to unsigned
|
||||||
* representation by adding CENTERJSAMPLE at the same time that we limit it.
|
* representation by adding CENTERJSAMPLE at the same time that we limit it.
|
||||||
* So the post-IDCT limiting table ends up looking like this:
|
* This is accomplished with SUBSET = CENTER - CENTERJSAMPLE.
|
||||||
* CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE,
|
|
||||||
* MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
|
|
||||||
* 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
|
|
||||||
* 0,1,...,CENTERJSAMPLE-1
|
|
||||||
* Negative inputs select values from the upper half of the table after
|
|
||||||
* masking.
|
|
||||||
*
|
|
||||||
* We can save some space by overlapping the start of the post-IDCT table
|
|
||||||
* with the simpler range limiting table. The post-IDCT table begins at
|
|
||||||
* sample_range_limit + CENTERJSAMPLE.
|
|
||||||
*
|
*
|
||||||
* Note that the table is allocated in near data space on PCs; it's small
|
* Note that the table is allocated in near data space on PCs; it's small
|
||||||
* enough and used often enough to justify this.
|
* enough and used often enough to justify this.
|
||||||
@@ -234,25 +232,18 @@ prepare_range_limit_table (j_decompress_ptr cinfo)
|
|||||||
JSAMPLE * table;
|
JSAMPLE * table;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
table = (JSAMPLE *)
|
table = (JSAMPLE *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
JPOOL_IMAGE, (RANGE_CENTER * 2 + MAXJSAMPLE + 1) * SIZEOF(JSAMPLE));
|
||||||
(5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
|
/* First segment of range limit table: limit[x] = 0 for x < 0 */
|
||||||
table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
|
MEMZERO(table, RANGE_CENTER * SIZEOF(JSAMPLE));
|
||||||
|
table += RANGE_CENTER; /* allow negative subscripts of table */
|
||||||
cinfo->sample_range_limit = table;
|
cinfo->sample_range_limit = table;
|
||||||
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
|
/* Main part of range limit table: limit[x] = x */
|
||||||
MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
|
|
||||||
/* Main part of "simple" table: limit[x] = x */
|
|
||||||
for (i = 0; i <= MAXJSAMPLE; i++)
|
for (i = 0; i <= MAXJSAMPLE; i++)
|
||||||
table[i] = (JSAMPLE) i;
|
table[i] = (JSAMPLE) i;
|
||||||
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
|
/* End of range limit table: limit[x] = MAXJSAMPLE for x > MAXJSAMPLE */
|
||||||
/* End of simple table, rest of first half of post-IDCT table */
|
for (; i <= MAXJSAMPLE + RANGE_CENTER; i++)
|
||||||
for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
|
|
||||||
table[i] = MAXJSAMPLE;
|
table[i] = MAXJSAMPLE;
|
||||||
/* Second half of post-IDCT table */
|
|
||||||
MEMZERO(table + (2 * (MAXJSAMPLE+1)),
|
|
||||||
(2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
|
|
||||||
MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
|
|
||||||
cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -275,10 +266,19 @@ master_selection (j_decompress_ptr cinfo)
|
|||||||
long samplesperrow;
|
long samplesperrow;
|
||||||
JDIMENSION jd_samplesperrow;
|
JDIMENSION jd_samplesperrow;
|
||||||
|
|
||||||
|
/* For now, precision must match compiled-in value... */
|
||||||
|
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
||||||
|
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
||||||
|
|
||||||
/* Initialize dimensions and other stuff */
|
/* Initialize dimensions and other stuff */
|
||||||
jpeg_calc_output_dimensions(cinfo);
|
jpeg_calc_output_dimensions(cinfo);
|
||||||
prepare_range_limit_table(cinfo);
|
prepare_range_limit_table(cinfo);
|
||||||
|
|
||||||
|
/* Sanity check on image dimensions */
|
||||||
|
if (cinfo->output_height <= 0 || cinfo->output_width <= 0 ||
|
||||||
|
cinfo->out_color_components <= 0)
|
||||||
|
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
|
||||||
|
|
||||||
/* Width of an output scanline must be representable as JDIMENSION. */
|
/* Width of an output scanline must be representable as JDIMENSION. */
|
||||||
samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
|
samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
|
||||||
jd_samplesperrow = (JDIMENSION) samplesperrow;
|
jd_samplesperrow = (JDIMENSION) samplesperrow;
|
||||||
@@ -520,10 +520,9 @@ jinit_master_decompress (j_decompress_ptr cinfo)
|
|||||||
{
|
{
|
||||||
my_master_ptr master;
|
my_master_ptr master;
|
||||||
|
|
||||||
master = (my_master_ptr)
|
master = (my_master_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_decomp_master));
|
||||||
SIZEOF(my_decomp_master));
|
cinfo->master = &master->pub;
|
||||||
cinfo->master = (struct jpeg_decomp_master *) master;
|
|
||||||
master->pub.prepare_for_output_pass = prepare_for_output_pass;
|
master->pub.prepare_for_output_pass = prepare_for_output_pass;
|
||||||
master->pub.finish_output_pass = finish_output_pass;
|
master->pub.finish_output_pass = finish_output_pass;
|
||||||
|
|
||||||
|
|||||||
Vendored
+97
-59
@@ -2,6 +2,7 @@
|
|||||||
* jdmerge.c
|
* jdmerge.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
|
* Modified 2013-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -23,7 +24,7 @@
|
|||||||
* multiplications needed for color conversion.
|
* multiplications needed for color conversion.
|
||||||
*
|
*
|
||||||
* This file currently provides implementations for the following cases:
|
* This file currently provides implementations for the following cases:
|
||||||
* YCbCr => RGB color conversion only.
|
* YCC => RGB color conversion only (YCbCr or BG_YCC).
|
||||||
* Sampling ratios of 2h1v or 2h2v.
|
* Sampling ratios of 2h1v or 2h2v.
|
||||||
* No scaling needed at upsample time.
|
* No scaling needed at upsample time.
|
||||||
* Corner-aligned (non-CCIR601) sampling alignment.
|
* Corner-aligned (non-CCIR601) sampling alignment.
|
||||||
@@ -39,6 +40,12 @@
|
|||||||
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
||||||
|
|
||||||
|
|
||||||
|
#if RANGE_BITS < 2
|
||||||
|
/* Deliberate syntax err */
|
||||||
|
Sorry, this code requires 2 or more range extension bits.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Private subobject */
|
/* Private subobject */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -75,45 +82,74 @@ typedef my_upsampler * my_upsample_ptr;
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize tables for YCC->RGB colorspace conversion.
|
* Initialize tables for YCbCr->RGB and BG_YCC->RGB colorspace conversion.
|
||||||
* This is taken directly from jdcolor.c; see that file for more info.
|
* This is taken directly from jdcolor.c; see that file for more info.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LOCAL(void)
|
LOCAL(void)
|
||||||
build_ycc_rgb_table (j_decompress_ptr cinfo)
|
build_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||||
|
/* Normal case, sYCC */
|
||||||
{
|
{
|
||||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||||
int i;
|
int i;
|
||||||
INT32 x;
|
INT32 x;
|
||||||
SHIFT_TEMPS
|
SHIFT_TEMPS
|
||||||
|
|
||||||
upsample->Cr_r_tab = (int *)
|
upsample->Cr_r_tab = (int *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int));
|
||||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
upsample->Cb_b_tab = (int *) (*cinfo->mem->alloc_small)
|
||||||
upsample->Cb_b_tab = (int *)
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int));
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
upsample->Cr_g_tab = (INT32 *) (*cinfo->mem->alloc_small)
|
||||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||||
upsample->Cr_g_tab = (INT32 *)
|
upsample->Cb_g_tab = (INT32 *) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
|
||||||
upsample->Cb_g_tab = (INT32 *)
|
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
||||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
|
||||||
|
|
||||||
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
||||||
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
||||||
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
||||||
/* Cr=>R value is nearest int to 1.40200 * x */
|
/* Cr=>R value is nearest int to 1.402 * x */
|
||||||
upsample->Cr_r_tab[i] = (int)
|
upsample->Cr_r_tab[i] = (int) DESCALE(FIX(1.402) * x, SCALEBITS);
|
||||||
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
/* Cb=>B value is nearest int to 1.772 * x */
|
||||||
/* Cb=>B value is nearest int to 1.77200 * x */
|
upsample->Cb_b_tab[i] = (int) DESCALE(FIX(1.772) * x, SCALEBITS);
|
||||||
upsample->Cb_b_tab[i] = (int)
|
/* Cr=>G value is scaled-up -0.714136286 * x */
|
||||||
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
upsample->Cr_g_tab[i] = (- FIX(0.714136286)) * x;
|
||||||
/* Cr=>G value is scaled-up -0.71414 * x */
|
/* Cb=>G value is scaled-up -0.344136286 * x */
|
||||||
upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
|
|
||||||
/* Cb=>G value is scaled-up -0.34414 * x */
|
|
||||||
/* We also add in ONE_HALF so that need not do it in inner loop */
|
/* We also add in ONE_HALF so that need not do it in inner loop */
|
||||||
upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
|
upsample->Cb_g_tab[i] = (- FIX(0.344136286)) * x + ONE_HALF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LOCAL(void)
|
||||||
|
build_bg_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||||
|
/* Wide gamut case, bg-sYCC */
|
||||||
|
{
|
||||||
|
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||||
|
int i;
|
||||||
|
INT32 x;
|
||||||
|
SHIFT_TEMPS
|
||||||
|
|
||||||
|
upsample->Cr_r_tab = (int *) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int));
|
||||||
|
upsample->Cb_b_tab = (int *) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(int));
|
||||||
|
upsample->Cr_g_tab = (INT32 *) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||||
|
upsample->Cb_g_tab = (INT32 *) (*cinfo->mem->alloc_small)
|
||||||
|
((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||||
|
|
||||||
|
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
||||||
|
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
||||||
|
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
||||||
|
/* Cr=>R value is nearest int to 2.804 * x */
|
||||||
|
upsample->Cr_r_tab[i] = (int) DESCALE(FIX(2.804) * x, SCALEBITS);
|
||||||
|
/* Cb=>B value is nearest int to 3.544 * x */
|
||||||
|
upsample->Cb_b_tab[i] = (int) DESCALE(FIX(3.544) * x, SCALEBITS);
|
||||||
|
/* Cr=>G value is scaled-up -1.428272572 * x */
|
||||||
|
upsample->Cr_g_tab[i] = (- FIX(1.428272572)) * x;
|
||||||
|
/* Cb=>G value is scaled-up -0.688272572 * x */
|
||||||
|
/* We also add in ONE_HALF so that need not do it in inner loop */
|
||||||
|
upsample->Cb_g_tab[i] = (- FIX(0.688272572)) * x + ONE_HALF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +190,7 @@ merged_2v_upsample (j_decompress_ptr cinfo,
|
|||||||
|
|
||||||
if (upsample->spare_full) {
|
if (upsample->spare_full) {
|
||||||
/* If we have a spare row saved from a previous cycle, just return it. */
|
/* If we have a spare row saved from a previous cycle, just return it. */
|
||||||
jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
|
jcopy_sample_rows(& upsample->spare_row, output_buf + *out_row_ctr,
|
||||||
1, upsample->out_row_width);
|
1, upsample->out_row_width);
|
||||||
num_rows = 1;
|
num_rows = 1;
|
||||||
upsample->spare_full = FALSE;
|
upsample->spare_full = FALSE;
|
||||||
@@ -250,32 +286,32 @@ h2v1_merged_upsample (j_decompress_ptr cinfo,
|
|||||||
/* Do the chroma part of the calculation */
|
/* Do the chroma part of the calculation */
|
||||||
cb = GETJSAMPLE(*inptr1++);
|
cb = GETJSAMPLE(*inptr1++);
|
||||||
cr = GETJSAMPLE(*inptr2++);
|
cr = GETJSAMPLE(*inptr2++);
|
||||||
cred = Crrtab[cr];
|
cred = Crrtab[cr];
|
||||||
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
||||||
cblue = Cbbtab[cb];
|
cblue = Cbbtab[cb];
|
||||||
/* Fetch 2 Y values and emit 2 pixels */
|
/* Fetch 2 Y values and emit 2 pixels */
|
||||||
y = GETJSAMPLE(*inptr0++);
|
y = GETJSAMPLE(*inptr0++);
|
||||||
outptr[RGB_RED] = range_limit[y + cred];
|
outptr[RGB_RED] = range_limit[y + cred];
|
||||||
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
||||||
outptr[RGB_BLUE] = range_limit[y + cblue];
|
outptr[RGB_BLUE] = range_limit[y + cblue];
|
||||||
outptr += RGB_PIXELSIZE;
|
outptr += RGB_PIXELSIZE;
|
||||||
y = GETJSAMPLE(*inptr0++);
|
y = GETJSAMPLE(*inptr0++);
|
||||||
outptr[RGB_RED] = range_limit[y + cred];
|
outptr[RGB_RED] = range_limit[y + cred];
|
||||||
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
||||||
outptr[RGB_BLUE] = range_limit[y + cblue];
|
outptr[RGB_BLUE] = range_limit[y + cblue];
|
||||||
outptr += RGB_PIXELSIZE;
|
outptr += RGB_PIXELSIZE;
|
||||||
}
|
}
|
||||||
/* If image width is odd, do the last output column separately */
|
/* If image width is odd, do the last output column separately */
|
||||||
if (cinfo->output_width & 1) {
|
if (cinfo->output_width & 1) {
|
||||||
cb = GETJSAMPLE(*inptr1);
|
cb = GETJSAMPLE(*inptr1);
|
||||||
cr = GETJSAMPLE(*inptr2);
|
cr = GETJSAMPLE(*inptr2);
|
||||||
cred = Crrtab[cr];
|
cred = Crrtab[cr];
|
||||||
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
||||||
cblue = Cbbtab[cb];
|
cblue = Cbbtab[cb];
|
||||||
y = GETJSAMPLE(*inptr0);
|
y = GETJSAMPLE(*inptr0);
|
||||||
outptr[RGB_RED] = range_limit[y + cred];
|
outptr[RGB_RED] = range_limit[y + cred];
|
||||||
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
outptr[RGB_GREEN] = range_limit[y + cgreen];
|
||||||
outptr[RGB_BLUE] = range_limit[y + cblue];
|
outptr[RGB_BLUE] = range_limit[y + cblue];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,46 +350,46 @@ h2v2_merged_upsample (j_decompress_ptr cinfo,
|
|||||||
/* Do the chroma part of the calculation */
|
/* Do the chroma part of the calculation */
|
||||||
cb = GETJSAMPLE(*inptr1++);
|
cb = GETJSAMPLE(*inptr1++);
|
||||||
cr = GETJSAMPLE(*inptr2++);
|
cr = GETJSAMPLE(*inptr2++);
|
||||||
cred = Crrtab[cr];
|
cred = Crrtab[cr];
|
||||||
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
||||||
cblue = Cbbtab[cb];
|
cblue = Cbbtab[cb];
|
||||||
/* Fetch 4 Y values and emit 4 pixels */
|
/* Fetch 4 Y values and emit 4 pixels */
|
||||||
y = GETJSAMPLE(*inptr00++);
|
y = GETJSAMPLE(*inptr00++);
|
||||||
outptr0[RGB_RED] = range_limit[y + cred];
|
outptr0[RGB_RED] = range_limit[y + cred];
|
||||||
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
||||||
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
||||||
outptr0 += RGB_PIXELSIZE;
|
outptr0 += RGB_PIXELSIZE;
|
||||||
y = GETJSAMPLE(*inptr00++);
|
y = GETJSAMPLE(*inptr00++);
|
||||||
outptr0[RGB_RED] = range_limit[y + cred];
|
outptr0[RGB_RED] = range_limit[y + cred];
|
||||||
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
||||||
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
||||||
outptr0 += RGB_PIXELSIZE;
|
outptr0 += RGB_PIXELSIZE;
|
||||||
y = GETJSAMPLE(*inptr01++);
|
y = GETJSAMPLE(*inptr01++);
|
||||||
outptr1[RGB_RED] = range_limit[y + cred];
|
outptr1[RGB_RED] = range_limit[y + cred];
|
||||||
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
||||||
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
||||||
outptr1 += RGB_PIXELSIZE;
|
outptr1 += RGB_PIXELSIZE;
|
||||||
y = GETJSAMPLE(*inptr01++);
|
y = GETJSAMPLE(*inptr01++);
|
||||||
outptr1[RGB_RED] = range_limit[y + cred];
|
outptr1[RGB_RED] = range_limit[y + cred];
|
||||||
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
||||||
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
||||||
outptr1 += RGB_PIXELSIZE;
|
outptr1 += RGB_PIXELSIZE;
|
||||||
}
|
}
|
||||||
/* If image width is odd, do the last output column separately */
|
/* If image width is odd, do the last output column separately */
|
||||||
if (cinfo->output_width & 1) {
|
if (cinfo->output_width & 1) {
|
||||||
cb = GETJSAMPLE(*inptr1);
|
cb = GETJSAMPLE(*inptr1);
|
||||||
cr = GETJSAMPLE(*inptr2);
|
cr = GETJSAMPLE(*inptr2);
|
||||||
cred = Crrtab[cr];
|
cred = Crrtab[cr];
|
||||||
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
||||||
cblue = Cbbtab[cb];
|
cblue = Cbbtab[cb];
|
||||||
y = GETJSAMPLE(*inptr00);
|
y = GETJSAMPLE(*inptr00);
|
||||||
outptr0[RGB_RED] = range_limit[y + cred];
|
outptr0[RGB_RED] = range_limit[y + cred];
|
||||||
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
||||||
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
outptr0[RGB_BLUE] = range_limit[y + cblue];
|
||||||
y = GETJSAMPLE(*inptr01);
|
y = GETJSAMPLE(*inptr01);
|
||||||
outptr1[RGB_RED] = range_limit[y + cred];
|
outptr1[RGB_RED] = range_limit[y + cred];
|
||||||
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
||||||
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
outptr1[RGB_BLUE] = range_limit[y + cblue];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,10 +407,9 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
|
|||||||
{
|
{
|
||||||
my_upsample_ptr upsample;
|
my_upsample_ptr upsample;
|
||||||
|
|
||||||
upsample = (my_upsample_ptr)
|
upsample = (my_upsample_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_upsampler));
|
||||||
SIZEOF(my_upsampler));
|
cinfo->upsample = &upsample->pub;
|
||||||
cinfo->upsample = (struct jpeg_upsampler *) upsample;
|
|
||||||
upsample->pub.start_pass = start_pass_merged_upsample;
|
upsample->pub.start_pass = start_pass_merged_upsample;
|
||||||
upsample->pub.need_context_rows = FALSE;
|
upsample->pub.need_context_rows = FALSE;
|
||||||
|
|
||||||
@@ -384,9 +419,9 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
|
|||||||
upsample->pub.upsample = merged_2v_upsample;
|
upsample->pub.upsample = merged_2v_upsample;
|
||||||
upsample->upmethod = h2v2_merged_upsample;
|
upsample->upmethod = h2v2_merged_upsample;
|
||||||
/* Allocate a spare row buffer */
|
/* Allocate a spare row buffer */
|
||||||
upsample->spare_row = (JSAMPROW)
|
upsample->spare_row = (JSAMPROW) (*cinfo->mem->alloc_large)
|
||||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
(size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
|
(size_t) upsample->out_row_width * SIZEOF(JSAMPLE));
|
||||||
} else {
|
} else {
|
||||||
upsample->pub.upsample = merged_1v_upsample;
|
upsample->pub.upsample = merged_1v_upsample;
|
||||||
upsample->upmethod = h2v1_merged_upsample;
|
upsample->upmethod = h2v1_merged_upsample;
|
||||||
@@ -394,7 +429,10 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
|
|||||||
upsample->spare_row = NULL;
|
upsample->spare_row = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
build_ycc_rgb_table(cinfo);
|
if (cinfo->jpeg_color_space == JCS_BG_YCC)
|
||||||
|
build_bg_ycc_rgb_table(cinfo);
|
||||||
|
else
|
||||||
|
build_ycc_rgb_table(cinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* UPSAMPLE_MERGING_SUPPORTED */
|
#endif /* UPSAMPLE_MERGING_SUPPORTED */
|
||||||
|
|||||||
Vendored
+39
-59
@@ -2,7 +2,7 @@
|
|||||||
* jdsample.c
|
* jdsample.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||||
* Modified 2002-2008 by Guido Vollbeding.
|
* Modified 2002-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
/* Pointer to routine to upsample a single component */
|
/* Pointer to routine to upsample a single component */
|
||||||
typedef JMETHOD(void, upsample1_ptr,
|
typedef JMETHOD(void, upsample1_ptr,
|
||||||
(j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
(j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
|
JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr));
|
||||||
|
|
||||||
/* Private subobject */
|
/* Private subobject */
|
||||||
|
|
||||||
@@ -102,6 +102,9 @@ sep_upsample (j_decompress_ptr cinfo,
|
|||||||
if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
|
if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
|
/* Don't bother to upsample an uninteresting component. */
|
||||||
|
if (! compptr->component_needed)
|
||||||
|
continue;
|
||||||
/* Invoke per-component upsample method. Notice we pass a POINTER
|
/* Invoke per-component upsample method. Notice we pass a POINTER
|
||||||
* to color_buf[ci], so that fullsize_upsample can change it.
|
* to color_buf[ci], so that fullsize_upsample can change it.
|
||||||
*/
|
*/
|
||||||
@@ -156,25 +159,12 @@ sep_upsample (j_decompress_ptr cinfo,
|
|||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr)
|
||||||
{
|
{
|
||||||
*output_data_ptr = input_data;
|
*output_data_ptr = input_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This is a no-op version used for "uninteresting" components.
|
|
||||||
* These components will not be referenced by color conversion.
|
|
||||||
*/
|
|
||||||
|
|
||||||
METHODDEF(void)
|
|
||||||
noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|
||||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
|
||||||
{
|
|
||||||
*output_data_ptr = NULL; /* safety check */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This version handles any integral sampling ratios.
|
* This version handles any integral sampling ratios.
|
||||||
* This is not used for typical JPEG files, so it need not be fast.
|
* This is not used for typical JPEG files, so it need not be fast.
|
||||||
@@ -188,25 +178,25 @@ noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr)
|
||||||
{
|
{
|
||||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||||
JSAMPARRAY output_data = *output_data_ptr;
|
JSAMPARRAY output_data, output_end;
|
||||||
register JSAMPROW inptr, outptr;
|
register JSAMPROW inptr, outptr;
|
||||||
register JSAMPLE invalue;
|
register JSAMPLE invalue;
|
||||||
register int h;
|
register int h;
|
||||||
JSAMPROW outend;
|
JSAMPROW outend;
|
||||||
int h_expand, v_expand;
|
int h_expand, v_expand;
|
||||||
int inrow, outrow;
|
|
||||||
|
|
||||||
h_expand = upsample->h_expand[compptr->component_index];
|
h_expand = upsample->h_expand[compptr->component_index];
|
||||||
v_expand = upsample->v_expand[compptr->component_index];
|
v_expand = upsample->v_expand[compptr->component_index];
|
||||||
|
|
||||||
inrow = outrow = 0;
|
output_data = *output_data_ptr;
|
||||||
while (outrow < cinfo->max_v_samp_factor) {
|
output_end = output_data + cinfo->max_v_samp_factor;
|
||||||
|
for (; output_data < output_end; output_data += v_expand) {
|
||||||
/* Generate one output row with proper horizontal expansion */
|
/* Generate one output row with proper horizontal expansion */
|
||||||
inptr = input_data[inrow];
|
inptr = *input_data++;
|
||||||
outptr = output_data[outrow];
|
outptr = *output_data;
|
||||||
outend = outptr + cinfo->output_width;
|
outend = outptr + cinfo->output_width;
|
||||||
while (outptr < outend) {
|
while (outptr < outend) {
|
||||||
invalue = *inptr++; /* don't need GETJSAMPLE() here */
|
invalue = *inptr++; /* don't need GETJSAMPLE() here */
|
||||||
@@ -216,11 +206,9 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
}
|
}
|
||||||
/* Generate any additional output rows by duplicating the first one */
|
/* Generate any additional output rows by duplicating the first one */
|
||||||
if (v_expand > 1) {
|
if (v_expand > 1) {
|
||||||
jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
|
jcopy_sample_rows(output_data, output_data + 1,
|
||||||
v_expand-1, cinfo->output_width);
|
v_expand - 1, cinfo->output_width);
|
||||||
}
|
}
|
||||||
inrow++;
|
|
||||||
outrow += v_expand;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +220,7 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr)
|
||||||
{
|
{
|
||||||
JSAMPARRAY output_data = *output_data_ptr;
|
JSAMPARRAY output_data = *output_data_ptr;
|
||||||
register JSAMPROW inptr, outptr;
|
register JSAMPROW inptr, outptr;
|
||||||
@@ -260,28 +248,26 @@ h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(void)
|
||||||
h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
JSAMPARRAY input_data, JSAMPIMAGE output_data_ptr)
|
||||||
{
|
{
|
||||||
JSAMPARRAY output_data = *output_data_ptr;
|
JSAMPARRAY output_data, output_end;
|
||||||
register JSAMPROW inptr, outptr;
|
register JSAMPROW inptr, outptr;
|
||||||
register JSAMPLE invalue;
|
register JSAMPLE invalue;
|
||||||
JSAMPROW outend;
|
JSAMPROW outend;
|
||||||
int inrow, outrow;
|
|
||||||
|
|
||||||
inrow = outrow = 0;
|
output_data = *output_data_ptr;
|
||||||
while (outrow < cinfo->max_v_samp_factor) {
|
output_end = output_data + cinfo->max_v_samp_factor;
|
||||||
inptr = input_data[inrow];
|
for (; output_data < output_end; output_data += 2) {
|
||||||
outptr = output_data[outrow];
|
inptr = *input_data++;
|
||||||
|
outptr = *output_data;
|
||||||
outend = outptr + cinfo->output_width;
|
outend = outptr + cinfo->output_width;
|
||||||
while (outptr < outend) {
|
while (outptr < outend) {
|
||||||
invalue = *inptr++; /* don't need GETJSAMPLE() here */
|
invalue = *inptr++; /* don't need GETJSAMPLE() here */
|
||||||
*outptr++ = invalue;
|
*outptr++ = invalue;
|
||||||
*outptr++ = invalue;
|
*outptr++ = invalue;
|
||||||
}
|
}
|
||||||
jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
|
jcopy_sample_rows(output_data, output_data + 1,
|
||||||
1, cinfo->output_width);
|
1, cinfo->output_width);
|
||||||
inrow++;
|
|
||||||
outrow += 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,13 +282,11 @@ jinit_upsampler (j_decompress_ptr cinfo)
|
|||||||
my_upsample_ptr upsample;
|
my_upsample_ptr upsample;
|
||||||
int ci;
|
int ci;
|
||||||
jpeg_component_info * compptr;
|
jpeg_component_info * compptr;
|
||||||
boolean need_buffer;
|
|
||||||
int h_in_group, v_in_group, h_out_group, v_out_group;
|
int h_in_group, v_in_group, h_out_group, v_out_group;
|
||||||
|
|
||||||
upsample = (my_upsample_ptr)
|
upsample = (my_upsample_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_upsampler));
|
||||||
SIZEOF(my_upsampler));
|
cinfo->upsample = &upsample->pub;
|
||||||
cinfo->upsample = (struct jpeg_upsampler *) upsample;
|
|
||||||
upsample->pub.start_pass = start_pass_upsample;
|
upsample->pub.start_pass = start_pass_upsample;
|
||||||
upsample->pub.upsample = sep_upsample;
|
upsample->pub.upsample = sep_upsample;
|
||||||
upsample->pub.need_context_rows = FALSE; /* until we find out differently */
|
upsample->pub.need_context_rows = FALSE; /* until we find out differently */
|
||||||
@@ -315,6 +299,9 @@ jinit_upsampler (j_decompress_ptr cinfo)
|
|||||||
*/
|
*/
|
||||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||||
ci++, compptr++) {
|
ci++, compptr++) {
|
||||||
|
/* Don't bother to upsample an uninteresting component. */
|
||||||
|
if (! compptr->component_needed)
|
||||||
|
continue;
|
||||||
/* Compute size of an "input group" after IDCT scaling. This many samples
|
/* Compute size of an "input group" after IDCT scaling. This many samples
|
||||||
* are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
|
* are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
|
||||||
*/
|
*/
|
||||||
@@ -325,17 +312,12 @@ jinit_upsampler (j_decompress_ptr cinfo)
|
|||||||
h_out_group = cinfo->max_h_samp_factor;
|
h_out_group = cinfo->max_h_samp_factor;
|
||||||
v_out_group = cinfo->max_v_samp_factor;
|
v_out_group = cinfo->max_v_samp_factor;
|
||||||
upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
|
upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
|
||||||
need_buffer = TRUE;
|
if (h_in_group == h_out_group && v_in_group == v_out_group) {
|
||||||
if (! compptr->component_needed) {
|
|
||||||
/* Don't bother to upsample an uninteresting component. */
|
|
||||||
upsample->methods[ci] = noop_upsample;
|
|
||||||
need_buffer = FALSE;
|
|
||||||
} else if (h_in_group == h_out_group && v_in_group == v_out_group) {
|
|
||||||
/* Fullsize components can be processed without any work. */
|
/* Fullsize components can be processed without any work. */
|
||||||
upsample->methods[ci] = fullsize_upsample;
|
upsample->methods[ci] = fullsize_upsample;
|
||||||
need_buffer = FALSE;
|
continue; /* don't need to allocate buffer */
|
||||||
} else if (h_in_group * 2 == h_out_group &&
|
}
|
||||||
v_in_group == v_out_group) {
|
if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
|
||||||
/* Special case for 2h1v upsampling */
|
/* Special case for 2h1v upsampling */
|
||||||
upsample->methods[ci] = h2v1_upsample;
|
upsample->methods[ci] = h2v1_upsample;
|
||||||
} else if (h_in_group * 2 == h_out_group &&
|
} else if (h_in_group * 2 == h_out_group &&
|
||||||
@@ -350,12 +332,10 @@ jinit_upsampler (j_decompress_ptr cinfo)
|
|||||||
upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
|
upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
|
||||||
} else
|
} else
|
||||||
ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
|
ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
|
||||||
if (need_buffer) {
|
upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
|
||||||
upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
(JDIMENSION) jround_up((long) cinfo->output_width,
|
||||||
(JDIMENSION) jround_up((long) cinfo->output_width,
|
(long) cinfo->max_h_samp_factor),
|
||||||
(long) cinfo->max_h_samp_factor),
|
(JDIMENSION) cinfo->max_v_samp_factor);
|
||||||
(JDIMENSION) cinfo->max_v_samp_factor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+6
-5
@@ -2,6 +2,7 @@
|
|||||||
* jerror.c
|
* jerror.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||||
|
* Modified 2012-2015 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -18,16 +19,16 @@
|
|||||||
* These routines are used by both the compression and decompression code.
|
* These routines are used by both the compression and decompression code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef USE_WINDOWS_MESSAGEBOX
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
|
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
|
||||||
#include "jinclude.h"
|
#include "jinclude.h"
|
||||||
#include "jpeglib.h"
|
#include "jpeglib.h"
|
||||||
#include "jversion.h"
|
#include "jversion.h"
|
||||||
#include "jerror.h"
|
#include "jerror.h"
|
||||||
|
|
||||||
#ifdef USE_WINDOWS_MESSAGEBOX
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef EXIT_FAILURE /* define exit() codes if not provided */
|
#ifndef EXIT_FAILURE /* define exit() codes if not provided */
|
||||||
#define EXIT_FAILURE 1
|
#define EXIT_FAILURE 1
|
||||||
#endif
|
#endif
|
||||||
@@ -66,7 +67,7 @@ const char * const jpeg_std_message_table[] = {
|
|||||||
* or jpeg_destroy) at some point.
|
* or jpeg_destroy) at some point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
METHODDEF(void)
|
METHODDEF(noreturn_t)
|
||||||
error_exit (j_common_ptr cinfo)
|
error_exit (j_common_ptr cinfo)
|
||||||
{
|
{
|
||||||
/* Always display the message */
|
/* Always display the message */
|
||||||
|
|||||||
Vendored
+3
-3
@@ -2,7 +2,7 @@
|
|||||||
* jerror.h
|
* jerror.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||||
* Modified 1997-2009 by Guido Vollbeding.
|
* Modified 1997-2018 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -84,7 +84,7 @@ JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
|
|||||||
JMESSAGE(JERR_FILE_READ, "Input file read error")
|
JMESSAGE(JERR_FILE_READ, "Input file read error")
|
||||||
JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
|
JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
|
||||||
JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
|
JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
|
||||||
JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
|
JMESSAGE(JERR_HUFF_CLEN_OUTOFBOUNDS, "Huffman code size table out of bounds")
|
||||||
JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
|
JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
|
||||||
JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
|
JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
|
||||||
JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
|
JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
|
||||||
@@ -106,11 +106,11 @@ JMESSAGE(JERR_QUANT_COMPONENTS,
|
|||||||
"Cannot quantize more than %d color components")
|
"Cannot quantize more than %d color components")
|
||||||
JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
|
JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
|
||||||
JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
|
JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
|
||||||
|
JMESSAGE(JERR_SOF_BEFORE, "Invalid JPEG file structure: %s before SOF")
|
||||||
JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
|
JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
|
||||||
JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
|
JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
|
||||||
JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
|
JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
|
||||||
JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
|
JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
|
||||||
JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
|
|
||||||
JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
|
JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
|
||||||
JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
|
JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
|
||||||
JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
|
JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
|
||||||
|
|||||||
Vendored
+5
-3
@@ -2,7 +2,7 @@
|
|||||||
* jfdctflt.c
|
* jfdctflt.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
* Modified 2003-2009 by Guido Vollbeding.
|
* Modified 2003-2017 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -48,12 +48,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if DCTSIZE != 8
|
#if DCTSIZE != 8
|
||||||
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
|
Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform the forward DCT on one block of samples.
|
* Perform the forward DCT on one block of samples.
|
||||||
|
*
|
||||||
|
* cK represents cos(K*pi/16).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
@@ -89,7 +91,7 @@ jpeg_fdct_float (FAST_FLOAT * data, JSAMPARRAY sample_data, JDIMENSION start_col
|
|||||||
tmp11 = tmp1 + tmp2;
|
tmp11 = tmp1 + tmp2;
|
||||||
tmp12 = tmp1 - tmp2;
|
tmp12 = tmp1 - tmp2;
|
||||||
|
|
||||||
/* Apply unsigned->signed conversion */
|
/* Apply unsigned->signed conversion. */
|
||||||
dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */
|
dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */
|
||||||
dataptr[4] = tmp10 - tmp11;
|
dataptr[4] = tmp10 - tmp11;
|
||||||
|
|
||||||
|
|||||||
Vendored
+5
-3
@@ -2,7 +2,7 @@
|
|||||||
* jfdctfst.c
|
* jfdctfst.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||||
* Modified 2003-2009 by Guido Vollbeding.
|
* Modified 2003-2017 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if DCTSIZE != 8
|
#if DCTSIZE != 8
|
||||||
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
|
Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -109,6 +109,8 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform the forward DCT on one block of samples.
|
* Perform the forward DCT on one block of samples.
|
||||||
|
*
|
||||||
|
* cK represents cos(K*pi/16).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
@@ -145,7 +147,7 @@ jpeg_fdct_ifast (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
|
|||||||
tmp11 = tmp1 + tmp2;
|
tmp11 = tmp1 + tmp2;
|
||||||
tmp12 = tmp1 - tmp2;
|
tmp12 = tmp1 - tmp2;
|
||||||
|
|
||||||
/* Apply unsigned->signed conversion */
|
/* Apply unsigned->signed conversion. */
|
||||||
dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */
|
dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */
|
||||||
dataptr[4] = tmp10 - tmp11;
|
dataptr[4] = tmp10 - tmp11;
|
||||||
|
|
||||||
|
|||||||
Vendored
+452
-385
File diff suppressed because it is too large
Load Diff
Vendored
+20
-17
@@ -2,7 +2,7 @@
|
|||||||
* jidctflt.c
|
* jidctflt.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||||
* Modified 2010 by Guido Vollbeding.
|
* Modified 2010-2017 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if DCTSIZE != 8
|
#if DCTSIZE != 8
|
||||||
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
|
Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -63,6 +63,8 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform dequantization and inverse DCT on one block of coefficients.
|
* Perform dequantization and inverse DCT on one block of coefficients.
|
||||||
|
*
|
||||||
|
* cK represents cos(K*pi/16).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
@@ -77,7 +79,7 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
FLOAT_MULT_TYPE * quantptr;
|
FLOAT_MULT_TYPE * quantptr;
|
||||||
FAST_FLOAT * wsptr;
|
FAST_FLOAT * wsptr;
|
||||||
JSAMPROW outptr;
|
JSAMPROW outptr;
|
||||||
JSAMPLE *range_limit = cinfo->sample_range_limit;
|
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||||
int ctr;
|
int ctr;
|
||||||
FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
|
FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
|
||||||
|
|
||||||
@@ -186,13 +188,14 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
|
|
||||||
/* Even part */
|
/* Even part */
|
||||||
|
|
||||||
/* Apply signed->unsigned and prepare float->int conversion */
|
/* Prepare range-limit and float->int conversion */
|
||||||
z5 = wsptr[0] + ((FAST_FLOAT) CENTERJSAMPLE + (FAST_FLOAT) 0.5);
|
z5 = wsptr[0] + (((FAST_FLOAT) RANGE_CENTER) + ((FAST_FLOAT) 0.5));
|
||||||
tmp10 = z5 + wsptr[4];
|
tmp10 = z5 + wsptr[4];
|
||||||
tmp11 = z5 - wsptr[4];
|
tmp11 = z5 - wsptr[4];
|
||||||
|
|
||||||
tmp13 = wsptr[2] + wsptr[6];
|
tmp13 = wsptr[2] + wsptr[6];
|
||||||
tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
|
tmp12 = (wsptr[2] - wsptr[6]) *
|
||||||
|
((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
|
||||||
|
|
||||||
tmp0 = tmp10 + tmp13;
|
tmp0 = tmp10 + tmp13;
|
||||||
tmp3 = tmp10 - tmp13;
|
tmp3 = tmp10 - tmp13;
|
||||||
@@ -206,27 +209,27 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
z11 = wsptr[1] + wsptr[7];
|
z11 = wsptr[1] + wsptr[7];
|
||||||
z12 = wsptr[1] - wsptr[7];
|
z12 = wsptr[1] - wsptr[7];
|
||||||
|
|
||||||
tmp7 = z11 + z13;
|
tmp7 = z11 + z13; /* phase 5 */
|
||||||
tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
|
tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
|
||||||
|
|
||||||
z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
|
z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
|
||||||
tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */
|
tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */
|
||||||
tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */
|
tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */
|
||||||
|
|
||||||
tmp6 = tmp12 - tmp7;
|
tmp6 = tmp12 - tmp7; /* phase 2 */
|
||||||
tmp5 = tmp11 - tmp6;
|
tmp5 = tmp11 - tmp6;
|
||||||
tmp4 = tmp10 - tmp5;
|
tmp4 = tmp10 - tmp5;
|
||||||
|
|
||||||
/* Final output stage: float->int conversion and range-limit */
|
/* Final output stage: float->int conversion and range-limit */
|
||||||
|
|
||||||
outptr[0] = range_limit[((int) (tmp0 + tmp7)) & RANGE_MASK];
|
outptr[0] = range_limit[(int) (tmp0 + tmp7) & RANGE_MASK];
|
||||||
outptr[7] = range_limit[((int) (tmp0 - tmp7)) & RANGE_MASK];
|
outptr[7] = range_limit[(int) (tmp0 - tmp7) & RANGE_MASK];
|
||||||
outptr[1] = range_limit[((int) (tmp1 + tmp6)) & RANGE_MASK];
|
outptr[1] = range_limit[(int) (tmp1 + tmp6) & RANGE_MASK];
|
||||||
outptr[6] = range_limit[((int) (tmp1 - tmp6)) & RANGE_MASK];
|
outptr[6] = range_limit[(int) (tmp1 - tmp6) & RANGE_MASK];
|
||||||
outptr[2] = range_limit[((int) (tmp2 + tmp5)) & RANGE_MASK];
|
outptr[2] = range_limit[(int) (tmp2 + tmp5) & RANGE_MASK];
|
||||||
outptr[5] = range_limit[((int) (tmp2 - tmp5)) & RANGE_MASK];
|
outptr[5] = range_limit[(int) (tmp2 - tmp5) & RANGE_MASK];
|
||||||
outptr[3] = range_limit[((int) (tmp3 + tmp4)) & RANGE_MASK];
|
outptr[3] = range_limit[(int) (tmp3 + tmp4) & RANGE_MASK];
|
||||||
outptr[4] = range_limit[((int) (tmp3 - tmp4)) & RANGE_MASK];
|
outptr[4] = range_limit[(int) (tmp3 - tmp4) & RANGE_MASK];
|
||||||
|
|
||||||
wsptr += DCTSIZE; /* advance pointer to next row */
|
wsptr += DCTSIZE; /* advance pointer to next row */
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+37
-54
@@ -2,6 +2,7 @@
|
|||||||
* jidctfst.c
|
* jidctfst.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||||
|
* Modified 2015-2017 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -45,7 +46,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if DCTSIZE != 8
|
#if DCTSIZE != 8
|
||||||
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
|
Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -133,35 +134,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Like DESCALE, but applies to a DCTELEM and produces an int.
|
|
||||||
* We assume that int right shift is unsigned if INT32 right shift is.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef RIGHT_SHIFT_IS_UNSIGNED
|
|
||||||
#define ISHIFT_TEMPS DCTELEM ishift_temp;
|
|
||||||
#if BITS_IN_JSAMPLE == 8
|
|
||||||
#define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
|
|
||||||
#else
|
|
||||||
#define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
|
|
||||||
#endif
|
|
||||||
#define IRIGHT_SHIFT(x,shft) \
|
|
||||||
((ishift_temp = (x)) < 0 ? \
|
|
||||||
(ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
|
|
||||||
(ishift_temp >> (shft)))
|
|
||||||
#else
|
|
||||||
#define ISHIFT_TEMPS
|
|
||||||
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_ACCURATE_ROUNDING
|
|
||||||
#define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
|
|
||||||
#else
|
|
||||||
#define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform dequantization and inverse DCT on one block of coefficients.
|
* Perform dequantization and inverse DCT on one block of coefficients.
|
||||||
|
*
|
||||||
|
* cK represents cos(K*pi/16).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
@@ -180,7 +156,7 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
int ctr;
|
int ctr;
|
||||||
int workspace[DCTSIZE2]; /* buffers data between passes */
|
int workspace[DCTSIZE2]; /* buffers data between passes */
|
||||||
SHIFT_TEMPS /* for DESCALE */
|
SHIFT_TEMPS /* for DESCALE */
|
||||||
ISHIFT_TEMPS /* for IDESCALE */
|
ISHIFT_TEMPS /* for IRIGHT_SHIFT */
|
||||||
|
|
||||||
/* Pass 1: process columns from input, store into work array. */
|
/* Pass 1: process columns from input, store into work array. */
|
||||||
|
|
||||||
@@ -253,12 +229,12 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
|
tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
|
||||||
|
|
||||||
z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
|
z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
|
||||||
tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
|
tmp10 = z5 - MULTIPLY(z12, FIX_1_082392200); /* 2*(c2-c6) */
|
||||||
tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
|
tmp12 = z5 - MULTIPLY(z10, FIX_2_613125930); /* 2*(c2+c6) */
|
||||||
|
|
||||||
tmp6 = tmp12 - tmp7; /* phase 2 */
|
tmp6 = tmp12 - tmp7; /* phase 2 */
|
||||||
tmp5 = tmp11 - tmp6;
|
tmp5 = tmp11 - tmp6;
|
||||||
tmp4 = tmp10 + tmp5;
|
tmp4 = tmp10 - tmp5;
|
||||||
|
|
||||||
wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
|
wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
|
||||||
wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
|
wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
|
||||||
@@ -266,21 +242,28 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
|
wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
|
||||||
wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
|
wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
|
||||||
wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
|
wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
|
||||||
wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
|
wsptr[DCTSIZE*3] = (int) (tmp3 + tmp4);
|
||||||
wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
|
wsptr[DCTSIZE*4] = (int) (tmp3 - tmp4);
|
||||||
|
|
||||||
inptr++; /* advance pointers to next column */
|
inptr++; /* advance pointers to next column */
|
||||||
quantptr++;
|
quantptr++;
|
||||||
wsptr++;
|
wsptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pass 2: process rows from work array, store into output array. */
|
/* Pass 2: process rows from work array, store into output array.
|
||||||
/* Note that we must descale the results by a factor of 8 == 2**3, */
|
* Note that we must descale the results by a factor of 8 == 2**3,
|
||||||
/* and also undo the PASS1_BITS scaling. */
|
* and also undo the PASS1_BITS scaling.
|
||||||
|
*/
|
||||||
|
|
||||||
wsptr = workspace;
|
wsptr = workspace;
|
||||||
for (ctr = 0; ctr < DCTSIZE; ctr++) {
|
for (ctr = 0; ctr < DCTSIZE; ctr++) {
|
||||||
outptr = output_buf[ctr] + output_col;
|
outptr = output_buf[ctr] + output_col;
|
||||||
|
|
||||||
|
/* Add range center and fudge factor for final descale and range-limit. */
|
||||||
|
z5 = (DCTELEM) wsptr[0] +
|
||||||
|
((((DCTELEM) RANGE_CENTER) << (PASS1_BITS+3)) +
|
||||||
|
(1 << (PASS1_BITS+2)));
|
||||||
|
|
||||||
/* Rows of zeroes can be exploited in the same way as we did with columns.
|
/* Rows of zeroes can be exploited in the same way as we did with columns.
|
||||||
* However, the column calculation has created many nonzero AC terms, so
|
* However, the column calculation has created many nonzero AC terms, so
|
||||||
* the simplification applies less often (typically 5% to 10% of the time).
|
* the simplification applies less often (typically 5% to 10% of the time).
|
||||||
@@ -293,7 +276,7 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
|
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
|
||||||
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
|
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
|
||||||
/* AC terms all zero */
|
/* AC terms all zero */
|
||||||
JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
|
JSAMPLE dcval = range_limit[(int) IRIGHT_SHIFT(z5, PASS1_BITS+3)
|
||||||
& RANGE_MASK];
|
& RANGE_MASK];
|
||||||
|
|
||||||
outptr[0] = dcval;
|
outptr[0] = dcval;
|
||||||
@@ -312,12 +295,12 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
|
|
||||||
/* Even part */
|
/* Even part */
|
||||||
|
|
||||||
tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
|
tmp10 = z5 + (DCTELEM) wsptr[4];
|
||||||
tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
|
tmp11 = z5 - (DCTELEM) wsptr[4];
|
||||||
|
|
||||||
tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
|
tmp13 = (DCTELEM) wsptr[2] + (DCTELEM) wsptr[6];
|
||||||
tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
|
tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6],
|
||||||
- tmp13;
|
FIX_1_414213562) - tmp13; /* 2*c4 */
|
||||||
|
|
||||||
tmp0 = tmp10 + tmp13;
|
tmp0 = tmp10 + tmp13;
|
||||||
tmp3 = tmp10 - tmp13;
|
tmp3 = tmp10 - tmp13;
|
||||||
@@ -335,30 +318,30 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
|||||||
tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
|
tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
|
||||||
|
|
||||||
z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
|
z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
|
||||||
tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
|
tmp10 = z5 - MULTIPLY(z12, FIX_1_082392200); /* 2*(c2-c6) */
|
||||||
tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
|
tmp12 = z5 - MULTIPLY(z10, FIX_2_613125930); /* 2*(c2+c6) */
|
||||||
|
|
||||||
tmp6 = tmp12 - tmp7; /* phase 2 */
|
tmp6 = tmp12 - tmp7; /* phase 2 */
|
||||||
tmp5 = tmp11 - tmp6;
|
tmp5 = tmp11 - tmp6;
|
||||||
tmp4 = tmp10 + tmp5;
|
tmp4 = tmp10 - tmp5;
|
||||||
|
|
||||||
/* Final output stage: scale down by a factor of 8 and range-limit */
|
/* Final output stage: scale down by a factor of 8 and range-limit */
|
||||||
|
|
||||||
outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
|
outptr[0] = range_limit[(int) IRIGHT_SHIFT(tmp0 + tmp7, PASS1_BITS+3)
|
||||||
& RANGE_MASK];
|
& RANGE_MASK];
|
||||||
outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
|
outptr[7] = range_limit[(int) IRIGHT_SHIFT(tmp0 - tmp7, PASS1_BITS+3)
|
||||||
& RANGE_MASK];
|
& RANGE_MASK];
|
||||||
outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
|
outptr[1] = range_limit[(int) IRIGHT_SHIFT(tmp1 + tmp6, PASS1_BITS+3)
|
||||||
& RANGE_MASK];
|
& RANGE_MASK];
|
||||||
outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
|
outptr[6] = range_limit[(int) IRIGHT_SHIFT(tmp1 - tmp6, PASS1_BITS+3)
|
||||||
& RANGE_MASK];
|
& RANGE_MASK];
|
||||||
outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
|
outptr[2] = range_limit[(int) IRIGHT_SHIFT(tmp2 + tmp5, PASS1_BITS+3)
|
||||||
& RANGE_MASK];
|
& RANGE_MASK];
|
||||||
outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
|
outptr[5] = range_limit[(int) IRIGHT_SHIFT(tmp2 - tmp5, PASS1_BITS+3)
|
||||||
& RANGE_MASK];
|
& RANGE_MASK];
|
||||||
outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
|
outptr[3] = range_limit[(int) IRIGHT_SHIFT(tmp3 + tmp4, PASS1_BITS+3)
|
||||||
& RANGE_MASK];
|
& RANGE_MASK];
|
||||||
outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
|
outptr[4] = range_limit[(int) IRIGHT_SHIFT(tmp3 - tmp4, PASS1_BITS+3)
|
||||||
& RANGE_MASK];
|
& RANGE_MASK];
|
||||||
|
|
||||||
wsptr += DCTSIZE; /* advance pointer to next row */
|
wsptr += DCTSIZE; /* advance pointer to next row */
|
||||||
|
|||||||
Vendored
+328
-225
File diff suppressed because it is too large
Load Diff
Vendored
+6
@@ -2,6 +2,7 @@
|
|||||||
* jinclude.h
|
* jinclude.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1994, Thomas G. Lane.
|
* Copyright (C) 1991-1994, Thomas G. Lane.
|
||||||
|
* Modified 2017 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -83,9 +84,14 @@
|
|||||||
* The modules that use fread() and fwrite() always invoke them through
|
* The modules that use fread() and fwrite() always invoke them through
|
||||||
* these macros. On some systems you may need to twiddle the argument casts.
|
* these macros. On some systems you may need to twiddle the argument casts.
|
||||||
* CAUTION: argument order is different from underlying functions!
|
* CAUTION: argument order is different from underlying functions!
|
||||||
|
*
|
||||||
|
* Furthermore, macros are provided for fflush() and ferror() in order
|
||||||
|
* to facilitate adaption by applications using an own FILE class.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define JFREAD(file,buf,sizeofbuf) \
|
#define JFREAD(file,buf,sizeofbuf) \
|
||||||
((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
|
((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
|
||||||
#define JFWRITE(file,buf,sizeofbuf) \
|
#define JFWRITE(file,buf,sizeofbuf) \
|
||||||
((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
|
((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
|
||||||
|
#define JFFLUSH(file) fflush(file)
|
||||||
|
#define JFERROR(file) ferror(file)
|
||||||
|
|||||||
Vendored
+379
@@ -0,0 +1,379 @@
|
|||||||
|
;
|
||||||
|
; jmemdosa.asm
|
||||||
|
;
|
||||||
|
; Copyright (C) 1992, Thomas G. Lane.
|
||||||
|
; This file is part of the Independent JPEG Group's software.
|
||||||
|
; For conditions of distribution and use, see the accompanying README file.
|
||||||
|
;
|
||||||
|
; This file contains low-level interface routines to support the MS-DOS
|
||||||
|
; backing store manager (jmemdos.c). Routines are provided to access disk
|
||||||
|
; files through direct DOS calls, and to access XMS and EMS drivers.
|
||||||
|
;
|
||||||
|
; This file should assemble with Microsoft's MASM or any compatible
|
||||||
|
; assembler (including Borland's Turbo Assembler). If you haven't got
|
||||||
|
; a compatible assembler, better fall back to jmemansi.c or jmemname.c.
|
||||||
|
;
|
||||||
|
; To minimize dependence on the C compiler's register usage conventions,
|
||||||
|
; we save and restore all 8086 registers, even though most compilers only
|
||||||
|
; require SI,DI,DS to be preserved. Also, we use only 16-bit-wide return
|
||||||
|
; values, which everybody returns in AX.
|
||||||
|
;
|
||||||
|
; Based on code contributed by Ge' Weijers.
|
||||||
|
;
|
||||||
|
|
||||||
|
JMEMDOSA_TXT segment byte public 'CODE'
|
||||||
|
|
||||||
|
assume cs:JMEMDOSA_TXT
|
||||||
|
|
||||||
|
public _jdos_open
|
||||||
|
public _jdos_close
|
||||||
|
public _jdos_seek
|
||||||
|
public _jdos_read
|
||||||
|
public _jdos_write
|
||||||
|
public _jxms_getdriver
|
||||||
|
public _jxms_calldriver
|
||||||
|
public _jems_available
|
||||||
|
public _jems_calldriver
|
||||||
|
|
||||||
|
;
|
||||||
|
; short far jdos_open (short far * handle, char far * filename)
|
||||||
|
;
|
||||||
|
; Create and open a temporary file
|
||||||
|
;
|
||||||
|
_jdos_open proc far
|
||||||
|
push bp ; linkage
|
||||||
|
mov bp,sp
|
||||||
|
push si ; save all registers for safety
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push es
|
||||||
|
push ds
|
||||||
|
mov cx,0 ; normal file attributes
|
||||||
|
lds dx,dword ptr [bp+10] ; get filename pointer
|
||||||
|
mov ah,3ch ; create file
|
||||||
|
int 21h
|
||||||
|
jc open_err ; if failed, return error code
|
||||||
|
lds bx,dword ptr [bp+6] ; get handle pointer
|
||||||
|
mov word ptr [bx],ax ; save the handle
|
||||||
|
xor ax,ax ; return zero for OK
|
||||||
|
open_err: pop ds ; restore registers and exit
|
||||||
|
pop es
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
_jdos_open endp
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
; short far jdos_close (short handle)
|
||||||
|
;
|
||||||
|
; Close the file handle
|
||||||
|
;
|
||||||
|
_jdos_close proc far
|
||||||
|
push bp ; linkage
|
||||||
|
mov bp,sp
|
||||||
|
push si ; save all registers for safety
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push es
|
||||||
|
push ds
|
||||||
|
mov bx,word ptr [bp+6] ; file handle
|
||||||
|
mov ah,3eh ; close file
|
||||||
|
int 21h
|
||||||
|
jc close_err ; if failed, return error code
|
||||||
|
xor ax,ax ; return zero for OK
|
||||||
|
close_err: pop ds ; restore registers and exit
|
||||||
|
pop es
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
_jdos_close endp
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
; short far jdos_seek (short handle, long offset)
|
||||||
|
;
|
||||||
|
; Set file position
|
||||||
|
;
|
||||||
|
_jdos_seek proc far
|
||||||
|
push bp ; linkage
|
||||||
|
mov bp,sp
|
||||||
|
push si ; save all registers for safety
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push es
|
||||||
|
push ds
|
||||||
|
mov bx,word ptr [bp+6] ; file handle
|
||||||
|
mov dx,word ptr [bp+8] ; LS offset
|
||||||
|
mov cx,word ptr [bp+10] ; MS offset
|
||||||
|
mov ax,4200h ; absolute seek
|
||||||
|
int 21h
|
||||||
|
jc seek_err ; if failed, return error code
|
||||||
|
xor ax,ax ; return zero for OK
|
||||||
|
seek_err: pop ds ; restore registers and exit
|
||||||
|
pop es
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
_jdos_seek endp
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
; short far jdos_read (short handle, void far * buffer, unsigned short count)
|
||||||
|
;
|
||||||
|
; Read from file
|
||||||
|
;
|
||||||
|
_jdos_read proc far
|
||||||
|
push bp ; linkage
|
||||||
|
mov bp,sp
|
||||||
|
push si ; save all registers for safety
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push es
|
||||||
|
push ds
|
||||||
|
mov bx,word ptr [bp+6] ; file handle
|
||||||
|
lds dx,dword ptr [bp+8] ; buffer address
|
||||||
|
mov cx,word ptr [bp+12] ; number of bytes
|
||||||
|
mov ah,3fh ; read file
|
||||||
|
int 21h
|
||||||
|
jc read_err ; if failed, return error code
|
||||||
|
cmp ax,word ptr [bp+12] ; make sure all bytes were read
|
||||||
|
je read_ok
|
||||||
|
mov ax,1 ; else return 1 for not OK
|
||||||
|
jmp short read_err
|
||||||
|
read_ok: xor ax,ax ; return zero for OK
|
||||||
|
read_err: pop ds ; restore registers and exit
|
||||||
|
pop es
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
_jdos_read endp
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
; short far jdos_write (short handle, void far * buffer, unsigned short count)
|
||||||
|
;
|
||||||
|
; Write to file
|
||||||
|
;
|
||||||
|
_jdos_write proc far
|
||||||
|
push bp ; linkage
|
||||||
|
mov bp,sp
|
||||||
|
push si ; save all registers for safety
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push es
|
||||||
|
push ds
|
||||||
|
mov bx,word ptr [bp+6] ; file handle
|
||||||
|
lds dx,dword ptr [bp+8] ; buffer address
|
||||||
|
mov cx,word ptr [bp+12] ; number of bytes
|
||||||
|
mov ah,40h ; write file
|
||||||
|
int 21h
|
||||||
|
jc write_err ; if failed, return error code
|
||||||
|
cmp ax,word ptr [bp+12] ; make sure all bytes written
|
||||||
|
je write_ok
|
||||||
|
mov ax,1 ; else return 1 for not OK
|
||||||
|
jmp short write_err
|
||||||
|
write_ok: xor ax,ax ; return zero for OK
|
||||||
|
write_err: pop ds ; restore registers and exit
|
||||||
|
pop es
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
_jdos_write endp
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
; void far jxms_getdriver (XMSDRIVER far *)
|
||||||
|
;
|
||||||
|
; Get the address of the XMS driver, or NULL if not available
|
||||||
|
;
|
||||||
|
_jxms_getdriver proc far
|
||||||
|
push bp ; linkage
|
||||||
|
mov bp,sp
|
||||||
|
push si ; save all registers for safety
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push es
|
||||||
|
push ds
|
||||||
|
mov ax,4300h ; call multiplex interrupt with
|
||||||
|
int 2fh ; a magic cookie, hex 4300
|
||||||
|
cmp al,80h ; AL should contain hex 80
|
||||||
|
je xmsavail
|
||||||
|
xor dx,dx ; no XMS driver available
|
||||||
|
xor ax,ax ; return a nil pointer
|
||||||
|
jmp short xmsavail_done
|
||||||
|
xmsavail: mov ax,4310h ; fetch driver address with
|
||||||
|
int 2fh ; another magic cookie
|
||||||
|
mov dx,es ; copy address to dx:ax
|
||||||
|
mov ax,bx
|
||||||
|
xmsavail_done: les bx,dword ptr [bp+6] ; get pointer to return value
|
||||||
|
mov word ptr es:[bx],ax
|
||||||
|
mov word ptr es:[bx+2],dx
|
||||||
|
pop ds ; restore registers and exit
|
||||||
|
pop es
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
_jxms_getdriver endp
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
; void far jxms_calldriver (XMSDRIVER, XMScontext far *)
|
||||||
|
;
|
||||||
|
; The XMScontext structure contains values for the AX,DX,BX,SI,DS registers.
|
||||||
|
; These are loaded, the XMS call is performed, and the new values of the
|
||||||
|
; AX,DX,BX registers are written back to the context structure.
|
||||||
|
;
|
||||||
|
_jxms_calldriver proc far
|
||||||
|
push bp ; linkage
|
||||||
|
mov bp,sp
|
||||||
|
push si ; save all registers for safety
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push es
|
||||||
|
push ds
|
||||||
|
les bx,dword ptr [bp+10] ; get XMScontext pointer
|
||||||
|
mov ax,word ptr es:[bx] ; load registers
|
||||||
|
mov dx,word ptr es:[bx+2]
|
||||||
|
mov si,word ptr es:[bx+6]
|
||||||
|
mov ds,word ptr es:[bx+8]
|
||||||
|
mov bx,word ptr es:[bx+4]
|
||||||
|
call dword ptr [bp+6] ; call the driver
|
||||||
|
mov cx,bx ; save returned BX for a sec
|
||||||
|
les bx,dword ptr [bp+10] ; get XMScontext pointer
|
||||||
|
mov word ptr es:[bx],ax ; put back ax,dx,bx
|
||||||
|
mov word ptr es:[bx+2],dx
|
||||||
|
mov word ptr es:[bx+4],cx
|
||||||
|
pop ds ; restore registers and exit
|
||||||
|
pop es
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
_jxms_calldriver endp
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
; short far jems_available (void)
|
||||||
|
;
|
||||||
|
; Have we got an EMS driver? (this comes straight from the EMS 4.0 specs)
|
||||||
|
;
|
||||||
|
_jems_available proc far
|
||||||
|
push si ; save all registers for safety
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push es
|
||||||
|
push ds
|
||||||
|
mov ax,3567h ; get interrupt vector 67h
|
||||||
|
int 21h
|
||||||
|
push cs
|
||||||
|
pop ds
|
||||||
|
mov di,000ah ; check offs 10 in returned seg
|
||||||
|
lea si,ASCII_device_name ; against literal string
|
||||||
|
mov cx,8
|
||||||
|
cld
|
||||||
|
repe cmpsb
|
||||||
|
jne no_ems
|
||||||
|
mov ax,1 ; match, it's there
|
||||||
|
jmp short avail_done
|
||||||
|
no_ems: xor ax,ax ; it's not there
|
||||||
|
avail_done: pop ds ; restore registers and exit
|
||||||
|
pop es
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
ret
|
||||||
|
|
||||||
|
ASCII_device_name db "EMMXXXX0"
|
||||||
|
|
||||||
|
_jems_available endp
|
||||||
|
|
||||||
|
|
||||||
|
;
|
||||||
|
; void far jems_calldriver (EMScontext far *)
|
||||||
|
;
|
||||||
|
; The EMScontext structure contains values for the AX,DX,BX,SI,DS registers.
|
||||||
|
; These are loaded, the EMS trap is performed, and the new values of the
|
||||||
|
; AX,DX,BX registers are written back to the context structure.
|
||||||
|
;
|
||||||
|
_jems_calldriver proc far
|
||||||
|
push bp ; linkage
|
||||||
|
mov bp,sp
|
||||||
|
push si ; save all registers for safety
|
||||||
|
push di
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push es
|
||||||
|
push ds
|
||||||
|
les bx,dword ptr [bp+6] ; get EMScontext pointer
|
||||||
|
mov ax,word ptr es:[bx] ; load registers
|
||||||
|
mov dx,word ptr es:[bx+2]
|
||||||
|
mov si,word ptr es:[bx+6]
|
||||||
|
mov ds,word ptr es:[bx+8]
|
||||||
|
mov bx,word ptr es:[bx+4]
|
||||||
|
int 67h ; call the EMS driver
|
||||||
|
mov cx,bx ; save returned BX for a sec
|
||||||
|
les bx,dword ptr [bp+6] ; get EMScontext pointer
|
||||||
|
mov word ptr es:[bx],ax ; put back ax,dx,bx
|
||||||
|
mov word ptr es:[bx+2],dx
|
||||||
|
mov word ptr es:[bx+4],cx
|
||||||
|
pop ds ; restore registers and exit
|
||||||
|
pop es
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop di
|
||||||
|
pop si
|
||||||
|
pop bp
|
||||||
|
ret
|
||||||
|
_jems_calldriver endp
|
||||||
|
|
||||||
|
JMEMDOSA_TXT ends
|
||||||
|
|
||||||
|
end
|
||||||
Vendored
+31
-34
@@ -2,6 +2,7 @@
|
|||||||
* jmemmgr.c
|
* jmemmgr.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
|
* Modified 2011-2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -129,7 +130,7 @@ typedef struct {
|
|||||||
jvirt_barray_ptr virt_barray_list;
|
jvirt_barray_ptr virt_barray_list;
|
||||||
|
|
||||||
/* This counts total space obtained from jpeg_get_small/large */
|
/* This counts total space obtained from jpeg_get_small/large */
|
||||||
long total_space_allocated;
|
size_t total_space_allocated;
|
||||||
|
|
||||||
/* alloc_sarray and alloc_barray set this value for use by virtual
|
/* alloc_sarray and alloc_barray set this value for use by virtual
|
||||||
* array routines.
|
* array routines.
|
||||||
@@ -194,7 +195,7 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
|
|||||||
* This is helpful because message parm array can't handle longs.
|
* This is helpful because message parm array can't handle longs.
|
||||||
*/
|
*/
|
||||||
fprintf(stderr, "Freeing pool %d, total space = %ld\n",
|
fprintf(stderr, "Freeing pool %d, total space = %ld\n",
|
||||||
pool_id, mem->total_space_allocated);
|
pool_id, (long) mem->total_space_allocated);
|
||||||
|
|
||||||
for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
|
for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
|
||||||
lhdr_ptr = lhdr_ptr->hdr.next) {
|
lhdr_ptr = lhdr_ptr->hdr.next) {
|
||||||
@@ -213,7 +214,7 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
|
|||||||
#endif /* MEM_STATS */
|
#endif /* MEM_STATS */
|
||||||
|
|
||||||
|
|
||||||
LOCAL(void)
|
LOCAL(noreturn_t)
|
||||||
out_of_memory (j_common_ptr cinfo, int which)
|
out_of_memory (j_common_ptr cinfo, int which)
|
||||||
/* Report an out-of-memory error and stop execution */
|
/* Report an out-of-memory error and stop execution */
|
||||||
/* If we compiled MEM_STATS support, report alloc requests before dying */
|
/* If we compiled MEM_STATS support, report alloc requests before dying */
|
||||||
@@ -259,11 +260,11 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
|||||||
{
|
{
|
||||||
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
||||||
small_pool_ptr hdr_ptr, prev_hdr_ptr;
|
small_pool_ptr hdr_ptr, prev_hdr_ptr;
|
||||||
char * data_ptr;
|
|
||||||
size_t odd_bytes, min_request, slop;
|
size_t odd_bytes, min_request, slop;
|
||||||
|
char * data_ptr;
|
||||||
|
|
||||||
/* Check for unsatisfiable request (do now to ensure no overflow below) */
|
/* Check for unsatisfiable request (do now to ensure no overflow below) */
|
||||||
if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
|
if (sizeofobject > (size_t) MAX_ALLOC_CHUNK - SIZEOF(small_pool_hdr))
|
||||||
out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
|
out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
|
||||||
|
|
||||||
/* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
|
/* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
|
||||||
@@ -292,8 +293,8 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
|||||||
else
|
else
|
||||||
slop = extra_pool_slop[pool_id];
|
slop = extra_pool_slop[pool_id];
|
||||||
/* Don't ask for more than MAX_ALLOC_CHUNK */
|
/* Don't ask for more than MAX_ALLOC_CHUNK */
|
||||||
if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
|
if (slop > (size_t) MAX_ALLOC_CHUNK - min_request)
|
||||||
slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
|
slop = (size_t) MAX_ALLOC_CHUNK - min_request;
|
||||||
/* Try to get space, if fail reduce slop and try again */
|
/* Try to get space, if fail reduce slop and try again */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
|
hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
|
||||||
@@ -347,7 +348,7 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
|||||||
size_t odd_bytes;
|
size_t odd_bytes;
|
||||||
|
|
||||||
/* Check for unsatisfiable request (do now to ensure no overflow below) */
|
/* Check for unsatisfiable request (do now to ensure no overflow below) */
|
||||||
if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
|
if (sizeofobject > (size_t) MAX_ALLOC_CHUNK - SIZEOF(large_pool_hdr))
|
||||||
out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
|
out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
|
||||||
|
|
||||||
/* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
|
/* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */
|
||||||
@@ -403,7 +404,7 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
|
|||||||
long ltemp;
|
long ltemp;
|
||||||
|
|
||||||
/* Calculate max # of rows allowed in one allocation chunk */
|
/* Calculate max # of rows allowed in one allocation chunk */
|
||||||
ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
|
ltemp = (MAX_ALLOC_CHUNK - SIZEOF(large_pool_hdr)) /
|
||||||
((long) samplesperrow * SIZEOF(JSAMPLE));
|
((long) samplesperrow * SIZEOF(JSAMPLE));
|
||||||
if (ltemp <= 0)
|
if (ltemp <= 0)
|
||||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||||
@@ -415,15 +416,14 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
|
|||||||
|
|
||||||
/* Get space for row pointers (small object) */
|
/* Get space for row pointers (small object) */
|
||||||
result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
|
result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
|
||||||
(size_t) (numrows * SIZEOF(JSAMPROW)));
|
(size_t) numrows * SIZEOF(JSAMPROW));
|
||||||
|
|
||||||
/* Get the rows themselves (large objects) */
|
/* Get the rows themselves (large objects) */
|
||||||
currow = 0;
|
currow = 0;
|
||||||
while (currow < numrows) {
|
while (currow < numrows) {
|
||||||
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
||||||
workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
|
workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
|
||||||
(size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
|
(size_t) rowsperchunk * (size_t) samplesperrow * SIZEOF(JSAMPLE));
|
||||||
* SIZEOF(JSAMPLE)));
|
|
||||||
for (i = rowsperchunk; i > 0; i--) {
|
for (i = rowsperchunk; i > 0; i--) {
|
||||||
result[currow++] = workspace;
|
result[currow++] = workspace;
|
||||||
workspace += samplesperrow;
|
workspace += samplesperrow;
|
||||||
@@ -451,7 +451,7 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
|
|||||||
long ltemp;
|
long ltemp;
|
||||||
|
|
||||||
/* Calculate max # of rows allowed in one allocation chunk */
|
/* Calculate max # of rows allowed in one allocation chunk */
|
||||||
ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
|
ltemp = (MAX_ALLOC_CHUNK - SIZEOF(large_pool_hdr)) /
|
||||||
((long) blocksperrow * SIZEOF(JBLOCK));
|
((long) blocksperrow * SIZEOF(JBLOCK));
|
||||||
if (ltemp <= 0)
|
if (ltemp <= 0)
|
||||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||||
@@ -463,15 +463,14 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
|
|||||||
|
|
||||||
/* Get space for row pointers (small object) */
|
/* Get space for row pointers (small object) */
|
||||||
result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
|
result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
|
||||||
(size_t) (numrows * SIZEOF(JBLOCKROW)));
|
(size_t) numrows * SIZEOF(JBLOCKROW));
|
||||||
|
|
||||||
/* Get the rows themselves (large objects) */
|
/* Get the rows themselves (large objects) */
|
||||||
currow = 0;
|
currow = 0;
|
||||||
while (currow < numrows) {
|
while (currow < numrows) {
|
||||||
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
||||||
workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
|
workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
|
||||||
(size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
|
(size_t) rowsperchunk * (size_t) blocksperrow * SIZEOF(JBLOCK));
|
||||||
* SIZEOF(JBLOCK)));
|
|
||||||
for (i = rowsperchunk; i > 0; i--) {
|
for (i = rowsperchunk; i > 0; i--) {
|
||||||
result[currow++] = workspace;
|
result[currow++] = workspace;
|
||||||
workspace += blocksperrow;
|
workspace += blocksperrow;
|
||||||
@@ -584,8 +583,8 @@ realize_virt_arrays (j_common_ptr cinfo)
|
|||||||
/* Allocate the in-memory buffers for any unrealized virtual arrays */
|
/* Allocate the in-memory buffers for any unrealized virtual arrays */
|
||||||
{
|
{
|
||||||
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
||||||
long space_per_minheight, maximum_space, avail_mem;
|
long bytesperrow, space_per_minheight, maximum_space;
|
||||||
long minheights, max_minheights;
|
long avail_mem, minheights, max_minheights;
|
||||||
jvirt_sarray_ptr sptr;
|
jvirt_sarray_ptr sptr;
|
||||||
jvirt_barray_ptr bptr;
|
jvirt_barray_ptr bptr;
|
||||||
|
|
||||||
@@ -597,18 +596,16 @@ realize_virt_arrays (j_common_ptr cinfo)
|
|||||||
maximum_space = 0;
|
maximum_space = 0;
|
||||||
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
|
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
|
||||||
if (sptr->mem_buffer == NULL) { /* if not realized yet */
|
if (sptr->mem_buffer == NULL) { /* if not realized yet */
|
||||||
space_per_minheight += (long) sptr->maxaccess *
|
bytesperrow = (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
|
||||||
(long) sptr->samplesperrow * SIZEOF(JSAMPLE);
|
space_per_minheight += (long) sptr->maxaccess * bytesperrow;
|
||||||
maximum_space += (long) sptr->rows_in_array *
|
maximum_space += (long) sptr->rows_in_array * bytesperrow;
|
||||||
(long) sptr->samplesperrow * SIZEOF(JSAMPLE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
|
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
|
||||||
if (bptr->mem_buffer == NULL) { /* if not realized yet */
|
if (bptr->mem_buffer == NULL) { /* if not realized yet */
|
||||||
space_per_minheight += (long) bptr->maxaccess *
|
bytesperrow = (long) bptr->blocksperrow * SIZEOF(JBLOCK);
|
||||||
(long) bptr->blocksperrow * SIZEOF(JBLOCK);
|
space_per_minheight += (long) bptr->maxaccess * bytesperrow;
|
||||||
maximum_space += (long) bptr->rows_in_array *
|
maximum_space += (long) bptr->rows_in_array * bytesperrow;
|
||||||
(long) bptr->blocksperrow * SIZEOF(JBLOCK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,7 +614,7 @@ realize_virt_arrays (j_common_ptr cinfo)
|
|||||||
|
|
||||||
/* Determine amount of memory to actually use; this is system-dependent. */
|
/* Determine amount of memory to actually use; this is system-dependent. */
|
||||||
avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
|
avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
|
||||||
mem->total_space_allocated);
|
(long) mem->total_space_allocated);
|
||||||
|
|
||||||
/* If the maximum space needed is available, make all the buffers full
|
/* If the maximum space needed is available, make all the buffers full
|
||||||
* height; otherwise parcel it out with the same number of minheights
|
* height; otherwise parcel it out with the same number of minheights
|
||||||
@@ -693,7 +690,7 @@ do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
|
|||||||
long bytesperrow, file_offset, byte_count, rows, thisrow, i;
|
long bytesperrow, file_offset, byte_count, rows, thisrow, i;
|
||||||
|
|
||||||
bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
|
bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
|
||||||
file_offset = ptr->cur_start_row * bytesperrow;
|
file_offset = (long) ptr->cur_start_row * bytesperrow;
|
||||||
/* Loop to read or write each allocation chunk in mem_buffer */
|
/* Loop to read or write each allocation chunk in mem_buffer */
|
||||||
for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
|
for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
|
||||||
/* One chunk, but check for short chunk at end of buffer */
|
/* One chunk, but check for short chunk at end of buffer */
|
||||||
@@ -726,7 +723,7 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
|
|||||||
long bytesperrow, file_offset, byte_count, rows, thisrow, i;
|
long bytesperrow, file_offset, byte_count, rows, thisrow, i;
|
||||||
|
|
||||||
bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
|
bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
|
||||||
file_offset = ptr->cur_start_row * bytesperrow;
|
file_offset = (long) ptr->cur_start_row * bytesperrow;
|
||||||
/* Loop to read or write each allocation chunk in mem_buffer */
|
/* Loop to read or write each allocation chunk in mem_buffer */
|
||||||
for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
|
for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
|
||||||
/* One chunk, but check for short chunk at end of buffer */
|
/* One chunk, but check for short chunk at end of buffer */
|
||||||
@@ -770,7 +767,7 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
|||||||
|
|
||||||
/* Make the desired part of the virtual array accessible */
|
/* Make the desired part of the virtual array accessible */
|
||||||
if (start_row < ptr->cur_start_row ||
|
if (start_row < ptr->cur_start_row ||
|
||||||
end_row > ptr->cur_start_row+ptr->rows_in_mem) {
|
end_row > ptr->cur_start_row + ptr->rows_in_mem) {
|
||||||
if (! ptr->b_s_open)
|
if (! ptr->b_s_open)
|
||||||
ERREXIT(cinfo, JERR_VIRTUAL_BUG);
|
ERREXIT(cinfo, JERR_VIRTUAL_BUG);
|
||||||
/* Flush old buffer contents if necessary */
|
/* Flush old buffer contents if necessary */
|
||||||
@@ -821,7 +818,7 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
|||||||
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
|
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
|
||||||
end_row -= ptr->cur_start_row;
|
end_row -= ptr->cur_start_row;
|
||||||
while (undef_row < end_row) {
|
while (undef_row < end_row) {
|
||||||
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
|
FMEMZERO((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
|
||||||
undef_row++;
|
undef_row++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -855,7 +852,7 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
|
|||||||
|
|
||||||
/* Make the desired part of the virtual array accessible */
|
/* Make the desired part of the virtual array accessible */
|
||||||
if (start_row < ptr->cur_start_row ||
|
if (start_row < ptr->cur_start_row ||
|
||||||
end_row > ptr->cur_start_row+ptr->rows_in_mem) {
|
end_row > ptr->cur_start_row + ptr->rows_in_mem) {
|
||||||
if (! ptr->b_s_open)
|
if (! ptr->b_s_open)
|
||||||
ERREXIT(cinfo, JERR_VIRTUAL_BUG);
|
ERREXIT(cinfo, JERR_VIRTUAL_BUG);
|
||||||
/* Flush old buffer contents if necessary */
|
/* Flush old buffer contents if necessary */
|
||||||
@@ -906,7 +903,7 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
|
|||||||
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
|
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
|
||||||
end_row -= ptr->cur_start_row;
|
end_row -= ptr->cur_start_row;
|
||||||
while (undef_row < end_row) {
|
while (undef_row < end_row) {
|
||||||
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
|
FMEMZERO((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
|
||||||
undef_row++;
|
undef_row++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1092,7 +1089,7 @@ jinit_memory_mgr (j_common_ptr cinfo)
|
|||||||
mem->total_space_allocated = SIZEOF(my_memory_mgr);
|
mem->total_space_allocated = SIZEOF(my_memory_mgr);
|
||||||
|
|
||||||
/* Declare ourselves open for business */
|
/* Declare ourselves open for business */
|
||||||
cinfo->mem = & mem->pub;
|
cinfo->mem = &mem->pub;
|
||||||
|
|
||||||
/* Check for an environment variable JPEGMEM; if found, override the
|
/* Check for an environment variable JPEGMEM; if found, override the
|
||||||
* default max_memory setting from jpeg_mem_init. Note that the
|
* default max_memory setting from jpeg_mem_init. Note that the
|
||||||
|
|||||||
Vendored
+6
-2
@@ -2,6 +2,7 @@
|
|||||||
* jmemnobs.c
|
* jmemnobs.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1992-1996, Thomas G. Lane.
|
* Copyright (C) 1992-1996, Thomas G. Lane.
|
||||||
|
* Modified 2019 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
* This is very portable in the sense that it'll compile on almost anything,
|
* This is very portable in the sense that it'll compile on almost anything,
|
||||||
* but you'd better have lots of main memory (or virtual memory) if you want
|
* but you'd better have lots of main memory (or virtual memory) if you want
|
||||||
* to process big images.
|
* to process big images.
|
||||||
* Note that the max_memory_to_use option is ignored by this implementation.
|
* Note that the max_memory_to_use option is respected by this implementation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define JPEG_INTERNALS
|
#define JPEG_INTERNALS
|
||||||
@@ -66,13 +67,16 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* This routine computes the total memory space available for allocation.
|
* This routine computes the total memory space available for allocation.
|
||||||
* Here we always say, "we got all you want bud!"
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GLOBAL(long)
|
GLOBAL(long)
|
||||||
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||||
long max_bytes_needed, long already_allocated)
|
long max_bytes_needed, long already_allocated)
|
||||||
{
|
{
|
||||||
|
if (cinfo->mem->max_memory_to_use)
|
||||||
|
return cinfo->mem->max_memory_to_use - already_allocated;
|
||||||
|
|
||||||
|
/* Here we say, "we got all you want bud!" */
|
||||||
return max_bytes_needed;
|
return max_bytes_needed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+90
-15
@@ -2,7 +2,7 @@
|
|||||||
* jmorecfg.h
|
* jmorecfg.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
* Modified 1997-2009 by Guido Vollbeding.
|
* Modified 1997-2013 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -15,13 +15,22 @@
|
|||||||
/*
|
/*
|
||||||
* Define BITS_IN_JSAMPLE as either
|
* Define BITS_IN_JSAMPLE as either
|
||||||
* 8 for 8-bit sample values (the usual setting)
|
* 8 for 8-bit sample values (the usual setting)
|
||||||
|
* 9 for 9-bit sample values
|
||||||
|
* 10 for 10-bit sample values
|
||||||
|
* 11 for 11-bit sample values
|
||||||
* 12 for 12-bit sample values
|
* 12 for 12-bit sample values
|
||||||
* Only 8 and 12 are legal data precisions for lossy JPEG according to the
|
* Only 8, 9, 10, 11, and 12 bits sample data precision are supported for
|
||||||
* JPEG standard, and the IJG code does not support anything else!
|
* full-feature DCT processing. Further depths up to 16-bit may be added
|
||||||
* We do not support run-time selection of data precision, sorry.
|
* later for the lossless modes of operation.
|
||||||
|
* Run-time selection and conversion of data precision will be added later
|
||||||
|
* and are currently not supported, sorry.
|
||||||
|
* Exception: The transcoding part (jpegtran) supports all settings in a
|
||||||
|
* single instance, since it operates on the level of DCT coefficients and
|
||||||
|
* not sample values. The DCT coefficients are of the same type (16 bits)
|
||||||
|
* in all cases (see below).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
|
#define BITS_IN_JSAMPLE 8 /* use 8, 9, 10, 11, or 12 */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -77,6 +86,48 @@ typedef char JSAMPLE;
|
|||||||
#endif /* BITS_IN_JSAMPLE == 8 */
|
#endif /* BITS_IN_JSAMPLE == 8 */
|
||||||
|
|
||||||
|
|
||||||
|
#if BITS_IN_JSAMPLE == 9
|
||||||
|
/* JSAMPLE should be the smallest type that will hold the values 0..511.
|
||||||
|
* On nearly all machines "short" will do nicely.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef short JSAMPLE;
|
||||||
|
#define GETJSAMPLE(value) ((int) (value))
|
||||||
|
|
||||||
|
#define MAXJSAMPLE 511
|
||||||
|
#define CENTERJSAMPLE 256
|
||||||
|
|
||||||
|
#endif /* BITS_IN_JSAMPLE == 9 */
|
||||||
|
|
||||||
|
|
||||||
|
#if BITS_IN_JSAMPLE == 10
|
||||||
|
/* JSAMPLE should be the smallest type that will hold the values 0..1023.
|
||||||
|
* On nearly all machines "short" will do nicely.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef short JSAMPLE;
|
||||||
|
#define GETJSAMPLE(value) ((int) (value))
|
||||||
|
|
||||||
|
#define MAXJSAMPLE 1023
|
||||||
|
#define CENTERJSAMPLE 512
|
||||||
|
|
||||||
|
#endif /* BITS_IN_JSAMPLE == 10 */
|
||||||
|
|
||||||
|
|
||||||
|
#if BITS_IN_JSAMPLE == 11
|
||||||
|
/* JSAMPLE should be the smallest type that will hold the values 0..2047.
|
||||||
|
* On nearly all machines "short" will do nicely.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef short JSAMPLE;
|
||||||
|
#define GETJSAMPLE(value) ((int) (value))
|
||||||
|
|
||||||
|
#define MAXJSAMPLE 2047
|
||||||
|
#define CENTERJSAMPLE 1024
|
||||||
|
|
||||||
|
#endif /* BITS_IN_JSAMPLE == 11 */
|
||||||
|
|
||||||
|
|
||||||
#if BITS_IN_JSAMPLE == 12
|
#if BITS_IN_JSAMPLE == 12
|
||||||
/* JSAMPLE should be the smallest type that will hold the values 0..4095.
|
/* JSAMPLE should be the smallest type that will hold the values 0..4095.
|
||||||
* On nearly all machines "short" will do nicely.
|
* On nearly all machines "short" will do nicely.
|
||||||
@@ -210,6 +261,26 @@ typedef unsigned int JDIMENSION;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* The noreturn type identifier is used to declare functions
|
||||||
|
* which cannot return.
|
||||||
|
* Compilers can thus create more optimized code and perform
|
||||||
|
* better checks for warnings and errors.
|
||||||
|
* Static analyzer tools can make improved inferences about
|
||||||
|
* execution paths and are prevented from giving false alerts.
|
||||||
|
*
|
||||||
|
* Unfortunately, the proposed specifications of corresponding
|
||||||
|
* extensions in the Dec 2011 ISO C standard revision (C11),
|
||||||
|
* GCC, MSVC, etc. are not viable.
|
||||||
|
* Thus we introduce a user defined type to declare noreturn
|
||||||
|
* functions at least for clarity. A proper compiler would
|
||||||
|
* have a suitable noreturn type to match in place of void.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef HAVE_NORETURN_T
|
||||||
|
typedef void noreturn_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Here is the pseudo-keyword for declaring pointers that must be "far"
|
/* Here is the pseudo-keyword for declaring pointers that must be "far"
|
||||||
* on 80x86 machines. Most of the specialized coding for 80x86 is handled
|
* on 80x86 machines. Most of the specialized coding for 80x86 is handled
|
||||||
* by just saying "FAR *" where such a pointer is needed. In a few places
|
* by just saying "FAR *" where such a pointer is needed. In a few places
|
||||||
@@ -233,14 +304,19 @@ typedef unsigned int JDIMENSION;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HAVE_BOOLEAN
|
#ifndef HAVE_BOOLEAN
|
||||||
|
#if defined FALSE || defined TRUE || defined QGLOBAL_H
|
||||||
|
/* Qt3 defines FALSE and TRUE as "const" variables in qglobal.h */
|
||||||
typedef int boolean;
|
typedef int boolean;
|
||||||
#endif
|
|
||||||
#ifndef FALSE /* in case these macros already exist */
|
#ifndef FALSE /* in case these macros already exist */
|
||||||
#define FALSE 0 /* values of boolean */
|
#define FALSE 0 /* values of boolean */
|
||||||
#endif
|
#endif
|
||||||
#ifndef TRUE
|
#ifndef TRUE
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#endif
|
#endif
|
||||||
|
#else
|
||||||
|
typedef enum { FALSE = 0, TRUE = 1 } boolean;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -278,11 +354,12 @@ typedef int boolean;
|
|||||||
#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
|
#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
|
||||||
#define DCT_SCALING_SUPPORTED /* Input rescaling via DCT? (Requires DCT_ISLOW)*/
|
#define DCT_SCALING_SUPPORTED /* Input rescaling via DCT? (Requires DCT_ISLOW)*/
|
||||||
#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
|
#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
|
||||||
/* Note: if you selected 12-bit data precision, it is dangerous to turn off
|
/* Note: if you selected more than 8-bit data precision, it is dangerous to
|
||||||
* ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
|
* turn off ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only
|
||||||
* precision, so jchuff.c normally uses entropy optimization to compute
|
* good for 8-bit precision, so arithmetic coding is recommended for higher
|
||||||
* usable tables for higher precision. If you don't want to do optimization,
|
* precision. The Huffman encoder normally uses entropy optimization to
|
||||||
* you'll have to supply different default Huffman tables.
|
* compute usable tables for higher precision. Otherwise, you'll have to
|
||||||
|
* supply different default Huffman tables.
|
||||||
* The exact same statements apply for progressive JPEG: the default tables
|
* The exact same statements apply for progressive JPEG: the default tables
|
||||||
* don't work for progressive mode. (This may get fixed, however.)
|
* don't work for progressive mode. (This may get fixed, however.)
|
||||||
*/
|
*/
|
||||||
@@ -293,7 +370,7 @@ typedef int boolean;
|
|||||||
#define D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
|
#define D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
|
||||||
#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
|
#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
|
||||||
#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
|
#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
|
||||||
#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
|
#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? (Requires DCT_ISLOW)*/
|
||||||
#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
|
#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
|
||||||
#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
|
#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
|
||||||
#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
|
#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
|
||||||
@@ -312,9 +389,7 @@ typedef int boolean;
|
|||||||
* the offsets will also change the order in which colormap data is organized.
|
* the offsets will also change the order in which colormap data is organized.
|
||||||
* RESTRICTIONS:
|
* RESTRICTIONS:
|
||||||
* 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
|
* 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
|
||||||
* 2. These macros only affect RGB<=>YCbCr color conversion, so they are not
|
* 2. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
|
||||||
* useful if you are using JPEG color spaces other than YCbCr or grayscale.
|
|
||||||
* 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
|
|
||||||
* is not 3 (they don't understand about dummy color components!). So you
|
* is not 3 (they don't understand about dummy color components!). So you
|
||||||
* can't use color quantization if you change that value.
|
* can't use color quantization if you change that value.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Vendored
+54
-16
@@ -2,7 +2,7 @@
|
|||||||
* jpegint.h
|
* jpegint.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||||
* Modified 1997-2009 by Guido Vollbeding.
|
* Modified 1997-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -103,8 +103,7 @@ struct jpeg_downsampler {
|
|||||||
typedef JMETHOD(void, forward_DCT_ptr,
|
typedef JMETHOD(void, forward_DCT_ptr,
|
||||||
(j_compress_ptr cinfo, jpeg_component_info * compptr,
|
(j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||||
JDIMENSION start_row, JDIMENSION start_col,
|
JDIMENSION start_col, JDIMENSION num_blocks));
|
||||||
JDIMENSION num_blocks));
|
|
||||||
|
|
||||||
struct jpeg_forward_dct {
|
struct jpeg_forward_dct {
|
||||||
JMETHOD(void, start_pass, (j_compress_ptr cinfo));
|
JMETHOD(void, start_pass, (j_compress_ptr cinfo));
|
||||||
@@ -115,7 +114,7 @@ struct jpeg_forward_dct {
|
|||||||
/* Entropy encoding */
|
/* Entropy encoding */
|
||||||
struct jpeg_entropy_encoder {
|
struct jpeg_entropy_encoder {
|
||||||
JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
|
JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
|
||||||
JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
|
JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKARRAY MCU_data));
|
||||||
JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
|
JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,8 +210,8 @@ struct jpeg_marker_reader {
|
|||||||
/* Entropy decoding */
|
/* Entropy decoding */
|
||||||
struct jpeg_entropy_decoder {
|
struct jpeg_entropy_decoder {
|
||||||
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
|
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
|
||||||
JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
|
JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JBLOCKARRAY MCU_data));
|
||||||
JBLOCKROW *MCU_data));
|
JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Inverse DCT (also performs dequantization) */
|
/* Inverse DCT (also performs dequantization) */
|
||||||
@@ -260,6 +259,19 @@ struct jpeg_color_quantizer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Definition of range extension bits for decompression processes.
|
||||||
|
* See the comments with prepare_range_limit_table (in jdmaster.c)
|
||||||
|
* for more info.
|
||||||
|
* The recommended default value for normal applications is 2.
|
||||||
|
* Applications with special requirements may use a different value.
|
||||||
|
* For example, Ghostscript wants to use 3 for proper handling of
|
||||||
|
* wacky images with oversize coefficient values.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define RANGE_BITS 2
|
||||||
|
#define RANGE_CENTER (CENTERJSAMPLE << RANGE_BITS)
|
||||||
|
|
||||||
|
|
||||||
/* Miscellaneous useful macros */
|
/* Miscellaneous useful macros */
|
||||||
|
|
||||||
#undef MAX
|
#undef MAX
|
||||||
@@ -289,6 +301,13 @@ struct jpeg_color_quantizer {
|
|||||||
#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
|
#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Descale and correctly round an INT32 value that's scaled by N bits.
|
||||||
|
* We assume RIGHT_SHIFT rounds towards minus infinity, so adding
|
||||||
|
* the fudge factor is correct for either sign of X.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DESCALE(x,n) RIGHT_SHIFT((x) + ((INT32) 1 << ((n)-1)), n)
|
||||||
|
|
||||||
|
|
||||||
/* Short forms of external names for systems with brain-damaged linkers. */
|
/* Short forms of external names for systems with brain-damaged linkers. */
|
||||||
|
|
||||||
@@ -321,21 +340,41 @@ struct jpeg_color_quantizer {
|
|||||||
#define jinit_memory_mgr jIMemMgr
|
#define jinit_memory_mgr jIMemMgr
|
||||||
#define jdiv_round_up jDivRound
|
#define jdiv_round_up jDivRound
|
||||||
#define jround_up jRound
|
#define jround_up jRound
|
||||||
|
#define jzero_far jZeroFar
|
||||||
#define jcopy_sample_rows jCopySamples
|
#define jcopy_sample_rows jCopySamples
|
||||||
#define jcopy_block_row jCopyBlocks
|
#define jcopy_block_row jCopyBlocks
|
||||||
#define jzero_far jZeroFar
|
|
||||||
#define jpeg_zigzag_order jZIGTable
|
#define jpeg_zigzag_order jZIGTable
|
||||||
#define jpeg_natural_order jZAGTable
|
#define jpeg_natural_order jZAGTable
|
||||||
#define jpeg_natural_order7 jZAGTable7
|
#define jpeg_natural_order7 jZAG7Table
|
||||||
#define jpeg_natural_order6 jZAGTable6
|
#define jpeg_natural_order6 jZAG6Table
|
||||||
#define jpeg_natural_order5 jZAGTable5
|
#define jpeg_natural_order5 jZAG5Table
|
||||||
#define jpeg_natural_order4 jZAGTable4
|
#define jpeg_natural_order4 jZAG4Table
|
||||||
#define jpeg_natural_order3 jZAGTable3
|
#define jpeg_natural_order3 jZAG3Table
|
||||||
#define jpeg_natural_order2 jZAGTable2
|
#define jpeg_natural_order2 jZAG2Table
|
||||||
#define jpeg_aritab jAriTab
|
#define jpeg_aritab jAriTab
|
||||||
#endif /* NEED_SHORT_EXTERNAL_NAMES */
|
#endif /* NEED_SHORT_EXTERNAL_NAMES */
|
||||||
|
|
||||||
|
|
||||||
|
/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
|
||||||
|
* and coefficient-block arrays. This won't work on 80x86 because the arrays
|
||||||
|
* are FAR and we're assuming a small-pointer memory model. However, some
|
||||||
|
* DOS compilers provide far-pointer versions of memcpy() and memset() even
|
||||||
|
* in the small-model libraries. These will be used if USE_FMEM is defined.
|
||||||
|
* Otherwise, the routines in jutils.c do it the hard way.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NEED_FAR_POINTERS /* normal case, same as regular macro */
|
||||||
|
#define FMEMZERO(target,size) MEMZERO(target,size)
|
||||||
|
#else /* 80x86 case */
|
||||||
|
#ifdef USE_FMEM
|
||||||
|
#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
|
||||||
|
#else
|
||||||
|
EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
|
||||||
|
#define FMEMZERO(target,size) jzero_far(target, size)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Compression module initialization routines */
|
/* Compression module initialization routines */
|
||||||
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
|
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
|
||||||
EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
|
EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
|
||||||
@@ -376,12 +415,11 @@ EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
|
|||||||
/* Utility routines in jutils.c */
|
/* Utility routines in jutils.c */
|
||||||
EXTERN(long) jdiv_round_up JPP((long a, long b));
|
EXTERN(long) jdiv_round_up JPP((long a, long b));
|
||||||
EXTERN(long) jround_up JPP((long a, long b));
|
EXTERN(long) jround_up JPP((long a, long b));
|
||||||
EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
|
EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array,
|
||||||
JSAMPARRAY output_array, int dest_row,
|
JSAMPARRAY output_array,
|
||||||
int num_rows, JDIMENSION num_cols));
|
int num_rows, JDIMENSION num_cols));
|
||||||
EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
|
EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
|
||||||
JDIMENSION num_blocks));
|
JDIMENSION num_blocks));
|
||||||
EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
|
|
||||||
/* Constant tables in jutils.c */
|
/* Constant tables in jutils.c */
|
||||||
#if 0 /* This table is not actually needed in v6a */
|
#if 0 /* This table is not actually needed in v6a */
|
||||||
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
|
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
|
||||||
|
|||||||
Vendored
+46
-23
@@ -2,7 +2,7 @@
|
|||||||
* jpeglib.h
|
* jpeglib.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||||
* Modified 2002-2010 by Guido Vollbeding.
|
* Modified 2002-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -34,20 +34,20 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Version IDs for the JPEG library.
|
/* Version IDs for the JPEG library.
|
||||||
* Might be useful for tests like "#if JPEG_LIB_VERSION >= 80".
|
* Might be useful for tests like "#if JPEG_LIB_VERSION >= 90".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define JPEG_LIB_VERSION 80 /* Compatibility version 8.0 */
|
#define JPEG_LIB_VERSION 90 /* Compatibility version 9.0 */
|
||||||
#define JPEG_LIB_VERSION_MAJOR 8
|
#define JPEG_LIB_VERSION_MAJOR 9
|
||||||
#define JPEG_LIB_VERSION_MINOR 3
|
#define JPEG_LIB_VERSION_MINOR 5
|
||||||
|
|
||||||
|
|
||||||
/* Various constants determining the sizes of things.
|
/* Various constants determining the sizes of things.
|
||||||
* All of these are specified by the JPEG standard, so don't change them
|
* All of these are specified by the JPEG standard,
|
||||||
* if you want to be compatible.
|
* so don't change them if you want to be compatible.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
|
#define DCTSIZE 8 /* The basic DCT block is 8x8 coefficients */
|
||||||
#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
|
#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
|
||||||
#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
|
#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
|
||||||
#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
|
#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
|
||||||
@@ -157,16 +157,21 @@ typedef struct {
|
|||||||
/* The downsampled dimensions are the component's actual, unpadded number
|
/* The downsampled dimensions are the component's actual, unpadded number
|
||||||
* of samples at the main buffer (preprocessing/compression interface);
|
* of samples at the main buffer (preprocessing/compression interface);
|
||||||
* DCT scaling is included, so
|
* DCT scaling is included, so
|
||||||
* downsampled_width = ceil(image_width * Hi/Hmax * DCT_h_scaled_size/DCTSIZE)
|
* downsampled_width =
|
||||||
|
* ceil(image_width * Hi/Hmax * DCT_h_scaled_size/block_size)
|
||||||
* and similarly for height.
|
* and similarly for height.
|
||||||
*/
|
*/
|
||||||
JDIMENSION downsampled_width; /* actual width in samples */
|
JDIMENSION downsampled_width; /* actual width in samples */
|
||||||
JDIMENSION downsampled_height; /* actual height in samples */
|
JDIMENSION downsampled_height; /* actual height in samples */
|
||||||
/* This flag is used only for decompression. In cases where some of the
|
/* For decompression, in cases where some of the components will be
|
||||||
* components will be ignored (eg grayscale output from YCbCr image),
|
* ignored (eg grayscale output from YCbCr image), we can skip most
|
||||||
* we can skip most computations for the unused components.
|
* computations for the unused components.
|
||||||
|
* For compression, some of the components will need further quantization
|
||||||
|
* scale by factor of 2 after DCT (eg BG_YCC output from normal RGB input).
|
||||||
|
* The field is first set TRUE for decompression, FALSE for compression
|
||||||
|
* in initial_setup, and then adapted in color conversion setup.
|
||||||
*/
|
*/
|
||||||
boolean component_needed; /* do we need the value of this component? */
|
boolean component_needed;
|
||||||
|
|
||||||
/* These values are computed before starting a scan of the component. */
|
/* These values are computed before starting a scan of the component. */
|
||||||
/* The decompressor output side may not use these variables. */
|
/* The decompressor output side may not use these variables. */
|
||||||
@@ -215,12 +220,21 @@ struct jpeg_marker_struct {
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
JCS_UNKNOWN, /* error/unspecified */
|
JCS_UNKNOWN, /* error/unspecified */
|
||||||
JCS_GRAYSCALE, /* monochrome */
|
JCS_GRAYSCALE, /* monochrome */
|
||||||
JCS_RGB, /* red/green/blue */
|
JCS_RGB, /* red/green/blue, standard RGB (sRGB) */
|
||||||
JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
|
JCS_YCbCr, /* Y/Cb/Cr (also known as YUV), standard YCC */
|
||||||
JCS_CMYK, /* C/M/Y/K */
|
JCS_CMYK, /* C/M/Y/K */
|
||||||
JCS_YCCK /* Y/Cb/Cr/K */
|
JCS_YCCK, /* Y/Cb/Cr/K */
|
||||||
|
JCS_BG_RGB, /* big gamut red/green/blue, bg-sRGB */
|
||||||
|
JCS_BG_YCC /* big gamut Y/Cb/Cr, bg-sYCC */
|
||||||
} J_COLOR_SPACE;
|
} J_COLOR_SPACE;
|
||||||
|
|
||||||
|
/* Supported color transforms. */
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
JCT_NONE = 0,
|
||||||
|
JCT_SUBTRACT_GREEN = 1
|
||||||
|
} J_COLOR_TRANSFORM;
|
||||||
|
|
||||||
/* DCT/IDCT algorithm options. */
|
/* DCT/IDCT algorithm options. */
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -370,6 +384,9 @@ struct jpeg_compress_struct {
|
|||||||
UINT16 Y_density; /* Vertical pixel density */
|
UINT16 Y_density; /* Vertical pixel density */
|
||||||
boolean write_Adobe_marker; /* should an Adobe marker be written? */
|
boolean write_Adobe_marker; /* should an Adobe marker be written? */
|
||||||
|
|
||||||
|
J_COLOR_TRANSFORM color_transform;
|
||||||
|
/* Color transform identifier, writes LSE marker if nonzero */
|
||||||
|
|
||||||
/* State variable: index of next scanline to be written to
|
/* State variable: index of next scanline to be written to
|
||||||
* jpeg_write_scanlines(). Application may use this to control its
|
* jpeg_write_scanlines(). Application may use this to control its
|
||||||
* processing loop, e.g., "while (next_scanline < image_height)".
|
* processing loop, e.g., "while (next_scanline < image_height)".
|
||||||
@@ -394,8 +411,8 @@ struct jpeg_compress_struct {
|
|||||||
JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
|
JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
|
||||||
/* The coefficient controller receives data in units of MCU rows as defined
|
/* The coefficient controller receives data in units of MCU rows as defined
|
||||||
* for fully interleaved scans (whether the JPEG file is interleaved or not).
|
* for fully interleaved scans (whether the JPEG file is interleaved or not).
|
||||||
* There are v_samp_factor * DCTSIZE sample rows of each component in an
|
* There are v_samp_factor * DCT_v_scaled_size sample rows of each component
|
||||||
* "iMCU" (interleaved MCU) row.
|
* in an "iMCU" (interleaved MCU) row.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -589,6 +606,9 @@ struct jpeg_decompress_struct {
|
|||||||
boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
|
boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
|
||||||
UINT8 Adobe_transform; /* Color transform code from Adobe marker */
|
UINT8 Adobe_transform; /* Color transform code from Adobe marker */
|
||||||
|
|
||||||
|
J_COLOR_TRANSFORM color_transform;
|
||||||
|
/* Color transform identifier derived from LSE marker, otherwise zero */
|
||||||
|
|
||||||
boolean CCIR601_sampling; /* TRUE=first samples are cosited */
|
boolean CCIR601_sampling; /* TRUE=first samples are cosited */
|
||||||
|
|
||||||
/* Aside from the specific data retained from APPn markers known to the
|
/* Aside from the specific data retained from APPn markers known to the
|
||||||
@@ -616,7 +636,7 @@ struct jpeg_decompress_struct {
|
|||||||
* in fully interleaved JPEG scans, but are used whether the scan is
|
* in fully interleaved JPEG scans, but are used whether the scan is
|
||||||
* interleaved or not. We define an iMCU row as v_samp_factor DCT block
|
* interleaved or not. We define an iMCU row as v_samp_factor DCT block
|
||||||
* rows of each component. Therefore, the IDCT output contains
|
* rows of each component. Therefore, the IDCT output contains
|
||||||
* v_samp_factor*DCT_v_scaled_size sample rows of a component per iMCU row.
|
* v_samp_factor * DCT_v_scaled_size sample rows of a component per iMCU row.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
JSAMPLE * sample_range_limit; /* table for fast range-limiting */
|
JSAMPLE * sample_range_limit; /* table for fast range-limiting */
|
||||||
@@ -681,7 +701,7 @@ struct jpeg_decompress_struct {
|
|||||||
|
|
||||||
struct jpeg_error_mgr {
|
struct jpeg_error_mgr {
|
||||||
/* Error exit handler: does not return to caller */
|
/* Error exit handler: does not return to caller */
|
||||||
JMETHOD(void, error_exit, (j_common_ptr cinfo));
|
JMETHOD(noreturn_t, error_exit, (j_common_ptr cinfo));
|
||||||
/* Conditionally emit a trace or warning message */
|
/* Conditionally emit a trace or warning message */
|
||||||
JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
|
JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
|
||||||
/* Routine that actually outputs a trace or error message */
|
/* Routine that actually outputs a trace or error message */
|
||||||
@@ -889,6 +909,7 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
|
|||||||
#define jpeg_suppress_tables jSuppressTables
|
#define jpeg_suppress_tables jSuppressTables
|
||||||
#define jpeg_alloc_quant_table jAlcQTable
|
#define jpeg_alloc_quant_table jAlcQTable
|
||||||
#define jpeg_alloc_huff_table jAlcHTable
|
#define jpeg_alloc_huff_table jAlcHTable
|
||||||
|
#define jpeg_std_huff_table jStdHTable
|
||||||
#define jpeg_start_compress jStrtCompress
|
#define jpeg_start_compress jStrtCompress
|
||||||
#define jpeg_write_scanlines jWrtScanlines
|
#define jpeg_write_scanlines jWrtScanlines
|
||||||
#define jpeg_finish_compress jFinCompress
|
#define jpeg_finish_compress jFinCompress
|
||||||
@@ -957,10 +978,10 @@ EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
|
|||||||
/* Data source and destination managers: memory buffers. */
|
/* Data source and destination managers: memory buffers. */
|
||||||
EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo,
|
EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo,
|
||||||
unsigned char ** outbuffer,
|
unsigned char ** outbuffer,
|
||||||
unsigned long * outsize));
|
size_t * outsize));
|
||||||
EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo,
|
EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo,
|
||||||
unsigned char * inbuffer,
|
const unsigned char * inbuffer,
|
||||||
unsigned long insize));
|
size_t insize));
|
||||||
|
|
||||||
/* Default parameter setup for compression */
|
/* Default parameter setup for compression */
|
||||||
EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
|
EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
|
||||||
@@ -985,6 +1006,8 @@ EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
|
|||||||
boolean suppress));
|
boolean suppress));
|
||||||
EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
|
EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
|
||||||
EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
|
EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
|
||||||
|
EXTERN(JHUFF_TBL *) jpeg_std_huff_table JPP((j_common_ptr cinfo,
|
||||||
|
boolean isDC, int tblno));
|
||||||
|
|
||||||
/* Main entry points for compression */
|
/* Main entry points for compression */
|
||||||
EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
|
EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
|
||||||
|
|||||||
Vendored
+328
@@ -0,0 +1,328 @@
|
|||||||
|
.TH JPEGTRAN 1 "28 August 2019"
|
||||||
|
.SH NAME
|
||||||
|
jpegtran \- lossless transformation of JPEG files
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B jpegtran
|
||||||
|
[
|
||||||
|
.I options
|
||||||
|
]
|
||||||
|
[
|
||||||
|
.I filename
|
||||||
|
]
|
||||||
|
.LP
|
||||||
|
.SH DESCRIPTION
|
||||||
|
.LP
|
||||||
|
.B jpegtran
|
||||||
|
performs various useful transformations of JPEG files.
|
||||||
|
It can translate the coded representation from one variant of JPEG to another,
|
||||||
|
for example from baseline JPEG to progressive JPEG or vice versa. It can also
|
||||||
|
perform some rearrangements of the image data, for example turning an image
|
||||||
|
from landscape to portrait format by rotation.
|
||||||
|
.PP
|
||||||
|
For EXIF files and JPEG files containing Exif data, you may prefer to use
|
||||||
|
.B exiftran
|
||||||
|
instead.
|
||||||
|
.PP
|
||||||
|
.B jpegtran
|
||||||
|
works by rearranging the compressed data (DCT coefficients), without
|
||||||
|
ever fully decoding the image. Therefore, its transformations are lossless:
|
||||||
|
there is no image degradation at all, which would not be true if you used
|
||||||
|
.B djpeg
|
||||||
|
followed by
|
||||||
|
.B cjpeg
|
||||||
|
to accomplish the same conversion. But by the same token,
|
||||||
|
.B jpegtran
|
||||||
|
cannot perform lossy operations such as changing the image quality. However,
|
||||||
|
while the image data is losslessly transformed, metadata can be removed. See
|
||||||
|
the
|
||||||
|
.B \-copy
|
||||||
|
option for specifics.
|
||||||
|
.PP
|
||||||
|
.B jpegtran
|
||||||
|
reads the named JPEG/JFIF file, or the standard input if no file is
|
||||||
|
named, and produces a JPEG/JFIF file on the standard output.
|
||||||
|
.SH OPTIONS
|
||||||
|
All switch names may be abbreviated; for example,
|
||||||
|
.B \-optimize
|
||||||
|
may be written
|
||||||
|
.B \-opt
|
||||||
|
or
|
||||||
|
.BR \-o .
|
||||||
|
Upper and lower case are equivalent.
|
||||||
|
British spellings are also accepted (e.g.,
|
||||||
|
.BR \-optimise ),
|
||||||
|
though for brevity these are not mentioned below.
|
||||||
|
.PP
|
||||||
|
To specify the coded JPEG representation used in the output file,
|
||||||
|
.B jpegtran
|
||||||
|
accepts a subset of the switches recognized by
|
||||||
|
.BR cjpeg :
|
||||||
|
.TP
|
||||||
|
.B \-optimize
|
||||||
|
Perform optimization of entropy encoding parameters.
|
||||||
|
.TP
|
||||||
|
.B \-progressive
|
||||||
|
Create progressive JPEG file.
|
||||||
|
.TP
|
||||||
|
.BI \-restart " N"
|
||||||
|
Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is
|
||||||
|
attached to the number.
|
||||||
|
.TP
|
||||||
|
.B \-arithmetic
|
||||||
|
Use arithmetic coding.
|
||||||
|
.TP
|
||||||
|
.BI \-scans " file"
|
||||||
|
Use the scan script given in the specified text file.
|
||||||
|
.PP
|
||||||
|
See
|
||||||
|
.BR cjpeg (1)
|
||||||
|
for more details about these switches.
|
||||||
|
If you specify none of these switches, you get a plain baseline-JPEG output
|
||||||
|
file. The quality setting and so forth are determined by the input file.
|
||||||
|
.PP
|
||||||
|
The image can be losslessly transformed by giving one of these switches:
|
||||||
|
.TP
|
||||||
|
.B \-flip horizontal
|
||||||
|
Mirror image horizontally (left-right).
|
||||||
|
.TP
|
||||||
|
.B \-flip vertical
|
||||||
|
Mirror image vertically (top-bottom).
|
||||||
|
.TP
|
||||||
|
.B \-rotate 90
|
||||||
|
Rotate image 90 degrees clockwise.
|
||||||
|
.TP
|
||||||
|
.B \-rotate 180
|
||||||
|
Rotate image 180 degrees.
|
||||||
|
.TP
|
||||||
|
.B \-rotate 270
|
||||||
|
Rotate image 270 degrees clockwise (or 90 ccw).
|
||||||
|
.TP
|
||||||
|
.B \-transpose
|
||||||
|
Transpose image (across UL-to-LR axis).
|
||||||
|
.TP
|
||||||
|
.B \-transverse
|
||||||
|
Transverse transpose (across UR-to-LL axis).
|
||||||
|
.IP
|
||||||
|
The transpose transformation has no restrictions regarding image dimensions.
|
||||||
|
The other transformations operate rather oddly if the image dimensions are not
|
||||||
|
a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
|
||||||
|
transform complete blocks of DCT coefficient data in the desired way.
|
||||||
|
.IP
|
||||||
|
.BR jpegtran 's
|
||||||
|
default behavior when transforming an odd-size image is designed
|
||||||
|
to preserve exact reversibility and mathematical consistency of the
|
||||||
|
transformation set. As stated, transpose is able to flip the entire image
|
||||||
|
area. Horizontal mirroring leaves any partial iMCU column at the right edge
|
||||||
|
untouched, but is able to flip all rows of the image. Similarly, vertical
|
||||||
|
mirroring leaves any partial iMCU row at the bottom edge untouched, but is
|
||||||
|
able to flip all columns. The other transforms can be built up as sequences
|
||||||
|
of transpose and flip operations; for consistency, their actions on edge
|
||||||
|
pixels are defined to be the same as the end result of the corresponding
|
||||||
|
transpose-and-flip sequence.
|
||||||
|
.IP
|
||||||
|
For practical use, you may prefer to discard any untransformable edge pixels
|
||||||
|
rather than having a strange-looking strip along the right and/or bottom edges
|
||||||
|
of a transformed image. To do this, add the
|
||||||
|
.B \-trim
|
||||||
|
switch:
|
||||||
|
.TP
|
||||||
|
.B \-trim
|
||||||
|
Drop non-transformable edge blocks.
|
||||||
|
.IP
|
||||||
|
Obviously, a transformation with
|
||||||
|
.B \-trim
|
||||||
|
is not reversible, so strictly speaking
|
||||||
|
.B jpegtran
|
||||||
|
with this switch is not lossless. Also, the expected mathematical
|
||||||
|
equivalences between the transformations no longer hold. For example,
|
||||||
|
.B \-rot 270 -trim
|
||||||
|
trims only the bottom edge, but
|
||||||
|
.B \-rot 90 -trim
|
||||||
|
followed by
|
||||||
|
.B \-rot 180 -trim
|
||||||
|
trims both edges.
|
||||||
|
.IP
|
||||||
|
If you are only interested in perfect transformation, add the
|
||||||
|
.B \-perfect
|
||||||
|
switch:
|
||||||
|
.TP
|
||||||
|
.B \-perfect
|
||||||
|
Fails with an error if the transformation is not perfect.
|
||||||
|
.IP
|
||||||
|
For example you may want to do
|
||||||
|
.IP
|
||||||
|
.B (jpegtran \-rot 90 -perfect
|
||||||
|
.I foo.jpg
|
||||||
|
.B || djpeg
|
||||||
|
.I foo.jpg
|
||||||
|
.B | pnmflip \-r90 | cjpeg)
|
||||||
|
.IP
|
||||||
|
to do a perfect rotation if available or an approximated one if not.
|
||||||
|
.PP
|
||||||
|
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 current 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 by
|
||||||
|
attaching an 'f' character ("force") to the width or height number.
|
||||||
|
.PP
|
||||||
|
The image can be losslessly cropped by giving the switch:
|
||||||
|
.TP
|
||||||
|
.B \-crop WxH+X+Y
|
||||||
|
Crop to a rectangular subarea of width W, height H starting at point X,Y.
|
||||||
|
.PP
|
||||||
|
Crop extension: The width or height parameters can be made larger than the
|
||||||
|
source image. In this case the extra area is filled in with zero (neutral
|
||||||
|
gray). A larger width parameter has two more options: Attaching an 'f'
|
||||||
|
character ("flatten") to the width number will fill in the extra area with
|
||||||
|
the DC of the adjacent block, instead of gray out. Attaching an 'r'
|
||||||
|
character ("reflect") to the width number will fill in the extra area with
|
||||||
|
repeated reflections of the source region, instead of gray out.
|
||||||
|
.PP
|
||||||
|
A complementary lossless-wipe option is provided to discard (gray out) data
|
||||||
|
inside a given image region while losslessly preserving what is outside:
|
||||||
|
.TP
|
||||||
|
.B \-wipe WxH+X+Y
|
||||||
|
Wipe (gray out) a rectangular subarea of width W, height H starting at point
|
||||||
|
X,Y.
|
||||||
|
.PP
|
||||||
|
Attaching an 'f' character ("flatten") to the width number will fill the
|
||||||
|
region with the average of adjacent blocks, instead of gray out. In case
|
||||||
|
the wipe region and outside area form two horizontally adjacent rectangles,
|
||||||
|
attaching an 'r' character ("reflect") to the width number will fill the
|
||||||
|
region with repeated reflections of the outside area, instead of gray out.
|
||||||
|
.PP
|
||||||
|
Another option is lossless-drop, which replaces data at a given image
|
||||||
|
position by another image:
|
||||||
|
.TP
|
||||||
|
.B \-drop +X+Y filename
|
||||||
|
Drop another image
|
||||||
|
.PP
|
||||||
|
Both source images must have the same subsampling values. It is best if
|
||||||
|
they also have the same quantization, otherwise quantization adaption occurs.
|
||||||
|
The trim option can be used with the drop option to requantize the drop file
|
||||||
|
to the source file.
|
||||||
|
.PP
|
||||||
|
Other not-strictly-lossless transformation switches are:
|
||||||
|
.TP
|
||||||
|
.B \-grayscale
|
||||||
|
Force grayscale output.
|
||||||
|
.IP
|
||||||
|
This option discards the chrominance channels if the input image is YCbCr
|
||||||
|
(ie, a standard color JPEG), resulting in a grayscale JPEG file. The
|
||||||
|
luminance channel is preserved exactly, so this is a better method of reducing
|
||||||
|
to grayscale than decompression, conversion, and recompression. This switch
|
||||||
|
is particularly handy for fixing a monochrome picture that was mistakenly
|
||||||
|
encoded as a color JPEG. (In such a case, the space savings from getting rid
|
||||||
|
of the near-empty chroma channels won't be large; but the decoding time for
|
||||||
|
a grayscale JPEG is substantially less than that for a color JPEG.)
|
||||||
|
.TP
|
||||||
|
.BI \-scale " M/N"
|
||||||
|
Scale the output image by a factor M/N.
|
||||||
|
.IP
|
||||||
|
Currently supported scale factors are M/N with all M from 1 to 16, where N is
|
||||||
|
the source DCT size, which is 8 for baseline JPEG. If the /N part is omitted,
|
||||||
|
then M specifies the DCT scaled size to be applied on the given input. For
|
||||||
|
baseline JPEG this is equivalent to M/8 scaling, since the source DCT size
|
||||||
|
for baseline JPEG is 8.
|
||||||
|
.B Caution:
|
||||||
|
An implementation of the JPEG SmartScale extension is required for this
|
||||||
|
feature. SmartScale enabled JPEG is not yet widely implemented, so many
|
||||||
|
decoders will be unable to view a SmartScale extended JPEG file at all.
|
||||||
|
.PP
|
||||||
|
.B jpegtran
|
||||||
|
also recognizes these switches that control what to do with "extra" markers,
|
||||||
|
such as comment blocks:
|
||||||
|
.TP
|
||||||
|
.B \-copy none
|
||||||
|
Copy no extra markers from source file. This setting suppresses all
|
||||||
|
comments and other metadata in the source file.
|
||||||
|
.TP
|
||||||
|
.B \-copy comments
|
||||||
|
Copy only comment markers. This setting copies comments from the source file,
|
||||||
|
but discards any other metadata.
|
||||||
|
.TP
|
||||||
|
.B \-copy all
|
||||||
|
Copy all extra markers. This setting preserves metadata
|
||||||
|
found in the source file, such as JFIF thumbnails, Exif data, and Photoshop
|
||||||
|
settings. In some files these extra markers can be sizable. Note that this
|
||||||
|
option will copy thumbnails as-is; they will not be transformed.
|
||||||
|
.IP
|
||||||
|
The default behavior is
|
||||||
|
.BR "\-copy comments" .
|
||||||
|
(Note: in IJG releases v6 and v6a,
|
||||||
|
.B jpegtran
|
||||||
|
always did the equivalent of
|
||||||
|
.BR "\-copy none" .)
|
||||||
|
.PP
|
||||||
|
Additional switches recognized by jpegtran are:
|
||||||
|
.TP
|
||||||
|
.BI \-maxmemory " N"
|
||||||
|
Set limit for amount of memory to use in processing large images. Value is
|
||||||
|
in thousands of bytes, or millions of bytes if "M" is attached to the
|
||||||
|
number. For example,
|
||||||
|
.B \-max 4m
|
||||||
|
selects 4000000 bytes. If more space is needed, temporary files will be used.
|
||||||
|
.TP
|
||||||
|
.BI \-outfile " name"
|
||||||
|
Send output image to the named file, not to standard output.
|
||||||
|
.TP
|
||||||
|
.B \-verbose
|
||||||
|
Enable debug printout. More
|
||||||
|
.BR \-v 's
|
||||||
|
give more output. Also, version information is printed at startup.
|
||||||
|
.TP
|
||||||
|
.B \-debug
|
||||||
|
Same as
|
||||||
|
.BR \-verbose .
|
||||||
|
.SH EXAMPLES
|
||||||
|
.LP
|
||||||
|
This example converts a baseline JPEG file to progressive form:
|
||||||
|
.IP
|
||||||
|
.B jpegtran \-progressive
|
||||||
|
.I foo.jpg
|
||||||
|
.B >
|
||||||
|
.I fooprog.jpg
|
||||||
|
.PP
|
||||||
|
This example rotates an image 90 degrees clockwise, discarding any
|
||||||
|
unrotatable edge pixels:
|
||||||
|
.IP
|
||||||
|
.B jpegtran \-rot 90 -trim
|
||||||
|
.I foo.jpg
|
||||||
|
.B >
|
||||||
|
.I foo90.jpg
|
||||||
|
.SH ENVIRONMENT
|
||||||
|
.TP
|
||||||
|
.B JPEGMEM
|
||||||
|
If this environment variable is set, its value is the default memory limit.
|
||||||
|
The value is specified as described for the
|
||||||
|
.B \-maxmemory
|
||||||
|
switch.
|
||||||
|
.B JPEGMEM
|
||||||
|
overrides the default value specified when the program was compiled, and
|
||||||
|
itself is overridden by an explicit
|
||||||
|
.BR \-maxmemory .
|
||||||
|
.SH SEE ALSO
|
||||||
|
.BR cjpeg (1),
|
||||||
|
.BR djpeg (1),
|
||||||
|
.BR rdjpgcom (1),
|
||||||
|
.BR wrjpgcom (1)
|
||||||
|
.br
|
||||||
|
Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
|
||||||
|
Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
|
||||||
|
.SH AUTHOR
|
||||||
|
Independent JPEG Group
|
||||||
|
.SH BUGS
|
||||||
|
The transform options can't transform odd-size images perfectly. Use
|
||||||
|
.B \-trim
|
||||||
|
or
|
||||||
|
.B \-perfect
|
||||||
|
if you don't like the results.
|
||||||
|
.PP
|
||||||
|
The entire image is read into memory and then written out again, even in
|
||||||
|
cases where this isn't really necessary. Expect swapping on large images,
|
||||||
|
especially when using the more complex transform options.
|
||||||
Vendored
+105
-11
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* jpegtran.c
|
* jpegtran.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1995-2010, Thomas G. Lane, Guido Vollbeding.
|
* Copyright (C) 1995-2019, Thomas G. Lane, Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
static const char * progname; /* program name for error messages */
|
static const char * progname; /* program name for error messages */
|
||||||
static char * outfilename; /* for -outfile switch */
|
static char * outfilename; /* for -outfile switch */
|
||||||
|
static char * dropfilename; /* for -drop switch */
|
||||||
static char * scaleoption; /* -scale switch */
|
static char * scaleoption; /* -scale switch */
|
||||||
static JCOPY_OPTION copyoption; /* -copy switch */
|
static JCOPY_OPTION copyoption; /* -copy switch */
|
||||||
static jpeg_transform_info transformoption; /* image transformation options */
|
static jpeg_transform_info transformoption; /* image transformation options */
|
||||||
@@ -66,8 +67,9 @@ usage (void)
|
|||||||
fprintf(stderr, "Switches for modifying the image:\n");
|
fprintf(stderr, "Switches for modifying the image:\n");
|
||||||
#if TRANSFORMS_SUPPORTED
|
#if TRANSFORMS_SUPPORTED
|
||||||
fprintf(stderr, " -crop WxH+X+Y Crop to a rectangular subarea\n");
|
fprintf(stderr, " -crop WxH+X+Y Crop to a rectangular subarea\n");
|
||||||
fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n");
|
fprintf(stderr, " -drop +X+Y filename Drop another image\n");
|
||||||
fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n");
|
fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n");
|
||||||
|
fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n");
|
||||||
fprintf(stderr, " -perfect Fail if there is non-transformable edge blocks\n");
|
fprintf(stderr, " -perfect Fail if there is non-transformable edge blocks\n");
|
||||||
fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n");
|
fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n");
|
||||||
#endif
|
#endif
|
||||||
@@ -76,16 +78,18 @@ usage (void)
|
|||||||
fprintf(stderr, " -transpose Transpose image\n");
|
fprintf(stderr, " -transpose Transpose image\n");
|
||||||
fprintf(stderr, " -transverse Transverse transpose image\n");
|
fprintf(stderr, " -transverse Transverse transpose image\n");
|
||||||
fprintf(stderr, " -trim Drop non-transformable edge blocks\n");
|
fprintf(stderr, " -trim Drop non-transformable edge blocks\n");
|
||||||
|
fprintf(stderr, " with -drop: Requantize drop file to source file\n");
|
||||||
|
fprintf(stderr, " -wipe WxH+X+Y Wipe (gray out) a rectangular subarea\n");
|
||||||
#endif
|
#endif
|
||||||
fprintf(stderr, "Switches for advanced users:\n");
|
fprintf(stderr, "Switches for advanced users:\n");
|
||||||
|
#ifdef C_ARITH_CODING_SUPPORTED
|
||||||
|
fprintf(stderr, " -arithmetic Use arithmetic coding\n");
|
||||||
|
#endif
|
||||||
fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
|
fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n");
|
||||||
fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
|
fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n");
|
||||||
fprintf(stderr, " -outfile name Specify name for output file\n");
|
fprintf(stderr, " -outfile name Specify name for output file\n");
|
||||||
fprintf(stderr, " -verbose or -debug Emit debug output\n");
|
fprintf(stderr, " -verbose or -debug Emit debug output\n");
|
||||||
fprintf(stderr, "Switches for wizards:\n");
|
fprintf(stderr, "Switches for wizards:\n");
|
||||||
#ifdef C_ARITH_CODING_SUPPORTED
|
|
||||||
fprintf(stderr, " -arithmetic Use arithmetic coding\n");
|
|
||||||
#endif
|
|
||||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||||
fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n");
|
fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n");
|
||||||
#endif
|
#endif
|
||||||
@@ -187,7 +191,8 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
|||||||
#if TRANSFORMS_SUPPORTED
|
#if TRANSFORMS_SUPPORTED
|
||||||
if (++argn >= argc) /* advance to next argument */
|
if (++argn >= argc) /* advance to next argument */
|
||||||
usage();
|
usage();
|
||||||
if (! jtransform_parse_crop_spec(&transformoption, argv[argn])) {
|
if (transformoption.crop /* reject multiple crop/drop/wipe requests */ ||
|
||||||
|
! jtransform_parse_crop_spec(&transformoption, argv[argn])) {
|
||||||
fprintf(stderr, "%s: bogus -crop argument '%s'\n",
|
fprintf(stderr, "%s: bogus -crop argument '%s'\n",
|
||||||
progname, argv[argn]);
|
progname, argv[argn]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -196,6 +201,26 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
|||||||
select_transform(JXFORM_NONE); /* force an error */
|
select_transform(JXFORM_NONE); /* force an error */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
} else if (keymatch(arg, "drop", 2)) {
|
||||||
|
#if TRANSFORMS_SUPPORTED
|
||||||
|
if (++argn >= argc) /* advance to next argument */
|
||||||
|
usage();
|
||||||
|
if (transformoption.crop /* reject multiple crop/drop/wipe requests */ ||
|
||||||
|
! jtransform_parse_crop_spec(&transformoption, argv[argn]) ||
|
||||||
|
transformoption.crop_width_set != JCROP_UNSET ||
|
||||||
|
transformoption.crop_height_set != JCROP_UNSET) {
|
||||||
|
fprintf(stderr, "%s: bogus -drop argument '%s'\n",
|
||||||
|
progname, argv[argn]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (++argn >= argc) /* advance to next argument */
|
||||||
|
usage();
|
||||||
|
dropfilename = argv[argn];
|
||||||
|
select_transform(JXFORM_DROP);
|
||||||
|
#else
|
||||||
|
select_transform(JXFORM_NONE); /* force an error */
|
||||||
|
#endif
|
||||||
|
|
||||||
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
|
} else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
|
||||||
/* Enable debug printouts. */
|
/* Enable debug printouts. */
|
||||||
/* On first -d, print version identification */
|
/* On first -d, print version identification */
|
||||||
@@ -336,6 +361,21 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
|||||||
/* Trim off any partial edge MCUs that the transform can't handle. */
|
/* Trim off any partial edge MCUs that the transform can't handle. */
|
||||||
transformoption.trim = TRUE;
|
transformoption.trim = TRUE;
|
||||||
|
|
||||||
|
} else if (keymatch(arg, "wipe", 1)) {
|
||||||
|
#if TRANSFORMS_SUPPORTED
|
||||||
|
if (++argn >= argc) /* advance to next argument */
|
||||||
|
usage();
|
||||||
|
if (transformoption.crop /* reject multiple crop/drop/wipe requests */ ||
|
||||||
|
! jtransform_parse_crop_spec(&transformoption, argv[argn])) {
|
||||||
|
fprintf(stderr, "%s: bogus -wipe argument '%s'\n",
|
||||||
|
progname, argv[argn]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
select_transform(JXFORM_WIPE);
|
||||||
|
#else
|
||||||
|
select_transform(JXFORM_NONE); /* force an error */
|
||||||
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
usage(); /* bogus switch */
|
usage(); /* bogus switch */
|
||||||
}
|
}
|
||||||
@@ -369,8 +409,14 @@ int
|
|||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct jpeg_decompress_struct srcinfo;
|
struct jpeg_decompress_struct srcinfo;
|
||||||
|
struct jpeg_error_mgr jsrcerr;
|
||||||
|
#if TRANSFORMS_SUPPORTED
|
||||||
|
struct jpeg_decompress_struct dropinfo;
|
||||||
|
struct jpeg_error_mgr jdroperr;
|
||||||
|
FILE * drop_file;
|
||||||
|
#endif
|
||||||
struct jpeg_compress_struct dstinfo;
|
struct jpeg_compress_struct dstinfo;
|
||||||
struct jpeg_error_mgr jsrcerr, jdsterr;
|
struct jpeg_error_mgr jdsterr;
|
||||||
#ifdef PROGRESS_REPORT
|
#ifdef PROGRESS_REPORT
|
||||||
struct cdjpeg_progress_mgr progress;
|
struct cdjpeg_progress_mgr progress;
|
||||||
#endif
|
#endif
|
||||||
@@ -410,7 +456,7 @@ main (int argc, char **argv)
|
|||||||
* values read here are mostly ignored; we will rescan the switches after
|
* values read here are mostly ignored; we will rescan the switches after
|
||||||
* opening the input file. Also note that most of the switches affect the
|
* opening the input file. Also note that most of the switches affect the
|
||||||
* destination JPEG object, so we parse into that and then copy over what
|
* destination JPEG object, so we parse into that and then copy over what
|
||||||
* needs to affects the source too.
|
* needs to affect the source too.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE);
|
file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE);
|
||||||
@@ -452,6 +498,21 @@ main (int argc, char **argv)
|
|||||||
fp = read_stdin();
|
fp = read_stdin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TRANSFORMS_SUPPORTED
|
||||||
|
/* Open the drop file. */
|
||||||
|
if (dropfilename != NULL) {
|
||||||
|
if ((drop_file = fopen(dropfilename, READ_BINARY)) == NULL) {
|
||||||
|
fprintf(stderr, "%s: can't open %s for reading\n", progname, dropfilename);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
dropinfo.err = jpeg_std_error(&jdroperr);
|
||||||
|
jpeg_create_decompress(&dropinfo);
|
||||||
|
jpeg_stdio_src(&dropinfo, drop_file);
|
||||||
|
} else {
|
||||||
|
drop_file = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef PROGRESS_REPORT
|
#ifdef PROGRESS_REPORT
|
||||||
start_progress_monitor((j_common_ptr) &dstinfo, &progress);
|
start_progress_monitor((j_common_ptr) &dstinfo, &progress);
|
||||||
#endif
|
#endif
|
||||||
@@ -467,10 +528,21 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
/* Adjust default decompression parameters */
|
/* Adjust default decompression parameters */
|
||||||
if (scaleoption != NULL)
|
if (scaleoption != NULL)
|
||||||
if (sscanf(scaleoption, "%d/%d",
|
if (sscanf(scaleoption, "%u/%u",
|
||||||
&srcinfo.scale_num, &srcinfo.scale_denom) < 1)
|
&srcinfo.scale_num, &srcinfo.scale_denom) < 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
|
#if TRANSFORMS_SUPPORTED
|
||||||
|
if (dropfilename != NULL) {
|
||||||
|
(void) jpeg_read_header(&dropinfo, TRUE);
|
||||||
|
transformoption.crop_width = dropinfo.image_width;
|
||||||
|
transformoption.crop_width_set = JCROP_POS;
|
||||||
|
transformoption.crop_height = dropinfo.image_height;
|
||||||
|
transformoption.crop_height_set = JCROP_POS;
|
||||||
|
transformoption.drop_ptr = &dropinfo;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Any space needed by a transform option must be requested before
|
/* Any space needed by a transform option must be requested before
|
||||||
* jpeg_read_coefficients so that memory allocation will be done right.
|
* jpeg_read_coefficients so that memory allocation will be done right.
|
||||||
*/
|
*/
|
||||||
@@ -486,6 +558,12 @@ main (int argc, char **argv)
|
|||||||
/* Read source file as DCT coefficients */
|
/* Read source file as DCT coefficients */
|
||||||
src_coef_arrays = jpeg_read_coefficients(&srcinfo);
|
src_coef_arrays = jpeg_read_coefficients(&srcinfo);
|
||||||
|
|
||||||
|
#if TRANSFORMS_SUPPORTED
|
||||||
|
if (dropfilename != NULL) {
|
||||||
|
transformoption.drop_coef_arrays = jpeg_read_coefficients(&dropinfo);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Initialize destination compression parameters from source values */
|
/* Initialize destination compression parameters from source values */
|
||||||
jpeg_copy_critical_parameters(&srcinfo, &dstinfo);
|
jpeg_copy_critical_parameters(&srcinfo, &dstinfo);
|
||||||
|
|
||||||
@@ -543,18 +621,34 @@ main (int argc, char **argv)
|
|||||||
/* Finish compression and release memory */
|
/* Finish compression and release memory */
|
||||||
jpeg_finish_compress(&dstinfo);
|
jpeg_finish_compress(&dstinfo);
|
||||||
jpeg_destroy_compress(&dstinfo);
|
jpeg_destroy_compress(&dstinfo);
|
||||||
|
#if TRANSFORMS_SUPPORTED
|
||||||
|
if (dropfilename != NULL) {
|
||||||
|
(void) jpeg_finish_decompress(&dropinfo);
|
||||||
|
jpeg_destroy_decompress(&dropinfo);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
(void) jpeg_finish_decompress(&srcinfo);
|
(void) jpeg_finish_decompress(&srcinfo);
|
||||||
jpeg_destroy_decompress(&srcinfo);
|
jpeg_destroy_decompress(&srcinfo);
|
||||||
|
|
||||||
/* Close output file, if we opened it */
|
/* Close output file, if we opened it */
|
||||||
if (fp != stdout)
|
if (fp != stdout)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
#if TRANSFORMS_SUPPORTED
|
||||||
|
if (drop_file != NULL)
|
||||||
|
fclose(drop_file);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef PROGRESS_REPORT
|
#ifdef PROGRESS_REPORT
|
||||||
end_progress_monitor((j_common_ptr) &dstinfo);
|
end_progress_monitor((j_common_ptr) &dstinfo);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* All done. */
|
/* All done. */
|
||||||
exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS);
|
#if TRANSFORMS_SUPPORTED
|
||||||
return 0; /* suppress no-return-value warnings */
|
if (dropfilename != NULL)
|
||||||
|
exit(jsrcerr.num_warnings + jdroperr.num_warnings +
|
||||||
|
jdsterr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
|
||||||
|
#endif
|
||||||
|
exit(jsrcerr.num_warnings + jdsterr.num_warnings ?
|
||||||
|
EXIT_WARNING : EXIT_SUCCESS);
|
||||||
|
return 0; /* suppress no-return-value warnings */
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+14
-19
@@ -2,6 +2,7 @@
|
|||||||
* jquant1.c
|
* jquant1.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||||
|
* Modified 2011-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -292,8 +293,7 @@ create_colormap (j_decompress_ptr cinfo)
|
|||||||
/* The colors are ordered in the map in standard row-major order, */
|
/* The colors are ordered in the map in standard row-major order, */
|
||||||
/* i.e. rightmost (highest-indexed) color changes most rapidly. */
|
/* i.e. rightmost (highest-indexed) color changes most rapidly. */
|
||||||
|
|
||||||
colormap = (*cinfo->mem->alloc_sarray)
|
colormap = (*cinfo->mem->alloc_sarray) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
||||||
(JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
|
(JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
|
||||||
|
|
||||||
/* blksize is number of adjacent repeated entries for a component */
|
/* blksize is number of adjacent repeated entries for a component */
|
||||||
@@ -399,9 +399,8 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
|
|||||||
int j,k;
|
int j,k;
|
||||||
INT32 num,den;
|
INT32 num,den;
|
||||||
|
|
||||||
odither = (ODITHER_MATRIX_PTR)
|
odither = (ODITHER_MATRIX_PTR) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(ODITHER_MATRIX));
|
||||||
SIZEOF(ODITHER_MATRIX));
|
|
||||||
/* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
|
/* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
|
||||||
* Hence the dither value for the matrix cell with fill order f
|
* Hence the dither value for the matrix cell with fill order f
|
||||||
* (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
|
* (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
|
||||||
@@ -530,8 +529,7 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
|||||||
|
|
||||||
for (row = 0; row < num_rows; row++) {
|
for (row = 0; row < num_rows; row++) {
|
||||||
/* Initialize output values to 0 so can process components separately */
|
/* Initialize output values to 0 so can process components separately */
|
||||||
jzero_far((void FAR *) output_buf[row],
|
FMEMZERO((void FAR *) output_buf[row], (size_t) width * SIZEOF(JSAMPLE));
|
||||||
(size_t) (width * SIZEOF(JSAMPLE)));
|
|
||||||
row_index = cquantize->row_index;
|
row_index = cquantize->row_index;
|
||||||
for (ci = 0; ci < nc; ci++) {
|
for (ci = 0; ci < nc; ci++) {
|
||||||
input_ptr = input_buf[row] + ci;
|
input_ptr = input_buf[row] + ci;
|
||||||
@@ -635,8 +633,7 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
|||||||
|
|
||||||
for (row = 0; row < num_rows; row++) {
|
for (row = 0; row < num_rows; row++) {
|
||||||
/* Initialize output values to 0 so can process components separately */
|
/* Initialize output values to 0 so can process components separately */
|
||||||
jzero_far((void FAR *) output_buf[row],
|
FMEMZERO((void FAR *) output_buf[row], (size_t) width * SIZEOF(JSAMPLE));
|
||||||
(size_t) (width * SIZEOF(JSAMPLE)));
|
|
||||||
for (ci = 0; ci < nc; ci++) {
|
for (ci = 0; ci < nc; ci++) {
|
||||||
input_ptr = input_buf[row] + ci;
|
input_ptr = input_buf[row] + ci;
|
||||||
output_ptr = output_buf[row];
|
output_ptr = output_buf[row];
|
||||||
@@ -725,10 +722,10 @@ alloc_fs_workspace (j_decompress_ptr cinfo)
|
|||||||
size_t arraysize;
|
size_t arraysize;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
|
arraysize = ((size_t) cinfo->output_width + (size_t) 2) * SIZEOF(FSERROR);
|
||||||
for (i = 0; i < cinfo->out_color_components; i++) {
|
for (i = 0; i < cinfo->out_color_components; i++) {
|
||||||
cquantize->fserrors[i] = (FSERRPTR)
|
cquantize->fserrors[i] = (FSERRPTR) (*cinfo->mem->alloc_large)
|
||||||
(*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
|
((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,13 +776,12 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
|
|||||||
if (cquantize->fserrors[0] == NULL)
|
if (cquantize->fserrors[0] == NULL)
|
||||||
alloc_fs_workspace(cinfo);
|
alloc_fs_workspace(cinfo);
|
||||||
/* Initialize the propagated errors to zero. */
|
/* Initialize the propagated errors to zero. */
|
||||||
arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
|
arraysize = ((size_t) cinfo->output_width + (size_t) 2) * SIZEOF(FSERROR);
|
||||||
for (i = 0; i < cinfo->out_color_components; i++)
|
for (i = 0; i < cinfo->out_color_components; i++)
|
||||||
jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
|
FMEMZERO((void FAR *) cquantize->fserrors[i], arraysize);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -822,10 +818,9 @@ jinit_1pass_quantizer (j_decompress_ptr cinfo)
|
|||||||
{
|
{
|
||||||
my_cquantize_ptr cquantize;
|
my_cquantize_ptr cquantize;
|
||||||
|
|
||||||
cquantize = (my_cquantize_ptr)
|
cquantize = (my_cquantize_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_cquantizer));
|
||||||
SIZEOF(my_cquantizer));
|
cinfo->cquantize = &cquantize->pub;
|
||||||
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
|
|
||||||
cquantize->pub.start_pass = start_pass_1_quant;
|
cquantize->pub.start_pass = start_pass_1_quant;
|
||||||
cquantize->pub.finish_pass = finish_pass_1_quant;
|
cquantize->pub.finish_pass = finish_pass_1_quant;
|
||||||
cquantize->pub.new_color_map = new_color_map_1_quant;
|
cquantize->pub.new_color_map = new_color_map_1_quant;
|
||||||
|
|||||||
Vendored
+12
-11
@@ -2,6 +2,7 @@
|
|||||||
* jquant2.c
|
* jquant2.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||||
|
* Modified 2011-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -1196,14 +1197,14 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
|
|||||||
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
|
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
|
||||||
|
|
||||||
if (cinfo->dither_mode == JDITHER_FS) {
|
if (cinfo->dither_mode == JDITHER_FS) {
|
||||||
size_t arraysize = (size_t) ((cinfo->output_width + 2) *
|
size_t arraysize = ((size_t) cinfo->output_width + (size_t) 2)
|
||||||
(3 * SIZEOF(FSERROR)));
|
* (3 * SIZEOF(FSERROR));
|
||||||
/* Allocate Floyd-Steinberg workspace if we didn't already. */
|
/* Allocate Floyd-Steinberg workspace if we didn't already. */
|
||||||
if (cquantize->fserrors == NULL)
|
if (cquantize->fserrors == NULL)
|
||||||
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
|
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
|
||||||
((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
|
((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
|
||||||
/* Initialize the propagated errors to zero. */
|
/* Initialize the propagated errors to zero. */
|
||||||
jzero_far((void FAR *) cquantize->fserrors, arraysize);
|
FMEMZERO((void FAR *) cquantize->fserrors, arraysize);
|
||||||
/* Make the error-limit table if we didn't already. */
|
/* Make the error-limit table if we didn't already. */
|
||||||
if (cquantize->error_limiter == NULL)
|
if (cquantize->error_limiter == NULL)
|
||||||
init_error_limit(cinfo);
|
init_error_limit(cinfo);
|
||||||
@@ -1214,8 +1215,8 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
|
|||||||
/* Zero the histogram or inverse color map, if necessary */
|
/* Zero the histogram or inverse color map, if necessary */
|
||||||
if (cquantize->needs_zeroed) {
|
if (cquantize->needs_zeroed) {
|
||||||
for (i = 0; i < HIST_C0_ELEMS; i++) {
|
for (i = 0; i < HIST_C0_ELEMS; i++) {
|
||||||
jzero_far((void FAR *) histogram[i],
|
FMEMZERO((void FAR *) histogram[i],
|
||||||
HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
|
HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
|
||||||
}
|
}
|
||||||
cquantize->needs_zeroed = FALSE;
|
cquantize->needs_zeroed = FALSE;
|
||||||
}
|
}
|
||||||
@@ -1246,10 +1247,9 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
|
|||||||
my_cquantize_ptr cquantize;
|
my_cquantize_ptr cquantize;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
cquantize = (my_cquantize_ptr)
|
cquantize = (my_cquantize_ptr) (*cinfo->mem->alloc_small)
|
||||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(my_cquantizer));
|
||||||
SIZEOF(my_cquantizer));
|
cinfo->cquantize = &cquantize->pub;
|
||||||
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
|
|
||||||
cquantize->pub.start_pass = start_pass_2_quant;
|
cquantize->pub.start_pass = start_pass_2_quant;
|
||||||
cquantize->pub.new_color_map = new_color_map_2_quant;
|
cquantize->pub.new_color_map = new_color_map_2_quant;
|
||||||
cquantize->fserrors = NULL; /* flag optional arrays not allocated */
|
cquantize->fserrors = NULL; /* flag optional arrays not allocated */
|
||||||
@@ -1283,7 +1283,8 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
|
|||||||
if (desired > MAXNUMCOLORS)
|
if (desired > MAXNUMCOLORS)
|
||||||
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
|
ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
|
||||||
cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
|
cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
|
||||||
((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
|
(JDIMENSION) desired, (JDIMENSION) 3);
|
||||||
cquantize->desired = desired;
|
cquantize->desired = desired;
|
||||||
} else
|
} else
|
||||||
cquantize->sv_colormap = NULL;
|
cquantize->sv_colormap = NULL;
|
||||||
@@ -1301,7 +1302,7 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
|
|||||||
if (cinfo->dither_mode == JDITHER_FS) {
|
if (cinfo->dither_mode == JDITHER_FS) {
|
||||||
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
|
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
|
||||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||||
(size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
|
((size_t) cinfo->output_width + (size_t) 2) * (3 * SIZEOF(FSERROR)));
|
||||||
/* Might as well create the error-limiting table too. */
|
/* Might as well create the error-limiting table too. */
|
||||||
init_error_limit(cinfo);
|
init_error_limit(cinfo);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+67
-74
@@ -2,7 +2,7 @@
|
|||||||
* jutils.c
|
* jutils.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||||
* Modified 2009 by Guido Vollbeding.
|
* Modified 2009-2020 by Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -52,67 +52,67 @@ const int jpeg_zigzag_order[DCTSIZE2] = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const int jpeg_natural_order[DCTSIZE2+16] = {
|
const int jpeg_natural_order[DCTSIZE2+16] = {
|
||||||
0, 1, 8, 16, 9, 2, 3, 10,
|
0, 1, 8, 16, 9, 2, 3, 10,
|
||||||
17, 24, 32, 25, 18, 11, 4, 5,
|
17, 24, 32, 25, 18, 11, 4, 5,
|
||||||
12, 19, 26, 33, 40, 48, 41, 34,
|
12, 19, 26, 33, 40, 48, 41, 34,
|
||||||
27, 20, 13, 6, 7, 14, 21, 28,
|
27, 20, 13, 6, 7, 14, 21, 28,
|
||||||
35, 42, 49, 56, 57, 50, 43, 36,
|
35, 42, 49, 56, 57, 50, 43, 36,
|
||||||
29, 22, 15, 23, 30, 37, 44, 51,
|
29, 22, 15, 23, 30, 37, 44, 51,
|
||||||
58, 59, 52, 45, 38, 31, 39, 46,
|
58, 59, 52, 45, 38, 31, 39, 46,
|
||||||
53, 60, 61, 54, 47, 55, 62, 63,
|
53, 60, 61, 54, 47, 55, 62, 63,
|
||||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||||
63, 63, 63, 63, 63, 63, 63, 63
|
63, 63, 63, 63, 63, 63, 63, 63
|
||||||
};
|
};
|
||||||
|
|
||||||
const int jpeg_natural_order7[7*7+16] = {
|
const int jpeg_natural_order7[7*7+16] = {
|
||||||
0, 1, 8, 16, 9, 2, 3, 10,
|
0, 1, 8, 16, 9, 2, 3, 10,
|
||||||
17, 24, 32, 25, 18, 11, 4, 5,
|
17, 24, 32, 25, 18, 11, 4, 5,
|
||||||
12, 19, 26, 33, 40, 48, 41, 34,
|
12, 19, 26, 33, 40, 48, 41, 34,
|
||||||
27, 20, 13, 6, 14, 21, 28, 35,
|
27, 20, 13, 6, 14, 21, 28, 35,
|
||||||
42, 49, 50, 43, 36, 29, 22, 30,
|
42, 49, 50, 43, 36, 29, 22, 30,
|
||||||
37, 44, 51, 52, 45, 38, 46, 53,
|
37, 44, 51, 52, 45, 38, 46, 53,
|
||||||
54,
|
54,
|
||||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||||
63, 63, 63, 63, 63, 63, 63, 63
|
63, 63, 63, 63, 63, 63, 63, 63
|
||||||
};
|
};
|
||||||
|
|
||||||
const int jpeg_natural_order6[6*6+16] = {
|
const int jpeg_natural_order6[6*6+16] = {
|
||||||
0, 1, 8, 16, 9, 2, 3, 10,
|
0, 1, 8, 16, 9, 2, 3, 10,
|
||||||
17, 24, 32, 25, 18, 11, 4, 5,
|
17, 24, 32, 25, 18, 11, 4, 5,
|
||||||
12, 19, 26, 33, 40, 41, 34, 27,
|
12, 19, 26, 33, 40, 41, 34, 27,
|
||||||
20, 13, 21, 28, 35, 42, 43, 36,
|
20, 13, 21, 28, 35, 42, 43, 36,
|
||||||
29, 37, 44, 45,
|
29, 37, 44, 45,
|
||||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||||
63, 63, 63, 63, 63, 63, 63, 63
|
63, 63, 63, 63, 63, 63, 63, 63
|
||||||
};
|
};
|
||||||
|
|
||||||
const int jpeg_natural_order5[5*5+16] = {
|
const int jpeg_natural_order5[5*5+16] = {
|
||||||
0, 1, 8, 16, 9, 2, 3, 10,
|
0, 1, 8, 16, 9, 2, 3, 10,
|
||||||
17, 24, 32, 25, 18, 11, 4, 12,
|
17, 24, 32, 25, 18, 11, 4, 12,
|
||||||
19, 26, 33, 34, 27, 20, 28, 35,
|
19, 26, 33, 34, 27, 20, 28, 35,
|
||||||
36,
|
36,
|
||||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||||
63, 63, 63, 63, 63, 63, 63, 63
|
63, 63, 63, 63, 63, 63, 63, 63
|
||||||
};
|
};
|
||||||
|
|
||||||
const int jpeg_natural_order4[4*4+16] = {
|
const int jpeg_natural_order4[4*4+16] = {
|
||||||
0, 1, 8, 16, 9, 2, 3, 10,
|
0, 1, 8, 16, 9, 2, 3, 10,
|
||||||
17, 24, 25, 18, 11, 19, 26, 27,
|
17, 24, 25, 18, 11, 19, 26, 27,
|
||||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||||
63, 63, 63, 63, 63, 63, 63, 63
|
63, 63, 63, 63, 63, 63, 63, 63
|
||||||
};
|
};
|
||||||
|
|
||||||
const int jpeg_natural_order3[3*3+16] = {
|
const int jpeg_natural_order3[3*3+16] = {
|
||||||
0, 1, 8, 16, 9, 2, 10, 17,
|
0, 1, 8, 16, 9, 2, 10, 17,
|
||||||
18,
|
18,
|
||||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||||
63, 63, 63, 63, 63, 63, 63, 63
|
63, 63, 63, 63, 63, 63, 63, 63
|
||||||
};
|
};
|
||||||
|
|
||||||
const int jpeg_natural_order2[2*2+16] = {
|
const int jpeg_natural_order2[2*2+16] = {
|
||||||
0, 1, 8, 9,
|
0, 1, 8, 9,
|
||||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||||
63, 63, 63, 63, 63, 63, 63, 63
|
63, 63, 63, 63, 63, 63, 63, 63
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -148,38 +148,49 @@ jround_up (long a, long b)
|
|||||||
* is not all that great, because these routines aren't very heavily used.)
|
* is not all that great, because these routines aren't very heavily used.)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
|
#ifndef NEED_FAR_POINTERS /* normal case, same as regular macro */
|
||||||
#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
|
#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
|
||||||
#define FMEMZERO(target,size) MEMZERO(target,size)
|
|
||||||
#else /* 80x86 case, define if we can */
|
#else /* 80x86 case, define if we can */
|
||||||
#ifdef USE_FMEM
|
#ifdef USE_FMEM
|
||||||
#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
|
#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
|
||||||
#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
|
#else
|
||||||
|
/* This function is for use by the FMEMZERO macro defined in jpegint.h.
|
||||||
|
* Do not call this function directly, use the FMEMZERO macro instead.
|
||||||
|
*/
|
||||||
|
GLOBAL(void)
|
||||||
|
jzero_far (void FAR * target, size_t bytestozero)
|
||||||
|
/* Zero out a chunk of FAR memory. */
|
||||||
|
/* This might be sample-array data, block-array data, or alloc_large data. */
|
||||||
|
{
|
||||||
|
register char FAR * ptr = (char FAR *) target;
|
||||||
|
register size_t count;
|
||||||
|
|
||||||
|
for (count = bytestozero; count > 0; count--) {
|
||||||
|
*ptr++ = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
GLOBAL(void)
|
GLOBAL(void)
|
||||||
jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
|
jcopy_sample_rows (JSAMPARRAY input_array,
|
||||||
JSAMPARRAY output_array, int dest_row,
|
JSAMPARRAY output_array,
|
||||||
int num_rows, JDIMENSION num_cols)
|
int num_rows, JDIMENSION num_cols)
|
||||||
/* Copy some rows of samples from one place to another.
|
/* Copy some rows of samples from one place to another.
|
||||||
* num_rows rows are copied from input_array[source_row++]
|
* num_rows rows are copied from *input_array++ to *output_array++;
|
||||||
* to output_array[dest_row++]; these areas may overlap for duplication.
|
* these areas may overlap for duplication.
|
||||||
* The source and destination arrays must be at least as wide as num_cols.
|
* The source and destination arrays must be at least as wide as num_cols.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
register JSAMPROW inptr, outptr;
|
register JSAMPROW inptr, outptr;
|
||||||
#ifdef FMEMCOPY
|
#ifdef FMEMCOPY
|
||||||
register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
|
register size_t count = (size_t) num_cols * SIZEOF(JSAMPLE);
|
||||||
#else
|
#else
|
||||||
register JDIMENSION count;
|
register JDIMENSION count;
|
||||||
#endif
|
#endif
|
||||||
register int row;
|
register int row;
|
||||||
|
|
||||||
input_array += source_row;
|
|
||||||
output_array += dest_row;
|
|
||||||
|
|
||||||
for (row = num_rows; row > 0; row--) {
|
for (row = num_rows; row > 0; row--) {
|
||||||
inptr = *input_array++;
|
inptr = *input_array++;
|
||||||
outptr = *output_array++;
|
outptr = *output_array++;
|
||||||
@@ -199,7 +210,7 @@ jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
|
|||||||
/* Copy a row of coefficient blocks from one place to another. */
|
/* Copy a row of coefficient blocks from one place to another. */
|
||||||
{
|
{
|
||||||
#ifdef FMEMCOPY
|
#ifdef FMEMCOPY
|
||||||
FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
|
FMEMCOPY(output_row, input_row, (size_t) num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
|
||||||
#else
|
#else
|
||||||
register JCOEFPTR inptr, outptr;
|
register JCOEFPTR inptr, outptr;
|
||||||
register long count;
|
register long count;
|
||||||
@@ -211,21 +222,3 @@ jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GLOBAL(void)
|
|
||||||
jzero_far (void FAR * target, size_t bytestozero)
|
|
||||||
/* Zero out a chunk of FAR memory. */
|
|
||||||
/* This might be sample-array data, block-array data, or alloc_large data. */
|
|
||||||
{
|
|
||||||
#ifdef FMEMZERO
|
|
||||||
FMEMZERO(target, bytestozero);
|
|
||||||
#else
|
|
||||||
register char FAR * ptr = (char FAR *) target;
|
|
||||||
register size_t count;
|
|
||||||
|
|
||||||
for (count = bytestozero; count > 0; count--) {
|
|
||||||
*ptr++ = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|||||||
Vendored
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* jversion.h
|
* jversion.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 1991-2011, Thomas G. Lane, Guido Vollbeding.
|
* Copyright (C) 1991-2022, Thomas G. Lane, Guido Vollbeding.
|
||||||
* This file is part of the Independent JPEG Group's software.
|
* This file is part of the Independent JPEG Group's software.
|
||||||
* For conditions of distribution and use, see the accompanying README file.
|
* For conditions of distribution and use, see the accompanying README file.
|
||||||
*
|
*
|
||||||
@@ -9,6 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define JVERSION "8c 16-Jan-2011"
|
#define JVERSION "9e 16-Jan-2022"
|
||||||
|
|
||||||
#define JCOPYRIGHT "Copyright (C) 2011, Thomas G. Lane, Guido Vollbeding"
|
#define JCOPYRIGHT "Copyright (C) 2022, Thomas G. Lane, Guido Vollbeding"
|
||||||
|
|||||||
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
prefix=@prefix@
|
||||||
|
exec_prefix=@exec_prefix@
|
||||||
|
libdir=@libdir@
|
||||||
|
includedir=@includedir@
|
||||||
|
|
||||||
|
Name: libjpeg
|
||||||
|
Description: Reads and writes JPEG files
|
||||||
|
Version: @JPEG_LIB_VERSION_MAJOR@.@[email protected]
|
||||||
|
Libs: -L${libdir} -ljpeg
|
||||||
|
Cflags: -I${includedir}
|
||||||
Vendored
+98
-72
@@ -1,6 +1,6 @@
|
|||||||
USING THE IJG JPEG LIBRARY
|
USING THE IJG JPEG LIBRARY
|
||||||
|
|
||||||
Copyright (C) 1994-2010, Thomas G. Lane, Guido Vollbeding.
|
Copyright (C) 1994-2019, Thomas G. Lane, Guido Vollbeding.
|
||||||
This file is part of the Independent JPEG Group's software.
|
This file is part of the Independent JPEG Group's software.
|
||||||
For conditions of distribution and use, see the accompanying README file.
|
For conditions of distribution and use, see the accompanying README file.
|
||||||
|
|
||||||
@@ -95,8 +95,8 @@ use.) Unsupported ISO options include:
|
|||||||
* Lossless JPEG
|
* Lossless JPEG
|
||||||
* DNL marker
|
* DNL marker
|
||||||
* Nonintegral subsampling ratios
|
* Nonintegral subsampling ratios
|
||||||
We support both 8- and 12-bit data precision, but this is a compile-time
|
We support 8-bit to 12-bit data precision, but this is a compile-time choice
|
||||||
choice rather than a run-time choice; hence it is difficult to use both
|
rather than a run-time choice; hence it is difficult to use different
|
||||||
precisions in a single application.
|
precisions in a single application.
|
||||||
|
|
||||||
By itself, the library handles only interchange JPEG datastreams --- in
|
By itself, the library handles only interchange JPEG datastreams --- in
|
||||||
@@ -225,7 +225,7 @@ For best results, source data values should have the precision specified by
|
|||||||
BITS_IN_JSAMPLE (normally 8 bits). For instance, if you choose to compress
|
BITS_IN_JSAMPLE (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
|
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
|
byte before passing it to the compressor. If you need to compress data
|
||||||
that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 12.
|
that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 9 to 12.
|
||||||
(See "Library compile-time options", later.)
|
(See "Library compile-time options", later.)
|
||||||
|
|
||||||
|
|
||||||
@@ -876,6 +876,10 @@ jpeg_simple_progression (j_compress_ptr cinfo)
|
|||||||
|
|
||||||
Compression parameters (cinfo fields) include:
|
Compression parameters (cinfo fields) include:
|
||||||
|
|
||||||
|
boolean arith_code
|
||||||
|
If TRUE, use arithmetic coding.
|
||||||
|
If FALSE, use Huffman coding.
|
||||||
|
|
||||||
int block_size
|
int block_size
|
||||||
Set DCT block size. All N from 1 to 16 are possible.
|
Set DCT block size. All N from 1 to 16 are possible.
|
||||||
Default is 8 (baseline format).
|
Default is 8 (baseline format).
|
||||||
@@ -916,7 +920,16 @@ J_COLOR_SPACE jpeg_color_space
|
|||||||
int num_components
|
int num_components
|
||||||
The JPEG color space and corresponding number of components; see
|
The JPEG color space and corresponding number of components; see
|
||||||
"Special color spaces", below, for more info. We recommend using
|
"Special color spaces", below, for more info. We recommend using
|
||||||
jpeg_set_color_space() if you want to change these.
|
jpeg_set_colorspace() if you want to change these.
|
||||||
|
|
||||||
|
J_COLOR_TRANSFORM color_transform
|
||||||
|
Internal color transform identifier, writes LSE marker if nonzero
|
||||||
|
(requires decoder with inverse color transform support, introduced
|
||||||
|
with IJG JPEG 9).
|
||||||
|
Two values are currently possible: JCT_NONE and JCT_SUBTRACT_GREEN.
|
||||||
|
Set this value for lossless RGB application *before* calling
|
||||||
|
jpeg_set_colorspace(), because entropy table assignment in
|
||||||
|
jpeg_set_colorspace() depends on color_transform.
|
||||||
|
|
||||||
boolean optimize_coding
|
boolean optimize_coding
|
||||||
TRUE causes the compressor to compute optimal Huffman coding tables
|
TRUE causes the compressor to compute optimal Huffman coding tables
|
||||||
@@ -1260,9 +1273,10 @@ Special color spaces
|
|||||||
The JPEG standard itself is "color blind" and doesn't specify any particular
|
The JPEG standard itself is "color blind" and doesn't specify any particular
|
||||||
color space. It is customary to convert color data to a luminance/chrominance
|
color space. It is customary to convert color data to a luminance/chrominance
|
||||||
color space before compressing, since this permits greater compression. The
|
color space before compressing, since this permits greater compression. The
|
||||||
existing de-facto JPEG file format standards specify YCbCr or grayscale data
|
existing JPEG file interchange format standards specify YCbCr or GRAYSCALE
|
||||||
(JFIF), or grayscale, RGB, YCbCr, CMYK, or YCCK (Adobe). For special
|
data (JFIF version 1), GRAYSCALE, RGB, YCbCr, CMYK, or YCCK (Adobe), or BG_RGB
|
||||||
applications such as multispectral images, other color spaces can be used,
|
or BG_YCC (big gamut color spaces, JFIF version 2). For special applications
|
||||||
|
such as multispectral images, other color spaces can be used,
|
||||||
but it must be understood that such files will be unportable.
|
but it must be understood that such files will be unportable.
|
||||||
|
|
||||||
The JPEG library can handle the most common colorspace conversions (namely
|
The JPEG library can handle the most common colorspace conversions (namely
|
||||||
@@ -1279,22 +1293,25 @@ jpeg_set_colorspace(). Of course you must select a supported transformation.
|
|||||||
jccolor.c currently supports the following transformations:
|
jccolor.c currently supports the following transformations:
|
||||||
RGB => YCbCr
|
RGB => YCbCr
|
||||||
RGB => GRAYSCALE
|
RGB => GRAYSCALE
|
||||||
|
RGB => BG_YCC
|
||||||
YCbCr => GRAYSCALE
|
YCbCr => GRAYSCALE
|
||||||
|
YCbCr => BG_YCC
|
||||||
CMYK => YCCK
|
CMYK => YCCK
|
||||||
plus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB,
|
plus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB,
|
||||||
YCbCr => YCbCr, CMYK => CMYK, YCCK => YCCK, and UNKNOWN => UNKNOWN.
|
BG_RGB => BG_RGB, YCbCr => YCbCr, BG_YCC => BG_YCC, CMYK => CMYK,
|
||||||
|
YCCK => YCCK, and UNKNOWN => UNKNOWN.
|
||||||
|
|
||||||
The de-facto file format standards (JFIF and Adobe) specify APPn markers that
|
The file interchange format standards (JFIF and Adobe) specify APPn markers
|
||||||
indicate the color space of the JPEG file. It is important to ensure that
|
that indicate the color space of the JPEG file. It is important to ensure
|
||||||
these are written correctly, or omitted if the JPEG file's color space is not
|
that these are written correctly, or omitted if the JPEG file's color space
|
||||||
one of the ones supported by the de-facto standards. jpeg_set_colorspace()
|
is not one of the ones supported by the interchange standards.
|
||||||
will set the compression parameters to include or omit the APPn markers
|
jpeg_set_colorspace() will set the compression parameters to include or omit
|
||||||
properly, so long as it is told the truth about the JPEG color space.
|
the APPn markers properly, so long as it is told the truth about the JPEG
|
||||||
For example, if you are writing some random 3-component color space without
|
color space. For example, if you are writing some random 3-component color
|
||||||
conversion, don't try to fake out the library by setting in_color_space and
|
space without conversion, don't try to fake out the library by setting
|
||||||
jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN. You may want to write an
|
in_color_space and jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN.
|
||||||
APPn marker of your own devising to identify the colorspace --- see "Special
|
You may want to write an APPn marker of your own devising to identify
|
||||||
markers", below.
|
the colorspace --- see "Special markers", below.
|
||||||
|
|
||||||
When told that the color space is UNKNOWN, the library will default to using
|
When told that the color space is UNKNOWN, the library will default to using
|
||||||
luminance-quality compression parameters for all color components. You may
|
luminance-quality compression parameters for all color components. You may
|
||||||
@@ -1310,8 +1327,11 @@ jpeg_read_header's guess by setting jpeg_color_space. jpeg_read_header also
|
|||||||
selects a default output color space based on (its guess of) jpeg_color_space;
|
selects a default output color space based on (its guess of) jpeg_color_space;
|
||||||
set out_color_space to override this. Again, you must select a supported
|
set out_color_space to override this. Again, you must select a supported
|
||||||
transformation. jdcolor.c currently supports
|
transformation. jdcolor.c currently supports
|
||||||
YCbCr => GRAYSCALE
|
|
||||||
YCbCr => RGB
|
YCbCr => RGB
|
||||||
|
YCbCr => GRAYSCALE
|
||||||
|
BG_YCC => RGB
|
||||||
|
BG_YCC => GRAYSCALE
|
||||||
|
RGB => GRAYSCALE
|
||||||
GRAYSCALE => RGB
|
GRAYSCALE => RGB
|
||||||
YCCK => CMYK
|
YCCK => CMYK
|
||||||
as well as the null transforms. (Since GRAYSCALE=>RGB is provided, an
|
as well as the null transforms. (Since GRAYSCALE=>RGB is provided, an
|
||||||
@@ -2571,10 +2591,10 @@ different sizes. If the image dimensions are not a multiple of the MCU size,
|
|||||||
you must also pad the data correctly (usually, this is done by replicating
|
you must also pad the data correctly (usually, this is done by replicating
|
||||||
the last column and/or row). The data must be padded to a multiple of a DCT
|
the last column and/or row). The data must be padded to a multiple of a DCT
|
||||||
block in each component: that is, each downsampled row must contain a
|
block in each component: that is, each downsampled row must contain a
|
||||||
multiple of 8 valid samples, and there must be a multiple of 8 sample rows
|
multiple of DCT_h_scaled_size valid samples, and there must be a multiple of
|
||||||
for each component. (For applications such as conversion of digital TV
|
DCT_v_scaled_size sample rows for each component. (For applications such as
|
||||||
images, the standard image size is usually a multiple of the DCT block size,
|
conversion of digital TV images, the standard image size is usually a
|
||||||
so that no padding need actually be done.)
|
multiple of the DCT block size, so that no padding need actually be done.)
|
||||||
|
|
||||||
The procedure for compression of raw data is basically the same as normal
|
The procedure for compression of raw data is basically the same as normal
|
||||||
compression, except that you call jpeg_write_raw_data() in place of
|
compression, except that you call jpeg_write_raw_data() in place of
|
||||||
@@ -2582,8 +2602,6 @@ jpeg_write_scanlines(). Before calling jpeg_start_compress(), you must do
|
|||||||
the following:
|
the following:
|
||||||
* Set cinfo->raw_data_in to TRUE. (It is set FALSE by jpeg_set_defaults().)
|
* Set cinfo->raw_data_in to TRUE. (It is set FALSE by jpeg_set_defaults().)
|
||||||
This notifies the library that you will be supplying raw data.
|
This notifies the library that you will be supplying raw data.
|
||||||
Furthermore, set cinfo->do_fancy_downsampling to FALSE if you want to use
|
|
||||||
real downsampled data. (It is set TRUE by jpeg_set_defaults().)
|
|
||||||
* Ensure jpeg_color_space is correct --- an explicit jpeg_set_colorspace()
|
* Ensure jpeg_color_space is correct --- an explicit jpeg_set_colorspace()
|
||||||
call is a good idea. Note that since color conversion is bypassed,
|
call is a good idea. Note that since color conversion is bypassed,
|
||||||
in_color_space is ignored, except that jpeg_set_defaults() uses it to
|
in_color_space is ignored, except that jpeg_set_defaults() uses it to
|
||||||
@@ -2600,23 +2618,25 @@ The scanlines count passed to and returned from jpeg_write_raw_data is
|
|||||||
measured in terms of the component with the largest v_samp_factor.
|
measured in terms of the component with the largest v_samp_factor.
|
||||||
|
|
||||||
jpeg_write_raw_data() processes one MCU row per call, which is to say
|
jpeg_write_raw_data() processes one MCU row per call, which is to say
|
||||||
v_samp_factor*DCTSIZE sample rows of each component. The passed num_lines
|
v_samp_factor*min_DCT_v_scaled_size sample rows of each component. The passed
|
||||||
value must be at least max_v_samp_factor*DCTSIZE, and the return value will
|
num_lines value must be at least max_v_samp_factor*min_DCT_v_scaled_size, and
|
||||||
be exactly that amount (or possibly some multiple of that amount, in future
|
the return value will be exactly that amount (or possibly some multiple of
|
||||||
library versions). This is true even on the last call at the bottom of the
|
that amount, in future library versions). This is true even on the last call
|
||||||
image; don't forget to pad your data as necessary.
|
at the bottom of the image; don't forget to pad your data as necessary.
|
||||||
|
|
||||||
The required dimensions of the supplied data can be computed for each
|
The required dimensions of the supplied data can be computed for each
|
||||||
component as
|
component as
|
||||||
cinfo->comp_info[i].width_in_blocks*DCTSIZE samples per row
|
cinfo->comp_info[i].width_in_blocks *
|
||||||
cinfo->comp_info[i].height_in_blocks*DCTSIZE rows in image
|
cinfo->comp_info[i].DCT_h_scaled_size samples per row
|
||||||
|
cinfo->comp_info[i].height_in_blocks *
|
||||||
|
cinfo->comp_info[i].DCT_v_scaled_size rows in image
|
||||||
after jpeg_start_compress() has initialized those fields. If the valid data
|
after jpeg_start_compress() has initialized those fields. If the valid data
|
||||||
is smaller than this, it must be padded appropriately. For some sampling
|
is smaller than this, it must be padded appropriately. For some sampling
|
||||||
factors and image sizes, additional dummy DCT blocks are inserted to make
|
factors and image sizes, additional dummy DCT blocks are inserted to make
|
||||||
the image a multiple of the MCU dimensions. The library creates such dummy
|
the image a multiple of the MCU dimensions. The library creates such dummy
|
||||||
blocks itself; it does not read them from your supplied data. Therefore you
|
blocks itself; it does not read them from your supplied data. Therefore you
|
||||||
need never pad by more than DCTSIZE samples. An example may help here.
|
need never pad by more than DCT_scaled_size samples.
|
||||||
Assume 2h2v downsampling of YCbCr data, that is
|
An example may help here. Assume 2h2v downsampling of YCbCr data, that is
|
||||||
cinfo->comp_info[0].h_samp_factor = 2 for Y
|
cinfo->comp_info[0].h_samp_factor = 2 for Y
|
||||||
cinfo->comp_info[0].v_samp_factor = 2
|
cinfo->comp_info[0].v_samp_factor = 2
|
||||||
cinfo->comp_info[1].h_samp_factor = 1 for Cb
|
cinfo->comp_info[1].h_samp_factor = 1 for Cb
|
||||||
@@ -2642,27 +2662,26 @@ destination module suspends, jpeg_write_raw_data() will return 0.
|
|||||||
In this case the same data rows must be passed again on the next call.
|
In this case the same data rows must be passed again on the next call.
|
||||||
|
|
||||||
|
|
||||||
Decompression with raw data output implies bypassing all postprocessing.
|
Decompression with raw data output implies bypassing all postprocessing:
|
||||||
You must deal with the color space and sampling factors present in the
|
you cannot ask for color quantization, for instance. More seriously, you
|
||||||
incoming file. If your application only handles, say, 2h1v YCbCr data,
|
must deal with the color space and sampling factors present in the incoming
|
||||||
you must check for and fail on other color spaces or other sampling factors.
|
file. If your application only handles, say, 2h1v YCbCr data, you must
|
||||||
|
check for and fail on other color spaces or other sampling factors.
|
||||||
The library will not convert to a different color space for you.
|
The library will not convert to a different color space for you.
|
||||||
|
|
||||||
To obtain raw data output, set cinfo->raw_data_out = TRUE before
|
To obtain raw data output, set cinfo->raw_data_out = TRUE before
|
||||||
jpeg_start_decompress() (it is set FALSE by jpeg_read_header()). Be sure to
|
jpeg_start_decompress() (it is set FALSE by jpeg_read_header()). Be sure to
|
||||||
verify that the color space and sampling factors are ones you can handle.
|
verify that the color space and sampling factors are ones you can handle.
|
||||||
Furthermore, set cinfo->do_fancy_upsampling = FALSE if you want to get real
|
|
||||||
downsampled data (it is set TRUE by jpeg_read_header()).
|
|
||||||
Then call jpeg_read_raw_data() in place of jpeg_read_scanlines(). The
|
Then call jpeg_read_raw_data() in place of jpeg_read_scanlines(). The
|
||||||
decompression process is otherwise the same as usual.
|
decompression process is otherwise the same as usual.
|
||||||
|
|
||||||
jpeg_read_raw_data() returns one MCU row per call, and thus you must pass a
|
jpeg_read_raw_data() returns one MCU row per call, and thus you must pass a
|
||||||
buffer of at least max_v_samp_factor*DCTSIZE scanlines (scanline counting is
|
buffer of at least max_v_samp_factor*min_DCT_v_scaled_size scanlines (scanline
|
||||||
the same as for raw-data compression). The buffer you pass must be large
|
counting is the same as for raw-data compression). The buffer you pass must
|
||||||
enough to hold the actual data plus padding to DCT-block boundaries. As with
|
be large enough to hold the actual data plus padding to DCT-block boundaries.
|
||||||
compression, any entirely dummy DCT blocks are not processed so you need not
|
As with compression, any entirely dummy DCT blocks are not processed so you
|
||||||
allocate space for them, but the total scanline count includes them. The
|
need not allocate space for them, but the total scanline count includes them.
|
||||||
above example of computing buffer dimensions for raw-data compression is
|
The above example of computing buffer dimensions for raw-data compression is
|
||||||
equally valid for decompression.
|
equally valid for decompression.
|
||||||
|
|
||||||
Input suspension is supported with raw-data decompression: if the data source
|
Input suspension is supported with raw-data decompression: if the data source
|
||||||
@@ -2914,10 +2933,10 @@ This does not count any memory allocated by the application, such as a
|
|||||||
buffer to hold the final output image.
|
buffer to hold the final output image.
|
||||||
|
|
||||||
The above figures are valid for 8-bit JPEG data precision and a machine with
|
The above figures are valid for 8-bit JPEG data precision and a machine with
|
||||||
32-bit ints. For 12-bit JPEG data, double the size of the strip buffers and
|
32-bit ints. For 9-bit to 12-bit JPEG data, double the size of the strip
|
||||||
quantization pixel buffer. The "fixed-size" data will be somewhat smaller
|
buffers and quantization pixel buffer. The "fixed-size" data will be
|
||||||
with 16-bit ints, larger with 64-bit ints. Also, CMYK or other unusual
|
somewhat smaller with 16-bit ints, larger with 64-bit ints. Also, CMYK
|
||||||
color spaces will require different amounts of space.
|
or other unusual color spaces will require different amounts of space.
|
||||||
|
|
||||||
The full-image coefficient and pixel buffers, if needed at all, do not
|
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
|
have to be fully RAM resident; you can have the library use temporary
|
||||||
@@ -2939,27 +2958,34 @@ Library compile-time options
|
|||||||
|
|
||||||
A number of compile-time options are available by modifying jmorecfg.h.
|
A number of compile-time options are available by modifying jmorecfg.h.
|
||||||
|
|
||||||
The JPEG standard provides for both the baseline 8-bit DCT process and
|
The IJG code currently supports 8-bit to 12-bit sample data precision by
|
||||||
a 12-bit DCT process. The IJG code supports 12-bit lossy JPEG if you define
|
defining BITS_IN_JSAMPLE as 8, 9, 10, 11, or 12.
|
||||||
BITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be
|
Note that a value larger than 8 causes JSAMPLE to be larger than a char,
|
||||||
larger than a char, so it affects the surrounding application's image data.
|
so it affects the surrounding application's image data.
|
||||||
The sample applications cjpeg and djpeg can support 12-bit mode only for PPM
|
The sample applications cjpeg and djpeg can support deeper than 8-bit data
|
||||||
and GIF file formats; you must disable the other file formats to compile a
|
only for PPM and GIF file formats; you must disable the other file formats
|
||||||
12-bit cjpeg or djpeg. (install.txt has more information about that.)
|
to compile a 9-bit to 12-bit cjpeg or djpeg. (install.txt has more
|
||||||
At present, a 12-bit library can handle *only* 12-bit images, not both
|
information about that.)
|
||||||
precisions. (If you need to include both 8- and 12-bit libraries in a single
|
Run-time selection and conversion of data precision are currently not
|
||||||
application, you could probably do it by defining NEED_SHORT_EXTERNAL_NAMES
|
supported and may be added later.
|
||||||
for just one of the copies. You'd have to access the 8-bit and 12-bit copies
|
Exception: The transcoding part (jpegtran) supports all settings in a
|
||||||
from separate application source files. This is untested ... if you try it,
|
single instance, since it operates on the level of DCT coefficients and
|
||||||
we'd like to hear whether it works!)
|
not sample values.
|
||||||
|
(If you need to include an 8-bit library and a 9-bit to 12-bit library for
|
||||||
|
compression or decompression in a single application, you could probably do
|
||||||
|
it by defining NEED_SHORT_EXTERNAL_NAMES for just one of the copies. You'd
|
||||||
|
have to access the 8-bit and the 9-bit to 12-bit copies from separate
|
||||||
|
application source files. This is untested ... if you try it, we'd like to
|
||||||
|
hear whether it works!)
|
||||||
|
|
||||||
Note that a 12-bit library always compresses in Huffman optimization mode,
|
Note that the standard Huffman tables are only valid for 8-bit data precision.
|
||||||
in order to generate valid Huffman tables. This is necessary because our
|
If you selected more than 8-bit data precision, cjpeg uses arithmetic coding
|
||||||
default Huffman tables only cover 8-bit data. If you need to output 12-bit
|
by default. The Huffman encoder normally uses entropy optimization to
|
||||||
files in one pass, you'll have to supply suitable default Huffman tables.
|
compute usable tables for higher precision. Otherwise, you'll have to
|
||||||
You may also want to supply your own DCT quantization tables; the existing
|
supply different default Huffman tables. You may also want to supply your
|
||||||
quality-scaling code has been developed for 8-bit use, and probably doesn't
|
own DCT quantization tables; the existing quality-scaling code has been
|
||||||
generate especially good tables for 12-bit.
|
developed for 8-bit use, and probably doesn't generate especially good tables
|
||||||
|
for 9-bit to 12-bit.
|
||||||
|
|
||||||
The maximum number of components (color channels) in the image is determined
|
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
|
by MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we
|
||||||
|
|||||||
Vendored
+11147
File diff suppressed because it is too large
Load Diff
Vendored
+36
@@ -0,0 +1,36 @@
|
|||||||
|
; Project file for Independent JPEG Group's software
|
||||||
|
;
|
||||||
|
; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.
|
||||||
|
; Thanks to Frank Moehle, B. Setzepfandt, and Guido Vollbeding.
|
||||||
|
;
|
||||||
|
; To use this file, rename it to cjpeg.prj.
|
||||||
|
; If you are using Turbo C, change filenames beginning with "pc..." to "tc..."
|
||||||
|
; Read installation instructions before trying to make the program!
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; * * * Output file * * *
|
||||||
|
cjpeg.ttp
|
||||||
|
;
|
||||||
|
; * * * COMPILER OPTIONS * * *
|
||||||
|
.C[-P] ; absolute calls
|
||||||
|
.C[-M] ; and no string merging, folks
|
||||||
|
.C[-w-cln] ; no "constant is long" warnings
|
||||||
|
.C[-w-par] ; no "parameter xxxx unused"
|
||||||
|
.C[-w-rch] ; no "unreachable code"
|
||||||
|
.C[-wsig] ; warn if significant digits may be lost
|
||||||
|
=
|
||||||
|
; * * * * List of modules * * * *
|
||||||
|
pcstart.o
|
||||||
|
cjpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,jversion.h)
|
||||||
|
cdjpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
rdswitch.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
rdppm.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
rdgif.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
rdtarga.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
rdbmp.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
rdrle.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
libjpeg.lib ; built by libjpeg.prj
|
||||||
|
pcfltlib.lib ; floating point library
|
||||||
|
; the float library can be omitted if you've turned off DCT_FLOAT_SUPPORTED
|
||||||
|
pcstdlib.lib ; standard library
|
||||||
|
pcextlib.lib ; extended library
|
||||||
Vendored
+36
@@ -0,0 +1,36 @@
|
|||||||
|
; Project file for Independent JPEG Group's software
|
||||||
|
;
|
||||||
|
; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.
|
||||||
|
; Thanks to Frank Moehle, B. Setzepfandt, and Guido Vollbeding.
|
||||||
|
;
|
||||||
|
; To use this file, rename it to djpeg.prj.
|
||||||
|
; If you are using Turbo C, change filenames beginning with "pc..." to "tc..."
|
||||||
|
; Read installation instructions before trying to make the program!
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; * * * Output file * * *
|
||||||
|
djpeg.ttp
|
||||||
|
;
|
||||||
|
; * * * COMPILER OPTIONS * * *
|
||||||
|
.C[-P] ; absolute calls
|
||||||
|
.C[-M] ; and no string merging, folks
|
||||||
|
.C[-w-cln] ; no "constant is long" warnings
|
||||||
|
.C[-w-par] ; no "parameter xxxx unused"
|
||||||
|
.C[-w-rch] ; no "unreachable code"
|
||||||
|
.C[-wsig] ; warn if significant digits may be lost
|
||||||
|
=
|
||||||
|
; * * * * List of modules * * * *
|
||||||
|
pcstart.o
|
||||||
|
djpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,jversion.h)
|
||||||
|
cdjpeg.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
rdcolmap.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
wrppm.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
wrgif.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
wrtarga.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
wrbmp.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
wrrle.c (cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)
|
||||||
|
libjpeg.lib ; built by libjpeg.prj
|
||||||
|
pcfltlib.lib ; floating point library
|
||||||
|
; the float library can be omitted if you've turned off DCT_FLOAT_SUPPORTED
|
||||||
|
pcstdlib.lib ; standard library
|
||||||
|
pcextlib.lib ; extended library
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user