reorganization of indexer before importing extentional libopenjpeg files

This commit is contained in:
Kaori Hagihara 2011-08-28 21:43:57 +00:00
parent 13c5f806c6
commit 0c65d2cc0c
15 changed files with 388 additions and 285 deletions

View File

@ -1,14 +1,15 @@
INCDIR = ../../../../libopenjpeg INCDIR = ../../../../libopenjpeg
INCDIR2 = ext_libopenjpeg
LIBDIR = $(INCDIR)/.libs LIBDIR = $(INCDIR)/.libs
LIBFNAME = $(LIBDIR)/libopenjpeg.a LIBFNAME = $(LIBDIR)/libopenjpeg.a
CFLAGS = -O3 -Wall -I$(INCDIR) CFLAGS = -O3 -Wall -I$(INCDIR) -I$(INCDIR2)
LDFLAGS = -L$(LIBDIR) -lm LDFLAGS = -L$(LIBDIR) -lm
ALL = j2k_to_idxjp2 ALL = j2k_to_idxjp2
all: $(ALL) all: $(ALL)
j2k_to_idxjp2: j2k_to_idxjp2.o event_mgr_handler.o idxjp2_manager.o j2k_decoder.o cidx_manager.o cio_ext.o tpix_manager.o thix_manager.o ppix_manager.o phix_manager.o $(LIBFNAME) j2k_to_idxjp2: j2k_to_idxjp2.o event_mgr_handler.o idxjp2_manager.o j2k_decoder.o $(INCDIR2)/cidx_manager.o $(INCDIR2)/cio_ext.o $(INCDIR2)/ext_j2k.o $(INCDIR2)/ext_jp2.o $(INCDIR2)/phix_manager.o $(INCDIR2)/ppix_manager.o $(INCDIR2)/thix_manager.o $(INCDIR2)/tpix_manager.o $(LIBFNAME)
$(CC) $(CFLAGS) $< event_mgr_handler.o idxjp2_manager.o j2k_decoder.o cidx_manager.o cio_ext.o tpix_manager.o thix_manager.o ppix_manager.o phix_manager.o $(LDFLAGS) $(LIBFNAME) -o $@ $(CC) $(CFLAGS) $< event_mgr_handler.o idxjp2_manager.o j2k_decoder.o $(INCDIR2)/cidx_manager.o $(INCDIR2)/cio_ext.o $(INCDIR2)/ext_j2k.o $(INCDIR2)/ext_jp2.o $(INCDIR2)/phix_manager.o $(INCDIR2)/ppix_manager.o $(INCDIR2)/thix_manager.o $(INCDIR2)/tpix_manager.o $(LDFLAGS) $(LIBFNAME) -o $@
clean: clean:
rm -f $(ALL) *.o *~ rm -f $(ALL) *.o *~

View File

@ -38,6 +38,7 @@
/* /*
* Write a byte. * Write a byte.
* A copy of cio.c:opj_bool cio_byteout(opj_cio_t *cio, unsigned char v)
*/ */
opj_bool cio_ext_byteout(opj_cio_t *cio, unsigned char v); opj_bool cio_ext_byteout(opj_cio_t *cio, unsigned char v);

View File

@ -0,0 +1,95 @@
/*
* $Id$
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include "ext_openjpeg.h"
#include "cio.h"
#include "j2k.h"
/*
* Get main headr marker size
*
* @param[in] type marker type
* @param[in] cstr_info codestream information
* @param[in] cio file input handle
* @return marker size
*/
unsigned short get_mh_markersize( unsigned short type, opj_codestream_info_t cstr_info, opj_cio_t *cio);
void add_mainheader_marker_info( opj_cio_t *cio, opj_codestream_info_t *cstr_info)
{
opj_marker_info_t marker;
int pos;
cstr_info->marker = (opj_marker_info_t *)malloc( 100*sizeof(opj_marker_info_t)); // max 100
pos = cstr_info->main_head_start;
cio_seek( cio, pos);
while( pos <= cstr_info->main_head_end){
marker.type = cio_read( cio, 2);
marker.pos = cio_tell( cio);
marker.len = get_mh_markersize( marker.type, *cstr_info, cio);
cio_skip( cio, marker.len);
cstr_info->marker[ cstr_info->marknum] = marker;
cstr_info->marknum++;
pos = cio_tell( cio);
}
}
unsigned short get_mh_markersize( unsigned short type, opj_codestream_info_t cstr_info, opj_cio_t *cio)
{
unsigned short siz;
int pos;
siz = 0;
switch( type){
case J2K_MS_SOC:
siz = 0;
break;
case J2K_MS_SIZ:
siz = 38+3*cstr_info.numcomps;
break;
case J2K_MS_COD:
case J2K_MS_QCD:
case J2K_MS_COM:
pos = cio_tell( cio);
siz = cio_read( cio, 2);
cio_seek( cio, pos);
break;
default:
fprintf( stderr, "marker %x length not defined yet!\n", type);
}
return siz;
}

View File

@ -0,0 +1,226 @@
/*
* $Id$
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "ext_openjpeg.h"
#include "cio.h"
#include "cio_ext.h"
#include "cidx_manager.h"
#include "indexbox_manager.h"
/*
* Write JP box
* copy from jp2.c
*
* @param[in] cio file output handler
*/
void jp2_write_jp(opj_cio_t *cio);
/*
* Write FTYP box - File type box
* copy from jp2.c
*
* @param[in] jp2 JP2 handle
* @param[in] cio file output handle
*/
void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
/*
* Write file Index (superbox)
*
* @param[in] offset_jp2c offset of jp2c box
* @param[in] length_jp2c length of jp2c box
* @param[in] offset_idx offset of cidx box
* @param[in] length_idx length of cidx box
* @param[in] cio file output handle
* @return length of fidx box
*/
int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio);
/*
* Write index Finder box
*
* @param[in] offset offset of fidx box
* @param[in] length length of fidx box
* @param[in] cio file output handle
*/
void write_iptr( int offset, int length, opj_cio_t *cio);
opj_bool idxjp2_encode( opj_cinfo_t *cinfo, opj_cio_t *cio, unsigned char *j2kstream, int j2klen, opj_codestream_info_t cstr_info, opj_image_t *image)
{
opj_jp2_t *jp2;
int pos_iptr, pos_cidx, pos_jp2c, end_pos, pos_fidx, len_fidx;
int i;
jp2 = cinfo->jp2_handle;
/* JP2 encoding */
/* JPEG 2000 Signature box */
jp2_write_jp(cio);
/* File Type box */
jp2_write_ftyp(jp2, cio);
/* JP2 Header box */
jp2_write_jp2h(jp2, cio);
pos_iptr = cio_tell( cio);
cio_skip( cio, 24); /* IPTR further ! */
pos_jp2c = cio_tell( cio);
cio_write( cio, j2klen+8, 4); // L NOTICE: modify for the extended box
cio_write( cio, JP2_JP2C, 4); // JP2C
for( i=0; i<j2klen; i++)
cio_write( cio, j2kstream[i], 1);
pos_cidx = cio_tell( cio);
write_cidx( pos_jp2c+8, cio, image, cstr_info, j2klen);
pos_fidx = cio_tell( cio);
len_fidx = write_fidx( pos_jp2c, pos_cidx-pos_jp2c, pos_cidx, cio_tell(cio), cio);
end_pos = cio_tell( cio);
cio_seek( cio, pos_iptr);
write_iptr( pos_fidx, len_fidx, cio);
cio_seek( cio, end_pos);
return OPJ_TRUE;
}
void jp2_write_jp( opj_cio_t *cio)
{
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_JP, 4); /* JP2 signature */
cio_write(cio, 0x0d0a870a, 4);
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio)
{
unsigned int i;
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_FTYP, 4); /* FTYP */
cio_write(cio, jp2->brand, 4); /* BR */
cio_write(cio, jp2->minversion, 4); /* MinV */
for (i = 0; i < jp2->numcl; i++) {
cio_write(cio, jp2->cl[i], 4); /* CL */
}
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
/*
* Write proxy box
*
* @param[in] offset_jp2c offset of jp2c box
* @param[in] length_jp2c length of jp2c box
* @param[in] offset_idx offset of cidx box
* @param[in] length_idx length of cidx box
* @param[in] cio file output handle
*/
void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio);
int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio)
{
int len, lenp;
lenp = cio_tell( cio);
cio_skip( cio, 4); /* L [at the end] */
cio_write( cio, JPIP_FIDX, 4); /* IPTR */
write_prxy( offset_jp2c, length_jp2c, offset_idx, offset_jp2c, cio);
len = cio_tell( cio)-lenp;
cio_seek( cio, lenp);
cio_write( cio, len, 4); /* L */
cio_seek( cio, lenp+len);
return len;
}
void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio)
{
int len, lenp;
lenp = cio_tell( cio);
cio_skip( cio, 4); /* L [at the end] */
cio_write( cio, JPIP_PRXY, 4); /* IPTR */
cio_ext_write( cio, offset_jp2c, 8); /* OOFF */
cio_write( cio, length_jp2c, 4); /* OBH part 1 */
cio_write( cio, JP2_JP2C, 4); /* OBH part 2 */
cio_write( cio, 1,1); /* NI */
cio_ext_write( cio, offset_idx, 8); /* IOFF */
cio_write( cio, length_idx, 4); /* IBH part 1 */
cio_write( cio, JPIP_CIDX, 4); /* IBH part 2 */
len = cio_tell( cio)-lenp;
cio_seek( cio, lenp);
cio_write( cio, len, 4); /* L */
cio_seek( cio, lenp+len);
}
void write_iptr( int offset, int length, opj_cio_t *cio)
{
int len, lenp;
lenp = cio_tell( cio);
cio_skip( cio, 4); /* L [at the end] */
cio_write( cio, JPIP_IPTR, 4); /* IPTR */
cio_ext_write( cio, offset, 8);
cio_ext_write( cio, length, 8);
len = cio_tell( cio)-lenp;
cio_seek( cio, lenp);
cio_write( cio, len, 4); /* L */
cio_seek( cio, lenp+len);
}

View File

@ -0,0 +1,57 @@
/*
* $Id$
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2011, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef EXT_OPENJPEG_H_
# define EXT_OPENJPEG_H_
#include "openjpeg.h"
/*
* Decode and Add main header marker information
*
* @param[in] cio file input handle
* @param[in,out] cstr_info codestream information
*/
void add_mainheader_marker_info( opj_cio_t *cio, opj_codestream_info_t *cstr_info);
/*
* Encode JP2 stream with index box
*
* @param[in] cinfo codestream information
* @param[in] cio file output handle
* @param[in] j2kstream j2k codestream
* @param[in] j2klen length of j2k codestream
* @param[in] cstr_info codestream information
* @param[in] image image data
* @return true if succeed
*/
opj_bool idxjp2_encode( opj_cinfo_t *cinfo, opj_cio_t *cio, unsigned char *j2kstream, int j2klen, opj_codestream_info_t cstr_info, opj_image_t *image);
#endif /* !EXT_OPENJPEGS_H_ */

View File

@ -38,27 +38,9 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include "ext_openjpeg.h"
#include <stdlib.h>
#include "event_mgr_handler.h"
#include "cio.h"
#include "cio_ext.h"
#include "j2k_to_idxjp2.h" #include "j2k_to_idxjp2.h"
#include "cidx_manager.h" #include "event_mgr_handler.h"
#include "indexbox_manager.h"
/*
* Encode JP2 stream with index box
*
* @param[in] jp2 jp2 handle
* @param[in] cio file output handle
* @param[in] j2kstream j2k codestream
* @param[in] j2klen length of j2k codestream
* @param[in] cstr_info codestream information
* @param[in] image image data
* @return true if succeed
*/
opj_bool idxjp2_encode( opj_jp2_t *jp2, opj_cio_t *cio, unsigned char *j2kstream, int j2klen, opj_codestream_info_t cstr_info, opj_image_t *image);
void fwrite_idxjp2( char filename[], unsigned char *j2kstream, int j2klen, opj_image_t *image, opj_codestream_info_t cstr_info) void fwrite_idxjp2( char filename[], unsigned char *j2kstream, int j2klen, opj_image_t *image, opj_codestream_info_t cstr_info)
@ -89,7 +71,7 @@ void fwrite_idxjp2( char filename[], unsigned char *j2kstream, int j2klen, opj_i
/* allocate memory for all tiles */ /* allocate memory for all tiles */
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0); cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
encSuccess = idxjp2_encode( (opj_jp2_t*)cinfo->jp2_handle, cio, j2kstream, j2klen, cstr_info, image); encSuccess = idxjp2_encode( cinfo, cio, j2kstream, j2klen, cstr_info, image);
if (!encSuccess){ if (!encSuccess){
opj_cio_close(cio); opj_cio_close(cio);
@ -116,191 +98,3 @@ void fwrite_idxjp2( char filename[], unsigned char *j2kstream, int j2klen, opj_i
opj_destroy_cstr_info(&cstr_info); opj_destroy_cstr_info(&cstr_info);
} }
/*
* Write JP box
* copy from jp2.c
*
* @param[in] cio file output handler
*/
void jp2_write_jp(opj_cio_t *cio);
/*
* Write FTYP box - File type box
* copy from jp2.c
*
* @param[in] jp2 JP2 handle
* @param[in] cio file output handle
*/
void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
/*
* Write file Index (superbox)
*
* @param[in] offset_jp2c offset of jp2c box
* @param[in] length_jp2c length of jp2c box
* @param[in] offset_idx offset of cidx box
* @param[in] length_idx length of cidx box
* @param[in] cio file output handle
* @return length of fidx box
*/
int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio);
/*
* Write index Finder box
*
* @param[in] offset offset of fidx box
* @param[in] length length of fidx box
* @param[in] cio file output handle
*/
void write_iptr( int offset, int length, opj_cio_t *cio);
opj_bool idxjp2_encode( opj_jp2_t *jp2, opj_cio_t *cio, unsigned char *j2kstream, int j2klen, opj_codestream_info_t cstr_info, opj_image_t *image)
{
int pos_iptr, pos_cidx, pos_jp2c, end_pos, pos_fidx, len_fidx;
int i;
/* JP2 encoding */
/* JPEG 2000 Signature box */
jp2_write_jp(cio);
/* File Type box */
jp2_write_ftyp(jp2, cio);
/* JP2 Header box */
jp2_write_jp2h(jp2, cio);
pos_iptr = cio_tell( cio);
cio_skip( cio, 24); /* IPTR further ! */
pos_jp2c = cio_tell( cio);
cio_write( cio, j2klen+8, 4); // L NOTICE: modify for the extended box
cio_write( cio, JP2_JP2C, 4); // JP2C
for( i=0; i<j2klen; i++)
cio_write( cio, j2kstream[i], 1);
pos_cidx = cio_tell( cio);
write_cidx( pos_jp2c+8, cio, image, cstr_info, j2klen);
pos_fidx = cio_tell( cio);
len_fidx = write_fidx( pos_jp2c, pos_cidx-pos_jp2c, pos_cidx, cio_tell(cio), cio);
end_pos = cio_tell( cio);
cio_seek( cio, pos_iptr);
write_iptr( pos_fidx, len_fidx, cio);
cio_seek( cio, end_pos);
return OPJ_TRUE;
}
void jp2_write_jp( opj_cio_t *cio)
{
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_JP, 4); /* JP2 signature */
cio_write(cio, 0x0d0a870a, 4);
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio)
{
unsigned int i;
opj_jp2_box_t box;
box.init_pos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio, JP2_FTYP, 4); /* FTYP */
cio_write(cio, jp2->brand, 4); /* BR */
cio_write(cio, jp2->minversion, 4); /* MinV */
for (i = 0; i < jp2->numcl; i++) {
cio_write(cio, jp2->cl[i], 4); /* CL */
}
box.length = cio_tell(cio) - box.init_pos;
cio_seek(cio, box.init_pos);
cio_write(cio, box.length, 4); /* L */
cio_seek(cio, box.init_pos + box.length);
}
/*
* Write proxy box
*
* @param[in] offset_jp2c offset of jp2c box
* @param[in] length_jp2c length of jp2c box
* @param[in] offset_idx offset of cidx box
* @param[in] length_idx length of cidx box
* @param[in] cio file output handle
*/
void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio);
int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio)
{
int len, lenp;
lenp = cio_tell( cio);
cio_skip( cio, 4); /* L [at the end] */
cio_write( cio, JPIP_FIDX, 4); /* IPTR */
write_prxy( offset_jp2c, length_jp2c, offset_idx, offset_jp2c, cio);
len = cio_tell( cio)-lenp;
cio_seek( cio, lenp);
cio_write( cio, len, 4); /* L */
cio_seek( cio, lenp+len);
return len;
}
void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_cio_t *cio)
{
int len, lenp;
lenp = cio_tell( cio);
cio_skip( cio, 4); /* L [at the end] */
cio_write( cio, JPIP_PRXY, 4); /* IPTR */
cio_ext_write( cio, offset_jp2c, 8); /* OOFF */
cio_write( cio, length_jp2c, 4); /* OBH part 1 */
cio_write( cio, JP2_JP2C, 4); /* OBH part 2 */
cio_write( cio, 1,1); /* NI */
cio_ext_write( cio, offset_idx, 8); /* IOFF */
cio_write( cio, length_idx, 4); /* IBH part 1 */
cio_write( cio, JPIP_CIDX, 4); /* IBH part 2 */
len = cio_tell( cio)-lenp;
cio_seek( cio, lenp);
cio_write( cio, len, 4); /* L */
cio_seek( cio, lenp+len);
}
void write_iptr( int offset, int length, opj_cio_t *cio)
{
int len, lenp;
lenp = cio_tell( cio);
cio_skip( cio, 4); /* L [at the end] */
cio_write( cio, JPIP_IPTR, 4); /* IPTR */
cio_ext_write( cio, offset, 8);
cio_ext_write( cio, length, 8);
len = cio_tell( cio)-lenp;
cio_seek( cio, lenp);
cio_write( cio, len, 4); /* L */
cio_seek( cio, lenp+len);
}

View File

@ -29,19 +29,9 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include "ext_openjpeg.h"
#include "j2k_to_idxjp2.h" #include "j2k_to_idxjp2.h"
#include "event_mgr_handler.h" #include "event_mgr_handler.h"
#include "cio.h"
#include "j2k.h"
/*
* Decode and Add main header marker information
*
* @param[in] cio file input handle
* @param[in,out] cstr_info codestream information
*/
void add_mainheader_marker_info( opj_cio_t *cio, opj_codestream_info_t *cstr_info);
opj_image_t * decode_j2k( unsigned char *j2kstream, int j2klen, opj_codestream_info_t *cstr_info) opj_image_t * decode_j2k( unsigned char *j2kstream, int j2klen, opj_codestream_info_t *cstr_info)
{ {
@ -94,64 +84,3 @@ opj_image_t * decode_j2k( unsigned char *j2kstream, int j2klen, opj_codestream_i
return image; return image;
} }
/*
* Get main headr marker size
*
* @param[in] type marker type
* @param[in] cstr_info codestream information
* @param[in] cio file input handle
* @return marker size
*/
unsigned short get_mh_markersize( unsigned short type, opj_codestream_info_t cstr_info, opj_cio_t *cio);
void add_mainheader_marker_info( opj_cio_t *cio, opj_codestream_info_t *cstr_info)
{
opj_marker_info_t marker;
int pos;
cstr_info->marker = (opj_marker_info_t *)malloc( 100*sizeof(opj_marker_info_t)); // max 100
pos = cstr_info->main_head_start;
cio_seek( cio, pos);
while( pos <= cstr_info->main_head_end){
marker.type = cio_read( cio, 2);
marker.pos = cio_tell( cio);
marker.len = get_mh_markersize( marker.type, *cstr_info, cio);
cio_skip( cio, marker.len);
cstr_info->marker[ cstr_info->marknum] = marker;
cstr_info->marknum++;
pos = cio_tell( cio);
}
}
unsigned short get_mh_markersize( unsigned short type, opj_codestream_info_t cstr_info, opj_cio_t *cio)
{
unsigned short siz;
int pos;
siz = 0;
switch( type){
case J2K_MS_SOC:
siz = 0;
break;
case J2K_MS_SIZ:
siz = 38+3*cstr_info.numcomps;
break;
case J2K_MS_COD:
case J2K_MS_QCD:
case J2K_MS_COM:
pos = cio_tell( cio);
siz = cio_read( cio, 2);
cio_seek( cio, pos);
break;
default:
fprintf( stderr, "marker %x length not defined yet!\n", type);
}
return siz;
}