diff options
| author | Antonin Descampe <antonin@gmail.com> | 2010-10-05 10:33:15 +0000 |
|---|---|---|
| committer | Antonin Descampe <antonin@gmail.com> | 2010-10-05 10:33:15 +0000 |
| commit | eeefefd56cb3edddefb73141733fd1e757c4b798 (patch) | |
| tree | 4727958764c4c348762c043c2efbb7470a9ffcca /libopenjpeg | |
| parent | 531c0cf26f0c327b42a5caa79725e4afeb98768d (diff) | |
Added files to let people build openjpeg with configure tools ; Added makefiles to let people manually build openjpeg on *nix platforms ; Removed obsolete Makefiles ; Renamed dirent.h to windirent.h ; Made optional the PNG, TIFF, and LCMS support in CMake files ; Added opj_config* files to configure openjpeg before building it (opj_config.h generated by configure, cmake, or manually by the user) ; Renamed this file from ChangeLog to CHANGES ; Renamed License.txt to LICENSE ; Updated README files ; Added INSTALL and LICENSE files ; Added man pages
Diffstat (limited to 'libopenjpeg')
| -rw-r--r-- | libopenjpeg/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | libopenjpeg/Makefile.am | 80 | ||||
| -rw-r--r-- | libopenjpeg/Makefile.in | 653 | ||||
| -rw-r--r-- | libopenjpeg/jp2.c | 768 | ||||
| -rw-r--r-- | libopenjpeg/jp2.h | 42 | ||||
| -rw-r--r-- | libopenjpeg/openjpeg.c | 3 | ||||
| -rw-r--r-- | libopenjpeg/openjpeg.h | 1 | ||||
| -rw-r--r-- | libopenjpeg/opj_convert.c | 315 | ||||
| -rw-r--r-- | libopenjpeg/opj_convert.h | 6 | ||||
| -rw-r--r-- | libopenjpeg/t2.c | 3 |
10 files changed, 1765 insertions, 109 deletions
diff --git a/libopenjpeg/CMakeLists.txt b/libopenjpeg/CMakeLists.txt index d7096bd6..c1719b7b 100644 --- a/libopenjpeg/CMakeLists.txt +++ b/libopenjpeg/CMakeLists.txt @@ -19,8 +19,11 @@ SET(OPENJPEG_SRCS t2.c tcd.c tgt.c + opj_convert.c ) +INCLUDE_DIRECTORIES( ${LCMS_INCLUDE_DIR} ) + # Pass proper definition to preprocessor to generate shared lib IF(WIN32) IF(BUILD_SHARED_LIBS) diff --git a/libopenjpeg/Makefile.am b/libopenjpeg/Makefile.am new file mode 100644 index 00000000..ddf909db --- /dev/null +++ b/libopenjpeg/Makefile.am @@ -0,0 +1,80 @@ +MAJOR = @MAJOR_NR@ +MINOR = @MINOR_NR@ +BUILD = @BUILD_NR@ +CURRENT=`expr $(MAJOR) + $(MINOR)` + +lib_LTLIBRARIES = libopenjpeg.la + +INCLUDES = -I.. -I. + +libopenjpeg_la_LDFLAGS = -no-undefined \ + -version-info $(CURRENT):$(BUILD):$(MINOR) + +libopenjpeg_la_LIBADD = @LDLIBS@ + +#Cygwin needs this: +if with_libjpwl +libopenjpeg_la_LIBADD += ../jpwl/libopenjpeg_JPWL.la +endif + +SRCS = bio.c cio.c dwt.c event.c image.c j2k.c j2k_lib.c jp2.c jpt.c \ + mct.c mqc.c openjpeg.c pi.c raw.c t1.c t2.c tcd.c tgt.c opj_convert.c + +INCLS = bio.h cio.h dwt.h event.h fix.h image.h int.h j2k.h j2k_lib.h \ + jp2.h jpt.h mct.h mqc.h pi.h raw.h t1.h t2.h tcd.h tgt.h opj_malloc.h \ + opj_convert.h opj_includes.h + +libopenjpeg_la_SOURCES = $(SRCS) $(INCLS) + +includedir = ${prefix}/include/openjpeg-$(MAJOR).$(MINOR) +include_HEADERS = openjpeg.h + +# Converts cr/lf to just lf +DOS2UNIX = dos2unix + +dos2unix: + @$(DOS2UNIX) $(SRCS) $(INCLS) + +COMPILERFLAGS = -Wall -O3 -ffast-math -std=c99 + +if with_libjpwl +COMPILERFLAGS += -DUSE_JPWL +endif + +if with_liblcms1 +INCLUDES += @lcms1includes@ +endif + +if with_liblcms2 +INCLUDES += @lcms2includes@ +endif + +CFLAGS = $(COMPILERFLAGS) $(INCLUDES) + +headerdir = openjpeg-$(MAJOR).$(MINOR) + +all-local: + @$(INSTALL) -d ../bin + @cp -d .libs/libopenjpeg.* ../bin/ + @rm -f ../bin/libopenjpeg.la* + @rm -rf .report_lib + @$(INSTALL) -d .report_lib + @cp -d .libs/libopenjpeg.* .report_lib + @rm -f .report_lib/libopenjpeg.lai + @echo "" > .report.txt + @echo "Installing: ${prefix}/include/${headerdir}/" >> .report.txt + @echo "Installing: ${prefix}/include/${headerdir}/openjpeg.h" >> .report.txt + @(cd .report_lib; \ + l=`ls --file-type`; \ + for f in $$l ; do \ + echo "Installing: ${prefix}/lib/$$f" >> ../.report.txt ; \ + done) + @rm -rf .report_lib + +install-data-hook: + (cd $(DESTDIR)${prefix}/include && rm -f openjpeg.h) + (cd $(DESTDIR)${prefix}/include && \ + $(LN_S) ${headerdir}/openjpeg.h openjpeg.h) + +uninstall-hook: + (cd $(DESTDIR)${prefix}/include && rm -rf openjpeg.h ${headerdir}) diff --git a/libopenjpeg/Makefile.in b/libopenjpeg/Makefile.in new file mode 100644 index 00000000..85162713 --- /dev/null +++ b/libopenjpeg/Makefile.in @@ -0,0 +1,653 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ + +#Cygwin needs this: +@with_libjpwl_TRUE@am__append_1 = ../jpwl/libopenjpeg_JPWL.la +@with_libjpwl_TRUE@am__append_2 = -DUSE_JPWL +@with_liblcms1_TRUE@am__append_3 = @lcms1includes@ +@with_liblcms2_TRUE@am__append_4 = @lcms2includes@ +subdir = libopenjpeg +DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/opj_config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)" +LTLIBRARIES = $(lib_LTLIBRARIES) +libopenjpeg_la_DEPENDENCIES = $(am__append_1) +am__objects_1 = bio.lo cio.lo dwt.lo event.lo image.lo j2k.lo \ + j2k_lib.lo jp2.lo jpt.lo mct.lo mqc.lo openjpeg.lo pi.lo \ + raw.lo t1.lo t2.lo tcd.lo tgt.lo opj_convert.lo +am__objects_2 = +am_libopenjpeg_la_OBJECTS = $(am__objects_1) $(am__objects_2) +libopenjpeg_la_OBJECTS = $(am_libopenjpeg_la_OBJECTS) +libopenjpeg_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libopenjpeg_la_LDFLAGS) $(LDFLAGS) -o $@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libopenjpeg_la_SOURCES) +DIST_SOURCES = $(libopenjpeg_la_SOURCES) +HEADERS = $(include_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BUILD_NR = @BUILD_NR@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = $(COMPILERFLAGS) $(INCLUDES) +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JP3D_BUILD_NR = @JP3D_BUILD_NR@ +JP3D_MAJOR_NR = @JP3D_MAJOR_NR@ +JP3D_MINOR_NR = @JP3D_MINOR_NR@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LDLIBS = @LDLIBS@ +LIBOBJS = @LIBOBJS@ +LIBPNG_CONFIG = @LIBPNG_CONFIG@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAJOR_NR = @MAJOR_NR@ +MAKEINFO = @MAKEINFO@ +MINOR_NR = @MINOR_NR@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKGCONFIG = @PKGCONFIG@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +doxy_dir = @doxy_dir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = ${prefix}/include/openjpeg-$(MAJOR).$(MINOR) +infodir = @infodir@ +install_sh = @install_sh@ +jp3d_dir = @jp3d_dir@ +jpwl_dir = @jpwl_dir@ +lcms1includes = @lcms1includes@ +lcms1libs = @lcms1libs@ +lcms2includes = @lcms2includes@ +lcms2libs = @lcms2libs@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pngincludes = @pngincludes@ +pnglibs = @pnglibs@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +tiffincludes = @tiffincludes@ +tifflibs = @tifflibs@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +with_doxygen = @with_doxygen@ +MAJOR = @MAJOR_NR@ +MINOR = @MINOR_NR@ +BUILD = @BUILD_NR@ +CURRENT = `expr $(MAJOR) + $(MINOR)` +lib_LTLIBRARIES = libopenjpeg.la +INCLUDES = -I.. -I. $(am__append_3) $(am__append_4) +libopenjpeg_la_LDFLAGS = -no-undefined \ + -version-info $(CURRENT):$(BUILD):$(MINOR) + +libopenjpeg_la_LIBADD = @LDLIBS@ $(am__append_1) +SRCS = bio.c cio.c dwt.c event.c image.c j2k.c j2k_lib.c jp2.c jpt.c \ + mct.c mqc.c openjpeg.c pi.c raw.c t1.c t2.c tcd.c tgt.c opj_convert.c + +INCLS = bio.h cio.h dwt.h event.h fix.h image.h int.h j2k.h j2k_lib.h \ + jp2.h jpt.h mct.h mqc.h pi.h raw.h t1.h t2.h tcd.h tgt.h opj_malloc.h \ + opj_convert.h opj_includes.h + +libopenjpeg_la_SOURCES = $(SRCS) $(INCLS) +include_HEADERS = openjpeg.h + +# Converts cr/lf to just lf +DOS2UNIX = dos2unix +COMPILERFLAGS = -Wall -O3 -ffast-math -std=c99 $(am__append_2) +headerdir = openjpeg-$(MAJOR).$(MINOR) +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libopenjpeg/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign libopenjpeg/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ + } + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libopenjpeg.la: $(libopenjpeg_la_OBJECTS) $(libopenjpeg_la_DEPENDENCIES) + $(libopenjpeg_la_LINK) -rpath $(libdir) $(libopenjpeg_la_OBJECTS) $(libopenjpeg_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dwt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/event.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/image.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/j2k.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/j2k_lib.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jp2.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/jpt.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mct.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mqc.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/openjpeg.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/opj_convert.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pi.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/raw.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t1.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/t2.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcd.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tgt.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-includeHEADERS: $(include_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(includedir)" || $(MKDIR_P) "$(DESTDIR)$(includedir)" + @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \ + done + +uninstall-includeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(includedir)" && rm -f $$files + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) all-local +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-includeHEADERS + @$(NORMAL_INSTALL) + $(MAKE) $(AM_MAKEFLAGS) install-data-hook +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES + @$(NORMAL_INSTALL) + $(MAKE) $(AM_MAKEFLAGS) uninstall-hook +.MAKE: install-am install-data-am install-strip uninstall-am + +.PHONY: CTAGS GTAGS all all-am all-local check check-am clean \ + clean-generic clean-libLTLIBRARIES clean-libtool ctags \ + distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-data-hook install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-includeHEADERS install-info install-info-am \ + install-libLTLIBRARIES install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-hook \ + uninstall-includeHEADERS uninstall-libLTLIBRARIES + + +dos2unix: + @$(DOS2UNIX) $(SRCS) $(INCLS) + +all-local: + @$(INSTALL) -d ../bin + @cp -d .libs/libopenjpeg.* ../bin/ + @rm -f ../bin/libopenjpeg.la* + @rm -rf .report_lib + @$(INSTALL) -d .report_lib + @cp -d .libs/libopenjpeg.* .report_lib + @rm -f .report_lib/libopenjpeg.lai + @echo "" > .report.txt + @echo "Installing: ${prefix}/include/${headerdir}/" >> .report.txt + @echo "Installing: ${prefix}/include/${headerdir}/openjpeg.h" >> .report.txt + @(cd .report_lib; \ + l=`ls --file-type`; \ + for f in $$l ; do \ + echo "Installing: ${prefix}/lib/$$f" >> ../.report.txt ; \ + done) + @rm -rf .report_lib + +install-data-hook: + (cd $(DESTDIR)${prefix}/include && rm -f openjpeg.h) + (cd $(DESTDIR)${prefix}/include && \ + $(LN_S) ${headerdir}/openjpeg.h openjpeg.h) + +uninstall-hook: + (cd $(DESTDIR)${prefix}/include && rm -rf openjpeg.h ${headerdir}) + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libopenjpeg/jp2.c b/libopenjpeg/jp2.c index b2831cfb..449466b4 100644 --- a/libopenjpeg/jp2.c +++ b/libopenjpeg/jp2.c @@ -28,8 +28,17 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - +#include <opj_config.h> +#ifdef HAVE_LIBLCMS2 +#include <math.h> +#include <lcms2.h> +#endif +#ifdef HAVE_LIBLCMS1 +#include <math.h> +#include <lcms.h> +#endif #include "opj_includes.h" +#include "opj_convert.h" /** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */ /*@{*/ @@ -57,7 +66,6 @@ static void jp2_write_ihdr(opj_jp2_t *jp2, opj_cio_t *cio); static void jp2_write_bpcc(opj_jp2_t *jp2, opj_cio_t *cio); static bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio); static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio); -static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio); /** Write the FTYP box - File type box @param jp2 JP2 handle @@ -87,7 +95,8 @@ Decode the structure of a JP2 file @param cio Input buffer stream @return Returns true if successful, returns false otherwise */ -static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio); +static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio, + struct extension *ext); /*@}*/ @@ -258,42 +267,664 @@ static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio) { cio_seek(cio, box.init_pos + box.length); } -static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio) { - opj_jp2_box_t box; +static void jp2_free_pclr(struct extension *ext) +{ + opj_free(ext->jp2_pclr->channel_sign); + opj_free(ext->jp2_pclr->channel_size); + opj_free(ext->jp2_pclr->entries); + + if(ext->jp2_pclr->cmap) opj_free(ext->jp2_pclr->cmap); + + opj_free(ext->jp2_pclr); ext->jp2_pclr = NULL; +} + +static void free_ext_data(struct extension *ext) +{ + if(ext->jp2_pclr) + { + jp2_free_pclr(ext); + } + if(ext->jp2_cdef) + { + if(ext->jp2_cdef->info) opj_free(ext->jp2_cdef->info); + opj_free(ext->jp2_cdef); + } + if(ext->jp2_profile_buf) opj_free(ext->jp2_profile_buf); +} + +static void jp2_apply_pclr(struct extension *ext, opj_image_t *image) +{ + opj_image_comp_t *old_comps, *new_comps; + unsigned char *channel_size, *channel_sign; + unsigned int *entries; + opj_jp2_cmap_comp_t *cmap; + int *src, *dst; + unsigned int j, max; + unsigned short i, nr_channels, cmp, pcol; + int k, top_k; + + channel_size = ext->jp2_pclr->channel_size; + channel_sign = ext->jp2_pclr->channel_sign; + entries = ext->jp2_pclr->entries; + cmap = ext->jp2_pclr->cmap; + nr_channels = ext->jp2_pclr->nr_channels; + + old_comps = image->comps; + new_comps = (opj_image_comp_t*) + opj_malloc(nr_channels * sizeof(opj_image_comp_t)); + + for(i = 0; i < nr_channels; ++i) + { + pcol = cmap[i].pcol; cmp = cmap[i].cmp; + + new_comps[pcol] = old_comps[cmp]; + + if(cmap[i].mtyp == 0) /* Direct use */ + { + old_comps[cmp].data = NULL; continue; + } +/* Palette mapping: */ + new_comps[pcol].data = (int*) + opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(int)); + new_comps[pcol].prec = channel_size[i]; + new_comps[pcol].sgnd = channel_sign[i]; + } + top_k = ext->jp2_pclr->nr_entries - 1; + + for(i = 0; i < nr_channels; ++i) + { +/* Direct use: */ + if(cmap[i].mtyp == 0) continue; + +/* Palette mapping: */ + cmp = cmap[i].cmp; pcol = cmap[i].pcol; + src = old_comps[cmp].data; + dst = new_comps[pcol].data; + max = new_comps[pcol].w * new_comps[pcol].h; + + for(j = 0; j < max; ++j) + { +/* The index */ + if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; +/* The colour */ + dst[j] = entries[k * nr_channels + pcol]; + } + } + max = image->numcomps; + for(i = 0; i < max; ++i) + { + if(old_comps[i].data) opj_free(old_comps[i].data); + } + opj_free(old_comps); + image->comps = new_comps; + image->numcomps = nr_channels; + + jp2_free_pclr(ext); + +}/* apply_pclr() */ + +static bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, struct extension *ext) +{ + opj_jp2_pclr_t *jp2_pclr; + unsigned char *channel_size, *channel_sign; + unsigned int *entries; + unsigned short nr_entries, nr_channels; + unsigned short i, j; + unsigned char uc; + +/* Part 1, I.5.3.4: 'There shall be at most one Palette box inside + * a JP2 Header box' : +*/ + if(ext->jp2_pclr) return false; + + nr_entries = cio_read(cio, 2); /* NE */ + nr_channels = cio_read(cio, 1);/* NPC */ + + entries = (unsigned int*) + opj_malloc(nr_channels * nr_entries * sizeof(unsigned int)); + channel_size = (unsigned char*)opj_malloc(nr_channels); + channel_sign = (unsigned char*)opj_malloc(nr_channels); + + jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t)); + jp2_pclr->channel_sign = channel_sign; + jp2_pclr->channel_size = channel_size; + jp2_pclr->entries = entries; + jp2_pclr->nr_entries = nr_entries; + jp2_pclr->nr_channels = nr_channels; + jp2_pclr->cmap = NULL; + + ext->jp2_pclr = jp2_pclr; + + for(i = 0; i < nr_channels; ++i) + { + uc = cio_read(cio, 1); /* Bi */ + channel_size[i] = (uc & 0x7f) + 1; + channel_sign[i] = (uc & 0x80)?1:0; + } + + for(j = 0; j < nr_entries; ++j) + { + for(i = 0; i < nr_channels; ++i) + { +/* Cji */ + *entries++ = cio_read(cio, channel_size[i]>>3); + } + } + + return true; +}/* jp2_read_pclr() */ + +static bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, struct extension *ext) +{ + opj_jp2_cmap_comp_t *cmap; + unsigned short i, nr_channels; + +/* Need nr_channels: */ + if(ext->jp2_pclr == NULL) return false; + +/* Part 1, I.5.3.5: 'There shall be at most one Component Mapping box + * inside a JP2 Header box' : +*/ + if(ext->jp2_pclr->cmap) return false; + + nr_channels = ext->jp2_pclr->nr_channels; + cmap = (opj_jp2_cmap_comp_t*) + opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t)); + + for(i = 0; i < nr_channels; ++i) + { + cmap[i].cmp = cio_read(cio, 2); + cmap[i].mtyp = cio_read(cio, 1); + cmap[i].pcol = cio_read(cio, 1); + + } + ext->jp2_pclr->cmap = cmap; + + return true; +}/* jp2_read_cmap() */ + +static void jp2_apply_cdef(opj_image_t *image, struct extension *ext) +{ + opj_jp2_cdef_info_t *info; + int color_space; + unsigned short i, n, cn, typ, asoc, acn; + + color_space = image->color_space; + info = ext->jp2_cdef->info; + n = ext->jp2_cdef->n; + + for(i = 0; i < n; ++i) + { +/* WATCH: acn = asoc - 1 ! */ + if((asoc = info[i].asoc) == 0) continue; + + cn = info[i].cn; typ = info[i].typ; acn = asoc - 1; + + if(cn != acn) + { + opj_image_comp_t saved; + + memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t)); + memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t)); + memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t)); + + info[i].asoc = cn + 1; + info[acn].asoc = info[acn].cn + 1; + } + } + if(ext->jp2_cdef->info) opj_free(ext->jp2_cdef->info); + + opj_free(ext->jp2_cdef); ext->jp2_cdef = NULL; + +}/* jp2_apply_cdef() */ + +static bool jp2_read_cdef(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, struct extension *ext) +{ + opj_jp2_cdef_info_t *info; + unsigned short i, n; + +/* Part 1, I.5.3.6: 'The shall be at most one Channel Definition box + * inside a JP2 Header box.' +*/ + if(ext->jp2_cdef) return false; + + if((n = cio_read(cio, 2)) == 0) return false; /* szukw000: FIXME */ + + info = (opj_jp2_cdef_info_t*) + opj_malloc(n * sizeof(opj_jp2_cdef_info_t)); + + ext->jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)); + ext->jp2_cdef->info = info; + ext->jp2_cdef->n = n; + + for(i = 0; i < n; ++i) + { + info[i].cn = cio_read(cio, 2); + info[i].typ = cio_read(cio, 2); + info[i].asoc = cio_read(cio, 2); + + } + return true; +}/* jp2_read_cdef() */ + +static bool jp2_read_colr(opj_jp2_t *jp2, opj_cio_t *cio, + opj_jp2_box_t *box, struct extension *ext) +{ int skip_len; - opj_common_ptr cinfo = jp2->cinfo; +/* Part 1, I.5.3.3 : 'A conforming JP2 reader shall ignore all Colour + * Specification boxes after the first.' +*/ + if(ext->jp2_has_colr) return false; - jp2_read_boxhdr(cinfo, cio, &box); - do { - if (JP2_COLR != box.type) { - cio_skip(cio, box.length - 8); - jp2_read_boxhdr(cinfo, cio, &box); - } - } while(JP2_COLR != box.type); + opj_common_ptr cinfo = jp2->cinfo; jp2->meth = cio_read(cio, 1); /* METH */ jp2->precedence = cio_read(cio, 1); /* PRECEDENCE */ jp2->approx = cio_read(cio, 1); /* APPROX */ - if (jp2->meth == 1) { - jp2->enumcs = cio_read(cio, 4); /* EnumCS */ - } else { - /* skip PROFILE */ - skip_len = box.init_pos + box.length - cio_tell(cio); - if (skip_len < 0) { - opj_event_msg(cinfo, EVT_ERROR, "Error with JP2H box size\n"); - return false; - } - cio_skip(cio, box.init_pos + box.length - cio_tell(cio)); - } + if (jp2->meth == 1) + { + jp2->enumcs = cio_read(cio, 4); /* EnumCS */ + } + else + { +/* skip PROFILE */ + skip_len = box->init_pos + box->length - cio_tell(cio); + if (skip_len < 0) + { + opj_event_msg(cinfo, EVT_ERROR, "Error with COLR box size\n"); + return false; + } + if(skip_len > 0) + { + unsigned char *start; + + start = cio_getbp(cio); + ext->jp2_profile_buf = (unsigned char*)opj_malloc(skip_len); + ext->jp2_profile_len = skip_len; + + cio_skip(cio, box->init_pos + box->length - cio_tell(cio)); + + memcpy(ext->jp2_profile_buf, start, skip_len); + } + } + + if (cio_tell(cio) - box->init_pos != box->length) + { + opj_event_msg(cinfo, EVT_ERROR, "Error with COLR Box\n"); + return false; + } + ext->jp2_has_colr = 1; - if (cio_tell(cio) - box.init_pos != box.length) { - opj_event_msg(cinfo, EVT_ERROR, "Error with BPCC Box\n"); - return false; - } return true; -} +}/* jp2_read_colr() */ + +#if defined(HAVE_LIBLCMS2) || defined(HAVE_LIBLCMS1) +#ifdef HAVE_LIBLCMS1 +/* Bob Friesenhahn proposed:*/ +#define cmsSigXYZData icSigXYZData +#define cmsSigLabData icSigLabData +#define cmsSigCmykData icSigCmykData +#define cmsSigYCbCrData icSigYCbCrData +#define cmsSigLuvData icSigLuvData +#define cmsSigGrayData icSigGrayData +#define cmsSigRgbData icSigRgbData +#define cmsUInt32Number DWORD + +#define cmsColorSpaceSignature icColorSpaceSignature +#define cmsGetHeaderRenderingIntent cmsTakeRenderingIntent + +#endif /* HAVE_LIBLCMS1 */ + +static void jp2_apply_profile(struct extension *ext, opj_image_t *image) +{ + cmsHPROFILE in_prof, out_prof; + cmsHTRANSFORM transform; + cmsColorSpaceSignature in_space, out_space; + cmsUInt32Number intent, in_type, out_type, nr_samples; + int *r, *g, *b; + int prec, i, max, max_w, max_h; + OPJ_COLOR_SPACE oldspace; + + in_prof = + cmsOpenProfileFromMem(ext->jp2_profile_buf, ext->jp2_profile_len); + in_space = cmsGetPCS(in_prof); + out_space = cmsGetColorSpace(in_prof); + intent = cmsGetHeaderRenderingIntent(in_prof); + + + max_w = image->comps[0].w; max_h = image->comps[0].h; + prec = image->comps[0].prec; + oldspace = image->color_space; + + if(out_space == cmsSigRgbData) /* enumCS 16 */ + { + in_type = TYPE_RGB_16; + out_type = TYPE_RGB_16; + out_prof = cmsCreate_sRGBProfile(); + image->color_space = CLRSPC_SRGB; + } + else + if(out_space == cmsSigGrayData) /* enumCS 17 */ + { + in_type = TYPE_GRAY_8; + out_type = TYPE_RGB_8; + out_prof = cmsCreate_sRGBProfile(); + image->color_space = CLRSPC_SRGB; + } + else + if(out_space == cmsSigYCbCrData) /* enumCS 18 */ + { + in_type = TYPE_YCbCr_16; + out_type = TYPE_RGB_16; + out_prof = cmsCreate_sRGBProfile(); + image->color_space = CLRSPC_SRGB; + } + else + { +#ifdef DEBUG_PROFILE +fprintf(stderr,"%s:%d: jp2_apply_profile\n\tICC Profile has unknown " +"output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n", +__FILE__,__LINE__,out_space, +(out_space>>24) & 0xff,(out_space>>16) & 0xff, +(out_space>>8) & 0xff, out_space & 0xff); +#endif + return; + } + +#ifdef DEBUG_PROFILE +fprintf(stderr,"%s:%d:jp2_apply_profile\n\tchannels(%d) prec(%d) w(%d) h(%d)" +"\n\tprofile: in(%p) out(%p)\n",__FILE__,__LINE__,image->numcomps,prec, +max_w,max_h, (void*)in_prof,(void*)out_prof); + +fprintf(stderr,"\trender_intent (%u)\n\t" +"color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t" +" type: in(%u) out:(%u)\n", +intent, +in_space, +(in_space>>24) & 0xff,(in_space>>16) & 0xff, +(in_space>>8) & 0xff, in_space & 0xff, + +out_space, +(out_space>>24) & 0xff,(out_space>>16) & 0xff, +(out_space>>8) & 0xff, out_space & 0xff, + +in_type,out_type + ); +#endif /* DEBUG_PROFILE */ + + transform = cmsCreateTransform(in_prof, in_type, + out_prof, out_type, intent, 0); + +#ifdef HAVE_LIBLCMS2 +/* Possible for: LCMS_VERSION >= 2000 :*/ + cmsCloseProfile(in_prof); + cmsCloseProfile(out_prof); +#endif + + if(transform == NULL) + { +#ifdef DEBUG_PROFILE +fprintf(stderr,"%s:%d:jp2_apply_profile\n\tcmsCreateTransform failed. " +"ICC Profile ignored.\n",__FILE__,__LINE__); +#endif + image->color_space = oldspace; +#ifdef HAVE_LIBLCMS1 + cmsCloseProfile(in_prof); + cmsCloseProfile(out_prof); +#endif + return; + } + + if(image->numcomps > 2)/* RGB, RGBA */ + { + unsigned short *inbuf, *outbuf, *in, *out; + max = max_w * max_h; nr_samples = max * 3 * sizeof(unsigned short); + in = inbuf = (unsigned short*)opj_malloc(nr_samples); + out = outbuf = (unsigned short*)opj_malloc(nr_samples); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for(i = 0; i < max; ++i) + { + *in++ = (unsigned short)*r++; + *in++ = (unsigned short)*g++; + *in++ = (unsigned short)*b++; + } + + cmsDoTransform(transform, inbuf, outbuf, max); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for(i = 0; i < max; ++i) + { + *r++ = (int)*out++; + *g++ = (int)*out++; + *b++ = (int)*out++; + } + opj_free(inbuf); opj_free(outbuf); + } + else /* GRAY, GRAYA */ + { + unsigned char *in, *inbuf, *out, *outbuf; + + max = max_w * max_h; nr_samples = max * 3 * sizeof(unsigned char); + in = inbuf = (unsigned char*)opj_malloc(nr_samples); + out = outbuf = (unsigned char*)opj_malloc(nr_samples); + + image->comps = (opj_image_comp_t*) + opj_realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); + + if(image->numcomps == 2) + image->comps[3] = image->comps[1]; + + image->comps[1] = image->comps[0]; + image->comps[2] = image->comps[0]; + + image->comps[1].data = (int*)opj_calloc(max, sizeof(int)); + image->comps[2].data = (int*)opj_calloc(max, sizeof(int)); + + image->numcomps += 2; + + r = image->comps[0].data; + + for(i = 0; i < max; ++i) + { + *in++ = (unsigned char)*r++; + } + cmsDoTransform(transform, inbuf, outbuf, max); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for(i = 0; i < max; ++i) + { + *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; + } + opj_free(inbuf); opj_free(outbuf); + + }/* if(image->numcomps */ + + cmsDeleteTransform(transform); + +#ifdef HAVE_LIBLCMS1 + cmsCloseProfile(in_prof); + cmsCloseProfile(out_prof); +#endif +}/* jp2_apply_profile() */ + +#endif /* HAVE_LIBLCMS2 || HAVE_LIBLCMS1 */ + +bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, struct extension *ext) +{ + opj_jp2_box_t box; + unsigned int jp2h_end; + + opj_common_ptr cinfo = jp2->cinfo; + + jp2_read_boxhdr(cinfo, cio, &box); + do + { + if (JP2_JP2H != box.type) + { + if (box.type == JP2_JP2C) + { + opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n"); + return false; + } + cio_skip(cio, box.length - 8); + + if(cio->bp >= cio->end) return false; + + jp2_read_boxhdr(cinfo, cio, &box); + } + } while(JP2_JP2H != box.type); + + if (!jp2_read_ihdr(jp2, cio)) + return false; + jp2h_end = box.init_pos + box.length; + + if (jp2->bpc == 255) + { + if (!jp2_read_bpcc(jp2, cio)) + return false; + } + jp2_read_boxhdr(cinfo, cio, &box); + + while(cio_tell(cio) < jp2h_end) + { + if(box.type == JP2_COLR) + { + if( !jp2_read_colr(jp2, cio, &box, ext)) + { + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + } + jp2_read_boxhdr(cinfo, cio, &box); + continue; + } + if(box.type == JP2_CDEF) + { + if( !jp2_read_cdef(jp2, cio, &box, ext)) + { + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + } + jp2_read_boxhdr(cinfo, cio, &box); + continue; + } + if(box.type == JP2_PCLR) + { + if( !jp2_read_pclr(jp2, cio, &box, ext)) + { + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + } + jp2_read_boxhdr(cinfo, cio, &box); + continue; + } + if(box.type == JP2_CMAP) + { + if( !jp2_read_cmap(jp2, cio, &box, ext)) + { + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + } + jp2_read_boxhdr(cinfo, cio, &box); + continue; + } + cio_seek(cio, box.init_pos + 8); + cio_skip(cio, box.length - 8); + jp2_read_boxhdr(cinfo, cio, &box); + + }/* while(cio_tell(cio) < box_end) */ + + cio_seek(cio, jp2h_end); + +/* Part 1, I.5.3.3 : 'must contain at least one' */ + return (ext->jp2_has_colr == 1); + +}/* jp2_read_jp2h() */ + +opj_image_t* jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, + opj_codestream_info_t *cstr_info) +{ + opj_common_ptr cinfo; + opj_image_t *image = NULL; + struct extension ext; + + if(!jp2 || !cio) + { + return NULL; + } + memset(&ext, 0, sizeof(struct extension)); + cinfo = jp2->cinfo; + +/* JP2 decoding */ + if(!jp2_read_struct(jp2, cio, &ext)) + { + free_ext_data(&ext); + opj_event_msg(cinfo, EVT_ERROR, "Failed to decode jp2 structure\n"); + return NULL; + } + +/* J2K decoding */ + image = j2k_decode(jp2->j2k, cio, cstr_info); + + if(!image) + { + free_ext_data(&ext); + opj_event_msg(cinfo, EVT_ERROR, "Failed to decode J2K image\n"); + return NULL; + } + +/* Set Image Color Space */ + if (jp2->enumcs == 16) + image->color_space = CLRSPC_SRGB; + else if (jp2->enumcs == 17) + image->color_space = CLRSPC_GRAY; + else if (jp2->enumcs == 18) + image->color_space = CLRSPC_SYCC; + else + image->color_space = CLRSPC_UNKNOWN; + + if(ext.jp2_cdef) + { + jp2_apply_cdef(image, &ext); + } + if(ext.jp2_pclr) + { +/* Part 1, I.5.3.4: Either both or none : */ + if( !ext.jp2_pclr->cmap) + jp2_free_pclr(&ext); + else + jp2_apply_pclr(&ext, image); + } + if(ext.jp2_profile_buf) + { +#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) + jp2_apply_profile(&ext, image); +#endif + opj_free(ext.jp2_profile_buf); + } + else + if(image->color_space == CLRSPC_SYCC) + { + opj_convert_sycc_to_rgb(image); + } + return image; + +}/* jp2_decode() */ + void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) { opj_jp2_box_t box; @@ -315,44 +946,6 @@ void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) { cio_seek(cio, box.init_pos + box.length); } -bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) { - opj_jp2_box_t box; - int skip_len; - - opj_common_ptr cinfo = jp2->cinfo; - - jp2_read_boxhdr(cinfo, cio, &box); - do { - if (JP2_JP2H != box.type) { - if (box.type == JP2_JP2C) { - opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n"); - return false; - } - cio_skip(cio, box.length - 8); - jp2_read_boxhdr(cinfo, cio, &box); - } - } while(JP2_JP2H != box.type); - - if (!jp2_read_ihdr(jp2, cio)) - return false; - - if (jp2->bpc == 255) { - if (!jp2_read_bpcc(jp2, cio)) - return false; - } - if (!jp2_read_colr(jp2, cio)) - return false; - - skip_len = box.init_pos + box.length - cio_tell(cio); - if (skip_len < 0) { - opj_event_msg(cinfo, EVT_ERROR, "Error with JP2H Box\n"); - return false; - } - cio_skip(cio, box.init_pos + box.length - cio_tell(cio)); - - return true; -} - static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) { unsigned int i; opj_jp2_box_t box; @@ -489,12 +1082,13 @@ static bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio) { } -static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio) { +static bool jp2_read_struct(opj_jp2_t *jp2, opj_cio_t *cio, + struct extension *ext) { if (!jp2_read_jp(jp2, cio)) return false; if (!jp2_read_ftyp(jp2, cio)) return false; - if (!jp2_read_jp2h(jp2, cio)) + if (!jp2_read_jp2h(jp2, cio, ext)) return false; if (!jp2_read_jp2c(jp2, cio, &jp2->j2k_codestream_length, &jp2->j2k_codestream_offset)) return false; @@ -541,42 +1135,6 @@ void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) { /* further JP2 initializations go here */ } -opj_image_t* jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_t *cstr_info) { - opj_common_ptr cinfo; - opj_image_t *image = NULL; - - if(!jp2 || !cio) { - return NULL; - } - - cinfo = jp2->cinfo; - - /* JP2 decoding */ - if(!jp2_read_struct(jp2, cio)) { - opj_event_msg(cinfo, EVT_ERROR, "Failed to decode jp2 structure\n"); - return NULL; - } - - /* J2K decoding */ - image = j2k_decode(jp2->j2k, cio, cstr_info); - if(!image) { - opj_event_msg(cinfo, EVT_ERROR, "Failed to decode J2K image\n"); - return NULL; - } - - /* Set Image Color Space */ - if (jp2->enumcs == 16) - image->color_space = CLRSPC_SRGB; - else if (jp2->enumcs == 17) - image->color_space = CLRSPC_GRAY; - else if (jp2->enumcs == 18) - image->color_space = CLRSPC_SYCC; - else - image->color_space = CLRSPC_UNKNOWN; - - return image; -} - /* ----------------------------------------------------------------------- */ /* JP2 encoder interface */ /* ----------------------------------------------------------------------- */ diff --git a/libopenjpeg/jp2.h b/libopenjpeg/jp2.h index 7e363be2..e9ce242a 100644 --- a/libopenjpeg/jp2.h +++ b/libopenjpeg/jp2.h @@ -49,8 +49,48 @@ #define JP2_DBTL 0x6474626c /**< ??? */ #define JP2_BPCC 0x62706363 /**< Bits per component box */ #define JP2_JP2 0x6a703220 /**< File type fields */ +#define JP2_PCLR 0x70636c72 +#define JP2_CMAP 0x636d6170 +#define JP2_CDEF 0x63646566 /* ----------------------------------------------------------------------- */ +/* cdef, cmap, pclr, colr +*/ +typedef struct opj_jp2_cdef_info +{ + unsigned short cn, typ, asoc; +} opj_jp2_cdef_info_t; + +typedef struct opj_jp2_cdef +{ + opj_jp2_cdef_info_t *info; + unsigned short n; +} opj_jp2_cdef_t; + +typedef struct opj_jp2_cmap_comp +{ + unsigned short cmp; + unsigned char mtyp, pcol; +} opj_jp2_cmap_comp_t; + +typedef struct opj_jp2_pclr +{ + unsigned int *entries; + unsigned char *channel_sign; + unsigned char *channel_size; + opj_jp2_cmap_comp_t *cmap; + unsigned short nr_entries, nr_channels; +} opj_jp2_pclr_t; + +struct extension +{ + unsigned char *jp2_profile_buf; + int jp2_profile_len; + + opj_jp2_cdef_t *jp2_cdef; + opj_jp2_pclr_t *jp2_pclr; + unsigned char jp2_has_colr; +}; /** JP2 component @@ -113,7 +153,7 @@ Read the JP2H box - JP2 Header box (used in MJ2) @param cio Input buffer stream @return Returns true if successful, returns false otherwise */ -bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio); +bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, struct extension *ext); /** Creates a JP2 decompression structure @param cinfo Codec context info diff --git a/libopenjpeg/openjpeg.c b/libopenjpeg/openjpeg.c index 565c5caa..99866b8a 100644 --- a/libopenjpeg/openjpeg.c +++ b/libopenjpeg/openjpeg.c @@ -1,3 +1,4 @@ +#include <opj_config.h> /* * Copyright (c) 2005, Hervé Drolon, FreeImage Team * All rights reserved. @@ -54,7 +55,7 @@ DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { const char* OPJ_CALLCONV opj_version(void) { - return OPENJPEG_VERSION; + return PACKAGE_VERSION; } opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) { diff --git a/libopenjpeg/openjpeg.h b/libopenjpeg/openjpeg.h index 288f788e..b2ade89c 100644 --- a/libopenjpeg/openjpeg.h +++ b/libopenjpeg/openjpeg.h @@ -32,7 +32,6 @@ #ifndef OPENJPEG_H #define OPENJPEG_H -#define OPENJPEG_VERSION "1.3.0" /* ========================================================== diff --git a/libopenjpeg/opj_convert.c b/libopenjpeg/opj_convert.c new file mode 100644 index 00000000..33216655 --- /dev/null +++ b/libopenjpeg/opj_convert.c @@ -0,0 +1,315 @@ +#include "opj_includes.h" +#include "opj_convert.h" +/* + * The yuv code is based on cinelerra-VERSION/quicktime/rtjpeg_core.c +*/ +#define KcrR 76284 +#define KcrG 53281 +#define KcbG 25625 +#define KcbB 132252 +#define Ky 76284 + +static void opj_convert_yuv444(opj_image_t *img) +{ + int *d0, *d1, *d2, *red, *green, *blue; + const int *sY, *sCb, *sCr; + int maxw, maxh, max, i; + int R, G, B, C, D, E; + int shiftR, shiftG, shiftB; + int addR, addG, addB; + + maxw = img->comps[0].w; maxh = img->comps[0].h; + max = maxw * maxh; + + sY = img->comps[0].data; + sCb = img->comps[1].data; + sCr = img->comps[2].data; + + if(img->comps[0].prec > 8) + shiftR = img->comps[0].prec - 8; + else + shiftR = 0; + + if(img->comps[1].prec > 8) + shiftG = img->comps[1].prec - 8; + else + shiftG = 0; + + if(img->comps[2].prec > 8) + shiftB = img->comps[2].prec - 8; + else + shiftB = 0; + + addR = (img->comps[0].sgnd ? 1 << (img->comps[0].prec - 1) : 0); + addG = (img->comps[1].sgnd ? 1 << (img->comps[1].prec - 1) : 0); + addB = (img->comps[2].sgnd ? 1 << (img->comps[2].prec - 1) : 0); + + d0 = red = (int*)opj_malloc(sizeof(int) * max); + d1 = green = (int*)opj_malloc(sizeof(int) * max); + d2 = blue = (int*)opj_malloc(sizeof(int) * max); + + for(i = 0; i < max; ++i) + { + C = ((*sY++ + addR) >> shiftR) - 16; + D = ((*sCb++ + addG) >> shiftG) - 128; + E = ((*sCr++ + addB) >> shiftB) - 128; + + + R = (298 * C + 409 * E + 128)>>8; + if(R < 0) R = 0; else if(R > 255) R = 255; + + G = (298 * C - 100 * D - 208 * E + 128)>>8; + if(G < 0) G = 0; else if(G > 255) G = 255; + + B = (298 * C + 516 * D + 128)>>8; + if(B < 0) B = 0; else if(B > 255) B = 255; + + *d0++ = R; *d1++ = G; *d2++ = B; + + } + opj_free(img->comps[0].data); img->comps[0].data = red; + opj_free(img->comps[1].data); img->comps[1].data = green; + opj_free(img->comps[2].data); img->comps[2].data = blue; + + img->comps[0].prec = 8; img->comps[1].prec = 8; img->comps[2].prec = 8; +}/* opj_convert_yuv444() */ + +static void yuv422rgb(int *src_y, int *src_cb, int *src_cr, int *red, + int *green, int *blue, int width, int height) +{ + int i, j, tmp; + int y, crR, crG, cbG, cbB; + + for(i=0; i<height; i++) + { + for(j=0; j<width; j+=2) + { + crR=(*src_cr - 128)*KcrR; + crG=(*src_cr - 128)*KcrG; ++src_cr; + cbG=(*src_cb - 128)*KcbG; + cbB=(*src_cb - 128)*KcbB; ++src_cb; + + y=(src_y[j]-16)*Ky; + + tmp=(y+crR)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *red++ = tmp; + + tmp=(y-crG-cbG)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *green++ = tmp; + + tmp=(y+cbB)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *blue = tmp; + + y=(src_y[j+1]-16)*Ky; + + tmp=(y+crR)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *red++ = tmp; + + tmp=(y-crG-cbG)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *green++ = tmp; + + tmp=(y+cbB)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *blue++ = tmp; + } + src_y += width; + } +}/* yuv422rgb() */ + +static void yuv420rgb(const int *src_y, const int *src_cb, + const int *src_cr, int *red, int *green, int *blue, + int width, int height) +{ + int *red_e, *green_e, *blue_e, *red_o, *green_o, *blue_o; + int y, crR, crG, cbG, cbB, i, j, tmp; + int yskip; + + yskip = width; + red_e = red; green_e = green; blue_e = blue; + red_o = red + width; green_o = green + width; blue_o = blue + width; + + for(i=0; i < (height>>1); i++) + { + for(j=0; j < width; j+=2) + { + crR=(*src_cr-128)*KcrR; + crG=(*(src_cr++)-128)*KcrG; + cbG=(*src_cb-128)*KcbG; + cbB=(*(src_cb++)-128)*KcbB; + + y=(src_y[j]-16)*Ky; + + tmp=(y+crR)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *red_e++ = tmp;//*(bufoute++)=(tmp>255)?255:((tmp<0)?0:tmp); + + tmp=(y-crG-cbG)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *green_e++ = tmp;//*(bufoute++)=(tmp>255)?255:((tmp<0)?0:tmp); + + tmp=(y+cbB)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *blue_e++ = tmp;//*(bufoute++)=(tmp>255)?255:((tmp<0)?0:tmp); + + y=(src_y[j+1]-16)*Ky; + + tmp=(y+crR)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *red_e++ = tmp;//*(bufoute++)=(tmp>255)?255:((tmp<0)?0:tmp); + + tmp=(y-crG-cbG)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *green_e++ = tmp;//*(bufoute++)=(tmp>255)?255:((tmp<0)?0:tmp); + + tmp=(y+cbB)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *blue_e++ = tmp;//*(bufoute++)=(tmp>255)?255:((tmp<0)?0:tmp); + + y=(src_y[j+yskip]-16)*Ky; + + tmp=(y+crR)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *red_o++ = tmp;//*(bufouto++)=(tmp>255)?255:((tmp<0)?0:tmp); + + tmp=(y-crG-cbG)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *green_o++ = tmp;//*(bufouto++)=(tmp>255)?255:((tmp<0)?0:tmp); + + tmp=(y+cbB)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *blue_o++ = tmp;//*(bufouto++)=(tmp>255)?255:((tmp<0)?0:tmp); + + y=(src_y[j+1+yskip]-16)*Ky; + + tmp=(y+crR)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *red_o++ = tmp;//*(bufouto++)=(tmp>255)?255:((tmp<0)?0:tmp); + + tmp=(y-crG-cbG)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *green_o++ = tmp;//*(bufouto++)=(tmp>255)?255:((tmp<0)?0:tmp); + + tmp=(y+cbB)>>16; + if(tmp < 0) tmp = 0; else if(tmp > 255) tmp = 255; + *blue_o++ = tmp;//*(bufouto++)=(tmp>255)?255:((tmp<0)?0:tmp); + + } + red_e += width; green_e += width; blue_e += width; + red_o += width; green_o += width; blue_o += width; + src_y += width<<1; + } +}/* yuv420rgb() */ + +static void opj_convert_yuv422(opj_image_t *img) +{ + int *y, *cb, *cr, *red, *green, *blue; + int maxy, maxw, maxh; + + maxw = img->comps[0].w; maxh = img->comps[0].h; + maxy = maxw * maxh; + + y = img->comps[0].data; + cb = img->comps[1].data; + cr = img->comps[2].data; + +//YUV422 -> YUV444 -> RGB + red = (int*)opj_calloc(sizeof(int), maxy); + green = (int*)opj_calloc(sizeof(int), maxy); + blue = (int*)opj_calloc(sizeof(int), maxy); + + yuv422rgb(y, cb, cr, red, green, blue, maxw, maxh); + + opj_free(img->comps[0].data); img->comps[0].data = red; + opj_free(img->comps[1].data); img->comps[1].data = green; + opj_free(img->comps[2].data); img->comps[2].data = blue; + + img->comps[1].w = maxw; img->comps[2].h = maxh; + img->comps[1].dx = img->comps[0].dx; + img->comps[2].dx = img->comps[0].dx; + img->comps[1].dy = img->comps[0].dy; + img->comps[2].dy = img->comps[0].dy; + + img->comps[0].prec = 8; img->comps[1].prec = 8; img->comps[2].prec = 8; +} + +static void opj_convert_yuv420(opj_image_t *img) +{ + int *y, *cb, *cr, *red, *green, *blue; + int maxy, maxw, maxh; + + maxw = img->comps[0].w; maxh = img->comps[0].h; + maxy = maxw * maxh; + + y = img->comps[0].data; + cb = img->comps[1].data; + cr = img->comps[2].data; + +//YUV420 -> YUV422 -> YUV444 -> RGB + red = (int*)opj_calloc(sizeof(int), maxy); + green = (int*)opj_calloc(sizeof(int), maxy); + blue = (int*)opj_calloc(sizeof(int), maxy); + + yuv420rgb(y, cb, cr, red, green, blue, maxw, maxh); + + opj_free(img->comps[0].data); img->comps[0].data = red; + opj_free(img->comps[1].data); img->comps[1].data = green; + opj_free(img->comps[2].data); img->comps[2].data = blue; + + img->comps[1].w = maxw; img->comps[2].h = maxh; + img->comps[1].dx = img->comps[0].dx; + img->comps[2].dx = img->comps[0].dx; + img->comps[1].dy = img->comps[0].dy; + img->comps[2].dy = img->comps[0].dy; + + img->comps[0].prec = 8; img->comps[1].prec = 8; img->comps[2].prec = 8; +} + +void opj_convert_sycc_to_rgb(opj_image_t *img) +{ + if(img->numcomps < 3) + { + img->color_space = CLRSPC_GRAY; + return; + } + if((img->comps[0].dx == 1) + && (img->comps[1].dx == 2) + && (img->comps[2].dx == 2) + && (img->comps[0].dy == 1) + && (img->comps[1].dy == 2) + && (img->comps[2].dy == 2))// horizontal and vertical + { + opj_convert_yuv420(img); + } + else + if((img->comps[0].dx == 1) + && (img->comps[1].dx == 2) + && (img->comps[2].dx == 2) + && (img->comps[0].dy == 1) + && (img->comps[1].dy == 1) + && (img->comps[2].dy == 1))// horizontal only + { + opj_convert_yuv422(img); + } + else + if((img->comps[0].dx == 1) + && (img->comps[1].dx == 1) + && (img->comps[2].dx == 1) + && (img->comps[0].dy == 1) + && (img->comps[1].dy == 1) + && (img->comps[2].dy == 1)) + { + opj_convert_yuv444(img); + } + else + { +fprintf(stderr,"%s:%d:opj_convert_sycc_to_rgb\n\tCAN NOT CONVERT\n", +__FILE__,__LINE__); + return; + } + img->color_space = CLRSPC_SRGB; +}/* opj_convert_sycc_to_rgb() */ diff --git a/libopenjpeg/opj_convert.h b/libopenjpeg/opj_convert.h new file mode 100644 index 00000000..029072c2 --- /dev/null +++ b/libopenjpeg/opj_convert.h @@ -0,0 +1,6 @@ +#ifndef _OPJ_CONVERT_H_ +#define _OPJ_CONVERT_H_ + +extern void opj_convert_sycc_to_rgb(opj_image_t *img); + +#endif /* _OPJ_CONVERT_H_ */ diff --git a/libopenjpeg/t2.c b/libopenjpeg/t2.c index a76f4ed2..102104fe 100644 --- a/libopenjpeg/t2.c +++ b/libopenjpeg/t2.c @@ -494,6 +494,7 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t if (tcp->csty & J2K_CP_CSTY_EPH) { if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n"); + return -999; } else { hd += 2; } @@ -711,7 +712,7 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj } else { e = 0; } - + if(e == -999) return -999; /* progression in resolution */ image->comps[pi[pino].compno].resno_decoded = (e > 0) ? |
