Compare commits

..

2 Commits

419 changed files with 105229 additions and 114273 deletions

View File

@@ -1,63 +0,0 @@
language: c
matrix:
include:
- os: osx
compiler: clang
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
- os: linux
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
- os: linux
compiler: gcc
env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
packages:
- gcc-multilib
- os: linux
compiler: gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug
- os: linux
compiler: clang
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_ASAN=1
- os: linux
compiler: x86_64-w64-mingw32-gcc
env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
packages:
- gcc-mingw-w64-base
- binutils-mingw-w64-x86-64
- gcc-mingw-w64-x86-64
- gcc-mingw-w64
- os: linux
compiler: x86_64-w64-mingw32-gcc
env: OPJ_CI_ARCH=i386 OPJ_CI_BUILD_CONFIGURATION=Release
addons:
apt:
packages:
- gcc-mingw-w64-base
- binutils-mingw-w64-i686
- gcc-mingw-w64-i686
- gcc-mingw-w64
- os: linux
compiler: gcc-4.8
env: OPJ_CI_ABI_CHECK=1
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- libelf-dev
- elfutils
- texinfo
- exuberant-ctags
install:
- ./tools/travis-ci/install.sh
script:
- ./tools/travis-ci/run.sh
- ./tools/travis-ci/abi-check.sh

9979
CHANGES Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -11,9 +11,6 @@ cmake_minimum_required(VERSION 2.8.2)
if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0003 NEW)
if (NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
cmake_policy(SET CMP0042 NEW)
endif()
endif()
if(NOT OPENJPEG_NAMESPACE)
@@ -190,7 +187,7 @@ 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.
# Do not use ffast-math for all build, it would produce incorrect results, only set for release:
SET(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
set(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
endif()
#-----------------------------------------------------------------------------
@@ -225,18 +222,6 @@ CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
include(TestLargeFiles)
OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
# Allocating Aligned Memory Blocks
include(CheckIncludeFiles)
check_include_files(malloc.h OPJ_HAVE_MALLOC_H)
include(CheckSymbolExists)
# _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx
check_symbol_exists(_aligned_malloc malloc.h OPJ_HAVE__ALIGNED_MALLOC)
# posix_memalign (needs _POSIX_C_SOURCE >= 200112L on Linux)
set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L)
check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN)
unset(CMAKE_REQUIRED_DEFINITIONS)
# memalign (obsolete)
check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN)
#-----------------------------------------------------------------------------
# Build Library
if(BUILD_JPIP_SERVER)
@@ -303,8 +288,8 @@ if(BUILD_TESTING)
include(CTest)
# Search openjpeg data needed for the tests
# They could be found via git on the OpenJPEG GitHub code project
# git clone https://github.com/uclouvain/openjpeg-data.git
# 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
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH

View File

@@ -44,7 +44,7 @@ Main available cmake flags:
cmake . -DBUILD_TESTING:BOOL=ON -DOPJ_DATA_ROOT:PATH='path/to/the/data/directory'
make
make Experimental
Note : JPEG2000 test files are available with 'git clone https://github.com/uclouvain/openjpeg-data.git'.
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).

2
NEWS
View File

@@ -36,7 +36,7 @@ API/ABI modifications: (see abi_compat_report in dev-utils/scripts)
Misc:
* OpenJPEG is now officially conformant with JPEG 2000 Part-1
* OpenJPEG is now officialy conformant with JPEG 2000 Part-1
and will soon become official reference software at the
JPEG committee.
* Huge amount of bug fixes. See CHANGES for details.

47
README Normal file
View File

@@ -0,0 +1,47 @@
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.

View File

@@ -1,79 +0,0 @@
# OPENJPEG Library and Applications
## What is OpenJPEG ?
OpenJPEG is an open-source JPEG 2000 codec written in C language. It has been developed in order to promote the use of [JPEG 2000](http://www.jpeg.org/jpeg2000), a still-image compression standard from the Joint Photographic Experts Group ([JPEG](http://www.jpeg.org)). Since April 2015, it is officially recognized by ISO/IEC and ITU-T as a [JPEG 2000 Reference Software](http://www.itu.int/rec/T-REC-T.804-201504-I!Amd2).
## Who can use the code ?
[![badge-license]][link-license]
Anyone. As the OpenJPEG code is released under the [BSD 2-clause "Simplified" License][link-license], anyone can use or modify the code, even for commercial applications. The only restriction is to retain the copyright in the sources or in the binaries documentation. Of course, if you modified the code in a way that might be of interest for other users, you are encouraged to share it (through a [github pull request](https://github.com/uclouvain/openjpeg/pulls) or by filling an [issue](https://github.com/uclouvain/openjpeg/issues)) but this is not a requirement.
## How to install and use OpenJPEG ?
API Documentation needs a major refactoring. Meanwhile, you can check [installation](https://github.com/uclouvain/openjpeg/wiki/Installation) instructions and [codec documentation](https://github.com/uclouvain/openjpeg/wiki/DocJ2KCodec).
## Current Status
[![badge-build]][link-build]
[![badge-msvc-build]][link-msvc-build]
[![badge-coverity]][link-coverity]
## Who are the developers ?
The library is developed and maintained by the Image and Signal Processing Group ([ISPGroup](http://sites.uclouvain.be/ispgroup/)), in the Université catholique de Louvain ([UCL](http://www.uclouvain.be/en-index.html), with the support of the [CNES](https://cnes.fr/), the [CS](http://www.c-s.fr/) company and the [intoPIX](http://www.intopix.com) company. The JPWL module has been developed by the Digital Signal Processing Lab ([DSPLab](http://dsplab.diei.unipg.it/)) of the University of Perugia, Italy ([UNIPG](http://www.unipg.it/)).
## 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 [openjpeg-data](https://github.com/uclouvain/openjpeg-data) repository.
* cmake: cmake related files
See [LICENSE][link-license] for license and copyright information.
See [INSTALL](https://github.com/uclouvain/openjpeg/blob/master/INSTALL) for installation procedures.
See [NEWS](https://github.com/uclouvain/openjpeg/blob/master/NEWS) for user visible changes in successive releases.
## 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 mechanism 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/hiding function and as such the only
API available is the one supported by OpenJPEG.
[comment-license]: https://img.shields.io/github/license/uclouvain/openjpeg.svg "https://img.shields.io/badge/license-BSD--2--Clause-blue.svg"
[badge-license]: https://img.shields.io/badge/license-BSD--2--Clause-blue.svg "BSD 2-clause "Simplified" License"
[link-license]: https://github.com/uclouvain/openjpeg/blob/master/LICENSE "BSD 2-clause "Simplified" License"
[badge-build]: https://travis-ci.org/uclouvain/openjpeg.svg?branch=master "Build Status"
[link-build]: https://travis-ci.org/uclouvain/openjpeg "Build Status"
[badge-msvc-build]: https://ci.appveyor.com/api/projects/status/github/uclouvain/openjpeg?branch=master&svg=true "Windows Build Status"
[link-msvc-build]: https://ci.appveyor.com/project/detonin/openjpeg/branch/master "Windows Build Status"
[badge-coverity]: https://scan.coverity.com/projects/6383/badge.svg "Coverity Scan Build Status"
[link-coverity]: https://scan.coverity.com/projects/uclouvain-openjpeg "Coverity Scan Build Status"

View File

@@ -1,23 +0,0 @@
version: 2.1.1.{build}
branches:
except:
- coverity_scan
skip_tags: true
clone_depth: 50
environment:
matrix:
- OPJ_CI_ARCH: x86
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
- OPJ_CI_ARCH: x64
OPJ_CI_VSCOMNTOOLS: $(VS140COMNTOOLS)
- OPJ_CI_ARCH: x86
OPJ_CI_VSCOMNTOOLS: $(VS100COMNTOOLS)
install:
- cmd: c:\cygwin\bin\bash ./tools/travis-ci/install.sh
build_script:
- cmd: >-
"%OPJ_CI_VSCOMNTOOLS%..\..\VC\vcvarsall.bat" %OPJ_CI_ARCH%
bash ./tools/travis-ci/run.sh
test: off
deploy: off

View File

@@ -30,7 +30,7 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION
# java also warns about deprecated API
".*java.*deprecation"
".*deprecation.*"
# suppress warnings caused by 3rd party libs:
# supress warnings caused by 3rd party libs:
".*thirdparty.*"
"libtiff.*has no symbols"
"libpng.*has no symbols"

View File

@@ -1,12 +0,0 @@
#
# this module looks for JPYLYZER
# http://jpylyzer.openpreservation.org
#
find_program(JPYLYZER_EXECUTABLE
jpylyzer
)
mark_as_advanced(
JPYLYZER_EXECUTABLE
)

View File

@@ -17,7 +17,7 @@
#
macro(OPJ_TEST_LARGE_FILES VARIABLE)
if(NOT DEFINED ${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

View File

@@ -36,21 +36,21 @@
*
* \section home Home page
*
* The Home Page of the OpenJPEG project can be found at:
* 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 source code repository is available here:
*
* http://github.com/uclouvain/openjpeg
*
* The OpenJPEG mailing list is located here:
*
* http://groups.google.com/group/openjpeg
*
* The test files repository is available here:
* All the source code is online and can be retrieved using svn from here:
*
* http://github.com/uclouvain/openjpeg-data
* 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

View File

@@ -29,7 +29,7 @@
.SP
.fi
..
.TH opj_compress 1 "Version 2.1.1" "opj_compress" "converts to jpeg2000 files"
.TH opj_compress 1 "Version 1.4.0" "opj_compress" "converts to jpeg2000 files"
.P
.SH NAME
opj_compress -

View File

@@ -29,7 +29,7 @@
.SP
.fi
..
.TH opj_decompress 1 "Version 2.1.1" "opj_decompress" "converts jpeg2000 files"
.TH opj_decompress 1 "Version 1.4.0" "opj_decompress" "converts jpeg2000 files"
.P
.SH NAME
opj_decompress -
@@ -73,19 +73,9 @@ n is the maximum number of quality layers to decode. See LAYERS below)
.B \-\^OutFor "ext"
(extension for output files)
.P
.SH JPIP OPTIONS
Options usable only if the library has been compiled with
.B BUILD_JPIP
.TP
.B -jpip
Embed index table box into the output JP2 file (compulsory for JPIP)
.TP
.B -TP R
Partition a tile into tile parts of different resolution levels (compulsory for JPT-stream)
.P
.SH JPWL OPTIONS
Options usable only if the library has been compiled with
.B BUILD_JPWL
.B -DUSE_JPWL
.TP
.B -W c\fR[=Nc] (Nc is the number of expected components in the codestream; default:3)
.TP

View File

@@ -29,7 +29,7 @@
.SP
.fi
..
.TH opj_dump 1 "Version 2.1.1" "opj_dump" "dumps jpeg2000 files"
.TH opj_dump 1 "Version 1.4.0" "opj_dump" "dumps jpeg2000 files"
.P
.SH NAME
opj_dump -

View File

@@ -64,7 +64,7 @@
*
*
* \section sysarchtect System Architecture
* JPIP protocol is implemented between the JPIP server program (opj_server) and the JPIP client java program (opj_viewer).\n
* 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

View File

@@ -76,37 +76,27 @@ static void sycc_to_rgb(int offset, int upb, int y, int cb, int cr,
{
int r, g, b;
cb -= offset;
cr -= offset;
cb -= offset; cr -= offset;
r = y + (int)(1.402 * (float)cr);
if(r < 0) r = 0;
else if(r > upb) r = upb;
*out_r = r;
if(r < 0) r = 0; else if(r > upb) r = upb; *out_r = r;
g = y - (int)(0.344 * (float)cb + 0.714 * (float)cr);
if(g < 0) g = 0;
else if(g > upb) g = upb;
*out_g = g;
if(g < 0) g = 0; else if(g > upb) g = upb; *out_g = g;
b = y + (int)(1.772 * (float)cb);
if(b < 0) b = 0;
else if(b > upb) b = upb;
*out_b = b;
if(b < 0) b = 0; else if(b > upb) b = upb; *out_b = b;
}
static void sycc444_to_rgb(opj_image_t *img)
{
int *d0, *d1, *d2, *r, *g, *b;
const int *y, *cb, *cr;
unsigned int maxw, maxh, max, i;
int offset, upb;
int maxw, maxh, max, i, offset, upb;
upb = (int)img->comps[0].prec;
offset = 1<<(upb - 1);
upb = (1<<upb)-1;
i = (int)img->comps[0].prec;
offset = 1<<(i - 1); upb = (1<<i)-1;
maxw = (unsigned int)img->comps[0].w;
maxh = (unsigned int)img->comps[0].h;
maxw = (int)img->comps[0].w; maxh = (int)img->comps[0].h;
max = maxw * maxh;
y = img->comps[0].data;
@@ -117,21 +107,15 @@ static void sycc444_to_rgb(opj_image_t *img)
d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i = 0U; i < max; ++i) {
for(i = 0; i < max; ++i)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y;
++cb;
++cr;
++r;
++g;
++b;
++y; ++cb; ++cr; ++r; ++g; ++b;
}
free(img->comps[0].data);
img->comps[0].data = d0;
free(img->comps[1].data);
img->comps[1].data = d1;
free(img->comps[2].data);
img->comps[2].data = d2;
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
}/* sycc444_to_rgb() */
@@ -139,16 +123,13 @@ static void sycc422_to_rgb(opj_image_t *img)
{
int *d0, *d1, *d2, *r, *g, *b;
const int *y, *cb, *cr;
unsigned int maxw, maxh, max;
int offset, upb;
unsigned int i, j;
int maxw, maxh, max, offset, upb;
int i, j;
upb = (int)img->comps[0].prec;
offset = 1<<(upb - 1);
upb = (1<<upb)-1;
i = (int)img->comps[0].prec;
offset = 1<<(i - 1); upb = (1<<i)-1;
maxw = (unsigned int)img->comps[0].w;
maxh = (unsigned int)img->comps[0].h;
maxw = (int)img->comps[0].w; maxh = (int)img->comps[0].h;
max = maxw * maxh;
y = img->comps[0].data;
@@ -159,48 +140,33 @@ static void sycc422_to_rgb(opj_image_t *img)
d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0U; i < maxh; ++i) {
for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U) {
for(i=0; i < maxh; ++i)
{
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y;
++r;
++g;
++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y;
++r;
++g;
++b;
++cb;
++cr;
++y; ++r; ++g; ++b; ++cb; ++cr;
}
if (j < maxw) {
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y;
++r;
++g;
++b;
++cb;
++cr;
++y; ++r; ++g; ++b; ++cb; ++cr;
}
}
free(img->comps[0].data);
img->comps[0].data = d0;
free(img->comps[1].data);
img->comps[1].data = d1;
free(img->comps[2].data);
img->comps[2].data = d2;
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
#if defined(USE_JPWL) || defined(USE_MJ2)
img->comps[1].w = maxw;
img->comps[1].h = maxh;
img->comps[2].w = maxw;
img->comps[2].h = maxh;
img->comps[1].w = maxw; img->comps[1].h = maxh;
img->comps[2].w = maxw; img->comps[2].h = maxh;
#else
img->comps[1].w = (OPJ_UINT32)maxw;
img->comps[1].h = (OPJ_UINT32)maxh;
img->comps[2].w = (OPJ_UINT32)maxw;
img->comps[2].h = (OPJ_UINT32)maxh;
img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh;
img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh;
#endif
img->comps[1].dx = img->comps[0].dx;
img->comps[2].dx = img->comps[0].dx;
@@ -213,16 +179,13 @@ static void sycc420_to_rgb(opj_image_t *img)
{
int *d0, *d1, *d2, *r, *g, *b, *nr, *ng, *nb;
const int *y, *cb, *cr, *ny;
unsigned int maxw, maxh, max;
int offset, upb;
unsigned int i, j;
int maxw, maxh, max, offset, upb;
int i, j;
upb = (int)img->comps[0].prec;
offset = 1<<(upb - 1);
upb = (1<<upb)-1;
i = (int)img->comps[0].prec;
offset = 1<<(i - 1); upb = (1<<i)-1;
maxw = (unsigned int)img->comps[0].w;
maxh = (unsigned int)img->comps[0].h;
maxw = (int)img->comps[0].w; maxh = (int)img->comps[0].h;
max = maxw * maxh;
y = img->comps[0].data;
@@ -233,97 +196,69 @@ static void sycc420_to_rgb(opj_image_t *img)
d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0U; i < (maxh & ~(unsigned int)1U); i += 2U) {
for(i=0; (OPJ_UINT32)i < (maxh & ~(OPJ_UINT32)1); i += 2)
{
ny = y + maxw;
nr = r + maxw;
ng = g + maxw;
nb = b + maxw;
nr = r + maxw; ng = g + maxw; nb = b + maxw;
for(j=0; j < (maxw & ~(unsigned int)1U); j += 2U) {
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y;
++r;
++g;
++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y;
++r;
++g;
++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny;
++nr;
++ng;
++nb;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny;
++nr;
++ng;
++nb;
++cb;
++cr;
}
if(j < maxw) {
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y;
++r;
++g;
++b;
++ny; ++nr; ++ng; ++nb;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny;
++nr;
++ng;
++nb;
++cb;
++cr;
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
y += maxw;
r += maxw;
g += maxw;
b += maxw;
}
if(i < maxh) {
for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U) {
if(j < maxw)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y;
++r;
++g;
++b;
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++cb; ++cr;
}
y += maxw; r += maxw; g += maxw; b += maxw;
}
if(i < maxh)
{
for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y;
++r;
++g;
++b;
++cb;
++cr;
++y; ++r; ++g; ++b; ++cb; ++cr;
}
if(j < maxw) {
if(j < maxw)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
}
}
free(img->comps[0].data);
img->comps[0].data = d0;
free(img->comps[1].data);
img->comps[1].data = d1;
free(img->comps[2].data);
img->comps[2].data = d2;
free(img->comps[0].data); img->comps[0].data = d0;
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
#if defined(USE_JPWL) || defined(USE_MJ2)
img->comps[1].w = maxw;
img->comps[1].h = maxh;
img->comps[2].w = maxw;
img->comps[2].h = maxh;
img->comps[1].w = maxw; img->comps[1].h = maxh;
img->comps[2].w = maxw; img->comps[2].h = maxh;
#else
img->comps[1].w = (OPJ_UINT32)maxw;
img->comps[1].h = (OPJ_UINT32)maxh;
img->comps[2].w = (OPJ_UINT32)maxw;
img->comps[2].h = (OPJ_UINT32)maxh;
img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh;
img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh;
#endif
img->comps[1].dx = img->comps[0].dx;
img->comps[2].dx = img->comps[0].dx;
@@ -334,7 +269,8 @@ static void sycc420_to_rgb(opj_image_t *img)
void color_sycc_to_rgb(opj_image_t *img)
{
if(img->numcomps < 3) {
if(img->numcomps < 3)
{
img->color_space = OPJ_CLRSPC_GRAY;
return;
}
@@ -344,24 +280,34 @@ void color_sycc_to_rgb(opj_image_t *img)
&& (img->comps[2].dx == 2)
&& (img->comps[0].dy == 1)
&& (img->comps[1].dy == 2)
&& (img->comps[2].dy == 2)) { /* horizontal and vertical sub-sample */
&& (img->comps[2].dy == 2))/* horizontal and vertical sub-sample */
{
sycc420_to_rgb(img);
} else if((img->comps[0].dx == 1)
}
else
if((img->comps[0].dx == 1)
&& (img->comps[1].dx == 2)
&& (img->comps[2].dx == 2)
&& (img->comps[0].dy == 1)
&& (img->comps[1].dy == 1)
&& (img->comps[2].dy == 1)) { /* horizontal sub-sample only */
&& (img->comps[2].dy == 1))/* horizontal sub-sample only */
{
sycc422_to_rgb(img);
} else if((img->comps[0].dx == 1)
}
else
if((img->comps[0].dx == 1)
&& (img->comps[1].dx == 1)
&& (img->comps[2].dx == 1)
&& (img->comps[0].dy == 1)
&& (img->comps[1].dy == 1)
&& (img->comps[2].dy == 1)) { /* no sub-sample */
&& (img->comps[2].dy == 1))/* no sub-sample */
{
sycc444_to_rgb(img);
} else {
fprintf(stderr,"%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__);
}
else
{
fprintf(stderr,"%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n",
__FILE__,__LINE__);
return;
}
img->color_space = OPJ_CLRSPC_SRGB;
@@ -369,7 +315,6 @@ void color_sycc_to_rgb(opj_image_t *img)
}/* color_sycc_to_rgb() */
#if defined(OPJ_HAVE_LIBLCMS2) || defined(OPJ_HAVE_LIBLCMS1)
#ifdef OPJ_HAVE_LIBLCMS1
/* Bob Friesenhahn proposed:*/
#define cmsSigXYZData icSigXYZData
@@ -417,27 +362,39 @@ void color_apply_icc_profile(opj_image_t *image)
prec = (int)image->comps[0].prec;
oldspace = image->color_space;
if(out_space == cmsSigRgbData) { /* enumCS 16 */
if( prec <= 8 ) {
if(out_space == cmsSigRgbData) /* enumCS 16 */
{
if( prec <= 8 )
{
in_type = TYPE_RGB_8;
out_type = TYPE_RGB_8;
} else {
}
else
{
in_type = TYPE_RGB_16;
out_type = TYPE_RGB_16;
}
out_prof = cmsCreate_sRGBProfile();
image->color_space = OPJ_CLRSPC_SRGB;
} else if(out_space == cmsSigGrayData) { /* enumCS 17 */
}
else
if(out_space == cmsSigGrayData) /* enumCS 17 */
{
in_type = TYPE_GRAY_8;
out_type = TYPE_RGB_8;
out_prof = cmsCreate_sRGBProfile();
image->color_space = OPJ_CLRSPC_SRGB;
} else if(out_space == cmsSigYCbCrData) { /* enumCS 18 */
}
else
if(out_space == cmsSigYCbCrData) /* enumCS 18 */
{
in_type = TYPE_YCbCr_16;
out_type = TYPE_RGB_16;
out_prof = cmsCreate_sRGBProfile();
image->color_space = OPJ_CLRSPC_SRGB;
} else {
}
else
{
#ifdef DEBUG_PROFILE
fprintf(stderr,"%s:%d: color_apply_icc_profile\n\tICC Profile has unknown "
"output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n",
@@ -481,7 +438,8 @@ void color_apply_icc_profile(opj_image_t *image)
cmsCloseProfile(out_prof);
#endif
if(transform == NULL) {
if(transform == NULL)
{
#ifdef DEBUG_PROFILE
fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
"ICC Profile ignored.\n",__FILE__,__LINE__);
@@ -494,8 +452,10 @@ void color_apply_icc_profile(opj_image_t *image)
return;
}
if(image->numcomps > 2) { /* RGB, RGBA */
if( prec <= 8 ) {
if(image->numcomps > 2)/* RGB, RGBA */
{
if( prec <= 8 )
{
unsigned char *inbuf, *outbuf, *in, *out;
max = max_w * max_h;
nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned char);
@@ -506,7 +466,8 @@ void color_apply_icc_profile(opj_image_t *image)
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0; i < max; ++i) {
for(i = 0; i < max; ++i)
{
*in++ = (unsigned char)*r++;
*in++ = (unsigned char)*g++;
*in++ = (unsigned char)*b++;
@@ -518,14 +479,16 @@ void color_apply_icc_profile(opj_image_t *image)
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0; i < max; ++i) {
for(i = 0; i < max; ++i)
{
*r++ = (int)*out++;
*g++ = (int)*out++;
*b++ = (int)*out++;
}
free(inbuf);
free(outbuf);
} else {
free(inbuf); free(outbuf);
}
else
{
unsigned short *inbuf, *outbuf, *in, *out;
max = max_w * max_h;
nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short);
@@ -536,7 +499,8 @@ void color_apply_icc_profile(opj_image_t *image)
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0; i < max; ++i) {
for(i = 0; i < max; ++i)
{
*in++ = (unsigned short)*r++;
*in++ = (unsigned short)*g++;
*in++ = (unsigned short)*b++;
@@ -548,15 +512,17 @@ void color_apply_icc_profile(opj_image_t *image)
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0; i < max; ++i) {
for(i = 0; i < max; ++i)
{
*r++ = (int)*out++;
*g++ = (int)*out++;
*b++ = (int)*out++;
}
free(inbuf);
free(outbuf);
free(inbuf); free(outbuf);
}
} else { /* GRAY, GRAYA */
}
else /* GRAY, GRAYA */
{
unsigned char *in, *inbuf, *out, *outbuf;
max = max_w * max_h;
nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char);
@@ -579,7 +545,8 @@ void color_apply_icc_profile(opj_image_t *image)
r = image->comps[0].data;
for(i = 0; i < max; ++i) {
for(i = 0; i < max; ++i)
{
*in++ = (unsigned char)*r++;
}
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
@@ -588,13 +555,11 @@ void color_apply_icc_profile(opj_image_t *image)
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0; i < max; ++i) {
*r++ = (int)*out++;
*g++ = (int)*out++;
*b++ = (int)*out++;
for(i = 0; i < max; ++i)
{
*r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++;
}
free(inbuf);
free(outbuf);
free(inbuf); free(outbuf);
}/* if(image->numcomps */
@@ -606,236 +571,5 @@ void color_apply_icc_profile(opj_image_t *image)
#endif
}/* color_apply_icc_profile() */
void color_cielab_to_rgb(opj_image_t *image)
{
int *row;
int enumcs, numcomps;
image->color_space = OPJ_CLRSPC_SRGB;
numcomps = (int)image->numcomps;
if(numcomps != 3) {
fprintf(stderr,"%s:%d:\n\tnumcomps %d not handled. Quitting.\n",
__FILE__,__LINE__,numcomps);
return;
}
row = (int*)image->icc_profile_buf;
enumcs = row[0];
if(enumcs == 14) { /* CIELab */
int *L, *a, *b, *red, *green, *blue;
int *src0, *src1, *src2, *dst0, *dst1, *dst2;
double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2;
double minL, maxL, mina, maxa, minb, maxb;
unsigned int default_type;
unsigned int i, max;
cmsHPROFILE in, out;
cmsHTRANSFORM transform;
cmsUInt16Number RGB[3];
cmsCIELab Lab;
in = cmsCreateLab4Profile(NULL);
out = cmsCreate_sRGBProfile();
transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, INTENT_PERCEPTUAL, 0);
#ifdef OPJ_HAVE_LIBLCMS2
cmsCloseProfile(in);
cmsCloseProfile(out);
#endif
if(transform == NULL) {
#ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in);
cmsCloseProfile(out);
#endif
return;
}
prec0 = (double)image->comps[0].prec;
prec1 = (double)image->comps[1].prec;
prec2 = (double)image->comps[2].prec;
default_type = (unsigned int)row[1];
if(default_type == 0x44454600) { /* DEF : default */
rl = 100;
ra = 170;
rb = 200;
ol = 0;
oa = pow(2, prec1 - 1);
ob = pow(2, prec2 - 2) + pow(2, prec2 - 3);
} else {
rl = row[2];
ra = row[4];
rb = row[6];
ol = row[3];
oa = row[5];
ob = row[7];
}
L = src0 = image->comps[0].data;
a = src1 = image->comps[1].data;
b = src2 = image->comps[2].data;
max = image->comps[0].w * image->comps[0].h;
red = dst0 = (int*)malloc(max * sizeof(int));
green = dst1 = (int*)malloc(max * sizeof(int));
blue = dst2 = (int*)malloc(max * sizeof(int));
minL = -(rl * ol)/(pow(2, prec0)-1);
maxL = minL + rl;
mina = -(ra * oa)/(pow(2, prec1)-1);
maxa = mina + ra;
minb = -(rb * ob)/(pow(2, prec2)-1);
maxb = minb + rb;
for(i = 0; i < max; ++i) {
Lab.L = minL + (double)(*L) * (maxL - minL)/(pow(2, prec0)-1);
++L;
Lab.a = mina + (double)(*a) * (maxa - mina)/(pow(2, prec1)-1);
++a;
Lab.b = minb + (double)(*b) * (maxb - minb)/(pow(2, prec2)-1);
++b;
cmsDoTransform(transform, &Lab, RGB, 1);
*red++ = RGB[0];
*green++ = RGB[1];
*blue++ = RGB[2];
}
cmsDeleteTransform(transform);
#ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in);
cmsCloseProfile(out);
#endif
free(src0);
image->comps[0].data = dst0;
free(src1);
image->comps[1].data = dst1;
free(src2);
image->comps[2].data = dst2;
image->color_space = OPJ_CLRSPC_SRGB;
image->comps[0].prec = 16;
image->comps[1].prec = 16;
image->comps[2].prec = 16;
return;
}
fprintf(stderr,"%s:%d:\n\tenumCS %d not handled. Ignoring.\n", __FILE__,__LINE__, enumcs);
}/* color_apply_conversion() */
#endif /* OPJ_HAVE_LIBLCMS2 || OPJ_HAVE_LIBLCMS1 */
void color_cmyk_to_rgb(opj_image_t *image)
{
float C, M, Y, K;
float sC, sM, sY, sK;
unsigned int w, h, max, i;
w = image->comps[0].w;
h = image->comps[0].h;
if(image->numcomps < 4) return;
max = w * h;
sC = 1.0F / (float)((1 << image->comps[0].prec) - 1);
sM = 1.0F / (float)((1 << image->comps[1].prec) - 1);
sY = 1.0F / (float)((1 << image->comps[2].prec) - 1);
sK = 1.0F / (float)((1 << image->comps[3].prec) - 1);
for(i = 0; i < max; ++i) {
/* CMYK values from 0 to 1 */
C = (float)(image->comps[0].data[i]) * sC;
M = (float)(image->comps[1].data[i]) * sM;
Y = (float)(image->comps[2].data[i]) * sY;
K = (float)(image->comps[3].data[i]) * sK;
/* Invert all CMYK values */
C = 1.0F - C;
M = 1.0F - M;
Y = 1.0F - Y;
K = 1.0F - K;
/* CMYK -> RGB : RGB results from 0 to 255 */
image->comps[0].data[i] = (int)(255.0F * C * K); /* R */
image->comps[1].data[i] = (int)(255.0F * M * K); /* G */
image->comps[2].data[i] = (int)(255.0F * Y * K); /* B */
}
free(image->comps[3].data);
image->comps[3].data = NULL;
image->comps[0].prec = 8;
image->comps[1].prec = 8;
image->comps[2].prec = 8;
image->numcomps -= 1;
image->color_space = OPJ_CLRSPC_SRGB;
for (i = 3; i < image->numcomps; ++i) {
memcpy(&(image->comps[i]), &(image->comps[i+1]), sizeof(image->comps[i]));
}
}/* color_cmyk_to_rgb() */
/*
* This code has been adopted from sjpx_openjpeg.c of ghostscript
*/
void color_esycc_to_rgb(opj_image_t *image)
{
int y, cb, cr, sign1, sign2, val;
unsigned int w, h, max, i;
int flip_value = (1 << (image->comps[0].prec-1));
int max_value = (1 << image->comps[0].prec) - 1;
if(image->numcomps < 3) return;
w = image->comps[0].w;
h = image->comps[0].h;
sign1 = (int)image->comps[1].sgnd;
sign2 = (int)image->comps[2].sgnd;
max = w * h;
for(i = 0; i < max; ++i) {
y = image->comps[0].data[i];
cb = image->comps[1].data[i];
cr = image->comps[2].data[i];
if( !sign1) cb -= flip_value;
if( !sign2) cr -= flip_value;
val = (int)
((float)y - (float)0.0000368 * (float)cb
+ (float)1.40199 * (float)cr + (float)0.5);
if(val > max_value) val = max_value;
else if(val < 0) val = 0;
image->comps[0].data[i] = val;
val = (int)
((float)1.0003 * (float)y - (float)0.344125 * (float)cb
- (float)0.7141128 * (float)cr + (float)0.5);
if(val > max_value) val = max_value;
else if(val < 0) val = 0;
image->comps[1].data[i] = val;
val = (int)
((float)0.999823 * (float)y + (float)1.77204 * (float)cb
- (float)0.000008 *(float)cr + (float)0.5);
if(val > max_value) val = max_value;
else if(val < 0) val = 0;
image->comps[2].data[i] = val;
}
image->color_space = OPJ_CLRSPC_SRGB;
}/* color_esycc_to_rgb() */

View File

@@ -40,8 +40,5 @@
extern void color_sycc_to_rgb(opj_image_t *img);
extern void color_apply_icc_profile(opj_image_t *image);
extern void color_cielab_to_rgb(opj_image_t *image);
extern void color_cmyk_to_rgb(opj_image_t *image);
extern void color_esycc_to_rgb(opj_image_t *image);
#endif /* _OPJ_COLOR_H_ */

View File

@@ -54,8 +54,7 @@ char *opj_optarg; /* argument associated with option */
static char EMSG[]={""};
/* As this class remembers its values from one Java call to the other, reset the values before each use */
void opj_reset_options_reading(void)
{
void reset_options_reading(void) {
opj_opterr = 1;
opj_optind = 1;
}
@@ -64,11 +63,10 @@ void opj_reset_options_reading(void)
* getopt --
* Parse argc/argv argument vector.
*/
int opj_getopt(int nargc, char *const *nargv, const char *ostr)
{
int opj_getopt(int nargc, char *const *nargv, const char *ostr) {
# define __progname nargv[0]
static char *place = EMSG; /* option letter processing */
const char *oli = NULL; /* option letter list index */
char *oli = NULL; /* option letter list index */
if (opj_optreset || !*place) { /* update scanning pointer */
opj_optreset = 0;
@@ -125,10 +123,9 @@ int opj_getopt(int nargc, char *const *nargv, const char *ostr)
int opj_getopt_long(int argc, char * const argv[], const char *optstring,
const opj_option_t *longopts, int totlen)
{
const opj_option_t *longopts, int totlen) {
static int lastidx,lastofs;
const char *tmp;
char *tmp;
int i,len;
char param = 1;
@@ -139,10 +136,12 @@ again:
if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
if(opj_optind >= (argc - 1)){ /* no more input parameters */
param = 0;
} else { /* more input parameters */
}
else{ /* more input parameters */
if(argv[opj_optind + 1][0] == '-'){
param = 0; /* Missing parameter after '-' */
} else {
}
else{
param = 2;
}
}
@@ -162,7 +161,8 @@ again:
if (param > 1){
arg = argv[opj_optind+1];
opj_optind++;
} else
}
else
arg = argv[opj_optind]+1;
if(strlen(arg)>1){
@@ -205,8 +205,7 @@ again:
}else{ /*Single character input parameter*/
if (*optstring==':') return ':';
if (lastidx!=opj_optind) {
lastidx=opj_optind;
lastofs=0;
lastidx=opj_optind; lastofs=0;
}
opj_optopt=argv[opj_optind][lastofs+1];
if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/

View File

@@ -3,7 +3,8 @@
#ifndef _GETOPT_H_
#define _GETOPT_H_
typedef struct opj_option {
typedef struct opj_option
{
const char *name;
int has_arg;
int *flag;
@@ -23,6 +24,6 @@ extern char *opj_optarg;
extern int opj_getopt(int nargc, char *const *nargv, const char *ostr);
extern int opj_getopt_long(int argc, char * const argv[], const char *optstring,
const opj_option_t *longopts, int totlen);
extern void opj_reset_options_reading(void);
extern void reset_options_reading(void);
#endif /* _GETOPT_H_ */

View File

@@ -1,72 +0,0 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2015, Matthieu Darbois
* 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 OPJ_STRING_H
#define OPJ_STRING_H
#include <errno.h>
#include <string.h>
/* strnlen is not standard, strlen_s is C11... */
/* keep in mind there still is a buffer read overflow possible */
static size_t opj_strnlen_s(const char *src, size_t max_len)
{
size_t len;
if (src == NULL) {
return 0U;
}
for (len = 0U; (*src != '\0') && (len < max_len); src++, len++);
return len;
}
/* should be equivalent to C11 function except for the handler */
/* keep in mind there still is a buffer read overflow possible */
static int opj_strcpy_s(char* dst, size_t dst_size, const char* src)
{
size_t src_len = 0U;
if ((dst == NULL) || (dst_size == 0U)) {
return EINVAL;
}
if (src == NULL) {
dst[0] = '\0';
return EINVAL;
}
src_len = opj_strnlen_s(src, dst_size);
if (src_len >= dst_size) {
return ERANGE;
}
memcpy(dst, src, src_len);
dst[src_len] = '\0';
return 0;
}
#endif /* OPJ_STRING_H */

View File

@@ -3,24 +3,11 @@
# First thing define the common source:
set(common_SRCS
convert.c
convert.h
convertbmp.c
index.c
index.h
${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c
${OPENJPEG_SOURCE_DIR}/src/bin/common/color.h
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.h
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_string.h
)
if(OPJ_HAVE_LIBTIFF)
list(APPEND common_SRCS converttif.c)
endif()
if(OPJ_HAVE_LIBPNG)
list(APPEND common_SRCS convertpng.c)
endif()
# Headers file are located here:
include_directories(
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
@@ -64,9 +51,10 @@ foreach(exe opj_decompress opj_compress opj_dump)
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
if(OPJ_USE_DSYMUTIL)
GET_TARGET_PROPERTY(EXE_LOCATION ${exe} LOCATION)
add_custom_command(TARGET ${exe} POST_BUILD
COMMAND "dsymutil" "$<TARGET_FILE:${exe}>"
COMMENT "dsymutil $<TARGET_FILE:${exe}>"
COMMAND "dsymutil" "${EXE_LOCATION}"
COMMENT "dsymutil ${EXE_LOCATION}"
DEPENDS ${exe})
endif()
endforeach()

File diff suppressed because it is too large Load Diff

View File

@@ -65,23 +65,6 @@ typedef struct raw_cparameters {
/*@}*/
} raw_cparameters_t;
/* Component precision clipping */
void clip_component(opj_image_comp_t* component, OPJ_UINT32 precision);
/* Component precision scaling */
void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision);
/* planar / interleaved conversions */
typedef void (* convert_32s_CXPX)(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst, OPJ_SIZE_T length);
extern const convert_32s_CXPX convert_32s_CXPX_LUT[5];
typedef void (* convert_32s_PXCX)(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length, OPJ_INT32 adjust);
extern const convert_32s_PXCX convert_32s_PXCX_LUT[5];
/* bit depth conversions */
typedef void (* convert_XXx32s_C1R)(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length);
extern const convert_XXx32s_C1R convert_XXu32s_C1R_LUT[9]; /* up to 8bpp */
typedef void (* convert_32sXXx_C1R)(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length);
extern const convert_32sXXx_C1R convert_32sXXu_C1R_LUT[9]; /* up to 8bpp */
/* TGA conversion */
opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters);
int imagetotga(opj_image_t * image, const char *outfile);
@@ -103,7 +86,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters);
int imagetopgx(opj_image_t *image, const char *outfile);
opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters);
int imagetopnm(opj_image_t *image, const char *outfile, int force_split);
int imagetopnm(opj_image_t *image, const char *outfile);
/* RAW conversion */
int imagetoraw(opj_image_t * image, const char *outfile);

View File

@@ -1,958 +0,0 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* 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 "opj_apps_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "openjpeg.h"
#include "convert.h"
typedef struct {
OPJ_UINT16 bfType; /* 'BM' for Bitmap (19776) */
OPJ_UINT32 bfSize; /* Size of the file */
OPJ_UINT16 bfReserved1; /* Reserved : 0 */
OPJ_UINT16 bfReserved2; /* Reserved : 0 */
OPJ_UINT32 bfOffBits; /* Offset */
} OPJ_BITMAPFILEHEADER;
typedef struct {
OPJ_UINT32 biSize; /* Size of the structure in bytes */
OPJ_UINT32 biWidth; /* Width of the image in pixels */
OPJ_UINT32 biHeight; /* Heigth of the image in pixels */
OPJ_UINT16 biPlanes; /* 1 */
OPJ_UINT16 biBitCount; /* Number of color bits by pixels */
OPJ_UINT32 biCompression; /* Type of encoding 0: none 1: RLE8 2: RLE4 */
OPJ_UINT32 biSizeImage; /* Size of the image in bytes */
OPJ_UINT32 biXpelsPerMeter; /* Horizontal (X) resolution in pixels/meter */
OPJ_UINT32 biYpelsPerMeter; /* Vertical (Y) resolution in pixels/meter */
OPJ_UINT32 biClrUsed; /* Number of color used in the image (0: ALL) */
OPJ_UINT32 biClrImportant; /* Number of important color (0: ALL) */
OPJ_UINT32 biRedMask; /* Red channel bit mask */
OPJ_UINT32 biGreenMask; /* Green channel bit mask */
OPJ_UINT32 biBlueMask; /* Blue channel bit mask */
OPJ_UINT32 biAlphaMask; /* Alpha channel bit mask */
OPJ_UINT32 biColorSpaceType; /* Color space type */
OPJ_UINT8 biColorSpaceEP[36]; /* Color space end points */
OPJ_UINT32 biRedGamma; /* Red channel gamma */
OPJ_UINT32 biGreenGamma; /* Green channel gamma */
OPJ_UINT32 biBlueGamma; /* Blue channel gamma */
OPJ_UINT32 biIntent; /* Intent */
OPJ_UINT32 biIccProfileData; /* ICC profile data */
OPJ_UINT32 biIccProfileSize; /* ICC profile size */
OPJ_UINT32 biReserved; /* Reserved */
} OPJ_BITMAPINFOHEADER;
static void opj_applyLUT8u_8u32s_C1R(
OPJ_UINT8 const* pSrc, OPJ_INT32 srcStride,
OPJ_INT32* pDst, OPJ_INT32 dstStride,
OPJ_UINT8 const* pLUT,
OPJ_UINT32 width, OPJ_UINT32 height)
{
OPJ_UINT32 y;
for (y = height; y != 0U; --y) {
OPJ_UINT32 x;
for(x = 0; x < width; x++) {
pDst[x] = (OPJ_INT32)pLUT[pSrc[x]];
}
pSrc += srcStride;
pDst += dstStride;
}
}
static void opj_applyLUT8u_8u32s_C1P3R(
OPJ_UINT8 const* pSrc, OPJ_INT32 srcStride,
OPJ_INT32* const* pDst, OPJ_INT32 const* pDstStride,
OPJ_UINT8 const* const* pLUT,
OPJ_UINT32 width, OPJ_UINT32 height)
{
OPJ_UINT32 y;
OPJ_INT32* pR = pDst[0];
OPJ_INT32* pG = pDst[1];
OPJ_INT32* pB = pDst[2];
OPJ_UINT8 const* pLUT_R = pLUT[0];
OPJ_UINT8 const* pLUT_G = pLUT[1];
OPJ_UINT8 const* pLUT_B = pLUT[2];
for (y = height; y != 0U; --y) {
OPJ_UINT32 x;
for(x = 0; x < width; x++) {
OPJ_UINT8 idx = pSrc[x];
pR[x] = (OPJ_INT32)pLUT_R[idx];
pG[x] = (OPJ_INT32)pLUT_G[idx];
pB[x] = (OPJ_INT32)pLUT_B[idx];
}
pSrc += srcStride;
pR += pDstStride[0];
pG += pDstStride[1];
pB += pDstStride[2];
}
}
static void bmp24toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t* image)
{
int index;
OPJ_UINT32 width, height;
OPJ_UINT32 x, y;
const OPJ_UINT8 *pSrc = NULL;
width = image->comps[0].w;
height = image->comps[0].h;
index = 0;
pSrc = pData + (height - 1U) * stride;
for(y = 0; y < height; y++) {
for(x = 0; x < width; x++) {
image->comps[0].data[index] = (OPJ_INT32)pSrc[3*x+2]; /* R */
image->comps[1].data[index] = (OPJ_INT32)pSrc[3*x+1]; /* G */
image->comps[2].data[index] = (OPJ_INT32)pSrc[3*x+0]; /* B */
index++;
}
pSrc -= stride;
}
}
static void bmp_mask_get_shift_and_prec(OPJ_UINT32 mask, OPJ_UINT32* shift, OPJ_UINT32* prec)
{
OPJ_UINT32 l_shift, l_prec;
l_shift = l_prec = 0U;
if (mask != 0U) {
while ((mask & 1U) == 0U) {
mask >>= 1;
l_shift++;
}
while (mask & 1U) {
mask >>= 1;
l_prec++;
}
}
*shift = l_shift;
*prec = l_prec;
}
static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t* image, OPJ_UINT32 redMask, OPJ_UINT32 greenMask, OPJ_UINT32 blueMask, OPJ_UINT32 alphaMask)
{
int index;
OPJ_UINT32 width, height;
OPJ_UINT32 x, y;
const OPJ_UINT8 *pSrc = NULL;
OPJ_BOOL hasAlpha = OPJ_FALSE;
OPJ_UINT32 redShift, redPrec;
OPJ_UINT32 greenShift, greenPrec;
OPJ_UINT32 blueShift, bluePrec;
OPJ_UINT32 alphaShift, alphaPrec;
width = image->comps[0].w;
height = image->comps[0].h;
hasAlpha = image->numcomps > 3U;
bmp_mask_get_shift_and_prec(redMask, &redShift, &redPrec);
bmp_mask_get_shift_and_prec(greenMask, &greenShift, &greenPrec);
bmp_mask_get_shift_and_prec(blueMask, &blueShift, &bluePrec);
bmp_mask_get_shift_and_prec(alphaMask, &alphaShift, &alphaPrec);
image->comps[0].bpp = redPrec;
image->comps[0].prec = redPrec;
image->comps[1].bpp = greenPrec;
image->comps[1].prec = greenPrec;
image->comps[2].bpp = bluePrec;
image->comps[2].prec = bluePrec;
if (hasAlpha) {
image->comps[3].bpp = alphaPrec;
image->comps[3].prec = alphaPrec;
}
index = 0;
pSrc = pData + (height - 1U) * stride;
for(y = 0; y < height; y++) {
for(x = 0; x < width; x++) {
OPJ_UINT32 value = 0U;
value |= ((OPJ_UINT32)pSrc[4*x+0]) << 0;
value |= ((OPJ_UINT32)pSrc[4*x+1]) << 8;
value |= ((OPJ_UINT32)pSrc[4*x+2]) << 16;
value |= ((OPJ_UINT32)pSrc[4*x+3]) << 24;
image->comps[0].data[index] = (OPJ_INT32)((value & redMask) >> redShift); /* R */
image->comps[1].data[index] = (OPJ_INT32)((value & greenMask) >> greenShift); /* G */
image->comps[2].data[index] = (OPJ_INT32)((value & blueMask) >> blueShift); /* B */
if (hasAlpha) {
image->comps[3].data[index] = (OPJ_INT32)((value & alphaMask) >> alphaShift); /* A */
}
index++;
}
pSrc -= stride;
}
}
static void bmpmask16toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t* image, OPJ_UINT32 redMask, OPJ_UINT32 greenMask, OPJ_UINT32 blueMask, OPJ_UINT32 alphaMask)
{
int index;
OPJ_UINT32 width, height;
OPJ_UINT32 x, y;
const OPJ_UINT8 *pSrc = NULL;
OPJ_BOOL hasAlpha = OPJ_FALSE;
OPJ_UINT32 redShift, redPrec;
OPJ_UINT32 greenShift, greenPrec;
OPJ_UINT32 blueShift, bluePrec;
OPJ_UINT32 alphaShift, alphaPrec;
width = image->comps[0].w;
height = image->comps[0].h;
hasAlpha = image->numcomps > 3U;
bmp_mask_get_shift_and_prec(redMask, &redShift, &redPrec);
bmp_mask_get_shift_and_prec(greenMask, &greenShift, &greenPrec);
bmp_mask_get_shift_and_prec(blueMask, &blueShift, &bluePrec);
bmp_mask_get_shift_and_prec(alphaMask, &alphaShift, &alphaPrec);
image->comps[0].bpp = redPrec;
image->comps[0].prec = redPrec;
image->comps[1].bpp = greenPrec;
image->comps[1].prec = greenPrec;
image->comps[2].bpp = bluePrec;
image->comps[2].prec = bluePrec;
if (hasAlpha) {
image->comps[3].bpp = alphaPrec;
image->comps[3].prec = alphaPrec;
}
index = 0;
pSrc = pData + (height - 1U) * stride;
for(y = 0; y < height; y++) {
for(x = 0; x < width; x++) {
OPJ_UINT32 value = 0U;
value |= ((OPJ_UINT32)pSrc[2*x+0]) << 0;
value |= ((OPJ_UINT32)pSrc[2*x+1]) << 8;
image->comps[0].data[index] = (OPJ_INT32)((value & redMask) >> redShift); /* R */
image->comps[1].data[index] = (OPJ_INT32)((value & greenMask) >> greenShift); /* G */
image->comps[2].data[index] = (OPJ_INT32)((value & blueMask) >> blueShift); /* B */
if (hasAlpha) {
image->comps[3].data[index] = (OPJ_INT32)((value & alphaMask) >> alphaShift); /* A */
}
index++;
}
pSrc -= stride;
}
}
static opj_image_t* bmp8toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t* image, OPJ_UINT8 const* const* pLUT)
{
OPJ_UINT32 width, height;
const OPJ_UINT8 *pSrc = NULL;
width = image->comps[0].w;
height = image->comps[0].h;
pSrc = pData + (height - 1U) * stride;
if (image->numcomps == 1U) {
opj_applyLUT8u_8u32s_C1R(pSrc, -(OPJ_INT32)stride, image->comps[0].data, (OPJ_INT32)width, pLUT[0], width, height);
} else {
OPJ_INT32* pDst[3];
OPJ_INT32 pDstStride[3];
pDst[0] = image->comps[0].data;
pDst[1] = image->comps[1].data;
pDst[2] = image->comps[2].data;
pDstStride[0] = (OPJ_INT32)width;
pDstStride[1] = (OPJ_INT32)width;
pDstStride[2] = (OPJ_INT32)width;
opj_applyLUT8u_8u32s_C1P3R(pSrc, -(OPJ_INT32)stride, pDst, pDstStride, pLUT, width, height);
}
return image;
}
static OPJ_BOOL bmp_read_file_header(FILE* IN, OPJ_BITMAPFILEHEADER* header)
{
header->bfType = (OPJ_UINT16)getc(IN);
header->bfType |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8);
if (header->bfType != 19778) {
fprintf(stderr,"Error, not a BMP file!\n");
return OPJ_FALSE;
}
/* FILE HEADER */
/* ------------- */
header->bfSize = (OPJ_UINT32)getc(IN);
header->bfSize |= (OPJ_UINT32)getc(IN) << 8;
header->bfSize |= (OPJ_UINT32)getc(IN) << 16;
header->bfSize |= (OPJ_UINT32)getc(IN) << 24;
header->bfReserved1 = (OPJ_UINT16)getc(IN);
header->bfReserved1 |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8);
header->bfReserved2 = (OPJ_UINT16)getc(IN);
header->bfReserved2 |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8);
header->bfOffBits = (OPJ_UINT32)getc(IN);
header->bfOffBits |= (OPJ_UINT32)getc(IN) << 8;
header->bfOffBits |= (OPJ_UINT32)getc(IN) << 16;
header->bfOffBits |= (OPJ_UINT32)getc(IN) << 24;
return OPJ_TRUE;
}
static OPJ_BOOL bmp_read_info_header(FILE* IN, OPJ_BITMAPINFOHEADER* header)
{
memset(header, 0, sizeof(*header));
/* INFO HEADER */
/* ------------- */
header->biSize = (OPJ_UINT32)getc(IN);
header->biSize |= (OPJ_UINT32)getc(IN) << 8;
header->biSize |= (OPJ_UINT32)getc(IN) << 16;
header->biSize |= (OPJ_UINT32)getc(IN) << 24;
switch (header->biSize) {
case 12U: /* BITMAPCOREHEADER */
case 40U: /* BITMAPINFOHEADER */
case 52U: /* BITMAPV2INFOHEADER */
case 56U: /* BITMAPV3INFOHEADER */
case 108U: /* BITMAPV4HEADER */
case 124U: /* BITMAPV5HEADER */
break;
default:
fprintf(stderr,"Error, unknown BMP header size %d\n", header->biSize);
return OPJ_FALSE;
}
header->biWidth = (OPJ_UINT32)getc(IN);
header->biWidth |= (OPJ_UINT32)getc(IN) << 8;
header->biWidth |= (OPJ_UINT32)getc(IN) << 16;
header->biWidth |= (OPJ_UINT32)getc(IN) << 24;
header->biHeight = (OPJ_UINT32)getc(IN);
header->biHeight |= (OPJ_UINT32)getc(IN) << 8;
header->biHeight |= (OPJ_UINT32)getc(IN) << 16;
header->biHeight |= (OPJ_UINT32)getc(IN) << 24;
header->biPlanes = (OPJ_UINT16)getc(IN);
header->biPlanes |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8);
header->biBitCount = (OPJ_UINT16)getc(IN);
header->biBitCount |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8);
if(header->biSize >= 40U) {
header->biCompression = (OPJ_UINT32)getc(IN);
header->biCompression |= (OPJ_UINT32)getc(IN) << 8;
header->biCompression |= (OPJ_UINT32)getc(IN) << 16;
header->biCompression |= (OPJ_UINT32)getc(IN) << 24;
header->biSizeImage = (OPJ_UINT32)getc(IN);
header->biSizeImage |= (OPJ_UINT32)getc(IN) << 8;
header->biSizeImage |= (OPJ_UINT32)getc(IN) << 16;
header->biSizeImage |= (OPJ_UINT32)getc(IN) << 24;
header->biXpelsPerMeter = (OPJ_UINT32)getc(IN);
header->biXpelsPerMeter |= (OPJ_UINT32)getc(IN) << 8;
header->biXpelsPerMeter |= (OPJ_UINT32)getc(IN) << 16;
header->biXpelsPerMeter |= (OPJ_UINT32)getc(IN) << 24;
header->biYpelsPerMeter = (OPJ_UINT32)getc(IN);
header->biYpelsPerMeter |= (OPJ_UINT32)getc(IN) << 8;
header->biYpelsPerMeter |= (OPJ_UINT32)getc(IN) << 16;
header->biYpelsPerMeter |= (OPJ_UINT32)getc(IN) << 24;
header->biClrUsed = (OPJ_UINT32)getc(IN);
header->biClrUsed |= (OPJ_UINT32)getc(IN) << 8;
header->biClrUsed |= (OPJ_UINT32)getc(IN) << 16;
header->biClrUsed |= (OPJ_UINT32)getc(IN) << 24;
header->biClrImportant = (OPJ_UINT32)getc(IN);
header->biClrImportant |= (OPJ_UINT32)getc(IN) << 8;
header->biClrImportant |= (OPJ_UINT32)getc(IN) << 16;
header->biClrImportant |= (OPJ_UINT32)getc(IN) << 24;
}
if(header->biSize >= 56U) {
header->biRedMask = (OPJ_UINT32)getc(IN);
header->biRedMask |= (OPJ_UINT32)getc(IN) << 8;
header->biRedMask |= (OPJ_UINT32)getc(IN) << 16;
header->biRedMask |= (OPJ_UINT32)getc(IN) << 24;
header->biGreenMask = (OPJ_UINT32)getc(IN);
header->biGreenMask |= (OPJ_UINT32)getc(IN) << 8;
header->biGreenMask |= (OPJ_UINT32)getc(IN) << 16;
header->biGreenMask |= (OPJ_UINT32)getc(IN) << 24;
header->biBlueMask = (OPJ_UINT32)getc(IN);
header->biBlueMask |= (OPJ_UINT32)getc(IN) << 8;
header->biBlueMask |= (OPJ_UINT32)getc(IN) << 16;
header->biBlueMask |= (OPJ_UINT32)getc(IN) << 24;
header->biAlphaMask = (OPJ_UINT32)getc(IN);
header->biAlphaMask |= (OPJ_UINT32)getc(IN) << 8;
header->biAlphaMask |= (OPJ_UINT32)getc(IN) << 16;
header->biAlphaMask |= (OPJ_UINT32)getc(IN) << 24;
}
if(header->biSize >= 108U) {
header->biColorSpaceType = (OPJ_UINT32)getc(IN);
header->biColorSpaceType |= (OPJ_UINT32)getc(IN) << 8;
header->biColorSpaceType |= (OPJ_UINT32)getc(IN) << 16;
header->biColorSpaceType |= (OPJ_UINT32)getc(IN) << 24;
if (fread(&(header->biColorSpaceEP), 1U, sizeof(header->biColorSpaceEP), IN) != sizeof(header->biColorSpaceEP)) {
fprintf(stderr,"Error, can't read BMP header\n");
return OPJ_FALSE;
}
header->biRedGamma = (OPJ_UINT32)getc(IN);
header->biRedGamma |= (OPJ_UINT32)getc(IN) << 8;
header->biRedGamma |= (OPJ_UINT32)getc(IN) << 16;
header->biRedGamma |= (OPJ_UINT32)getc(IN) << 24;
header->biGreenGamma = (OPJ_UINT32)getc(IN);
header->biGreenGamma |= (OPJ_UINT32)getc(IN) << 8;
header->biGreenGamma |= (OPJ_UINT32)getc(IN) << 16;
header->biGreenGamma |= (OPJ_UINT32)getc(IN) << 24;
header->biBlueGamma = (OPJ_UINT32)getc(IN);
header->biBlueGamma |= (OPJ_UINT32)getc(IN) << 8;
header->biBlueGamma |= (OPJ_UINT32)getc(IN) << 16;
header->biBlueGamma |= (OPJ_UINT32)getc(IN) << 24;
}
if(header->biSize >= 124U) {
header->biIntent = (OPJ_UINT32)getc(IN);
header->biIntent |= (OPJ_UINT32)getc(IN) << 8;
header->biIntent |= (OPJ_UINT32)getc(IN) << 16;
header->biIntent |= (OPJ_UINT32)getc(IN) << 24;
header->biIccProfileData = (OPJ_UINT32)getc(IN);
header->biIccProfileData |= (OPJ_UINT32)getc(IN) << 8;
header->biIccProfileData |= (OPJ_UINT32)getc(IN) << 16;
header->biIccProfileData |= (OPJ_UINT32)getc(IN) << 24;
header->biIccProfileSize = (OPJ_UINT32)getc(IN);
header->biIccProfileSize |= (OPJ_UINT32)getc(IN) << 8;
header->biIccProfileSize |= (OPJ_UINT32)getc(IN) << 16;
header->biIccProfileSize |= (OPJ_UINT32)getc(IN) << 24;
header->biReserved = (OPJ_UINT32)getc(IN);
header->biReserved |= (OPJ_UINT32)getc(IN) << 8;
header->biReserved |= (OPJ_UINT32)getc(IN) << 16;
header->biReserved |= (OPJ_UINT32)getc(IN) << 24;
}
return OPJ_TRUE;
}
static OPJ_BOOL bmp_read_raw_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride, OPJ_UINT32 width, OPJ_UINT32 height)
{
OPJ_ARG_NOT_USED(width);
if ( fread(pData, sizeof(OPJ_UINT8), stride * height, IN) != (stride * height) ) {
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return OPJ_FALSE;
}
return OPJ_TRUE;
}
static OPJ_BOOL bmp_read_rle8_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride, OPJ_UINT32 width, OPJ_UINT32 height)
{
OPJ_UINT32 x, y;
OPJ_UINT8 *pix;
const OPJ_UINT8 *beyond;
beyond = pData + stride * height;
pix = pData;
x = y = 0U;
while (y < height) {
int c = getc(IN);
if (c) {
int j;
OPJ_UINT8 c1 = (OPJ_UINT8)getc(IN);
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
*pix = c1;
}
} else {
c = getc(IN);
if (c == 0x00) { /* EOL */
x = 0;
++y;
pix = pData + y * stride + x;
} else if (c == 0x01) { /* EOP */
break;
} else if (c == 0x02) { /* MOVE by dxdy */
c = getc(IN);
x += (OPJ_UINT32)c;
c = getc(IN);
y += (OPJ_UINT32)c;
pix = pData + y * stride + x;
} else { /* 03 .. 255 */
int j;
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
OPJ_UINT8 c1 = (OPJ_UINT8)getc(IN);
*pix = c1;
}
if ((OPJ_UINT32)c & 1U) { /* skip padding byte */
getc(IN);
}
}
}
}/* while() */
return OPJ_TRUE;
}
static OPJ_BOOL bmp_read_rle4_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride, OPJ_UINT32 width, OPJ_UINT32 height)
{
OPJ_UINT32 x, y;
OPJ_UINT8 *pix;
const OPJ_UINT8 *beyond;
beyond = pData + stride * height;
pix = pData;
x = y = 0U;
while(y < height) {
int c = getc(IN);
if(c == EOF) break;
if(c) {/* encoded mode */
int j;
OPJ_UINT8 c1 = (OPJ_UINT8)getc(IN);
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
*pix = (OPJ_UINT8)((j&1) ? (c1 & 0x0fU) : ((c1>>4)&0x0fU));
}
} else { /* absolute mode */
c = getc(IN);
if(c == EOF) break;
if(c == 0x00) { /* EOL */
x = 0;
y++;
pix = pData + y * stride;
} else if(c == 0x01) { /* EOP */
break;
} else if(c == 0x02) { /* MOVE by dxdy */
c = getc(IN);
x += (OPJ_UINT32)c;
c = getc(IN);
y += (OPJ_UINT32)c;
pix = pData + y * stride + x;
} else { /* 03 .. 255 : absolute mode */
int j;
OPJ_UINT8 c1 = 0U;
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
if((j&1) == 0) {
c1 = (OPJ_UINT8)getc(IN);
}
*pix = (OPJ_UINT8)((j&1) ? (c1 & 0x0fU) : ((c1>>4)&0x0fU));
}
if(((c&3) == 1) || ((c&3) == 2)) { /* skip padding byte */
getc(IN);
}
}
}
} /* while(y < height) */
return OPJ_TRUE;
}
opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
{
opj_image_cmptparm_t cmptparm[4]; /* maximum of 4 components */
OPJ_UINT8 lut_R[256], lut_G[256], lut_B[256];
OPJ_UINT8 const* pLUT[3];
opj_image_t * image = NULL;
FILE *IN;
OPJ_BITMAPFILEHEADER File_h;
OPJ_BITMAPINFOHEADER Info_h;
OPJ_UINT32 i, palette_len, numcmpts = 1U;
OPJ_BOOL l_result = OPJ_FALSE;
OPJ_UINT8* pData = NULL;
OPJ_UINT32 stride;
pLUT[0] = lut_R;
pLUT[1] = lut_G;
pLUT[2] = lut_B;
IN = fopen(filename, "rb");
if (!IN) {
fprintf(stderr, "Failed to open %s for reading !!\n", filename);
return NULL;
}
if (!bmp_read_file_header(IN, &File_h)) {
fclose(IN);
return NULL;
}
if (!bmp_read_info_header(IN, &Info_h)) {
fclose(IN);
return NULL;
}
/* Load palette */
if (Info_h.biBitCount <= 8U) {
memset(&lut_R[0], 0, sizeof(lut_R));
memset(&lut_G[0], 0, sizeof(lut_G));
memset(&lut_B[0], 0, sizeof(lut_B));
palette_len = Info_h.biClrUsed;
if((palette_len == 0U) && (Info_h.biBitCount <= 8U)) {
palette_len = (1U << Info_h.biBitCount);
}
if (palette_len > 256U) {
palette_len = 256U;
}
if (palette_len > 0U) {
OPJ_UINT8 has_color = 0U;
for (i = 0U; i < palette_len; i++) {
lut_B[i] = (OPJ_UINT8)getc(IN);
lut_G[i] = (OPJ_UINT8)getc(IN);
lut_R[i] = (OPJ_UINT8)getc(IN);
(void)getc(IN); /* padding */
has_color |= (lut_B[i] ^ lut_G[i]) | (lut_G[i] ^ lut_R[i]);
}
if(has_color) {
numcmpts = 3U;
}
}
} else {
numcmpts = 3U;
if ((Info_h.biCompression == 3) && (Info_h.biAlphaMask != 0U)) {
numcmpts++;
}
}
stride = ((Info_h.biWidth * Info_h.biBitCount + 31U) / 32U) * 4U; /* rows are aligned on 32bits */
if (Info_h.biBitCount == 4 && Info_h.biCompression == 2) { /* RLE 4 gets decoded as 8 bits data for now... */
stride = ((Info_h.biWidth * 8U + 31U) / 32U) * 4U;
}
pData = (OPJ_UINT8 *) calloc(1, stride * Info_h.biHeight * sizeof(OPJ_UINT8));
if (pData == NULL) {
fclose(IN);
return NULL;
}
/* Place the cursor at the beginning of the image information */
fseek(IN, 0, SEEK_SET);
fseek(IN, (long)File_h.bfOffBits, SEEK_SET);
switch (Info_h.biCompression) {
case 0:
case 3:
/* read raw data */
l_result = bmp_read_raw_data(IN, pData, stride, Info_h.biWidth, Info_h.biHeight);
break;
case 1:
/* read rle8 data */
l_result = bmp_read_rle8_data(IN, pData, stride, Info_h.biWidth, Info_h.biHeight);
break;
case 2:
/* read rle4 data */
l_result = bmp_read_rle4_data(IN, pData, stride, Info_h.biWidth, Info_h.biHeight);
break;
default:
fprintf(stderr, "Unsupported BMP compression\n");
l_result = OPJ_FALSE;
break;
}
if (!l_result) {
free(pData);
fclose(IN);
return NULL;
}
/* create the image */
memset(&cmptparm[0], 0, sizeof(cmptparm));
for(i = 0; i < 4U; i++) {
cmptparm[i].prec = 8;
cmptparm[i].bpp = 8;
cmptparm[i].sgnd = 0;
cmptparm[i].dx = (OPJ_UINT32)parameters->subsampling_dx;
cmptparm[i].dy = (OPJ_UINT32)parameters->subsampling_dy;
cmptparm[i].w = Info_h.biWidth;
cmptparm[i].h = Info_h.biHeight;
}
image = opj_image_create(numcmpts, &cmptparm[0], (numcmpts == 1U) ? OPJ_CLRSPC_GRAY : OPJ_CLRSPC_SRGB);
if(!image) {
fclose(IN);
free(pData);
return NULL;
}
if (numcmpts == 4U) {
image->comps[3].alpha = 1;
}
/* set image offset and reference grid */
image->x0 = (OPJ_UINT32)parameters->image_offset_x0;
image->y0 = (OPJ_UINT32)parameters->image_offset_y0;
image->x1 = image->x0 + (Info_h.biWidth - 1U) * (OPJ_UINT32)parameters->subsampling_dx + 1U;
image->y1 = image->y0 + (Info_h.biHeight - 1U) * (OPJ_UINT32)parameters->subsampling_dy + 1U;
/* Read the data */
if (Info_h.biBitCount == 24 && Info_h.biCompression == 0) { /*RGB */
bmp24toimage(pData, stride, image);
} else if (Info_h.biBitCount == 8 && Info_h.biCompression == 0) { /* RGB 8bpp Indexed */
bmp8toimage(pData, stride, image, pLUT);
} else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) { /*RLE8*/
bmp8toimage(pData, stride, image, pLUT);
} else if (Info_h.biBitCount == 4 && Info_h.biCompression == 2) { /*RLE4*/
bmp8toimage(pData, stride, image, pLUT); /* RLE 4 gets decoded as 8 bits data for now */
} else if (Info_h.biBitCount == 32 && Info_h.biCompression == 0) { /* RGBX */
bmpmask32toimage(pData, stride, image, 0x00FF0000U, 0x0000FF00U, 0x000000FFU, 0x00000000U);
} else if (Info_h.biBitCount == 32 && Info_h.biCompression == 3) { /* bitmask */
bmpmask32toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, Info_h.biBlueMask, Info_h.biAlphaMask);
} else if (Info_h.biBitCount == 16 && Info_h.biCompression == 0) { /* RGBX */
bmpmask16toimage(pData, stride, image, 0x7C00U, 0x03E0U, 0x001FU, 0x0000U);
} else if (Info_h.biBitCount == 16 && Info_h.biCompression == 3) { /* bitmask */
if ((Info_h.biRedMask == 0U) && (Info_h.biGreenMask == 0U) && (Info_h.biBlueMask == 0U)) {
Info_h.biRedMask = 0xF800U;
Info_h.biGreenMask = 0x07E0U;
Info_h.biBlueMask = 0x001FU;
}
bmpmask16toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, Info_h.biBlueMask, Info_h.biAlphaMask);
} else {
opj_image_destroy(image);
image = NULL;
fprintf(stderr, "Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n", Info_h.biBitCount);
}
free(pData);
fclose(IN);
return image;
}
int imagetobmp(opj_image_t * image, const char *outfile)
{
int w, h;
int i, pad;
FILE *fdest = NULL;
int adjustR, adjustG, adjustB;
if (image->comps[0].prec < 8) {
fprintf(stderr, "Unsupported number of components: %d\n", image->comps[0].prec);
return 1;
}
if (image->numcomps >= 3 && image->comps[0].dx == image->comps[1].dx
&& image->comps[1].dx == image->comps[2].dx
&& image->comps[0].dy == image->comps[1].dy
&& image->comps[1].dy == image->comps[2].dy
&& image->comps[0].prec == image->comps[1].prec
&& image->comps[1].prec == image->comps[2].prec) {
/* -->> -->> -->> -->>
24 bits color
<<-- <<-- <<-- <<-- */
fdest = fopen(outfile, "wb");
if (!fdest) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
return 1;
}
w = (int)image->comps[0].w;
h = (int)image->comps[0].h;
fprintf(fdest, "BM");
/* FILE HEADER */
/* ------------- */
fprintf(fdest, "%c%c%c%c",
(OPJ_UINT8) (h * w * 3 + 3 * h * (w % 2) + 54) & 0xff,
(OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 8) & 0xff,
(OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 16) & 0xff,
(OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (54) & 0xff, ((54) >> 8) & 0xff,((54) >> 16) & 0xff, ((54) >> 24) & 0xff);
/* INFO HEADER */
/* ------------- */
fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, ((40) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (OPJ_UINT8) ((w) & 0xff),
(OPJ_UINT8) ((w) >> 8) & 0xff,
(OPJ_UINT8) ((w) >> 16) & 0xff,
(OPJ_UINT8) ((w) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (OPJ_UINT8) ((h) & 0xff),
(OPJ_UINT8) ((h) >> 8) & 0xff,
(OPJ_UINT8) ((h) >> 16) & 0xff,
(OPJ_UINT8) ((h) >> 24) & 0xff);
fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff);
fprintf(fdest, "%c%c", (24) & 0xff, ((24) >> 8) & 0xff);
fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (OPJ_UINT8) (3 * h * w + 3 * h * (w % 2)) & 0xff,
(OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2)) >> 8) & 0xff,
(OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2)) >> 16) & 0xff,
(OPJ_UINT8) ((h * w * 3 + 3 * h * (w % 2)) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
if (image->comps[0].prec > 8) {
adjustR = (int)image->comps[0].prec - 8;
printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec);
} else
adjustR = 0;
if (image->comps[1].prec > 8) {
adjustG = (int)image->comps[1].prec - 8;
printf("BMP CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec);
} else
adjustG = 0;
if (image->comps[2].prec > 8) {
adjustB = (int)image->comps[2].prec - 8;
printf("BMP CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec);
} else
adjustB = 0;
for (i = 0; i < w * h; i++) {
OPJ_UINT8 rc, gc, bc;
int r, g, b;
r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
r = ((r >> adjustR)+((r >> (adjustR-1))%2));
if(r > 255) r = 255;
else if(r < 0) r = 0;
rc = (OPJ_UINT8)r;
g = image->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
g = ((g >> adjustG)+((g >> (adjustG-1))%2));
if(g > 255) g = 255;
else if(g < 0) g = 0;
gc = (OPJ_UINT8)g;
b = image->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
b = ((b >> adjustB)+((b >> (adjustB-1))%2));
if(b > 255) b = 255;
else if(b < 0) b = 0;
bc = (OPJ_UINT8)b;
fprintf(fdest, "%c%c%c", bc, gc, rc);
if ((i + 1) % w == 0) {
for (pad = (3 * w) % 4 ? 4 - (3 * w) % 4 : 0; pad > 0; pad--) /* ADD */
fprintf(fdest, "%c", 0);
}
}
fclose(fdest);
} else { /* Gray-scale */
/* -->> -->> -->> -->>
8 bits non code (Gray scale)
<<-- <<-- <<-- <<-- */
fdest = fopen(outfile, "wb");
if (!fdest) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
return 1;
}
w = (int)image->comps[0].w;
h = (int)image->comps[0].h;
fprintf(fdest, "BM");
/* FILE HEADER */
/* ------------- */
fprintf(fdest, "%c%c%c%c", (OPJ_UINT8) (h * w + 54 + 1024 + h * (w % 2)) & 0xff,
(OPJ_UINT8) ((h * w + 54 + 1024 + h * (w % 2)) >> 8) & 0xff,
(OPJ_UINT8) ((h * w + 54 + 1024 + h * (w % 2)) >> 16) & 0xff,
(OPJ_UINT8) ((h * w + 54 + 1024 + w * (w % 2)) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (54 + 1024) & 0xff, ((54 + 1024) >> 8) & 0xff,
((54 + 1024) >> 16) & 0xff,
((54 + 1024) >> 24) & 0xff);
/* INFO HEADER */
/* ------------- */
fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, ((40) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (OPJ_UINT8) ((w) & 0xff),
(OPJ_UINT8) ((w) >> 8) & 0xff,
(OPJ_UINT8) ((w) >> 16) & 0xff,
(OPJ_UINT8) ((w) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (OPJ_UINT8) ((h) & 0xff),
(OPJ_UINT8) ((h) >> 8) & 0xff,
(OPJ_UINT8) ((h) >> 16) & 0xff,
(OPJ_UINT8) ((h) >> 24) & 0xff);
fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff);
fprintf(fdest, "%c%c", (8) & 0xff, ((8) >> 8) & 0xff);
fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (OPJ_UINT8) (h * w + h * (w % 2)) & 0xff,
(OPJ_UINT8) ((h * w + h * (w % 2)) >> 8) & 0xff,
(OPJ_UINT8) ((h * w + h * (w % 2)) >> 16) & 0xff,
(OPJ_UINT8) ((h * w + h * (w % 2)) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff);
fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff);
if (image->comps[0].prec > 8) {
adjustR = (int)image->comps[0].prec - 8;
printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec);
} else
adjustR = 0;
for (i = 0; i < 256; i++) {
fprintf(fdest, "%c%c%c%c", i, i, i, 0);
}
for (i = 0; i < w * h; i++) {
int r;
r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
r = ((r >> adjustR)+((r >> (adjustR-1))%2));
if(r > 255) r = 255;
else if(r < 0) r = 0;
fprintf(fdest, "%c", (OPJ_UINT8)r);
if ((i + 1) % w == 0) {
for (pad = w % 4 ? 4 - w % 4 : 0; pad > 0; pad--) /* ADD */
fprintf(fdest, "%c", 0);
}
}
fclose(fdest);
}
return 0;
}

View File

@@ -1,477 +0,0 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* Copyright (c) 2015, Matthieu Darbois
* 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 "opj_apps_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <zlib.h>
#include <png.h>
#include "openjpeg.h"
#include "convert.h"
#define PNG_MAGIC "\x89PNG\x0d\x0a\x1a\x0a"
#define MAGIC_SIZE 8
/* PNG allows bits per sample: 1, 2, 4, 8, 16 */
static void convert_16u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_INT32 val0 = *pSrc++;
OPJ_INT32 val1 = *pSrc++;
pDst[i] = val0 << 8 | val1;
}
}
opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
{
png_structp png = NULL;
png_infop info = NULL;
double gamma;
int bit_depth, interlace_type,compression_type, filter_type;
OPJ_UINT32 i;
png_uint_32 width, height = 0U;
int color_type;
FILE *reader = NULL;
OPJ_BYTE** rows = NULL;
OPJ_INT32* row32s = NULL;
/* j2k: */
opj_image_t *image = NULL;
opj_image_cmptparm_t cmptparm[4];
OPJ_UINT32 nr_comp;
OPJ_BYTE sigbuf[8];
convert_XXx32s_C1R cvtXXTo32s = NULL;
convert_32s_CXPX cvtCxToPx = NULL;
OPJ_INT32* planes[4];
if((reader = fopen(read_idf, "rb")) == NULL) {
fprintf(stderr,"pngtoimage: can not open %s\n",read_idf);
return NULL;
}
if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) {
fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf);
goto fin;
}
if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL)) == NULL)
goto fin;
if((info = png_create_info_struct(png)) == NULL)
goto fin;
if(setjmp(png_jmpbuf(png)))
goto fin;
png_init_io(png, reader);
png_set_sig_bytes(png, MAGIC_SIZE);
png_read_info(png, info);
if(png_get_IHDR(png, info, &width, &height,
&bit_depth, &color_type, &interlace_type,
&compression_type, &filter_type) == 0)
goto fin;
/* png_set_expand():
* expand paletted images to RGB, expand grayscale images of
* less than 8-bit depth to 8-bit depth, and expand tRNS chunks
* to alpha channels.
*/
if(color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_expand(png);
}
if(png_get_valid(png, info, PNG_INFO_tRNS)) {
png_set_expand(png);
}
/* We might wan't to expand background */
/*
if(png_get_valid(png, info, PNG_INFO_bKGD)) {
png_color_16p bgnd;
png_get_bKGD(png, info, &bgnd);
png_set_background(png, bgnd, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
}
*/
if( !png_get_gAMA(png, info, &gamma))
gamma = 1.0;
/* we're not displaying but converting, screen gamma == 1.0 */
png_set_gamma(png, 1.0, gamma);
png_read_update_info(png, info);
color_type = png_get_color_type(png, info);
switch (color_type) {
case PNG_COLOR_TYPE_GRAY:
nr_comp = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
nr_comp = 2;
break;
case PNG_COLOR_TYPE_RGB:
nr_comp = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
nr_comp = 4;
break;
default:
fprintf(stderr,"pngtoimage: colortype %d is not supported\n", color_type);
goto fin;
}
cvtCxToPx = convert_32s_CXPX_LUT[nr_comp];
bit_depth = png_get_bit_depth(png, info);
switch (bit_depth) {
case 1:
case 2:
case 4:
case 8:
cvtXXTo32s = convert_XXu32s_C1R_LUT[bit_depth];
break;
case 16: /* 16 bpp is specific to PNG */
cvtXXTo32s = convert_16u32s_C1R;
break;
default:
fprintf(stderr,"pngtoimage: bit depth %d is not supported\n", bit_depth);
goto fin;
}
rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*));
for(i = 0; i < height; ++i)
rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info));
png_read_image(png, rows);
/* Create image */
memset(cmptparm, 0, sizeof(cmptparm));
for(i = 0; i < nr_comp; ++i) {
cmptparm[i].prec = (OPJ_UINT32)bit_depth;
/* bits_per_pixel: 8 or 16 */
cmptparm[i].bpp = (OPJ_UINT32)bit_depth;
cmptparm[i].sgnd = 0;
cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx;
cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy;
cmptparm[i].w = (OPJ_UINT32)width;
cmptparm[i].h = (OPJ_UINT32)height;
}
image = opj_image_create(nr_comp, &cmptparm[0], (nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY);
if(image == NULL) goto fin;
image->x0 = (OPJ_UINT32)params->image_offset_x0;
image->y0 = (OPJ_UINT32)params->image_offset_y0;
image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)params->subsampling_dx + 1 + image->x0);
image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)params->subsampling_dy + 1 + image->y0);
row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32));
if(row32s == NULL) goto fin;
/* Set alpha channel */
image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U);
for(i = 0; i < nr_comp; i++) {
planes[i] = image->comps[i].data;
}
for(i = 0; i < height; ++i) {
cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp);
cvtCxToPx(row32s, planes, width);
planes[0] += width;
planes[1] += width;
planes[2] += width;
planes[3] += width;
}
fin:
if(rows) {
for(i = 0; i < height; ++i)
free(rows[i]);
free(rows);
}
if (row32s) {
free(row32s);
}
if(png)
png_destroy_read_struct(&png, &info, NULL);
fclose(reader);
return image;
}/* pngtoimage() */
static void convert_32s16u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_UINT32 val = (OPJ_UINT32)pSrc[i];
*pDst++ = (OPJ_BYTE)(val >> 8);
*pDst++ = (OPJ_BYTE)val;
}
}
int imagetopng(opj_image_t * image, const char *write_idf)
{
FILE * volatile writer = NULL;
png_structp png = NULL;
png_infop info = NULL;
png_bytep volatile row_buf = NULL;
int nr_comp, color_type;
volatile int prec;
png_color_8 sig_bit;
OPJ_INT32 const* planes[4];
int i;
OPJ_INT32* volatile buffer32s = NULL;
volatile int fails = 1;
memset(&sig_bit, 0, sizeof(sig_bit));
prec = (int)image->comps[0].prec;
planes[0] = image->comps[0].data;
nr_comp = (int)image->numcomps;
if (nr_comp > 4) {
nr_comp = 4;
}
for (i = 1; i < nr_comp; ++i) {
if (image->comps[0].dx != image->comps[i].dx) {
break;
}
if (image->comps[0].dy != image->comps[i].dy) {
break;
}
if (image->comps[0].prec != image->comps[i].prec) {
break;
}
if (image->comps[0].sgnd != image->comps[i].sgnd) {
break;
}
planes[i] = image->comps[i].data;
}
if (i != nr_comp) {
fprintf(stderr,"imagetopng: All components shall have the same subsampling, same bit depth, same sign.\n");
fprintf(stderr,"\tAborting\n");
return 1;
}
for (i = 0; i < nr_comp; ++i) {
clip_component(&(image->comps[i]), image->comps[0].prec);
}
if(prec > 8 && prec < 16) {
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 16);
}
prec = 16;
} else if(prec < 8 && nr_comp > 1) { /* GRAY_ALPHA, RGB, RGB_ALPHA */
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 8);
}
prec = 8;
} else if((prec > 1) && (prec < 8) && ((prec == 6) || ((prec & 1)==1))) { /* GRAY with non native precision */
if ((prec == 5) || (prec == 6)) {
prec = 8;
} else {
prec++;
}
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), (OPJ_UINT32)prec);
}
}
if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) {
fprintf(stderr,"imagetopng: can not create %s\n\twrong bit_depth %d\n", write_idf, prec);
return fails;
}
writer = fopen(write_idf, "wb");
if(writer == NULL) return fails;
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also check that
* the library version is compatible with the one used at compile time,
* in case we are using dynamically linked libraries. REQUIRED.
*/
png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
/*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */
if(png == NULL) goto fin;
/* Allocate/initialize the image information data. REQUIRED
*/
info = png_create_info_struct(png);
if(info == NULL) goto fin;
/* Set error handling. REQUIRED if you are not supplying your own
* error handling functions in the png_create_write_struct() call.
*/
if(setjmp(png_jmpbuf(png))) goto fin;
/* I/O initialization functions is REQUIRED
*/
png_init_io(png, writer);
/* Set the image information here. Width and height are up to 2^31,
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
* PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE.
* REQUIRED
*
* ERRORS:
*
* color_type == PNG_COLOR_TYPE_PALETTE && bit_depth > 8
* color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8
* color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8
* color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8
*
*/
png_set_compression_level(png, Z_BEST_COMPRESSION);
if(nr_comp >= 3) { /* RGB(A) */
color_type = PNG_COLOR_TYPE_RGB;
sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec;
} else { /* GRAY(A) */
color_type = PNG_COLOR_TYPE_GRAY;
sig_bit.gray = (png_byte)prec;
}
if((nr_comp & 1) == 0) { /* ALPHA */
color_type |= PNG_COLOR_MASK_ALPHA;
sig_bit.alpha = (png_byte)prec;
}
png_set_IHDR(png, info, image->comps[0].w, image->comps[0].h, prec, color_type,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_sBIT(png, info, &sig_bit);
/* png_set_gamma(png, 2.2, 1./2.2); */
/* png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); */
png_write_info(png, info);
/* setup conversion */
{
OPJ_SIZE_T rowStride;
png_size_t png_row_size;
png_row_size = png_get_rowbytes(png, info);
rowStride = ((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * (OPJ_SIZE_T)prec + 7U) / 8U;
if (rowStride != (OPJ_SIZE_T)png_row_size) {
fprintf(stderr, "Invalid PNG row size\n");
goto fin;
}
row_buf = (png_bytep)malloc(png_row_size);
if (row_buf == NULL) {
fprintf(stderr, "Can't allocate memory for PNG row\n");
goto fin;
}
buffer32s = (OPJ_INT32*)malloc((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * sizeof(OPJ_INT32));
if (buffer32s == NULL) {
fprintf(stderr, "Can't allocate memory for interleaved 32s row\n");
goto fin;
}
}
/* convert */
{
OPJ_SIZE_T width= image->comps[0].w;
OPJ_UINT32 y;
convert_32s_PXCX cvtPxToCx = convert_32s_PXCX_LUT[nr_comp];
convert_32sXXx_C1R cvt32sToPack = NULL;
OPJ_INT32 adjust = image->comps[0].sgnd ? 1 << (prec - 1) : 0;
png_bytep row_buf_cpy = row_buf;
OPJ_INT32* buffer32s_cpy = buffer32s;
switch (prec) {
case 1:
case 2:
case 4:
case 8:
cvt32sToPack = convert_32sXXu_C1R_LUT[prec];
break;
case 16:
cvt32sToPack = convert_32s16u_C1R;
break;
default:
/* never here */
break;
}
for(y = 0; y < image->comps[0].h; ++y) {
cvtPxToCx(planes, buffer32s_cpy, width, adjust);
cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp);
png_write_row(png, row_buf_cpy);
planes[0] += width;
planes[1] += width;
planes[2] += width;
planes[3] += width;
}
}
png_write_end(png, info);
fails = 0;
fin:
if(png) {
png_destroy_write_struct(&png, &info);
}
if(row_buf) {
free(row_buf);
}
if(buffer32s) {
free(buffer32s);
}
fclose(writer);
if(fails) (void)remove(write_idf); /* ignore return value */
return fails;
}/* imagetopng() */

View File

@@ -1,629 +0,0 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* Copyright (c) 2015, Matthieu Darbois
* 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 "opj_apps_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifndef OPJ_HAVE_LIBTIFF
# error OPJ_HAVE_LIBTIFF_NOT_DEFINED
#endif /* OPJ_HAVE_LIBTIFF */
#include <tiffio.h>
#include "openjpeg.h"
#include "convert.h"
/* -->> -->> -->> -->>
TIFF IMAGE FORMAT
<<-- <<-- <<-- <<-- */
static void tif_32sto10u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i+=4U) {
OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0];
OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1];
OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2];
OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3];
*pDst++ = (OPJ_BYTE)(src0 >> 2);
*pDst++ = (OPJ_BYTE)(((src0 & 0x3U) << 6) | (src1 >> 4));
*pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 6));
*pDst++ = (OPJ_BYTE)(((src2 & 0x3FU) << 2) | (src3 >> 8));
*pDst++ = (OPJ_BYTE)(src3);
}
if (length & 3U) {
OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0];
OPJ_UINT32 src1 = 0U;
OPJ_UINT32 src2 = 0U;
length = length & 3U;
if (length > 1U) {
src1 = (OPJ_UINT32)pSrc[i+1];
if (length > 2U) {
src2 = (OPJ_UINT32)pSrc[i+2];
}
}
*pDst++ = (OPJ_BYTE)(src0 >> 2);
*pDst++ = (OPJ_BYTE)(((src0 & 0x3U) << 6) | (src1 >> 4));
if (length > 1U) {
*pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 6));
if (length > 2U) {
*pDst++ = (OPJ_BYTE)(((src2 & 0x3FU) << 2));
}
}
}
}
static void tif_32sto12u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < (length & ~(OPJ_SIZE_T)1U); i+=2U) {
OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0];
OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1];
*pDst++ = (OPJ_BYTE)(src0 >> 4);
*pDst++ = (OPJ_BYTE)(((src0 & 0xFU) << 4) | (src1 >> 8));
*pDst++ = (OPJ_BYTE)(src1);
}
if (length & 1U) {
OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0];
*pDst++ = (OPJ_BYTE)(src0 >> 4);
*pDst++ = (OPJ_BYTE)(((src0 & 0xFU) << 4));
}
}
static void tif_32sto14u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i+=4U) {
OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0];
OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1];
OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2];
OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3];
*pDst++ = (OPJ_BYTE)(src0 >> 6);
*pDst++ = (OPJ_BYTE)(((src0 & 0x3FU) << 2) | (src1 >> 12));
*pDst++ = (OPJ_BYTE)(src1 >> 4);
*pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 10));
*pDst++ = (OPJ_BYTE)(src2 >> 2);
*pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6) | (src3 >> 8));
*pDst++ = (OPJ_BYTE)(src3);
}
if (length & 3U) {
OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0];
OPJ_UINT32 src1 = 0U;
OPJ_UINT32 src2 = 0U;
length = length & 3U;
if (length > 1U) {
src1 = (OPJ_UINT32)pSrc[i+1];
if (length > 2U) {
src2 = (OPJ_UINT32)pSrc[i+2];
}
}
*pDst++ = (OPJ_BYTE)(src0 >> 6);
*pDst++ = (OPJ_BYTE)(((src0 & 0x3FU) << 2) | (src1 >> 12));
if (length > 1U) {
*pDst++ = (OPJ_BYTE)(src1 >> 4);
*pDst++ = (OPJ_BYTE)(((src1 & 0xFU) << 4) | (src2 >> 10));
if (length > 2U) {
*pDst++ = (OPJ_BYTE)(src2 >> 2);
*pDst++ = (OPJ_BYTE)(((src2 & 0x3U) << 6));
}
}
}
}
static void tif_32sto16u(const OPJ_INT32* pSrc, OPJ_UINT16* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < length; ++i) {
pDst[i] = (OPJ_UINT16)pSrc[i];
}
}
int imagetotif(opj_image_t * image, const char *outfile)
{
int width, height;
int bps,adjust, sgnd;
int tiPhoto;
TIFF *tif;
tdata_t buf;
tsize_t strip_size;
OPJ_UINT32 i, numcomps;
OPJ_SIZE_T rowStride;
OPJ_INT32* buffer32s = NULL;
OPJ_INT32 const* planes[4];
convert_32s_PXCX cvtPxToCx = NULL;
convert_32sXXx_C1R cvt32sToTif = NULL;
bps = (int)image->comps[0].prec;
planes[0] = image->comps[0].data;
numcomps = image->numcomps;
if (image->color_space == OPJ_CLRSPC_CMYK) {
if (numcomps < 4U) {
fprintf(stderr,"imagetotif: CMYK images shall be composed of at least 4 planes.\n");
fprintf(stderr,"\tAborting\n");
return 1;
}
tiPhoto = PHOTOMETRIC_SEPARATED;
if (numcomps > 4U) {
numcomps = 4U; /* Alpha not supported */
}
} else if (numcomps > 2U) {
tiPhoto = PHOTOMETRIC_RGB;
if (numcomps > 4U) {
numcomps = 4U;
}
} else {
tiPhoto = PHOTOMETRIC_MINISBLACK;
}
for (i = 1U; i < numcomps; ++i) {
if (image->comps[0].dx != image->comps[i].dx) {
break;
}
if (image->comps[0].dy != image->comps[i].dy) {
break;
}
if (image->comps[0].prec != image->comps[i].prec) {
break;
}
if (image->comps[0].sgnd != image->comps[i].sgnd) {
break;
}
planes[i] = image->comps[i].data;
}
if (i != numcomps) {
fprintf(stderr,"imagetotif: All components shall have the same subsampling, same bit depth.\n");
fprintf(stderr,"\tAborting\n");
return 1;
}
if((bps > 16) || ((bps != 1) && (bps & 1))) bps = 0;
if(bps == 0) {
fprintf(stderr,"imagetotif: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",bps);
fprintf(stderr,"\tAborting\n");
return 1;
}
tif = TIFFOpen(outfile, "wb");
if (!tif) {
fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile);
return 1;
}
for (i = 0U; i < numcomps; ++i) {
clip_component(&(image->comps[i]), image->comps[0].prec);
}
cvtPxToCx = convert_32s_PXCX_LUT[numcomps];
switch (bps) {
case 1:
case 2:
case 4:
case 6:
case 8:
cvt32sToTif = convert_32sXXu_C1R_LUT[bps];
break;
case 10:
cvt32sToTif = tif_32sto10u;
break;
case 12:
cvt32sToTif = tif_32sto12u;
break;
case 14:
cvt32sToTif = tif_32sto14u;
break;
case 16:
cvt32sToTif = (convert_32sXXx_C1R)tif_32sto16u;
break;
default:
/* never here */
break;
}
sgnd = (int)image->comps[0].sgnd;
adjust = sgnd ? 1 << (image->comps[0].prec - 1) : 0;
width = (int)image->comps[0].w;
height = (int)image->comps[0].h;
TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, numcomps);
TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps);
TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, tiPhoto);
TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
strip_size = TIFFStripSize(tif);
rowStride = ((OPJ_SIZE_T)width * numcomps * (OPJ_SIZE_T)bps + 7U) / 8U;
if (rowStride != (OPJ_SIZE_T)strip_size) {
fprintf(stderr, "Invalid TIFF strip size\n");
TIFFClose(tif);
return 1;
}
buf = _TIFFmalloc(strip_size);
if (buf == NULL) {
TIFFClose(tif);
return 1;
}
buffer32s = (OPJ_INT32 *)malloc((OPJ_SIZE_T)width * numcomps * sizeof(OPJ_INT32));
if (buffer32s == NULL) {
_TIFFfree(buf);
TIFFClose(tif);
return 1;
}
for (i = 0; i < image->comps[0].h; ++i) {
cvtPxToCx(planes, buffer32s, (OPJ_SIZE_T)width, adjust);
cvt32sToTif(buffer32s, (OPJ_BYTE *)buf, (OPJ_SIZE_T)width * numcomps);
(void)TIFFWriteEncodedStrip(tif, i, (void*)buf, strip_size);
planes[0] += width;
planes[1] += width;
planes[2] += width;
planes[3] += width;
}
_TIFFfree((void*)buf);
TIFFClose(tif);
free(buffer32s);
return 0;
}/* imagetotif() */
static void tif_10uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i+=4U) {
OPJ_UINT32 val0 = *pSrc++;
OPJ_UINT32 val1 = *pSrc++;
OPJ_UINT32 val2 = *pSrc++;
OPJ_UINT32 val3 = *pSrc++;
OPJ_UINT32 val4 = *pSrc++;
pDst[i+0] = (OPJ_INT32)((val0 << 2) | (val1 >> 6));
pDst[i+1] = (OPJ_INT32)(((val1 & 0x3FU) << 4) | (val2 >> 4));
pDst[i+2] = (OPJ_INT32)(((val2 & 0xFU) << 6) | (val3 >> 2));
pDst[i+3] = (OPJ_INT32)(((val3 & 0x3U) << 8) | val4);
}
if (length & 3U) {
OPJ_UINT32 val0 = *pSrc++;
OPJ_UINT32 val1 = *pSrc++;
length = length & 3U;
pDst[i+0] = (OPJ_INT32)((val0 << 2) | (val1 >> 6));
if (length > 1U) {
OPJ_UINT32 val2 = *pSrc++;
pDst[i+1] = (OPJ_INT32)(((val1 & 0x3FU) << 4) | (val2 >> 4));
if (length > 2U) {
OPJ_UINT32 val3 = *pSrc++;
pDst[i+2] = (OPJ_INT32)(((val2 & 0xFU) << 6) | (val3 >> 2));
}
}
}
}
static void tif_12uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < (length & ~(OPJ_SIZE_T)1U); i+=2U) {
OPJ_UINT32 val0 = *pSrc++;
OPJ_UINT32 val1 = *pSrc++;
OPJ_UINT32 val2 = *pSrc++;
pDst[i+0] = (OPJ_INT32)((val0 << 4) | (val1 >> 4));
pDst[i+1] = (OPJ_INT32)(((val1 & 0xFU) << 8) | val2);
}
if (length & 1U) {
OPJ_UINT32 val0 = *pSrc++;
OPJ_UINT32 val1 = *pSrc++;
pDst[i+0] = (OPJ_INT32)((val0 << 4) | (val1 >> 4));
}
}
static void tif_14uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < (length & ~(OPJ_SIZE_T)3U); i+=4U) {
OPJ_UINT32 val0 = *pSrc++;
OPJ_UINT32 val1 = *pSrc++;
OPJ_UINT32 val2 = *pSrc++;
OPJ_UINT32 val3 = *pSrc++;
OPJ_UINT32 val4 = *pSrc++;
OPJ_UINT32 val5 = *pSrc++;
OPJ_UINT32 val6 = *pSrc++;
pDst[i+0] = (OPJ_INT32)((val0 << 6) | (val1 >> 2));
pDst[i+1] = (OPJ_INT32)(((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4));
pDst[i+2] = (OPJ_INT32)(((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6));
pDst[i+3] = (OPJ_INT32)(((val5 & 0x3FU) << 8) | val6);
}
if (length & 3U) {
OPJ_UINT32 val0 = *pSrc++;
OPJ_UINT32 val1 = *pSrc++;
length = length & 3U;
pDst[i+0] = (OPJ_INT32)((val0 << 6) | (val1 >> 2));
if (length > 1U) {
OPJ_UINT32 val2 = *pSrc++;
OPJ_UINT32 val3 = *pSrc++;
pDst[i+1] = (OPJ_INT32)(((val1 & 0x3U) << 12) | (val2 << 4) | (val3 >> 4));
if (length > 2U) {
OPJ_UINT32 val4 = *pSrc++;
OPJ_UINT32 val5 = *pSrc++;
pDst[i+2] = (OPJ_INT32)(((val3 & 0xFU) << 10) | (val4 << 2) | (val5 >> 6));
}
}
}
}
/* seems that libtiff decodes this to machine endianness */
static void tif_16uto32s(const OPJ_UINT16* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
pDst[i] = pSrc[i];
}
}
/*
* libtiff/tif_getimage.c : 1,2,4,8,16 bitspersample accepted
* CINEMA : 12 bit precision
*/
opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
{
int subsampling_dx = parameters->subsampling_dx;
int subsampling_dy = parameters->subsampling_dy;
TIFF *tif;
tdata_t buf;
tstrip_t strip;
tsize_t strip_size;
int j, currentPlane, numcomps = 0, w, h;
OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_UNKNOWN;
opj_image_cmptparm_t cmptparm[4]; /* RGBA */
opj_image_t *image = NULL;
int has_alpha = 0;
unsigned short tiBps, tiPhoto, tiSf, tiSpp, tiPC;
unsigned int tiWidth, tiHeight;
OPJ_BOOL is_cinema = OPJ_IS_CINEMA(parameters->rsiz);
convert_XXx32s_C1R cvtTifTo32s = NULL;
convert_32s_CXPX cvtCxToPx = NULL;
OPJ_INT32* buffer32s = NULL;
OPJ_INT32* planes[4];
OPJ_SIZE_T rowStride;
tif = TIFFOpen(filename, "r");
if(!tif) {
fprintf(stderr, "tiftoimage:Failed to open %s for reading\n", filename);
return 0;
}
tiBps = tiPhoto = tiSf = tiSpp = tiPC = 0;
tiWidth = tiHeight = 0;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &tiWidth);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &tiHeight);
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &tiBps);
TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &tiSf);
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &tiSpp);
TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tiPhoto);
TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &tiPC);
w= (int)tiWidth;
h= (int)tiHeight;
if((tiBps > 16U) || ((tiBps != 1U) && (tiBps & 1U))) {
fprintf(stderr,"tiftoimage: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",tiBps);
fprintf(stderr,"\tAborting\n");
TIFFClose(tif);
return NULL;
}
if(tiPhoto != PHOTOMETRIC_MINISBLACK && tiPhoto != PHOTOMETRIC_RGB) {
fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A) and GRAY(A) has been implemented\n",(int) tiPhoto);
fprintf(stderr,"\tAborting\n");
TIFFClose(tif);
return NULL;
}
switch (tiBps) {
case 1:
case 2:
case 4:
case 6:
case 8:
cvtTifTo32s = convert_XXu32s_C1R_LUT[tiBps];
break;
/* others are specific to TIFF */
case 10:
cvtTifTo32s = tif_10uto32s;
break;
case 12:
cvtTifTo32s = tif_12uto32s;
break;
case 14:
cvtTifTo32s = tif_14uto32s;
break;
case 16:
cvtTifTo32s = (convert_XXx32s_C1R)tif_16uto32s;
break;
default:
/* never here */
break;
}
{/* From: tiff-4.0.x/libtiff/tif_getimage.c : */
uint16* sampleinfo;
uint16 extrasamples;
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
&extrasamples, &sampleinfo);
if(extrasamples >= 1) {
switch(sampleinfo[0]) {
case EXTRASAMPLE_UNSPECIFIED:
/* Workaround for some images without correct info about alpha channel
*/
if(tiSpp > 3)
has_alpha = 1;
break;
case EXTRASAMPLE_ASSOCALPHA: /* data pre-multiplied */
case EXTRASAMPLE_UNASSALPHA: /* data not pre-multiplied */
has_alpha = 1;
break;
}
} else /* extrasamples == 0 */
if(tiSpp == 4 || tiSpp == 2) has_alpha = 1;
}
/* initialize image components */
memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t));
if ((tiPhoto == PHOTOMETRIC_RGB) && (is_cinema) && (tiBps != 12U)) {
fprintf(stdout,"WARNING:\n"
"Input image bitdepth is %d bits\n"
"TIF conversion has automatically rescaled to 12-bits\n"
"to comply with cinema profiles.\n",
tiBps);
} else {
is_cinema = 0U;
}
if(tiPhoto == PHOTOMETRIC_RGB) { /* RGB(A) */
numcomps = 3 + has_alpha;
color_space = OPJ_CLRSPC_SRGB;
} else if (tiPhoto == PHOTOMETRIC_MINISBLACK) { /* GRAY(A) */
numcomps = 1 + has_alpha;
color_space = OPJ_CLRSPC_GRAY;
}
cvtCxToPx = convert_32s_CXPX_LUT[numcomps];
if (tiPC == PLANARCONFIG_SEPARATE) {
cvtCxToPx = convert_32s_CXPX_LUT[1]; /* override */
tiSpp = 1U; /* consider only one sample per plane */
}
for(j = 0; j < numcomps; j++) {
cmptparm[j].prec = tiBps;
cmptparm[j].bpp = tiBps;
cmptparm[j].dx = (OPJ_UINT32)subsampling_dx;
cmptparm[j].dy = (OPJ_UINT32)subsampling_dy;
cmptparm[j].w = (OPJ_UINT32)w;
cmptparm[j].h = (OPJ_UINT32)h;
}
image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space);
if(!image) {
TIFFClose(tif);
return NULL;
}
/* set image offset and reference grid */
image->x0 = (OPJ_UINT32)parameters->image_offset_x0;
image->y0 = (OPJ_UINT32)parameters->image_offset_y0;
image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 :
image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1;
image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 :
image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1;
for(j = 0; j < numcomps; j++) {
planes[j] = image->comps[j].data;
}
image->comps[numcomps - 1].alpha = (OPJ_UINT16)(1 - (numcomps & 1));
strip_size = TIFFStripSize(tif);
buf = _TIFFmalloc(strip_size);
if (buf == NULL) {
TIFFClose(tif);
opj_image_destroy(image);
return NULL;
}
rowStride = ((OPJ_SIZE_T)w * tiSpp * tiBps + 7U) / 8U;
buffer32s = (OPJ_INT32 *)malloc((OPJ_SIZE_T)w * tiSpp * sizeof(OPJ_INT32));
if (buffer32s == NULL) {
_TIFFfree(buf);
TIFFClose(tif);
opj_image_destroy(image);
return NULL;
}
strip = 0;
currentPlane = 0;
do {
planes[0] = image->comps[currentPlane].data; /* to manage planar data */
h= (int)tiHeight;
/* Read the Image components */
for(; (h > 0) && (strip < TIFFNumberOfStrips(tif)); strip++) {
const OPJ_UINT8 *dat8;
OPJ_SIZE_T ssize;
ssize = (OPJ_SIZE_T)TIFFReadEncodedStrip(tif, strip, buf, strip_size);
dat8 = (const OPJ_UINT8*)buf;
while (ssize >= rowStride) {
cvtTifTo32s(dat8, buffer32s, (OPJ_SIZE_T)w * tiSpp);
cvtCxToPx(buffer32s, planes, (OPJ_SIZE_T)w);
planes[0] += w;
planes[1] += w;
planes[2] += w;
planes[3] += w;
dat8 += rowStride;
ssize -= rowStride;
h--;
}
}
currentPlane++;
} while ((tiPC == PLANARCONFIG_SEPARATE) && (currentPlane < numcomps));
free(buffer32s);
_TIFFfree(buf);
TIFFClose(tif);
if (is_cinema) {
for (j=0; j < numcomps; ++j) {
scale_component(&(image->comps[j]), 12);
}
}
return image;
}/* tiftoimage() */

View File

@@ -46,8 +46,7 @@ Write a structured index to a file
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/
int write_index_file(opj_codestream_info_t *cstr_info, char *index)
{
int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL;
double total_disto = 0;

View File

@@ -57,9 +57,6 @@
#define strncasecmp _strnicmp
#else
#include <strings.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/times.h>
#endif /* _WIN32 */
#include "opj_apps_config.h"
@@ -69,7 +66,6 @@
#include "index.h"
#include "format_defs.h"
#include "opj_string.h"
typedef struct dircnt{
/** Buffer for holding images read from Directory*/
@@ -89,8 +85,7 @@ typedef struct img_folder {
char set_out_format;
}img_fol_t;
static void encode_help_display(void)
{
static void encode_help_display(void) {
fprintf(stdout,"\nThis is the opj_compress utility from the OpenJPEG project.\n"
"It compresses various image formats with the JPEG 2000 algorithm.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version());
@@ -354,8 +349,7 @@ static void encode_help_display(void)
#endif /*FIXME_INDEX*/
}
static OPJ_PROG_ORDER give_progression(const char progression[4])
{
static OPJ_PROG_ORDER give_progression(const char progression[4]) {
if(strncmp(progression, "LRCP", 4) == 0) {
return OPJ_LRCP;
}
@@ -375,8 +369,7 @@ static OPJ_PROG_ORDER give_progression(const char progression[4])
return OPJ_PROG_UNKNOWN;
}
static unsigned int get_num_images(char *imgdirpath)
{
static unsigned int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
unsigned int num_images = 0;
@@ -395,12 +388,10 @@ static unsigned int get_num_images(char *imgdirpath)
continue;
num_images++;
}
closedir(dir);
return num_images;
}
static int load_images(dircnt_t *dirptr, char *imgdirpath)
{
static int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
int i = 0;
@@ -422,12 +413,10 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath)
strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
return 0;
}
static int get_file_format(char *filename)
{
static int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc"
@@ -447,14 +436,12 @@ static int get_file_format(char *filename)
return -1;
}
static char * get_file_name(char *name)
{
static char * get_file_name(char *name){
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)
{
static 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]="";
@@ -464,9 +451,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
if (parameters->decod_format == -1)
return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) {
return 1;
}
strncpy(parameters->infile, infilename, sizeof(infilename));
/*Set output file*/
strcpy(temp_ofname,get_file_name(image_filename));
@@ -476,9 +461,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
}
if(img_fol->set_out_format==1){
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
return 1;
}
strncpy(parameters->outfile, outfilename, sizeof(outfilename));
}
return 0;
}
@@ -486,8 +469,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
/* ------------------------------------------------------------------------------------ */
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, size_t indexfilename_size)
{
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
OPJ_UINT32 i, j;
int totlen, c;
opj_option_t long_option[]={
@@ -520,7 +502,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if (c == -1)
break;
switch (c) {
case 'i': { /* input file */
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -540,15 +523,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
infile);
return 1;
}
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) {
return 1;
}
strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
}
break;
/* ----------------------------------------------------- */
case 'o': { /* output file */
case 'o': /* output file */
{
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -559,14 +541,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
fprintf(stderr, "Unknown output format image %s [only *.j2k, *.j2c or *.jp2]!! \n", outfile);
return 1;
}
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfile) != 0) {
return 1;
}
strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
}
break;
/* ----------------------------------------------------- */
case 'O': { /* output format */
case 'O': /* output format */
{
char outformat[50];
char *of = opj_optarg;
sprintf(outformat,".%s",of);
@@ -588,7 +569,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'r': { /* rates rates/distorsion */
case 'r': /* rates rates/distorsion */
{
char *s = opj_optarg;
parameters->tcp_numlayers = 0;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
@@ -607,7 +589,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'F': { /* Raw image format parameters */
case 'F': /* Raw image format parameters */
{
OPJ_BOOL wrong = OPJ_FALSE;
char *substr1;
char *substr2;
@@ -615,7 +598,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
char signo;
int width,height,bitdepth,ncomp;
OPJ_UINT32 len;
OPJ_BOOL raw_signed = OPJ_FALSE;
OPJ_BOOL raw_signed;
substr2 = strchr(opj_optarg,'@');
if (substr2 == NULL) {
len = (OPJ_UINT32) strlen(opj_optarg);
@@ -624,9 +607,6 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
substr2++; /* skip '@' character */
}
substr1 = (char*) malloc((len+1)*sizeof(char));
if (substr1 == NULL) {
return 1;
}
memcpy(substr1,opj_optarg,len);
substr1[len] = '\0';
if (sscanf(substr1, "%d,%d,%d,%d,%c", &width, &height, &ncomp, &bitdepth, &signo) == 5) {
@@ -641,7 +621,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
wrong = OPJ_TRUE;
}
if (!wrong) {
int compno;
int i;
int lastdx = 1;
int lastdy = 1;
raw_cp->rawWidth = width;
@@ -650,10 +630,10 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
raw_cp->rawBitDepth = bitdepth;
raw_cp->rawSigned = raw_signed;
raw_cp->rawComps = (raw_comp_cparameters_t*) malloc(((OPJ_UINT32)(ncomp))*sizeof(raw_comp_cparameters_t));
for (compno = 0; compno < ncomp && !wrong; compno++) {
for (i = 0; i < ncomp && !wrong; i++) {
if (substr2 == NULL) {
raw_cp->rawComps[compno].dx = lastdx;
raw_cp->rawComps[compno].dy = lastdy;
raw_cp->rawComps[i].dx = lastdx;
raw_cp->rawComps[i].dy = lastdy;
} else {
int dx,dy;
sep = strchr(substr2,':');
@@ -661,16 +641,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if (sscanf(substr2, "%dx%d", &dx, &dy) == 2) {
lastdx = dx;
lastdy = dy;
raw_cp->rawComps[compno].dx = dx;
raw_cp->rawComps[compno].dy = dy;
raw_cp->rawComps[i].dx = dx;
raw_cp->rawComps[i].dy = dy;
substr2 = NULL;
} else {
wrong = OPJ_TRUE;
}
} else {
if (sscanf(substr2, "%dx%d:%s", &dx, &dy, substr2) == 3) {
raw_cp->rawComps[compno].dx = dx;
raw_cp->rawComps[compno].dy = dy;
raw_cp->rawComps[i].dx = dx;
raw_cp->rawComps[i].dy = dy;
} else {
wrong = OPJ_TRUE;
}
@@ -678,7 +658,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
}
}
}
free(substr1);
if (substr1) free(substr1);
if (wrong) {
fprintf(stderr,"\nError: invalid raw image parameters\n");
fprintf(stderr,"Please use the Format option -F:\n");
@@ -694,7 +674,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'q': { /* add fixed_quality */
case 'q': /* add fixed_quality */
{
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
@@ -712,12 +693,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* dda */
/* ----------------------------------------------------- */
case 'f': { /* mod fixed_quality (before : -q) */
case 'f': /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL;
OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0;
char *s = opj_optarg;
sscanf(s, "%u", &numlayers);
sscanf(s, "%ud", &numlayers);
s++;
if (numlayers > 9)
s++;
@@ -758,7 +740,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 't': { /* tiles */
case 't': /* tiles */
{
sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
parameters->tile_size_on = OPJ_TRUE;
}
@@ -766,13 +749,15 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'n': { /* resolution */
case 'n': /* resolution */
{
sscanf(opj_optarg, "%d", &parameters->numresolution);
}
break;
/* ----------------------------------------------------- */
case 'c': { /* precinct dimension */
case 'c': /* precinct dimension */
{
char sep;
int res_spec = 0;
@@ -782,7 +767,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
sep = 0;
ret = sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],
&parameters->prch_init[res_spec], &sep);
if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') ) {
if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') )
{
fprintf(stderr,"\nError: could not parse precinct dimension: '%s' %x\n", s, sep);
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n");
return 1;
@@ -790,14 +776,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
} while (sep == ',');
}
while (sep == ',');
parameters->res_spec = res_spec;
}
break;
/* ----------------------------------------------------- */
case 'b': { /* code-block dimension */
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@@ -814,10 +802,10 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'x': { /* creation of index file */
if (opj_strcpy_s(indexfilename, indexfilename_size, opj_optarg) != 0) {
return 1;
}
case 'x': /* creation of index file */
{
char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
/* FIXME ADE INDEX >> */
fprintf(stderr,
"[WARNING] Index file generation is currently broken.\n"
@@ -828,7 +816,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'p': { /* progression order */
case 'p': /* progression order */
{
char progression[4];
strncpy(progression, opj_optarg, 4);
@@ -843,7 +832,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 's': { /* subsampling factor */
case 's': /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx,
&parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
@@ -854,7 +844,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'd': { /* coordonnate of the reference grid */
case 'd': /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0,
&parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@@ -872,14 +863,15 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'P': { /* POC */
case 'P': /* POC */
{
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;
POC = parameters->POC;
while (sscanf(s, "T%u=%u,%u,%u,%u,%u,%4s", &POC[numpocs].tile,
while (sscanf(s, "T%ud=%ud,%ud,%ud,%ud,%ud,%4s", &POC[numpocs].tile,
&POC[numpocs].resno0, &POC[numpocs].compno0,
&POC[numpocs].layno1, &POC[numpocs].resno1,
&POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
@@ -899,21 +891,24 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'S': { /* SOP marker */
case 'S': /* SOP marker */
{
parameters->csty |= 0x02;
}
break;
/* ------------------------------------------------------ */
case 'E': { /* EPH marker */
case 'E': /* EPH marker */
{
parameters->csty |= 0x04;
}
break;
/* ------------------------------------------------------ */
case 'M': { /* Mode switch pas tous au point !! */
case 'M': /* Mode switch pas tous au point !! */
{
int value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) {
@@ -927,7 +922,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'R': { /* ROI */
case 'R': /* ROI */
{
if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno,
&parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
@@ -938,7 +934,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'T': { /* Tile offset */
case 'T': /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
@@ -948,7 +945,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'C': { /* add a comment */
case 'C': /* add a comment */
{
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment) {
strcpy(parameters->cp_comment, opj_optarg);
@@ -959,14 +957,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'I': { /* reversible or not */
case 'I': /* reversible or not */
{
parameters->irreversible = 1;
}
break;
/* ------------------------------------------------------ */
case 'u': { /* Tile part generation*/
case 'u': /* Tile part generation*/
{
parameters->tp_flag = opj_optarg[0];
parameters->tp_on = 1;
}
@@ -974,7 +974,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'z': { /* Image Directory path */
case 'z': /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
@@ -983,7 +984,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'w': { /* Digital Cinema 2K profile compliance*/
case 'w': /* Digital Cinema 2K profile compliance*/
{
int fps=0;
sscanf(opj_optarg,"%d",&fps);
if(fps == 24){
@@ -1006,7 +1008,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'y': { /* Digital Cinema 4K profile compliance*/
case 'y': /* Digital Cinema 4K profile compliance*/
{
parameters->rsiz = OPJ_PROFILE_CINEMA_4K;
fprintf(stdout,"CINEMA 4K profile activated\n"
"Other options specified could be overriden\n");
@@ -1015,7 +1018,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'Y': { /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/
case 'Y': /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/
{
int mct_mode=0;
sscanf(opj_optarg,"%d",&mct_mode);
if(mct_mode < 0 || mct_mode > 2){
@@ -1029,7 +1033,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'm': { /* mct input file */
case 'm': /* mct input file */
{
char *lFilename = opj_optarg;
char *lMatrix;
char *lCurrentPtr ;
@@ -1050,16 +1055,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
lStrLen = (size_t)ftell(lFile);
fseek(lFile,0,SEEK_SET);
lMatrix = (char *) malloc(lStrLen + 1);
if (lMatrix == NULL) {
fclose(lFile);
return 1;
}
lStrFread = fread(lMatrix, 1, lStrLen, lFile);
fclose(lFile);
if( lStrLen != lStrFread ) {
free(lMatrix);
return 1;
}
if( lStrLen != lStrFread ) return 1;
lMatrix[lStrLen] = 0;
lCurrentPtr = lMatrix;
@@ -1079,10 +1077,6 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
lMctComp = lNbComp * lNbComp;
lTotalComp = lMctComp + lNbComp;
lSpace = (float *) malloc((size_t)lTotalComp * sizeof(float));
if(lSpace == NULL) {
free(lMatrix);
return 1;
}
lCurrentDoublePtr = lSpace;
for (i2=0;i2<lMctComp;++i2) {
lStrLen = strlen(lCurrentPtr) + 1;
@@ -1113,15 +1107,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
#ifdef USE_JPWL
/* ------------------------------------------------------ */
case 'W': { /* JPWL capabilities switched on */
case 'W': /* JPWL capabilities switched on */
{
char *token = NULL;
int hprot, pprot, sens, addr, size, range;
/* we need to enable indexing */
if (!indexfilename || !*indexfilename) {
if (opj_strcpy_s(indexfilename, indexfilename_size, JPWL_PRIVATEINDEX_NAME) != 0) {
return 1;
}
strncpy(indexfilename, JPWL_PRIVATEINDEX_NAME, OPJ_PATH_LEN);
}
/* search for different protection methods */
@@ -1431,7 +1424,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* <<UniPG */
/* ------------------------------------------------------ */
case 'J': { /* jpip on */
case 'J': /* jpip on */
{
parameters->jpip_on = OPJ_TRUE;
}
break;
@@ -1462,7 +1456,7 @@ 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, "[ERROR] Required parameters are missing\n"
"Example: %s -i image.pgm -o image.j2k\n",argv[0]);
"Example: %s -i image.j2k -o image.pgm\n",argv[0]);
fprintf(stderr, " Help: %s -h\n",argv[0]);
return 1;
}
@@ -1522,61 +1516,31 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/**
sample error debug callback expecting no client object
*/
static void error_callback(const char *msg, void *client_data)
{
static void error_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[ERROR] %s", msg);
}
/**
sample warning debug callback expecting no client object
*/
static void warning_callback(const char *msg, void *client_data)
{
static void warning_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[WARNING] %s", msg);
}
/**
sample debug callback expecting no client object
*/
static void info_callback(const char *msg, void *client_data)
{
static void info_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[INFO] %s", msg);
}
OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ;
return freq.QuadPart ? ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) : 0 ;
#else
/* Unix or Linux: use resource usage */
struct rusage t;
OPJ_FLOAT64 procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */
procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
/* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
#endif
}
/* -------------------------------------------------------------------------- */
/**
* OPJ_COMPRESS MAIN
*/
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
opj_cparameters_t parameters; /* compression parameters */
@@ -1584,7 +1548,6 @@ int main(int argc, char **argv)
opj_codec_t* l_codec = 00;
opj_image_t *image = NULL;
raw_cparameters_t raw_cp;
OPJ_SIZE_T num_compressed_files = 0;
char indexfilename[OPJ_PATH_LEN]; /* index file name */
@@ -1595,7 +1558,6 @@ int main(int argc, char **argv)
OPJ_BOOL bSuccess;
OPJ_BOOL bUseTiles = OPJ_FALSE; /* OPJ_TRUE */
OPJ_UINT32 l_nb_tiles = 4;
OPJ_FLOAT64 t = opj_clock();
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(&parameters);
@@ -1614,7 +1576,7 @@ int main(int argc, char **argv)
/* parse input and get user encoding parameters */
parameters.tcp_mct = (char) 255; /* This will be set later according to the input image or the provided option */
if(parse_cmdline_encoder(argc, argv, &parameters,&img_fol, &raw_cp, indexfilename, sizeof(indexfilename)) == 1) {
if(parse_cmdline_encoder(argc, argv, &parameters,&img_fol, &raw_cp, indexfilename) == 1) {
return 1;
}
@@ -1776,12 +1738,14 @@ int main(int argc, char **argv)
/* ---------------------------- */
switch(parameters.cod_format) {
case J2K_CFMT: { /* JPEG-2000 codestream */
case J2K_CFMT: /* JPEG-2000 codestream */
{
/* Get a decoder handle */
l_codec = opj_create_compress(OPJ_CODEC_J2K);
break;
}
case JP2_CFMT: { /* JPEG 2000 compressed image data */
case JP2_CFMT: /* JPEG 2000 compressed image data */
{
/* Get a decoder handle */
l_codec = opj_create_compress(OPJ_CODEC_JP2);
break;
@@ -1804,12 +1768,7 @@ int main(int argc, char **argv)
parameters.cp_tdx = 512;
parameters.cp_tdy = 512;
}
if (! opj_setup_encoder(l_codec, &parameters, image)) {
fprintf(stderr, "failed to encode image: opj_setup_encoder\n");
opj_destroy_codec(l_codec);
opj_image_destroy(image);
return 1;
}
opj_setup_encoder(l_codec, &parameters, image);
/* open a byte stream for writing and allocate memory for all tiles */
l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE);
@@ -1837,7 +1796,8 @@ int main(int argc, char **argv)
}
}
free(l_data);
} else {
}
else {
bSuccess = bSuccess && opj_encode(l_codec, l_stream);
if (!bSuccess) {
fprintf(stderr, "failed to encode image: opj_encode\n");
@@ -1857,7 +1817,6 @@ int main(int argc, char **argv)
return 1;
}
num_compressed_files++;
fprintf(stdout,"[INFO] Generated outfile %s\n",parameters.outfile);
/* close and free the byte stream */
opj_stream_destroy(l_stream);
@@ -1875,10 +1834,5 @@ int main(int argc, char **argv)
if(parameters.cp_matrice) free(parameters.cp_matrice);
if(raw_cp.rawComps) free(raw_cp.rawComps);
t = opj_clock() - t;
if (num_compressed_files) {
fprintf(stdout, "encode time: %d ms \n", (int)((t * 1000.0)/(OPJ_FLOAT64)num_compressed_files));
}
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -57,7 +57,6 @@
#include "index.h"
#include "format_defs.h"
#include "opj_string.h"
typedef struct dircnt{
/** Buffer for holding images read from Directory*/
@@ -91,8 +90,7 @@ static int infile_format(const char *fname);
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol);
/* -------------------------------------------------------------------------- */
static void decode_help_display(void)
{
static void decode_help_display(void) {
fprintf(stdout,"\nThis is the opj_dump utility from the OpenJPEG project.\n"
"It dumps JPEG 2000 codestream info to stdout or a given file.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version());
@@ -118,8 +116,7 @@ static void decode_help_display(void)
}
/* -------------------------------------------------------------------------- */
static int get_num_images(char *imgdirpath)
{
static int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
int num_images = 0;
@@ -137,13 +134,11 @@ static int get_num_images(char *imgdirpath)
continue;
num_images++;
}
closedir(dir);
return num_images;
}
/* -------------------------------------------------------------------------- */
static int load_images(dircnt_t *dirptr, char *imgdirpath)
{
static int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
int i = 0;
@@ -165,17 +160,15 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath)
strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
return 0;
}
/* -------------------------------------------------------------------------- */
static int get_file_format(const char *filename)
{
static int get_file_format(const 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 };
const char *ext = strrchr(filename, '.');
char * ext = strrchr(filename, '.');
if (ext == NULL)
return -1;
ext++;
@@ -191,8 +184,7 @@ static int get_file_format(const char *filename)
}
/* -------------------------------------------------------------------------- */
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters)
{
static 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]="";
@@ -202,9 +194,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_d
if (parameters->decod_format == -1)
return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) {
return 1;
}
strncpy(parameters->infile, infilename, sizeof(infilename));
/*Set output file*/
strcpy(temp_ofname,strtok(image_filename,"."));
@@ -214,9 +204,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_d
}
if(img_fol->set_out_format==1){
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
return 1;
}
strncpy(parameters->outfile, outfilename, sizeof(outfilename));
}
return 0;
}
@@ -256,10 +244,12 @@ static int infile_format(const char *fname)
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) {
}
else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
magic_format = J2K_CFMT;
magic_s = ".j2k or .jpc or .j2c";
} else
}
else
return -1;
if (magic_format == ext_format)
@@ -279,8 +269,7 @@ static int infile_format(const char *fname)
* Parse the command line
*/
/* -------------------------------------------------------------------------- */
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol)
{
static 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[]={
{"ImgDir",REQ_ARG, NULL ,'y'}
@@ -294,7 +283,8 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
if (c == -1)
break;
switch (c) {
case 'i': { /* input file */
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = infile_format(infile);
switch(parameters->decod_format) {
@@ -311,20 +301,16 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
infile);
return 1;
}
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n");
return 1;
}
strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
}
break;
/* ------------------------------------------------------ */
case 'o': { /* output file */
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), opj_optarg) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n");
return 1;
}
case 'o': /* output file */
{
char *outfile = opj_optarg;
strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
}
break;
@@ -340,7 +326,8 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ------------------------------------------------------ */
case 'y': { /* Image Directory path */
case 'y': /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
@@ -349,7 +336,8 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ----------------------------------------------------- */
case 'v': { /* Verbose mode */
case 'v': /* Verbose mode */
{
parameters->m_verbose = 1;
}
break;
@@ -394,24 +382,21 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/**
sample error debug callback expecting no client object
*/
static void error_callback(const char *msg, void *client_data)
{
static void error_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[ERROR] %s", msg);
}
/**
sample warning debug callback expecting no client object
*/
static void warning_callback(const char *msg, void *client_data)
{
static void warning_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[WARNING] %s", msg);
}
/**
sample debug callback expecting no client object
*/
static void info_callback(const char *msg, void *client_data)
{
static void info_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[INFO] %s", msg);
}
@@ -491,7 +476,8 @@ int main(int argc, char *argv[])
fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile);
return EXIT_FAILURE;
}
} else
}
else
fout = stdout;
/* Read the header of each image one by one */
@@ -519,17 +505,20 @@ int main(int argc, char *argv[])
/* ------------------------ */
switch(parameters.decod_format) {
case J2K_CFMT: { /* JPEG-2000 codestream */
case J2K_CFMT: /* JPEG-2000 codestream */
{
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_J2K);
break;
}
case JP2_CFMT: { /* JPEG 2000 compressed image data */
case JP2_CFMT: /* JPEG 2000 compressed image data */
{
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JP2);
break;
}
case JPT_CFMT: { /* JPEG 2000, JPIP */
case JPT_CFMT: /* JPEG 2000, JPIP */
{
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JPT);
break;

View File

@@ -243,7 +243,7 @@
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data.
* as a pointer refering the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
@@ -365,7 +365,8 @@ static DIR *opendir(const char *dirname)
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
strcpy (p++, "\\");
}
# ifdef DIRENT_WIN32_INTERFACE
@@ -410,7 +411,7 @@ static DIR *opendir(const char *dirname)
* capacity of d_name with different macros and some systems do not define
* capacity at all (besides actual declaration of the field). If you really
* need to find out storage capacity of d_name then you might want to try
* NAME_MAX macro. The NAME_MAX is defined in POSIX standard although
* NAME_MAX macro. The NAME_MAX is defined in POSIX standard althought
* there are many MS-DOS and MS-Windows implementations those do not define
* it. There are also systems that declare d_name as "char d_name[1]" and
* then allocate suitable amount of memory at run-time. Thanks to Alain
@@ -465,7 +466,7 @@ readdir (DIR *dirp)
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
/* Last file has been processed or an error occured */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
@@ -618,7 +619,8 @@ _initdir (DIR *dirp)
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) {
&dirp->current.data) != 0)
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
@@ -654,8 +656,7 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
static void
_setdirname (struct DIR *dirp)
{
_setdirname (struct DIR *dirp) {
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);

View File

@@ -45,8 +45,7 @@
void dump_volume(FILE *fd, opj_volume_t * vol)
{
void dump_volume(FILE *fd, opj_volume_t * vol) {
int compno;
fprintf(fd, "volume {\n");
fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", vol->x0, vol->y0, vol->z0,vol->x1, vol->y1, vol->z1);
@@ -67,8 +66,7 @@ void dump_volume(FILE *fd, opj_volume_t * vol)
*
* log2(a)
*/
static int int_floorlog2(int a)
{
static int int_floorlog2(int a) {
int l;
for (l = 0; a > 1; l++) {
a >>= 1;
@@ -81,8 +79,7 @@ static int int_floorlog2(int a)
*
* a divided by 2^b
*/
static int int_ceildivpow2(int a, int b)
{
static int int_ceildivpow2(int a, int b) {
return (a + (1 << b) - 1) >> b;
}
@@ -91,8 +88,7 @@ static int int_ceildivpow2(int a, int b)
*
* a divided by b
*/
static int int_ceildiv(int a, int b)
{
static int int_ceildiv(int a, int b) {
return (a + b - 1) / b;
}
@@ -154,8 +150,7 @@ static unsigned int LongSwap (unsigned int i)
}
/*****************************************/
opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
{
opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
FILE *f = NULL;
int w, h, prec;
@@ -201,8 +196,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
/*Fetch only the path */
strcpy(tmpdirpath,relpath);
if ((tmp = strrchr(tmpdirpath,'/')) != NULL){
tmp++;
*tmp='\0';
tmp++; *tmp='\0';
strcpy(dirpath,tmpdirpath);
} else {
strcpy(dirpath,"./");
@@ -228,7 +222,8 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
}
/*Read all .pgx files of directory */
while ( (direntp = readdir( dirp )) != NULL ) {
while ( (direntp = readdir( dirp )) != NULL )
{
/* Found a directory, but ignore . and .. */
if(strcmp(".",direntp->d_name) == 0 || strcmp("..",direntp->d_name) == 0)
continue;
@@ -246,8 +241,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
tmpno[i++] = *tmp2;
point = tmp2;
tmp2 = strpbrk (tmp2+1,"0123456789");
}
tmpno[i]='\0';
}tmpno[i]='\0';
/*Comprobamos que no estamos leyendo algo raro como pattern.jp3d*/
if ((point = strpbrk (point,".")) == NULL){
@@ -276,7 +270,8 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
return NULL;
}*/
for (s=0; s<sliceno; s++) {
for (s=0;s<sliceno;s++)
{
int pos = maxslice == sliceno ? s: pgxslicepos[s];
f = fopen(pgxfiles[pos], "rb");
if (!f) {
@@ -384,8 +379,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
}
int volumetopgx(opj_volume_t * volume, char *outfile)
{
int volumetopgx(opj_volume_t * volume, char *outfile) {
int w, wr, wrr, h, hr, hrr, l, lr, lrr;
int i, j, compno, offset, sliceno;
FILE *fdest = NULL;
@@ -472,8 +466,7 @@ BIN IMAGE FORMAT
<<-- <<-- <<-- <<-- */
opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *parameters)
{
opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *parameters) {
int subsampling_dx = parameters->subsampling_dx;
int subsampling_dy = parameters->subsampling_dy;
int subsampling_dz = parameters->subsampling_dz;
@@ -685,8 +678,7 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
return volume;
}
int volumetobin(opj_volume_t * volume, char *outfile)
{
int volumetobin(opj_volume_t * volume, char *outfile) {
int w, wr, wrr, h, hr, hrr, l, lr, lrr, max;
int i,j, compno, nbytes;
int offset, sliceno;
@@ -772,8 +764,7 @@ int volumetobin(opj_volume_t * volume, char *outfile)
IMG IMAGE FORMAT
<<-- <<-- <<-- <<-- */
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters)
{
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
int subsampling_dx = parameters->subsampling_dx;
int subsampling_dy = parameters->subsampling_dy;
int subsampling_dz = parameters->subsampling_dz;
@@ -804,8 +795,7 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters)
/*Fetch only the path */
strcpy(tmpdirpath,fileimg);
if ((tmp = strrchr(tmpdirpath,'/')) != NULL){
tmp++;
*tmp='\0';
tmp++; *tmp='\0';
strcpy(dirpath,tmpdirpath);
} else {
strcpy(dirpath,"./");

View File

@@ -55,8 +55,7 @@ char *optarg; /* argument associated with option */
* getopt --
* Parse argc/argv argument vector.
*/
int getopt(int nargc, char *const *nargv, const char *ostr)
{
int getopt(int nargc, char *const *nargv, const char *ostr) {
# define __progname nargv[0] /* program name */

View File

@@ -46,8 +46,7 @@
/* ----------------------------------------------------------------------- */
void encode_help_display()
{
void encode_help_display() {
fprintf(stdout,"List of parameters for the JPEG2000 Part 10 encoder:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"\n");
@@ -167,8 +166,7 @@ void encode_help_display()
}
OPJ_PROG_ORDER give_progression(char progression[4])
{
OPJ_PROG_ORDER give_progression(char progression[4]) {
if(strncmp(progression, "LRCP", 4) == 0) {
return LRCP;
}
@@ -188,8 +186,7 @@ OPJ_PROG_ORDER give_progression(char progression[4])
return PROG_UNKNOWN;
}
OPJ_TRANSFORM give_transform(char transform[4])
{
OPJ_TRANSFORM give_transform(char transform[4]) {
if(strncmp(transform, "2DWT", 4) == 0) {
return TRF_2D_DWT;
}
@@ -199,8 +196,7 @@ OPJ_TRANSFORM give_transform(char transform[4])
return TRF_UNKNOWN;
}
OPJ_ENTROPY_CODING give_coding(char coding[3])
{
OPJ_ENTROPY_CODING give_coding(char coding[3]) {
if(strncmp(coding, "2EB", 3) == 0) {
return ENCOD_2EB;
@@ -218,8 +214,7 @@ OPJ_ENTROPY_CODING give_coding(char coding[3])
return ENCOD_UNKNOWN;
}
int get_file_format(char *filename)
{
int get_file_format(char *filename) {
int i;
static const char *extension[] = {"pgx", "bin", "img", "j3d", "jp3d", "j2k"};
static const int format[] = { PGX_DFMT, BIN_DFMT, IMG_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT};
@@ -238,8 +233,7 @@ int get_file_format(char *filename)
/* ------------------------------------------------------------------------------------ */
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
{
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) {
int i, value;
/* parse the command line */
@@ -249,7 +243,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
if (c == -1)
break;
switch (c) {
case 'i': { /* input file */
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -269,7 +264,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
break;
/* ----------------------------------------------------- */
case 'm': { /* input IMG file */
case 'm': /* input IMG file */
{
char *imgfile = opj_optarg;
int imgformat = get_file_format(imgfile);
switch(imgformat) {
@@ -286,7 +282,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
break;
/* ----------------------------------------------------- */
case 'o': { /* output file */
case 'o': /* output file */
{
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -306,7 +303,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'r': { /* define compression rates for each layer */
case 'r': /* define compression rates for each layer */
{
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
@@ -323,7 +321,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'q': { /* define distorsion (PSNR) for each layer */
case 'q': /* define distorsion (PSNR) for each layer */
{
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
@@ -340,7 +339,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'f': {
case 'f':
{
fprintf(stdout, "/---------------------------------------------------\\\n");
fprintf(stdout, "| Fixed layer allocation option not implemented !! |\n");
fprintf(stdout, "\\---------------------------------------------------/\n");
@@ -388,7 +388,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 't': { /* tiles */
case 't': /* tiles */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tdx, &parameters->cp_tdy, &parameters->cp_tdz) !=3) {
fprintf(stdout, "[ERROR] '-t' 'dimensions of tiles' argument error ! [-t tdx,tdy,tdz]\n");
return 1;
@@ -399,7 +400,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'n': { /* resolution */
case 'n': /* resolution */
{
int aux;
aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->numresolution[0], &parameters->numresolution[1], &parameters->numresolution[2]);
if (aux == 2)
@@ -416,7 +418,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
break;
/* ----------------------------------------------------- */
case 'c': { /* precinct dimension */
case 'c': /* precinct dimension */
{
char sep;
int res_spec = 0;
int aux;
@@ -431,14 +434,16 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
} while (sep == ',');
}
while (sep == ',');
parameters->res_spec = res_spec; /* number of precinct size specifications */
}
break;
/* ----------------------------------------------------- */
case 'b': { /* code-block dimension */
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0, cblockl_init = 0;
if (sscanf(opj_optarg, "%d,%d,%d", &cblockw_init, &cblockh_init, &cblockl_init) != 3) {
fprintf(stdout, "[ERROR] '-b' 'dimensions of codeblocks' argument error ! [-b cblkx,cblky,cblkz]\n");
@@ -456,7 +461,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'x': { /* creation of index file */
case 'x': /* creation of index file */
{
char *index = opj_optarg;
strncpy(parameters->index, index, MAX_PATH);
parameters->index_on = 1;
@@ -465,7 +471,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'p': { /* progression order */
case 'p': /* progression order */
{
char progression[4];
strncpy(progression, opj_optarg, 4);
@@ -479,7 +486,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 's': { /* subsampling factor */
case 's': /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->subsampling_dx, &parameters->subsampling_dy, &parameters->subsampling_dz) != 3) {
fprintf(stdout, "[ERROR] '-s' sub-sampling argument error ! [-s dx,dy,dz]\n");
return 1;
@@ -489,7 +497,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'd': { /* coordonnate of the reference grid */
case 'd': /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->volume_offset_x0, &parameters->volume_offset_y0, &parameters->volume_offset_z0) != 3) {
fprintf(stdout, "[ERROR] -d 'coordonnate of the reference grid' argument error !! [-d x0,y0,z0]\n");
return 1;
@@ -499,7 +508,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'h': { /* display an help description */
case 'h': /* display an help description */
{
encode_help_display();
return 1;
}
@@ -507,7 +517,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */
case 'P': { /* POC */
case 'P': /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@@ -539,21 +550,24 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'S': { /* SOP marker */
case 'S': /* SOP marker */
{
parameters->csty |= 0x02;
}
break;
/* ------------------------------------------------------ */
case 'E': { /* EPH marker */
case 'E': /* EPH marker */
{
parameters->csty |= 0x04;
}
break;
/* ------------------------------------------------------ */
case 'M': { /* Codification mode switch */
case 'M': /* Codification mode switch */
{
fprintf(stdout, "[INFO] Mode switch option not fully tested !!\n");
value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) {
@@ -568,7 +582,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'D': { /* DCO */
case 'D': /* DCO */
{
if (sscanf(opj_optarg, "%d", &parameters->dcoffset) != 1) {
fprintf(stdout, "[ERROR] DC offset error !! [-D %d]\n",parameters->dcoffset);
return 1;
@@ -578,7 +593,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'R': { /* ROI */
case 'R': /* ROI */
{
if (sscanf(opj_optarg, "OI:c=%d,U=%d", &parameters->roi_compno, &parameters->roi_shift) != 2) {
fprintf(stdout, "[ERROR] ROI error !! [-ROI:c='compno',U='shift']\n");
return 1;
@@ -588,7 +604,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'l': { /* Tile offset */
case 'l': /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tx0, &parameters->cp_ty0, &parameters->cp_tz0) != 3) {
fprintf(stdout, "[ERROR] -l 'tile offset' argument error !! [-l X0,Y0,Z0]");
return 1;
@@ -613,7 +630,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
------------------------------------------------------ */
case 'C': { /* Coding of transformed data */
case 'C': /* Coding of transformed data */
{
char coding[3];
strncpy(coding, opj_optarg, 3);
@@ -627,7 +645,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */
case 'I': { /* reversible or not */
case 'I': /* reversible or not */
{
parameters->irreversible = 1;
}
break;
@@ -735,32 +754,28 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/**
sample error callback expecting a FILE* client object
*/
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
*/
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
*/
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);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
bool bSuccess;
bool delete_comment = true;
opj_cparameters_t parameters; /* compression parameters */

View File

@@ -149,8 +149,7 @@ static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded)
return sum;
}
void decode_help_display()
{
void decode_help_display() {
fprintf(stdout,"HELP\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@@ -196,8 +195,7 @@ void decode_help_display()
/* -------------------------------------------------------------------------- */
int get_file_format(char *filename)
{
int get_file_format(char *filename) {
int i;
static const char *extension[] = {"pgx", "bin", "j3d", "jp3d", "j2k", "img"};
static const int format[] = { PGX_DFMT, BIN_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT, IMG_DFMT};
@@ -216,8 +214,7 @@ int get_file_format(char *filename)
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
{
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters) {
/* parse the command line */
while (1) {
@@ -225,7 +222,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
if (c == -1)
break;
switch (c) {
case 'i': { /* input file */
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -243,7 +241,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
}
break;
case 'm': { /* img file */
case 'm': /* img file */
{
char *imgfile = opj_optarg;
int imgformat = get_file_format(imgfile);
switch(imgformat) {
@@ -261,7 +260,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */
case 'o': { /* output file */
case 'o': /* output file */
{
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -281,7 +281,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */
case 'O': { /* Original image for PSNR computing */
case 'O': /* Original image for PSNR computing */
{
char *original = opj_optarg;
parameters->orig_format = get_file_format(original);
switch(parameters->orig_format) {
@@ -300,7 +301,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */
case 'r': { /* reduce option */
case 'r': /* reduce option */
{
/*sscanf(opj_optarg, "%d, %d, %d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);*/
int aux;
aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);
@@ -319,28 +321,32 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */
case 'l': { /* layering option */
case 'l': /* layering option */
{
sscanf(opj_optarg, "%d", &parameters->cp_layer);
}
break;
/* ----------------------------------------------------- */
case 'B': { /* BIGENDIAN vs. LITTLEENDIAN */
case 'B': /* BIGENDIAN vs. LITTLEENDIAN */
{
parameters->bigendian = 1;
}
break;
/* ----------------------------------------------------- */
case 'L': { /* BIGENDIAN vs. LITTLEENDIAN */
case 'L': /* BIGENDIAN vs. LITTLEENDIAN */
{
parameters->decod_format = LSE_CFMT;
}
break;
/* ----------------------------------------------------- */
case 'h': { /* display an help description */
case 'h': /* display an help description */
{
decode_help_display();
return 1;
}
@@ -369,31 +375,27 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/**
sample error callback expecting a FILE* client object
*/
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
*/
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 no client object
*/
void info_callback(const char *msg, void *client_data)
{
void info_callback(const char *msg, void *client_data) {
fprintf(stdout, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */
@@ -497,12 +499,8 @@ int main(int argc, char **argv)
case PGX_DFMT: /* PGX */
if (strcmp("NULL",parameters.original) != 0){
fprintf(stdout,"Loading original file %s \n",parameters.original);
cparameters.subsampling_dx = 1;
cparameters.subsampling_dy = 1;
cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;
cparameters.volume_offset_y0 = 0;
cparameters.volume_offset_z0 = 0;
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0;
original = pgxtovolume(parameters.original,&cparameters);
}
break;
@@ -510,12 +508,8 @@ int main(int argc, char **argv)
case BIN_DFMT: /* BMP */
if (strcmp("NULL",parameters.original) != 0 && strcmp("NULL",parameters.imgfile) != 0){
fprintf(stdout,"Loading original file %s %s\n",parameters.original,parameters.imgfile);
cparameters.subsampling_dx = 1;
cparameters.subsampling_dy = 1;
cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;
cparameters.volume_offset_y0 = 0;
cparameters.volume_offset_z0 = 0;
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0;
original = bintovolume(parameters.original,parameters.imgfile,&cparameters);
}
break;

View File

@@ -242,7 +242,7 @@
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data.
* as a pointer refering the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
@@ -364,7 +364,8 @@ static DIR *opendir(const char *dirname)
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
strcpy (p++, "\\");
}
# ifdef DIRENT_WIN32_INTERFACE
@@ -409,7 +410,7 @@ static DIR *opendir(const char *dirname)
* capacity of d_name with different macros and some systems do not define
* capacity at all (besides actual declaration of the field). If you really
* need to find out storage capacity of d_name then you might want to try
* NAME_MAX macro. The NAME_MAX is defined in POSIX standard although
* NAME_MAX macro. The NAME_MAX is defined in POSIX standard althought
* there are many MS-DOS and MS-Windows implementations those do not define
* it. There are also systems that declare d_name as "char d_name[1]" and
* then allocate suitable amount of memory at run-time. Thanks to Alain
@@ -464,7 +465,7 @@ readdir (DIR *dirp)
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
/* Last file has been processed or an error occured */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
@@ -617,7 +618,8 @@ _initdir (DIR *dirp)
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) {
&dirp->current.data) != 0)
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
@@ -653,8 +655,7 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
static void
_setdirname (struct DIR *dirp)
{
_setdirname (struct DIR *dirp) {
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);

View File

@@ -54,8 +54,7 @@
WSADATA initialisation_win32;
#endif
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]){
dec_server_record_t *server_record;
client_t client;

View File

@@ -106,12 +106,15 @@ int main(int argc,char *argv[])
}
ext = strrchr( argv[2], '.' );
if( ext ) {
if( ext )
{
/* strcasecmp ? */
if( strcmp(ext, ".jp2" ) == 0 ) {
if( strcmp(ext, ".jp2" ) == 0 )
{
return jpip_to_jp2(argv);
}
if( strcmp(ext, ".j2k" ) == 0 ) {
if( strcmp(ext, ".j2k" ) == 0 )
{
return jpip_to_j2k(argv);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -45,8 +45,7 @@ Write a structured index to a file
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/
int write_index_file(opj_codestream_info_t *cstr_info, char *index)
{
int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL;
double total_disto = 0;

View File

@@ -88,8 +88,7 @@ typedef struct img_folder {
float *rates;
}img_fol_t;
static void encode_help_display(void)
{
static void encode_help_display(void) {
fprintf(stdout,"HELP for opj_jpwl_compress\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@@ -200,7 +199,7 @@ 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 : divide packets of every tile into tile-parts (-TP R) [R, L, C]\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");
@@ -328,8 +327,7 @@ static void encode_help_display(void)
fprintf(stdout,"TotalDisto\n\n");
}
static OPJ_PROG_ORDER give_progression(const char progression[4])
{
static OPJ_PROG_ORDER give_progression(const char progression[4]) {
if(strncmp(progression, "LRCP", 4) == 0) {
return LRCP;
}
@@ -349,8 +347,7 @@ static OPJ_PROG_ORDER give_progression(const char progression[4])
return PROG_UNKNOWN;
}
static unsigned int get_num_images(char *imgdirpath)
{
static unsigned int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
unsigned int num_images = 0;
@@ -372,8 +369,7 @@ static unsigned int get_num_images(char *imgdirpath)
return num_images;
}
static int load_images(dircnt_t *dirptr, char *imgdirpath)
{
static int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
int i = 0;
@@ -398,8 +394,7 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath)
return 0;
}
static int get_file_format(char *filename)
{
static 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"
@@ -419,16 +414,14 @@ static int get_file_format(char *filename)
return -1;
}
static char * get_file_name(char *name)
{
static 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)
{
static 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]="";
@@ -453,8 +446,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
return 0;
}
static int initialise_4K_poc(opj_poc_t *POC, int numres)
{
static int initialise_4K_poc(opj_poc_t *POC, int numres){
POC[0].tile = 1;
POC[0].resno0 = 0;
POC[0].compno0 = 0;
@@ -472,8 +464,7 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres)
return 2;
}
static void cinema_parameters(opj_cparameters_t *parameters)
{
static void cinema_parameters(opj_cparameters_t *parameters){
parameters->tile_size_on = OPJ_FALSE;
parameters->cp_tdx=1;
parameters->cp_tdy=1;
@@ -499,16 +490,14 @@ static void cinema_parameters(opj_cparameters_t *parameters)
/* No ROI */
parameters->roi_compno = -1;
parameters->subsampling_dx = 1;
parameters->subsampling_dy = 1;
parameters->subsampling_dx = 1; parameters->subsampling_dy = 1;
/* 9-7 transform */
parameters->irreversible = 1;
}
static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol)
{
static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){
int i;
float temp_rate;
@@ -594,8 +583,7 @@ 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,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename)
{
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
int i, j, totlen, c;
opj_option_t long_option[]={
{"cinema2K",REQ_ARG, NULL ,'w'},
@@ -626,7 +614,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if (c == -1)
break;
switch (c) {
case 'i': { /* input file */
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -651,7 +640,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'o': { /* output file */
case 'o': /* output file */
{
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -667,7 +657,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
break;
/* ----------------------------------------------------- */
case 'O': { /* output format */
case 'O': /* output format */
{
char outformat[50];
char *of = opj_optarg;
sprintf(outformat,".%s",of);
@@ -689,7 +680,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'r': { /* rates rates/distorsion */
case 'r': /* rates rates/distorsion */
{
char *s = opj_optarg;
parameters->tcp_numlayers = 0;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
@@ -708,24 +700,28 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'F': { /* Raw image format parameters */
case 'F': /* Raw image format parameters */
{
char signo;
char *s = opj_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;
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') {
}
else if (signo == 'u') {
raw_cp->rawSigned = OPJ_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 {
}
else {
fprintf(stderr,"\nError: invalid raw image parameters: Unknown sign of raw file\n");
fprintf(stderr,"Please use the Format option -F:\n");
fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
fprintf(stderr,"Aborting\n");
}
} else {
}
else {
fprintf(stderr,"\nError: invalid raw image parameters\n");
fprintf(stderr,"Please use the Format option -F:\n");
fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
@@ -738,7 +734,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'q': { /* add fixed_quality */
case 'q': /* add fixed_quality */
{
char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++;
@@ -756,7 +753,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* dda */
/* ----------------------------------------------------- */
case 'f': { /* mod fixed_quality (before : -q) */
case 'f': /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
@@ -802,7 +800,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 't': { /* tiles */
case 't': /* tiles */
{
sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
parameters->tile_size_on = OPJ_TRUE;
}
@@ -810,13 +809,15 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'n': { /* resolution */
case 'n': /* resolution */
{
sscanf(opj_optarg, "%d", &parameters->numresolution);
}
break;
/* ----------------------------------------------------- */
case 'c': { /* precinct dimension */
case 'c': /* precinct dimension */
{
char sep;
int res_spec = 0;
@@ -828,14 +829,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
} while (sep == ',');
}
while (sep == ',');
parameters->res_spec = res_spec;
}
break;
/* ----------------------------------------------------- */
case 'b': { /* code-block dimension */
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@@ -852,7 +855,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'x': { /* creation of index file */
case 'x': /* creation of index file */
{
char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
}
@@ -860,7 +864,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'p': { /* progression order */
case 'p': /* progression order */
{
char progression[4];
strncpy(progression, opj_optarg, 4);
@@ -875,7 +880,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 's': { /* subsampling factor */
case 's': /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx,
&parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
@@ -886,7 +892,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'd': { /* coordonnate of the reference grid */
case 'd': /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0,
&parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@@ -904,7 +911,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */
case 'P': { /* POC */
case 'P': /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@@ -931,21 +939,24 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'S': { /* SOP marker */
case 'S': /* SOP marker */
{
parameters->csty |= 0x02;
}
break;
/* ------------------------------------------------------ */
case 'E': { /* EPH marker */
case 'E': /* EPH marker */
{
parameters->csty |= 0x04;
}
break;
/* ------------------------------------------------------ */
case 'M': { /* Mode switch pas tous au point !! */
case 'M': /* Mode switch pas tous au point !! */
{
int value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) {
@@ -959,7 +970,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'R': { /* ROI */
case 'R': /* ROI */
{
if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno,
&parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
@@ -970,7 +982,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'T': { /* Tile offset */
case 'T': /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
@@ -980,7 +993,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'C': { /* add a comment */
case 'C': /* add a comment */
{
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment) {
strcpy(parameters->cp_comment, opj_optarg);
@@ -991,14 +1005,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'I': { /* reversible or not */
case 'I': /* reversible or not */
{
parameters->irreversible = 1;
}
break;
/* ------------------------------------------------------ */
case 'u': { /* Tile part generation*/
case 'u': /* Tile part generation*/
{
parameters->tp_flag = opj_optarg[0];
parameters->tp_on = 1;
}
@@ -1006,7 +1022,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'z': { /* Image Directory path */
case 'z': /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
@@ -1015,7 +1032,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'w': { /* Digital Cinema 2K profile compliance*/
case 'w': /* Digital Cinema 2K profile compliance*/
{
int fps=0;
sscanf(opj_optarg,"%d",&fps);
if(fps == 24){
@@ -1034,7 +1052,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */
case 'y': { /* Digital Cinema 4K profile compliance*/
case 'y': /* Digital Cinema 4K profile compliance*/
{
parameters->cp_cinema = CINEMA4K_24;
fprintf(stdout,"CINEMA 4K compliant codestream\n");
parameters->cp_rsiz = CINEMA4K;
@@ -1047,7 +1066,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
#ifdef USE_JPWL
/* ------------------------------------------------------ */
case 'W': { /* JPWL capabilities switched on */
case 'W': /* JPWL capabilities switched on */
{
char *token = NULL;
int hprot, pprot, sens, addr, size, range;
@@ -1363,7 +1383,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* <<UniPG */
/* ------------------------------------------------------ */
case 'J': { /* jpip on */
case 'J': /* jpip on */
{
/*parameters->jpip_on = OPJ_TRUE;*/
}
break;
@@ -1451,32 +1472,28 @@ 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)
{
static 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)
{
static 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)
{
static void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
opj_bool bSuccess;
opj_cparameters_t parameters; /* compression parameters */
img_fol_t img_fol;
@@ -1653,7 +1670,8 @@ int main(int argc, char **argv)
/* Can happen if input file is TIFF or PNG
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/
if( !image) {
if( !image)
{
fprintf(stderr, "Unable to load file: got no image\n");
return 1;
}

View File

@@ -91,8 +91,7 @@ typedef struct img_folder {
}img_fol_t;
void decode_help_display(void)
{
void decode_help_display(void) {
fprintf(stdout,"HELP for j2k_to_image\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@@ -151,8 +150,7 @@ void decode_help_display(void)
/* -------------------------------------------------------------------------- */
int get_num_images(char *imgdirpath)
{
int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
int num_images = 0;
@@ -173,8 +171,7 @@ int get_num_images(char *imgdirpath)
return num_images;
}
int load_images(dircnt_t *dirptr, char *imgdirpath)
{
int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
int i = 0;
@@ -199,8 +196,7 @@ int load_images(dircnt_t *dirptr, char *imgdirpath)
return 0;
}
int get_file_format(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 };
@@ -219,8 +215,7 @@ int get_file_format(char *filename)
return -1;
}
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters)
{
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]="";
@@ -246,8 +241,7 @@ 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)
{
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[]={
@@ -270,7 +264,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
if (c == -1)
break;
switch (c) {
case 'i': { /* input file */
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
@@ -290,7 +285,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
case 'o': { /* output file */
case 'o': /* output file */
{
char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
@@ -312,7 +308,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
case 'O': { /* output format */
case 'O': /* output format */
{
char outformat[50];
char *of = opj_optarg;
sprintf(outformat,".%s",of);
@@ -351,7 +348,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
case 'r': { /* reduce option */
case 'r': /* reduce option */
{
sscanf(opj_optarg, "%d", &parameters->cp_reduce);
}
break;
@@ -359,7 +357,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */
case 'l': { /* layering option */
case 'l': /* layering option */
{
sscanf(opj_optarg, "%d", &parameters->cp_layer);
}
break;
@@ -372,14 +371,16 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ------------------------------------------------------ */
case 'y': { /* Image Directory path */
case 'y': /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
/* ----------------------------------------------------- */
case 'x': { /* Creation of index file */
case 'x': /* Creation of index file */
{
char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN);
}
@@ -388,7 +389,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* UniPG>> */
#ifdef USE_JPWL
case 'W': { /* activate JPWL correction */
case 'W': /* activate JPWL correction */
{
char *token = NULL;
token = strtok(opj_optarg, ",");
@@ -494,32 +496,28 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/**
sample error callback expecting a FILE* client object
*/
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
*/
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 no client object
*/
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);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
opj_dparameters_t parameters; /* decompression parameters */
img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */
@@ -603,7 +601,8 @@ int main(int argc, char **argv)
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 (fread(src, 1, file_length, fsrc) != (size_t)file_length)
{
free(src);
fclose(fsrc);
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
@@ -615,7 +614,8 @@ int main(int argc, char **argv)
/* ---------------------- */
switch(parameters.decod_format) {
case J2K_CFMT: {
case J2K_CFMT:
{
/* JPEG-2000 codestream */
/* get a decoder handle */
@@ -657,7 +657,8 @@ int main(int argc, char **argv)
}
break;
case JP2_CFMT: {
case JP2_CFMT:
{
/* JPEG 2000 compressed image data */
/* get a decoder handle */
@@ -699,7 +700,8 @@ int main(int argc, char **argv)
}
break;
case JPT_CFMT: {
case JPT_CFMT:
{
/* JPEG 2000, JPIP */
/* get a decoder handle */
@@ -750,18 +752,19 @@ int main(int argc, char **argv)
free(src);
src = NULL;
if(image->color_space == CLRSPC_SYCC) {
if(image->color_space == CLRSPC_SYCC)
{
color_sycc_to_rgb(image);
}
if(image->icc_profile_buf) {
if(image->icc_profile_buf)
{
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(image);
#endif
free(image->icc_profile_buf);
image->icc_profile_buf = NULL;
image->icc_profile_len = 0;
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
}
/* create output image */
@@ -770,7 +773,8 @@ 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);
} else {
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -778,7 +782,8 @@ int main(int argc, char **argv)
case PGX_DFMT: /* PGX */
if(imagetopgx(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} else {
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -786,7 +791,8 @@ int main(int argc, char **argv)
case BMP_DFMT: /* BMP */
if(imagetobmp(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} else {
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -794,7 +800,8 @@ int main(int argc, char **argv)
case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} else {
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
@@ -802,7 +809,8 @@ int main(int argc, char **argv)
case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)){
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
} else {
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
@@ -810,7 +818,8 @@ int main(int argc, char **argv)
case TGA_DFMT: /* TGA */
if(imagetotga(image, parameters.outfile)){
fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
} else {
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
@@ -818,7 +827,8 @@ int main(int argc, char **argv)
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)){
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
} else {
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;

View File

@@ -243,7 +243,7 @@
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data.
* as a pointer refering the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
@@ -365,7 +365,8 @@ static DIR *opendir(const char *dirname)
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
strcpy (p++, "\\");
}
# ifdef DIRENT_WIN32_INTERFACE
@@ -410,7 +411,7 @@ static DIR *opendir(const char *dirname)
* capacity of d_name with different macros and some systems do not define
* capacity at all (besides actual declaration of the field). If you really
* need to find out storage capacity of d_name then you might want to try
* NAME_MAX macro. The NAME_MAX is defined in POSIX standard although
* NAME_MAX macro. The NAME_MAX is defined in POSIX standard althought
* there are many MS-DOS and MS-Windows implementations those do not define
* it. There are also systems that declare d_name as "char d_name[1]" and
* then allocate suitable amount of memory at run-time. Thanks to Alain
@@ -465,7 +466,7 @@ readdir (DIR *dirp)
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
/* Last file has been processed or an error occured */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
@@ -618,7 +619,8 @@ _initdir (DIR *dirp)
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) {
&dirp->current.data) != 0)
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
@@ -654,8 +656,7 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
static void
_setdirname (struct DIR *dirp)
{
_setdirname (struct DIR *dirp) {
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);

View File

@@ -89,10 +89,10 @@ void xml_write_init(BOOL n, BOOL t, BOOL r, BOOL d)
derived = d;
}
int xml_write_struct(FILE* file, FILE *xmlout, opj_mj2_t * movie, unsigned int sampleframe, char* stringDTD, opj_event_mgr_t *event_mgr)
{
int xml_write_struct(FILE* file, FILE *xmlout, opj_mj2_t * movie, unsigned int sampleframe, char* stringDTD, opj_event_mgr_t *event_mgr) {
if(stringDTD != NULL) {
if(stringDTD != NULL)
{
fprintf(xmlout,"<?xml version=\"1.0\" standalone=\"no\"?>\n");
/* stringDTD is known to start with "SYSTEM " or "PUBLIC " */
/* typical: SYSTEM mj2_to_metadata.dtd */
@@ -123,7 +123,8 @@ int xml_write_overall_header(FILE *file, FILE *xmlout, opj_mj2_t * movie, unsign
fprintf(xmlout, " <Brand>%s</Brand>\n", buf); /* 4 character; BR */
fprintf(xmlout, " <MinorVersion>%u</MinorVersion>\n", movie->minversion); /* 4 char; MinV */
fprintf(xmlout, " <CompatibilityList Count=\"%d\">\n",movie->num_cl);
for (i = movie->num_cl - 1; i > -1; i--) { /* read routine stored in reverse order, so let's undo damage */
for (i = movie->num_cl - 1; i > -1; i--) /* read routine stored in reverse order, so let's undo damage */
{
uint_to_chars(movie->cl[i], buf);
fprintf(xmlout, " <CompatibleBrand>%s</CompatibleBrand>\n", buf); /*4 characters, each CLi */
}
@@ -263,7 +264,8 @@ void uint_to_chars(unsigned int value, char* buf)
{
/* buf is at least char[5] */
int i;
for (i = 3; i >= 0; i--) {
for (i = 3; i >= 0; i--)
{
buf[i] = (value & 0x000000ff);
value = (value >> 8);
}
@@ -317,8 +319,7 @@ void xml_time_out(FILE* xmlout, time_t t)
/* ------------- */
void xml_write_moov_udta(FILE* xmlout, opj_mj2_t * movie)
{
void xml_write_moov_udta(FILE* xmlout, opj_mj2_t * movie) {
/* Compare with xml_write_udta */
#ifdef NOTYET
/* NO-OP so far. Optional UserData 'udta' (zero or one in moov or each trak)
@@ -345,8 +346,7 @@ void xml_write_moov_udta(FILE* xmlout, opj_mj2_t * movie)
#endif
}
void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie)
{
void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie) {
#ifdef NOTYET
/* NO-OP so far. There can be zero or more instances of free and/or skip
at the top level of the file. This may be a place where the user squirrel's metadata.
@@ -374,9 +374,8 @@ void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie)
#endif
}
void xml_write_uuid(FILE* xmlout, opj_mj2_t * movie)
{
/* Universal Unique IDs of 16 bytes. */
void xml_write_uuid(FILE* xmlout, opj_mj2_t * movie) {
/* Univeral Unique IDs of 16 bytes. */
#ifdef NOTYET
/* NO-OP so far. There can be zero or more instances of private uuid boxes in a file.
This function supports the top level of the file, but uuid may be elsewhere [not yet supported].
@@ -412,7 +411,8 @@ void xml_write_trak(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
/* sampleframe is from user option -f. 1 = first frame */
/* sampleframe of 0 is a user requests: no jp2 header */
/* Treat out-of-bounds values in the same way */
if(sampleframe > 0 && sampleframe <= track->num_samples) {
if(sampleframe > 0 && sampleframe <= track->num_samples)
{
mj2_sample_t *sample;
unsigned int snum;
@@ -439,12 +439,14 @@ void xml_write_tkhd(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " <!-- If both found, value read from MediaHeader is used. -->\n");
}
fprintf(xmlout, " <TrackID>%u</TrackID>\n", track->track_ID);
if(track->track_type==0) { /* For visual track */
if(track->track_type==0) /* For visual track */
{
fprintf(xmlout, " <TrackLayer>%d</TrackLayer>\n", track->layer);
if(notes)
fprintf(xmlout," <!-- front-to-back ordering of video tracks. 0 = normal, -1 is closer, etc. -->\n");
}
if(track->track_type!=0) { /* volume irrelevant for visual track */
if(track->track_type!=0) /* volume irrelevant for visual track */
{
#ifdef CURRENTSTRUCT
track->volume = track->volume << 8;
#endif
@@ -464,7 +466,8 @@ void xml_write_tkhd(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
track->volume = track->volume >> 8;
#endif
}
if(track->track_type==0) {
if(track->track_type==0)
{
/* Transformation matrix for video */
fprintf(xmlout, " <TransformationMatrix>\n");
if(notes) {
@@ -515,8 +518,7 @@ void xml_write_tkhd(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
/* ------------- */
void xml_write_udta(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum)
{
void xml_write_udta(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum) {
/* NO-OP so far. Optional UserData 'udta' (zero or one in moov or each trak)
can contain multiple Copyright 'cprt' with different language codes */
/* There may be nested non-standard boxes within udta */
@@ -588,16 +590,14 @@ void xml_write_mdia(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " <Language>%s</Language>\n", buf); /* 3 chars */
fprintf(xmlout, " </MediaHeader>\n");
fprintf(xmlout, " <HandlerReference BoxType=\"hdlr\">\n");
switch(track->track_type) {
switch(track->track_type)
{
case 0:
fprintf(xmlout, " <HandlerType Code=\"vide\">video media track</HandlerType>\n");
break;
fprintf(xmlout, " <HandlerType Code=\"vide\">video media track</HandlerType>\n"); break;
case 1:
fprintf(xmlout, " <HandlerType Code=\"soun\">Sound</HandlerType>\n");
break;
fprintf(xmlout, " <HandlerType Code=\"soun\">Sound</HandlerType>\n"); break;
case 2:
fprintf(xmlout, " <HandlerType Code=\"hint\">Hint</HandlerType>\n");
break;
fprintf(xmlout, " <HandlerType Code=\"hint\">Hint</HandlerType>\n"); break;
}
if(notes) {
fprintf(xmlout, " <!-- String value shown is not actually read from file. -->\n");
@@ -605,7 +605,8 @@ void xml_write_mdia(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
}
fprintf(xmlout, " </HandlerReference>\n");
fprintf(xmlout, " <MediaInfoContainer BoxType=\"minf\">\n");
switch(track->track_type) {
switch(track->track_type)
{
case 0:
fprintf(xmlout, " <VideoMediaHeader BoxType=\"vmhd\">\n");
fprintf(xmlout, " <GraphicsMode>0x%02x</GraphicsMode>\n", track->graphicsmode);
@@ -723,7 +724,8 @@ void xml_write_stbl(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " <SampleTable BoxType=\"stbl\">\n");
if(notes)
fprintf(xmlout, " <!-- What follows are specific instances of generic SampleDescription BoxType=\"stsd\" -->\n");
switch(track->track_type) {
switch(track->track_type)
{
case 0:
// There could be multiple instances of this, but "entry_count" is just a local at read-time.
// And it's used wrong, too, as count of just visual type, when it's really all 3 types.
@@ -795,15 +797,16 @@ void xml_write_stbl(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " </FieldCoding>\n");
fprintf(xmlout, " <MJP2_Profile BoxType=\"jp2p\" Count=\"%d\">\n",track->num_br);
for (i = 0; i < track->num_br; i++) { /* read routine stored in reverse order, so let's undo damage */
for (i = 0; i < track->num_br; i++) /* read routine stored in reverse order, so let's undo damage */
{
uint_to_chars(track->br[i], buf);
fprintf(xmlout, " <CompatibleBrand>%s</CompatibleBrand>\n", buf); /*4 characters, each CLi */
}
fprintf(xmlout, " </MJP2_Profile>\n");
fprintf(xmlout, " <MJP2_Prefix BoxType=\"jp2x\" Count=\"%d\">\n",track->num_jp2x);
for (i = 0; i < track->num_jp2x; i++) {
// We'll probably need better formatting than this
for (i = 0; i < track->num_jp2x; i++)
{ // We'll probably need better formatting than this
fprintf(xmlout, " <Data>0x%02x</Data>\n", track->jp2xdata[i]); /* Each entry is single byte */
}
fprintf(xmlout, " </MJP2_Prefix>\n");
@@ -840,11 +843,9 @@ void xml_write_stbl(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " </MJP2_OriginalFormat>\n");
fprintf(xmlout, " </VisualSampleEntry>\n");
break;
case 1:
case 2:
case 1: case 2:
if(notes)
fprintf(xmlout, " <!-- mj2_to_metadata's data structure doesn't record this currently. -->\n");
break;
fprintf(xmlout, " <!-- mj2_to_metadata's data structure doesn't record this currently. -->\n"); break;
}
fprintf(xmlout, " <TimeToSample BoxType=\"stts\">\n");
fprintf(xmlout, " <SampleStatistics>\n");
@@ -961,7 +962,7 @@ int xml_out_frame(FILE* file, FILE* xmlout, mj2_sample_t *sample, unsigned int s
fprintf(xmlout, " <JP2_Frame Num=\"%d\">\n", snum+1);
fprintf(xmlout, " <MainHeader>\n");
/* There can be multiple codestreams; a particular image is entirely within a single codestream */
/* TO DO: A frame can be represented by two I-guess-contiguous codestreams if its interleaved. */
/* TO DO: A frame can be represented by two I-guess-contigious codestreams if its interleaved. */
fprintf(xmlout, " <StartOfCodestream Marker=\"SOC\" />\n");
/* "cp" stands for "coding parameter"; "tcp" is tile coding parameters, "tccp" is tile-component coding parameters */
xml_out_frame_siz(xmlout, img, cp); /* reqd in main */
@@ -1030,11 +1031,13 @@ int xml_out_frame(FILE* file, FILE* xmlout, mj2_sample_t *sample, unsigned int s
&& (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1))
|| (img->numcomps == 1)) {
fprintf(xmlout, " <!-- file to a YUV movie in the normal manner. -->\n");
} else if ((img->numcomps == 3) &&
}
else if ((img->numcomps == 3) &&
(img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(img->comps[2].dx == 1)) {// If YUV 4:4:4 input --> to bmp
fprintf(xmlout, " <!-- YUV 4:4:4 file to a series of .bmp files. -->\n");
} else {
}
else {
fprintf(xmlout, " <!-- file whose image component dimension are unknown, to a series of .j2k files. -->\n");
}
}
@@ -1053,7 +1056,8 @@ void int16_to_3packedchars(short int value, char* buf)
/* This is to retrieve the 3-letter ASCII language code */
/* Each char is packed into 5 bits, as difference from 0x60 */
int i;
for (i = 2; i >= 0; i--) {
for (i = 2; i >= 0; i--)
{
buf[i] = (value & 0x001f) + 0x60;
value = (value >>5);
}
@@ -1140,8 +1144,7 @@ void xml_out_frame_cod(FILE* xmlout, opj_tcp_t *tcp)
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;
s++; /* shorten s to 10 spaces if main */
s++;s++; /* shorten s to 10 spaces if main */
}
tccp = &(tcp->tccps[0]);
@@ -1222,8 +1225,7 @@ void xml_out_frame_coc(FILE* xmlout, opj_tcp_t *tcp, int numcomps) /* Optional i
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;
s++; /* shorten s to 10 spaces if main */
s++;s++; /* shorten s to 10 spaces if main */
}
firstcomp_tccp = &(tcp->tccps[0]);
@@ -1239,7 +1241,8 @@ void xml_out_frame_coc(FILE* xmlout, opj_tcp_t *tcp, int numcomps) /* Optional i
else
fprintf(xmlout, "%s<!-- and any other component, with tile-part-header style values different from [0], as COC. -->\n", s);
}
for (compno = 1; compno < numcomps; compno++) { /* spec says components are zero-based */
for (compno = 1; compno < numcomps; compno++) /* spec says components are zero-based */
{
tccp = &tcp->tccps[compno];
if(same_component_style(firstcomp_tccp, tccp))
continue;
@@ -1341,8 +1344,7 @@ void xml_out_frame_qcd(FILE* xmlout, opj_tcp_t *tcp)
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;
s++; /* shorten s to 10 spaces if main */
s++;s++; /* shorten s to 10 spaces if main */
}
/* Compare j2k_read_qcx */
@@ -1475,8 +1477,7 @@ void xml_out_frame_qcc(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;
s++; /* shorten s to 10 spaces if main */
s++;s++; /* shorten s to 10 spaces if main */
}
firstcomp_tccp = &(tcp->tccps[0]);
@@ -1492,7 +1493,8 @@ void xml_out_frame_qcc(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
else
fprintf(xmlout, "%s<!-- and any other component, with tile-part-header quantization values different from [0], as QCC. -->\n", s);
}
for (compno = 1; compno < numcomps; compno++) { /* spec says components are zero-based */
for (compno = 1; compno < numcomps; compno++) /* spec says components are zero-based */
{
tccp = &(tcp->tccps[compno]);
if(same_component_quantization(firstcomp_tccp, tccp))
continue;
@@ -1659,8 +1661,7 @@ void xml_out_frame_rgn(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;
s++; /* shorten s to 10 spaces if main */
s++;s++; /* shorten s to 10 spaces if main */
}
for(compno = 0; compno < numcomps; compno++) {
@@ -1685,16 +1686,14 @@ void xml_out_frame_rgn(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
/* ------------- */
void xml_out_frame_poc(FILE* xmlout, opj_tcp_t *tcp) /* Progression Order Change */
{
void xml_out_frame_poc(FILE* xmlout, opj_tcp_t *tcp) { /* Progression Order Change */
/* Compare j2k_read_poc() */
int i;
opj_poc_t *poc;
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == j2k_default_tcp) {
s++;
s++; /* shorten s to 10 spaces if main */
s++;s++; /* shorten s to 10 spaces if main */
}
if(tcp->POC != 1)
@@ -1740,8 +1739,7 @@ void xml_out_frame_poc(FILE* xmlout, opj_tcp_t *tcp) /* Progression Order Chan
/* Suppress PPM and PPT since we're not showing data from the third option, namely within the codestream, and
that's evidently what frames_to_mj2 uses. And a hex dump isn't so useful anyway */
void xml_out_frame_ppm(FILE *xmlout, opj_cp_t *cp) /* For main header, not tile-part (which uses PPT instead). */
{
void xml_out_frame_ppm(FILE *xmlout, opj_cp_t *cp) { /* For main header, not tile-part (which uses PPT instead). */
/* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */
/* Use of PPM and PPT are mutually exclusive. */
/* Compare j2k_read_ppm() */
@@ -1772,8 +1770,7 @@ void xml_out_frame_ppm(FILE *xmlout, opj_cp_t *cp) /* For main header, not til
/* ------------- */
void xml_out_frame_ppt(FILE *xmlout, opj_tcp_t *tcp) /* For tile-part header, not main (which uses PPM instead). */
{
void xml_out_frame_ppt(FILE *xmlout, opj_tcp_t *tcp) { /* For tile-part header, not main (which uses PPM instead). */
/* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */
/* Use of PPM and PPT are mutually exclusive. */
/* Compare j2k_read_ppt() */
@@ -1806,8 +1803,7 @@ void xml_out_frame_ppt(FILE *xmlout, opj_tcp_t *tcp) /* For tile-part header,
/* ------------- */
void xml_out_frame_tlm(FILE* xmlout) /* opt, main header only. May be multiple. */
{
void xml_out_frame_tlm(FILE* xmlout) { /* opt, main header only. May be multiple. */
/* Compare j2k_read_tlm()... which doesn't retain anything! */
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */
/* Main header indents are 10 spaces */
@@ -1815,8 +1811,7 @@ void xml_out_frame_tlm(FILE* xmlout) /* opt, main header only. May be multipl
/* ------------- */
void xml_out_frame_plm(FILE* xmlout) /* opt, main header only; can be used in conjunction with tile-part's PLT */
{
void xml_out_frame_plm(FILE* xmlout) { /* opt, main header only; can be used in conjunction with tile-part's PLT */
/* NO-OP. PLM NOT SAVED IN DATA STRUCTURE */
/* Compare j2k_read_plm()... which doesn't retain anything! */
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */
@@ -1825,8 +1820,7 @@ void xml_out_frame_plm(FILE* xmlout) /* opt, main header only; can be used in
/* ------------- */
void xml_out_frame_plt(FILE* xmlout, opj_tcp_t *tcp) /* opt, tile-part headers only; can be used in conjunction with main header's PLM */
{
void xml_out_frame_plt(FILE* xmlout, opj_tcp_t *tcp) { /* opt, tile-part headers only; can be used in conjunction with main header's PLM */
/* NO-OP. PLT NOT SAVED IN DATA STRUCTURE */
/* Compare j2k_read_plt()... which doesn't retain anything! */
/* Tile-part header indents are 12 spaces */
@@ -1834,14 +1828,11 @@ void xml_out_frame_plt(FILE* xmlout, opj_tcp_t *tcp) /* opt, tile-part headers
/* ------------- */
void xml_out_frame_crg(FILE* xmlout)
{
/* NO-OP. CRG NOT SAVED IN DATA STRUCTURE */ /* opt, main header only; */
void xml_out_frame_crg(FILE* xmlout) { /* NO-OP. CRG NOT SAVED IN DATA STRUCTURE */ /* opt, main header only; */
/* Compare j2k_read_crg()... which doesn't retain anything! */
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */
#ifdef NOTYET
THIS PSEUDOCODE IMAGINES THESE EXIST:
j2k_default_tcp->crg, j2k_default_tcp->crg_i, j2k_default_tcp->crg_xcrg*, j2k_default_tcp->crg_ycrg*
THIS PSEUDOCODE IMAGINES THESE EXIST: j2k_default_tcp->crg, j2k_default_tcp->crg_i, j2k_default_tcp->crg_xcrg*, j2k_default_tcp->crg_ycrg*
(POSSIBLY DON'T NEED crg_i, CAN GET NUMBER OR COMPONENTS FROM ELSEWHERE)
if(j2k_default_tcp->crg != 1 || j2k_default_tcp->crg_i == 0)
return; /* Not present */
@@ -1884,19 +1875,15 @@ THIS PSEUDOCODE IMAGINES THESE EXIST:
/* ------------- */
/* Regrettably from a metadata point of view, j2k_read_com() skips over any comments in main header or tile-part-header */
void xml_out_frame_com(FILE* xmlout, opj_tcp_t *tcp)
{
/* NO-OP. COM NOT SAVED IN DATA STRUCTURE */ /* opt in main or tile-part headers; */
void xml_out_frame_com(FILE* xmlout, opj_tcp_t *tcp) { /* NO-OP. COM NOT SAVED IN DATA STRUCTURE */ /* opt in main or tile-part headers; */
/* Compare j2k_read_com()... which doesn't retain anything! */
#ifdef NOTYET
char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces;
if(tcp == &j2k_default_tcp) {
s++;
s++; /* shorten s to 10 spaces if main */
s++;s++; /* shorten s to 10 spaces if main */
}
THIS PSEUDOCODE IMAGINES THESE EXIST:
tcp->com, tcp->com_len, tcp->com_data array
THIS PSEUDOCODE IMAGINES THESE EXIST: tcp->com, tcp->com_len, tcp->com_data array
if(tcp->com != 1)
return; /* Not present */
@@ -1906,8 +1893,7 @@ THIS PSEUDOCODE IMAGINES THESE EXIST:
#endif
}
void xml_out_dump_hex(FILE* xmlout, char *data, int data_len, char* s)
{
void xml_out_dump_hex(FILE* xmlout, char *data, int data_len, char* s) {
/* s is a string of spaces for indent */
int i;
@@ -1923,8 +1909,7 @@ void xml_out_dump_hex(FILE* xmlout, char *data, int data_len, char* s)
/* Define this as an even number: */
#define BYTES_PER_DUMP_LINE 40
/* Current total width for Hex and ASCII is : 11 spaces lead + (3 * BPDL) + 2 spaces + BPDL */
void xml_out_dump_hex_and_ascii(FILE* xmlout, char *data, int data_len, char* s)
{
void xml_out_dump_hex_and_ascii(FILE* xmlout, char *data, int data_len, char* s) {
/* s is a string of spaces for indent */
int i,j;
@@ -1959,8 +1944,7 @@ void xml_out_dump_hex_and_ascii(FILE* xmlout, char *data, int data_len, char* s)
/* ------------- */
void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) /* JP2 Header */
{
void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) { /* JP2 Header */
/* Compare jp2_read_jp2h(opj_jp2_t * jp2_struct) */
int i;
@@ -2003,7 +1987,8 @@ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) /* JP2 Header */
fprintf(xmlout, " <!-- IPR is 1 if frame contains an Intellectual Property box; 0 otherwise. -->\n"); /* 2 bytes */
fprintf(xmlout, " </ImageHeader>\n");
if (jp2_struct->bpc == 255) {
if (jp2_struct->bpc == 255)
{
fprintf(xmlout, " <BitsPerComponent BoxType=\"bpcc\">\n");
if(notes)
fprintf(xmlout, " <!-- Pixel depth (range 1 to 38) is low 7 bits of hex value + 1 -->\n");
@@ -2044,7 +2029,9 @@ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) /* JP2 Header */
fprintf(xmlout, " <!-- 18: sRGB YCC (from JPEG 2000 Part II). -->\n");
fprintf(xmlout, " <!-- (Additional JPX values are defined in Part II). -->\n");
}
} else if(notes)
}
else
if(notes)
fprintf(xmlout, " <!-- PROFILE is not handled by current OpenJPEG implementation. -->\n");
/* only 1 byte is read and nothing stored */
fprintf(xmlout, " </ColourSpecification>\n");
@@ -2061,15 +2048,15 @@ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) /* JP2 Header */
#ifdef NOTYET
IMAGE these use cp structure, extended... but we could use a new data structure instead
void xml_out_frame_jp2i(FILE* xmlout, opj_cp_t *cp)
{
void xml_out_frame_jp2i(FILE* xmlout, opj_cp_t *cp) {
/* IntellectualProperty 'jp2i' (no restrictions on location) */
int i;
IMAGE cp->jp2i, cp->jp2i_count, cp->jp2i_data (array of chars), cp->cp2i_len (array of ints)
if(cp->jp2i != 1)
return; /* Not present */
for(i = 0; i < cp->jp2i_count; i++) {
for(i = 0; i < cp->jp2i_count; i++)
{
fprintf(xmlout, " <IntellectualProperty BoxType=\"jp2i\">\n");
/* I think this can be anything, including binary, so do a dump */
/* Is it better to indent or not indent this content? Indent is better for reading, but
@@ -2079,8 +2066,7 @@ void xml_out_frame_jp2i(FILE* xmlout, opj_cp_t *cp)
}
}
void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp)
{
void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp) {
/* XML 'xml\040' (0x786d6c20). Can appear multiply, before or after jp2c codestreams */
IMAGE cp->xml, cp->xml_count, cp->xml_data (array of chars)
MAYBE WE DON'T NEED cp->xml_len (array of ints) IF WE ASSUME xml_data IS NULL-TERMINATED.
@@ -2099,8 +2085,7 @@ void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp)
}
}
void xml_out_frame_uuid(FILE* xmlout, opj_cp_t *cp)
{
void xml_out_frame_uuid(FILE* xmlout, opj_cp_t *cp) {
/* UUID 'uuid' (top level only) */
/* Part I 1.7.2 says: may appear multiply in JP2 file, anywhere except before File Type box */
/* Part III 5.2.1 says: Private extensions shall be achieved through the 'uuid' type. */

View File

@@ -23,24 +23,21 @@ can be bound by the Open JPEG open-source license and disclaimer, expressed else
/**
sample error callback expecting a FILE* client object
*/
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
*/
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
*/
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);
}
@@ -67,7 +64,7 @@ void help_display()
fprintf(stdout,"----------\n");
fprintf(stdout,"The metadata includes the jp2 image and tile headers of the first frame.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Metadata values are shown in 'raw' form (e.g., hexadecimal) as stored in the\n");
fprintf(stdout,"Metadata values are shown in 'raw' form (e.g., hexidecimal) as stored in the\n");
fprintf(stdout,"file, and, if apt, in a 'derived' form that is more quickly grasped.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Notes explaining the XML are embedded as terse comments. These include\n");
@@ -110,8 +107,7 @@ void help_display()
/* ------------- */
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
@@ -142,9 +138,7 @@ int main(int argc, char *argv[])
case 'i': /* IN file */
infile = optarg;
s = optarg;
while (*s) {
s++; /* Run to filename end */
}
while (*s) { s++; } /* Run to filename end */
s--;
S3 = *s;
s--;
@@ -162,9 +156,7 @@ int main(int argc, char *argv[])
/* ----------------------------------------------------- */
case 'o': /* OUT file */
outfile = optarg;
while (*outfile) {
outfile++; /* Run to filename end */
}
while (*outfile) { outfile++; } /* Run to filename end */
outfile--;
S3 = *outfile;
outfile--;
@@ -252,7 +244,8 @@ int main(int argc, char *argv[])
}
*/
len = strlen(infile);
if(infile[0] == ' ') {
if(infile[0] == ' ')
{
infile++; /* There may be a leading blank if user put space after -i */
}
@@ -264,7 +257,8 @@ int main(int argc, char *argv[])
}
len = strlen(outfile);
if(outfile[0] == ' ') {
if(outfile[0] == ' ')
{
outfile++; /* There may be a leading blank if user put space after -o */
}
@@ -295,7 +289,8 @@ int main(int argc, char *argv[])
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(dinfo->mj2_handle, &parameters);
if (mj2_read_struct(file, movie)) { // Creating the movie structure
if (mj2_read_struct(file, movie)) // Creating the movie structure
{
fclose(xmlout);
return 1;
}

View File

@@ -50,16 +50,14 @@ Size of memory first allocated for MOOV box
/**
sample error callback expecting a FILE* client object
*/
static void error_callback(const char *msg, void *client_data)
{
static 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)
{
static void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
@@ -287,7 +285,8 @@ int main(int argc, char **argv)
if (c == -1)
break;
switch (c) {
case 'i': { /* IN fill */
case 'i': /* IN fill */
{
char *infile = opj_optarg;
s = opj_optarg;
while (*s) {
@@ -303,7 +302,8 @@ int main(int argc, char **argv)
if ((S1 == 'y' && S2 == 'u' && S3 == 'v')
|| (S1 == 'Y' && S2 == 'U' && S3 == 'V')) {
mj2_parameters.decod_format = YUV_DFMT;
} else {
}
else {
fprintf(stderr,
"!! Unrecognized format for infile : %c%c%c [accept only *.yuv] !!\n\n",
S1, S2, S3);
@@ -313,7 +313,8 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 'o': { /* OUT fill */
case 'o': /* OUT fill */
{
char *outfile = opj_optarg;
while (*outfile) {
outfile++;
@@ -340,7 +341,8 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 'r': { /* rates rates/distorsion */
case 'r': /* rates rates/distorsion */
{
float rate;
s = opj_optarg;
while (sscanf(s, "%f", &rate) == 1) {
@@ -372,7 +374,8 @@ int main(int argc, char **argv)
break;
/* dda */
/* ----------------------------------------------------- */
case 'f': { /* mod fixed_quality (before : -q) */
case 'f': /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
@@ -425,7 +428,8 @@ int main(int argc, char **argv)
sscanf(opj_optarg, "%d", &j2k_parameters->numresolution);
break;
/* ----------------------------------------------------- */
case 'c': { /* precinct dimension */
case 'c': /* precinct dimension */
{
char sep;
int res_spec = 0;
@@ -437,13 +441,15 @@ int main(int argc, char **argv)
j2k_parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
} while (sep == ',');
}
while (sep == ',');
j2k_parameters->res_spec = res_spec;
}
break;
/* ----------------------------------------------------- */
case 'b': { /* code-block dimension */
case 'b': /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@@ -458,7 +464,8 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 'p': { /* progression order */
case 'p': /* progression order */
{
char progression[5];
strncpy(progression, opj_optarg, 5);
@@ -471,7 +478,8 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 's': { /* subsampling factor */
case 's': /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->subsampling_dx,
&j2k_parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
@@ -480,7 +488,8 @@ int main(int argc, char **argv)
}
break;
/* ----------------------------------------------------- */
case 'd': { /* coordonnate of the reference grid */
case 'd': /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->image_offset_x0,
&j2k_parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@@ -495,7 +504,8 @@ int main(int argc, char **argv)
return 0;
break;
/* ----------------------------------------------------- */
case 'P': { /* POC */
case 'P': /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@@ -538,7 +548,8 @@ int main(int argc, char **argv)
}
break;
/* ------------------------------------------------------ */
case 'R': { /* ROI */
case 'R': /* ROI */
{
if (sscanf(opj_optarg, "OI:c=%d,U=%d", &j2k_parameters->roi_compno,
&j2k_parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n");
@@ -547,7 +558,8 @@ int main(int argc, char **argv)
}
break;
/* ------------------------------------------------------ */
case 'T': { /* Tile offset */
case 'T': /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tx0, &j2k_parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
@@ -555,7 +567,8 @@ int main(int argc, char **argv)
}
break;
/* ------------------------------------------------------ */
case 'C': { /* Add a comment */
case 'C': /* Add a comment */
{
j2k_parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(j2k_parameters->cp_comment) {
strcpy(j2k_parameters->cp_comment, opj_optarg);
@@ -563,7 +576,8 @@ int main(int argc, char **argv)
}
break;
/* ------------------------------------------------------ */
case 'I': { /* reversible or not */
case 'I': /* reversible or not */
{
j2k_parameters->irreversible = 1;
}
break;
@@ -600,7 +614,8 @@ int main(int argc, char **argv)
"Usage: %s -i yuv-file -o mj2-file (+ options)\n",argv[0]);
return 1;
}
if(prec < 1 || prec > 16) {
if(prec < 1 || prec > 16)
{
fprintf(stderr, "Error: Depth %d must be in the range 8 .. 16\n",prec);
return 1;
}
@@ -708,10 +723,14 @@ int main(int argc, char **argv)
opj_cio_close(cio);
free(buf);
for(i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++) {
if(movie->tk[i].track_type != 0) {
for(i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++)
{
if(movie->tk[i].track_type != 0)
{
fprintf(stderr, "Unable to write sound or hint tracks\n");
} else {
}
else
{
mj2_tk_t *tk;
int buflen = 0;
@@ -727,12 +746,14 @@ int main(int argc, char **argv)
buflen = 2 * (tk->w * tk->h * 8);
buf = (unsigned char *) malloc(buflen*sizeof(unsigned char));
for(sampleno = 0; sampleno < numframes; sampleno++) {
for(sampleno = 0; sampleno < numframes; sampleno++)
{
double init_time = opj_clock();
double elapsed_time;
if(yuvtoimage(tk, img, sampleno, j2k_parameters,
mj2_parameters.infile)) {
mj2_parameters.infile))
{
fprintf(stderr, "Error with frame number %d in YUV file\n", sampleno);
return 1;
}

View File

@@ -50,16 +50,14 @@
/**
sample error callback expecting a FILE* client object
*/
static void error_callback(const char *msg, void *client_data)
{
static 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)
{
static void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
@@ -67,8 +65,7 @@ static void warning_callback(const char *msg, void *client_data)
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
mj2_dparameters_t mj2_parameters; /* decompression parameters */
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
@@ -153,7 +150,8 @@ int main(int argc, char *argv[])
numframes = track->num_samples;
for (snum=0; snum < numframes; snum++) {
for (snum=0; snum < numframes; snum++)
{
double init_time = opj_clock();
double elapsed_time;
@@ -175,19 +173,20 @@ int main(int argc, char *argv[])
img = opj_decode(dinfo, cio); /* Decode J2K to image */
#ifdef WANT_SYCC_TO_RGB
if(img->color_space == CLRSPC_SYCC) {
if(img->color_space == CLRSPC_SYCC)
{
color_sycc_to_rgb(img);
}
#endif
if(img->icc_profile_buf) {
if(img->icc_profile_buf)
{
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(img);
#endif
free(img->icc_profile_buf);
img->icc_profile_buf = NULL;
img->icc_profile_len = 0;
img->icc_profile_buf = NULL; img->icc_profile_len = 0;
}
if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2)
@@ -196,15 +195,18 @@ int main(int argc, char *argv[])
if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */
return 1;
} else if ((img->numcomps == 3) &&
}
else if ((img->numcomps == 3) &&
(img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(img->comps[2].dx == 1)) { /* If YUV 4:4:4 input --> to bmp */
(img->comps[2].dx == 1))/* If YUV 4:4:4 input --> to bmp */
{
fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n");
sprintf(outfilename,"output_%d.bmp",snum);
if (imagetobmp(img, outfilename)) /* Convert image to BMP */
return 1;
} else {
}
else {
fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n");
fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n");

View File

@@ -46,24 +46,21 @@
/**
sample error callback expecting a FILE* client object
*/
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
*/
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
*/
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);
}
@@ -71,8 +68,7 @@ void info_callback(const char *msg, void *client_data)
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
int tnum;
@@ -130,7 +126,8 @@ int main(int argc, char *argv[])
fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
for (snum=0; snum < track->num_samples; snum++) {
for (snum=0; snum < track->num_samples; snum++)
{
sample = &track->sample[snum];
frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/
fseek(file,sample->offset+8,SEEK_SET);

View File

@@ -41,8 +41,7 @@
#include "jp2.h"
#include "mj2.h"
static int int_ceildiv(int a, int b)
{
static int int_ceildiv(int a, int b) {
return (a + b - 1) / b;
}
@@ -77,9 +76,9 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
fread(src, 1, src_len, reader);
fclose(reader);
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0) {
free(src);
return success;
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0)
{
free(src); return success;
}
memset(&dparameters, 0, sizeof(opj_dparameters_t));
@@ -93,8 +92,7 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
image = opj_decode(dinfo, cio);
free(src);
cio->buffer = NULL;
free(src); cio->buffer = NULL;
opj_cio_close(cio);
if(image == NULL) goto fin;
@@ -104,59 +102,75 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
cp->h = image->comps[0].h;
cp->prec = image->comps[0].prec;
if(image->numcomps > 2 ) {
if(image->numcomps > 2 )
{
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2)) { /* horizontal and vertical*/
&& (image->comps[2].dy == 2))/* horizontal and vertical*/
{
/* Y420*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 2;
} else if((image->comps[0].dx == 1)
}
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1)) { /* horizontal only*/
&& (image->comps[2].dy == 1))/* horizontal only*/
{
/* Y422*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 1;
} else if((image->comps[0].dx == 1)
}
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1)) {
&& (image->comps[2].dy == 1))
{
/* Y444 or RGB */
if(image->color_space == CLRSPC_SRGB) {
if(image->color_space == CLRSPC_SRGB)
{
cp->enumcs = ENUMCS_SRGB;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
} else {
}
else
{
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 1;
cp->CbCr_subsampling_dy = 1;
}
} else {
}
else
{
goto fin;
}
} else {
}
else
{
cp->enumcs = ENUMCS_GRAY;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
}
if(image->icc_profile_buf) {
if(image->icc_profile_buf)
{
cp->meth = 2;
free(image->icc_profile_buf);
image->icc_profile_buf = NULL;
} else cp->meth = 1;
free(image->icc_profile_buf); image->icc_profile_buf = NULL;
}
else cp->meth = 1;
success = 1;
fin:
@@ -172,24 +186,21 @@ fin:
/**
sample error callback expecting a FILE* client object
*/
static void error_callback(const char *msg, void *client_data)
{
static 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)
{
static 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)
{
static void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
@@ -210,7 +221,8 @@ static void read_siz_marker(FILE *file, opj_image_t *image)
fread(&buf,1,1, file);
if (buf==(char)0xff)
fread(&buf,1,1, file);
} while (!(buf==(char)0x51));
}
while (!(buf==(char)0x51));
fread(buf2,2,1,file); /* Lsiz */
len = ((buf2[0])<<8) + buf2[1];
@@ -245,8 +257,7 @@ static void read_siz_marker(FILE *file, opj_image_t *image)
free(siz_buffer);
}
static void setparams(opj_mj2_t *movie, opj_image_t *image)
{
static void setparams(opj_mj2_t *movie, opj_image_t *image) {
int i, depth_0, depth, sign;
movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
@@ -260,7 +271,8 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1))
movie->tk[0].CbCr_subsampling_dx = 1;
else if ((image->comps[0].dx == 1)
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2;
@@ -271,7 +283,8 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else if ((image->comps[0].dy == 1)
else
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
@@ -324,7 +337,8 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image)
if (image->numcomps == 1)
movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */
else if ((image->comps[0].dx == 1)
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
@@ -332,7 +346,8 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image)
&& (image->comps[2].dy == 1))
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else if ((image->comps[0].dx == 1)
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
@@ -341,11 +356,10 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image)
movie->tk[0].jp2_struct.enumcs = 18; /* YUV */
else
movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
movie->tk[0].jp2_struct.enumcs = 0; /* Unkown profile */
}
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
opj_cinfo_t* cinfo;
opj_event_mgr_t event_mgr; /* event manager */
unsigned int snum;
@@ -418,7 +432,8 @@ int main(int argc, char *argv[])
/* Insert each j2k codestream in a JP2C box */
snum=0;
offset = 0;
while(1) {
while(1)
{
mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum];
@@ -428,7 +443,8 @@ int main(int argc, char *argv[])
if (snum==0) { /* Could not open a single codestream */
fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1;
} else { /* Tried to open a inexistant codestream */
}
else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}

View File

@@ -889,7 +889,7 @@ void OPJMarkerTree::OnSelChanged(wxTreeEvent& event)
m_peektextCtrl->WriteText(text);
delete [] buffer;
delete buffer;
}
/*void LogKeyEvent(const wxChar *name, const wxKeyEvent& event)

View File

@@ -184,23 +184,13 @@ class OPJViewerApp: public wxApp
public:
// class constructor
OPJViewerApp()
{
m_showImages = true;
m_showButtons = false;
}
OPJViewerApp() { m_showImages = true; m_showButtons = false; }
// other methods
bool OnInit(void);
int OnExit(void);
void SetShowImages(bool show)
{
m_showImages = show;
}
bool ShowImages() const
{
return m_showImages;
}
void SetShowImages(bool show) { m_showImages = show; }
bool ShowImages() const { return m_showImages; }
void ShowCmdLine(const wxCmdLineParser& parser);
// all the threads currently alive - as soon as the thread terminates, it's
@@ -275,8 +265,7 @@ public:
virtual void OnDraw(wxDC& dc);
void OnEvent(wxMouseEvent& event);
void WriteText(const wxString& text)
{
void WriteText(const wxString& text) {
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif //__WXGTK__
@@ -310,21 +299,11 @@ class OPJMarkerData : public wxTreeItemData
public:
// class constructor
OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname)
{
m_start = start;
m_length = length;
}
OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname) { m_start = start; m_length = length; }
void ShowInfo(wxTreeCtrl *tree);
const wxChar *GetDesc1() const
{
return m_desc.c_str();
}
const wxChar *GetDesc2() const
{
return m_filestring.c_str();
}
const wxChar *GetDesc1() const { return m_desc.c_str(); }
const wxChar *GetDesc2() const { return m_filestring.c_str(); }
wxFileOffset m_start, m_length;
wxString m_desc;
@@ -337,7 +316,8 @@ private:
class OPJMarkerTree : public wxTreeCtrl
{
public:
enum {
enum
{
TreeCtrlIcon_File,
TreeCtrlIcon_FileSelected,
TreeCtrlIcon_Folder,
@@ -351,12 +331,7 @@ public:
long style);
virtual ~OPJMarkerTree(){};
OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00, OPJChildFrame *subframe = NULL);
void WriteText(const wxString& text)
{
wxMutexGuiEnter();
wxLogMessage(text);
wxMutexGuiLeave();
}
void WriteText(const wxString& text) { wxMutexGuiEnter(); wxLogMessage(text); wxMutexGuiLeave(); }
wxFileName m_fname;
wxTextCtrl *m_peektextCtrl;
@@ -397,15 +372,9 @@ public:
/*void DoToggleIcon(const wxTreeItemId& item);*/
/*void ShowMenu(wxTreeItemId id, const wxPoint& pt);*/
int ImageSize(void) const
{
return m_imageSize;
}
int ImageSize(void) const { return m_imageSize; }
void SetLastItem(wxTreeItemId id)
{
m_lastItem = id;
}
void SetLastItem(wxTreeItemId id) { m_lastItem = id; }
protected:
/*virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);*/
@@ -572,7 +541,8 @@ enum {
// menu and control ids
enum {
enum
{
TreeTest_Quit = wxID_EXIT,
TreeTest_About = wxID_ABOUT,
TreeTest_TogButtons = wxID_HIGHEST,
@@ -696,10 +666,7 @@ private:
class OPJDnDFile: public wxFileDropTarget
{
public:
OPJDnDFile(OPJFrame *pOwner)
{
m_pOwner = pOwner;
}
OPJDnDFile(OPJFrame *pOwner) { m_pOwner = pOwner; }
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
private:

View File

@@ -8,4 +8,4 @@ Anybody. As the OpenJPEG library is released under the BSD license, anybody can
Who is developing the library ?
===============================
The library is developed by the Communications and Remote Sensing Lab (TELE), in the Universit<69> Catholique de Louvain (UCL). The JPWL module is developed and maintained by the Digital Signal Processing Lab (DSPLab) of the University of Perugia, Italy (UNIPG). As our purpose is to make OpenJPEG really useful for those interested in the image compression field, any feedback/advices are obviously welcome ! We will do our best to handle them quickly.
The library is developed by the Communications and Remote Sensing Lab (TELE), in the Universit<69> Catholique de Louvain (UCL). The JPWL module is developped and maintained by the Digital Signal Processing Lab (DSPLab) of the University of Perugia, Italy (UNIPG). As our purpose is to make OpenJPEG really useful for those interested in the image compression field, any feedback/advices are obviously welcome ! We will do our best to handle them quickly.

View File

@@ -10,69 +10,37 @@ include_directories(
# Defines the source code for the library
set(OPENJPEG_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/bio.c
${CMAKE_CURRENT_SOURCE_DIR}/bio.h
${CMAKE_CURRENT_SOURCE_DIR}/cio.c
${CMAKE_CURRENT_SOURCE_DIR}/cio.h
${CMAKE_CURRENT_SOURCE_DIR}/dwt.c
${CMAKE_CURRENT_SOURCE_DIR}/dwt.h
${CMAKE_CURRENT_SOURCE_DIR}/event.c
${CMAKE_CURRENT_SOURCE_DIR}/event.h
${CMAKE_CURRENT_SOURCE_DIR}/image.c
${CMAKE_CURRENT_SOURCE_DIR}/image.h
${CMAKE_CURRENT_SOURCE_DIR}/invert.c
${CMAKE_CURRENT_SOURCE_DIR}/invert.h
${CMAKE_CURRENT_SOURCE_DIR}/j2k.c
${CMAKE_CURRENT_SOURCE_DIR}/j2k.h
${CMAKE_CURRENT_SOURCE_DIR}/jp2.c
${CMAKE_CURRENT_SOURCE_DIR}/jp2.h
${CMAKE_CURRENT_SOURCE_DIR}/mct.c
${CMAKE_CURRENT_SOURCE_DIR}/mct.h
${CMAKE_CURRENT_SOURCE_DIR}/mqc.c
${CMAKE_CURRENT_SOURCE_DIR}/mqc.h
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c
${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c
${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.h
${CMAKE_CURRENT_SOURCE_DIR}/pi.c
${CMAKE_CURRENT_SOURCE_DIR}/pi.h
${CMAKE_CURRENT_SOURCE_DIR}/raw.c
${CMAKE_CURRENT_SOURCE_DIR}/raw.h
${CMAKE_CURRENT_SOURCE_DIR}/t1.c
${CMAKE_CURRENT_SOURCE_DIR}/t1.h
${CMAKE_CURRENT_SOURCE_DIR}/t2.c
${CMAKE_CURRENT_SOURCE_DIR}/t2.h
${CMAKE_CURRENT_SOURCE_DIR}/tcd.c
${CMAKE_CURRENT_SOURCE_DIR}/tcd.h
${CMAKE_CURRENT_SOURCE_DIR}/tgt.c
${CMAKE_CURRENT_SOURCE_DIR}/tgt.h
${CMAKE_CURRENT_SOURCE_DIR}/function_list.c
${CMAKE_CURRENT_SOURCE_DIR}/function_list.h
${CMAKE_CURRENT_SOURCE_DIR}/opj_codec.h
${CMAKE_CURRENT_SOURCE_DIR}/opj_includes.h
${CMAKE_CURRENT_SOURCE_DIR}/opj_intmath.h
${CMAKE_CURRENT_SOURCE_DIR}/opj_malloc.c
${CMAKE_CURRENT_SOURCE_DIR}/opj_malloc.h
${CMAKE_CURRENT_SOURCE_DIR}/opj_stdint.h
)
if(BUILD_JPIP)
add_definitions(-DUSE_JPIP)
set(OPENJPEG_SRCS
${OPENJPEG_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/cidx_manager.c
${CMAKE_CURRENT_SOURCE_DIR}/cidx_manager.h
${CMAKE_CURRENT_SOURCE_DIR}/phix_manager.c
${CMAKE_CURRENT_SOURCE_DIR}/ppix_manager.c
${CMAKE_CURRENT_SOURCE_DIR}/thix_manager.c
${CMAKE_CURRENT_SOURCE_DIR}/tpix_manager.c
${CMAKE_CURRENT_SOURCE_DIR}/indexbox_manager.h
)
endif()
option(OPJ_DISABLE_TPSOT_FIX "Disable TPsot==TNsot fix. See https://github.com/uclouvain/openjpeg/issues/254." OFF)
if(OPJ_DISABLE_TPSOT_FIX)
add_definitions(-DOPJ_DISABLE_TPSOT_FIX)
endif()
# Build the library
if(WIN32)
if(BUILD_SHARED_LIBS)
@@ -86,9 +54,6 @@ if(UNIX)
target_link_libraries(${OPENJPEG_LIBRARY_NAME} m)
endif()
set_target_properties(${OPENJPEG_LIBRARY_NAME} PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
if(${CMAKE_VERSION} VERSION_GREATER "2.8.11")
target_compile_options(${OPENJPEG_LIBRARY_NAME} PRIVATE ${OPENJPEG_LIBRARY_COMPILE_OPTIONS})
endif()
# Install library
install(TARGETS ${OPENJPEG_LIBRARY_NAME}
@@ -136,9 +101,10 @@ endif()
if(OPJ_USE_DSYMUTIL)
if(BUILD_SHARED_LIBS)
GET_TARGET_PROPERTY(OPENJPEG_LIBRARY_LOCATION ${OPENJPEG_LIBRARY_NAME} LOCATION)
add_custom_command(TARGET ${OPENJPEG_LIBRARY_NAME} POST_BUILD
COMMAND "dsymutil" "$<TARGET_SONAME_FILE:${OPENJPEG_LIBRARY_NAME}>"
COMMENT "dsymutil $<TARGET_SONAME_FILE:${OPENJPEG_LIBRARY_NAME}>"
COMMAND "dsymutil" "${OPENJPEG_LIBRARY_LOCATION}"
COMMENT "dsymutil ${OPENJPEG_LIBRARY_LOCATION}"
DEPENDS ${OPENJPEG_LIBRARY_NAME})
endif()
endif()

View File

@@ -78,8 +78,7 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
==========================================================
*/
static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio)
{
OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
@@ -89,8 +88,7 @@ static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio)
return OPJ_TRUE;
}
static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio)
{
OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
@@ -100,8 +98,7 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio)
return OPJ_TRUE;
}
static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b)
{
void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) {
if (bio->ct == 0) {
opj_bio_byteout(bio); /* MSD: why not check the return value of this function ? */
}
@@ -109,8 +106,7 @@ static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b)
bio->buf |= b << bio->ct;
}
static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio)
{
OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) {
if (bio->ct == 0) {
opj_bio_bytein(bio); /* MSD: why not check the return value of this function ? */
}
@@ -124,26 +120,22 @@ static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio)
==========================================================
*/
opj_bio_t* opj_bio_create(void)
{
opj_bio_t* opj_bio_create(void) {
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
}
void opj_bio_destroy(opj_bio_t *bio)
{
void opj_bio_destroy(opj_bio_t *bio) {
if(bio) {
opj_free(bio);
}
}
ptrdiff_t opj_bio_numbytes(opj_bio_t *bio)
{
ptrdiff_t opj_bio_numbytes(opj_bio_t *bio) {
return (bio->bp - bio->start);
}
void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
{
void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
@@ -151,8 +143,7 @@ void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
bio->ct = 8;
}
void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
{
void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
@@ -160,16 +151,14 @@ void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
bio->ct = 0;
}
void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n)
{
void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) {
OPJ_UINT32 i;
for (i = n - 1; i < n; i--) {
opj_bio_putbit(bio, (v >> i) & 1);
}
}
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n)
{
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) {
OPJ_UINT32 i;
OPJ_UINT32 v;
v = 0;
@@ -179,12 +168,13 @@ OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n)
return v;
}
OPJ_BOOL opj_bio_flush(opj_bio_t *bio)
{
OPJ_BOOL opj_bio_flush(opj_bio_t *bio) {
bio->ct = 0;
if (! opj_bio_byteout(bio)) {
return OPJ_FALSE;
}
if (bio->ct == 7) {
bio->ct = 0;
if (! opj_bio_byteout(bio)) {
return OPJ_FALSE;
}
@@ -192,13 +182,13 @@ OPJ_BOOL opj_bio_flush(opj_bio_t *bio)
return OPJ_TRUE;
}
OPJ_BOOL opj_bio_inalign(opj_bio_t *bio)
{
OPJ_BOOL opj_bio_inalign(opj_bio_t *bio) {
bio->ct = 0;
if ((bio->buf & 0xff) == 0xff) {
if (! opj_bio_bytein(bio)) {
return OPJ_FALSE;
}
}
bio->ct = 0;
}
return OPJ_TRUE;
}

View File

@@ -219,8 +219,10 @@ OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, op
OPJ_OFF_T org_pos;
unsigned int Scod;
for(i = 0; i < marknum; i++) {
if( markers[i].type == J2K_MS_COD) {
for(i = 0; i < marknum; i++)
{
if( markers[i].type == J2K_MS_COD)
{
org_pos = opj_stream_tell(cio);
opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);

View File

@@ -46,7 +46,7 @@
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)+sizeof(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));
@@ -72,7 +72,7 @@ void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
*p_value = 0;
memcpy(l_data_ptr+sizeof(OPJ_UINT32)-p_nb_bytes,p_buffer,p_nb_bytes);
memcpy(l_data_ptr+4-p_nb_bytes,p_buffer,p_nb_bytes);
}
void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes)
@@ -166,11 +166,12 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l
l_stream->m_current_data = l_stream->m_stored_data;
if (l_is_input) {
l_stream->m_status |= OPJ_STREAM_STATUS_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_STATUS_OUTPUT;
}
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;
}
@@ -206,7 +207,7 @@ void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_strea
{
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if ((!l_stream) || (! (l_stream->m_status & OPJ_STREAM_STATUS_INPUT))) {
if ((!l_stream) || (! (l_stream->m_status & opj_stream_e_input))) {
return;
}
@@ -227,7 +228,7 @@ void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stre
{
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if ((!l_stream )|| (! (l_stream->m_status & OPJ_STREAM_STATUS_OUTPUT))) {
if ((!l_stream )|| (! (l_stream->m_status & opj_stream_e_output))) {
return;
}
@@ -275,7 +276,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
}
/* we are now in the case when the remaining data if not sufficient */
if (p_stream->m_status & OPJ_STREAM_STATUS_END) {
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;
@@ -293,14 +294,15 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0;
} else {
}
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;
}
for (;;) {
while(1){
/* 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 */
@@ -311,10 +313,11 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
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_STATUS_END;
p_stream->m_status |= opj_stream_e_end;
/* end of stream */
return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1;
} else if (p_stream->m_bytes_in_buffer < p_size) {
}
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);
@@ -323,7 +326,8 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0;
} else {
}
else {
l_read_nb_bytes += p_size;
memcpy(p_buffer,p_stream->m_current_data,p_size);
p_stream->m_current_data += p_size;
@@ -331,7 +335,8 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_stream->m_byte_offset += (OPJ_OFF_T)p_size;
return l_read_nb_bytes;
}
} else {
}
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);
@@ -340,10 +345,11 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
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_STATUS_END;
p_stream->m_status |= opj_stream_e_end;
/* end of stream */
return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1;
} else if (p_stream->m_bytes_in_buffer < p_size) {
}
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;
@@ -351,7 +357,8 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0;
} else {
}
else {
/* we have read the exact size */
l_read_nb_bytes += p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
@@ -371,11 +378,11 @@ OPJ_SIZE_T opj_stream_write_data (opj_stream_private_t * p_stream,
OPJ_SIZE_T l_remaining_bytes = 0;
OPJ_SIZE_T l_write_nb_bytes = 0;
if (p_stream->m_status & OPJ_STREAM_STATUS_ERROR) {
if (p_stream->m_status & opj_stream_e_error) {
return (OPJ_SIZE_T)-1;
}
for (;;) {
while(1) {
l_remaining_bytes = p_stream->m_buffer_size - p_stream->m_bytes_in_buffer;
/* we have more memory than required */
@@ -425,7 +432,7 @@ OPJ_BOOL opj_stream_flush (opj_stream_private_t * p_stream, opj_event_mgr_t * p_
p_stream->m_user_data);
if (l_current_write_nb_bytes == (OPJ_SIZE_T)-1) {
p_stream->m_status |= OPJ_STREAM_STATUS_ERROR;
p_stream->m_status |= opj_stream_e_error;
opj_event_msg(p_event_mgr, EVT_INFO, "Error on writing stream!\n");
return OPJ_FALSE;
@@ -458,7 +465,7 @@ OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
}
/* we are now in the case when the remaining data if not sufficient */
if (p_stream->m_status & OPJ_STREAM_STATUS_END) {
if (p_stream->m_status & opj_stream_e_end) {
l_skip_nb_bytes += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_current_data += p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0;
@@ -480,7 +487,7 @@ OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
if (l_current_skip_nb_bytes == (OPJ_OFF_T) -1) {
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
p_stream->m_status |= OPJ_STREAM_STATUS_END;
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_OFF_T) -1;
@@ -500,14 +507,14 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si
OPJ_OFF_T l_current_skip_nb_bytes = 0;
OPJ_OFF_T l_skip_nb_bytes = 0;
if (p_stream->m_status & OPJ_STREAM_STATUS_ERROR) {
if (p_stream->m_status & opj_stream_e_error) {
return (OPJ_OFF_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_STATUS_ERROR;
p_stream->m_status |= opj_stream_e_error;
p_stream->m_bytes_in_buffer = 0;
return (OPJ_OFF_T) -1;
}
@@ -520,7 +527,7 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si
if (l_current_skip_nb_bytes == (OPJ_OFF_T)-1) {
opj_event_msg(p_event_mgr, EVT_INFO, "Stream error!\n");
p_stream->m_status |= OPJ_STREAM_STATUS_ERROR;
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_OFF_T)-1;
@@ -561,11 +568,12 @@ OPJ_BOOL opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size
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_STATUS_END;
p_stream->m_status |= opj_stream_e_end;
return OPJ_FALSE;
} else {
}
else {
/* reset stream status */
p_stream->m_status &= (~OPJ_STREAM_STATUS_END);
p_stream->m_status &= (~opj_stream_e_end);
p_stream->m_byte_offset = p_size;
}
@@ -576,7 +584,7 @@ OPJ_BOOL opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size
OPJ_BOOL opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_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_STATUS_ERROR;
p_stream->m_status |= opj_stream_e_error;
return OPJ_FALSE;
}
@@ -584,9 +592,10 @@ OPJ_BOOL opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
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_STATUS_ERROR;
p_stream->m_status |= opj_stream_e_error;
return OPJ_FALSE;
} else {
}
else {
p_stream->m_byte_offset = p_size;
}

View File

@@ -70,15 +70,22 @@ The functions in CIO.C have for goal to realize a byte input / output process.
#endif
#define OPJ_STREAM_STATUS_OUTPUT 0x1U
#define OPJ_STREAM_STATUS_INPUT 0x2U
#define OPJ_STREAM_STATUS_END 0x4U
#define OPJ_STREAM_STATUS_ERROR 0x8U
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,
opj_stream_e_error = 0x8
}
opj_stream_flag ;
/**
Byte input-output stream.
*/
typedef struct opj_stream_private {
typedef struct opj_stream_private
{
/**
* User data, be it files, ... The actual data depends on the type of the stream.
*/
@@ -155,9 +162,8 @@ typedef struct opj_stream_private {
/**
* Flags to tell the status of the stream.
* Used with OPJ_STREAM_STATUS_* defines.
*/
OPJ_UINT32 m_status;
opj_stream_flag m_status;
}
opj_stream_private_t;
@@ -178,7 +184,7 @@ void opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_n
* @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 occurred.
* @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);
@@ -187,7 +193,7 @@ void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT
* @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 occurred
* @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);
@@ -196,7 +202,7 @@ void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_n
* @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 occurred.
* @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);
@@ -263,7 +269,7 @@ void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value);
* @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 occurred or if the stream is at the end.
* @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);
@@ -273,7 +279,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
* @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 occurred.
* @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);
@@ -290,7 +296,7 @@ OPJ_BOOL opj_stream_flush (opj_stream_private_t * p_stream, struct opj_event_mgr
* @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 occurred.
* @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);
@@ -318,7 +324,7 @@ OPJ_OFF_T opj_stream_get_number_byte_left (const opj_stream_private_t * p_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 occurred.
* @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);
@@ -327,7 +333,7 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si
* @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 occurred.
* @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);
@@ -336,7 +342,7 @@ OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
* @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 occurred.
* @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);
@@ -345,7 +351,7 @@ OPJ_BOOL opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size
* @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 occurred.
* @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);

View File

@@ -193,8 +193,7 @@ static const OPJ_FLOAT64 opj_dwt_norms_real[4][10] = {
/* <summary> */
/* Forward lazy transform (horizontal). */
/* </summary> */
static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
void opj_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;
@@ -216,8 +215,7 @@ static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ
/* <summary> */
/* Forward lazy transform (vertical). */
/* </summary> */
static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas)
{
void opj_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;
@@ -242,8 +240,7 @@ static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ
/* <summary> */
/* Inverse lazy transform (horizontal). */
/* </summary> */
static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a)
{
void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) {
OPJ_INT32 *ai = a;
OPJ_INT32 *bi = h->mem + h->cas;
OPJ_INT32 i = h->sn;
@@ -263,8 +260,7 @@ static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a)
/* <summary> */
/* Inverse lazy transform (vertical). */
/* </summary> */
static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x)
{
void opj_dwt_interleave_v(opj_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;
@@ -287,8 +283,7 @@ static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x)
/* <summary> */
/* Forward 5-3 wavelet transform in 1-D. */
/* </summary> */
static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
OPJ_INT32 i;
if (!cas) {
@@ -309,8 +304,7 @@ static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32
/* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */
/* </summary> */
static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) {
OPJ_INT32 i;
if (!cas) {
@@ -331,16 +325,14 @@ static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT3
/* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */
/* </summary> */
static void opj_dwt_decode_1(opj_dwt_t *v)
{
void opj_dwt_decode_1(opj_dwt_t *v) {
opj_dwt_decode_1_(v->mem, v->dn, v->sn, v->cas);
}
/* <summary> */
/* Forward 9-7 wavelet transform in 1-D. */
/* </summary> */
static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
void opj_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 */
@@ -375,8 +367,7 @@ static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_
}
}
static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize)
{
void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize) {
OPJ_INT32 p, n;
p = opj_int_floorlog2(stepsize) - 13;
n = 11 - opj_int_floorlog2(stepsize);
@@ -394,7 +385,7 @@ static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_st
/* <summary> */
/* Forward 5-3 wavelet transform in 2-D. */
/* </summary> */
static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_function)(OPJ_INT32 *, OPJ_INT32,OPJ_INT32,OPJ_INT32) )
INLINE OPJ_BOOL opj_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;
@@ -418,9 +409,7 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void
l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32);
bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size);
/* l_data_size is equal to 0 when numresolutions == 1 but bj is not used */
/* in that case, so do not error out */
if (l_data_size != 0 && ! bj) {
if (! bj) {
return OPJ_FALSE;
}
i = l;
@@ -482,8 +471,7 @@ OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec)
/* <summary> */
/* Inverse 5-3 wavelet transform in 2-D. */
/* </summary> */
OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres)
{
OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres) {
return opj_dwt_decode_tile(tilec, numres, &opj_dwt_decode_1);
}
@@ -491,8 +479,7 @@ OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres)
/* <summary> */
/* Get gain of 5-3 wavelet transform. */
/* </summary> */
OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient)
{
OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient) {
if (orient == 0)
return 0;
if (orient == 1 || orient == 2)
@@ -503,8 +490,7 @@ OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient)
/* <summary> */
/* Get norm of 5-3 wavelet. */
/* </summary> */
OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient)
{
OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient) {
return opj_dwt_norms[orient][level];
}
@@ -519,8 +505,7 @@ OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec)
/* <summary> */
/* Get gain of 9-7 wavelet transform. */
/* </summary> */
OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient)
{
OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient) {
(void)orient;
return 0;
}
@@ -528,13 +513,11 @@ OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient)
/* <summary> */
/* Get norm of 9-7 wavelet. */
/* </summary> */
OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient)
{
OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient) {
return opj_dwt_norms_real[orient][level];
}
void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec)
{
void opj_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++) {
@@ -558,8 +541,7 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec)
/* <summary> */
/* Determine maximum computed resolution level for inverse wavelet transform */
/* </summary> */
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i)
{
OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i) {
OPJ_UINT32 mr = 0;
OPJ_UINT32 w;
while( --i ) {
@@ -575,8 +557,7 @@ static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_U
/* <summary> */
/* Inverse wavelet transform in 2-D. */
/* </summary> */
static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D)
{
OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D) {
opj_dwt_t h;
opj_dwt_t v;
@@ -587,10 +568,8 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres
OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
if (numres == 1U) {
return OPJ_TRUE;
}
h.mem = (OPJ_INT32*)opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
h.mem = (OPJ_INT32*)
opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
if (! h.mem){
/* FIXME event manager error callback */
return OPJ_FALSE;
@@ -634,8 +613,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres
return OPJ_TRUE;
}
static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OPJ_INT32 x, OPJ_INT32 size)
{
void opj_v4dwt_interleave_h(opj_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;
@@ -653,7 +631,8 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restric
j += x;
bi[i*8 + 3] = a[j];
}
} else {
}
else {
/* Slow code path */
for(i = 0; i < count; ++i){
OPJ_INT32 j = i;
@@ -677,8 +656,7 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restric
}
}
static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read)
{
void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read){
opj_v4_t* restrict bi = v->wavelet + v->cas;
OPJ_INT32 i;
@@ -696,8 +674,7 @@ static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restri
#ifdef __SSE__
static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c)
{
void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c){
__m128* restrict vw = (__m128*) w;
OPJ_INT32 i;
/* 4x unrolled loop */
@@ -718,8 +695,7 @@ static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m12
}
}
void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, __m128 c)
{
void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, __m128 c){
__m128* restrict vl = (__m128*) l;
__m128* restrict vw = (__m128*) w;
OPJ_INT32 i;
@@ -747,7 +723,7 @@ void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32
#else
static void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT32 c)
void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT32 c)
{
OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w;
OPJ_INT32 i;
@@ -763,10 +739,10 @@ static void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT
}
}
static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, OPJ_FLOAT32 c)
void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, OPJ_FLOAT32 c)
{
OPJ_FLOAT32* fl = (OPJ_FLOAT32*) l;
OPJ_FLOAT32* fw = (OPJ_FLOAT32*) w;
OPJ_FLOAT32* restrict fl = (OPJ_FLOAT32*) l;
OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w;
OPJ_INT32 i;
for(i = 0; i < m; ++i){
OPJ_FLOAT32 tmp1_1 = fl[0];
@@ -817,7 +793,7 @@ static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_IN
/* <summary> */
/* Inverse 9-7 wavelet transform in 1-D. */
/* </summary> */
static void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt)
void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt)
{
OPJ_INT32 a, b;
if(dwt->cas == 0) {
@@ -912,12 +888,9 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
opj_v4dwt_decode(&h);
for(k = (OPJ_INT32)rw; --k >= 0;){
switch(j) {
case 3:
aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2];
case 2:
aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1];
case 1:
aj[k ] = h.wavelet[k].f[0];
case 3: aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2];
case 2: aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1];
case 1: aj[k ] = h.wavelet[k].f[0];
}
}
}

View File

@@ -54,14 +54,14 @@ DWT.C are used by some function in TCD.C.
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Forward 5-3 wavelet transform in 2-D.
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);
/**
Inverse 5-3 wavelet transform in 2-D.
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

View File

@@ -40,8 +40,7 @@
#ifdef OPJ_CODE_NOT_USED
#ifndef _WIN32
static char*
i2a(unsigned i, char *a, unsigned r)
{
i2a(unsigned i, char *a, unsigned r) {
if (i/r > 0) a = i2a(i/r,a,r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1;
@@ -56,13 +55,13 @@ i2a(unsigned i, char *a, unsigned r)
@return Returns a
*/
static char *
_itoa(int i, char *a, int r)
{
_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;
}
else *i2a(i, a, r) = 0;
return a;
}
@@ -84,8 +83,7 @@ static void opj_default_callback (const char *msg, void *client_data)
/* ----------------------------------------------------------------------- */
OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...)
{
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 */
opj_msg_callback msg_handler = 00;
void * l_data = 00;

View File

@@ -47,7 +47,8 @@ used for
<li>Debugging messages
</ul>
*/
typedef struct opj_event_mgr {
typedef struct opj_event_mgr
{
/** Data to call the event manager upon */
void * m_error_data;
/** Data to call the event manager upon */
@@ -94,12 +95,6 @@ OPJ_BOOL opj_event_msg(opj_event_mgr_t* event_mgr, OPJ_INT32 event_type, const c
*/
void opj_set_default_event_handler(opj_event_mgr_t * p_manager);
/*
#ifdef __GNUC__
#pragma GCC poison printf fprintf
#endif
*/
/*@}*/
/*@}*/

View File

@@ -40,13 +40,15 @@ opj_procedure_list_t * opj_procedure_list_create()
{
/* memory allocation */
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
if (! l_validation) {
if (! l_validation)
{
return 00;
}
/* initialization */
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
if (! l_validation->m_procedures) {
if (! l_validation->m_procedures)
{
opj_free(l_validation);
return 00;
}
@@ -55,35 +57,40 @@ opj_procedure_list_t * opj_procedure_list_create()
void opj_procedure_list_destroy(opj_procedure_list_t * p_list)
{
if (! p_list) {
if (! p_list)
{
return;
}
/* initialization */
if (p_list->m_procedures) {
if (p_list->m_procedures)
{
opj_free(p_list->m_procedures);
}
opj_free(p_list);
}
OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure, opj_event_mgr_t* p_manager )
OPJ_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)
{
assert(p_manager != NULL);
if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures) {
opj_procedure * new_procedures;
p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE;
new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_procedures,
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
if (! new_procedures) {
if (! new_procedures)
{
opj_free(p_validation_list->m_procedures);
p_validation_list->m_nb_max_procedures = 0;
p_validation_list->m_nb_procedures = 0;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n");
/* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n"); */
fprintf(stderr, "Not enough memory to add a new validation procedure\n");
return OPJ_FALSE;
} else {
}
else
{
p_validation_list->m_procedures = new_procedures;
}
}

View File

@@ -54,7 +54,8 @@ typedef void (*opj_procedure)(void);
/**
* A list of procedures.
*/
typedef struct opj_procedure_list {
typedef struct opj_procedure_list
{
/**
* The number of validation procedures.
*/
@@ -94,7 +95,7 @@ void opj_procedure_list_destroy(opj_procedure_list_t * p_list);
*
* @return OPJ_TRUE if the procedure could be added.
*/
OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure, opj_event_mgr_t* p_manager);
OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure);
/**
* Gets the number of validation procedures.

View File

@@ -31,14 +31,12 @@
#include "opj_includes.h"
opj_image_t* opj_image_create0(void)
{
opj_image_t* opj_image_create0(void) {
opj_image_t *image = (opj_image_t*)opj_calloc(1, 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_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 = NULL;
@@ -49,8 +47,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptpa
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t));
if(!image->comps) {
/* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */
fprintf(stderr,"Unable to allocate memory for image.\n");
opj_image_destroy(image);
return NULL;
}
@@ -68,8 +65,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptpa
comp->sgnd = cmptparms[compno].sgnd;
comp->data = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32));
if(!comp->data) {
/* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */
fprintf(stderr,"Unable to allocate memory for image.\n");
opj_image_destroy(image);
return NULL;
}
@@ -79,8 +75,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptpa
return image;
}
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image)
{
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
if(image) {
if(image->comps) {
OPJ_UINT32 compno;
@@ -112,29 +107,27 @@ void OPJ_CALLCONV opj_image_destroy(opj_image_t *image)
void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj_cp * p_cp)
{
OPJ_UINT32 i, l_width, l_height;
OPJ_UINT32 l_x0, l_y0, l_x1, l_y1;
OPJ_UINT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1;
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 = NULL;
l_x0 = opj_uint_max(p_cp->tx0 , p_image_header->x0);
l_y0 = opj_uint_max(p_cp->ty0 , p_image_header->y0);
l_x1 = p_cp->tx0 + (p_cp->tw - 1U) * p_cp->tdx; /* validity of p_cp members used here checked in opj_j2k_read_siz. Can't overflow. */
l_y1 = p_cp->ty0 + (p_cp->th - 1U) * p_cp->tdy; /* can't overflow */
l_x1 = opj_uint_min(opj_uint_adds(l_x1, p_cp->tdx), p_image_header->x1); /* use add saturated to prevent overflow */
l_y1 = opj_uint_min(opj_uint_adds(l_y1, p_cp->tdy), p_image_header->y1); /* use add saturated to prevent overflow */
l_x0 = opj_int_max((OPJ_INT32)p_cp->tx0 , (OPJ_INT32)p_image_header->x0);
l_y0 = opj_int_max((OPJ_INT32)p_cp->ty0 , (OPJ_INT32)p_image_header->y0);
l_x1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + p_cp->tw * p_cp->tdx), (OPJ_INT32)p_image_header->x1);
l_y1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + p_cp->th * p_cp->tdy), (OPJ_INT32)p_image_header->y1);
l_img_comp = p_image_header->comps;
for (i = 0; i < p_image_header->numcomps; ++i) {
l_comp_x0 = opj_uint_ceildiv(l_x0, l_img_comp->dx);
l_comp_y0 = opj_uint_ceildiv(l_y0, l_img_comp->dy);
l_comp_x1 = opj_uint_ceildiv(l_x1, l_img_comp->dx);
l_comp_y1 = opj_uint_ceildiv(l_y1, l_img_comp->dy);
l_width = opj_uint_ceildivpow2(l_comp_x1 - l_comp_x0, l_img_comp->factor);
l_height = opj_uint_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor);
l_comp_x0 = opj_int_ceildiv(l_x0, (OPJ_INT32)l_img_comp->dx);
l_comp_y0 = opj_int_ceildiv(l_y0, (OPJ_INT32)l_img_comp->dy);
l_comp_x1 = opj_int_ceildiv(l_x1, (OPJ_INT32)l_img_comp->dx);
l_comp_y1 = opj_int_ceildiv(l_y1, (OPJ_INT32)l_img_comp->dy);
l_width = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_x1 - l_comp_x0, (OPJ_INT32)l_img_comp->factor);
l_height = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_y1 - l_comp_y0, (OPJ_INT32)l_img_comp->factor);
l_img_comp->w = l_width;
l_img_comp->h = l_height;
l_img_comp->x0 = l_comp_x0;
l_img_comp->y0 = l_comp_y0;
l_img_comp->x0 = (OPJ_UINT32)l_comp_x0/*l_x0*/;
l_img_comp->y0 = (OPJ_UINT32)l_comp_y0/*l_y0*/;
++l_img_comp;
}
}
@@ -201,19 +194,20 @@ void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_
memcpy( p_image_dest->icc_profile_buf,
p_image_src->icc_profile_buf,
p_image_src->icc_profile_len);
} else
}
else
p_image_dest->icc_profile_buf = NULL;
return;
}
opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
{
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_calloc(1,sizeof(opj_image_t));
if (image) {
if (image)
{
image->color_space = clrspc;
image->numcomps = numcmpts;

View File

@@ -108,7 +108,7 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
opj_event_mgr_t * p_manager );
/*
* Write manifest box (box)
* Wriet manifest box (box)
*
* @param[in] second number to be visited
* @param[in] v number of boxes

View File

@@ -103,7 +103,7 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
Local functions
==========================================================
*/
static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations,
OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations,
OPJ_FLOAT32 * p_swap_area,
OPJ_UINT32 nb_compo)
{
@@ -121,10 +121,11 @@ static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations,
OPJ_UINT32 lStride = nb_compo-1;
/*initialize permutations */
for (i = 0; i < nb_compo; ++i) {
for (i = 0; i < nb_compo; ++i)
{
*tmpPermutations++ = i;
}
/* now make a pivot with column switch */
/* now make a pivot with colum switch */
tmpPermutations = permutations;
for (k = 0; k < lLastColum; ++k) {
p = 0.0;
@@ -203,7 +204,7 @@ static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations,
return OPJ_TRUE;
}
static void opj_lupSolve (OPJ_FLOAT32 * pResult,
void opj_lupSolve (OPJ_FLOAT32 * pResult,
OPJ_FLOAT32 * pMatrix,
OPJ_FLOAT32 * pVector,
OPJ_UINT32* pPermutations,
@@ -231,7 +232,8 @@ static void opj_lupSolve (OPJ_FLOAT32 * pResult,
sum = 0.0;
lCurrentPtr = p_intermediate_data;
lTmpMatrix = lLineMatrix;
for (j = 1; j <= i; ++j) {
for (j = 1; j <= i; ++j)
{
/* sum += matrix[i][j-1] * y[j-1]; */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
}
@@ -264,7 +266,7 @@ static void opj_lupSolve (OPJ_FLOAT32 * pResult,
}
static void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix,
void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo,
OPJ_UINT32 * pPermutations,

File diff suppressed because it is too large Load Diff

View File

@@ -132,7 +132,8 @@ typedef enum J2K_STATUS {
/**
* Type of elements storing in the MCT data
*/
typedef enum MCT_ELEMENT_TYPE {
typedef enum MCT_ELEMENT_TYPE
{
MCT_TYPE_INT16 = 0, /** MCT data is stored as signed shorts*/
MCT_TYPE_INT32 = 1, /** MCT data is stored as signed integers*/
MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/
@@ -142,7 +143,8 @@ typedef enum MCT_ELEMENT_TYPE {
/**
* Type of MCT array
*/
typedef enum MCT_ARRAY_TYPE {
typedef enum MCT_ARRAY_TYPE
{
MCT_TYPE_DEPENDENCY = 0,
MCT_TYPE_DECORRELATION = 1,
MCT_TYPE_OFFSET = 2
@@ -171,7 +173,8 @@ typedef struct opj_stepsize {
/**
Tile-component coding parameters
*/
typedef struct opj_tccp {
typedef struct opj_tccp
{
/** coding style */
OPJ_UINT32 csty;
/** number of resolutions */
@@ -206,7 +209,8 @@ opj_tccp_t;
/**
* FIXME DOC
*/
typedef struct opj_mct_data {
typedef struct opj_mct_data
{
J2K_MCT_ELEMENT_TYPE m_element_type;
J2K_MCT_ARRAY_TYPE m_array_type;
OPJ_UINT32 m_index;
@@ -218,7 +222,8 @@ opj_mct_data_t;
/**
* FIXME DOC
*/
typedef struct opj_simple_mcc_decorrelation_data {
typedef struct opj_simple_mcc_decorrelation_data
{
OPJ_UINT32 m_index;
OPJ_UINT32 m_nb_comps;
opj_mct_data_t * m_decorrelation_array;
@@ -227,17 +232,13 @@ typedef struct opj_simple_mcc_decorrelation_data {
}
opj_simple_mcc_decorrelation_data_t;
typedef struct opj_ppx_struct {
OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */
OPJ_UINT32 m_data_size;
} opj_ppx;
/**
Tile coding parameters :
this structure is used to store coding/decoding parameters common to all
tiles (information like COD, COC in main header)
*/
typedef struct opj_tcp {
typedef struct opj_tcp
{
/** coding style */
OPJ_UINT32 csty;
/** progression order */
@@ -253,13 +254,7 @@ typedef struct opj_tcp {
OPJ_UINT32 numpocs;
/** progression order changes */
opj_poc_t pocs[32];
/** number of ppt markers (reserved size) */
OPJ_UINT32 ppt_markers_count;
/** ppt markers data (table indexed by Zppt) */
opj_ppx* ppt_markers;
/** packet header store there for future use in t2_decode_packet */
/** packet header store there for futur use in t2_decode_packet */
OPJ_BYTE *ppt_data;
/** used to keep a track of the allocated memory */
OPJ_BYTE *ppt_buffer;
@@ -298,8 +293,6 @@ typedef struct opj_tcp {
/***** FLAGS *******/
/** If cod == 1 --> there was a COD marker for the present tile */
OPJ_UINT32 cod : 1;
/** If ppt == 1 --> there was a PPT marker for the present tile */
OPJ_UINT32 ppt : 1;
/** indicates if a POC marker has been used O:NO, 1:YES */
@@ -309,7 +302,8 @@ typedef struct opj_tcp {
typedef struct opj_encoding_param {
typedef struct opj_encoding_param
{
/** Maximum rate for each component. If == 0, component size limitation is not considered */
OPJ_UINT32 m_max_comp_size;
/** Position of tile part flag in progression order*/
@@ -329,7 +323,8 @@ typedef struct opj_encoding_param {
}
opj_encoding_param_t;
typedef struct opj_decoding_param {
typedef struct opj_decoding_param
{
/** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */
OPJ_UINT32 m_reduce;
/** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
@@ -341,7 +336,8 @@ opj_decoding_param_t;
/**
* Coding parameters
*/
typedef struct opj_cp {
typedef struct opj_cp
{
/** Size of the image in bits*/
/*int img_size;*/
/** Rsiz*/
@@ -361,12 +357,7 @@ typedef struct opj_cp {
/** number of tiles in heigth */
OPJ_UINT32 th;
/** number of ppm markers (reserved size) */
OPJ_UINT32 ppm_markers_count;
/** ppm markers data (table indexed by Zppm) */
opj_ppx* ppm_markers;
/** packet header store there for future use in t2_decode_packet */
/** packet header store there for futur use in t2_decode_packet */
OPJ_BYTE *ppm_data;
/** size of the ppm_data*/
OPJ_UINT32 ppm_len;
@@ -389,7 +380,8 @@ typedef struct opj_cp {
/** tile coding parameters */
opj_tcp_t *tcps;
union {
union
{
opj_decoding_param_t m_dec;
opj_encoding_param_t m_enc;
}
@@ -449,7 +441,8 @@ typedef struct opj_cp {
} opj_cp_t;
typedef struct opj_j2k_dec {
typedef struct opj_j2k_dec
{
/** locate in which part of the codestream the decoder is (main header, tile header, end) */
OPJ_UINT32 m_state;
/**
@@ -488,13 +481,11 @@ typedef struct opj_j2k_dec {
OPJ_UINT32 m_can_decode : 1;
OPJ_UINT32 m_discard_tiles : 1;
OPJ_UINT32 m_skip_data : 1;
/** TNsot correction : see issue 254 **/
OPJ_UINT32 m_nb_tile_parts_correction_checked : 1;
OPJ_UINT32 m_nb_tile_parts_correction : 1;
} opj_j2k_dec_t;
typedef struct opj_j2k_enc {
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 */
@@ -540,12 +531,14 @@ struct opj_tcd;
/**
JPEG-2000 codestream reader/writer
*/
typedef struct opj_j2k {
typedef struct opj_j2k
{
/* J2K codestream is decoded*/
OPJ_BOOL m_is_decoder;
/* FIXME DOC*/
union {
union
{
opj_j2k_dec_t m_decoder;
opj_j2k_enc_t m_encoder;
}
@@ -574,6 +567,7 @@ typedef struct opj_j2k {
/** the current tile coder/decoder **/
struct opj_tcd * m_tcd;
}
opj_j2k_t;

File diff suppressed because it is too large Load Diff

View File

@@ -70,7 +70,8 @@
/* ----------------------------------------------------------------------- */
typedef enum {
typedef enum
{
JP2_STATE_NONE = 0x0,
JP2_STATE_SIGNATURE = 0x1,
JP2_STATE_FILE_TYPE = 0x2,
@@ -81,23 +82,26 @@ typedef enum {
}
JP2_STATE;
typedef enum {
typedef enum
{
JP2_IMG_STATE_NONE = 0x0,
JP2_IMG_STATE_UNKNOWN = 0x7fffffff
}
JP2_IMG_STATE;
/**
Channel description: channel index, type, association
Channel description: channel index, type, assocation
*/
typedef struct opj_jp2_cdef_info {
typedef struct opj_jp2_cdef_info
{
OPJ_UINT16 cn, typ, asoc;
} opj_jp2_cdef_info_t;
/**
Channel descriptions and number of descriptions
*/
typedef struct opj_jp2_cdef {
typedef struct opj_jp2_cdef
{
opj_jp2_cdef_info_t *info;
OPJ_UINT16 n;
} opj_jp2_cdef_t;
@@ -105,7 +109,8 @@ typedef struct opj_jp2_cdef {
/**
Component mappings: channel index, mapping type, palette index
*/
typedef struct opj_jp2_cmap_comp {
typedef struct opj_jp2_cmap_comp
{
OPJ_UINT16 cmp;
OPJ_BYTE mtyp, pcol;
} opj_jp2_cmap_comp_t;
@@ -113,7 +118,8 @@ typedef struct opj_jp2_cmap_comp {
/**
Palette data: table entries, palette columns
*/
typedef struct opj_jp2_pclr {
typedef struct opj_jp2_pclr
{
OPJ_UINT32 *entries;
OPJ_BYTE *channel_sign;
OPJ_BYTE *channel_size;
@@ -125,7 +131,8 @@ typedef struct opj_jp2_pclr {
/**
Collector for ICC profile, palette, component mapping, channel description
*/
typedef struct opj_jp2_color {
typedef struct opj_jp2_color
{
OPJ_BYTE *icc_profile_buf;
OPJ_UINT32 icc_profile_len;
@@ -146,7 +153,8 @@ typedef struct opj_jp2_comps {
/**
JPEG-2000 file format reader/writer
*/
typedef struct opj_jp2 {
typedef struct opj_jp2
{
/** handle to the J2K codec */
opj_j2k_t *j2k;
/** list of validation procedures */
@@ -199,7 +207,8 @@ typedef struct opj_jp2_box {
OPJ_INT32 init_pos;
} opj_jp2_box_t;
typedef struct opj_jp2_header_handler {
typedef struct opj_jp2_header_handler
{
/* marker value */
OPJ_UINT32 id;
/* action linked to the marker */
@@ -211,7 +220,8 @@ typedef struct opj_jp2_header_handler {
opj_jp2_header_handler_t;
typedef struct opj_jp2_img_header_writer_handler {
typedef struct opj_jp2_img_header_writer_handler
{
/* action to perform */
OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size);
/* result of the action : data */
@@ -225,6 +235,19 @@ opj_jp2_img_header_writer_handler_t;
/*@{*/
/* ----------------------------------------------------------------------- */
/**
* Writes the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
*
* @param jp2 the jpeg2000 file codec.
* @param stream the stream to write data to.
* @param p_manager user event manager.
*
* @return true if writing was successful.
*/
OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
opj_stream_private_t *stream,
opj_event_mgr_t * p_manager );
/**
Setup the decoder decoding parameters using user parameters.
Decoding parameters are returned in jp2->j2k->cp.

View File

@@ -40,12 +40,6 @@
#ifdef __SSE__
#include <xmmintrin.h>
#endif
#ifdef __SSE2__
#include <emmintrin.h>
#endif
#ifdef __SSE4_1__
#include <smmintrin.h>
#endif
#include "opj_includes.h"
@@ -70,39 +64,16 @@ const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
}
/* <summary> */
/* Forward reversible MCT. */
/* Foward reversible MCT. */
/* </summary> */
#ifdef __SSE2__
void opj_mct_encode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
/* buffer are aligned on 16 bytes */
assert( ((size_t)c0 & 0xf) == 0 );
assert( ((size_t)c1 & 0xf) == 0 );
assert( ((size_t)c2 & 0xf) == 0 );
for(i = 0; i < (len & ~3U); i += 4) {
__m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
y = _mm_add_epi32(g, g);
y = _mm_add_epi32(y, b);
y = _mm_add_epi32(y, r);
y = _mm_srai_epi32(y, 2);
u = _mm_sub_epi32(b, g);
v = _mm_sub_epi32(r, g);
_mm_store_si128((__m128i *)&(c0[i]), y);
_mm_store_si128((__m128i *)&(c1[i]), u);
_mm_store_si128((__m128i *)&(c2[i]), v);
}
for(; i < len; ++i) {
OPJ_UINT32 i;
for(i = 0; i < n; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i];
@@ -114,69 +85,10 @@ void opj_mct_encode(
c2[i] = v;
}
}
#else
void opj_mct_encode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
for(i = 0; i < len; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g;
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
#endif
/* <summary> */
/* Inverse reversible MCT. */
/* </summary> */
#ifdef __SSE2__
void opj_mct_decode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
for(i = 0; i < (len & ~3U); i += 4) {
__m128i r, g, b;
__m128i y = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i u = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i v = _mm_load_si128((const __m128i *)&(c2[i]));
g = y;
g = _mm_sub_epi32(g, _mm_srai_epi32(_mm_add_epi32(u, v), 2));
r = _mm_add_epi32(v, g);
b = _mm_add_epi32(u, g);
_mm_store_si128((__m128i *)&(c0[i]), r);
_mm_store_si128((__m128i *)&(c1[i]), g);
_mm_store_si128((__m128i *)&(c2[i]), b);
}
for (; i < len; ++i) {
OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g;
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
#else
void opj_mct_decode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
@@ -196,161 +108,17 @@ void opj_mct_decode(
c2[i] = b;
}
}
#endif
/* <summary> */
/* Get norm of basis function of reversible MCT. */
/* </summary> */
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno)
{
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
return opj_mct_norms[compno];
}
/* <summary> */
/* Forward irreversible MCT. */
/* Foward irreversible MCT. */
/* </summary> */
#ifdef __SSE4_1__
void opj_mct_encode_real(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
const __m128i ry = _mm_set1_epi32(2449);
const __m128i gy = _mm_set1_epi32(4809);
const __m128i by = _mm_set1_epi32(934);
const __m128i ru = _mm_set1_epi32(1382);
const __m128i gu = _mm_set1_epi32(2714);
/* const __m128i bu = _mm_set1_epi32(4096); */
/* const __m128i rv = _mm_set1_epi32(4096); */
const __m128i gv = _mm_set1_epi32(3430);
const __m128i bv = _mm_set1_epi32(666);
const __m128i mulround = _mm_shuffle_epi32(_mm_cvtsi32_si128(4096), _MM_SHUFFLE(1, 0, 1, 0));
for(i = 0; i < (len & ~3U); i += 4) {
__m128i lo, hi;
__m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ry);
hi = _mm_mul_epi32(hi, ry);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
y = _mm_blend_epi16(lo, hi, 0xCC);
lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gy);
hi = _mm_mul_epi32(hi, gy);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, by);
hi = _mm_mul_epi32(hi, by);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c0[i]), y);
/*lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/
lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 2, 0)));
hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 3, 1)));
lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
u = _mm_blend_epi16(lo, hi, 0xCC);
lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ru);
hi = _mm_mul_epi32(hi, ru);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gu);
hi = _mm_mul_epi32(hi, gu);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c1[i]), u);
/*lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/
lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 2, 0)));
hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 3, 1)));
lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
v = _mm_blend_epi16(lo, hi, 0xCC);
lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gv);
hi = _mm_mul_epi32(hi, gv);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, bv);
hi = _mm_mul_epi32(hi, bv);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c2[i]), v);
}
for(; i < len; ++i) {
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);
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
#else
void opj_mct_encode_real(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
@@ -370,7 +138,6 @@ void opj_mct_encode_real(
c2[i] = v;
}
}
#endif
/* <summary> */
/* Inverse irreversible MCT. */
@@ -436,8 +203,7 @@ void opj_mct_decode_real(
/* <summary> */
/* Get norm of basis function of irreversible MCT. */
/* </summary> */
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno)
{
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) {
return opj_mct_norms_real[compno];
}

View File

@@ -202,8 +202,7 @@ static opj_mqc_state_t mqc_states[47 * 2] = {
==========================================================
*/
static void opj_mqc_byteout(opj_mqc_t *mqc)
{
void opj_mqc_byteout(opj_mqc_t *mqc) {
if (*mqc->bp == 0xff) {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
@@ -233,8 +232,7 @@ static void opj_mqc_byteout(opj_mqc_t *mqc)
}
}
static void opj_mqc_renorme(opj_mqc_t *mqc)
{
void opj_mqc_renorme(opj_mqc_t *mqc) {
do {
mqc->a <<= 1;
mqc->c <<= 1;
@@ -245,8 +243,7 @@ static void opj_mqc_renorme(opj_mqc_t *mqc)
} while ((mqc->a & 0x8000) == 0);
}
static void opj_mqc_codemps(opj_mqc_t *mqc)
{
void opj_mqc_codemps(opj_mqc_t *mqc) {
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->a & 0x8000) == 0) {
if (mqc->a < (*mqc->curctx)->qeval) {
@@ -261,8 +258,7 @@ static void opj_mqc_codemps(opj_mqc_t *mqc)
}
}
static void opj_mqc_codelps(opj_mqc_t *mqc)
{
void opj_mqc_codelps(opj_mqc_t *mqc) {
mqc->a -= (*mqc->curctx)->qeval;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->c += (*mqc->curctx)->qeval;
@@ -273,8 +269,7 @@ static void opj_mqc_codelps(opj_mqc_t *mqc)
opj_mqc_renorme(mqc);
}
static void opj_mqc_setbits(opj_mqc_t *mqc)
{
void opj_mqc_setbits(opj_mqc_t *mqc) {
OPJ_UINT32 tempc = mqc->c + mqc->a;
mqc->c |= 0xffff;
if (mqc->c >= tempc) {
@@ -282,8 +277,7 @@ static void opj_mqc_setbits(opj_mqc_t *mqc)
}
}
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc)
{
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) {
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
@@ -296,8 +290,7 @@ static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc)
return d;
}
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc)
{
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) {
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
@@ -313,16 +306,14 @@ static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc)
}
#ifdef MQC_PERF_OPT
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc)
{
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) {
unsigned int i = *((unsigned int *) mqc->bp);
mqc->c += i & 0xffff00;
mqc->ct = i & 0x0f;
mqc->bp += (i >> 2) & 0x04;
}
#else
static void opj_mqc_bytein(opj_mqc_t *const mqc)
{
static void opj_mqc_bytein(opj_mqc_t *const mqc) {
if (mqc->bp != mqc->end) {
OPJ_UINT32 c;
if (mqc->bp + 1 != mqc->end) {
@@ -351,8 +342,7 @@ static void opj_mqc_bytein(opj_mqc_t *const mqc)
}
#endif
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc)
{
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
do {
if (mqc->ct == 0) {
opj_mqc_bytein(mqc);
@@ -369,8 +359,7 @@ static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc)
==========================================================
*/
opj_mqc_t* opj_mqc_create(void)
{
opj_mqc_t* opj_mqc_create(void) {
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
#ifdef MQC_PERF_OPT
if (mqc) {
@@ -380,8 +369,7 @@ opj_mqc_t* opj_mqc_create(void)
return mqc;
}
void opj_mqc_destroy(opj_mqc_t *mqc)
{
void opj_mqc_destroy(opj_mqc_t *mqc) {
if(mqc) {
#ifdef MQC_PERF_OPT
if (mqc->buffer) {
@@ -392,8 +380,7 @@ void opj_mqc_destroy(opj_mqc_t *mqc)
}
}
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc)
{
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) {
const ptrdiff_t diff = mqc->bp - mqc->start;
#if 0
assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */
@@ -401,8 +388,7 @@ OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc)
return (OPJ_UINT32)diff;
}
void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp)
{
void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) {
/* TODO MSD: need to take a look to the v2 version */
opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
@@ -415,8 +401,7 @@ void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp)
mqc->start = bp;
}
void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d)
{
void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) {
if ((*mqc->curctx)->mps == d) {
opj_mqc_codemps(mqc);
} else {
@@ -424,8 +409,7 @@ void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d)
}
}
void opj_mqc_flush(opj_mqc_t *mqc)
{
void opj_mqc_flush(opj_mqc_t *mqc) {
opj_mqc_setbits(mqc);
mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc);
@@ -437,8 +421,7 @@ void opj_mqc_flush(opj_mqc_t *mqc)
}
}
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc)
{
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) {
mqc->c = 0;
mqc->ct = 8;
/*if (*mqc->bp == 0xff) {
@@ -446,8 +429,7 @@ void opj_mqc_bypass_init_enc(opj_mqc_t *mqc)
} */
}
void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d)
{
void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) {
mqc->ct--;
mqc->c = mqc->c + (d << mqc->ct);
if (mqc->ct == 0) {
@@ -461,8 +443,7 @@ void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d)
}
}
OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc)
{
OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) {
OPJ_BYTE bit_padding;
bit_padding = 0;
@@ -482,16 +463,14 @@ OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc)
return 1;
}
void opj_mqc_reset_enc(opj_mqc_t *mqc)
{
void opj_mqc_reset_enc(opj_mqc_t *mqc) {
opj_mqc_resetstates(mqc);
opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
}
OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc)
{
OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) {
OPJ_UINT32 correction = 1;
/* <flush part> */
@@ -507,8 +486,7 @@ OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc)
return correction;
}
void opj_mqc_restart_init_enc(opj_mqc_t *mqc)
{
void opj_mqc_restart_init_enc(opj_mqc_t *mqc) {
/* <Re-init part> */
opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
@@ -520,8 +498,7 @@ void opj_mqc_restart_init_enc(opj_mqc_t *mqc)
}
}
void opj_mqc_erterm_enc(opj_mqc_t *mqc)
{
void opj_mqc_erterm_enc(opj_mqc_t *mqc) {
OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1);
while (k > 0) {
@@ -536,8 +513,7 @@ void opj_mqc_erterm_enc(opj_mqc_t *mqc)
}
}
void opj_mqc_segmark_enc(opj_mqc_t *mqc)
{
void opj_mqc_segmark_enc(opj_mqc_t *mqc) {
OPJ_UINT32 i;
opj_mqc_setcurctx(mqc, 18);
@@ -546,8 +522,7 @@ void opj_mqc_segmark_enc(opj_mqc_t *mqc)
}
}
OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len)
{
OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
opj_mqc_setcurctx(mqc, 0);
mqc->start = bp;
mqc->end = bp + len;
@@ -606,8 +581,7 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len)
return OPJ_TRUE;
}
OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc)
{
OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) {
OPJ_INT32 d;
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
@@ -626,16 +600,14 @@ OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc)
return d;
}
void opj_mqc_resetstates(opj_mqc_t *mqc)
{
void opj_mqc_resetstates(opj_mqc_t *mqc) {
OPJ_UINT32 i;
for (i = 0; i < MQC_NUMCTXS; i++) {
mqc->ctxs[i] = mqc_states;
}
}
void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob)
{
void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) {
mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)];
}

View File

@@ -132,8 +132,7 @@ static OPJ_BOOL opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
#ifdef _WIN32
#ifndef OPJ_STATIC
BOOL APIENTRY
DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
OPJ_ARG_NOT_USED(lpReserved);
OPJ_ARG_NOT_USED(hModule);
@@ -155,8 +154,7 @@ DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
/* ---------------------------------------------------------------------- */
const char* OPJ_CALLCONV opj_version(void)
{
const char* OPJ_CALLCONV opj_version(void) {
return OPJ_PACKAGE_VERSION;
}
@@ -336,8 +334,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
return (opj_codec_t*) l_codec;
}
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters)
{
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
if(parameters) {
memset(parameters, 0, sizeof(opj_dparameters_t));
/* default decoding parameters */
@@ -527,12 +524,14 @@ OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec,
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
if ( !l_codec ){
fprintf(stderr, "[ERROR] Input parameters of the setup_decoder function are incorrect.\n");
return OPJ_FALSE;
}
return l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor(l_codec->m_codec,
l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor(l_codec->m_codec,
res_factor,
&(l_codec->m_event_mgr) );
return OPJ_TRUE;
}
/* ---------------------------------------------------------------------- */
@@ -634,8 +633,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
return (opj_codec_t*) l_codec;
}
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters)
{
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
if(parameters) {
memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */
@@ -702,10 +700,11 @@ OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
if (! l_codec->is_decompressor) {
return l_codec->m_codec_data.m_compression.opj_setup_encoder( l_codec->m_codec,
l_codec->m_codec_data.m_compression.opj_setup_encoder( l_codec->m_codec,
parameters,
p_image,
&(l_codec->m_event_mgr) );
return OPJ_TRUE;
}
}
@@ -847,7 +846,8 @@ void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec)
if (l_codec->is_decompressor) {
l_codec->m_codec_data.m_decompression.opj_destroy(l_codec->m_codec);
} else {
}
else {
l_codec->m_codec_data.m_compression.opj_destroy(l_codec->m_codec);
}
@@ -869,8 +869,7 @@ void OPJ_CALLCONV opj_dump_codec( opj_codec_t *p_codec,
return;
}
/* TODO return error */
/* fprintf(stderr, "[ERROR] Input parameter of the dump_codec function are incorrect.\n"); */
fprintf(stderr, "[ERROR] Input parameter of the dump_codec function are incorrect.\n");
return;
}
@@ -885,8 +884,7 @@ opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec)
return NULL;
}
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info)
{
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) {
if (cstr_info) {
if ((*cstr_info)->m_default_tile_info.tccp_info){
@@ -939,8 +937,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (
return NULL;
}
if(p_is_read_stream) mode = "rb";
else mode = "wb";
if(p_is_read_stream) mode = "rb"; else mode = "wb";
p_file = fopen(fname, mode);

View File

@@ -79,11 +79,7 @@ Most compilers implement their own version of this keyword ...
#if defined(OPJ_STATIC) || !defined(_WIN32)
/* http://gcc.gnu.org/wiki/Visibility */
#if __GNUC__ >= 4
# if defined(OPJ_STATIC) /* static library uses "hidden" */
# define OPJ_API __attribute__ ((visibility ("hidden")))
# else
#define OPJ_API __attribute__ ((visibility ("default")))
# endif
#define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
#else
#define OPJ_API
@@ -97,7 +93,7 @@ The following ifdef block is the standard way of creating macros which make expo
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, whereas this DLL sees symbols
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)
@@ -850,12 +846,13 @@ typedef struct opj_codestream_info {
} opj_codestream_info_t;
/* <----------------------------------------------------------- */
/* new output management of the codestream information and index */
/* new output managment of the codestream information and index */
/**
* Tile-component coding parameters information
*/
typedef struct opj_tccp_info {
typedef struct opj_tccp_info
{
/** component index */
OPJ_UINT32 compno;
/** coding style */
@@ -1346,7 +1343,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile ( opj_codec_t *p_codec,
opj_stream_t *p_stream );
/**
* Reads a tile header. This function is compulsory and allows one to know the size of the tile that will be decoded.
* 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.

View File

@@ -29,8 +29,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
#ifdef _WIN32
#include <windows.h>
#else
@@ -38,9 +36,9 @@
#include <sys/resource.h>
#include <sys/times.h>
#endif /* _WIN32 */
#include "opj_includes.h"
OPJ_FLOAT64 opj_clock(void)
{
OPJ_FLOAT64 opj_clock(void) {
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;

View File

@@ -39,13 +39,16 @@
/**
* Main codec handler used for compression or decompression.
*/
typedef struct opj_codec_private {
typedef struct opj_codec_private
{
/** FIXME DOC */
union {
union
{
/**
* Decompression handler.
*/
struct opj_decompression {
struct opj_decompression
{
/** Main header reading function handler */
OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio,
void * p_codec,
@@ -115,7 +118,8 @@ typedef struct opj_codec_private {
/**
* Compression handler. FIXME DOC
*/
struct opj_compression {
struct opj_compression
{
OPJ_BOOL (* opj_start_compress) ( void *p_codec,
struct opj_stream_private * cio,
struct opj_image * p_image,

View File

@@ -17,24 +17,6 @@
#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
#cmakedefine OPJ_HAVE_FSEEKO @OPJ_HAVE_FSEEKO@
/* find whether or not have <malloc.h> */
#cmakedefine OPJ_HAVE_MALLOC_H
/* check if function `aligned_alloc` exists */
#cmakedefine OPJ_HAVE_ALIGNED_ALLOC
/* check if function `_aligned_malloc` exists */
#cmakedefine OPJ_HAVE__ALIGNED_MALLOC
/* check if function `memalign` exists */
#cmakedefine OPJ_HAVE_MEMALIGN
/* check if function `posix_memalign` exists */
#cmakedefine OPJ_HAVE_POSIX_MEMALIGN
#if !defined(_POSIX_C_SOURCE)
#if defined(OPJ_HAVE_FSEEKO) || defined(OPJ_HAVE_POSIX_MEMALIGN)
/* Get declarations of fseeko, ftello, posix_memalign. */
#define _POSIX_C_SOURCE 200112L
#endif
#endif
/* Byte order. */
/* All compilers that support Mac OS X define either __BIG_ENDIAN__ or
__LITTLE_ENDIAN__ to match the endianness of the architecture being

View File

@@ -118,33 +118,9 @@
#endif
#endif
/* MSVC before 2013 and Borland C do not have lrintf */
#if defined(_MSC_VER)
#include <intrin.h>
static INLINE long opj_lrintf(float f)
{
#ifdef _M_X64
return _mm_cvt_ss2si(_mm_load_ss(&f));
/* commented out line breaks many tests */
/* return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); */
#elif defined(_M_IX86)
int i;
_asm{
fld f
fistp i
};
return i;
#else
return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f));
#endif
}
#elif defined(__BORLANDC__)
static INLINE long opj_lrintf(float f)
{
#if defined(_MSC_VER) && (_MSC_VER < 1800) || defined(__BORLANDC__)
static INLINE long lrintf(float f){
#ifdef _M_X64
return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f));
#else
@@ -158,28 +134,13 @@ static INLINE long opj_lrintf(float f)
return i;
#endif
}
#else
static INLINE long opj_lrintf(float f)
{
return lrintf(f);
}
#endif
#if defined(_MSC_VER) && (_MSC_VER < 1400)
#define vsnprintf _vsnprintf
#endif
/* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
# include <intrin.h>
# pragma intrinsic(__emul)
#endif
#include "opj_inttypes.h"
#include "opj_clock.h"
#include "opj_malloc.h"
#include "event.h"
#include "function_list.h"
#include "event.h"
#include "bio.h"
#include "cio.h"

View File

@@ -53,8 +53,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 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) {
return a < b ? a : b;
}
@@ -62,8 +61,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 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
return a < b ? a : b;
}
@@ -71,8 +69,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 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) {
return (a > b) ? a : b;
}
@@ -80,21 +77,10 @@ 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 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) {
return (a > b) ? a : b;
}
/**
Get the saturated sum of two unsigned integers
@return Returns saturated sum of a+b
*/
static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b)
{
OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b;
return (OPJ_UINT32)(-(OPJ_INT32)(sum >> 32)) | (OPJ_UINT32)sum;
}
/**
Clamp an integer inside an interval
@return
@@ -104,8 +90,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 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max) {
if (a < min)
return min;
if (a > max)
@@ -115,16 +100,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 opj_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 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) {
assert(b);
return (a + b - 1) / b;
}
@@ -133,9 +116,7 @@ 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)
{
assert(b);
static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) {
return (a + b - 1) / b;
}
@@ -143,43 +124,21 @@ static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 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)
{
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
return (OPJ_INT32)((a + (OPJ_INT64)(1 << b) - 1) >> b);
}
/**
Divide a 64bits integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b)
{
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
}
/**
Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b)
{
return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> 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 opj_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 opj_int_floorlog2(OPJ_INT32 a) {
OPJ_INT32 l;
for (l = 0; a > 1; l++) {
a >>= 1;
@@ -190,10 +149,10 @@ static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a)
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 opj_uint_floorlog2(OPJ_UINT32 a) {
OPJ_UINT32 l;
for (l = 0; a > 1; ++l) {
for (l = 0; a > 1; ++l)
{
a >>= 1;
}
return l;
@@ -205,32 +164,12 @@ Multiply two fixed-precision rational numbers.
@param b
@return Returns a * b
*/
static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b);
#else
static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) {
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
#endif
temp += 4096;
assert((temp >> 13) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> 13) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
temp += temp & 4096;
return (OPJ_INT32) (temp >> 13) ;
}
static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b);
#else
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
#endif
temp += 4096;
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
return (OPJ_INT32) (temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ;
}
/* ----------------------------------------------------------------------- */
/*@}*/

View File

@@ -1,237 +0,0 @@
/*
* The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2015, Mathieu Malaterre <mathieu.malaterre@gmail.com>
* Copyright (c) 2015, Matthieu Darbois
* 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.
*/
#define OPJ_SKIP_POISON
#include "opj_includes.h"
#if defined(OPJ_HAVE_MALLOC_H) && defined(OPJ_HAVE_MEMALIGN)
# include <malloc.h>
#endif
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size)
{
void* ptr;
/* alignment shall be power of 2 */
assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U));
/* alignment shall be at least sizeof(void*) */
assert( alignment >= sizeof(void*));
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
#if defined(OPJ_HAVE_POSIX_MEMALIGN)
/* aligned_alloc requires c11, restrict to posix_memalign for now. Quote:
* This function was introduced in POSIX 1003.1d. Although this function is
* superseded by aligned_alloc, it is more portable to older POSIX systems
* that do not support ISO C11. */
if (posix_memalign (&ptr, alignment, size)) {
ptr = NULL;
}
/* older linux */
#elif defined(OPJ_HAVE_MEMALIGN)
ptr = memalign( alignment, size );
/* _MSC_VER */
#elif defined(OPJ_HAVE__ALIGNED_MALLOC)
ptr = _aligned_malloc(size, alignment);
#else
/*
* Generic aligned malloc implementation.
* Uses size_t offset for the integer manipulation of the pointer,
* as uintptr_t is not available in C89 to do
* bitwise operations on the pointer itself.
*/
alignment--;
{
size_t offset;
OPJ_UINT8 *mem;
/* Room for padding and extra pointer stored in front of allocated area */
size_t overhead = alignment + sizeof(void *);
/* let's be extra careful */
assert(alignment <= (SIZE_MAX - sizeof(void *)));
/* Avoid integer overflow */
if (size > (SIZE_MAX - overhead)) {
return NULL;
}
mem = (OPJ_UINT8*)malloc(size + overhead);
if (mem == NULL) {
return mem;
}
/* offset = ((alignment + 1U) - ((size_t)(mem + sizeof(void*)) & alignment)) & alignment; */
/* Use the fact that alignment + 1U is a power of 2 */
offset = ((alignment ^ ((size_t)(mem + sizeof(void*)) & alignment)) + 1U) & alignment;
ptr = (void *)(mem + sizeof(void*) + offset);
((void**) ptr)[-1] = mem;
}
#endif
return ptr;
}
static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t new_size)
{
void *r_ptr;
/* alignment shall be power of 2 */
assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U));
/* alignment shall be at least sizeof(void*) */
assert( alignment >= sizeof(void*));
if (new_size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
/* no portable aligned realloc */
#if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN)
/* glibc doc states one can mix aligned malloc with realloc */
r_ptr = realloc( ptr, new_size ); /* fast path */
/* we simply use `size_t` to cast, since we are only interest in binary AND
* operator */
if( ((size_t)r_ptr & (alignment - 1U)) != 0U ) {
/* this is non-trivial to implement a portable aligned realloc, so use a
* simple approach where we do not need a function that return the size of an
* allocated array (eg. _msize on Windows, malloc_size on MacOS,
* malloc_usable_size on systems with glibc) */
void *a_ptr = opj_aligned_alloc_n(alignment, new_size);
if (a_ptr != NULL) {
memcpy(a_ptr, r_ptr, new_size);
}
free( r_ptr );
r_ptr = a_ptr;
}
/* _MSC_VER */
#elif defined(OPJ_HAVE__ALIGNED_MALLOC)
r_ptr = _aligned_realloc( ptr, new_size, alignment );
#else
if (ptr == NULL) {
return opj_aligned_alloc_n(alignment, new_size);
}
alignment--;
{
void *oldmem;
OPJ_UINT8 *newmem;
size_t overhead = alignment + sizeof(void *);
/* let's be extra careful */
assert(alignment <= (SIZE_MAX - sizeof(void *)));
/* Avoid integer overflow */
if (new_size > SIZE_MAX - overhead) {
return NULL;
}
oldmem = ((void**) ptr)[-1];
newmem = (OPJ_UINT8*)realloc(oldmem, new_size + overhead);
if (newmem == NULL) {
return newmem;
}
if (newmem == oldmem) {
r_ptr = ptr;
} else {
size_t old_offset;
size_t new_offset;
/* realloc created a new copy, realign the copied memory block */
old_offset = (size_t)((OPJ_UINT8*)ptr - (OPJ_UINT8*)oldmem);
/* offset = ((alignment + 1U) - ((size_t)(mem + sizeof(void*)) & alignment)) & alignment; */
/* Use the fact that alignment + 1U is a power of 2 */
new_offset = ((alignment ^ ((size_t)(newmem + sizeof(void*)) & alignment)) + 1U) & alignment;
new_offset += sizeof(void*);
r_ptr = (void *)(newmem + new_offset);
if (new_offset != old_offset) {
memmove(newmem + new_offset, newmem + old_offset, new_size);
}
((void**) r_ptr)[-1] = newmem;
}
}
#endif
return r_ptr;
}
void * opj_malloc(size_t size)
{
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
return malloc(size);
}
void * opj_calloc(size_t num, size_t size)
{
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
/* according to C89 standard, num == 0 shall return a valid pointer */
return calloc(num, size);
}
void *opj_aligned_malloc(size_t size)
{
return opj_aligned_alloc_n(16U, size);
}
void * opj_aligned_realloc(void *ptr, size_t size)
{
return opj_aligned_realloc_n(ptr, 16U, size);
}
void opj_aligned_free(void* ptr)
{
#if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN)
free( ptr );
#elif defined(OPJ_HAVE__ALIGNED_MALLOC)
_aligned_free( ptr );
#else
/* Generic implementation has malloced pointer stored in front of used area */
if (ptr != NULL) {
free(((void**) ptr)[-1]);
}
#endif
}
void * opj_realloc(void *ptr, size_t new_size)
{
if (new_size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
return realloc(ptr, new_size);
}
void opj_free(void *ptr)
{
free(ptr);
}

View File

@@ -31,8 +31,6 @@
*/
#ifndef __OPJ_MALLOC_H
#define __OPJ_MALLOC_H
#include <stddef.h>
/**
@file opj_malloc.h
@brief Internal functions
@@ -52,7 +50,16 @@ 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
*/
void * opj_malloc(size_t size);
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_malloc(size_t size);
#else
/* prevent assertion on overflow for MSVC */
#ifdef _MSC_VER
#define opj_malloc(size) ((size_t)(size) >= (size_t)-0x100 ? NULL : malloc(size))
#else
#define opj_malloc(size) malloc(size)
#endif
#endif
/**
Allocate a memory block with elements initialized to 0
@@ -60,16 +67,83 @@ 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
*/
void * opj_calloc(size_t numOfElements, size_t sizeOfElements);
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements);
#else
/* prevent assertion on overflow for MSVC */
#ifdef _MSC_VER
#define opj_calloc(num, size) ((size_t)(num) != 0 && (size_t)(num) >= (size_t)-0x100 / (size_t)(size) ? NULL : calloc(num, size))
#else
#define opj_calloc(num, size) calloc(num, size)
#endif
#endif
/**
Allocate memory aligned to a 16 byte boundary
Allocate memory aligned to a 16 byte boundry
@param size Bytes to allocate
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
*/
void * opj_aligned_malloc(size_t size);
void * opj_aligned_realloc(void *ptr, size_t size);
void opj_aligned_free(void* ptr);
/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
#ifdef _WIN32
/* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
#ifdef __GNUC__
#include <mm_malloc.h>
#define HAVE_MM_MALLOC
#else /* MSVC, Intel C++ */
#include <malloc.h>
#ifdef _mm_malloc
#define HAVE_MM_MALLOC
#endif
#endif
#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>
#endif
#endif
#define opj_aligned_malloc(size) malloc(size)
#define opj_aligned_free(m) free(m)
#ifdef HAVE_MM_MALLOC
#undef opj_aligned_malloc
#define opj_aligned_malloc(size) _mm_malloc(size, 16)
#undef opj_aligned_free
#define opj_aligned_free(m) _mm_free(m)
#endif
#ifdef HAVE_MEMALIGN
extern void* memalign(size_t, size_t);
#undef opj_aligned_malloc
#define opj_aligned_malloc(size) memalign(16, (size))
#undef opj_aligned_free
#define opj_aligned_free(m) free(m)
#endif
#ifdef HAVE_POSIX_MEMALIGN
#undef opj_aligned_malloc
extern int posix_memalign(void**, size_t, size_t);
static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){
void* mem = NULL;
posix_memalign(&mem, 16, size);
return mem;
}
#undef opj_aligned_free
#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.
@@ -77,15 +151,28 @@ Reallocate memory blocks.
@param s New size in bytes
@return Returns a void pointer to the reallocated (and possibly moved) memory block
*/
void * opj_realloc(void * m, size_t s);
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_realloc(void * m, size_t s);
#else
/* prevent assertion on overflow for MSVC */
#ifdef _MSC_VER
#define opj_realloc(m, s) ((size_t)(s) >= (size_t)-0x100 ? NULL : realloc(m, s))
#else
#define opj_realloc(m, s) realloc(m, s)
#endif
#endif
/**
Deallocates or frees a memory block.
@param m Previously allocated memory block to be freed
*/
void opj_free(void * m);
#ifdef ALLOC_PERF_OPT
void OPJ_CALLCONV opj_free(void * m);
#else
#define opj_free(m) free(m)
#endif
#if defined(__GNUC__) && !defined(OPJ_SKIP_POISON)
#ifdef __GNUC__
#pragma GCC poison malloc calloc realloc free
#endif

View File

@@ -107,7 +107,8 @@ int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
if( j2klen > pow( 2, 32)){
size_of_coding = 8;
version = 1;
} else {
}
else{
size_of_coding = 4;
version = 0;
}

View File

@@ -136,10 +136,10 @@ static void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp,
* @param p_tx1 pointer that will hold the X1 parameter for the tile
* @param p_ty0 pointer that will hold the Y0 parameter for the tile
* @param p_ty1 pointer that will hold the Y1 parameter for the tile
* @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile
* @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile.
* @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile.
* @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile.
* @param p_max_prec pointer that will hold the the maximum precision for all the bands of the tile
* @param p_max_res pointer that will hold the the maximum number of resolutions for all the poc inside the tile.
* @param p_dx_min pointer that will hold the the minimum dx of all the components of all the resolutions for the tile.
* @param p_dy_min pointer that will hold the the minimum dy of all the components of all the resolutions for the tile.
*/
static void opj_get_encoding_parameters(const opj_image_t *p_image,
const opj_cp_t *p_cp,
@@ -167,10 +167,10 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image,
* @param p_tx1 pointer that will hold the X1 parameter for the tile
* @param p_ty0 pointer that will hold the Y0 parameter for the tile
* @param p_ty1 pointer that will hold the Y1 parameter for the tile
* @param p_max_prec pointer that will hold the maximum precision for all the bands of the tile
* @param p_max_res pointer that will hold the maximum number of resolutions for all the poc inside the tile.
* @param p_dx_min pointer that will hold the minimum dx of all the components of all the resolutions for the tile.
* @param p_dy_min pointer that will hold the minimum dy of all the components of all the resolutions for the tile.
* @param p_max_prec pointer that will hold the the maximum precision for all the bands of the tile
* @param p_max_res pointer that will hold the the maximum number of resolutions for all the poc inside the tile.
* @param p_dx_min pointer that will hold the the minimum dx of all the components of all the resolutions for the tile.
* @param p_dy_min pointer that will hold the the minimum dy of all the components of all the resolutions for the tile.
* @param p_resolutions pointer to an area corresponding to the one described above.
*/
static void opj_get_all_encoding_parameters(const opj_image_t *p_image,
@@ -214,7 +214,7 @@ static void opj_pi_update_decode_poc ( opj_pi_iterator_t * p_pi,
/**
* FIXME DOC
*/
static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
opj_cp_t *cp,
OPJ_UINT32 tileno,
OPJ_UINT32 pino,
@@ -230,8 +230,7 @@ static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
==========================================================
*/
static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi)
{
OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -262,8 +261,7 @@ static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi)
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:
;
LABEL_SKIP:;
}
}
}
@@ -272,8 +270,7 @@ LABEL_SKIP:
return OPJ_FALSE;
}
static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi)
{
OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -303,8 +300,7 @@ static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi)
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:
;
LABEL_SKIP:;
}
}
}
@@ -313,8 +309,7 @@ LABEL_SKIP:
return OPJ_FALSE;
}
static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi)
{
OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -387,8 +382,7 @@ static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi)
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:
;
LABEL_SKIP:;
}
}
}
@@ -398,8 +392,7 @@ LABEL_SKIP:
return OPJ_FALSE;
}
static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi)
{
OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -470,8 +463,7 @@ static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi)
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:
;
LABEL_SKIP:;
}
}
}
@@ -481,8 +473,7 @@ LABEL_SKIP:
return OPJ_FALSE;
}
static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi)
{
OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0;
@@ -551,8 +542,7 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi)
pi->include[index] = 1;
return OPJ_TRUE;
}
LABEL_SKIP:
;
LABEL_SKIP:;
}
}
}
@@ -562,7 +552,7 @@ LABEL_SKIP:
return OPJ_FALSE;
}
static void opj_get_encoding_parameters( const opj_image_t *p_image,
void opj_get_encoding_parameters( const opj_image_t *p_image,
const opj_cp_t *p_cp,
OPJ_UINT32 p_tileno,
OPJ_INT32 * p_tx0,
@@ -676,7 +666,7 @@ static void opj_get_encoding_parameters( const opj_image_t *p_image,
}
static void opj_get_all_encoding_parameters( const opj_image_t *p_image,
void opj_get_all_encoding_parameters( const opj_image_t *p_image,
const opj_cp_t *p_cp,
OPJ_UINT32 tileno,
OPJ_INT32 * p_tx0,
@@ -703,9 +693,6 @@ static void opj_get_all_encoding_parameters( const opj_image_t *p_image,
/* position in x and y of tile*/
OPJ_UINT32 p, q;
/* non-corrected (in regard to image offset) tile offset */
OPJ_UINT32 l_tx0, l_ty0;
/* preconditions in debug*/
assert(p_cp != 00);
assert(p_image != 00);
@@ -721,12 +708,10 @@ static void opj_get_all_encoding_parameters( const opj_image_t *p_image,
q = tileno / p_cp->tw;
/* here calculation of tx0, tx1, ty0, ty1, maxprec, l_dx and l_dy */
l_tx0 = p_cp->tx0 + p * p_cp->tdx; /* can't be greater than p_image->x1 so won't overflow */
*p_tx0 = (OPJ_INT32)opj_uint_max(l_tx0, p_image->x0);
*p_tx1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_tx0, p_cp->tdx), p_image->x1);
l_ty0 = p_cp->ty0 + q * p_cp->tdy; /* can't be greater than p_image->y1 so won't overflow */
*p_ty0 = (OPJ_INT32)opj_uint_max(l_ty0, p_image->y0);
*p_ty1 = (OPJ_INT32)opj_uint_min(opj_uint_adds(l_ty0, p_cp->tdy), p_image->y1);
*p_tx0 = opj_int_max((OPJ_INT32)(p_cp->tx0 + p * p_cp->tdx), (OPJ_INT32)p_image->x0);
*p_tx1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + (p + 1) * p_cp->tdx), (OPJ_INT32)p_image->x1);
*p_ty0 = opj_int_max((OPJ_INT32)(p_cp->ty0 + q * p_cp->tdy), (OPJ_INT32)p_image->y0);
*p_ty1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + (q + 1) * p_cp->tdy), (OPJ_INT32)p_image->y1);
/* max precision and resolution is 0 (can only grow)*/
*p_max_prec = 0;
@@ -799,7 +784,7 @@ static void opj_get_all_encoding_parameters( const opj_image_t *p_image,
}
}
static opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
const opj_cp_t *cp,
OPJ_UINT32 tileno )
{
@@ -860,7 +845,7 @@ static opj_pi_iterator_t * opj_pi_create( const opj_image_t *image,
return l_pi;
}
static void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp,
void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp,
OPJ_UINT32 p_tileno,
OPJ_INT32 p_tx0,
OPJ_INT32 p_tx1,
@@ -938,7 +923,7 @@ static void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp,
}
}
static void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp,
void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp,
OPJ_UINT32 p_num_comps,
OPJ_UINT32 p_tileno,
OPJ_INT32 p_tx0,
@@ -993,7 +978,7 @@ static void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp,
}
}
static void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi,
void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi,
opj_tcp_t * p_tcp,
OPJ_UINT32 p_max_precision,
OPJ_UINT32 p_max_res)
@@ -1035,7 +1020,7 @@ static void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi,
}
}
static void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,
void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,
opj_tcp_t * p_tcp,
OPJ_UINT32 p_max_precision,
OPJ_UINT32 p_max_res)
@@ -1072,7 +1057,7 @@ static void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,
static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
opj_cp_t *cp,
OPJ_UINT32 tileno,
OPJ_UINT32 pino,
@@ -1204,13 +1189,15 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_tmp_data = (OPJ_UINT32*)opj_malloc(
l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
if
(! l_tmp_data) {
(! l_tmp_data)
{
return 00;
}
l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
p_image->numcomps * sizeof(OPJ_UINT32 *));
if
(! l_tmp_ptr) {
(! l_tmp_ptr)
{
opj_free(l_tmp_data);
return 00;
}
@@ -1226,7 +1213,8 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_encoding_value_ptr = l_tmp_data;
/* update pointer array */
for
(compno = 0; compno < p_image->numcomps; ++compno) {
(compno = 0; compno < p_image->numcomps; ++compno)
{
l_tmp_ptr[compno] = l_encoding_value_ptr;
l_encoding_value_ptr += l_data_stride;
}
@@ -1245,7 +1233,8 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
/* memory allocation for include */
l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16));
if
(!l_current_pi->include) {
(!l_current_pi->include)
{
opj_free(l_tmp_data);
opj_free(l_tmp_ptr);
opj_pi_destroy(l_pi, l_bound);
@@ -1272,7 +1261,8 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
/* allocation for components and number of components has already been calculated by opj_pi_create */
for
(compno = 0; compno < l_current_pi->numcomps; ++compno) {
(compno = 0; compno < l_current_pi->numcomps; ++compno)
{
opj_pi_resolution_t *l_res = l_current_comp->resolutions;
l_encoding_value_ptr = l_tmp_ptr[compno];
@@ -1280,7 +1270,8 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_current_comp->dy = l_img_comp->dy;
/* resolutions have already been initialized */
for
(resno = 0; resno < l_current_comp->numresolutions; resno++) {
(resno = 0; resno < l_current_comp->numresolutions; resno++)
{
l_res->pdx = *(l_encoding_value_ptr++);
l_res->pdy = *(l_encoding_value_ptr++);
l_res->pw = *(l_encoding_value_ptr++);
@@ -1293,7 +1284,8 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
}
++l_current_pi;
for (pino = 1 ; pino<l_bound ; ++pino ) {
for (pino = 1 ; pino<l_bound ; ++pino )
{
l_current_comp = l_current_pi->comps;
l_img_comp = p_image->comps;
l_tccp = l_tcp->tccps;
@@ -1311,7 +1303,8 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
/* allocation for components and number of components has already been calculated by opj_pi_create */
for
(compno = 0; compno < l_current_pi->numcomps; ++compno) {
(compno = 0; compno < l_current_pi->numcomps; ++compno)
{
opj_pi_resolution_t *l_res = l_current_comp->resolutions;
l_encoding_value_ptr = l_tmp_ptr[compno];
@@ -1319,7 +1312,8 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_current_comp->dy = l_img_comp->dy;
/* resolutions have already been initialized */
for
(resno = 0; resno < l_current_comp->numresolutions; resno++) {
(resno = 0; resno < l_current_comp->numresolutions; resno++)
{
l_res->pdx = *(l_encoding_value_ptr++);
l_res->pdy = *(l_encoding_value_ptr++);
l_res->pw = *(l_encoding_value_ptr++);
@@ -1339,9 +1333,12 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
opj_free(l_tmp_ptr);
l_tmp_ptr = 00;
if
(l_tcp->POC) {
(l_tcp->POC)
{
opj_pi_update_decode_poc (l_pi,l_tcp,l_max_prec,l_max_res);
} else {
}
else
{
opj_pi_update_decode_not_poc(l_pi,l_tcp,l_max_prec,l_max_res);
}
return l_pi;
@@ -1428,7 +1425,7 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
l_step_l = l_max_res * l_step_r;
/* set values for first packet iterator*/
l_pi->tp_on = (OPJ_BYTE)p_cp->m_specific_param.m_enc.m_tp_on;
l_pi->tp_on = p_cp->m_specific_param.m_enc.m_tp_on;
l_current_pi = l_pi;
/* memory allocation for include*/
@@ -1526,7 +1523,8 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
if (l_tcp->POC && (OPJ_IS_CINEMA(p_cp->rsiz) || p_t2_mode == FINAL_PASS)) {
opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
} else {
}
else {
opj_pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
}
@@ -1759,18 +1757,15 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
incr_top=1;
resetX=1;
incr_top=1;resetX=1;
}else{
incr_top=0;
resetX=0;
incr_top=0;resetX=0;
}
}else{
pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
incr_top=0;
resetX=1;
incr_top=0;resetX=1;
}
if(resetX==1){
tcp->tx0_t = tcp->txS;
@@ -1851,13 +1846,13 @@ void opj_pi_update_encoding_parameters( const opj_image_t *p_image,
if (l_tcp->POC) {
opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
} else {
}
else {
opj_pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
}
}
OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi)
{
OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi) {
switch (pi->poc.prg) {
case OPJ_LRCP:
return opj_pi_next_lrcp(pi);

View File

@@ -73,7 +73,7 @@ Packet iterator
typedef struct opj_pi_iterator {
/** Enabling Tile part generation*/
OPJ_BYTE tp_on;
/** precise if the packet has been already used (useful for progression order change) */
/** precise if the packet has been already used (usefull for progression order change) */
OPJ_INT16 *include;
/** layer step used to localize the packet in the include vector */
OPJ_UINT32 step_l;

View File

@@ -112,7 +112,8 @@ int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
if( j2klen > pow( 2, 32)){
size_of_coding = 8;
version = 1;
} else {
}
else{
size_of_coding = 4;
version = 0;
}

View File

@@ -48,28 +48,24 @@
==========================================================
*/
opj_raw_t* opj_raw_create(void)
{
opj_raw_t* opj_raw_create(void) {
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw;
}
void opj_raw_destroy(opj_raw_t *raw)
{
void opj_raw_destroy(opj_raw_t *raw) {
if(raw) {
opj_free(raw);
}
}
OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw)
{
OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw) {
const ptrdiff_t diff = raw->bp - raw->start;
assert( diff <= (ptrdiff_t)0xffffffff && diff >= 0 ); /* UINT32_MAX */
return (OPJ_UINT32)diff;
}
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len)
{
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) {
raw->start = bp;
raw->lenmax = len;
raw->len = 0;
@@ -77,8 +73,7 @@ void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len)
raw->ct = 0;
}
OPJ_UINT32 opj_raw_decode(opj_raw_t *raw)
{
OPJ_UINT32 opj_raw_decode(opj_raw_t *raw) {
OPJ_UINT32 d;
if (raw->ct == 0) {
raw->ct = 8;

View File

@@ -265,8 +265,7 @@ static OPJ_FLOAT64 opj_t1_getwmsedec(
OPJ_UINT32 qmfbid,
OPJ_FLOAT64 stepsize,
OPJ_UINT32 numcomps,
const OPJ_FLOAT64 * mct_norms,
OPJ_UINT32 mct_numcomps);
const OPJ_FLOAT64 * mct_norms);
static void opj_t1_encode_cblk( opj_t1_t *t1,
opj_tcd_cblk_enc_t* cblk,
@@ -278,8 +277,7 @@ static void opj_t1_encode_cblk( opj_t1_t *t1,
OPJ_UINT32 cblksty,
OPJ_UINT32 numcomps,
opj_tcd_tile_t * tile,
const OPJ_FLOAT64 * mct_norms,
OPJ_UINT32 mct_numcomps);
const OPJ_FLOAT64 * mct_norms);
/**
Decode 1 code-block
@@ -295,7 +293,7 @@ static OPJ_BOOL opj_t1_decode_cblk( opj_t1_t *t1,
OPJ_UINT32 roishift,
OPJ_UINT32 cblksty);
static OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1,
OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1,
OPJ_UINT32 w,
OPJ_UINT32 h);
@@ -305,48 +303,41 @@ static OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1,
/* ----------------------------------------------------------------------- */
static OPJ_BYTE opj_t1_getctxno_zc(OPJ_UINT32 f, OPJ_UINT32 orient)
{
OPJ_BYTE opj_t1_getctxno_zc(OPJ_UINT32 f, OPJ_UINT32 orient) {
return lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)];
}
static OPJ_BYTE opj_t1_getctxno_sc(OPJ_UINT32 f)
{
OPJ_BYTE opj_t1_getctxno_sc(OPJ_UINT32 f) {
return lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4];
}
static OPJ_UINT32 opj_t1_getctxno_mag(OPJ_UINT32 f)
{
OPJ_UINT32 opj_t1_getctxno_mag(OPJ_UINT32 f) {
OPJ_UINT32 tmp1 = (f & T1_SIG_OTH) ? T1_CTXNO_MAG + 1 : T1_CTXNO_MAG;
OPJ_UINT32 tmp2 = (f & T1_REFINE) ? T1_CTXNO_MAG + 2 : tmp1;
return (tmp2);
}
static OPJ_BYTE opj_t1_getspb(OPJ_UINT32 f)
{
OPJ_BYTE opj_t1_getspb(OPJ_UINT32 f) {
return lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4];
}
static OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos)
{
if (bitpos > 0) {
return lut_nmsedec_sig[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)];
OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos) {
if (bitpos > T1_NMSEDEC_FRACBITS) {
return lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
}
return lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
}
static OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos)
{
if (bitpos > 0) {
return lut_nmsedec_ref[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)];
OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos) {
if (bitpos > T1_NMSEDEC_FRACBITS) {
return lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
}
return lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
}
static void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT32 stride)
{
void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT32 stride) {
opj_flag_t *np = flagsp - stride;
opj_flag_t *sp = flagsp + stride;
@@ -370,7 +361,7 @@ static void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT32 stri
sp[1] |= T1_SIG_NW;
}
static void opj_t1_enc_sigpass_step( opj_t1_t *t1,
void opj_t1_enc_sigpass_step( opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
OPJ_UINT32 orient,
@@ -397,7 +388,7 @@ static void opj_t1_enc_sigpass_step( opj_t1_t *t1,
}
if (v) {
v = *datap < 0 ? 1 : 0;
*nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno));
*nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno + T1_NMSEDEC_FRACBITS));
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag)); /* ESSAI */
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
opj_mqc_bypass_enc(mqc, (OPJ_UINT32)v);
@@ -434,7 +425,7 @@ static INLINE void opj_t1_dec_sigpass_step_raw(
}
}
static INLINE void opj_t1_dec_sigpass_step_mqc(
INLINE void opj_t1_dec_sigpass_step_mqc(
opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@@ -458,7 +449,7 @@ static INLINE void opj_t1_dec_sigpass_step_mqc(
}
} /* VSC and BYPASS by Antonin */
static INLINE void opj_t1_dec_sigpass_step_mqc_vsc(
INLINE void opj_t1_dec_sigpass_step_mqc_vsc(
opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@@ -485,7 +476,7 @@ static INLINE void opj_t1_dec_sigpass_step_mqc_vsc(
static void opj_t1_enc_sigpass(opj_t1_t *t1,
void opj_t1_enc_sigpass(opj_t1_t *t1,
OPJ_INT32 bpno,
OPJ_UINT32 orient,
OPJ_INT32 *nmsedec,
@@ -505,7 +496,7 @@ static void opj_t1_enc_sigpass(opj_t1_t *t1,
opj_t1_enc_sigpass_step(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->data_stride) + i],
&t1->data[(j * t1->w) + i],
orient,
bpno,
one,
@@ -517,7 +508,7 @@ static void opj_t1_enc_sigpass(opj_t1_t *t1,
}
}
static void opj_t1_dec_sigpass_raw(
void opj_t1_dec_sigpass_raw(
opj_t1_t *t1,
OPJ_INT32 bpno,
OPJ_INT32 orient,
@@ -544,7 +535,7 @@ static void opj_t1_dec_sigpass_raw(
}
} /* VSC and BYPASS by Antonin */
static void opj_t1_dec_sigpass_mqc(
void opj_t1_dec_sigpass_mqc(
opj_t1_t *t1,
OPJ_INT32 bpno,
OPJ_INT32 orient)
@@ -587,7 +578,7 @@ static void opj_t1_dec_sigpass_mqc(
}
} /* VSC and BYPASS by Antonin */
static void opj_t1_dec_sigpass_mqc_vsc(
void opj_t1_dec_sigpass_mqc_vsc(
opj_t1_t *t1,
OPJ_INT32 bpno,
OPJ_INT32 orient)
@@ -615,7 +606,7 @@ static void opj_t1_dec_sigpass_mqc_vsc(
static void opj_t1_enc_refpass_step( opj_t1_t *t1,
void opj_t1_enc_refpass_step( opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
OPJ_INT32 bpno,
@@ -631,7 +622,7 @@ static void opj_t1_enc_refpass_step( opj_t1_t *t1,
flag = vsc ? (OPJ_UINT32)((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (OPJ_UINT32)(*flagsp);
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
*nmsedec += opj_t1_getnmsedec_ref((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno));
*nmsedec += opj_t1_getnmsedec_ref((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno + T1_NMSEDEC_FRACBITS));
v = opj_int_abs(*datap) & one ? 1 : 0;
opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag(flag)); /* ESSAI */
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
@@ -643,7 +634,7 @@ static void opj_t1_enc_refpass_step( opj_t1_t *t1,
}
}
static INLINE void opj_t1_dec_refpass_step_raw(
INLINE void opj_t1_dec_refpass_step_raw(
opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@@ -664,7 +655,7 @@ static INLINE void opj_t1_dec_refpass_step_raw(
}
} /* VSC and BYPASS by Antonin */
static INLINE void opj_t1_dec_refpass_step_mqc(
INLINE void opj_t1_dec_refpass_step_mqc(
opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@@ -685,7 +676,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc(
}
} /* VSC and BYPASS by Antonin */
static INLINE void opj_t1_dec_refpass_step_mqc_vsc(
INLINE void opj_t1_dec_refpass_step_mqc_vsc(
opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@@ -708,7 +699,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc_vsc(
} /* VSC and BYPASS by Antonin */
static void opj_t1_enc_refpass(
void opj_t1_enc_refpass(
opj_t1_t *t1,
OPJ_INT32 bpno,
OPJ_INT32 *nmsedec,
@@ -727,7 +718,7 @@ static void opj_t1_enc_refpass(
opj_t1_enc_refpass_step(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->data_stride) + i],
&t1->data[(j * t1->w) + i],
bpno,
one,
nmsedec,
@@ -738,7 +729,7 @@ static void opj_t1_enc_refpass(
}
}
static void opj_t1_dec_refpass_raw(
void opj_t1_dec_refpass_raw(
opj_t1_t *t1,
OPJ_INT32 bpno,
OPJ_INT32 cblksty)
@@ -765,7 +756,7 @@ static void opj_t1_dec_refpass_raw(
}
} /* VSC and BYPASS by Antonin */
static void opj_t1_dec_refpass_mqc(
void opj_t1_dec_refpass_mqc(
opj_t1_t *t1,
OPJ_INT32 bpno)
{
@@ -807,7 +798,7 @@ static void opj_t1_dec_refpass_mqc(
}
} /* VSC and BYPASS by Antonin */
static void opj_t1_dec_refpass_mqc_vsc(
void opj_t1_dec_refpass_mqc_vsc(
opj_t1_t *t1,
OPJ_INT32 bpno)
{
@@ -834,7 +825,7 @@ static void opj_t1_dec_refpass_mqc_vsc(
} /* VSC and BYPASS by Antonin */
static void opj_t1_enc_clnpass_step(
void opj_t1_enc_clnpass_step(
opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@@ -860,7 +851,7 @@ static void opj_t1_enc_clnpass_step(
opj_mqc_encode(mqc, (OPJ_UINT32)v);
if (v) {
LABEL_PARTIAL:
*nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno));
*nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno + T1_NMSEDEC_FRACBITS));
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag));
v = *datap < 0 ? 1 : 0;
opj_mqc_encode(mqc, (OPJ_UINT32)(v ^ opj_t1_getspb((OPJ_UINT32)flag)));
@@ -944,7 +935,7 @@ LABEL_PARTIAL:
*flagsp &= ~T1_VISIT;
}
static void opj_t1_enc_clnpass(
void opj_t1_enc_clnpass(
opj_t1_t *t1,
OPJ_INT32 bpno,
OPJ_UINT32 orient,
@@ -969,17 +960,17 @@ static void opj_t1_enc_clnpass(
|| (MACRO_t1_flags(1 + k + 3,1 + i)
& (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
} else {
agg = !((MACRO_t1_flags(1 + k,1 + i) |
MACRO_t1_flags(1 + k + 1,1 + i) |
MACRO_t1_flags(1 + k + 2,1 + i) |
MACRO_t1_flags(1 + k + 3,1 + i)) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
}
} else {
agg = 0;
}
if (agg) {
for (runlen = 0; runlen < 4; ++runlen) {
if (opj_int_abs(t1->data[((k + runlen)*t1->data_stride) + i]) & one)
if (opj_int_abs(t1->data[((k + runlen)*t1->w) + i]) & one)
break;
}
opj_mqc_setcurctx(mqc, T1_CTXNO_AGG);
@@ -998,7 +989,7 @@ static void opj_t1_enc_clnpass(
opj_t1_enc_clnpass_step(
t1,
&t1->flags[((j+1) * t1->flags_stride) + i + 1],
&t1->data[(j * t1->data_stride) + i],
&t1->data[(j * t1->w) + i],
orient,
bpno,
one,
@@ -1068,10 +1059,10 @@ static void opj_t1_dec_clnpass(
for (i = 0; i < t1->w; ++i) {
OPJ_INT32 *data2 = data1 + i;
opj_flag_t *flags2 = flags1 + i;
agg = !((MACRO_t1_flags(1 + k, 1 + i) |
MACRO_t1_flags(1 + k + 1, 1 + i) |
MACRO_t1_flags(1 + k + 2, 1 + i) |
MACRO_t1_flags(1 + k + 3, 1 + i)) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
agg = !(MACRO_t1_flags(1 + k,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 1,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 2,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| MACRO_t1_flags(1 + k + 3,1 + i) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
if (agg) {
opj_mqc_setcurctx(mqc, T1_CTXNO_AGG);
if (!opj_mqc_decode(mqc)) {
@@ -1082,9 +1073,9 @@ static void opj_t1_dec_clnpass(
runlen = (runlen << 1) | opj_mqc_decode(mqc);
flags2 += (OPJ_UINT32)runlen * t1->flags_stride;
data2 += (OPJ_UINT32)runlen * t1->w;
for (j = (OPJ_UINT32)runlen; j < 4 && j < t1->h; ++j) {
for (j = k + (OPJ_UINT32)runlen; j < k + 4 && j < t1->h; ++j) {
flags2 += t1->flags_stride;
if (agg && (j == (OPJ_UINT32)runlen)) {
if (agg && (j == k + (OPJ_UINT32)runlen)) {
opj_t1_dec_clnpass_step_partial(t1, flags2, data2, orient, oneplushalf);
} else {
opj_t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf);
@@ -1146,13 +1137,12 @@ static OPJ_FLOAT64 opj_t1_getwmsedec(
OPJ_UINT32 qmfbid,
OPJ_FLOAT64 stepsize,
OPJ_UINT32 numcomps,
const OPJ_FLOAT64 * mct_norms,
OPJ_UINT32 mct_numcomps)
const OPJ_FLOAT64 * mct_norms)
{
OPJ_FLOAT64 w1 = 1, w2, wmsedec;
OPJ_ARG_NOT_USED(numcomps);
if (mct_norms && (compno < mct_numcomps)) {
if (mct_norms) {
w1 = mct_norms[compno];
}
@@ -1168,7 +1158,7 @@ static OPJ_FLOAT64 opj_t1_getwmsedec(
return wmsedec;
}
static OPJ_BOOL opj_t1_allocate_buffers(
OPJ_BOOL opj_t1_allocate_buffers(
opj_t1_t *t1,
OPJ_UINT32 w,
OPJ_UINT32 h)
@@ -1176,8 +1166,6 @@ static OPJ_BOOL opj_t1_allocate_buffers(
OPJ_UINT32 datasize=w * h;
OPJ_UINT32 flagssize;
/* encoder uses tile buffer, so no need to allocate */
if (!t1->encoder) {
if(datasize > t1->datasize){
opj_aligned_free(t1->data);
t1->data = (OPJ_INT32*) opj_aligned_malloc(datasize * sizeof(OPJ_INT32));
@@ -1188,7 +1176,7 @@ static OPJ_BOOL opj_t1_allocate_buffers(
t1->datasize=datasize;
}
memset(t1->data,0,datasize * sizeof(OPJ_INT32));
}
t1->flags_stride=w+2;
flagssize=t1->flags_stride * (h+2);
@@ -1217,7 +1205,7 @@ static OPJ_BOOL opj_t1_allocate_buffers(
* 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(OPJ_BOOL isEncoder)
opj_t1_t* opj_t1_create()
{
opj_t1_t *l_t1 = 00;
@@ -1238,7 +1226,6 @@ opj_t1_t* opj_t1_create(OPJ_BOOL isEncoder)
opj_t1_destroy(l_t1);
return 00;
}
l_t1->encoder = isEncoder;
return l_t1;
}
@@ -1261,8 +1248,7 @@ void opj_t1_destroy(opj_t1_t *p_t1)
opj_raw_destroy(p_t1->raw);
p_t1->raw = 00;
/* encoder uses tile buffer, so no need to free */
if (!p_t1->encoder && p_t1->data) {
if (p_t1->data) {
opj_aligned_free(p_t1->data);
p_t1->data = 00;
}
@@ -1295,6 +1281,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) {
opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno];
OPJ_INT32* restrict datap;
/*void* restrict tiledp;*/
OPJ_UINT32 cblk_w, cblk_h;
OPJ_INT32 x, y;
OPJ_UINT32 i, j;
@@ -1336,6 +1323,8 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
}
}
}
/*tiledp=(void*)&tilec->data[(y * tile_w) + x];*/
if (tccp->qmfbid == 1) {
OPJ_INT32* restrict tiledp = &tilec->data[(OPJ_UINT32)y * tile_w + (OPJ_UINT32)x];
for (j = 0; j < cblk_h; ++j) {
@@ -1353,11 +1342,18 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
*tiledp2 = tmp;
datap++;
tiledp2++;
/*float tmp = datap[(j * cblk_w) + i] * band->stepsize;
((float*)tiledp)[(j * tile_w) + i] = tmp;*/
}
tiledp += tile_w;
}
}
/*opj_free(cblk->data);
opj_free(cblk->segs);*/
/*cblk->segs = 00;*/
} /* cblkno */
/*opj_free(precinct->cblks.dec);*/
} /* precno */
} /* bandno */
} /* resno */
@@ -1365,7 +1361,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
}
static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
opj_tcd_cblk_dec_t* cblk,
OPJ_UINT32 orient,
OPJ_UINT32 roishift,
@@ -1374,7 +1370,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
opj_raw_t *raw = t1->raw; /* RAW component */
opj_mqc_t *mqc = t1->mqc; /* MQC component */
OPJ_INT32 bpno_plus_one;
OPJ_INT32 bpno;
OPJ_UINT32 passtype;
OPJ_UINT32 segno, passno;
OPJ_BYTE type = T1_TYPE_MQ; /* BYPASS mode */
@@ -1382,11 +1378,12 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
if(!opj_t1_allocate_buffers(
t1,
(OPJ_UINT32)(cblk->x1 - cblk->x0),
(OPJ_UINT32)(cblk->y1 - cblk->y0))) {
(OPJ_UINT32)(cblk->y1 - cblk->y0)))
{
return OPJ_FALSE;
}
bpno_plus_one = (OPJ_INT32)(roishift + cblk->numbps);
bpno = (OPJ_INT32)(roishift + cblk->numbps - 1);
passtype = 2;
opj_mqc_resetstates(mqc);
@@ -1398,7 +1395,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
opj_tcd_seg_t *seg = &cblk->segs[segno];
/* BYPASS mode */
type = ((bpno_plus_one <= ((OPJ_INT32) (cblk->numbps)) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
type = ((bpno <= ((OPJ_INT32) (cblk->numbps) - 1) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
/* FIXME: slviewer gets here with a null pointer. Why? Partially downloaded and/or corrupt textures? */
if(seg->data == 00){
continue;
@@ -1415,28 +1412,28 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
switch (passtype) {
case 0:
if (type == T1_TYPE_RAW) {
opj_t1_dec_sigpass_raw(t1, bpno_plus_one, (OPJ_INT32)orient, (OPJ_INT32)cblksty);
opj_t1_dec_sigpass_raw(t1, bpno+1, (OPJ_INT32)orient, (OPJ_INT32)cblksty);
} else {
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
opj_t1_dec_sigpass_mqc_vsc(t1, bpno_plus_one, (OPJ_INT32)orient);
opj_t1_dec_sigpass_mqc_vsc(t1, bpno+1, (OPJ_INT32)orient);
} else {
opj_t1_dec_sigpass_mqc(t1, bpno_plus_one, (OPJ_INT32)orient);
opj_t1_dec_sigpass_mqc(t1, bpno+1, (OPJ_INT32)orient);
}
}
break;
case 1:
if (type == T1_TYPE_RAW) {
opj_t1_dec_refpass_raw(t1, bpno_plus_one, (OPJ_INT32)cblksty);
opj_t1_dec_refpass_raw(t1, bpno+1, (OPJ_INT32)cblksty);
} else {
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
opj_t1_dec_refpass_mqc_vsc(t1, bpno_plus_one);
opj_t1_dec_refpass_mqc_vsc(t1, bpno+1);
} else {
opj_t1_dec_refpass_mqc(t1, bpno_plus_one);
opj_t1_dec_refpass_mqc(t1, bpno+1);
}
}
break;
case 2:
opj_t1_dec_clnpass(t1, bpno_plus_one, (OPJ_INT32)orient, (OPJ_INT32)cblksty);
opj_t1_dec_clnpass(t1, bpno+1, (OPJ_INT32)orient, (OPJ_INT32)cblksty);
break;
}
@@ -1448,7 +1445,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
}
if (++passtype == 3) {
passtype = 0;
bpno_plus_one--;
bpno--;
}
}
}
@@ -1461,8 +1458,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
opj_tcd_tile_t *tile,
opj_tcp_t *tcp,
const OPJ_FLOAT64 * mct_norms,
OPJ_UINT32 mct_numcomps
const OPJ_FLOAT64 * mct_norms
)
{
OPJ_UINT32 compno, resno, bandno, precno, cblkno;
@@ -1486,10 +1482,11 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
for (cblkno = 0; cblkno < prc->cw * prc->ch; ++cblkno) {
opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno];
OPJ_INT32 * restrict datap;
OPJ_INT32* restrict tiledp;
OPJ_UINT32 cblk_w;
OPJ_UINT32 cblk_h;
OPJ_UINT32 i, j, tileIndex=0, tileLineAdvance;
OPJ_UINT32 i, j;
OPJ_INT32 x = cblk->x0 - band->x0;
OPJ_INT32 y = cblk->y0 - band->y0;
@@ -1505,36 +1502,32 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
if(!opj_t1_allocate_buffers(
t1,
(OPJ_UINT32)(cblk->x1 - cblk->x0),
(OPJ_UINT32)(cblk->y1 - cblk->y0))) {
(OPJ_UINT32)(cblk->y1 - cblk->y0)))
{
return OPJ_FALSE;
}
datap=t1->data;
cblk_w = t1->w;
cblk_h = t1->h;
tileLineAdvance = tile_w - cblk_w;
tiledp=&tilec->data[(OPJ_UINT32)y * tile_w + (OPJ_UINT32)x];
t1->data = tiledp;
t1->data_stride = tile_w;
if (tccp->qmfbid == 1) {
for (j = 0; j < cblk_h; ++j) {
for (i = 0; i < cblk_w; ++i) {
tiledp[tileIndex] <<= T1_NMSEDEC_FRACBITS;
tileIndex++;
OPJ_INT32 tmp = tiledp[(j * tile_w) + i];
datap[(j * cblk_w) + i] = tmp << T1_NMSEDEC_FRACBITS;
}
tileIndex += tileLineAdvance;
}
} else { /* if (tccp->qmfbid == 0) */
for (j = 0; j < cblk_h; ++j) {
for (i = 0; i < cblk_w; ++i) {
OPJ_INT32 tmp = tiledp[tileIndex];
tiledp[tileIndex] =
opj_int_fix_mul_t1(
OPJ_INT32 tmp = tiledp[(j * tile_w) + i];
datap[(j * cblk_w) + i] =
opj_int_fix_mul(
tmp,
bandconst);
tileIndex++;
bandconst) >> (11 - T1_NMSEDEC_FRACBITS);
}
tileIndex += tileLineAdvance;
}
}
@@ -1549,8 +1542,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
tccp->cblksty,
tile->numcomps,
tile,
mct_norms,
mct_numcomps);
mct_norms);
} /* cblkno */
} /* precno */
@@ -1561,7 +1553,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
}
/** mod fixed_quality */
static void opj_t1_encode_cblk(opj_t1_t *t1,
void opj_t1_encode_cblk(opj_t1_t *t1,
opj_tcd_cblk_enc_t* cblk,
OPJ_UINT32 orient,
OPJ_UINT32 compno,
@@ -1571,8 +1563,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1,
OPJ_UINT32 cblksty,
OPJ_UINT32 numcomps,
opj_tcd_tile_t * tile,
const OPJ_FLOAT64 * mct_norms,
OPJ_UINT32 mct_numcomps)
const OPJ_FLOAT64 * mct_norms)
{
OPJ_FLOAT64 cumwmsedec = 0.0;
@@ -1583,17 +1574,15 @@ static void opj_t1_encode_cblk(opj_t1_t *t1,
OPJ_UINT32 passtype;
OPJ_INT32 nmsedec = 0;
OPJ_INT32 max;
OPJ_UINT32 i, j;
OPJ_UINT32 i;
OPJ_BYTE type = T1_TYPE_MQ;
OPJ_FLOAT64 tempwmsedec;
max = 0;
for (i = 0; i < t1->w; ++i) {
for (j = 0; j < t1->h; ++j) {
OPJ_INT32 tmp = abs(t1->data[i + j*t1->data_stride]);
for (i = 0; i < t1->w * t1->h; ++i) {
OPJ_INT32 tmp = abs(t1->data[i]);
max = opj_int_max(max, tmp);
}
}
cblk->numbps = max ? (OPJ_UINT32)((opj_int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS) : 0;
@@ -1627,7 +1616,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1,
}
/* fixed_quality */
tempwmsedec = opj_t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps,mct_norms, mct_numcomps) ;
tempwmsedec = opj_t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps,mct_norms) ;
cumwmsedec += tempwmsedec;
tile->distotile += tempwmsedec;
@@ -1701,7 +1690,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1,
}
#if 0
static void opj_t1_dec_refpass_step( opj_t1_t *t1,
void opj_t1_dec_refpass_step( opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
OPJ_INT32 poshalf,
@@ -1733,7 +1722,7 @@ static void opj_t1_dec_refpass_step( opj_t1_t *t1,
#if 0
static void opj_t1_dec_sigpass_step( opj_t1_t *t1,
void opj_t1_dec_sigpass_step( opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
OPJ_UINT32 orient,

View File

@@ -110,8 +110,6 @@ typedef struct opj_t1 {
OPJ_UINT32 datasize;
OPJ_UINT32 flagssize;
OPJ_UINT32 flags_stride;
OPJ_UINT32 data_stride;
OPJ_BOOL encoder;
} opj_t1_t;
#define MACRO_t1_flags(x,y) t1->flags[((x)*(t1->flags_stride))+(y)]
@@ -126,13 +124,11 @@ Encode the code-blocks of a tile
@param tile The tile to encode
@param tcp Tile coding parameters
@param mct_norms FIXME DOC
@param mct_numcomps Number of components used for MCT
*/
OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
opj_tcd_tile_t *tile,
opj_tcp_t *tcp,
const OPJ_FLOAT64 * mct_norms,
OPJ_UINT32 mct_numcomps);
const OPJ_FLOAT64 * mct_norms);
/**
Decode the code-blocks of a tile
@@ -151,7 +147,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
* 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(OPJ_BOOL isEncoder);
opj_t1_t* opj_t1_create(void);
/**
* Destroys a previously created T1 handle

View File

@@ -38,8 +38,7 @@
#include "opj_includes.h"
static int t1_init_ctxno_zc(int f, int orient)
{
static int t1_init_ctxno_zc(int f, int orient) {
int h, v, d, n, t, hv;
n = 0;
h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0);
@@ -111,8 +110,7 @@ static int t1_init_ctxno_zc(int f, int orient)
return (T1_CTXNO_ZC + n);
}
static int t1_init_ctxno_sc(int f)
{
static int t1_init_ctxno_sc(int f) {
int hc, vc, n;
n = 0;
@@ -153,8 +151,7 @@ static int t1_init_ctxno_sc(int f)
return (T1_CTXNO_SC + n);
}
static int t1_init_spb(int f)
{
static int t1_init_spb(int f) {
int hc, vc, n;
hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
@@ -179,8 +176,7 @@ static int t1_init_spb(int f)
return n;
}
static void dump_array16(int array[],int size)
{
static void dump_array16(int array[],int size){
int i;
--size;
for (i = 0; i < size; ++i) {
@@ -201,8 +197,7 @@ int main(int argc, char **argv)
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
(void)argc;
(void)argv;
(void)argc; (void)argv;
printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");

View File

@@ -97,8 +97,7 @@ static OPJ_BOOL opj_t2_decode_packet( opj_t2_t* t2,
OPJ_BYTE *src,
OPJ_UINT32 * data_read,
OPJ_UINT32 max_length,
opj_packet_info_t *pack_info,
opj_event_mgr_t *p_manager);
opj_packet_info_t *pack_info);
static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
@@ -107,8 +106,7 @@ static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2,
OPJ_BYTE *p_src,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *p_pack_info,
opj_event_mgr_t *p_manager);
opj_packet_info_t *p_pack_info);
static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
@@ -118,8 +116,7 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
OPJ_BYTE *p_src_data,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *p_pack_info,
opj_event_mgr_t *p_manager);
opj_packet_info_t *p_pack_info);
static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
@@ -127,16 +124,14 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2,
OPJ_BYTE *p_src_data,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *pack_info,
opj_event_mgr_t *p_manager);
opj_packet_info_t *pack_info);
static OPJ_BOOL opj_t2_skip_packet_data(opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
opj_pi_iterator_t *p_pi,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *pack_info,
opj_event_mgr_t *p_manager);
opj_packet_info_t *pack_info);
/**
@param cblk
@@ -156,15 +151,14 @@ static OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
/* ----------------------------------------------------------------------- */
/* #define RESTART 0x04 */
static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n)
{
static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n) {
while (--n >= 0) {
opj_bio_write(bio, 1, 1);
}
opj_bio_write(bio, 0, 1);
}
static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio)
OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio)
{
OPJ_UINT32 n = 0;
while (opj_bio_read(bio, 1)) {
@@ -173,8 +167,7 @@ static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio)
return n;
}
static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n)
{
void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) {
if (n == 1) {
opj_bio_write(bio, 0, 1);
} else if (n == 2) {
@@ -188,8 +181,7 @@ static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n)
}
}
static OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio)
{
OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) {
OPJ_UINT32 n;
if (!opj_bio_read(bio, 1))
return 1;
@@ -282,7 +274,8 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
++l_current_pi;
}
}
} else { /* t2_mode == FINAL_PASS */
}
else { /* t2_mode == FINAL_PASS */
opj_pi_create_encode(l_pi, l_cp,p_tile_no,p_pino,p_tp_num,p_tp_pos,p_t2_mode);
l_current_pi = &l_pi[p_pino];
@@ -352,8 +345,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
OPJ_BYTE *p_src,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_len,
opj_codestream_index_t *p_cstr_index,
opj_event_mgr_t *p_manager)
opj_codestream_index_t *p_cstr_index)
{
OPJ_BYTE *l_current_data = p_src;
opj_pi_iterator_t *l_pi = 00;
@@ -395,21 +387,19 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
* l_current_pi->resno is always >= p_tile->comps[l_current_pi->compno].minimum_num_resolutions
* and no l_img_comp->resno_decoded are computed
*/
OPJ_BOOL* first_pass_failed = NULL;
OPJ_BOOL* first_pass_failed = (OPJ_BOOL*)opj_malloc(l_image->numcomps * sizeof(OPJ_BOOL));
if (!first_pass_failed)
{
opj_pi_destroy(l_pi,l_nb_pocs);
return OPJ_FALSE;
}
memset(first_pass_failed, OPJ_TRUE, l_image->numcomps * sizeof(OPJ_BOOL));
if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) {
/* TODO ADE : add an error */
opj_pi_destroy(l_pi, l_nb_pocs);
return OPJ_FALSE;
}
first_pass_failed = (OPJ_BOOL*)opj_malloc(l_image->numcomps * sizeof(OPJ_BOOL));
if (!first_pass_failed) {
opj_pi_destroy(l_pi,l_nb_pocs);
return OPJ_FALSE;
}
memset(first_pass_failed, OPJ_TRUE, l_image->numcomps * sizeof(OPJ_BOOL));
while (opj_pi_next(l_current_pi)) {
JAS_FPRINTF( stderr, "packet offset=00000166 prg=%d cmptno=%02d rlvlno=%02d prcno=%03d lyrno=%02d\n\n",
l_current_pi->poc.prg1, l_current_pi->compno, l_current_pi->resno, l_current_pi->precno, l_current_pi->layno );
@@ -420,7 +410,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
first_pass_failed[l_current_pi->compno] = OPJ_FALSE;
if (! opj_t2_decode_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info, p_manager)) {
if (! opj_t2_decode_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info)) {
opj_pi_destroy(l_pi,l_nb_pocs);
opj_free(first_pass_failed);
return OPJ_FALSE;
@@ -428,9 +418,10 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
l_img_comp = &(l_image->comps[l_current_pi->compno]);
l_img_comp->resno_decoded = opj_uint_max(l_current_pi->resno, l_img_comp->resno_decoded);
} else {
}
else {
l_nb_bytes_read = 0;
if (! opj_t2_skip_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info, p_manager)) {
if (! opj_t2_skip_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info)) {
opj_pi_destroy(l_pi,l_nb_pocs);
opj_free(first_pass_failed);
return OPJ_FALSE;
@@ -511,22 +502,20 @@ opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp)
return l_t2;
}
void opj_t2_destroy(opj_t2_t *t2)
{
void opj_t2_destroy(opj_t2_t *t2) {
if(t2) {
opj_free(t2);
}
}
static OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2,
OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
opj_tcp_t *p_tcp,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *p_pack_info,
opj_event_mgr_t *p_manager)
opj_packet_info_t *p_pack_info)
{
OPJ_BOOL l_read_data;
OPJ_UINT32 l_nb_bytes_read = 0;
@@ -534,7 +523,7 @@ static OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2,
*p_data_read = 0;
if (! opj_t2_read_packet_header(p_t2,p_tile,p_tcp,p_pi,&l_read_data,p_src,&l_nb_bytes_read,p_max_length,p_pack_info, p_manager)) {
if (! opj_t2_read_packet_header(p_t2,p_tile,p_tcp,p_pi,&l_read_data,p_src,&l_nb_bytes_read,p_max_length,p_pack_info)) {
return OPJ_FALSE;
}
@@ -546,7 +535,7 @@ static OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2,
if (l_read_data) {
l_nb_bytes_read = 0;
if (! opj_t2_read_packet_data(p_t2,p_tile,p_pi,p_src,&l_nb_bytes_read,p_max_length,p_pack_info, p_manager)) {
if (! opj_t2_read_packet_data(p_t2,p_tile,p_pi,p_src,&l_nb_bytes_read,p_max_length,p_pack_info)) {
return OPJ_FALSE;
}
@@ -558,7 +547,7 @@ static OPJ_BOOL opj_t2_decode_packet( opj_t2_t* p_t2,
return OPJ_TRUE;
}
static OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
opj_tcd_tile_t * tile,
opj_tcp_t * tcp,
opj_pi_iterator_t *pi,
@@ -801,8 +790,7 @@ static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2,
OPJ_BYTE *p_src,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *p_pack_info,
opj_event_mgr_t *p_manager)
opj_packet_info_t *p_pack_info)
{
OPJ_BOOL l_read_data;
OPJ_UINT32 l_nb_bytes_read = 0;
@@ -810,7 +798,7 @@ static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2,
*p_data_read = 0;
if (! opj_t2_read_packet_header(p_t2,p_tile,p_tcp,p_pi,&l_read_data,p_src,&l_nb_bytes_read,p_max_length,p_pack_info, p_manager)) {
if (! opj_t2_read_packet_header(p_t2,p_tile,p_tcp,p_pi,&l_read_data,p_src,&l_nb_bytes_read,p_max_length,p_pack_info)) {
return OPJ_FALSE;
}
@@ -822,7 +810,7 @@ static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2,
if (l_read_data) {
l_nb_bytes_read = 0;
if (! opj_t2_skip_packet_data(p_t2,p_tile,p_pi,&l_nb_bytes_read,p_max_length,p_pack_info, p_manager)) {
if (! opj_t2_skip_packet_data(p_t2,p_tile,p_pi,&l_nb_bytes_read,p_max_length,p_pack_info)) {
return OPJ_FALSE;
}
@@ -834,7 +822,7 @@ static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2,
}
static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
opj_tcp_t *p_tcp,
opj_pi_iterator_t *p_pi,
@@ -842,8 +830,7 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
OPJ_BYTE *p_src_data,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *p_pack_info,
opj_event_mgr_t *p_manager)
opj_packet_info_t *p_pack_info)
{
/* loop */
@@ -892,9 +879,11 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
if (p_tcp->csty & J2K_CP_CSTY_SOP) {
if (p_max_length < 6) {
opj_event_msg(p_manager, EVT_WARNING, "Not enough space for expected SOP marker\n");
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Not enough space for expected SOP marker\n"); */
fprintf(stderr, "Not enough space for expected SOP marker\n");
} else if ((*l_current_data) != 0xff || (*(l_current_data + 1) != 0x91)) {
opj_event_msg(p_manager, EVT_WARNING, "Expected SOP marker\n");
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Expected SOP marker\n"); */
fprintf(stderr, "Warning: expected SOP marker\n");
} else {
l_current_data += 6;
}
@@ -919,11 +908,13 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
l_header_data = *l_header_data_start;
l_modified_length_ptr = &(l_cp->ppm_len);
} else if (p_tcp->ppt == 1) { /* PPT */
}
else if (p_tcp->ppt == 1) { /* PPT */
l_header_data_start = &(p_tcp->ppt_data);
l_header_data = *l_header_data_start;
l_modified_length_ptr = &(p_tcp->ppt_len);
} else { /* Normal Case */
}
else { /* Normal Case */
l_header_data_start = &(l_current_data);
l_header_data = *l_header_data_start;
l_remaining_length = (OPJ_UINT32)(p_src_data+p_max_length-l_header_data);
@@ -943,9 +934,9 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - *l_header_data_start)) < 2U) {
opj_event_msg(p_manager, EVT_WARNING, "Not enough space for expected EPH marker\n");
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
opj_event_msg(p_manager, EVT_WARNING, "Expected EPH marker\n");
fprintf(stderr, "Error : expected EPH marker\n");
} else {
l_header_data += 2;
}
@@ -987,7 +978,8 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
if (!l_cblk->numsegs) {
l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1));
/* else one bit */
} else {
}
else {
l_included = opj_bio_read(l_bio, 1);
}
@@ -1024,7 +1016,8 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
opj_bio_destroy(l_bio);
return OPJ_FALSE;
}
} else {
}
else {
l_segno = l_cblk->numsegs - 1;
if (l_cblk->segs[l_segno].numpasses == l_cblk->segs[l_segno].maxpasses) {
++l_segno;
@@ -1069,9 +1062,10 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - *l_header_data_start)) < 2U) {
opj_event_msg(p_manager, EVT_WARNING, "Not enough space for expected EPH marker\n");
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
opj_event_msg(p_manager, EVT_WARNING, "Expected EPH marker\n");
/* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_ERROR, "Expected EPH marker\n"); */
fprintf(stderr, "Error : expected EPH marker\n");
} else {
l_header_data += 2;
}
@@ -1097,14 +1091,13 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
return OPJ_TRUE;
}
static OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
opj_pi_iterator_t *p_pi,
OPJ_BYTE *p_src_data,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *pack_info,
opj_event_mgr_t* p_manager)
opj_packet_info_t *pack_info)
{
OPJ_UINT32 bandno, cblkno;
OPJ_UINT32 l_nb_code_blocks;
@@ -1141,7 +1134,8 @@ static OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
l_seg = l_cblk->segs;
++l_cblk->numsegs;
l_cblk->data_current_size = 0;
} else {
}
else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
if (l_seg->numpasses == l_seg->maxpasses) {
@@ -1153,7 +1147,7 @@ static OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
do {
/* Check possible overflow (on l_current_data only, assumes input args already checked) then size */
if ((((OPJ_SIZE_T)l_current_data + (OPJ_SIZE_T)l_seg->newlen) < (OPJ_SIZE_T)l_current_data) || (l_current_data + l_seg->newlen > p_src_data + p_max_length)) {
opj_event_msg(p_manager, EVT_ERROR, "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
fprintf(stderr, "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;
}
@@ -1164,22 +1158,22 @@ static OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
/* let's check that we are not exceeding */
if ((l_cblk->len + l_seg->newlen) > 8192) {
opj_event_msg(p_manager, EVT_WARNING,
opj_event_msg(p_t2->cinfo, EVT_WARNING,
"JPWL: segment too long (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
if (!JPWL_ASSUME) {
opj_event_msg(p_manager, EVT_ERROR, "JPWL: giving up\n");
opj_event_msg(p_t2->cinfo, EVT_ERROR, "JPWL: giving up\n");
return OPJ_FALSE;
}
l_seg->newlen = 8192 - l_cblk->len;
opj_event_msg(p_manager, EVT_WARNING, " - truncating segment to %d\n", l_seg->newlen);
opj_event_msg(p_t2->cinfo, EVT_WARNING, " - truncating segment to %d\n", l_seg->newlen);
break;
};
#endif /* USE_JPWL */
/* Check possible overflow on size */
if ((l_cblk->data_current_size + l_seg->newlen) < l_cblk->data_current_size) {
opj_event_msg(p_manager, EVT_ERROR, "read: segment too long (%d) with current size (%d > %d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
fprintf(stderr, "read: segment too long (%d) with current size (%d > %d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, l_cblk->data_current_size, 0xFFFFFFFF - l_seg->newlen, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;
}
@@ -1231,13 +1225,12 @@ static OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
return OPJ_TRUE;
}
static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
opj_pi_iterator_t *p_pi,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 p_max_length,
opj_packet_info_t *pack_info,
opj_event_mgr_t *p_manager)
opj_packet_info_t *pack_info)
{
OPJ_UINT32 bandno, cblkno;
OPJ_UINT32 l_nb_code_blocks;
@@ -1275,7 +1268,8 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
l_seg = l_cblk->segs;
++l_cblk->numsegs;
l_cblk->data_current_size = 0;
} else {
}
else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
if (l_seg->numpasses == l_seg->maxpasses) {
@@ -1287,7 +1281,7 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
do {
/* Check possible overflow then size */
if (((*p_data_read + l_seg->newlen) < (*p_data_read)) || ((*p_data_read + l_seg->newlen) > p_max_length)) {
opj_event_msg(p_manager, EVT_ERROR, "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
fprintf(stderr, "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;
}
@@ -1298,15 +1292,15 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
/* let's check that we are not exceeding */
if ((l_cblk->len + l_seg->newlen) > 8192) {
opj_event_msg(p_manager, EVT_WARNING,
opj_event_msg(p_t2->cinfo, EVT_WARNING,
"JPWL: segment too long (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
if (!JPWL_ASSUME) {
opj_event_msg(p_manager, EVT_ERROR, "JPWL: giving up\n");
opj_event_msg(p_t2->cinfo, EVT_ERROR, "JPWL: giving up\n");
return -999;
}
l_seg->newlen = 8192 - l_cblk->len;
opj_event_msg(p_manager, EVT_WARNING, " - truncating segment to %d\n", l_seg->newlen);
opj_event_msg(p_t2->cinfo, EVT_WARNING, " - truncating segment to %d\n", l_seg->newlen);
break;
};
@@ -1316,7 +1310,8 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
l_seg->numpasses += l_seg->numnewpasses;
l_cblk->numnewpasses -= l_seg->numnewpasses;
if (l_cblk->numnewpasses > 0) {
if (l_cblk->numnewpasses > 0)
{
++l_seg;
++l_cblk->numsegs;
}
@@ -1332,7 +1327,7 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
}
static OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
OPJ_UINT32 index,
OPJ_UINT32 cblksty,
OPJ_UINT32 first)
@@ -1360,7 +1355,8 @@ static OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
if (cblksty & J2K_CCP_CBLKSTY_TERMALL) {
seg->maxpasses = 1;
} else if (cblksty & J2K_CCP_CBLKSTY_LAZY) {
}
else if (cblksty & J2K_CCP_CBLKSTY_LAZY) {
if (first) {
seg->maxpasses = 10;
} else {

View File

@@ -108,8 +108,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *t2,
OPJ_BYTE *src,
OPJ_UINT32 * p_data_read,
OPJ_UINT32 len,
opj_codestream_index_t *cstr_info,
opj_event_mgr_t *p_manager);
opj_codestream_index_t *cstr_info);
/**
* Creates a Tier 2 handle

File diff suppressed because it is too large Load Diff

View File

@@ -93,7 +93,6 @@ typedef struct opj_tcd_cblk_enc {
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 data_size; /* Size of allocated data buffer */
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 */
@@ -123,7 +122,6 @@ typedef struct opj_tcd_precinct {
union{ /* code-blocks information */
opj_tcd_cblk_enc_t* enc;
opj_tcd_cblk_dec_t* dec;
void* blocks;
} cblks;
OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */
opj_tgt_tree_t *incltree; /* inclusion tree */
@@ -155,15 +153,14 @@ typedef struct opj_tcd_resolution {
/**
FIXME DOC
*/
typedef struct opj_tcd_tilecomp {
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_BOOL ownsData; /* if true, then need to free after usage, otherwise do not free */
OPJ_UINT32 data_size_needed; /* we may either need to allocate this amount of data, or re-use image data and ignore this value */
OPJ_UINT32 data_size; /* size of the data of the component */
OPJ_INT32 numpix; /* add fixed_quality */
} opj_tcd_tilecomp_t;
@@ -185,7 +182,8 @@ typedef struct opj_tcd_tile {
/**
FIXME DOC
*/
typedef struct opj_tcd_image {
typedef struct opj_tcd_image
{
opj_tcd_tile_t *tiles; /* Tiles information */
}
opj_tcd_image_t;
@@ -194,7 +192,8 @@ opj_tcd_image_t;
/**
Tile coder/decoder
*/
typedef struct opj_tcd {
typedef struct opj_tcd
{
/** Position of the tilepart flag in Progression order*/
OPJ_INT32 tp_pos;
/** Tile part number*/
@@ -259,11 +258,10 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
* @param p_tcd the tile decoder.
* @param p_tile_no the index of the tile received in sequence. This not necessarily lead to the
* tile at index p_tile_no.
* @param p_manager the event manager.
*
* @return true if the remaining data is sufficient.
*/
OPJ_BOOL opj_tcd_init_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, opj_event_mgr_t* p_manager);
OPJ_BOOL opj_tcd_init_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no);
void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final);
@@ -293,7 +291,7 @@ OPJ_UINT32 opj_tcd_get_decoded_tile_size (opj_tcd_t *p_tcd );
* @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 successful.
* @return true if the coding is successfull.
*/
OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd,
OPJ_UINT32 p_tile_no,
@@ -310,14 +308,12 @@ Decode a tile from a buffer into a raw image
@param len Length of source buffer
@param tileno Number that identifies one of the tiles to be decoded
@param cstr_info FIXME DOC
@param manager the event manager.
*/
OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *tcd,
OPJ_BYTE *src,
OPJ_UINT32 len,
OPJ_UINT32 tileno,
opj_codestream_index_t *cstr_info,
opj_event_mgr_t *manager);
opj_codestream_index_t *cstr_info);
/**
@@ -337,12 +333,11 @@ OPJ_UINT32 opj_tcd_get_encoded_tile_size ( opj_tcd_t *p_tcd );
*
* @param p_tcd TCD handle.
* @param p_tile_no current tile index to encode.
* @param p_manager the event manager.
*
* @return true if the encoding values could be set (false otherwise).
*/
OPJ_BOOL opj_tcd_init_encode_tile ( opj_tcd_t *p_tcd,
OPJ_UINT32 p_tile_no, opj_event_mgr_t* p_manager );
OPJ_UINT32 p_tile_no );
/**
* Copies tile data from the given memory block onto the system.
@@ -351,13 +346,6 @@ OPJ_BOOL opj_tcd_copy_tile_data (opj_tcd_t *p_tcd,
OPJ_BYTE * p_src,
OPJ_UINT32 p_src_length );
/**
* Allocates tile component data
*
*
*/
OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec);
/* ----------------------------------------------------------------------- */
/*@}*/

View File

@@ -45,8 +45,7 @@
==========================================================
*/
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager)
{
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
OPJ_INT32 nplh[32];
OPJ_INT32 nplv[32];
opj_tgt_node_t *node = 00;
@@ -60,7 +59,7 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_e
tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t));
if(!tree) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree\n");
fprintf(stderr, "ERROR in tgt_create while allocating tree\n");
return 00;
}
@@ -82,13 +81,13 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_e
/* ADD */
if (tree->numnodes == 0) {
opj_free(tree);
opj_event_msg(manager, EVT_WARNING, "tgt_create tree->numnodes == 0, no tree created.\n");
fprintf(stderr, "WARNING in tgt_create tree->numnodes == 0, no tree created.\n");
return 00;
}
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
if(!tree->nodes) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree nodes\n");
fprintf(stderr, "ERROR in tgt_create while allocating node of the tree\n");
opj_free(tree);
return 00;
}
@@ -131,7 +130,7 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_e
* @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 *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_UINT32 p_num_leafs_v, opj_event_mgr_t *p_manager)
opj_tgt_tree_t *opj_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];
@@ -156,13 +155,15 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
l_nplh[0] = (OPJ_INT32)p_num_leafs_h;
l_nplv[0] = (OPJ_INT32)p_num_leafs_v;
p_tree->numnodes = 0;
do {
do
{
n = (OPJ_UINT32)(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);
}
while (n > 1);
/* ADD */
if (p_tree->numnodes == 0) {
@@ -174,7 +175,7 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
if (l_node_size > p_tree->nodes_size) {
opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);
if (! new_nodes) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to reinitialize the tag tree\n");
fprintf(stderr, "ERROR Not enough memory to reinitialize the tag tree\n");
opj_tgt_destroy(p_tree);
return 00;
}
@@ -198,9 +199,12 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
}
++l_parent_node;
}
if ((j & 1) || j == l_nplv[i] - 1) {
if ((j & 1) || j == l_nplv[i] - 1)
{
l_parent_node0 = l_parent_node;
} else {
}
else
{
l_parent_node = l_parent_node0;
l_parent_node0 += l_nplh[i];
}
@@ -226,8 +230,7 @@ void opj_tgt_destroy(opj_tgt_tree_t *p_tree)
opj_free(p_tree);
}
void opj_tgt_reset(opj_tgt_tree_t *p_tree)
{
void opj_tgt_reset(opj_tgt_tree_t *p_tree) {
OPJ_UINT32 i;
opj_tgt_node_t * l_current_node = 00;;
@@ -236,7 +239,8 @@ void opj_tgt_reset(opj_tgt_tree_t *p_tree)
}
l_current_node = p_tree->nodes;
for (i = 0; i < p_tree->numnodes; ++i) {
for (i = 0; i < p_tree->numnodes; ++i)
{
l_current_node->value = 999;
l_current_node->low = 0;
l_current_node->known = 0;
@@ -244,8 +248,7 @@ void opj_tgt_reset(opj_tgt_tree_t *p_tree)
}
}
void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value)
{
void opj_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) {
@@ -254,8 +257,7 @@ void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value)
}
}
void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold)
{
void opj_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;
@@ -295,8 +297,7 @@ void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ
}
}
OPJ_UINT32 opj_tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold)
{
OPJ_UINT32 opj_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;

View File

@@ -64,7 +64,8 @@ typedef struct opj_tgt_node {
/**
Tag tree
*/
typedef struct opj_tgt_tree {
typedef struct opj_tgt_tree
{
OPJ_UINT32 numleafsh;
OPJ_UINT32 numleafsv;
OPJ_UINT32 numnodes;
@@ -82,7 +83,7 @@ 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 *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager);
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv);
/**
* Reinitialises a tag-tree from an exixting one.
@@ -90,12 +91,11 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_e
* @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
* @param p_manager the event manager
* @return a new tag-tree if successful, NULL otherwise
*/
opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,
OPJ_UINT32 p_num_leafs_h,
OPJ_UINT32 p_num_leafs_v, opj_event_mgr_t *p_manager);
OPJ_UINT32 p_num_leafs_v);
/**
Destroy a tag-tree, liberating memory
@param tree Tag-tree to destroy

View File

@@ -105,7 +105,8 @@ int opj_write_tpixfaix( int coff,
if( j2klen > pow( 2, 32)){
size_of_coding = 8;
version = num_max_tile_parts == 1 ? 1:3;
} else {
}
else{
size_of_coding = 4;
version = num_max_tile_parts == 1 ? 0:2;
}
@@ -122,8 +123,10 @@ int opj_write_tpixfaix( int coff,
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++) {
for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++) {
for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++)
{
for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++)
{
tp = cstr_info.tile[i].tp[j];
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_start_pos-coff),size_of_coding); /* start position */
@@ -131,7 +134,8 @@ int opj_write_tpixfaix( int coff,
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_pos-tp.tp_start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
if (version & 0x02) {
if (version & 0x02)
{
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
Aux = (OPJ_UINT32)(cstr_info.numdecompos[compno] + 1);
else
@@ -146,7 +150,8 @@ int opj_write_tpixfaix( int coff,
/*cio_write(0,4);*/
}
/* PADDING */
while (j < num_max_tile_parts) {
while (j < num_max_tile_parts)
{
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);

View File

@@ -27,9 +27,6 @@ if(UNIX)
target_link_libraries(${OPENJP3D_LIBRARY_NAME} m)
endif()
set_target_properties(${OPENJP3D_LIBRARY_NAME} PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
if(${CMAKE_VERSION} VERSION_GREATER "2.8.11")
target_compile_options(${OPENJP3D_LIBRARY_NAME} PRIVATE ${OPENJPEG_LIBRARY_COMPILE_OPTIONS})
endif()
# Install library
install(TARGETS ${OPENJP3D_LIBRARY_NAME}

View File

@@ -77,8 +77,7 @@ static int bio_bytein(opj_bio_t *bio);
==========================================================
*/
static int bio_byteout(opj_bio_t *bio)
{
static int bio_byteout(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
@@ -88,8 +87,7 @@ static int bio_byteout(opj_bio_t *bio)
return 0;
}
static int bio_bytein(opj_bio_t *bio)
{
static int bio_bytein(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
@@ -99,8 +97,7 @@ static int bio_bytein(opj_bio_t *bio)
return 0;
}
static void bio_putbit(opj_bio_t *bio, int b)
{
static void bio_putbit(opj_bio_t *bio, int b) {
if (bio->ct == 0) {
bio_byteout(bio);
}
@@ -109,8 +106,7 @@ static void bio_putbit(opj_bio_t *bio, int b)
}
/* MOD antonin */
static int bio_getbit(opj_bio_t *bio)
{
static int bio_getbit(opj_bio_t *bio) {
/* DOM */
if (bio->ct == 0) {
bio_bytein(bio);
@@ -125,26 +121,22 @@ static int bio_getbit(opj_bio_t *bio)
==========================================================
*/
opj_bio_t* bio_create()
{
opj_bio_t* bio_create() {
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
}
void bio_destroy(opj_bio_t *bio)
{
void bio_destroy(opj_bio_t *bio) {
if(bio) {
opj_free(bio);
}
}
int bio_numbytes(opj_bio_t *bio)
{
int 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, unsigned char *bp, int len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
@@ -152,8 +144,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, unsigned char *bp, int len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
@@ -161,16 +152,14 @@ 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)
{
void bio_write(opj_bio_t *bio, int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
bio_putbit(bio, (v >> i) & 1);
}
}
int bio_read(opj_bio_t *bio, int n)
{
int bio_read(opj_bio_t *bio, int n) {
int i, v;
v = 0;
for (i = n - 1; i >= 0; i--) {
@@ -179,8 +168,7 @@ int bio_read(opj_bio_t *bio, int n)
return v;
}
int bio_flush(opj_bio_t *bio)
{
int bio_flush(opj_bio_t *bio) {
bio->ct = 0;
if (bio_byteout(bio)) {
return 1;
@@ -194,8 +182,7 @@ int bio_flush(opj_bio_t *bio)
return 0;
}
int bio_inalign(opj_bio_t *bio)
{
int bio_inalign(opj_bio_t *bio) {
bio->ct = 0;
if ((bio->buf & 0xff) == 0xff) {
if (bio_bytein(bio)) {

View File

@@ -37,8 +37,7 @@
/* ----------------------------------------------------------------------- */
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length)
{
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) {
opj_cp_t *cp = NULL;
opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t));
if(!cio) return NULL;
@@ -48,7 +47,8 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
cio->openmode = OPJ_STREAM_READ;
cio->buffer = buffer;
cio->length = length;
} else if(!buffer && !length && cinfo) {
}
else if(!buffer && !length && cinfo) {
/* allocate a buffer for the encoded image */
cio->openmode = OPJ_STREAM_WRITE;
switch(cinfo->codec_format) {
@@ -67,7 +67,8 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
opj_free(cio);
return NULL;
}
} else {
}
else {
opj_free(cio);
return NULL;
}
@@ -80,8 +81,7 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
return cio;
}
void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio)
{
void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) {
if(cio) {
if(cio->openmode == OPJ_STREAM_WRITE) {
/* destroy the allocated buffer */
@@ -98,8 +98,7 @@ void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio)
/*
* Get position in byte stream.
*/
int OPJ_CALLCONV cio_tell(opj_cio_t *cio)
{
int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
return cio->bp - cio->start;
}
@@ -108,32 +107,28 @@ int OPJ_CALLCONV cio_tell(opj_cio_t *cio)
*
* pos : position, in number of bytes, from the beginning of the stream
*/
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos)
{
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) {
cio->bp = cio->start + pos;
}
/*
* Number of bytes left before the end of the stream.
*/
int cio_numbytesleft(opj_cio_t *cio)
{
int cio_numbytesleft(opj_cio_t *cio) {
return cio->end - cio->bp;
}
/*
* Get pointer to the current position in the stream.
*/
unsigned char *cio_getbp(opj_cio_t *cio)
{
unsigned char *cio_getbp(opj_cio_t *cio) {
return cio->bp;
}
/*
* Write a byte.
*/
static bool cio_byteout(opj_cio_t *cio, unsigned char v)
{
static bool cio_byteout(opj_cio_t *cio, unsigned char v) {
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
return false;
@@ -145,8 +140,7 @@ static bool cio_byteout(opj_cio_t *cio, unsigned char v)
/*
* Read a byte.
*/
static unsigned char cio_bytein(opj_cio_t *cio)
{
static unsigned char cio_bytein(opj_cio_t *cio) {
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
return 0;
@@ -160,8 +154,7 @@ static unsigned char cio_bytein(opj_cio_t *cio)
* v : value to write
* n : number of bytes to write
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n)
{
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
@@ -177,8 +170,7 @@ unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n)
*
* return : value of the n bytes read
*/
unsigned int cio_read(opj_cio_t *cio, int n)
{
unsigned int cio_read(opj_cio_t *cio, int n) {
int i;
unsigned int v;
v = 0;
@@ -193,8 +185,7 @@ unsigned int cio_read(opj_cio_t *cio, int n)
*
* n : number of bytes to skip
*/
void cio_skip(opj_cio_t *cio, int n)
{
void cio_skip(opj_cio_t *cio, int n) {
cio->bp += n;
}
@@ -204,8 +195,7 @@ void cio_skip(opj_cio_t *cio, int n)
* v : value to write
* n : number of bytes to write
*/
int cio_write_int(opj_cio_t *cio, int v, int n)
{
int cio_write_int(opj_cio_t *cio, int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) )
@@ -221,8 +211,7 @@ int cio_write_int(opj_cio_t *cio, int v, int n)
*
* return : value of the n bytes read
*/
int cio_read_int(opj_cio_t *cio, int n)
{
int cio_read_int(opj_cio_t *cio, int n) {
int i;
int v;
v = 0;

Some files were not shown because too many files have changed in this diff Show More