OpenJPEG 1.5.2
This commit is contained in:
@@ -7,14 +7,15 @@ include(00-Common)
|
|||||||
|
|
||||||
# OPENJPEG version number, useful for packaging and doxygen doc:
|
# OPENJPEG version number, useful for packaging and doxygen doc:
|
||||||
set(OPENJPEG_VERSION_MAJOR 1)
|
set(OPENJPEG_VERSION_MAJOR 1)
|
||||||
set(OPENJPEG_VERSION_MINOR 4)
|
set(OPENJPEG_VERSION_MINOR 5)
|
||||||
set(OPENJPEG_VERSION_BUILD 0)
|
set(OPENJPEG_VERSION_BUILD 2)
|
||||||
set(OPENJPEG_VERSION
|
set(OPENJPEG_VERSION
|
||||||
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
|
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
|
||||||
|
|
||||||
set(openjpeg_SOURCE_FILES
|
set(openjpeg_SOURCE_FILES
|
||||||
bio.c
|
bio.c
|
||||||
cio.c
|
cio.c
|
||||||
|
cidx_manager.c
|
||||||
dwt.c
|
dwt.c
|
||||||
event.c
|
event.c
|
||||||
image.c
|
image.c
|
||||||
@@ -26,20 +27,26 @@ set(openjpeg_SOURCE_FILES
|
|||||||
mqc.c
|
mqc.c
|
||||||
openjpeg.c
|
openjpeg.c
|
||||||
pi.c
|
pi.c
|
||||||
|
phix_manager.c
|
||||||
|
ppix_manager.c
|
||||||
raw.c
|
raw.c
|
||||||
t1.c
|
t1.c
|
||||||
t2.c
|
t2.c
|
||||||
tcd.c
|
tcd.c
|
||||||
tgt.c
|
tgt.c
|
||||||
|
thix_manager.c
|
||||||
|
tpix_manager.c
|
||||||
)
|
)
|
||||||
|
|
||||||
set(openjpeg_HEADER_FILES
|
set(openjpeg_HEADER_FILES
|
||||||
bio.h
|
bio.h
|
||||||
cio.h
|
cio.h
|
||||||
|
cidx_manager.h
|
||||||
dwt.h
|
dwt.h
|
||||||
event.h
|
event.h
|
||||||
fix.h
|
fix.h
|
||||||
image.h
|
image.h
|
||||||
|
indexbox_manager.h
|
||||||
int.h
|
int.h
|
||||||
j2k.h
|
j2k.h
|
||||||
j2k_lib.h
|
j2k_lib.h
|
||||||
@@ -48,6 +55,7 @@ set(openjpeg_HEADER_FILES
|
|||||||
mct.h
|
mct.h
|
||||||
mqc.h
|
mqc.h
|
||||||
openjpeg.h
|
openjpeg.h
|
||||||
|
opj_config.h
|
||||||
opj_includes.h
|
opj_includes.h
|
||||||
opj_malloc.h
|
opj_malloc.h
|
||||||
pi.h
|
pi.h
|
||||||
|
|||||||
211
indra/libopenjpeg/cidx_manager.c
Normal file
211
indra/libopenjpeg/cidx_manager.c
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
/*
|
||||||
|
* $Id: cidx_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||||
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||||
|
* Copyright (c) 2003-2004, Yannick Verschueren
|
||||||
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "opj_includes.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write CPTR Codestream finder box
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] clen length of j2k codestream
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
*/
|
||||||
|
void write_cptr(int coff, int clen, opj_cio_t *cio);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write main header index table (box)
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return length of mainmhix box
|
||||||
|
*/
|
||||||
|
int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check if EPH option is used
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] markers marker information
|
||||||
|
* @param[in] marknum number of markers
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return true if EPH is used
|
||||||
|
*/
|
||||||
|
opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio);
|
||||||
|
|
||||||
|
|
||||||
|
int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen)
|
||||||
|
{
|
||||||
|
int len, i, lenp;
|
||||||
|
opj_jp2_box_t *box;
|
||||||
|
int num_box = 0;
|
||||||
|
opj_bool EPHused;
|
||||||
|
(void)image; /* unused ? */
|
||||||
|
|
||||||
|
lenp = -1;
|
||||||
|
box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
|
||||||
|
|
||||||
|
for (i=0;i<2;i++){
|
||||||
|
|
||||||
|
if(i)
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_CIDX, 4); /* CIDX */
|
||||||
|
write_cptr( offset, cstr_info.codestream_size, cio);
|
||||||
|
|
||||||
|
write_manf( i, num_box, box, cio);
|
||||||
|
|
||||||
|
num_box = 0;
|
||||||
|
box[num_box].length = write_mainmhix( offset, cstr_info, cio);
|
||||||
|
box[num_box].type = JPIP_MHIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
box[num_box].length = write_tpix( offset, cstr_info, j2klen, cio);
|
||||||
|
box[num_box].type = JPIP_TPIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
box[num_box].length = write_thix( offset, cstr_info, cio);
|
||||||
|
box[num_box].type = JPIP_THIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
EPHused = check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio);
|
||||||
|
|
||||||
|
box[num_box].length = write_ppix( offset, cstr_info, EPHused, j2klen, cio);
|
||||||
|
box[num_box].type = JPIP_PPIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
box[num_box].length = write_phix( offset, cstr_info, EPHused, j2klen, cio);
|
||||||
|
box[num_box].type = JPIP_PHIX;
|
||||||
|
num_box++;
|
||||||
|
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free( box);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_cptr(int coff, int clen, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int len, lenp;
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_CPTR, 4); /* T */
|
||||||
|
cio_write( cio, 0, 2); /* DR A PRECISER !! */
|
||||||
|
cio_write( cio, 0, 2); /* CONT */
|
||||||
|
cio_write( cio, coff, 8); /* COFF A PRECISER !! */
|
||||||
|
cio_write( cio, clen, 8); /* CLEN */
|
||||||
|
len = cio_tell( cio) - lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int len, lenp, i;
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_MANF,4); /* T */
|
||||||
|
|
||||||
|
if (second){ /* Write only during the second pass */
|
||||||
|
for( i=0; i<v; i++){
|
||||||
|
cio_write( cio, box[i].length, 4); /* Box length */
|
||||||
|
cio_write( cio, box[i].type, 4); /* Box type */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len = cio_tell( cio) - lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int len, lenp;
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_MHIX, 4); /* MHIX */
|
||||||
|
|
||||||
|
cio_write( cio, cstr_info.main_head_end-cstr_info.main_head_start+1, 8); /* TLEN */
|
||||||
|
|
||||||
|
for(i = 1; i < cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */
|
||||||
|
cio_write( cio, cstr_info.marker[i].type, 2);
|
||||||
|
cio_write( cio, 0, 2);
|
||||||
|
cio_write( cio, cstr_info.marker[i].pos-coff, 8);
|
||||||
|
cio_write( cio, cstr_info.marker[i].len, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
len = cio_tell( cio) - lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
opj_bool EPHused = OPJ_FALSE;
|
||||||
|
int i=0;
|
||||||
|
int org_pos;
|
||||||
|
unsigned int Scod;
|
||||||
|
|
||||||
|
for(i = 0; i < marknum; i++){
|
||||||
|
if( markers[i].type == J2K_MS_COD){
|
||||||
|
org_pos = cio_tell( cio);
|
||||||
|
cio_seek( cio, coff+markers[i].pos+2);
|
||||||
|
|
||||||
|
Scod = cio_read( cio, 1);
|
||||||
|
if( ((Scod >> 2) & 1))
|
||||||
|
EPHused = OPJ_TRUE;
|
||||||
|
cio_seek( cio, org_pos);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return EPHused;
|
||||||
|
}
|
||||||
56
indra/libopenjpeg/cidx_manager.h
Normal file
56
indra/libopenjpeg/cidx_manager.h
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* $Id: cidx_manager.h 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||||
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||||
|
* Copyright (c) 2003-2004, Yannick Verschueren
|
||||||
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \file
|
||||||
|
* \brief Modification of jpip.h from 2KAN indexer
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CIDX_MANAGER_H_
|
||||||
|
# define CIDX_MANAGER_H_
|
||||||
|
|
||||||
|
#include "openjpeg.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write Codestream index box (superbox)
|
||||||
|
*
|
||||||
|
* @param[in] offset offset of j2k codestream
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @param[in] image image data
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @param[in] j2klen length of j2k codestream
|
||||||
|
* @return length of cidx box
|
||||||
|
*/
|
||||||
|
int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* !CIDX_MANAGER_H_ */
|
||||||
@@ -126,13 +126,13 @@ unsigned char *cio_getbp(opj_cio_t *cio) {
|
|||||||
/*
|
/*
|
||||||
* Write a byte.
|
* Write a byte.
|
||||||
*/
|
*/
|
||||||
bool cio_byteout(opj_cio_t *cio, unsigned char v) {
|
opj_bool cio_byteout(opj_cio_t *cio, unsigned char v) {
|
||||||
if (cio->bp >= cio->end) {
|
if (cio->bp >= cio->end) {
|
||||||
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
|
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
*cio->bp++ = v;
|
*cio->bp++ = v;
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -152,7 +152,7 @@ unsigned char cio_bytein(opj_cio_t *cio) {
|
|||||||
* v : value to write
|
* v : value to write
|
||||||
* n : number of bytes 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 int64 v, int n) {
|
||||||
int i;
|
int i;
|
||||||
for (i = n - 1; i >= 0; i--) {
|
for (i = n - 1; i >= 0; i--) {
|
||||||
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
|
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
|
||||||
|
|||||||
@@ -31,6 +31,13 @@
|
|||||||
|
|
||||||
#ifndef __CIO_H
|
#ifndef __CIO_H
|
||||||
#define __CIO_H
|
#define __CIO_H
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||||
|
#define int64 __int64
|
||||||
|
#else
|
||||||
|
#define int64 long long
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@file cio.h
|
@file cio.h
|
||||||
@brief Implementation of a byte input-output process (CIO)
|
@brief Implementation of a byte input-output process (CIO)
|
||||||
@@ -63,7 +70,7 @@ Write some bytes
|
|||||||
@param n Number of bytes to write
|
@param n Number of bytes to write
|
||||||
@return Returns the number of bytes written or 0 if an error occured
|
@return Returns the number of bytes written or 0 if an error occured
|
||||||
*/
|
*/
|
||||||
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n);
|
unsigned int cio_write(opj_cio_t *cio, unsigned int64 v, int n);
|
||||||
/**
|
/**
|
||||||
Read some bytes
|
Read some bytes
|
||||||
@param cio CIO handle
|
@param cio CIO handle
|
||||||
|
|||||||
@@ -64,12 +64,12 @@ typedef struct v4dwt_local {
|
|||||||
int cas ;
|
int cas ;
|
||||||
} v4dwt_t ;
|
} v4dwt_t ;
|
||||||
|
|
||||||
static const float dwt_alpha = 1.586134342f; // 12994
|
static const float dwt_alpha = 1.586134342f; /* 12994 */
|
||||||
static const float dwt_beta = 0.052980118f; // 434
|
static const float dwt_beta = 0.052980118f; /* 434 */
|
||||||
static const float dwt_gamma = -0.882911075f; // -7233
|
static const float dwt_gamma = -0.882911075f; /* -7233 */
|
||||||
static const float dwt_delta = -0.443506852f; // -3633
|
static const float dwt_delta = -0.443506852f; /* -3633 */
|
||||||
|
|
||||||
static const float K = 1.230174105f; // 10078
|
static const float K = 1.230174105f; /* 10078 */
|
||||||
/* FIXME: What is this constant? */
|
/* FIXME: What is this constant? */
|
||||||
static const float c13318 = 1.625732422f;
|
static const float c13318 = 1.625732422f;
|
||||||
|
|
||||||
@@ -527,7 +527,7 @@ static void dwt_decode_tile(opj_tcd_tilecomp_t* tilec, int numres, DWT1DFN dwt_1
|
|||||||
|
|
||||||
int w = tilec->x1 - tilec->x0;
|
int w = tilec->x1 - tilec->x0;
|
||||||
|
|
||||||
h.mem = (int *)opj_aligned_malloc(dwt_decode_max_resolution(tr, numres) * sizeof(int));
|
h.mem = (int*)opj_aligned_malloc(dwt_decode_max_resolution(tr, numres) * sizeof(int));
|
||||||
v.mem = h.mem;
|
v.mem = h.mem;
|
||||||
|
|
||||||
while( --numres) {
|
while( --numres) {
|
||||||
@@ -570,7 +570,7 @@ static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x, in
|
|||||||
int count = w->sn;
|
int count = w->sn;
|
||||||
int i, k;
|
int i, k;
|
||||||
for(k = 0; k < 2; ++k){
|
for(k = 0; k < 2; ++k){
|
||||||
if (count + 3 * x < size && ((long) a & 0x0f) == 0 && ((long) bi & 0x0f) == 0 && (x & 0x0f) == 0) {
|
if (count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0) {
|
||||||
/* Fast code path */
|
/* Fast code path */
|
||||||
for(i = 0; i < count; ++i){
|
for(i = 0; i < count; ++i){
|
||||||
int j = i;
|
int j = i;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Hervé Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -26,6 +26,42 @@
|
|||||||
|
|
||||||
#include "opj_includes.h"
|
#include "opj_includes.h"
|
||||||
|
|
||||||
|
/* ==========================================================
|
||||||
|
Utility functions
|
||||||
|
==========================================================*/
|
||||||
|
|
||||||
|
#ifdef OPJ_CODE_NOT_USED
|
||||||
|
#ifndef _WIN32
|
||||||
|
static char*
|
||||||
|
i2a(unsigned i, char *a, unsigned r) {
|
||||||
|
if (i/r > 0) a = i2a(i/r,a,r);
|
||||||
|
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
|
||||||
|
return a+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Transforms integer i into an ascii string and stores the result in a;
|
||||||
|
string is encoded in the base indicated by r.
|
||||||
|
@param i Number to be converted
|
||||||
|
@param a String result
|
||||||
|
@param r Base of value; must be in the range 2 - 36
|
||||||
|
@return Returns a
|
||||||
|
*/
|
||||||
|
static char *
|
||||||
|
_itoa(int i, char *a, int r) {
|
||||||
|
r = ((r < 2) || (r > 36)) ? 10 : r;
|
||||||
|
if(i < 0) {
|
||||||
|
*a = '-';
|
||||||
|
*i2a(-i, a+1, r) = 0;
|
||||||
|
}
|
||||||
|
else *i2a(i, a, r) = 0;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* !_WIN32 */
|
||||||
|
#endif
|
||||||
|
/* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
|
opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
|
||||||
if(cinfo) {
|
if(cinfo) {
|
||||||
opj_event_mgr_t *previous = cinfo->event_mgr;
|
opj_event_mgr_t *previous = cinfo->event_mgr;
|
||||||
@@ -37,7 +73,7 @@ opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
|
opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
|
||||||
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
|
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
|
||||||
opj_msg_callback msg_handler = NULL;
|
opj_msg_callback msg_handler = NULL;
|
||||||
|
|
||||||
@@ -57,30 +93,29 @@ bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(msg_handler == NULL) {
|
if(msg_handler == NULL) {
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fmt != NULL) && (event_mgr != NULL)) {
|
if ((fmt != NULL) && (event_mgr != NULL)) {
|
||||||
va_list arg;
|
va_list arg;
|
||||||
int str_length/*, i, j*/; /* UniPG */
|
int str_length/*, i, j*/; /* UniPG */
|
||||||
char message[MSG_SIZE];
|
char message[MSG_SIZE];
|
||||||
memset(message, 0, MSG_SIZE);
|
|
||||||
/* initialize the optional parameter list */
|
/* initialize the optional parameter list */
|
||||||
va_start(arg, fmt);
|
va_start(arg, fmt);
|
||||||
/* check the length of the format string */
|
|
||||||
str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
|
|
||||||
/* parse the format string and put the result in 'message' */
|
/* parse the format string and put the result in 'message' */
|
||||||
vsprintf(message, fmt, arg); /* UniPG */
|
str_length = vsnprintf(message, MSG_SIZE, fmt, arg); /* UniPG */
|
||||||
/* deinitialize the optional parameter list */
|
/* deinitialize the optional parameter list */
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
|
|
||||||
/* output the message to the user program */
|
/* output the message to the user program */
|
||||||
msg_handler(message, cinfo->client_data);
|
if( str_length > -1 && str_length < MSG_SIZE )
|
||||||
|
msg_handler(message, cinfo->client_data);
|
||||||
|
else return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Herv<EFBFBD> Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -49,7 +49,7 @@ Write formatted data to a string and send the string to a user callback.
|
|||||||
@param fmt Format-control string (plus optionnal arguments)
|
@param fmt Format-control string (plus optionnal arguments)
|
||||||
@return Returns true if successful, returns false otherwise
|
@return Returns true if successful, returns false otherwise
|
||||||
*/
|
*/
|
||||||
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...);
|
opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...);
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Herv Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
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));
|
opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t));
|
||||||
image->comps=NULL;
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Herv<EFBFBD> Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
118
indra/libopenjpeg/indexbox_manager.h
Normal file
118
indra/libopenjpeg/indexbox_manager.h
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* $Id: indexbox_manager.h 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||||
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||||
|
* Copyright (c) 2003-2004, Yannick Verschueren
|
||||||
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \file
|
||||||
|
* \brief Modification of jpip.c from 2KAN indexer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INDEXBOX_MANAGER_H_
|
||||||
|
# define INDEXBOX_MANAGER_H_
|
||||||
|
|
||||||
|
#include "openjpeg.h"
|
||||||
|
#include "j2k.h" /* needed to use jp2.h */
|
||||||
|
#include "jp2.h"
|
||||||
|
|
||||||
|
#define JPIP_CIDX 0x63696478 /* Codestream index */
|
||||||
|
#define JPIP_CPTR 0x63707472 /* Codestream Finder Box */
|
||||||
|
#define JPIP_MANF 0x6d616e66 /* Manifest Box */
|
||||||
|
#define JPIP_FAIX 0x66616978 /* Fragment array Index box */
|
||||||
|
#define JPIP_MHIX 0x6d686978 /* Main Header Index Table */
|
||||||
|
#define JPIP_TPIX 0x74706978 /* Tile-part Index Table box */
|
||||||
|
#define JPIP_THIX 0x74686978 /* Tile header Index Table box */
|
||||||
|
#define JPIP_PPIX 0x70706978 /* Precinct Packet Index Table box */
|
||||||
|
#define JPIP_PHIX 0x70686978 /* Packet Header index Table */
|
||||||
|
#define JPIP_FIDX 0x66696478 /* File Index */
|
||||||
|
#define JPIP_FPTR 0x66707472 /* File Finder */
|
||||||
|
#define JPIP_PRXY 0x70727879 /* Proxy boxes */
|
||||||
|
#define JPIP_IPTR 0x69707472 /* Index finder box */
|
||||||
|
#define JPIP_PHLD 0x70686c64 /* Place holder */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write tile-part Index table box (superbox)
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @param[in] j2klen length of j2k codestream
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return length of tpix box
|
||||||
|
*/
|
||||||
|
int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write tile header index table box (superbox)
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] cstr_info codestream information pointer
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return length of thix box
|
||||||
|
*/
|
||||||
|
int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write precinct packet index table box (superbox)
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @param[in] EPHused true if EPH option used
|
||||||
|
* @param[in] j2klen length of j2k codestream
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return length of ppix box
|
||||||
|
*/
|
||||||
|
int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write packet header index table box (superbox)
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @param[in] EPHused true if EPH option used
|
||||||
|
* @param[in] j2klen length of j2k codestream
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return length of ppix box
|
||||||
|
*/
|
||||||
|
int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wriet manifest box (box)
|
||||||
|
*
|
||||||
|
* @param[in] second number to be visited
|
||||||
|
* @param[in] v number of boxes
|
||||||
|
* @param[in] box box to be manifested
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
*/
|
||||||
|
void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* !INDEXBOX_MANAGER_H_ */
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* Copyright (c) 2006-2007, Parvatha Elangovan
|
* Copyright (c) 2006-2007, Parvatha Elangovan
|
||||||
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -228,6 +229,23 @@ Read an unknown marker
|
|||||||
@param j2k J2K handle
|
@param j2k J2K handle
|
||||||
*/
|
*/
|
||||||
static void j2k_read_unk(opj_j2k_t *j2k);
|
static void j2k_read_unk(opj_j2k_t *j2k);
|
||||||
|
/**
|
||||||
|
Add main header marker information
|
||||||
|
@param cstr_info Codestream information structure
|
||||||
|
@param type marker type
|
||||||
|
@param pos byte offset of marker segment
|
||||||
|
@param len length of marker segment
|
||||||
|
*/
|
||||||
|
static void j2k_add_mhmarker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len);
|
||||||
|
/**
|
||||||
|
Add tile header marker information
|
||||||
|
@param tileno tile index number
|
||||||
|
@param cstr_info Codestream information structure
|
||||||
|
@param type marker type
|
||||||
|
@param pos byte offset of marker segment
|
||||||
|
@param len length of marker segment
|
||||||
|
*/
|
||||||
|
static void j2k_add_tlmarker( int tileno, opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len);
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
@@ -258,80 +276,6 @@ char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){
|
|||||||
return po->str_prog;
|
return po->str_prog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void j2k_dump_image(FILE *fd, opj_image_t * img) {
|
|
||||||
int compno;
|
|
||||||
fprintf(fd, "image {\n");
|
|
||||||
fprintf(fd, " x0=%d, y0=%d, x1=%d, y1=%d\n", img->x0, img->y0, img->x1, img->y1);
|
|
||||||
fprintf(fd, " numcomps=%d\n", img->numcomps);
|
|
||||||
for (compno = 0; compno < img->numcomps; compno++) {
|
|
||||||
opj_image_comp_t *comp = &img->comps[compno];
|
|
||||||
fprintf(fd, " comp %d {\n", compno);
|
|
||||||
fprintf(fd, " dx=%d, dy=%d\n", comp->dx, comp->dy);
|
|
||||||
fprintf(fd, " prec=%d\n", comp->prec);
|
|
||||||
//fprintf(fd, " bpp=%d\n", comp->bpp);
|
|
||||||
fprintf(fd, " sgnd=%d\n", comp->sgnd);
|
|
||||||
fprintf(fd, " }\n");
|
|
||||||
}
|
|
||||||
fprintf(fd, "}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp) {
|
|
||||||
int tileno, compno, layno, bandno, resno, numbands;
|
|
||||||
fprintf(fd, "coding parameters {\n");
|
|
||||||
fprintf(fd, " tx0=%d, ty0=%d\n", cp->tx0, cp->ty0);
|
|
||||||
fprintf(fd, " tdx=%d, tdy=%d\n", cp->tdx, cp->tdy);
|
|
||||||
fprintf(fd, " tw=%d, th=%d\n", cp->tw, cp->th);
|
|
||||||
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
|
|
||||||
opj_tcp_t *tcp = &cp->tcps[tileno];
|
|
||||||
fprintf(fd, " tile %d {\n", tileno);
|
|
||||||
fprintf(fd, " csty=%x\n", tcp->csty);
|
|
||||||
fprintf(fd, " prg=%d\n", tcp->prg);
|
|
||||||
fprintf(fd, " numlayers=%d\n", tcp->numlayers);
|
|
||||||
fprintf(fd, " mct=%d\n", tcp->mct);
|
|
||||||
fprintf(fd, " rates=");
|
|
||||||
for (layno = 0; layno < tcp->numlayers; layno++) {
|
|
||||||
fprintf(fd, "%.1f ", tcp->rates[layno]);
|
|
||||||
}
|
|
||||||
fprintf(fd, "\n");
|
|
||||||
for (compno = 0; compno < img->numcomps; compno++) {
|
|
||||||
opj_tccp_t *tccp = &tcp->tccps[compno];
|
|
||||||
fprintf(fd, " comp %d {\n", compno);
|
|
||||||
fprintf(fd, " csty=%x\n", tccp->csty);
|
|
||||||
fprintf(fd, " numresolutions=%d\n", tccp->numresolutions);
|
|
||||||
fprintf(fd, " cblkw=%d\n", tccp->cblkw);
|
|
||||||
fprintf(fd, " cblkh=%d\n", tccp->cblkh);
|
|
||||||
fprintf(fd, " cblksty=%x\n", tccp->cblksty);
|
|
||||||
fprintf(fd, " qmfbid=%d\n", tccp->qmfbid);
|
|
||||||
fprintf(fd, " qntsty=%d\n", tccp->qntsty);
|
|
||||||
fprintf(fd, " numgbits=%d\n", tccp->numgbits);
|
|
||||||
fprintf(fd, " roishift=%d\n", tccp->roishift);
|
|
||||||
fprintf(fd, " stepsizes=");
|
|
||||||
numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2;
|
|
||||||
for (bandno = 0; bandno < numbands; bandno++) {
|
|
||||||
fprintf(fd, "(%d,%d) ", tccp->stepsizes[bandno].mant,
|
|
||||||
tccp->stepsizes[bandno].expn);
|
|
||||||
}
|
|
||||||
fprintf(fd, "\n");
|
|
||||||
|
|
||||||
if (tccp->csty & J2K_CCP_CSTY_PRT) {
|
|
||||||
fprintf(fd, " prcw=");
|
|
||||||
for (resno = 0; resno < tccp->numresolutions; resno++) {
|
|
||||||
fprintf(fd, "%d ", tccp->prcw[resno]);
|
|
||||||
}
|
|
||||||
fprintf(fd, "\n");
|
|
||||||
fprintf(fd, " prch=");
|
|
||||||
for (resno = 0; resno < tccp->numresolutions; resno++) {
|
|
||||||
fprintf(fd, "%d ", tccp->prch[resno]);
|
|
||||||
}
|
|
||||||
fprintf(fd, "\n");
|
|
||||||
}
|
|
||||||
fprintf(fd, " }\n");
|
|
||||||
}
|
|
||||||
fprintf(fd, " }\n");
|
|
||||||
}
|
|
||||||
fprintf(fd, "}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
|
static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
|
||||||
char *prog;
|
char *prog;
|
||||||
@@ -371,6 +315,9 @@ static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
|
|||||||
/** mem allocation for TLM marker*/
|
/** mem allocation for TLM marker*/
|
||||||
int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *j2k ){
|
int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *j2k ){
|
||||||
int pino,tileno,totnum_tp=0;
|
int pino,tileno,totnum_tp=0;
|
||||||
|
|
||||||
|
OPJ_ARG_NOT_USED(img_numcomp);
|
||||||
|
|
||||||
j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
|
j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
|
||||||
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
|
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
|
||||||
int cur_totnum_tp = 0;
|
int cur_totnum_tp = 0;
|
||||||
@@ -399,12 +346,14 @@ static void j2k_write_soc(opj_j2k_t *j2k) {
|
|||||||
opj_cio_t *cio = j2k->cio;
|
opj_cio_t *cio = j2k->cio;
|
||||||
cio_write(cio, J2K_MS_SOC, 2);
|
cio_write(cio, J2K_MS_SOC, 2);
|
||||||
|
|
||||||
|
if(j2k->cstr_info)
|
||||||
|
j2k_add_mhmarker(j2k->cstr_info, J2K_MS_SOC, cio_tell(cio), 0);
|
||||||
|
|
||||||
/* UniPG>> */
|
/* UniPG>> */
|
||||||
#ifdef USE_JPWL
|
#ifdef USE_JPWL
|
||||||
|
|
||||||
/* update markers struct */
|
/* update markers struct */
|
||||||
j2k_add_marker(j2k->cstr_info, J2K_MS_SOC, cio_tell(cio) - 2, 2);
|
j2k_add_marker(j2k->cstr_info, J2K_MS_SOC, cio_tell(cio) - 2, 2);
|
||||||
|
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
/* <<UniPG */
|
/* <<UniPG */
|
||||||
}
|
}
|
||||||
@@ -425,7 +374,7 @@ static void j2k_write_siz(opj_j2k_t *j2k) {
|
|||||||
opj_cio_t *cio = j2k->cio;
|
opj_cio_t *cio = j2k->cio;
|
||||||
opj_image_t *image = j2k->image;
|
opj_image_t *image = j2k->image;
|
||||||
opj_cp_t *cp = j2k->cp;
|
opj_cp_t *cp = j2k->cp;
|
||||||
|
|
||||||
cio_write(cio, J2K_MS_SIZ, 2); /* SIZ */
|
cio_write(cio, J2K_MS_SIZ, 2); /* SIZ */
|
||||||
lenp = cio_tell(cio);
|
lenp = cio_tell(cio);
|
||||||
cio_skip(cio, 2);
|
cio_skip(cio, 2);
|
||||||
@@ -448,6 +397,9 @@ static void j2k_write_siz(opj_j2k_t *j2k) {
|
|||||||
cio_seek(cio, lenp);
|
cio_seek(cio, lenp);
|
||||||
cio_write(cio, len, 2); /* Lsiz */
|
cio_write(cio, len, 2); /* Lsiz */
|
||||||
cio_seek(cio, lenp + len);
|
cio_seek(cio, lenp + len);
|
||||||
|
|
||||||
|
if(j2k->cstr_info)
|
||||||
|
j2k_add_mhmarker(j2k->cstr_info, J2K_MS_SIZ, lenp, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void j2k_read_siz(opj_j2k_t *j2k) {
|
static void j2k_read_siz(opj_j2k_t *j2k) {
|
||||||
@@ -516,6 +468,12 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
|
|||||||
}
|
}
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
|
/* prevent division by zero */
|
||||||
|
if (!(cp->tdx * cp->tdy)) {
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: invalid tile size (tdx: %d, tdy: %d)\n", cp->tdx, cp->tdy);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
|
image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
|
||||||
for (i = 0; i < image->numcomps; i++) {
|
for (i = 0; i < image->numcomps; i++) {
|
||||||
int tmp, w, h;
|
int tmp, w, h;
|
||||||
@@ -554,6 +512,12 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
|
|||||||
}
|
}
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
|
/* prevent division by zero */
|
||||||
|
if (!(image->comps[i].dx * image->comps[i].dy)) {
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: invalid component size (dx: %d, dy: %d)\n", image->comps[i].dx, image->comps[i].dy);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: unused ? */
|
/* TODO: unused ? */
|
||||||
w = int_ceildiv(image->x1 - image->x0, image->comps[i].dx);
|
w = int_ceildiv(image->x1 - image->x0, image->comps[i].dx);
|
||||||
h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy);
|
h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy);
|
||||||
@@ -606,7 +570,17 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
|
|||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
|
cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
|
||||||
|
if (cp->tcps == NULL)
|
||||||
|
{
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int));
|
cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int));
|
||||||
|
if (cp->tileno == NULL)
|
||||||
|
{
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
cp->tileno_size = 0;
|
cp->tileno_size = 0;
|
||||||
|
|
||||||
#ifdef USE_JPWL
|
#ifdef USE_JPWL
|
||||||
@@ -678,6 +652,11 @@ static void j2k_write_com(opj_j2k_t *j2k) {
|
|||||||
cio_seek(cio, lenp);
|
cio_seek(cio, lenp);
|
||||||
cio_write(cio, len, 2);
|
cio_write(cio, len, 2);
|
||||||
cio_seek(cio, lenp + len);
|
cio_seek(cio, lenp + len);
|
||||||
|
|
||||||
|
|
||||||
|
if(j2k->cstr_info)
|
||||||
|
j2k_add_mhmarker(j2k->cstr_info, J2K_MS_COM, lenp, len);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,12 +700,18 @@ static void j2k_read_cox(opj_j2k_t *j2k, int compno) {
|
|||||||
|
|
||||||
tccp->numresolutions = cio_read(cio, 1) + 1; /* SPcox (D) */
|
tccp->numresolutions = cio_read(cio, 1) + 1; /* SPcox (D) */
|
||||||
|
|
||||||
// If user wants to remove more resolutions than the codestream contains, return error
|
/* If user wants to remove more resolutions than the codestream contains, return error*/
|
||||||
if (cp->reduce >= tccp->numresolutions) {
|
if (cp->reduce >= tccp->numresolutions) {
|
||||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions to remove is higher than the number "
|
opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions to remove is higher than the number "
|
||||||
"of resolutions of this component\nModify the cp_reduce parameter.\n\n", compno);
|
"of resolutions of this component\nModify the cp_reduce parameter.\n\n", compno);
|
||||||
j2k->state |= J2K_STATE_ERR;
|
j2k->state |= J2K_STATE_ERR;
|
||||||
}
|
}
|
||||||
|
if( tccp->numresolutions > J2K_MAXRLVLS ) {
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions is too big: %d vs max= %d. Truncating.\n\n",
|
||||||
|
compno, tccp->numresolutions, J2K_MAXRLVLS);
|
||||||
|
j2k->state |= J2K_STATE_ERR;
|
||||||
|
tccp->numresolutions = J2K_MAXRLVLS;
|
||||||
|
}
|
||||||
|
|
||||||
tccp->cblkw = cio_read(cio, 1) + 2; /* SPcox (E) */
|
tccp->cblkw = cio_read(cio, 1) + 2; /* SPcox (E) */
|
||||||
tccp->cblkh = cio_read(cio, 1) + 2; /* SPcox (F) */
|
tccp->cblkh = cio_read(cio, 1) + 2; /* SPcox (F) */
|
||||||
@@ -781,6 +766,10 @@ static void j2k_write_cod(opj_j2k_t *j2k) {
|
|||||||
cio_seek(cio, lenp);
|
cio_seek(cio, lenp);
|
||||||
cio_write(cio, len, 2); /* Lcod */
|
cio_write(cio, len, 2); /* Lcod */
|
||||||
cio_seek(cio, lenp + len);
|
cio_seek(cio, lenp + len);
|
||||||
|
|
||||||
|
if(j2k->cstr_info)
|
||||||
|
j2k_add_mhmarker(j2k->cstr_info, J2K_MS_COD, lenp, len);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void j2k_read_cod(opj_j2k_t *j2k) {
|
static void j2k_read_cod(opj_j2k_t *j2k) {
|
||||||
@@ -846,6 +835,12 @@ static void j2k_read_coc(opj_j2k_t *j2k) {
|
|||||||
|
|
||||||
len = cio_read(cio, 2); /* Lcoc */
|
len = cio_read(cio, 2); /* Lcoc */
|
||||||
compno = cio_read(cio, image->numcomps <= 256 ? 1 : 2); /* Ccoc */
|
compno = cio_read(cio, image->numcomps <= 256 ? 1 : 2); /* Ccoc */
|
||||||
|
if (compno >= image->numcomps) {
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_ERROR,
|
||||||
|
"bad component number in COC (%d out of a maximum of %d)\n",
|
||||||
|
compno, image->numcomps);
|
||||||
|
return;
|
||||||
|
}
|
||||||
tcp->tccps[compno].csty = cio_read(cio, 1); /* Scoc */
|
tcp->tccps[compno].csty = cio_read(cio, 1); /* Scoc */
|
||||||
j2k_read_cox(j2k, compno);
|
j2k_read_cox(j2k, compno);
|
||||||
}
|
}
|
||||||
@@ -909,6 +904,15 @@ static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* We check whether there are too many subbands */
|
||||||
|
if ((numbands < 0) || (numbands >= J2K_MAXBANDS)) {
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_WARNING ,
|
||||||
|
"bad number of subbands in Sqcx (%d) regarding to J2K_MAXBANDS (%d) \n"
|
||||||
|
"- limiting number of bands to J2K_MAXBANDS and try to move to the next markers\n", numbands, J2K_MAXBANDS);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
for (bandno = 0; bandno < numbands; bandno++) {
|
for (bandno = 0; bandno < numbands; bandno++) {
|
||||||
@@ -921,8 +925,10 @@ static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len) {
|
|||||||
expn = tmp >> 11;
|
expn = tmp >> 11;
|
||||||
mant = tmp & 0x7ff;
|
mant = tmp & 0x7ff;
|
||||||
}
|
}
|
||||||
tccp->stepsizes[bandno].expn = expn;
|
if (bandno < J2K_MAXBANDS){
|
||||||
tccp->stepsizes[bandno].mant = mant;
|
tccp->stepsizes[bandno].expn = expn;
|
||||||
|
tccp->stepsizes[bandno].mant = mant;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add Antonin : if scalar_derived -> compute other stepsizes */
|
/* Add Antonin : if scalar_derived -> compute other stepsizes */
|
||||||
@@ -950,6 +956,9 @@ static void j2k_write_qcd(opj_j2k_t *j2k) {
|
|||||||
cio_seek(cio, lenp);
|
cio_seek(cio, lenp);
|
||||||
cio_write(cio, len, 2); /* Lqcd */
|
cio_write(cio, len, 2); /* Lqcd */
|
||||||
cio_seek(cio, lenp + len);
|
cio_seek(cio, lenp + len);
|
||||||
|
|
||||||
|
if(j2k->cstr_info)
|
||||||
|
j2k_add_mhmarker(j2k->cstr_info, J2K_MS_QCD, lenp, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void j2k_read_qcd(opj_j2k_t *j2k) {
|
static void j2k_read_qcd(opj_j2k_t *j2k) {
|
||||||
@@ -986,7 +995,7 @@ static void j2k_read_qcc(opj_j2k_t *j2k) {
|
|||||||
int len, compno;
|
int len, compno;
|
||||||
int numcomp = j2k->image->numcomps;
|
int numcomp = j2k->image->numcomps;
|
||||||
opj_cio_t *cio = j2k->cio;
|
opj_cio_t *cio = j2k->cio;
|
||||||
|
|
||||||
len = cio_read(cio, 2); /* Lqcc */
|
len = cio_read(cio, 2); /* Lqcc */
|
||||||
compno = cio_read(cio, numcomp <= 256 ? 1 : 2); /* Cqcc */
|
compno = cio_read(cio, numcomp <= 256 ? 1 : 2); /* Cqcc */
|
||||||
|
|
||||||
@@ -1013,9 +1022,16 @@ static void j2k_read_qcc(opj_j2k_t *j2k) {
|
|||||||
|
|
||||||
/* keep your private count of tiles */
|
/* keep your private count of tiles */
|
||||||
backup_compno++;
|
backup_compno++;
|
||||||
};
|
}
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
|
if ((compno < 0) || (compno >= numcomp)) {
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_ERROR,
|
||||||
|
"bad component number in QCC (%d out of a maximum of %d)\n",
|
||||||
|
compno, j2k->image->numcomps);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
j2k_read_qcx(j2k, compno, len - 2 - (numcomp <= 256 ? 1 : 2));
|
j2k_read_qcx(j2k, compno, len - 2 - (numcomp <= 256 ? 1 : 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1271,6 +1287,10 @@ static void j2k_write_sot(opj_j2k_t *j2k) {
|
|||||||
j2k_add_marker(j2k->cstr_info, J2K_MS_SOT, j2k->sot_start, len + 2);
|
j2k_add_marker(j2k->cstr_info, J2K_MS_SOT, j2k->sot_start, len + 2);
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
/* <<UniPG */
|
/* <<UniPG */
|
||||||
|
|
||||||
|
if( j2k->cstr_info && j2k->cur_tp_num==0){
|
||||||
|
j2k_add_tlmarker( j2k->curtileno, j2k->cstr_info, J2K_MS_SOT, lenp, len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void j2k_read_sot(opj_j2k_t *j2k) {
|
static void j2k_read_sot(opj_j2k_t *j2k) {
|
||||||
@@ -1354,6 +1374,11 @@ static void j2k_read_sot(opj_j2k_t *j2k) {
|
|||||||
|
|
||||||
partno = cio_read(cio, 1);
|
partno = cio_read(cio, 1);
|
||||||
numparts = cio_read(cio, 1);
|
numparts = cio_read(cio, 1);
|
||||||
|
|
||||||
|
if (partno >= numparts) {
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_WARNING, "SOT marker inconsistency in tile %d: tile-part index greater (%d) than number of tile-parts (%d)\n", tileno, partno, numparts);
|
||||||
|
numparts = partno+1;
|
||||||
|
}
|
||||||
|
|
||||||
j2k->curtileno = tileno;
|
j2k->curtileno = tileno;
|
||||||
j2k->cur_tp_num = partno;
|
j2k->cur_tp_num = partno;
|
||||||
@@ -1369,15 +1394,14 @@ static void j2k_read_sot(opj_j2k_t *j2k) {
|
|||||||
j2k->cstr_info->tile[tileno].tileno = tileno;
|
j2k->cstr_info->tile[tileno].tileno = tileno;
|
||||||
j2k->cstr_info->tile[tileno].start_pos = cio_tell(cio) - 12;
|
j2k->cstr_info->tile[tileno].start_pos = cio_tell(cio) - 12;
|
||||||
j2k->cstr_info->tile[tileno].end_pos = j2k->cstr_info->tile[tileno].start_pos + totlen - 1;
|
j2k->cstr_info->tile[tileno].end_pos = j2k->cstr_info->tile[tileno].start_pos + totlen - 1;
|
||||||
j2k->cstr_info->tile[tileno].num_tps = numparts;
|
} else {
|
||||||
if (numparts)
|
|
||||||
j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(numparts * sizeof(opj_tp_info_t));
|
|
||||||
else
|
|
||||||
j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_malloc(10 * sizeof(opj_tp_info_t)); // Fixme (10)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
j2k->cstr_info->tile[tileno].end_pos += totlen;
|
j2k->cstr_info->tile[tileno].end_pos += totlen;
|
||||||
}
|
}
|
||||||
|
j2k->cstr_info->tile[tileno].num_tps = numparts;
|
||||||
|
if (numparts)
|
||||||
|
j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, numparts * sizeof(opj_tp_info_t));
|
||||||
|
else
|
||||||
|
j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, 10 * sizeof(opj_tp_info_t)); /* Fixme (10)*/
|
||||||
j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = cio_tell(cio) - 12;
|
j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = cio_tell(cio) - 12;
|
||||||
j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos =
|
j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos =
|
||||||
j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1;
|
j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1;
|
||||||
@@ -1413,6 +1437,11 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
|
|||||||
tcd->cur_tp_num = j2k->cur_tp_num;
|
tcd->cur_tp_num = j2k->cur_tp_num;
|
||||||
|
|
||||||
cio_write(cio, J2K_MS_SOD, 2);
|
cio_write(cio, J2K_MS_SOD, 2);
|
||||||
|
|
||||||
|
if( j2k->cstr_info && j2k->cur_tp_num==0){
|
||||||
|
j2k_add_tlmarker( j2k->curtileno, j2k->cstr_info, J2K_MS_SOD, cio_tell(cio), 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (j2k->curtileno == 0) {
|
if (j2k->curtileno == 0) {
|
||||||
j2k->sod_start = cio_tell(cio) + j2k->pos_correction;
|
j2k->sod_start = cio_tell(cio) + j2k->pos_correction;
|
||||||
}
|
}
|
||||||
@@ -1489,6 +1518,24 @@ static void j2k_read_sod(opj_j2k_t *j2k) {
|
|||||||
truncate = 1; /* Case of a truncate codestream */
|
truncate = 1; /* Case of a truncate codestream */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{/* chop padding bytes: */
|
||||||
|
unsigned char *s, *e;
|
||||||
|
|
||||||
|
s = cio_getbp(cio);
|
||||||
|
e = s + len;
|
||||||
|
|
||||||
|
if(len > 8) s = e - 8;
|
||||||
|
|
||||||
|
if(e[-2] == 0x00 && e[-1] == 0x00) /* padding bytes */
|
||||||
|
{
|
||||||
|
while(e > s)
|
||||||
|
{
|
||||||
|
if(e[-2] == 0xff && e[-1] == 0xd9) break;
|
||||||
|
--len; --e; truncate = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data = j2k->tile_data[curtileno];
|
data = j2k->tile_data[curtileno];
|
||||||
data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char));
|
data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char));
|
||||||
|
|
||||||
@@ -1548,6 +1595,13 @@ static void j2k_read_rgn(opj_j2k_t *j2k) {
|
|||||||
};
|
};
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
|
if (compno >= numcomps) {
|
||||||
|
opj_event_msg(j2k->cinfo, EVT_ERROR,
|
||||||
|
"bad component number in RGN (%d out of a maximum of %d)\n",
|
||||||
|
compno, j2k->image->numcomps);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */
|
tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1566,7 +1620,7 @@ static void j2k_write_eoc(opj_j2k_t *j2k) {
|
|||||||
|
|
||||||
static void j2k_read_eoc(opj_j2k_t *j2k) {
|
static void j2k_read_eoc(opj_j2k_t *j2k) {
|
||||||
int i, tileno;
|
int i, tileno;
|
||||||
bool success;
|
opj_bool success = OPJ_FALSE;
|
||||||
|
|
||||||
/* if packets should be decoded */
|
/* if packets should be decoded */
|
||||||
if (j2k->cp->limit_decoding != DECODE_ALL_BUT_PACKETS) {
|
if (j2k->cp->limit_decoding != DECODE_ALL_BUT_PACKETS) {
|
||||||
@@ -1574,12 +1628,17 @@ static void j2k_read_eoc(opj_j2k_t *j2k) {
|
|||||||
tcd_malloc_decode(tcd, j2k->image, j2k->cp);
|
tcd_malloc_decode(tcd, j2k->image, j2k->cp);
|
||||||
for (i = 0; i < j2k->cp->tileno_size; i++) {
|
for (i = 0; i < j2k->cp->tileno_size; i++) {
|
||||||
tcd_malloc_decode_tile(tcd, j2k->image, j2k->cp, i, j2k->cstr_info);
|
tcd_malloc_decode_tile(tcd, j2k->image, j2k->cp, i, j2k->cstr_info);
|
||||||
tileno = j2k->cp->tileno[i];
|
if (j2k->cp->tileno[i] != -1)
|
||||||
success = tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info);
|
{
|
||||||
opj_free(j2k->tile_data[tileno]);
|
tileno = j2k->cp->tileno[i];
|
||||||
j2k->tile_data[tileno] = NULL;
|
success = tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info);
|
||||||
tcd_free_decode_tile(tcd, i);
|
opj_free(j2k->tile_data[tileno]);
|
||||||
if (success == false) {
|
j2k->tile_data[tileno] = NULL;
|
||||||
|
tcd_free_decode_tile(tcd, i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = OPJ_FALSE;
|
||||||
|
if (success == OPJ_FALSE) {
|
||||||
j2k->state |= J2K_STATE_ERR;
|
j2k->state |= J2K_STATE_ERR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1749,6 +1808,14 @@ void j2k_destroy_decompress(opj_j2k_t *j2k) {
|
|||||||
opj_free(j2k->tile_len);
|
opj_free(j2k->tile_len);
|
||||||
}
|
}
|
||||||
if(j2k->tile_data != NULL) {
|
if(j2k->tile_data != NULL) {
|
||||||
|
if(j2k->cp != NULL) {
|
||||||
|
for (i = 0; i < j2k->cp->tileno_size; i++) {
|
||||||
|
int tileno = j2k->cp->tileno[i];
|
||||||
|
opj_free(j2k->tile_data[tileno]);
|
||||||
|
j2k->tile_data[tileno] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
opj_free(j2k->tile_data);
|
opj_free(j2k->tile_data);
|
||||||
}
|
}
|
||||||
if(j2k->default_tcp != NULL) {
|
if(j2k->default_tcp != NULL) {
|
||||||
@@ -1834,7 +1901,7 @@ opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *c
|
|||||||
if (j2k->cp->correct) {
|
if (j2k->cp->correct) {
|
||||||
|
|
||||||
int orig_pos = cio_tell(cio);
|
int orig_pos = cio_tell(cio);
|
||||||
bool status;
|
opj_bool status;
|
||||||
|
|
||||||
/* call the corrector */
|
/* call the corrector */
|
||||||
status = jpwl_correct(j2k);
|
status = jpwl_correct(j2k);
|
||||||
@@ -1868,18 +1935,24 @@ opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *c
|
|||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
if (id >> 8 != 0xff) {
|
if (id >> 8 != 0xff) {
|
||||||
opj_image_destroy(image);
|
if(cio_numbytesleft(cio) != 0) /* not end of file reached and no EOC */
|
||||||
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
|
{
|
||||||
return 0;
|
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
|
||||||
|
opj_image_destroy(image);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
opj_event_msg(cinfo, EVT_WARNING, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
|
||||||
|
j2k->state = J2K_STATE_NEOC;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
e = j2k_dec_mstab_lookup(id);
|
e = j2k_dec_mstab_lookup(id);
|
||||||
// Check if the marker is known
|
/* Check if the marker is known*/
|
||||||
if (!(j2k->state & e->states)) {
|
if (!(j2k->state & e->states)) {
|
||||||
opj_image_destroy(image);
|
opj_image_destroy(image);
|
||||||
opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id);
|
opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Check if the decoding is limited to the main header
|
/* Check if the decoding is limited to the main header*/
|
||||||
if (e->id == J2K_MS_SOT && j2k->cp->limit_decoding == LIMIT_TO_MAIN_HEADER) {
|
if (e->id == J2K_MS_SOT && j2k->cp->limit_decoding == LIMIT_TO_MAIN_HEADER) {
|
||||||
opj_event_msg(cinfo, EVT_INFO, "Main Header decoded.\n");
|
opj_event_msg(cinfo, EVT_INFO, "Main Header decoded.\n");
|
||||||
return image;
|
return image;
|
||||||
@@ -1889,7 +1962,10 @@ opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *c
|
|||||||
(*e->handler)(j2k);
|
(*e->handler)(j2k);
|
||||||
}
|
}
|
||||||
if (j2k->state & J2K_STATE_ERR)
|
if (j2k->state & J2K_STATE_ERR)
|
||||||
|
{
|
||||||
|
opj_image_destroy(image);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (j2k->state == J2K_STATE_MT) {
|
if (j2k->state == J2K_STATE_MT) {
|
||||||
break;
|
break;
|
||||||
@@ -1905,7 +1981,6 @@ opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *c
|
|||||||
if (j2k->state != J2K_STATE_MT) {
|
if (j2k->state != J2K_STATE_MT) {
|
||||||
opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n");
|
opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1917,9 +1992,10 @@ opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestre
|
|||||||
opj_image_t *image = NULL;
|
opj_image_t *image = NULL;
|
||||||
opj_jpt_msg_header_t header;
|
opj_jpt_msg_header_t header;
|
||||||
int position;
|
int position;
|
||||||
|
|
||||||
opj_common_ptr cinfo = j2k->cinfo;
|
opj_common_ptr cinfo = j2k->cinfo;
|
||||||
|
|
||||||
|
OPJ_ARG_NOT_USED(cstr_info);
|
||||||
|
|
||||||
j2k->cio = cio;
|
j2k->cio = cio;
|
||||||
|
|
||||||
/* create an empty image */
|
/* create an empty image */
|
||||||
@@ -1961,9 +2037,15 @@ opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestre
|
|||||||
|
|
||||||
id = cio_read(cio, 2);
|
id = cio_read(cio, 2);
|
||||||
if (id >> 8 != 0xff) {
|
if (id >> 8 != 0xff) {
|
||||||
opj_image_destroy(image);
|
if(cio_numbytesleft(cio) != 0) /* no end of file reached and no EOC */
|
||||||
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
|
{
|
||||||
return 0;
|
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
|
||||||
|
opj_image_destroy(image);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
opj_event_msg(cinfo, EVT_WARNING, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
|
||||||
|
j2k->state = J2K_STATE_NEOC;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
e = j2k_dec_mstab_lookup(id);
|
e = j2k_dec_mstab_lookup(id);
|
||||||
if (!(j2k->state & e->states)) {
|
if (!(j2k->state & e->states)) {
|
||||||
@@ -2110,12 +2192,12 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* set JPWL on */
|
/* set JPWL on */
|
||||||
cp->epc_on = true;
|
cp->epc_on = OPJ_TRUE;
|
||||||
cp->info_on = false; /* no informative technique */
|
cp->info_on = OPJ_FALSE; /* no informative technique */
|
||||||
|
|
||||||
/* set EPB on */
|
/* set EPB on */
|
||||||
if ((parameters->jpwl_hprot_MH > 0) || (parameters->jpwl_hprot_TPH[0] > 0)) {
|
if ((parameters->jpwl_hprot_MH > 0) || (parameters->jpwl_hprot_TPH[0] > 0)) {
|
||||||
cp->epb_on = true;
|
cp->epb_on = OPJ_TRUE;
|
||||||
|
|
||||||
cp->hprot_MH = parameters->jpwl_hprot_MH;
|
cp->hprot_MH = parameters->jpwl_hprot_MH;
|
||||||
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
|
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
|
||||||
@@ -2136,7 +2218,7 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
|
|||||||
|
|
||||||
/* set ESD writing */
|
/* set ESD writing */
|
||||||
if ((parameters->jpwl_sens_size == 1) || (parameters->jpwl_sens_size == 2)) {
|
if ((parameters->jpwl_sens_size == 1) || (parameters->jpwl_sens_size == 2)) {
|
||||||
cp->esd_on = true;
|
cp->esd_on = OPJ_TRUE;
|
||||||
|
|
||||||
cp->sens_size = parameters->jpwl_sens_size;
|
cp->sens_size = parameters->jpwl_sens_size;
|
||||||
cp->sens_addr = parameters->jpwl_sens_addr;
|
cp->sens_addr = parameters->jpwl_sens_addr;
|
||||||
@@ -2150,10 +2232,10 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* always set RED writing to false: we are at the encoder */
|
/* always set RED writing to false: we are at the encoder */
|
||||||
cp->red_on = false;
|
cp->red_on = OPJ_FALSE;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
cp->epc_on = false;
|
cp->epc_on = OPJ_FALSE;
|
||||||
}
|
}
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
@@ -2226,10 +2308,10 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
|
|||||||
|
|
||||||
if(parameters->cp_cinema)
|
if(parameters->cp_cinema)
|
||||||
{
|
{
|
||||||
//Precinct size for lowest frequency subband=128
|
/*Precinct size for lowest frequency subband=128*/
|
||||||
tccp->prcw[0] = 7;
|
tccp->prcw[0] = 7;
|
||||||
tccp->prch[0] = 7;
|
tccp->prch[0] = 7;
|
||||||
//Precinct size at all other resolutions = 256
|
/*Precinct size at all other resolutions = 256*/
|
||||||
for (j = 1; j < tccp->numresolutions; j++) {
|
for (j = 1; j < tccp->numresolutions; j++) {
|
||||||
tccp->prcw[j] = 8;
|
tccp->prcw[j] = 8;
|
||||||
tccp->prch[j] = 8;
|
tccp->prch[j] = 8;
|
||||||
@@ -2271,7 +2353,7 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
|
|||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
/*printf("\nsize precinct for level %d : %d,%d\n", j,tccp->prcw[j], tccp->prch[j]); */
|
/*printf("\nsize precinct for level %d : %d,%d\n", j,tccp->prcw[j], tccp->prch[j]); */
|
||||||
} //end for
|
} /*end for*/
|
||||||
} else {
|
} else {
|
||||||
for (j = 0; j < tccp->numresolutions; j++) {
|
for (j = 0; j < tccp->numresolutions; j++) {
|
||||||
tccp->prcw[j] = 15;
|
tccp->prcw[j] = 15;
|
||||||
@@ -2285,7 +2367,7 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
|
opj_bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
|
||||||
int tileno, compno;
|
int tileno, compno;
|
||||||
opj_cp_t *cp = NULL;
|
opj_cp_t *cp = NULL;
|
||||||
|
|
||||||
@@ -2296,8 +2378,6 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
|
|||||||
|
|
||||||
cp = j2k->cp;
|
cp = j2k->cp;
|
||||||
|
|
||||||
/* j2k_dump_cp(stdout, image, cp); */
|
|
||||||
|
|
||||||
/* INDEX >> */
|
/* INDEX >> */
|
||||||
j2k->cstr_info = cstr_info;
|
j2k->cstr_info = cstr_info;
|
||||||
if (cstr_info) {
|
if (cstr_info) {
|
||||||
@@ -2394,6 +2474,9 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
|
|||||||
/* INDEX >> */
|
/* INDEX >> */
|
||||||
if(cstr_info) {
|
if(cstr_info) {
|
||||||
cstr_info->tile[j2k->curtileno].start_pos = cio_tell(cio) + j2k->pos_correction;
|
cstr_info->tile[j2k->curtileno].start_pos = cio_tell(cio) + j2k->pos_correction;
|
||||||
|
cstr_info->tile[j2k->curtileno].maxmarknum = 10;
|
||||||
|
cstr_info->tile[j2k->curtileno].marker = (opj_marker_info_t *) opj_malloc(cstr_info->tile[j2k->curtileno].maxmarknum * sizeof(opj_marker_info_t));
|
||||||
|
cstr_info->tile[j2k->curtileno].marknum = 0;
|
||||||
}
|
}
|
||||||
/* << INDEX */
|
/* << INDEX */
|
||||||
|
|
||||||
@@ -2500,11 +2583,46 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
|
|||||||
}
|
}
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void j2k_add_mhmarker(opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) {
|
||||||
|
|
||||||
|
if (!cstr_info)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* expand the list? */
|
||||||
|
if ((cstr_info->marknum + 1) > cstr_info->maxmarknum) {
|
||||||
|
cstr_info->maxmarknum = 100 + (int) ((float) cstr_info->maxmarknum * 1.0F);
|
||||||
|
cstr_info->marker = (opj_marker_info_t*)opj_realloc(cstr_info->marker, cstr_info->maxmarknum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add the marker */
|
||||||
|
cstr_info->marker[cstr_info->marknum].type = type;
|
||||||
|
cstr_info->marker[cstr_info->marknum].pos = pos;
|
||||||
|
cstr_info->marker[cstr_info->marknum].len = len;
|
||||||
|
cstr_info->marknum++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void j2k_add_tlmarker( int tileno, opj_codestream_info_t *cstr_info, unsigned short int type, int pos, int len) {
|
||||||
|
|
||||||
|
opj_marker_info_t *marker;
|
||||||
|
|
||||||
|
if (!cstr_info)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* expand the list? */
|
||||||
|
if ((cstr_info->tile[tileno].marknum + 1) > cstr_info->tile[tileno].maxmarknum) {
|
||||||
|
cstr_info->tile[tileno].maxmarknum = 100 + (int) ((float) cstr_info->tile[tileno].maxmarknum * 1.0F);
|
||||||
|
cstr_info->tile[tileno].marker = (opj_marker_info_t*)opj_realloc(cstr_info->tile[tileno].marker, cstr_info->maxmarknum);
|
||||||
|
}
|
||||||
|
|
||||||
|
marker = &(cstr_info->tile[tileno].marker[cstr_info->tile[tileno].marknum]);
|
||||||
|
|
||||||
|
/* add the marker */
|
||||||
|
marker->type = type;
|
||||||
|
marker->pos = pos;
|
||||||
|
marker->len = len;
|
||||||
|
cstr_info->tile[tileno].marknum++;
|
||||||
|
}
|
||||||
|
|||||||
@@ -265,15 +265,15 @@ typedef struct opj_cp {
|
|||||||
/* UniPG>> */
|
/* UniPG>> */
|
||||||
#ifdef USE_JPWL
|
#ifdef USE_JPWL
|
||||||
/** enables writing of EPC in MH, thus activating JPWL */
|
/** enables writing of EPC in MH, thus activating JPWL */
|
||||||
bool epc_on;
|
opj_bool epc_on;
|
||||||
/** enables writing of EPB, in case of activated JPWL */
|
/** enables writing of EPB, in case of activated JPWL */
|
||||||
bool epb_on;
|
opj_bool epb_on;
|
||||||
/** enables writing of ESD, in case of activated JPWL */
|
/** enables writing of ESD, in case of activated JPWL */
|
||||||
bool esd_on;
|
opj_bool esd_on;
|
||||||
/** enables writing of informative techniques of ESD, in case of activated JPWL */
|
/** enables writing of informative techniques of ESD, in case of activated JPWL */
|
||||||
bool info_on;
|
opj_bool info_on;
|
||||||
/** enables writing of RED, in case of activated JPWL */
|
/** enables writing of RED, in case of activated JPWL */
|
||||||
bool red_on;
|
opj_bool red_on;
|
||||||
/** error protection method for MH (0,1,16,32,37-128) */
|
/** error protection method for MH (0,1,16,32,37-128) */
|
||||||
int hprot_MH;
|
int hprot_MH;
|
||||||
/** tile number of header protection specification (>=0) */
|
/** tile number of header protection specification (>=0) */
|
||||||
@@ -299,7 +299,7 @@ typedef struct opj_cp {
|
|||||||
/** sensitivity methods for TPHs (-1,0-7) */
|
/** sensitivity methods for TPHs (-1,0-7) */
|
||||||
int sens_TPH[JPWL_MAX_NO_TILESPECS];
|
int sens_TPH[JPWL_MAX_NO_TILESPECS];
|
||||||
/** enables JPWL correction at the decoder */
|
/** enables JPWL correction at the decoder */
|
||||||
bool correct;
|
opj_bool correct;
|
||||||
/** expected number of components at the decoder */
|
/** expected number of components at the decoder */
|
||||||
int exp_comps;
|
int exp_comps;
|
||||||
/** maximum number of tiles at the decoder */
|
/** maximum number of tiles at the decoder */
|
||||||
@@ -436,10 +436,8 @@ Encode an image into a JPEG-2000 codestream
|
|||||||
@param cstr_info Codestream information structure if required, NULL otherwise
|
@param cstr_info Codestream information structure if required, NULL otherwise
|
||||||
@return Returns true if successful, returns false otherwise
|
@return Returns true if successful, returns false otherwise
|
||||||
*/
|
*/
|
||||||
bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
opj_bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
||||||
|
|
||||||
void j2k_dump_image(FILE *fd, opj_image_t * img);
|
|
||||||
void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp);
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Herv<EFBFBD> Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -24,18 +24,18 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/times.h>
|
#include <sys/times.h>
|
||||||
#endif /* WIN32 */
|
#endif /* _WIN32 */
|
||||||
#include "opj_includes.h"
|
#include "opj_includes.h"
|
||||||
|
|
||||||
double opj_clock(void) {
|
double opj_clock(void) {
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
/* WIN32: use QueryPerformance (very accurate) */
|
/* _WIN32: use QueryPerformance (very accurate) */
|
||||||
LARGE_INTEGER freq , t ;
|
LARGE_INTEGER freq , t ;
|
||||||
/* freq is the clock speed of the CPU */
|
/* freq is the clock speed of the CPU */
|
||||||
QueryPerformanceFrequency(&freq) ;
|
QueryPerformanceFrequency(&freq) ;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Herv<EFBFBD> Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -46,11 +46,64 @@
|
|||||||
#define JP2_COLR 0x636f6c72 /**< Colour specification box */
|
#define JP2_COLR 0x636f6c72 /**< Colour specification box */
|
||||||
#define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */
|
#define JP2_JP2C 0x6a703263 /**< Contiguous codestream box */
|
||||||
#define JP2_URL 0x75726c20 /**< URL box */
|
#define JP2_URL 0x75726c20 /**< URL box */
|
||||||
#define JP2_DBTL 0x6474626c /**< ??? */
|
#define JP2_DTBL 0x6474626c /**< Data Reference box */
|
||||||
#define JP2_BPCC 0x62706363 /**< Bits per component box */
|
#define JP2_BPCC 0x62706363 /**< Bits per component box */
|
||||||
#define JP2_JP2 0x6a703220 /**< File type fields */
|
#define JP2_JP2 0x6a703220 /**< File type fields */
|
||||||
|
#define JP2_PCLR 0x70636c72 /**< Palette box */
|
||||||
|
#define JP2_CMAP 0x636d6170 /**< Component Mapping box */
|
||||||
|
#define JP2_CDEF 0x63646566 /**< Channel Definition box */
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
Channel description: channel index, type, assocation
|
||||||
|
*/
|
||||||
|
typedef struct opj_jp2_cdef_info
|
||||||
|
{
|
||||||
|
unsigned short cn, typ, asoc;
|
||||||
|
} opj_jp2_cdef_info_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Channel descriptions and number of descriptions
|
||||||
|
*/
|
||||||
|
typedef struct opj_jp2_cdef
|
||||||
|
{
|
||||||
|
opj_jp2_cdef_info_t *info;
|
||||||
|
unsigned short n;
|
||||||
|
} opj_jp2_cdef_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Component mappings: channel index, mapping type, palette index
|
||||||
|
*/
|
||||||
|
typedef struct opj_jp2_cmap_comp
|
||||||
|
{
|
||||||
|
unsigned short cmp;
|
||||||
|
unsigned char mtyp, pcol;
|
||||||
|
} opj_jp2_cmap_comp_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Palette data: table entries, palette columns
|
||||||
|
*/
|
||||||
|
typedef struct opj_jp2_pclr
|
||||||
|
{
|
||||||
|
unsigned int *entries;
|
||||||
|
unsigned char *channel_sign;
|
||||||
|
unsigned char *channel_size;
|
||||||
|
opj_jp2_cmap_comp_t *cmap;
|
||||||
|
unsigned short nr_entries, nr_channels;
|
||||||
|
} opj_jp2_pclr_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Collector for ICC profile, palette, component mapping, channel description
|
||||||
|
*/
|
||||||
|
typedef struct opj_jp2_color
|
||||||
|
{
|
||||||
|
unsigned char *icc_profile_buf;
|
||||||
|
int icc_profile_len;
|
||||||
|
|
||||||
|
opj_jp2_cdef_t *jp2_cdef;
|
||||||
|
opj_jp2_pclr_t *jp2_pclr;
|
||||||
|
unsigned char jp2_has_colr;
|
||||||
|
} opj_jp2_color_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
JP2 component
|
JP2 component
|
||||||
@@ -87,6 +140,8 @@ typedef struct opj_jp2 {
|
|||||||
opj_jp2_comps_t *comps;
|
opj_jp2_comps_t *comps;
|
||||||
unsigned int j2k_codestream_offset;
|
unsigned int j2k_codestream_offset;
|
||||||
unsigned int j2k_codestream_length;
|
unsigned int j2k_codestream_length;
|
||||||
|
opj_bool jpip_on;
|
||||||
|
opj_bool ignore_pclr_cmap_cdef;
|
||||||
} opj_jp2_t;
|
} opj_jp2_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,9 +166,10 @@ void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio);
|
|||||||
Read the JP2H box - JP2 Header box (used in MJ2)
|
Read the JP2H box - JP2 Header box (used in MJ2)
|
||||||
@param jp2 JP2 handle
|
@param jp2 JP2 handle
|
||||||
@param cio Input buffer stream
|
@param cio Input buffer stream
|
||||||
|
@param ext Collector for profile, cdef and pclr data
|
||||||
@return Returns true if successful, returns false otherwise
|
@return Returns true if successful, returns false otherwise
|
||||||
*/
|
*/
|
||||||
bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio);
|
opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color);
|
||||||
/**
|
/**
|
||||||
Creates a JP2 decompression structure
|
Creates a JP2 decompression structure
|
||||||
@param cinfo Codec context info
|
@param cinfo Codec context info
|
||||||
@@ -139,7 +195,7 @@ Decode an image from a JPEG-2000 file stream
|
|||||||
@param cstr_info Codestream information structure if required, NULL otherwise
|
@param cstr_info Codestream information structure if required, NULL otherwise
|
||||||
@return Returns a decoded image if successful, returns NULL otherwise
|
@return Returns a decoded image if successful, returns NULL otherwise
|
||||||
*/
|
*/
|
||||||
opj_image_t* jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
|
opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
|
||||||
/**
|
/**
|
||||||
Creates a JP2 compression structure
|
Creates a JP2 compression structure
|
||||||
@param cinfo Codec context info
|
@param cinfo Codec context info
|
||||||
@@ -167,7 +223,8 @@ Encode an image into a JPEG-2000 file stream
|
|||||||
@param cstr_info Codestream information structure if required, NULL otherwise
|
@param cstr_info Codestream information structure if required, NULL otherwise
|
||||||
@return Returns true if successful, returns false otherwise
|
@return Returns true if successful, returns false otherwise
|
||||||
*/
|
*/
|
||||||
bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
opj_bool opj_jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
|||||||
@@ -521,22 +521,21 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
|
|||||||
unsigned int c;
|
unsigned int c;
|
||||||
unsigned int *ip;
|
unsigned int *ip;
|
||||||
unsigned char *end = mqc->end - 1;
|
unsigned char *end = mqc->end - 1;
|
||||||
mqc->buffer = opj_realloc(mqc->buffer, (2 * len + 1) * sizeof(unsigned int));
|
mqc->buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int));
|
||||||
ip = (unsigned int *) mqc->buffer;
|
ip = (unsigned int *) mqc->buffer;
|
||||||
|
|
||||||
while (bp != end) {
|
while (bp < end) {
|
||||||
c = *(bp + 1);
|
c = *(bp + 1);
|
||||||
if (*bp == 0xff) {
|
if (*bp == 0xff) {
|
||||||
if (c > 0x8f) {
|
if (c > 0x8f) {
|
||||||
*ip = 0x0000ff18;
|
break;
|
||||||
} else {
|
} else {
|
||||||
bp++;
|
|
||||||
*ip = 0x00000017 | (c << 9);
|
*ip = 0x00000017 | (c << 9);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bp++;
|
|
||||||
*ip = 0x00000018 | (c << 8);
|
*ip = 0x00000018 | (c << 8);
|
||||||
}
|
}
|
||||||
|
bp++;
|
||||||
ip++;
|
ip++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Herv<EFBFBD> Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -24,17 +24,22 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif /* WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
#include "opj_config.h"
|
||||||
#include "opj_includes.h"
|
#include "opj_includes.h"
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
#ifndef OPJ_STATIC
|
#ifndef OPJ_STATIC
|
||||||
BOOL APIENTRY
|
BOOL APIENTRY
|
||||||
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
||||||
|
|
||||||
|
OPJ_ARG_NOT_USED(lpReserved);
|
||||||
|
OPJ_ARG_NOT_USED(hModule);
|
||||||
|
|
||||||
switch (ul_reason_for_call) {
|
switch (ul_reason_for_call) {
|
||||||
case DLL_PROCESS_ATTACH :
|
case DLL_PROCESS_ATTACH :
|
||||||
break;
|
break;
|
||||||
@@ -48,19 +53,19 @@ DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
#endif /* OPJ_STATIC */
|
#endif /* OPJ_STATIC */
|
||||||
#endif /* WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
const char* OPJ_CALLCONV opj_version(void) {
|
const char* OPJ_CALLCONV opj_version(void) {
|
||||||
return OPENJPEG_VERSION;
|
return PACKAGE_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
|
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
|
||||||
opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
|
opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
|
||||||
if(!dinfo) return NULL;
|
if(!dinfo) return NULL;
|
||||||
dinfo->is_decompressor = true;
|
dinfo->is_decompressor = OPJ_TRUE;
|
||||||
switch(format) {
|
switch(format) {
|
||||||
case CODEC_J2K:
|
case CODEC_J2K:
|
||||||
case CODEC_JPT:
|
case CODEC_JPT:
|
||||||
@@ -120,9 +125,10 @@ void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *paramete
|
|||||||
|
|
||||||
parameters->decod_format = -1;
|
parameters->decod_format = -1;
|
||||||
parameters->cod_format = -1;
|
parameters->cod_format = -1;
|
||||||
|
parameters->flags = 0;
|
||||||
/* UniPG>> */
|
/* UniPG>> */
|
||||||
#ifdef USE_JPWL
|
#ifdef USE_JPWL
|
||||||
parameters->jpwl_correct = false;
|
parameters->jpwl_correct = OPJ_FALSE;
|
||||||
parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
|
parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
|
||||||
parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
|
parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
@@ -159,7 +165,7 @@ opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *ci
|
|||||||
case CODEC_JPT:
|
case CODEC_JPT:
|
||||||
return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
|
return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
|
||||||
case CODEC_JP2:
|
case CODEC_JP2:
|
||||||
return jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info);
|
return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info);
|
||||||
case CODEC_UNKNOWN:
|
case CODEC_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -171,7 +177,7 @@ opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *ci
|
|||||||
opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
|
opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
|
||||||
opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
|
opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
|
||||||
if(!cinfo) return NULL;
|
if(!cinfo) return NULL;
|
||||||
cinfo->is_decompressor = false;
|
cinfo->is_decompressor = OPJ_FALSE;
|
||||||
switch(format) {
|
switch(format) {
|
||||||
case CODEC_J2K:
|
case CODEC_J2K:
|
||||||
/* get a J2K coder handle */
|
/* get a J2K coder handle */
|
||||||
@@ -243,10 +249,10 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete
|
|||||||
parameters->cp_disto_alloc = 0;
|
parameters->cp_disto_alloc = 0;
|
||||||
parameters->cp_fixed_alloc = 0;
|
parameters->cp_fixed_alloc = 0;
|
||||||
parameters->cp_fixed_quality = 0;
|
parameters->cp_fixed_quality = 0;
|
||||||
|
parameters->jpip_on = OPJ_FALSE;
|
||||||
/* UniPG>> */
|
/* UniPG>> */
|
||||||
#ifdef USE_JPWL
|
#ifdef USE_JPWL
|
||||||
parameters->jpwl_epc_on = false;
|
parameters->jpwl_epc_on = OPJ_FALSE;
|
||||||
parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
|
parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -296,7 +302,7 @@ void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *param
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
|
opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
|
||||||
if (index != NULL)
|
if (index != NULL)
|
||||||
opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
|
opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
|
||||||
"To extract the index, use the opj_encode_with_info() function.\n"
|
"To extract the index, use the opj_encode_with_info() function.\n"
|
||||||
@@ -304,20 +310,20 @@ bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *im
|
|||||||
return opj_encode_with_info(cinfo, cio, image, NULL);
|
return opj_encode_with_info(cinfo, cio, image, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
|
opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
|
||||||
if(cinfo && cio && image) {
|
if(cinfo && cio && image) {
|
||||||
switch(cinfo->codec_format) {
|
switch(cinfo->codec_format) {
|
||||||
case CODEC_J2K:
|
case CODEC_J2K:
|
||||||
return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
|
return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
|
||||||
case CODEC_JP2:
|
case CODEC_JP2:
|
||||||
return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
|
return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
|
||||||
case CODEC_JPT:
|
case CODEC_JPT:
|
||||||
case CODEC_UNKNOWN:
|
case CODEC_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
|
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
|
||||||
@@ -328,6 +334,7 @@ void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
|
|||||||
opj_free(tile_info->thresh);
|
opj_free(tile_info->thresh);
|
||||||
opj_free(tile_info->packet);
|
opj_free(tile_info->packet);
|
||||||
opj_free(tile_info->tp);
|
opj_free(tile_info->tp);
|
||||||
|
opj_free(tile_info->marker);
|
||||||
}
|
}
|
||||||
opj_free(cstr_info->tile);
|
opj_free(cstr_info->tile);
|
||||||
opj_free(cstr_info->marker);
|
opj_free(cstr_info->marker);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* Copyright (c) 2006-2007, Parvatha Elangovan
|
* Copyright (c) 2006-2007, Parvatha Elangovan
|
||||||
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -32,7 +33,6 @@
|
|||||||
#ifndef OPENJPEG_H
|
#ifndef OPENJPEG_H
|
||||||
#define OPENJPEG_H
|
#define OPENJPEG_H
|
||||||
|
|
||||||
#define OPENJPEG_VERSION "1.4.0.635"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
==========================================================
|
==========================================================
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
==========================================================
|
==========================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(OPJ_STATIC) || !(defined(WIN32) || defined(__WIN32__))
|
#if defined(OPJ_STATIC) || !defined(_WIN32)
|
||||||
#define OPJ_API
|
#define OPJ_API
|
||||||
#define OPJ_CALLCONV
|
#define OPJ_CALLCONV
|
||||||
#else
|
#else
|
||||||
@@ -53,38 +53,19 @@ that uses this DLL. This way any other project whose source files include this f
|
|||||||
OPJ_API functions as being imported from a DLL, wheras 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.
|
defined with this macro as being exported.
|
||||||
*/
|
*/
|
||||||
#ifdef OPJ_EXPORTS
|
#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
|
||||||
#define OPJ_API __declspec(dllexport)
|
#define OPJ_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define OPJ_API __declspec(dllimport)
|
#define OPJ_API __declspec(dllimport)
|
||||||
#endif /* OPJ_EXPORTS */
|
#endif /* OPJ_EXPORTS */
|
||||||
#endif /* !OPJ_STATIC || !WIN32 */
|
#endif /* !OPJ_STATIC || !_WIN32 */
|
||||||
|
|
||||||
#ifndef __cplusplus
|
typedef int opj_bool;
|
||||||
#if defined(HAVE_STDBOOL_H)
|
#define OPJ_TRUE 1
|
||||||
/*
|
#define OPJ_FALSE 0
|
||||||
The C language implementation does correctly provide the standard header
|
|
||||||
file "stdbool.h".
|
|
||||||
*/
|
|
||||||
#include <stdbool.h>
|
|
||||||
#else
|
|
||||||
/*
|
|
||||||
The C language implementation does not provide the standard header file
|
|
||||||
"stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
|
|
||||||
braindamage below.
|
|
||||||
*/
|
|
||||||
#if !defined(bool)
|
|
||||||
#define bool int
|
|
||||||
#endif
|
|
||||||
#if !defined(true)
|
|
||||||
#define true 1
|
|
||||||
#endif
|
|
||||||
#if !defined(false)
|
|
||||||
#define false 0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
|
/* Avoid compile-time warning because parameter is not used */
|
||||||
|
#define OPJ_ARG_NOT_USED(x) (void)(x)
|
||||||
/*
|
/*
|
||||||
==========================================================
|
==========================================================
|
||||||
Useful constant definitions
|
Useful constant definitions
|
||||||
@@ -154,14 +135,18 @@ typedef enum COLOR_SPACE {
|
|||||||
CLRSPC_SYCC = 3 /**< YUV */
|
CLRSPC_SYCC = 3 /**< YUV */
|
||||||
} OPJ_COLOR_SPACE;
|
} OPJ_COLOR_SPACE;
|
||||||
|
|
||||||
|
#define ENUMCS_SRGB 16
|
||||||
|
#define ENUMCS_GRAY 17
|
||||||
|
#define ENUMCS_SYCC 18
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Supported codec
|
Supported codec
|
||||||
*/
|
*/
|
||||||
typedef enum CODEC_FORMAT {
|
typedef enum CODEC_FORMAT {
|
||||||
CODEC_UNKNOWN = -1, /**< place-holder */
|
CODEC_UNKNOWN = -1, /**< place-holder */
|
||||||
CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
|
CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
|
||||||
CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
|
CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
|
||||||
CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
|
CODEC_JP2 = 2 /**< JPEG-2000 file format : read/write */
|
||||||
} OPJ_CODEC_FORMAT;
|
} OPJ_CODEC_FORMAT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -244,7 +229,7 @@ Compression parameters
|
|||||||
*/
|
*/
|
||||||
typedef struct opj_cparameters {
|
typedef struct opj_cparameters {
|
||||||
/** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
|
/** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
|
||||||
bool tile_size_on;
|
opj_bool tile_size_on;
|
||||||
/** XTOsiz */
|
/** XTOsiz */
|
||||||
int cp_tx0;
|
int cp_tx0;
|
||||||
/** YTOsiz */
|
/** YTOsiz */
|
||||||
@@ -326,7 +311,7 @@ typedef struct opj_cparameters {
|
|||||||
/**@name JPWL encoding parameters */
|
/**@name JPWL encoding parameters */
|
||||||
/*@{*/
|
/*@{*/
|
||||||
/** enables writing of EPC in MH, thus activating JPWL */
|
/** enables writing of EPC in MH, thus activating JPWL */
|
||||||
bool jpwl_epc_on;
|
opj_bool jpwl_epc_on;
|
||||||
/** error protection method for MH (0,1,16,32,37-128) */
|
/** error protection method for MH (0,1,16,32,37-128) */
|
||||||
int jpwl_hprot_MH;
|
int jpwl_hprot_MH;
|
||||||
/** tile number of header protection specification (>=0) */
|
/** tile number of header protection specification (>=0) */
|
||||||
@@ -366,8 +351,12 @@ typedef struct opj_cparameters {
|
|||||||
char tp_flag;
|
char tp_flag;
|
||||||
/** MCT (multiple component transform) */
|
/** MCT (multiple component transform) */
|
||||||
char tcp_mct;
|
char tcp_mct;
|
||||||
|
/** Enable JPIP indexing*/
|
||||||
|
opj_bool jpip_on;
|
||||||
} opj_cparameters_t;
|
} opj_cparameters_t;
|
||||||
|
|
||||||
|
#define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Decompression parameters
|
Decompression parameters
|
||||||
*/
|
*/
|
||||||
@@ -404,7 +393,7 @@ typedef struct opj_dparameters {
|
|||||||
/**@name JPWL decoding parameters */
|
/**@name JPWL decoding parameters */
|
||||||
/*@{*/
|
/*@{*/
|
||||||
/** activates the JPWL correction capabilities */
|
/** activates the JPWL correction capabilities */
|
||||||
bool jpwl_correct;
|
opj_bool jpwl_correct;
|
||||||
/** expected number of components */
|
/** expected number of components */
|
||||||
int jpwl_exp_comps;
|
int jpwl_exp_comps;
|
||||||
/** maximum number of tiles */
|
/** maximum number of tiles */
|
||||||
@@ -420,6 +409,7 @@ typedef struct opj_dparameters {
|
|||||||
*/
|
*/
|
||||||
OPJ_LIMIT_DECODING cp_limit_decoding;
|
OPJ_LIMIT_DECODING cp_limit_decoding;
|
||||||
|
|
||||||
|
unsigned int flags;
|
||||||
} opj_dparameters_t;
|
} opj_dparameters_t;
|
||||||
|
|
||||||
/** Common fields between JPEG-2000 compression and decompression master structs. */
|
/** Common fields between JPEG-2000 compression and decompression master structs. */
|
||||||
@@ -427,7 +417,7 @@ typedef struct opj_dparameters {
|
|||||||
#define opj_common_fields \
|
#define opj_common_fields \
|
||||||
opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
|
opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\
|
||||||
void * client_data; /**< Available for use by application */\
|
void * client_data; /**< Available for use by application */\
|
||||||
bool is_decompressor; /**< So common code can tell which is which */\
|
opj_bool is_decompressor; /**< So common code can tell which is which */\
|
||||||
OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
|
OPJ_CODEC_FORMAT codec_format; /**< selected codec */\
|
||||||
void *j2k_handle; /**< pointer to the J2K codec */\
|
void *j2k_handle; /**< pointer to the J2K codec */\
|
||||||
void *jp2_handle; /**< pointer to the JP2 codec */\
|
void *jp2_handle; /**< pointer to the JP2 codec */\
|
||||||
@@ -555,6 +545,10 @@ typedef struct opj_image {
|
|||||||
OPJ_COLOR_SPACE color_space;
|
OPJ_COLOR_SPACE color_space;
|
||||||
/** image components */
|
/** image components */
|
||||||
opj_image_comp_t *comps;
|
opj_image_comp_t *comps;
|
||||||
|
/** 'restricted' ICC profile */
|
||||||
|
unsigned char *icc_profile_buf;
|
||||||
|
/** size of ICC profile */
|
||||||
|
int icc_profile_len;
|
||||||
} opj_image_t;
|
} opj_image_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -601,6 +595,21 @@ typedef struct opj_packet_info {
|
|||||||
double disto;
|
double disto;
|
||||||
} opj_packet_info_t;
|
} opj_packet_info_t;
|
||||||
|
|
||||||
|
|
||||||
|
/* UniPG>> */
|
||||||
|
/**
|
||||||
|
Marker structure
|
||||||
|
*/
|
||||||
|
typedef struct opj_marker_info_t {
|
||||||
|
/** marker type */
|
||||||
|
unsigned short int type;
|
||||||
|
/** position in codestream */
|
||||||
|
int pos;
|
||||||
|
/** length, marker val included */
|
||||||
|
int len;
|
||||||
|
} opj_marker_info_t;
|
||||||
|
/* <<UniPG */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Index structure : Information concerning tile-parts
|
Index structure : Information concerning tile-parts
|
||||||
*/
|
*/
|
||||||
@@ -645,26 +654,18 @@ typedef struct opj_tile_info {
|
|||||||
int numpix;
|
int numpix;
|
||||||
/** add fixed_quality */
|
/** add fixed_quality */
|
||||||
double distotile;
|
double distotile;
|
||||||
|
/** number of markers */
|
||||||
|
int marknum;
|
||||||
|
/** list of markers */
|
||||||
|
opj_marker_info_t *marker;
|
||||||
|
/** actual size of markers array */
|
||||||
|
int maxmarknum;
|
||||||
/** number of tile parts */
|
/** number of tile parts */
|
||||||
int num_tps;
|
int num_tps;
|
||||||
/** information concerning tile parts */
|
/** information concerning tile parts */
|
||||||
opj_tp_info_t *tp;
|
opj_tp_info_t *tp;
|
||||||
} opj_tile_info_t;
|
} opj_tile_info_t;
|
||||||
|
|
||||||
/* UniPG>> */
|
|
||||||
/**
|
|
||||||
Marker structure
|
|
||||||
*/
|
|
||||||
typedef struct opj_marker_info_t {
|
|
||||||
/** marker type */
|
|
||||||
unsigned short int type;
|
|
||||||
/** position in codestream */
|
|
||||||
int pos;
|
|
||||||
/** length, marker val included */
|
|
||||||
int len;
|
|
||||||
} opj_marker_info_t;
|
|
||||||
/* <<UniPG */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Index structure of the codestream
|
Index structure of the codestream
|
||||||
*/
|
*/
|
||||||
@@ -883,13 +884,13 @@ Setup the encoder parameters using the current image and using user parameters.
|
|||||||
OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
|
OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
|
||||||
/**
|
/**
|
||||||
Encode an image into a JPEG-2000 codestream
|
Encode an image into a JPEG-2000 codestream
|
||||||
@param cinfo compressor handle
|
3@param cinfo compressor handle
|
||||||
@param cio Output buffer stream
|
@param cio Output buffer stream
|
||||||
@param image Image to encode
|
@param image Image to encode
|
||||||
@param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
|
@param index Depreacted -> Set to NULL. To extract index, used opj_encode_wci()
|
||||||
@return Returns true if successful, returns false otherwise
|
@return Returns true if successful, returns false otherwise
|
||||||
*/
|
*/
|
||||||
OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
|
OPJ_API opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
|
||||||
/**
|
/**
|
||||||
Encode an image into a JPEG-2000 codestream and extract the codestream information
|
Encode an image into a JPEG-2000 codestream and extract the codestream information
|
||||||
@param cinfo compressor handle
|
@param cinfo compressor handle
|
||||||
@@ -898,13 +899,14 @@ Encode an image into a JPEG-2000 codestream and extract the codestream informati
|
|||||||
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise
|
@param cstr_info Codestream information structure if needed afterwards, NULL otherwise
|
||||||
@return Returns true if successful, returns false otherwise
|
@return Returns true if successful, returns false otherwise
|
||||||
*/
|
*/
|
||||||
OPJ_API bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
OPJ_API opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
|
||||||
/**
|
/**
|
||||||
Destroy Codestream information after compression or decompression
|
Destroy Codestream information after compression or decompression
|
||||||
@param cstr_info Codestream information structure
|
@param cstr_info Codestream information structure
|
||||||
*/
|
*/
|
||||||
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
|
OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
36
indra/libopenjpeg/opj_config.h
Normal file
36
indra/libopenjpeg/opj_config.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/* create config.h for CMake */
|
||||||
|
#define PACKAGE_VERSION "1.5.2"
|
||||||
|
|
||||||
|
#define HAVE_INTTYPES_H
|
||||||
|
#define HAVE_MEMORY_H
|
||||||
|
#define HAVE_STDINT_H
|
||||||
|
#define HAVE_STDLIB_H
|
||||||
|
#define HAVE_STRINGS_H
|
||||||
|
#define HAVE_STRING_H
|
||||||
|
#define HAVE_SYS_STAT_H
|
||||||
|
#define HAVE_SYS_TYPES_H
|
||||||
|
#define HAVE_UNISTD_H
|
||||||
|
/* #define HAVE_LIBPNG */
|
||||||
|
/* #define HAVE_PNG_H */
|
||||||
|
/* #define HAVE_LIBTIFF */
|
||||||
|
/* #define HAVE_TIFF_H */
|
||||||
|
|
||||||
|
/* #undef HAVE_LIBLCMS1 */
|
||||||
|
/* #undef HAVE_LIBLCMS2 */
|
||||||
|
/* #undef HAVE_LCMS1_H */
|
||||||
|
/* #undef HAVE_LCMS2_H */
|
||||||
|
|
||||||
|
/* Byte order. */
|
||||||
|
/* All compilers that support Mac OS X define either __BIG_ENDIAN__ or
|
||||||
|
* __LITTLE_ENDIAN__ to match the endianness of the architecture being
|
||||||
|
* compiled for. This is not necessarily the same as the architecture of the
|
||||||
|
* machine doing the building. In order to support Universal Binaries on
|
||||||
|
* Mac OS X, we prefer those defines to decide the endianness.
|
||||||
|
* On other platforms we use the result of the TRY_RUN. */
|
||||||
|
#if !defined(__APPLE__)
|
||||||
|
/* #undef OPJ_BIG_ENDIAN */
|
||||||
|
#elif defined(__BIG_ENDIAN__)
|
||||||
|
# define OPJ_BIG_ENDIAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Herv<EFBFBD> Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -89,20 +89,25 @@ Most compilers implement their own version of this keyword ...
|
|||||||
/* MSVC and Borland C do not have lrintf */
|
/* MSVC and Borland C do not have lrintf */
|
||||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||||
static INLINE long lrintf(float f){
|
static INLINE long lrintf(float f){
|
||||||
int i;
|
#ifdef _M_X64
|
||||||
|
return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f));
|
||||||
_asm{
|
#else
|
||||||
fld f
|
int i;
|
||||||
fistp i
|
|
||||||
};
|
_asm{
|
||||||
|
fld f
|
||||||
return i;
|
fistp i
|
||||||
|
};
|
||||||
|
|
||||||
|
return i;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "j2k_lib.h"
|
#include "j2k_lib.h"
|
||||||
#include "opj_malloc.h"
|
#include "opj_malloc.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
#include "bio.h"
|
||||||
#include "cio.h"
|
#include "cio.h"
|
||||||
|
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
@@ -123,9 +128,12 @@ static INLINE long lrintf(float f){
|
|||||||
#include "int.h"
|
#include "int.h"
|
||||||
#include "fix.h"
|
#include "fix.h"
|
||||||
|
|
||||||
|
#include "cidx_manager.h"
|
||||||
|
#include "indexbox_manager.h"
|
||||||
|
|
||||||
/* JPWL>> */
|
/* JPWL>> */
|
||||||
#ifdef USE_JPWL
|
#ifdef USE_JPWL
|
||||||
#include "../jpwl/jpwl.h"
|
#include "./jpwl/jpwl.h"
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
/* <<JPWL */
|
/* <<JPWL */
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Herv<EFBFBD> Drolon, FreeImage Team
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||||
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
|
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -69,7 +69,7 @@ Allocate memory aligned to a 16 byte boundry
|
|||||||
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
|
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
|
||||||
*/
|
*/
|
||||||
/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
|
/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
/* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
|
/* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#include <mm_malloc.h>
|
#include <mm_malloc.h>
|
||||||
@@ -80,11 +80,13 @@ Allocate memory aligned to a 16 byte boundry
|
|||||||
#define HAVE_MM_MALLOC
|
#define HAVE_MM_MALLOC
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#else /* Not WIN32 */
|
#else /* Not _WIN32 */
|
||||||
#if defined(__sun)
|
#if defined(__sun)
|
||||||
#define HAVE_MEMALIGN
|
#define HAVE_MEMALIGN
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
#define HAVE_POSIX_MEMALIGN
|
||||||
/* Linux x86_64 and OSX always align allocations to 16 bytes */
|
/* Linux x86_64 and OSX always align allocations to 16 bytes */
|
||||||
#elif !defined(__amd64__) && !defined(__APPLE__)
|
#elif !defined(__amd64__) && !defined(__APPLE__) && !defined(_AIX)
|
||||||
#define HAVE_MEMALIGN
|
#define HAVE_MEMALIGN
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -130,22 +132,22 @@ Allocate memory aligned to a 16 byte boundry
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Reallocate memory blocks.
|
Reallocate memory blocks.
|
||||||
@param memblock Pointer to previously allocated memory block
|
@param m Pointer to previously allocated memory block
|
||||||
@param size New size in bytes
|
@param s New size in bytes
|
||||||
@return Returns a void pointer to the reallocated (and possibly moved) memory block
|
@return Returns a void pointer to the reallocated (and possibly moved) memory block
|
||||||
*/
|
*/
|
||||||
#ifdef ALLOC_PERF_OPT
|
#ifdef ALLOC_PERF_OPT
|
||||||
void * OPJ_CALLCONV opj_realloc(void * _Memory, size_t NewSize);
|
void * OPJ_CALLCONV opj_realloc(void * m, size_t s);
|
||||||
#else
|
#else
|
||||||
#define opj_realloc(m, s) realloc(m, s)
|
#define opj_realloc(m, s) realloc(m, s)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Deallocates or frees a memory block.
|
Deallocates or frees a memory block.
|
||||||
@param memblock Previously allocated memory block to be freed
|
@param m Previously allocated memory block to be freed
|
||||||
*/
|
*/
|
||||||
#ifdef ALLOC_PERF_OPT
|
#ifdef ALLOC_PERF_OPT
|
||||||
void OPJ_CALLCONV opj_free(void * _Memory);
|
void OPJ_CALLCONV opj_free(void * m);
|
||||||
#else
|
#else
|
||||||
#define opj_free(m) free(m)
|
#define opj_free(m) free(m)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
170
indra/libopenjpeg/phix_manager.c
Normal file
170
indra/libopenjpeg/phix_manager.c
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
* $Id: phix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||||
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||||
|
* Copyright (c) 2003-2004, Yannick Verschueren
|
||||||
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \file
|
||||||
|
* \brief Modification of jpip.c from 2KAN indexer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "opj_includes.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write faix box of phix
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] compno component number
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @param[in] EPHused true if if EPH option used
|
||||||
|
* @param[in] j2klen length of j2k codestream
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return length of faix box
|
||||||
|
*/
|
||||||
|
int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
|
||||||
|
|
||||||
|
int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int len, lenp=0, compno, i;
|
||||||
|
opj_jp2_box_t *box;
|
||||||
|
|
||||||
|
box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
|
||||||
|
|
||||||
|
for( i=0;i<2;i++){
|
||||||
|
if (i) cio_seek( cio, lenp);
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_PHIX, 4); /* PHIX */
|
||||||
|
|
||||||
|
write_manf( i, cstr_info.numcomps, box, cio);
|
||||||
|
|
||||||
|
for( compno=0; compno<cstr_info.numcomps; compno++){
|
||||||
|
box[compno].length = write_phixfaix( coff, compno, cstr_info, EPHused, j2klen, cio);
|
||||||
|
box[compno].type = JPIP_FAIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free(box);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
|
||||||
|
opj_tile_info_t *tile_Idx;
|
||||||
|
opj_packet_info_t packet;
|
||||||
|
int resno, precno, layno, num_packet;
|
||||||
|
int numOfres, numOfprec, numOflayers;
|
||||||
|
packet.end_ph_pos = packet.start_pos = -1;
|
||||||
|
(void)EPHused; /* unused ? */
|
||||||
|
|
||||||
|
if( j2klen > pow( 2, 32)){
|
||||||
|
size_of_coding = 8;
|
||||||
|
version = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
size_of_coding = 4;
|
||||||
|
version = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_FAIX, 4); /* FAIX */
|
||||||
|
cio_write( cio, version,1); /* Version 0 = 4 bytes */
|
||||||
|
|
||||||
|
nmax = 0;
|
||||||
|
for( i=0; i<=cstr_info.numdecompos[compno]; i++)
|
||||||
|
nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
|
||||||
|
|
||||||
|
cio_write( cio, nmax, size_of_coding); /* NMAX */
|
||||||
|
cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
|
||||||
|
|
||||||
|
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
|
||||||
|
tile_Idx = &cstr_info.tile[ tileno];
|
||||||
|
|
||||||
|
num_packet = 0;
|
||||||
|
numOfres = cstr_info.numdecompos[compno] + 1;
|
||||||
|
|
||||||
|
for( resno=0; resno<numOfres ; resno++){
|
||||||
|
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
|
||||||
|
for( precno=0; precno<numOfprec; precno++){
|
||||||
|
numOflayers = cstr_info.numlayers;
|
||||||
|
for( layno=0; layno<numOflayers; layno++){
|
||||||
|
|
||||||
|
switch ( cstr_info.prog){
|
||||||
|
case LRCP:
|
||||||
|
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
|
||||||
|
break;
|
||||||
|
case RLCP:
|
||||||
|
packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
|
||||||
|
break;
|
||||||
|
case RPCL:
|
||||||
|
packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
|
||||||
|
break;
|
||||||
|
case PCRL:
|
||||||
|
packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
|
||||||
|
break;
|
||||||
|
case CPRL:
|
||||||
|
packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf( stderr, "failed to ppix indexing\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, packet.end_ph_pos-packet.start_pos+1, size_of_coding); /* length */
|
||||||
|
|
||||||
|
num_packet++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* PADDING */
|
||||||
|
while( num_packet < nmax){
|
||||||
|
cio_write( cio, 0, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, 0, size_of_coding); /* length */
|
||||||
|
num_packet++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
@@ -43,31 +43,31 @@ Get next packet in layer-resolution-component-precinct order.
|
|||||||
@param pi packet iterator to modify
|
@param pi packet iterator to modify
|
||||||
@return returns false if pi pointed to the last packet or else returns true
|
@return returns false if pi pointed to the last packet or else returns true
|
||||||
*/
|
*/
|
||||||
static bool pi_next_lrcp(opj_pi_iterator_t * pi);
|
static opj_bool pi_next_lrcp(opj_pi_iterator_t * pi);
|
||||||
/**
|
/**
|
||||||
Get next packet in resolution-layer-component-precinct order.
|
Get next packet in resolution-layer-component-precinct order.
|
||||||
@param pi packet iterator to modify
|
@param pi packet iterator to modify
|
||||||
@return returns false if pi pointed to the last packet or else returns true
|
@return returns false if pi pointed to the last packet or else returns true
|
||||||
*/
|
*/
|
||||||
static bool pi_next_rlcp(opj_pi_iterator_t * pi);
|
static opj_bool pi_next_rlcp(opj_pi_iterator_t * pi);
|
||||||
/**
|
/**
|
||||||
Get next packet in resolution-precinct-component-layer order.
|
Get next packet in resolution-precinct-component-layer order.
|
||||||
@param pi packet iterator to modify
|
@param pi packet iterator to modify
|
||||||
@return returns false if pi pointed to the last packet or else returns true
|
@return returns false if pi pointed to the last packet or else returns true
|
||||||
*/
|
*/
|
||||||
static bool pi_next_rpcl(opj_pi_iterator_t * pi);
|
static opj_bool pi_next_rpcl(opj_pi_iterator_t * pi);
|
||||||
/**
|
/**
|
||||||
Get next packet in precinct-component-resolution-layer order.
|
Get next packet in precinct-component-resolution-layer order.
|
||||||
@param pi packet iterator to modify
|
@param pi packet iterator to modify
|
||||||
@return returns false if pi pointed to the last packet or else returns true
|
@return returns false if pi pointed to the last packet or else returns true
|
||||||
*/
|
*/
|
||||||
static bool pi_next_pcrl(opj_pi_iterator_t * pi);
|
static opj_bool pi_next_pcrl(opj_pi_iterator_t * pi);
|
||||||
/**
|
/**
|
||||||
Get next packet in component-precinct-resolution-layer order.
|
Get next packet in component-precinct-resolution-layer order.
|
||||||
@param pi packet iterator to modify
|
@param pi packet iterator to modify
|
||||||
@return returns false if pi pointed to the last packet or else returns true
|
@return returns false if pi pointed to the last packet or else returns true
|
||||||
*/
|
*/
|
||||||
static bool pi_next_cprl(opj_pi_iterator_t * pi);
|
static opj_bool pi_next_cprl(opj_pi_iterator_t * pi);
|
||||||
|
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi);
|
|||||||
==========================================================
|
==========================================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static bool pi_next_lrcp(opj_pi_iterator_t * pi) {
|
static opj_bool pi_next_lrcp(opj_pi_iterator_t * pi) {
|
||||||
opj_pi_comp_t *comp = NULL;
|
opj_pi_comp_t *comp = NULL;
|
||||||
opj_pi_resolution_t *res = NULL;
|
opj_pi_resolution_t *res = NULL;
|
||||||
long index = 0;
|
long index = 0;
|
||||||
@@ -108,7 +108,7 @@ static bool pi_next_lrcp(opj_pi_iterator_t * pi) {
|
|||||||
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
||||||
if (!pi->include[index]) {
|
if (!pi->include[index]) {
|
||||||
pi->include[index] = 1;
|
pi->include[index] = 1;
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
LABEL_SKIP:;
|
LABEL_SKIP:;
|
||||||
}
|
}
|
||||||
@@ -116,10 +116,10 @@ LABEL_SKIP:;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool pi_next_rlcp(opj_pi_iterator_t * pi) {
|
static opj_bool pi_next_rlcp(opj_pi_iterator_t * pi) {
|
||||||
opj_pi_comp_t *comp = NULL;
|
opj_pi_comp_t *comp = NULL;
|
||||||
opj_pi_resolution_t *res = NULL;
|
opj_pi_resolution_t *res = NULL;
|
||||||
long index = 0;
|
long index = 0;
|
||||||
@@ -147,7 +147,7 @@ static bool pi_next_rlcp(opj_pi_iterator_t * pi) {
|
|||||||
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
||||||
if (!pi->include[index]) {
|
if (!pi->include[index]) {
|
||||||
pi->include[index] = 1;
|
pi->include[index] = 1;
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
LABEL_SKIP:;
|
LABEL_SKIP:;
|
||||||
}
|
}
|
||||||
@@ -155,10 +155,10 @@ LABEL_SKIP:;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool pi_next_rpcl(opj_pi_iterator_t * pi) {
|
static opj_bool pi_next_rpcl(opj_pi_iterator_t * pi) {
|
||||||
opj_pi_comp_t *comp = NULL;
|
opj_pi_comp_t *comp = NULL;
|
||||||
opj_pi_resolution_t *res = NULL;
|
opj_pi_resolution_t *res = NULL;
|
||||||
long index = 0;
|
long index = 0;
|
||||||
@@ -229,7 +229,7 @@ if (!pi->tp_on){
|
|||||||
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
||||||
if (!pi->include[index]) {
|
if (!pi->include[index]) {
|
||||||
pi->include[index] = 1;
|
pi->include[index] = 1;
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
LABEL_SKIP:;
|
LABEL_SKIP:;
|
||||||
}
|
}
|
||||||
@@ -238,10 +238,10 @@ LABEL_SKIP:;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool pi_next_pcrl(opj_pi_iterator_t * pi) {
|
static opj_bool pi_next_pcrl(opj_pi_iterator_t * pi) {
|
||||||
opj_pi_comp_t *comp = NULL;
|
opj_pi_comp_t *comp = NULL;
|
||||||
opj_pi_resolution_t *res = NULL;
|
opj_pi_resolution_t *res = NULL;
|
||||||
long index = 0;
|
long index = 0;
|
||||||
@@ -310,7 +310,7 @@ static bool pi_next_pcrl(opj_pi_iterator_t * pi) {
|
|||||||
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
||||||
if (!pi->include[index]) {
|
if (!pi->include[index]) {
|
||||||
pi->include[index] = 1;
|
pi->include[index] = 1;
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
LABEL_SKIP:;
|
LABEL_SKIP:;
|
||||||
}
|
}
|
||||||
@@ -319,10 +319,10 @@ LABEL_SKIP:;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool pi_next_cprl(opj_pi_iterator_t * pi) {
|
static opj_bool pi_next_cprl(opj_pi_iterator_t * pi) {
|
||||||
opj_pi_comp_t *comp = NULL;
|
opj_pi_comp_t *comp = NULL;
|
||||||
opj_pi_resolution_t *res = NULL;
|
opj_pi_resolution_t *res = NULL;
|
||||||
long index = 0;
|
long index = 0;
|
||||||
@@ -389,7 +389,7 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi) {
|
|||||||
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
|
||||||
if (!pi->include[index]) {
|
if (!pi->include[index]) {
|
||||||
pi->include[index] = 1;
|
pi->include[index] = 1;
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
LABEL_SKIP:;
|
LABEL_SKIP:;
|
||||||
}
|
}
|
||||||
@@ -398,7 +398,7 @@ LABEL_SKIP:;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -707,7 +707,7 @@ void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pi_next(opj_pi_iterator_t * pi) {
|
opj_bool pi_next(opj_pi_iterator_t * pi) {
|
||||||
switch (pi->poc.prg) {
|
switch (pi->poc.prg) {
|
||||||
case LRCP:
|
case LRCP:
|
||||||
return pi_next_lrcp(pi);
|
return pi_next_lrcp(pi);
|
||||||
@@ -720,13 +720,13 @@ bool pi_next(opj_pi_iterator_t * pi) {
|
|||||||
case CPRL:
|
case CPRL:
|
||||||
return pi_next_cprl(pi);
|
return pi_next_cprl(pi);
|
||||||
case PROG_UNKNOWN:
|
case PROG_UNKNOWN:
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp){
|
opj_bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp){
|
||||||
char prog[4];
|
char prog[4];
|
||||||
int i;
|
int i;
|
||||||
int incr_top=1,resetX=0;
|
int incr_top=1,resetX=0;
|
||||||
@@ -748,7 +748,7 @@ bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,
|
|||||||
case RPCL: strncpy(prog, "RPCL",4);
|
case RPCL: strncpy(prog, "RPCL",4);
|
||||||
break;
|
break;
|
||||||
case PROG_UNKNOWN:
|
case PROG_UNKNOWN:
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(cp->tp_on && ((!cp->cinema && (t2_mode == FINAL_PASS)) || cp->cinema))){
|
if(!(cp->tp_on && ((!cp->cinema && (t2_mode == FINAL_PASS)) || cp->cinema))){
|
||||||
@@ -958,6 +958,6 @@ bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,12 +115,14 @@ Modify the packet iterator for enabling tile part generation
|
|||||||
@param pi Handle to the packet iterator generated in pi_initialise_encode
|
@param pi Handle to the packet iterator generated in pi_initialise_encode
|
||||||
@param cp Coding parameters
|
@param cp Coding parameters
|
||||||
@param tileno Number that identifies the tile for which to list the packets
|
@param tileno Number that identifies the tile for which to list the packets
|
||||||
|
@param pino Iterator index for pi
|
||||||
@param tpnum Tile part number of the current tile
|
@param tpnum Tile part number of the current tile
|
||||||
@param tppos The position of the tile part flag in the progression order
|
@param tppos The position of the tile part flag in the progression order
|
||||||
|
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
|
||||||
@param cur_totnum_tp The total number of tile parts in the current tile
|
@param cur_totnum_tp The total number of tile parts in the current tile
|
||||||
@return Returns true if an error is detected
|
@return Returns true if an error is detected
|
||||||
*/
|
*/
|
||||||
bool pi_create_encode(opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp);
|
opj_bool pi_create_encode(opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos, J2K_T2_MODE t2_mode,int cur_totnum_tp);
|
||||||
/**
|
/**
|
||||||
Create a packet iterator for Decoder
|
Create a packet iterator for Decoder
|
||||||
@param image Raw image for which the packets will be listed
|
@param image Raw image for which the packets will be listed
|
||||||
@@ -145,7 +147,7 @@ Modify the packet iterator to point to the next packet
|
|||||||
@param pi Packet iterator to modify
|
@param pi Packet iterator to modify
|
||||||
@return Returns false if pi pointed to the last packet or else returns true
|
@return Returns false if pi pointed to the last packet or else returns true
|
||||||
*/
|
*/
|
||||||
bool pi_next(opj_pi_iterator_t * pi);
|
opj_bool pi_next(opj_pi_iterator_t * pi);
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
/*@}*/
|
/*@}*/
|
||||||
|
|
||||||
|
|||||||
173
indra/libopenjpeg/ppix_manager.c
Normal file
173
indra/libopenjpeg/ppix_manager.c
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
/*
|
||||||
|
* $Id: ppix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||||
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||||
|
* Copyright (c) 2003-2004, Yannick Verschueren
|
||||||
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \file
|
||||||
|
* \brief Modification of jpip.c from 2KAN indexer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include "opj_includes.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write faix box of ppix
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] compno component number
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @param[in] EPHused true if if EPH option used
|
||||||
|
* @param[in] j2klen length of j2k codestream
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return length of faix box
|
||||||
|
*/
|
||||||
|
int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
|
||||||
|
|
||||||
|
int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int len, lenp, compno, i;
|
||||||
|
opj_jp2_box_t *box;
|
||||||
|
|
||||||
|
/* printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */
|
||||||
|
|
||||||
|
lenp = -1;
|
||||||
|
box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
|
||||||
|
|
||||||
|
for (i=0;i<2;i++){
|
||||||
|
if (i) cio_seek( cio, lenp);
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_PPIX, 4); /* PPIX */
|
||||||
|
|
||||||
|
write_manf( i, cstr_info.numcomps, box, cio);
|
||||||
|
|
||||||
|
for (compno=0; compno<cstr_info.numcomps; compno++){
|
||||||
|
box[compno].length = write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio);
|
||||||
|
box[compno].type = JPIP_FAIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free(box);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
|
||||||
|
opj_tile_info_t *tile_Idx;
|
||||||
|
opj_packet_info_t packet;
|
||||||
|
int resno, precno, layno, num_packet;
|
||||||
|
int numOfres, numOfprec, numOflayers;
|
||||||
|
packet.end_pos = packet.end_ph_pos = packet.start_pos = -1;
|
||||||
|
(void)EPHused; /* unused ? */
|
||||||
|
|
||||||
|
if( j2klen > pow( 2, 32)){
|
||||||
|
size_of_coding = 8;
|
||||||
|
version = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
size_of_coding = 4;
|
||||||
|
version = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_FAIX, 4); /* FAIX */
|
||||||
|
cio_write( cio, version, 1); /* Version 0 = 4 bytes */
|
||||||
|
|
||||||
|
nmax = 0;
|
||||||
|
for( i=0; i<=cstr_info.numdecompos[compno]; i++)
|
||||||
|
nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
|
||||||
|
|
||||||
|
cio_write( cio, nmax, size_of_coding); /* NMAX */
|
||||||
|
cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
|
||||||
|
|
||||||
|
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
|
||||||
|
tile_Idx = &cstr_info.tile[ tileno];
|
||||||
|
|
||||||
|
num_packet=0;
|
||||||
|
numOfres = cstr_info.numdecompos[compno] + 1;
|
||||||
|
|
||||||
|
for( resno=0; resno<numOfres ; resno++){
|
||||||
|
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
|
||||||
|
for( precno=0; precno<numOfprec; precno++){
|
||||||
|
numOflayers = cstr_info.numlayers;
|
||||||
|
for( layno=0; layno<numOflayers; layno++){
|
||||||
|
|
||||||
|
switch ( cstr_info.prog){
|
||||||
|
case LRCP:
|
||||||
|
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
|
||||||
|
break;
|
||||||
|
case RLCP:
|
||||||
|
packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
|
||||||
|
break;
|
||||||
|
case RPCL:
|
||||||
|
packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
|
||||||
|
break;
|
||||||
|
case PCRL:
|
||||||
|
packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
|
||||||
|
break;
|
||||||
|
case CPRL:
|
||||||
|
packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf( stderr, "failed to ppix indexing\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
cio_write( cio, packet.start_pos-coff, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, packet.end_pos-packet.start_pos+1, size_of_coding); /* length */
|
||||||
|
|
||||||
|
num_packet++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while( num_packet < nmax){ /* PADDING */
|
||||||
|
cio_write( cio, 0, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, 0, size_of_coding); /* length */
|
||||||
|
num_packet++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
@@ -123,20 +123,20 @@ static void t1_enc_refpass_step(
|
|||||||
/**
|
/**
|
||||||
Decode refinement pass
|
Decode refinement pass
|
||||||
*/
|
*/
|
||||||
static void INLINE t1_dec_refpass_step_raw(
|
static INLINE void t1_dec_refpass_step_raw(
|
||||||
opj_t1_t *t1,
|
opj_t1_t *t1,
|
||||||
flag_t *flagsp,
|
flag_t *flagsp,
|
||||||
int *datap,
|
int *datap,
|
||||||
int poshalf,
|
int poshalf,
|
||||||
int neghalf,
|
int neghalf,
|
||||||
int vsc);
|
int vsc);
|
||||||
static void INLINE t1_dec_refpass_step_mqc(
|
static INLINE void t1_dec_refpass_step_mqc(
|
||||||
opj_t1_t *t1,
|
opj_t1_t *t1,
|
||||||
flag_t *flagsp,
|
flag_t *flagsp,
|
||||||
int *datap,
|
int *datap,
|
||||||
int poshalf,
|
int poshalf,
|
||||||
int neghalf);
|
int neghalf);
|
||||||
static void INLINE t1_dec_refpass_step_mqc_vsc(
|
static INLINE void t1_dec_refpass_step_mqc_vsc(
|
||||||
opj_t1_t *t1,
|
opj_t1_t *t1,
|
||||||
flag_t *flagsp,
|
flag_t *flagsp,
|
||||||
int *datap,
|
int *datap,
|
||||||
@@ -240,6 +240,7 @@ Encode 1 code-block
|
|||||||
@param stepsize
|
@param stepsize
|
||||||
@param cblksty Code-block style
|
@param cblksty Code-block style
|
||||||
@param numcomps
|
@param numcomps
|
||||||
|
@param mct
|
||||||
@param tile
|
@param tile
|
||||||
*/
|
*/
|
||||||
static void t1_encode_cblk(
|
static void t1_encode_cblk(
|
||||||
@@ -381,9 +382,10 @@ static INLINE void t1_dec_sigpass_step_raw(
|
|||||||
int vsc)
|
int vsc)
|
||||||
{
|
{
|
||||||
int v, flag;
|
int v, flag;
|
||||||
|
|
||||||
opj_raw_t *raw = t1->raw; /* RAW component */
|
opj_raw_t *raw = t1->raw; /* RAW component */
|
||||||
|
|
||||||
|
OPJ_ARG_NOT_USED(orient);
|
||||||
|
|
||||||
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
|
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
|
||||||
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
|
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
|
||||||
if (raw_decode(raw)) {
|
if (raw_decode(raw)) {
|
||||||
@@ -822,9 +824,10 @@ static void t1_dec_clnpass_step_partial(
|
|||||||
int oneplushalf)
|
int oneplushalf)
|
||||||
{
|
{
|
||||||
int v, flag;
|
int v, flag;
|
||||||
|
|
||||||
opj_mqc_t *mqc = t1->mqc; /* MQC component */
|
opj_mqc_t *mqc = t1->mqc; /* MQC component */
|
||||||
|
|
||||||
|
OPJ_ARG_NOT_USED(orient);
|
||||||
|
|
||||||
flag = *flagsp;
|
flag = *flagsp;
|
||||||
mqc_setcurctx(mqc, t1_getctxno_sc(flag));
|
mqc_setcurctx(mqc, t1_getctxno_sc(flag));
|
||||||
v = mqc_decode(mqc) ^ t1_getspb(flag);
|
v = mqc_decode(mqc) ^ t1_getspb(flag);
|
||||||
@@ -1088,34 +1091,21 @@ static double t1_getwmsedec(
|
|||||||
int numcomps,
|
int numcomps,
|
||||||
int mct)
|
int mct)
|
||||||
{
|
{
|
||||||
double w1 = 1, w2, wmsedec;
|
double w1, w2, wmsedec;
|
||||||
|
|
||||||
// Prevent running an MCT on more than 3 components. NB openjpeg v2.0 will support this via
|
|
||||||
// custom MCT tables that can be passed as encode parameters, 1.3 cannot support this as it
|
|
||||||
// uses a static table of 3 entries and there for can only cope with 3 components with out an
|
|
||||||
// array overflow
|
|
||||||
|
|
||||||
if(numcomps==3) {
|
|
||||||
if (qmfbid == 1) {
|
|
||||||
w1 = (numcomps > 1) ? mct_getnorm(compno) : 1.0;
|
|
||||||
} else {
|
|
||||||
w1 = (numcomps > 1) ? mct_getnorm_real(compno) : 1.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qmfbid == 1) {
|
if (qmfbid == 1) {
|
||||||
|
w1 = (mct && numcomps==3) ? mct_getnorm(compno) : 1.0;
|
||||||
w2 = dwt_getnorm(level, orient);
|
w2 = dwt_getnorm(level, orient);
|
||||||
} else { /* if (qmfbid == 0) */
|
} else { /* if (qmfbid == 0) */
|
||||||
|
w1 = (mct && numcomps==3) ? mct_getnorm_real(compno) : 1.0;
|
||||||
w2 = dwt_getnorm_real(level, orient);
|
w2 = dwt_getnorm_real(level, orient);
|
||||||
}
|
}
|
||||||
|
|
||||||
wmsedec = w1 * w2 * stepsize * (1 << bpno);
|
wmsedec = w1 * w2 * stepsize * (1 << bpno);
|
||||||
wmsedec *= wmsedec * nmsedec / 8192.0;
|
wmsedec *= wmsedec * nmsedec / 8192.0;
|
||||||
|
|
||||||
return wmsedec;
|
return wmsedec;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool allocate_buffers(
|
static opj_bool allocate_buffers(
|
||||||
opj_t1_t *t1,
|
opj_t1_t *t1,
|
||||||
int w,
|
int w,
|
||||||
int h)
|
int h)
|
||||||
@@ -1127,7 +1117,7 @@ static bool allocate_buffers(
|
|||||||
opj_aligned_free(t1->data);
|
opj_aligned_free(t1->data);
|
||||||
t1->data = (int*) opj_aligned_malloc(datasize * sizeof(int));
|
t1->data = (int*) opj_aligned_malloc(datasize * sizeof(int));
|
||||||
if(!t1->data){
|
if(!t1->data){
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
t1->datasize=datasize;
|
t1->datasize=datasize;
|
||||||
}
|
}
|
||||||
@@ -1140,7 +1130,7 @@ static bool allocate_buffers(
|
|||||||
opj_aligned_free(t1->flags);
|
opj_aligned_free(t1->flags);
|
||||||
t1->flags = (flag_t*) opj_aligned_malloc(flagssize * sizeof(flag_t));
|
t1->flags = (flag_t*) opj_aligned_malloc(flagssize * sizeof(flag_t));
|
||||||
if(!t1->flags){
|
if(!t1->flags){
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
t1->flagssize=flagssize;
|
t1->flagssize=flagssize;
|
||||||
}
|
}
|
||||||
@@ -1149,7 +1139,7 @@ static bool allocate_buffers(
|
|||||||
t1->w=w;
|
t1->w=w;
|
||||||
t1->h=h;
|
t1->h=h;
|
||||||
|
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** mod fixed_quality */
|
/** mod fixed_quality */
|
||||||
@@ -1425,6 +1415,7 @@ void t1_encode_cblks(
|
|||||||
|
|
||||||
for (bandno = 0; bandno < res->numbands; ++bandno) {
|
for (bandno = 0; bandno < res->numbands; ++bandno) {
|
||||||
opj_tcd_band_t* restrict band = &res->bands[bandno];
|
opj_tcd_band_t* restrict band = &res->bands[bandno];
|
||||||
|
int bandconst = 8192 * 8192 / ((int) floor(band->stepsize * 8192));
|
||||||
|
|
||||||
for (precno = 0; precno < res->pw * res->ph; ++precno) {
|
for (precno = 0; precno < res->pw * res->ph; ++precno) {
|
||||||
opj_tcd_precinct_t *prc = &band->precincts[precno];
|
opj_tcd_precinct_t *prc = &band->precincts[precno];
|
||||||
@@ -1475,7 +1466,7 @@ void t1_encode_cblks(
|
|||||||
datap[(j * cblk_w) + i] =
|
datap[(j * cblk_w) + i] =
|
||||||
fix_mul(
|
fix_mul(
|
||||||
tmp,
|
tmp,
|
||||||
8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (11 - T1_NMSEDEC_FRACBITS);
|
bandconst) >> (11 - T1_NMSEDEC_FRACBITS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1586,6 +1577,7 @@ void t1_decode_cblks(
|
|||||||
opj_free(cblk->segs);
|
opj_free(cblk->segs);
|
||||||
} /* cblkno */
|
} /* cblkno */
|
||||||
opj_free(precinct->cblks.dec);
|
opj_free(precinct->cblks.dec);
|
||||||
|
precinct->cblks.dec = NULL;
|
||||||
} /* precno */
|
} /* precno */
|
||||||
} /* bandno */
|
} /* bandno */
|
||||||
} /* resno */
|
} /* resno */
|
||||||
|
|||||||
@@ -135,8 +135,8 @@ void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
|
|||||||
/**
|
/**
|
||||||
Decode the code-blocks of a tile
|
Decode the code-blocks of a tile
|
||||||
@param t1 T1 handle
|
@param t1 T1 handle
|
||||||
@param tile The tile to decode
|
@param tilec The tile to decode
|
||||||
@param tcp Tile coding parameters
|
@param tccp Tile coding parameters
|
||||||
*/
|
*/
|
||||||
void t1_decode_cblks(opj_t1_t* t1, opj_tcd_tilecomp_t* tilec, opj_tccp_t* tccp);
|
void t1_decode_cblks(opj_t1_t* t1, opj_tcd_tilecomp_t* tilec, opj_tccp_t* tccp);
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
|
|||||||
@@ -59,11 +59,12 @@ Encode a packet of a tile to a destination buffer
|
|||||||
*/
|
*/
|
||||||
static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_codestream_info_t *cstr_info, int tileno);
|
static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_codestream_info_t *cstr_info, int tileno);
|
||||||
/**
|
/**
|
||||||
@param seg
|
@param cblk
|
||||||
|
@param index
|
||||||
@param cblksty
|
@param cblksty
|
||||||
@param first
|
@param first
|
||||||
*/
|
*/
|
||||||
static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first);
|
static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first);
|
||||||
/**
|
/**
|
||||||
Decode a packet of a tile from a source buffer
|
Decode a packet of a tile from a source buffer
|
||||||
@param t2 T2 handle
|
@param t2 T2 handle
|
||||||
@@ -72,6 +73,7 @@ Decode a packet of a tile from a source buffer
|
|||||||
@param tile Tile for which to write the packets
|
@param tile Tile for which to write the packets
|
||||||
@param tcp Tile coding parameters
|
@param tcp Tile coding parameters
|
||||||
@param pi Packet identity
|
@param pi Packet identity
|
||||||
|
@param pack_info Packet information
|
||||||
@return
|
@return
|
||||||
*/
|
*/
|
||||||
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
|
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
|
||||||
@@ -147,8 +149,8 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
|
|||||||
c[1] = 145;
|
c[1] = 145;
|
||||||
c[2] = 0;
|
c[2] = 0;
|
||||||
c[3] = 4;
|
c[3] = 4;
|
||||||
c[4] = (tile->packno % 65536) / 256;
|
c[4] = (unsigned char)((tile->packno % 65536) / 256);
|
||||||
c[5] = (tile->packno % 65536) % 256;
|
c[5] = (unsigned char)((tile->packno % 65536) % 256);
|
||||||
c += 6;
|
c += 6;
|
||||||
}
|
}
|
||||||
/* </SOP> */
|
/* </SOP> */
|
||||||
@@ -253,8 +255,8 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
|
|||||||
/* </EPH> */
|
/* </EPH> */
|
||||||
|
|
||||||
/* << INDEX */
|
/* << INDEX */
|
||||||
// End of packet header position. Currently only represents the distance to start of packet
|
/* End of packet header position. Currently only represents the distance to start of packet
|
||||||
// Will be updated later by incrementing with packet start value
|
// Will be updated later by incrementing with packet start value */
|
||||||
if(cstr_info && cstr_info->index_write) {
|
if(cstr_info && cstr_info->index_write) {
|
||||||
opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno];
|
opj_packet_info_t *info_PK = &cstr_info->tile[tileno].packet[cstr_info->packno];
|
||||||
info_PK->end_ph_pos = (int)(c - dest);
|
info_PK->end_ph_pos = (int)(c - dest);
|
||||||
@@ -294,9 +296,17 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
|
|||||||
return (c - dest);
|
return (c - dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) {
|
static opj_bool t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int first) {
|
||||||
opj_tcd_seg_t* seg;
|
opj_tcd_seg_t* seg;
|
||||||
cblk->segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t));
|
opj_tcd_seg_t* segs;
|
||||||
|
segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, (index + 1) * sizeof(opj_tcd_seg_t));
|
||||||
|
|
||||||
|
if (segs == NULL)
|
||||||
|
{
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
cblk->segs = segs;
|
||||||
|
|
||||||
seg = &cblk->segs[index];
|
seg = &cblk->segs[index];
|
||||||
seg->data = NULL;
|
seg->data = NULL;
|
||||||
seg->dataindex = 0;
|
seg->dataindex = 0;
|
||||||
@@ -314,6 +324,8 @@ static void t2_init_seg(opj_tcd_cblk_dec_t* cblk, int index, int cblksty, int fi
|
|||||||
} else {
|
} else {
|
||||||
seg->maxpasses = 109;
|
seg->maxpasses = 109;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
|
static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile,
|
||||||
@@ -401,8 +413,8 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* << INDEX */
|
/* << INDEX */
|
||||||
// End of packet header position. Currently only represents the distance to start of packet
|
/* End of packet header position. Currently only represents the distance to start of packet
|
||||||
// Will be updated later by incrementing with packet start value
|
// Will be updated later by incrementing with packet start value*/
|
||||||
if(pack_info) {
|
if(pack_info) {
|
||||||
pack_info->end_ph_pos = (int)(c - src);
|
pack_info->end_ph_pos = (int)(c - src);
|
||||||
}
|
}
|
||||||
@@ -460,12 +472,22 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
|||||||
cblk->numlenbits += increment;
|
cblk->numlenbits += increment;
|
||||||
segno = 0;
|
segno = 0;
|
||||||
if (!cblk->numsegs) {
|
if (!cblk->numsegs) {
|
||||||
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1);
|
if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 1))
|
||||||
|
{
|
||||||
|
opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n");
|
||||||
|
bio_destroy(bio);
|
||||||
|
return -999;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
segno = cblk->numsegs - 1;
|
segno = cblk->numsegs - 1;
|
||||||
if (cblk->segs[segno].numpasses == cblk->segs[segno].maxpasses) {
|
if (cblk->segs[segno].numpasses == cblk->segs[segno].maxpasses) {
|
||||||
++segno;
|
++segno;
|
||||||
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
|
if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0))
|
||||||
|
{
|
||||||
|
opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n");
|
||||||
|
bio_destroy(bio);
|
||||||
|
return -999;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n = cblk->numnewpasses;
|
n = cblk->numnewpasses;
|
||||||
@@ -476,7 +498,12 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
|||||||
n -= cblk->segs[segno].numnewpasses;
|
n -= cblk->segs[segno].numnewpasses;
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
++segno;
|
++segno;
|
||||||
t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0);
|
if (!t2_init_seg(cblk, segno, tcp->tccps[compno].cblksty, 0))
|
||||||
|
{
|
||||||
|
opj_event_msg(t2->cinfo, EVT_ERROR, "Out of memory\n");
|
||||||
|
bio_destroy(bio);
|
||||||
|
return -999;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (n > 0);
|
} while (n > 0);
|
||||||
}
|
}
|
||||||
@@ -494,14 +521,15 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
|||||||
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
||||||
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
||||||
opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n");
|
opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n");
|
||||||
|
return -999;
|
||||||
} else {
|
} else {
|
||||||
hd += 2;
|
hd += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* << INDEX */
|
/* << INDEX */
|
||||||
// End of packet header position. Currently only represents the distance to start of packet
|
/* End of packet header position. Currently only represents the distance to start of packet
|
||||||
// Will be updated later by incrementing with packet start value
|
// Will be updated later by incrementing with packet start value*/
|
||||||
if(pack_info) {
|
if(pack_info) {
|
||||||
pack_info->end_ph_pos = (int)(hd - src);
|
pack_info->end_ph_pos = (int)(hd - src);
|
||||||
}
|
}
|
||||||
@@ -565,7 +593,7 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
|||||||
|
|
||||||
#endif /* USE_JPWL */
|
#endif /* USE_JPWL */
|
||||||
|
|
||||||
cblk->data = (unsigned char*) opj_realloc(cblk->data, (cblk->len + seg->newlen) * sizeof(unsigned char*));
|
cblk->data = (unsigned char*) opj_realloc(cblk->data, (cblk->len + seg->newlen) * sizeof(unsigned char));
|
||||||
memcpy(cblk->data + cblk->len, c, seg->newlen);
|
memcpy(cblk->data + cblk->len, c, seg->newlen);
|
||||||
if (seg->numpasses == 0) {
|
if (seg->numpasses == 0) {
|
||||||
seg->data = &cblk->data;
|
seg->data = &cblk->data;
|
||||||
@@ -659,8 +687,8 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
|
|||||||
info_PK->start_pos = ((cp->tp_on | tcp->POC)&& info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1;
|
info_PK->start_pos = ((cp->tp_on | tcp->POC)&& info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1;
|
||||||
}
|
}
|
||||||
info_PK->end_pos = info_PK->start_pos + e - 1;
|
info_PK->end_pos = info_PK->start_pos + e - 1;
|
||||||
info_PK->end_ph_pos += info_PK->start_pos - 1; // End of packet header which now only represents the distance
|
info_PK->end_ph_pos += info_PK->start_pos - 1; /* End of packet header which now only represents the distance
|
||||||
// to start of packet is incremented by value of start of packet
|
// to start of packet is incremented by value of start of packet*/
|
||||||
}
|
}
|
||||||
|
|
||||||
cstr_info->packno++;
|
cstr_info->packno++;
|
||||||
@@ -711,7 +739,11 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
|
|||||||
} else {
|
} else {
|
||||||
e = 0;
|
e = 0;
|
||||||
}
|
}
|
||||||
|
if(e == -999)
|
||||||
|
{
|
||||||
|
pi_destroy(pi, cp, tileno);
|
||||||
|
return -999;
|
||||||
|
}
|
||||||
/* progression in resolution */
|
/* progression in resolution */
|
||||||
image->comps[pi[pino].compno].resno_decoded =
|
image->comps[pi[pino].compno].resno_decoded =
|
||||||
(e > 0) ?
|
(e > 0) ?
|
||||||
@@ -725,8 +757,9 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
|
|||||||
opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->packno];
|
opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->packno];
|
||||||
if (!cstr_info->packno) {
|
if (!cstr_info->packno) {
|
||||||
info_PK->start_pos = info_TL->end_header + 1;
|
info_PK->start_pos = info_TL->end_header + 1;
|
||||||
} else if (info_TL->packet[cstr_info->packno-1].end_pos >= (int)cstr_info->tile[tileno].tp[curtp].tp_end_pos){ // New tile part
|
} else if (info_TL->packet[cstr_info->packno-1].end_pos >= (int)cstr_info->tile[tileno].tp[curtp].tp_end_pos){ /* New tile part*/
|
||||||
info_TL->tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; // Number of packets in previous tile-part
|
info_TL->tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; /* Number of packets in previous tile-part*/
|
||||||
|
info_TL->tp[curtp].tp_start_pack = tp_start_packno;
|
||||||
tp_start_packno = cstr_info->packno;
|
tp_start_packno = cstr_info->packno;
|
||||||
curtp++;
|
curtp++;
|
||||||
info_PK->start_pos = cstr_info->tile[tileno].tp[curtp].tp_end_header+1;
|
info_PK->start_pos = cstr_info->tile[tileno].tp[curtp].tp_end_header+1;
|
||||||
@@ -734,8 +767,8 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
|
|||||||
info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1;
|
info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->packno - 1].end_pos + 1;
|
||||||
}
|
}
|
||||||
info_PK->end_pos = info_PK->start_pos + e - 1;
|
info_PK->end_pos = info_PK->start_pos + e - 1;
|
||||||
info_PK->end_ph_pos += info_PK->start_pos - 1; // End of packet header which now only represents the distance
|
info_PK->end_ph_pos += info_PK->start_pos - 1; /* End of packet header which now only represents the distance
|
||||||
// to start of packet is incremented by value of start of packet
|
// to start of packet is incremented by value of start of packet*/
|
||||||
cstr_info->packno++;
|
cstr_info->packno++;
|
||||||
}
|
}
|
||||||
/* << INDEX */
|
/* << INDEX */
|
||||||
@@ -749,7 +782,8 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
|
|||||||
}
|
}
|
||||||
/* INDEX >> */
|
/* INDEX >> */
|
||||||
if(cstr_info) {
|
if(cstr_info) {
|
||||||
cstr_info->tile[tileno].tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; // Number of packets in last tile-part
|
cstr_info->tile[tileno].tp[curtp].tp_numpacks = cstr_info->packno - tp_start_packno; /* Number of packets in last tile-part*/
|
||||||
|
cstr_info->tile[tileno].tp[curtp].tp_start_pack = tp_start_packno;
|
||||||
}
|
}
|
||||||
/* << INDEX */
|
/* << INDEX */
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ Encode the packets of a tile to a destination buffer
|
|||||||
@param cstr_info Codestream information structure
|
@param cstr_info Codestream information structure
|
||||||
@param tpnum Tile part number of the current tile
|
@param tpnum Tile part number of the current tile
|
||||||
@param tppos The position of the tile part flag in the progression order
|
@param tppos The position of the tile part flag in the progression order
|
||||||
|
@param pino
|
||||||
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
|
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
|
||||||
@param cur_totnum_tp The total number of tile parts in the current tile
|
@param cur_totnum_tp The total number of tile parts in the current tile
|
||||||
*/
|
*/
|
||||||
@@ -78,6 +79,7 @@ Decode the packets of a tile from a source buffer
|
|||||||
@param len length of the source buffer
|
@param len length of the source buffer
|
||||||
@param tileno number that identifies the tile for which to decode the packets
|
@param tileno number that identifies the tile for which to decode the packets
|
||||||
@param tile tile for which to decode the packets
|
@param tile tile for which to decode the packets
|
||||||
|
@param cstr_info Codestream information structure
|
||||||
*/
|
*/
|
||||||
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info);
|
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile, opj_codestream_info_t *cstr_info);
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,11 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _ISOC99_SOURCE /* lrintf is C99 */
|
||||||
#include "opj_includes.h"
|
#include "opj_includes.h"
|
||||||
|
|
||||||
void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) {
|
void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) {
|
||||||
int tileno, compno, resno, bandno, precno;//, cblkno;
|
int tileno, compno, resno, bandno, precno;/*, cblkno;*/
|
||||||
|
|
||||||
fprintf(fd, "image {\n");
|
fprintf(fd, "image {\n");
|
||||||
fprintf(fd, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n",
|
fprintf(fd, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n",
|
||||||
@@ -290,6 +291,7 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
|
|||||||
for (i = 0; i < res->pw * res->ph * 3; i++) {
|
for (i = 0; i < res->pw * res->ph * 3; i++) {
|
||||||
band->precincts[i].imsbtree = NULL;
|
band->precincts[i].imsbtree = NULL;
|
||||||
band->precincts[i].incltree = NULL;
|
band->precincts[i].incltree = NULL;
|
||||||
|
band->precincts[i].cblks.enc = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (precno = 0; precno < res->pw * res->ph; precno++) {
|
for (precno = 0; precno < res->pw * res->ph; precno++) {
|
||||||
@@ -332,8 +334,10 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int c
|
|||||||
cblk->y0 = int_max(cblkystart, prc->y0);
|
cblk->y0 = int_max(cblkystart, prc->y0);
|
||||||
cblk->x1 = int_min(cblkxend, prc->x1);
|
cblk->x1 = int_min(cblkxend, prc->x1);
|
||||||
cblk->y1 = int_min(cblkyend, prc->y1);
|
cblk->y1 = int_min(cblkyend, prc->y1);
|
||||||
cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char));
|
cblk->data = (unsigned char*) opj_calloc(9728+2, sizeof(unsigned char));
|
||||||
/* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */
|
/* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */
|
||||||
|
cblk->data[0] = 0;
|
||||||
|
cblk->data[1] = 0;
|
||||||
cblk->data += 2;
|
cblk->data += 2;
|
||||||
cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
|
cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
|
||||||
cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
|
cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
|
||||||
@@ -593,6 +597,8 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur
|
|||||||
cblk->y1 = int_min(cblkyend, prc->y1);
|
cblk->y1 = int_min(cblkyend, prc->y1);
|
||||||
cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char));
|
cblk->data = (unsigned char*) opj_calloc(8192+2, sizeof(unsigned char));
|
||||||
/* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */
|
/* FIXME: mqc_init_enc and mqc_byteout underrun the buffer if we don't do this. Why? */
|
||||||
|
cblk->data[0] = 0;
|
||||||
|
cblk->data[1] = 0;
|
||||||
cblk->data += 2;
|
cblk->data += 2;
|
||||||
cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
|
cblk->layers = (opj_tcd_layer_t*) opj_calloc(100, sizeof(opj_tcd_layer_t));
|
||||||
cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
|
cblk->passes = (opj_tcd_pass_t*) opj_calloc(100, sizeof(opj_tcd_pass_t));
|
||||||
@@ -613,7 +619,7 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
|
|||||||
tcd->image = image;
|
tcd->image = image;
|
||||||
tcd->tcd_image->tw = cp->tw;
|
tcd->tcd_image->tw = cp->tw;
|
||||||
tcd->tcd_image->th = cp->th;
|
tcd->tcd_image->th = cp->th;
|
||||||
tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tcd_tile_t));
|
tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_calloc(cp->tw * cp->th, sizeof(opj_tcd_tile_t));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Allocate place to store the decoded data = final image
|
Allocate place to store the decoded data = final image
|
||||||
@@ -656,7 +662,7 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
|
|||||||
tilec->y1 = int_ceildiv(tile->y1, image->comps[i].dy);
|
tilec->y1 = int_ceildiv(tile->y1, image->comps[i].dy);
|
||||||
|
|
||||||
x0 = j == 0 ? tilec->x0 : int_min(x0, (unsigned int) tilec->x0);
|
x0 = j == 0 ? tilec->x0 : int_min(x0, (unsigned int) tilec->x0);
|
||||||
y0 = j == 0 ? tilec->y0 : int_min(y0, (unsigned int) tilec->x0);
|
y0 = j == 0 ? tilec->y0 : int_min(y0, (unsigned int) tilec->y0);
|
||||||
x1 = j == 0 ? tilec->x1 : int_max(x1, (unsigned int) tilec->x1);
|
x1 = j == 0 ? tilec->x1 : int_max(x1, (unsigned int) tilec->x1);
|
||||||
y1 = j == 0 ? tilec->y1 : int_max(y1, (unsigned int) tilec->y1);
|
y1 = j == 0 ? tilec->y1 : int_max(y1, (unsigned int) tilec->y1);
|
||||||
}
|
}
|
||||||
@@ -676,6 +682,8 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
|
|||||||
opj_tcp_t *tcp;
|
opj_tcp_t *tcp;
|
||||||
opj_tcd_tile_t *tile;
|
opj_tcd_tile_t *tile;
|
||||||
|
|
||||||
|
OPJ_ARG_NOT_USED(cstr_info);
|
||||||
|
|
||||||
tcd->cp = cp;
|
tcd->cp = cp;
|
||||||
|
|
||||||
tcp = &(cp->tcps[cp->tileno[tileno]]);
|
tcp = &(cp->tcps[cp->tileno[tileno]]);
|
||||||
@@ -687,6 +695,12 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
|
|||||||
opj_tccp_t *tccp = &tcp->tccps[compno];
|
opj_tccp_t *tccp = &tcp->tccps[compno];
|
||||||
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
|
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||||
|
|
||||||
|
if (tccp->numresolutions <= 0)
|
||||||
|
{
|
||||||
|
cp->tileno[tileno] = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* border of each tile component (global) */
|
/* border of each tile component (global) */
|
||||||
tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx);
|
tilec->x0 = int_ceildiv(tile->x0, image->comps[compno].dx);
|
||||||
tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy);
|
tilec->y0 = int_ceildiv(tile->y0, image->comps[compno].dy);
|
||||||
@@ -997,7 +1011,7 @@ void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
|
opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
|
||||||
int compno, resno, bandno, precno, cblkno, passno, layno;
|
int compno, resno, bandno, precno, cblkno, passno, layno;
|
||||||
double min, max;
|
double min, max;
|
||||||
double cumdisto[100]; /* fixed_quality */
|
double cumdisto[100]; /* fixed_quality */
|
||||||
@@ -1149,7 +1163,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestre
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cstr_info) { /* Threshold for Marcela Index */
|
if(cstr_info) { /* Threshold for Marcela Index */
|
||||||
@@ -1161,7 +1175,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestre
|
|||||||
cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]);
|
cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
|
int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
|
||||||
@@ -1313,7 +1327,7 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info) {
|
opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info) {
|
||||||
int l;
|
int l;
|
||||||
int compno;
|
int compno;
|
||||||
int eof = 0;
|
int eof = 0;
|
||||||
@@ -1349,7 +1363,7 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cstr_info->tile[tileno].pdx[resno] = 15;
|
cstr_info->tile[tileno].pdx[resno] = 15;
|
||||||
cstr_info->tile[tileno].pdx[resno] = 15;
|
cstr_info->tile[tileno].pdy[resno] = 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1373,14 +1387,24 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
|
|
||||||
t1_time = opj_clock(); /* time needed to decode a tile */
|
t1_time = opj_clock(); /* time needed to decode a tile */
|
||||||
t1 = t1_create(tcd->cinfo);
|
t1 = t1_create(tcd->cinfo);
|
||||||
|
if (t1 == NULL)
|
||||||
|
{
|
||||||
|
opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n");
|
||||||
|
t1_destroy(t1);
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
for (compno = 0; compno < tile->numcomps; ++compno) {
|
for (compno = 0; compno < tile->numcomps; ++compno) {
|
||||||
opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
|
opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
|
||||||
/* The +3 is headroom required by the vectorized DWT */
|
/* The +3 is headroom required by the vectorized DWT */
|
||||||
tilec->data = (int*) opj_aligned_malloc((((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0))+3) * sizeof(int));
|
tilec->data = (int*) opj_aligned_malloc((((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0))+3) * sizeof(int));
|
||||||
if(tilec->data)
|
if (tilec->data == NULL)
|
||||||
t1_decode_cblks(t1, tilec, &tcd->tcp->tccps[compno]);
|
{
|
||||||
else
|
opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n");
|
||||||
opj_event_msg(tcd->cinfo, EVT_ERROR, "tcd_decode: tile size invalid\n");
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
t1_decode_cblks(t1, tilec, &tcd->tcp->tccps[compno]);
|
||||||
}
|
}
|
||||||
t1_destroy(t1);
|
t1_destroy(t1);
|
||||||
t1_time = opj_clock() - t1_time;
|
t1_time = opj_clock() - t1_time;
|
||||||
@@ -1394,18 +1418,15 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
int numres2decode;
|
int numres2decode;
|
||||||
|
|
||||||
if (tcd->cp->reduce != 0) {
|
if (tcd->cp->reduce != 0) {
|
||||||
tcd->image->comps[compno].resno_decoded =
|
if ( tile->comps[compno].numresolutions < ( tcd->cp->reduce - 1 ) ) {
|
||||||
tile->comps[compno].numresolutions - tcd->cp->reduce - 1;
|
|
||||||
if (tcd->image->comps[compno].resno_decoded < 0) {
|
|
||||||
opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. The number of resolutions to remove [%d+1] is higher than the number "
|
opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. The number of resolutions to remove [%d+1] is higher than the number "
|
||||||
" of resolutions in the original codestream [%d]\nModify the cp_reduce parameter.\n", tcd->cp->reduce, tile->comps[compno].numresolutions);
|
" of resolutions in the original codestream [%d]\nModify the cp_reduce parameter.\n", tcd->cp->reduce, tile->comps[compno].numresolutions);
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
tcd->image->comps[compno].resno_decoded =
|
||||||
if(!tilec->data) {
|
tile->comps[compno].numresolutions - tcd->cp->reduce - 1;
|
||||||
opj_event_msg(tcd->cinfo, EVT_ERROR, "Error decoding tile. null data\n");
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
numres2decode = tcd->image->comps[compno].resno_decoded + 1;
|
numres2decode = tcd->image->comps[compno].resno_decoded + 1;
|
||||||
@@ -1424,18 +1445,23 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
|
|
||||||
if (tcd->tcp->mct) {
|
if (tcd->tcp->mct) {
|
||||||
int n = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0);
|
int n = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0);
|
||||||
if (tcd->tcp->tccps[0].qmfbid == 1) {
|
|
||||||
mct_decode(
|
if (tile->numcomps >= 3 ){
|
||||||
tile->comps[0].data,
|
if (tcd->tcp->tccps[0].qmfbid == 1) {
|
||||||
tile->comps[1].data,
|
mct_decode(
|
||||||
tile->comps[2].data,
|
tile->comps[0].data,
|
||||||
n);
|
tile->comps[1].data,
|
||||||
} else {
|
tile->comps[2].data,
|
||||||
mct_decode_real(
|
n);
|
||||||
(float*)tile->comps[0].data,
|
} else {
|
||||||
(float*)tile->comps[1].data,
|
mct_decode_real(
|
||||||
(float*)tile->comps[2].data,
|
(float*)tile->comps[0].data,
|
||||||
n);
|
(float*)tile->comps[1].data,
|
||||||
|
(float*)tile->comps[2].data,
|
||||||
|
n);
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
opj_event_msg(tcd->cinfo, EVT_WARNING,"Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",tile->numcomps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1459,6 +1485,11 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
if(!imagec->data){
|
if(!imagec->data){
|
||||||
imagec->data = (int*) opj_malloc(imagec->w * imagec->h * sizeof(int));
|
imagec->data = (int*) opj_malloc(imagec->w * imagec->h * sizeof(int));
|
||||||
}
|
}
|
||||||
|
if (!imagec->data)
|
||||||
|
{
|
||||||
|
opj_event_msg(tcd->cinfo, EVT_ERROR, "Out of memory\n");
|
||||||
|
return OPJ_FALSE;
|
||||||
|
}
|
||||||
if(tcd->tcp->tccps[compno].qmfbid == 1) {
|
if(tcd->tcp->tccps[compno].qmfbid == 1) {
|
||||||
for(j = res->y0; j < res->y1; ++j) {
|
for(j = res->y0; j < res->y1; ++j) {
|
||||||
for(i = res->x0; i < res->x1; ++i) {
|
for(i = res->x0; i < res->x1; ++i) {
|
||||||
@@ -1484,40 +1515,59 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, op
|
|||||||
opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time);
|
opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time);
|
||||||
|
|
||||||
if (eof) {
|
if (eof) {
|
||||||
return false;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tcd_free_decode(opj_tcd_t *tcd) {
|
void tcd_free_decode(opj_tcd_t *tcd) {
|
||||||
opj_tcd_image_t *tcd_image = tcd->tcd_image;
|
opj_tcd_image_t *tcd_image = tcd->tcd_image;
|
||||||
|
int i = 0;
|
||||||
|
for (i = 0; i < tcd_image->tw * tcd_image->th; i++)
|
||||||
|
{
|
||||||
|
tcd_free_decode_tile(tcd, i);
|
||||||
|
}
|
||||||
|
|
||||||
opj_free(tcd_image->tiles);
|
opj_free(tcd_image->tiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) {
|
void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) {
|
||||||
int compno,resno,bandno,precno;
|
int compno,resno,bandno,precno,cblkno;
|
||||||
|
|
||||||
opj_tcd_image_t *tcd_image = tcd->tcd_image;
|
opj_tcd_image_t *tcd_image = tcd->tcd_image;
|
||||||
|
|
||||||
opj_tcd_tile_t *tile = &tcd_image->tiles[tileno];
|
opj_tcd_tile_t *tile = &tcd_image->tiles[tileno];
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
if (tile->comps != NULL) {
|
||||||
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
for (resno = 0; resno < tilec->numresolutions; resno++) {
|
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||||
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
|
for (resno = 0; resno < tilec->numresolutions; resno++) {
|
||||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
|
||||||
opj_tcd_band_t *band = &res->bands[bandno];
|
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||||
for (precno = 0; precno < res->ph * res->pw; precno++) {
|
opj_tcd_band_t *band = &res->bands[bandno];
|
||||||
opj_tcd_precinct_t *prec = &band->precincts[precno];
|
for (precno = 0; precno < res->ph * res->pw; precno++) {
|
||||||
if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree);
|
opj_tcd_precinct_t *prec = &band->precincts[precno];
|
||||||
if (prec->incltree != NULL) tgt_destroy(prec->incltree);
|
if (prec->cblks.dec != NULL) {
|
||||||
|
for (cblkno = 0; cblkno < prec->cw * prec->ch; ++cblkno) {
|
||||||
|
opj_tcd_cblk_dec_t* cblk = &prec->cblks.dec[cblkno];
|
||||||
|
opj_free(cblk->data);
|
||||||
|
opj_free(cblk->segs);
|
||||||
|
}
|
||||||
|
opj_free(prec->cblks.dec);
|
||||||
|
}
|
||||||
|
if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree);
|
||||||
|
if (prec->incltree != NULL) tgt_destroy(prec->incltree);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
opj_free(band->precincts);
|
||||||
}
|
}
|
||||||
opj_free(band->precincts);
|
|
||||||
}
|
}
|
||||||
|
opj_free(tilec->resolutions);
|
||||||
}
|
}
|
||||||
opj_free(tilec->resolutions);
|
opj_free(tile->comps);
|
||||||
|
tile->comps = NULL;
|
||||||
}
|
}
|
||||||
opj_free(tile->comps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
|
|||||||
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
|
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
|
||||||
void tcd_rateallocate_fixed(opj_tcd_t *tcd);
|
void tcd_rateallocate_fixed(opj_tcd_t *tcd);
|
||||||
void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
|
void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
|
||||||
bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
|
opj_bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
|
||||||
/**
|
/**
|
||||||
Encode a tile from the raw image into a buffer
|
Encode a tile from the raw image into a buffer
|
||||||
@param tcd TCD handle
|
@param tcd TCD handle
|
||||||
@@ -268,8 +268,9 @@ Decode a tile from a buffer into a raw image
|
|||||||
@param src Source buffer
|
@param src Source buffer
|
||||||
@param len Length of source buffer
|
@param len Length of source buffer
|
||||||
@param tileno Number that identifies one of the tiles to be decoded
|
@param tileno Number that identifies one of the tiles to be decoded
|
||||||
|
@param cstr_info Codestream information structure
|
||||||
*/
|
*/
|
||||||
bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info);
|
opj_bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno, opj_codestream_info_t *cstr_info);
|
||||||
/**
|
/**
|
||||||
Free the memory allocated for decoding
|
Free the memory allocated for decoding
|
||||||
@param tcd TCD handle
|
@param tcd TCD handle
|
||||||
|
|||||||
120
indra/libopenjpeg/thix_manager.c
Normal file
120
indra/libopenjpeg/thix_manager.c
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* $Id: thix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||||
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||||
|
* Copyright (c) 2003-2004, Yannick Verschueren
|
||||||
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \file
|
||||||
|
* \brief Modification of jpip.c from 2KAN indexer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "opj_includes.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write tile-part headers mhix box
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @param[in] tileno tile number
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return length of mhix box
|
||||||
|
*/
|
||||||
|
int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio);
|
||||||
|
|
||||||
|
int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int len, lenp, i;
|
||||||
|
int tileno;
|
||||||
|
opj_jp2_box_t *box;
|
||||||
|
|
||||||
|
lenp = 0;
|
||||||
|
box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t));
|
||||||
|
|
||||||
|
for ( i = 0; i < 2 ; i++ ){
|
||||||
|
if (i)
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_THIX, 4); /* THIX */
|
||||||
|
write_manf( i, cstr_info.tw*cstr_info.th, box, cio);
|
||||||
|
|
||||||
|
for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){
|
||||||
|
box[tileno].length = write_tilemhix( coff, cstr_info, tileno, cio);
|
||||||
|
box[tileno].type = JPIP_MHIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
}
|
||||||
|
|
||||||
|
opj_free(box);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
opj_tile_info_t tile;
|
||||||
|
opj_tp_info_t tp;
|
||||||
|
int len, lenp;
|
||||||
|
opj_marker_info_t *marker;
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_MHIX, 4); /* MHIX */
|
||||||
|
|
||||||
|
tile = cstr_info.tile[tileno];
|
||||||
|
tp = tile.tp[0];
|
||||||
|
|
||||||
|
cio_write( cio, tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */
|
||||||
|
|
||||||
|
marker = cstr_info.tile[tileno].marker;
|
||||||
|
|
||||||
|
for( i=0; i<cstr_info.tile[tileno].marknum; i++){ /* Marker restricted to 1 apparition */
|
||||||
|
cio_write( cio, marker[i].type, 2);
|
||||||
|
cio_write( cio, 0, 2);
|
||||||
|
cio_write( cio, marker[i].pos-coff, 8);
|
||||||
|
cio_write( cio, marker[i].len, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free( marker);*/
|
||||||
|
|
||||||
|
len = cio_tell( cio) - lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
153
indra/libopenjpeg/tpix_manager.c
Normal file
153
indra/libopenjpeg/tpix_manager.c
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
/*
|
||||||
|
* $Id: tpix_manager.c 897 2011-08-28 21:43:57Z Kaori.Hagihara@gmail.com $
|
||||||
|
*
|
||||||
|
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||||
|
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||||
|
* Copyright (c) 2003-2004, Yannick Verschueren
|
||||||
|
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \file
|
||||||
|
* \brief Modification of jpip.c from 2KAN indexer
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include "opj_includes.h"
|
||||||
|
|
||||||
|
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write faix box of tpix
|
||||||
|
*
|
||||||
|
* @param[in] coff offset of j2k codestream
|
||||||
|
* @param[in] compno component number
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @param[in] j2klen length of j2k codestream
|
||||||
|
* @param[in] cio file output handle
|
||||||
|
* @return length of faix box
|
||||||
|
*/
|
||||||
|
int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio);
|
||||||
|
|
||||||
|
|
||||||
|
int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int len, lenp;
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_TPIX, 4); /* TPIX */
|
||||||
|
|
||||||
|
write_tpixfaix( coff, 0, cstr_info, j2klen, cio);
|
||||||
|
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get number of maximum tile parts per tile
|
||||||
|
*
|
||||||
|
* @param[in] cstr_info codestream information
|
||||||
|
* @return number of maximum tile parts per tile
|
||||||
|
*/
|
||||||
|
int get_num_max_tile_parts( opj_codestream_info_t cstr_info);
|
||||||
|
|
||||||
|
int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio)
|
||||||
|
{
|
||||||
|
int len, lenp;
|
||||||
|
int i, j;
|
||||||
|
int Aux;
|
||||||
|
int num_max_tile_parts;
|
||||||
|
int size_of_coding; /* 4 or 8 */
|
||||||
|
opj_tp_info_t tp;
|
||||||
|
int version;
|
||||||
|
|
||||||
|
num_max_tile_parts = get_num_max_tile_parts( cstr_info);
|
||||||
|
|
||||||
|
if( j2klen > pow( 2, 32)){
|
||||||
|
size_of_coding = 8;
|
||||||
|
version = num_max_tile_parts == 1 ? 1:3;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
size_of_coding = 4;
|
||||||
|
version = num_max_tile_parts == 1 ? 0:2;
|
||||||
|
}
|
||||||
|
|
||||||
|
lenp = cio_tell( cio);
|
||||||
|
cio_skip( cio, 4); /* L [at the end] */
|
||||||
|
cio_write( cio, JPIP_FAIX, 4); /* FAIX */
|
||||||
|
cio_write( cio, version, 1); /* Version 0 = 4 bytes */
|
||||||
|
|
||||||
|
cio_write( cio, num_max_tile_parts, size_of_coding); /* NMAX */
|
||||||
|
cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
|
||||||
|
for (i = 0; i < cstr_info.tw*cstr_info.th; i++){
|
||||||
|
for (j = 0; j < cstr_info.tile[i].num_tps; j++){
|
||||||
|
tp = cstr_info.tile[i].tp[j];
|
||||||
|
cio_write( cio, tp.tp_start_pos-coff, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, tp.tp_end_pos-tp.tp_start_pos+1, size_of_coding); /* length */
|
||||||
|
if (version & 0x02){
|
||||||
|
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
|
||||||
|
Aux = cstr_info.numdecompos[compno] + 1;
|
||||||
|
else
|
||||||
|
Aux = j + 1;
|
||||||
|
|
||||||
|
cio_write( cio, Aux,4);
|
||||||
|
/*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
|
||||||
|
/* fprintf(stderr,"AUX value %d\n",Aux);*/
|
||||||
|
}
|
||||||
|
/*cio_write(0,4);*/
|
||||||
|
}
|
||||||
|
/* PADDING */
|
||||||
|
while (j < num_max_tile_parts){
|
||||||
|
cio_write( cio, 0, size_of_coding); /* start position */
|
||||||
|
cio_write( cio, 0, size_of_coding); /* length */
|
||||||
|
if (version & 0x02)
|
||||||
|
cio_write( cio, 0,4); /* Aux_i,j : Auxiliary value */
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len = cio_tell( cio)-lenp;
|
||||||
|
cio_seek( cio, lenp);
|
||||||
|
cio_write( cio, len, 4); /* L */
|
||||||
|
cio_seek( cio, lenp+len);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_num_max_tile_parts( opj_codestream_info_t cstr_info)
|
||||||
|
{
|
||||||
|
int num_max_tp = 0, i;
|
||||||
|
|
||||||
|
for( i=0; i<cstr_info.tw*cstr_info.th; i++)
|
||||||
|
num_max_tp = MAX( cstr_info.tile[i].num_tps, num_max_tp);
|
||||||
|
|
||||||
|
return num_max_tp;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/**
|
||||||
* @file llimagej2coj.cpp
|
* @file llimagej2coj.cpp
|
||||||
* @brief This is an implementation of JPEG2000 encode/decode using OpenJPEG.
|
* @brief This is an implementation of JPEG2000 encode/decode using OpenJPEG.
|
||||||
*
|
*
|
||||||
@@ -35,9 +35,7 @@
|
|||||||
|
|
||||||
const char* fallbackEngineInfoLLImageJ2CImpl()
|
const char* fallbackEngineInfoLLImageJ2CImpl()
|
||||||
{
|
{
|
||||||
static std::string version_string =
|
static std::string version_string = std::string("OpenJPEG: ") + opj_version();
|
||||||
std::string("OpenJPEG: " OPENJPEG_VERSION ", Runtime: ")
|
|
||||||
+ opj_version();
|
|
||||||
return version_string.c_str();
|
return version_string.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +184,15 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
|
|||||||
{
|
{
|
||||||
opj_image_destroy(image);
|
opj_image_destroy(image);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
std::stringstream filename;
|
||||||
|
filename << "err" << (int)base.getRawDiscardLevel() << "_" << rand() << ".jp2";
|
||||||
|
FILE* file = fopen(filename.str().c_str(), "wb");
|
||||||
|
if (file) {
|
||||||
|
fwrite(base.getData(), base.getDataSize(), 1, file);
|
||||||
|
fclose(file);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
base.decodeFailed();
|
base.decodeFailed();
|
||||||
return TRUE; // done
|
return TRUE; // done
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -873,7 +873,7 @@ BOOL LLTextureCache::isInLocal(const LLUUID& id)
|
|||||||
|
|
||||||
//static
|
//static
|
||||||
const S32 MAX_REASONABLE_FILE_SIZE = 512*1024*1024; // 512 MB
|
const S32 MAX_REASONABLE_FILE_SIZE = 512*1024*1024; // 512 MB
|
||||||
F32 LLTextureCache::sHeaderCacheVersion = 1.7f;
|
F32 LLTextureCache::sHeaderCacheVersion = 1.8f;
|
||||||
U32 LLTextureCache::sCacheMaxEntries = MAX_REASONABLE_FILE_SIZE / TEXTURE_CACHE_ENTRY_SIZE;
|
U32 LLTextureCache::sCacheMaxEntries = MAX_REASONABLE_FILE_SIZE / TEXTURE_CACHE_ENTRY_SIZE;
|
||||||
S64 LLTextureCache::sCacheMaxTexturesSize = 0; // no limit
|
S64 LLTextureCache::sCacheMaxTexturesSize = 0; // no limit
|
||||||
const char* entries_filename = "texture.entries";
|
const char* entries_filename = "texture.entries";
|
||||||
|
|||||||
@@ -1282,7 +1282,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
|
|||||||
{
|
{
|
||||||
//NOTE:
|
//NOTE:
|
||||||
//control the number of the http requests issued for:
|
//control the number of the http requests issued for:
|
||||||
//1, not openning too many file descriptors at the same time;
|
//1, not opening too many file descriptors at the same time;
|
||||||
//2, control the traffic of http so udp gets bandwidth.
|
//2, control the traffic of http so udp gets bandwidth.
|
||||||
//
|
//
|
||||||
static const LLCachedControl<U32> max_http_requests("HTTPMaxRequests", 32);
|
static const LLCachedControl<U32> max_http_requests("HTTPMaxRequests", 32);
|
||||||
|
|||||||
Reference in New Issue
Block a user