[trunk][JPIP]removed obsolete indexer utility
This commit is contained in:
parent
fc01873d60
commit
5d5adf7c7e
@ -5,6 +5,9 @@ What's New for OpenJPIP
|
||||
! : changed
|
||||
+ : added
|
||||
|
||||
October 10, 2011
|
||||
- [antonin] removed obsolete indexer utility
|
||||
|
||||
September 30, 2011
|
||||
+ [kaori] enabled JPP-stream
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
ADD_SUBDIRECTORY(indexer)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
../libopenjpip
|
||||
)
|
||||
@ -36,4 +34,4 @@ ENDIF(UNIX)
|
||||
INSTALL(TARGETS test_index
|
||||
EXPORT OpenJPEGTargets
|
||||
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
|
||||
)
|
||||
)
|
||||
|
@ -1,7 +1,5 @@
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
SUBDIRS = indexer
|
||||
|
||||
bin_PROGRAMS = jpip_to_jp2 jpip_to_j2k test_index addXMLinJP2
|
||||
|
||||
jpip_to_jp2_CPPFLAGS = \
|
||||
|
@ -5,10 +5,7 @@ LDFLAGS = -L$(LIBDIR) -lm -lopenjpip_local
|
||||
|
||||
ALL = jpip_to_jp2 jpip_to_j2k test_index addXMLinJP2
|
||||
|
||||
all: t_indexer $(ALL)
|
||||
|
||||
t_indexer:
|
||||
make -C indexer -f Makefile.nix
|
||||
all: $(ALL)
|
||||
|
||||
jpip_to_jp2: jpip_to_jp2.o $(LIBFNAME)
|
||||
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
|
||||
|
@ -1,34 +0,0 @@
|
||||
SET(INDEXER_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/j2k_to_idxjp2.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext_libopenjpeg/cidx_manager.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext_libopenjpeg/cio_ext.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/event_mgr_handler.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/idxjp2_manager.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/j2k_decoder.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext_libopenjpeg/phix_manager.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext_libopenjpeg/ppix_manager.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext_libopenjpeg/thix_manager.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext_libopenjpeg/tpix_manager.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext_libopenjpeg/ext_j2k.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ext_libopenjpeg/ext_jp2.c
|
||||
)
|
||||
|
||||
# Headers file are located here:
|
||||
INCLUDE_DIRECTORIES(
|
||||
${OPENJPEG_SOURCE_DIR}/libopenjpeg
|
||||
)
|
||||
|
||||
# Build executable
|
||||
|
||||
ADD_EXECUTABLE(j2k_to_idxjp2 ${INDEXER_SRCS})
|
||||
TARGET_LINK_LIBRARIES(j2k_to_idxjp2 ${OPENJPEG_LIBRARY_NAME})
|
||||
|
||||
# On unix you need to link to the math library:
|
||||
IF(UNIX)
|
||||
TARGET_LINK_LIBRARIES(j2k_to_idxjp2 m)
|
||||
ENDIF(UNIX)
|
||||
# Install exe
|
||||
INSTALL(TARGETS j2k_to_idxjp2
|
||||
EXPORT OpenJPEGTargets
|
||||
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
|
||||
)
|
@ -1,35 +0,0 @@
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
bin_PROGRAMS = j2k_to_idxjp2
|
||||
|
||||
j2k_to_idxjp2_CPPFLAGS = \
|
||||
-I. \
|
||||
-I$(top_srcdir)/applications/libopenjpip/tools/indexer \
|
||||
-I$(top_builddir)/applications/libopenjpip/tools/indexer \
|
||||
-I$(top_srcdir)/libopenjpeg \
|
||||
-I$(top_builddir)/libopenjpeg
|
||||
j2k_to_idxjp2_CFLAGS =
|
||||
j2k_to_idxjp2_LDADD = $(top_builddir)/libopenjpeg/libopenjpeg.la -lm
|
||||
j2k_to_idxjp2_SOURCES = \
|
||||
ext_libopenjpeg/cidx_manager.c \
|
||||
ext_libopenjpeg/cidx_manager.h \
|
||||
ext_libopenjpeg/cio_ext.c \
|
||||
ext_libopenjpeg/cio_ext.h \
|
||||
ext_libopenjpeg/ext_j2k.c \
|
||||
ext_libopenjpeg/ext_jp2.c \
|
||||
ext_libopenjpeg/ext_openjpeg.h \
|
||||
ext_libopenjpeg/indexbox_manager.h \
|
||||
j2k_to_idxjp2.c \
|
||||
j2k_to_idxjp2.h \
|
||||
event_mgr_handler.c \
|
||||
event_mgr_handler.h \
|
||||
idxjp2_manager.c \
|
||||
j2k_decoder.c \
|
||||
ext_libopenjpeg/phix_manager.c \
|
||||
ext_libopenjpeg/ppix_manager.c \
|
||||
ext_libopenjpeg/thix_manager.c \
|
||||
ext_libopenjpeg/tpix_manager.c
|
||||
|
||||
install-data-hook:
|
||||
@echo -e " (B)\t$(bindir)/j2k_to_idxjp2$(EXEEXT)" >> $(top_builddir)/report.txt
|
||||
|
@ -1,15 +0,0 @@
|
||||
INCDIR = ../../../../libopenjpeg
|
||||
INCDIR2 = ext_libopenjpeg
|
||||
LIBDIR = $(INCDIR)/.libs
|
||||
LIBFNAME = $(LIBDIR)/libopenjpeg.a
|
||||
CFLAGS = -O3 -Wall -I$(INCDIR) -I$(INCDIR2)
|
||||
LDFLAGS = -L$(LIBDIR) -lm
|
||||
|
||||
ALL = j2k_to_idxjp2
|
||||
|
||||
all: $(ALL)
|
||||
|
||||
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 $(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:
|
||||
rm -f $(ALL) *.o *~
|
@ -1,72 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "event_mgr_handler.h"
|
||||
|
||||
void error_callback(const char *msg, void *client_data);
|
||||
void warning_callback(const char *msg, void *client_data);
|
||||
void info_callback(const char *msg, void *client_data);
|
||||
|
||||
opj_event_mgr_t set_default_event_mgr()
|
||||
{
|
||||
opj_event_mgr_t event_mgr;
|
||||
|
||||
/* configure the event callbacks (not required) */
|
||||
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
|
||||
event_mgr.error_handler = error_callback;
|
||||
event_mgr.warning_handler = warning_callback;
|
||||
event_mgr.info_handler = info_callback;
|
||||
|
||||
return event_mgr;
|
||||
}
|
||||
|
||||
/**
|
||||
sample error callback expecting a FILE* client object
|
||||
*/
|
||||
void error_callback(const char *msg, void *client_data) {
|
||||
FILE *stream = (FILE*)client_data;
|
||||
fprintf(stream, "[ERROR] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample warning callback expecting a FILE* client object
|
||||
*/
|
||||
void warning_callback(const char *msg, void *client_data) {
|
||||
FILE *stream = (FILE*)client_data;
|
||||
fprintf(stream, "[WARNING] %s", msg);
|
||||
}
|
||||
/**
|
||||
sample debug callback expecting no client object
|
||||
*/
|
||||
void info_callback(const char *msg, void *client_data) {
|
||||
(void)client_data;
|
||||
// fprintf(stdout, "[INFO] %s", msg);
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef EVENT_MG_HANDLER_H_
|
||||
# define EVENT_MG_HANDLER_H_
|
||||
|
||||
#include "openjpeg.h"
|
||||
|
||||
/*
|
||||
* Set default event message handler
|
||||
*
|
||||
* @return event message handler
|
||||
*/
|
||||
opj_event_mgr_t set_default_event_mgr();
|
||||
|
||||
#endif /* !EVENT_MG_HANDLER_H_ */
|
@ -1,213 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "cidx_manager.h"
|
||||
#include "indexbox_manager.h"
|
||||
#include "cio_ext.h"
|
||||
#include "cio.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] cstr_info codestream information
|
||||
* @param[in] cio file output handle
|
||||
* @return length of mainmhix box
|
||||
*/
|
||||
int write_mainmhix( 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;
|
||||
|
||||
box = (opj_jp2_box_t *)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( cstr_info, cio);
|
||||
box[num_box].type = JPIP_MHIX;
|
||||
num_box++;
|
||||
|
||||
box[num_box].length = write_tpix( 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( cstr_info, EPHused, j2klen, cio);
|
||||
box[num_box].type = JPIP_PPIX;
|
||||
num_box++;
|
||||
|
||||
box[num_box].length = write_phix( 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);
|
||||
}
|
||||
|
||||
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_ext_write( cio, coff, 8); /* COFF A PRECISER !! */
|
||||
cio_ext_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( 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_ext_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_ext_write( cio, cstr_info.marker[i].pos, 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;
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 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_ */
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2001-2003, David Janssens
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
* Copyright (c) 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 "cio_ext.h"
|
||||
#include "event.h"
|
||||
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
unsigned int cio_ext_write( opj_cio_t *cio, unsigned long long int v, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
if( !cio_ext_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
|
||||
return 0;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
opj_bool cio_ext_byteout(opj_cio_t *cio, unsigned char v)
|
||||
{
|
||||
if (cio->bp >= cio->end) {
|
||||
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
*cio->bp++ = v;
|
||||
return OPJ_TRUE;
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief Additional functions to libopenjpeg/cio.h
|
||||
*/
|
||||
|
||||
#ifndef CIO_EXT_H_
|
||||
# define CIO_EXT_H_
|
||||
|
||||
#include "openjpeg.h"
|
||||
|
||||
|
||||
/*
|
||||
* Write byte codes with 5 bytes to 8 bytes length
|
||||
* cio_write supports up to 4 bytes
|
||||
*
|
||||
* @param[in] cio file handler
|
||||
* @param[in] v byte code
|
||||
* @param[in] n byte length
|
||||
* @return really writen byte length
|
||||
*/
|
||||
unsigned int cio_ext_write( opj_cio_t *cio, unsigned long long int v, int n);
|
||||
|
||||
#endif /* !CIO_EXT_H_ */
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
@ -1,228 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#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);
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#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_ */
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 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] 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( 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
|
||||
* @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] 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( opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
|
||||
|
||||
|
||||
/*
|
||||
* Write packet header index table box (superbox)
|
||||
*
|
||||
* @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( 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_ */
|
@ -1,147 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 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 <math.h>
|
||||
#include "indexbox_manager.h"
|
||||
#include "cio_ext.h"
|
||||
#include "cio.h"
|
||||
|
||||
/*
|
||||
* Write faix box of phix
|
||||
*
|
||||
* @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 compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
|
||||
|
||||
int write_phix( 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 *)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( 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);
|
||||
}
|
||||
|
||||
free(box);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int write_phixfaix( int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
||||
{
|
||||
int len, lenp;
|
||||
int size_of_coding; // 4 or 8
|
||||
int version;
|
||||
int tileno, resno, precno, layno, num_packet=0;
|
||||
int i,nmax=0;
|
||||
|
||||
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 */
|
||||
|
||||
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_ext_write( cio, nmax , size_of_coding); /* NMAX */
|
||||
cio_ext_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
|
||||
|
||||
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
|
||||
|
||||
opj_tile_info_t *tile_Idx = &cstr_info.tile[ tileno];
|
||||
// int correction = EPHused ? 3 : 1;
|
||||
num_packet = 0;
|
||||
|
||||
for( resno=0; resno<cstr_info.numdecompos[compno]+1; resno++){
|
||||
for( precno=0; precno<tile_Idx->pw[resno]*tile_Idx->ph[resno]; precno++){
|
||||
for( layno=0; layno<cstr_info.numlayers; layno++){
|
||||
opj_packet_info_t packet = tile_Idx->packet[ num_packet * cstr_info.numcomps + compno];
|
||||
cio_ext_write( cio, packet.start_pos, size_of_coding); /* start position */
|
||||
cio_ext_write( cio, packet.end_ph_pos-packet.start_pos+1, size_of_coding); /* length */
|
||||
|
||||
num_packet++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* PADDING */
|
||||
while( num_packet < nmax){
|
||||
cio_ext_write( cio, 0, size_of_coding); /* start position */
|
||||
cio_ext_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;
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 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 "indexbox_manager.h"
|
||||
#include "cio_ext.h"
|
||||
#include "cio.h"
|
||||
|
||||
/*
|
||||
* Write faix box of ppix
|
||||
*
|
||||
* @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 compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
|
||||
|
||||
int write_ppix( 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?
|
||||
|
||||
box = (opj_jp2_box_t *)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( 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);
|
||||
}
|
||||
|
||||
free(box);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// NMAX might be wrong , phix too, do sth to correction
|
||||
int write_ppixfaix( int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
|
||||
{
|
||||
int len, lenp;
|
||||
int tileno, resno, precno, layno, num_packet=0;
|
||||
int size_of_coding; // 4 or 8
|
||||
int version;
|
||||
int i,nmax=0;
|
||||
|
||||
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 */
|
||||
|
||||
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_ext_write( cio, nmax, size_of_coding); /* NMAX */
|
||||
cio_ext_write( cio, cstr_info.tw*cstr_info.th, size_of_coding); /* M */
|
||||
|
||||
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
|
||||
|
||||
opj_tile_info_t *tile_Idx = &cstr_info.tile[ tileno];
|
||||
// int correction = EPHused ? 3 : 1;
|
||||
num_packet=0;
|
||||
|
||||
for( resno=0; resno< cstr_info.numdecompos[compno]+1; resno++){
|
||||
for( precno=0; precno<tile_Idx->pw[resno]*tile_Idx->ph[resno]; precno++){
|
||||
for( layno=0; layno<cstr_info.numlayers; layno++){
|
||||
opj_packet_info_t packet = tile_Idx->packet[ num_packet * cstr_info.numcomps + compno];
|
||||
cio_ext_write( cio, packet.start_pos, size_of_coding); /* start position */
|
||||
cio_ext_write( cio, packet.end_pos-packet.start_pos+1, size_of_coding); /* length */
|
||||
|
||||
num_packet++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* PADDING */
|
||||
while( num_packet < nmax){
|
||||
cio_ext_write( cio, 0, size_of_coding); /* start position */
|
||||
cio_ext_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;
|
||||
|
||||
}
|
@ -1,208 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 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 "indexbox_manager.h"
|
||||
#include "cio_ext.h"
|
||||
#include "cio.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 *)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);
|
||||
}
|
||||
|
||||
free(box);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Find tile markers
|
||||
*
|
||||
* @param[in] coff offset of j2k codestream
|
||||
* @param[in] startpos tile start byte position
|
||||
* @param[in] endpos tile end position
|
||||
* @param[in] cio file output handle
|
||||
* @param[out] marknum pointer to number of markers
|
||||
* @return found marker information array
|
||||
*/
|
||||
opj_marker_info_t * find_tile_markers( int coff, int startpos, int endpos, opj_cio_t *cio, int *marknum);
|
||||
|
||||
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 marknum;
|
||||
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_ext_write( cio, tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */
|
||||
|
||||
marker = find_tile_markers( coff, tile.start_pos, tile.end_header, cio, &marknum);
|
||||
|
||||
for( i=0; i<marknum; i++){ /* Marker restricted to 1 apparition */
|
||||
cio_write( cio, marker[i].type, 2);
|
||||
cio_write( cio, 0, 2);
|
||||
cio_ext_write( cio, marker[i].pos, 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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get tile marker size
|
||||
*
|
||||
* @param[in] type marker type
|
||||
* @param[in] cio file input handle
|
||||
* @return marker size
|
||||
*/
|
||||
unsigned short get_tile_markersize( unsigned short type, opj_cio_t *cio);
|
||||
|
||||
opj_marker_info_t * find_tile_markers( int coff, int startpos, int endpos, opj_cio_t *cio, int *marknum)
|
||||
{
|
||||
int org_pos, pos;
|
||||
opj_marker_info_t *marker, *tmp;
|
||||
int max_num_of_markers = 100;
|
||||
|
||||
marker = (opj_marker_info_t *)malloc( max_num_of_markers*sizeof(opj_marker_info_t));
|
||||
if( !marker){
|
||||
fprintf( stderr, "malloc error for marker in find_tile_markers()\n");
|
||||
exit(-1);
|
||||
}
|
||||
(*marknum) = 0;
|
||||
|
||||
org_pos = cio_tell( cio);
|
||||
cio_seek( cio, coff+startpos);
|
||||
pos = startpos;
|
||||
|
||||
while( pos < coff+endpos){
|
||||
if( *marknum >= max_num_of_markers){
|
||||
tmp = marker;
|
||||
marker = (opj_marker_info_t *)malloc( (max_num_of_markers+100)*sizeof(opj_marker_info_t));
|
||||
memcpy( marker, tmp, max_num_of_markers*sizeof(opj_marker_info_t));
|
||||
free( tmp);
|
||||
max_num_of_markers += 100;
|
||||
}
|
||||
|
||||
marker[*marknum].type = cio_read( cio, 2);
|
||||
marker[*marknum].pos = cio_tell( cio)-coff;
|
||||
marker[*marknum].len = get_tile_markersize( marker[*marknum].type, cio);
|
||||
cio_skip( cio, marker[*marknum].len);
|
||||
|
||||
(*marknum)++;
|
||||
pos += 2+marker[*marknum].len;
|
||||
}
|
||||
|
||||
cio_seek( cio, org_pos);
|
||||
|
||||
return marker;
|
||||
}
|
||||
|
||||
unsigned short get_tile_markersize( unsigned short type, opj_cio_t *cio)
|
||||
{
|
||||
unsigned short siz;
|
||||
int pos;
|
||||
|
||||
siz = 0;
|
||||
|
||||
switch( type){
|
||||
case J2K_MS_SOD:
|
||||
case J2K_MS_EOC:
|
||||
case J2K_MS_EPH:
|
||||
siz = 0;
|
||||
break;
|
||||
default:
|
||||
pos = cio_tell( cio);
|
||||
siz = cio_read( cio, 2);
|
||||
cio_seek( cio, pos);
|
||||
break;
|
||||
}
|
||||
return siz;
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 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 <math.h>
|
||||
#include "indexbox_manager.h"
|
||||
#include "cio_ext.h"
|
||||
#include "cio.h"
|
||||
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
|
||||
|
||||
/*
|
||||
* Write faix box of tpix
|
||||
*
|
||||
* @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 compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio);
|
||||
|
||||
|
||||
int write_tpix( 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( 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 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_ext_write( cio, num_max_tile_parts, size_of_coding); /* NMAX */
|
||||
cio_ext_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_ext_write( cio, tp.tp_start_pos, size_of_coding); /* start position */
|
||||
cio_ext_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_ext_write( cio, 0, size_of_coding); /* start position */
|
||||
cio_ext_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,100 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2001-2003, David Janssens
|
||||
* Copyright (c) 2002-2003, Yannick Verschueren
|
||||
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
|
||||
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
||||
|
||||
* Copyright (c) 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 Copy of some jp2.c functions, and modification of jpip.h from 2KAN indexer
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ext_libopenjpeg/ext_openjpeg.h"
|
||||
#include "j2k_to_idxjp2.h"
|
||||
#include "event_mgr_handler.h"
|
||||
|
||||
|
||||
void fwrite_idxjp2( char filename[], unsigned char *j2kstream, int j2klen, opj_image_t *image, opj_codestream_info_t cstr_info)
|
||||
{
|
||||
int codestream_length;
|
||||
opj_cio_t *cio = NULL;
|
||||
FILE *fp = NULL;
|
||||
opj_cinfo_t *cinfo;
|
||||
opj_cparameters_t parameters; /* compression parameters */
|
||||
opj_event_mgr_t event_mgr;
|
||||
opj_bool encSuccess;
|
||||
|
||||
/* set encoding parameters to default values */
|
||||
opj_set_default_encoder_parameters(¶meters);
|
||||
|
||||
/* get a JP2 compressor handle */
|
||||
cinfo = opj_create_compress(CODEC_JP2);
|
||||
|
||||
event_mgr = set_default_event_mgr();
|
||||
|
||||
/* catch events using our callbacks and give a local context */
|
||||
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
|
||||
|
||||
/* setup the encoder parameters using the current image and using user parameters */
|
||||
opj_setup_encoder(cinfo, ¶meters, image);
|
||||
|
||||
/* open a byte stream for writing */
|
||||
/* allocate memory for all tiles */
|
||||
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
|
||||
|
||||
encSuccess = idxjp2_encode( cinfo, cio, j2kstream, j2klen, cstr_info, image);
|
||||
|
||||
if (!encSuccess){
|
||||
opj_cio_close(cio);
|
||||
fprintf(stderr, "failed to encode image\n");
|
||||
return;
|
||||
}
|
||||
codestream_length = cio_tell(cio);
|
||||
|
||||
/* write the buffer to disk */
|
||||
fp = fopen( filename, "wb");
|
||||
if (!fp) {
|
||||
fprintf(stderr, "failed to open %s for writing\n", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
fwrite(cio->buffer, 1, codestream_length, fp);
|
||||
fclose(fp);
|
||||
fprintf(stderr,"Generated outfile %s\n", filename);
|
||||
/* close and free the byte stream */
|
||||
opj_cio_close(cio);
|
||||
|
||||
/* free remaining compression structures */
|
||||
opj_destroy_compress(cinfo);
|
||||
|
||||
opj_destroy_cstr_info(&cstr_info);
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ext_libopenjpeg/ext_openjpeg.h"
|
||||
#include "j2k_to_idxjp2.h"
|
||||
#include "event_mgr_handler.h"
|
||||
|
||||
opj_image_t * decode_j2k( unsigned char *j2kstream, int j2klen, opj_codestream_info_t *cstr_info)
|
||||
{
|
||||
opj_image_t *image;
|
||||
opj_dparameters_t parameters; /* decompression parameters */
|
||||
opj_dinfo_t *dinfo; /* handle to a decompressor */
|
||||
opj_cio_t *cio;
|
||||
opj_event_mgr_t event_mgr; /* event manager */
|
||||
|
||||
/* set decoding parameters to default values */
|
||||
opj_set_default_decoder_parameters(¶meters);
|
||||
|
||||
/* decode the code-stream */
|
||||
/* ---------------------- */
|
||||
|
||||
/* JPEG-2000 codestream */
|
||||
/* get a decoder handle */
|
||||
dinfo = opj_create_decompress( CODEC_J2K);
|
||||
|
||||
event_mgr = set_default_event_mgr();
|
||||
|
||||
/* catch events using our callbacks and give a local context */
|
||||
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
|
||||
|
||||
/* setup the decoder decoding parameters using user parameters */
|
||||
opj_setup_decoder(dinfo, ¶meters);
|
||||
|
||||
/* open a byte stream */
|
||||
cio = opj_cio_open((opj_common_ptr)dinfo, j2kstream, j2klen);
|
||||
|
||||
/* decode the stream and fill the image structure */
|
||||
image = opj_decode_with_info(dinfo, cio, cstr_info);
|
||||
if(!image) {
|
||||
fprintf(stderr, "ERROR -> jp2_to_image: failed to decode image!\n");
|
||||
opj_destroy_decompress(dinfo);
|
||||
opj_cio_close(cio);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if( cstr_info->marknum == 0)
|
||||
add_mainheader_marker_info( cio, cstr_info);
|
||||
|
||||
/* close the byte stream */
|
||||
opj_cio_close(cio);
|
||||
|
||||
/* free remaining structures */
|
||||
if(dinfo) {
|
||||
opj_destroy_decompress(dinfo);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief j2k_to_idxjp2 is a program to make jp2 file with index box from j2k file
|
||||
*
|
||||
* \section impinst Implementing instructions
|
||||
* This program takes two arguments. \n
|
||||
* -# Input J2K image file\n
|
||||
* -# Output JP2 file name\n
|
||||
* % ./j2k_to_idxjp2 image.j2k image.jp2\n
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "openjpeg.h"
|
||||
#include "j2k_to_idxjp2.h"
|
||||
|
||||
|
||||
/*
|
||||
* Read a binary file
|
||||
*
|
||||
* @param[in] filename file name
|
||||
* @param[out] lenoffile pointer to feed file length
|
||||
* @return byte code
|
||||
*/
|
||||
unsigned char * read_binaryfile( char filename[], int *lenoffile);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
opj_image_t *image = NULL;
|
||||
opj_codestream_info_t cstr_info; /* Codestream information structure */
|
||||
unsigned char *j2kstream;
|
||||
int j2klen;
|
||||
|
||||
if (argc < 3){
|
||||
fprintf(stderr,"\nERROR in entry : j2k_to_idxjp2 J2K-file JP2-file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
j2kstream = read_binaryfile( argv[1], &j2klen);
|
||||
|
||||
image = decode_j2k( j2kstream, j2klen, &cstr_info);
|
||||
if( !image){
|
||||
free(j2kstream);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fwrite_idxjp2( argv[2], j2kstream, j2klen, image, cstr_info);
|
||||
|
||||
free(j2kstream);
|
||||
|
||||
/* free image data structure */
|
||||
opj_image_destroy(image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char * read_binaryfile( char filename[], int *lenoffile)
|
||||
{
|
||||
FILE *fp;
|
||||
unsigned char *bytecode;
|
||||
|
||||
fp = fopen( filename, "rb");
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Failed to open %s for reading !!\n", filename);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
/* length of the codestream */
|
||||
fseek( fp, 0, SEEK_END);
|
||||
*lenoffile = ftell(fp);
|
||||
fseek( fp, 0, SEEK_SET);
|
||||
|
||||
bytecode = (unsigned char*)malloc(*lenoffile);
|
||||
fread( bytecode, *lenoffile, 1, fp);
|
||||
fclose(fp);
|
||||
|
||||
return bytecode;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
|
||||
* Copyright (c) 2002-2011, Professor Benoit Macq
|
||||
* Copyright (c) 2010-2011, Kaori Hagihara
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef J2K_TO_IDXJP2_H_
|
||||
# define J2K_TO_IDXJP2_H_
|
||||
|
||||
#include "openjpeg.h"
|
||||
|
||||
/*
|
||||
* Decode j2k codestream
|
||||
*
|
||||
* @param[in] j2kstream j2k codestream
|
||||
* @param[in] j2klen length of j2k codestream
|
||||
* @param[out] cstr_info codestream information
|
||||
* @return image data
|
||||
*/
|
||||
opj_image_t * decode_j2k( unsigned char *j2kstream, int j2klen, opj_codestream_info_t *cstr_info);
|
||||
|
||||
|
||||
/*
|
||||
* Write a JP2 file with index box
|
||||
*
|
||||
* @param[in] filename file name
|
||||
* @param[in] j2kstream j2k codestream
|
||||
* @param[in] j2klen length of j2k codestream
|
||||
* @param[in] image image data
|
||||
* @param[in] cstr_info codestream information
|
||||
*/
|
||||
void fwrite_idxjp2( char filename[], unsigned char *j2kstream, int j2klen, opj_image_t *image, opj_codestream_info_t cstr_info);
|
||||
|
||||
#endif /* !J2K_TO_IDXJP2S_H_ */
|
Loading…
Reference in New Issue
Block a user