Compare commits
60 Commits
version.2.
...
v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6cb0c86e2 | ||
|
|
a937c91694 | ||
|
|
c49becae30 | ||
|
|
9e0e3611c5 | ||
|
|
9fba123a7a | ||
|
|
fef7d00dc8 | ||
|
|
a916dcd052 | ||
|
|
cc01949777 | ||
|
|
287be4e683 | ||
|
|
dea5c48227 | ||
|
|
68e1771ae5 | ||
|
|
6ab100903e | ||
|
|
3e5715a994 | ||
|
|
9f446c88e8 | ||
|
|
2f9e80da9c | ||
|
|
871cd3968f | ||
|
|
e5bfc65137 | ||
|
|
315179c719 | ||
|
|
cab60a170d | ||
|
|
889aa9227b | ||
|
|
8dcd3318c2 | ||
|
|
f71e6e7879 | ||
|
|
3a44c91ea3 | ||
|
|
786dee8782 | ||
|
|
5badc82fa9 | ||
|
|
ecd70f033c | ||
|
|
0c69d6e1a8 | ||
|
|
306e58761a | ||
|
|
eb1baa78fc | ||
|
|
414b680e53 | ||
|
|
b1342da5c5 | ||
|
|
27850206b5 | ||
|
|
5bffbfc638 | ||
|
|
49f47e2b00 | ||
|
|
1f348833dd | ||
|
|
f509865242 | ||
|
|
173ad641aa | ||
|
|
3b28bfcb3c | ||
|
|
04c131a315 | ||
|
|
40c092bbc3 | ||
|
|
576f380eba | ||
|
|
8a634d0fe3 | ||
|
|
f9e6b81176 | ||
|
|
a346da0599 | ||
|
|
b2d22d6bc0 | ||
|
|
73b4d32638 | ||
|
|
67b5ab3c04 | ||
|
|
935baae8fc | ||
|
|
324c949cfd | ||
|
|
dc9459029f | ||
|
|
ca3f19c7e3 | ||
|
|
5238a26db5 | ||
|
|
ec400c4fa5 | ||
|
|
b1d8788a46 | ||
|
|
1915409c92 | ||
|
|
c5ec4896fe | ||
|
|
fcede9f913 | ||
|
|
46c3dc4bdf | ||
|
|
7caaea18b7 | ||
|
|
8407e057c9 |
15
AUTHORS
15
AUTHORS
@@ -1,15 +0,0 @@
|
||||
Authors of OpenJPEG
|
||||
See also the files THANKS and CHANGES
|
||||
|
||||
David Janssens designed and implemented the first version of OpenJPEG.
|
||||
Kaori Hagihara designed and implemented the first version of OpenJPIP.
|
||||
Jerome Fimes implemented the alpha version of OpenJPEG v2.
|
||||
Giuseppe Baruffa added the JPWL functionalities.
|
||||
Micka<EFBFBD>l Savinaud implemented the final OpenJPEG v2 version based on a big merge between 1.5 version and alpha version of v2.
|
||||
Mathieu Malaterre participate to the OpenJPEG v2 version and release the OpenJPEG 1.5 and 1.5.1 version.
|
||||
Yannick Verschueren,
|
||||
Herve Drolon,
|
||||
Francois-Olivier Devaux,
|
||||
Antonin Descampe
|
||||
improved the libraries and utilities.
|
||||
|
||||
21
CMake/CTestCustom.cmake.in
Normal file
21
CMake/CTestCustom.cmake.in
Normal file
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# For further details regarding this file,
|
||||
# see http://www.vtk.org/Wiki/CMake_Testing_With_CTest#Customizing_CTest
|
||||
#
|
||||
|
||||
SET (CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS 50)
|
||||
SET (CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 50)
|
||||
|
||||
SET(CTEST_CUSTOM_COVERAGE_EXCLUDE
|
||||
${CTEST_CUSTOM_COVERAGE_EXCLUDE}
|
||||
|
||||
# Exclude files from the Testing directories
|
||||
".*/Testing/.*"
|
||||
)
|
||||
|
||||
SET(CTEST_CUSTOM_WARNING_EXCEPTION
|
||||
${CTEST_CUSTOM_WARNING_EXCEPTION}
|
||||
|
||||
# Suppress warning caused by intentional messages about deprecation
|
||||
".*warning,.* is deprecated"
|
||||
)
|
||||
52
CMake/FindFreeImage.cmake
Normal file
52
CMake/FindFreeImage.cmake
Normal file
@@ -0,0 +1,52 @@
|
||||
#
|
||||
# Try to find the FreeImage library and include path.
|
||||
# Once done this will define
|
||||
#
|
||||
# FREEIMAGE_FOUND
|
||||
# FREEIMAGE_INCLUDE_PATH
|
||||
# FREEIMAGE_LIBRARY
|
||||
#
|
||||
|
||||
IF (WIN32)
|
||||
FIND_PATH( FREEIMAGE_INCLUDE_PATH FreeImage.h
|
||||
${OPENJPEG_SOURCE_DIR}/libs/FreeImage
|
||||
DOC "The directory where FreeImage.h resides")
|
||||
FIND_LIBRARY( FREEIMAGE_LIBRARY
|
||||
NAMES FreeImage freeimage freeimage.s
|
||||
PATHS
|
||||
${OPENJPEG_SOURCE_DIR}/libs/FreeImage
|
||||
DOC "The FreeImage library")
|
||||
ELSE (WIN32)
|
||||
FIND_PATH( FREEIMAGE_INCLUDE_PATH FreeImage.h
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/sw/include
|
||||
/opt/local/include
|
||||
DOC "The directory where FreeImage.h resides")
|
||||
FIND_LIBRARY( FREEIMAGE_LIBRARY
|
||||
NAMES FreeImage freeimage
|
||||
PATHS
|
||||
/usr/lib64
|
||||
/usr/lib
|
||||
/usr/local/lib64
|
||||
/usr/local/lib
|
||||
/sw/lib
|
||||
/opt/local/lib
|
||||
DOC "The FreeImage library")
|
||||
ENDIF (WIN32)
|
||||
|
||||
SET(FREEIMAGE_LIBRARIES ${FREEIMAGE_LIBRARY})
|
||||
|
||||
IF (FREEIMAGE_INCLUDE_PATH AND FREEIMAGE_LIBRARY)
|
||||
SET( FREEIMAGE_FOUND TRUE CACHE BOOL "Set to TRUE if GLEW is found, FALSE otherwise")
|
||||
ELSE (FREEIMAGE_INCLUDE_PATH AND FREEIMAGE_LIBRARY)
|
||||
SET( FREEIMAGE_FOUND FALSE CACHE BOOL "Set to TRUE if GLEW is found, FALSE otherwise")
|
||||
ENDIF (FREEIMAGE_INCLUDE_PATH AND FREEIMAGE_LIBRARY)
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
FREEIMAGE_FOUND
|
||||
FREEIMAGE_LIBRARY
|
||||
FREEIMAGE_LIBRARIES
|
||||
FREEIMAGE_INCLUDE_PATH)
|
||||
|
||||
|
||||
3
CMake/Free_CMakeImport.cmake
Normal file
3
CMake/Free_CMakeImport.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
SET(CMAKE_MODULE_PATH "${OPENJPEG_SOURCE_DIR}/CMake")
|
||||
FIND_PACKAGE(FreeImage REQUIRED)
|
||||
ADD_DEFINITIONS ( -DFREEIMAGE_LIB )
|
||||
@@ -6,21 +6,21 @@
|
||||
# module to load OPENJPEG's settings for an external project.
|
||||
@OPENJPEG_CONFIG_INSTALL_ONLY@
|
||||
# The OPENJPEG version number.
|
||||
set(OPENJPEG_MAJOR_VERSION "@OPENJPEG_VERSION_MAJOR@")
|
||||
set(OPENJPEG_MINOR_VERSION "@OPENJPEG_VERSION_MINOR@")
|
||||
set(OPENJPEG_BUILD_VERSION "@OPENJPEG_VERSION_BUILD@")
|
||||
SET(OPENJPEG_MAJOR_VERSION "@OPENJPEG_VERSION_MAJOR@")
|
||||
SET(OPENJPEG_MINOR_VERSION "@OPENJPEG_VERSION_MINOR@")
|
||||
SET(OPENJPEG_BUILD_VERSION "@OPENJPEG_VERSION_BUILD@")
|
||||
|
||||
# The libraries.
|
||||
set(OPENJPEG_LIBRARIES "@OPENJPEG_LIBRARY_NAME@")
|
||||
SET(OPENJPEG_LIBRARIES "@OPENJPEG_LIBRARIES@")
|
||||
|
||||
# The CMake macros dir.
|
||||
set(OPENJPEG_CMAKE_DIR "@OPENJPEG_INSTALL_PACKAGE_DIR@")
|
||||
SET(OPENJPEG_CMAKE_DIR "@OPENJPEG_CMAKE_DIR_CONFIG@")
|
||||
|
||||
# The configuration options.
|
||||
set(OPENJPEG_BUILD_SHARED_LIBS "@BUILD_SHARED_LIBS@")
|
||||
SET(OPENJPEG_BUILD_SHARED_LIBS "@OPENJPEG_BUILD_SHARED_LIBS@")
|
||||
|
||||
# The "use" file.
|
||||
set(OPENJPEG_USE_FILE "@OPENJPEG_USE_FILE_CONFIG@")
|
||||
SET(OPENJPEG_USE_FILE "@OPENJPEG_USE_FILE_CONFIG@")
|
||||
|
||||
get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
if(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake)
|
||||
@@ -28,21 +28,22 @@ if(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake)
|
||||
include(${SELF_DIR}/OpenJPEGTargets.cmake)
|
||||
get_filename_component(OPENJPEG_INCLUDE_ROOT "${SELF_DIR}/../../@OPENJPEG_INSTALL_INCLUDE_DIR@" ABSOLUTE)
|
||||
set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG_INCLUDE_ROOT})
|
||||
set(OPENJPEG_LIBRARIES openjpeg)
|
||||
|
||||
else()
|
||||
else(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake)
|
||||
if(EXISTS ${SELF_DIR}/OpenJPEGExports.cmake)
|
||||
# This is a build tree
|
||||
set( OPENJPEG_INCLUDE_DIRS @OPENJPEG_INCLUDE_PATH@)
|
||||
SET( OPENJPEG_INCLUDE_DIRS @OPENJPEG_INCLUDE_PATH@)
|
||||
|
||||
include(${SELF_DIR}/OpenJPEGExports.cmake)
|
||||
|
||||
else()
|
||||
else(EXISTS ${SELF_DIR}/OpenJPEGExports.cmake)
|
||||
message(FATAL_ERROR "ooops")
|
||||
endif()
|
||||
endif()
|
||||
endif(EXISTS ${SELF_DIR}/OpenJPEGExports.cmake)
|
||||
endif(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake)
|
||||
|
||||
set(OPENJPEG_USE_FILE ${SELF_DIR}/UseOPENJPEG.cmake)
|
||||
|
||||
# Backward compatible part:
|
||||
set(OPENJPEG_FOUND TRUE)
|
||||
SET(OPENJPEG_FOUND TRUE)
|
||||
|
||||
51
CMake/mymachine_openjpeg.cmake
Normal file
51
CMake/mymachine_openjpeg.cmake
Normal file
@@ -0,0 +1,51 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
# simply copy this file anywhere on your system and execute like this:
|
||||
# ctest -S mymachine_openjpeg.cmake -V
|
||||
# This will retrieve/compile/run tests/upload to cdash OpenJPEG
|
||||
# results will be available at: http://my.cdash.org/index.php?project=OPENJPEG
|
||||
|
||||
# Begin User inputs:
|
||||
set( CTEST_SITE "mymachine" ) # generally the output of hostname
|
||||
set( CTEST_DASHBOARD_ROOT "/tmp" ) # writable path
|
||||
set( CTEST_CMAKE_GENERATOR "Unix Makefiles" ) # What is your compilation apps ?
|
||||
set( CTEST_BUILD_CONFIGURATION Debug) # What type of build do you want ?
|
||||
set( ENV{CFLAGS} "-Wall" ) # just for fun...
|
||||
|
||||
# For testing we need to define the path to J2KP4files
|
||||
# wget http://www.crc.ricoh.com/~gormish/jpeg2000conformance/j2kp4files_v1_5.zip
|
||||
# unzip j2kp4files_v1_5.zip
|
||||
set( CACHE_CONTENTS "
|
||||
BUILD_TESTING:BOOL=TRUE
|
||||
JPEG2000_CONFORMANCE_DATA_ROOT:PATH=${CTEST_SOURCE_DIRECTORY}/J2KP4files" )
|
||||
# End User inputs:
|
||||
|
||||
# You do not need to change anything after that:
|
||||
# 1. openjpeg specific:
|
||||
set( CTEST_PROJECT_NAME "OPENJPEG" )
|
||||
set( CTEST_SOURCE_NAME OpenJPEG)
|
||||
set( CTEST_BUILD_NAME "${CMAKE_SYSTEM}-${CTEST_CMAKE_GENERATOR}-${CTEST_BUILD_CONFIGURATION}")
|
||||
set( CTEST_BINARY_NAME "${CTEST_SOURCE_NAME}-${CTEST_BUILD_NAME}")
|
||||
|
||||
# 2. cdash/openjpeg specific:
|
||||
# svn checkout http://openjpeg.googlecode.com/svn/trunk/ openjpeg-read-only
|
||||
set( CTEST_SVN_URL "http://openjpeg.googlecode.com/svn/")
|
||||
set( CTEST_UPDATE_COMMAND "svn")
|
||||
#set( CTEST_CHECKOUT_COMMAND "${CTEST_UPDATE_COMMAND} co ${CTEST_SVN_URL}/trunk ${CTEST_SOURCE_NAME}")
|
||||
set( CTEST_CHECKOUT_COMMAND "${CTEST_UPDATE_COMMAND} co ${CTEST_SVN_URL}/branches/v2 ${CTEST_SOURCE_NAME}")
|
||||
|
||||
# 3. cmake specific:
|
||||
set( CTEST_SOURCE_DIRECTORY "${CTEST_DASHBOARD_ROOT}/${CTEST_SOURCE_NAME}")
|
||||
set( CTEST_BINARY_DIRECTORY "${CTEST_DASHBOARD_ROOT}/${CTEST_BINARY_NAME}")
|
||||
set( CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIPT_NAME}")
|
||||
|
||||
ctest_empty_binary_directory( "${CTEST_BINARY_DIRECTORY}" )
|
||||
file(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" "${CACHE_CONTENTS}")
|
||||
|
||||
# Perform the Nightly build
|
||||
ctest_start(Nightly)
|
||||
ctest_update(SOURCE "${CTEST_SOURCE_DIRECTORY}")
|
||||
ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}")
|
||||
ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}")
|
||||
ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}")
|
||||
ctest_submit()
|
||||
|
||||
373
CMakeLists.txt
373
CMakeLists.txt
@@ -6,284 +6,199 @@
|
||||
# you will eventually like to prefix the library to avoid linking confusion
|
||||
# For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like
|
||||
# e.g.:
|
||||
# set(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
|
||||
cmake_minimum_required(VERSION 2.8.2)
|
||||
# SET(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
||||
|
||||
if(COMMAND CMAKE_POLICY)
|
||||
cmake_policy(SET CMP0003 NEW)
|
||||
endif()
|
||||
IF(COMMAND CMAKE_POLICY)
|
||||
CMAKE_POLICY(SET CMP0003 NEW)
|
||||
ENDIF(COMMAND CMAKE_POLICY)
|
||||
|
||||
if(NOT OPENJPEG_NAMESPACE)
|
||||
set(OPENJPEG_NAMESPACE "OPENJPEG")
|
||||
set(OPENJPEG_STANDALONE 1)
|
||||
endif()
|
||||
IF(NOT OPENJPEG_NAMESPACE)
|
||||
SET(OPENJPEG_NAMESPACE "OPENJPEG")
|
||||
SET(OPENJPEG_STANDALONE 1)
|
||||
ENDIF(NOT OPENJPEG_NAMESPACE)
|
||||
# In all cases:
|
||||
#string(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
|
||||
set(OPENJPEG_LIBRARY_NAME openjp2)
|
||||
STRING(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
|
||||
|
||||
project(${OPENJPEG_NAMESPACE} C)
|
||||
PROJECT(${OPENJPEG_NAMESPACE} C)
|
||||
|
||||
# Do full dependency headers.
|
||||
include_regular_expression("^.*$")
|
||||
INCLUDE_REGULAR_EXPRESSION("^.*$")
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# OPENJPEG version number, useful for packaging and doxygen doc:
|
||||
set(OPENJPEG_VERSION_MAJOR 2)
|
||||
set(OPENJPEG_VERSION_MINOR 0)
|
||||
set(OPENJPEG_VERSION_BUILD 0)
|
||||
set(OPENJPEG_VERSION
|
||||
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
|
||||
set(PACKAGE_VERSION
|
||||
SET(OPENJPEG_VERSION_MAJOR 2)
|
||||
SET(OPENJPEG_VERSION_MINOR 0)
|
||||
SET(OPENJPEG_VERSION_BUILD 0)
|
||||
SET(OPENJPEG_VERSION
|
||||
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
|
||||
|
||||
# Because autotools does not support X.Y notation for SOVERSION, we have to use
|
||||
# two numbering, one for the openjpeg version and one for openjpeg soversion
|
||||
# version | soversion
|
||||
# 1.0 | 0
|
||||
# 1.1 | 1
|
||||
# 1.2 | 2
|
||||
# 1.3 | 3
|
||||
# 1.4 | 4
|
||||
# 1.5 | 5
|
||||
# 1.5.1 | 5
|
||||
# 2.0 | 6
|
||||
# above is the recommendation by the OPJ team. If you really need to override this default,
|
||||
# you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
|
||||
# cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
|
||||
if(NOT OPENJPEG_SOVERSION)
|
||||
SET(OPENJPEG_SOVERSION 6)
|
||||
endif(NOT OPENJPEG_SOVERSION)
|
||||
set(OPENJPEG_LIBRARY_PROPERTIES
|
||||
# This setting of SOVERSION assumes that any API change
|
||||
# will increment either the minor or major version number of openjpeg
|
||||
SET(OPENJPEG_LIBRARY_PROPERTIES
|
||||
VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
|
||||
SOVERSION "${OPENJPEG_SOVERSION}"
|
||||
SOVERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}"
|
||||
)
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Path to additional CMake modules
|
||||
set(CMAKE_MODULE_PATH
|
||||
${CMAKE_SOURCE_DIR}/cmake
|
||||
${CMAKE_MODULE_PATH})
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
|
||||
# warnings
|
||||
if(WIN32)
|
||||
if(NOT BORLAND)
|
||||
if(NOT CYGWIN)
|
||||
if(NOT MINGW)
|
||||
if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
|
||||
add_definitions(
|
||||
-D_CRT_FAR_MAPPINGS_NO_DEPRECATE
|
||||
-D_CRT_IS_WCTYPE_NO_DEPRECATE
|
||||
-D_CRT_MANAGED_FP_NO_DEPRECATE
|
||||
-D_CRT_NONSTDC_NO_DEPRECATE
|
||||
-D_CRT_SECURE_NO_DEPRECATE
|
||||
-D_CRT_SECURE_NO_DEPRECATE_GLOBALS
|
||||
-D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
|
||||
-D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
|
||||
-D_CRT_VCCLRIT_NO_DEPRECATE
|
||||
-D_SCL_SECURE_NO_DEPRECATE
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# You will also need to define a value for the following variables:
|
||||
# OPENJPEG_INSTALL_BIN_DIR - binary dir (executables)
|
||||
# OPENJPEG_INSTALL_LIB_DIR - library dir (libs)
|
||||
# OPENJPEG_INSTALL_DATA_DIR - share dir (say, examples, data, etc)
|
||||
# OPENJPEG_INSTALL_INCLUDE_DIR - include dir (headers)
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# Install directories
|
||||
|
||||
string(TOLOWER ${PROJECT_NAME} projectname)
|
||||
set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
|
||||
STRING(TOLOWER ${PROJECT_NAME} projectname)
|
||||
SET(subdir "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
|
||||
|
||||
if(NOT OPENJPEG_INSTALL_BIN_DIR)
|
||||
set(OPENJPEG_INSTALL_BIN_DIR "bin")
|
||||
endif()
|
||||
IF(NOT OPENJPEG_INSTALL_BIN_DIR)
|
||||
SET(OPENJPEG_INSTALL_BIN_DIR "bin")
|
||||
ENDIF(NOT OPENJPEG_INSTALL_BIN_DIR)
|
||||
|
||||
if(NOT OPENJPEG_INSTALL_LIB_DIR)
|
||||
set(OPENJPEG_INSTALL_LIB_DIR "lib")
|
||||
endif()
|
||||
IF(NOT OPENJPEG_INSTALL_LIB_DIR)
|
||||
SET(OPENJPEG_INSTALL_LIB_DIR "lib")
|
||||
ENDIF(NOT OPENJPEG_INSTALL_LIB_DIR)
|
||||
|
||||
if(NOT OPENJPEG_INSTALL_SHARE_DIR)
|
||||
set(OPENJPEG_INSTALL_SHARE_DIR "share")
|
||||
endif()
|
||||
IF(NOT OPENJPEG_INSTALL_DATA_DIR)
|
||||
SET(OPENJPEG_INSTALL_DATA_DIR "share/${subdir}")
|
||||
ENDIF(NOT OPENJPEG_INSTALL_DATA_DIR)
|
||||
|
||||
if(NOT OPENJPEG_INSTALL_DATA_DIR)
|
||||
set(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
|
||||
endif()
|
||||
IF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
|
||||
SET(OPENJPEG_INSTALL_INCLUDE_DIR "include/${subdir}")
|
||||
ENDIF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
|
||||
|
||||
if(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
|
||||
set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
|
||||
endif()
|
||||
IF(NOT OPENJPEG_INSTALL_DOC_DIR)
|
||||
SET(OPENJPEG_INSTALL_DOC_DIR "share/doc/${subdir}")
|
||||
ENDIF(NOT OPENJPEG_INSTALL_DOC_DIR)
|
||||
|
||||
if(NOT OPENJPEG_INSTALL_MAN_DIR)
|
||||
set(OPENJPEG_INSTALL_MAN_DIR "share/man/")
|
||||
endif()
|
||||
|
||||
if(NOT OPENJPEG_INSTALL_DOC_DIR)
|
||||
set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
|
||||
endif()
|
||||
|
||||
if(NOT OPENJPEG_INSTALL_JNI_DIR)
|
||||
if(WIN32)
|
||||
set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR})
|
||||
else()
|
||||
set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
|
||||
# We could install *.cmake files in share/ however those files contains
|
||||
# hardcoded path to libraries on a multi-arch system (fedora/debian) those
|
||||
# path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu)
|
||||
set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
|
||||
endif()
|
||||
IF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
|
||||
SET(OPENJPEG_INSTALL_PACKAGE_DIR ${OPENJPEG_INSTALL_LIB_DIR}/${subdir}
|
||||
CACHE INTERNAL "")
|
||||
ENDIF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Big endian test:
|
||||
include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
|
||||
TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
|
||||
# Test for some required system information.
|
||||
INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityC.cmake)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Setup file for setting custom ctest vars
|
||||
configure_file(
|
||||
${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake.in
|
||||
${CMAKE_BINARY_DIR}/CTestCustom.cmake
|
||||
CONFIGURE_FILE(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMake/CTestCustom.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
|
||||
@ONLY
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# OpenJPEG build configuration options.
|
||||
option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
|
||||
set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
|
||||
set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
|
||||
mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
|
||||
OPTION(BUILD_SHARED_LIBS "Build OpenJPEG with shared libraries." OFF)
|
||||
OPTION(ENABLE_PROFILING "Enable profiling for the library" OFF)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
|
||||
SET (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
|
||||
MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# For the codec...
|
||||
OPTION(BUILD_EXAMPLES "Build the Examples (codec...)." OFF)
|
||||
|
||||
|
||||
# configure name mangling to allow multiple libraries to coexist
|
||||
# peacefully
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
|
||||
set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
|
||||
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
|
||||
SET(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
|
||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
|
||||
@ONLY)
|
||||
endif()
|
||||
@ONLY IMMEDIATE)
|
||||
ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Configure files with settings for use by the build.
|
||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/opj_configure.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/opj_configure.h)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Always build the library
|
||||
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
SUBDIRS(
|
||||
libopenjpeg
|
||||
# mj2
|
||||
#j2kviewer/src
|
||||
)
|
||||
|
||||
#IF(NOT UNIX)
|
||||
#SUBDIRS(
|
||||
# jpwl
|
||||
# jp3d
|
||||
# indexer_JPIP
|
||||
# )
|
||||
#ENDIF(NOT UNIX)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Build example only if requested
|
||||
IF(BUILD_EXAMPLES)
|
||||
SUBDIRS(codec)
|
||||
ENDIF(BUILD_EXAMPLES)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# For the documentation
|
||||
OPTION(BUILD_DOCUMENTATION "Build the doxygen documentation" OFF)
|
||||
IF(BUILD_DOCUMENTATION)
|
||||
SUBDIRS(doc)
|
||||
ENDIF(BUILD_DOCUMENTATION)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# For openjpeg team if they ever want CDash+CMake
|
||||
OPTION(BUILD_TESTING "Build the tests." OFF)
|
||||
IF(BUILD_TESTING)
|
||||
ENABLE_TESTING()
|
||||
INCLUDE(CTest)
|
||||
ENDIF(BUILD_TESTING)
|
||||
|
||||
IF(BUILD_TESTING)
|
||||
SET(CMAKE_MODULE_PATH "${OPENJPEG_SOURCE_DIR}/CMake")
|
||||
FIND_PACKAGE(FreeImage)
|
||||
|
||||
SUBDIRS(
|
||||
test_V2_tile_handling
|
||||
)
|
||||
if(FREEIMAGE_FOUND)
|
||||
INCLUDE_DIRECTORIES( ${FREEIMAGE_INCLUDE_PATH} )
|
||||
SUBDIRS(
|
||||
test_Free_image_V2_tile_handling
|
||||
)
|
||||
endif(FREEIMAGE_FOUND)
|
||||
ENDIF(BUILD_TESTING)
|
||||
|
||||
# Adding test with dataset from:
|
||||
# http://www.crc.ricoh.com/~gormish/jpeg2000conformance/
|
||||
# -> wget http://www.crc.ricoh.com/~gormish/jpeg2000conformance/j2kp4files_v1_5.zip
|
||||
# http://www.jpeg.org/jpeg2000guide/testimages/testimages.html
|
||||
#-----------------------------------------------------------------------------
|
||||
# Adding JPEG2000_CONFORMANCE_DATA_ROOT
|
||||
FIND_PATH(JPEG2000_CONFORMANCE_DATA_ROOT testimages.html
|
||||
${OPENJPEG_SOURCE_DIR}/../jpeg2000testimages
|
||||
$ENV{JPEG2000_CONFORMANCE_DATA_ROOT}
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Compiler specific flags:
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
IF(CMAKE_COMPILER_IS_GNUCC)
|
||||
# For all builds, make sure openjpeg is std99 compliant:
|
||||
# set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
|
||||
# SET(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
|
||||
# Do not use ffast-math for all build, it would produce incorrect results, only set for release:
|
||||
set(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
|
||||
endif()
|
||||
SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
|
||||
ENDIF(CMAKE_COMPILER_IS_GNUCC)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# opj_config.h generation (1/2)
|
||||
include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
|
||||
CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
|
||||
CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
|
||||
CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H)
|
||||
CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
|
||||
CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
|
||||
CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
|
||||
CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
|
||||
CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
|
||||
CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
|
||||
# ssize_t
|
||||
include(CheckTypeSize)
|
||||
CHECK_TYPE_SIZE(ssize_t SSIZE_T)
|
||||
|
||||
# Enable Large file support
|
||||
include(TestLargeFiles)
|
||||
OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Build Library
|
||||
add_subdirectory(src)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Build Applications
|
||||
option(BUILD_CODEC "Build the CODEC executables" ON)
|
||||
option(BUILD_MJ2 "Build the MJ2 executables." OFF)
|
||||
option(BUILD_JPWL "Build the JPWL library and executables" OFF)
|
||||
option(BUILD_JPIP "Build the JPIP library and executables." OFF)
|
||||
if(BUILD_JPIP)
|
||||
option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
|
||||
endif()
|
||||
option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
|
||||
option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
|
||||
option(BUILD_JP3D "Build the JP3D comp" OFF)
|
||||
mark_as_advanced(BUILD_VIEWER)
|
||||
mark_as_advanced(BUILD_JAVA)
|
||||
mark_as_advanced(BUILD_JP3D)
|
||||
|
||||
if(BUILD_CODEC OR BUILD_MJ2)
|
||||
# OFF: It will only build 3rd party libs if they are not found on the system
|
||||
# ON: 3rd party libs will ALWAYS be build, and used
|
||||
option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
|
||||
add_subdirectory(thirdparty)
|
||||
add_subdirectory(src/bin)
|
||||
endif ()
|
||||
add_subdirectory(wrapping)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# opj_config.h generation (2/2)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
|
||||
option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
|
||||
if(BUILD_DOC)
|
||||
add_subdirectory(doc)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Buld Testing
|
||||
option(BUILD_TESTING "Build the tests." OFF)
|
||||
if(BUILD_TESTING)
|
||||
if(BUILD_CODEC)
|
||||
enable_testing()
|
||||
include(CTest)
|
||||
|
||||
# Search openjpeg data needed for the tests
|
||||
# They could be found via svn on the OpenJPEG google code project
|
||||
# svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo)
|
||||
find_path(OPJ_DATA_ROOT README-OPJ-Data
|
||||
PATHS
|
||||
$ENV{OPJ_DATA_ROOT}
|
||||
${CMAKE_SOURCE_DIR}/../data
|
||||
)
|
||||
|
||||
# Add repository where to find tests
|
||||
add_subdirectory(tests)
|
||||
|
||||
else()
|
||||
message(FATAL_ERROR "You need build codec to run the tests")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# install all targets referenced as OPENJPEGTargets
|
||||
install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
|
||||
configure_file( ${OPENJPEG_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
|
||||
CONFIGURE_FILE( ${OPENJPEG_SOURCE_DIR}/CMake/OpenJPEGConfig.cmake.in
|
||||
${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
|
||||
@ONLY
|
||||
)
|
||||
install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
|
||||
INSTALL( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
|
||||
DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
|
||||
)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# install CHANGES and LICENSE
|
||||
if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
|
||||
install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
|
||||
endif()
|
||||
install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
|
||||
|
||||
include (cmake/OpenJPEGCPack.cmake)
|
||||
|
||||
69
INSTALL
69
INSTALL
@@ -1,69 +0,0 @@
|
||||
|
||||
How to build and install openjpeg binaries
|
||||
==========================================
|
||||
|
||||
UNIX/LINUX/MacOSX/Windows systems
|
||||
--------------------------
|
||||
|
||||
Using cmake (see www.cmake.org)
|
||||
|
||||
Type:
|
||||
cmake .
|
||||
make
|
||||
|
||||
If you are root:
|
||||
make install
|
||||
|
||||
else if you have sudo power:
|
||||
sudo make install
|
||||
|
||||
else
|
||||
DESTDIR=$HOME/local make install
|
||||
|
||||
To build the Doxygen documentation (Doxygen needs to be found on the system):
|
||||
(A 'html' directory is generated in the 'doc' directory)
|
||||
make doc
|
||||
|
||||
Binaries are located in the 'bin' directory.
|
||||
|
||||
Main available cmake flags:
|
||||
* To specify the install path: '-DCMAKE_INSTALL_PREFIX=/path', or use DESTDIR env variable (see above)
|
||||
* To build the shared libraries and links the executables against it: '-DBUILD_SHARED_LIBS:bool=on' (default: 'ON')
|
||||
Note: when using this option, static libraries are not built and executables are dynamically linked.
|
||||
* To build the CODEC executables: '-DBUILD_CODEC:bool=on' (default: 'ON')
|
||||
* To build the documentation: '-DBUILD_DOC:bool=on' (default: 'OFF')
|
||||
* To build the MJ2 executables: '-DBUILD_MJ2:bool=on' (default: 'OFF')
|
||||
* To build the JPWL executables and JPWL library: '-DBUILD_JPWL:bool=on' (default: 'OFF')
|
||||
* To build the JPIP library and utilities: '-DBUILD_JPIP:bool=on' (default: 'OFF')
|
||||
** To build the JPIP server: '-DBUILD_JPIP_SERVER:bool=on' (default: 'OFF')
|
||||
* To build the JP3D library and utilities: '-DBUILD_JP3D:bool=on' (default: 'OFF') (experimental)
|
||||
* To build the Java binding: '-DBUILD_JAVA:bool=on' (default: 'OFF') (experimental).
|
||||
** to choose which java implementation, you can set your JAVA_HOME env var.
|
||||
* To build the wxWidgets/C++ viewer: 'BUILD_VIEWER:BOOL=ON' (default OFF) (experimental)
|
||||
* To enable testing (and automatic result upload to http://my.cdash.org/index.php?project=OPENJPEG):
|
||||
cmake . -DBUILD_TESTING:BOOL=ON -DOPJ_DATA_ROOT:PATH='path/to/the/data/directory'
|
||||
make
|
||||
make Experimental
|
||||
Note : JPEG2000 test files are available with 'svn checkout http://openjpeg.googlecode.com/svn/data' (about 70 Mo).
|
||||
If '-DOPJ_DATA_ROOT:PATH' option is omitted, test files will be automatically searched in '${CMAKE_SOURCE_DIR}/../data',
|
||||
corresponding to the location of the data directory when compiling from the trunk (and assuming the data directory has
|
||||
been checked out of course).
|
||||
|
||||
MACOSX
|
||||
------
|
||||
|
||||
The same building procedures as above work for MACOSX.
|
||||
The xcode project file can also be used.
|
||||
|
||||
If it does not work, try adding the following flag to the cmake command :
|
||||
'-DCMAKE_OSX_ARCHITECTURES:STRING=i386'
|
||||
|
||||
WINDOWS
|
||||
-------
|
||||
|
||||
You can use cmake to generate project files for the IDE you are using (VS2010, NMake, etc).
|
||||
Type 'cmake --help' for available generators on your platform.
|
||||
|
||||
Make sure to build the third party libs (png, zlib ...):
|
||||
|
||||
'-DBUILD_THIRDPARTY:BOOL=ON'
|
||||
14
LICENSE
14
LICENSE
@@ -1,14 +1,10 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2012, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2012, Professor Benoit Macq
|
||||
* Copyright (c) 2003-2012, Antonin Descampe
|
||||
* Copyright (c) 2003-2009, Francois-Olivier Devaux
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2001-2003, David Janssens
|
||||
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
|
||||
* Copyright (c) 2012, CS Systemes d'Information, France
|
||||
*
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
21
NEWS
21
NEWS
@@ -1,21 +0,0 @@
|
||||
|
||||
OpenJPEG NEWS - user visible changes
|
||||
====================================
|
||||
|
||||
Changes from OpenJPEG 1.5.x to OpenJPEG 2.0.0
|
||||
----------------------------------------------
|
||||
|
||||
New Features:
|
||||
|
||||
* streaming capabilities
|
||||
* merge JP3D
|
||||
|
||||
API modifications:
|
||||
|
||||
* Use a 64bits capable API
|
||||
|
||||
Misc:
|
||||
|
||||
* removed autotools build system
|
||||
* folders hierarchies reorganisation
|
||||
* Huge amount of bug fixes. See CHANGES for details.
|
||||
109
OpenJPEG.rc
Normal file
109
OpenJPEG.rc
Normal file
@@ -0,0 +1,109 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// French (France) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,1,0,0
|
||||
PRODUCTVERSION 1,1,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "000004b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "The OpenJPEG library is an open-source JPEG 2000 codec. \0"
|
||||
VALUE "CompanyName", "OpenJPEG\0"
|
||||
VALUE "FileDescription", "OpenJPEG\0"
|
||||
VALUE "FileVersion", "1, 1, 0, 0\0"
|
||||
VALUE "InternalName", "OpenJPEG\0"
|
||||
VALUE "LegalCopyright", "Copyright <20> 2002-2007, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium\0"
|
||||
VALUE "LegalTrademarks", "See http://www.openjpeg.org for details\0"
|
||||
VALUE "OriginalFilename", "OpenJPEG.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "OpenJPEG\0"
|
||||
VALUE "ProductVersion", "1, 1, 0, 0\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // French (France) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
47
README
47
README
@@ -1,47 +0,0 @@
|
||||
|
||||
OPENJPEG LIBRARY and APPLICATIONS
|
||||
----------------------------------
|
||||
|
||||
Details on folders hierarchy:
|
||||
|
||||
* src
|
||||
* lib
|
||||
* openjp2: contains the sources of the openjp2 library (Part 1 & 2)
|
||||
* openjpwl: contains the additional sources if you want to build a JPWL-flavoured library.
|
||||
* openjpip: complete client-server architecture for remote browsing of jpeg 2000 images.
|
||||
* openjp3d: JP3D implementation
|
||||
* openmj2: MJ2 implementation
|
||||
* bin: contains all applications that use the openjpeg library
|
||||
* common: common files to all applications
|
||||
* jp2: a basic codec
|
||||
* mj2: motion jpeg 2000 executables
|
||||
* jpip: OpenJPIP applications (server and dec server)
|
||||
* java: a Java client viewer for JPIP
|
||||
* jp3d: JP3D applications
|
||||
* tcltk: a test tool for JP3D
|
||||
* wx
|
||||
* OPJViewer: gui for displaying j2k files (based on wxWidget)
|
||||
* wrapping
|
||||
* java: java jni to use openjpeg in a java program
|
||||
* thirdparty: thirdparty libraries used by some applications. These libraries will be built only if there are not found on the system. Note that libopenjpeg itself does not have any dependency.
|
||||
* doc: doxygen documentation setup file and man pages
|
||||
* tests: configuration files and utilities for the openjpeg test suite. All test images are located in 'http://openjpeg.googlecode.com/svn/data' folder.
|
||||
* cmake: cmake related files
|
||||
|
||||
see LICENSE for license and copyright information.
|
||||
see INSTALL for installation procedures.
|
||||
see NEWS for user visible changes in successive releases.
|
||||
see CHANGES for per-revision changes.
|
||||
|
||||
----------------
|
||||
API/ABI
|
||||
|
||||
OpenJPEG strives to provide a stable API/ABI for your applications. As such it
|
||||
only exposes a limited subset of its functions. It uses a mecanism of
|
||||
exporting/hiding functions. If you are unsure which functions you can use in
|
||||
your applications, you should compile OpenJPEG using something similar to gcc:
|
||||
-fvisibility=hidden compilation flag.
|
||||
See also: http://gcc.gnu.org/wiki/Visibility
|
||||
|
||||
On windows, MSVC directly supports export/hidding function and as such the only
|
||||
API available is the one supported by OpenJPEG.
|
||||
9
README.cmake
Normal file
9
README.cmake
Normal file
@@ -0,0 +1,9 @@
|
||||
Basic instructions on how to build using CMake (CMake 2.4.5 or newer is required)
|
||||
|
||||
svn co http://www.openjpeg.org/svn/trunk
|
||||
cd trunk
|
||||
mkdir bin
|
||||
cd bin
|
||||
cmake .. -DBUILD_EXAMPLES:BOOL=ON
|
||||
make
|
||||
./bin/j2k_to_image
|
||||
26
README.v2
Normal file
26
README.v2
Normal file
@@ -0,0 +1,26 @@
|
||||
Preliminary notes
|
||||
-----------------
|
||||
|
||||
The Version 2 of openjpeg has been currently added as a branch on the repository.
|
||||
|
||||
All the trunk has been copied and files that needed to change have been patched. In comparison with the trunk, the 'jp3d' directory has been removed because it's based on a modified version of libopenjpeg version 1 and there is no plan to make it reach the version 2 status. Idem with the 'indexer_JPIP', which is obsolete and should be rewritten from scratch.
|
||||
|
||||
At the time of the branch creation, the following files and directories have been updated (or added) for version 2 :
|
||||
* libopenjpeg/
|
||||
* codec/
|
||||
* test_Free_image_V2_tile_handling/ : a test program that uses libopenjpeg v2 and libfreeimage (see libs) to implement a basic codec.
|
||||
* test_V2_tile_handling/ : a test program that generates a random image and (de)compresses it with libopenjpeg v2.
|
||||
* CMakeLists.txt
|
||||
* Free_CMakeImport.cmake
|
||||
* opj_configure.h.in
|
||||
|
||||
Other files and directories from the trunk (project files, jpwl/, OPJViewer/, ...) have also been copied in the branch and should be modified progressively to comply with v2. Check the Changelog for updates on this topic.
|
||||
|
||||
Enjoy v2 and feel free to contribute !
|
||||
|
||||
|
||||
Instructions to compile v2
|
||||
--------------------------
|
||||
|
||||
to be added.
|
||||
|
||||
33
THANKS
33
THANKS
@@ -1,33 +0,0 @@
|
||||
OpenJPEG THANKS file
|
||||
|
||||
Many people have contributed to OpenJPEG by reporting problems, suggesting various improvements,
|
||||
or submitting actual code. Here is a list of these people. Help me keep
|
||||
it complete and exempt of errors.
|
||||
|
||||
Winfried Szukalski
|
||||
Vincent Torri
|
||||
Bob Friesenhahn
|
||||
Callum Lerwick
|
||||
Dzonatas Sol
|
||||
Julien Malik
|
||||
Jerôme Fimes
|
||||
Herve Drolon
|
||||
Yannick Verschueren
|
||||
Sebastien Lugan
|
||||
Kaori Hagihara
|
||||
Peter Wimmer
|
||||
Francois-Olivier Devaux
|
||||
Antonin Descampe
|
||||
David Janssens
|
||||
Pr. Benoit Macq
|
||||
Luis Ibanez
|
||||
Ben Boeckel
|
||||
Vincent Nicolas
|
||||
Glenn Pearson
|
||||
Giuseppe Baruffa
|
||||
Arnaud Maye
|
||||
Rex Dieter
|
||||
David Burken
|
||||
Parvatha Elangovan
|
||||
Hans Johnson
|
||||
Luc Hermitte
|
||||
@@ -1,34 +0,0 @@
|
||||
#----------------------------------------------------------------------
|
||||
#
|
||||
# For further details regarding this file,
|
||||
# see http://www.cmake.org/Wiki/CMake_Testing_With_CTest#Customizing_CTest
|
||||
#
|
||||
# and
|
||||
# http://www.kitware.com/blog/home/post/27
|
||||
#
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
set(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE 1000000)
|
||||
set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS 50)
|
||||
set(CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 2000)
|
||||
|
||||
set(CTEST_CUSTOM_COVERAGE_EXCLUDE
|
||||
${CTEST_CUSTOM_COVERAGE_EXCLUDE}
|
||||
|
||||
# Exclude files from the Testing directories
|
||||
".*/tests/.*"
|
||||
|
||||
# Exclude files from the ThirdParty Utilities directories
|
||||
".*/thirdparty/.*"
|
||||
)
|
||||
|
||||
set(CTEST_CUSTOM_WARNING_EXCEPTION
|
||||
${CTEST_CUSTOM_WARNING_EXCEPTION}
|
||||
|
||||
# Suppress warning caused by intentional messages about deprecation
|
||||
".*warning,.* is deprecated"
|
||||
# supress warnings caused by 3rd party libs:
|
||||
".*thirdparty.*"
|
||||
"libtiff.*has no symbols"
|
||||
"libpng.*has no symbols"
|
||||
)
|
||||
@@ -1,16 +0,0 @@
|
||||
# cppcheck
|
||||
#
|
||||
# Copyright (c) 2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New
|
||||
# BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
#
|
||||
|
||||
find_program(CPPCHECK_EXECUTABLE
|
||||
cppcheck
|
||||
)
|
||||
|
||||
mark_as_advanced(
|
||||
CPPCHECK_EXECUTABLE
|
||||
)
|
||||
@@ -1,20 +0,0 @@
|
||||
# Look for the header file.
|
||||
find_path(FCGI_INCLUDE_DIR NAMES fastcgi.h)
|
||||
|
||||
# Look for the library.
|
||||
find_library(FCGI_LIBRARY NAMES fcgi)
|
||||
|
||||
# Handle the QUIETLY and REQUIRED arguments and set FCGI_FOUND to TRUE if all listed variables are TRUE.
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FCGI DEFAULT_MSG FCGI_LIBRARY FCGI_INCLUDE_DIR)
|
||||
|
||||
# Copy the results to the output variables.
|
||||
if(FCGI_FOUND)
|
||||
set(FCGI_LIBRARIES ${FCGI_LIBRARY})
|
||||
set(FCGI_INCLUDE_DIRS ${FCGI_INCLUDE_DIR})
|
||||
else()
|
||||
set(FCGI_LIBRARIES)
|
||||
set(FCGI_INCLUDE_DIRS)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(FCGI_INCLUDE_DIR FCGI_LIBRARY)
|
||||
@@ -1,19 +0,0 @@
|
||||
#
|
||||
# this module looks for KAKADu
|
||||
# http://www.kakadusoftware.com/
|
||||
#
|
||||
#
|
||||
# Copyright (c) 2006-2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New
|
||||
# BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
#
|
||||
|
||||
find_program(KDU_EXPAND_EXECUTABLE
|
||||
kdu_expand
|
||||
)
|
||||
|
||||
mark_as_advanced(
|
||||
KDU_EXPAND_EXECUTABLE
|
||||
)
|
||||
@@ -1,31 +0,0 @@
|
||||
# - Find LCMS library
|
||||
# Find the native LCMS includes and library
|
||||
# Once done this will define
|
||||
#
|
||||
# LCMS_INCLUDE_DIR - Where to find lcms.h, etc.
|
||||
# LCMS_LIBRARIES - Libraries to link against to use LCMS.
|
||||
# LCMS_FOUND - If false, do not try to use LCMS.
|
||||
#
|
||||
# also defined, but not for general use are
|
||||
# LCMS_LIBRARY, where to find the LCMS library.
|
||||
|
||||
#=============================================================================
|
||||
#=============================================================================
|
||||
|
||||
find_path(LCMS_INCLUDE_DIR lcms.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include)
|
||||
|
||||
set(LCMS_NAMES ${LCMS_NAMES} lcms liblcms liblcms_static)
|
||||
|
||||
find_library(LCMS_LIBRARY NAMES ${LCMS_NAMES} )
|
||||
|
||||
mark_as_advanced(LCMS_INCLUDE_DIR LCMS_LIBRARY)
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set LCMS_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS DEFAULT_MSG LCMS_LIBRARY LCMS_INCLUDE_DIR)
|
||||
|
||||
if(LCMS_FOUND)
|
||||
set( LCMS_INCLUDE_DIRS ${LCMS_INCLUDE_DIR})
|
||||
set( LCMS_LIBRARIES ${LCMS_LIBRARY} )
|
||||
endif()
|
||||
@@ -1,31 +0,0 @@
|
||||
# - Find LCMS2 library
|
||||
# Find the native LCMS2 includes and library
|
||||
# Once done this will define
|
||||
#
|
||||
# LCMS2_INCLUDE_DIR - Where to find lcms2.h, etc.
|
||||
# LCMS2_LIBRARIES - Libraries to link against to use LCMS2.
|
||||
# LCMS2_FOUND - If false, do not try to use LCMS2.
|
||||
#
|
||||
# also defined, but not for general use are
|
||||
# LCMS2_LIBRARY - Where to find the LCMS2 library.
|
||||
|
||||
#=============================================================================
|
||||
#=============================================================================
|
||||
|
||||
find_path(LCMS2_INCLUDE_DIR lcms2.h PATHS /usr/include /usr/local/include /opt/include /opt/local/include)
|
||||
|
||||
set(LCMS2_NAMES ${LCMS2_NAMES} lcms2 liblcms2 liblcms2_static)
|
||||
|
||||
find_library(LCMS2_LIBRARY NAMES ${LCMS2_NAMES} )
|
||||
|
||||
mark_as_advanced(LCMS2_INCLUDE_DIR LCMS2_LIBRARY)
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set LCMS2_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LCMS2 DEFAULT_MSG LCMS2_LIBRARY LCMS2_INCLUDE_DIR)
|
||||
|
||||
if(LCMS2_FOUND)
|
||||
set( LCMS2_INCLUDE_DIRS ${LCMS2_INCLUDE_DIR})
|
||||
set( LCMS2_LIBRARIES ${LCMS2_LIBRARY} )
|
||||
endif()
|
||||
@@ -1,9 +0,0 @@
|
||||
# JPIP test driver
|
||||
#message(STATUS "${D_URL}")
|
||||
file(DOWNLOAD
|
||||
"${D_URL}"
|
||||
"${D_FILE}"
|
||||
LOG log
|
||||
EXPECTED_MD5 "${EXPECTED_MD5}"
|
||||
)
|
||||
message(STATUS "LOG: ${log}")
|
||||
@@ -1,72 +0,0 @@
|
||||
# package bundler
|
||||
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
|
||||
if(EXISTS "${CMAKE_ROOT}/Modules/InstallRequiredSystemLibraries.cmake")
|
||||
set(CMAKE_INSTALL_MFC_LIBRARIES 0)
|
||||
set(CMAKE_INSTALL_DEBUG_LIBRARIES 0)
|
||||
if(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
|
||||
set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
|
||||
endif()
|
||||
include(${CMAKE_ROOT}/Modules/InstallRequiredSystemLibraries.cmake)
|
||||
endif()
|
||||
|
||||
set(OPJ_PACKAGE_DESCRIPTION_SUMMARY "OpenJPEG - OpenJPEG a JPEG 2000 implementation.")
|
||||
set(OPJ_PACKAGE_CONTACT "openjpeg users <openjpeg@googlegroups.com>")
|
||||
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${OPJ_PACKAGE_DESCRIPTION_SUMMARY})
|
||||
set(CPACK_PACKAGE_VENDOR "OpenJPEG Team")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" COPYONLY
|
||||
)
|
||||
# For PackageMaker on MacOSX it is important to have a file extension:
|
||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "${OPENJPEG_VERSION_MAJOR}")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "${OPENJPEG_VERSION_MINOR}")
|
||||
set(CPACK_PACKAGE_VERSION_PATCH "${OPENJPEG_VERSION_BUILD}")
|
||||
set(CPACK_PACKAGE_INSTALL_DIRECTORY "OpenJPEG ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
|
||||
set(CPACK_SOURCE_PACKAGE_FILE_NAME "openjpeg-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
||||
|
||||
# Make this explicit here, rather than accepting the CPack default value,
|
||||
# so we can refer to it:
|
||||
set(CPACK_PACKAGE_NAME "${OPENJPEG_LIBRARY_NAME}")
|
||||
|
||||
if(NOT DEFINED CPACK_SYSTEM_NAME)
|
||||
# make sure package is not Cygwin-unknown, for Cygwin just
|
||||
# cygwin is good for the system name
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
|
||||
set(CPACK_SYSTEM_NAME Cygwin)
|
||||
else()
|
||||
set(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR})
|
||||
endif()
|
||||
endif()
|
||||
if(${CPACK_SYSTEM_NAME} MATCHES Windows)
|
||||
if(CMAKE_CL_64)
|
||||
set(CPACK_SYSTEM_NAME win64-x64)
|
||||
else()
|
||||
set(CPACK_SYSTEM_NAME win32-x86)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CPACK_PACKAGE_FILE_NAME)
|
||||
# if the CPACK_PACKAGE_FILE_NAME is not defined by the cache
|
||||
# default to source package - system, on cygwin system is not
|
||||
# needed
|
||||
if(CYGWIN)
|
||||
set(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}")
|
||||
else()
|
||||
set(CPACK_PACKAGE_FILE_NAME
|
||||
"${CPACK_SOURCE_PACKAGE_FILE_NAME}-${CPACK_SYSTEM_NAME}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CPACK_BUNDLE_NAME "OpenJPEG ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
|
||||
if(APPLE)
|
||||
configure_file(${CMAKE_ROOT}/Templates/AppleInfo.plist
|
||||
${CMAKE_CURRENT_BINARY_DIR}/opj.plist)
|
||||
set(CPACK_BUNDLE_PLIST
|
||||
${CMAKE_CURRENT_BINARY_DIR}/opj.plist)
|
||||
#include(BundleUtilities)
|
||||
endif()
|
||||
|
||||
include(CPack)
|
||||
endiF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
|
||||
@@ -1,10 +0,0 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* Cause a compile-time error if off_t is smaller than 64 bits */
|
||||
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||
int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#cmakedefine _LARGEFILE_SOURCE
|
||||
#cmakedefine _LARGE_FILES
|
||||
#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* Cause a compile-time error if off_t is smaller than 64 bits,
|
||||
* and make sure we have ftello / fseeko.
|
||||
*/
|
||||
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
|
||||
int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
|
||||
FILE *fp = fopen(argv[0],"r");
|
||||
off_t offset = ftello( fp );
|
||||
|
||||
fseeko( fp, offset, SEEK_CUR );
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
# - Define macro to check large file support
|
||||
#
|
||||
# OPJ_TEST_LARGE_FILES(VARIABLE)
|
||||
#
|
||||
# VARIABLE will be set to true if off_t is 64 bits, and fseeko/ftello present.
|
||||
# This macro will also defines the necessary variable enable large file support, for instance
|
||||
# _LARGE_FILES
|
||||
# _LARGEFILE_SOURCE
|
||||
# _FILE_OFFSET_BITS 64
|
||||
# HAVE_FSEEKO
|
||||
#
|
||||
# However, it is YOUR job to make sure these defines are set in a #cmakedefine so they
|
||||
# end up in a config.h file that is included in your source if necessary!
|
||||
#
|
||||
# Adapted from Gromacs project (http://www.gromacs.org/)
|
||||
# by Julien Malik
|
||||
#
|
||||
|
||||
macro(OPJ_TEST_LARGE_FILES VARIABLE)
|
||||
if("${VARIABLE}" MATCHES "^${VARIABLE}$")
|
||||
|
||||
# On most platforms it is probably overkill to first test the flags for 64-bit off_t,
|
||||
# and then separately fseeko. However, in the future we might have 128-bit filesystems
|
||||
# (ZFS), so it might be dangerous to indiscriminately set e.g. _FILE_OFFSET_BITS=64.
|
||||
|
||||
message(STATUS "Checking for 64-bit off_t")
|
||||
|
||||
# First check without any special flags
|
||||
try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c")
|
||||
if(FILE64_OK)
|
||||
message(STATUS "Checking for 64-bit off_t - present")
|
||||
endif()
|
||||
|
||||
if(NOT FILE64_OK)
|
||||
# Test with _FILE_OFFSET_BITS=64
|
||||
try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
|
||||
COMPILE_DEFINITIONS "-D_FILE_OFFSET_BITS=64" )
|
||||
if(FILE64_OK)
|
||||
message(STATUS "Checking for 64-bit off_t - present with _FILE_OFFSET_BITS=64")
|
||||
set(_FILE_OFFSET_BITS 64)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT FILE64_OK)
|
||||
# Test with _LARGE_FILES
|
||||
try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
|
||||
COMPILE_DEFINITIONS "-D_LARGE_FILES" )
|
||||
if(FILE64_OK)
|
||||
message(STATUS "Checking for 64-bit off_t - present with _LARGE_FILES")
|
||||
set(_LARGE_FILES 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT FILE64_OK)
|
||||
# Test with _LARGEFILE_SOURCE
|
||||
try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
|
||||
"${PROJECT_SOURCE_DIR}/cmake/TestFileOffsetBits.c"
|
||||
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
|
||||
if(FILE64_OK)
|
||||
message(STATUS "Checking for 64-bit off_t - present with _LARGEFILE_SOURCE")
|
||||
set(_LARGEFILE_SOURCE 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
#if(NOT FILE64_OK)
|
||||
# # now check for Windows stuff
|
||||
# try_compile(FILE64_OK "${PROJECT_BINARY_DIR}"
|
||||
# "${PROJECT_SOURCE_DIR}/cmake/TestWindowsFSeek.c")
|
||||
# if(FILE64_OK)
|
||||
# message(STATUS "Checking for 64-bit off_t - present with _fseeki64")
|
||||
# set(HAVE__FSEEKI64 1)
|
||||
# endif()
|
||||
#endif()
|
||||
|
||||
if(NOT FILE64_OK)
|
||||
message(STATUS "Checking for 64-bit off_t - not present")
|
||||
endif()
|
||||
|
||||
set(_FILE_OFFSET_BITS ${_FILE_OFFSET_BITS} CACHE INTERNAL "Result of test for needed _FILE_OFFSET_BITS=64")
|
||||
set(_LARGE_FILES ${_LARGE_FILES} CACHE INTERNAL "Result of test for needed _LARGE_FILES")
|
||||
set(_LARGEFILE_SOURCE ${_LARGEFILE_SOURCE} CACHE INTERNAL "Result of test for needed _LARGEFILE_SOURCE")
|
||||
|
||||
# Set the flags we might have determined to be required above
|
||||
configure_file("${PROJECT_SOURCE_DIR}/cmake/TestLargeFiles.c.cmake.in"
|
||||
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
|
||||
|
||||
message(STATUS "Checking for fseeko/ftello")
|
||||
|
||||
# Test if ftello/fseeko are available
|
||||
try_compile(FSEEKO_COMPILE_OK
|
||||
"${PROJECT_BINARY_DIR}"
|
||||
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c")
|
||||
|
||||
if(FSEEKO_COMPILE_OK)
|
||||
message(STATUS "Checking for fseeko/ftello - present")
|
||||
endif()
|
||||
|
||||
if(NOT FSEEKO_COMPILE_OK)
|
||||
# glibc 2.2 needs _LARGEFILE_SOURCE for fseeko (but not for 64-bit off_t...)
|
||||
try_compile(FSEEKO_COMPILE_OK
|
||||
"${PROJECT_BINARY_DIR}"
|
||||
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestLargeFiles.c"
|
||||
COMPILE_DEFINITIONS "-D_LARGEFILE_SOURCE" )
|
||||
|
||||
if(FSEEKO_COMPILE_OK)
|
||||
message(STATUS "Checking for fseeko/ftello - present with _LARGEFILE_SOURCE")
|
||||
set(_LARGEFILE_SOURCE ${_LARGEFILE_SOURCE} CACHE INTERNAL "Result of test for needed _LARGEFILE_SOURCE")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(FSEEKO_COMPILE_OK)
|
||||
set(HAVE_FSEEKO ON CACHE INTERNAL "Result of test for fseeko/ftello")
|
||||
else()
|
||||
message(STATUS "Checking for fseeko/ftello - not found")
|
||||
set(HAVE_FSEEKO OFF CACHE INTERNAL "Result of test for fseeko/ftello")
|
||||
endif()
|
||||
|
||||
if(FILE64_OK AND FSEEKO_COMPILE_OK)
|
||||
message(STATUS "Large File support - found")
|
||||
set(${VARIABLE} ON CACHE INTERNAL "Result of test for large file support")
|
||||
else()
|
||||
message(STATUS "Large File support - not found")
|
||||
set(${VARIABLE} OFF CACHE INTERNAL "Result of test for large file support")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
__int64 off=0;
|
||||
|
||||
_fseeki64(NULL, off, SEEK_SET);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
|
||||
|
||||
{
|
||||
<Appears with libpng uses with Ubuntu10.04 (hulk)>
|
||||
Memcheck:Cond
|
||||
fun:deflate
|
||||
obj:/lib/libpng12.so.0.42.0
|
||||
obj:/lib/libpng12.so.0.42.0
|
||||
obj:/lib/libpng12.so.0.42.0
|
||||
fun:png_write_row
|
||||
fun:imagetopng
|
||||
fun:main
|
||||
}
|
||||
{
|
||||
<Appears with libpng uses with Ubuntu10.04 (hulk)>
|
||||
Memcheck:Value8
|
||||
fun:crc32
|
||||
obj:/lib/libpng12.so.0.42.0
|
||||
fun:png_write_chunk
|
||||
obj:/lib/libpng12.so.0.42.0
|
||||
obj:/lib/libpng12.so.0.42.0
|
||||
obj:/lib/libpng12.so.0.42.0
|
||||
obj:/lib/libpng12.so.0.42.0
|
||||
fun:png_write_row
|
||||
fun:imagetopng
|
||||
fun:main
|
||||
}
|
||||
{
|
||||
<Appears with libpng uses with Ubuntu10.04 (hulk)>
|
||||
Memcheck:Param
|
||||
write(buf)
|
||||
fun:__write_nocancel
|
||||
fun:_IO_file_write@@GLIBC_2.2.5
|
||||
fun:_IO_do_write@@GLIBC_2.2.5
|
||||
fun:_IO_file_close_it@@GLIBC_2.2.5
|
||||
fun:fclose@@GLIBC_2.2.5
|
||||
fun:imagetopng
|
||||
fun:main
|
||||
}
|
||||
94
codec/CMakeLists.txt
Normal file
94
codec/CMakeLists.txt
Normal file
@@ -0,0 +1,94 @@
|
||||
# Build the demo app, small examples
|
||||
|
||||
# First thing define the common source:
|
||||
SET(common_SRCS
|
||||
convert.c
|
||||
index.c
|
||||
)
|
||||
|
||||
# Then check if getopt is present:
|
||||
INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
|
||||
SET(DONT_HAVE_GETOPT 1)
|
||||
IF(UNIX) #I am pretty sure only *nix sys have this anyway
|
||||
CHECK_INCLUDE_FILE("getopt.h" CMAKE_HAVE_GETOPT_H)
|
||||
# Seems like we need the contrary:
|
||||
IF(CMAKE_HAVE_GETOPT_H)
|
||||
SET(DONT_HAVE_GETOPT 0)
|
||||
ENDIF(CMAKE_HAVE_GETOPT_H)
|
||||
ENDIF(UNIX)
|
||||
|
||||
# If not getopt was found then add it to the lib:
|
||||
IF(DONT_HAVE_GETOPT)
|
||||
ADD_DEFINITIONS(-DDONT_HAVE_GETOPT)
|
||||
SET(common_SRCS
|
||||
${common_SRCS}
|
||||
compat/getopt.c
|
||||
)
|
||||
ENDIF(DONT_HAVE_GETOPT)
|
||||
|
||||
# Headers file are located here:
|
||||
INCLUDE_DIRECTORIES(
|
||||
${OPENJPEG_SOURCE_DIR}/libopenjpeg
|
||||
)
|
||||
|
||||
# Do the proper thing when building static...if only there was configured
|
||||
# headers or def files instead
|
||||
IF(NOT BUILD_SHARED_LIBS)
|
||||
ADD_DEFINITIONS(-DOPJ_STATIC)
|
||||
ENDIF(NOT BUILD_SHARED_LIBS)
|
||||
|
||||
FIND_PACKAGE(TIFF REQUIRED)
|
||||
FIND_PACKAGE(PNG REQUIRED)
|
||||
INCLUDE_DIRECTORIES( ${PNG_INCLUDE_DIR} )
|
||||
INCLUDE_DIRECTORIES( ${TIFF_INCLUDE_DIR} )
|
||||
|
||||
# Loop over all executables:
|
||||
FOREACH(exe j2k_to_image image_to_j2k j2k_dump)
|
||||
ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS})
|
||||
TARGET_LINK_LIBRARIES(${exe} ${OPJ_PREFIX}openjpeg ${TIFF_LIBRARIES} ${PNG_LIBRARIES})
|
||||
ADD_TEST(${exe} ${EXECUTABLE_OUTPUT_PATH}/${exe})
|
||||
# calling those exe without option will make them fail always:
|
||||
SET_TESTS_PROPERTIES(${exe} PROPERTIES WILL_FAIL TRUE)
|
||||
# On unix you need to link to the math library:
|
||||
IF(UNIX)
|
||||
TARGET_LINK_LIBRARIES(${exe} m)
|
||||
ENDIF(UNIX)
|
||||
# Install exe
|
||||
INSTALL(TARGETS ${exe}
|
||||
EXPORT OpenJPEGTargets
|
||||
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
|
||||
)
|
||||
ENDFOREACH(exe)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
# Do testing here, once we know the examples are being built:
|
||||
FILE(GLOB_RECURSE OPENJPEG_DATA_IMAGES_GLOB
|
||||
"${JPEG2000_CONFORMANCE_DATA_ROOT}/*.j2k"
|
||||
"${JPEG2000_CONFORMANCE_DATA_ROOT}/*.j2c"
|
||||
"${JPEG2000_CONFORMANCE_DATA_ROOT}/*.jp2"
|
||||
)
|
||||
|
||||
foreach(filename ${OPENJPEG_DATA_IMAGES_GLOB})
|
||||
get_filename_component(filename_temp ${filename} NAME)
|
||||
get_filename_component(filename_ext ${filename} EXT)
|
||||
execute_process(COMMAND ${EXECUTABLE_OUTPUT_PATH}/j2k_dump -i ${filename}
|
||||
OUTPUT_VARIABLE dump_success
|
||||
OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${filename_temp}.dump
|
||||
ERROR_QUIET
|
||||
)
|
||||
if(dump_success)
|
||||
file(READ ${CMAKE_CURRENT_BINARY_DIR}/${filename_temp}.dump numcomp_file)
|
||||
string(REGEX REPLACE ".*numcomps=([0-9]+).*" "\\1"
|
||||
numcomps "${numcomp_file}")
|
||||
#message( "found:${output_variable} for ${filename_temp}" )
|
||||
endif()
|
||||
ADD_TEST(dump-${filename_temp} ${EXECUTABLE_OUTPUT_PATH}/j2k_dump -i ${filename})
|
||||
foreach(codec_type ppm pgx bmp tif raw tga png)
|
||||
ADD_TEST(j2i-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/j2k_to_image -i ${filename} -o ${filename_temp}.${codec_type})
|
||||
ADD_TEST(i2j-${filename_temp}-${codec_type} ${EXECUTABLE_OUTPUT_PATH}/image_to_j2k -i ${filename_temp}.${codec_type} -o ${filename_temp}.${codec_type}${filename_ext})
|
||||
#if(UNIX)
|
||||
# ADD_TEST(cmp-${filename_temp}-${codec_type} cmp ${filename} ${filename_temp}.${codec_type}${filename_ext})
|
||||
#endif(UNIX)
|
||||
endforeach(codec_type)
|
||||
endforeach(filename)
|
||||
endif(BUILD_TESTING)
|
||||
@@ -34,110 +34,113 @@
|
||||
/* last review : october 29th, 2002 */
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)opj_getopt.c 8.3 (Berkeley) 4/27/95";
|
||||
static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "opj_getopt.h"
|
||||
|
||||
int opj_opterr = 1, /* if error message should be printed */
|
||||
opj_optind = 1, /* index into parent argv vector */
|
||||
opj_optopt, /* character checked for validity */
|
||||
opj_optreset; /* reset getopt */
|
||||
char *opj_optarg; /* argument associated with option */
|
||||
int opterr = 1, /* if error message should be printed */
|
||||
optind = 1, /* index into parent argv vector */
|
||||
optopt, /* character checked for validity */
|
||||
optreset; /* reset getopt */
|
||||
const char *optarg; /* argument associated with option */
|
||||
|
||||
typedef struct option
|
||||
{
|
||||
const char *name;
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
}option_t;
|
||||
|
||||
#define BADCH (int)'?'
|
||||
#define BADARG (int)':'
|
||||
static char EMSG[]={""};
|
||||
#define EMSG ""
|
||||
|
||||
|
||||
/* As this class remembers its values from one Java call to the other, reset the values before each use */
|
||||
void reset_options_reading(void) {
|
||||
opj_opterr = 1;
|
||||
opj_optind = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* getopt --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int opj_getopt(int nargc, char *const *nargv, const char *ostr) {
|
||||
int getopt(int nargc, char *const *nargv, const char *ostr) {
|
||||
# define __progname nargv[0]
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
char *oli = NULL; /* option letter list index */
|
||||
static const char *place = EMSG; /* option letter processing */
|
||||
char *oli; /* option letter list index */
|
||||
|
||||
if (opj_optreset || !*place) { /* update scanning pointer */
|
||||
opj_optreset = 0;
|
||||
if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') {
|
||||
if (optreset || !*place) { /* update scanning pointer */
|
||||
optreset = 0;
|
||||
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
if (place[1] && *++place == '-') { /* found "--" */
|
||||
++opj_optind;
|
||||
++optind;
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
} /* option letter okay? */
|
||||
if ((opj_optopt = (int) *place++) == (int) ':' ||
|
||||
!(oli = strchr(ostr, opj_optopt))) {
|
||||
if ((optopt = (int) *place++) == (int) ':' ||
|
||||
!(oli = strchr(ostr, optopt))) {
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means -1.
|
||||
*/
|
||||
if (opj_optopt == (int) '-')
|
||||
if (optopt == (int) '-')
|
||||
return (-1);
|
||||
if (!*place)
|
||||
++opj_optind;
|
||||
if (opj_opterr && *ostr != ':') {
|
||||
++optind;
|
||||
if (opterr && *ostr != ':') {
|
||||
fprintf(stderr,
|
||||
"%s: illegal option -- %c\n", __progname, opj_optopt);
|
||||
"%s: illegal option -- %c\n", __progname, optopt);
|
||||
return (BADCH);
|
||||
}
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
opj_optarg = NULL;
|
||||
optarg = NULL;
|
||||
if (!*place)
|
||||
++opj_optind;
|
||||
++optind;
|
||||
} else { /* need an argument */
|
||||
if (*place) /* no white space */
|
||||
opj_optarg = place;
|
||||
else if (nargc <= ++opj_optind) { /* no arg */
|
||||
optarg = place;
|
||||
else if (nargc <= ++optind) { /* no arg */
|
||||
place = EMSG;
|
||||
if (*ostr == ':')
|
||||
return (BADARG);
|
||||
if (opj_opterr) {
|
||||
if (opterr) {
|
||||
fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
__progname, opj_optopt);
|
||||
__progname, optopt);
|
||||
return (BADCH);
|
||||
}
|
||||
} else /* white space */
|
||||
opj_optarg = nargv[opj_optind];
|
||||
optarg = nargv[optind];
|
||||
place = EMSG;
|
||||
++opj_optind;
|
||||
++optind;
|
||||
}
|
||||
return (opj_optopt); /* dump back option letter */
|
||||
return (optopt); /* dump back option letter */
|
||||
}
|
||||
|
||||
|
||||
int opj_getopt_long(int argc, char * const argv[], const char *optstring,
|
||||
const opj_option_t *longopts, int totlen) {
|
||||
int getopt_long(int argc, char * const argv[], const char *optstring,
|
||||
struct option *longopts, int totlen) {
|
||||
static int lastidx,lastofs;
|
||||
char *tmp;
|
||||
int i,len;
|
||||
char param = 1;
|
||||
|
||||
again:
|
||||
if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind]!='-')
|
||||
if (optind>argc || !argv[optind] || *argv[optind]!='-')
|
||||
return -1;
|
||||
|
||||
if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
|
||||
if(opj_optind >= (argc - 1)){ /* no more input parameters */
|
||||
if (argv[optind][0]=='-' && argv[optind][1]==0) {
|
||||
if(optind >= (argc - 1)){ /* no more input parameters */
|
||||
param = 0;
|
||||
}
|
||||
else{ /* more input parameters */
|
||||
if(argv[opj_optind + 1][0] == '-'){
|
||||
if(argv[optind + 1][0] == '-'){
|
||||
param = 0; /* Missing parameter after '-' */
|
||||
}
|
||||
else{
|
||||
@@ -147,108 +150,108 @@ again:
|
||||
}
|
||||
|
||||
if (param == 0) {
|
||||
++opj_optind;
|
||||
++optind;
|
||||
return (BADCH);
|
||||
}
|
||||
|
||||
if (argv[opj_optind][0]=='-') { /* long option */
|
||||
char* arg=argv[opj_optind]+1;
|
||||
const opj_option_t* o;
|
||||
if (argv[optind][0]=='-') { /* long option */
|
||||
char* arg=argv[optind]+1;
|
||||
const struct option* o;
|
||||
o=longopts;
|
||||
len=sizeof(longopts[0]);
|
||||
|
||||
if (param > 1){
|
||||
arg = argv[opj_optind+1];
|
||||
opj_optind++;
|
||||
arg = argv[optind+1];
|
||||
optind++;
|
||||
}
|
||||
else
|
||||
arg = argv[opj_optind]+1;
|
||||
arg = argv[optind]+1;
|
||||
|
||||
if(strlen(arg)>1){
|
||||
for (i=0;i<totlen;i=i+len,o++) {
|
||||
if (!strcmp(o->name,arg)) { /* match */
|
||||
if (o->has_arg == 0) {
|
||||
if ((argv[opj_optind+1])&&(!(argv[opj_optind+1][0]=='-'))){
|
||||
fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[opj_optind+1]);
|
||||
++opj_optind;
|
||||
if ((argv[optind+1])&&(!(argv[optind+1][0]=='-'))){
|
||||
fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[optind+1]);
|
||||
++optind;
|
||||
}
|
||||
}else{
|
||||
opj_optarg=argv[opj_optind+1];
|
||||
if(opj_optarg){
|
||||
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
|
||||
if (opj_opterr) {
|
||||
optarg=argv[optind+1];
|
||||
if(optarg){
|
||||
if (optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
|
||||
if (opterr) {
|
||||
fprintf(stderr,"%s: option requires an argument\n",arg);
|
||||
return (BADCH);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!opj_optarg && o->has_arg==1) { /* no argument there */
|
||||
if (opj_opterr) {
|
||||
if (!optarg && o->has_arg==1) { /* no argument there */
|
||||
if (opterr) {
|
||||
fprintf(stderr,"%s: option requires an argument \n",arg);
|
||||
return (BADCH);
|
||||
}
|
||||
}
|
||||
++opj_optind;
|
||||
++optind;
|
||||
}
|
||||
++opj_optind;
|
||||
++optind;
|
||||
if (o->flag)
|
||||
*(o->flag)=o->val;
|
||||
else
|
||||
return o->val;
|
||||
return 0;
|
||||
}
|
||||
}/*(end for)String not found in the list*/
|
||||
}//(end for)String not found in the list
|
||||
fprintf(stderr,"Invalid option %s\n",arg);
|
||||
++opj_optind;
|
||||
++optind;
|
||||
return (BADCH);
|
||||
}else{ /*Single character input parameter*/
|
||||
if (*optstring==':') return ':';
|
||||
if (lastidx!=opj_optind) {
|
||||
lastidx=opj_optind; lastofs=0;
|
||||
if (lastidx!=optind) {
|
||||
lastidx=optind; lastofs=0;
|
||||
}
|
||||
opj_optopt=argv[opj_optind][lastofs+1];
|
||||
if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/
|
||||
optopt=argv[optind][lastofs+1];
|
||||
if ((tmp=strchr(optstring,optopt))) {/*Found input parameter in list*/
|
||||
if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */
|
||||
++opj_optind;
|
||||
++optind;
|
||||
goto again;
|
||||
}
|
||||
if (tmp[1]==':') { /* argument expected */
|
||||
if (tmp[2]==':' || argv[opj_optind][lastofs+2]) { /* "-foo", return "oo" as opj_optarg */
|
||||
if (!*(opj_optarg=argv[opj_optind]+lastofs+2)) opj_optarg=0;
|
||||
if (tmp[2]==':' || argv[optind][lastofs+2]) { /* "-foo", return "oo" as optarg */
|
||||
if (!*(optarg=argv[optind]+lastofs+2)) optarg=0;
|
||||
goto found;
|
||||
}
|
||||
opj_optarg=argv[opj_optind+1];
|
||||
if(opj_optarg){
|
||||
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
|
||||
if (opj_opterr) {
|
||||
optarg=argv[optind+1];
|
||||
if(optarg){
|
||||
if (optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
|
||||
if (opterr) {
|
||||
fprintf(stderr,"%s: option requires an argument\n",arg);
|
||||
return (BADCH);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!opj_optarg) { /* missing argument */
|
||||
if (opj_opterr) {
|
||||
if (!optarg) { /* missing argument */
|
||||
if (opterr) {
|
||||
fprintf(stderr,"%s: option requires an argument\n",arg);
|
||||
return (BADCH);
|
||||
}
|
||||
}
|
||||
++opj_optind;
|
||||
++optind;
|
||||
}else {/*Argument not expected*/
|
||||
++lastofs;
|
||||
return opj_optopt;
|
||||
return optopt;
|
||||
}
|
||||
found:
|
||||
++opj_optind;
|
||||
return opj_optopt;
|
||||
++optind;
|
||||
return optopt;
|
||||
} else { /* not found */
|
||||
fprintf(stderr,"Invalid option %s\n",arg);
|
||||
++opj_optind;
|
||||
++optind;
|
||||
return (BADCH);
|
||||
}/*end of not found*/
|
||||
}//end of not found
|
||||
|
||||
}/* end of single character*/
|
||||
}/*end '-'*/
|
||||
}// end of single character
|
||||
}//end '-'
|
||||
fprintf(stderr,"Invalid option\n");
|
||||
++opj_optind;
|
||||
++optind;
|
||||
return (BADCH);;
|
||||
}/*end function*/
|
||||
}//end function
|
||||
15
src/bin/jp3d/getopt.h → codec/compat/getopt.h
Executable file → Normal file
15
src/bin/jp3d/getopt.h → codec/compat/getopt.h
Executable file → Normal file
@@ -3,6 +3,18 @@
|
||||
#ifndef _GETOPT_H_
|
||||
#define _GETOPT_H_
|
||||
|
||||
typedef struct option
|
||||
{
|
||||
const char *name;
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
}option_t;
|
||||
|
||||
#define NO_ARG 0
|
||||
#define REQ_ARG 1
|
||||
#define OPT_ARG 2
|
||||
|
||||
extern int opterr;
|
||||
extern int optind;
|
||||
extern int optopt;
|
||||
@@ -10,5 +22,8 @@ extern int optreset;
|
||||
extern char *optarg;
|
||||
|
||||
extern int getopt(int nargc, char *const *nargv, const char *ostr);
|
||||
extern int getopt_long(int argc, char * const argv[], const char *optstring,
|
||||
const struct option *longopts, int totlen);
|
||||
|
||||
|
||||
#endif /* _GETOPT_H_ */
|
||||
2518
codec/convert.c
Normal file
2518
codec/convert.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -43,7 +43,7 @@ typedef struct raw_cparameters {
|
||||
/** bit depth of the raw image */
|
||||
int rawBitDepth;
|
||||
/** signed/unsigned raw image */
|
||||
opj_bool rawSigned;
|
||||
bool rawSigned;
|
||||
/*@}*/
|
||||
} raw_cparameters_t;
|
||||
|
||||
@@ -55,7 +55,7 @@ int imagetotga(opj_image_t * image, const char *outfile);
|
||||
opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters);
|
||||
int imagetobmp(opj_image_t *image, const char *outfile);
|
||||
|
||||
/* TIFF conversion*/
|
||||
/* TIFF to image conversion*/
|
||||
opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters);
|
||||
int imagetotif(opj_image_t *image, const char *outfile);
|
||||
/**
|
||||
@@ -74,9 +74,5 @@ int imagetopnm(opj_image_t *image, const char *outfile);
|
||||
int imagetoraw(opj_image_t * image, const char *outfile);
|
||||
opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw_cparameters_t *raw_cp);
|
||||
|
||||
/* PNG conversion*/
|
||||
extern int imagetopng(opj_image_t *image, const char *write_idf);
|
||||
extern opj_image_t* pngtoimage(const char *filename, opj_cparameters_t *parameters);
|
||||
|
||||
#endif /* __J2K_CONVERT_H */
|
||||
|
||||
@@ -107,8 +107,6 @@
|
||||
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
|
||||
# if defined(_MSC_VER) /* Microsoft C/C++ */
|
||||
/* no dirent.h */
|
||||
# elif defined(__MINGW32__) /* MinGW */
|
||||
/* no dirent.h */
|
||||
# elif defined(__BORLANDC__) /* Borland C/C++ */
|
||||
# define HAVE_DIRENT_H
|
||||
# define VOID_CLOSEDIR
|
||||
@@ -124,7 +122,7 @@
|
||||
# error "not implemented"
|
||||
# elif defined(__sgi) /* Silicon Graphics */
|
||||
# define HAVE_DIRENT_H
|
||||
# elif defined(sun) || defined(__sun) /* Sun Solaris */
|
||||
# elif defined(sun) || defined(_sun) /* Sun Solaris */
|
||||
# define HAVE_DIRENT_H
|
||||
# elif defined(__FreeBSD__) /* FreeBSD */
|
||||
# define HAVE_DIRENT_H
|
||||
@@ -6,6 +6,7 @@
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2006-2007, Parvatha Elangovan
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -29,34 +30,38 @@
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "windirent.h"
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#include "opj_config.h"
|
||||
#define USE_OPJ_DEPRECATED
|
||||
#include "openjpeg.h"
|
||||
#include "opj_getopt.h"
|
||||
#include "compat/getopt.h"
|
||||
#include "convert.h"
|
||||
#include "dirent.h"
|
||||
#include "index.h"
|
||||
|
||||
#include "format_defs.h"
|
||||
#ifndef WIN32
|
||||
#include <strings.h>
|
||||
#define _stricmp strcasecmp
|
||||
#define _strnicmp strncasecmp
|
||||
#endif
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#define J2K_CFMT 0
|
||||
#define JP2_CFMT 1
|
||||
#define JPT_CFMT 2
|
||||
|
||||
#define PXM_DFMT 10
|
||||
#define PGX_DFMT 11
|
||||
#define BMP_DFMT 12
|
||||
#define YUV_DFMT 13
|
||||
#define TIF_DFMT 14
|
||||
#define RAW_DFMT 15
|
||||
#define TGA_DFMT 16
|
||||
#define PNG_DFMT 17
|
||||
/* ----------------------------------------------------------------------- */
|
||||
#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/
|
||||
#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/
|
||||
#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/
|
||||
@@ -82,8 +87,8 @@ typedef struct img_folder{
|
||||
float *rates;
|
||||
}img_fol_t;
|
||||
|
||||
static void encode_help_display(void) {
|
||||
fprintf(stdout,"HELP for opj_jpwl_compress\n----\n\n");
|
||||
void encode_help_display() {
|
||||
fprintf(stdout,"HELP\n----\n\n");
|
||||
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
|
||||
|
||||
/* UniPG>> */
|
||||
@@ -136,9 +141,9 @@ static void encode_help_display(void) {
|
||||
fprintf(stdout,"-OutFor \n");
|
||||
fprintf(stdout," REQUIRED only if -ImgDir is used\n");
|
||||
fprintf(stdout," Need to specify only format without filename <BMP> \n");
|
||||
fprintf(stdout," Currently accepts PBM, PGM, PPM, PNM, PAM, PGX, PNG, BMP, TIF, RAW and TGA formats\n");
|
||||
fprintf(stdout," Currently accepts PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA formats\n");
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(stdout,"-i : source file (-i source.pnm also *pbm, *.pgm, *.ppm, *.pam, *.pgx, *png, *.bmp, *.tif, *.raw, *.tga) \n");
|
||||
fprintf(stdout,"-i : source file (-i source.pnm also *.pgm, *.ppm, *.bmp, *.tif, *.raw, *.tga) \n");
|
||||
fprintf(stdout," When using this option -o must be used\n");
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(stdout,"-o : destination file (-o dest.j2k or .jp2) \n");
|
||||
@@ -193,8 +198,6 @@ static void encode_help_display(void) {
|
||||
fprintf(stdout," Indicate multiple modes by adding their values. \n");
|
||||
fprintf(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(stdout,"-TP : devide packets of every tile into tile-parts (-TP R) [R, L, C]\n");
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n");
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(stdout,"-ROI : c=%%d,U=%%d : quantization indices upshifted \n");
|
||||
@@ -210,9 +213,8 @@ static void encode_help_display(void) {
|
||||
fprintf(stdout,"-F : characteristics of the raw input image\n");
|
||||
fprintf(stdout," -F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
|
||||
fprintf(stdout," Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(stdout,"-jpip : write jpip codestream index box in JP2 output file\n");
|
||||
fprintf(stdout," NOTICE: currently supports only RPCL order\n");
|
||||
fprintf(stdout,"-m : use array-based MCT, values are coma separated, line by line\n");
|
||||
fprintf(stdout," no specific separators between lines, no space allowed between values\n");
|
||||
fprintf(stdout,"\n");
|
||||
/* UniPG>> */
|
||||
#ifdef USE_JPWL
|
||||
@@ -321,7 +323,7 @@ static void encode_help_display(void) {
|
||||
fprintf(stdout,"TotalDisto\n\n");
|
||||
}
|
||||
|
||||
static OPJ_PROG_ORDER give_progression(const char progression[4]) {
|
||||
OPJ_PROG_ORDER give_progression(char progression[4]) {
|
||||
if(strncmp(progression, "LRCP", 4) == 0) {
|
||||
return LRCP;
|
||||
}
|
||||
@@ -341,10 +343,10 @@ static OPJ_PROG_ORDER give_progression(const char progression[4]) {
|
||||
return PROG_UNKNOWN;
|
||||
}
|
||||
|
||||
static unsigned int get_num_images(char *imgdirpath){
|
||||
int get_num_images(char *imgdirpath){
|
||||
DIR *dir;
|
||||
struct dirent* content;
|
||||
unsigned int num_images = 0;
|
||||
int num_images = 0;
|
||||
|
||||
/*Reading the input images from given input directory*/
|
||||
|
||||
@@ -363,7 +365,7 @@ static unsigned int get_num_images(char *imgdirpath){
|
||||
return num_images;
|
||||
}
|
||||
|
||||
static int load_images(dircnt_t *dirptr, char *imgdirpath){
|
||||
int load_images(dircnt_t *dirptr, char *imgdirpath){
|
||||
DIR *dir;
|
||||
struct dirent* content;
|
||||
int i = 0;
|
||||
@@ -388,34 +390,34 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_file_format(char *filename) {
|
||||
int get_file_format(char *filename) {
|
||||
unsigned int i;
|
||||
static const char *extension[] = {
|
||||
"pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "tga", "png", "j2k", "jp2", "j2c", "jpc"
|
||||
"pgx", "pnm", "pgm", "ppm", "bmp", "tif", "raw", "tga", "png", "j2k", "jp2", "j2c", "jpc"
|
||||
};
|
||||
static const int format[] = {
|
||||
PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT, J2K_CFMT
|
||||
PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT, J2K_CFMT
|
||||
};
|
||||
char * ext = strrchr(filename, '.');
|
||||
if (ext == NULL)
|
||||
return -1;
|
||||
ext++;
|
||||
for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
|
||||
if(strcasecmp(ext, extension[i]) == 0) {
|
||||
if(_strnicmp(ext, extension[i], 3) == 0) {
|
||||
return format[i];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static char * get_file_name(char *name){
|
||||
char * get_file_name(char *name){
|
||||
char *fname;
|
||||
fname= (char*)malloc(OPJ_PATH_LEN*sizeof(char));
|
||||
fname= strtok(name,".");
|
||||
return fname;
|
||||
}
|
||||
|
||||
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters){
|
||||
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters){
|
||||
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
|
||||
char *temp_p, temp1[OPJ_PATH_LEN]="";
|
||||
|
||||
@@ -427,7 +429,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
|
||||
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
|
||||
strncpy(parameters->infile, infilename, sizeof(infilename));
|
||||
|
||||
/*Set output file*/
|
||||
//Set output file
|
||||
strcpy(temp_ofname,get_file_name(image_filename));
|
||||
while((temp_p = strtok(NULL,".")) != NULL){
|
||||
strcat(temp_ofname,temp1);
|
||||
@@ -458,8 +460,8 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres){
|
||||
return 2;
|
||||
}
|
||||
|
||||
static void cinema_parameters(opj_cparameters_t *parameters){
|
||||
parameters->tile_size_on = OPJ_FALSE;
|
||||
void cinema_parameters(opj_cparameters_t *parameters){
|
||||
parameters->tile_size_on = false;
|
||||
parameters->cp_tdx=1;
|
||||
parameters->cp_tdy=1;
|
||||
|
||||
@@ -491,7 +493,7 @@ static void cinema_parameters(opj_cparameters_t *parameters){
|
||||
|
||||
}
|
||||
|
||||
static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){
|
||||
void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){
|
||||
int i;
|
||||
float temp_rate;
|
||||
|
||||
@@ -576,41 +578,40 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag
|
||||
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
|
||||
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
||||
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
||||
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
|
||||
int i, j, totlen, c;
|
||||
opj_option_t long_option[]={
|
||||
int i, j,totlen;
|
||||
option_t long_option[]={
|
||||
{"cinema2K",REQ_ARG, NULL ,'w'},
|
||||
{"cinema4K",NO_ARG, NULL ,'y'},
|
||||
{"ImgDir",REQ_ARG, NULL ,'z'},
|
||||
{"TP",REQ_ARG, NULL ,'u'},
|
||||
{"TP",REQ_ARG, NULL ,'v'},
|
||||
{"SOP",NO_ARG, NULL ,'S'},
|
||||
{"EPH",NO_ARG, NULL ,'E'},
|
||||
{"OutFor",REQ_ARG, NULL ,'O'},
|
||||
{"POC",REQ_ARG, NULL ,'P'},
|
||||
{"ROI",REQ_ARG, NULL ,'R'},
|
||||
{"jpip",NO_ARG, NULL, 'J'}
|
||||
};
|
||||
|
||||
/* parse the command line */
|
||||
const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:J"
|
||||
const char optlist[] = "i:o:hr:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:m:"
|
||||
#ifdef USE_JPWL
|
||||
"W:"
|
||||
#endif /* USE_JPWL */
|
||||
"h";
|
||||
;
|
||||
|
||||
totlen=sizeof(long_option);
|
||||
img_fol->set_out_format=0;
|
||||
raw_cp->rawWidth = 0;
|
||||
|
||||
do{
|
||||
c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
|
||||
while (1) {
|
||||
int c = getopt_long(argc, argv, optlist,long_option,totlen);
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
case 'i': /* input file */
|
||||
{
|
||||
char *infile = opj_optarg;
|
||||
char *infile = optarg;
|
||||
parameters->decod_format = get_file_format(infile);
|
||||
switch(parameters->decod_format) {
|
||||
case PGX_DFMT:
|
||||
@@ -624,7 +625,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"!! Unrecognized format for infile : %s "
|
||||
"[accept only *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga] !!\n\n",
|
||||
"[accept only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga] !!\n\n",
|
||||
infile);
|
||||
return 1;
|
||||
}
|
||||
@@ -636,7 +637,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'o': /* output file */
|
||||
{
|
||||
char *outfile = opj_optarg;
|
||||
char *outfile = optarg;
|
||||
parameters->cod_format = get_file_format(outfile);
|
||||
switch(parameters->cod_format) {
|
||||
case J2K_CFMT:
|
||||
@@ -654,14 +655,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
case 'O': /* output format */
|
||||
{
|
||||
char outformat[50];
|
||||
char *of = opj_optarg;
|
||||
char *of = optarg;
|
||||
sprintf(outformat,".%s",of);
|
||||
img_fol->set_out_format = 1;
|
||||
parameters->cod_format = get_file_format(outformat);
|
||||
switch(parameters->cod_format) {
|
||||
case J2K_CFMT:
|
||||
case JP2_CFMT:
|
||||
img_fol->out_format = opj_optarg;
|
||||
img_fol->out_format = optarg;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n");
|
||||
@@ -676,7 +677,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'r': /* rates rates/distorsion */
|
||||
{
|
||||
char *s = opj_optarg;
|
||||
char *s = optarg;
|
||||
parameters->tcp_numlayers = 0;
|
||||
while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) {
|
||||
parameters->tcp_numlayers++;
|
||||
@@ -697,14 +698,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
case 'F': /* Raw image format parameters */
|
||||
{
|
||||
char signo;
|
||||
char *s = opj_optarg;
|
||||
char *s = optarg;
|
||||
if (sscanf(s, "%d,%d,%d,%d,%c", &raw_cp->rawWidth, &raw_cp->rawHeight, &raw_cp->rawComp, &raw_cp->rawBitDepth, &signo) == 5) {
|
||||
if (signo == 's') {
|
||||
raw_cp->rawSigned = OPJ_TRUE;
|
||||
raw_cp->rawSigned = true;
|
||||
fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Signed\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth);
|
||||
}
|
||||
else if (signo == 'u') {
|
||||
raw_cp->rawSigned = OPJ_FALSE;
|
||||
raw_cp->rawSigned = false;
|
||||
fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Unsigned\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth);
|
||||
}
|
||||
else {
|
||||
@@ -730,7 +731,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'q': /* add fixed_quality */
|
||||
{
|
||||
char *s = opj_optarg;
|
||||
char *s = optarg;
|
||||
while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
|
||||
parameters->tcp_numlayers++;
|
||||
while (*s && *s != ',') {
|
||||
@@ -752,7 +753,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
int *row = NULL, *col = NULL;
|
||||
int numlayers = 0, numresolution = 0, matrix_width = 0;
|
||||
|
||||
char *s = opj_optarg;
|
||||
char *s = optarg;
|
||||
sscanf(s, "%d", &numlayers);
|
||||
s++;
|
||||
if (numlayers > 9)
|
||||
@@ -796,8 +797,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 't': /* tiles */
|
||||
{
|
||||
sscanf(opj_optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);
|
||||
parameters->tile_size_on = OPJ_TRUE;
|
||||
sscanf(optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy);
|
||||
parameters->tile_size_on = true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -805,7 +806,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'n': /* resolution */
|
||||
{
|
||||
sscanf(opj_optarg, "%d", ¶meters->numresolution);
|
||||
sscanf(optarg, "%d", ¶meters->numresolution);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -815,7 +816,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
char sep;
|
||||
int res_spec = 0;
|
||||
|
||||
char *s = opj_optarg;
|
||||
char *s = optarg;
|
||||
do {
|
||||
sep = 0;
|
||||
sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec],
|
||||
@@ -834,7 +835,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
case 'b': /* code-block dimension */
|
||||
{
|
||||
int cblockw_init = 0, cblockh_init = 0;
|
||||
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
|
||||
sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);
|
||||
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
|
||||
|| cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
|
||||
fprintf(stderr,
|
||||
@@ -851,7 +852,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'x': /* creation of index file */
|
||||
{
|
||||
char *index = opj_optarg;
|
||||
char *index = optarg;
|
||||
strncpy(indexfilename, index, OPJ_PATH_LEN);
|
||||
}
|
||||
break;
|
||||
@@ -862,7 +863,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
{
|
||||
char progression[4];
|
||||
|
||||
strncpy(progression, opj_optarg, 4);
|
||||
strncpy(progression, optarg, 4);
|
||||
parameters->prog_order = give_progression(progression);
|
||||
if (parameters->prog_order == -1) {
|
||||
fprintf(stderr, "Unrecognized progression order "
|
||||
@@ -876,7 +877,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 's': /* subsampling factor */
|
||||
{
|
||||
if (sscanf(opj_optarg, "%d,%d", ¶meters->subsampling_dx,
|
||||
if (sscanf(optarg, "%d,%d", ¶meters->subsampling_dx,
|
||||
¶meters->subsampling_dy) != 2) {
|
||||
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
|
||||
return 1;
|
||||
@@ -888,7 +889,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'd': /* coordonnate of the reference grid */
|
||||
{
|
||||
if (sscanf(opj_optarg, "%d,%d", ¶meters->image_offset_x0,
|
||||
if (sscanf(optarg, "%d,%d", ¶meters->image_offset_x0,
|
||||
¶meters->image_offset_y0) != 2) {
|
||||
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
|
||||
"error !! [-d x0,y0]\n");
|
||||
@@ -910,7 +911,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
int numpocs = 0; /* number of progression order change (POC) default 0 */
|
||||
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
|
||||
|
||||
char *s = opj_optarg;
|
||||
char *s = optarg;
|
||||
POC = parameters->POC;
|
||||
|
||||
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
|
||||
@@ -952,7 +953,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
case 'M': /* Mode switch pas tous au point !! */
|
||||
{
|
||||
int value = 0;
|
||||
if (sscanf(opj_optarg, "%d", &value) == 1) {
|
||||
if (sscanf(optarg, "%d", &value) == 1) {
|
||||
for (i = 0; i <= 5; i++) {
|
||||
int cache = value & (1 << i);
|
||||
if (cache)
|
||||
@@ -966,7 +967,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'R': /* ROI */
|
||||
{
|
||||
if (sscanf(opj_optarg, "c=%d,U=%d", ¶meters->roi_compno,
|
||||
if (sscanf(optarg, "c=%d,U=%d", ¶meters->roi_compno,
|
||||
¶meters->roi_shift) != 2) {
|
||||
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
|
||||
return 1;
|
||||
@@ -978,7 +979,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'T': /* Tile offset */
|
||||
{
|
||||
if (sscanf(opj_optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) {
|
||||
if (sscanf(optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) {
|
||||
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
|
||||
return 1;
|
||||
}
|
||||
@@ -989,9 +990,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'C': /* add a comment */
|
||||
{
|
||||
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
|
||||
parameters->cp_comment = (char*)malloc(strlen(optarg) + 1);
|
||||
if(parameters->cp_comment) {
|
||||
strcpy(parameters->cp_comment, opj_optarg);
|
||||
strcpy(parameters->cp_comment, optarg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1007,9 +1008,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
|
||||
case 'u': /* Tile part generation*/
|
||||
case 'v': /* Tile part generation*/
|
||||
{
|
||||
parameters->tp_flag = opj_optarg[0];
|
||||
parameters->tp_flag = optarg[0];
|
||||
parameters->tp_on = 1;
|
||||
}
|
||||
break;
|
||||
@@ -1018,8 +1019,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
case 'z': /* Image Directory path */
|
||||
{
|
||||
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
|
||||
strcpy(img_fol->imgdirpath,opj_optarg);
|
||||
img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
|
||||
strcpy(img_fol->imgdirpath,optarg);
|
||||
img_fol->set_imgdir=1;
|
||||
}
|
||||
break;
|
||||
@@ -1029,7 +1030,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
case 'w': /* Digital Cinema 2K profile compliance*/
|
||||
{
|
||||
int fps=0;
|
||||
sscanf(opj_optarg,"%d",&fps);
|
||||
sscanf(optarg,"%d",&fps);
|
||||
if(fps == 24){
|
||||
parameters->cp_cinema = CINEMA2K_24;
|
||||
}else if(fps == 48 ){
|
||||
@@ -1052,6 +1053,76 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
fprintf(stdout,"CINEMA 4K compliant codestream\n");
|
||||
parameters->cp_rsiz = CINEMA4K;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'm': /* output file */
|
||||
{
|
||||
char *lFilename = optarg;
|
||||
char * lMatrix;
|
||||
char *lCurrentPtr ;
|
||||
int lNbComp = 0;
|
||||
int lTotalComp;
|
||||
int lMctComp;
|
||||
float * lCurrentDoublePtr;
|
||||
float * lSpace;
|
||||
int * l_int_ptr;
|
||||
int i;
|
||||
int lStrLen;
|
||||
|
||||
FILE * lFile = fopen(lFilename,"r");
|
||||
if
|
||||
(lFile == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
fseek(lFile,0,SEEK_END);
|
||||
lStrLen = ftell(lFile);
|
||||
fseek(lFile,0,SEEK_SET);
|
||||
lMatrix = (char *) malloc(lStrLen + 1);
|
||||
fread(lMatrix,lStrLen,1,lFile);
|
||||
fclose(lFile);
|
||||
lMatrix[lStrLen] = 0;
|
||||
lCurrentPtr = lMatrix;
|
||||
|
||||
// replace ',' by 0
|
||||
while
|
||||
(*lCurrentPtr != 0 )
|
||||
{
|
||||
if
|
||||
(*lCurrentPtr == ' ')
|
||||
{
|
||||
*lCurrentPtr = 0;
|
||||
++lNbComp;
|
||||
}
|
||||
++lCurrentPtr;
|
||||
}
|
||||
++lNbComp;
|
||||
lCurrentPtr = lMatrix;
|
||||
|
||||
lNbComp = (int) (sqrt(4*lNbComp + 1)/2. - 0.5);
|
||||
lMctComp = lNbComp * lNbComp;
|
||||
lTotalComp = lMctComp + lNbComp;
|
||||
lSpace = (float *) malloc(lTotalComp * sizeof(float));
|
||||
lCurrentDoublePtr = lSpace;
|
||||
for
|
||||
(i=0;i<lMctComp;++i)
|
||||
{
|
||||
lStrLen = strlen(lCurrentPtr) + 1;
|
||||
*lCurrentDoublePtr++ = (float) atof(lCurrentPtr);
|
||||
lCurrentPtr += lStrLen;
|
||||
}
|
||||
l_int_ptr = (int*) lCurrentDoublePtr;
|
||||
for
|
||||
(i=0;i<lNbComp;++i)
|
||||
{
|
||||
lStrLen = strlen(lCurrentPtr) + 1;
|
||||
*l_int_ptr++ = atoi(lCurrentPtr);
|
||||
lCurrentPtr += lStrLen;
|
||||
}
|
||||
opj_set_MCT(parameters,lSpace,(int *)(lSpace + lMctComp), lNbComp);
|
||||
free(lSpace);
|
||||
free(lMatrix);
|
||||
}
|
||||
break;
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
@@ -1073,7 +1144,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
/* search for different protection methods */
|
||||
|
||||
/* break the option in comma points and parse the result */
|
||||
token = strtok(opj_optarg, ",");
|
||||
token = strtok(optarg, ",");
|
||||
while(token != NULL) {
|
||||
|
||||
/* search header error protection method */
|
||||
@@ -1369,27 +1440,20 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
|
||||
/* some info */
|
||||
fprintf(stdout, "Info: JPWL capabilities enabled\n");
|
||||
parameters->jpwl_epc_on = OPJ_TRUE;
|
||||
parameters->jpwl_epc_on = true;
|
||||
|
||||
}
|
||||
break;
|
||||
#endif /* USE_JPWL */
|
||||
/* <<UniPG */
|
||||
/* ------------------------------------------------------ */
|
||||
|
||||
case 'J': /* jpip on */
|
||||
{
|
||||
/*parameters->jpip_on = OPJ_TRUE;*/
|
||||
}
|
||||
break;
|
||||
/* ------------------------------------------------------ */
|
||||
|
||||
|
||||
default:
|
||||
fprintf(stderr, "ERROR -> Command line not valid\n");
|
||||
return 1;
|
||||
}
|
||||
}while(c != -1);
|
||||
}
|
||||
|
||||
/* check for possible errors */
|
||||
if (parameters->cp_cinema){
|
||||
@@ -1415,8 +1479,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
}
|
||||
}else{
|
||||
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
|
||||
fprintf(stderr, "Example: %s -i image.ppm -o image.j2k\n",argv[0]);
|
||||
fprintf(stderr, " Try: %s -h\n",argv[0]);
|
||||
fprintf(stderr, "Error: One of the options; -i or -ImgDir must be specified\n");
|
||||
fprintf(stderr, "Error: When using -i; -o must be used\n");
|
||||
fprintf(stderr, "usage: image_to_j2k -i image-file -o j2k/jp2-file (+ options)\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1466,21 +1531,21 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
|
||||
/**
|
||||
sample error callback expecting a FILE* client object
|
||||
*/
|
||||
static void error_callback(const char *msg, void *client_data) {
|
||||
void error_callback(const char *msg, void *client_data) {
|
||||
FILE *stream = (FILE*)client_data;
|
||||
fprintf(stream, "[ERROR] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample warning callback expecting a FILE* client object
|
||||
*/
|
||||
static void warning_callback(const char *msg, void *client_data) {
|
||||
void warning_callback(const char *msg, void *client_data) {
|
||||
FILE *stream = (FILE*)client_data;
|
||||
fprintf(stream, "[WARNING] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample debug callback expecting a FILE* client object
|
||||
*/
|
||||
static void info_callback(const char *msg, void *client_data) {
|
||||
void info_callback(const char *msg, void *client_data) {
|
||||
FILE *stream = (FILE*)client_data;
|
||||
fprintf(stream, "[INFO] %s", msg);
|
||||
}
|
||||
@@ -1488,27 +1553,24 @@ static void info_callback(const char *msg, void *client_data) {
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
opj_bool bSuccess;
|
||||
bool bSuccess;
|
||||
opj_cparameters_t parameters; /* compression parameters */
|
||||
img_fol_t img_fol;
|
||||
opj_event_mgr_t event_mgr; /* event manager */
|
||||
opj_image_t *image = NULL;
|
||||
int i,num_images;
|
||||
int imageno;
|
||||
dircnt_t *dirptr = NULL;
|
||||
dircnt_t *dirptr;
|
||||
raw_cparameters_t raw_cp;
|
||||
opj_codestream_info_t cstr_info; /* Codestream information structure */
|
||||
char indexfilename[OPJ_PATH_LEN]; /* index file name */
|
||||
opj_stream_t *cio = 00;
|
||||
opj_codec_t* cinfo = 00;
|
||||
FILE *f = NULL;
|
||||
|
||||
/*
|
||||
configure the event callbacks (not required)
|
||||
setting of each callback is optionnal
|
||||
*/
|
||||
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
|
||||
event_mgr.error_handler = error_callback;
|
||||
event_mgr.warning_handler = warning_callback;
|
||||
event_mgr.info_handler = info_callback;
|
||||
|
||||
/* set encoding parameters to default values */
|
||||
opj_set_default_encoder_parameters(¶meters);
|
||||
|
||||
@@ -1550,7 +1612,7 @@ int main(int argc, char **argv) {
|
||||
num_images=get_num_images(img_fol.imgdirpath);
|
||||
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
|
||||
if(dirptr){
|
||||
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
|
||||
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); // Stores at max 10 image file names
|
||||
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
|
||||
if(!dirptr->filename_buf){
|
||||
return 0;
|
||||
@@ -1627,7 +1689,7 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
#ifdef HAVE_LIBTIFF
|
||||
|
||||
case TIF_DFMT:
|
||||
image = tiftoimage(parameters.infile, ¶meters);
|
||||
if (!image) {
|
||||
@@ -1635,7 +1697,7 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
#endif /* HAVE_LIBTIFF */
|
||||
|
||||
case RAW_DFMT:
|
||||
image = rawtoimage(parameters.infile, ¶meters, &raw_cp);
|
||||
if (!image) {
|
||||
@@ -1651,7 +1713,7 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
#ifdef HAVE_LIBPNG
|
||||
|
||||
case PNG_DFMT:
|
||||
image = pngtoimage(parameters.infile, ¶meters);
|
||||
if (!image) {
|
||||
@@ -1659,15 +1721,6 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
#endif /* HAVE_LIBPNG */
|
||||
}
|
||||
/* Can happen if input file is TIFF or PNG
|
||||
* and HAVE_LIBTIF or HAVE_LIBPNG is undefined
|
||||
*/
|
||||
if( !image)
|
||||
{
|
||||
fprintf(stderr, "Unable to load file: got no image\n");
|
||||
return 1;
|
||||
}
|
||||
/* Decide if MCT should be used */
|
||||
parameters.tcp_mct = image->numcomps == 3 ? 1 : 0;
|
||||
@@ -1679,113 +1732,45 @@ int main(int argc, char **argv) {
|
||||
/* encode the destination image */
|
||||
/* ---------------------------- */
|
||||
|
||||
if (parameters.cod_format == J2K_CFMT) { /* J2K format output */
|
||||
int codestream_length;
|
||||
size_t res;
|
||||
opj_cio_t *cio = NULL;
|
||||
FILE *f = NULL;
|
||||
|
||||
/* get a J2K compressor handle */
|
||||
opj_cinfo_t* cinfo = opj_create_compress(CODEC_J2K);
|
||||
|
||||
/* catch events using our callbacks and give a local context */
|
||||
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
|
||||
|
||||
/* setup the encoder parameters using the current image and user parameters */
|
||||
cinfo = parameters.cod_format == J2K_CFMT ? opj_create_compress(CODEC_J2K) : opj_create_compress(CODEC_JP2);
|
||||
opj_setup_encoder(cinfo, ¶meters, image);
|
||||
|
||||
/* open a byte stream for writing */
|
||||
/* allocate memory for all tiles */
|
||||
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
|
||||
|
||||
/* encode the image */
|
||||
if (*indexfilename) /* If need to extract codestream information*/
|
||||
bSuccess = opj_encode_with_info(cinfo, cio, image, &cstr_info);
|
||||
else
|
||||
bSuccess = opj_encode(cinfo, cio, image, NULL);
|
||||
if (!bSuccess) {
|
||||
opj_cio_close(cio);
|
||||
f = fopen(parameters.outfile, "wb");
|
||||
if
|
||||
(! f)
|
||||
{
|
||||
fprintf(stderr, "failed to encode image\n");
|
||||
return 1;
|
||||
}
|
||||
codestream_length = cio_tell(cio);
|
||||
|
||||
/* write the buffer to disk */
|
||||
f = fopen(parameters.outfile, "wb");
|
||||
if (!f) {
|
||||
fprintf(stderr, "failed to open %s for writing\n", parameters.outfile);
|
||||
return 1;
|
||||
}
|
||||
res = fwrite(cio->buffer, 1, codestream_length, f);
|
||||
if( res < (size_t)codestream_length ) { /* FIXME */
|
||||
fprintf(stderr, "failed to write %d (%s)\n", codestream_length, parameters.outfile);
|
||||
return 1;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
fprintf(stderr,"Generated outfile %s\n",parameters.outfile);
|
||||
/* close and free the byte stream */
|
||||
opj_cio_close(cio);
|
||||
|
||||
/* Write the index to disk */
|
||||
if (*indexfilename) {
|
||||
bSuccess = write_index_file(&cstr_info, indexfilename);
|
||||
if (bSuccess) {
|
||||
fprintf(stderr, "Failed to output index file into [%s]\n", indexfilename);
|
||||
}
|
||||
}
|
||||
|
||||
/* free remaining compression structures */
|
||||
opj_destroy_compress(cinfo);
|
||||
if (*indexfilename)
|
||||
opj_destroy_cstr_info(&cstr_info);
|
||||
} else { /* JP2 format output */
|
||||
int codestream_length;
|
||||
size_t res;
|
||||
opj_cio_t *cio = NULL;
|
||||
FILE *f = NULL;
|
||||
opj_cinfo_t *cinfo = NULL;
|
||||
|
||||
/* get a JP2 compressor handle */
|
||||
cinfo = opj_create_compress(CODEC_JP2);
|
||||
|
||||
/* catch events using our callbacks and give a local context */
|
||||
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
|
||||
|
||||
/* setup the encoder parameters using the current image and using user parameters */
|
||||
opj_setup_encoder(cinfo, ¶meters, image);
|
||||
|
||||
/* open a byte stream for writing */
|
||||
/* allocate memory for all tiles */
|
||||
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
|
||||
|
||||
cio = opj_stream_create_default_file_stream(f,false);
|
||||
if
|
||||
(! cio)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
/* encode the image */
|
||||
if (*indexfilename /*|| parameters.jpip_on*/) /* If need to extract codestream information*/
|
||||
/*if (*indexfilename) // If need to extract codestream information
|
||||
bSuccess = opj_encode_with_info(cinfo, cio, image, &cstr_info);
|
||||
else
|
||||
bSuccess = opj_encode(cinfo, cio, image, NULL);
|
||||
if (!bSuccess) {
|
||||
opj_cio_close(cio);
|
||||
else*/
|
||||
bSuccess = opj_start_compress(cinfo,image,cio);
|
||||
bSuccess = bSuccess && opj_encode(cinfo, cio);
|
||||
bSuccess = bSuccess && opj_end_compress(cinfo, cio);
|
||||
|
||||
if
|
||||
(!bSuccess)
|
||||
{
|
||||
opj_stream_destroy(cio);
|
||||
fclose(f);
|
||||
fprintf(stderr, "failed to encode image\n");
|
||||
return 1;
|
||||
}
|
||||
codestream_length = cio_tell(cio);
|
||||
|
||||
/* write the buffer to disk */
|
||||
f = fopen(parameters.outfile, "wb");
|
||||
if (!f) {
|
||||
fprintf(stderr, "failed to open %s for writing\n", parameters.outfile);
|
||||
return 1;
|
||||
}
|
||||
res = fwrite(cio->buffer, 1, codestream_length, f);
|
||||
if( res < (size_t)codestream_length ) { /* FIXME */
|
||||
fprintf(stderr, "failed to write %d (%s)\n", codestream_length, parameters.outfile);
|
||||
return 1;
|
||||
}
|
||||
fclose(f);
|
||||
fprintf(stderr,"Generated outfile %s\n",parameters.outfile);
|
||||
/* close and free the byte stream */
|
||||
opj_cio_close(cio);
|
||||
opj_stream_destroy(cio);
|
||||
fclose(f);
|
||||
|
||||
/* Write the index to disk */
|
||||
if (*indexfilename) {
|
||||
@@ -1796,10 +1781,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
/* free remaining compression structures */
|
||||
opj_destroy_compress(cinfo);
|
||||
opj_destroy_codec(cinfo);
|
||||
if (*indexfilename)
|
||||
opj_destroy_cstr_info(&cstr_info);
|
||||
}
|
||||
|
||||
/* free image data */
|
||||
opj_image_destroy(image);
|
||||
@@ -260,7 +260,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
|
||||
int x1 = x0 + cstr_info->tile_x;
|
||||
int y1 = y0 + cstr_info->tile_y;
|
||||
|
||||
/* Count the maximum number of precincts */
|
||||
// Count the maximum number of precincts
|
||||
int max_numprec = 0;
|
||||
for (resno = 0; resno < max_numdecompos + 1; resno++) {
|
||||
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
|
||||
@@ -311,7 +311,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
|
||||
} /* PCRL */
|
||||
|
||||
else { /* CPRL */
|
||||
/* Count the maximum number of precincts */
|
||||
// Count the maximum number of precincts
|
||||
int max_numprec = 0;
|
||||
for (resno = 0; resno < max_numdecompos + 1; resno++) {
|
||||
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
|
||||
@@ -1,7 +1,12 @@
|
||||
/*
|
||||
* Copyright (c) 2010, Mathieu Malaterre, GDCM
|
||||
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
|
||||
* Copyright (c) 2012, CS Systemes d'Information, France
|
||||
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2001-2003, David Janssens
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2006-2007, Parvatha Elangovan
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -25,33 +30,40 @@
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "opj_config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#define USE_OPJ_DEPRECATED
|
||||
#include "openjpeg.h"
|
||||
#include "j2k.h"
|
||||
#include "jp2.h"
|
||||
#include "compat/getopt.h"
|
||||
#include "convert.h"
|
||||
#include "dirent.h"
|
||||
#include "index.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "windirent.h"
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#ifndef WIN32
|
||||
#include <strings.h>
|
||||
#define _stricmp strcasecmp
|
||||
#define _strnicmp strncasecmp
|
||||
#endif /* _WIN32 */
|
||||
#endif
|
||||
|
||||
#include "openjpeg.h"
|
||||
#include "opj_getopt.h"
|
||||
#include "convert.h"
|
||||
#include "index.h"
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#include "format_defs.h"
|
||||
#define J2K_CFMT 0
|
||||
#define JP2_CFMT 1
|
||||
#define JPT_CFMT 2
|
||||
|
||||
#define PXM_DFMT 10
|
||||
#define PGX_DFMT 11
|
||||
#define BMP_DFMT 12
|
||||
#define YUV_DFMT 13
|
||||
#define TIF_DFMT 14
|
||||
#define RAW_DFMT 15
|
||||
#define TGA_DFMT 16
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
typedef struct dircnt{
|
||||
/** Buffer for holding images read from Directory*/
|
||||
@@ -73,20 +85,8 @@ typedef struct img_folder{
|
||||
|
||||
}img_fol_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Declarations */
|
||||
int get_num_images(char *imgdirpath);
|
||||
int load_images(dircnt_t *dirptr, char *imgdirpath);
|
||||
int get_file_format(const char *filename);
|
||||
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters);
|
||||
static int infile_format(const char *fname);
|
||||
|
||||
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol);
|
||||
int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
static void decode_help_display(void) {
|
||||
fprintf(stdout,"HELP for opj_dump\n----\n\n");
|
||||
void decode_help_display() {
|
||||
fprintf(stdout,"HELP\n----\n\n");
|
||||
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
|
||||
|
||||
/* UniPG>> */
|
||||
@@ -104,18 +104,11 @@ static void decode_help_display(void) {
|
||||
fprintf(stdout," REQUIRED only if an Input image directory not specified\n");
|
||||
fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n");
|
||||
fprintf(stdout," is identified based on its suffix.\n");
|
||||
fprintf(stdout," -o <output file>\n");
|
||||
fprintf(stdout," OPTIONAL\n");
|
||||
fprintf(stdout," Output file where file info will be dump.\n");
|
||||
fprintf(stdout," By default it will be in the stdout.\n");
|
||||
fprintf(stdout," -v "); /* FIXME WIP_MSD */
|
||||
fprintf(stdout," OPTIONAL\n");
|
||||
fprintf(stdout," Activate or not the verbose mode (display info and warning message)\n");
|
||||
fprintf(stdout," By default verbose mode is off.\n");
|
||||
fprintf(stdout,"\n");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int get_num_images(char *imgdirpath){
|
||||
DIR *dir;
|
||||
struct dirent* content;
|
||||
@@ -137,7 +130,6 @@ int get_num_images(char *imgdirpath){
|
||||
return num_images;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
int load_images(dircnt_t *dirptr, char *imgdirpath){
|
||||
DIR *dir;
|
||||
struct dirent* content;
|
||||
@@ -163,11 +155,10 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
int get_file_format(const char *filename) {
|
||||
int get_file_format(char *filename) {
|
||||
unsigned int i;
|
||||
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
|
||||
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
|
||||
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "j2k", "jp2", "jpt", "j2c", "jpc" };
|
||||
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
|
||||
char * ext = strrchr(filename, '.');
|
||||
if (ext == NULL)
|
||||
return -1;
|
||||
@@ -183,7 +174,6 @@ int get_file_format(const char *filename) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
|
||||
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
|
||||
char *temp_p, temp1[OPJ_PATH_LEN]="";
|
||||
@@ -196,7 +186,7 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
|
||||
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
|
||||
strncpy(parameters->infile, infilename, sizeof(infilename));
|
||||
|
||||
/*Set output file*/
|
||||
//Set output file
|
||||
strcpy(temp_ofname,strtok(image_filename,"."));
|
||||
while((temp_p = strtok(NULL,".")) != NULL){
|
||||
strcat(temp_ofname,temp1);
|
||||
@@ -210,88 +200,28 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define JP2_RFC3745_MAGIC "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a"
|
||||
#define JP2_MAGIC "\x0d\x0a\x87\x0a"
|
||||
/* position 45: "\xff\x52" */
|
||||
#define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51"
|
||||
|
||||
static int infile_format(const char *fname)
|
||||
{
|
||||
FILE *reader;
|
||||
const char *s, *magic_s;
|
||||
int ext_format, magic_format;
|
||||
unsigned char buf[12];
|
||||
unsigned int l_nb_read;
|
||||
|
||||
reader = fopen(fname, "rb");
|
||||
|
||||
if (reader == NULL)
|
||||
return -1;
|
||||
|
||||
memset(buf, 0, 12);
|
||||
l_nb_read = fread(buf, 1, 12, reader);
|
||||
fclose(reader);
|
||||
if (l_nb_read != 12)
|
||||
return -1;
|
||||
|
||||
|
||||
|
||||
ext_format = get_file_format(fname);
|
||||
|
||||
if (ext_format == JPT_CFMT)
|
||||
return JPT_CFMT;
|
||||
|
||||
if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
|
||||
magic_format = JP2_CFMT;
|
||||
magic_s = ".jp2";
|
||||
}
|
||||
else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
|
||||
magic_format = J2K_CFMT;
|
||||
magic_s = ".j2k or .jpc or .j2c";
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
if (magic_format == ext_format)
|
||||
return ext_format;
|
||||
|
||||
s = fname + strlen(fname) - 4;
|
||||
|
||||
fputs("\n===========================================\n", stderr);
|
||||
fprintf(stderr, "The extension of this file is incorrect.\n"
|
||||
"FOUND %s. SHOULD BE %s\n", s, magic_s);
|
||||
fputs("===========================================\n", stderr);
|
||||
|
||||
return magic_format;
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Parse the command line
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
|
||||
int totlen, c;
|
||||
opj_option_t long_option[]={
|
||||
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
|
||||
/* parse the command line */
|
||||
int totlen;
|
||||
option_t long_option[]={
|
||||
{"ImgDir",REQ_ARG, NULL ,'y'},
|
||||
};
|
||||
const char optlist[] = "i:o:hv";
|
||||
|
||||
const char optlist[] = "i:h";
|
||||
totlen=sizeof(long_option);
|
||||
img_fol->set_out_format = 0;
|
||||
do {
|
||||
c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
|
||||
while (1) {
|
||||
int c = getopt_long(argc, argv,optlist,long_option,totlen);
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
case 'i': /* input file */
|
||||
{
|
||||
char *infile = opj_optarg;
|
||||
parameters->decod_format = infile_format(infile);
|
||||
char *infile = optarg;
|
||||
parameters->decod_format = get_file_format(infile);
|
||||
switch(parameters->decod_format) {
|
||||
case J2K_CFMT:
|
||||
break;
|
||||
case JP2_CFMT:
|
||||
break;
|
||||
case JPT_CFMT:
|
||||
break;
|
||||
default:
|
||||
@@ -302,15 +232,6 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
}
|
||||
strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
|
||||
}
|
||||
break;
|
||||
|
||||
/* ------------------------------------------------------ */
|
||||
|
||||
case 'o': /* output file */
|
||||
{
|
||||
char *outfile = opj_optarg;
|
||||
strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
|
||||
}
|
||||
break;
|
||||
|
||||
/* ----------------------------------------------------- */
|
||||
@@ -323,26 +244,19 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
|
||||
case 'y': /* Image Directory path */
|
||||
{
|
||||
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
|
||||
strcpy(img_fol->imgdirpath,opj_optarg);
|
||||
img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
|
||||
strcpy(img_fol->imgdirpath,optarg);
|
||||
img_fol->set_imgdir=1;
|
||||
}
|
||||
break;
|
||||
|
||||
/* ----------------------------------------------------- */
|
||||
|
||||
case 'v': /* Verbose mode */
|
||||
{
|
||||
parameters->m_verbose = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
/* ----------------------------------------------------- */
|
||||
default:
|
||||
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
|
||||
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);
|
||||
break;
|
||||
}
|
||||
}while(c != -1);
|
||||
}
|
||||
|
||||
/* check for possible errors */
|
||||
if(img_fol->set_imgdir==1){
|
||||
@@ -355,14 +269,14 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n");
|
||||
return 1;
|
||||
}
|
||||
if(!(parameters->outfile[0] == 0)){
|
||||
if(!((parameters->outfile[0] == 0))){
|
||||
fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
|
||||
return 1;
|
||||
}
|
||||
}else{
|
||||
if(parameters->infile[0] == 0) {
|
||||
fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]);
|
||||
fprintf(stderr, " Try: %s -h\n",argv[0]);
|
||||
if((parameters->infile[0] == 0) ) {
|
||||
fprintf(stderr, "Error: One of the options -i or -ImgDir must be specified\n");
|
||||
fprintf(stderr, "usage: image_to_j2k -i *.j2k/jp2/j2c (+ options)\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -373,86 +287,80 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
sample error debug callback expecting no client object
|
||||
sample error callback expecting a FILE* client object
|
||||
*/
|
||||
static void error_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
fprintf(stdout, "[ERROR] %s", msg);
|
||||
void error_callback(const char *msg, void *client_data) {
|
||||
FILE *stream = (FILE*)client_data;
|
||||
fprintf(stream, "[ERROR] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample warning debug callback expecting no client object
|
||||
sample warning callback expecting a FILE* client object
|
||||
*/
|
||||
static void warning_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
fprintf(stdout, "[WARNING] %s", msg);
|
||||
void warning_callback(const char *msg, void *client_data) {
|
||||
FILE *stream = (FILE*)client_data;
|
||||
fprintf(stream, "[WARNING] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample debug callback expecting no client object
|
||||
*/
|
||||
static void info_callback(const char *msg, void *client_data) {
|
||||
void info_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
fprintf(stdout, "[INFO] %s", msg);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/**
|
||||
* OPJ_DUMP MAIN
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *fsrc = NULL, *fout = NULL;
|
||||
|
||||
opj_dparameters_t parameters; /* Decompression parameters */
|
||||
opj_image_t* image = NULL; /* Image structure */
|
||||
opj_codec_t* l_codec = NULL; /* Handle to a decompressor */
|
||||
opj_stream_t *l_stream = NULL; /* Stream */
|
||||
opj_codestream_info_v2_t* cstr_info = NULL;
|
||||
opj_codestream_index_t* cstr_index = NULL;
|
||||
|
||||
OPJ_INT32 num_images, imageno;
|
||||
int ret;
|
||||
opj_dparameters_t parameters; /* decompression parameters */
|
||||
img_fol_t img_fol;
|
||||
dircnt_t *dirptr = NULL;
|
||||
opj_image_t *image = NULL;
|
||||
FILE *fsrc = NULL;
|
||||
bool bResult;
|
||||
int num_images;
|
||||
int i,imageno;
|
||||
dircnt_t *dirptr;
|
||||
opj_codec_t* dinfo = NULL; /* handle to a decompressor */
|
||||
opj_stream_t *cio = NULL;
|
||||
opj_codestream_info_t cstr_info; /* Codestream information structure */
|
||||
char indexfilename[OPJ_PATH_LEN]; /* index file name */
|
||||
OPJ_INT32 l_tile_x0,l_tile_y0;
|
||||
OPJ_UINT32 l_tile_width,l_tile_height,l_nb_tiles_x,l_nb_tiles_y;
|
||||
|
||||
#ifdef MSD
|
||||
OPJ_BOOL l_go_on = OPJ_TRUE;
|
||||
OPJ_UINT32 l_max_data_size = 1000;
|
||||
OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
|
||||
#endif
|
||||
/* configure the event callbacks (not required) */
|
||||
|
||||
/* Set decoding parameters to default values */
|
||||
/* set decoding parameters to default values */
|
||||
opj_set_default_decoder_parameters(¶meters);
|
||||
|
||||
/* Initialize img_fol */
|
||||
/* Initialize indexfilename and img_fol */
|
||||
*indexfilename = 0;
|
||||
memset(&img_fol,0,sizeof(img_fol_t));
|
||||
|
||||
/* Parse input and get user encoding parameters */
|
||||
if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) {
|
||||
/* parse input and get user encoding parameters */
|
||||
if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Initialize reading of directory */
|
||||
if(img_fol.set_imgdir==1){
|
||||
int it_image;
|
||||
num_images=get_num_images(img_fol.imgdirpath);
|
||||
|
||||
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
|
||||
if(dirptr){
|
||||
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
|
||||
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); // Stores at max 10 image file names
|
||||
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
|
||||
|
||||
if(!dirptr->filename_buf){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for(it_image=0;it_image<num_images;it_image++){
|
||||
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
|
||||
for(i=0;i<num_images;i++){
|
||||
dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
|
||||
}
|
||||
}
|
||||
if(load_images(dirptr,img_fol.imgdirpath)==1){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (num_images==0){
|
||||
fprintf(stdout,"Folder is empty\n");
|
||||
return EXIT_FAILURE;
|
||||
@@ -461,20 +369,10 @@ int main(int argc, char *argv[])
|
||||
num_images=1;
|
||||
}
|
||||
|
||||
/* Try to open for writing the output file if necessary */
|
||||
if (parameters.outfile[0] != 0){
|
||||
fout = fopen(parameters.outfile,"w");
|
||||
if (!fout){
|
||||
fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else
|
||||
fout = stdout;
|
||||
|
||||
/* Read the header of each image one by one */
|
||||
for(imageno = 0; imageno < num_images ; imageno++){
|
||||
|
||||
/*Encoding image one by one*/
|
||||
for(imageno = 0; imageno < num_images ; imageno++)
|
||||
{
|
||||
image = NULL;
|
||||
fprintf(stderr,"\n");
|
||||
|
||||
if(img_fol.set_imgdir==1){
|
||||
@@ -484,103 +382,114 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
/* Read the input file and put it in memory */
|
||||
/* read the input file and put it in memory */
|
||||
/* ---------------------------------------- */
|
||||
fsrc = fopen(parameters.infile, "rb");
|
||||
if (!fsrc) {
|
||||
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cio = opj_stream_create_default_file_stream(fsrc,true);
|
||||
/* decode the code-stream */
|
||||
/* ---------------------- */
|
||||
|
||||
l_stream = opj_stream_create_default_file_stream(fsrc,1);
|
||||
if (!l_stream){
|
||||
fclose(fsrc);
|
||||
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Read the JPEG2000 stream */
|
||||
/* ------------------------ */
|
||||
|
||||
switch(parameters.decod_format) {
|
||||
case J2K_CFMT: /* JPEG-2000 codestream */
|
||||
switch (parameters.decod_format)
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
l_codec = opj_create_decompress(OPJ_CODEC_J2K);
|
||||
case J2K_CFMT:
|
||||
{
|
||||
/* JPEG-2000 codestream */
|
||||
|
||||
/* get a decoder handle */
|
||||
dinfo = opj_create_decompress(CODEC_J2K);
|
||||
break;
|
||||
}
|
||||
case JP2_CFMT: /* JPEG 2000 compressed image data */
|
||||
case JP2_CFMT:
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
l_codec = opj_create_decompress(OPJ_CODEC_JP2);
|
||||
/* JPEG 2000 compressed image data */
|
||||
/* get a decoder handle */
|
||||
dinfo = opj_create_decompress(CODEC_JP2);
|
||||
break;
|
||||
}
|
||||
case JPT_CFMT: /* JPEG 2000, JPIP */
|
||||
case JPT_CFMT:
|
||||
{
|
||||
/* Get a decoder handle */
|
||||
l_codec = opj_create_decompress(OPJ_CODEC_JPT);
|
||||
/* JPEG 2000, JPIP */
|
||||
/* get a decoder handle */
|
||||
dinfo = opj_create_decompress(CODEC_JPT);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
fprintf(stderr, "skipping file..\n");
|
||||
opj_stream_destroy(l_stream);
|
||||
opj_stream_destroy(cio);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* catch events using our callbacks and give a local context */
|
||||
opj_set_info_handler(l_codec, info_callback,00);
|
||||
opj_set_warning_handler(l_codec, warning_callback,00);
|
||||
opj_set_error_handler(l_codec, error_callback,00);
|
||||
|
||||
/* Setup the decoder decoding parameters using user parameters */
|
||||
if ( !opj_setup_decoder(l_codec, ¶meters) ){
|
||||
fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n");
|
||||
opj_stream_destroy(l_stream);
|
||||
fclose(fsrc);
|
||||
opj_destroy_codec(l_codec);
|
||||
fclose(fout);
|
||||
/* setup the decoder decoding parameters using user parameters */
|
||||
opj_setup_decoder(dinfo, ¶meters);
|
||||
|
||||
/* decode the stream and fill the image structure */
|
||||
/* if (*indexfilename) // If need to extract codestream information
|
||||
image = opj_decode_with_info(dinfo, cio, &cstr_info);
|
||||
else
|
||||
*/
|
||||
bResult = opj_read_header(
|
||||
dinfo,
|
||||
&image,
|
||||
&l_tile_x0,
|
||||
&l_tile_y0,
|
||||
&l_tile_width,
|
||||
&l_tile_height,
|
||||
&l_nb_tiles_x,
|
||||
&l_nb_tiles_y,
|
||||
cio);
|
||||
//image = opj_decode(dinfo, cio);
|
||||
//bResult = bResult && (image != 00);
|
||||
//bResult = bResult && opj_end_decompress(dinfo,cio);
|
||||
//if
|
||||
// (!image)
|
||||
//{
|
||||
// fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
||||
// opj_destroy_codec(dinfo);
|
||||
// opj_stream_destroy(cio);
|
||||
// fclose(fsrc);
|
||||
// return EXIT_FAILURE;
|
||||
//}
|
||||
/* dump image */
|
||||
if(!image)
|
||||
{
|
||||
fprintf(stderr, "ERROR -> j2k_to_image: failed to read header\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
j2k_dump_image(stdout, image);
|
||||
|
||||
/* Read the main header of the codestream and if necessary the JP2 boxes*/
|
||||
if(! opj_read_header(l_stream, l_codec, &image)){
|
||||
fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n");
|
||||
opj_stream_destroy(l_stream);
|
||||
fclose(fsrc);
|
||||
opj_destroy_codec(l_codec);
|
||||
opj_image_destroy(image);
|
||||
fclose(fout);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
opj_dump_codec(l_codec, OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND, fout );
|
||||
|
||||
cstr_info = opj_get_cstr_info(l_codec);
|
||||
|
||||
cstr_index = opj_get_cstr_index(l_codec);
|
||||
/* dump cp */
|
||||
//j2k_dump_cp(stdout, image, dinfo->m_codec);
|
||||
|
||||
/* close the byte stream */
|
||||
opj_stream_destroy(l_stream);
|
||||
opj_stream_destroy(cio);
|
||||
fclose(fsrc);
|
||||
/* Write the index to disk */
|
||||
if (*indexfilename) {
|
||||
char bSuccess;
|
||||
bSuccess = write_index_file(&cstr_info, indexfilename);
|
||||
if (bSuccess) {
|
||||
fprintf(stderr, "Failed to output index file\n");
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/* free remaining structures */
|
||||
if (l_codec) {
|
||||
opj_destroy_codec(l_codec);
|
||||
if (dinfo) {
|
||||
opj_destroy_codec(dinfo);
|
||||
}
|
||||
|
||||
/* destroy the image header */
|
||||
/* free codestream information structure */
|
||||
if (*indexfilename)
|
||||
opj_destroy_cstr_info(&cstr_info);
|
||||
/* free image data structure */
|
||||
opj_image_destroy(image);
|
||||
|
||||
/* destroy the codestream index */
|
||||
opj_destroy_cstr_index(&cstr_index);
|
||||
|
||||
/* destroy the codestream info */
|
||||
opj_destroy_cstr_info(&cstr_info);
|
||||
|
||||
}
|
||||
|
||||
/* Close the output file */
|
||||
fclose(fout);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
//end main
|
||||
@@ -6,6 +6,7 @@
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2006-2007, Parvatha Elangovan
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -29,41 +30,38 @@
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#define USE_OPJ_DEPRECATED
|
||||
#include "openjpeg.h"
|
||||
#include "compat/getopt.h"
|
||||
#include "convert.h"
|
||||
#include "dirent.h"
|
||||
#include "index.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "windirent.h"
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#ifndef WIN32
|
||||
#include <strings.h>
|
||||
#define _stricmp strcasecmp
|
||||
#define _strnicmp strncasecmp
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#include "opj_config.h"
|
||||
#include "openjpeg.h"
|
||||
#include "opj_getopt.h"
|
||||
#include "convert.h"
|
||||
#include "index.h"
|
||||
|
||||
#ifdef HAVE_LIBLCMS2
|
||||
#include <lcms2.h>
|
||||
#endif
|
||||
#ifdef HAVE_LIBLCMS1
|
||||
#include <lcms.h>
|
||||
#endif
|
||||
#include "color.h"
|
||||
|
||||
#include "format_defs.h"
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#define J2K_CFMT 0
|
||||
#define JP2_CFMT 1
|
||||
#define JPT_CFMT 2
|
||||
|
||||
#define PXM_DFMT 10
|
||||
#define PGX_DFMT 11
|
||||
#define BMP_DFMT 12
|
||||
#define YUV_DFMT 13
|
||||
#define TIF_DFMT 14
|
||||
#define RAW_DFMT 15
|
||||
#define TGA_DFMT 16
|
||||
#define PNG_DFMT 17
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
typedef struct dircnt{
|
||||
/** Buffer for holding images read from Directory*/
|
||||
@@ -85,8 +83,8 @@ typedef struct img_folder{
|
||||
|
||||
}img_fol_t;
|
||||
|
||||
void decode_help_display(void) {
|
||||
fprintf(stdout,"HELP for j2k_to_image\n----\n\n");
|
||||
void decode_help_display() {
|
||||
fprintf(stdout,"HELP\n----\n\n");
|
||||
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
|
||||
|
||||
/* UniPG>> */
|
||||
@@ -103,14 +101,14 @@ void decode_help_display(void) {
|
||||
fprintf(stdout," -OutFor \n");
|
||||
fprintf(stdout," REQUIRED only if -ImgDir is used\n");
|
||||
fprintf(stdout," Need to specify only format without filename <BMP> \n");
|
||||
fprintf(stdout," Currently accepts PGM, PPM, PNM, PGX, PNG, BMP, TIF, RAW and TGA formats\n");
|
||||
fprintf(stdout," Currently accepts PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA formats\n");
|
||||
fprintf(stdout," -i <compressed file>\n");
|
||||
fprintf(stdout," REQUIRED only if an Input image directory not specified\n");
|
||||
fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n");
|
||||
fprintf(stdout," is identified based on its suffix.\n");
|
||||
fprintf(stdout," -o <decompressed file>\n");
|
||||
fprintf(stdout," REQUIRED\n");
|
||||
fprintf(stdout," Currently accepts PGM, PPM, PNM, PGX, PNG, BMP, TIF, RAW and TGA files\n");
|
||||
fprintf(stdout," Currently accepts PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA files\n");
|
||||
fprintf(stdout," Binary data is written to the file (not ascii). If a PGX\n");
|
||||
fprintf(stdout," filename is given, there will be as many output files as there are\n");
|
||||
fprintf(stdout," components: an indice starting from 0 will then be appended to the\n");
|
||||
@@ -221,7 +219,7 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
|
||||
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
|
||||
strncpy(parameters->infile, infilename, sizeof(infilename));
|
||||
|
||||
/*Set output file*/
|
||||
//Set output file
|
||||
strcpy(temp_ofname,strtok(image_filename,"."));
|
||||
while((temp_p = strtok(NULL,".")) != NULL){
|
||||
strcat(temp_ofname,temp1);
|
||||
@@ -237,30 +235,30 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
|
||||
/* -------------------------------------------------------------------------- */
|
||||
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
|
||||
/* parse the command line */
|
||||
int totlen, c;
|
||||
opj_option_t long_option[]={
|
||||
int totlen;
|
||||
option_t long_option[]={
|
||||
{"ImgDir",REQ_ARG, NULL ,'y'},
|
||||
{"OutFor",REQ_ARG, NULL ,'O'},
|
||||
};
|
||||
|
||||
const char optlist[] = "i:o:r:l:x:"
|
||||
const char optlist[] = "i:o:r:l:hx:"
|
||||
|
||||
/* UniPG>> */
|
||||
#ifdef USE_JPWL
|
||||
"W:"
|
||||
#endif /* USE_JPWL */
|
||||
/* <<UniPG */
|
||||
"h" ;
|
||||
;
|
||||
totlen=sizeof(long_option);
|
||||
img_fol->set_out_format = 0;
|
||||
do {
|
||||
c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
|
||||
while (1) {
|
||||
int c = getopt_long(argc, argv,optlist,long_option,totlen);
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
case 'i': /* input file */
|
||||
{
|
||||
char *infile = opj_optarg;
|
||||
char *infile = optarg;
|
||||
parameters->decod_format = get_file_format(infile);
|
||||
switch(parameters->decod_format) {
|
||||
case J2K_CFMT:
|
||||
@@ -281,7 +279,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
|
||||
case 'o': /* output file */
|
||||
{
|
||||
char *outfile = opj_optarg;
|
||||
char *outfile = optarg;
|
||||
parameters->cod_format = get_file_format(outfile);
|
||||
switch(parameters->cod_format) {
|
||||
case PGX_DFMT:
|
||||
@@ -305,7 +303,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
case 'O': /* output format */
|
||||
{
|
||||
char outformat[50];
|
||||
char *of = opj_optarg;
|
||||
char *of = optarg;
|
||||
sprintf(outformat,".%s",of);
|
||||
img_fol->set_out_format = 1;
|
||||
parameters->cod_format = get_file_format(outformat);
|
||||
@@ -344,7 +342,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
|
||||
case 'r': /* reduce option */
|
||||
{
|
||||
sscanf(opj_optarg, "%d", ¶meters->cp_reduce);
|
||||
sscanf(optarg, "%d", ¶meters->cp_reduce);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -353,7 +351,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
|
||||
case 'l': /* layering option */
|
||||
{
|
||||
sscanf(opj_optarg, "%d", ¶meters->cp_layer);
|
||||
sscanf(optarg, "%d", ¶meters->cp_layer);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -367,15 +365,15 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
|
||||
case 'y': /* Image Directory path */
|
||||
{
|
||||
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
|
||||
strcpy(img_fol->imgdirpath,opj_optarg);
|
||||
img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
|
||||
strcpy(img_fol->imgdirpath,optarg);
|
||||
img_fol->set_imgdir=1;
|
||||
}
|
||||
break;
|
||||
/* ----------------------------------------------------- */
|
||||
case 'x': /* Creation of index file */
|
||||
{
|
||||
char *index = opj_optarg;
|
||||
char *index = optarg;
|
||||
strncpy(indexfilename, index, OPJ_PATH_LEN);
|
||||
}
|
||||
break;
|
||||
@@ -387,7 +385,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
{
|
||||
char *token = NULL;
|
||||
|
||||
token = strtok(opj_optarg, ",");
|
||||
token = strtok(optarg, ",");
|
||||
while(token != NULL) {
|
||||
|
||||
/* search expected number of components */
|
||||
@@ -443,7 +441,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
/* next token or bust */
|
||||
token = strtok(NULL, ",");
|
||||
};
|
||||
parameters->jpwl_correct = OPJ_TRUE;
|
||||
parameters->jpwl_correct = true;
|
||||
fprintf(stdout, "JPWL correction capability activated\n");
|
||||
fprintf(stdout, "- expecting %d components\n", parameters->jpwl_exp_comps);
|
||||
}
|
||||
@@ -454,10 +452,10 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
/* ----------------------------------------------------- */
|
||||
|
||||
default:
|
||||
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
|
||||
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);
|
||||
break;
|
||||
}
|
||||
}while(c != -1);
|
||||
}
|
||||
|
||||
/* check for possible errors */
|
||||
if(img_fol->set_imgdir==1){
|
||||
@@ -476,8 +474,9 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
||||
}
|
||||
}else{
|
||||
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
|
||||
fprintf(stderr, "Example: %s -i image.j2k -o image.pgm\n",argv[0]);
|
||||
fprintf(stderr, " Try: %s -h\n",argv[0]);
|
||||
fprintf(stderr, "Error: One of the options -i or -ImgDir must be specified\n");
|
||||
fprintf(stderr, "Error: When using -i, -o must be used\n");
|
||||
fprintf(stderr, "usage: image_to_j2k -i *.j2k/jp2/j2c -o *.pgm/ppm/pnm/pgx/bmp/tif/raw/tga(+ options)\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -511,27 +510,25 @@ void info_callback(const char *msg, void *client_data) {
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
opj_dparameters_t parameters; /* decompression parameters */
|
||||
img_fol_t img_fol;
|
||||
opj_event_mgr_t event_mgr; /* event manager */
|
||||
opj_image_t *image = NULL;
|
||||
FILE *fsrc = NULL;
|
||||
unsigned char *src = NULL;
|
||||
int file_length;
|
||||
bool bResult;
|
||||
int num_images;
|
||||
int i,imageno;
|
||||
dircnt_t *dirptr = NULL;
|
||||
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
|
||||
opj_cio_t *cio = NULL;
|
||||
dircnt_t *dirptr;
|
||||
opj_codec_t* dinfo = NULL; /* handle to a decompressor */
|
||||
opj_stream_t *cio = NULL;
|
||||
opj_codestream_info_t cstr_info; /* Codestream information structure */
|
||||
char indexfilename[OPJ_PATH_LEN]; /* index file name */
|
||||
OPJ_INT32 l_tile_x0,l_tile_y0;
|
||||
OPJ_UINT32 l_tile_width,l_tile_height,l_nb_tiles_x,l_nb_tiles_y;
|
||||
|
||||
/* configure the event callbacks (not required) */
|
||||
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
|
||||
event_mgr.error_handler = error_callback;
|
||||
event_mgr.warning_handler = warning_callback;
|
||||
event_mgr.info_handler = info_callback;
|
||||
|
||||
/* set decoding parameters to default values */
|
||||
opj_set_default_decoder_parameters(¶meters);
|
||||
@@ -542,7 +539,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* parse input and get user encoding parameters */
|
||||
if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) {
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Initialize reading of directory */
|
||||
@@ -551,29 +548,30 @@ int main(int argc, char **argv) {
|
||||
|
||||
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
|
||||
if(dirptr){
|
||||
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
|
||||
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); // Stores at max 10 image file names
|
||||
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
|
||||
|
||||
if(!dirptr->filename_buf){
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for(i=0;i<num_images;i++){
|
||||
dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
|
||||
}
|
||||
}
|
||||
if(load_images(dirptr,img_fol.imgdirpath)==1){
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (num_images==0){
|
||||
fprintf(stdout,"Folder is empty\n");
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}else{
|
||||
num_images=1;
|
||||
}
|
||||
|
||||
/*Encoding image one by one*/
|
||||
for(imageno = 0; imageno < num_images ; imageno++) {
|
||||
for(imageno = 0; imageno < num_images ; imageno++)
|
||||
{
|
||||
image = NULL;
|
||||
fprintf(stderr,"\n");
|
||||
|
||||
@@ -587,178 +585,90 @@ int main(int argc, char **argv) {
|
||||
/* read the input file and put it in memory */
|
||||
/* ---------------------------------------- */
|
||||
fsrc = fopen(parameters.infile, "rb");
|
||||
if (!fsrc) {
|
||||
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
|
||||
return 1;
|
||||
}
|
||||
fseek(fsrc, 0, SEEK_END);
|
||||
file_length = ftell(fsrc);
|
||||
fseek(fsrc, 0, SEEK_SET);
|
||||
src = (unsigned char *) malloc(file_length);
|
||||
if (fread(src, 1, file_length, fsrc) != (size_t)file_length)
|
||||
if
|
||||
(!fsrc)
|
||||
{
|
||||
free(src);
|
||||
fclose(fsrc);
|
||||
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
|
||||
return 1;
|
||||
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fclose(fsrc);
|
||||
|
||||
cio = opj_stream_create_default_file_stream(fsrc,true);
|
||||
/* decode the code-stream */
|
||||
/* ---------------------- */
|
||||
|
||||
switch(parameters.decod_format) {
|
||||
switch
|
||||
(parameters.decod_format)
|
||||
{
|
||||
case J2K_CFMT:
|
||||
{
|
||||
/* JPEG-2000 codestream */
|
||||
|
||||
/* get a decoder handle */
|
||||
dinfo = opj_create_decompress(CODEC_J2K);
|
||||
|
||||
/* catch events using our callbacks and give a local context */
|
||||
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
|
||||
|
||||
/* setup the decoder decoding parameters using user parameters */
|
||||
opj_setup_decoder(dinfo, ¶meters);
|
||||
|
||||
/* open a byte stream */
|
||||
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
|
||||
|
||||
/* decode the stream and fill the image structure */
|
||||
if (*indexfilename) /* If need to extract codestream information*/
|
||||
image = opj_decode_with_info(dinfo, cio, &cstr_info);
|
||||
else
|
||||
image = opj_decode(dinfo, cio);
|
||||
if(!image) {
|
||||
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
||||
opj_destroy_decompress(dinfo);
|
||||
opj_cio_close(cio);
|
||||
free(src);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* close the byte stream */
|
||||
opj_cio_close(cio);
|
||||
|
||||
/* Write the index to disk */
|
||||
if (*indexfilename) {
|
||||
opj_bool bSuccess;
|
||||
bSuccess = write_index_file(&cstr_info, indexfilename);
|
||||
if (bSuccess) {
|
||||
fprintf(stderr, "Failed to output index file\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
case JP2_CFMT:
|
||||
{
|
||||
/* JPEG 2000 compressed image data */
|
||||
|
||||
/* get a decoder handle */
|
||||
dinfo = opj_create_decompress(CODEC_JP2);
|
||||
|
||||
/* catch events using our callbacks and give a local context */
|
||||
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
|
||||
|
||||
/* setup the decoder decoding parameters using the current image and user parameters */
|
||||
opj_setup_decoder(dinfo, ¶meters);
|
||||
|
||||
/* open a byte stream */
|
||||
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
|
||||
|
||||
/* decode the stream and fill the image structure */
|
||||
if (*indexfilename) /* If need to extract codestream information*/
|
||||
image = opj_decode_with_info(dinfo, cio, &cstr_info);
|
||||
else
|
||||
image = opj_decode(dinfo, cio);
|
||||
if(!image) {
|
||||
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
||||
opj_destroy_decompress(dinfo);
|
||||
opj_cio_close(cio);
|
||||
free(src);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* close the byte stream */
|
||||
opj_cio_close(cio);
|
||||
|
||||
/* Write the index to disk */
|
||||
if (*indexfilename) {
|
||||
opj_bool bSuccess;
|
||||
bSuccess = write_index_file(&cstr_info, indexfilename);
|
||||
if (bSuccess) {
|
||||
fprintf(stderr, "Failed to output index file\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
case JPT_CFMT:
|
||||
{
|
||||
/* JPEG 2000, JPIP */
|
||||
|
||||
/* get a decoder handle */
|
||||
dinfo = opj_create_decompress(CODEC_JPT);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
fprintf(stderr, "skipping file..\n");
|
||||
opj_stream_destroy(cio);
|
||||
continue;
|
||||
}
|
||||
/* catch events using our callbacks and give a local context */
|
||||
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
|
||||
|
||||
/* setup the decoder decoding parameters using user parameters */
|
||||
opj_setup_decoder(dinfo, ¶meters);
|
||||
|
||||
/* open a byte stream */
|
||||
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
|
||||
|
||||
/* decode the stream and fill the image structure */
|
||||
if (*indexfilename) /* If need to extract codestream information*/
|
||||
/* if (*indexfilename) // If need to extract codestream information
|
||||
image = opj_decode_with_info(dinfo, cio, &cstr_info);
|
||||
else
|
||||
*/
|
||||
bResult = opj_read_header(
|
||||
dinfo,
|
||||
&image,
|
||||
&l_tile_x0,
|
||||
&l_tile_y0,
|
||||
&l_tile_width,
|
||||
&l_tile_height,
|
||||
&l_nb_tiles_x,
|
||||
&l_nb_tiles_y,
|
||||
cio);
|
||||
image = opj_decode(dinfo, cio);
|
||||
if(!image) {
|
||||
bResult = bResult && (image != 00);
|
||||
bResult = bResult && opj_end_decompress(dinfo,cio);
|
||||
if
|
||||
(!image)
|
||||
{
|
||||
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
||||
opj_destroy_decompress(dinfo);
|
||||
opj_cio_close(cio);
|
||||
free(src);
|
||||
return 1;
|
||||
opj_destroy_codec(dinfo);
|
||||
opj_stream_destroy(cio);
|
||||
fclose(fsrc);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* close the byte stream */
|
||||
opj_cio_close(cio);
|
||||
|
||||
opj_stream_destroy(cio);
|
||||
fclose(fsrc);
|
||||
/* Write the index to disk */
|
||||
if (*indexfilename) {
|
||||
opj_bool bSuccess;
|
||||
char bSuccess;
|
||||
bSuccess = write_index_file(&cstr_info, indexfilename);
|
||||
if (bSuccess) {
|
||||
fprintf(stderr, "Failed to output index file\n");
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "skipping file..\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* free the memory containing the code-stream */
|
||||
free(src);
|
||||
src = NULL;
|
||||
|
||||
if(image->color_space == CLRSPC_SYCC)
|
||||
{
|
||||
color_sycc_to_rgb(image);
|
||||
}
|
||||
|
||||
if(image->icc_profile_buf)
|
||||
{
|
||||
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
|
||||
color_apply_icc_profile(image);
|
||||
#endif
|
||||
|
||||
free(image->icc_profile_buf);
|
||||
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
|
||||
}
|
||||
|
||||
/* create output image */
|
||||
@@ -767,57 +677,69 @@ int main(int argc, char **argv) {
|
||||
case PXM_DFMT: /* PNM PGM PPM */
|
||||
if (imagetopnm(image, parameters.outfile)) {
|
||||
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
|
||||
ret = EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
||||
case PGX_DFMT: /* PGX */
|
||||
if(imagetopgx(image, parameters.outfile)){
|
||||
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
|
||||
ret = EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
||||
case BMP_DFMT: /* BMP */
|
||||
if(imagetobmp(image, parameters.outfile)){
|
||||
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
|
||||
ret = EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
#ifdef HAVE_LIBTIFF
|
||||
|
||||
case TIF_DFMT: /* TIFF */
|
||||
if(imagetotif(image, parameters.outfile)){
|
||||
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
|
||||
ret = EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
#endif /* HAVE_LIBTIFF */
|
||||
|
||||
case RAW_DFMT: /* RAW */
|
||||
if(imagetoraw(image, parameters.outfile)){
|
||||
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
|
||||
ret = EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
||||
case TGA_DFMT: /* TGA */
|
||||
if(imagetotga(image, parameters.outfile)){
|
||||
fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
else {
|
||||
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
|
||||
ret = EXIT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
#ifdef HAVE_LIBPNG
|
||||
|
||||
case PNG_DFMT: /* PNG */
|
||||
if(imagetopng(image, parameters.outfile)){
|
||||
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
|
||||
@@ -826,17 +748,14 @@ int main(int argc, char **argv) {
|
||||
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
|
||||
}
|
||||
break;
|
||||
#endif /* HAVE_LIBPNG */
|
||||
/* Can happen if output file is TIFF or PNG
|
||||
* and HAVE_LIBTIF or HAVE_LIBPNG is undefined
|
||||
*/
|
||||
default:
|
||||
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
|
||||
|
||||
}
|
||||
|
||||
/* free remaining structures */
|
||||
if(dinfo) {
|
||||
opj_destroy_decompress(dinfo);
|
||||
if
|
||||
(dinfo)
|
||||
{
|
||||
opj_destroy_codec(dinfo);
|
||||
}
|
||||
/* free codestream information structure */
|
||||
if (*indexfilename)
|
||||
@@ -845,9 +764,9 @@ int main(int argc, char **argv) {
|
||||
opj_image_destroy(image);
|
||||
|
||||
}
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
/*end main*/
|
||||
//end main
|
||||
|
||||
|
||||
|
||||
@@ -1,52 +1,12 @@
|
||||
# Generate target to build the html documentation through CMake tool
|
||||
# After having configured the project with the BUILD_DOC option you can run make doc
|
||||
# to generate the html documentation in the doc/html repository of the build folder.
|
||||
FIND_PACKAGE(Doxygen REQUIRED)
|
||||
|
||||
# Try to find the doxygen tool
|
||||
find_package(Doxygen)
|
||||
|
||||
if(DOXYGEN_FOUND)
|
||||
# Configure the doxygen config file with variable from CMake and move it
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.dox.cmake.in
|
||||
${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox @ONLY)
|
||||
|
||||
# Configure the html mainpage file of the doxygen documentation with variable
|
||||
# from CMake and move it
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mainpage.dox.in
|
||||
${CMAKE_BINARY_DIR}/doc/mainpage.dox @ONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpip.dox.in
|
||||
${CMAKE_BINARY_DIR}/doc/openjpip.dox @ONLY)
|
||||
# copy png file to make local (binary tree) documentation valid:
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jpip_architect.png
|
||||
${CMAKE_BINARY_DIR}/doc/html/jpip_architect.png COPYONLY)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/jpip_protocol.png
|
||||
${CMAKE_BINARY_DIR}/doc/html/jpip_protocol.png COPYONLY)
|
||||
|
||||
file(GLOB headers
|
||||
${OPENJPEG_SOURCE_DIR}/src/lib/openjp2/*.h
|
||||
${OPENJPEG_SOURCE_DIR}/src/lib/openjp2/*.c
|
||||
${OPENJPEG_SOURCE_DIR}/src/lib/openjpip/*.h
|
||||
${OPENJPEG_SOURCE_DIR}/src/lib/openjpip/*.c
|
||||
# The Doxyfile.dox is poorly defined and produce output
|
||||
# in the source dir
|
||||
ADD_CUSTOM_TARGET(doxygen
|
||||
# By default doxygen target is added to the 'all' target. Project is small
|
||||
# thus running doxygen is not too time consuming
|
||||
ALL
|
||||
${DOXYGEN}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.dox
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
# Generate new target to build the html documentation
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/html/index.html
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox
|
||||
${CMAKE_BINARY_DIR}/doc/mainpage.dox
|
||||
${CMAKE_BINARY_DIR}/doc/openjpip.dox
|
||||
${headers}
|
||||
)
|
||||
add_custom_target(doc ALL
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/doc/html/index.html
|
||||
COMMENT "Building doxygen documentation"
|
||||
)
|
||||
|
||||
# install HTML documentation (install png files too):
|
||||
install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/html
|
||||
DESTINATION share/doc
|
||||
PATTERN ".svn" EXCLUDE
|
||||
)
|
||||
else()
|
||||
message(STATUS "Doxygen not found, we cannot generate the documentation")
|
||||
endif()
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# Doxyfile 1.7.1
|
||||
# Doxyfile 1.4.2
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Project related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = OpenJPEG
|
||||
PROJECT_NUMBER = @OPENJPEG_VERSION@
|
||||
OUTPUT_DIRECTORY = @OPENJPEG_BINARY_DIR@/doc
|
||||
PROJECT_NUMBER =
|
||||
OUTPUT_DIRECTORY = ../
|
||||
CREATE_SUBDIRS = NO
|
||||
OUTPUT_LANGUAGE = English
|
||||
USE_WINDOWS_ENCODING = YES
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ABBREVIATE_BRIEF = "The $name class" \
|
||||
@@ -29,25 +29,16 @@ STRIP_FROM_PATH = C://
|
||||
STRIP_FROM_INC_PATH =
|
||||
SHORT_NAMES = NO
|
||||
JAVADOC_AUTOBRIEF = YES
|
||||
QT_AUTOBRIEF = NO
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
DETAILS_AT_TOP = YES
|
||||
INHERIT_DOCS = YES
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
SEPARATE_MEMBER_PAGES = NO
|
||||
TAB_SIZE = 8
|
||||
ALIASES =
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
OPTIMIZE_OUTPUT_JAVA = NO
|
||||
OPTIMIZE_FOR_FORTRAN = NO
|
||||
OPTIMIZE_OUTPUT_VHDL = NO
|
||||
EXTENSION_MAPPING =
|
||||
BUILTIN_STL_SUPPORT = NO
|
||||
CPP_CLI_SUPPORT = NO
|
||||
SIP_SUPPORT = NO
|
||||
IDL_PROPERTY_SUPPORT = YES
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
SUBGROUPING = YES
|
||||
TYPEDEF_HIDES_STRUCT = NO
|
||||
SYMBOL_CACHE_SIZE = 0
|
||||
#---------------------------------------------------------------------------
|
||||
# Build related configuration options
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -56,7 +47,6 @@ EXTRACT_PRIVATE = YES
|
||||
EXTRACT_STATIC = YES
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
EXTRACT_LOCAL_METHODS = NO
|
||||
EXTRACT_ANON_NSPACES = NO
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
@@ -65,12 +55,9 @@ INTERNAL_DOCS = NO
|
||||
CASE_SENSE_NAMES = NO
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
FORCE_LOCAL_INCLUDES = NO
|
||||
INLINE_INFO = YES
|
||||
SORT_MEMBER_DOCS = YES
|
||||
SORT_BRIEF_DOCS = NO
|
||||
SORT_MEMBERS_CTORS_1ST = NO
|
||||
SORT_GROUP_NAMES = NO
|
||||
SORT_BY_SCOPE_NAME = NO
|
||||
GENERATE_TODOLIST = YES
|
||||
GENERATE_TESTLIST = YES
|
||||
@@ -80,10 +67,7 @@ ENABLED_SECTIONS =
|
||||
MAX_INITIALIZER_LINES = 30
|
||||
SHOW_USED_FILES = YES
|
||||
SHOW_DIRECTORIES = NO
|
||||
SHOW_FILES = YES
|
||||
SHOW_NAMESPACES = YES
|
||||
FILE_VERSION_FILTER =
|
||||
LAYOUT_FILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to warning and progress messages
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -97,22 +81,18 @@ WARN_LOGFILE =
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the input files
|
||||
#---------------------------------------------------------------------------
|
||||
INPUT = @OPENJPEG_SOURCE_DIR@/src/lib/openjp2 \
|
||||
@OPENJPEG_SOURCE_DIR@/src/lib/openjpip \
|
||||
@OPENJPEG_BINARY_DIR@/doc
|
||||
INPUT_ENCODING = UTF-8
|
||||
INPUT = ../libopenjpeg \
|
||||
../jpwl
|
||||
FILE_PATTERNS = *.h \
|
||||
*.c \
|
||||
*.dox
|
||||
RECURSIVE = YES
|
||||
*.c
|
||||
RECURSIVE = NO
|
||||
EXCLUDE =
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS = */.svn/*
|
||||
EXCLUDE_SYMBOLS =
|
||||
EXCLUDE_PATTERNS =
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATTERNS = *
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH = @OPENJPEG_SOURCE_DIR@/doc
|
||||
IMAGE_PATH =
|
||||
INPUT_FILTER =
|
||||
FILTER_PATTERNS =
|
||||
FILTER_SOURCE_FILES = NO
|
||||
@@ -124,8 +104,6 @@ INLINE_SOURCES = NO
|
||||
STRIP_CODE_COMMENTS = YES
|
||||
REFERENCED_BY_RELATION = YES
|
||||
REFERENCES_RELATION = YES
|
||||
REFERENCES_LINK_SOURCE = YES
|
||||
USE_HTAGS = NO
|
||||
VERBATIM_HEADERS = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the alphabetical class index
|
||||
@@ -142,44 +120,17 @@ HTML_FILE_EXTENSION = .html
|
||||
HTML_HEADER =
|
||||
HTML_FOOTER =
|
||||
HTML_STYLESHEET =
|
||||
HTML_COLORSTYLE_HUE = 220
|
||||
HTML_COLORSTYLE_SAT = 100
|
||||
HTML_COLORSTYLE_GAMMA = 80
|
||||
HTML_TIMESTAMP = YES
|
||||
HTML_ALIGN_MEMBERS = YES
|
||||
HTML_DYNAMIC_SECTIONS = NO
|
||||
GENERATE_DOCSET = NO
|
||||
DOCSET_FEEDNAME = "Doxygen generated docs"
|
||||
DOCSET_BUNDLE_ID = org.doxygen.Project
|
||||
DOCSET_PUBLISHER_ID = org.doxygen.Publisher
|
||||
DOCSET_PUBLISHER_NAME = Publisher
|
||||
GENERATE_HTMLHELP = NO
|
||||
CHM_FILE =
|
||||
HHC_LOCATION =
|
||||
GENERATE_CHI = NO
|
||||
CHM_INDEX_ENCODING =
|
||||
BINARY_TOC = NO
|
||||
TOC_EXPAND = NO
|
||||
GENERATE_QHP = NO
|
||||
QCH_FILE =
|
||||
QHP_NAMESPACE = org.doxygen.Project
|
||||
QHP_VIRTUAL_FOLDER = doc
|
||||
QHP_CUST_FILTER_NAME =
|
||||
QHP_CUST_FILTER_ATTRS =
|
||||
QHP_SECT_FILTER_ATTRS =
|
||||
QHG_LOCATION =
|
||||
GENERATE_ECLIPSEHELP = NO
|
||||
ECLIPSE_DOC_ID = org.doxygen.Project
|
||||
DISABLE_INDEX = NO
|
||||
ENUM_VALUES_PER_LINE = 4
|
||||
GENERATE_TREEVIEW = NO
|
||||
USE_INLINE_TREES = NO
|
||||
TREEVIEW_WIDTH = 250
|
||||
EXT_LINKS_IN_WINDOW = NO
|
||||
FORMULA_FONTSIZE = 10
|
||||
FORMULA_TRANSPARENT = YES
|
||||
SEARCHENGINE = NO
|
||||
SERVER_BASED_SEARCH = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the LaTeX output
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -195,7 +146,6 @@ PDF_HYPERLINKS = NO
|
||||
USE_PDFLATEX = NO
|
||||
LATEX_BATCHMODE = NO
|
||||
LATEX_HIDE_INDICES = NO
|
||||
LATEX_SOURCE_CODE = NO
|
||||
#---------------------------------------------------------------------------
|
||||
# configuration options related to the RTF output
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -256,13 +206,8 @@ PERL_PATH = /usr/bin/perl
|
||||
# Configuration options related to the dot tool
|
||||
#---------------------------------------------------------------------------
|
||||
CLASS_DIAGRAMS = YES
|
||||
MSCGEN_PATH =
|
||||
HIDE_UNDOC_RELATIONS = YES
|
||||
HAVE_DOT = NO
|
||||
DOT_NUM_THREADS = 0
|
||||
DOT_FONTNAME = Helvetica
|
||||
DOT_FONTSIZE = 10
|
||||
DOT_FONTPATH =
|
||||
CLASS_GRAPH = YES
|
||||
COLLABORATION_GRAPH = YES
|
||||
GROUP_GRAPHS = YES
|
||||
@@ -271,15 +216,19 @@ TEMPLATE_RELATIONS = NO
|
||||
INCLUDE_GRAPH = YES
|
||||
INCLUDED_BY_GRAPH = YES
|
||||
CALL_GRAPH = NO
|
||||
CALLER_GRAPH = NO
|
||||
GRAPHICAL_HIERARCHY = YES
|
||||
DIRECTORY_GRAPH = YES
|
||||
DOT_IMAGE_FORMAT = png
|
||||
DOT_PATH =
|
||||
DOTFILE_DIRS =
|
||||
DOT_GRAPH_MAX_NODES = 50
|
||||
MAX_DOT_GRAPH_WIDTH = 1024
|
||||
MAX_DOT_GRAPH_HEIGHT = 1024
|
||||
MAX_DOT_GRAPH_DEPTH = 1000
|
||||
DOT_TRANSPARENT = NO
|
||||
DOT_MULTI_TARGETS = NO
|
||||
GENERATE_LEGEND = YES
|
||||
DOT_CLEANUP = YES
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration::additions related to the search engine
|
||||
#---------------------------------------------------------------------------
|
||||
SEARCHENGINE = NO
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 61 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.2 KiB |
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*! \mainpage OpenJPEG v@OPENJPEG_VERSION@ Documentation
|
||||
*
|
||||
* \section intro Introduction
|
||||
* This manual documents the low-level OpenJPEG C API.\n
|
||||
* The OpenJPEG library is an open-source JPEG 2000 library developed in order to promote the use of JPEG 2000.\n
|
||||
* This documents is focused on the main part of the library which try to implement Part 1 and Part 2 of the JPEG2000 norm.\n
|
||||
*
|
||||
* \section home Home page
|
||||
*
|
||||
* The Home Page of the OpenJPEG library can be found at:
|
||||
*
|
||||
* http://code.google.com/p/openjpeg/
|
||||
*
|
||||
* More information about the OpenJPEG library is available here:
|
||||
*
|
||||
* http://www.openjpeg.org/
|
||||
*
|
||||
* The OpenJPEG mailing list is located here:
|
||||
*
|
||||
* http://groups.google.com/group/openjpeg
|
||||
*
|
||||
* All the source code is online and can be retrieved using svn from here:
|
||||
*
|
||||
* http://openjpeg.googlecode.com/svn/
|
||||
*
|
||||
* \section license License
|
||||
* This software is released under the BSD license, anybody can use or modify the library, even for commercial applications.\n
|
||||
* The only restriction is to retain the copyright in the sources or the binaries documentation.\n
|
||||
* Neither the author, nor the university accept any responsibility for any kind of error or data loss which may occur during usage.
|
||||
*
|
||||
* \author OpenJPEG Team
|
||||
*
|
||||
*/
|
||||
@@ -1,222 +0,0 @@
|
||||
'\" t
|
||||
'\" The line above instructs most `man' programs to invoke tbl
|
||||
'\"
|
||||
'\" Separate paragraphs; not the same as PP which resets indent level.
|
||||
.de SP
|
||||
.if t .sp .5
|
||||
.if n .sp
|
||||
..
|
||||
'\"
|
||||
'\" Replacement em-dash for nroff (default is too short).
|
||||
.ie n .ds m " -
|
||||
.el .ds m \(em
|
||||
'\"
|
||||
'\" Placeholder macro for if longer nroff arrow is needed.
|
||||
.ds RA \(->
|
||||
'\"
|
||||
'\" Decimal point set slightly raised
|
||||
.if t .ds d \v'-.15m'.\v'+.15m'
|
||||
.if n .ds d .
|
||||
'\"
|
||||
'\" Enclosure macro for examples
|
||||
.de EX
|
||||
.SP
|
||||
.nf
|
||||
.ft CW
|
||||
..
|
||||
.de EE
|
||||
.ft R
|
||||
.SP
|
||||
.fi
|
||||
..
|
||||
.TH opj_compress 1 "Version 1.4.0" "opj_compress" "converts to jpeg2000 files"
|
||||
.P
|
||||
.SH NAME
|
||||
opj_compress -
|
||||
This program reads in an image of a certain type and converts it to a
|
||||
jpeg2000 file. It is part of the OpenJPEG library.
|
||||
.SP
|
||||
Valid input image extensions are
|
||||
.B .bmp, .pgm, .pgx, .png, .pnm, .ppm, .raw, .tga, .tif \fR. For PNG resp. TIF it needs libpng resp. libtiff .
|
||||
.SP
|
||||
Valid output image extensions are
|
||||
.B .j2k, .jp2
|
||||
.SH SYNOPSIS
|
||||
.P
|
||||
.B opj_compress -i \fRinfile.bmp \fB-o \fRoutfile.j2k
|
||||
.P
|
||||
.B opj_compress -ImgDir \fRdirectory_name \fB-OutFor \fRjp2
|
||||
.P
|
||||
.B opj_compress -h \fRPrint a help message and exit.
|
||||
.P
|
||||
.R See JPWL OPTIONS for special options
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-\^b " n,n"
|
||||
(Size of code block (e.g. -b 32,32). Default: 64 x 64)
|
||||
.TP
|
||||
.B \-\^c " n"
|
||||
(Size of precinct (e.g. -c 128,128). Default: 2^15 x 2^15)
|
||||
.TP
|
||||
.B \-\^cinema2K " fps"
|
||||
Digital Cinema 2K profile compliant codestream. Valid \fBfps\fR values are 24 or 48.
|
||||
.TP
|
||||
.B \-\^cinema4K
|
||||
Digital Cinema 4K profile compliant codestream. Does not need an fps: default is 24 fps.
|
||||
.TP
|
||||
.B \-\^d " X,Y"
|
||||
(Offset of image origin (e.g. -d 150,300))
|
||||
.TP
|
||||
.B \-\^h
|
||||
Print a help message and exit.
|
||||
.TP
|
||||
.B \-\^i " name"
|
||||
(input file name)
|
||||
.TP
|
||||
.B \-\^n " n"
|
||||
(Number of resolutions. Default: 6)
|
||||
.TP
|
||||
.B \-\^o " name"
|
||||
(output file name)
|
||||
.TP
|
||||
.B \-\^p " name"
|
||||
Progression order. \fBname\fR can be one out of:LRCP, RLCP, RPCL, PCRL, CPRL. Default: LRCP.
|
||||
.TP
|
||||
.B \-\^q " n"
|
||||
different psnr for successive layers
|
||||
.br
|
||||
.B Note: \fR(options -r and -q cannot be used together)
|
||||
.TP
|
||||
.B \-\^r " n"
|
||||
different compression ratio(s) for successive layers. The rate specified for each quality level is the desired compression factor.
|
||||
.br
|
||||
.B Note: \fR(options -r and -q cannot be used together)
|
||||
.TP
|
||||
.B \-\^s " X,Y"
|
||||
sub-sampling factor (e.g. -s 2,2). Default: No sub-sampling in x or y direction.
|
||||
.br
|
||||
.B Remark: \fRsub-sampling bigger than 2 can produce errors.
|
||||
.TP
|
||||
.B \-\^t " W,H"
|
||||
(Size of tile (e.g. -t 512,512) )
|
||||
.TP
|
||||
.B \-\^x " name"
|
||||
(Create index file and fill it. Default: no index file)
|
||||
.TP
|
||||
.B \-\^EPH
|
||||
(Write EPH marker after each header packet. Default:no EPH)
|
||||
.TP
|
||||
.B \-\^F " rawWidth,rawHeight,rawComp,rawBitDepth,s_or_u"
|
||||
characteristics of the raw input image
|
||||
.TP
|
||||
.B \-\^I
|
||||
(Use the irreversible DWT 9-7. Default: Reversible DWT 5-3)
|
||||
.TP
|
||||
.B \-\^ImgDir " directory_name"
|
||||
(directory containing input files)
|
||||
.TP
|
||||
.B \-\^M " n"
|
||||
mode switch with values: 1, 2, 4, 8, 16, 32. Default:No mode switch activated.
|
||||
.br
|
||||
\fIMeaning:\fR
|
||||
.br
|
||||
BYPASS(1)
|
||||
.br
|
||||
RESET(2)
|
||||
.br
|
||||
RESTART(4)
|
||||
.br
|
||||
VSC(8)
|
||||
.br
|
||||
ERTERM(16)
|
||||
.br
|
||||
SEGMARK(32)
|
||||
.br
|
||||
Values can be added: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38
|
||||
.TP
|
||||
.B \-\^OutFor "ext"
|
||||
(extension for output files)
|
||||
.TP
|
||||
.B \-\^POC "TtileNr=resolutionStart, componentStart, layerEnd, resolutionEnd, componentEnd, progressionOrder"
|
||||
(see Examples)
|
||||
.TP
|
||||
.B \-\^ROI "c=n,U=n"
|
||||
quantization indices upshifted for component c (0 or 1 or 2) with a value of U (>= 0 and <= 37)
|
||||
.br
|
||||
e.g. \fB-ROI c=0,U=25\fR
|
||||
.TP
|
||||
.B \-\^SOP
|
||||
(Write SOP marker before each packet. Default: No SOP marker in the codestream.)
|
||||
.TP
|
||||
.B \-\^T "X,Y"
|
||||
(Offset of the origin of the tiles (e.g. -T 100,75) )
|
||||
.TP
|
||||
.B \-\^W
|
||||
(see JPWL OPTIONS)
|
||||
.P
|
||||
.SH JPWL OPTIONS
|
||||
Options usable only if the library has been compiled with \fB-DUSE_JPWL\fR
|
||||
.P
|
||||
.B -W h<tilepart><=type>, s<tilepart><=method>, a=<addr>, z=<size>, g=<range>, p<tilepart:pack><=type>
|
||||
.P
|
||||
.B h\fR selects the header error protection (EPB): \fBtype\fR can be
|
||||
[0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]
|
||||
if \fBtilepart\fR is absent, it is for main and tile headers
|
||||
if \fBtilepart\fR is present, it applies from that tile
|
||||
onwards, up to the next h<> spec, or to the last tilepart
|
||||
in the codestream (max. 16 specs)
|
||||
.P
|
||||
.B p \fRselects the packet error protection (EEP/UEP with EPBs)
|
||||
to be applied to raw data: \fBtype\fR can be
|
||||
[0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]
|
||||
if \fBtilepart:pack\fR is absent, it is from tile 0, packet 0
|
||||
if \fBtilepart:pack\fR is present, it applies from that tile
|
||||
and that packet onwards, up to the next packet spec
|
||||
or to the last packet in the last tilepart in the stream
|
||||
(max. 16 specs)
|
||||
.P
|
||||
.B s \fRenables sensitivity data insertion (ESD): \fBmethod\fR can be
|
||||
[-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR
|
||||
4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED]
|
||||
if \fBtilepart\fR is absent, it is for main header only
|
||||
if \fBtilepart\fR is present, it applies from that tile
|
||||
onwards, up to the next s<> spec, or to the last tilepart
|
||||
in the codestream (max. 16 specs)
|
||||
.P
|
||||
.B g \fRdetermines the addressing mode: \fBrange\fR can be
|
||||
[0=PACKET 1=BYTE RANGE 2=PACKET RANGE]
|
||||
.P
|
||||
.B a \fRdetermines the size of data addressing: \fBaddr\fR can be
|
||||
2/4 bytes (small/large codestreams). If not set, auto-mode
|
||||
.P
|
||||
.B z \fRdetermines the size of sensitivity values: \fBsize\fR can be
|
||||
1/2 bytes, for the transformed pseudo-floating point value
|
||||
.P
|
||||
.SH EXAMPLES
|
||||
.P
|
||||
.B opj_compress -i \fRfile.bmp \fB-o \fRfile.j2k \fB-r \fR20,10,1 (compress 20x, then 10x, then lossless).
|
||||
.P
|
||||
.B opj_compress -i \fRfile.ppm \fB-o \fRfile.j2k \fB-q \fR30,40,50
|
||||
.P
|
||||
.B opj_compress -i \fRfile.pgx \fB-o \fRfile.j2k \fB-POC \fRT1=0,0,1,5,3,CPRL
|
||||
.P
|
||||
.B opj_compress -i \fRlena.raw \fB-o \fRlena.j2k \fB-F \fR512,512,3,8,u
|
||||
.P
|
||||
.SH AUTHORS
|
||||
Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
.br
|
||||
Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
.br
|
||||
Copyright (c) 2001-2003, David Janssens
|
||||
.br
|
||||
Copyright (c) 2002-2003, Yannick Verschueren
|
||||
.br
|
||||
Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
.br
|
||||
Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
.br
|
||||
Copyright (c) 2006-2007, Parvatha Elangovan
|
||||
.P
|
||||
.SH "SEE ALSO"
|
||||
opj_decompress(1) opj_dump(1)
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
'\" t
|
||||
'\" The line above instructs most `man' programs to invoke tbl
|
||||
'\"
|
||||
'\" Separate paragraphs; not the same as PP which resets indent level.
|
||||
.de SP
|
||||
.if t .sp .5
|
||||
.if n .sp
|
||||
..
|
||||
'\"
|
||||
'\" Replacement em-dash for nroff (default is too short).
|
||||
.ie n .ds m " -
|
||||
.el .ds m \(em
|
||||
'\"
|
||||
'\" Placeholder macro for if longer nroff arrow is needed.
|
||||
.ds RA \(->
|
||||
'\"
|
||||
'\" Decimal point set slightly raised
|
||||
.if t .ds d \v'-.15m'.\v'+.15m'
|
||||
.if n .ds d .
|
||||
'\"
|
||||
'\" Enclosure macro for examples
|
||||
.de EX
|
||||
.SP
|
||||
.nf
|
||||
.ft CW
|
||||
..
|
||||
.de EE
|
||||
.ft R
|
||||
.SP
|
||||
.fi
|
||||
..
|
||||
.TH opj_decompress 1 "Version 1.4.0" "opj_decompress" "converts jpeg2000 files"
|
||||
.P
|
||||
.SH NAME
|
||||
opj_decompress -
|
||||
This program reads in a jpeg2000 image and converts it to another
|
||||
image type. It is part of the OpenJPEG library.
|
||||
.SP
|
||||
Valid input image extensions are
|
||||
.B .j2k, .jp2, .j2c, .jpt
|
||||
.SP
|
||||
Valid output image extensions are
|
||||
.B .bmp, .pgm, .pgx, .png, .pnm, .ppm, .raw, .tga, .tif \fR. For PNG resp. TIF it needs libpng resp. libtiff .
|
||||
.SH SYNOPSIS
|
||||
.P
|
||||
.B opj_decompress -i \fRinfile.j2k \fB-o \fRoutfile.png
|
||||
.P
|
||||
.B opj_decompress -ImgDir \fRimages/ \fB-OutFor \fRbmp
|
||||
.P
|
||||
.B opj_decompress -h \fRPrint help message and exit
|
||||
.P
|
||||
.R See JPWL OPTIONS for special options
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-\^i "name"
|
||||
(jpeg2000 input file name)
|
||||
.TP
|
||||
.B \-\^l "n"
|
||||
n is the maximum number of quality layers to decode. See LAYERS below)
|
||||
.TP
|
||||
.B \-\^o "name"
|
||||
(output file name with extension)
|
||||
.TP
|
||||
.B \-\^r "n"
|
||||
(n is the highest resolution level to be discarded. See REDUCTION below)
|
||||
.TP
|
||||
.B \-\^x "name"
|
||||
(use name as index file and fill it)
|
||||
.TP
|
||||
.B \-\^ImgDir "directory_name"
|
||||
(directory containing input files)
|
||||
.TP
|
||||
.B \-\^OutFor "ext"
|
||||
(extension for output files)
|
||||
.P
|
||||
.SH JPWL OPTIONS
|
||||
Options usable only if the library has been compiled with
|
||||
.B -DUSE_JPWL
|
||||
.TP
|
||||
.B -W c\fR[=Nc] (Nc is the number of expected components in the codestream; default:3)
|
||||
.TP
|
||||
.B -W t\fR[=Nt] (Nt is the maximum number of tiles in the codestream; default:8192)
|
||||
.TP
|
||||
.B -W c\fR[=Nc]\fB, t\fR[=Nt] \fR(same as above)
|
||||
.P
|
||||
.SH REDUCTION
|
||||
Set the number of highest resolution levels to be discarded.
|
||||
The image resolution is effectively divided by 2 to the power of the number of discarded levels. The reduce factor is limited by the smallest total number of decomposition levels among tiles.
|
||||
.SH TILES
|
||||
Set the maximum number of quality layers to decode. If there are less quality layers than the specified number, all the quality layers are decoded.
|
||||
.P
|
||||
'\".SH BUGS
|
||||
.SH AUTHORS
|
||||
Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
.br
|
||||
Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
.br
|
||||
Copyright (c) 2001-2003, David Janssens
|
||||
.br
|
||||
Copyright (c) 2002-2003, Yannick Verschueren
|
||||
.br
|
||||
Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
.br
|
||||
Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
.br
|
||||
Copyright (c) 2006-2007, Parvatha Elangovan
|
||||
.P
|
||||
.SH "SEE ALSO"
|
||||
opj_compress(1) opj_dump(1)
|
||||
@@ -1,62 +0,0 @@
|
||||
'\" t
|
||||
'\" The line above instructs most `man' programs to invoke tbl
|
||||
'\"
|
||||
'\" Separate paragraphs; not the same as PP which resets indent level.
|
||||
.de SP
|
||||
.if t .sp .5
|
||||
.if n .sp
|
||||
..
|
||||
'\"
|
||||
'\" Replacement em-dash for nroff (default is too short).
|
||||
.ie n .ds m " -
|
||||
.el .ds m \(em
|
||||
'\"
|
||||
'\" Placeholder macro for if longer nroff arrow is needed.
|
||||
.ds RA \(->
|
||||
'\"
|
||||
'\" Decimal point set slightly raised
|
||||
.if t .ds d \v'-.15m'.\v'+.15m'
|
||||
.if n .ds d .
|
||||
'\"
|
||||
'\" Enclosure macro for examples
|
||||
.de EX
|
||||
.SP
|
||||
.nf
|
||||
.ft CW
|
||||
..
|
||||
.de EE
|
||||
.ft R
|
||||
.SP
|
||||
.fi
|
||||
..
|
||||
.TH opj_dump 1 "Version 1.4.0" "opj_dump" "dumps jpeg2000 files"
|
||||
.P
|
||||
.SH NAME
|
||||
opj_dump -
|
||||
This program reads in a jpeg2000 image and dumps the contents to stdout. It is part of the OpenJPEG library.
|
||||
.SP
|
||||
Valid input image extensions are
|
||||
.B .j2k, .jp2, .jpt
|
||||
.SP
|
||||
.SH SYNOPSIS
|
||||
.P
|
||||
.B opj_dump -i \fRinfile.j2k
|
||||
.P
|
||||
.B opj_dump -ImgDir \fRimages/ \fRDump all files in images/
|
||||
.P
|
||||
.B opj_dump -h \fRPrint help message and exit
|
||||
.P
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-\^i "name"
|
||||
(jpeg2000 input file name)
|
||||
.TP
|
||||
.B \-\^ImgDir "directory_name"
|
||||
(directory containing jpeg2000 input files)
|
||||
.P
|
||||
'\".SH BUGS
|
||||
.SH AUTHORS
|
||||
Copyright (c) 2010, Mathieu Malaterre
|
||||
.P
|
||||
.SH "SEE ALSO"
|
||||
opj_compress(1) opj_decompress(1)
|
||||
@@ -1,337 +0,0 @@
|
||||
'\" t
|
||||
'\" The line above instructs most `man' programs to invoke tbl
|
||||
'\"
|
||||
'\" Separate paragraphs; not the same as PP which resets indent level.
|
||||
.de SP
|
||||
.if t .sp .5
|
||||
.if n .sp
|
||||
..
|
||||
'\"
|
||||
'\" Replacement em-dash for nroff (default is too short).
|
||||
.ie n .ds m " -
|
||||
.el .ds m \(em
|
||||
'\"
|
||||
'\" Placeholder macro for if longer nroff arrow is needed.
|
||||
.ds RA \(->
|
||||
'\"
|
||||
'\" Decimal point set slightly raised
|
||||
.if t .ds d \v'-.15m'.\v'+.15m'
|
||||
.if n .ds d .
|
||||
'\"
|
||||
'\" Enclosure macro for examples
|
||||
.de EX
|
||||
.SP
|
||||
.nf
|
||||
.ft CW
|
||||
..
|
||||
.de EE
|
||||
.ft R
|
||||
.SP
|
||||
.fi
|
||||
..
|
||||
.TH libopenjp2 3 "Oct 2010" "Version 1.4.0" "Oct 2010"
|
||||
.P
|
||||
.SH NAME
|
||||
libopenjp2 -
|
||||
a library for reading and writing JPEG2000 image files.
|
||||
.SP
|
||||
.SH SYNOPSIS
|
||||
.P
|
||||
.B #include <openjpeg.h>
|
||||
.P
|
||||
.SS CONVERSION FORMATS
|
||||
.B PGX: imagetopgx() \fR/\fB pgxtoimage()
|
||||
.P
|
||||
.B PXM: imagetopnm() \fR/\fB pnmtoimage()
|
||||
.P
|
||||
.B BMP: imagetobmp() \fR/\fB bmptoimage()
|
||||
.P
|
||||
.B TIF: imagetotif() \fR/\fB tiftoimage()
|
||||
.P
|
||||
.B RAW: imagetoraw() \fR/\fB rawtoimage()
|
||||
.P
|
||||
.B TGA: imagetotga() \fR/\fB tgatoimage()
|
||||
.P
|
||||
.B PNG: imagetopng() \fR/\fB pngtoimage()
|
||||
.P
|
||||
.B YUV: imagetoyuv() \fR/\fB yuvtoimage() \fR(MJ2)
|
||||
.P
|
||||
.SS READ
|
||||
.B opj_set_default_decoder_parameters(opj_dparameters_t *\fIparams\fB);
|
||||
.P
|
||||
.B opj_dinfo_t *opj_create_decompress(OPJ_CODEC_FORMAT \fIformat\fB);
|
||||
.P
|
||||
.B opj_event_mgr_t *opj_set_event_mgr(opj_common_ptr \fIinfo\fB, opj_event_mgr_t *\fIevent_mgr\fB, void *\fIcontext\fB);
|
||||
.P
|
||||
.B void opj_setup_decoder(opj_dinfo_t *\fIdinfo\fB, opj_dparameters_t * \fIparams\fB);
|
||||
.P
|
||||
.B opj_cio_t *opj_cio_open(opj_common_ptr \fIinfo\fB, unsigned char *\fIbuf\fB, int \fIbuf_len\fB);
|
||||
.P
|
||||
.B opj_image_t *opj_decode(opj_dinfo_t *\fIdinfo\fB, opj_cio_t *\fIcio\fB);
|
||||
.P
|
||||
.B void opj_cio_close(opj_cio_t *\fIcio\fB);
|
||||
.P
|
||||
.B void opj_destroy_decompress(opj_dinfo_t *\fIdinfo\fB);
|
||||
.P
|
||||
.B void opj_image_destroy(opj_image_t *\fIimage\fB);
|
||||
.P
|
||||
.SS WRITE
|
||||
.B void opj_set_default_encoder_parameters(opj_cparameters_t *\fIparams\fB);
|
||||
.P
|
||||
/*
|
||||
.B opj_image_t *FORMATtoimage(const char *\fIfname\fB, opj_cparameters_t *\fIparams\fB);
|
||||
.P
|
||||
*/
|
||||
.br
|
||||
.B opj_cinfo_t* opj_create_compress(OPJ_CODEC_FORMAT \fIformat\fB);
|
||||
.P
|
||||
.B opj_event_mgr_t *opj_set_event_mgr(opj_common_ptr \fIinfo\fB, opj_event_mgr_t *\fIevent_mgr\fB, void *\fIcontext\fB);
|
||||
.P
|
||||
.B void opj_setup_encoder(opj_cinfo_t *\fIcinfo\fB, opj_cparameters_t *\fIparams\fB, opj_image_t *\fIimage\fB);
|
||||
.P
|
||||
.B opj_cio_t *opj_cio_open(opj_common_ptr \fIcinfo\fB, \fINULL\fB, \fI0\fB);
|
||||
.P
|
||||
.B bool opj_encode(opj_cinfo_t *\fIcinfo\fB, opj_cio_t *\fIcio\fB, opj_image_t *\fIimage\fB, char *\fIindex\fB);
|
||||
.P
|
||||
.B void opj_cio_close(opj_cio_t *\fIcio\fB);
|
||||
.P
|
||||
.B void opj_destroy_compress(opj_cinfo_t *\fIcinfo\fB);
|
||||
.P
|
||||
.B void opj_image_destroy(opj_image_t *\fIimage\fB);
|
||||
.P
|
||||
.SS GENERAL
|
||||
.P
|
||||
.B void opj_image_create(int \fInumcmpts\fB, opj_image_cmptparm_t *\fIcmptparms\fB, OPJ_COLOR_SPACE \fIclrspc\fB);
|
||||
.P
|
||||
.B int cio_tell(opj_cio_t *\fIcio\fB);
|
||||
.P
|
||||
.B void cio_seek(opj_cio_t *\fIcio\fB, int \fIpos\fB);
|
||||
.P
|
||||
.B opj_image_t *opj_decode_with_info(opj_dinfo_t *\fIdinfo\fB, opj_cio_t *\fIcio\fB, opj_codestream_info_t *\fIcstr_info\fB);
|
||||
.P
|
||||
.B bool opj_encode_with_info(opj_cinfo_t *\fIcinfo\fB, opj_cio_t *\fIcio\fB, opj_image_t *\fIimage\fB, opj_codestream_info_t *\fIcstr_info\fB);
|
||||
.P
|
||||
.B void opj_destroy_cstr_info(opj_codestream_info_t *\fIcstr_info\fB);
|
||||
.P
|
||||
.B const char *opj_version(\fIvoid\fB);
|
||||
.P
|
||||
.SH OPJ_CODEC_FORMAT
|
||||
.P
|
||||
.B CODEC_J2K\fR or \fBCODEC_JPT\fR or \fBCODEC_JP2
|
||||
.P
|
||||
.SH OPJ_COLOR_SPACE
|
||||
.P
|
||||
.B CLRSPC_UNKNOWN\fR or \fBCLRSPC_UNSPECIFIED\fR or \fBCLRSPC_SRGB\fR or \fBCLRSPC_GRAY\fR or \fBCLRSPC_SYCC
|
||||
.P
|
||||
.SH DECOMPRESSION PARAMETERS
|
||||
.p
|
||||
typedef struct opj_dparameters
|
||||
.br
|
||||
{
|
||||
/*
|
||||
Set the number of highest resolution levels to be discarded.
|
||||
The image resolution is effectively divided by 2 to the power
|
||||
of the number of discarded levels.
|
||||
The reduce factor is limited by the smallest total number of
|
||||
decomposition levels among tiles.
|
||||
if != 0, then original dimension divided by 2^(reduce);
|
||||
if == 0 or not used, image is decoded to the full resolution
|
||||
*/
|
||||
\fBint\fR cp_reduce;
|
||||
/*
|
||||
Set the maximum number of quality layers to decode.
|
||||
If there are less quality layers than the specified number,
|
||||
all the quality layers are decoded.
|
||||
if != 0, then only the first "layer" layers are decoded;
|
||||
if == 0 or not used, all the quality layers are decoded
|
||||
*/
|
||||
\fBint\fR cp_layer;
|
||||
|
||||
/*command line encoder parameters (not used inside the library) */
|
||||
/* input file name */
|
||||
\fBchar\fR infile[OPJ_PATH_LEN];
|
||||
/* output file name */
|
||||
\fBchar\fR outfile[OPJ_PATH_LEN];
|
||||
/* input file format: see OPJ_CODEC_FORMAT */
|
||||
\fBint\fR decod_format;
|
||||
/* output file format */
|
||||
\fBint\fR cod_format;
|
||||
|
||||
/*JPWL decoding parameters */
|
||||
/* activates the JPWL correction capabilities */
|
||||
\fBbool\fR jpwl_correct;
|
||||
/* expected number of components */
|
||||
\fBint\fR jpwl_exp_comps;
|
||||
/* maximum number of tiles */
|
||||
\fBint\fR jpwl_max_tiles;
|
||||
|
||||
/*
|
||||
Specify whether the decoding should be done on the entire
|
||||
codestream, or be limited to the main header
|
||||
Limiting the decoding to the main header makes it possible
|
||||
to extract the characteristics of the codestream
|
||||
if == NO_LIMITATION, the entire codestream is decoded;
|
||||
if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
|
||||
*/
|
||||
\fBOPJ_LIMIT_DECODING\fR cp_limit_decoding;
|
||||
.br
|
||||
} opj_dparameters_t;
|
||||
|
||||
.SH COMPRESSION PARAMETERS
|
||||
.P
|
||||
typedef struct opj_cparameters
|
||||
.br
|
||||
{
|
||||
/* size of tile: tile_size_on = false (not in argument)
|
||||
or tile_size_on = true (in argument) */
|
||||
\fBbool\fR tile_size_on;
|
||||
/* XTOsiz */
|
||||
\fBint\fR cp_tx0;
|
||||
/* YTOsiz */
|
||||
\fBint\fR cp_ty0;
|
||||
/* XTsiz */
|
||||
\fBint\fR cp_tdx;
|
||||
/* YTsiz */
|
||||
\fBint\fR cp_tdy;
|
||||
/* allocation by rate/distortion */
|
||||
\fBint\fR cp_disto_alloc;
|
||||
/* allocation by fixed layer */
|
||||
\fBint\fR cp_fixed_alloc;
|
||||
/* add fixed_quality */
|
||||
\fBint\fR cp_fixed_quality;
|
||||
/* fixed layer */
|
||||
\fBint *\fRcp_matrice;
|
||||
/* comment for coding */
|
||||
\fBchar *\fRcp_comment;
|
||||
/* coding style */
|
||||
\fBint\fR csty;
|
||||
/* progression order:
|
||||
PROG_UNKNOWN, LRCP(default), RLCP, RPCL, PCRL, CPRL */
|
||||
\fBOPJ_PROG_ORDER\fR prog_order;
|
||||
/* progression order changes */
|
||||
\fBopj_poc_t\fR POC[32];
|
||||
/* number of progression order changes (POC), default: 0 */
|
||||
\fBint\fR numpocs;
|
||||
/* number of layers */
|
||||
\fBint\fR tcp_numlayers;
|
||||
/* rates of layers */
|
||||
\fBfloat\fR tcp_rates[100];
|
||||
/* different psnr for successive layers */
|
||||
\fBfloat\fR tcp_distoratio[100];
|
||||
/* number of resolutions */
|
||||
\fBint\fR numresolution;
|
||||
/* initial code block width, default: 64 */
|
||||
\fBint\fR cblockw_init;
|
||||
/* initial code block height, default: 64 */
|
||||
\fBint\fR cblockh_init;
|
||||
/* mode switch (cblk_style) */
|
||||
/* 1 : use the irreversible DWT 9-7,
|
||||
0 : use lossless compression (default) */
|
||||
\fBint\fR irreversible;
|
||||
/* region of interest: affected component in [0..3],
|
||||
-1 means no ROI */
|
||||
\fBint\fR roi_compno;
|
||||
/* region of interest: upshift value */
|
||||
\fBint\fR roi_shift;
|
||||
/* number of precinct size specifications */
|
||||
\fBint\fR res_spec;
|
||||
/* initial precinct width */
|
||||
\fBint\fR prcw_init[J2K_MAXRLVLS];
|
||||
/* initial precinct height */
|
||||
\fBint\fR prch_init[J2K_MAXRLVLS];
|
||||
|
||||
/*command line encoder parameters (not used inside the library) */
|
||||
/* input file name */
|
||||
\fBchar\fR infile[OPJ_PATH_LEN];
|
||||
/* output file name */
|
||||
\fBchar\fR outfile[OPJ_PATH_LEN];
|
||||
/* DEPRECATED. Index generation is now handeld with the
|
||||
opj_encode_with_info() function. Set to NULL */
|
||||
\fBint\fR index_on;
|
||||
/* DEPRECATED. Index generation is now handeld with the
|
||||
opj_encode_with_info() function. Set to NULL */
|
||||
\fBchar\fR index[OPJ_PATH_LEN];
|
||||
/* subimage encoding: origin image offset in x direction */
|
||||
\fBint\fR image_offset_x0;
|
||||
/* subimage encoding: origin image offset in y direction */
|
||||
\fBint\fR image_offset_y0;
|
||||
/* subsampling value for dx */
|
||||
\fBint\fR subsampling_dx;
|
||||
/* subsampling value for dy */
|
||||
\fBint\fR subsampling_dy;
|
||||
/* input file format */
|
||||
\fBint\fR decod_format;
|
||||
/* output file format: see OPJ_CODEC_FORMAT */
|
||||
\fBint\fR cod_format;
|
||||
|
||||
/*JPWL encoding parameters */
|
||||
/* enables writing of EPC in MH, thus activating JPWL */
|
||||
\fBbool\fR jpwl_epc_on;
|
||||
/* error protection method for MH (0,1,16,32,37-128) */
|
||||
\fBint\fR jpwl_hprot_MH;
|
||||
/* tile number of header protection specification (>=0) */
|
||||
\fBint\fR jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
|
||||
/* error protection methods for TPHs (0,1,16,32,37-128) */
|
||||
\fBint\fR jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
|
||||
/* tile number of packet protection specification (>=0) */
|
||||
\fBint\fR jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
|
||||
/* packet number of packet protection specification (>=0) */
|
||||
\fBint\fR jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
|
||||
/* error protection methods for packets (0,1,16,32,37-128) */
|
||||
\fBint\fR jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
|
||||
/* enables writing of ESD, (0=no/1/2 bytes) */
|
||||
\fBint\fR jpwl_sens_size;
|
||||
/* sensitivity addressing size (0=auto/2/4 bytes) */
|
||||
\fBint\fR jpwl_sens_addr;
|
||||
/* sensitivity range (0-3) */
|
||||
\fBint\fR jpwl_sens_range;
|
||||
/* sensitivity method for MH (-1=no,0-7) */
|
||||
\fBint\fR jpwl_sens_MH;
|
||||
/* tile number of sensitivity specification (>=0) */
|
||||
\fBint\fR jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
|
||||
/* sensitivity methods for TPHs (-1=no,0-7) */
|
||||
\fBint\fR jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
|
||||
|
||||
/* Digital Cinema compliance: OFF-not compliant,
|
||||
CINEMA2K_24, CINEMA2K_48, CINEMA4K_24 */
|
||||
\fBOPJ_CINEMA_MODE\fR cp_cinema;
|
||||
/* Maximum rate for each component.
|
||||
If == 0, component size limitation is not considered */
|
||||
\fBint\fR max_comp_size;
|
||||
/* Profile name*/
|
||||
\fBOPJ_RSIZ_CAPABILITIES\fR cp_rsiz;
|
||||
/* Tile part generation*/
|
||||
\fBchar\fR tp_on;
|
||||
/* Flag for Tile part generation*/
|
||||
\fBchar\fR tp_flag;
|
||||
/* MCT (multiple component transform) */
|
||||
\fBchar\fR tcp_mct;
|
||||
.br
|
||||
} opj_cparameters_t;
|
||||
|
||||
|
||||
'\".SH OPTIONS
|
||||
'\".SH BUGS
|
||||
.SH AUTHORS
|
||||
Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
|
||||
Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
|
||||
Copyright (c) 2001-2003, David Janssens
|
||||
|
||||
Copyright (c) 2002-2003, Yannick Verschueren
|
||||
|
||||
Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
|
||||
Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
|
||||
Copyright (c) 2006-2007, Parvatha Elangovan
|
||||
|
||||
.P
|
||||
.SH "SEE ALSO"
|
||||
\fBimage_to_j2k\fR(1) \fBj2k_to_image\fR(1) \fBj2k_dump\fR(1)
|
||||
|
||||
\fBJPWL_image_to_j2k\fR(1) \fBJPWL_j2k_to_image\fR(1)
|
||||
|
||||
\fBextract_j2k_from_mj2\fR(1) \fBwrap_j2k_in_mj2\fR(1)
|
||||
\fBframes_to_mj2\fR(1) \fBmj2_to_frames\fR(1)
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*! \page openjpippage OpenJPIP v@OPENJPEG_VERSION@ Documentation
|
||||
*
|
||||
* \section intro Introduction
|
||||
* This manual documents the low-level OpenJPIP C API.\n
|
||||
* OpenJPIP software is an implementation of JPEG 2000 Part9: Interactivity tools, APIs and protocols (JPIP).\n
|
||||
* ( For more info about JPIP, check the website: http://www.jpeg.org/jpeg2000/j2kpart9.html)\n
|
||||
*
|
||||
* This whole documents covers the following six programs.\n
|
||||
* - opj_server.c JPIP server supporting HTTP connection and JPT/JPP-stream
|
||||
* - opj_dec_server.c Server to decode JPT/JPP-stream and communicate locally with JPIP client, which is coded in java
|
||||
* - opj_jpip_addxml.c To Embed metadata into JP2 file
|
||||
* - opj_jpip_transcode.c To Convert JPT/JPP-stream to JP2 or J2K
|
||||
* - opj_jpip_test.c To test index code format of a JP2 file
|
||||
*
|
||||
* \section license License
|
||||
* This software is released under the BSD license, anybody can use or modify the library, even for commercial applications.\n
|
||||
* The only restriction is to retain the copyright in the sources or the binaries documentation.\n
|
||||
* Neither the author, nor the university accept any responsibility for any kind of error or data loss which may occur during usage.
|
||||
*
|
||||
*
|
||||
* \section reqlibs Required libraries
|
||||
* - OpenJPEG library
|
||||
* - FastCGI development kit (C libraries) at server (http://www.fastcgi.com)
|
||||
* - libcURL library
|
||||
*
|
||||
* We tested this software with a virtual server running on the same Linux machine as the clients.
|
||||
*
|
||||
*
|
||||
* \section compilenotes Compiling Notes
|
||||
* When you are making opj_server, set anything (e.g. yes) to the parameter jpipserver to define itself in the Makefile, which enables to make it in server mode.\n
|
||||
* Otherwise do not define (or do not set to) the parameter jpipserver.\n
|
||||
* Be sure that any object files and library file libopenjpip.a are not reused to compile in the two different mode (server mode and non server mode).\n
|
||||
* In other words, do make clean before making new targets which are in different modes as previous make.\n
|
||||
*
|
||||
*
|
||||
* \section sysarchtect System Architecture
|
||||
* JPIP protocol is implimented between the JPIP server program (opj_server) and the JPIP client java program (opj_viewer).\n
|
||||
* Figure below represents the overview of our system architecture.\n
|
||||
* The JPIP server parses JPIP query and sends corresponding JPT/JPP-stream.
|
||||
* The JPIP client viewer is an image viewer with GUI to publish JPIP requests and receive JPT/JPP-stream.\n
|
||||
* Particularly, our system has the image decoding module implemented on a server (opj_dec_server, Image decoding Server).
|
||||
* Image decoding Server and JPIP client viewer communicate closely.
|
||||
* This specific architecture enables sharing cache of image codestream data among all viewers connected to the same Image decoding Server not only locally but also remotely.
|
||||
*
|
||||
* \image html jpip_architect.png "OpenJPIP system architecture"
|
||||
*
|
||||
* JPIP server follows up the client cache during a session. \n
|
||||
* Concretely, the JPIP server models cache in each session, to which Channel IDs are associated.
|
||||
* A Channel ID identifies a JPIP client viewer.
|
||||
* And, new viewers can belong to a session by referring to one of its channel ID.
|
||||
* The Image decoding Server maintains the association between channel IDs and targets, and provides a reference channel ID to a Viewer on demand.\n
|
||||
*
|
||||
* Typical requests and replies among JPIP server, JPIP client, and Image decoding server is presented below.\n
|
||||
* The JPIP server parses HTTP query and sends corresponding JPT/JPP-stream back to the JPIP client (Viewer).
|
||||
* JPT/JPP-stream is unreadable by JPIP client, and it is directly passed to Image decoding Server, and which provides the image in raw format (PGM or PPM) to the JPIP client.
|
||||
* The Image decoding Server handles the decoding and caching of JPT/JPP-stream.
|
||||
* JPIP client can read PGM and PPM images natively.
|
||||
* Before connecting to the JPIP server, every JPIP client checks local cache data of the requesting image with the image decoding server.
|
||||
* If its cache exists, the image decoding server provides ChannelID (CID), which identifies the image and its cache model on the JPIP server, and the whole system can continue the session using the CID.
|
||||
*
|
||||
* \image html jpip_protocol.png "Message Sequence Chart of OpenJPIP impementation"
|
||||
*
|
||||
* \author Kaori Hagihara UCL/SST/ICTM/ELEN
|
||||
*/
|
||||
80
libopenjpeg/CMakeLists.txt
Normal file
80
libopenjpeg/CMakeLists.txt
Normal file
@@ -0,0 +1,80 @@
|
||||
INCLUDE_REGULAR_EXPRESSION("^.*$")
|
||||
# Defines the source code for the library
|
||||
SET(OPENJPEG_SRCS
|
||||
tcd.c
|
||||
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
|
||||
tgt.c
|
||||
profile.c
|
||||
invert.c
|
||||
function_list.c
|
||||
t2.c
|
||||
bio.h
|
||||
cio.h
|
||||
dwt.h
|
||||
event.h
|
||||
image.h
|
||||
j2k.h
|
||||
j2k_lib.h
|
||||
jp2.h
|
||||
jpt.h
|
||||
mct.h
|
||||
mqc.h
|
||||
openjpeg.h
|
||||
pi.h
|
||||
int.h
|
||||
raw.h
|
||||
t1.h
|
||||
t2.h
|
||||
tcd.h
|
||||
tgt.h
|
||||
profile.h
|
||||
invert.h
|
||||
function_list.h
|
||||
)
|
||||
|
||||
# Pass proper definition to preprocessor to generate shared lib
|
||||
IF(WIN32)
|
||||
IF(BUILD_SHARED_LIBS)
|
||||
ADD_DEFINITIONS(-DOPJ_EXPORTS)
|
||||
ELSE(BUILD_SHARED_LIBS)
|
||||
ADD_DEFINITIONS(-DOPJ_STATIC)
|
||||
ENDIF(BUILD_SHARED_LIBS)
|
||||
ENDIF(WIN32)
|
||||
|
||||
IF(ENABLE_PROFILING)
|
||||
ADD_DEFINITIONS(-D_PROFILE)
|
||||
ENDIF(ENABLE_PROFILING)
|
||||
|
||||
# Create the library
|
||||
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
|
||||
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME} PROPERTIES
|
||||
${OPENJPEG_LIBRARY_PROPERTIES})
|
||||
IF(UNIX)
|
||||
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME} m)
|
||||
ENDIF(UNIX)
|
||||
|
||||
|
||||
# Install library
|
||||
INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}
|
||||
EXPORT OpenJPEGTargets
|
||||
DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
|
||||
)
|
||||
|
||||
# Install includes files
|
||||
INSTALL(FILES openjpeg.h
|
||||
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers
|
||||
)
|
||||
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -29,7 +30,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "opj_includes.h"
|
||||
#include "bio.h"
|
||||
#include "opj_malloc.h"
|
||||
|
||||
/** @defgroup BIO BIO - Individual bit input-output stream */
|
||||
/*@{*/
|
||||
@@ -42,25 +44,25 @@ Write a bit
|
||||
@param bio BIO handle
|
||||
@param b Bit to write (0 or 1)
|
||||
*/
|
||||
static void bio_putbit(opj_bio_t *bio, int b);
|
||||
static void bio_putbit(opj_bio_t *bio, OPJ_UINT32 b);
|
||||
/**
|
||||
Read a bit
|
||||
@param bio BIO handle
|
||||
@return Returns the read bit
|
||||
*/
|
||||
static int bio_getbit(opj_bio_t *bio);
|
||||
static OPJ_UINT32 bio_getbit(opj_bio_t *bio);
|
||||
/**
|
||||
Write a byte
|
||||
@param bio BIO handle
|
||||
@return Returns 0 if successful, returns 1 otherwise
|
||||
*/
|
||||
static int bio_byteout(opj_bio_t *bio);
|
||||
static bool bio_byteout(opj_bio_t *bio);
|
||||
/**
|
||||
Read a byte
|
||||
@param bio BIO handle
|
||||
@return Returns 0 if successful, returns 1 otherwise
|
||||
*/
|
||||
static int bio_bytein(opj_bio_t *bio);
|
||||
static bool bio_bytein(opj_bio_t *bio);
|
||||
|
||||
/*@}*/
|
||||
|
||||
@@ -72,27 +74,27 @@ static int bio_bytein(opj_bio_t *bio);
|
||||
==========================================================
|
||||
*/
|
||||
|
||||
static int bio_byteout(opj_bio_t *bio) {
|
||||
static bool bio_byteout(opj_bio_t *bio) {
|
||||
bio->buf = (bio->buf << 8) & 0xffff;
|
||||
bio->ct = bio->buf == 0xff00 ? 7 : 8;
|
||||
if (bio->bp >= bio->end) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
*bio->bp++ = bio->buf >> 8;
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int bio_bytein(opj_bio_t *bio) {
|
||||
static bool bio_bytein(opj_bio_t *bio) {
|
||||
bio->buf = (bio->buf << 8) & 0xffff;
|
||||
bio->ct = bio->buf == 0xff00 ? 7 : 8;
|
||||
if (bio->bp >= bio->end) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
bio->buf |= *bio->bp++;
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void bio_putbit(opj_bio_t *bio, int b) {
|
||||
static void bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) {
|
||||
if (bio->ct == 0) {
|
||||
bio_byteout(bio);
|
||||
}
|
||||
@@ -100,7 +102,7 @@ static void bio_putbit(opj_bio_t *bio, int b) {
|
||||
bio->buf |= b << bio->ct;
|
||||
}
|
||||
|
||||
static int bio_getbit(opj_bio_t *bio) {
|
||||
static OPJ_UINT32 bio_getbit(opj_bio_t *bio) {
|
||||
if (bio->ct == 0) {
|
||||
bio_bytein(bio);
|
||||
}
|
||||
@@ -125,11 +127,11 @@ void bio_destroy(opj_bio_t *bio) {
|
||||
}
|
||||
}
|
||||
|
||||
int bio_numbytes(opj_bio_t *bio) {
|
||||
OPJ_UINT32 bio_numbytes(opj_bio_t *bio) {
|
||||
return (bio->bp - bio->start);
|
||||
}
|
||||
|
||||
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) {
|
||||
void bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
|
||||
bio->start = bp;
|
||||
bio->end = bp + len;
|
||||
bio->bp = bp;
|
||||
@@ -137,7 +139,7 @@ void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) {
|
||||
bio->ct = 8;
|
||||
}
|
||||
|
||||
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) {
|
||||
void bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
|
||||
bio->start = bp;
|
||||
bio->end = bp + len;
|
||||
bio->bp = bp;
|
||||
@@ -145,43 +147,43 @@ void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) {
|
||||
bio->ct = 0;
|
||||
}
|
||||
|
||||
void bio_write(opj_bio_t *bio, int v, int n) {
|
||||
int i;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
void bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) {
|
||||
OPJ_UINT32 i;
|
||||
for (i = n - 1; i != -1 ; --i) {
|
||||
bio_putbit(bio, (v >> i) & 1);
|
||||
}
|
||||
}
|
||||
|
||||
int bio_read(opj_bio_t *bio, int n) {
|
||||
int i, v;
|
||||
OPJ_UINT32 bio_read(opj_bio_t *bio, OPJ_UINT32 n) {
|
||||
OPJ_UINT32 i, v;
|
||||
v = 0;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
for (i = n - 1; i != -1 ; --i) {
|
||||
v += bio_getbit(bio) << i;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
int bio_flush(opj_bio_t *bio) {
|
||||
bool bio_flush(opj_bio_t *bio) {
|
||||
bio->ct = 0;
|
||||
if (bio_byteout(bio)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
if (bio->ct == 7) {
|
||||
bio->ct = 0;
|
||||
if (bio_byteout(bio)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
int bio_inalign(opj_bio_t *bio) {
|
||||
bool bio_inalign(opj_bio_t *bio) {
|
||||
bio->ct = 0;
|
||||
if ((bio->buf & 0xff) == 0xff) {
|
||||
if (bio_bytein(bio)) {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
bio->ct = 0;
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -37,7 +38,7 @@
|
||||
|
||||
The functions in BIO.C have for goal to realize an individual bit input - output.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
/** @defgroup BIO BIO - Individual bit input-output stream */
|
||||
/*@{*/
|
||||
|
||||
@@ -46,15 +47,15 @@ Individual bit input-output stream (BIO)
|
||||
*/
|
||||
typedef struct opj_bio {
|
||||
/** pointer to the start of the buffer */
|
||||
unsigned char *start;
|
||||
OPJ_BYTE *start;
|
||||
/** pointer to the end of the buffer */
|
||||
unsigned char *end;
|
||||
OPJ_BYTE *end;
|
||||
/** pointer to the present position in the buffer */
|
||||
unsigned char *bp;
|
||||
OPJ_BYTE *bp;
|
||||
/** temporary place where each byte is read or written */
|
||||
unsigned int buf;
|
||||
OPJ_UINT32 buf;
|
||||
/** coder : number of bits free to write. decoder : number of bits read */
|
||||
int ct;
|
||||
OPJ_UINT32 ct;
|
||||
} opj_bio_t;
|
||||
|
||||
/** @name Exported functions */
|
||||
@@ -75,47 +76,47 @@ Number of bytes written.
|
||||
@param bio BIO handle
|
||||
@return Returns the number of bytes written
|
||||
*/
|
||||
int bio_numbytes(opj_bio_t *bio);
|
||||
OPJ_UINT32 bio_numbytes(opj_bio_t *bio);
|
||||
/**
|
||||
Init encoder
|
||||
@param bio BIO handle
|
||||
@param bp Output buffer
|
||||
@param len Output buffer length
|
||||
*/
|
||||
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len);
|
||||
void bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len);
|
||||
/**
|
||||
Init decoder
|
||||
@param bio BIO handle
|
||||
@param bp Input buffer
|
||||
@param len Input buffer length
|
||||
*/
|
||||
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len);
|
||||
void bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len);
|
||||
/**
|
||||
Write bits
|
||||
@param bio BIO handle
|
||||
@param v Value of bits
|
||||
@param n Number of bits to write
|
||||
*/
|
||||
void bio_write(opj_bio_t *bio, int v, int n);
|
||||
void bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n);
|
||||
/**
|
||||
Read bits
|
||||
@param bio BIO handle
|
||||
@param n Number of bits to read
|
||||
@return Returns the corresponding read number
|
||||
*/
|
||||
int bio_read(opj_bio_t *bio, int n);
|
||||
OPJ_UINT32 bio_read(opj_bio_t *bio, OPJ_UINT32 n);
|
||||
/**
|
||||
Flush bits
|
||||
@param bio BIO handle
|
||||
@return Returns 1 if successful, returns 0 otherwise
|
||||
*/
|
||||
int bio_flush(opj_bio_t *bio);
|
||||
bool bio_flush(opj_bio_t *bio);
|
||||
/**
|
||||
Passes the ending bits (coming from flushing)
|
||||
@param bio BIO handle
|
||||
@return Returns 1 if successful, returns 0 otherwise
|
||||
*/
|
||||
int bio_inalign(opj_bio_t *bio);
|
||||
bool bio_inalign(opj_bio_t *bio);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
828
libopenjpeg/cio.c
Normal file
828
libopenjpeg/cio.c
Normal file
@@ -0,0 +1,828 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2001-2003, David Janssens
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "cio.h"
|
||||
#include "opj_includes.h"
|
||||
#include "opj_malloc.h"
|
||||
#include "event.h"
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/**
|
||||
* Write some bytes to the given data buffer, this function is used in Big Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to write data to.
|
||||
* @param p_value the value to write
|
||||
* @param p_nb_bytes the number of bytes to write
|
||||
*/
|
||||
void opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes)
|
||||
{
|
||||
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + p_nb_bytes;
|
||||
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
|
||||
memcpy(p_buffer,l_data_ptr,p_nb_bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write some bytes to the given data buffer, this function is used in Little Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to write data to.
|
||||
* @param p_value the value to write
|
||||
* @param p_nb_bytes the number of bytes to write
|
||||
* @return the number of bytes written or -1 if an error occured
|
||||
*/
|
||||
void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes)
|
||||
{
|
||||
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + p_nb_bytes - 1;
|
||||
OPJ_UINT32 i;
|
||||
|
||||
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
|
||||
for
|
||||
(i=0;i<p_nb_bytes;++i)
|
||||
{
|
||||
*(p_buffer++) = *(l_data_ptr--);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads some bytes from the given data buffer, this function is used in Big Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to read data from.
|
||||
* @param p_value pointer to the value that will store the data.
|
||||
* @param p_nb_bytes the nb bytes to read.
|
||||
* @return the number of bytes read or -1 if an error occured.
|
||||
*/
|
||||
void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes)
|
||||
{
|
||||
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value);
|
||||
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
|
||||
*p_value = 0;
|
||||
memcpy(l_data_ptr+4-p_nb_bytes,p_buffer,p_nb_bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads some bytes from the given data buffer, this function is used in Little Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to read data from.
|
||||
* @param p_value pointer to the value that will store the data.
|
||||
* @param p_nb_bytes the nb bytes to read.
|
||||
* @return the number of bytes read or -1 if an error occured.
|
||||
*/
|
||||
void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes)
|
||||
{
|
||||
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + p_nb_bytes-1;
|
||||
OPJ_UINT32 i;
|
||||
|
||||
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
|
||||
*p_value = 0;
|
||||
for
|
||||
(i=0;i<p_nb_bytes;++i)
|
||||
{
|
||||
*(l_data_ptr--) = *(p_buffer++);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write some bytes to the given data buffer, this function is used in Big Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to write data to.
|
||||
* @param p_value the value to write
|
||||
* @return the number of bytes written or -1 if an error occured
|
||||
*/
|
||||
void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value)
|
||||
{
|
||||
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value);
|
||||
memcpy(p_buffer,l_data_ptr,sizeof(OPJ_FLOAT64));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write some bytes to the given data buffer, this function is used in Little Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to write data to.
|
||||
* @param p_value the value to write
|
||||
*/
|
||||
void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value)
|
||||
{
|
||||
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT64) - 1;
|
||||
OPJ_UINT32 i;
|
||||
for
|
||||
(i=0;i<sizeof(OPJ_FLOAT64);++i)
|
||||
{
|
||||
*(p_buffer++) = *(l_data_ptr--);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads some bytes from the given data buffer, this function is used in Big Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to read data from.
|
||||
* @param p_value pointer to the value that will store the data.
|
||||
*/
|
||||
void opj_read_double_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value)
|
||||
{
|
||||
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value);
|
||||
memcpy(l_data_ptr,p_buffer,sizeof(OPJ_FLOAT64));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads some bytes from the given data buffer, this function is used in Little Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to read data from.
|
||||
* @param p_value pointer to the value that will store the data.
|
||||
*/
|
||||
void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value)
|
||||
{
|
||||
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT64)-1;
|
||||
OPJ_UINT32 i;
|
||||
for
|
||||
(i=0;i<sizeof(OPJ_FLOAT64);++i)
|
||||
{
|
||||
*(l_data_ptr--) = *(p_buffer++);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write some bytes to the given data buffer, this function is used in Big Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to write data to.
|
||||
* @param p_value the value to write
|
||||
* @return the number of bytes written or -1 if an error occured
|
||||
*/
|
||||
void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value)
|
||||
{
|
||||
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value);
|
||||
memcpy(p_buffer,l_data_ptr,sizeof(OPJ_FLOAT32));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write some bytes to the given data buffer, this function is used in Little Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to write data to.
|
||||
* @param p_value the value to write
|
||||
*/
|
||||
void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value)
|
||||
{
|
||||
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT32) - 1;
|
||||
OPJ_UINT32 i;
|
||||
for
|
||||
(i=0;i<sizeof(OPJ_FLOAT32);++i)
|
||||
{
|
||||
*(p_buffer++) = *(l_data_ptr--);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads some bytes from the given data buffer, this function is used in Big Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to read data from.
|
||||
* @param p_value pointer to the value that will store the data.
|
||||
*/
|
||||
void opj_read_float_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value)
|
||||
{
|
||||
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value);
|
||||
memcpy(l_data_ptr,p_buffer,sizeof(OPJ_FLOAT32));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads some bytes from the given data buffer, this function is used in Little Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to read data from.
|
||||
* @param p_value pointer to the value that will store the data.
|
||||
*/
|
||||
void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value)
|
||||
{
|
||||
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT32)-1;
|
||||
OPJ_UINT32 i;
|
||||
for
|
||||
(i=0;i<sizeof(OPJ_FLOAT32);++i)
|
||||
{
|
||||
*(l_data_ptr--) = *(p_buffer++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
|
||||
* @return a stream object.
|
||||
*/
|
||||
opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_UINT32 p_size,bool l_is_input)
|
||||
{
|
||||
opj_stream_private_t * l_stream = 00;
|
||||
l_stream = (opj_stream_private_t*) opj_malloc(sizeof(opj_stream_private_t));
|
||||
if
|
||||
(! l_stream)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
memset(l_stream,0,sizeof(opj_stream_private_t));
|
||||
l_stream->m_buffer_size = p_size;
|
||||
l_stream->m_stored_data = (OPJ_BYTE *) opj_malloc(p_size);
|
||||
if
|
||||
(! l_stream->m_stored_data)
|
||||
{
|
||||
opj_free(l_stream);
|
||||
return 00;
|
||||
}
|
||||
l_stream->m_current_data = l_stream->m_stored_data;
|
||||
if
|
||||
(l_is_input)
|
||||
{
|
||||
l_stream->m_status |= opj_stream_e_input;
|
||||
l_stream->m_opj_skip = opj_stream_read_skip;
|
||||
l_stream->m_opj_seek = opj_stream_read_seek;
|
||||
}
|
||||
else
|
||||
{
|
||||
l_stream->m_status |= opj_stream_e_output;
|
||||
l_stream->m_opj_skip = opj_stream_write_skip;
|
||||
l_stream->m_opj_seek = opj_stream_write_seek;
|
||||
}
|
||||
l_stream->m_read_fn = opj_stream_default_read;
|
||||
l_stream->m_write_fn = opj_stream_default_write;
|
||||
l_stream->m_skip_fn = opj_stream_default_skip;
|
||||
l_stream->m_seek_fn = opj_stream_default_seek;
|
||||
|
||||
return (opj_stream_t *) l_stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
|
||||
* @return a stream object.
|
||||
*/
|
||||
opj_stream_t* OPJ_CALLCONV opj_stream_default_create(bool l_is_input)
|
||||
{
|
||||
return opj_stream_create(J2K_STREAM_CHUNK_SIZE,l_is_input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
|
||||
* close its own implementation of the stream.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream)
|
||||
{
|
||||
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
|
||||
if
|
||||
(l_stream)
|
||||
{
|
||||
opj_free(l_stream->m_stored_data);
|
||||
l_stream->m_stored_data = 00;
|
||||
opj_free(l_stream);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given function to be used as a read function.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_function the function to use a read function.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function)
|
||||
{
|
||||
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
|
||||
if
|
||||
((!l_stream) || (! (l_stream->m_status & opj_stream_e_input)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
l_stream->m_read_fn = p_function;
|
||||
}
|
||||
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function)
|
||||
{
|
||||
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
|
||||
if
|
||||
(!l_stream)
|
||||
{
|
||||
return;
|
||||
}
|
||||
l_stream->m_seek_fn = p_function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given function to be used as a write function.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_function the function to use a write function.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function)
|
||||
{
|
||||
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
|
||||
if
|
||||
((!l_stream )|| (! (l_stream->m_status & opj_stream_e_output)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
l_stream->m_write_fn = p_function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given function to be used as a skip function.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_function the function to use a skip function.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function)
|
||||
{
|
||||
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
|
||||
if
|
||||
(! l_stream)
|
||||
{
|
||||
return;
|
||||
}
|
||||
l_stream->m_skip_fn = p_function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given data to be used as a user data for the stream.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_data the data to set.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data)
|
||||
{
|
||||
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
|
||||
l_stream->m_user_data = p_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads some bytes from the stream.
|
||||
* @param p_stream the stream to read data from.
|
||||
* @param p_buffer pointer to the data buffer that will receive the data.
|
||||
* @param p_size number of bytes to read.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes read, or -1 if an error occured or if the stream is at the end.
|
||||
*/
|
||||
OPJ_UINT32 opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_UINT32 p_size, opj_event_mgr_t * p_event_mgr)
|
||||
{
|
||||
OPJ_UINT32 l_read_nb_bytes = 0;
|
||||
if
|
||||
(p_stream->m_bytes_in_buffer >= p_size)
|
||||
{
|
||||
memcpy(p_buffer,p_stream->m_current_data,p_size);
|
||||
p_stream->m_current_data += p_size;
|
||||
p_stream->m_bytes_in_buffer -= p_size;
|
||||
l_read_nb_bytes += p_size;
|
||||
p_stream->m_byte_offset += p_size;
|
||||
return l_read_nb_bytes;
|
||||
}
|
||||
|
||||
// we are now in the case when the remaining data if not sufficient
|
||||
if
|
||||
(p_stream->m_status & opj_stream_e_end)
|
||||
{
|
||||
l_read_nb_bytes += p_stream->m_bytes_in_buffer;
|
||||
memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer);
|
||||
p_stream->m_current_data += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_byte_offset += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
return l_read_nb_bytes ? l_read_nb_bytes : -1;
|
||||
}
|
||||
|
||||
// the flag is not set, we copy data and then do an actual read on the stream
|
||||
if
|
||||
(p_stream->m_bytes_in_buffer)
|
||||
{
|
||||
l_read_nb_bytes += p_stream->m_bytes_in_buffer;
|
||||
memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer);
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
p_buffer += p_stream->m_bytes_in_buffer;
|
||||
p_size -= p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_byte_offset += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* case where we are already at the end of the buffer
|
||||
so reset the m_current_data to point to the start of the
|
||||
stored buffer to get ready to read from disk*/
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
}
|
||||
|
||||
|
||||
while
|
||||
(true)
|
||||
{
|
||||
// we should read less than a chunk -> read a chunk
|
||||
if
|
||||
(p_size < p_stream->m_buffer_size)
|
||||
{
|
||||
// we should do an actual read on the media
|
||||
p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_stream->m_stored_data,p_stream->m_buffer_size,p_stream->m_user_data);
|
||||
if
|
||||
(p_stream->m_bytes_in_buffer == -1)
|
||||
{
|
||||
// end of stream
|
||||
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
p_stream->m_status |= opj_stream_e_end;
|
||||
// end of stream
|
||||
return l_read_nb_bytes ? l_read_nb_bytes : -1;
|
||||
}
|
||||
else if
|
||||
(p_stream->m_bytes_in_buffer < p_size)
|
||||
{
|
||||
// not enough data
|
||||
l_read_nb_bytes += p_stream->m_bytes_in_buffer;
|
||||
memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer);
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
p_buffer += p_stream->m_bytes_in_buffer;
|
||||
p_size -= p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_byte_offset += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
l_read_nb_bytes += p_size;
|
||||
memcpy(p_buffer,p_stream->m_current_data,p_size);
|
||||
p_stream->m_current_data += p_size;
|
||||
p_stream->m_bytes_in_buffer -= p_size;
|
||||
p_stream->m_byte_offset += p_size;
|
||||
return l_read_nb_bytes;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// direct read on the dest buffer
|
||||
p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_buffer,p_size,p_stream->m_user_data);
|
||||
if
|
||||
(p_stream->m_bytes_in_buffer == -1)
|
||||
{
|
||||
// end of stream
|
||||
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
p_stream->m_status |= opj_stream_e_end;
|
||||
// end of stream
|
||||
return l_read_nb_bytes ? l_read_nb_bytes : -1;
|
||||
}
|
||||
else if
|
||||
(p_stream->m_bytes_in_buffer < p_size)
|
||||
{
|
||||
// not enough data
|
||||
l_read_nb_bytes += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
p_buffer += p_stream->m_bytes_in_buffer;
|
||||
p_size -= p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_byte_offset += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have read the exact size
|
||||
l_read_nb_bytes += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_byte_offset += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
return l_read_nb_bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes some bytes from the stream.
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_buffer pointer to the data buffer holds the data to be writtent.
|
||||
* @param p_size number of bytes to write.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes writtent, or -1 if an error occured.
|
||||
*/
|
||||
OPJ_UINT32 opj_stream_write_data (opj_stream_private_t * p_stream,const OPJ_BYTE * p_buffer,OPJ_UINT32 p_size, opj_event_mgr_t * p_event_mgr)
|
||||
{
|
||||
OPJ_UINT32 l_remaining_bytes = 0;
|
||||
OPJ_UINT32 l_write_nb_bytes = 0;
|
||||
|
||||
if
|
||||
(p_stream->m_status & opj_stream_e_error)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
while
|
||||
(true)
|
||||
{
|
||||
l_remaining_bytes = p_stream->m_buffer_size - p_stream->m_bytes_in_buffer;
|
||||
// we have more memory than required
|
||||
if
|
||||
(l_remaining_bytes >= p_size)
|
||||
{
|
||||
memcpy(p_stream->m_current_data,p_buffer,p_size);
|
||||
p_stream->m_current_data += p_size;
|
||||
p_stream->m_bytes_in_buffer += p_size;
|
||||
l_write_nb_bytes += p_size;
|
||||
p_stream->m_byte_offset += p_size;
|
||||
return l_write_nb_bytes;
|
||||
}
|
||||
|
||||
// we copy data and then do an actual read on the stream
|
||||
if
|
||||
(l_remaining_bytes)
|
||||
{
|
||||
l_write_nb_bytes += l_remaining_bytes;
|
||||
memcpy(p_stream->m_current_data,p_buffer,l_remaining_bytes);
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
p_buffer += l_remaining_bytes;
|
||||
p_size -= l_remaining_bytes;
|
||||
p_stream->m_bytes_in_buffer += l_remaining_bytes;
|
||||
p_stream->m_byte_offset += l_remaining_bytes;
|
||||
}
|
||||
if
|
||||
(! opj_stream_flush(p_stream, p_event_mgr))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the stream buffer to the stream.
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes written, or -1 if an error occured.
|
||||
*/
|
||||
bool opj_stream_flush (opj_stream_private_t * p_stream, opj_event_mgr_t * p_event_mgr)
|
||||
{
|
||||
// the number of bytes written on the media.
|
||||
OPJ_UINT32 l_current_write_nb_bytes = 0;
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
|
||||
while
|
||||
(p_stream->m_bytes_in_buffer)
|
||||
{
|
||||
// we should do an actual write on the media
|
||||
l_current_write_nb_bytes = p_stream->m_write_fn(p_stream->m_current_data,p_stream->m_bytes_in_buffer,p_stream->m_user_data);
|
||||
if
|
||||
(l_current_write_nb_bytes == -1)
|
||||
{
|
||||
p_stream->m_status |= opj_stream_e_error;
|
||||
opj_event_msg(p_event_mgr, EVT_INFO, "Error on writting stream!\n");
|
||||
return false;
|
||||
}
|
||||
p_stream->m_current_data += l_current_write_nb_bytes;
|
||||
p_stream->m_bytes_in_buffer -= l_current_write_nb_bytes;
|
||||
}
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
* @param p_stream the stream to skip data from.
|
||||
* @param p_size the number of bytes to skip.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
OPJ_SIZE_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr)
|
||||
{
|
||||
OPJ_SIZE_T l_skip_nb_bytes = 0;
|
||||
OPJ_SIZE_T l_current_skip_nb_bytes = 0;
|
||||
|
||||
if
|
||||
(p_stream->m_bytes_in_buffer >= p_size)
|
||||
{
|
||||
p_stream->m_current_data += p_size;
|
||||
p_stream->m_bytes_in_buffer -= p_size;
|
||||
l_skip_nb_bytes += p_size;
|
||||
p_stream->m_byte_offset += l_skip_nb_bytes;
|
||||
return l_skip_nb_bytes;
|
||||
}
|
||||
|
||||
// we are now in the case when the remaining data if not sufficient
|
||||
if
|
||||
(p_stream->m_status & opj_stream_e_end)
|
||||
{
|
||||
l_skip_nb_bytes += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_current_data += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
p_stream->m_byte_offset += l_skip_nb_bytes;
|
||||
return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_SIZE_T) -1;
|
||||
}
|
||||
|
||||
// the flag is not set, we copy data and then do an actual skip on the stream
|
||||
if
|
||||
(p_stream->m_bytes_in_buffer)
|
||||
{
|
||||
l_skip_nb_bytes += p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
p_size -= p_stream->m_bytes_in_buffer;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
}
|
||||
|
||||
while
|
||||
(p_size > 0)
|
||||
{
|
||||
// we should do an actual skip on the media
|
||||
l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data);
|
||||
if
|
||||
(l_current_skip_nb_bytes == (OPJ_SIZE_T) -1)
|
||||
{
|
||||
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
|
||||
p_stream->m_status |= opj_stream_e_end;
|
||||
p_stream->m_byte_offset += l_skip_nb_bytes;
|
||||
// end if stream
|
||||
return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_SIZE_T) -1;
|
||||
}
|
||||
p_size -= l_current_skip_nb_bytes;
|
||||
l_skip_nb_bytes += l_current_skip_nb_bytes;
|
||||
}
|
||||
p_stream->m_byte_offset += l_skip_nb_bytes;
|
||||
return l_skip_nb_bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
* @param p_stream the stream to skip data from.
|
||||
* @param p_size the number of bytes to skip.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
OPJ_SIZE_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr)
|
||||
{
|
||||
bool l_is_written = 0;
|
||||
OPJ_SIZE_T l_current_skip_nb_bytes = 0;
|
||||
OPJ_SIZE_T l_skip_nb_bytes = 0;
|
||||
|
||||
if
|
||||
(p_stream->m_status & opj_stream_e_error)
|
||||
{
|
||||
return (OPJ_SIZE_T) -1;
|
||||
}
|
||||
|
||||
// we should flush data
|
||||
l_is_written = opj_stream_flush (p_stream, p_event_mgr);
|
||||
if
|
||||
(! l_is_written)
|
||||
{
|
||||
p_stream->m_status |= opj_stream_e_error;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
p_stream->m_current_data = p_stream->m_current_data;
|
||||
return (OPJ_SIZE_T) -1;
|
||||
}
|
||||
// then skip
|
||||
|
||||
while
|
||||
(p_size > 0)
|
||||
{
|
||||
// we should do an actual skip on the media
|
||||
l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data);
|
||||
if
|
||||
(l_current_skip_nb_bytes == (OPJ_SIZE_T)-1)
|
||||
{
|
||||
opj_event_msg(p_event_mgr, EVT_INFO, "Stream error!\n");
|
||||
p_stream->m_status |= opj_stream_e_error;
|
||||
p_stream->m_byte_offset += l_skip_nb_bytes;
|
||||
// end if stream
|
||||
return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_SIZE_T)-1;
|
||||
}
|
||||
p_size -= l_current_skip_nb_bytes;
|
||||
l_skip_nb_bytes += l_current_skip_nb_bytes;
|
||||
}
|
||||
p_stream->m_byte_offset += l_skip_nb_bytes;
|
||||
return l_skip_nb_bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the byte offset on the stream (similar to ftell).
|
||||
*
|
||||
* @param p_stream the stream to get the information from.
|
||||
*
|
||||
* @return the current position o fthe stream.
|
||||
*/
|
||||
OPJ_SIZE_T opj_stream_tell (const opj_stream_private_t * p_stream)
|
||||
{
|
||||
return p_stream->m_byte_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
* @param p_stream the stream to skip data from.
|
||||
* @param p_size the number of bytes to skip.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
OPJ_SIZE_T opj_stream_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr)
|
||||
{
|
||||
return p_stream->m_opj_skip(p_stream,p_size,p_event_mgr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
* @param p_stream the stream to skip data from.
|
||||
* @param p_size the number of bytes to skip.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
bool opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr)
|
||||
{
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
if
|
||||
(! p_stream->m_seek_fn(p_size,p_stream->m_user_data))
|
||||
{
|
||||
p_stream->m_status |= opj_stream_e_end;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// reset stream status
|
||||
p_stream->m_status &= (~opj_stream_e_end);
|
||||
p_stream->m_byte_offset = p_size;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
* @param p_stream the stream to skip data from.
|
||||
* @param p_size the number of bytes to skip.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
bool opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr)
|
||||
{
|
||||
if
|
||||
(! opj_stream_flush(p_stream,p_event_mgr))
|
||||
{
|
||||
p_stream->m_status |= opj_stream_e_error;
|
||||
return false;
|
||||
}
|
||||
|
||||
p_stream->m_current_data = p_stream->m_stored_data;
|
||||
p_stream->m_bytes_in_buffer = 0;
|
||||
|
||||
if
|
||||
(! p_stream->m_seek_fn(p_size,p_stream->m_user_data))
|
||||
{
|
||||
p_stream->m_status |= opj_stream_e_error;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_stream->m_byte_offset = p_size;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Seeks a number of bytes from the stream.
|
||||
* @param p_stream the stream to skip data from.
|
||||
* @param p_size the number of bytes to skip.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return true if the stream is seekable.
|
||||
*/
|
||||
bool opj_stream_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr)
|
||||
{
|
||||
return p_stream->m_opj_seek(p_stream,p_size,p_event_mgr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if the given stream is seekable.
|
||||
*/
|
||||
bool opj_stream_has_seek (const opj_stream_private_t * p_stream)
|
||||
{
|
||||
return p_stream->m_seek_fn != opj_stream_default_seek;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
OPJ_UINT32 opj_stream_default_read (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data)
|
||||
{
|
||||
return (OPJ_UINT32) -1;
|
||||
}
|
||||
OPJ_UINT32 opj_stream_default_write (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data)
|
||||
{
|
||||
return (OPJ_UINT32) -1;
|
||||
}
|
||||
OPJ_SIZE_T opj_stream_default_skip (OPJ_SIZE_T p_nb_bytes, void * p_user_data)
|
||||
{
|
||||
return (OPJ_SIZE_T) -1;
|
||||
}
|
||||
|
||||
bool opj_stream_default_seek (OPJ_SIZE_T p_nb_bytes, void * p_user_data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France
|
||||
* Copyright (c) 2012, CS Systemes d'Information, France
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,11 +42,15 @@ The functions in CIO.C have for goal to realize a byte input / output process.
|
||||
/** @defgroup CIO CIO - byte input-output stream */
|
||||
/*@{*/
|
||||
|
||||
#include "opj_config.h"
|
||||
|
||||
#include "openjpeg.h"
|
||||
#include "opj_configure.h"
|
||||
struct opj_event_mgr;
|
||||
/** @name Exported functions (see also openjpeg.h) */
|
||||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#if defined(OPJ_BIG_ENDIAN)
|
||||
#if !defined(OPJ_LITTLE_ENDIAN)
|
||||
#define opj_write_bytes opj_write_bytes_BE
|
||||
#define opj_read_bytes opj_read_bytes_BE
|
||||
#define opj_write_double opj_write_double_BE
|
||||
@@ -55,19 +58,25 @@ The functions in CIO.C have for goal to realize a byte input / output process.
|
||||
#define opj_write_float opj_write_float_BE
|
||||
#define opj_read_float opj_read_float_BE
|
||||
#else
|
||||
#error "Either BIG_ENDIAN or LITTLE_ENDIAN must be #defined, but not both."
|
||||
#endif
|
||||
#else
|
||||
#if defined(OPJ_LITTLE_ENDIAN)
|
||||
#define opj_write_bytes opj_write_bytes_LE
|
||||
#define opj_read_bytes opj_read_bytes_LE
|
||||
#define opj_write_double opj_write_double_LE
|
||||
#define opj_read_double opj_read_double_LE
|
||||
#define opj_write_float opj_write_float_LE
|
||||
#define opj_read_float opj_read_float_LE
|
||||
#else
|
||||
#error "Either BIG_ENDIAN or LITTLE_ENDIAN must be #defined, but not none."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
opj_signed_sentinel = -1, /* do not use in code */
|
||||
opj_stream_e_output = 0x1,
|
||||
opj_stream_e_input = 0x2,
|
||||
opj_stream_e_end = 0x4,
|
||||
@@ -85,11 +94,6 @@ typedef struct opj_stream_private
|
||||
*/
|
||||
void * m_user_data;
|
||||
|
||||
/**
|
||||
* User data length
|
||||
*/
|
||||
OPJ_UINT64 m_user_data_length;
|
||||
|
||||
/**
|
||||
* Pointer to actual read function (NULL at the initialization of the cio.
|
||||
*/
|
||||
@@ -111,6 +115,9 @@ typedef struct opj_stream_private
|
||||
*/
|
||||
opj_stream_seek_fn m_seek_fn;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Actual data stored into the stream if readed from. Data is read by chunk of fixed size.
|
||||
* you should never access this data directly.
|
||||
@@ -122,42 +129,34 @@ typedef struct opj_stream_private
|
||||
*/
|
||||
OPJ_BYTE * m_current_data;
|
||||
|
||||
/**
|
||||
* FIXME DOC.
|
||||
*/
|
||||
OPJ_OFF_T (* m_opj_skip)(struct opj_stream_private * ,OPJ_OFF_T , struct opj_event_mgr *);
|
||||
OPJ_SIZE_T (* m_opj_skip)(struct opj_stream_private * ,OPJ_SIZE_T , struct opj_event_mgr *);
|
||||
|
||||
/**
|
||||
* FIXME DOC.
|
||||
*/
|
||||
OPJ_BOOL (* m_opj_seek) (struct opj_stream_private * , OPJ_OFF_T , struct opj_event_mgr *);
|
||||
bool (* m_opj_seek) (struct opj_stream_private * , OPJ_SIZE_T , struct opj_event_mgr *);
|
||||
|
||||
/**
|
||||
* number of bytes containing in the buffer.
|
||||
*/
|
||||
OPJ_SIZE_T m_bytes_in_buffer;
|
||||
OPJ_UINT32 m_bytes_in_buffer;
|
||||
|
||||
/**
|
||||
* The number of bytes read/written from the beginning of the stream
|
||||
* The number of bytes read/written.
|
||||
*/
|
||||
OPJ_OFF_T m_byte_offset;
|
||||
OPJ_SIZE_T m_byte_offset;
|
||||
|
||||
/**
|
||||
* The size of the buffer.
|
||||
*/
|
||||
OPJ_SIZE_T m_buffer_size;
|
||||
OPJ_UINT32 m_buffer_size;
|
||||
|
||||
/**
|
||||
* Flags to tell the status of the stream.
|
||||
*/
|
||||
opj_stream_flag m_status;
|
||||
OPJ_UINT32 m_status;
|
||||
|
||||
}
|
||||
opj_stream_private_t;
|
||||
|
||||
/** @name Exported functions (see also openjpeg.h) */
|
||||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Write some bytes to the given data buffer, this function is used in Big Endian cpus.
|
||||
* @param p_buffer pointer the data buffer to write data to.
|
||||
@@ -258,7 +257,7 @@ void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value);
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes read, or -1 if an error occured or if the stream is at the end.
|
||||
*/
|
||||
OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
OPJ_UINT32 opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_UINT32 p_size, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Writes some bytes to the stream.
|
||||
@@ -268,7 +267,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes writtent, or -1 if an error occured.
|
||||
*/
|
||||
OPJ_SIZE_T opj_stream_write_data (opj_stream_private_t * p_stream,const OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
OPJ_UINT32 opj_stream_write_data (opj_stream_private_t * p_stream,const OPJ_BYTE * p_buffer, OPJ_UINT32 p_size, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Writes the content of the stream buffer to the stream.
|
||||
@@ -276,7 +275,7 @@ OPJ_SIZE_T opj_stream_write_data (opj_stream_private_t * p_stream,const OPJ_BYTE
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return true if the data could be flushed, false else.
|
||||
*/
|
||||
OPJ_BOOL opj_stream_flush (opj_stream_private_t * p_stream, struct opj_event_mgr * p_event_mgr);
|
||||
bool opj_stream_flush (opj_stream_private_t * p_stream, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
@@ -285,7 +284,7 @@ OPJ_BOOL opj_stream_flush (opj_stream_private_t * p_stream, struct opj_event_mgr
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
OPJ_OFF_T opj_stream_skip (opj_stream_private_t * p_stream,OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
OPJ_SIZE_T opj_stream_skip (opj_stream_private_t * p_stream,OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Tells the byte offset on the stream (similar to ftell).
|
||||
@@ -294,17 +293,7 @@ OPJ_OFF_T opj_stream_skip (opj_stream_private_t * p_stream,OPJ_OFF_T p_size, str
|
||||
*
|
||||
* @return the current position o fthe stream.
|
||||
*/
|
||||
OPJ_OFF_T opj_stream_tell (const opj_stream_private_t * p_stream);
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of bytes left before the end of the stream (similar to cio_numbytesleft).
|
||||
*
|
||||
* @param p_stream the stream to get the information from.
|
||||
*
|
||||
* @return Number of bytes left before the end of the stream.
|
||||
*/
|
||||
OPJ_OFF_T opj_stream_get_number_byte_left (const opj_stream_private_t * p_stream);
|
||||
OPJ_SIZE_T opj_stream_tell (const opj_stream_private_t * p_stream);
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
@@ -313,7 +302,7 @@ OPJ_OFF_T opj_stream_get_number_byte_left (const opj_stream_private_t * p_stream
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
OPJ_SIZE_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
@@ -322,16 +311,7 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
* @param p_stream the stream to skip data from.
|
||||
* @param p_size the number of bytes to skip.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return OPJ_TRUE if success, or OPJ_FALSE if an error occured.
|
||||
*/
|
||||
OPJ_BOOL opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
OPJ_SIZE_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
@@ -340,7 +320,16 @@ OPJ_BOOL opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
OPJ_BOOL opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
bool opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Skips a number of bytes from the stream.
|
||||
* @param p_stream the stream to skip data from.
|
||||
* @param p_size the number of bytes to skip.
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return the number of bytes skipped, or -1 if an error occured.
|
||||
*/
|
||||
bool opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Seeks a number of bytes from the stream.
|
||||
@@ -349,38 +338,22 @@ OPJ_BOOL opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
|
||||
* @param p_event_mgr the user event manager to be notified of special events.
|
||||
* @return true if the stream is seekable.
|
||||
*/
|
||||
OPJ_BOOL opj_stream_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
bool opj_stream_seek (opj_stream_private_t * p_stream, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr);
|
||||
|
||||
/**
|
||||
* Tells if the given stream is seekable.
|
||||
*/
|
||||
OPJ_BOOL opj_stream_has_seek (const opj_stream_private_t * p_stream);
|
||||
bool opj_stream_has_seek (const opj_stream_private_t * p_stream);
|
||||
|
||||
/**
|
||||
* FIXME DOC.
|
||||
*/
|
||||
OPJ_SIZE_T opj_stream_default_read (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data);
|
||||
|
||||
/**
|
||||
* FIXME DOC.
|
||||
*/
|
||||
OPJ_SIZE_T opj_stream_default_write (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data);
|
||||
|
||||
/**
|
||||
* FIXME DOC.
|
||||
*/
|
||||
OPJ_OFF_T opj_stream_default_skip (OPJ_OFF_T p_nb_bytes, void * p_user_data);
|
||||
|
||||
/**
|
||||
* FIXME DOC.
|
||||
*/
|
||||
OPJ_BOOL opj_stream_default_seek (OPJ_OFF_T p_nb_bytes, void * p_user_data);
|
||||
OPJ_UINT32 opj_stream_default_read (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data);
|
||||
OPJ_UINT32 opj_stream_default_write (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data);
|
||||
OPJ_SIZE_T opj_stream_default_skip (OPJ_SIZE_T p_nb_bytes, void * p_user_data);
|
||||
bool opj_stream_default_seek (OPJ_SIZE_T p_nb_bytes, void * p_user_data);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
||||
#endif /* __CIO_H */
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2007, Jonathan Ballard <dzonatas@dzonux.net>
|
||||
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,7 +36,12 @@
|
||||
#include <xmmintrin.h>
|
||||
#endif
|
||||
|
||||
#include "opj_includes.h"
|
||||
#include "dwt.h"
|
||||
#include "j2k.h"
|
||||
#include "tcd.h"
|
||||
#include "fix.h"
|
||||
#include "opj_malloc.h"
|
||||
#include "int.h"
|
||||
|
||||
/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */
|
||||
/*@{*/
|
||||
@@ -47,31 +53,31 @@
|
||||
/*@{*/
|
||||
|
||||
typedef struct dwt_local {
|
||||
int* mem;
|
||||
int dn;
|
||||
int sn;
|
||||
int cas;
|
||||
OPJ_INT32* mem;
|
||||
OPJ_INT32 dn;
|
||||
OPJ_INT32 sn;
|
||||
OPJ_INT32 cas;
|
||||
} dwt_t;
|
||||
|
||||
typedef union {
|
||||
float f[4];
|
||||
OPJ_FLOAT32 f[4];
|
||||
} v4;
|
||||
|
||||
typedef struct v4dwt_local {
|
||||
v4* wavelet ;
|
||||
int dn ;
|
||||
int sn ;
|
||||
int cas ;
|
||||
OPJ_INT32 dn ;
|
||||
OPJ_INT32 sn ;
|
||||
OPJ_INT32 cas ;
|
||||
} v4dwt_t ;
|
||||
|
||||
static const float dwt_alpha = 1.586134342f; /* 12994 */
|
||||
static const float dwt_beta = 0.052980118f; /* 434 */
|
||||
static const float dwt_gamma = -0.882911075f; /* -7233 */
|
||||
static const float dwt_delta = -0.443506852f; /* -3633 */
|
||||
static const OPJ_FLOAT32 dwt_alpha = 1.586134342f; // 12994
|
||||
static const OPJ_FLOAT32 dwt_beta = 0.052980118f; // 434
|
||||
static const OPJ_FLOAT32 dwt_gamma = -0.882911075f; // -7233
|
||||
static const OPJ_FLOAT32 delta = -0.443506852f; // -3633
|
||||
|
||||
static const float K = 1.230174105f; /* 10078 */
|
||||
static const OPJ_FLOAT32 K = 1.230174105f; // 10078
|
||||
/* FIXME: What is this constant? */
|
||||
static const float c13318 = 1.625732422f;
|
||||
static const OPJ_FLOAT32 c13318 = 1.625732422f;
|
||||
|
||||
/*@}*/
|
||||
|
||||
@@ -86,23 +92,23 @@ typedef void (*DWT1DFN)(dwt_t* v);
|
||||
/**
|
||||
Forward lazy transform (horizontal)
|
||||
*/
|
||||
static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas);
|
||||
static void dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas);
|
||||
/**
|
||||
Forward lazy transform (vertical)
|
||||
*/
|
||||
static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas);
|
||||
static void dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas);
|
||||
/**
|
||||
Inverse lazy transform (horizontal)
|
||||
*/
|
||||
static void dwt_interleave_h(dwt_t* h, int *a);
|
||||
static void dwt_interleave_h(dwt_t* h, OPJ_INT32 *a);
|
||||
/**
|
||||
Inverse lazy transform (vertical)
|
||||
*/
|
||||
static void dwt_interleave_v(dwt_t* v, int *a, int x);
|
||||
static void dwt_interleave_v(dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x);
|
||||
/**
|
||||
Forward 5-3 wavelet transform in 1-D
|
||||
*/
|
||||
static void dwt_encode_1(int *a, int dn, int sn, int cas);
|
||||
static void dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas);
|
||||
/**
|
||||
Inverse 5-3 wavelet transform in 1-D
|
||||
*/
|
||||
@@ -110,16 +116,19 @@ static void dwt_decode_1(dwt_t *v);
|
||||
/**
|
||||
Forward 9-7 wavelet transform in 1-D
|
||||
*/
|
||||
static void dwt_encode_1_real(int *a, int dn, int sn, int cas);
|
||||
static void dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas);
|
||||
/**
|
||||
Explicit calculation of the Quantization Stepsizes
|
||||
*/
|
||||
static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize);
|
||||
static void dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize);
|
||||
/**
|
||||
Inverse wavelet transform in 2-D.
|
||||
*/
|
||||
static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int i, DWT1DFN fn);
|
||||
static bool dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 i, DWT1DFN fn);
|
||||
|
||||
static OPJ_UINT32 dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i);
|
||||
|
||||
static bool dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) );
|
||||
/*@}*/
|
||||
|
||||
/*@}*/
|
||||
@@ -135,7 +144,7 @@ static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int i, DWT1DFN fn);
|
||||
/* <summary> */
|
||||
/* This table contains the norms of the 5-3 wavelets for different bands. */
|
||||
/* </summary> */
|
||||
static const double dwt_norms[4][10] = {
|
||||
static const OPJ_FLOAT64 dwt_norms[4][10] = {
|
||||
{1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3},
|
||||
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
|
||||
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
|
||||
@@ -145,7 +154,7 @@ static const double dwt_norms[4][10] = {
|
||||
/* <summary> */
|
||||
/* This table contains the norms of the 9-7 wavelets for different bands. */
|
||||
/* </summary> */
|
||||
static const double dwt_norms_real[4][10] = {
|
||||
static const OPJ_FLOAT64 dwt_norms_real[4][10] = {
|
||||
{1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9},
|
||||
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
||||
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
||||
@@ -161,36 +170,76 @@ static const double dwt_norms_real[4][10] = {
|
||||
/* <summary> */
|
||||
/* Forward lazy transform (horizontal). */
|
||||
/* </summary> */
|
||||
static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas) {
|
||||
int i;
|
||||
for (i=0; i<sn; i++) b[i]=a[2*i+cas];
|
||||
for (i=0; i<dn; i++) b[sn+i]=a[(2*i+1-cas)];
|
||||
static void dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
|
||||
OPJ_INT32 i;
|
||||
|
||||
OPJ_INT32 * l_dest = b;
|
||||
OPJ_INT32 * l_src = a+cas;
|
||||
for
|
||||
(i=0; i<sn; ++i)
|
||||
{
|
||||
*l_dest++ = *l_src;
|
||||
l_src += 2;
|
||||
}
|
||||
l_dest = b + sn;
|
||||
l_src = a + 1 - cas;
|
||||
for
|
||||
(i=0; i<dn; ++i)
|
||||
{
|
||||
*l_dest++=*l_src;
|
||||
l_src += 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
/* Forward lazy transform (vertical). */
|
||||
/* </summary> */
|
||||
static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
|
||||
int i;
|
||||
for (i=0; i<sn; i++) b[i*x]=a[2*i+cas];
|
||||
for (i=0; i<dn; i++) b[(sn+i)*x]=a[(2*i+1-cas)];
|
||||
static void dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas) {
|
||||
OPJ_INT32 i = sn;
|
||||
OPJ_INT32 * l_dest = b;
|
||||
OPJ_INT32 * l_src = a+cas;
|
||||
|
||||
while
|
||||
(i--)
|
||||
{
|
||||
*l_dest = *l_src;
|
||||
l_dest += x;
|
||||
l_src += 2;
|
||||
/* b[i*x]=a[2*i+cas]; */
|
||||
}
|
||||
l_dest = b + sn * x;
|
||||
l_src = a + 1 - cas;
|
||||
|
||||
i = dn;
|
||||
while
|
||||
(i--)
|
||||
{
|
||||
*l_dest = *l_src;
|
||||
l_dest += x;
|
||||
l_src += 2;
|
||||
/*b[(sn+i)*x]=a[(2*i+1-cas)];*/
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
/* Inverse lazy transform (horizontal). */
|
||||
/* </summary> */
|
||||
static void dwt_interleave_h(dwt_t* h, int *a) {
|
||||
int *ai = a;
|
||||
int *bi = h->mem + h->cas;
|
||||
int i = h->sn;
|
||||
while( i-- ) {
|
||||
static void dwt_interleave_h(dwt_t* h, OPJ_INT32 *a) {
|
||||
OPJ_INT32 *ai = a;
|
||||
OPJ_INT32 *bi = h->mem + h->cas;
|
||||
OPJ_INT32 i = h->sn;
|
||||
while
|
||||
( i-- )
|
||||
{
|
||||
*bi = *(ai++);
|
||||
bi += 2;
|
||||
}
|
||||
ai = a + h->sn;
|
||||
bi = h->mem + 1 - h->cas;
|
||||
i = h->dn ;
|
||||
while( i-- ) {
|
||||
while
|
||||
( i-- )
|
||||
{
|
||||
*bi = *(ai++);
|
||||
bi += 2;
|
||||
}
|
||||
@@ -199,10 +248,10 @@ static void dwt_interleave_h(dwt_t* h, int *a) {
|
||||
/* <summary> */
|
||||
/* Inverse lazy transform (vertical). */
|
||||
/* </summary> */
|
||||
static void dwt_interleave_v(dwt_t* v, int *a, int x) {
|
||||
int *ai = a;
|
||||
int *bi = v->mem + v->cas;
|
||||
int i = v->sn;
|
||||
static void dwt_interleave_v(dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) {
|
||||
OPJ_INT32 *ai = a;
|
||||
OPJ_INT32 *bi = v->mem + v->cas;
|
||||
OPJ_INT32 i = v->sn;
|
||||
while( i-- ) {
|
||||
*bi = *ai;
|
||||
bi += 2;
|
||||
@@ -222,8 +271,8 @@ static void dwt_interleave_v(dwt_t* v, int *a, int x) {
|
||||
/* <summary> */
|
||||
/* Forward 5-3 wavelet transform in 1-D. */
|
||||
/* </summary> */
|
||||
static void dwt_encode_1(int *a, int dn, int sn, int cas) {
|
||||
int i;
|
||||
static void dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
|
||||
OPJ_INT32 i;
|
||||
|
||||
if (!cas) {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
@@ -243,8 +292,8 @@ static void dwt_encode_1(int *a, int dn, int sn, int cas) {
|
||||
/* <summary> */
|
||||
/* Inverse 5-3 wavelet transform in 1-D. */
|
||||
/* </summary> */
|
||||
static void dwt_decode_1_(int *a, int dn, int sn, int cas) {
|
||||
int i;
|
||||
static void dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
|
||||
OPJ_INT32 i;
|
||||
|
||||
if (!cas) {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
@@ -271,8 +320,8 @@ static void dwt_decode_1(dwt_t *v) {
|
||||
/* <summary> */
|
||||
/* Forward 9-7 wavelet transform in 1-D. */
|
||||
/* </summary> */
|
||||
static void dwt_encode_1_real(int *a, int dn, int sn, int cas) {
|
||||
int i;
|
||||
static void dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
|
||||
OPJ_INT32 i;
|
||||
if (!cas) {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < dn; i++)
|
||||
@@ -306,8 +355,8 @@ static void dwt_encode_1_real(int *a, int dn, int sn, int cas) {
|
||||
}
|
||||
}
|
||||
|
||||
static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize) {
|
||||
int p, n;
|
||||
static void dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize) {
|
||||
OPJ_INT32 p, n;
|
||||
p = int_floorlog2(stepsize) - 13;
|
||||
n = 11 - int_floorlog2(stepsize);
|
||||
bandno_stepsize->mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff;
|
||||
@@ -323,71 +372,105 @@ static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno
|
||||
/* <summary> */
|
||||
/* Forward 5-3 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
void dwt_encode(opj_tcd_tilecomp_t * tilec) {
|
||||
int i, j, k;
|
||||
int *a = NULL;
|
||||
int *aj = NULL;
|
||||
int *bj = NULL;
|
||||
int w, l;
|
||||
INLINE bool dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) )
|
||||
{
|
||||
OPJ_INT32 i, j, k;
|
||||
OPJ_INT32 *a = 00;
|
||||
OPJ_INT32 *aj = 00;
|
||||
OPJ_INT32 *bj = 00;
|
||||
OPJ_INT32 w, l;
|
||||
|
||||
OPJ_INT32 rw; /* width of the resolution level computed */
|
||||
OPJ_INT32 rh; /* height of the resolution level computed */
|
||||
OPJ_INT32 l_data_size;
|
||||
|
||||
opj_tcd_resolution_t * l_cur_res = 0;
|
||||
opj_tcd_resolution_t * l_last_res = 0;
|
||||
|
||||
w = tilec->x1-tilec->x0;
|
||||
l = tilec->numresolutions-1;
|
||||
a = tilec->data;
|
||||
|
||||
for (i = 0; i < l; i++) {
|
||||
int rw; /* width of the resolution level computed */
|
||||
int rh; /* height of the resolution level computed */
|
||||
int rw1; /* width of the resolution level once lower than computed one */
|
||||
int rh1; /* height of the resolution level once lower than computed one */
|
||||
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
int dn, sn;
|
||||
l_cur_res = tilec->resolutions + l;
|
||||
l_last_res = l_cur_res - 1;
|
||||
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||
rw = l_cur_res->x1 - l_cur_res->x0;
|
||||
rh = l_cur_res->y1 - l_cur_res->y0;
|
||||
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
l_data_size = dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * sizeof(OPJ_INT32);
|
||||
bj = (OPJ_INT32*)opj_malloc(l_data_size);
|
||||
if
|
||||
(! bj)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
i = l;
|
||||
|
||||
while
|
||||
(i--)
|
||||
{
|
||||
OPJ_INT32 rw1; /* width of the resolution level once lower than computed one */
|
||||
OPJ_INT32 rh1; /* height of the resolution level once lower than computed one */
|
||||
OPJ_INT32 cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
OPJ_INT32 cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
OPJ_INT32 dn, sn;
|
||||
|
||||
rw = l_cur_res->x1 - l_cur_res->x0;
|
||||
rh = l_cur_res->y1 - l_cur_res->y0;
|
||||
rw1 = l_last_res->x1 - l_last_res->x0;
|
||||
rh1 = l_last_res->y1 - l_last_res->y0;
|
||||
|
||||
cas_row = l_cur_res->x0 & 1;
|
||||
cas_col = l_cur_res->y0 & 1;
|
||||
|
||||
sn = rh1;
|
||||
dn = rh - rh1;
|
||||
bj = (int*)opj_malloc(rh * sizeof(int));
|
||||
for (j = 0; j < rw; j++) {
|
||||
for
|
||||
(j = 0; j < rw; ++j)
|
||||
{
|
||||
aj = a + j;
|
||||
for (k = 0; k < rh; k++) bj[k] = aj[k*w];
|
||||
dwt_encode_1(bj, dn, sn, cas_col);
|
||||
for
|
||||
(k = 0; k < rh; ++k)
|
||||
{
|
||||
bj[k] = aj[k*w];
|
||||
}
|
||||
(*p_function) (bj, dn, sn, cas_col);
|
||||
dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
|
||||
}
|
||||
opj_free(bj);
|
||||
|
||||
sn = rw1;
|
||||
dn = rw - rw1;
|
||||
bj = (int*)opj_malloc(rw * sizeof(int));
|
||||
for (j = 0; j < rh; j++) {
|
||||
for (j = 0; j < rh; j++)
|
||||
{
|
||||
aj = a + j * w;
|
||||
for (k = 0; k < rw; k++) bj[k] = aj[k];
|
||||
dwt_encode_1(bj, dn, sn, cas_row);
|
||||
(*p_function) (bj, dn, sn, cas_row);
|
||||
dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
|
||||
}
|
||||
l_cur_res = l_last_res;
|
||||
--l_last_res;
|
||||
}
|
||||
opj_free(bj);
|
||||
return true;
|
||||
}
|
||||
/* Forward 5-3 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
bool dwt_encode(opj_tcd_tilecomp_t * tilec)
|
||||
{
|
||||
return dwt_encode_procedure(tilec,dwt_encode_1);
|
||||
}
|
||||
|
||||
|
||||
/* <summary> */
|
||||
/* Inverse 5-3 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
void dwt_decode(opj_tcd_tilecomp_t* tilec, int numres) {
|
||||
dwt_decode_tile(tilec, numres, &dwt_decode_1);
|
||||
bool dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres) {
|
||||
return dwt_decode_tile(tilec, numres, &dwt_decode_1);
|
||||
}
|
||||
|
||||
|
||||
/* <summary> */
|
||||
/* Get gain of 5-3 wavelet transform. */
|
||||
/* </summary> */
|
||||
int dwt_getgain(int orient) {
|
||||
OPJ_UINT32 dwt_getgain(OPJ_UINT32 orient) {
|
||||
if (orient == 0)
|
||||
return 0;
|
||||
if (orient == 1 || orient == 2)
|
||||
@@ -398,71 +481,24 @@ int dwt_getgain(int orient) {
|
||||
/* <summary> */
|
||||
/* Get norm of 5-3 wavelet. */
|
||||
/* </summary> */
|
||||
double dwt_getnorm(int level, int orient) {
|
||||
OPJ_FLOAT64 dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient) {
|
||||
return dwt_norms[orient][level];
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
/* Forward 9-7 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
|
||||
void dwt_encode_real(opj_tcd_tilecomp_t * tilec) {
|
||||
int i, j, k;
|
||||
int *a = NULL;
|
||||
int *aj = NULL;
|
||||
int *bj = NULL;
|
||||
int w, l;
|
||||
|
||||
w = tilec->x1-tilec->x0;
|
||||
l = tilec->numresolutions-1;
|
||||
a = tilec->data;
|
||||
|
||||
for (i = 0; i < l; i++) {
|
||||
int rw; /* width of the resolution level computed */
|
||||
int rh; /* height of the resolution level computed */
|
||||
int rw1; /* width of the resolution level once lower than computed one */
|
||||
int rh1; /* height of the resolution level once lower than computed one */
|
||||
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
int dn, sn;
|
||||
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
|
||||
sn = rh1;
|
||||
dn = rh - rh1;
|
||||
bj = (int*)opj_malloc(rh * sizeof(int));
|
||||
for (j = 0; j < rw; j++) {
|
||||
aj = a + j;
|
||||
for (k = 0; k < rh; k++) bj[k] = aj[k*w];
|
||||
dwt_encode_1_real(bj, dn, sn, cas_col);
|
||||
dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
|
||||
bool dwt_encode_real(opj_tcd_tilecomp_t * tilec)
|
||||
{
|
||||
return dwt_encode_procedure(tilec,dwt_encode_1_real);
|
||||
}
|
||||
opj_free(bj);
|
||||
|
||||
sn = rw1;
|
||||
dn = rw - rw1;
|
||||
bj = (int*)opj_malloc(rw * sizeof(int));
|
||||
for (j = 0; j < rh; j++) {
|
||||
aj = a + j * w;
|
||||
for (k = 0; k < rw; k++) bj[k] = aj[k];
|
||||
dwt_encode_1_real(bj, dn, sn, cas_row);
|
||||
dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
|
||||
}
|
||||
opj_free(bj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* <summary> */
|
||||
/* Get gain of 9-7 wavelet transform. */
|
||||
/* </summary> */
|
||||
int dwt_getgain_real(int orient) {
|
||||
OPJ_UINT32 dwt_getgain_real(OPJ_UINT32 orient) {
|
||||
(void)orient;
|
||||
return 0;
|
||||
}
|
||||
@@ -470,16 +506,16 @@ int dwt_getgain_real(int orient) {
|
||||
/* <summary> */
|
||||
/* Get norm of 9-7 wavelet. */
|
||||
/* </summary> */
|
||||
double dwt_getnorm_real(int level, int orient) {
|
||||
OPJ_FLOAT64 dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient) {
|
||||
return dwt_norms_real[orient][level];
|
||||
}
|
||||
|
||||
void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec) {
|
||||
int numbands, bandno;
|
||||
void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) {
|
||||
OPJ_UINT32 numbands, bandno;
|
||||
numbands = 3 * tccp->numresolutions - 2;
|
||||
for (bandno = 0; bandno < numbands; bandno++) {
|
||||
double stepsize;
|
||||
int resno, level, orient, gain;
|
||||
OPJ_FLOAT64 stepsize;
|
||||
OPJ_UINT32 resno, level, orient, gain;
|
||||
|
||||
resno = (bandno == 0) ? 0 : ((bandno - 1) / 3 + 1);
|
||||
orient = (bandno == 0) ? 0 : ((bandno - 1) % 3 + 1);
|
||||
@@ -488,10 +524,10 @@ void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec) {
|
||||
if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
|
||||
stepsize = 1.0;
|
||||
} else {
|
||||
double norm = dwt_norms_real[orient][level];
|
||||
OPJ_FLOAT64 norm = dwt_norms_real[orient][level];
|
||||
stepsize = (1 << (gain)) / norm;
|
||||
}
|
||||
dwt_encode_stepsize((int) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]);
|
||||
dwt_encode_stepsize((OPJ_INT32) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -499,11 +535,11 @@ void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec) {
|
||||
/* <summary> */
|
||||
/* Determine maximum computed resolution level for inverse wavelet transform */
|
||||
/* </summary> */
|
||||
static int dwt_decode_max_resolution(opj_tcd_resolution_t* restrict r, int i) {
|
||||
int mr = 1;
|
||||
int w;
|
||||
static OPJ_UINT32 dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i) {
|
||||
OPJ_UINT32 mr = 0;
|
||||
OPJ_UINT32 w;
|
||||
while( --i ) {
|
||||
r++;
|
||||
++r;
|
||||
if( mr < ( w = r->x1 - r->x0 ) )
|
||||
mr = w ;
|
||||
if( mr < ( w = r->y1 - r->y0 ) )
|
||||
@@ -516,23 +552,30 @@ static int dwt_decode_max_resolution(opj_tcd_resolution_t* restrict r, int i) {
|
||||
/* <summary> */
|
||||
/* Inverse wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres, DWT1DFN dwt_1D) {
|
||||
static bool dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D) {
|
||||
dwt_t h;
|
||||
dwt_t v;
|
||||
|
||||
opj_tcd_resolution_t* tr = tilec->resolutions;
|
||||
|
||||
int rw = tr->x1 - tr->x0; /* width of the resolution level computed */
|
||||
int rh = tr->y1 - tr->y0; /* height of the resolution level computed */
|
||||
OPJ_UINT32 rw = tr->x1 - tr->x0; /* width of the resolution level computed */
|
||||
OPJ_UINT32 rh = tr->y1 - tr->y0; /* height of the resolution level computed */
|
||||
|
||||
int w = tilec->x1 - tilec->x0;
|
||||
OPJ_UINT32 w = tilec->x1 - tilec->x0;
|
||||
|
||||
h.mem = (OPJ_INT32*)
|
||||
opj_aligned_malloc(dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
|
||||
if
|
||||
(! h.mem)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
h.mem = (int*)opj_aligned_malloc(dwt_decode_max_resolution(tr, numres) * sizeof(int));
|
||||
v.mem = h.mem;
|
||||
|
||||
while( --numres) {
|
||||
int * restrict tiledp = tilec->data;
|
||||
int j;
|
||||
OPJ_INT32 * restrict tiledp = tilec->data;
|
||||
OPJ_UINT32 j;
|
||||
|
||||
++tr;
|
||||
h.sn = rw;
|
||||
@@ -547,14 +590,14 @@ static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres, DWT1DFN dwt_1
|
||||
for(j = 0; j < rh; ++j) {
|
||||
dwt_interleave_h(&h, &tiledp[j*w]);
|
||||
(dwt_1D)(&h);
|
||||
memcpy(&tiledp[j*w], h.mem, rw * sizeof(int));
|
||||
memcpy(&tiledp[j*w], h.mem, rw * sizeof(OPJ_INT32));
|
||||
}
|
||||
|
||||
v.dn = rh - v.sn;
|
||||
v.cas = tr->y0 % 2;
|
||||
|
||||
for(j = 0; j < rw; ++j){
|
||||
int k;
|
||||
OPJ_UINT32 k;
|
||||
dwt_interleave_v(&v, &tiledp[j], w);
|
||||
(dwt_1D)(&v);
|
||||
for(k = 0; k < rh; ++k) {
|
||||
@@ -563,120 +606,92 @@ static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres, DWT1DFN dwt_1
|
||||
}
|
||||
}
|
||||
opj_aligned_free(h.mem);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x, int size){
|
||||
float* restrict bi = (float*) (w->wavelet + w->cas);
|
||||
int count = w->sn;
|
||||
int i, k;
|
||||
static void v4dwt_interleave_h(v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OPJ_INT32 x, OPJ_INT32 size){
|
||||
OPJ_FLOAT32* restrict bi = (OPJ_FLOAT32*) (w->wavelet + w->cas);
|
||||
OPJ_INT32 count = w->sn;
|
||||
OPJ_INT32 i, k;
|
||||
for(k = 0; k < 2; ++k){
|
||||
if (count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0) {
|
||||
/* Fast code path */
|
||||
for(i = 0; i < count; ++i){
|
||||
int j = i;
|
||||
OPJ_INT32 j = i;
|
||||
bi[i*8 ] = a[j];
|
||||
j += x;
|
||||
if(j >= size) continue;
|
||||
bi[i*8 + 1] = a[j];
|
||||
j += x;
|
||||
if(j >= size) continue;
|
||||
bi[i*8 + 2] = a[j];
|
||||
j += x;
|
||||
if(j >= size) continue;
|
||||
bi[i*8 + 3] = a[j];
|
||||
}
|
||||
} else {
|
||||
/* Slow code path */
|
||||
for(i = 0; i < count; ++i){
|
||||
int j = i;
|
||||
bi[i*8 ] = a[j];
|
||||
j += x;
|
||||
if(j > size) continue;
|
||||
bi[i*8 + 1] = a[j];
|
||||
j += x;
|
||||
if(j > size) continue;
|
||||
bi[i*8 + 2] = a[j];
|
||||
j += x;
|
||||
if(j > size) continue;
|
||||
bi[i*8 + 3] = a[j];
|
||||
}
|
||||
}
|
||||
bi = (float*) (w->wavelet + 1 - w->cas);
|
||||
bi = (OPJ_FLOAT32*) (w->wavelet + 1 - w->cas);
|
||||
a += w->sn;
|
||||
size -= w->sn;
|
||||
count = w->dn;
|
||||
}
|
||||
}
|
||||
|
||||
static void v4dwt_interleave_v(v4dwt_t* restrict v , float* restrict a , int x){
|
||||
static void v4dwt_interleave_v(v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x){
|
||||
v4* restrict bi = v->wavelet + v->cas;
|
||||
int i;
|
||||
OPJ_INT32 i;
|
||||
for(i = 0; i < v->sn; ++i){
|
||||
memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float));
|
||||
memcpy(&bi[i*2], &a[i*x], 4 * sizeof(OPJ_FLOAT32));
|
||||
}
|
||||
a += v->sn * x;
|
||||
bi = v->wavelet + 1 - v->cas;
|
||||
for(i = 0; i < v->dn; ++i){
|
||||
memcpy(&bi[i*2], &a[i*x], 4 * sizeof(float));
|
||||
memcpy(&bi[i*2], &a[i*x], 4 * sizeof(OPJ_FLOAT32));
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __SSE__
|
||||
|
||||
static void v4dwt_decode_step1_sse(v4* w, int count, const __m128 c){
|
||||
static void v4dwt_decode_step1_sse(v4* w, OPJ_INT32 count, const __m128 c){
|
||||
__m128* restrict vw = (__m128*) w;
|
||||
int i;
|
||||
/* 4x unrolled loop */
|
||||
for(i = 0; i < count >> 2; ++i){
|
||||
*vw = _mm_mul_ps(*vw, c);
|
||||
vw += 2;
|
||||
*vw = _mm_mul_ps(*vw, c);
|
||||
vw += 2;
|
||||
*vw = _mm_mul_ps(*vw, c);
|
||||
vw += 2;
|
||||
*vw = _mm_mul_ps(*vw, c);
|
||||
vw += 2;
|
||||
}
|
||||
count &= 3;
|
||||
OPJ_INT32 i;
|
||||
for(i = 0; i < count; ++i){
|
||||
*vw = _mm_mul_ps(*vw, c);
|
||||
vw += 2;
|
||||
__m128 tmp = vw[i*2];
|
||||
vw[i*2] = tmp * c;
|
||||
}
|
||||
}
|
||||
|
||||
static void v4dwt_decode_step2_sse(v4* l, v4* w, int k, int m, __m128 c){
|
||||
static void v4dwt_decode_step2_sse(v4* l, v4* w, OPJ_INT32 k, OPJ_INT32 m, __m128 c){
|
||||
__m128* restrict vl = (__m128*) l;
|
||||
__m128* restrict vw = (__m128*) w;
|
||||
int i;
|
||||
__m128 tmp1, tmp2, tmp3;
|
||||
tmp1 = vl[0];
|
||||
OPJ_INT32 i;
|
||||
for(i = 0; i < m; ++i){
|
||||
tmp2 = vw[-1];
|
||||
tmp3 = vw[ 0];
|
||||
vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c));
|
||||
tmp1 = tmp3;
|
||||
__m128 tmp1 = vl[ 0];
|
||||
__m128 tmp2 = vw[-1];
|
||||
__m128 tmp3 = vw[ 0];
|
||||
vw[-1] = tmp2 + ((tmp1 + tmp3) * c);
|
||||
vl = vw;
|
||||
vw += 2;
|
||||
}
|
||||
vl = vw - 2;
|
||||
if(m >= k){
|
||||
return;
|
||||
}
|
||||
c = _mm_add_ps(c, c);
|
||||
c = _mm_mul_ps(c, vl[0]);
|
||||
c += c;
|
||||
c *= vl[0];
|
||||
for(; m < k; ++m){
|
||||
__m128 tmp = vw[-1];
|
||||
vw[-1] = _mm_add_ps(tmp, c);
|
||||
vw[-1] = tmp + c;
|
||||
vw += 2;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void v4dwt_decode_step1(v4* w, int count, const float c){
|
||||
float* restrict fw = (float*) w;
|
||||
int i;
|
||||
static void v4dwt_decode_step1(v4* w, OPJ_INT32 count, const OPJ_FLOAT32 c){
|
||||
OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w;
|
||||
OPJ_INT32 i;
|
||||
for(i = 0; i < count; ++i){
|
||||
float tmp1 = fw[i*8 ];
|
||||
float tmp2 = fw[i*8 + 1];
|
||||
float tmp3 = fw[i*8 + 2];
|
||||
float tmp4 = fw[i*8 + 3];
|
||||
OPJ_FLOAT32 tmp1 = fw[i*8 ];
|
||||
OPJ_FLOAT32 tmp2 = fw[i*8 + 1];
|
||||
OPJ_FLOAT32 tmp3 = fw[i*8 + 2];
|
||||
OPJ_FLOAT32 tmp4 = fw[i*8 + 3];
|
||||
fw[i*8 ] = tmp1 * c;
|
||||
fw[i*8 + 1] = tmp2 * c;
|
||||
fw[i*8 + 2] = tmp3 * c;
|
||||
@@ -684,23 +699,23 @@ static void v4dwt_decode_step1(v4* w, int count, const float c){
|
||||
}
|
||||
}
|
||||
|
||||
static void v4dwt_decode_step2(v4* l, v4* w, int k, int m, float c){
|
||||
float* restrict fl = (float*) l;
|
||||
float* restrict fw = (float*) w;
|
||||
int i;
|
||||
static void v4dwt_decode_step2(v4* l, v4* w, OPJ_INT32 k, OPJ_INT32 m, OPJ_FLOAT32 c){
|
||||
OPJ_FLOAT32* restrict fl = (OPJ_FLOAT32*) l;
|
||||
OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w;
|
||||
OPJ_INT32 i;
|
||||
for(i = 0; i < m; ++i){
|
||||
float tmp1_1 = fl[0];
|
||||
float tmp1_2 = fl[1];
|
||||
float tmp1_3 = fl[2];
|
||||
float tmp1_4 = fl[3];
|
||||
float tmp2_1 = fw[-4];
|
||||
float tmp2_2 = fw[-3];
|
||||
float tmp2_3 = fw[-2];
|
||||
float tmp2_4 = fw[-1];
|
||||
float tmp3_1 = fw[0];
|
||||
float tmp3_2 = fw[1];
|
||||
float tmp3_3 = fw[2];
|
||||
float tmp3_4 = fw[3];
|
||||
OPJ_FLOAT32 tmp1_1 = fl[0];
|
||||
OPJ_FLOAT32 tmp1_2 = fl[1];
|
||||
OPJ_FLOAT32 tmp1_3 = fl[2];
|
||||
OPJ_FLOAT32 tmp1_4 = fl[3];
|
||||
OPJ_FLOAT32 tmp2_1 = fw[-4];
|
||||
OPJ_FLOAT32 tmp2_2 = fw[-3];
|
||||
OPJ_FLOAT32 tmp2_3 = fw[-2];
|
||||
OPJ_FLOAT32 tmp2_4 = fw[-1];
|
||||
OPJ_FLOAT32 tmp3_1 = fw[0];
|
||||
OPJ_FLOAT32 tmp3_2 = fw[1];
|
||||
OPJ_FLOAT32 tmp3_3 = fw[2];
|
||||
OPJ_FLOAT32 tmp3_4 = fw[3];
|
||||
fw[-4] = tmp2_1 + ((tmp1_1 + tmp3_1) * c);
|
||||
fw[-3] = tmp2_2 + ((tmp1_2 + tmp3_2) * c);
|
||||
fw[-2] = tmp2_3 + ((tmp1_3 + tmp3_3) * c);
|
||||
@@ -709,20 +724,20 @@ static void v4dwt_decode_step2(v4* l, v4* w, int k, int m, float c){
|
||||
fw += 8;
|
||||
}
|
||||
if(m < k){
|
||||
float c1;
|
||||
float c2;
|
||||
float c3;
|
||||
float c4;
|
||||
OPJ_FLOAT32 c1;
|
||||
OPJ_FLOAT32 c2;
|
||||
OPJ_FLOAT32 c3;
|
||||
OPJ_FLOAT32 c4;
|
||||
c += c;
|
||||
c1 = fl[0] * c;
|
||||
c2 = fl[1] * c;
|
||||
c3 = fl[2] * c;
|
||||
c4 = fl[3] * c;
|
||||
for(; m < k; ++m){
|
||||
float tmp1 = fw[-4];
|
||||
float tmp2 = fw[-3];
|
||||
float tmp3 = fw[-2];
|
||||
float tmp4 = fw[-1];
|
||||
OPJ_FLOAT32 tmp1 = fw[-4];
|
||||
OPJ_FLOAT32 tmp2 = fw[-3];
|
||||
OPJ_FLOAT32 tmp3 = fw[-2];
|
||||
OPJ_FLOAT32 tmp4 = fw[-1];
|
||||
fw[-4] = tmp1 + c1;
|
||||
fw[-3] = tmp2 + c2;
|
||||
fw[-2] = tmp3 + c3;
|
||||
@@ -738,7 +753,7 @@ static void v4dwt_decode_step2(v4* l, v4* w, int k, int m, float c){
|
||||
/* Inverse 9-7 wavelet transform in 1-D. */
|
||||
/* </summary> */
|
||||
static void v4dwt_decode(v4dwt_t* restrict dwt){
|
||||
int a, b;
|
||||
OPJ_INT32 a, b;
|
||||
if(dwt->cas == 0) {
|
||||
if(!((dwt->dn > 0) || (dwt->sn > 1))){
|
||||
return;
|
||||
@@ -755,14 +770,14 @@ static void v4dwt_decode(v4dwt_t* restrict dwt){
|
||||
#ifdef __SSE__
|
||||
v4dwt_decode_step1_sse(dwt->wavelet+a, dwt->sn, _mm_set1_ps(K));
|
||||
v4dwt_decode_step1_sse(dwt->wavelet+b, dwt->dn, _mm_set1_ps(c13318));
|
||||
v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_delta));
|
||||
v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(delta));
|
||||
v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_gamma));
|
||||
v4dwt_decode_step2_sse(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), _mm_set1_ps(dwt_beta));
|
||||
v4dwt_decode_step2_sse(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), _mm_set1_ps(dwt_alpha));
|
||||
#else
|
||||
v4dwt_decode_step1(dwt->wavelet+a, dwt->sn, K);
|
||||
v4dwt_decode_step1(dwt->wavelet+b, dwt->dn, c13318);
|
||||
v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_delta);
|
||||
v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), delta);
|
||||
v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_gamma);
|
||||
v4dwt_decode_step2(dwt->wavelet+b, dwt->wavelet+a+1, dwt->sn, int_min(dwt->sn, dwt->dn-a), dwt_beta);
|
||||
v4dwt_decode_step2(dwt->wavelet+a, dwt->wavelet+b+1, dwt->dn, int_min(dwt->dn, dwt->sn-b), dwt_alpha);
|
||||
@@ -772,24 +787,24 @@ static void v4dwt_decode(v4dwt_t* restrict dwt){
|
||||
/* <summary> */
|
||||
/* Inverse 9-7 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
void dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, int numres){
|
||||
bool dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numres){
|
||||
v4dwt_t h;
|
||||
v4dwt_t v;
|
||||
|
||||
opj_tcd_resolution_t* res = tilec->resolutions;
|
||||
|
||||
int rw = res->x1 - res->x0; /* width of the resolution level computed */
|
||||
int rh = res->y1 - res->y0; /* height of the resolution level computed */
|
||||
OPJ_UINT32 rw = res->x1 - res->x0; /* width of the resolution level computed */
|
||||
OPJ_UINT32 rh = res->y1 - res->y0; /* height of the resolution level computed */
|
||||
|
||||
int w = tilec->x1 - tilec->x0;
|
||||
OPJ_UINT32 w = tilec->x1 - tilec->x0;
|
||||
|
||||
h.wavelet = (v4*) opj_aligned_malloc((dwt_decode_max_resolution(res, numres)+5) * sizeof(v4));
|
||||
h.wavelet = (v4*) opj_aligned_malloc((dwt_max_resolution(res, numres)+5) * sizeof(v4));
|
||||
v.wavelet = h.wavelet;
|
||||
|
||||
while( --numres) {
|
||||
float * restrict aj = (float*) tilec->data;
|
||||
int bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0);
|
||||
int j;
|
||||
OPJ_FLOAT32 * restrict aj = (OPJ_FLOAT32*) tilec->data;
|
||||
OPJ_UINT32 bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0);
|
||||
OPJ_INT32 j;
|
||||
|
||||
h.sn = rw;
|
||||
v.sn = rh;
|
||||
@@ -800,27 +815,26 @@ void dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, int numres){
|
||||
rh = res->y1 - res->y0; /* height of the resolution level computed */
|
||||
|
||||
h.dn = rw - h.sn;
|
||||
h.cas = res->x0 % 2;
|
||||
h.cas = res->x0 & 1;
|
||||
|
||||
for(j = rh; j > 3; j -= 4){
|
||||
int k;
|
||||
for(j = rh; j > 0; j -= 4){
|
||||
v4dwt_interleave_h(&h, aj, w, bufsize);
|
||||
v4dwt_decode(&h);
|
||||
for(k = rw; --k >= 0;){
|
||||
if(j >= 4){
|
||||
OPJ_INT32 k = rw;
|
||||
while
|
||||
(--k >= 0)
|
||||
{
|
||||
aj[k ] = h.wavelet[k].f[0];
|
||||
aj[k+w ] = h.wavelet[k].f[1];
|
||||
aj[k+w*2] = h.wavelet[k].f[2];
|
||||
aj[k+w*3] = h.wavelet[k].f[3];
|
||||
}
|
||||
aj += w*4;
|
||||
bufsize -= w*4;
|
||||
}
|
||||
if (rh & 0x03) {
|
||||
int k;
|
||||
j = rh & 0x03;
|
||||
v4dwt_interleave_h(&h, aj, w, bufsize);
|
||||
v4dwt_decode(&h);
|
||||
for(k = rw; --k >= 0;){
|
||||
}else{
|
||||
OPJ_INT32 k = rw;
|
||||
while
|
||||
(--k >= 0)
|
||||
{
|
||||
switch(j) {
|
||||
case 3: aj[k+w*2] = h.wavelet[k].f[2];
|
||||
case 2: aj[k+w ] = h.wavelet[k].f[1];
|
||||
@@ -828,31 +842,33 @@ void dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, int numres){
|
||||
}
|
||||
}
|
||||
}
|
||||
aj += w*4;
|
||||
bufsize -= w*4;
|
||||
}
|
||||
|
||||
v.dn = rh - v.sn;
|
||||
v.cas = res->y0 % 2;
|
||||
|
||||
aj = (float*) tilec->data;
|
||||
for(j = rw; j > 3; j -= 4){
|
||||
int k;
|
||||
aj = (OPJ_FLOAT32*) tilec->data;
|
||||
for(j = rw; j > 0; j -= 4){
|
||||
v4dwt_interleave_v(&v, aj, w);
|
||||
v4dwt_decode(&v);
|
||||
if(j >= 4){
|
||||
OPJ_UINT32 k;
|
||||
for(k = 0; k < rh; ++k){
|
||||
memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(float));
|
||||
memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(OPJ_FLOAT32));
|
||||
}
|
||||
}else{
|
||||
OPJ_UINT32 k;
|
||||
for(k = 0; k < rh; ++k){
|
||||
memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(OPJ_FLOAT32));
|
||||
}
|
||||
}
|
||||
aj += 4;
|
||||
}
|
||||
if (rw & 0x03){
|
||||
int k;
|
||||
j = rw & 0x03;
|
||||
v4dwt_interleave_v(&v, aj, w);
|
||||
v4dwt_decode(&v);
|
||||
for(k = 0; k < rh; ++k){
|
||||
memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(float));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
opj_aligned_free(h.wavelet);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,6 +40,10 @@ The functions in DWT.C have for goal to realize forward and inverse discret wave
|
||||
transform with filter 5-3 (reversible) and filter 9-7 (irreversible). The functions in
|
||||
DWT.C are used by some function in TCD.C.
|
||||
*/
|
||||
#include "openjpeg.h"
|
||||
|
||||
struct opj_tcd_tilecomp;
|
||||
struct opj_tccp;
|
||||
|
||||
/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */
|
||||
/*@{*/
|
||||
@@ -52,62 +57,59 @@ Forward 5-3 wavelet tranform in 2-D.
|
||||
Apply a reversible DWT transform to a component of an image.
|
||||
@param tilec Tile component information (current tile)
|
||||
*/
|
||||
OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec);
|
||||
|
||||
bool dwt_encode(struct opj_tcd_tilecomp * tilec);
|
||||
/**
|
||||
Inverse 5-3 wavelet tranform in 2-D.
|
||||
Apply a reversible inverse DWT transform to a component of an image.
|
||||
@param tilec Tile component information (current tile)
|
||||
@param numres Number of resolution levels to decode
|
||||
*/
|
||||
OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres);
|
||||
|
||||
bool dwt_decode(struct opj_tcd_tilecomp* tilec, OPJ_UINT32 numres);
|
||||
/**
|
||||
Get the gain of a subband for the reversible 5-3 DWT.
|
||||
@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
|
||||
@return Returns 0 if orient = 0, returns 1 if orient = 1 or 2, returns 2 otherwise
|
||||
*/
|
||||
OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient) ;
|
||||
OPJ_UINT32 dwt_getgain(OPJ_UINT32 orient);
|
||||
/**
|
||||
Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT.
|
||||
@param level Level of the wavelet function
|
||||
@param orient Band of the wavelet function
|
||||
@return Returns the norm of the wavelet function
|
||||
*/
|
||||
OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient);
|
||||
OPJ_FLOAT64 dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient);
|
||||
/**
|
||||
Forward 9-7 wavelet transform in 2-D.
|
||||
Apply an irreversible DWT transform to a component of an image.
|
||||
@param tilec Tile component information (current tile)
|
||||
*/
|
||||
OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec);
|
||||
bool dwt_encode_real(struct opj_tcd_tilecomp * tilec);
|
||||
/**
|
||||
Inverse 9-7 wavelet transform in 2-D.
|
||||
Apply an irreversible inverse DWT transform to a component of an image.
|
||||
@param tilec Tile component information (current tile)
|
||||
@param numres Number of resolution levels to decode
|
||||
*/
|
||||
OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numres);
|
||||
|
||||
bool dwt_decode_real(struct opj_tcd_tilecomp* tilec, OPJ_UINT32 numres);
|
||||
/**
|
||||
Get the gain of a subband for the irreversible 9-7 DWT.
|
||||
@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
|
||||
@return Returns the gain of the 9-7 wavelet transform
|
||||
*/
|
||||
OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient);
|
||||
OPJ_UINT32 dwt_getgain_real(OPJ_UINT32 orient);
|
||||
/**
|
||||
Get the norm of a wavelet function of a subband at a specified level for the irreversible 9-7 DWT
|
||||
@param level Level of the wavelet function
|
||||
@param orient Band of the wavelet function
|
||||
@return Returns the norm of the 9-7 wavelet
|
||||
*/
|
||||
OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient);
|
||||
OPJ_FLOAT64 dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient);
|
||||
/**
|
||||
Explicit calculation of the Quantization Stepsizes
|
||||
@param tccp Tile-component coding parameters
|
||||
@param prec Precint analyzed
|
||||
*/
|
||||
void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec);
|
||||
void dwt_calc_explicit_stepsizes(struct opj_tccp * tccp, OPJ_UINT32 prec);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France
|
||||
* Copyright (c) 2012, CS Systemes d'Information, France
|
||||
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -26,63 +24,31 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "event.h"
|
||||
#include "openjpeg.h"
|
||||
#include "opj_includes.h"
|
||||
|
||||
|
||||
/* ==========================================================
|
||||
Utility functions
|
||||
==========================================================*/
|
||||
|
||||
#ifdef OPJ_CODE_NOT_USED
|
||||
#ifndef _WIN32
|
||||
static char*
|
||||
i2a(unsigned i, char *a, unsigned r) {
|
||||
#if !defined(_MSC_VER) && !defined(__MINGW32__)
|
||||
static OPJ_CHAR*
|
||||
i2a(OPJ_UINT32 i, OPJ_CHAR *a, OPJ_UINT32 r) {
|
||||
if (i/r > 0) a = i2a(i/r,a,r);
|
||||
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
|
||||
return a+1;
|
||||
}
|
||||
|
||||
/**
|
||||
Transforms integer i into an ascii string and stores the result in a;
|
||||
string is encoded in the base indicated by r.
|
||||
@param i Number to be converted
|
||||
@param a String result
|
||||
@param r Base of value; must be in the range 2 - 36
|
||||
@return Returns a
|
||||
*/
|
||||
static char *
|
||||
_itoa(int i, char *a, int r) {
|
||||
r = ((r < 2) || (r > 36)) ? 10 : r;
|
||||
if(i < 0) {
|
||||
*a = '-';
|
||||
*i2a(-i, a+1, r) = 0;
|
||||
}
|
||||
else *i2a(i, a, r) = 0;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif /* !_WIN32 */
|
||||
#endif
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/**
|
||||
* Default callback function.
|
||||
* Do nothing.
|
||||
*/
|
||||
static void opj_default_callback (const char *msg, void *client_data)
|
||||
{
|
||||
OPJ_ARG_NOT_USED(msg);
|
||||
OPJ_ARG_NOT_USED(client_data);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...) {
|
||||
#define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
|
||||
bool opj_event_msg(opj_event_mgr_t * p_event_mgr, OPJ_INT32 event_type, const OPJ_CHAR *fmt, ...) {
|
||||
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
|
||||
opj_msg_callback msg_handler = 00;
|
||||
void * l_data = 00;
|
||||
|
||||
|
||||
if(p_event_mgr != 00) {
|
||||
switch(event_type) {
|
||||
case EVT_ERROR:
|
||||
@@ -101,22 +67,21 @@ OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const
|
||||
break;
|
||||
}
|
||||
if(msg_handler == 00) {
|
||||
return OPJ_FALSE;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return OPJ_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((fmt != 00) && (p_event_mgr != 00)) {
|
||||
va_list arg;
|
||||
size_t str_length/*, i, j*/; /* UniPG */
|
||||
char message[OPJ_MSG_SIZE];
|
||||
memset(message, 0, OPJ_MSG_SIZE);
|
||||
OPJ_INT32 str_length/*, i, j*/; /* UniPG */
|
||||
OPJ_CHAR message[MSG_SIZE];
|
||||
memset(message, 0, MSG_SIZE);
|
||||
/* initialize the optional parameter list */
|
||||
va_start(arg, fmt);
|
||||
/* check the length of the format string */
|
||||
str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
|
||||
(void)str_length;
|
||||
str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
|
||||
/* parse the format string and put the result in 'message' */
|
||||
vsprintf(message, fmt, arg); /* UniPG */
|
||||
/* deinitialize the optional parameter list */
|
||||
@@ -126,16 +91,6 @@ OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const
|
||||
msg_handler(message, l_data);
|
||||
}
|
||||
|
||||
return OPJ_TRUE;
|
||||
}
|
||||
|
||||
void opj_set_default_event_handler(opj_event_mgr_t * p_manager)
|
||||
{
|
||||
p_manager->m_error_data = 00;
|
||||
p_manager->m_warning_data = 00;
|
||||
p_manager->m_info_data = 00;
|
||||
p_manager->error_handler = opj_default_callback;
|
||||
p_manager->info_handler = opj_default_callback;
|
||||
p_manager->warning_handler = opj_default_callback;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France
|
||||
* Copyright (c) 2012, CS Systemes d'Information, France
|
||||
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,6 +26,9 @@
|
||||
*/
|
||||
#ifndef __EVENT_H
|
||||
#define __EVENT_H
|
||||
|
||||
#include "openjpeg.h"
|
||||
|
||||
/**
|
||||
@file event.h
|
||||
@brief Implementation of a event callback system
|
||||
@@ -58,7 +60,6 @@ typedef struct opj_event_mgr
|
||||
opj_msg_callback info_handler;
|
||||
} opj_event_mgr_t;
|
||||
|
||||
|
||||
#define EVT_ERROR 1 /**< Error event type */
|
||||
#define EVT_WARNING 2 /**< Warning event type */
|
||||
#define EVT_INFO 4 /**< Debug event type */
|
||||
@@ -69,27 +70,15 @@ typedef struct opj_event_mgr
|
||||
/** @name Exported functions (see also openjpeg.h) */
|
||||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Write formatted data to a string and send the string to a user callback.
|
||||
*
|
||||
* @param event_mgr Event handler
|
||||
* @param event_type Event type or callback to use to send the message
|
||||
* @param fmt Format-control string (plus optional arguments)
|
||||
*
|
||||
* Writes formatted data to a string and send the string to a user callback.
|
||||
* @param p_event_mgr the event manager to display messages.
|
||||
* @param event_type Event type of the message
|
||||
* @param fmt Format-control string (plus optionnal arguments)
|
||||
* @return Returns true if successful, returns false otherwise
|
||||
*/
|
||||
OPJ_BOOL opj_event_msg(opj_event_mgr_t* event_mgr, OPJ_INT32 event_type, const char *fmt, ...);
|
||||
bool opj_event_msg(struct opj_event_mgr * p_event_mgr, OPJ_INT32 event_type, const OPJ_CHAR *fmt, ...);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Set the event manager with the default callback function for the 3 levels.
|
||||
*/
|
||||
void opj_set_default_event_handler(opj_event_mgr_t * p_manager);
|
||||
|
||||
/*@}*/
|
||||
|
||||
/*@}*/
|
||||
@@ -31,11 +31,8 @@
|
||||
#ifndef __FIX_H
|
||||
#define __FIX_H
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
#define int64 __int64
|
||||
#else
|
||||
#define int64 long long
|
||||
#endif
|
||||
#include "openjpeg.h"
|
||||
#include "opj_includes.h"
|
||||
|
||||
/**
|
||||
@file fix.h
|
||||
@@ -43,7 +40,6 @@
|
||||
|
||||
The functions in FIX.H have for goal to realize specific multiplication.
|
||||
*/
|
||||
|
||||
/** @defgroup FIX FIX - Implementation of operations of specific multiplication */
|
||||
/*@{*/
|
||||
|
||||
@@ -54,7 +50,7 @@ Multiply two fixed-precision rational numbers.
|
||||
@return Returns a * b
|
||||
*/
|
||||
static INLINE int fix_mul(int a, int b) {
|
||||
int64 temp = (int64) a * (int64) b ;
|
||||
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
|
||||
temp += temp & 4096;
|
||||
return (int) (temp >> 13) ;
|
||||
}
|
||||
149
libopenjpeg/function_list.c
Normal file
149
libopenjpeg/function_list.c
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "function_list.h"
|
||||
#include "opj_includes.h"
|
||||
#include "opj_malloc.h"
|
||||
/**
|
||||
* Default size of the validation list, if not sufficient, data will be reallocated with a double size.
|
||||
*/
|
||||
#define OPJ_VALIDATION_SIZE 10
|
||||
|
||||
/**
|
||||
* Creates a validation list.
|
||||
*
|
||||
* @return the newly created validation list.
|
||||
*/
|
||||
opj_procedure_list_t * opj_procedure_list_create()
|
||||
{
|
||||
/* memory allocation */
|
||||
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_malloc(sizeof(opj_procedure_list_t));
|
||||
if
|
||||
(! l_validation)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
/* initialization */
|
||||
memset(l_validation,0,sizeof(opj_procedure_list_t));
|
||||
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
|
||||
l_validation->m_procedures = (void**)opj_malloc(
|
||||
OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
|
||||
if
|
||||
(! l_validation->m_procedures)
|
||||
{
|
||||
opj_free(l_validation);
|
||||
return 00;
|
||||
}
|
||||
memset(l_validation->m_procedures,0,OPJ_VALIDATION_SIZE * sizeof(opj_procedure));
|
||||
return l_validation;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Destroys a validation list.
|
||||
*
|
||||
* @param p_list the list to destroy.
|
||||
*/
|
||||
void opj_procedure_list_destroy(opj_procedure_list_t * p_list)
|
||||
{
|
||||
if
|
||||
(! p_list)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/* initialization */
|
||||
if
|
||||
(p_list->m_procedures)
|
||||
{
|
||||
opj_free(p_list->m_procedures);
|
||||
}
|
||||
opj_free(p_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new validation procedure.
|
||||
*
|
||||
* @param p_validation_list the list of procedure to modify.
|
||||
* @param p_procedure the procedure to add.
|
||||
*/
|
||||
bool opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure)
|
||||
{
|
||||
if
|
||||
(p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures)
|
||||
{
|
||||
p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE;
|
||||
p_validation_list->m_procedures = (void**)opj_realloc(
|
||||
p_validation_list->m_procedures,p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
|
||||
if
|
||||
(! p_validation_list->m_procedures)
|
||||
{
|
||||
p_validation_list->m_nb_max_procedures = 0;
|
||||
p_validation_list->m_nb_procedures = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
p_validation_list->m_procedures[p_validation_list->m_nb_procedures] = p_procedure;
|
||||
++p_validation_list->m_nb_procedures;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of validation procedures.
|
||||
*
|
||||
* @param p_validation_list the list of procedure to modify.
|
||||
*
|
||||
* @return the number of validation procedures.
|
||||
*/
|
||||
OPJ_UINT32 opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list)
|
||||
{
|
||||
return p_validation_list->m_nb_procedures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pointer on the first validation procedure. This function is similar to the C++
|
||||
* iterator class to iterate through all the procedures inside the validation list.
|
||||
* the caller does not take ownership of the pointer.
|
||||
*
|
||||
* @param p_validation_list the list of procedure to get the first procedure from.
|
||||
*
|
||||
* @return a pointer to the first procedure.
|
||||
*/
|
||||
opj_procedure* opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list)
|
||||
{
|
||||
return p_validation_list->m_procedures;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the list of validation procedures.
|
||||
*
|
||||
* @param p_validation_list the list of procedure to clear.
|
||||
*
|
||||
*/
|
||||
void opj_procedure_list_clear (opj_procedure_list_t * p_validation_list)
|
||||
{
|
||||
p_validation_list->m_nb_procedures = 0;
|
||||
}
|
||||
@@ -34,17 +34,22 @@
|
||||
* The functions in validation.c aims to have access to a list of procedures.
|
||||
*/
|
||||
|
||||
/** @defgroup VAL VAL - validation procedure*/
|
||||
/** @defgroup validation validation procedure*/
|
||||
/*@{*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
/**************************************************************************************************
|
||||
***************************************** FORWARD DECLARATION ************************************
|
||||
**************************************************************************************************/
|
||||
struct opj_jp2;
|
||||
|
||||
/**
|
||||
* declare a function pointer
|
||||
* ARGGGG, when will the template be added to the C language ???
|
||||
* in order not to have to duplicate the code in a vast number of times, use void * and downcast
|
||||
* it after => UGLY but faster and easier
|
||||
* TODO : make the class template in C++, use STL vector or duplicate code for each procedure type.
|
||||
*/
|
||||
typedef void (*opj_procedure)(void);
|
||||
typedef void * opj_procedure;
|
||||
|
||||
/**
|
||||
* A list of procedures.
|
||||
@@ -73,7 +78,7 @@ typedef struct opj_procedure_list
|
||||
*
|
||||
* @return the newly created validation list.
|
||||
*/
|
||||
opj_procedure_list_t * opj_procedure_list_create(void);
|
||||
opj_procedure_list_t * opj_procedure_list_create();
|
||||
|
||||
/**
|
||||
* Destroys a validation list.
|
||||
@@ -88,9 +93,9 @@ void opj_procedure_list_destroy(opj_procedure_list_t * p_list);
|
||||
* @param p_validation_list the list of procedure to modify.
|
||||
* @param p_procedure the procedure to add.
|
||||
*
|
||||
* @return OPJ_TRUE if the procedure could be added.
|
||||
* @return true if the procedure could ne added.
|
||||
*/
|
||||
OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure);
|
||||
bool opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure);
|
||||
|
||||
/**
|
||||
* Gets the number of validation procedures.
|
||||
@@ -120,7 +125,7 @@ opj_procedure* opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_
|
||||
*
|
||||
*/
|
||||
void opj_procedure_list_clear (opj_procedure_list_t * p_validation_list);
|
||||
/*@}*/
|
||||
|
||||
|
||||
#endif /* __FUNCTION_LIST_H */
|
||||
|
||||
175
libopenjpeg/image.c
Normal file
175
libopenjpeg/image.c
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Herv<72> Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "image.h"
|
||||
#include "openjpeg.h"
|
||||
#include "opj_malloc.h"
|
||||
#include "j2k.h"
|
||||
#include "int.h"
|
||||
|
||||
opj_image_t* opj_image_create0(void) {
|
||||
opj_image_t *image = (opj_image_t*)opj_malloc(sizeof(opj_image_t));
|
||||
memset(image,0,sizeof(opj_image_t));
|
||||
return image;
|
||||
}
|
||||
|
||||
opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
|
||||
OPJ_UINT32 compno;
|
||||
opj_image_t *image = 00;
|
||||
|
||||
image = (opj_image_t*) opj_malloc(sizeof(opj_image_t));
|
||||
if
|
||||
(image)
|
||||
{
|
||||
memset(image,0,sizeof(opj_image_t));
|
||||
image->color_space = clrspc;
|
||||
image->numcomps = numcmpts;
|
||||
/* allocate memory for the per-component information */
|
||||
image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
|
||||
if
|
||||
(!image->comps)
|
||||
{
|
||||
opj_image_destroy(image);
|
||||
return 00;
|
||||
}
|
||||
memset(image->comps,0,image->numcomps * sizeof(opj_image_comp_t));
|
||||
/* create the individual image components */
|
||||
for(compno = 0; compno < numcmpts; compno++) {
|
||||
opj_image_comp_t *comp = &image->comps[compno];
|
||||
comp->dx = cmptparms[compno].dx;
|
||||
comp->dy = cmptparms[compno].dy;
|
||||
comp->w = cmptparms[compno].w;
|
||||
comp->h = cmptparms[compno].h;
|
||||
comp->x0 = cmptparms[compno].x0;
|
||||
comp->y0 = cmptparms[compno].y0;
|
||||
comp->prec = cmptparms[compno].prec;
|
||||
comp->sgnd = cmptparms[compno].sgnd;
|
||||
comp->data = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32));
|
||||
if
|
||||
(!comp->data)
|
||||
{
|
||||
opj_image_destroy(image);
|
||||
return 00;
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
|
||||
OPJ_UINT32 compno;
|
||||
opj_image_t *image = 00;
|
||||
|
||||
image = (opj_image_t*) opj_malloc(sizeof(opj_image_t));
|
||||
if
|
||||
(image)
|
||||
{
|
||||
memset(image,0,sizeof(opj_image_t));
|
||||
image->color_space = clrspc;
|
||||
image->numcomps = numcmpts;
|
||||
/* allocate memory for the per-component information */
|
||||
image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
|
||||
if
|
||||
(!image->comps)
|
||||
{
|
||||
opj_image_destroy(image);
|
||||
return 00;
|
||||
}
|
||||
memset(image->comps,0,image->numcomps * sizeof(opj_image_comp_t));
|
||||
/* create the individual image components */
|
||||
for(compno = 0; compno < numcmpts; compno++) {
|
||||
opj_image_comp_t *comp = &image->comps[compno];
|
||||
comp->dx = cmptparms[compno].dx;
|
||||
comp->dy = cmptparms[compno].dy;
|
||||
comp->w = cmptparms[compno].w;
|
||||
comp->h = cmptparms[compno].h;
|
||||
comp->x0 = cmptparms[compno].x0;
|
||||
comp->y0 = cmptparms[compno].y0;
|
||||
comp->prec = cmptparms[compno].prec;
|
||||
comp->sgnd = cmptparms[compno].sgnd;
|
||||
comp->data = 0;
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
|
||||
OPJ_UINT32 i;
|
||||
if
|
||||
(image)
|
||||
{
|
||||
if
|
||||
(image->comps)
|
||||
{
|
||||
/* image components */
|
||||
for(i = 0; i < image->numcomps; i++) {
|
||||
opj_image_comp_t *image_comp = &image->comps[i];
|
||||
if(image_comp->data) {
|
||||
opj_free(image_comp->data);
|
||||
}
|
||||
}
|
||||
opj_free(image->comps);
|
||||
}
|
||||
opj_free(image);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the components of the image from the coding parameters.
|
||||
*
|
||||
* @param p_image the image to update.
|
||||
* @param p_cp the coding parameters from which to update the image.
|
||||
*/
|
||||
void opj_image_comp_update(opj_image_t * p_image,const opj_cp_t * p_cp)
|
||||
{
|
||||
OPJ_UINT32 i, l_width, l_height;
|
||||
OPJ_INT32 l_x0,l_y0,l_x1,l_y1;
|
||||
OPJ_INT32 l_comp_x0,l_comp_y0,l_comp_x1,l_comp_y1;
|
||||
opj_image_comp_t * l_img_comp = 00;
|
||||
|
||||
l_x0 = int_max(p_cp->tx0 , p_image->x0);
|
||||
l_y0 = int_max(p_cp->ty0 , p_image->y0);
|
||||
l_x1 = int_min(p_cp->tx0 + p_cp->tw * p_cp->tdx, p_image->x1);
|
||||
l_y1 = int_min(p_cp->ty0 + p_cp->th * p_cp->tdy, p_image->y1);
|
||||
|
||||
l_img_comp = p_image->comps;
|
||||
for
|
||||
(i = 0; i < p_image->numcomps; ++i)
|
||||
{
|
||||
l_comp_x0 = int_ceildiv(l_x0, l_img_comp->dx);
|
||||
l_comp_y0 = int_ceildiv(l_y0, l_img_comp->dy);
|
||||
l_comp_x1 = int_ceildiv(l_x1, l_img_comp->dx);
|
||||
l_comp_y1 = int_ceildiv(l_y1, l_img_comp->dy);
|
||||
l_width = int_ceildivpow2(l_comp_x1 - l_comp_x0, l_img_comp->factor);
|
||||
l_height = int_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor);
|
||||
l_img_comp->w = l_width;
|
||||
l_img_comp->h = l_height;
|
||||
l_img_comp->x0 = l_x0;
|
||||
l_img_comp->y0 = l_y0;
|
||||
++l_img_comp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +32,8 @@
|
||||
|
||||
The functions in IMAGE.C have for goal to realize operations on images.
|
||||
*/
|
||||
|
||||
struct opj_image;
|
||||
struct opj_cp;
|
||||
/** @defgroup IMAGE IMAGE - Implementation of operations on images */
|
||||
/*@{*/
|
||||
|
||||
@@ -40,7 +42,15 @@ Create an empty image
|
||||
@todo this function should be removed
|
||||
@return returns an empty image if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_image_t* opj_image_create0(void);
|
||||
struct opj_image* opj_image_create0(void);
|
||||
|
||||
/**
|
||||
* Updates the components of the image from the coding parameters.
|
||||
*
|
||||
* @param p_image the image to update.
|
||||
* @param p_cp the coding parameters from which to update the image.
|
||||
*/
|
||||
void opj_image_comp_update(struct opj_image * p_image,const struct opj_cp * p_cp);
|
||||
|
||||
/*@}*/
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,13 +32,14 @@
|
||||
#ifndef __INT_H
|
||||
#define __INT_H
|
||||
/**
|
||||
@file opj_intmath.h
|
||||
@file int.h
|
||||
@brief Implementation of operations on integers (INT)
|
||||
|
||||
The functions in OPJ_INTMATH.H have for goal to realize operations on integers.
|
||||
The functions in INT.H have for goal to realize operations on integers.
|
||||
*/
|
||||
|
||||
/** @defgroup OPJ_INTMATH OPJ_INTMATH - Implementation of operations on integers */
|
||||
#include "openjpeg.h"
|
||||
#include "opj_includes.h"
|
||||
/** @defgroup INT INT - Implementation of operations on integers */
|
||||
/*@{*/
|
||||
|
||||
/** @name Exported functions (see also openjpeg.h) */
|
||||
@@ -47,7 +49,7 @@ The functions in OPJ_INTMATH.H have for goal to realize operations on integers.
|
||||
Get the minimum of two integers
|
||||
@return Returns a if a < b else b
|
||||
*/
|
||||
static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
static INLINE OPJ_INT32 int_min(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
@@ -55,7 +57,7 @@ static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
Get the minimum of two integers
|
||||
@return Returns a if a < b else b
|
||||
*/
|
||||
static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
|
||||
static INLINE OPJ_UINT32 uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
|
||||
Get the maximum of two integers
|
||||
@return Returns a if a > b else b
|
||||
*/
|
||||
static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
static INLINE OPJ_INT32 int_max(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
@@ -71,10 +73,9 @@ static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
Get the maximum of two integers
|
||||
@return Returns a if a > b else b
|
||||
*/
|
||||
static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) {
|
||||
static INLINE OPJ_UINT32 uint_max(OPJ_UINT32 a, OPJ_UINT32 b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
/**
|
||||
Clamp an integer inside an interval
|
||||
@return
|
||||
@@ -84,7 +85,7 @@ Clamp an integer inside an interval
|
||||
<li>Returns min if (a < min)
|
||||
</ul>
|
||||
*/
|
||||
static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max) {
|
||||
static INLINE OPJ_INT32 int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max) {
|
||||
if (a < min)
|
||||
return min;
|
||||
if (a > max)
|
||||
@@ -94,14 +95,14 @@ static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max)
|
||||
/**
|
||||
@return Get absolute value of integer
|
||||
*/
|
||||
static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a) {
|
||||
static INLINE OPJ_INT32 int_abs(OPJ_INT32 a) {
|
||||
return a < 0 ? -a : a;
|
||||
}
|
||||
/**
|
||||
Divide an integer and round upwards
|
||||
@return Returns a divided by b
|
||||
*/
|
||||
static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
static INLINE OPJ_INT32 int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
return (a + b - 1) / b;
|
||||
}
|
||||
|
||||
@@ -109,40 +110,40 @@ static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
Divide an integer and round upwards
|
||||
@return Returns a divided by b
|
||||
*/
|
||||
static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) {
|
||||
static INLINE OPJ_UINT32 uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) {
|
||||
return (a + b - 1) / b;
|
||||
}
|
||||
|
||||
/**
|
||||
Divide an integer by a power of 2 and round upwards
|
||||
@return Returns a divided by 2^b
|
||||
*/
|
||||
static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
static INLINE OPJ_INT32 int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
return (a + (1 << b) - 1) >> b;
|
||||
}
|
||||
/**
|
||||
Divide an integer by a power of 2 and round downwards
|
||||
@return Returns a divided by 2^b
|
||||
*/
|
||||
static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
static INLINE OPJ_INT32 int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
return a >> b;
|
||||
}
|
||||
/**
|
||||
Get logarithm of an integer and round downwards
|
||||
@return Returns log2(a)
|
||||
*/
|
||||
static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) {
|
||||
static INLINE OPJ_INT32 int_floorlog2(OPJ_INT32 a) {
|
||||
OPJ_INT32 l;
|
||||
for (l = 0; a > 1; l++) {
|
||||
a >>= 1;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
Get logarithm of an integer and round downwards
|
||||
@return Returns log2(a)
|
||||
*/
|
||||
static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a) {
|
||||
static INLINE OPJ_UINT32 uint_floorlog2(OPJ_UINT32 a) {
|
||||
OPJ_UINT32 l;
|
||||
for (l = 0; a > 1; ++l)
|
||||
{
|
||||
@@ -150,19 +151,6 @@ static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a) {
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
Multiply two fixed-precision rational numbers.
|
||||
@param a
|
||||
@param b
|
||||
@return Returns a * b
|
||||
*/
|
||||
static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) {
|
||||
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
|
||||
temp += temp & 4096;
|
||||
return (OPJ_INT32) (temp >> 13) ;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
291
libopenjpeg/invert.c
Normal file
291
libopenjpeg/invert.c
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "invert.h"
|
||||
#include "opj_malloc.h"
|
||||
|
||||
|
||||
bool opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations, OPJ_FLOAT32 * p_swap_area,OPJ_UINT32 n);
|
||||
void opj_lupSolve(OPJ_FLOAT32 * pResult, OPJ_FLOAT32* pMatrix, OPJ_FLOAT32* pVector, OPJ_UINT32* pPermutations, OPJ_UINT32 n,OPJ_FLOAT32 * p_intermediate_data);
|
||||
void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix,
|
||||
OPJ_FLOAT32 * pDestMatrix,
|
||||
OPJ_UINT32 n,
|
||||
OPJ_UINT32 * pPermutations,
|
||||
OPJ_FLOAT32 * p_src_temp,
|
||||
OPJ_FLOAT32 * p_dest_temp,
|
||||
OPJ_FLOAT32 * p_swap_area);
|
||||
|
||||
/**
|
||||
* Matrix inversion.
|
||||
*/
|
||||
bool opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,OPJ_FLOAT32 * pDestMatrix, OPJ_UINT32 n)
|
||||
{
|
||||
OPJ_BYTE * l_data = 00;
|
||||
OPJ_UINT32 l_permutation_size = n * sizeof(OPJ_UINT32);
|
||||
OPJ_UINT32 l_swap_size = n * sizeof(OPJ_FLOAT32);
|
||||
OPJ_UINT32 l_total_size = l_permutation_size + 3 * l_swap_size;
|
||||
OPJ_UINT32 * lPermutations = 00;
|
||||
OPJ_FLOAT32 * l_double_data = 00;
|
||||
|
||||
l_data = (OPJ_BYTE *) opj_malloc(l_total_size);
|
||||
if
|
||||
(l_data == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
lPermutations = (OPJ_UINT32 *) l_data;
|
||||
l_double_data = (OPJ_FLOAT32 *) (l_data + l_permutation_size);
|
||||
memset(lPermutations,0,l_permutation_size);
|
||||
|
||||
if
|
||||
(! opj_lupDecompose(pSrcMatrix,lPermutations,l_double_data,n))
|
||||
{
|
||||
opj_free(l_data);
|
||||
return false;
|
||||
}
|
||||
opj_lupInvert(pSrcMatrix,pDestMatrix,n,lPermutations,l_double_data,l_double_data + n,l_double_data + 2*n);
|
||||
opj_free(l_data);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* LUP decomposition
|
||||
*/
|
||||
bool opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations, OPJ_FLOAT32 * p_swap_area,OPJ_UINT32 n)
|
||||
{
|
||||
OPJ_UINT32 * tmpPermutations = permutations;
|
||||
OPJ_UINT32 * dstPermutations;
|
||||
OPJ_UINT32 k2=0,t;
|
||||
OPJ_FLOAT32 temp;
|
||||
OPJ_UINT32 i,j,k;
|
||||
OPJ_FLOAT32 p;
|
||||
OPJ_UINT32 lLastColum = n - 1;
|
||||
OPJ_UINT32 lSwapSize = n * sizeof(OPJ_FLOAT32);
|
||||
OPJ_FLOAT32 * lTmpMatrix = matrix;
|
||||
OPJ_FLOAT32 * lColumnMatrix,* lDestMatrix;
|
||||
OPJ_UINT32 offset = 1;
|
||||
OPJ_UINT32 lStride = n-1;
|
||||
|
||||
//initialize permutations
|
||||
for
|
||||
(i = 0; i < n; ++i)
|
||||
{
|
||||
*tmpPermutations++ = i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// now make a pivot with colum switch
|
||||
tmpPermutations = permutations;
|
||||
for
|
||||
(k = 0; k < lLastColum; ++k)
|
||||
{
|
||||
p = 0.0;
|
||||
|
||||
// take the middle element
|
||||
lColumnMatrix = lTmpMatrix + k;
|
||||
|
||||
// make permutation with the biggest value in the column
|
||||
for
|
||||
(i = k; i < n; ++i)
|
||||
{
|
||||
temp = ((*lColumnMatrix > 0) ? *lColumnMatrix : -(*lColumnMatrix));
|
||||
if
|
||||
(temp > p)
|
||||
{
|
||||
p = temp;
|
||||
k2 = i;
|
||||
}
|
||||
// next line
|
||||
lColumnMatrix += n;
|
||||
}
|
||||
|
||||
// a whole rest of 0 -> non singular
|
||||
if
|
||||
(p == 0.0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// should we permute ?
|
||||
if
|
||||
(k2 != k)
|
||||
{
|
||||
//exchange of line
|
||||
// k2 > k
|
||||
dstPermutations = tmpPermutations + k2 - k;
|
||||
// swap indices
|
||||
t = *tmpPermutations;
|
||||
*tmpPermutations = *dstPermutations;
|
||||
*dstPermutations = t;
|
||||
|
||||
// and swap entire line.
|
||||
lColumnMatrix = lTmpMatrix + (k2 - k) * n;
|
||||
memcpy(p_swap_area,lColumnMatrix,lSwapSize);
|
||||
memcpy(lColumnMatrix,lTmpMatrix,lSwapSize);
|
||||
memcpy(lTmpMatrix,p_swap_area,lSwapSize);
|
||||
}
|
||||
|
||||
// now update data in the rest of the line and line after
|
||||
lDestMatrix = lTmpMatrix + k;
|
||||
lColumnMatrix = lDestMatrix + n;
|
||||
// take the middle element
|
||||
temp = *(lDestMatrix++);
|
||||
|
||||
// now compute up data (i.e. coeff up of the diagonal).
|
||||
for (i = offset; i < n; ++i)
|
||||
{
|
||||
//lColumnMatrix;
|
||||
// divide the lower column elements by the diagonal value
|
||||
|
||||
// matrix[i][k] /= matrix[k][k];
|
||||
// p = matrix[i][k]
|
||||
p = *lColumnMatrix / temp;
|
||||
*(lColumnMatrix++) = p;
|
||||
for
|
||||
(j = /* k + 1 */ offset; j < n; ++j)
|
||||
{
|
||||
// matrix[i][j] -= matrix[i][k] * matrix[k][j];
|
||||
*(lColumnMatrix++) -= p * (*(lDestMatrix++));
|
||||
}
|
||||
// come back to the k+1th element
|
||||
lDestMatrix -= lStride;
|
||||
// go to kth element of the next line
|
||||
lColumnMatrix += k;
|
||||
}
|
||||
// offset is now k+2
|
||||
++offset;
|
||||
// 1 element less for stride
|
||||
--lStride;
|
||||
// next line
|
||||
lTmpMatrix+=n;
|
||||
// next permutation element
|
||||
++tmpPermutations;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* LUP solving
|
||||
*/
|
||||
void opj_lupSolve (OPJ_FLOAT32 * pResult, OPJ_FLOAT32 * pMatrix, OPJ_FLOAT32 * pVector, OPJ_UINT32* pPermutations, OPJ_UINT32 n,OPJ_FLOAT32 * p_intermediate_data)
|
||||
{
|
||||
OPJ_UINT32 i,j;
|
||||
OPJ_FLOAT32 sum;
|
||||
OPJ_FLOAT32 u;
|
||||
OPJ_UINT32 lStride = n+1;
|
||||
OPJ_FLOAT32 * lCurrentPtr;
|
||||
OPJ_FLOAT32 * lIntermediatePtr;
|
||||
OPJ_FLOAT32 * lDestPtr;
|
||||
OPJ_FLOAT32 * lTmpMatrix;
|
||||
OPJ_FLOAT32 * lLineMatrix = pMatrix;
|
||||
OPJ_FLOAT32 * lBeginPtr = pResult + n - 1;
|
||||
OPJ_FLOAT32 * lGeneratedData;
|
||||
OPJ_UINT32 * lCurrentPermutationPtr = pPermutations;
|
||||
|
||||
|
||||
lIntermediatePtr = p_intermediate_data;
|
||||
lGeneratedData = p_intermediate_data + n - 1;
|
||||
|
||||
for
|
||||
(i = 0; i < n; ++i)
|
||||
{
|
||||
sum = 0.0;
|
||||
lCurrentPtr = p_intermediate_data;
|
||||
lTmpMatrix = lLineMatrix;
|
||||
for
|
||||
(j = 1; j <= i; ++j)
|
||||
{
|
||||
// sum += matrix[i][j-1] * y[j-1];
|
||||
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
|
||||
}
|
||||
//y[i] = pVector[pPermutations[i]] - sum;
|
||||
*(lIntermediatePtr++) = pVector[*(lCurrentPermutationPtr++)] - sum;
|
||||
lLineMatrix += n;
|
||||
}
|
||||
|
||||
// we take the last point of the matrix
|
||||
lLineMatrix = pMatrix + n*n - 1;
|
||||
|
||||
// and we take after the last point of the destination vector
|
||||
lDestPtr = pResult + n;
|
||||
|
||||
for
|
||||
(i = n - 1; i != -1 ; --i)
|
||||
{
|
||||
sum = 0.0;
|
||||
lTmpMatrix = lLineMatrix;
|
||||
u = *(lTmpMatrix++);
|
||||
lCurrentPtr = lDestPtr--;
|
||||
for
|
||||
(j = i + 1; j < n; ++j)
|
||||
{
|
||||
// sum += matrix[i][j] * x[j]
|
||||
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
|
||||
}
|
||||
//x[i] = (y[i] - sum) / u;
|
||||
*(lBeginPtr--) = (*(lGeneratedData--) - sum) / u;
|
||||
lLineMatrix -= lStride;
|
||||
}
|
||||
}
|
||||
|
||||
/** LUP inversion (call with the result of lupDecompose)
|
||||
*/
|
||||
void opj_lupInvert (
|
||||
OPJ_FLOAT32 * pSrcMatrix,
|
||||
OPJ_FLOAT32 * pDestMatrix,
|
||||
OPJ_UINT32 n,
|
||||
OPJ_UINT32 * pPermutations,
|
||||
OPJ_FLOAT32 * p_src_temp,
|
||||
OPJ_FLOAT32 * p_dest_temp,
|
||||
OPJ_FLOAT32 * p_swap_area
|
||||
)
|
||||
{
|
||||
OPJ_UINT32 j,i;
|
||||
OPJ_FLOAT32 * lCurrentPtr;
|
||||
OPJ_FLOAT32 * lLineMatrix = pDestMatrix;
|
||||
OPJ_UINT32 lSwapSize = n * sizeof(OPJ_FLOAT32);
|
||||
|
||||
for
|
||||
(j = 0; j < n; ++j)
|
||||
{
|
||||
lCurrentPtr = lLineMatrix++;
|
||||
memset(p_src_temp,0,lSwapSize);
|
||||
p_src_temp[j] = 1.0;
|
||||
opj_lupSolve(p_dest_temp,pSrcMatrix,p_src_temp, pPermutations, n , p_swap_area);
|
||||
|
||||
for
|
||||
(i = 0; i < n; ++i)
|
||||
{
|
||||
*(lCurrentPtr) = p_dest_temp[i];
|
||||
lCurrentPtr+=n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,34 +26,15 @@
|
||||
|
||||
#ifndef __INVERT_H
|
||||
#define __INVERT_H
|
||||
/**
|
||||
@file invert.h
|
||||
@brief Implementation of the matrix inversion
|
||||
|
||||
The function in INVERT.H compute a matrix inversion with a LUP method
|
||||
*/
|
||||
|
||||
/** @defgroup INVERT INVERT - Implementation of a matrix inversion */
|
||||
/*@{*/
|
||||
/** @name Exported functions */
|
||||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#include "openjpeg.h"
|
||||
/**
|
||||
* Calculates a n x n double matrix inversion with a LUP method. Data is aligned, rows after rows (or columns after columns).
|
||||
* The function does not take ownership of any memory block, data must be fred by the user.
|
||||
*
|
||||
* @param pSrcMatrix the matrix to invert.
|
||||
* @param pDestMatrix data to store the inverted matrix.
|
||||
* @param n size of the matrix
|
||||
* @return OPJ_TRUE if the inversion is successful, OPJ_FALSE if the matrix is singular.
|
||||
* @return 1 if the inversion is successful, 0 if the matrix is singular.
|
||||
*/
|
||||
OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
|
||||
OPJ_FLOAT32 * pDestMatrix,
|
||||
OPJ_UINT32 nb_compo);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
bool opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,OPJ_FLOAT32 * pDestMatrix, OPJ_UINT32 n);
|
||||
#endif
|
||||
|
||||
/*@}*/
|
||||
|
||||
#endif /* __INVERT_H */
|
||||
9398
libopenjpeg/j2k.c
Normal file
9398
libopenjpeg/j2k.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,9 +7,6 @@
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2006-2007, Parvatha Elangovan
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
|
||||
* Copyright (c) 2012, CS Systemes d'Information, France
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -42,6 +39,11 @@
|
||||
The functions in J2K.C have for goal to read/write the several parts of the codestream: markers and data.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
|
||||
struct opj_dparameters;
|
||||
struct opj_stream_private;
|
||||
struct opj_event_mgr;
|
||||
/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */
|
||||
/*@{*/
|
||||
|
||||
@@ -49,12 +51,12 @@ The functions in J2K.C have for goal to read/write the several parts of the code
|
||||
#define J2K_CP_CSTY_SOP 0x02
|
||||
#define J2K_CP_CSTY_EPH 0x04
|
||||
#define J2K_CCP_CSTY_PRT 0x01
|
||||
#define J2K_CCP_CBLKSTY_LAZY 0x01 /**< Selective arithmetic coding bypass */
|
||||
#define J2K_CCP_CBLKSTY_RESET 0x02 /**< Reset context probabilities on coding pass boundaries */
|
||||
#define J2K_CCP_CBLKSTY_TERMALL 0x04 /**< Termination on each coding pass */
|
||||
#define J2K_CCP_CBLKSTY_VSC 0x08 /**< Vertically stripe causal context */
|
||||
#define J2K_CCP_CBLKSTY_PTERM 0x10 /**< Predictable termination */
|
||||
#define J2K_CCP_CBLKSTY_SEGSYM 0x20 /**< Segmentation symbols are used */
|
||||
#define J2K_CCP_CBLKSTY_LAZY 0x01
|
||||
#define J2K_CCP_CBLKSTY_RESET 0x02
|
||||
#define J2K_CCP_CBLKSTY_TERMALL 0x04
|
||||
#define J2K_CCP_CBLKSTY_VSC 0x08
|
||||
#define J2K_CCP_CBLKSTY_PTERM 0x10
|
||||
#define J2K_CCP_CBLKSTY_SEGSYM 0x20
|
||||
#define J2K_CCP_QNTSTY_NOQNT 0
|
||||
#define J2K_CCP_QNTSTY_SIQNT 1
|
||||
#define J2K_CCP_QNTSTY_SEQNT 2
|
||||
@@ -86,8 +88,6 @@ The functions in J2K.C have for goal to read/write the several parts of the code
|
||||
#define J2K_MS_MCT 0xff74 /**< MCT marker value */
|
||||
#define J2K_MS_MCO 0xff77 /**< MCO marker value */
|
||||
|
||||
#define J2K_MS_UNK 0 /**< UNKNOWN marker value */
|
||||
|
||||
/* UniPG>> */
|
||||
#ifdef USE_JPWL
|
||||
#define J2K_MS_EPC 0xff68 /**< EPC marker value (Part 11: JPEG 2000 for Wireless) */
|
||||
@@ -101,28 +101,42 @@ The functions in J2K.C have for goal to read/write the several parts of the code
|
||||
#endif /* USE_JPSEC */
|
||||
/* <<UniPG */
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Values that specify the status of the decoding process when decoding the main header.
|
||||
* These values may be combined with a | operator.
|
||||
* */
|
||||
typedef enum J2K_STATUS {
|
||||
J2K_STATE_NONE = 0x0000, /**< a SOC marker is expected */
|
||||
J2K_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */
|
||||
J2K_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */
|
||||
J2K_STATE_MH = 0x0004, /**< the decoding process is in the main header */
|
||||
J2K_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */
|
||||
J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */
|
||||
J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */
|
||||
J2K_STATE_NEOC = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */
|
||||
|
||||
J2K_STATE_EOC = 0x0100, /**< the decoding process has encountered the EOC marker */
|
||||
J2K_STATE_ERR = 0x8000 /**< the decoding process has encountered an error (FIXME warning V1 = 0x0080)*/
|
||||
} J2K_STATUS;
|
||||
Values that specify the status of the decoding process when decoding the main header.
|
||||
These values may be combined with a | operator.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
J2K_DEC_STATE_NONE = 0x0000, /**< a SOC marker is expected */
|
||||
J2K_DEC_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */
|
||||
J2K_DEC_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */
|
||||
J2K_DEC_STATE_MH = 0x0004, /**< the decoding process is in the main header */
|
||||
J2K_DEC_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */
|
||||
J2K_DEC_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */
|
||||
J2K_DEC_STATE_MT = 0x0020, /**< the EOC marker has just been read */
|
||||
J2K_DEC_STATE_NEOC = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */
|
||||
J2K_DEC_STATE_DATA = 0x0080, /**< the decoding process must not expect a EOC marker because the codestream is truncated */
|
||||
J2K_DEC_STATE_ERR = 0x8000, /**< the decoding process has encountered an error */
|
||||
J2K_DEC_STATE_EOC = 0x0100
|
||||
}
|
||||
J2K_DECODING_STATUS;
|
||||
|
||||
/**
|
||||
* Type of elements storing in the MCT data
|
||||
Values that specify the status of the decoding process when decoding the main header.
|
||||
These values may be combined with a | operator.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
J2K_ENC_STATE_NONE = 0x0000, /**< a SOC marker is expected */
|
||||
J2K_ENC_STATE_ENCODE = 0x0001, /**< a SOC marker is expected */
|
||||
}
|
||||
J2K_ENCODING_STATUS;
|
||||
|
||||
/**
|
||||
* Type of data for storing the MCT data
|
||||
*/
|
||||
typedef enum MCT_ELEMENT_TYPE
|
||||
{
|
||||
@@ -133,7 +147,7 @@ typedef enum MCT_ELEMENT_TYPE
|
||||
} J2K_MCT_ELEMENT_TYPE;
|
||||
|
||||
/**
|
||||
* Type of MCT array
|
||||
* Type of data for storing the MCT data
|
||||
*/
|
||||
typedef enum MCT_ARRAY_TYPE
|
||||
{
|
||||
@@ -142,25 +156,43 @@ typedef enum MCT_ARRAY_TYPE
|
||||
MCT_TYPE_OFFSET = 2
|
||||
} J2K_MCT_ARRAY_TYPE;
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
T2 encoding mode
|
||||
*/
|
||||
typedef enum T2_MODE {
|
||||
THRESH_CALC = 0, /** Function called in Rate allocation process*/
|
||||
FINAL_PASS = 1 /** Function called in Tier 2 process*/
|
||||
}J2K_T2_MODE;
|
||||
|
||||
|
||||
/**
|
||||
* Quantization stepsize
|
||||
Quantization stepsize
|
||||
*/
|
||||
typedef struct opj_stepsize {
|
||||
typedef struct opj_stepsize
|
||||
{
|
||||
/** exponent */
|
||||
OPJ_INT32 expn;
|
||||
OPJ_UINT32 expn;
|
||||
/** mantissa */
|
||||
OPJ_INT32 mant;
|
||||
} opj_stepsize_t;
|
||||
OPJ_UINT32 mant;
|
||||
}
|
||||
opj_stepsize_t;
|
||||
|
||||
typedef struct opj_mct_data
|
||||
{
|
||||
J2K_MCT_ELEMENT_TYPE m_element_type;
|
||||
J2K_MCT_ARRAY_TYPE m_array_type;
|
||||
OPJ_UINT32 m_index;
|
||||
OPJ_BYTE * m_data;
|
||||
OPJ_UINT32 m_data_size;
|
||||
}
|
||||
opj_mct_data_t;
|
||||
|
||||
typedef struct opj_simple_mcc_decorrelation_data
|
||||
{
|
||||
OPJ_UINT32 m_index;
|
||||
OPJ_UINT32 m_nb_comps;
|
||||
opj_mct_data_t * m_decorrelation_array;
|
||||
opj_mct_data_t * m_offset_array;
|
||||
OPJ_UINT32 m_is_irreversible : 1;
|
||||
}
|
||||
opj_simple_mcc_decorrelation_data_t;
|
||||
|
||||
|
||||
/**
|
||||
Tile-component coding parameters
|
||||
@@ -182,48 +214,20 @@ typedef struct opj_tccp
|
||||
/** quantisation style */
|
||||
OPJ_UINT32 qntsty;
|
||||
/** stepsizes used for quantization */
|
||||
opj_stepsize_t stepsizes[OPJ_J2K_MAXBANDS];
|
||||
opj_stepsize_t stepsizes[J2K_MAXBANDS];
|
||||
/** number of guard bits */
|
||||
OPJ_UINT32 numgbits;
|
||||
/** Region Of Interest shift */
|
||||
OPJ_INT32 roishift;
|
||||
/** precinct width */
|
||||
OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
|
||||
OPJ_UINT32 prcw[J2K_MAXRLVLS];
|
||||
/** precinct height */
|
||||
OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
|
||||
OPJ_UINT32 prch[J2K_MAXRLVLS];
|
||||
/** the dc_level_shift **/
|
||||
OPJ_INT32 m_dc_level_shift;
|
||||
}
|
||||
opj_tccp_t;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* FIXME DOC
|
||||
*/
|
||||
typedef struct opj_mct_data
|
||||
{
|
||||
J2K_MCT_ELEMENT_TYPE m_element_type;
|
||||
J2K_MCT_ARRAY_TYPE m_array_type;
|
||||
OPJ_UINT32 m_index;
|
||||
OPJ_BYTE * m_data;
|
||||
OPJ_UINT32 m_data_size;
|
||||
}
|
||||
opj_mct_data_t;
|
||||
|
||||
/**
|
||||
* FIXME DOC
|
||||
*/
|
||||
typedef struct opj_simple_mcc_decorrelation_data
|
||||
{
|
||||
OPJ_UINT32 m_index;
|
||||
OPJ_UINT32 m_nb_comps;
|
||||
opj_mct_data_t * m_decorrelation_array;
|
||||
opj_mct_data_t * m_offset_array;
|
||||
OPJ_UINT32 m_is_irreversible : 1;
|
||||
}
|
||||
opj_simple_mcc_decorrelation_data_t;
|
||||
|
||||
/**
|
||||
Tile coding parameters :
|
||||
this structure is used to store coding/decoding parameters common to all
|
||||
@@ -284,6 +288,7 @@ typedef struct opj_tcp
|
||||
OPJ_UINT32 m_nb_max_mcc_records;
|
||||
|
||||
|
||||
|
||||
/***** FLAGS *******/
|
||||
/** If ppt == 1 --> there was a PPT marker for the present tile */
|
||||
OPJ_UINT32 ppt : 1;
|
||||
@@ -291,9 +296,6 @@ typedef struct opj_tcp
|
||||
OPJ_UINT32 POC : 1;
|
||||
} opj_tcp_t;
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct opj_encoding_param
|
||||
{
|
||||
/** Digital cinema profile*/
|
||||
@@ -326,9 +328,8 @@ typedef struct opj_decoding_param
|
||||
}
|
||||
opj_decoding_param_t;
|
||||
|
||||
|
||||
/**
|
||||
* Coding parameters
|
||||
Coding parameters
|
||||
*/
|
||||
typedef struct opj_cp
|
||||
{
|
||||
@@ -337,9 +338,9 @@ typedef struct opj_cp
|
||||
/** Rsiz*/
|
||||
OPJ_RSIZ_CAPABILITIES rsiz;
|
||||
/** XTOsiz */
|
||||
OPJ_UINT32 tx0; /* MSD see norm */
|
||||
OPJ_INT32 tx0;
|
||||
/** YTOsiz */
|
||||
OPJ_UINT32 ty0; /* MSD see norm */
|
||||
OPJ_INT32 ty0;
|
||||
/** XTsiz */
|
||||
OPJ_UINT32 tdx;
|
||||
/** YTsiz */
|
||||
@@ -350,30 +351,16 @@ typedef struct opj_cp
|
||||
OPJ_UINT32 tw;
|
||||
/** number of tiles in heigth */
|
||||
OPJ_UINT32 th;
|
||||
|
||||
/** packet header storage original buffer */
|
||||
OPJ_BYTE *ppm_buffer;
|
||||
/** packet header store there for futur use in t2_decode_packet */
|
||||
OPJ_BYTE *ppm_data;
|
||||
/** size of the ppm_data*/
|
||||
OPJ_UINT32 ppm_len;
|
||||
/** size of the ppm_data*/
|
||||
OPJ_UINT32 ppm_data_read;
|
||||
|
||||
OPJ_BYTE *ppm_data_current;
|
||||
|
||||
/** packet header storage original buffer */
|
||||
OPJ_BYTE *ppm_buffer;
|
||||
/** pointer remaining on the first byte of the first header if ppm is used */
|
||||
OPJ_BYTE *ppm_data_first;
|
||||
/** Number of bytes actually stored inside the ppm_data */
|
||||
OPJ_UINT32 ppm_data_size;
|
||||
/** use in case of multiple marker PPM (number of info already store) */
|
||||
OPJ_INT32 ppm_store;
|
||||
/** use in case of multiple marker PPM (case on non-finished previous info) */
|
||||
OPJ_INT32 ppm_previous;
|
||||
|
||||
/** tile coding parameters */
|
||||
opj_tcp_t *tcps;
|
||||
|
||||
union
|
||||
{
|
||||
opj_decoding_param_t m_dec;
|
||||
@@ -385,15 +372,15 @@ typedef struct opj_cp
|
||||
/* UniPG>> */
|
||||
#ifdef USE_JPWL
|
||||
/** enables writing of EPC in MH, thus activating JPWL */
|
||||
OPJ_BOOL epc_on;
|
||||
bool epc_on;
|
||||
/** enables writing of EPB, in case of activated JPWL */
|
||||
OPJ_BOOL epb_on;
|
||||
bool epb_on;
|
||||
/** enables writing of ESD, in case of activated JPWL */
|
||||
OPJ_BOOL esd_on;
|
||||
bool esd_on;
|
||||
/** enables writing of informative techniques of ESD, in case of activated JPWL */
|
||||
OPJ_BOOL info_on;
|
||||
bool info_on;
|
||||
/** enables writing of RED, in case of activated JPWL */
|
||||
OPJ_BOOL red_on;
|
||||
bool red_on;
|
||||
/** error protection method for MH (0,1,16,32,37-128) */
|
||||
int hprot_MH;
|
||||
/** tile number of header protection specification (>=0) */
|
||||
@@ -419,11 +406,11 @@ typedef struct opj_cp
|
||||
/** sensitivity methods for TPHs (-1,0-7) */
|
||||
int sens_TPH[JPWL_MAX_NO_TILESPECS];
|
||||
/** enables JPWL correction at the decoder */
|
||||
OPJ_BOOL correct;
|
||||
bool correct;
|
||||
/** expected number of components at the decoder */
|
||||
int exp_comps;
|
||||
/** maximum number of tiles at the decoder */
|
||||
OPJ_UINT32 max_tiles;
|
||||
int max_tiles;
|
||||
#endif /* USE_JPWL */
|
||||
|
||||
/******** FLAGS *********/
|
||||
@@ -434,7 +421,6 @@ typedef struct opj_cp
|
||||
/* <<UniPG */
|
||||
} opj_cp_t;
|
||||
|
||||
|
||||
typedef struct opj_j2k_dec
|
||||
{
|
||||
/** locate in which part of the codestream the decoder is (main header, tile header, end) */
|
||||
@@ -452,25 +438,6 @@ typedef struct opj_j2k_dec
|
||||
OPJ_UINT32 m_start_tile_y;
|
||||
OPJ_UINT32 m_end_tile_x;
|
||||
OPJ_UINT32 m_end_tile_y;
|
||||
/**
|
||||
* Decoded area set by the user
|
||||
*/
|
||||
OPJ_UINT32 m_DA_x0;
|
||||
OPJ_UINT32 m_DA_y0;
|
||||
OPJ_UINT32 m_DA_x1;
|
||||
OPJ_UINT32 m_DA_y1;
|
||||
|
||||
/** Index of the tile to decode (used in get_tile) */
|
||||
OPJ_INT32 m_tile_ind_to_dec;
|
||||
/** Position of the last SOT marker read */
|
||||
OPJ_OFF_T m_last_sot_read_pos;
|
||||
|
||||
/**
|
||||
* Indicate that the current tile-part is assume as the last tile part of the codestream.
|
||||
* It is useful in the case of PSot is equal to zero. The sot length will be compute in the
|
||||
* SOD reader function. FIXME NOT USED for the moment
|
||||
*/
|
||||
OPJ_BOOL m_last_tile_part;
|
||||
/** to tell that a tile can be decoded. */
|
||||
OPJ_UINT32 m_can_decode : 1;
|
||||
OPJ_UINT32 m_discard_tiles : 1;
|
||||
@@ -481,16 +448,16 @@ typedef struct opj_j2k_dec
|
||||
typedef struct opj_j2k_enc
|
||||
{
|
||||
/** Tile part number, regardless of poc, for each new poc, tp is reset to 1*/
|
||||
OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */
|
||||
OPJ_UINT32 m_current_poc_tile_part_number; // tp_num
|
||||
|
||||
/** Tile part number currently coding, taking into account POC. m_current_tile_part_number holds the total number of tile parts while encoding the last tile part.*/
|
||||
OPJ_UINT32 m_current_tile_part_number; /*cur_tp_num */
|
||||
OPJ_UINT32 m_current_tile_part_number; //cur_tp_num
|
||||
|
||||
/**
|
||||
locate the start position of the TLM marker
|
||||
after encoding the tilepart, a jump (in j2k_write_sod) is done to the TLM marker to store the value of its length.
|
||||
*/
|
||||
OPJ_OFF_T m_tlm_start;
|
||||
OPJ_SIZE_T m_tlm_start;
|
||||
/**
|
||||
* Stores the sizes of the tlm.
|
||||
*/
|
||||
@@ -502,7 +469,7 @@ typedef struct opj_j2k_enc
|
||||
|
||||
/** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/
|
||||
/** used in TLMmarker*/
|
||||
OPJ_UINT32 m_total_tile_parts; /* totnum_tp */
|
||||
OPJ_UINT32 m_total_tile_parts; // totnum_tp
|
||||
|
||||
/* encoded data for a tile */
|
||||
OPJ_BYTE * m_encoded_tile_data;
|
||||
@@ -521,16 +488,12 @@ typedef struct opj_j2k_enc
|
||||
|
||||
|
||||
|
||||
struct opj_tcd;
|
||||
|
||||
/**
|
||||
JPEG-2000 codestream reader/writer
|
||||
*/
|
||||
typedef struct opj_j2k
|
||||
{
|
||||
/* J2K codestream is decoded*/
|
||||
OPJ_BOOL m_is_decoder;
|
||||
|
||||
/* FIXME DOC*/
|
||||
union
|
||||
{
|
||||
opj_j2k_dec_t m_decoder;
|
||||
@@ -538,140 +501,200 @@ typedef struct opj_j2k
|
||||
}
|
||||
m_specific_param;
|
||||
|
||||
/** pointer to the internal/private encoded / decoded image */
|
||||
opj_image_t* m_private_image;
|
||||
/** number of the tile curently concern by coding/decoding */
|
||||
OPJ_UINT32 m_current_tile_number;
|
||||
|
||||
/* pointer to the output image (decoded)*/
|
||||
opj_image_t* m_output_image;
|
||||
/** pointer to the encoded / decoded image */
|
||||
opj_image_t *m_image;
|
||||
|
||||
/** Coding parameters */
|
||||
opj_cp_t m_cp;
|
||||
|
||||
/** the list of procedures to exec **/
|
||||
opj_procedure_list_t * m_procedure_list;
|
||||
struct opj_procedure_list * m_procedure_list;
|
||||
|
||||
/** the list of validation procedures to follow to make sure the code is valid **/
|
||||
opj_procedure_list_t * m_validation_list;
|
||||
struct opj_procedure_list * m_validation_list;
|
||||
|
||||
/** helper used to write the index file */
|
||||
opj_codestream_index_t *cstr_index;
|
||||
|
||||
/** number of the tile curently concern by coding/decoding */
|
||||
OPJ_UINT32 m_current_tile_number;
|
||||
opj_codestream_info_t *cstr_info;
|
||||
|
||||
/** the current tile coder/decoder **/
|
||||
struct opj_tcd * m_tcd;
|
||||
|
||||
OPJ_UINT32 m_is_decoder : 1;
|
||||
|
||||
}
|
||||
opj_j2k_t;
|
||||
|
||||
|
||||
|
||||
|
||||
/** @name Exported functions */
|
||||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
Setup the decoder decoding parameters using user parameters.
|
||||
Decoding parameters are returned in j2k->cp.
|
||||
@param j2k J2K decompressor handle
|
||||
@param parameters decompression parameters
|
||||
*/
|
||||
void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
|
||||
|
||||
/**
|
||||
* Creates a J2K compression structure
|
||||
* Creates a J2K decompression structure.
|
||||
*
|
||||
* @return Returns a handle to a J2K compressor if successful, returns NULL otherwise
|
||||
* @return a handle to a J2K decompressor if successful, NULL otherwise.
|
||||
*/
|
||||
opj_j2k_t* opj_j2k_create_compress(void);
|
||||
|
||||
|
||||
void opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
|
||||
opj_cparameters_t *parameters,
|
||||
opj_image_t *image,
|
||||
opj_event_mgr_t * p_manager);
|
||||
|
||||
/**
|
||||
Converts an enum type progression order to string type
|
||||
*/
|
||||
char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* Ends the decompression procedures and possibiliy add data to be read after the
|
||||
* codestream.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_end_decompress(opj_j2k_t *j2k,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager);
|
||||
|
||||
/**
|
||||
* Reads a jpeg2000 codestream header structure.
|
||||
*
|
||||
* @param p_stream the stream to read data from.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_manager the user event manager.
|
||||
*
|
||||
* @return true if the box is valid.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_read_header( opj_stream_private_t *p_stream,
|
||||
opj_j2k_t* p_j2k,
|
||||
opj_image_t** p_image,
|
||||
opj_event_mgr_t* p_manager );
|
||||
|
||||
opj_j2k_t* j2k_create_decompress();
|
||||
|
||||
/**
|
||||
* Destroys a jpeg2000 codec.
|
||||
*
|
||||
* @param p_j2k the jpeg20000 structure to destroy.
|
||||
*/
|
||||
void opj_j2k_destroy (opj_j2k_t *p_j2k);
|
||||
void j2k_destroy (opj_j2k_t *p_j2k);
|
||||
|
||||
/**
|
||||
* Destroys a codestream index structure.
|
||||
* Starts a compression scheme, i.e. validates the codec parameters, writes the header.
|
||||
*
|
||||
* @param p_cstr_ind the codestream index parameter to destroy.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param cio the stream object.
|
||||
* @param p_manager the user event manager.
|
||||
*
|
||||
* @return true if the codec is valid.
|
||||
*/
|
||||
void j2k_destroy_cstr_index (opj_codestream_index_t *p_cstr_ind);
|
||||
bool j2k_start_compress(
|
||||
opj_j2k_t *p_j2k,
|
||||
struct opj_stream_private *cio,
|
||||
struct opj_image * p_image,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
/**
|
||||
* Ends the compression procedures and possibiliy add data to be read after the
|
||||
* codestream.
|
||||
*/
|
||||
bool j2k_end_compress(opj_j2k_t *p_j2k, struct opj_stream_private *cio, struct opj_event_mgr * p_manager);
|
||||
|
||||
/**
|
||||
* Sets up the decoder decoding parameters using user parameters.
|
||||
* Decoding parameters are stored in j2k->cp.
|
||||
*
|
||||
* @param p_j2k J2K codec
|
||||
* @param p_parameters decompression parameters
|
||||
* @deprecated
|
||||
*/
|
||||
void j2k_setup_decoder(
|
||||
opj_j2k_t *p_j2k,
|
||||
struct opj_dparameters *p_parameters
|
||||
);
|
||||
/**
|
||||
* Reads a jpeg2000 codestream header structure.
|
||||
*
|
||||
* @param cio the stream to read data from.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_manager the user event manager.
|
||||
*
|
||||
* @return true if the box is valid.
|
||||
*/
|
||||
bool j2k_read_header(
|
||||
opj_j2k_t *p_j2k,
|
||||
struct opj_image ** p_image,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
OPJ_INT32 * p_tile_y0,
|
||||
OPJ_UINT32 * p_tile_width,
|
||||
OPJ_UINT32 * p_tile_height,
|
||||
OPJ_UINT32 * p_nb_tiles_x,
|
||||
OPJ_UINT32 * p_nb_tiles_y,
|
||||
struct opj_stream_private *cio,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
/**
|
||||
Decode an image from a JPEG-2000 codestream
|
||||
@param j2k J2K decompressor handle
|
||||
@param cio Input buffer stream
|
||||
@param cstr_info Codestream information structure if required, NULL otherwise
|
||||
@return Returns a decoded image if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_image_t* j2k_decode(opj_j2k_t *j2k, struct opj_stream_private *cio, struct opj_event_mgr * p_manager);
|
||||
|
||||
/**
|
||||
* Ends the decompression procedures and possibiliy add data to be read after the
|
||||
* codestream.
|
||||
*/
|
||||
bool j2k_end_decompress(opj_j2k_t *j2k, struct opj_stream_private *cio, struct opj_event_mgr * p_manager);
|
||||
|
||||
/**
|
||||
Decode an image form a JPT-stream (JPEG 2000, JPIP)
|
||||
@param j2k J2K decompressor handle
|
||||
@param cio Input buffer stream
|
||||
@param cstr_info Codestream information structure if required, NULL otherwise
|
||||
@return Returns a decoded image if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, struct opj_stream_private *cio, struct opj_codestream_info *cstr_info);
|
||||
|
||||
/**
|
||||
Creates a J2K compression structure
|
||||
@param cinfo Codec context info
|
||||
@return Returns a handle to a J2K compressor if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_j2k_t* j2k_create_compress();
|
||||
|
||||
/**
|
||||
Setup the encoder parameters using the current image and using user parameters.
|
||||
Coding parameters are returned in j2k->cp.
|
||||
@param j2k J2K compressor handle
|
||||
@param parameters compression parameters
|
||||
@param image input filled image
|
||||
*/
|
||||
void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image, struct opj_event_mgr * p_manager);
|
||||
|
||||
/**
|
||||
* Writes a tile.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
bool j2k_write_tile (
|
||||
opj_j2k_t * p_j2k,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
struct opj_stream_private *p_stream,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
|
||||
/**
|
||||
* Converts an enum type progression order to string type.
|
||||
*
|
||||
* @param prg_order the progression order to get.
|
||||
*
|
||||
* @return the string representation of the gicen progression order.
|
||||
*/
|
||||
const char * j2k_convert_progression_order(OPJ_PROG_ORDER prg_order);
|
||||
|
||||
|
||||
/**
|
||||
* Encodes an image into a JPEG-2000 codestream
|
||||
*/
|
||||
bool j2k_encode(
|
||||
opj_j2k_t * p_j2k,
|
||||
struct opj_stream_private *cio,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
bool j2k_setup_mct_encoding (opj_tcp_t * p_tcp,opj_image_t * p_image);
|
||||
|
||||
/**
|
||||
* Decode tile data.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_tile_index
|
||||
* @param p_data FIXME DOC
|
||||
* @param p_data_size FIXME DOC
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k,
|
||||
bool j2k_decode_tile (
|
||||
opj_j2k_t * p_j2k,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager );
|
||||
|
||||
struct opj_stream_private *p_stream,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
/**
|
||||
* Reads a tile header.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_tile_index FIXME DOC
|
||||
* @param p_data_size FIXME DOC
|
||||
* @param p_tile_x0 FIXME DOC
|
||||
* @param p_tile_y0 FIXME DOC
|
||||
* @param p_tile_x1 FIXME DOC
|
||||
* @param p_tile_y1 FIXME DOC
|
||||
* @param p_nb_comps FIXME DOC
|
||||
* @param p_go_on FIXME DOC
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_read_tile_header ( opj_j2k_t * p_j2k,
|
||||
bool j2k_read_tile_header (
|
||||
opj_j2k_t * p_j2k,
|
||||
OPJ_UINT32 * p_tile_index,
|
||||
OPJ_UINT32 * p_data_size,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
@@ -679,158 +702,36 @@ OPJ_BOOL opj_j2k_read_tile_header ( opj_j2k_t * p_j2k,
|
||||
OPJ_INT32 * p_tile_x1,
|
||||
OPJ_INT32 * p_tile_y1,
|
||||
OPJ_UINT32 * p_nb_comps,
|
||||
OPJ_BOOL * p_go_on,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager );
|
||||
|
||||
|
||||
bool * p_go_on,
|
||||
struct opj_stream_private *p_stream,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
/**
|
||||
* Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
|
||||
*
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_start_x the left position of the rectangle to decode (in image coordinates).
|
||||
* @param p_start_y the up position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_x the right position of the rectangle to decode (in image coordinates).
|
||||
* @param p_start_y the up position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
|
||||
* @param p_manager the user event manager
|
||||
*
|
||||
* @return true if the area could be set.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
|
||||
opj_image_t* p_image,
|
||||
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
|
||||
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
|
||||
opj_event_mgr_t * p_manager );
|
||||
bool j2k_set_decode_area(
|
||||
opj_j2k_t *p_j2k,
|
||||
OPJ_INT32 p_start_x,
|
||||
OPJ_INT32 p_start_y,
|
||||
OPJ_INT32 p_end_x,
|
||||
OPJ_INT32 p_end_y,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a J2K decompression structure.
|
||||
*
|
||||
* @return a handle to a J2K decompressor if successful, NULL otherwise.
|
||||
*/
|
||||
opj_j2k_t* opj_j2k_create_decompress(void);
|
||||
void j2k_dump_image(FILE *fd, opj_image_t * img);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
/**
|
||||
* Dump some elements from the J2K decompression structure .
|
||||
*
|
||||
*@param p_j2k the jpeg2000 codec.
|
||||
*@param flag flag to describe what elments are dump.
|
||||
*@param out_stream output stream where dump the elements.
|
||||
*
|
||||
*/
|
||||
void j2k_dump (opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Dump an image header structure.
|
||||
*
|
||||
*@param image the image header to dump.
|
||||
*@param dev_dump_flag flag to describe if we are in the case of this function is use outside j2k_dump function
|
||||
*@param out_stream output stream where dump the elements.
|
||||
*/
|
||||
void j2k_dump_image_header(opj_image_t* image, OPJ_BOOL dev_dump_flag, FILE* out_stream);
|
||||
|
||||
/**
|
||||
* Dump a component image header structure.
|
||||
*
|
||||
*@param comp the component image header to dump.
|
||||
*@param dev_dump_flag flag to describe if we are in the case of this function is use outside j2k_dump function
|
||||
*@param out_stream output stream where dump the elements.
|
||||
*/
|
||||
void j2k_dump_image_comp_header(opj_image_comp_t* comp, OPJ_BOOL dev_dump_flag, FILE* out_stream);
|
||||
|
||||
/**
|
||||
* Get the codestream info from a JPEG2000 codec.
|
||||
*
|
||||
*@param p_j2k the component image header to dump.
|
||||
*
|
||||
*@return the codestream information extract from the jpg2000 codec
|
||||
*/
|
||||
opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k);
|
||||
|
||||
/**
|
||||
* Get the codestream index from a JPEG2000 codec.
|
||||
*
|
||||
*@param p_j2k the component image header to dump.
|
||||
*
|
||||
*@return the codestream index extract from the jpg2000 codec
|
||||
*/
|
||||
opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k);
|
||||
|
||||
/**
|
||||
* Decode an image from a JPEG-2000 codestream
|
||||
* @param j2k J2K decompressor handle
|
||||
* @param p_stream FIXME DOC
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_manager FIXME DOC
|
||||
* @return FIXME DOC
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_decode(opj_j2k_t *j2k,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_image_t *p_image,
|
||||
opj_event_mgr_t *p_manager);
|
||||
|
||||
|
||||
OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_image_t* p_image,
|
||||
opj_event_mgr_t * p_manager,
|
||||
OPJ_UINT32 tile_index );
|
||||
|
||||
OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k,
|
||||
OPJ_UINT32 res_factor,
|
||||
opj_event_mgr_t * p_manager);
|
||||
|
||||
|
||||
/**
|
||||
* Writes a tile.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_tile_index FIXME DOC
|
||||
* @param p_data FIXME DOC
|
||||
* @param p_data_size FIXME DOC
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_write_tile ( opj_j2k_t * p_j2k,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_event_mgr_t * p_manager );
|
||||
|
||||
/**
|
||||
* Encodes an image into a JPEG-2000 codestream
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k,
|
||||
opj_stream_private_t *cio,
|
||||
opj_event_mgr_t * p_manager );
|
||||
|
||||
/**
|
||||
* Starts a compression scheme, i.e. validates the codec parameters, writes the header.
|
||||
*
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_stream the stream object.
|
||||
* @param p_image FIXME DOC
|
||||
* @param p_manager the user event manager.
|
||||
*
|
||||
* @return true if the codec is valid.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
|
||||
opj_stream_private_t *p_stream,
|
||||
opj_image_t * p_image,
|
||||
opj_event_mgr_t * p_manager);
|
||||
|
||||
/**
|
||||
* Ends the compression procedures and possibiliy add data to be read after the
|
||||
* codestream.
|
||||
*/
|
||||
OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k,
|
||||
opj_stream_private_t *cio,
|
||||
opj_event_mgr_t * p_manager);
|
||||
|
||||
OPJ_BOOL opj_j2k_setup_mct_encoding (opj_tcp_t * p_tcp, opj_image_t * p_image);
|
||||
|
||||
/*@}*/
|
||||
|
||||
#endif /* __J2K_H */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -24,18 +24,21 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
/*#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/times.h>
|
||||
#endif /* _WIN32 */
|
||||
#include "opj_includes.h"
|
||||
*/
|
||||
#endif /* WIN32 */
|
||||
#include "j2k_lib.h"
|
||||
|
||||
double OPJ_CALLCONV opj_clock(void) {
|
||||
#ifdef _WIN32
|
||||
/* _WIN32: use QueryPerformance (very accurate) */
|
||||
|
||||
OPJ_FLOAT64 opj_clock(void) {
|
||||
#if 0
|
||||
#ifdef WIN32
|
||||
/* WIN32: use QueryPerformance (very accurate) */
|
||||
LARGE_INTEGER freq , t ;
|
||||
/* freq is the clock speed of the CPU */
|
||||
QueryPerformanceFrequency(&freq) ;
|
||||
@@ -55,5 +58,8 @@ double OPJ_CALLCONV opj_clock(void) {
|
||||
/* (2b) More precisely! Get the microseconds part ! */
|
||||
return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
The functions in J2K_LIB.C are internal utilities mainly used for timing.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
/** @defgroup MISC MISC - Miscellaneous internal functions */
|
||||
/*@{*/
|
||||
|
||||
@@ -43,7 +43,7 @@ The functions in J2K_LIB.C are internal utilities mainly used for timing.
|
||||
Difference in successive opj_clock() calls tells you the elapsed time
|
||||
@return Returns time in seconds
|
||||
*/
|
||||
OPJ_API double OPJ_CALLCONV opj_clock(void);
|
||||
OPJ_FLOAT64 opj_clock(void);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
2237
libopenjpeg/jp2.c
Normal file
2237
libopenjpeg/jp2.c
Normal file
File diff suppressed because it is too large
Load Diff
342
libopenjpeg/jp2.h
Normal file
342
libopenjpeg/jp2.h
Normal file
@@ -0,0 +1,342 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef __JP2_H
|
||||
#define __JP2_H
|
||||
/**
|
||||
@file jp2.h
|
||||
@brief The JPEG-2000 file format Reader/Writer (JP2)
|
||||
|
||||
*/
|
||||
#include "openjpeg.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/**********************************************************************************
|
||||
********************************* FORWARD DECLARATIONS ***************************
|
||||
**********************************************************************************/
|
||||
struct opj_j2k;
|
||||
struct opj_procedure_list;
|
||||
struct opj_event_mgr;
|
||||
struct opj_stream_private;
|
||||
struct opj_dparameters;
|
||||
struct opj_cparameters;
|
||||
|
||||
/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
|
||||
/*@{*/
|
||||
|
||||
#define JPIP_JPIP 0x6a706970
|
||||
|
||||
#define JP2_JP 0x6a502020 /**< JPEG 2000 signature box */
|
||||
#define JP2_FTYP 0x66747970 /**< File type box */
|
||||
#define JP2_JP2H 0x6a703268 /**< JP2 header box */
|
||||
#define JP2_IHDR 0x69686472 /**< Image header box */
|
||||
#define JP2_COLR 0x636f6c72 /**< Colour specification box */
|
||||
#define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */
|
||||
#define JP2_URL 0x75726c20 /**< URL box */
|
||||
#define JP2_DBTL 0x6474626c /**< ??? */
|
||||
#define JP2_BPCC 0x62706363 /**< Bits per component box */
|
||||
#define JP2_JP2 0x6a703220 /**< File type fields */
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
JP2_STATE_NONE = 0x0,
|
||||
JP2_STATE_SIGNATURE = 0x1,
|
||||
JP2_STATE_FILE_TYPE = 0x2,
|
||||
JP2_STATE_HEADER = 0x4,
|
||||
JP2_STATE_CODESTREAM = 0x8,
|
||||
JP2_STATE_END_CODESTREAM = 0x10,
|
||||
JP2_STATE_UNKNOWN = 0x80000000
|
||||
}
|
||||
JP2_STATE;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
JP2_IMG_STATE_NONE = 0x0,
|
||||
JP2_IMG_STATE_UNKNOWN = 0x80000000
|
||||
}
|
||||
JP2_IMG_STATE;
|
||||
|
||||
/**
|
||||
JP2 component
|
||||
*/
|
||||
typedef struct opj_jp2_comps
|
||||
{
|
||||
unsigned int depth;
|
||||
int sgnd;
|
||||
unsigned int bpcc;
|
||||
}
|
||||
opj_jp2_comps_t;
|
||||
|
||||
/**
|
||||
JPEG-2000 file format reader/writer
|
||||
*/
|
||||
typedef struct opj_jp2
|
||||
{
|
||||
/** handle to the J2K codec */
|
||||
struct opj_j2k *j2k;
|
||||
/** list of validation procedures */
|
||||
struct opj_procedure_list * m_validation_list;
|
||||
/** list of execution procedures */
|
||||
struct opj_procedure_list * m_procedure_list;
|
||||
|
||||
/* width of image */
|
||||
unsigned int w;
|
||||
/* height of image */
|
||||
unsigned int h;
|
||||
/* number of components in the image */
|
||||
unsigned int numcomps;
|
||||
unsigned int bpc;
|
||||
unsigned int C;
|
||||
unsigned int UnkC;
|
||||
unsigned int IPR;
|
||||
unsigned int meth;
|
||||
unsigned int approx;
|
||||
unsigned int enumcs;
|
||||
unsigned int precedence;
|
||||
unsigned int brand;
|
||||
unsigned int minversion;
|
||||
unsigned int numcl;
|
||||
unsigned int *cl;
|
||||
opj_jp2_comps_t *comps;
|
||||
unsigned int j2k_codestream_offset;
|
||||
unsigned int jp2_state;
|
||||
unsigned int jp2_img_state;
|
||||
|
||||
}
|
||||
opj_jp2_t;
|
||||
|
||||
/**
|
||||
JP2 Box
|
||||
*/
|
||||
typedef struct opj_jp2_box
|
||||
{
|
||||
unsigned int length;
|
||||
unsigned int type;
|
||||
}
|
||||
opj_jp2_box_t;
|
||||
|
||||
typedef struct opj_jp2_header_handler
|
||||
{
|
||||
/* marker value */
|
||||
int id;
|
||||
/* action linked to the marker */
|
||||
bool (*handler) (opj_jp2_t *jp2,unsigned char * p_header_data, unsigned int p_header_size,struct opj_event_mgr * p_manager);
|
||||
}
|
||||
opj_jp2_header_handler_t;
|
||||
|
||||
|
||||
typedef struct opj_jp2_img_header_writer_handler
|
||||
{
|
||||
/* action to perform */
|
||||
unsigned char* (*handler) (opj_jp2_t *jp2, unsigned int * p_data_size);
|
||||
/* result of the action : data */
|
||||
unsigned char * m_data;
|
||||
/* size of data */
|
||||
unsigned int m_size;
|
||||
}
|
||||
opj_jp2_img_header_writer_handler_t;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** @name Exported functions */
|
||||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Creates a jpeg2000 file decompressor.
|
||||
*
|
||||
* @return an empty jpeg2000 file codec.
|
||||
*/
|
||||
opj_jp2_t* jp2_create (bool p_is_decoder);
|
||||
|
||||
/**
|
||||
Destroy a JP2 decompressor handle
|
||||
@param jp2 JP2 decompressor handle to destroy
|
||||
*/
|
||||
void jp2_destroy(opj_jp2_t *jp2);
|
||||
|
||||
/**
|
||||
Setup the decoder decoding parameters using user parameters.
|
||||
Decoding parameters are returned in jp2->j2k->cp.
|
||||
@param jp2 JP2 decompressor handle
|
||||
@param parameters decompression parameters
|
||||
*/
|
||||
void jp2_setup_decoder(opj_jp2_t *jp2, struct opj_dparameters *parameters);
|
||||
|
||||
/**
|
||||
* Decode an image from a JPEG-2000 file stream
|
||||
* @param jp2 JP2 decompressor handle
|
||||
* @param cio Input buffer stream
|
||||
* @param cstr_info Codestream information structure if required, NULL otherwise
|
||||
* @return Returns a decoded image if successful, returns NULL otherwise
|
||||
*/
|
||||
struct opj_image* opj_jp2_decode(opj_jp2_t *jp2, struct opj_stream_private *cio, struct opj_event_mgr * p_manager);
|
||||
/**
|
||||
Setup the encoder parameters using the current image and using user parameters.
|
||||
Coding parameters are returned in jp2->j2k->cp.
|
||||
@param jp2 JP2 compressor handle
|
||||
@param parameters compression parameters
|
||||
@param image input filled image
|
||||
*/
|
||||
void jp2_setup_encoder(opj_jp2_t *jp2, struct opj_cparameters *parameters, struct opj_image *image,struct opj_event_mgr * p_manager);
|
||||
|
||||
/**
|
||||
* Starts a compression scheme, i.e. validates the codec parameters, writes the header.
|
||||
*
|
||||
* @param jp2 the jpeg2000 file codec.
|
||||
* @param cio the stream object.
|
||||
*
|
||||
* @return true if the codec is valid.
|
||||
*/
|
||||
bool jp2_start_compress(opj_jp2_t *jp2, struct opj_stream_private *cio,struct opj_image * p_image,struct opj_event_mgr * p_manager);
|
||||
|
||||
/**
|
||||
* Ends the compression procedures and possibiliy add data to be read after the
|
||||
* codestream.
|
||||
*/
|
||||
bool jp2_end_compress(opj_jp2_t *jp2, struct opj_stream_private *cio, struct opj_event_mgr * p_manager);
|
||||
|
||||
/**
|
||||
Encode an image into a JPEG-2000 file stream
|
||||
@param jp2 JP2 compressor handle
|
||||
@param cio Output buffer stream
|
||||
@param image Image to encode
|
||||
@param cstr_info Codestream information structure if required, NULL otherwise
|
||||
@return Returns true if successful, returns false otherwise
|
||||
*/
|
||||
bool opj_jp2_encode(opj_jp2_t *jp2, struct opj_stream_private *cio, struct opj_event_mgr * p_manager);
|
||||
|
||||
/**
|
||||
* Reads a jpeg2000 file header structure.
|
||||
*
|
||||
* @param cio the stream to read data from.
|
||||
* @param jp2 the jpeg2000 file header structure.
|
||||
* @param p_manager the user event manager.
|
||||
*
|
||||
* @return true if the box is valid.
|
||||
*/
|
||||
bool jp2_read_header(
|
||||
opj_jp2_t *jp2,
|
||||
struct opj_image ** p_image,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
OPJ_INT32 * p_tile_y0,
|
||||
OPJ_UINT32 * p_tile_width,
|
||||
OPJ_UINT32 * p_tile_height,
|
||||
OPJ_UINT32 * p_nb_tiles_x,
|
||||
OPJ_UINT32 * p_nb_tiles_y,
|
||||
struct opj_stream_private *cio,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
/**
|
||||
* Ends the decompression procedures and possibiliy add data to be read after the
|
||||
* codestream.
|
||||
*/
|
||||
bool jp2_end_decompress(opj_jp2_t *jp2, struct opj_stream_private *cio, struct opj_event_mgr * p_manager);
|
||||
|
||||
/**
|
||||
* Writes a tile.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
bool jp2_write_tile (
|
||||
opj_jp2_t *p_jp2,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
struct opj_stream_private *p_stream,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
/**
|
||||
* Decode tile data.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
bool opj_jp2_decode_tile (
|
||||
opj_jp2_t * p_jp2,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
struct opj_stream_private *p_stream,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
/**
|
||||
* Reads a tile header.
|
||||
* @param p_j2k the jpeg2000 codec.
|
||||
* @param p_stream the stream to write data to.
|
||||
* @param p_manager the user event manager.
|
||||
*/
|
||||
bool jp2_read_tile_header (
|
||||
opj_jp2_t * p_j2k,
|
||||
OPJ_UINT32 * p_tile_index,
|
||||
OPJ_UINT32 * p_data_size,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
OPJ_INT32 * p_tile_y0,
|
||||
OPJ_INT32 * p_tile_x1,
|
||||
OPJ_INT32 * p_tile_y1,
|
||||
OPJ_UINT32 * p_nb_comps,
|
||||
bool * p_go_on,
|
||||
struct opj_stream_private *p_stream,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
/**
|
||||
* Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
|
||||
*
|
||||
* @param p_jp2 the jpeg2000 codec.
|
||||
* @param p_end_x the right position of the rectangle to decode (in image coordinates).
|
||||
* @param p_start_y the up position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
|
||||
* @param p_manager the user event manager
|
||||
*
|
||||
* @return true if the area could be set.
|
||||
*/
|
||||
bool jp2_set_decode_area(
|
||||
opj_jp2_t *p_jp2,
|
||||
OPJ_INT32 p_start_x,
|
||||
OPJ_INT32 p_start_y,
|
||||
OPJ_INT32 p_end_x,
|
||||
OPJ_INT32 p_end_y,
|
||||
struct opj_event_mgr * p_manager
|
||||
);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
/*@}*/
|
||||
|
||||
#endif /* __JP2_H */
|
||||
|
||||
249
libopenjpeg/jpt.c
Normal file
249
libopenjpeg/jpt.c
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "jpt.h"
|
||||
#include "openjpeg.h"
|
||||
#include "cio.h"
|
||||
#include "event.h"
|
||||
/*
|
||||
* Read the information contains in VBAS [JPP/JPT stream message header]
|
||||
* Store information (7 bits) in value
|
||||
* @param p_cio the stream to read from.
|
||||
* @param p_value the data to update
|
||||
* @return the nb of bytes read or -1 if an io error occurred.
|
||||
*/
|
||||
bool jpt_read_VBAS_info(opj_stream_private_t * p_cio, OPJ_UINT32 * p_nb_bytes_read, OPJ_UINT32 * p_value, opj_event_mgr_t * p_manager)
|
||||
{
|
||||
OPJ_BYTE l_elmt;
|
||||
OPJ_UINT32 l_nb_bytes_read = 0;
|
||||
|
||||
// read data till the MSB of the current byte is 1.
|
||||
// concatenate 7 bits of data, last bit is finish flag
|
||||
|
||||
// read data from the stream
|
||||
|
||||
if
|
||||
(opj_stream_read_data(p_cio,&l_elmt,1,p_manager) != 1)
|
||||
{
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Error trying to read a byte of data.\n");
|
||||
return false;
|
||||
}
|
||||
++l_nb_bytes_read;
|
||||
|
||||
// is the MSB equal to 1 ?
|
||||
while
|
||||
(l_elmt & 0x80)
|
||||
{
|
||||
// concatenate 7 bits of data, last bit is finish flag
|
||||
*p_value = (*p_value << 7) | (l_elmt & 0x7f);
|
||||
if
|
||||
(opj_stream_read_data(p_cio,&l_elmt,1,p_manager) != 1)
|
||||
{
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Error trying to read a byte of data.\n");
|
||||
return false;
|
||||
}
|
||||
++l_nb_bytes_read;
|
||||
}
|
||||
// concatenate 7 bits of data, last bit is finish flag
|
||||
*p_value = (*p_value << 7) | (l_elmt & 0x7f);
|
||||
* p_nb_bytes_read = l_nb_bytes_read;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the value of the message header structure
|
||||
*
|
||||
*/
|
||||
void jpt_init_msg_header(opj_jpt_msg_header_t * header)
|
||||
{
|
||||
header->Id = 0; /* In-class Identifier */
|
||||
header->last_byte = 0; /* Last byte information */
|
||||
header->Class_Id = 0; /* Class Identifier */
|
||||
header->CSn_Id = 0; /* CSn : index identifier */
|
||||
header->Msg_offset = 0; /* Message offset */
|
||||
header->Msg_length = 0; /* Message length */
|
||||
header->Layer_nb = 0; /* Auxiliary for JPP case */
|
||||
}
|
||||
|
||||
/*
|
||||
* Re-initialize the value of the message header structure
|
||||
*
|
||||
* Only parameters always present in message header
|
||||
*
|
||||
*/
|
||||
void jpt_reinit_msg_header(opj_jpt_msg_header_t * header)
|
||||
{
|
||||
header->Id = 0; /* In-class Identifier */
|
||||
header->last_byte = 0; /* Last byte information */
|
||||
header->Msg_offset = 0; /* Message offset */
|
||||
header->Msg_length = 0; /* Message length */
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the message header for a JPP/JPT - stream
|
||||
*
|
||||
*/
|
||||
bool jpt_read_msg_header(opj_stream_private_t *cio, opj_jpt_msg_header_t *header, OPJ_UINT32 * p_nb_bytes_read, opj_event_mgr_t * p_manager)
|
||||
{
|
||||
OPJ_BYTE elmt, Class = 0, CSn = 0;
|
||||
OPJ_UINT32 l_nb_bytes_read = 0;
|
||||
OPJ_UINT32 l_last_nb_bytes_read;
|
||||
|
||||
|
||||
jpt_reinit_msg_header(header);
|
||||
|
||||
/* ------------- */
|
||||
/* VBAS : Bin-ID */
|
||||
/* ------------- */
|
||||
if
|
||||
(opj_stream_read_data(cio,&elmt,1,p_manager) != 1)
|
||||
{
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Forbidden value encounter in message header !!\n");
|
||||
return false;
|
||||
}
|
||||
++l_nb_bytes_read;
|
||||
|
||||
/* See for Class and CSn */
|
||||
switch ((elmt >> 5) & 0x03)
|
||||
{
|
||||
case 0:
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Error trying to read a byte of data!!!\n");
|
||||
break;
|
||||
case 1:
|
||||
Class = 0;
|
||||
CSn = 0;
|
||||
break;
|
||||
case 2:
|
||||
Class = 1;
|
||||
CSn = 0;
|
||||
break;
|
||||
case 3:
|
||||
Class = 1;
|
||||
CSn = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */
|
||||
if
|
||||
(((elmt >> 4) & 0x01) == 1)
|
||||
{
|
||||
header->last_byte = 1;
|
||||
}
|
||||
|
||||
/* In-class identifier */
|
||||
header->Id |= (elmt & 0x0f);
|
||||
if
|
||||
((elmt >> 7) == 1)
|
||||
{
|
||||
l_last_nb_bytes_read = 0;
|
||||
if
|
||||
(! jpt_read_VBAS_info(cio, &l_last_nb_bytes_read, &(header->Id), p_manager))
|
||||
{
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Error trying to read a byte of data!!!\n");
|
||||
return false;
|
||||
}
|
||||
l_nb_bytes_read += l_last_nb_bytes_read;
|
||||
}
|
||||
|
||||
/* ------------ */
|
||||
/* VBAS : Class */
|
||||
/* ------------ */
|
||||
if (Class == 1)
|
||||
{
|
||||
header->Class_Id = 0;
|
||||
l_last_nb_bytes_read = 0;
|
||||
if
|
||||
(! jpt_read_VBAS_info(cio, &l_last_nb_bytes_read, &(header->Class_Id), p_manager))
|
||||
{
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Error trying to read a byte of data!!!\n");
|
||||
return false;
|
||||
}
|
||||
l_nb_bytes_read += l_last_nb_bytes_read;
|
||||
}
|
||||
|
||||
/* ---------- */
|
||||
/* VBAS : CSn */
|
||||
/* ---------- */
|
||||
if (CSn == 1)
|
||||
{
|
||||
header->CSn_Id = 0;
|
||||
l_last_nb_bytes_read = 0;
|
||||
if
|
||||
(! jpt_read_VBAS_info(cio, &l_last_nb_bytes_read, &(header->CSn_Id), p_manager))
|
||||
{
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Error trying to read a byte of data!!!\n");
|
||||
return false;
|
||||
}
|
||||
l_nb_bytes_read += l_last_nb_bytes_read;
|
||||
}
|
||||
|
||||
/* ----------------- */
|
||||
/* VBAS : Msg_offset */
|
||||
/* ----------------- */
|
||||
l_last_nb_bytes_read = 0;
|
||||
if
|
||||
(! jpt_read_VBAS_info(cio, &l_last_nb_bytes_read, &(header->Msg_offset), p_manager))
|
||||
{
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Error trying to read a byte of data!!!\n");
|
||||
return false;
|
||||
}
|
||||
l_nb_bytes_read += l_last_nb_bytes_read;
|
||||
|
||||
/* ----------------- */
|
||||
/* VBAS : Msg_length */
|
||||
/* ----------------- */
|
||||
l_last_nb_bytes_read = 0;
|
||||
if
|
||||
(! jpt_read_VBAS_info(cio, &l_last_nb_bytes_read, &(header->Msg_length), p_manager))
|
||||
{
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Error trying to read a byte of data!!!\n");
|
||||
return false;
|
||||
}
|
||||
l_nb_bytes_read += l_last_nb_bytes_read;
|
||||
|
||||
/* ---------- */
|
||||
/* VBAS : Aux */
|
||||
/* ---------- */
|
||||
if ((header->Class_Id & 0x01) == 1)
|
||||
{
|
||||
header->Layer_nb = 0;
|
||||
if
|
||||
(! jpt_read_VBAS_info(cio, &l_last_nb_bytes_read, &(header->Layer_nb), p_manager))
|
||||
{
|
||||
opj_event_msg(p_manager, EVT_ERROR, "Error trying to read a byte of data!!!\n");
|
||||
return false;
|
||||
}
|
||||
l_nb_bytes_read += l_last_nb_bytes_read;
|
||||
}
|
||||
* p_nb_bytes_read = l_nb_bytes_read;
|
||||
return true;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,25 +36,28 @@
|
||||
|
||||
JPT-stream functions are implemented in J2K.C.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
struct opj_stream_private;
|
||||
struct opj_event_mgr;
|
||||
/**
|
||||
Message Header JPT stream structure
|
||||
*/
|
||||
typedef struct opj_jpt_msg_header {
|
||||
typedef struct opj_jpt_msg_header
|
||||
{
|
||||
/** In-class Identifier */
|
||||
unsigned int Id;
|
||||
OPJ_UINT32 Id;
|
||||
/** Last byte information */
|
||||
unsigned int last_byte;
|
||||
OPJ_UINT32 last_byte;
|
||||
/** Class Identifier */
|
||||
unsigned int Class_Id;
|
||||
OPJ_UINT32 Class_Id;
|
||||
/** CSn : index identifier */
|
||||
unsigned int CSn_Id;
|
||||
OPJ_UINT32 CSn_Id;
|
||||
/** Message offset */
|
||||
unsigned int Msg_offset;
|
||||
OPJ_UINT32 Msg_offset;
|
||||
/** Message length */
|
||||
unsigned int Msg_length;
|
||||
OPJ_UINT32 Msg_length;
|
||||
/** Auxiliary for JPP case */
|
||||
unsigned int Layer_nb;
|
||||
OPJ_UINT32 Layer_nb;
|
||||
} opj_jpt_msg_header_t;
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
@@ -65,11 +69,15 @@ Initialize the value of the message header structure
|
||||
void jpt_init_msg_header(opj_jpt_msg_header_t * header);
|
||||
|
||||
/**
|
||||
Read the message header for a JPP/JPT - stream
|
||||
@param cinfo Codec context info
|
||||
@param cio CIO handle
|
||||
@param header Message header structure
|
||||
* Read the message header for a JPP/JPT - stream
|
||||
* @param p_cio stream handle
|
||||
* @param header JPT Message header structure
|
||||
* @param p_manager user event manager to display nice messages.
|
||||
*/
|
||||
void jpt_read_msg_header(opj_common_ptr cinfo, opj_cio_t *cio, opj_jpt_msg_header_t *header);
|
||||
bool jpt_read_msg_header(
|
||||
struct opj_stream_private * p_cio,
|
||||
opj_jpt_msg_header_t * p_header,
|
||||
OPJ_UINT32 * p_nb_bytes_read,
|
||||
struct opj_event_mgr * p_manager);
|
||||
|
||||
#endif
|
||||
@@ -5,8 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008;2011-2012, Centre National d'Etudes Spatiales (CNES), France
|
||||
* Copyright (c) 2012, CS Systemes d'Information, France
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,36 +30,38 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef __SSE__
|
||||
#include <xmmintrin.h>
|
||||
#endif
|
||||
|
||||
#include "opj_includes.h"
|
||||
#include "mct.h"
|
||||
#include "fix.h"
|
||||
#include "opj_malloc.h"
|
||||
|
||||
/* <summary> */
|
||||
/* This table contains the norms of the basis function of the reversible MCT. */
|
||||
/* </summary> */
|
||||
static const OPJ_FLOAT64 opj_mct_norms[3] = { 1.732, .8292, .8292 };
|
||||
static const OPJ_FLOAT64 mct_norms[3] = { 1.732, .8292, .8292 };
|
||||
|
||||
/* <summary> */
|
||||
/* This table contains the norms of the basis function of the irreversible MCT. */
|
||||
/* </summary> */
|
||||
static const OPJ_FLOAT64 opj_mct_norms_real[3] = { 1.732, 1.805, 1.573 };
|
||||
static const OPJ_FLOAT64 mct_norms_real[3] = { 1.732, 1.805, 1.573 };
|
||||
|
||||
const OPJ_FLOAT64 * opj_mct_get_mct_norms ()
|
||||
|
||||
|
||||
const OPJ_FLOAT64 * get_mct_norms ()
|
||||
{
|
||||
return opj_mct_norms;
|
||||
return mct_norms;
|
||||
}
|
||||
|
||||
const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
|
||||
const OPJ_FLOAT64 * get_mct_norms_real ()
|
||||
{
|
||||
return opj_mct_norms_real;
|
||||
return mct_norms_real;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* <summary> */
|
||||
/* Foward reversible MCT. */
|
||||
/* </summary> */
|
||||
void opj_mct_encode(
|
||||
void mct_encode(
|
||||
OPJ_INT32* restrict c0,
|
||||
OPJ_INT32* restrict c1,
|
||||
OPJ_INT32* restrict c2,
|
||||
@@ -83,7 +84,7 @@ void opj_mct_encode(
|
||||
/* <summary> */
|
||||
/* Inverse reversible MCT. */
|
||||
/* </summary> */
|
||||
void opj_mct_decode(
|
||||
void mct_decode(
|
||||
OPJ_INT32* restrict c0,
|
||||
OPJ_INT32* restrict c1,
|
||||
OPJ_INT32* restrict c2,
|
||||
@@ -106,14 +107,14 @@ void opj_mct_decode(
|
||||
/* <summary> */
|
||||
/* Get norm of basis function of reversible MCT. */
|
||||
/* </summary> */
|
||||
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
|
||||
return opj_mct_norms[compno];
|
||||
OPJ_FLOAT64 mct_getnorm(OPJ_UINT32 compno) {
|
||||
return mct_norms[compno];
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
/* Foward irreversible MCT. */
|
||||
/* </summary> */
|
||||
void opj_mct_encode_real(
|
||||
void mct_encode_real(
|
||||
OPJ_INT32* restrict c0,
|
||||
OPJ_INT32* restrict c1,
|
||||
OPJ_INT32* restrict c2,
|
||||
@@ -124,9 +125,9 @@ void opj_mct_encode_real(
|
||||
OPJ_INT32 r = c0[i];
|
||||
OPJ_INT32 g = c1[i];
|
||||
OPJ_INT32 b = c2[i];
|
||||
OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, 4809) + opj_int_fix_mul(b, 934);
|
||||
OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, 2714) + opj_int_fix_mul(b, 4096);
|
||||
OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, 3430) - opj_int_fix_mul(b, 666);
|
||||
OPJ_INT32 y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934);
|
||||
OPJ_INT32 u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096);
|
||||
OPJ_INT32 v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
|
||||
c0[i] = y;
|
||||
c1[i] = u;
|
||||
c2[i] = v;
|
||||
@@ -136,51 +137,13 @@ void opj_mct_encode_real(
|
||||
/* <summary> */
|
||||
/* Inverse irreversible MCT. */
|
||||
/* </summary> */
|
||||
void opj_mct_decode_real(
|
||||
void mct_decode_real(
|
||||
OPJ_FLOAT32* restrict c0,
|
||||
OPJ_FLOAT32* restrict c1,
|
||||
OPJ_FLOAT32* restrict c2,
|
||||
OPJ_UINT32 n)
|
||||
{
|
||||
OPJ_UINT32 i;
|
||||
#ifdef __SSE__
|
||||
__m128 vrv, vgu, vgv, vbu;
|
||||
vrv = _mm_set1_ps(1.402f);
|
||||
vgu = _mm_set1_ps(0.34413f);
|
||||
vgv = _mm_set1_ps(0.71414f);
|
||||
vbu = _mm_set1_ps(1.772f);
|
||||
for (i = 0; i < (n >> 3); ++i) {
|
||||
__m128 vy, vu, vv;
|
||||
__m128 vr, vg, vb;
|
||||
|
||||
vy = _mm_load_ps(c0);
|
||||
vu = _mm_load_ps(c1);
|
||||
vv = _mm_load_ps(c2);
|
||||
vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
|
||||
vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
|
||||
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
|
||||
_mm_store_ps(c0, vr);
|
||||
_mm_store_ps(c1, vg);
|
||||
_mm_store_ps(c2, vb);
|
||||
c0 += 4;
|
||||
c1 += 4;
|
||||
c2 += 4;
|
||||
|
||||
vy = _mm_load_ps(c0);
|
||||
vu = _mm_load_ps(c1);
|
||||
vv = _mm_load_ps(c2);
|
||||
vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
|
||||
vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
|
||||
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
|
||||
_mm_store_ps(c0, vr);
|
||||
_mm_store_ps(c1, vg);
|
||||
_mm_store_ps(c2, vb);
|
||||
c0 += 4;
|
||||
c1 += 4;
|
||||
c2 += 4;
|
||||
}
|
||||
n &= 7;
|
||||
#endif
|
||||
for(i = 0; i < n; ++i) {
|
||||
OPJ_FLOAT32 y = c0[i];
|
||||
OPJ_FLOAT32 u = c1[i];
|
||||
@@ -197,16 +160,20 @@ void opj_mct_decode_real(
|
||||
/* <summary> */
|
||||
/* Get norm of basis function of irreversible MCT. */
|
||||
/* </summary> */
|
||||
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) {
|
||||
return opj_mct_norms_real[compno];
|
||||
OPJ_FLOAT64 mct_getnorm_real(OPJ_UINT32 compno) {
|
||||
return mct_norms_real[compno];
|
||||
}
|
||||
|
||||
|
||||
OPJ_BOOL opj_mct_encode_custom(
|
||||
bool mct_encode_custom(
|
||||
// MCT data
|
||||
OPJ_BYTE * pCodingdata,
|
||||
// size of components
|
||||
OPJ_UINT32 n,
|
||||
// components
|
||||
OPJ_BYTE ** pData,
|
||||
// nb of components (i.e. size of pData)
|
||||
OPJ_UINT32 pNbComp,
|
||||
// tells if the data is signed
|
||||
OPJ_UINT32 isSigned)
|
||||
{
|
||||
OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata;
|
||||
@@ -220,46 +187,54 @@ OPJ_BOOL opj_mct_encode_custom(
|
||||
OPJ_UINT32 lMultiplicator = 1 << 13;
|
||||
OPJ_INT32 * lMctPtr;
|
||||
|
||||
OPJ_ARG_NOT_USED(isSigned);
|
||||
|
||||
lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32));
|
||||
if (! lCurrentData) {
|
||||
return OPJ_FALSE;
|
||||
if
|
||||
(! lCurrentData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
lCurrentMatrix = lCurrentData + pNbComp;
|
||||
|
||||
for (i =0;i<lNbMatCoeff;++i) {
|
||||
for
|
||||
(i =0;i<lNbMatCoeff;++i)
|
||||
{
|
||||
lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * lMultiplicator);
|
||||
}
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
for
|
||||
(i = 0; i < n; ++i)
|
||||
{
|
||||
lMctPtr = lCurrentMatrix;
|
||||
for (j=0;j<pNbComp;++j) {
|
||||
for
|
||||
(j=0;j<pNbComp;++j)
|
||||
{
|
||||
lCurrentData[j] = (*(lData[j]));
|
||||
}
|
||||
|
||||
for (j=0;j<pNbComp;++j) {
|
||||
for
|
||||
(j=0;j<pNbComp;++j)
|
||||
{
|
||||
*(lData[j]) = 0;
|
||||
for (k=0;k<pNbComp;++k) {
|
||||
*(lData[j]) += opj_int_fix_mul(*lMctPtr, lCurrentData[k]);
|
||||
for
|
||||
(k=0;k<pNbComp;++k)
|
||||
{
|
||||
*(lData[j]) += fix_mul(*lMctPtr, lCurrentData[k]);
|
||||
++lMctPtr;
|
||||
}
|
||||
|
||||
++lData[j];
|
||||
}
|
||||
}
|
||||
|
||||
opj_free(lCurrentData);
|
||||
|
||||
return OPJ_TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
OPJ_BOOL opj_mct_decode_custom(
|
||||
bool mct_decode_custom(
|
||||
// MCT data
|
||||
OPJ_BYTE * pDecodingData,
|
||||
// size of components
|
||||
OPJ_UINT32 n,
|
||||
// components
|
||||
OPJ_BYTE ** pData,
|
||||
// nb of components (i.e. size of pData)
|
||||
OPJ_UINT32 pNbComp,
|
||||
// tells if the data is signed
|
||||
OPJ_UINT32 isSigned)
|
||||
{
|
||||
OPJ_FLOAT32 * lMct;
|
||||
@@ -271,45 +246,54 @@ OPJ_BOOL opj_mct_decode_custom(
|
||||
OPJ_FLOAT32 * lCurrentResult = 00;
|
||||
OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData;
|
||||
|
||||
OPJ_ARG_NOT_USED(isSigned);
|
||||
|
||||
lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32));
|
||||
if (! lCurrentData) {
|
||||
return OPJ_FALSE;
|
||||
if
|
||||
(! lCurrentData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
lCurrentResult = lCurrentData + pNbComp;
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
for
|
||||
(i = 0; i < n; ++i)
|
||||
{
|
||||
lMct = (OPJ_FLOAT32 *) pDecodingData;
|
||||
for (j=0;j<pNbComp;++j) {
|
||||
for
|
||||
(j=0;j<pNbComp;++j)
|
||||
{
|
||||
lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j]));
|
||||
}
|
||||
for (j=0;j<pNbComp;++j) {
|
||||
for
|
||||
(j=0;j<pNbComp;++j)
|
||||
{
|
||||
lCurrentResult[j] = 0;
|
||||
for (k=0;k<pNbComp;++k) {
|
||||
for
|
||||
(k=0;k<pNbComp;++k)
|
||||
{
|
||||
lCurrentResult[j] += *(lMct++) * lCurrentData[k];
|
||||
}
|
||||
*(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]);
|
||||
}
|
||||
}
|
||||
opj_free(lCurrentData);
|
||||
return OPJ_TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
|
||||
OPJ_UINT32 pNbComps,
|
||||
OPJ_FLOAT32 * pMatrix)
|
||||
void opj_calculate_norms(OPJ_FLOAT64 * pNorms,OPJ_UINT32 pNbComps,OPJ_FLOAT32 * pMatrix)
|
||||
{
|
||||
OPJ_UINT32 i,j,lIndex;
|
||||
OPJ_FLOAT32 lCurrentValue;
|
||||
OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms;
|
||||
OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix;
|
||||
|
||||
for (i=0;i<pNbComps;++i) {
|
||||
for
|
||||
(i=0;i<pNbComps;++i)
|
||||
{
|
||||
lNorms[i] = 0;
|
||||
lIndex = i;
|
||||
|
||||
for (j=0;j<pNbComps;++j) {
|
||||
for
|
||||
(j=0;j<pNbComps;++j)
|
||||
{
|
||||
lCurrentValue = lMatrix[lIndex];
|
||||
lIndex += pNbComps;
|
||||
lNorms[i] += lCurrentValue * lCurrentValue;
|
||||
@@ -317,3 +301,4 @@ void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
|
||||
lNorms[i] = sqrt(lNorms[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -38,7 +39,7 @@
|
||||
The functions in MCT.C have for goal to realize reversible and irreversible multicomponent
|
||||
transform. The functions in MCT.C are used by some function in TCD.C.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
/** @defgroup MCT MCT - Implementation of a multi-component transform */
|
||||
/*@{*/
|
||||
|
||||
@@ -52,7 +53,7 @@ Apply a reversible multi-component transform to an image
|
||||
@param c2 Samples blue component
|
||||
@param n Number of samples for each component
|
||||
*/
|
||||
void mct_encode(int *c0, int *c1, int *c2, int n);
|
||||
void mct_encode(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
|
||||
/**
|
||||
Apply a reversible multi-component inverse transform to an image
|
||||
@param c0 Samples for luminance component
|
||||
@@ -60,13 +61,13 @@ Apply a reversible multi-component inverse transform to an image
|
||||
@param c2 Samples for blue chrominance component
|
||||
@param n Number of samples for each component
|
||||
*/
|
||||
void mct_decode(int *c0, int *c1, int *c2, int n);
|
||||
void mct_decode(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
|
||||
/**
|
||||
Get norm of the basis function used for the reversible multi-component transform
|
||||
@param compno Number of the component (0->Y, 1->U, 2->V)
|
||||
@return
|
||||
*/
|
||||
double mct_getnorm(int compno);
|
||||
OPJ_FLOAT64 mct_getnorm(OPJ_UINT32 compno);
|
||||
|
||||
/**
|
||||
Apply an irreversible multi-component transform to an image
|
||||
@@ -75,7 +76,7 @@ Apply an irreversible multi-component transform to an image
|
||||
@param c2 Samples blue component
|
||||
@param n Number of samples for each component
|
||||
*/
|
||||
void mct_encode_real(int *c0, int *c1, int *c2, int n);
|
||||
void mct_encode_real(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
|
||||
/**
|
||||
Apply an irreversible multi-component inverse transform to an image
|
||||
@param c0 Samples for luminance component
|
||||
@@ -83,13 +84,44 @@ Apply an irreversible multi-component inverse transform to an image
|
||||
@param c2 Samples for blue chrominance component
|
||||
@param n Number of samples for each component
|
||||
*/
|
||||
void mct_decode_real(float* c0, float* c1, float* c2, int n);
|
||||
void mct_decode_real(OPJ_FLOAT32* c0, OPJ_FLOAT32* c1, OPJ_FLOAT32* c2, OPJ_UINT32 n);
|
||||
/**
|
||||
Get norm of the basis function used for the irreversible multi-component transform
|
||||
@param compno Number of the component (0->Y, 1->U, 2->V)
|
||||
@return
|
||||
*/
|
||||
double mct_getnorm_real(int compno);
|
||||
OPJ_FLOAT64 mct_getnorm_real(OPJ_UINT32 compno);
|
||||
|
||||
bool mct_encode_custom(
|
||||
// MCT data
|
||||
OPJ_BYTE * p_coding_data,
|
||||
// size of components
|
||||
OPJ_UINT32 n,
|
||||
// components
|
||||
OPJ_BYTE ** p_data,
|
||||
// nb of components (i.e. size of p_data)
|
||||
OPJ_UINT32 p_nb_comp,
|
||||
// tells if the data is signed
|
||||
OPJ_UINT32 is_signed);
|
||||
|
||||
bool mct_decode_custom(
|
||||
// MCT data
|
||||
OPJ_BYTE * pDecodingData,
|
||||
// size of components
|
||||
OPJ_UINT32 n,
|
||||
// components
|
||||
OPJ_BYTE ** pData,
|
||||
// nb of components (i.e. size of pData)
|
||||
OPJ_UINT32 pNbComp,
|
||||
// tells if the data is signed
|
||||
OPJ_UINT32 isSigned);
|
||||
|
||||
void opj_calculate_norms(OPJ_FLOAT64 * pNorms,OPJ_UINT32 p_nb_comps,OPJ_FLOAT32 * pMatrix);
|
||||
|
||||
const OPJ_FLOAT64 * get_mct_norms ();
|
||||
const OPJ_FLOAT64 * get_mct_norms_real ();
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
92
src/lib/openjp3d/mqc.c → libopenjpeg/mqc.c
Executable file → Normal file
92
src/lib/openjp3d/mqc.c → libopenjpeg/mqc.c
Executable file → Normal file
@@ -1,9 +1,11 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2001-2003, David Janssens
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -28,7 +30,9 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "opj_includes.h"
|
||||
#include "mqc.h"
|
||||
#include "t1.h"
|
||||
#include "opj_malloc.h"
|
||||
|
||||
/** @defgroup MQC MQC - Implementation of an MQ-Coder */
|
||||
/*@{*/
|
||||
@@ -63,17 +67,17 @@ Fill mqc->c with 1's for flushing
|
||||
*/
|
||||
static void mqc_setbits(opj_mqc_t *mqc);
|
||||
/**
|
||||
Exchange MPS with LPS
|
||||
FIXME: documentation ???
|
||||
@param mqc MQC handle
|
||||
@return
|
||||
*/
|
||||
static int mqc_mpsexchange(opj_mqc_t *mqc);
|
||||
static OPJ_INT32 mqc_mpsexchange(opj_mqc_t *mqc);
|
||||
/**
|
||||
Exchange LPS with MPS
|
||||
FIXME: documentation ???
|
||||
@param mqc MQC handle
|
||||
@return
|
||||
*/
|
||||
static int mqc_lpsexchange(opj_mqc_t *mqc);
|
||||
static OPJ_INT32 mqc_lpsexchange(opj_mqc_t *mqc);
|
||||
/**
|
||||
Input a byte
|
||||
@param mqc MQC handle
|
||||
@@ -263,15 +267,15 @@ static void mqc_codelps(opj_mqc_t *mqc) {
|
||||
}
|
||||
|
||||
static void mqc_setbits(opj_mqc_t *mqc) {
|
||||
unsigned int tempc = mqc->c + mqc->a;
|
||||
OPJ_UINT32 tempc = mqc->c + mqc->a;
|
||||
mqc->c |= 0xffff;
|
||||
if (mqc->c >= tempc) {
|
||||
mqc->c -= 0x8000;
|
||||
}
|
||||
}
|
||||
|
||||
static int mqc_mpsexchange(opj_mqc_t *mqc) {
|
||||
int d;
|
||||
static OPJ_INT32 mqc_mpsexchange(opj_mqc_t *mqc) {
|
||||
OPJ_INT32 d;
|
||||
if (mqc->a < (*mqc->curctx)->qeval) {
|
||||
d = 1 - (*mqc->curctx)->mps;
|
||||
*mqc->curctx = (*mqc->curctx)->nlps;
|
||||
@@ -283,8 +287,8 @@ static int mqc_mpsexchange(opj_mqc_t *mqc) {
|
||||
return d;
|
||||
}
|
||||
|
||||
static int mqc_lpsexchange(opj_mqc_t *mqc) {
|
||||
int d;
|
||||
static OPJ_INT32 mqc_lpsexchange(opj_mqc_t *mqc) {
|
||||
OPJ_INT32 d;
|
||||
if (mqc->a < (*mqc->curctx)->qeval) {
|
||||
mqc->a = (*mqc->curctx)->qeval;
|
||||
d = (*mqc->curctx)->mps;
|
||||
@@ -300,7 +304,7 @@ static int mqc_lpsexchange(opj_mqc_t *mqc) {
|
||||
|
||||
static void mqc_bytein(opj_mqc_t *mqc) {
|
||||
if (mqc->bp != mqc->end) {
|
||||
unsigned int c;
|
||||
OPJ_UINT32 c;
|
||||
if (mqc->bp + 1 != mqc->end) {
|
||||
c = *(mqc->bp + 1);
|
||||
} else {
|
||||
@@ -343,38 +347,37 @@ static void mqc_renormd(opj_mqc_t *mqc) {
|
||||
==========================================================
|
||||
*/
|
||||
|
||||
opj_mqc_t* mqc_create() {
|
||||
opj_mqc_t* mqc_create(void) {
|
||||
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
|
||||
return mqc;
|
||||
}
|
||||
|
||||
void mqc_destroy(opj_mqc_t *mqc) {
|
||||
if(mqc) {
|
||||
if
|
||||
(mqc)
|
||||
{
|
||||
opj_free(mqc);
|
||||
}
|
||||
}
|
||||
|
||||
int mqc_numbytes(opj_mqc_t *mqc) {
|
||||
OPJ_UINT32 mqc_numbytes(opj_mqc_t *mqc) {
|
||||
return mqc->bp - mqc->start;
|
||||
}
|
||||
|
||||
void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) {
|
||||
void mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) {
|
||||
mqc_setcurctx(mqc, 0);
|
||||
mqc->a = 0x8000;
|
||||
mqc->c = 0;
|
||||
mqc->bp = bp - 1;
|
||||
*(mqc->bp) = 0;
|
||||
mqc->ct = 12;
|
||||
if (*mqc->bp == 0xff) {
|
||||
/*if (*mqc->bp == 0xff) {
|
||||
mqc->ct = 13;
|
||||
}
|
||||
}*/
|
||||
mqc->start = bp;
|
||||
}
|
||||
|
||||
void mqc_setcurctx(opj_mqc_t *mqc, int ctxno) {
|
||||
mqc->curctx = &mqc->ctxs[ctxno];
|
||||
}
|
||||
|
||||
void mqc_encode(opj_mqc_t *mqc, int d) {
|
||||
void mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) {
|
||||
if ((*mqc->curctx)->mps == d) {
|
||||
mqc_codemps(mqc);
|
||||
} else {
|
||||
@@ -402,7 +405,7 @@ void mqc_bypass_init_enc(opj_mqc_t *mqc) {
|
||||
} */
|
||||
}
|
||||
|
||||
void mqc_bypass_enc(opj_mqc_t *mqc, int d) {
|
||||
void mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) {
|
||||
mqc->ct--;
|
||||
mqc->c = mqc->c + (d << mqc->ct);
|
||||
if (mqc->ct == 0) {
|
||||
@@ -416,8 +419,8 @@ void mqc_bypass_enc(opj_mqc_t *mqc, int d) {
|
||||
}
|
||||
}
|
||||
|
||||
int mqc_bypass_flush_enc(opj_mqc_t *mqc) {
|
||||
unsigned char bit_padding;
|
||||
OPJ_UINT32 mqc_bypass_flush_enc(opj_mqc_t *mqc) {
|
||||
OPJ_BYTE bit_padding;
|
||||
|
||||
bit_padding = 0;
|
||||
|
||||
@@ -438,23 +441,16 @@ int mqc_bypass_flush_enc(opj_mqc_t *mqc) {
|
||||
|
||||
void mqc_reset_enc(opj_mqc_t *mqc) {
|
||||
mqc_resetstates(mqc);
|
||||
mqc_setstate(mqc, 18, 0, 46);
|
||||
mqc_setstate(mqc, 0, 0, 3);
|
||||
mqc_setstate(mqc, 1, 0, 4);
|
||||
mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
|
||||
mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
|
||||
mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
|
||||
}
|
||||
|
||||
void mqc_reset_enc_3(opj_mqc_t *mqc) {
|
||||
mqc_resetstates(mqc);
|
||||
mqc_setstate(mqc, T1_3D_CTXNO_UNI, 0, 46);
|
||||
mqc_setstate(mqc, T1_3D_CTXNO_AGG, 0, 3);
|
||||
mqc_setstate(mqc, T1_3D_CTXNO_ZC, 0, 4);
|
||||
}
|
||||
|
||||
int mqc_restart_enc(opj_mqc_t *mqc) {
|
||||
int correction = 1;
|
||||
OPJ_UINT32 mqc_restart_enc(opj_mqc_t *mqc) {
|
||||
OPJ_UINT32 correction = 1;
|
||||
|
||||
/* <flush part> */
|
||||
int n = 27 - 15 - mqc->ct;
|
||||
OPJ_INT32 n = 27 - 15 - mqc->ct;
|
||||
mqc->c <<= mqc->ct;
|
||||
while (n > 0) {
|
||||
mqc_byteout(mqc);
|
||||
@@ -479,7 +475,7 @@ void mqc_restart_init_enc(opj_mqc_t *mqc) {
|
||||
}
|
||||
|
||||
void mqc_erterm_enc(opj_mqc_t *mqc) {
|
||||
int k = 11 - mqc->ct + 1;
|
||||
OPJ_INT32 k = 11 - mqc->ct + 1;
|
||||
|
||||
while (k > 0) {
|
||||
mqc->c <<= mqc->ct;
|
||||
@@ -494,7 +490,7 @@ void mqc_erterm_enc(opj_mqc_t *mqc) {
|
||||
}
|
||||
|
||||
void mqc_segmark_enc(opj_mqc_t *mqc) {
|
||||
int i;
|
||||
OPJ_UINT32 i;
|
||||
mqc_setcurctx(mqc, 18);
|
||||
|
||||
for (i = 1; i < 5; i++) {
|
||||
@@ -502,7 +498,7 @@ void mqc_segmark_enc(opj_mqc_t *mqc) {
|
||||
}
|
||||
}
|
||||
|
||||
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
|
||||
void mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
|
||||
mqc_setcurctx(mqc, 0);
|
||||
mqc->start = bp;
|
||||
mqc->end = bp + len;
|
||||
@@ -515,8 +511,8 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
|
||||
mqc->a = 0x8000;
|
||||
}
|
||||
|
||||
int mqc_decode(opj_mqc_t *mqc) {
|
||||
int d;
|
||||
OPJ_UINT32 mqc_decode(opj_mqc_t *mqc) {
|
||||
OPJ_INT32 d;
|
||||
mqc->a -= (*mqc->curctx)->qeval;
|
||||
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
|
||||
d = mqc_lpsexchange(mqc);
|
||||
@@ -531,17 +527,17 @@ int mqc_decode(opj_mqc_t *mqc) {
|
||||
}
|
||||
}
|
||||
|
||||
return d;
|
||||
return (OPJ_UINT32)d;
|
||||
}
|
||||
|
||||
void mqc_resetstates(opj_mqc_t *mqc) {
|
||||
int i;
|
||||
OPJ_UINT32 i;
|
||||
for (i = 0; i < MQC_NUMCTXS; i++) {
|
||||
mqc->ctxs[i] = mqc_states;
|
||||
}
|
||||
}
|
||||
|
||||
void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) {
|
||||
void mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) {
|
||||
mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)];
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -38,7 +39,7 @@
|
||||
The functions in MQC.C have for goal to realize the MQ-coder operations. The functions
|
||||
in MQC.C are used by some function in T1.C.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
/** @defgroup MQC MQC - Implementation of an MQ-Coder */
|
||||
/*@{*/
|
||||
|
||||
@@ -47,32 +48,29 @@ This struct defines the state of a context.
|
||||
*/
|
||||
typedef struct opj_mqc_state {
|
||||
/** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
|
||||
unsigned int qeval;
|
||||
OPJ_UINT32 qeval;
|
||||
/** the Most Probable Symbol (0 or 1) */
|
||||
int mps;
|
||||
OPJ_INT32 mps;
|
||||
/** next state if the next encoded symbol is the MPS */
|
||||
struct opj_mqc_state *nmps;
|
||||
/** next state if the next encoded symbol is the LPS */
|
||||
struct opj_mqc_state *nlps;
|
||||
} opj_mqc_state_t;
|
||||
|
||||
#define MQC_NUMCTXS 19
|
||||
#define MQC_NUMCTXS 32
|
||||
|
||||
/**
|
||||
MQ coder
|
||||
*/
|
||||
typedef struct opj_mqc {
|
||||
unsigned int c;
|
||||
unsigned int a;
|
||||
unsigned int ct;
|
||||
unsigned char *bp;
|
||||
unsigned char *start;
|
||||
unsigned char *end;
|
||||
OPJ_UINT32 c;
|
||||
OPJ_UINT32 a;
|
||||
OPJ_UINT32 ct;
|
||||
OPJ_BYTE *bp;
|
||||
OPJ_BYTE *start;
|
||||
OPJ_BYTE *end;
|
||||
opj_mqc_state_t *ctxs[MQC_NUMCTXS];
|
||||
opj_mqc_state_t **curctx;
|
||||
#ifdef MQC_PERF_OPT
|
||||
unsigned char *buffer;
|
||||
#endif
|
||||
} opj_mqc_t;
|
||||
|
||||
/** @name Exported functions */
|
||||
@@ -93,7 +91,7 @@ Return the number of bytes written/read since initialisation
|
||||
@param mqc MQC handle
|
||||
@return Returns the number of bytes already encoded
|
||||
*/
|
||||
int mqc_numbytes(opj_mqc_t *mqc);
|
||||
OPJ_UINT32 mqc_numbytes(opj_mqc_t *mqc);
|
||||
/**
|
||||
Reset the states of all the context of the coder/decoder
|
||||
(each context is set to a state where 0 and 1 are more or less equiprobable)
|
||||
@@ -107,25 +105,25 @@ Set the state of a particular context
|
||||
@param msb The MSB of the new state of the context
|
||||
@param prob Number that identifies the probability of the symbols for the new state of the context
|
||||
*/
|
||||
void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob);
|
||||
void mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob);
|
||||
/**
|
||||
Initialize the encoder
|
||||
@param mqc MQC handle
|
||||
@param bp Pointer to the start of the buffer where the bytes will be written
|
||||
*/
|
||||
void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp);
|
||||
void mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp);
|
||||
/**
|
||||
Set the current context used for coding/decoding
|
||||
@param mqc MQC handle
|
||||
@param ctxno Number that identifies the context
|
||||
*/
|
||||
#define mqc_setcurctx(mqc, ctxno) (mqc)->curctx = &(mqc)->ctxs[(int)(ctxno)]
|
||||
#define mqc_setcurctx(mqc, ctxno) (mqc)->curctx = &(mqc)->ctxs[(OPJ_UINT32)(ctxno)]
|
||||
/**
|
||||
Encode a symbol using the MQ-coder
|
||||
@param mqc MQC handle
|
||||
@param d The symbol to be encoded (0 or 1)
|
||||
*/
|
||||
void mqc_encode(opj_mqc_t *mqc, int d);
|
||||
void mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d);
|
||||
/**
|
||||
Flush the encoder, so that all remaining data is written
|
||||
@param mqc MQC handle
|
||||
@@ -145,14 +143,14 @@ JPEG 2000 p 505.
|
||||
@param mqc MQC handle
|
||||
@param d The symbol to be encoded (0 or 1)
|
||||
*/
|
||||
void mqc_bypass_enc(opj_mqc_t *mqc, int d);
|
||||
void mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d);
|
||||
/**
|
||||
BYPASS mode switch, flush operation
|
||||
<h2>Not fully implemented and tested !!</h2>
|
||||
@param mqc MQC handle
|
||||
@return Returns 1 (always)
|
||||
*/
|
||||
int mqc_bypass_flush_enc(opj_mqc_t *mqc);
|
||||
OPJ_UINT32 mqc_bypass_flush_enc(opj_mqc_t *mqc);
|
||||
/**
|
||||
RESET mode switch
|
||||
@param mqc MQC handle
|
||||
@@ -163,7 +161,7 @@ RESTART mode switch (TERMALL)
|
||||
@param mqc MQC handle
|
||||
@return Returns 1 (always)
|
||||
*/
|
||||
int mqc_restart_enc(opj_mqc_t *mqc);
|
||||
OPJ_UINT32 mqc_restart_enc(opj_mqc_t *mqc);
|
||||
/**
|
||||
RESTART mode switch (TERMALL) reinitialisation
|
||||
@param mqc MQC handle
|
||||
@@ -185,13 +183,13 @@ Initialize the decoder
|
||||
@param bp Pointer to the start of the buffer from which the bytes will be read
|
||||
@param len Length of the input buffer
|
||||
*/
|
||||
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
|
||||
void mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len);
|
||||
/**
|
||||
Decode a symbol
|
||||
@param mqc MQC handle
|
||||
@return Returns the decoded symbol (0 or 1)
|
||||
*/
|
||||
int mqc_decode(opj_mqc_t *const mqc);
|
||||
OPJ_UINT32 mqc_decode(opj_mqc_t *mqc);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
908
libopenjpeg/openjpeg.c
Normal file
908
libopenjpeg/openjpeg.c
Normal file
@@ -0,0 +1,908 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Herv<72> Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#include "openjpeg.h"
|
||||
#include "opj_malloc.h"
|
||||
#include "j2k.h"
|
||||
#include "jp2.h"
|
||||
#include "event.h"
|
||||
#include "cio.h"
|
||||
|
||||
typedef struct opj_decompression
|
||||
{
|
||||
bool (* opj_read_header) (
|
||||
void *p_codec,
|
||||
opj_image_t **,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
OPJ_INT32 * p_tile_y0,
|
||||
OPJ_UINT32 * p_tile_width,
|
||||
OPJ_UINT32 * p_tile_height,
|
||||
OPJ_UINT32 * p_nb_tiles_x,
|
||||
OPJ_UINT32 * p_nb_tiles_y,
|
||||
struct opj_stream_private *cio,
|
||||
struct opj_event_mgr * p_manager);
|
||||
opj_image_t* (* opj_decode) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager);
|
||||
bool (*opj_read_tile_header)(
|
||||
void * p_codec,
|
||||
OPJ_UINT32 * p_tile_index,
|
||||
OPJ_UINT32* p_data_size,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
OPJ_INT32 * p_tile_y0,
|
||||
OPJ_INT32 * p_tile_x1,
|
||||
OPJ_INT32 * p_tile_y1,
|
||||
OPJ_UINT32 * p_nb_comps,
|
||||
bool * p_should_go_on,
|
||||
struct opj_stream_private *p_cio,
|
||||
struct opj_event_mgr * p_manager);
|
||||
bool (*opj_decode_tile_data)(void * p_codec,OPJ_UINT32 p_tile_index,OPJ_BYTE * p_data,OPJ_UINT32 p_data_size,struct opj_stream_private *p_cio,struct opj_event_mgr * p_manager);
|
||||
bool (* opj_end_decompress) (void *p_codec,struct opj_stream_private *cio,struct opj_event_mgr * p_manager);
|
||||
void (* opj_destroy) (void * p_codec);
|
||||
void (*opj_setup_decoder) (void * p_codec,opj_dparameters_t * p_param);
|
||||
bool (*opj_set_decode_area) (void * p_codec,OPJ_INT32 p_start_x,OPJ_INT32 p_end_x,OPJ_INT32 p_start_y,OPJ_INT32 p_end_y,struct opj_event_mgr * p_manager);
|
||||
|
||||
|
||||
}opj_decompression_t;
|
||||
|
||||
typedef struct opj_compression
|
||||
{
|
||||
bool (* opj_start_compress) (void *p_codec,struct opj_stream_private *cio,struct opj_image * p_image, struct opj_event_mgr * p_manager);
|
||||
bool (* opj_encode) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager);
|
||||
bool (* opj_write_tile) (void * p_codec,OPJ_UINT32 p_tile_index,OPJ_BYTE * p_data,OPJ_UINT32 p_data_size,struct opj_stream_private * p_cio,struct opj_event_mgr * p_manager);
|
||||
bool (* opj_end_compress) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager);
|
||||
void (* opj_destroy) (void * p_codec);
|
||||
void (*opj_setup_encoder) (void * p_codec,opj_cparameters_t * p_param,struct opj_image * p_image, struct opj_event_mgr * p_manager);
|
||||
|
||||
}opj_compression_t;
|
||||
|
||||
|
||||
|
||||
typedef struct opj_codec_private
|
||||
{
|
||||
union
|
||||
{ /* code-blocks informations */
|
||||
opj_decompression_t m_decompression;
|
||||
opj_compression_t m_compression;
|
||||
} m_codec_data;
|
||||
void * m_codec;
|
||||
opj_event_mgr_t m_event_mgr;
|
||||
unsigned is_decompressor : 1;
|
||||
}
|
||||
opj_codec_private_t;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Default callback function.
|
||||
* Do nothing.
|
||||
*/
|
||||
void opj_default_callback (const char *msg, void *client_data)
|
||||
{
|
||||
}
|
||||
|
||||
void set_default_event_handler(opj_event_mgr_t * p_manager)
|
||||
{
|
||||
p_manager->m_error_data = 00;
|
||||
p_manager->m_warning_data = 00;
|
||||
p_manager->m_info_data = 00;
|
||||
p_manager->error_handler = opj_default_callback;
|
||||
p_manager->info_handler = opj_default_callback;
|
||||
p_manager->warning_handler = opj_default_callback;
|
||||
}
|
||||
|
||||
OPJ_UINT32 opj_read_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file)
|
||||
{
|
||||
OPJ_UINT32 l_nb_read = fread(p_buffer,1,p_nb_bytes,p_file);
|
||||
return l_nb_read ? l_nb_read : -1;
|
||||
}
|
||||
|
||||
OPJ_UINT32 opj_write_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file)
|
||||
{
|
||||
return fwrite(p_buffer,1,p_nb_bytes,p_file);
|
||||
}
|
||||
|
||||
OPJ_SIZE_T opj_skip_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
|
||||
{
|
||||
if
|
||||
(fseek(p_user_data,p_nb_bytes,SEEK_CUR))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return p_nb_bytes;
|
||||
}
|
||||
|
||||
bool opj_seek_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
|
||||
{
|
||||
if
|
||||
(fseek(p_user_data,p_nb_bytes,SEEK_SET))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
#ifdef WIN32
|
||||
#ifndef OPJ_STATIC
|
||||
BOOL APIENTRY
|
||||
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH :
|
||||
break;
|
||||
case DLL_PROCESS_DETACH :
|
||||
break;
|
||||
case DLL_THREAD_ATTACH :
|
||||
case DLL_THREAD_DETACH :
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif /* OPJ_STATIC */
|
||||
#endif /* WIN32 */
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
const char* OPJ_CALLCONV opj_version(void) {
|
||||
return OPENJPEG_VERSION;
|
||||
}
|
||||
|
||||
opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
|
||||
{
|
||||
opj_codec_private_t *l_info = 00;
|
||||
|
||||
l_info = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
|
||||
if
|
||||
(!l_info)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
memset(l_info, 0, sizeof(opj_codec_private_t));
|
||||
l_info->is_decompressor = 1;
|
||||
switch
|
||||
(p_format)
|
||||
{
|
||||
case CODEC_J2K:
|
||||
l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode;
|
||||
l_info->m_codec_data.m_decompression.opj_end_decompress = (bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *))j2k_end_decompress;
|
||||
l_info->m_codec_data.m_decompression.opj_read_header = (bool (*) (
|
||||
void *,
|
||||
opj_image_t **,
|
||||
OPJ_INT32 * ,
|
||||
OPJ_INT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr * )) j2k_read_header;
|
||||
l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))j2k_destroy;
|
||||
l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) j2k_setup_decoder;
|
||||
l_info->m_codec_data.m_decompression.opj_read_tile_header = (bool (*) (
|
||||
void *,
|
||||
OPJ_UINT32*,
|
||||
OPJ_UINT32*,
|
||||
OPJ_INT32 * ,
|
||||
OPJ_INT32 * ,
|
||||
OPJ_INT32 * ,
|
||||
OPJ_INT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
bool *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr * )) j2k_read_tile_header;
|
||||
l_info->m_codec_data.m_decompression.opj_decode_tile_data = (bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) j2k_decode_tile;
|
||||
l_info->m_codec_data.m_decompression.opj_set_decode_area = (bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) j2k_set_decode_area;
|
||||
l_info->m_codec = j2k_create_decompress();
|
||||
if
|
||||
(! l_info->m_codec)
|
||||
{
|
||||
opj_free(l_info);
|
||||
return 00;
|
||||
}
|
||||
break;
|
||||
|
||||
case CODEC_JP2:
|
||||
/* get a JP2 decoder handle */
|
||||
l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))opj_jp2_decode;
|
||||
l_info->m_codec_data.m_decompression.opj_end_decompress = (bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
|
||||
l_info->m_codec_data.m_decompression.opj_read_header = (bool (*) (
|
||||
void *,
|
||||
opj_image_t **,
|
||||
|
||||
OPJ_INT32 * ,
|
||||
OPJ_INT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr * )) jp2_read_header;
|
||||
|
||||
l_info->m_codec_data.m_decompression.opj_read_tile_header = (
|
||||
bool (*) (
|
||||
void *,
|
||||
OPJ_UINT32*,
|
||||
OPJ_UINT32*,
|
||||
OPJ_INT32*,
|
||||
OPJ_INT32*,
|
||||
OPJ_INT32 * ,
|
||||
OPJ_INT32 * ,
|
||||
OPJ_UINT32 * ,
|
||||
bool *,
|
||||
struct opj_stream_private *,
|
||||
struct opj_event_mgr * )) jp2_read_tile_header;
|
||||
|
||||
l_info->m_codec_data.m_decompression.opj_decode_tile_data = (bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) opj_jp2_decode_tile;
|
||||
|
||||
l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy;
|
||||
l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder;
|
||||
l_info->m_codec_data.m_decompression.opj_set_decode_area = (bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) jp2_set_decode_area;
|
||||
|
||||
|
||||
l_info->m_codec = jp2_create(true);
|
||||
if
|
||||
(! l_info->m_codec)
|
||||
{
|
||||
opj_free(l_info);
|
||||
return 00;
|
||||
}
|
||||
break;
|
||||
case CODEC_UNKNOWN:
|
||||
case CODEC_JPT:
|
||||
default:
|
||||
opj_free(l_info);
|
||||
return 00;
|
||||
}
|
||||
set_default_event_handler(&(l_info->m_event_mgr));
|
||||
return (opj_codec_t*) l_info;
|
||||
}
|
||||
|
||||
void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info)
|
||||
{
|
||||
if
|
||||
(p_info)
|
||||
{
|
||||
opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
|
||||
if
|
||||
(l_info->is_decompressor)
|
||||
{
|
||||
l_info->m_codec_data.m_decompression.opj_destroy(l_info->m_codec);
|
||||
}
|
||||
else
|
||||
{
|
||||
l_info->m_codec_data.m_compression.opj_destroy(l_info->m_codec);
|
||||
}
|
||||
l_info->m_codec = 00;
|
||||
opj_free(l_info);
|
||||
}
|
||||
}
|
||||
|
||||
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
|
||||
if(parameters) {
|
||||
memset(parameters, 0, sizeof(opj_dparameters_t));
|
||||
/* default decoding parameters */
|
||||
parameters->cp_layer = 0;
|
||||
parameters->cp_reduce = 0;
|
||||
|
||||
parameters->decod_format = -1;
|
||||
parameters->cod_format = -1;
|
||||
/* UniPG>> */
|
||||
#ifdef USE_JPWL
|
||||
parameters->jpwl_correct = false;
|
||||
parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
|
||||
parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
|
||||
#endif /* USE_JPWL */
|
||||
/* <<UniPG */
|
||||
}
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_info, opj_dparameters_t *parameters) {
|
||||
if
|
||||
(p_info && parameters)
|
||||
{
|
||||
opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
|
||||
if
|
||||
(! l_info->is_decompressor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec,parameters);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
opj_image_t* OPJ_CALLCONV opj_decode(opj_codec_t *p_info, opj_stream_t *cio)
|
||||
{
|
||||
if
|
||||
(p_info && cio)
|
||||
{
|
||||
opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
|
||||
opj_stream_private_t * l_cio = (opj_stream_private_t *) cio;
|
||||
if
|
||||
(! l_info->is_decompressor)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
return l_info->m_codec_data.m_decompression.opj_decode(l_info->m_codec,l_cio,&(l_info->m_event_mgr));
|
||||
}
|
||||
return 00;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tile with the given data.
|
||||
*
|
||||
* @param p_compressor the jpeg2000 codec.
|
||||
* @param p_tile_index the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
|
||||
* @param p_data pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set.
|
||||
* @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes,
|
||||
* depending on the precision of the given component.
|
||||
* @param p_stream the stream to write data to.
|
||||
*/
|
||||
bool OPJ_CALLCONV opj_write_tile (
|
||||
opj_codec_t *p_codec,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_t *p_stream
|
||||
)
|
||||
{
|
||||
if
|
||||
(p_codec && p_stream && p_data)
|
||||
{
|
||||
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
||||
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
|
||||
if
|
||||
(l_info->is_decompressor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return l_info->m_codec_data.m_compression.opj_write_tile(l_info->m_codec,p_tile_index,p_data,p_data_size,l_cio,&(l_info->m_event_mgr));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
|
||||
* The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
|
||||
*
|
||||
* @param p_codec the jpeg2000 codec.
|
||||
* @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
|
||||
* @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
|
||||
* of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
|
||||
* as depicted in opj_write_tile.
|
||||
* @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
|
||||
* @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
|
||||
* @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
|
||||
* @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
|
||||
* @param p_nb_comps pointer to a value that will hold the number of components in the tile.
|
||||
* @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
|
||||
* codestream is over at the time of the call, the value will be set to false. The user should then stop
|
||||
* the decoding.
|
||||
* @param p_stream the stream to decode.
|
||||
* @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
|
||||
* returning false may be the result of a shortage of memory or an internal error.
|
||||
*/
|
||||
bool OPJ_CALLCONV opj_read_tile_header(
|
||||
opj_codec_t *p_codec,
|
||||
OPJ_UINT32 * p_tile_index,
|
||||
OPJ_UINT32 * p_data_size,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
OPJ_INT32 * p_tile_y0,
|
||||
OPJ_INT32 * p_tile_x1,
|
||||
OPJ_INT32 * p_tile_y1,
|
||||
OPJ_UINT32 * p_nb_comps,
|
||||
bool * p_should_go_on,
|
||||
opj_stream_t * p_stream)
|
||||
{
|
||||
if
|
||||
(p_codec && p_stream && p_data_size && p_tile_index)
|
||||
{
|
||||
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
||||
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
|
||||
if
|
||||
(! l_info->is_decompressor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return l_info->m_codec_data.m_decompression.opj_read_tile_header(
|
||||
l_info->m_codec,
|
||||
p_tile_index,
|
||||
p_data_size,
|
||||
p_tile_x0,
|
||||
p_tile_y0,
|
||||
p_tile_x1,
|
||||
p_tile_y1,
|
||||
p_nb_comps,
|
||||
p_should_go_on,
|
||||
l_cio,&(l_info->m_event_mgr));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
|
||||
* The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
|
||||
*
|
||||
* @param p_codec the jpeg2000 codec.
|
||||
* @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
|
||||
* @param p_data pointer to a memory block that will hold the decoded data.
|
||||
* @param p_data_size size of p_data. p_data_size should be bigger or equal to the value set by opj_read_tile_header.
|
||||
* @param p_stream the stream to decode.
|
||||
*
|
||||
* @return true if the data could be decoded.
|
||||
*/
|
||||
bool OPJ_CALLCONV opj_decode_tile_data(
|
||||
opj_codec_t *p_codec,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_t *p_stream
|
||||
)
|
||||
{
|
||||
if
|
||||
(p_codec && p_data && p_stream)
|
||||
{
|
||||
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
||||
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
|
||||
if
|
||||
(! l_info->is_decompressor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return l_info->m_codec_data.m_decompression.opj_decode_tile_data(l_info->m_codec,p_tile_index,p_data,p_data_size,l_cio,&(l_info->m_event_mgr));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_read_header (
|
||||
opj_codec_t *p_codec,
|
||||
opj_image_t ** p_image,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
OPJ_INT32 * p_tile_y0,
|
||||
OPJ_UINT32 * p_tile_width,
|
||||
OPJ_UINT32 * p_tile_height,
|
||||
OPJ_UINT32 * p_nb_tiles_x,
|
||||
OPJ_UINT32 * p_nb_tiles_y,
|
||||
opj_stream_t *p_cio)
|
||||
{
|
||||
if
|
||||
(p_codec && p_cio)
|
||||
{
|
||||
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
||||
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
|
||||
if
|
||||
(! l_info->is_decompressor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return l_info->m_codec_data.m_decompression.opj_read_header(
|
||||
l_info->m_codec,
|
||||
p_image,
|
||||
p_tile_x0,
|
||||
p_tile_y0,
|
||||
p_tile_width,
|
||||
p_tile_height,
|
||||
p_nb_tiles_x,
|
||||
p_nb_tiles_y,
|
||||
l_cio,
|
||||
&(l_info->m_event_mgr));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
|
||||
*
|
||||
* @param p_codec the jpeg2000 codec.
|
||||
* @param p_start_x the left position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_x the right position of the rectangle to decode (in image coordinates).
|
||||
* @param p_start_y the up position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
|
||||
*
|
||||
* @return true if the area could be set.
|
||||
*/
|
||||
bool OPJ_CALLCONV opj_set_decode_area(
|
||||
opj_codec_t *p_codec,
|
||||
OPJ_INT32 p_start_x,
|
||||
OPJ_INT32 p_start_y,
|
||||
OPJ_INT32 p_end_x,
|
||||
OPJ_INT32 p_end_y
|
||||
)
|
||||
{
|
||||
if
|
||||
(p_codec)
|
||||
{
|
||||
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
||||
if
|
||||
(! l_info->is_decompressor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return l_info->m_codec_data.m_decompression.opj_set_decode_area(
|
||||
l_info->m_codec,
|
||||
p_start_x,
|
||||
p_start_y,
|
||||
p_end_x,
|
||||
p_end_y,
|
||||
&(l_info->m_event_mgr));
|
||||
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_end_decompress (opj_codec_t *p_codec,opj_stream_t *p_cio)
|
||||
{
|
||||
if
|
||||
(p_codec && p_cio)
|
||||
{
|
||||
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
||||
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
|
||||
if
|
||||
(! l_info->is_decompressor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return l_info->m_codec_data.m_decompression.opj_end_decompress(l_info->m_codec,l_cio,&(l_info->m_event_mgr));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
|
||||
{
|
||||
opj_codec_private_t *l_info = 00;
|
||||
|
||||
l_info = (opj_codec_private_t*)opj_calloc(1, sizeof(opj_codec_private_t));
|
||||
if
|
||||
(!l_info)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
memset(l_info, 0, sizeof(opj_codec_private_t));
|
||||
l_info->is_decompressor = 0;
|
||||
switch
|
||||
(p_format)
|
||||
{
|
||||
case CODEC_J2K:
|
||||
l_info->m_codec_data.m_compression.opj_encode = (bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr * )) j2k_encode;
|
||||
l_info->m_codec_data.m_compression.opj_end_compress = (bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr *)) j2k_end_compress;
|
||||
l_info->m_codec_data.m_compression.opj_start_compress = (bool (*) (void *,struct opj_stream_private *,struct opj_image * , struct opj_event_mgr *)) j2k_start_compress;
|
||||
l_info->m_codec_data.m_compression.opj_write_tile = (bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr *)) j2k_write_tile;
|
||||
l_info->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) j2k_destroy;
|
||||
l_info->m_codec_data.m_compression.opj_setup_encoder = (void (*) (void *,opj_cparameters_t *,struct opj_image *, struct opj_event_mgr * )) j2k_setup_encoder;
|
||||
|
||||
l_info->m_codec = j2k_create_compress();
|
||||
if
|
||||
(! l_info->m_codec)
|
||||
{
|
||||
opj_free(l_info);
|
||||
return 00;
|
||||
}
|
||||
break;
|
||||
|
||||
case CODEC_JP2:
|
||||
/* get a JP2 decoder handle */
|
||||
l_info->m_codec_data.m_compression.opj_encode = (bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr * )) opj_jp2_encode;
|
||||
l_info->m_codec_data.m_compression.opj_end_compress = (bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr *)) jp2_end_compress;
|
||||
l_info->m_codec_data.m_compression.opj_start_compress = (bool (*) (void *,struct opj_stream_private *,struct opj_image * , struct opj_event_mgr *)) jp2_start_compress;
|
||||
l_info->m_codec_data.m_compression.opj_write_tile = (bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr *)) jp2_write_tile;
|
||||
l_info->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) jp2_destroy;
|
||||
l_info->m_codec_data.m_compression.opj_setup_encoder = (void (*) (void *,opj_cparameters_t *,struct opj_image *, struct opj_event_mgr * )) jp2_setup_encoder;
|
||||
|
||||
l_info->m_codec = jp2_create(false);
|
||||
if
|
||||
(! l_info->m_codec)
|
||||
{
|
||||
opj_free(l_info);
|
||||
return 00;
|
||||
}
|
||||
break;
|
||||
case CODEC_UNKNOWN:
|
||||
case CODEC_JPT:
|
||||
default:
|
||||
opj_free(l_info);
|
||||
return 00;
|
||||
}
|
||||
set_default_event_handler(&(l_info->m_event_mgr));
|
||||
return (opj_codec_t*) l_info;
|
||||
}
|
||||
|
||||
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
|
||||
if(parameters) {
|
||||
memset(parameters, 0, sizeof(opj_cparameters_t));
|
||||
/* default coding parameters */
|
||||
parameters->cp_cinema = OFF;
|
||||
parameters->max_comp_size = 0;
|
||||
parameters->numresolution = 6;
|
||||
parameters->cp_rsiz = STD_RSIZ;
|
||||
parameters->cblockw_init = 64;
|
||||
parameters->cblockh_init = 64;
|
||||
parameters->prog_order = LRCP;
|
||||
parameters->roi_compno = -1; /* no ROI */
|
||||
parameters->subsampling_dx = 1;
|
||||
parameters->subsampling_dy = 1;
|
||||
parameters->tp_on = 0;
|
||||
parameters->decod_format = -1;
|
||||
parameters->cod_format = -1;
|
||||
parameters->tcp_rates[0] = 0;
|
||||
parameters->tcp_numlayers = 0;
|
||||
parameters->cp_disto_alloc = 0;
|
||||
parameters->cp_fixed_alloc = 0;
|
||||
parameters->cp_fixed_quality = 0;
|
||||
/* UniPG>> */
|
||||
#ifdef USE_JPWL
|
||||
parameters->jpwl_epc_on = false;
|
||||
parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
|
||||
parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
|
||||
parameters->jpwl_hprot_TPH[i] = 0; /* absent */
|
||||
}
|
||||
};
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
|
||||
parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
|
||||
parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
|
||||
parameters->jpwl_pprot[i] = 0; /* absent */
|
||||
}
|
||||
};
|
||||
parameters->jpwl_sens_size = 0; /* 0 means no ESD */
|
||||
parameters->jpwl_sens_addr = 0; /* 0 means auto */
|
||||
parameters->jpwl_sens_range = 0; /* 0 means packet */
|
||||
parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
|
||||
parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
|
||||
parameters->jpwl_sens_TPH[i] = -1; /* absent */
|
||||
}
|
||||
};
|
||||
#endif /* USE_JPWL */
|
||||
/* <<UniPG */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function.
|
||||
* Sets the stream to be a file stream. The FILE must have been open previously.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_file handler to an already open file.
|
||||
*/
|
||||
opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file,bool p_is_read_stream)
|
||||
{
|
||||
return opj_stream_create_file_stream(p_file,J2K_STREAM_CHUNK_SIZE,p_is_read_stream);
|
||||
}
|
||||
|
||||
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file,OPJ_UINT32 p_size,bool p_is_read_stream)
|
||||
{
|
||||
opj_stream_t* l_stream = 00;
|
||||
if
|
||||
(! p_file)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
l_stream = opj_stream_create(p_size,p_is_read_stream);
|
||||
if
|
||||
(! l_stream)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
opj_stream_set_user_data(l_stream,p_file);
|
||||
opj_stream_set_read_function(l_stream,(opj_stream_read_fn) opj_read_from_file);
|
||||
opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
|
||||
opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
|
||||
opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
|
||||
return l_stream;
|
||||
}
|
||||
|
||||
|
||||
bool OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_info, opj_cparameters_t *parameters, opj_image_t *image)
|
||||
{
|
||||
if
|
||||
(p_info && parameters && image)
|
||||
{
|
||||
opj_codec_private_t * l_codec = ((opj_codec_private_t *) p_info);
|
||||
if
|
||||
(! l_codec->is_decompressor)
|
||||
{
|
||||
l_codec->m_codec_data.m_compression.opj_setup_encoder(l_codec->m_codec,parameters,image,&(l_codec->m_event_mgr));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *cio)
|
||||
{
|
||||
if
|
||||
(p_info && cio)
|
||||
{
|
||||
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_info;
|
||||
opj_stream_private_t * l_cio = (opj_stream_private_t *) cio;
|
||||
if
|
||||
(! l_codec->is_decompressor)
|
||||
{
|
||||
l_codec->m_codec_data.m_compression.opj_encode(l_codec->m_codec,l_cio,&(l_codec->m_event_mgr));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_start_compress (opj_codec_t *p_codec,opj_image_t * p_image,opj_stream_t *p_cio)
|
||||
{
|
||||
if
|
||||
(p_codec && p_cio)
|
||||
{
|
||||
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
||||
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
|
||||
if
|
||||
(! l_codec->is_decompressor)
|
||||
{
|
||||
return l_codec->m_codec_data.m_compression.opj_start_compress(l_codec->m_codec,l_cio,p_image,&(l_codec->m_event_mgr));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,opj_stream_t *p_cio)
|
||||
{
|
||||
if
|
||||
(p_codec && p_cio)
|
||||
{
|
||||
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
||||
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
|
||||
if
|
||||
(! l_codec->is_decompressor)
|
||||
{
|
||||
return l_codec->m_codec_data.m_compression.opj_end_compress(l_codec->m_codec,l_cio,&(l_codec->m_event_mgr));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data)
|
||||
{
|
||||
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
||||
if
|
||||
(! l_codec)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
l_codec->m_event_mgr.info_handler = p_callback;
|
||||
l_codec->m_event_mgr.m_info_data = p_user_data;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data)
|
||||
{
|
||||
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
||||
if
|
||||
(! l_codec)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
l_codec->m_event_mgr.warning_handler = p_callback;
|
||||
l_codec->m_event_mgr.m_warning_data = p_user_data;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data)
|
||||
{
|
||||
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
||||
if
|
||||
(! l_codec)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
l_codec->m_event_mgr.error_handler = p_callback;
|
||||
l_codec->m_event_mgr.m_error_data = p_user_data;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_stream_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
|
||||
if(cinfo && cio && image) {
|
||||
switch(cinfo->codec_format) {
|
||||
case CODEC_J2K:
|
||||
return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, (opj_stream_private_t *) cio, image, cstr_info);
|
||||
case CODEC_JP2:
|
||||
return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, (opj_stream_private_t *) cio, image, cstr_info);
|
||||
case CODEC_JPT:
|
||||
case CODEC_UNKNOWN:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}*/
|
||||
|
||||
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
|
||||
if
|
||||
(cstr_info)
|
||||
{
|
||||
int tileno;
|
||||
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
|
||||
opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
|
||||
opj_free(tile_info->thresh);
|
||||
opj_free(tile_info->packet);
|
||||
opj_free(tile_info->tp);
|
||||
}
|
||||
opj_free(cstr_info->tile);
|
||||
opj_free(cstr_info->marker);
|
||||
}
|
||||
}
|
||||
|
||||
bool OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,OPJ_FLOAT32 * pEncodingMatrix,OPJ_INT32 * p_dc_shift,OPJ_UINT32 pNbComp)
|
||||
{
|
||||
OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * sizeof(OPJ_FLOAT32);
|
||||
OPJ_UINT32 l_dc_shift_size = pNbComp * sizeof(OPJ_INT32);
|
||||
OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size;
|
||||
// add MCT capability
|
||||
int rsiz = (int)parameters->cp_rsiz | (int)MCT;
|
||||
parameters->cp_rsiz = (OPJ_RSIZ_CAPABILITIES)rsiz;
|
||||
parameters->irreversible = 1;
|
||||
// use array based MCT
|
||||
parameters->tcp_mct = 2;
|
||||
parameters->mct_data = opj_malloc(l_mct_total_size);
|
||||
if
|
||||
(! parameters->mct_data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
memcpy(parameters->mct_data,pEncodingMatrix,l_matrix_size);
|
||||
memcpy(((OPJ_BYTE *) parameters->mct_data) + l_matrix_size,p_dc_shift,l_dc_shift_size);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restricts the decoding to the given image area.
|
||||
*
|
||||
* @param parameters the parameters to update.
|
||||
* @param p_start_x the starting x position of the area to decode.
|
||||
* @param p_start_y the starting y position of the area to decode.
|
||||
* @param p_end_x the x end position of the area to decode.
|
||||
* @param p_end_x the y end position of the area to decode.
|
||||
*/
|
||||
OPJ_API bool OPJ_CALLCONV opj_restrict_decoding (opj_dparameters_t *parameters,OPJ_INT32 p_start_x,OPJ_INT32 p_start_y,OPJ_INT32 p_end_x,OPJ_INT32 p_end_y)
|
||||
{
|
||||
parameters->m_use_restrict_decode = 1;
|
||||
parameters->m_decode_start_x = p_start_x;
|
||||
parameters->m_decode_start_y = p_start_y;
|
||||
parameters->m_decode_end_x = p_end_x;
|
||||
parameters->m_decode_end_y = p_end_y;
|
||||
return true;
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2006-2007, Parvatha Elangovan
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,45 +33,60 @@
|
||||
#ifndef OPENJPEG_H
|
||||
#define OPENJPEG_H
|
||||
|
||||
#if defined(OPJ_STATIC) || !defined(_WIN32)
|
||||
#define OPJ_API
|
||||
#define OPJ_CALLCONV
|
||||
#else
|
||||
#define OPJ_CALLCONV __stdcall
|
||||
#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
|
||||
#define OPJ_API __declspec(dllexport)
|
||||
#else
|
||||
#define OPJ_API __declspec(dllimport)
|
||||
#endif /* OPJ_EXPORTS || DLL_EXPORT */
|
||||
#endif /* !OPJ_STATIC || !_WIN32 */
|
||||
|
||||
#ifndef __cplusplus
|
||||
#if defined(HAVE_STDBOOL_H)
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
#if !defined(bool)
|
||||
#define bool int
|
||||
#endif
|
||||
#if !defined(true)
|
||||
#define true 1
|
||||
#endif
|
||||
#if !defined(false)
|
||||
#define false 0
|
||||
#endif
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
typedef unsigned int OPJ_UINT32;
|
||||
typedef int OPJ_INT32;
|
||||
typedef unsigned short OPJ_UINT16;
|
||||
typedef short OPJ_INT16;
|
||||
typedef char OPJ_CHAR;
|
||||
typedef unsigned char OPJ_BYTE;
|
||||
typedef unsigned int OPJ_SIZE_T;
|
||||
typedef double OPJ_FLOAT64;
|
||||
typedef float OPJ_FLOAT32;
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 OPJ_INT64;
|
||||
#else
|
||||
typedef long long OPJ_INT64;
|
||||
#endif
|
||||
|
||||
#define OPENJPEG_VERSION "2.0.0"
|
||||
/*
|
||||
==========================================================
|
||||
Compiler directives
|
||||
==========================================================
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
#if defined(OPJ_STATIC) || !defined(_WIN32)
|
||||
/* http://gcc.gnu.org/wiki/Visibility */
|
||||
#if __GNUC__ >= 4
|
||||
#define OPJ_API __attribute__ ((visibility ("default")))
|
||||
#define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
|
||||
#else
|
||||
#define OPJ_API
|
||||
#define OPJ_LOCAL
|
||||
#endif
|
||||
#define OPJ_CALLCONV
|
||||
#else
|
||||
#define OPJ_CALLCONV __stdcall
|
||||
/*
|
||||
The following ifdef block is the standard way of creating macros which make exporting
|
||||
from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
|
||||
symbol defined on the command line. this symbol should not be defined on any project
|
||||
that uses this DLL. This way any other project whose source files include this file see
|
||||
OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
defined with this macro as being exported.
|
||||
*/
|
||||
#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
|
||||
#define OPJ_API __declspec(dllexport)
|
||||
#else
|
||||
#define OPJ_API __declspec(dllimport)
|
||||
#endif /* OPJ_EXPORTS */
|
||||
#endif /* !OPJ_STATIC || !_WIN32 */
|
||||
|
||||
typedef int opj_bool;
|
||||
#define OPJ_TRUE 1
|
||||
#define OPJ_FALSE 0
|
||||
|
||||
/* Avoid compile-time warning because parameter is not used */
|
||||
#define OPJ_ARG_NOT_USED(x) (void)(x)
|
||||
/*
|
||||
==========================================================
|
||||
Useful constant definitions
|
||||
@@ -79,9 +94,13 @@ typedef int opj_bool;
|
||||
*/
|
||||
|
||||
#define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
|
||||
|
||||
#define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
|
||||
#define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
|
||||
#define J2K_DEFAULT_NB_SEGS 10
|
||||
#define J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
|
||||
#define J2K_DEFAULT_HEADER_SIZE 1000
|
||||
#define J2K_MCC_DEFAULT_NB_RECORDS 10
|
||||
#define J2K_MCT_DEFAULT_NB_RECORDS 10
|
||||
|
||||
/* UniPG>> */
|
||||
#define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
|
||||
@@ -105,7 +124,8 @@ Rsiz Capabilities
|
||||
typedef enum RSIZ_CAPABILITIES {
|
||||
STD_RSIZ = 0, /** Standard JPEG2000 profile*/
|
||||
CINEMA2K = 3, /** Profile name for a 2K image*/
|
||||
CINEMA4K = 4 /** Profile name for a 4K image*/
|
||||
CINEMA4K = 4, /** Profile name for a 4K image*/
|
||||
MCT = 0x8100
|
||||
} OPJ_RSIZ_CAPABILITIES;
|
||||
|
||||
/**
|
||||
@@ -141,10 +161,6 @@ typedef enum COLOR_SPACE {
|
||||
CLRSPC_SYCC = 3 /**< YUV */
|
||||
} OPJ_COLOR_SPACE;
|
||||
|
||||
#define ENUMCS_SRGB 16
|
||||
#define ENUMCS_GRAY 17
|
||||
#define ENUMCS_SYCC 18
|
||||
|
||||
/**
|
||||
Supported codec
|
||||
*/
|
||||
@@ -155,14 +171,8 @@ typedef enum CODEC_FORMAT {
|
||||
CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
|
||||
} OPJ_CODEC_FORMAT;
|
||||
|
||||
/**
|
||||
Limit decoding to certain portions of the codestream.
|
||||
*/
|
||||
typedef enum LIMIT_DECODING {
|
||||
NO_LIMITATION = 0, /**< No limitation for the decoding. The entire codestream will de decoded */
|
||||
LIMIT_TO_MAIN_HEADER = 1, /**< The decoding is limited to the Main Header */
|
||||
DECODE_ALL_BUT_PACKETS = 2 /**< Decode everything except the JPEG 2000 packets */
|
||||
} OPJ_LIMIT_DECODING;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
@@ -175,25 +185,9 @@ Callback function prototype for events
|
||||
@param msg Event message
|
||||
@param client_data
|
||||
*/
|
||||
typedef void (*opj_msg_callback) (const char *msg, void *client_data);
|
||||
typedef void (*opj_msg_callback) (const OPJ_CHAR *msg, void *client_data);
|
||||
|
||||
|
||||
/**
|
||||
Message handler object
|
||||
used for
|
||||
<ul>
|
||||
<li>Error messages
|
||||
<li>Warning messages
|
||||
<li>Debugging messages
|
||||
</ul>
|
||||
*/
|
||||
typedef struct opj_event_mgr {
|
||||
/** Error message callback if available, NULL otherwise */
|
||||
opj_msg_callback error_handler;
|
||||
/** Warning message callback if available, NULL otherwise */
|
||||
opj_msg_callback warning_handler;
|
||||
/** Debug message callback if available, NULL otherwise */
|
||||
opj_msg_callback info_handler;
|
||||
} opj_event_mgr_t;
|
||||
|
||||
|
||||
/*
|
||||
@@ -205,29 +199,30 @@ typedef struct opj_event_mgr {
|
||||
/**
|
||||
Progression order changes
|
||||
*/
|
||||
typedef struct opj_poc {
|
||||
typedef struct opj_poc
|
||||
{
|
||||
/** Resolution num start, Component num start, given by POC */
|
||||
int resno0, compno0;
|
||||
OPJ_UINT32 resno0, compno0;
|
||||
/** Layer num end,Resolution num end, Component num end, given by POC */
|
||||
int layno1, resno1, compno1;
|
||||
OPJ_UINT32 layno1, resno1, compno1;
|
||||
/** Layer num start,Precinct num start, Precinct num end */
|
||||
int layno0, precno0, precno1;
|
||||
OPJ_UINT32 layno0, precno0, precno1;
|
||||
/** Progression order enum*/
|
||||
OPJ_PROG_ORDER prg1,prg;
|
||||
/** Progression order string*/
|
||||
char progorder[5];
|
||||
OPJ_CHAR progorder[5];
|
||||
/** Tile number */
|
||||
int tile;
|
||||
OPJ_UINT32 tile;
|
||||
/** Start and end values for Tile width and height*/
|
||||
int tx0,tx1,ty0,ty1;
|
||||
OPJ_INT32 tx0,tx1,ty0,ty1;
|
||||
/** Start value, initialised in pi_initialise_encode*/
|
||||
int layS, resS, compS, prcS;
|
||||
OPJ_UINT32 layS, resS, compS, prcS;
|
||||
/** End value, initialised in pi_initialise_encode */
|
||||
int layE, resE, compE, prcE;
|
||||
OPJ_UINT32 layE, resE, compE, prcE;
|
||||
/** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
|
||||
int txS,txE,tyS,tyE,dx,dy;
|
||||
OPJ_UINT32 txS,txE,tyS,tyE,dx,dy;
|
||||
/** Temporary values for Tile parts, initialised in pi_create_encode */
|
||||
int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
|
||||
OPJ_UINT32 lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
|
||||
} opj_poc_t;
|
||||
|
||||
/**
|
||||
@@ -235,7 +230,7 @@ Compression parameters
|
||||
*/
|
||||
typedef struct opj_cparameters {
|
||||
/** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
|
||||
opj_bool tile_size_on;
|
||||
bool tile_size_on;
|
||||
/** XTOsiz */
|
||||
int cp_tx0;
|
||||
/** YTOsiz */
|
||||
@@ -317,7 +312,7 @@ typedef struct opj_cparameters {
|
||||
/**@name JPWL encoding parameters */
|
||||
/*@{*/
|
||||
/** enables writing of EPC in MH, thus activating JPWL */
|
||||
opj_bool jpwl_epc_on;
|
||||
bool jpwl_epc_on;
|
||||
/** error protection method for MH (0,1,16,32,37-128) */
|
||||
int jpwl_hprot_MH;
|
||||
/** tile number of header protection specification (>=0) */
|
||||
@@ -357,9 +352,10 @@ typedef struct opj_cparameters {
|
||||
char tp_flag;
|
||||
/** MCT (multiple component transform) */
|
||||
char tcp_mct;
|
||||
} opj_cparameters_t;
|
||||
/** Naive implementation of MCT restricted to a single reversible array based encoding without offset concerning all the components. */
|
||||
void * mct_data;
|
||||
|
||||
#define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
|
||||
} opj_cparameters_t;
|
||||
|
||||
/**
|
||||
Decompression parameters
|
||||
@@ -381,6 +377,14 @@ typedef struct opj_dparameters {
|
||||
*/
|
||||
int cp_layer;
|
||||
|
||||
/**
|
||||
* Restrictive decoding parameters.
|
||||
*/
|
||||
OPJ_INT32 m_decode_start_x;
|
||||
OPJ_INT32 m_decode_start_y ;
|
||||
OPJ_INT32 m_decode_end_x ;
|
||||
OPJ_INT32 m_decode_end_y ;
|
||||
|
||||
/**@name command line encoder parameters (not used inside the library) */
|
||||
/*@{*/
|
||||
/** input file name */
|
||||
@@ -397,67 +401,24 @@ typedef struct opj_dparameters {
|
||||
/**@name JPWL decoding parameters */
|
||||
/*@{*/
|
||||
/** activates the JPWL correction capabilities */
|
||||
opj_bool jpwl_correct;
|
||||
bool jpwl_correct;
|
||||
/** expected number of components */
|
||||
int jpwl_exp_comps;
|
||||
/** maximum number of tiles */
|
||||
int jpwl_max_tiles;
|
||||
|
||||
/** use restrictive decoding ? */
|
||||
OPJ_UINT32 m_use_restrict_decode : 1;
|
||||
/*@}*/
|
||||
/* <<UniPG */
|
||||
|
||||
/**
|
||||
Specify whether the decoding should be done on the entire codestream, or be limited to the main header
|
||||
Limiting the decoding to the main header makes it possible to extract the characteristics of the codestream
|
||||
if == NO_LIMITATION, the entire codestream is decoded;
|
||||
if == LIMIT_TO_MAIN_HEADER, only the main header is decoded;
|
||||
*/
|
||||
OPJ_LIMIT_DECODING cp_limit_decoding;
|
||||
|
||||
unsigned int flags;
|
||||
} opj_dparameters_t;
|
||||
|
||||
/** Common fields between JPEG-2000 compression and decompression master structs. */
|
||||
|
||||
#define opj_common_fields \
|
||||
opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
|
||||
void * client_data; /**< Available for use by application */\
|
||||
opj_bool is_decompressor; /**< So common code can tell which is which */\
|
||||
OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
|
||||
void *j2k_handle; /**< pointer to the J2K codec */\
|
||||
void *jp2_handle; /**< pointer to the JP2 codec */\
|
||||
void *mj2_handle /**< pointer to the MJ2 codec */
|
||||
|
||||
/* Routines that are to be used by both halves of the library are declared
|
||||
* to receive a pointer to this structure. There are no actual instances of
|
||||
* opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t.
|
||||
*/
|
||||
typedef struct opj_common_struct {
|
||||
opj_common_fields; /* Fields common to both master struct types */
|
||||
/* Additional fields follow in an actual opj_cinfo_t or
|
||||
* opj_dinfo_t. All three structs must agree on these
|
||||
* initial fields! (This would be a lot cleaner in C++.)
|
||||
*/
|
||||
} opj_common_struct_t;
|
||||
|
||||
typedef opj_common_struct_t * opj_common_ptr;
|
||||
|
||||
/**
|
||||
Compression context info
|
||||
* J2k codec.
|
||||
*/
|
||||
typedef struct opj_cinfo {
|
||||
/** Fields shared with opj_dinfo_t */
|
||||
opj_common_fields;
|
||||
/* other specific fields go here */
|
||||
} opj_cinfo_t;
|
||||
typedef void * opj_codec_t;
|
||||
|
||||
/**
|
||||
Decompression context info
|
||||
*/
|
||||
typedef struct opj_dinfo {
|
||||
/** Fields shared with opj_cinfo_t */
|
||||
opj_common_fields;
|
||||
/* other specific fields go here */
|
||||
} opj_dinfo_t;
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
@@ -473,27 +434,14 @@ typedef struct opj_dinfo {
|
||||
/** The stream was opened for writing. */
|
||||
#define OPJ_STREAM_WRITE 0x0002
|
||||
|
||||
/**
|
||||
Byte input-output stream (CIO)
|
||||
*/
|
||||
typedef struct opj_cio {
|
||||
/** codec context */
|
||||
opj_common_ptr cinfo;
|
||||
|
||||
/** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
|
||||
int openmode;
|
||||
/** pointer to the start of the buffer */
|
||||
unsigned char *buffer;
|
||||
/** buffer size in bytes */
|
||||
int length;
|
||||
typedef OPJ_UINT32 (* opj_stream_read_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
|
||||
typedef OPJ_UINT32 (* opj_stream_write_fn) (void * p_buffer, OPJ_UINT32 p_nb_bytes, void * p_user_data) ;
|
||||
typedef OPJ_SIZE_T (* opj_stream_skip_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
|
||||
typedef bool (* opj_stream_seek_fn) (OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
|
||||
|
||||
/** pointer to the start of the stream */
|
||||
unsigned char *start;
|
||||
/** pointer to the end of the stream */
|
||||
unsigned char *end;
|
||||
/** pointer to the current position */
|
||||
unsigned char *bp;
|
||||
} opj_cio_t;
|
||||
|
||||
typedef void * opj_stream_t;
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
@@ -506,53 +454,49 @@ Defines a single image component
|
||||
*/
|
||||
typedef struct opj_image_comp {
|
||||
/** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
|
||||
int dx;
|
||||
OPJ_UINT32 dx;
|
||||
/** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
|
||||
int dy;
|
||||
OPJ_UINT32 dy;
|
||||
/** data width */
|
||||
int w;
|
||||
OPJ_UINT32 w;
|
||||
/** data height */
|
||||
int h;
|
||||
OPJ_UINT32 h;
|
||||
/** x component offset compared to the whole image */
|
||||
int x0;
|
||||
OPJ_INT32 x0;
|
||||
/** y component offset compared to the whole image */
|
||||
int y0;
|
||||
OPJ_INT32 y0;
|
||||
/** precision */
|
||||
int prec;
|
||||
/** image depth in bits */
|
||||
int bpp;
|
||||
/** signed (1) / unsigned (0) */
|
||||
int sgnd;
|
||||
OPJ_UINT32 prec;
|
||||
/** number of decoded resolution */
|
||||
int resno_decoded;
|
||||
OPJ_UINT32 resno_decoded;
|
||||
/** number of division by 2 of the out image compared to the original size of image */
|
||||
int factor;
|
||||
OPJ_UINT32 factor;
|
||||
/** image component data */
|
||||
int *data;
|
||||
/** signed (1) / unsigned (0) */
|
||||
OPJ_UINT32 sgnd : 1;
|
||||
|
||||
} opj_image_comp_t;
|
||||
|
||||
/**
|
||||
Defines image data and characteristics
|
||||
*/
|
||||
typedef struct opj_image {
|
||||
typedef struct opj_image
|
||||
{
|
||||
/** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
|
||||
int x0;
|
||||
OPJ_INT32 x0;
|
||||
/** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
|
||||
int y0;
|
||||
OPJ_INT32 y0;
|
||||
/** Xsiz: width of the reference grid */
|
||||
int x1;
|
||||
OPJ_INT32 x1;
|
||||
/** Ysiz: height of the reference grid */
|
||||
int y1;
|
||||
OPJ_INT32 y1;
|
||||
/** number of components in the image */
|
||||
int numcomps;
|
||||
OPJ_UINT32 numcomps;
|
||||
/** color space: sRGB, Greyscale or YUV */
|
||||
OPJ_COLOR_SPACE color_space;
|
||||
/** image components */
|
||||
opj_image_comp_t *comps;
|
||||
/** 'restricted' ICC profile */
|
||||
unsigned char *icc_profile_buf;
|
||||
/** size of ICC profile */
|
||||
int icc_profile_len;
|
||||
} opj_image_t;
|
||||
|
||||
/**
|
||||
@@ -560,13 +504,13 @@ Component parameters structure used by the opj_image_create function
|
||||
*/
|
||||
typedef struct opj_image_comptparm {
|
||||
/** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
|
||||
int dx;
|
||||
unsigned int dx;
|
||||
/** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
|
||||
int dy;
|
||||
unsigned int dy;
|
||||
/** data width */
|
||||
int w;
|
||||
unsigned int w;
|
||||
/** data height */
|
||||
int h;
|
||||
unsigned int h;
|
||||
/** x component offset compared to the whole image */
|
||||
int x0;
|
||||
/** y component offset compared to the whole image */
|
||||
@@ -599,21 +543,6 @@ typedef struct opj_packet_info {
|
||||
double disto;
|
||||
} opj_packet_info_t;
|
||||
|
||||
|
||||
/* UniPG>> */
|
||||
/**
|
||||
Marker structure
|
||||
*/
|
||||
typedef struct opj_marker_info_t {
|
||||
/** marker type */
|
||||
unsigned short int type;
|
||||
/** position in codestream */
|
||||
int pos;
|
||||
/** length, marker val included */
|
||||
int len;
|
||||
} opj_marker_info_t;
|
||||
/* <<UniPG */
|
||||
|
||||
/**
|
||||
Index structure : Information concerning tile-parts
|
||||
*/
|
||||
@@ -658,18 +587,26 @@ typedef struct opj_tile_info {
|
||||
int numpix;
|
||||
/** add fixed_quality */
|
||||
double distotile;
|
||||
/** number of markers */
|
||||
int marknum;
|
||||
/** list of markers */
|
||||
opj_marker_info_t *marker;
|
||||
/** actual size of markers array */
|
||||
int maxmarknum;
|
||||
/** number of tile parts */
|
||||
int num_tps;
|
||||
/** information concerning tile parts */
|
||||
opj_tp_info_t *tp;
|
||||
} opj_tile_info_t;
|
||||
|
||||
/* UniPG>> */
|
||||
/**
|
||||
Marker structure
|
||||
*/
|
||||
typedef struct opj_marker_info_t {
|
||||
/** marker type */
|
||||
unsigned short int type;
|
||||
/** position in codestream */
|
||||
int pos;
|
||||
/** length, marker val included */
|
||||
int len;
|
||||
} opj_marker_info_t;
|
||||
/* <<UniPG */
|
||||
|
||||
/**
|
||||
Index structure of the codestream
|
||||
*/
|
||||
@@ -733,7 +670,7 @@ extern "C" {
|
||||
==========================================================
|
||||
*/
|
||||
|
||||
OPJ_API const char * OPJ_CALLCONV opj_version(void);
|
||||
OPJ_API const OPJ_CHAR * OPJ_CALLCONV opj_version(void);
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
@@ -748,7 +685,18 @@ Create an image
|
||||
@param clrspc image color space
|
||||
@return returns a new image structure if successful, returns NULL otherwise
|
||||
*/
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
|
||||
|
||||
/**
|
||||
* Creates an image without allocating memory for the image (used in the new version of the library).
|
||||
*
|
||||
* @param p_num_cmpts the number of components
|
||||
* @param p_cmpt_parms the components parameters
|
||||
* @param p_clr_spc the image color space
|
||||
*
|
||||
* @return a new image structure if successful, NULL otherwise.
|
||||
*/
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
|
||||
|
||||
/**
|
||||
Deallocate any resources associated with an image
|
||||
@@ -763,44 +711,80 @@ OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
|
||||
*/
|
||||
|
||||
/**
|
||||
Open and allocate a memory stream for read / write.
|
||||
On reading, the user must provide a buffer containing encoded data. The buffer will be
|
||||
wrapped by the returned CIO handle.
|
||||
On writing, buffer parameters must be set to 0: a buffer will be allocated by the library
|
||||
to contain encoded data.
|
||||
@param cinfo Codec context info
|
||||
@param buffer Reading: buffer address. Writing: NULL
|
||||
@param length Reading: buffer length. Writing: 0
|
||||
@return Returns a CIO handle if successful, returns NULL otherwise
|
||||
* Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
|
||||
*
|
||||
* @param l_is_reader if set to true then the stream will be an input stream, an output stream else.
|
||||
*
|
||||
* @return a stream object.
|
||||
*/
|
||||
OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length);
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(bool p_is_input);
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_UINT32 p_size,bool p_is_input);
|
||||
|
||||
/**
|
||||
Close and free a CIO handle
|
||||
@param cio CIO handle to free
|
||||
* Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
|
||||
* close its own implementation of the stream.
|
||||
*
|
||||
* @param p_stream the stream to destroy.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio);
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
|
||||
|
||||
/**
|
||||
Get position in byte stream
|
||||
@param cio CIO handle
|
||||
@return Returns the position in bytes
|
||||
* Sets the given function to be used as a read function.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_function the function to use a read function.
|
||||
*/
|
||||
OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio);
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
|
||||
|
||||
/**
|
||||
Set position in byte stream
|
||||
@param cio CIO handle
|
||||
@param pos Position, in number of bytes, from the beginning of the stream
|
||||
* Sets the given function to be used as a write function.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_function the function to use a write function.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos);
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
|
||||
|
||||
/**
|
||||
* Sets the given function to be used as a skip function.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_function the function to use a skip function.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
|
||||
|
||||
/**
|
||||
* Sets the given function to be used as a seek function, the stream is then seekable.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_function the function to use a skip function.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the given data to be used as a user data for the stream.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_data the data to set.
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
|
||||
|
||||
/**
|
||||
* Helper function.
|
||||
* Sets the stream to be a file stream. The FILE must have been open previously.
|
||||
* @param p_stream the stream to modify
|
||||
* @param p_file handler to an already open file.
|
||||
*/
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file,bool p_is_read_stream);
|
||||
OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file,OPJ_UINT32 p_buffer_size, bool p_is_read_stream);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
event manager functions definitions
|
||||
==========================================================
|
||||
*/
|
||||
OPJ_API bool OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data);
|
||||
OPJ_API bool OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data);
|
||||
OPJ_API bool OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, opj_msg_callback p_callback,void * p_user_data);
|
||||
|
||||
|
||||
OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context);
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
@@ -812,31 +796,130 @@ Creates a J2K/JPT/JP2 decompression structure
|
||||
@param format Decoder to select
|
||||
@return Returns a handle to a decompressor if successful, returns NULL otherwise
|
||||
*/
|
||||
OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
|
||||
/**
|
||||
Destroy a decompressor handle
|
||||
@param dinfo decompressor handle to destroy
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo);
|
||||
OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
|
||||
|
||||
/**
|
||||
Set decoding parameters to default values
|
||||
@param parameters Decompression parameters
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
|
||||
|
||||
#ifdef USE_OPJ_DEPRECATED
|
||||
#ifdef _MSC_VER
|
||||
#pragma message ( "warning, opj_setup_decoder is deprecated")
|
||||
#else
|
||||
#warning "warning, opj_setup_decoder is deprecated"
|
||||
#endif
|
||||
/**
|
||||
Setup the decoder decoding parameters using user parameters.
|
||||
Decoding parameters are returned in j2k->cp.
|
||||
@param dinfo decompressor handle
|
||||
@param parameters decompression parameters
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters);
|
||||
OPJ_API bool OPJ_CALLCONV opj_setup_decoder(opj_codec_t *dinfo, opj_dparameters_t *parameters);
|
||||
#endif
|
||||
|
||||
/**
|
||||
Decode an image from a JPEG-2000 codestream
|
||||
@param dinfo decompressor handle
|
||||
@param cio Input buffer stream
|
||||
@return Returns a decoded image if successful, returns NULL otherwise
|
||||
*/
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio);
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_decode(opj_codec_t *p_decompressor, opj_stream_t * cio);
|
||||
|
||||
/**
|
||||
* Writes a tile with the given data.
|
||||
*
|
||||
* @param p_compressor the jpeg2000 codec.
|
||||
* @param p_tile_index the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
|
||||
* @param p_data pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set.
|
||||
* @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes,
|
||||
* depending on the precision of the given component.
|
||||
* @param p_stream the stream to write data to.
|
||||
*
|
||||
* @return true if the data could be written.
|
||||
*/
|
||||
OPJ_API bool OPJ_CALLCONV opj_write_tile (
|
||||
opj_codec_t *p_codec,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_t *p_stream
|
||||
);
|
||||
|
||||
/**
|
||||
* Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
|
||||
* The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
|
||||
*
|
||||
* @param p_codec the jpeg2000 codec.
|
||||
* @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
|
||||
* @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
|
||||
* of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
|
||||
* as depicted in opj_write_tile.
|
||||
* @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
|
||||
* @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
|
||||
* @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
|
||||
* @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
|
||||
* @param p_nb_comps pointer to a value that will hold the number of components in the tile.
|
||||
* @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
|
||||
* codestream is over at the time of the call, the value will be set to false. The user should then stop
|
||||
* the decoding.
|
||||
* @param p_stream the stream to decode.
|
||||
* @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
|
||||
* returning false may be the result of a shortage of memory or an internal error.
|
||||
*/
|
||||
OPJ_API bool OPJ_CALLCONV opj_read_tile_header(
|
||||
opj_codec_t *p_codec,
|
||||
OPJ_UINT32 * p_tile_index,
|
||||
OPJ_UINT32 * p_data_size,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
OPJ_INT32 * p_tile_y0,
|
||||
OPJ_INT32 * p_tile_x1,
|
||||
OPJ_INT32 * p_tile_y1,
|
||||
OPJ_UINT32 * p_nb_comps,
|
||||
bool * p_should_go_on,
|
||||
opj_stream_t * p_stream);
|
||||
|
||||
|
||||
/**
|
||||
* Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
|
||||
* The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
|
||||
*
|
||||
* @param p_codec the jpeg2000 codec.
|
||||
* @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
|
||||
* @param p_data pointer to a memory block that will hold the decoded data.
|
||||
* @param p_data_size size of p_data. p_data_size should be bigger or equal to the value set by opj_read_tile_header.
|
||||
* @param p_stream the stream to decode.
|
||||
*
|
||||
* @return true if the data could be decoded.
|
||||
*/
|
||||
OPJ_API bool OPJ_CALLCONV opj_decode_tile_data(
|
||||
opj_codec_t *p_codec,
|
||||
OPJ_UINT32 p_tile_index,
|
||||
OPJ_BYTE * p_data,
|
||||
OPJ_UINT32 p_data_size,
|
||||
opj_stream_t *p_stream
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
|
||||
*
|
||||
* @param p_codec the jpeg2000 codec.
|
||||
* @param p_start_x the left position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_x the right position of the rectangle to decode (in image coordinates).
|
||||
* @param p_start_y the up position of the rectangle to decode (in image coordinates).
|
||||
* @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
|
||||
*
|
||||
* @return true if the area could be set.
|
||||
*/
|
||||
OPJ_API bool OPJ_CALLCONV opj_set_decode_area(
|
||||
opj_codec_t *p_codec,
|
||||
OPJ_INT32 p_start_x,
|
||||
OPJ_INT32 p_start_y,
|
||||
OPJ_INT32 p_end_x,
|
||||
OPJ_INT32 p_end_y
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
Decode an image from a JPEG-2000 codestream and extract the codestream information
|
||||
@@ -845,18 +928,20 @@ Decode an image from a JPEG-2000 codestream and extract the codestream informati
|
||||
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise
|
||||
@return Returns a decoded image if successful, returns NULL otherwise
|
||||
*/
|
||||
OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
|
||||
//OPJ_API opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_stream_t cio, opj_codestream_info_t *cstr_info);
|
||||
/**
|
||||
Creates a J2K/JP2 compression structure
|
||||
@param format Coder to select
|
||||
@return Returns a handle to a compressor if successful, returns NULL otherwise
|
||||
*/
|
||||
OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
|
||||
OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
|
||||
|
||||
/**
|
||||
Destroy a compressor handle
|
||||
@param cinfo compressor handle to destroy
|
||||
Destroy a decompressor handle
|
||||
@param dinfo decompressor handle to destroy
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo);
|
||||
OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
|
||||
|
||||
/**
|
||||
Set encoding parameters to default values, that means :
|
||||
<ul>
|
||||
@@ -879,22 +964,83 @@ Set encoding parameters to default values, that means :
|
||||
@param parameters Compression parameters
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
|
||||
|
||||
/**
|
||||
* Sets the MCT matrix to use.
|
||||
*
|
||||
* @param parameters the parameters to change.
|
||||
* @param pEncodingMatrix the encoding matrix.
|
||||
* @param p_dc_shift the dc shift coefficients to use.
|
||||
* @param pNbComp the number of components of the image.
|
||||
*
|
||||
* @return true if the parameters could be set.
|
||||
*/
|
||||
OPJ_API bool OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,OPJ_FLOAT32 * pEncodingMatrix,OPJ_INT32 * p_dc_shift,OPJ_UINT32 pNbComp);
|
||||
|
||||
/**
|
||||
* Restricts the decoding to the given image area.
|
||||
*
|
||||
* @param parameters the parameters to update.
|
||||
* @param p_start_x the starting x position of the area to decode.
|
||||
* @param p_start_y the starting y position of the area to decode.
|
||||
* @param p_end_x the x end position of the area to decode.
|
||||
* @param p_end_x the y end position of the area to decode.
|
||||
*/
|
||||
OPJ_API bool OPJ_CALLCONV opj_restrict_decoding (opj_dparameters_t *parameters,OPJ_INT32 p_start_x,OPJ_INT32 p_start_y,OPJ_INT32 p_end_x,OPJ_INT32 p_end_y);
|
||||
|
||||
#ifdef USE_OPJ_DEPRECATED
|
||||
#ifdef _MSC_VER
|
||||
#pragma message ("warning, opj_setup_encoder is deprecated")
|
||||
#else
|
||||
#warning "warning, opj_setup_encoder is deprecated"
|
||||
#endif
|
||||
/**
|
||||
Setup the encoder parameters using the current image and using user parameters.
|
||||
@param cinfo Compressor handle
|
||||
@param parameters Compression parameters
|
||||
@param image Input filled image
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
|
||||
OPJ_API bool OPJ_CALLCONV opj_setup_encoder(opj_codec_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Decodes an image header.
|
||||
*
|
||||
* @param p_codec codec to use to decode the image.
|
||||
* @param p_image pointer to a previously created image.
|
||||
* @param p_tile_x0 pointer to a value that will hold the reference point x0 of the tiling grid.
|
||||
* @param p_tile_y0 pointer to a value that will hold the reference point y0 of the tiling grid.
|
||||
* @param p_tile_width pointer to a value that will hold the size in x of a tile in the grid.
|
||||
* @param p_tile_height pointer to a value that will hold the size in y of a tile in the grid.
|
||||
* @param p_nb_tiles_x pointer to a value that will hold the number of tiles in the x direction.
|
||||
* @param p_nb_tiles_y pointer to a value that will hold the number of tiles in the y direction.
|
||||
*/
|
||||
OPJ_API bool OPJ_CALLCONV opj_read_header (
|
||||
opj_codec_t *p_codec,
|
||||
opj_image_t ** p_image,
|
||||
OPJ_INT32 * p_tile_x0,
|
||||
OPJ_INT32 * p_tile_y0,
|
||||
OPJ_UINT32 * p_tile_width,
|
||||
OPJ_UINT32 * p_tile_height,
|
||||
OPJ_UINT32 * p_nb_tiles_x,
|
||||
OPJ_UINT32 * p_nb_tiles_y,
|
||||
opj_stream_t *p_cio);
|
||||
|
||||
|
||||
OPJ_API bool OPJ_CALLCONV opj_end_decompress (opj_codec_t *p_codec,opj_stream_t *p_cio);
|
||||
/**
|
||||
Encode an image into a JPEG-2000 codestream
|
||||
3@param cinfo compressor handle
|
||||
@param cinfo compressor handle
|
||||
@param cio Output buffer stream
|
||||
@param image Image to encode
|
||||
@param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
|
||||
@return Returns true if successful, returns false otherwise
|
||||
*/
|
||||
OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
|
||||
OPJ_API bool OPJ_CALLCONV opj_encode(opj_codec_t *cinfo, opj_stream_t * cio);
|
||||
|
||||
OPJ_API bool OPJ_CALLCONV opj_start_compress (opj_codec_t *p_codec,opj_image_t * p_image,opj_stream_t *p_cio);
|
||||
|
||||
OPJ_API bool OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,opj_stream_t *p_cio);
|
||||
/**
|
||||
Encode an image into a JPEG-2000 codestream and extract the codestream information
|
||||
@param cinfo compressor handle
|
||||
@@ -903,16 +1049,32 @@ Encode an image into a JPEG-2000 codestream and extract the codestream informati
|
||||
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise
|
||||
@return Returns true if successful, returns false otherwise
|
||||
*/
|
||||
OPJ_API opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
||||
//OPJ_API bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_stream_t cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
||||
/**
|
||||
Destroy Codestream information after compression or decompression
|
||||
@param cstr_info Codestream information structure
|
||||
*/
|
||||
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
|
||||
|
||||
//==============================================================================
|
||||
//==============================================================================
|
||||
/** profiling part */
|
||||
#ifdef _PROFILE
|
||||
void _ProfInit(void);
|
||||
void _ProfPrint(void);
|
||||
#define PROFINIT() _ProfInit();
|
||||
#define PROFSAVE(file) _ProfSave(file);
|
||||
#define PROFPRINT() _ProfPrint();
|
||||
#else
|
||||
#define PROFINIT()
|
||||
#define PROFSAVE(file)
|
||||
#define PROFPRINT()
|
||||
#endif // !_PROFILE
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OPENJPEG_H */
|
||||
|
||||
|
||||
16
libopenjpeg/opj_configure.h
Normal file
16
libopenjpeg/opj_configure.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* here is where system comupted values get stored these values should only
|
||||
* change when the target compile platform changes
|
||||
*/
|
||||
|
||||
/* what byte order */
|
||||
#ifndef __OPJ_CONFIGURE_H
|
||||
#define __OPJ_CONFIGURE_H
|
||||
/* #undef CMAKE_WORDS_BIGENDIAN */
|
||||
#ifdef CMAKE_WORDS_BIGENDIAN
|
||||
#define OPJ_BIG_ENDIAN
|
||||
#else
|
||||
#define OPJ_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#endif /* __OPJ_CONFIGURE_H */
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,13 +41,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
OpenJPEG interface
|
||||
==========================================================
|
||||
*/
|
||||
#include "openjpeg.h"
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
@@ -65,7 +66,7 @@ Most compilers implement their own version of this keyword ...
|
||||
*/
|
||||
#ifndef INLINE
|
||||
#if defined(_MSC_VER)
|
||||
#define INLINE __forceinline
|
||||
#define INLINE __inline
|
||||
#elif defined(__GNUC__)
|
||||
#define INLINE __inline__
|
||||
#elif defined(__MWERKS__)
|
||||
@@ -88,10 +89,10 @@ Most compilers implement their own version of this keyword ...
|
||||
|
||||
/* MSVC and Borland C do not have lrintf */
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
|
||||
/* MSVC 64bits doesn't support _asm */
|
||||
#if !defined(_WIN64)
|
||||
static INLINE long lrintf(float f){
|
||||
#ifdef _M_X64
|
||||
return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f));
|
||||
#else
|
||||
int i;
|
||||
|
||||
_asm{
|
||||
@@ -100,38 +101,24 @@ static INLINE long lrintf(float f){
|
||||
};
|
||||
|
||||
return i;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
static INLINE long lrintf(float x){
|
||||
long r;
|
||||
if (x>=0.f)
|
||||
{
|
||||
x+=0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
x-=0.5f;
|
||||
}
|
||||
r = (long)(x);
|
||||
if ( x != (float)(r) ) return r;
|
||||
return 2*(r/2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "j2k_lib.h"
|
||||
#include "opj_malloc.h"
|
||||
#include "event.h"
|
||||
#include "bio.h"
|
||||
#include "cio.h"
|
||||
|
||||
#include "image.h"
|
||||
#include "j2k.h"
|
||||
#include "jp2.h"
|
||||
#include "jpt.h"
|
||||
|
||||
#include "mqc.h"
|
||||
#include "raw.h"
|
||||
#include "bio.h"
|
||||
#include "tgt.h"
|
||||
#include "pi.h"
|
||||
#include "tcd.h"
|
||||
#include "t1.h"
|
||||
#include "dwt.h"
|
||||
#include "t2.h"
|
||||
#include "mct.h"
|
||||
#include "int.h"
|
||||
#include "fix.h"
|
||||
|
||||
/* JPWL>> */
|
||||
#ifdef USE_JPWL
|
||||
#include "jpwl.h"
|
||||
#endif /* USE_JPWL */
|
||||
/* <<JPWL */
|
||||
#endif
|
||||
|
||||
#endif /* OPJ_INCLUDES_H */
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
|
||||
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -32,7 +33,8 @@
|
||||
|
||||
The functions in opj_malloc.h are internal utilities used for memory management.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
#include "opj_includes.h"
|
||||
/** @defgroup MISC MISC - Miscellaneous internal functions */
|
||||
/*@{*/
|
||||
|
||||
@@ -45,11 +47,8 @@ Allocate an uninitialized memory block
|
||||
@param size Bytes to allocate
|
||||
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
|
||||
*/
|
||||
#ifdef ALLOC_PERF_OPT
|
||||
void * OPJ_CALLCONV opj_malloc(size_t size);
|
||||
#else
|
||||
#define opj_malloc(size) malloc(size)
|
||||
#endif
|
||||
#define my_opj_malloc(size) malloc(size)
|
||||
|
||||
/**
|
||||
Allocate a memory block with elements initialized to 0
|
||||
@@ -57,11 +56,7 @@ Allocate a memory block with elements initialized to 0
|
||||
@param size Bytes per block to allocate
|
||||
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
|
||||
*/
|
||||
#ifdef ALLOC_PERF_OPT
|
||||
void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements);
|
||||
#else
|
||||
#define opj_calloc(num, size) calloc(num, size)
|
||||
#endif
|
||||
|
||||
/**
|
||||
Allocate memory aligned to a 16 byte boundry
|
||||
@@ -69,7 +64,7 @@ Allocate memory aligned to a 16 byte boundry
|
||||
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
|
||||
*/
|
||||
/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
|
||||
#ifdef _WIN32
|
||||
#ifdef WIN32
|
||||
/* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
|
||||
#ifdef __GNUC__
|
||||
#include <mm_malloc.h>
|
||||
@@ -80,15 +75,13 @@ Allocate memory aligned to a 16 byte boundry
|
||||
#define HAVE_MM_MALLOC
|
||||
#endif
|
||||
#endif
|
||||
#else /* Not _WIN32 */
|
||||
#else /* Not WIN32 */
|
||||
#if defined(__sun)
|
||||
#define HAVE_MEMALIGN
|
||||
#elif defined(__FreeBSD__)
|
||||
#define HAVE_POSIX_MEMALIGN
|
||||
/* Linux x86_64 and OSX always align allocations to 16 bytes */
|
||||
#elif !defined(__amd64__) && !defined(__APPLE__) && !defined(_AIX)
|
||||
#define HAVE_MEMALIGN
|
||||
#include <malloc.h>
|
||||
#elif !defined(__amd64__) && !defined(__APPLE__)
|
||||
/* FIXME: Yes, this is a big assumption */
|
||||
#define HAVE_POSIX_MEMALIGN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -123,34 +116,21 @@ Allocate memory aligned to a 16 byte boundry
|
||||
#define opj_aligned_free(m) free(m)
|
||||
#endif
|
||||
|
||||
#ifdef ALLOC_PERF_OPT
|
||||
#undef opj_aligned_malloc
|
||||
#define opj_aligned_malloc(size) opj_malloc(size)
|
||||
#undef opj_aligned_free
|
||||
#define opj_aligned_free(m) opj_free(m)
|
||||
#endif
|
||||
|
||||
/**
|
||||
Reallocate memory blocks.
|
||||
@param m Pointer to previously allocated memory block
|
||||
@param s New size in bytes
|
||||
@param memblock Pointer to previously allocated memory block
|
||||
@param size New size in bytes
|
||||
@return Returns a void pointer to the reallocated (and possibly moved) memory block
|
||||
*/
|
||||
#ifdef ALLOC_PERF_OPT
|
||||
void * OPJ_CALLCONV opj_realloc(void * m, size_t s);
|
||||
#else
|
||||
#define opj_realloc(m, s) realloc(m, s)
|
||||
#endif
|
||||
#define my_opj_realloc(m,s) realloc(m,s)
|
||||
|
||||
|
||||
/**
|
||||
Deallocates or frees a memory block.
|
||||
@param m Previously allocated memory block to be freed
|
||||
@param memblock Previously allocated memory block to be freed
|
||||
*/
|
||||
#ifdef ALLOC_PERF_OPT
|
||||
void OPJ_CALLCONV opj_free(void * m);
|
||||
#else
|
||||
#define opj_free(m) free(m)
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC poison malloc calloc realloc free
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,25 +40,29 @@ The functions in PI.C have for goal to realize a packet iterator that permits to
|
||||
packet following the progression order and change of it. The functions in PI.C are used
|
||||
by some function in T2.C.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
#include "t2.h"
|
||||
/** @defgroup PI PI - Implementation of a packet iterator */
|
||||
/*@{*/
|
||||
struct opj_poc;
|
||||
struct opj_image;
|
||||
struct opj_cp;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_pi_resolution {
|
||||
int pdx, pdy;
|
||||
int pw, ph;
|
||||
OPJ_UINT32 pdx, pdy;
|
||||
OPJ_UINT32 pw, ph;
|
||||
} opj_pi_resolution_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_pi_comp {
|
||||
int dx, dy;
|
||||
OPJ_UINT32 dx, dy;
|
||||
/** number of resolution levels */
|
||||
int numresolutions;
|
||||
OPJ_UINT32 numresolutions;
|
||||
opj_pi_resolution_t *resolutions;
|
||||
} opj_pi_comp_t;
|
||||
|
||||
@@ -66,63 +71,78 @@ Packet iterator
|
||||
*/
|
||||
typedef struct opj_pi_iterator {
|
||||
/** Enabling Tile part generation*/
|
||||
char tp_on;
|
||||
OPJ_BYTE tp_on;
|
||||
/** precise if the packet has been already used (usefull for progression order change) */
|
||||
short int *include;
|
||||
OPJ_INT16 *include;
|
||||
/** layer step used to localize the packet in the include vector */
|
||||
int step_l;
|
||||
OPJ_UINT32 step_l;
|
||||
/** resolution step used to localize the packet in the include vector */
|
||||
int step_r;
|
||||
OPJ_UINT32 step_r;
|
||||
/** component step used to localize the packet in the include vector */
|
||||
int step_c;
|
||||
OPJ_UINT32 step_c;
|
||||
/** precinct step used to localize the packet in the include vector */
|
||||
int step_p;
|
||||
OPJ_UINT32 step_p;
|
||||
/** component that identify the packet */
|
||||
int compno;
|
||||
OPJ_UINT32 compno;
|
||||
/** resolution that identify the packet */
|
||||
int resno;
|
||||
OPJ_UINT32 resno;
|
||||
/** precinct that identify the packet */
|
||||
int precno;
|
||||
OPJ_UINT32 precno;
|
||||
/** layer that identify the packet */
|
||||
int layno;
|
||||
/** 0 if the first packet */
|
||||
int first;
|
||||
OPJ_UINT32 layno;
|
||||
/** progression order change information */
|
||||
opj_poc_t poc;
|
||||
struct opj_poc poc;
|
||||
/** number of components in the image */
|
||||
int numcomps;
|
||||
OPJ_UINT32 numcomps;
|
||||
/** Components*/
|
||||
opj_pi_comp_t *comps;
|
||||
int tx0, ty0, tx1, ty1;
|
||||
int x, y, dx, dy;
|
||||
OPJ_INT32 tx0, ty0, tx1, ty1;
|
||||
OPJ_INT32 x, y;
|
||||
OPJ_UINT32 dx, dy;
|
||||
/** 0 if the first packet */
|
||||
OPJ_UINT32 first : 1;
|
||||
} opj_pi_iterator_t;
|
||||
|
||||
/** @name Exported functions */
|
||||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/**
|
||||
Create a packet iterator for Encoder
|
||||
@param image Raw image for which the packets will be listed
|
||||
@param cp Coding parameters
|
||||
@param tileno Number that identifies the tile for which to list the packets
|
||||
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
|
||||
@return Returns a packet iterator that points to the first packet of the tile
|
||||
@see pi_destroy
|
||||
* Creates a packet iterator for encoding.
|
||||
*
|
||||
* @param p_image the image being encoded.
|
||||
* @param p_cp the coding parameters.
|
||||
* @param p_tile_no index of the tile being encoded.
|
||||
* @param p_t2_mode the type of pass for generating the packet iterator
|
||||
* @return a list of packet iterator that points to the first packet of the tile (not true).
|
||||
*/
|
||||
opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno,J2K_T2_MODE t2_mode);
|
||||
opj_pi_iterator_t *pi_initialise_encode(const struct opj_image *image,struct opj_cp *cp, OPJ_UINT32 tileno,J2K_T2_MODE t2_mode);
|
||||
|
||||
/**
|
||||
* Updates the encoding parameters of the codec.
|
||||
*
|
||||
* @param p_image the image being encoded.
|
||||
* @param p_cp the coding parameters.
|
||||
* @param p_tile_no index of the tile being encoded.
|
||||
*/
|
||||
void pi_update_encoding_parameters(
|
||||
const struct opj_image *p_image,
|
||||
struct opj_cp *p_cp,
|
||||
OPJ_UINT32 p_tile_no
|
||||
);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Modify the packet iterator for enabling tile part generation
|
||||
@param pi Handle to the packet iterator generated in pi_initialise_encode
|
||||
@param cp Coding parameters
|
||||
@param tileno Number that identifies the tile for which to list the packets
|
||||
@param pino Iterator index for pi
|
||||
@param tpnum Tile part number of the current tile
|
||||
@param tppos The position of the tile part flag in the progression order
|
||||
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
|
||||
@param cur_totnum_tp The total number of tile parts in the current tile
|
||||
@return Returns true if an error is detected
|
||||
*/
|
||||
opj_bool pi_create_encode(opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp);
|
||||
void pi_create_encode( opj_pi_iterator_t *pi, struct opj_cp *cp,OPJ_UINT32 tileno, OPJ_UINT32 pino,OPJ_UINT32 tpnum, OPJ_INT32 tppos, J2K_T2_MODE t2_mode);
|
||||
|
||||
|
||||
/**
|
||||
Create a packet iterator for Decoder
|
||||
@param image Raw image for which the packets will be listed
|
||||
@@ -131,23 +151,28 @@ Create a packet iterator for Decoder
|
||||
@return Returns a packet iterator that points to the first packet of the tile
|
||||
@see pi_destroy
|
||||
*/
|
||||
opj_pi_iterator_t *pi_create_decode(opj_image_t * image, opj_cp_t * cp, int tileno);
|
||||
opj_pi_iterator_t *pi_create_decode(struct opj_image * image, struct opj_cp * cp, OPJ_UINT32 tileno);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Destroy a packet iterator
|
||||
@param pi Previously created packet iterator
|
||||
@param cp Coding parameters
|
||||
@param tileno Number that identifies the tile for which the packets were listed
|
||||
@see pi_create
|
||||
* Destroys a packet iterator array.
|
||||
*
|
||||
* @param p_pi the packet iterator array to destroy.
|
||||
* @param p_nb_elements the number of elements in the array.
|
||||
*/
|
||||
void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno);
|
||||
void pi_destroy(
|
||||
opj_pi_iterator_t *p_pi,
|
||||
OPJ_UINT32 p_nb_elements);
|
||||
|
||||
/**
|
||||
Modify the packet iterator to point to the next packet
|
||||
@param pi Packet iterator to modify
|
||||
@return Returns false if pi pointed to the last packet or else returns true
|
||||
*/
|
||||
opj_bool pi_next(opj_pi_iterator_t * pi);
|
||||
bool pi_next(opj_pi_iterator_t * pi);
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
177
libopenjpeg/profile.c
Normal file
177
libopenjpeg/profile.c
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adapted from Herb Marselas
|
||||
"Profiling, Data Analysis, Scalability, and Magic Numbers: Meeting the Minimum System Requirements for AGE OF EMPIRES 2: THE AGE OF KINGS"
|
||||
Game Developer magazine
|
||||
June, 2000 issue.
|
||||
*/
|
||||
|
||||
#include "profile.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
//==============================================================================
|
||||
static OPJ_PROFILE_LIST group_list [PGROUP_LASTGROUP];
|
||||
|
||||
//==============================================================================
|
||||
static void GetTimeStamp(OPJ_UINT32 *pdwtime);
|
||||
|
||||
//==============================================================================
|
||||
#define SetMajorSection(entry, major) \
|
||||
{ group_list[ entry ].section = entry ; \
|
||||
group_list[ entry ].sectionName = #major ; }
|
||||
|
||||
//==============================================================================
|
||||
void _ProfInit(void)
|
||||
{
|
||||
// clear everything out
|
||||
memset(group_list, 0, sizeof(group_list));
|
||||
|
||||
// set groups and parents for timing
|
||||
SetMajorSection(PGROUP_DWT,PGROUP_DWT);
|
||||
SetMajorSection(PGROUP_T1, PGROUP_T1);
|
||||
SetMajorSection(PGROUP_T2, PGROUP_T2);
|
||||
} // ProfInit
|
||||
|
||||
//==============================================================================
|
||||
void _ProfStart (OPJ_PROFILE_GROUP group)
|
||||
{
|
||||
// make sure this hasn't been incorrectly started twice
|
||||
if (group_list[group].start)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// get the start time
|
||||
GetTimeStamp(&(group_list[group].start));
|
||||
|
||||
} // _ProfStart
|
||||
|
||||
//==============================================================================
|
||||
void _ProfStop(OPJ_PROFILE_GROUP group)
|
||||
{
|
||||
// make sure we called start first
|
||||
if (!group_list[group].start)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// get ending time
|
||||
GetTimeStamp(&(group_list[group].end));
|
||||
|
||||
// calculate this latest elapsed interval
|
||||
group_list[group].total_time += group_list[group].end - group_list[group].start;
|
||||
|
||||
// reset starting time
|
||||
group_list[group].start = 0;
|
||||
|
||||
// incr the number of calls made
|
||||
++group_list[group].totalCalls;
|
||||
|
||||
} // _ProfStop
|
||||
|
||||
//==============================================================================
|
||||
#define proftracef(id,totalTime) \
|
||||
fprintf(p, #id "\t%u\t\t%6.6f\t\t%12.6f\t%2.2f%%\n", \
|
||||
group_list[ id ].totalCalls, \
|
||||
(OPJ_FLOAT64) group_list[ id ].total_time / CLOCKS_PER_SEC, \
|
||||
((OPJ_FLOAT64) group_list[ id ].total_time / (group_list[ id ].totalCalls ? group_list[ id ].totalCalls : 1)), \
|
||||
((OPJ_FLOAT64) group_list[ id ].total_time / totalTime * 100))
|
||||
|
||||
#define proftracep(id,totalTime) \
|
||||
printf(#id "\t%u\t\t%6.6f\t\t%12.6f\t%2.2f%%\n", \
|
||||
group_list[ id ].totalCalls, \
|
||||
(OPJ_FLOAT64) group_list[ id ].total_time / CLOCKS_PER_SEC, \
|
||||
((OPJ_FLOAT64) group_list[ id ].total_time / (group_list[ id ].totalCalls ? group_list[ id ].totalCalls : 1)), \
|
||||
((OPJ_FLOAT64) group_list[ id ].total_time / totalTime * 100))
|
||||
|
||||
//==============================================================================
|
||||
void _ProfSave(const OPJ_CHAR * pFileName)
|
||||
{
|
||||
FILE *p = fopen(pFileName, "wt");
|
||||
OPJ_FLOAT64 totalTime = 0.;
|
||||
OPJ_UINT32 i;
|
||||
|
||||
if (!p)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for
|
||||
(i=0;i<PGROUP_LASTGROUP;++i)
|
||||
{
|
||||
totalTime += group_list[i].total_time;
|
||||
}
|
||||
|
||||
fputs("\n\nProfile Data:\n", p);
|
||||
fputs("description\tnb calls\ttotal time (sec)\ttime per call\t%% of section\n", p);
|
||||
|
||||
proftracef(PGROUP_DWT,totalTime);
|
||||
proftracef(PGROUP_T1,totalTime);
|
||||
proftracef(PGROUP_T2,totalTime);
|
||||
|
||||
fputs("=== end of profile list ===\n\n", p);
|
||||
|
||||
fclose(p);
|
||||
|
||||
} // _ProfSave
|
||||
|
||||
//==============================================================================
|
||||
void _ProfPrint(void)
|
||||
{
|
||||
OPJ_FLOAT64 totalTime = 0.;
|
||||
OPJ_UINT32 i;
|
||||
|
||||
for
|
||||
(i=0;i<PGROUP_LASTGROUP;++i)
|
||||
{
|
||||
totalTime += group_list[i].total_time;
|
||||
}
|
||||
|
||||
printf("\n\nProfile Data:\n");
|
||||
printf("description\tnb calls\ttotal time (sec)\ttime per call\t%% of section\n");
|
||||
|
||||
proftracep(PGROUP_RATE, totalTime);
|
||||
proftracep(PGROUP_DC_SHIFT, totalTime);
|
||||
proftracep(PGROUP_MCT, totalTime);
|
||||
proftracep(PGROUP_DWT, totalTime);
|
||||
proftracep(PGROUP_T1, totalTime);
|
||||
proftracep(PGROUP_T2, totalTime);
|
||||
|
||||
printf("\nTotal time: %6.3f second(s)\n", totalTime / CLOCKS_PER_SEC);
|
||||
|
||||
printf("=== end of profile list ===\n\n");
|
||||
|
||||
} // _ProfPrint
|
||||
|
||||
//==============================================================================
|
||||
static void GetTimeStamp(unsigned *time)
|
||||
{
|
||||
*time = clock();
|
||||
|
||||
} // GetTimeStamp
|
||||
83
libopenjpeg/profile.h
Normal file
83
libopenjpeg/profile.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adapted from Herb Marselas
|
||||
"Profiling, Data Analysis, Scalability, and Magic Numbers: Meeting the Minimum System Requirements for AGE OF EMPIRES 2: THE AGE OF KINGS"
|
||||
Game Developer magazine
|
||||
June, 2000 issue.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __PROFILE_H
|
||||
#define __PROFILE_H
|
||||
|
||||
#include "openjpeg.h"
|
||||
//==============================================================================
|
||||
typedef enum
|
||||
{
|
||||
PGROUP_RATE,
|
||||
PGROUP_DC_SHIFT,
|
||||
PGROUP_MCT,
|
||||
PGROUP_DWT,
|
||||
PGROUP_T1,
|
||||
PGROUP_T2,
|
||||
PGROUP_LASTGROUP
|
||||
} OPJ_PROFILE_GROUP;
|
||||
|
||||
//==============================================================================
|
||||
typedef struct PROFILELIST
|
||||
{
|
||||
OPJ_UINT32 start;
|
||||
OPJ_UINT32 end;
|
||||
OPJ_UINT32 total_time;
|
||||
OPJ_UINT32 totalCalls;
|
||||
OPJ_PROFILE_GROUP section;
|
||||
const OPJ_CHAR *sectionName; // string name of the profile group
|
||||
} OPJ_PROFILE_LIST;
|
||||
|
||||
//==============================================================================
|
||||
void _ProfStart(OPJ_PROFILE_GROUP group);
|
||||
void _ProfStop (OPJ_PROFILE_GROUP group);
|
||||
|
||||
//==============================================================================
|
||||
//==============================================================================
|
||||
#ifdef _PROFILE
|
||||
#define PROFINIT() _ProfInit();
|
||||
#define PROFSTART (group) _ProfStart (group);
|
||||
#define PROFSTOP (group) _ProfStop (group);
|
||||
#define PROFSAVE(file) _ProfSave(file);
|
||||
#define PROFPRINT() _ProfPrint();
|
||||
#else
|
||||
#define PROFINIT()
|
||||
#define PROFSTART(group)
|
||||
#define PROFSTOP (group)
|
||||
#define PROFSAVE(file)
|
||||
#define PROFPRINT()
|
||||
#endif // !_PROFILE
|
||||
|
||||
//==============================================================================
|
||||
#endif // __PROFILE_H
|
||||
@@ -3,6 +3,7 @@
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -27,7 +28,8 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "opj_includes.h"
|
||||
#include "raw.h"
|
||||
#include "opj_malloc.h"
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
@@ -53,11 +55,11 @@ void raw_destroy(opj_raw_t *raw) {
|
||||
}
|
||||
}
|
||||
|
||||
int raw_numbytes(opj_raw_t *raw) {
|
||||
OPJ_UINT32 raw_numbytes(opj_raw_t *raw) {
|
||||
return raw->bp - raw->start;
|
||||
}
|
||||
|
||||
void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) {
|
||||
void raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) {
|
||||
raw->start = bp;
|
||||
raw->lenmax = len;
|
||||
raw->len = 0;
|
||||
@@ -65,8 +67,8 @@ void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) {
|
||||
raw->ct = 0;
|
||||
}
|
||||
|
||||
int raw_decode(opj_raw_t *raw) {
|
||||
int d;
|
||||
OPJ_UINT32 raw_decode(opj_raw_t *raw) {
|
||||
OPJ_UINT32 d;
|
||||
if (raw->ct == 0) {
|
||||
raw->ct = 8;
|
||||
if (raw->len == raw->lenmax) {
|
||||
@@ -3,6 +3,7 @@
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -36,7 +37,7 @@
|
||||
The functions in RAW.C have for goal to realize the operation of raw encoding linked
|
||||
with the corresponding mode switch.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
/** @defgroup RAW RAW - Implementation of operations for raw encoding */
|
||||
/*@{*/
|
||||
|
||||
@@ -57,7 +58,7 @@ typedef struct opj_raw {
|
||||
/** pointer to the start of the buffer */
|
||||
OPJ_BYTE *start;
|
||||
/** pointer to the end of the buffer */
|
||||
OPJ_BYTE *end;
|
||||
unsigned char *end;
|
||||
} opj_raw_t;
|
||||
|
||||
/** @name Exported functions */
|
||||
@@ -67,31 +68,31 @@ typedef struct opj_raw {
|
||||
Create a new RAW handle
|
||||
@return Returns a new RAW handle if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_raw_t* opj_raw_create(void);
|
||||
opj_raw_t* raw_create(void);
|
||||
/**
|
||||
Destroy a previously created RAW handle
|
||||
@param raw RAW handle to destroy
|
||||
*/
|
||||
void opj_raw_destroy(opj_raw_t *raw);
|
||||
void raw_destroy(opj_raw_t *raw);
|
||||
/**
|
||||
Return the number of bytes written/read since initialisation
|
||||
@param raw RAW handle to destroy
|
||||
@return Returns the number of bytes already encoded
|
||||
*/
|
||||
OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw);
|
||||
OPJ_UINT32 raw_numbytes(opj_raw_t *raw);
|
||||
/**
|
||||
Initialize the decoder
|
||||
@param raw RAW handle
|
||||
@param bp Pointer to the start of the buffer from which the bytes will be read
|
||||
@param len Length of the input buffer
|
||||
*/
|
||||
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len);
|
||||
void raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len);
|
||||
/**
|
||||
Decode a symbol using raw-decoder. Cfr p.506 TAUBMAN
|
||||
@param raw RAW handle
|
||||
@return Returns the decoded symbol (0 or 1)
|
||||
*/
|
||||
OPJ_UINT32 opj_raw_decode(opj_raw_t *raw);
|
||||
OPJ_UINT32 raw_decode(opj_raw_t *raw);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -37,10 +38,10 @@
|
||||
The functions in T1.C have for goal to realize the tier-1 coding operation. The functions
|
||||
in T1.C are used by some function in TCD.C.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
/** @defgroup T1 T1 - Implementation of the tier-1 coding */
|
||||
/*@{*/
|
||||
|
||||
//#include "raw.h"
|
||||
/* ----------------------------------------------------------------------- */
|
||||
#define T1_NMSEDEC_BITS 7
|
||||
|
||||
@@ -84,21 +85,28 @@ in T1.C are used by some function in TCD.C.
|
||||
#define T1_TYPE_RAW 1 /**< No encoding the information is store under raw format in codestream (mode switch RAW)*/
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
struct opj_common_struct;
|
||||
struct opj_tcd_tile;
|
||||
struct opj_tcp;
|
||||
struct opj_tcd_tilecomp;
|
||||
struct opj_mqc;
|
||||
struct opj_raw;
|
||||
struct opj_tccp;
|
||||
|
||||
typedef OPJ_INT16 opj_flag_t;
|
||||
|
||||
typedef short flag_t;
|
||||
|
||||
/**
|
||||
Tier-1 coding (coding of code-block coefficients)
|
||||
*/
|
||||
typedef struct opj_t1 {
|
||||
|
||||
/** MQC component */
|
||||
opj_mqc_t *mqc;
|
||||
struct opj_mqc *mqc;
|
||||
/** RAW component */
|
||||
opj_raw_t *raw;
|
||||
struct opj_raw *raw;
|
||||
|
||||
OPJ_INT32 *data;
|
||||
opj_flag_t *flags;
|
||||
flag_t *flags;
|
||||
OPJ_UINT32 w;
|
||||
OPJ_UINT32 h;
|
||||
OPJ_UINT32 datasize;
|
||||
@@ -112,43 +120,34 @@ typedef struct opj_t1 {
|
||||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
Encode the code-blocks of a tile
|
||||
@param t1 T1 handle
|
||||
@param tile The tile to encode
|
||||
@param tcp Tile coding parameters
|
||||
@param mct_norms FIXME DOC
|
||||
*/
|
||||
OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
|
||||
opj_tcd_tile_t *tile,
|
||||
opj_tcp_t *tcp,
|
||||
const OPJ_FLOAT64 * mct_norms);
|
||||
|
||||
/**
|
||||
Decode the code-blocks of a tile
|
||||
@param t1 T1 handle
|
||||
@param tilec The tile to decode
|
||||
@param tccp Tile coding parameters
|
||||
*/
|
||||
OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
|
||||
opj_tcd_tilecomp_t* tilec,
|
||||
opj_tccp_t* tccp);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Tier 1 handle
|
||||
* and initializes the look-up tables of the Tier-1 coder/decoder
|
||||
* @return a new T1 handle if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_t1_t* opj_t1_create(void);
|
||||
opj_t1_t* t1_create();
|
||||
|
||||
/**
|
||||
* Destroys a previously created T1 handle
|
||||
*
|
||||
* @param p_t1 Tier 1 handle to destroy
|
||||
*/
|
||||
void opj_t1_destroy(opj_t1_t *p_t1);
|
||||
void t1_destroy(opj_t1_t *p_t1);
|
||||
|
||||
/**
|
||||
Encode the code-blocks of a tile
|
||||
@param t1 T1 handle
|
||||
@param tile The tile to encode
|
||||
@param tcp Tile coding parameters
|
||||
*/
|
||||
bool t1_encode_cblks(opj_t1_t *t1, struct opj_tcd_tile *tile, struct opj_tcp *tcp,const OPJ_FLOAT64 * mct_norms);
|
||||
/**
|
||||
Decode the code-blocks of a tile
|
||||
@param t1 T1 handle
|
||||
@param tile The tile to decode
|
||||
@param tcp Tile coding parameters
|
||||
*/
|
||||
void t1_decode_cblks(opj_t1_t* t1, struct opj_tcd_tilecomp* tilec, struct opj_tccp* tccp);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
1291
libopenjpeg/t2.c
Normal file
1291
libopenjpeg/t2.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,21 +36,36 @@
|
||||
@brief Implementation of a tier-2 coding (packetization of code-block data) (T2)
|
||||
|
||||
*/
|
||||
#include "openjpeg.h"
|
||||
|
||||
struct opj_common_struct;
|
||||
struct opj_image;
|
||||
struct opj_cp;
|
||||
struct opj_tcd_tile;
|
||||
struct opj_codestream_info;
|
||||
|
||||
/** @defgroup T2 T2 - Implementation of a tier-2 coding */
|
||||
/*@{*/
|
||||
|
||||
/**
|
||||
T2 encoding mode
|
||||
*/
|
||||
typedef enum T2_MODE
|
||||
{
|
||||
THRESH_CALC = 0, /** Function called in Rate allocation process*/
|
||||
FINAL_PASS = 1 /** Function called in Tier 2 process*/
|
||||
}
|
||||
J2K_T2_MODE;
|
||||
|
||||
/**
|
||||
Tier-2 coding
|
||||
*/
|
||||
typedef struct opj_t2 {
|
||||
/** codec context */
|
||||
opj_common_ptr cinfo;
|
||||
|
||||
typedef struct opj_t2 {
|
||||
/** Encoding: pointer to the src image. Decoding: pointer to the dst image. */
|
||||
opj_image_t *image;
|
||||
struct opj_image *image;
|
||||
/** pointer to the image coding parameters */
|
||||
opj_cp_t *cp;
|
||||
struct opj_cp *cp;
|
||||
} opj_t2_t;
|
||||
|
||||
/** @name Exported functions */
|
||||
@@ -67,11 +83,9 @@ Encode the packets of a tile to a destination buffer
|
||||
@param cstr_info Codestream information structure
|
||||
@param tpnum Tile part number of the current tile
|
||||
@param tppos The position of the tile part flag in the progression order
|
||||
@param pino
|
||||
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
|
||||
@param cur_totnum_tp The total number of tile parts in the current tile
|
||||
*/
|
||||
int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino,J2K_T2_MODE t2_mode,int cur_totnum_tp);
|
||||
bool t2_encode_packets(opj_t2_t* t2,OPJ_UINT32 tileno, struct opj_tcd_tile *tile, OPJ_UINT32 maxlayers, OPJ_BYTE *dest, OPJ_UINT32 * p_data_written, OPJ_UINT32 len, struct opj_codestream_info *cstr_info,OPJ_UINT32 tpnum, OPJ_INT32 tppos,OPJ_UINT32 pino,J2K_T2_MODE t2_mode);
|
||||
/**
|
||||
Decode the packets of a tile from a source buffer
|
||||
@param t2 T2 handle
|
||||
@@ -79,21 +93,22 @@ Decode the packets of a tile from a source buffer
|
||||
@param len length of the source buffer
|
||||
@param tileno number that identifies the tile for which to decode the packets
|
||||
@param tile tile for which to decode the packets
|
||||
@param cstr_info Codestream information structure
|
||||
*/
|
||||
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info);
|
||||
bool t2_decode_packets(opj_t2_t *t2, OPJ_UINT32 tileno,struct opj_tcd_tile *tile, OPJ_BYTE *src, OPJ_UINT32 * p_data_read, OPJ_UINT32 len, struct opj_codestream_info *cstr_info);
|
||||
|
||||
/**
|
||||
Create a T2 handle
|
||||
@param cinfo Codec context info
|
||||
@param image Source or destination image
|
||||
@param cp Image coding parameters
|
||||
@return Returns a new T2 handle if successful, returns NULL otherwise
|
||||
* Creates a Tier 2 handle
|
||||
*
|
||||
* @param p_image Source or destination image
|
||||
* @param p_cp Image coding parameters.
|
||||
* @return a new T2 handle if successful, NULL otherwise.
|
||||
*/
|
||||
opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp);
|
||||
opj_t2_t* t2_create(struct opj_image *p_image, struct opj_cp *p_cp);
|
||||
|
||||
/**
|
||||
Destroy a T2 handle
|
||||
@param t2 T2 handle to destroy
|
||||
* Destroys a Tier 2 handle.
|
||||
*
|
||||
* @param p_t2 the Tier 2 handle to destroy
|
||||
*/
|
||||
void t2_destroy(opj_t2_t *t2);
|
||||
|
||||
2121
libopenjpeg/tcd.c
Normal file
2121
libopenjpeg/tcd.c
Normal file
File diff suppressed because it is too large
Load Diff
344
libopenjpeg/tcd.h
Normal file
344
libopenjpeg/tcd.h
Normal file
@@ -0,0 +1,344 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2001-2003, David Janssens
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef __TCD_H
|
||||
#define __TCD_H
|
||||
/**
|
||||
@file tcd.h
|
||||
@brief Implementation of a tile coder/decoder (TCD)
|
||||
|
||||
The functions in TCD.C have for goal to encode or decode each tile independently from
|
||||
each other. The functions in TCD.C are used by some function in J2K.C.
|
||||
*/
|
||||
#include "openjpeg.h"
|
||||
/** @defgroup TCD TCD - Implementation of a tile coder/decoder */
|
||||
/*@{*/
|
||||
struct opj_common_struct;
|
||||
struct opj_codestream_info;
|
||||
struct opj_image;
|
||||
struct opj_tcp;
|
||||
struct opj_cp;
|
||||
struct opj_tgt_tree;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_seg {
|
||||
OPJ_BYTE ** data;
|
||||
OPJ_UINT32 dataindex;
|
||||
OPJ_UINT32 numpasses;
|
||||
OPJ_UINT32 real_num_passes;
|
||||
OPJ_UINT32 len;
|
||||
OPJ_UINT32 maxpasses;
|
||||
OPJ_UINT32 numnewpasses;
|
||||
OPJ_UINT32 newlen;
|
||||
} opj_tcd_seg_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_pass {
|
||||
OPJ_UINT32 rate;
|
||||
OPJ_FLOAT64 distortiondec;
|
||||
OPJ_UINT32 len;
|
||||
OPJ_UINT32 term : 1;
|
||||
} opj_tcd_pass_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_layer {
|
||||
OPJ_UINT32 numpasses; /* Number of passes in the layer */
|
||||
OPJ_UINT32 len; /* len of information */
|
||||
OPJ_FLOAT64 disto; /* add for index (Cfr. Marcela) */
|
||||
OPJ_BYTE *data; /* data */
|
||||
} opj_tcd_layer_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_cblk_enc {
|
||||
OPJ_BYTE* data; /* Data */
|
||||
opj_tcd_layer_t* layers; /* layer information */
|
||||
opj_tcd_pass_t* passes; /* information about the passes */
|
||||
OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
OPJ_UINT32 numbps;
|
||||
OPJ_UINT32 numlenbits;
|
||||
OPJ_UINT32 numpasses; /* number of pass already done for the code-blocks */
|
||||
OPJ_UINT32 numpassesinlayers; /* number of passes in the layer */
|
||||
OPJ_UINT32 totalpasses; /* total number of passes */
|
||||
} opj_tcd_cblk_enc_t;
|
||||
|
||||
typedef struct opj_tcd_cblk_dec {
|
||||
OPJ_BYTE * data; /* Data */
|
||||
opj_tcd_seg_t* segs; /* segments informations */
|
||||
OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
OPJ_UINT32 numbps;
|
||||
OPJ_UINT32 numlenbits;
|
||||
OPJ_UINT32 len; /* length */
|
||||
OPJ_UINT32 numnewpasses; /* number of pass added to the code-blocks */
|
||||
OPJ_UINT32 numsegs; /* number of segments */
|
||||
OPJ_UINT32 real_num_segs;
|
||||
OPJ_UINT32 m_current_max_segs;
|
||||
} opj_tcd_cblk_dec_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_precinct {
|
||||
OPJ_INT32 x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
OPJ_UINT32 cw, ch; /* number of precinct in width and heigth */
|
||||
union{ /* code-blocks informations */
|
||||
opj_tcd_cblk_enc_t* enc;
|
||||
opj_tcd_cblk_dec_t* dec;
|
||||
} cblks;
|
||||
OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */
|
||||
struct opj_tgt_tree *incltree; /* inclusion tree */
|
||||
struct opj_tgt_tree *imsbtree; /* IMSB tree */
|
||||
} opj_tcd_precinct_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_band {
|
||||
OPJ_INT32 x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
OPJ_UINT32 bandno;
|
||||
opj_tcd_precinct_t *precincts; /* precinct information */
|
||||
OPJ_UINT32 precincts_data_size; /* size of data taken by precincts */
|
||||
OPJ_INT32 numbps;
|
||||
OPJ_FLOAT32 stepsize;
|
||||
} opj_tcd_band_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_resolution {
|
||||
OPJ_INT32 x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
OPJ_UINT32 pw, ph;
|
||||
OPJ_UINT32 numbands; /* number sub-band for the resolution level */
|
||||
opj_tcd_band_t bands[3]; /* subband information */
|
||||
} opj_tcd_resolution_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_tilecomp
|
||||
{
|
||||
OPJ_INT32 x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
OPJ_UINT32 numresolutions; /* number of resolutions level */
|
||||
OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/
|
||||
opj_tcd_resolution_t *resolutions; /* resolutions information */
|
||||
OPJ_UINT32 resolutions_size; /* size of data for resolutions (in bytes) */
|
||||
OPJ_INT32 *data; /* data of the component */
|
||||
OPJ_UINT32 data_size; /* size of the data of the component */
|
||||
OPJ_INT32 numpix; /* add fixed_quality */
|
||||
} opj_tcd_tilecomp_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_tile {
|
||||
OPJ_INT32 x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
OPJ_UINT32 numcomps; /* number of components in tile */
|
||||
opj_tcd_tilecomp_t *comps; /* Components information */
|
||||
OPJ_INT32 numpix; /* add fixed_quality */
|
||||
OPJ_FLOAT64 distotile; /* add fixed_quality */
|
||||
OPJ_FLOAT64 distolayer[100]; /* add fixed_quality */
|
||||
/** packet number */
|
||||
OPJ_UINT32 packno;
|
||||
} opj_tcd_tile_t;
|
||||
|
||||
/**
|
||||
FIXME: documentation
|
||||
*/
|
||||
typedef struct opj_tcd_image
|
||||
{
|
||||
opj_tcd_tile_t *tiles; /* Tiles information */
|
||||
}
|
||||
opj_tcd_image_t;
|
||||
|
||||
/**
|
||||
Tile coder/decoder
|
||||
*/
|
||||
typedef struct opj_tcd
|
||||
{
|
||||
/** Position of the tilepart flag in Progression order*/
|
||||
OPJ_INT32 tp_pos;
|
||||
/** Tile part number*/
|
||||
OPJ_UINT32 tp_num;
|
||||
/** Current tile part number*/
|
||||
OPJ_UINT32 cur_tp_num;
|
||||
/** Total number of tileparts of the current tile*/
|
||||
OPJ_UINT32 cur_totnum_tp;
|
||||
/** Current Packet iterator number */
|
||||
OPJ_UINT32 cur_pino;
|
||||
/** info on each image tile */
|
||||
struct opj_tcd_image *tcd_image;
|
||||
/** image */
|
||||
struct opj_image *image;
|
||||
/** coding parameters */
|
||||
struct opj_cp *cp;
|
||||
/** coding/decoding parameters common to all tiles */
|
||||
struct opj_tcp *tcp;
|
||||
/** current encoded/decoded tile */
|
||||
OPJ_UINT32 tcd_tileno;
|
||||
/** tell if the tcd is a decoder. */
|
||||
OPJ_UINT32 m_is_decoder : 1;
|
||||
} opj_tcd_t;
|
||||
|
||||
/** @name Exported functions */
|
||||
/*@{*/
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
Dump the content of a tcd structure
|
||||
*/
|
||||
//void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);
|
||||
/**
|
||||
Create a new TCD handle
|
||||
@param cinfo Codec context info
|
||||
@return Returns a new TCD handle if successful returns NULL otherwise
|
||||
*/
|
||||
opj_tcd_t* tcd_create(bool p_is_decoder);
|
||||
|
||||
/**
|
||||
Destroy a previously created TCD handle
|
||||
@param tcd TCD handle to destroy
|
||||
*/
|
||||
void tcd_destroy(opj_tcd_t *tcd);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the tile coder and may reuse some meory.
|
||||
* @param p_tcd TCD handle.
|
||||
* @param p_image raw image.
|
||||
* @param p_cp coding parameters.
|
||||
* @param p_tile_no current tile index to encode.
|
||||
*
|
||||
* @return true if the encoding values could be set (false otherwise).
|
||||
*/
|
||||
bool tcd_init(
|
||||
opj_tcd_t *p_tcd,
|
||||
struct opj_image * p_image,
|
||||
struct opj_cp * p_cp
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Allocates memory for decoding a specific tile.
|
||||
*
|
||||
* @param p_tcd the tile decoder.
|
||||
* @param p_image the image to decode.
|
||||
* @param p_cp the decoding parameters.
|
||||
* @param p_tile_no the index of the tile received in sequence. This not necesseraly lead to the
|
||||
* tile at index p_tile_no.
|
||||
* @param p_cstr_info codestream info (if any).
|
||||
*
|
||||
* @return true if the remaining data is sufficient.s
|
||||
*/
|
||||
bool tcd_init_decode_tile(
|
||||
opj_tcd_t *p_tcd,
|
||||
OPJ_UINT32 p_tile_no
|
||||
);
|
||||
/**
|
||||
* Initialize the tile coder and may reuse some meory.
|
||||
* @param p_tcd TCD handle.
|
||||
* @param p_image raw image.
|
||||
* @param p_cp coding parameters.
|
||||
* @param p_tile_no current tile index to encode.
|
||||
*
|
||||
* @return true if the encoding values could be set (false otherwise).
|
||||
*/
|
||||
bool tcd_init_encode_tile
|
||||
(
|
||||
opj_tcd_t *p_tcd,
|
||||
OPJ_UINT32 p_tile_no
|
||||
);
|
||||
|
||||
void tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final);
|
||||
void tcd_rateallocate_fixed(opj_tcd_t *tcd);
|
||||
void tcd_makelayer(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_FLOAT64 thresh, OPJ_UINT32 final);
|
||||
bool tcd_rateallocate(opj_tcd_t *tcd, OPJ_BYTE *dest, OPJ_UINT32 * p_data_written, OPJ_UINT32 len, struct opj_codestream_info *cstr_info);
|
||||
/**
|
||||
* Encodes a tile from the raw image into the given buffer.
|
||||
* @param p_tcd Tile Coder handle
|
||||
* @param p_tile_no Index of the tile to encode.
|
||||
* @param p_dest Destination buffer
|
||||
* @param p_data_written pointer to an int that is incremented by the number of bytes really written on p_dest
|
||||
* @param p_len Maximum length of the destination buffer
|
||||
* @param p_cstr_info Codestream information structure
|
||||
* @return true if the coding is successfull.
|
||||
*/
|
||||
bool tcd_encode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_BYTE *p_dest, OPJ_UINT32 * p_data_written, OPJ_UINT32 p_len, struct opj_codestream_info *p_cstr_info);
|
||||
|
||||
/**
|
||||
Decode a tile from a buffer into a raw image
|
||||
@param tcd TCD handle
|
||||
@param src Source buffer
|
||||
@param len Length of source buffer
|
||||
@param tileno Number that identifies one of the tiles to be decoded
|
||||
*/
|
||||
bool tcd_decode_tile(opj_tcd_t *tcd, OPJ_BYTE *src, OPJ_UINT32 len, OPJ_UINT32 tileno, struct opj_codestream_info *cstr_info);
|
||||
|
||||
/**
|
||||
* Copies tile data from the given memory block onto the system.
|
||||
*/
|
||||
bool tcd_copy_tile_data (
|
||||
opj_tcd_t *p_tcd,
|
||||
OPJ_BYTE * p_src,
|
||||
OPJ_UINT32 p_src_length
|
||||
);
|
||||
/**
|
||||
* Copies tile data from the system onto the given memory block.
|
||||
*/
|
||||
bool tcd_update_tile_data (
|
||||
opj_tcd_t *p_tcd,
|
||||
OPJ_BYTE * p_dest,
|
||||
OPJ_UINT32 p_dest_length
|
||||
);
|
||||
/**
|
||||
* Gets the maximum tile size that will be taken by the tile once decoded.
|
||||
*/
|
||||
OPJ_UINT32 tcd_get_decoded_tile_size (
|
||||
opj_tcd_t *p_tcd
|
||||
);
|
||||
|
||||
OPJ_UINT32 tcd_get_encoded_tile_size (
|
||||
opj_tcd_t *p_tcd
|
||||
);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
/*@}*/
|
||||
|
||||
#endif /* __TCD_H */
|
||||
344
libopenjpeg/tgt.c
Normal file
344
libopenjpeg/tgt.c
Normal file
@@ -0,0 +1,344 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2007, Professor Benoit Macq
|
||||
* Copyright (c) 2001-2003, David Janssens
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "tgt.h"
|
||||
#include "bio.h"
|
||||
#include "opj_malloc.h"
|
||||
|
||||
/*
|
||||
==========================================================
|
||||
Tag-tree coder interface
|
||||
==========================================================
|
||||
*/
|
||||
|
||||
opj_tgt_tree_t *tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
|
||||
OPJ_INT32 nplh[32];
|
||||
OPJ_INT32 nplv[32];
|
||||
opj_tgt_node_t *node = 00;
|
||||
opj_tgt_node_t *l_parent_node = 00;
|
||||
opj_tgt_node_t *l_parent_node0 = 00;
|
||||
opj_tgt_tree_t *tree = 00;
|
||||
OPJ_UINT32 i;
|
||||
OPJ_INT32 j,k;
|
||||
OPJ_UINT32 numlvls;
|
||||
OPJ_UINT32 n;
|
||||
|
||||
tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
|
||||
if(!tree) return 00;
|
||||
memset(tree,0,sizeof(opj_tgt_tree_t));
|
||||
|
||||
tree->numleafsh = numleafsh;
|
||||
tree->numleafsv = numleafsv;
|
||||
|
||||
numlvls = 0;
|
||||
nplh[0] = numleafsh;
|
||||
nplv[0] = numleafsv;
|
||||
tree->numnodes = 0;
|
||||
do {
|
||||
n = nplh[numlvls] * nplv[numlvls];
|
||||
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
|
||||
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
|
||||
tree->numnodes += n;
|
||||
++numlvls;
|
||||
} while (n > 1);
|
||||
|
||||
/* ADD */
|
||||
if (tree->numnodes == 0) {
|
||||
opj_free(tree);
|
||||
return 00;
|
||||
}
|
||||
|
||||
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
|
||||
if(!tree->nodes) {
|
||||
opj_free(tree);
|
||||
return 00;
|
||||
}
|
||||
memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t));
|
||||
tree->nodes_size = tree->numnodes * sizeof(opj_tgt_node_t);
|
||||
|
||||
node = tree->nodes;
|
||||
l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv];
|
||||
l_parent_node0 = l_parent_node;
|
||||
|
||||
for (i = 0; i < numlvls - 1; ++i) {
|
||||
for (j = 0; j < nplv[i]; ++j) {
|
||||
k = nplh[i];
|
||||
while (--k >= 0) {
|
||||
node->parent = l_parent_node;
|
||||
++node;
|
||||
if (--k >= 0) {
|
||||
node->parent = l_parent_node;
|
||||
++node;
|
||||
}
|
||||
++l_parent_node;
|
||||
}
|
||||
if ((j & 1) || j == nplv[i] - 1) {
|
||||
l_parent_node0 = l_parent_node;
|
||||
} else {
|
||||
l_parent_node = l_parent_node0;
|
||||
l_parent_node0 += nplh[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
node->parent = 0;
|
||||
tgt_reset(tree);
|
||||
return tree;
|
||||
}
|
||||
/**
|
||||
* Reinitialises a tag-tree from an exixting one.
|
||||
*
|
||||
* @param p_tree the tree to reinitialize.
|
||||
* @param p_num_leafs_h the width of the array of leafs of the tree
|
||||
* @param p_num_leafs_v the height of the array of leafs of the tree
|
||||
* @return a new tag-tree if successful, NULL otherwise
|
||||
*/
|
||||
opj_tgt_tree_t *tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_UINT32 p_num_leafs_v)
|
||||
{
|
||||
OPJ_INT32 l_nplh[32];
|
||||
OPJ_INT32 l_nplv[32];
|
||||
opj_tgt_node_t *l_node = 00;
|
||||
opj_tgt_node_t *l_parent_node = 00;
|
||||
opj_tgt_node_t *l_parent_node0 = 00;
|
||||
OPJ_UINT32 i;
|
||||
OPJ_INT32 j,k;
|
||||
OPJ_UINT32 l_num_levels;
|
||||
OPJ_UINT32 n;
|
||||
OPJ_UINT32 l_node_size;
|
||||
|
||||
if
|
||||
(! p_tree)
|
||||
{
|
||||
return 00;
|
||||
}
|
||||
if
|
||||
((p_tree->numleafsh != p_num_leafs_h) || (p_tree->numleafsv != p_num_leafs_v))
|
||||
{
|
||||
p_tree->numleafsh = p_num_leafs_h;
|
||||
p_tree->numleafsv = p_num_leafs_v;
|
||||
|
||||
l_num_levels = 0;
|
||||
l_nplh[0] = p_num_leafs_h;
|
||||
l_nplv[0] = p_num_leafs_v;
|
||||
p_tree->numnodes = 0;
|
||||
do
|
||||
{
|
||||
n = l_nplh[l_num_levels] * l_nplv[l_num_levels];
|
||||
l_nplh[l_num_levels + 1] = (l_nplh[l_num_levels] + 1) / 2;
|
||||
l_nplv[l_num_levels + 1] = (l_nplv[l_num_levels] + 1) / 2;
|
||||
p_tree->numnodes += n;
|
||||
++l_num_levels;
|
||||
}
|
||||
while (n > 1);
|
||||
|
||||
/* ADD */
|
||||
if
|
||||
(p_tree->numnodes == 0)
|
||||
{
|
||||
tgt_destroy(p_tree);
|
||||
return 00;
|
||||
}
|
||||
l_node_size = p_tree->numnodes * sizeof(opj_tgt_node_t);
|
||||
if
|
||||
(l_node_size > p_tree->nodes_size)
|
||||
{
|
||||
p_tree->nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);
|
||||
if
|
||||
(! p_tree->nodes)
|
||||
{
|
||||
tgt_destroy(p_tree);
|
||||
return 00;
|
||||
}
|
||||
memset(((char *) p_tree->nodes) + p_tree->nodes_size, 0 , l_node_size - p_tree->nodes_size);
|
||||
p_tree->nodes_size = l_node_size;
|
||||
}
|
||||
l_node = p_tree->nodes;
|
||||
l_parent_node = &p_tree->nodes[p_tree->numleafsh * p_tree->numleafsv];
|
||||
l_parent_node0 = l_parent_node;
|
||||
|
||||
for
|
||||
(i = 0; i < l_num_levels - 1; ++i)
|
||||
{
|
||||
for
|
||||
(j = 0; j < l_nplv[i]; ++j)
|
||||
{
|
||||
k = l_nplh[i];
|
||||
while
|
||||
(--k >= 0)
|
||||
{
|
||||
l_node->parent = l_parent_node;
|
||||
++l_node;
|
||||
if (--k >= 0)
|
||||
{
|
||||
l_node->parent = l_parent_node;
|
||||
++l_node;
|
||||
}
|
||||
++l_parent_node;
|
||||
}
|
||||
if ((j & 1) || j == l_nplv[i] - 1)
|
||||
{
|
||||
l_parent_node0 = l_parent_node;
|
||||
}
|
||||
else
|
||||
{
|
||||
l_parent_node = l_parent_node0;
|
||||
l_parent_node0 += l_nplh[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
l_node->parent = 0;
|
||||
}
|
||||
tgt_reset(p_tree);
|
||||
|
||||
return p_tree;
|
||||
}
|
||||
|
||||
void tgt_destroy(opj_tgt_tree_t *p_tree)
|
||||
{
|
||||
if
|
||||
(! p_tree)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if
|
||||
(p_tree->nodes)
|
||||
{
|
||||
opj_free(p_tree->nodes);
|
||||
p_tree->nodes = 00;
|
||||
}
|
||||
opj_free(p_tree);
|
||||
}
|
||||
|
||||
void tgt_reset(opj_tgt_tree_t *p_tree) {
|
||||
OPJ_UINT32 i;
|
||||
opj_tgt_node_t * l_current_node = 00;;
|
||||
|
||||
if
|
||||
(! p_tree)
|
||||
{
|
||||
return;
|
||||
}
|
||||
l_current_node = p_tree->nodes;
|
||||
for
|
||||
(i = 0; i < p_tree->numnodes; ++i)
|
||||
{
|
||||
l_current_node->value = 999;
|
||||
l_current_node->low = 0;
|
||||
l_current_node->known = 0;
|
||||
++l_current_node;
|
||||
}
|
||||
}
|
||||
|
||||
void tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) {
|
||||
opj_tgt_node_t *node;
|
||||
node = &tree->nodes[leafno];
|
||||
while (node && node->value > value) {
|
||||
node->value = value;
|
||||
node = node->parent;
|
||||
}
|
||||
}
|
||||
|
||||
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) {
|
||||
opj_tgt_node_t *stk[31];
|
||||
opj_tgt_node_t **stkptr;
|
||||
opj_tgt_node_t *node;
|
||||
OPJ_INT32 low;
|
||||
|
||||
stkptr = stk;
|
||||
node = &tree->nodes[leafno];
|
||||
while (node->parent) {
|
||||
*stkptr++ = node;
|
||||
node = node->parent;
|
||||
}
|
||||
|
||||
low = 0;
|
||||
for (;;) {
|
||||
if (low > node->low) {
|
||||
node->low = low;
|
||||
} else {
|
||||
low = node->low;
|
||||
}
|
||||
|
||||
while (low < threshold) {
|
||||
if (low >= node->value) {
|
||||
if (!node->known) {
|
||||
bio_write(bio, 1, 1);
|
||||
node->known = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
bio_write(bio, 0, 1);
|
||||
++low;
|
||||
}
|
||||
|
||||
node->low = low;
|
||||
if (stkptr == stk)
|
||||
break;
|
||||
node = *--stkptr;
|
||||
}
|
||||
}
|
||||
|
||||
OPJ_UINT32 tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) {
|
||||
opj_tgt_node_t *stk[31];
|
||||
opj_tgt_node_t **stkptr;
|
||||
opj_tgt_node_t *node;
|
||||
OPJ_INT32 low;
|
||||
|
||||
stkptr = stk;
|
||||
node = &tree->nodes[leafno];
|
||||
while (node->parent) {
|
||||
*stkptr++ = node;
|
||||
node = node->parent;
|
||||
}
|
||||
|
||||
low = 0;
|
||||
for (;;) {
|
||||
if (low > node->low) {
|
||||
node->low = low;
|
||||
} else {
|
||||
low = node->low;
|
||||
}
|
||||
while (low < threshold && low < node->value) {
|
||||
if (bio_read(bio, 1)) {
|
||||
node->value = low;
|
||||
} else {
|
||||
++low;
|
||||
}
|
||||
}
|
||||
node->low = low;
|
||||
if (stkptr == stk) {
|
||||
break;
|
||||
}
|
||||
node = *--stkptr;
|
||||
}
|
||||
|
||||
return (node->value < threshold) ? 1 : 0;
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -38,28 +39,32 @@
|
||||
The functions in TGT.C have for goal to realize a tag-tree coder. The functions in TGT.C
|
||||
are used by some function in T2.C.
|
||||
*/
|
||||
|
||||
#include "openjpeg.h"
|
||||
/** @defgroup TGT TGT - Implementation of a tag-tree coder */
|
||||
/*@{*/
|
||||
struct opj_bio;
|
||||
|
||||
/**
|
||||
Tag node
|
||||
*/
|
||||
typedef struct opj_tgt_node {
|
||||
typedef struct opj_tgt_node
|
||||
{
|
||||
struct opj_tgt_node *parent;
|
||||
int value;
|
||||
int low;
|
||||
int known;
|
||||
OPJ_INT32 value;
|
||||
OPJ_INT32 low;
|
||||
OPJ_UINT32 known : 1;
|
||||
} opj_tgt_node_t;
|
||||
|
||||
/**
|
||||
Tag tree
|
||||
*/
|
||||
typedef struct opj_tgt_tree {
|
||||
int numleafsh;
|
||||
int numleafsv;
|
||||
int numnodes;
|
||||
typedef struct opj_tgt_tree
|
||||
{
|
||||
OPJ_UINT32 numleafsh;
|
||||
OPJ_UINT32 numleafsv;
|
||||
OPJ_UINT32 numnodes;
|
||||
opj_tgt_node_t *nodes;
|
||||
OPJ_UINT32 nodes_size; /* maximum size taken by nodes */
|
||||
} opj_tgt_tree_t;
|
||||
|
||||
/** @name Exported functions */
|
||||
@@ -71,7 +76,18 @@ Create a tag-tree
|
||||
@param numleafsv Height of the array of leafs of the tree
|
||||
@return Returns a new tag-tree if successful, returns NULL otherwise
|
||||
*/
|
||||
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv);
|
||||
opj_tgt_tree_t *tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv);
|
||||
|
||||
/**
|
||||
* Reinitialises a tag-tree from an exixting one.
|
||||
*
|
||||
* @param p_tree the tree to reinitialize.
|
||||
* @param p_num_leafs_h the width of the array of leafs of the tree
|
||||
* @param p_num_leafs_v the height of the array of leafs of the tree
|
||||
* @return a new tag-tree if successful, NULL otherwise
|
||||
*/
|
||||
opj_tgt_tree_t *tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_UINT32 p_num_leafs_v);
|
||||
|
||||
/**
|
||||
Destroy a tag-tree, liberating memory
|
||||
@param tree Tag-tree to destroy
|
||||
@@ -88,7 +104,7 @@ Set the value of a leaf of a tag-tree
|
||||
@param leafno Number that identifies the leaf to modify
|
||||
@param value New value of the leaf
|
||||
*/
|
||||
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value);
|
||||
void tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value);
|
||||
/**
|
||||
Encode the value of a leaf of the tag-tree up to a given threshold
|
||||
@param bio Pointer to a BIO handle
|
||||
@@ -96,7 +112,7 @@ Encode the value of a leaf of the tag-tree up to a given threshold
|
||||
@param leafno Number that identifies the leaf to encode
|
||||
@param threshold Threshold to use when encoding value of the leaf
|
||||
*/
|
||||
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
|
||||
void tgt_encode(struct opj_bio *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold);
|
||||
/**
|
||||
Decode the value of a leaf of the tag-tree up to a given threshold
|
||||
@param bio Pointer to a BIO handle
|
||||
@@ -105,7 +121,7 @@ Decode the value of a leaf of the tag-tree up to a given threshold
|
||||
@param threshold Threshold to use when decoding value of the leaf
|
||||
@return Returns 1 if the node's value < threshold, returns 0 otherwise
|
||||
*/
|
||||
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
|
||||
OPJ_UINT32 tgt_decode(struct opj_bio *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
1046
libs/FreeImage/FreeImage.h
Normal file
1046
libs/FreeImage/FreeImage.h
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user