]> granicus.if.org Git - openjpeg/commitdiff
backport r882:893 to openjpeg-1.5 branch
authorAntonin Descampe <antonin@gmail.com>
Sat, 27 Aug 2011 12:53:38 +0000 (12:53 +0000)
committerAntonin Descampe <antonin@gmail.com>
Sat, 27 Aug 2011 12:53:38 +0000 (12:53 +0000)
79 files changed:
Makefile.am
applications/jpip/CHANGES
applications/jpip/README
applications/jpip/libopenjpip/CMakeLists.txt
applications/jpip/libopenjpip/Makefile.am
applications/jpip/libopenjpip/box_manager.c
applications/jpip/libopenjpip/box_manager.h
applications/jpip/libopenjpip/boxheader_manager.c
applications/jpip/libopenjpip/byte_manager.c
applications/jpip/libopenjpip/byte_manager.h
applications/jpip/libopenjpip/cachemodel_manager.c [new file with mode: 0644]
applications/jpip/libopenjpip/cachemodel_manager.h [new file with mode: 0644]
applications/jpip/libopenjpip/codestream_manager.h
applications/jpip/libopenjpip/comMakefile.mk
applications/jpip/libopenjpip/index_manager.c
applications/jpip/libopenjpip/index_manager.h
applications/jpip/libopenjpip/metadata_manager.c
applications/jpip/libopenjpip/msgqueue_manager.c
applications/jpip/libopenjpip/msgqueue_manager.h
applications/jpip/libopenjpip/placeholder_manager.c
applications/jpip/libopenjpip/target_manager.c
applications/jpip/libopenjpip/target_manager.h
applications/jpip/opj_client/opj_dec_server/Makefile.nix
applications/jpip/opj_client/opj_dec_server/cache_manager.c
applications/jpip/opj_client/opj_dec_server/cache_manager.h
applications/jpip/opj_client/opj_dec_server/imgsock_manager.c
applications/jpip/opj_client/opj_dec_server/imgsock_manager.h
applications/jpip/opj_client/opj_dec_server/jp2k_decoder.c
applications/jpip/opj_client/opj_dec_server/opj_dec_server.c
applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110825.jar [moved from applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110711.jar with 54% similarity]
applications/jpip/opj_client/opj_viewer/dist/opj_viewer.jar
applications/jpip/opj_client/opj_viewer/src/ImageManager.java
applications/jpip/opj_client/opj_viewer/src/ImgdecClient.java
applications/jpip/opj_client/opj_viewer/src/JPIPHttpClient.java
applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110825.jar [moved from applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110711.jar with 63% similarity]
applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces.jar
applications/jpip/opj_server/Makefile.am
applications/jpip/opj_server/Makefile.nix
applications/jpip/opj_server/channel_manager.c
applications/jpip/opj_server/channel_manager.h
applications/jpip/opj_server/opj_server.c
applications/jpip/opj_server/query_parser.c
applications/jpip/opj_server/query_parser.h
applications/jpip/opj_server/session_manager.c
applications/jpip/opj_server/session_manager.h
applications/jpip/tools/indexer/CMakeLists.txt
applications/jpip/tools/indexer/Makefile.am
applications/jpip/tools/indexer/Makefile.nix
applications/jpip/tools/indexer/bio.c [deleted file]
applications/jpip/tools/indexer/cidx_manager.c [new file with mode: 0644]
applications/jpip/tools/indexer/cidx_manager.h [moved from applications/jpip/tools/indexer/cio.h with 62% similarity]
applications/jpip/tools/indexer/cio.c [deleted file]
applications/jpip/tools/indexer/cio_ext.c [moved from applications/jpip/tools/indexer/jpip.h with 57% similarity]
applications/jpip/tools/indexer/cio_ext.h [moved from applications/jpip/tools/indexer/t2.h with 65% similarity]
applications/jpip/tools/indexer/event_mgr_handler.c [new file with mode: 0644]
applications/jpip/tools/indexer/event_mgr_handler.h [moved from applications/jpip/tools/indexer/jp2.h with 74% similarity]
applications/jpip/tools/indexer/idxjp2_manager.c [new file with mode: 0644]
applications/jpip/tools/indexer/index_create.c [deleted file]
applications/jpip/tools/indexer/indexbox_manager.h [new file with mode: 0644]
applications/jpip/tools/indexer/int.c [deleted file]
applications/jpip/tools/indexer/int.h [deleted file]
applications/jpip/tools/indexer/j2k.h [deleted file]
applications/jpip/tools/indexer/j2k_decoder.c [new file with mode: 0644]
applications/jpip/tools/indexer/j2k_to_idxjp2.c [new file with mode: 0644]
applications/jpip/tools/indexer/j2k_to_idxjp2.h [moved from applications/jpip/tools/indexer/bio.h with 56% similarity]
applications/jpip/tools/indexer/jp2.c [deleted file]
applications/jpip/tools/indexer/jpip.c [deleted file]
applications/jpip/tools/indexer/phix_manager.c [new file with mode: 0644]
applications/jpip/tools/indexer/pi.c [deleted file]
applications/jpip/tools/indexer/pi.h [deleted file]
applications/jpip/tools/indexer/ppix_manager.c [new file with mode: 0644]
applications/jpip/tools/indexer/t2.c [deleted file]
applications/jpip/tools/indexer/tcd.c [deleted file]
applications/jpip/tools/indexer/tcd.h [deleted file]
applications/jpip/tools/indexer/tgt.c [deleted file]
applications/jpip/tools/indexer/tgt.h [deleted file]
applications/jpip/tools/indexer/thix_manager.c [new file with mode: 0644]
applications/jpip/tools/indexer/tpix_manager.c [new file with mode: 0644]
configure.ac

index c23ddbb9c78106632d3a0d6d1af669d0fdccab0d..6afd4dc98097280fc68e1943b24a7440b8ea7fdf 100644 (file)
@@ -28,18 +28,18 @@ missing
 EXTRA_DIST = \
 CMake/CheckHaveGetopt.cmake \
 CMake/OpenJPEGConfig.cmake.in \
-testing/CTestCustom.cmake.in \
-testing/CTestConfig.cmake \
 CMakeLists.txt \
-LICENSE \
+AUTHORS \
 CHANGES \
-README \
 INSTALL \
+LICENSE \
+NEWS \
+README \
+THANKS \
 bootstrap.sh \
 libopenjpeg1.pc.cmake \
 libopenjpeg1.pc.in \
 opj_configh.cmake.in \
-opj_config.h.in.user \
 m4/opj_check_lib.m4 \
 m4/opj_doxygen.m4 \
 m4/pkg.m4
@@ -53,7 +53,11 @@ doc:
        @cd doc && make doc
 
 install-data-hook:
+if HAVE_WIN32
+       $(LN_S) -f libopenjpeg1.pc $(DESTDIR)$(pkgconfigdir)/libopenjpeg.pc
+else
        $(LN_S) -nf libopenjpeg1.pc $(DESTDIR)$(pkgconfigdir)/libopenjpeg.pc
+endif
        @echo -e " (PC)\t$(pkgconfigdir)/libopenjpeg1.pc" >> $(top_builddir)/report.txt
        @echo -e " (LN)\t$(pkgconfigdir)/libopenjpeg.pc" >> $(top_builddir)/report.txt
 if WANT_JPWL
index 94d0359f3fd3c354c1a4b444db7ba845efcc8a28..8b84700f2e2493bb69dae36a5992bb37dc57a8a8 100644 (file)
@@ -5,6 +5,20 @@ What's New for OpenJPIP
 ! : changed
 + : added
 
+August 26, 2011
+* [antonin] fixed cmake and autotools files to reflect recent indexer changes in JPIP
+! [kaori] indexer using the latest openjpeg library
+* [antonin] fixed cmake and autotools files to reflect recent changes in JPIP
+! [kaori] fixed Makefile.nix to load openjpeg library from this archive
+
+August 25, 2011
++ [kaori] added tid request support to JPIP client
++ [kaori] added quit JPIP server request
+
+August 24, 2011
++ [kaori] added cachemodel_manager, which had been managed in target_manager previously
++ [kaori] added tid request support to JPIP server
+
 August 16, 2011
 * [antonin] fixed cmake support for openjpip
 
index 363ce1d00aaf0ab0f01e1a497b8bb29ae47db44d..0f053189f7084db93c91d69d986483fb7042de78 100644 (file)
@@ -90,6 +90,11 @@ Server:
 
  2. Launch opj_server from the server terminal:
     % spawn-fcgi -f ./opj_server -p 3000 -n
+ For shutting down JPIP server:
+     %GET http://hostname/myFCGI?quitJPIP
+     Notice, http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting)
+     Requst message "quitJPIP" can be changed in Makfile, modify -DQUIT_SIGNAL=\"quitJPIP\"
 
 Client:
  1. Launch image decoding server, and keep it alive as long as image viewers are open
@@ -127,7 +132,7 @@ An example to encode a TIF image "copenhague1.tif" at resolution 4780x4050, 8bit
     % ./kdu_compress -i copenhague1.tif -o copenhague1.j2k Corder=RPCL  ORGtparts=R Stiles={256,256}
 
  2. JP2 encoding with embedding indexing data
-    % ./index_create copenhague1.j2k copenhague1.jp2 2
+    % ./j2k_to_idxjp2 copenhague1.j2k copenhague1.jp2
 
 <Option>
  3. Embed metadata into JP2 file
index b61edf94a0218f20d6c8406ecba00f13c47f2838..ff9d708a2312cf0ea64f470f1aef9dd958ddb7e3 100644 (file)
@@ -21,6 +21,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/ihdrbox_manager.c
 ${CMAKE_CURRENT_SOURCE_DIR}/manfbox_manager.c
 ${CMAKE_CURRENT_SOURCE_DIR}/mhixbox_manager.c
 ${CMAKE_CURRENT_SOURCE_DIR}/target_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/cachemodel_manager.c
 )
 
 # Build the library
index bcf7e10a1914ebb42968c4b181d8836504883123..fbdffda4d81797dead3ac999329bfc6a001295c4 100644 (file)
@@ -21,6 +21,7 @@ ihdrbox_manager.c \
 manfbox_manager.c \
 mhixbox_manager.c \
 target_manager.c \
+cachemodel_manager.c \
 bool.h \
 boxheader_manager.h \
 box_manager.h \
@@ -36,7 +37,8 @@ metadata_manager.h \
 mhixbox_manager.h \
 msgqueue_manager.h \
 placeholder_manager.h \
-target_manager.h
+target_manager.h \
+cachemodel_manager.h
 
 libopenjpip_server_la_CPPFLAGS = \
 -I. \
index 41f5043b09b27a1c5aaf6ff358fccf66d511146f..d3332576c21c0253b08b2fe215af249d2616ebd5 100644 (file)
@@ -28,6 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <sys/types.h>
index 29d824e4898a53b315eaf44d0f0c3a1482d83f45..72f451bf0d3f0e85adc80332a24a8655eccb90bf 100644 (file)
@@ -31,7 +31,6 @@
 #ifndef        BOX_MANAGER_H_
 # define       BOX_MANAGER_H_
 
-#include <stdio.h>
 #include "byte_manager.h"
 
 //! box parameters
index 09253e2a47bac354c8a4cd54193f075a37ca8cd9..2f465a3b8a560911508eeeced6170ff32c2eef90 100644 (file)
@@ -28,6 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdlib.h>
index e2ce484b7a462dc8a00771ecb4ec12ff331bdc4d..288adb42a3155a490ce43a79106ca5f27d85c802 100644 (file)
@@ -28,6 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
index d5b8a0b6aec625095a4d7d00b7f1a84defe0455d..8b90fa90be5e38530f4c450233d48337cce6a3b1 100644 (file)
@@ -31,8 +31,6 @@
 #ifndef        BYTE_MANAGER_H_
 # define       BYTE_MANAGER_H_
 
-#include <stdio.h>
-
 //! 1Byte parameter type
 typedef unsigned char Byte_t;
 
diff --git a/applications/jpip/libopenjpip/cachemodel_manager.c b/applications/jpip/libopenjpip/cachemodel_manager.c
new file mode 100644 (file)
index 0000000..fdd1b83
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * $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 "cachemodel_manager.h"
+#include "faixbox_manager.h"
+
+#ifdef SERVER
+#include "fcgi_stdio.h"
+#define logstream FCGI_stdout
+#else
+#define FCGI_stdout stdout
+#define FCGI_stderr stderr
+#define logstream stderr
+#endif //SERVER
+
+
+cachemodellist_param_t * gene_cachemodellist()
+{
+  cachemodellist_param_t *cachemodellist;
+
+  cachemodellist = (cachemodellist_param_t *)malloc( sizeof(cachemodellist_param_t));
+  
+  cachemodellist->first = NULL;
+  cachemodellist->last  = NULL;
+
+  return cachemodellist;
+}
+
+cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, target_param_t *target)
+{
+  cachemodel_param_t *cachemodel;
+  faixbox_param_t *tilepart;
+  size_t numOfelem;
+
+  cachemodel = (cachemodel_param_t *)malloc( sizeof(cachemodel_param_t));
+
+  refer_target( target, &cachemodel->target);
+  cachemodel->mhead_model = false;
+  
+  tilepart = target->codeidx->tilepart;
+  numOfelem = get_nmax( tilepart)*get_m( tilepart);
+  cachemodel->tp_model = (bool *)calloc( 1, numOfelem*sizeof(bool));
+  
+  cachemodel->next = NULL;
+  
+  if( cachemodellist){
+    if( cachemodellist->first) // there are one or more entries
+      cachemodellist->last->next = cachemodel;
+    else                   // first entry
+      cachemodellist->first = cachemodel;
+    cachemodellist->last = cachemodel;
+  }
+
+#ifndef SERVER
+  fprintf( logstream, "local log: cachemodel generated\n");
+#endif
+
+  return cachemodel; 
+}
+
+void print_cachemodel( cachemodel_param_t cachemodel)
+{
+  Byte8_t TPnum; // num of tile parts in each tile
+  int i, j, k, n;
+  
+  fprintf( logstream, "target: %s\n", cachemodel.target->filename);
+  fprintf( logstream, "\t main header model: %d\n", cachemodel.mhead_model);
+
+  fprintf( logstream, "\t tile part model:\n");
+
+  TPnum = get_nmax( cachemodel.target->codeidx->tilepart);
+
+  for( i=0, n=0; i<cachemodel.target->codeidx->YTnum; i++){
+    for( j=0; j<cachemodel.target->codeidx->XTnum; j++){
+      for( k=0; k<TPnum; k++)
+       fprintf( logstream, "%d", cachemodel.tp_model[n++]);
+      fprintf( logstream, " ");
+    }
+    fprintf( logstream, "\n");
+  }
+}
+
+cachemodel_param_t * search_cachemodel( target_param_t *target, cachemodellist_param_t *cachemodellist)
+{
+  cachemodel_param_t *foundcachemodel;
+
+  foundcachemodel = cachemodellist->first;
+  
+  while( foundcachemodel != NULL){
+    
+    if( foundcachemodel->target == target)
+      return foundcachemodel;
+      
+    foundcachemodel = foundcachemodel->next;
+  }
+  return NULL;
+}
+
+void delete_cachemodellist( cachemodellist_param_t **cachemodellist)
+{  
+  cachemodel_param_t *cachemodelPtr, *cachemodelNext;
+
+  cachemodelPtr = (*cachemodellist)->first;
+  while( cachemodelPtr != NULL){
+    cachemodelNext=cachemodelPtr->next;
+    delete_cachemodel( &cachemodelPtr);
+    cachemodelPtr=cachemodelNext;
+  }
+  free(*cachemodellist);
+}
+
+void delete_cachemodel( cachemodel_param_t **cachemodel)
+{
+  unrefer_target( (*cachemodel)->target);
+  
+  free( (*cachemodel)->tp_model);
+
+#ifndef SERVER
+  fprintf( logstream, "local log: cachemodel deleted\n");
+#endif
+  free( *cachemodel);
+}
diff --git a/applications/jpip/libopenjpip/cachemodel_manager.h b/applications/jpip/libopenjpip/cachemodel_manager.h
new file mode 100644 (file)
index 0000000..efc6927
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * $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        CACHEMODEL_MANAGER_H_
+# define       CACHEMODEL_MANAGER_H_
+
+#include "bool.h"
+#include "target_manager.h"
+
+//! Cache model parameters
+typedef struct cachemodel_param{
+  target_param_t *target;        //!< reference pointer to the target
+  bool mhead_model;              //!< main header model, if sent, 1, else 0
+  bool *tp_model;                //!< dynamic array pointer of tile part model, if sent, 1, else 0
+  struct cachemodel_param *next; //!< pointer to the next cache model
+} cachemodel_param_t;
+
+//! Cache model list parameters
+typedef struct cachemodellist_param{
+  cachemodel_param_t *first; //!< first cache model pointer of the list
+  cachemodel_param_t *last;  //!< last  cache model pointer of the list
+} cachemodellist_param_t;
+
+
+/**
+ * generate a cache model list
+ *
+ * @return pointer to the generated cache model list
+ */
+cachemodellist_param_t * gene_cachemodellist();
+
+/**
+ * generate a session under the sesion list
+ *
+ * @param[in] cachemodellist cachemodel list to insert the generated cache model
+ * @param[in] target         pointer the reference target
+ * @return                   pointer to the generated cache model
+ */
+cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, target_param_t *target);
+
+
+/**
+ * print cache model
+ *
+ * @param[in] cachemodel cache model
+ */
+void print_cachemodel( cachemodel_param_t cachemodel);
+
+
+/**
+ * search a cache model of a target
+ *
+ * @param[in] target         refering target
+ * @param[in] cachemodellist cache model list
+ * @return                   found cache model pointer
+ */
+cachemodel_param_t * search_cachemodel( target_param_t *target, cachemodellist_param_t *cachemodellist);
+
+
+/**
+ * delete a cache model
+ *
+ * @param[in] cachemodel     address of the cachemodel pointer
+ */
+void delete_cachemodel( cachemodel_param_t **cachemodel);
+
+/**
+ * delete cachemodel list
+ *
+ * @param[in,out] cachemodellist address of the cachemodel list pointer
+ */
+void delete_cachemodellist( cachemodellist_param_t **cachemodellist);
+
+
+#endif             /* !CACHEMODEL_MANAGER_H_ */
index eb6aba6a1f6876ae51e07ba55eb339bd40765a7d..fcefbeeaceee395b2361918d7cd9eb5c650a13af 100644 (file)
@@ -31,7 +31,6 @@
 #ifndef        CODESTREAM_MANAGER_H_
 # define       CODESTREAM_MANAGER_H_
 
-#include <stdio.h>
 #include "byte_manager.h"
 
 //! codestream parameters
index de54ee0a42ad9ca0c8dd048c7edf83a25e8822bf..bee0d617c6a90f0f5d59d98748de89ca9d34fa99 100644 (file)
@@ -10,7 +10,7 @@ all: $(LIBNAME)
 
 $(LIBNAME): target_manager.o byte_manager.o box_manager.o boxheader_manager.o manfbox_manager.o \
        mhixbox_manager.o marker_manager.o codestream_manager.o faixbox_manager.o index_manager.o \
-       msgqueue_manager.o metadata_manager.o placeholder_manager.o ihdrbox_manager.o imgreg_manager.o 
+       msgqueue_manager.o metadata_manager.o placeholder_manager.o ihdrbox_manager.o imgreg_manager.o cachemodel_manager.o
        ar r $@ $^
 
 clean:
index 847fd5289ee5665ed9630275d3b2f52a30588096..96ae6b328701f0db2d257abfd1a6715d10c4f38e 100644 (file)
@@ -28,6 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
 #include <sys/types.h>
@@ -35,6 +36,7 @@
 #include <unistd.h>
 #include <string.h>
 
+#include "bool.h"
 #include "index_manager.h"
 #include "box_manager.h"
 #include "manfbox_manager.h"
@@ -145,31 +147,10 @@ void print_index( index_param_t index)
   print_allmetadata( index.metadatalist);
 }
 
-void print_cachemodel( index_param_t index)
-{
-  Byte8_t TPnum; // num of tile parts in each tile
-  int i, j, k, n;
-
-  TPnum = get_nmax( index.tilepart);
-  
-  fprintf( logstream, "\t main header model: %d\n", index.mhead_model);
-
-  fprintf( logstream, "\t tile part model:\n");
-  for( i=0, n=0; i<index.YTnum; i++){
-    for( j=0; j<index.XTnum; j++){
-      for( k=0; k<TPnum; k++)
-       fprintf( logstream, "%d", index.tp_model[n++]);
-      fprintf( logstream, " ");
-    }
-    fprintf( logstream, "\n");
-  }
-}
-
 void delete_index( index_param_t **index)
 {
   delete_metadatalist( &((*index)->metadatalist));
   delete_faixbox( &((*index)->tilepart));
-  free( (*index)->tp_model);
   free(*index);
 }
 
@@ -365,7 +346,6 @@ bool set_mainmhixdata( box_param_t *cidx_box, codestream_param_t codestream, ind
   if( !(mhix_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "mhix")))
     return false;
 
-  jp2idx->mhead_model = 0;
   jp2idx->mhead_length = fetch_DBox8bytebigendian( mhix_box, 0);
 
   mhix = gene_mhixbox( mhix_box);
@@ -383,8 +363,6 @@ bool set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx)
 {
   box_param_t *tpix_box;   //!< tpix box
   box_param_t *faix_box;   //!< faix box
-  faixbox_param_t *faix;   //!< faix
-  size_t numOfelem;
   
   if( !(tpix_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "tpix")))
     return false;
@@ -392,14 +370,8 @@ bool set_tpixdata( box_param_t *cidx_box, index_param_t *jp2idx)
   if( !(faix_box = gene_boxbyType( tpix_box->fd, get_DBoxoff( tpix_box), get_DBoxlen( tpix_box), "faix")))
     return false;
 
-  faix = gene_faixbox( faix_box);
-  jp2idx->tilepart = faix;
-  numOfelem = get_nmax( faix)*get_m( faix);
+  jp2idx->tilepart = gene_faixbox( faix_box);
   
-  jp2idx->tp_model = (bool *)malloc( numOfelem*sizeof(bool));
-  memset( jp2idx->tp_model, 0, numOfelem*sizeof(bool));
-
-  //delete_faixbox( &faix); // currently the jp2idx element
   free( tpix_box);
   free( faix_box);
 
index 5dd668c5fdae215aeb7b694e88cf8275be652725..6f16f6cba4c8b837f2d013bd5b3c5875b44fca26 100644 (file)
@@ -31,8 +31,6 @@
 #ifndef        INDEX_MANAGER_H_
 # define       INDEX_MANAGER_H_
 
-#include <stdio.h>
-#include "bool.h"
 #include "byte_manager.h"
 #include "faixbox_manager.h"
 #include "metadata_manager.h"
@@ -72,9 +70,6 @@ typedef struct index_param{
   Byte_t  YRsiz[3];          //!< vertical separation of a sample of
                             //!component with respect to the reference grid
   faixbox_param_t *tilepart; //!< tile part information from tpix box
-  bool mhead_model;          //!< main header model, if sent, 1, else 0
-  bool *tp_model;            //!< dynamic array pointer of tile part
-                            //!model, if sent, 1, else 0
 } index_param_t;
 
 
@@ -94,13 +89,6 @@ index_param_t * parse_jp2file( int fd);
  */
 void print_index( index_param_t index);
 
-/**
- * print cache model
- *
- * @param[in] index index parameters
- */
-void print_cachemodel( index_param_t index);
-
 
 /**
  * delete index
index 780a741bb1084a279703a819ed65e8cd5b56de2a..c60f437afff31cfdcb524c7655a8aa2497acd4de 100644 (file)
@@ -28,6 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
index 1e11041e607790bd927c0e7e93ea9dcf7fab2f4e..7d0d8dff744ed43506578ca27a1e40b42aee7b7f 100644 (file)
@@ -28,6 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
 #include <sys/types.h>
@@ -57,7 +58,7 @@
 #define MAINHEADER_MSG 6
 #define METADATA_MSG 8
 
-msgqueue_param_t * gene_msgqueue( bool stateless, target_param_t *target)
+msgqueue_param_t * gene_msgqueue( bool stateless, cachemodel_param_t *cachemodel)
 {
   msgqueue_param_t *msgqueue;
 
@@ -67,7 +68,7 @@ msgqueue_param_t * gene_msgqueue( bool stateless, target_param_t *target)
   msgqueue->last  = NULL;
 
   msgqueue->stateless = stateless;
-  msgqueue->target = target;
+  msgqueue->cachemodel = cachemodel;
   
   return msgqueue;
 }
@@ -86,8 +87,8 @@ void delete_msgqueue( msgqueue_param_t **msgqueue)
     free( ptr);
     ptr = next;
   }
-  if( (*msgqueue)->stateless && (*msgqueue)->target)
-    delete_target( &((*msgqueue)->target));
+  if( (*msgqueue)->stateless && (*msgqueue)->cachemodel)
+    delete_cachemodel( &((*msgqueue)->cachemodel));
 
   free(*msgqueue); 
 }
@@ -124,10 +125,12 @@ void enqueue_message( message_param_t *msg, msgqueue_param_t *msgqueue);
 
 void enqueue_mainheader( msgqueue_param_t *msgqueue)
 {
+  cachemodel_param_t *cachemodel;
   target_param_t *target;
   message_param_t *msg;
 
-  target = msgqueue->target;
+  cachemodel = msgqueue->cachemodel;
+  target = cachemodel->target;
 
   msg = (message_param_t *)malloc( sizeof(message_param_t));
 
@@ -144,11 +147,12 @@ void enqueue_mainheader( msgqueue_param_t *msgqueue)
 
   enqueue_message( msg, msgqueue);
 
-  target->codeidx->mhead_model = true;
+  cachemodel->mhead_model = true;
 }
 
 void enqueue_tile( int tile_id, int level, msgqueue_param_t *msgqueue)
 {
+  cachemodel_param_t *cachemodel;
   target_param_t *target;
   bool *tp_model;
   Byte8_t numOftparts; // num of tile parts par tile
@@ -159,7 +163,8 @@ void enqueue_tile( int tile_id, int level, msgqueue_param_t *msgqueue)
   Byte8_t binOffset, binLength;
   int i;
 
-  target = msgqueue->target;
+  cachemodel = msgqueue->cachemodel;
+  target = cachemodel->target;
   codeidx  = target->codeidx;
   tilepart = codeidx->tilepart;
   
@@ -171,7 +176,7 @@ void enqueue_tile( int tile_id, int level, msgqueue_param_t *msgqueue)
     return;
   }
   
-  tp_model = &codeidx->tp_model[ tile_id*numOftparts];
+  tp_model = &cachemodel->tp_model[ tile_id*numOftparts];
   
   binOffset=0;
   for( i=0; i<numOftparts-level; i++){
@@ -213,7 +218,7 @@ void enqueue_metadata( int meta_id, msgqueue_param_t *msgqueue)
   metadata_param_t *metadata;
   Byte8_t binOffset;
 
-  metadatalist = msgqueue->target->codeidx->metadatalist;
+  metadatalist = msgqueue->cachemodel->target->codeidx->metadatalist;
   metadata = search_metadata( meta_id, metadatalist);
   
   if( !metadata){
@@ -243,7 +248,7 @@ void enqueue_box( int meta_id, boxlist_param_t *boxlist, msgqueue_param_t *msgqu
   
   box = boxlist->first;
   while( box){
-    msg = gene_metamsg( meta_id, *binOffset, box->length, box->offset, NULL, msgqueue->target->csn);
+    msg = gene_metamsg( meta_id, *binOffset, box->length, box->offset, NULL, msgqueue->cachemodel->target->csn);
     enqueue_message( msg, msgqueue);
 
     *binOffset += box->length;
@@ -258,7 +263,7 @@ void enqueue_phld( int meta_id, placeholderlist_param_t *phldlist, msgqueue_para
   
   phld = phldlist->first;
   while( phld){
-    msg = gene_metamsg( meta_id, *binOffset, phld->LBox, 0, phld, msgqueue->target->csn);
+    msg = gene_metamsg( meta_id, *binOffset, phld->LBox, 0, phld, msgqueue->cachemodel->target->csn);
     enqueue_message( msg, msgqueue);
 
     *binOffset += phld->LBox;
@@ -270,7 +275,7 @@ void enqueue_boxcontents( int meta_id, boxcontents_param_t *boxcontents, msgqueu
 {
   message_param_t *msg;
 
-  msg = gene_metamsg( meta_id, *binOffset, boxcontents->length, boxcontents->offset, NULL, msgqueue->target->csn);
+  msg = gene_metamsg( meta_id, *binOffset, boxcontents->length, boxcontents->offset, NULL, msgqueue->cachemodel->target->csn);
   enqueue_message( msg, msgqueue);
   
   *binOffset += boxcontents->length;
@@ -357,7 +362,7 @@ void emit_stream_from_msgqueue( msgqueue_param_t *msgqueue)
     if( msg->phld)
       emit_placeholder( msg->phld);
     else
-      emit_body( msg, msgqueue->target->fd);
+      emit_body( msg, msgqueue->cachemodel->target->fd);
 
     msg = msg->next;
   }
@@ -738,31 +743,45 @@ Byte_t * recons_codestream( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte
   Byte_t *codestream = NULL;
   int last_tileID;
   int tileID;
-  
+  bool found;
+  Byte8_t binOffset;
+
   *codelen = 0;
 
   // main header first
   ptr = msgqueue->first;
+  binOffset = 0;
   while(( ptr = search_message( MAINHEADER_MSG, -1, csn, ptr))!=NULL){
-    codestream = add_msgstream( ptr, jpipstream, codestream, codelen);
+    if( ptr->bin_offset == binOffset){
+      codestream = add_msgstream( ptr, jpipstream, codestream, codelen);
+      binOffset += ptr->length;
+    }
     ptr = ptr->next;
   }
 
   last_tileID = get_last_tileID( msgqueue, csn); 
   
   for( tileID=0; tileID <= last_tileID; tileID++){
-    bool found = false;
+    found = false;
+    binOffset = 0;
+
     ptr = msgqueue->first;
     while(( ptr = search_message( TILE_MSG, tileID, csn, ptr))!=NULL){
-      found = true;
-      codestream = add_msgstream( ptr, jpipstream, codestream, codelen);
+      if( ptr->bin_offset == binOffset){
+       found = true;
+       codestream = add_msgstream( ptr, jpipstream, codestream, codelen);
+       binOffset += ptr->length;
+      }
       ptr = ptr->next;
     }
     ptr = msgqueue->first;
     while(( ptr = search_message( EXT_TILE_MSG, tileID, csn, ptr))!=NULL){
       if( ptr->aux >= minlev){
-       found = true;
-       codestream = add_msgstream( ptr, jpipstream, codestream, codelen);
+       if( ptr->bin_offset == binOffset){
+         found = true;
+         codestream = add_msgstream( ptr, jpipstream, codestream, codelen);
+         binOffset += ptr->length;
+       }
       }
       ptr = ptr->next;
     }
index 469194abbffbaf145a59d5308fa995952bebf8e0..d832958ee942b640985874b37717e80705301f1c 100644 (file)
 #ifndef        MSGQUEUE_MANAGER_H_
 # define       MSGQUEUE_MANAGER_H_
 
-#include <stdio.h>
 #include "bool.h"
 #include "byte_manager.h"
-#include "target_manager.h"
+#include "cachemodel_manager.h"
 #include "placeholder_manager.h"
 
 //! message parameters
@@ -56,17 +55,17 @@ typedef struct msgqueue_param{
   message_param_t *first; //!< first message pointer of the list
   message_param_t *last;  //!< last  message pointer of the list
   bool stateless;         //!< if this is a stateless message queue
-  target_param_t *target; //!< reference target pointer
+  cachemodel_param_t *cachemodel; //!< reference cachemodel pointer
 } msgqueue_param_t;
 
 /**
  * generate message queue
  *
- * @param[in] stateless if this is a stateless message queue
- * @param[in] target    reference target pointer
- * @return generated message queue pointer
+ * @param[in] stateless   if this is a stateless message queue
+ * @param[in] cachemodel  cachemodel pointer
+ * @return                generated message queue pointer
  */
-msgqueue_param_t * gene_msgqueue( bool stateless, target_param_t *target);
+msgqueue_param_t * gene_msgqueue( bool stateless, cachemodel_param_t *cachemodel);
 
 /**
  * delete message queue
index 803889b49ada8d86e7441efff8eb0f6af550e5b8..d76dbf3c4c3056869af316b71ae563f8471ad646 100644 (file)
@@ -28,6 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "placeholder_manager.h"
index f0056e722c8dc63a6900c3d12fc874ec834e38ad..6aea9aec68a6fb4374b328e0caaf31d83d081ff0 100644 (file)
@@ -35,6 +35,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <time.h>
 #include "target_manager.h"
 
 #ifdef SERVER
@@ -68,14 +69,13 @@ targetlist_param_t * gene_targetlist()
  */
 int open_jp2file( char filename[]);
 
-target_param_t * gene_target( char *targetname)
+target_param_t * gene_target( targetlist_param_t *targetlist, char *targetname)
 {
   target_param_t *target;
   int fd;
   index_param_t *jp2idx;
   static int last_csn = 0;
 
-
   if( targetname[0]=='\0'){
     fprintf( FCGI_stderr, "Error: exception, no targetname in gene_target()\n");
     return NULL;
@@ -92,16 +92,39 @@ target_param_t * gene_target( char *targetname)
   }
 
   target = (target_param_t *)malloc( sizeof(target_param_t));
+  snprintf( target->tid, MAX_LENOFTID, "%x-%x", (unsigned int)time(NULL), (unsigned int)rand());
   strcpy( target->filename, targetname); 
   target->fd = fd;
   target->csn = last_csn++;
   target->codeidx = jp2idx;
+  target->num_of_use = 0;
   
   target->next=NULL;
 
+  if( targetlist->first) // there are one or more entries
+    targetlist->last->next = target;
+  else                   // first entry
+    targetlist->first = target;
+  targetlist->last = target;
+
+#ifndef SERVER
+  fprintf( logstream, "local log: target %s generated\n", targetname);
+#endif
+  
   return target;
 }
 
+void refer_target( target_param_t *reftarget, target_param_t **ptr)
+{
+  *ptr = reftarget;
+  reftarget->num_of_use++;
+}
+
+void unrefer_target( target_param_t *target)
+{
+  target->num_of_use--;
+}
+
 void delete_target( target_param_t **target)
 {
   close( (*target)->fd);
@@ -146,14 +169,21 @@ void delete_targetlist(targetlist_param_t **targetlist)
   free( *targetlist);
 }
 
+void print_target( target_param_t *target)
+{
+  fprintf( logstream, "target:\n");
+  fprintf( logstream, "\t tid=%s\n", target->tid);
+  fprintf( logstream, "\t csn=%d\n", target->csn);
+  fprintf( logstream, "\t target=%s\n\n", target->filename);
+}
+
 void print_alltarget( targetlist_param_t *targetlist)
 {
   target_param_t *ptr;
 
   ptr = targetlist->first;
   while( ptr != NULL){
-    fprintf( logstream,"csn=%d\n", ptr->csn);
-    fprintf( logstream,"target=%s\n", ptr->filename);
+    print_target( ptr);
     ptr=ptr->next;
   }
 }
@@ -174,6 +204,23 @@ target_param_t * search_target( char targetname[], targetlist_param_t *targetlis
   return NULL;
 }
 
+target_param_t * search_targetBytid( char tid[], targetlist_param_t *targetlist)
+{
+  target_param_t *foundtarget;
+  
+  foundtarget = targetlist->first;
+  
+  while( foundtarget != NULL){
+    
+    if( strcmp( tid, foundtarget->tid) == 0)
+      return foundtarget;
+      
+    foundtarget = foundtarget->next;
+  }
+
+  return NULL;
+}
+
 int open_jp2file( char filename[])
 {
   int fd;
index afe367e7e12f1a61f17c8dbb234f61984d1a4ab4..fc872ea8d444b5fdd4e6882068db14e477a464d6 100644 (file)
 
 #include "index_manager.h"
 
+//! maximum length of target identifier
+#define MAX_LENOFTID 30
+
 //! maximum length of target name
 #define MAX_LENOFTARGET 128
 
 //! target parameters
 typedef struct target_param{
+  char tid[MAX_LENOFTID];         //!< taregt identifier
   char filename[MAX_LENOFTARGET]; //!< file name
   int fd;                         //!< file descriptor
   int csn;                        //!< codestream number
   index_param_t *codeidx;         //!< index information of codestream
+  int num_of_use;                 //!< numbers of sessions refering to this target
   struct target_param *next;      //!< pointer to the next target
 } target_param_t;
 
@@ -65,12 +70,29 @@ targetlist_param_t * gene_targetlist();
 /**
  * generate a target
  *
+ * @param[in] targetlist target list to insert the generated target
  * @param[in] targetname target file name
  * @return               pointer to the generated target
  */
-target_param_t * gene_target( char *targetname);
+target_param_t * gene_target( targetlist_param_t *targetlist, char *targetname);
+
+
+/**
+ * refer a target, used to make a new cache model
+ *
+ * @param[in]  reftarget reference target pointer
+ * @param[out] ptr       address of feeding target pointer
+ */
+void refer_target( target_param_t *reftarget, target_param_t **ptr);
 
 
+/**
+ * refer a target, used to make a new cache model
+ *
+ * @param[in]  target reference pointer to the target
+ */
+void unrefer_target( target_param_t *target);
+
 /**
  * delete a target
  *
@@ -95,6 +117,14 @@ void delete_target_in_list( target_param_t **target, targetlist_param_t *targetl
  */
 void delete_targetlist(targetlist_param_t **targetlist);
 
+
+/**
+ * print target parameters
+ *
+ * @param[in] target target pointer
+ */
+void print_target( target_param_t *target);
+
 /**
  * print all target parameters
  *
@@ -112,5 +142,15 @@ void print_alltarget( targetlist_param_t *targetlist);
  */
 target_param_t * search_target( char targetname[], targetlist_param_t *targetlist);
 
+
+/**
+ * search a target by tid
+ *
+ * @param[in] tid        target identifier
+ * @param[in] targetlist target list pointer
+ * @return               found target pointer
+ */
+target_param_t * search_targetBytid( char tid[], targetlist_param_t *targetlist);
+
 #endif             /* !TARGET_MANAGER_H_ */
 
index bfd41e4410adec083b80d6b1369edc1838eaad85..dd8e06cf1ee20a7c30ea48ef73770501c102bc3f 100644 (file)
@@ -1,7 +1,9 @@
-LIBDIR = ../../libopenjpip
-LIBFNAME = $(LIBDIR)/libopenjpip_local.a
-CFLAGS  = -O3 -Wall -I$(LIBDIR)
-LDFLAGS = -L$(LIBDIR) -lm -lopenjpeg -lopenjpip_local
+J2KINCDIR = ../../../../libopenjpeg
+J2KLIBDIR = $(J2KINCDIR)/.libs
+JPIPLIBDIR = ../../libopenjpip
+LIBFNAME = $(JPIPLIBDIR)/libopenjpip_local.a $(J2KLIBDIR)/libopenjpeg.a
+CFLAGS  = -O3 -Wall -I$(JPIPLIBDIR) -I$(J2KINCDIR)
+LDFLAGS = -L$(JPIPLIBDIR) -L$(J2KLIBDIR) -lm -lopenjpip_local
 #-lws2_32
 
 ALL = opj_dec_server
@@ -9,6 +11,6 @@ ALL = opj_dec_server
 all: $(ALL)
 
 opj_dec_server: opj_dec_server.o jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o $(LIBFNAME)
-       $(CC) $(CFLAGS) $< jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o $(LDFLAGS) -o $@
+       $(CC) $(CFLAGS) $< jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o $(LDFLAGS) $(LIBFNAME) -o $@
 clean:
        rm -f $(ALL) *.o *~
index 4d58f835565c95cd8f8085eab3bd42631efc22aa..6a7b92c914ae3094c4d3167064d4f640f89be649 100644 (file)
@@ -61,12 +61,13 @@ void delete_cachelist(cachelist_param_t **cachelist)
   free( *cachelist);
 }
 
-cache_param_t * gene_cache( char *targetname, int csn, char *cid)
+cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid)
 {
   cache_param_t *cache;
   
   cache = (cache_param_t *)malloc( sizeof(cache_param_t));
   strcpy( cache->filename, targetname);
+  strcpy( cache->tid, tid);
   cache->csn = csn;
   cache->cid = (char **)malloc( sizeof(char *));
   *cache->cid = (char *)malloc( MAX_LENOFCID);
@@ -175,6 +176,14 @@ void add_cachecid( char *cid, cache_param_t *cache)
   cache->numOfcid ++;
 }
 
+void update_cachetid( char *tid, cache_param_t *cache)
+{
+  if( tid[0] != '0' && strcmp( tid, cache->tid) !=0){
+    fprintf( stderr, "tid is updated to %s for %s\n", tid, cache->filename);
+    strcpy( cache->tid, tid);
+  }
+}
+
 void remove_cidInCache( char *cid, cache_param_t *cache);
 
 void remove_cachecid( char *cid, cachelist_param_t *cachelist)
@@ -225,6 +234,7 @@ void print_cache( cache_param_t *cache)
   
   fprintf( stdout,"cache\n");
   fprintf( stdout,"\t filename: %s\n", cache->filename);
+  fprintf( stdout,"\t tid: %s\n", cache->tid);
   fprintf( stdout,"\t csn: %d\n", cache->csn);
   fprintf( stdout,"\t cid:");
 
index 44450134caba528a255b509190daf5ea6d91ef6b..ad35de80e2b694c400591d312541d3b3ec024796 100644 (file)
 //! maximum length of target name
 #define MAX_LENOFTARGET 128
 
+//! maximum length of target identifier
+#define MAX_LENOFTID 30
+
 //! cache parameters
 typedef struct cache_param{
   char filename[MAX_LENOFTARGET];     //!< file name
+  char tid[MAX_LENOFTID];             //!< taregt identifier
   int csn;                            //!< codestream number
   char **cid;                         //!< dynamic array of channel identifiers
   int numOfcid;                       //!< number of cids
@@ -74,10 +78,11 @@ void delete_cachelist(cachelist_param_t **cachelist);
  *
  * @param[in] targetname target file name
  * @param[in] csn        codestream number
+ * @param[in] tid        target identifier
  * @param[in] cid        channel identifier
  * @return               pointer to the generated cache
  */
-cache_param_t * gene_cache( char *targetname, int csn, char *cid);
+cache_param_t * gene_cache( char *targetname, int csn, char *tid, char *cid);
 
 /**
  * delete a cache
@@ -132,6 +137,16 @@ cache_param_t * search_cacheBycid( char cid[], cachelist_param_t *cachelist);
  */
 void add_cachecid( char *cid, cache_param_t *cache);
 
+
+/**
+ * update tid of a cache
+ *
+ * @param[in] tid   target identifier
+ * @param[in] cache cache pointer
+ */
+void update_cachetid( char *tid, cache_param_t *cache);
+
+
 /**
  * remove cid in cache
  *
index 567b81ca7e051007fb6b0fbe46dcd7381280b2aa..19599a9a724ca1c4528ec52075d700dda4eb0b0e 100644 (file)
@@ -94,7 +94,7 @@ msgtype_t identify_clientmsg( SOCKET connected_socket)
 {
   int receive_size;
   char buf[BUF_LEN];
-  char *magicid[] = { "JPIP-stream", "PNM request", "XML request", "CID request", "CID destroy", "JP2 save", "QUIT"};
+  char *magicid[] = { "JPIP-stream", "PNM request", "XML request", "TID request", "CID request", "CID destroy", "JP2 save", "QUIT"};
   int i;
   
   receive_size = receive_line( connected_socket, buf);
@@ -106,7 +106,7 @@ msgtype_t identify_clientmsg( SOCKET connected_socket)
 
   for( i=0; i<NUM_OF_MSGTYPES; i++){
     if( strncasecmp( magicid[i], buf, strlen(magicid[i])) == 0){
-      printf("Client message: %s\n", magicid[i]);
+      printf("%s\n", magicid[i]);
       return i;
     }
   }
@@ -115,10 +115,10 @@ msgtype_t identify_clientmsg( SOCKET connected_socket)
   return MSGERROR;
 }
 
-Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, int *streamlen)
+Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen)
 {
   Byte_t *jpipstream=NULL, *ptr;
-  char buf[BUF_LEN], versionstring[] = "version 1.1";
+  char buf[BUF_LEN], versionstring[] = "version 1.2";
   int linelen, redlen, remlen;
   
   target[0] = 0;
@@ -137,6 +137,10 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, i
   if( strstr( buf, "jp2")){ 
     // register cid option
     strcpy( target, buf);
+    
+    if((linelen = receive_line( connected_socket, buf)) == 0)
+      return NULL;
+    strcpy( tid, buf);
 
     if((linelen = receive_line( connected_socket, buf)) == 0)
       return NULL;
@@ -147,9 +151,8 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, i
   }
 
   *streamlen = atoi( buf);
-  fprintf( stderr, "Receiveing Data length: %d\n", *streamlen);
+  fprintf( stderr, "Receive Data: %d Bytes\n", *streamlen);
   
-      
   jpipstream = (unsigned  char *)malloc( (*streamlen));
   ptr = jpipstream;
   remlen = (*streamlen);
@@ -162,7 +165,6 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, i
     remlen -= redlen;
     ptr = ptr + redlen;
   }
-  fprintf( stderr, "    done\n");
     
   return jpipstream;
 }
@@ -183,17 +185,29 @@ void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length)
   send_stream( connected_socket, xmlstream, length);
 }
 
+void send_IDstream(  SOCKET connected_socket, char *id, int idlen, char *label);
+
 void send_CIDstream( SOCKET connected_socket, char *cid, int cidlen)
+{
+  send_IDstream( connected_socket, cid, cidlen, "CID");
+}
+
+void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen)
+{
+  send_IDstream( connected_socket, tid, tidlen, "TID");
+}
+
+void send_IDstream(  SOCKET connected_socket, char *id, int idlen, char *label)
 {
   Byte_t header[4];
 
-  header[0] = 'C';
-  header[1] = 'I';
-  header[2] = 'D';
-  header[3] = cidlen & 0xff;
+  header[0] = label[0];
+  header[1] = label[1];
+  header[2] = label[2];
+  header[3] = idlen & 0xff;
 
   send_stream( connected_socket, header, 4);
-  send_stream( connected_socket, cid, cidlen);
+  send_stream( connected_socket, id, idlen);
 }
 
 void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int width, unsigned int height, unsigned int numofcomp, Byte_t maxval)
index df0085e6426269eca2336632ea3515b6f9df3e22..7a76d619bfc51c52d1ed1217b0271502a95cd868 100644 (file)
@@ -48,8 +48,8 @@ typedef int SOCKET;
  */
 SOCKET open_listeningsocket();
 
-#define NUM_OF_MSGTYPES 7
-typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, CIDREQ, CIDDST, JP2SAVE, QUIT, MSGERROR} msgtype_t;
+#define NUM_OF_MSGTYPES 8
+typedef enum eMSGTYPE{ JPIPSTREAM, PNMREQ, XMLREQ, TIDREQ, CIDREQ, CIDDST, JP2SAVE, QUIT, MSGERROR} msgtype_t;
 
 /**
  * indeitify client message type
@@ -64,11 +64,12 @@ msgtype_t identify_clientmsg( SOCKET connected_socket);
  *
  * @param [in]  connected_socket file descriptor of the connected socket
  * @param [out] target           received target file name (if not received, null string)
+ * @param [out] tid              received target identifier (if not received, null string)
  * @param [out] cid              received channel identifier (if not received, null string)
  * @param [out] streamlen        length of the received codestream
  * @return                       JPT- JPP- codestream
  */
-Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *cid, int *streamlen);
+Byte_t * receive_JPIPstream( SOCKET connected_socket, char *target, char *tid, char *cid, int *streamlen);
 
 /**
  * send PGM/PPM image stream to the client
@@ -91,6 +92,15 @@ void send_PNMstream( SOCKET connected_socket, Byte_t *pnmstream, unsigned int wi
  */
 void send_XMLstream( SOCKET connected_socket, Byte_t *xmlstream, int length);
 
+/**
+ * send TID data stream to the client
+ *
+ * @param [in]  connected_socket file descriptor of the connected socket
+ * @param [in]  tid              tid string
+ * @param [in]  tidlen           legnth of the tid string
+ */
+void send_TIDstream( SOCKET connected_socket, char *tid, int tidlen);
+
 /**
  * send CID data stream to the client
  *
@@ -125,7 +135,7 @@ int receive_line(SOCKET connected_socket, char *buf);
  *\section sec1 JPIP-stream
  * Cache JPT- JPP- stream in server
  *
- * client -> server: JPIP-stream\\n version 1.1\\n (optional for cid registration: targetnamestring\\n cidstring\\n) bytelengthvalue\\n data \n
+ * client -> server: JPIP-stream\\n version 1.1\\n (optional for cid registration: targetnamestring\\n  tidstring\\n  cidstring\\n) bytelengthvalue\\n data \n
  * server -> client: 1 or 0 (of 1Byte response signal)
  * 
  *\section sec2 PNM request
@@ -140,25 +150,31 @@ int receive_line(SOCKET connected_socket, char *buf);
  * client -> server: XML request\\n \n
  * server -> client: XML (3Byte) length (2Byte Big endian) data
  *
- *\section sec4 CID request
+ *\section sec4 TID request
+ * Get target ID of target image
+ *
+ * client -> server: TID request\\n targetname\\n \n
+ * server -> client: TID (3Byte) length (1Byte) tiddata
+ *
+ *\section sec5 CID request
  * Get Channel ID of identical target image
  *
  * client -> server: CID request\\n targetname\\n \n
  * server -> client: CID (3Byte) length (1Byte) ciddata
  *
- *\section sec5 CID destroy
+ *\section sec6 CID destroy
  * Close Channel ID
  *
  * client -> server: CID destroy\\n ciddata \n
  * server -> client: 1 or 0 (of 1Byte response signal)
  *
- *\section sec6 JP2 save
+ *\section sec7 JP2 save
  * Save in JP2 file format
  *
  * client -> server: JP2 save\\n ciddata \n
  * server -> client: 1 or 0 (of 1Byte response signal)
  *
- *\section sec7 QUIT
+ *\section sec8 QUIT
  * Quit the opj_dec_server program
  *
  * client -> server: quit or QUIT
index 41d1a31fa553c9e6128c81273229c313480d124f..0a58d52ab96cf8d8f14d9a95d4ae2b8326bf9b41 100644 (file)
@@ -28,6 +28,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include "jp2k_decoder.h"
index 895ade5ca4cb663e5703ee3e0ff0826eef58c6f3..c8c3c6958d7da6afa8df19eda96b25c781ef2ac7 100644 (file)
@@ -99,6 +99,14 @@ void handle_PNMreqMSG( SOCKET connected_socket, Byte_t *jpipstream, msgqueue_par
  */
 void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_param_t *cachelist);
 
+/**
+ * handle TargetID request message
+ *
+ * @param[in] connected_socket socket descriptor
+ * @param[in] cachelist        cache list pointer
+ */
+void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist);
+
 /**
  * handle ChannelID request message
  *
@@ -163,6 +171,10 @@ int main(int argc, char *argv[]){
     case XMLREQ:
       handle_XMLreqMSG( connected_socket, jpipstream, cachelist);
       break;
+
+    case TIDREQ:
+      handle_TIDreqMSG( connected_socket, cachelist);
+      break;
                                                
     case CIDREQ:
       handle_CIDreqMSG( connected_socket, cachelist);
@@ -183,7 +195,7 @@ int main(int argc, char *argv[]){
       break;
     }
         
-    printf("cut the connection. listening to port\n");
+    printf("\t end of the connection\n\n");
     if( closesocket(connected_socket) != 0){
       perror("close");
       return -1;
@@ -201,7 +213,7 @@ int main(int argc, char *argv[]){
   if( msgqueue)
     delete_msgqueue( &msgqueue);
   
-  //  save_codestream( jpipstream, jpipstreamlen, "jpt");
+  //save_codestream( jpipstream, jpipstreamlen, "jpt");
   free( jpipstream);
 
 #ifdef _WIN32
@@ -221,10 +233,10 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
   Byte_t *newjpipstream;
   int newstreamlen = 0;
   cache_param_t *cache;
-  char target[MAX_LENOFTARGET], cid[MAX_LENOFCID];
+  char target[MAX_LENOFTARGET], tid[MAX_LENOFTID], cid[MAX_LENOFCID];
   metadatalist_param_t *metadatalist;
   
-  newjpipstream = receive_JPIPstream( connected_socket, target, cid, &newstreamlen);
+  newjpipstream = receive_JPIPstream( connected_socket, target, tid, cid, &newstreamlen);
   
   parse_JPIPstream( newjpipstream, newstreamlen, *streamlen, msgqueue);
   
@@ -235,11 +247,13 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
   parse_metamsg( msgqueue, *jpipstream, *streamlen, metadatalist);
   
   // cid registration
-  if( target[0] != 0 && cid[0] != 0){
-    if((cache = search_cache( target, cachelist)))
+  if( target[0] != 0 && tid[0] != 0 && cid[0] != 0){
+    if((cache = search_cache( target, cachelist))){
       add_cachecid( cid, cache);
+      update_cachetid( tid, cache);
+    }
     else{
-      cache = gene_cache( target, msgqueue->last->csn, cid);
+      cache = gene_cache( target, msgqueue->last->csn, tid, cid);
       insert_cache_into_list( cache, cachelist);
     }
   }
@@ -294,6 +308,22 @@ void handle_XMLreqMSG( SOCKET connected_socket, Byte_t *jpipstream, cachelist_pa
   free( xmlstream);
 }
 
+void handle_TIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
+{
+  char target[MAX_LENOFTARGET], *tid = NULL;
+  cache_param_t *cache;
+  int tidlen = 0;
+
+  receive_line( connected_socket, target);
+  cache = search_cache( target, cachelist);
+  
+  if( cache){
+    tid = cache->tid;
+    tidlen = strlen(tid);
+  }
+  send_TIDstream( connected_socket, tid, tidlen);
+}
+
 void handle_CIDreqMSG( SOCKET connected_socket, cachelist_param_t *cachelist)
 {
   char target[MAX_LENOFTARGET], *cid = NULL;
similarity index 54%
rename from applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110711.jar
rename to applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110825.jar
index 1024d50a3a82a3a7eb30ca7d743a70bbb02a8756..67b68b672c4da658c166efb875395745650e8e46 100644 (file)
Binary files a/applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110711.jar and b/applications/jpip/opj_client/opj_viewer/dist/opj_viewer-20110825.jar differ
index 5f7ec56d205d62cdb4ca068be0a944d65e664098..ce826b27f1d1f1d0c5dff55dab9f1dda8483de52 120000 (symlink)
@@ -1 +1 @@
-opj_viewer-20110711.jar
\ No newline at end of file
+opj_viewer-20110825.jar
\ No newline at end of file
index a0eb625adca5541bb2f86dcbcededf38f71a65fa..62166f8a106790c2c0fed5836362eca979eb2185 100644 (file)
@@ -50,16 +50,19 @@ public class ImageManager extends JPIPHttpClient
        String refcid = ImgdecClient.query_cid( j2kfilename);
        byte[] jpipstream;
        
-       if( refcid == null)
-           jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, true);
+       if( refcid == null){
+           String reftid = ImgdecClient.query_tid( j2kfilename);
+           if( reftid == null)
+               jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, true);
+           else
+               jpipstream = super.requestViewWindow( j2kfilename, reftid, reqfw, reqfh, true);
+       }
        else
            jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, true);
        
        System.err.println( "decoding to PNM image");
-       pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, cid, fw, fh);
+       pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh);
        System.err.println( "     done");
-
-       //      System.out.println( "fw: " + fw + " fh: " + fh + "pnm w: ");
        
        return pnmimage.createROIImage( rx, ry, rw, rh);
     }
index 7466aa86058cdc3a4bda85da9153b112523f328f..85fba6127b9955f797d925a844376f75bbd3bda7 100644 (file)
@@ -40,9 +40,9 @@ public class ImgdecClient{
        return get_PNMstream( cid, fw, fh);
     }
 
-    public static PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String cid, int fw, int fh)
+    public static PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String tid, String cid, int fw, int fh)
     {
-       send_JPIPstream( jpipstream, j2kfilename, cid);
+       send_JPIPstream( jpipstream, j2kfilename, tid, cid);
        return get_PNMstream( cid, fw, fh);
     }
     
@@ -56,7 +56,7 @@ public class ImgdecClient{
            System.err.println("Sending " + jpipstream.length + "Data Bytes to decodingServer");
            
            os.writeBytes("JPIP-stream\n");
-           os.writeBytes("version 1.1\n");
+           os.writeBytes("version 1.2\n");
            os.writeBytes( jpipstream.length + "\n"); 
            os.write( jpipstream, 0, jpipstream.length);
       
@@ -71,7 +71,7 @@ public class ImgdecClient{
        }
     }
 
-    public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String cid)
+    public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid)
     {
        try{
            Socket imgdecSocket = new Socket( "localhost", 5000);
@@ -85,8 +85,12 @@ public class ImgdecClient{
            System.err.println("Sending " + length + "Data Bytes to decodingServer");
       
            os.writeBytes("JPIP-stream\n");
-           os.writeBytes("version 1.1\n");
+           os.writeBytes("version 1.2\n");
            os.writeBytes( j2kfilename + "\n");
+           if( tid == null)
+               os.writeBytes( "0\n");
+           else
+               os.writeBytes( tid + "\n");
            os.writeBytes( cid + "\n");
            os.writeBytes( length + "\n");
            os.write( jpipstream, 0, length);
@@ -189,7 +193,27 @@ public class ImgdecClient{
 
     public static String query_cid( String j2kfilename)
     {
-       String cid = null;
+       int []retmsglabel = new int[3];
+       retmsglabel[0] = 67;
+       retmsglabel[1] = 73;
+       retmsglabel[2] = 68;
+
+       return query_id( "CID request", j2kfilename, retmsglabel);
+    }
+
+    public static String query_tid( String j2kfilename)
+    {
+       int []retmsglabel = new int[3];
+       retmsglabel[0] = 84;
+       retmsglabel[1] = 73;
+       retmsglabel[2] = 68;
+
+       return query_id( "TID request", j2kfilename, retmsglabel);
+    }
+
+    public static String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel)
+    {
+       String id = null;
        
        try{
            Socket imgdecSocket = new Socket( "localhost", 5000);
@@ -197,23 +221,23 @@ public class ImgdecClient{
            DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
            byte []header = new byte[4];
 
-           os.writeBytes("CID request\n");
+           os.writeBytes( reqmsghead + "\n");
            os.writeBytes( j2kfilename + "\n");
 
            read_stream( is, header, 4);
            
-           if( header[0] == 67 && header[1] == 73 && header[2] == 68){
+           if( header[0] == retmsglabel[0] && header[1] == retmsglabel[1] && header[2] == retmsglabel[2]){
                int length = header[3]&0xff;
 
                if( length > 0){
                
-                   byte []ciddata = new byte[ length];
-                   read_stream( is, ciddata, length);
-                   cid = new String( ciddata);
+                   byte []iddata = new byte[ length];
+                   read_stream( is, iddata, length);
+                   id = new String( iddata);
                }
            }
            else
-               System.err.println("Error in query_cid(), not starting with CID");
+               System.err.println("Error in query_id("+ reqmsghead + "), wrong to start with " + header);
        }
        catch (UnknownHostException e) {
            System.err.println("Trying to connect to unknown host: " + e);
@@ -221,7 +245,7 @@ public class ImgdecClient{
            System.err.println("IOException: " + e);
        }
 
-       return cid;     
+       return id;      
     }
   
     public static void read_stream( DataInputStream is, byte []stream, int length)
index 3b8781afa4fabdefa45f2a9f46cff6ec611ace7d..cfd3db4cc897bbf6c5e123750ec874e7d441d015 100644 (file)
@@ -40,6 +40,7 @@ public class JPIPHttpClient
     protected int rx, ry;
     protected int rw, rh;
     protected String cid;
+    protected String tid;
     
     public JPIPHttpClient( String URI)
     {
@@ -48,6 +49,7 @@ public class JPIPHttpClient
        rx = ry = -1;
        rw = rh = -1;
        cid = null;
+       tid = null;
     }
 
     public int getFw(){ return fw;}
@@ -75,45 +77,57 @@ public class JPIPHttpClient
 
     public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid)
     {
-       return requestViewWindow( null, reqfw, reqfh, -1, -1, -1, -1, reqcid, false);
+       return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, false);
     }
 
     public byte[] requestViewWindow( int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh, String reqcid)
     {
-       return requestViewWindow( null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, false);
+       return requestViewWindow( null, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, false);
     }
 
     public byte[] requestViewWindow( String target, int reqfw, int reqfh)
     {
-       return requestViewWindow( target, reqfw, reqfh, -1, -1, -1, -1, null, false);
+       return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, false);
     }
     
     public byte[] requestViewWindow( String target, int reqfw, int reqfh, boolean reqcnew)
     {
        if( cid == null) // 1 channel allocation only
-           return requestViewWindow( target, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew);
+           return requestViewWindow( target, null, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew);
+       else
+           return null;
+    }
+
+    public byte[] requestViewWindow( String target, String reqtid, int reqfw, int reqfh, boolean reqcnew)
+    {
+       if( cid == null) // 1 channel allocation only
+           return requestViewWindow( target, reqtid, reqfw, reqfh, -1, -1, -1, -1, null, reqcnew);
        else
            return null;
     }
     
     public byte[] requestViewWindow( String target, int reqfw, int reqfh, int reqrx, int reqry, int reqrw, int reqrh)
     {
-       return requestViewWindow( target, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false);
+       return requestViewWindow( target, null, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, null, false);
     }
 
  
     public byte[] requestViewWindow( int reqfw, int reqfh, String reqcid, boolean reqcnew)
     {
-       return requestViewWindow( null, reqfw, reqfh, -1, -1, -1, -1, reqcid, reqcnew);
+       return requestViewWindow( null, null, reqfw, reqfh, -1, -1, -1, -1, reqcid, reqcnew);
     }
     
-    public byte[] requestViewWindow( String target, 
-                                       int reqfw, int reqfh, 
-                                       int reqrx, int reqry, 
-                                       int reqrw, int reqrh, 
-                                       String reqcid, boolean reqcnew)
+    public byte[] requestViewWindow( String target,
+                                    String reqtid,
+                                    int reqfw, int reqfh, 
+                                    int reqrx, int reqry, 
+                                    int reqrw, int reqrh, 
+                                    String reqcid, boolean reqcnew)
     {
-       String urlstring = const_urlstring( target, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, reqcnew);
+       if( reqtid != null)
+           tid = reqtid;
+
+       String urlstring = const_urlstring( target, reqtid, reqfw, reqfh, reqrx, reqry, reqrw, reqrh, reqcid, reqcnew);
        return GETrequest( urlstring);
     }
     
@@ -146,10 +160,17 @@ public class JPIPHttpClient
            urlconn.setRequestMethod("GET");
            urlconn.setInstanceFollowRedirects(false);
            urlconn.connect();
-      
+           
            Map<String,java.util.List<String>> headers = urlconn.getHeaderFields();
            java.util.List<String> hvaluelist;
-
+           
+           String status = headers.get(null).get(0);
+           
+           System.err.println( status);
+           if( !status.contains("OK"))
+               System.err.println( headers.get("Reason"));
+           System.err.println( headers.get("Content-type"));
+           
            if(( hvaluelist = headers.get("JPIP-fsiz")) != null){
                String hvalueline = hvaluelist.get(0);
                fw = Integer.valueOf( hvalueline.substring( 0, hvalueline.indexOf(','))).intValue();
@@ -178,9 +199,15 @@ public class JPIPHttpClient
                System.err.println("cid: " + cid);
            }
 
+           if(( hvaluelist = headers.get("JPIP-tid")) != null){
+               String hvalueline = hvaluelist.get(0);
+               tid = hvalueline.substring( hvalueline.indexOf('=')+1);
+               System.err.println("tid: " + tid);
+           }
+           
            InputStream input = urlconn.getInputStream();
            buflen = input.available();
-           
+
            if( buflen > 0){
                ByteArrayOutputStream tmpstream = new ByteArrayOutputStream();
                byte[] buf = new byte[ 1024];
@@ -230,11 +257,12 @@ public class JPIPHttpClient
        }
 
        urlconn.disconnect();     
-        
+               
        return jpipstream;
     }
   
-    private String const_urlstring( String target, 
+    private String const_urlstring( String target,
+                                   String reqtid,
                                    int reqfw, int reqfh, 
                                    int reqrx, int reqry, 
                                    int reqrw, int reqrh, 
@@ -250,6 +278,11 @@ public class JPIPHttpClient
                urlstring = urlstring.concat( "&");
            urlstring = urlstring.concat( "target=" + target);
        }
+       if( reqtid != null){
+           if( !urlstring.endsWith("?"))
+               urlstring = urlstring.concat( "&");
+           urlstring = urlstring.concat( "tid=" + reqtid);
+       }
        if( reqfw != -1 && reqfh != -1){
            if( !urlstring.endsWith("?"))
                urlstring = urlstring.concat( "&");
similarity index 63%
rename from applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110711.jar
rename to applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110825.jar
index 30b824b767fb50cc9ff94f96b0592d01f054489c..4028b66446449b158c49ef1604bb3cfcf518b29a 100644 (file)
Binary files a/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110711.jar and b/applications/jpip/opj_client/opj_viewer_xerces/dist/opj_viewer_xerces-20110825.jar differ
index 5288da8f55539e8169ba9da21cc964b73d41ee9d..0f5d3dc99413bb5458fb9abcf915928b0f86a11d 120000 (symlink)
@@ -1 +1 @@
-opj_viewer_xerces-20110711.jar
\ No newline at end of file
+opj_viewer_xerces-20110825.jar
\ No newline at end of file
index acc635fc6728e928b9f069693ffa1f9d5673234e..9fa75b7942c5ed5ed1b7a2f72068273bbf41fc51 100644 (file)
@@ -9,7 +9,8 @@ opj_server_CPPFLAGS = \
 -I$(top_srcdir)/applications/jpip/libopenjpip \
 -I$(top_builddir)/applications/jpip/libopenjpip \
 @FCGI_CFLAGS@ \
--DSERVER
+-DSERVER \
+-DQUIT_SIGNAL=\"quitJPIP\"
 opj_server_CFLAGS = 
 opj_server_LDADD = $(top_builddir)/applications/jpip/libopenjpip/libopenjpip_server.la @FCGI_LIBS@ -lm
 opj_server_SOURCES = \
index f4aa97b1b83762629be4c84ff69f25be2970dc98..3df9a6ee2afa60c3a4d280a43e31bebc7b67c829 100644 (file)
@@ -1,6 +1,7 @@
 LIBDIR = ../libopenjpip
+
 LIBFNAME = $(LIBDIR)/libopenjpip_server.a
-CFLAGS  = -O3 -Wall -m32 -DSERVER -I$(LIBDIR)
+CFLAGS  = -O3 -Wall -m32 -DSERVER -DQUIT_SIGNAL=\"quitJPIP\" -I$(LIBDIR)
 LDFLAGS = -L$(LIBDIR) -lm -lfcgi -lopenjpip_server
 
 ALL = opj_server
index cb2adc196c14afc9de3941905ead407f468577aa..3523161b07b0dd5d81bcaef61bd06cf10c32c780 100644 (file)
@@ -54,23 +54,21 @@ channellist_param_t * gene_channellist()
   return channellist;
 }
 
-
-channel_param_t * gene_channel( query_param_t query_param, target_param_t *target, channellist_param_t *channellist)
+channel_param_t * gene_channel( query_param_t query_param, cachemodel_param_t *cachemodel, channellist_param_t *channellist)
 {
   channel_param_t *channel;
-
-  // set the target
-  if( !target){
+  
+  if( !cachemodel){
     fprintf( FCGI_stdout, "Status: 404\r\n"); 
     fprintf( FCGI_stdout, "Reason: cnew cancelled\r\n"); 
     return NULL;
   }
-  
+
   channel = (channel_param_t *)malloc( sizeof(channel_param_t));
-  channel->target = target;
+  channel->cachemodel = cachemodel;
 
   // set channel ID and get present time
-  snprintf( channel->cid, MAX_LENOFCID, "%x%x", (unsigned int)time( &channel->start_tm), (unsigned int)rand());;
+  snprintf( channel->cid, MAX_LENOFCID, "%x%x", (unsigned int)time( &channel->start_tm), (unsigned int)rand());
   
   channel->next=NULL;
 
@@ -141,7 +139,7 @@ void print_allchannel( channellist_param_t *channellist)
 
   ptr = channellist->first;
   while( ptr != NULL){
-    fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->target->filename);
+    fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->cachemodel->target->filename);
     ptr=ptr->next;
   }
 }
index 5dd970a5e7195583917a7f090b4849e228caee7c..b42a2eb7fbaaa692972c1222636b7aba7498cd33 100644 (file)
 
 #include <time.h>
 #include "query_parser.h"
-#include "target_manager.h"
+#include "cachemodel_manager.h"
 
 //! Channel parameters
 typedef struct channel_param{
-  target_param_t *target;       //!< reference pointer to the target
-  char cid[MAX_LENOFCID];       //!< channel identifier
-  // - a record of the client's capabilities and preferences
-  // - to the extent that the server queues requests
-  time_t start_tm;              //!< starting time
-  struct channel_param *next;   //!< pointer to the next channel
+  cachemodel_param_t *cachemodel; //!< reference pointer to the cache model
+  char cid[MAX_LENOFCID];         //!< channel identifier
+  // - a record of the client's capabilities and preferences to the extent that the server queues requests
+  time_t start_tm;                //!< starting time
+  struct channel_param *next;     //!< pointer to the next channel
 } channel_param_t;
 
 
@@ -65,11 +64,11 @@ channellist_param_t * gene_channellist();
  * generate a channel under the channel list
  *
  * @param[in] query_param query parameters
- * @param[in] target      reference target
+ * @param[in] cachemodel  reference cachemodel
  * @param[in] channellist channel list pointer
  * @return                pointer to the generated channel
  */
-channel_param_t * gene_channel( query_param_t query_param, target_param_t *target, channellist_param_t *channellist);
+channel_param_t * gene_channel( query_param_t query_param, cachemodel_param_t *cachemodel, channellist_param_t *channellist);
 
 /**
  * set channel variable parameters
index 45b43df5e564fb0f3dc9140fffade2b49cb5f1e5..936b54ce71e730ea7f2bb5d4286e4cbd4de2e400 100644 (file)
@@ -55,6 +55,9 @@
 #include "imgreg_manager.h"
 #include "msgqueue_manager.h"
 
+#ifndef QUIT_SIGNAL
+#define QUIT_SIGNAL "quitJPIP"
+#endif
 
 #ifdef SERVER
 #include "fcgi_stdio.h"
  *
  * @param[in]     query_param   structured query
  * @param[in]     sessionlist   session list pointer
+ * @param[in]     targetlist    target list pointer
  * @param[in,out] msgqueue      address of the message queue pointer
  * @return                      if succeeded (true) or failed (false)
  */
 bool parse_JPIPrequest( query_param_t query_param,
                        sessionlist_param_t *sessionlist,
+                       targetlist_param_t *targetlist,
                        msgqueue_param_t **msgqueue);
 
+int main(void)
+{ 
+  sessionlist_param_t *sessionlist;
+  targetlist_param_t *targetlist;
+  bool parse_status;
+  
+  sessionlist = gene_sessionlist();
+  targetlist  = gene_targetlist();
+  
+#ifdef SERVER
+
+  char *query_string;
+  while(FCGI_Accept() >= 0)
+#else
+
+  char query_string[128];
+  while((fgets( query_string, 128, stdin))[0] != '\n' )
+#endif
+    {
+
+#ifdef SERVER     
+      query_string = getenv("QUERY_STRING");    
+#endif //SERVER
+
+      if( strcmp( query_string, QUIT_SIGNAL) == 0)
+       break;
+      
+      fprintf( FCGI_stdout, "Content-type: image/jpt-stream\r\n");
+      
+      query_param_t query_param;
+      msgqueue_param_t *msgqueue;
+
+      parse_query( query_string, &query_param); 
+      
+#ifndef SERVER
+      print_queryparam( query_param);
+#endif
+      
+      msgqueue = NULL;
+      if( !(parse_status = parse_JPIPrequest( query_param, sessionlist, targetlist, &msgqueue)))
+       fprintf( FCGI_stderr, "Error: JPIP request failed\n");
+            
+      fprintf( FCGI_stdout, "\r\n");
+
+#ifndef SERVER
+      //      if( parse_status)
+      //       print_allsession( sessionlist);
+      print_msgqueue( msgqueue);
+#endif
+
+      emit_stream_from_msgqueue( msgqueue);
+
+      delete_msgqueue( &msgqueue);
+    }
+  
+  fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
+
+  delete_sessionlist( &sessionlist);
+  delete_targetlist( &targetlist);
+
+  return 0;
+}
+
+/**
+ * REQUEST: target identification by target or tid request
+ *
+ * @param[in]     query_param   structured query
+ * @param[in]     targetlist    target list pointer
+ * @param[out]    target        address of target pointer
+ * @return                      if succeeded (true) or failed (false)
+ */
+bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target);
 
 /**
  * REQUEST: channel association
@@ -97,12 +174,14 @@ bool associate_channel( query_param_t    query_param,
  *
  * @param[in]     query_param   structured query
  * @param[in]     sessionlist   session list pointer
+ * @param[in]     target        requested target pointer
  * @param[in,out] cursession    address of the associated/opened session pointer
  * @param[in,out] curchannel    address of the associated/opened channel pointer
  * @return                      if succeeded (true) or failed (false)
  */
 bool open_channel( query_param_t query_param, 
                   sessionlist_param_t *sessionlist,
+                  target_param_t *target,
                   session_param_t **cursession, 
                   channel_param_t **curchannel);
 
@@ -124,82 +203,39 @@ bool close_channel( query_param_t query_param,
  * REQUEST: view-window (fsiz)
  *
  * @param[in]     query_param structured query
+ * @param[in]     target      requested target pointer
  * @param[in,out] cursession  associated session pointer
  * @param[in,out] curchannel  associated channel pointer
  * @param[in,out] msgqueue    address of the message queue pointer
  * @return                    if succeeded (true) or failed (false)
  */
 bool gene_JPTstream( query_param_t query_param,
+                    target_param_t *target,
                     session_param_t *cursession, 
                     channel_param_t *curchannel,
                     msgqueue_param_t **msgqueue);
 
-int main(void)
-{ 
-  sessionlist_param_t *sessionlist;
-  bool parse_status;
-  
-  sessionlist = gene_sessionlist();
-
-#ifdef SERVER
-
-  char *query_string;
-  while(FCGI_Accept() >= 0)
-#else
-
-  char query_string[128];
-  while((fgets( query_string, 128, stdin))[0] != '\n' )
-#endif
-    {
-
-#ifdef SERVER     
-      query_string = getenv("QUERY_STRING");    
-#endif //SERVER
-      
-      fprintf( FCGI_stdout, "Content-type: image/jpt-stream\r\n");
-      
-      query_param_t query_param;
-      msgqueue_param_t *msgqueue;
-
-      parse_query( query_string, &query_param); 
-      
-#ifndef SERVER
-      print_queryparam( query_param);
-#endif
-
-      msgqueue = NULL;
-      parse_status = parse_JPIPrequest( query_param, sessionlist, &msgqueue);
-
-      
-      fprintf( FCGI_stdout, "\r\n");
-
-#ifndef SERVER
-      //      if( parse_status)
-      //       print_allsession( sessionlist);
-      print_msgqueue( msgqueue);
-#endif
-      emit_stream_from_msgqueue( msgqueue);
-
-      delete_msgqueue( &msgqueue);
-    }
-  delete_sessionlist( &sessionlist);
-
-  return 0;
-}
-
 bool parse_JPIPrequest( query_param_t query_param,
                        sessionlist_param_t *sessionlist,
+                       targetlist_param_t *targetlist,
                        msgqueue_param_t **msgqueue)
 { 
+  target_param_t *target = NULL;
   session_param_t *cursession = NULL;
   channel_param_t *curchannel = NULL;
 
-  if( query_param.cid[0] != '\0')
+  if( query_param.target[0] != '\0' || query_param.tid[0] != '\0'){
+    if( !identify_target( query_param, targetlist, &target))
+      return false;
+  }
+
+  if( query_param.cid[0] != '\0'){
     if( !associate_channel( query_param, sessionlist, &cursession, &curchannel))
       return false;
-  
+  }
+
   if( query_param.cnew){
-    if( !open_channel( query_param, sessionlist, &cursession, &curchannel))
+    if( !open_channel( query_param, sessionlist, target, &cursession, &curchannel))
       return false;
   }
   if( query_param.cclose[0][0] != '\0')
@@ -207,12 +243,40 @@ bool parse_JPIPrequest( query_param_t query_param,
       return false;
   
   if( (query_param.fx > 0 && query_param.fy > 0) || query_param.box_type[0][0] != 0)
-    if( !gene_JPTstream( query_param, cursession, curchannel, msgqueue))
+    if( !gene_JPTstream( query_param, target, cursession, curchannel, msgqueue))
       return false;
       
   return true;
 }
 
+bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target)
+{
+  if( query_param.tid[0] !='\0' && strcmp( query_param.tid, "0") != 0 ){
+    if( query_param.cid[0] != '\0'){
+      fprintf( FCGI_stdout, "Reason: Target can not be specified both through tid and cid\r\n");
+      fprintf( FCGI_stdout, "Status: 400\r\n");
+      return false;
+    }
+    if( ( *target = search_targetBytid( query_param.tid, targetlist)))
+      return true;
+  }
+
+  if( query_param.target[0] !='\0')
+    if( !( *target = search_target( query_param.target, targetlist)))
+      if(!( *target = gene_target( targetlist, query_param.target)))
+       return false;
+
+  if( *target){
+    fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", (*target)->tid);
+    return true;
+  }
+  else{
+    fprintf( FCGI_stdout, "Reason: target not found\r\n");
+    fprintf( FCGI_stdout, "Status: 400\r\n");
+    return false;
+  }
+}
+
 bool associate_channel( query_param_t    query_param, 
                        sessionlist_param_t *sessionlist,
                        session_param_t **cursession, 
@@ -232,36 +296,24 @@ bool associate_channel( query_param_t    query_param,
 
 bool open_channel( query_param_t query_param, 
                   sessionlist_param_t *sessionlist,
+                  target_param_t *target,
                   session_param_t **cursession, 
                   channel_param_t **curchannel)
 {
-  target_param_t *target=NULL;
-
-  if( query_param.target[0] !='\0'){   // target query specified
-    if( *cursession){
-      if( !( target = search_target( query_param.target, (*cursession)->targetlist))){ 
-       if((target = gene_target( query_param.target)))
-         insert_target_into_session( *cursession, target);
-       else
-         return false;
-      }
-    }
-    else{
-      if((target = gene_target( query_param.target))){
-       // new session
-       *cursession = gene_session( sessionlist);
-       insert_target_into_session( *cursession, target);
-      }
-      else
+  cachemodel_param_t *cachemodel = NULL;
+
+  if( target){
+    if( !(*cursession))
+      *cursession = gene_session( sessionlist);
+    if( !( cachemodel = search_cachemodel( target, (*cursession)->cachemodellist)))
+      if( !(cachemodel = gene_cachemodel( (*cursession)->cachemodellist, target)))
        return false;
-    }
-  }
-  else{
-    if( *cursession)
-      target = (*curchannel)->target;
   }
-  
-  *curchannel = gene_channel( query_param, target, (*cursession)->channellist);
+  else
+    if( *curchannel)
+      cachemodel = (*curchannel)->cachemodel;
+
+  *curchannel = gene_channel( query_param, cachemodel, (*cursession)->channellist);
   if( *curchannel == NULL)
     return false;
 
@@ -335,22 +387,25 @@ void enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadata
 
 
 bool gene_JPTstream( query_param_t query_param,
+                    target_param_t *target,
                     session_param_t *cursession, 
                     channel_param_t *curchannel,
                     msgqueue_param_t **msgqueue)
 {
-  target_param_t *target;
   index_param_t *codeidx;
+  cachemodel_param_t *cachemodel;
   
   if( !cursession || !curchannel){ // stateless
-    if((target = gene_target( query_param.target)))
-      *msgqueue = gene_msgqueue( true, target);
-    else
+    if( !target)
       return false;
+    if( !(cachemodel = gene_cachemodel( NULL, target)))
+      return false;
+    *msgqueue = gene_msgqueue( true, cachemodel);
   }
   else{ // session
-    target  = curchannel->target;
-    *msgqueue = gene_msgqueue( false, target);
+    cachemodel  = curchannel->cachemodel;
+    target = cachemodel->target;
+    *msgqueue = gene_msgqueue( false, cachemodel);
   }
   
   codeidx = target->codeidx;
@@ -359,13 +414,12 @@ bool gene_JPTstream( query_param_t query_param,
   if( query_param.box_type[0][0] != 0)
     enqueue_metabins( query_param, codeidx->metadatalist, *msgqueue); 
 
-  // image code
+  // image codestream
   if( query_param.fx > 0 && query_param.fy > 0){
-    if( !codeidx->mhead_model)
+    if( !cachemodel->mhead_model)
       enqueue_mainheader( *msgqueue);
     enqueue_tiles( query_param, codeidx, *msgqueue);
   }
-  
   return true;
 }
 
index 53317d88a8adcc6d88261ade5291f7c91564cfab..b5dc414454997132d5b567b6341a73007df2bc26 100644 (file)
@@ -99,6 +99,9 @@ void parse_query( char *query_string, query_param_t *query_param)
       if( strcasecmp( fieldname, "target") == 0)
        strcpy( query_param->target,fieldval);
       
+      else if( strcasecmp( fieldname, "tid") == 0)
+       strcpy( query_param->tid, fieldval);
+
       else if( strcasecmp( fieldname, "fsiz") == 0)
        sscanf( fieldval, "%d,%d", &query_param->fx, &query_param->fy);
       
@@ -128,6 +131,7 @@ void init_queryparam( query_param_t *query_param)
   int i;
 
   query_param->target[0]='\0';
+  query_param->tid[0]='\0';
   query_param->fx=-1;
   query_param->fy=-1;
   query_param->rx=-1;
@@ -183,6 +187,7 @@ void print_queryparam( query_param_t query_param)
 
   fprintf( logstream, "query parameters:\n");
   fprintf( logstream, "\t target: %s\n", query_param.target);
+  fprintf( logstream, "\t tid: %s\n", query_param.tid);
   fprintf( logstream, "\t fx,fy: %d, %d\n", query_param.fx, query_param.fy);
   fprintf( logstream, "\t rx,ry: %d, %d \t rw,rh: %d, %d\n", query_param.rx, query_param.ry, query_param.rw, query_param.rh);
   fprintf( logstream, "\t cnew: %d\n", query_param.cnew);
index b511a7114d01b5c45ab8d96dc5e3989bbc8c8e01..db46f332a728b7c7edc3d0c2a0af0d16bc201091 100644 (file)
@@ -35,6 +35,9 @@
 
 //! maximum length of target name
 #define MAX_LENOFTARGET 128
+//! maximum length of target identifier
+#define MAX_LENOFTID 30
 
 //! maximum length of channel identifier
 #define MAX_LENOFCID 30
@@ -48,6 +51,7 @@
 //! Query parameters
 typedef struct query_param{
   char target[MAX_LENOFTARGET];               //!< target name
+  char tid[MAX_LENOFTID];                     //!< target identifier
   int fx, fy;                                 //!< frame size (fx,fy)
   int rx, ry, rw, rh;                         //!< roi region
   char cid[MAX_LENOFCID];                     //!< channel identifier
index 74d5e0657a5e44e792dd204f036942d80bdf9343..1e44a041f74831f8d549482e405ee2efe2e3e783 100644 (file)
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <stdio.h>
 #include "session_manager.h"
+#include "target_manager.h"
 
 #ifdef SERVER
 #include "fcgi_stdio.h"
@@ -62,7 +63,7 @@ session_param_t * gene_session( sessionlist_param_t *sessionlist)
   session = (session_param_t *)malloc( sizeof(session_param_t));
 
   session->channellist = gene_channellist();
-  session->targetlist = gene_targetlist();
+  session->cachemodellist = gene_cachemodellist();
 
   session->next = NULL;
   
@@ -102,19 +103,19 @@ bool search_session_and_channel( char cid[],
   return false;
 }
 
-void insert_target_into_session( session_param_t *session, target_param_t *target)
+void insert_cachemodel_into_session( session_param_t *session, cachemodel_param_t *cachemodel)
 {
-  if(!target)
+  if(!cachemodel)
     return;
 
 #ifndef SERVER
-  fprintf( logstream, "local log: insert target into session %p\n", (void *)session);
+  fprintf( logstream, "local log: insert cachemodel into session\n");
 #endif
-  if( session->targetlist->first != NULL)
-    session->targetlist->last->next = target;
+  if( session->cachemodellist->first != NULL)
+    session->cachemodellist->last->next = cachemodel;
   else
-    session->targetlist->first = target;
-  session->targetlist->last = target;
+    session->cachemodellist->first = cachemodel;
+  session->cachemodellist->last = cachemodel;
 }
 
 bool delete_session( session_param_t **session, sessionlist_param_t *sessionlist)
@@ -138,7 +139,7 @@ bool delete_session( session_param_t **session, sessionlist_param_t *sessionlist
   }
   
   delete_channellist( &((*session)->channellist));
-  delete_targetlist ( &((*session)->targetlist));
+  delete_cachemodellist( &((*session)->cachemodellist));
 
 #ifndef SERVER
   fprintf( logstream, "local log: session: %p deleted!\n", (void *)(*session));
@@ -157,7 +158,7 @@ void delete_sessionlist( sessionlist_param_t **sessionlist)
     sessionNext=sessionPtr->next;
 
     delete_channellist( &(sessionPtr->channellist));
-    delete_targetlist ( &(sessionPtr->targetlist));
+    delete_cachemodellist( &(sessionPtr->cachemodellist));
 
 #ifndef SERVER
     fprintf( logstream, "local log: session: %p deleted!\n", (void *)sessionPtr);
@@ -176,6 +177,7 @@ void delete_sessionlist( sessionlist_param_t **sessionlist)
 void print_allsession( sessionlist_param_t *sessionlist)
 {
   session_param_t *ptr;
+  cachemodel_param_t *cachemodel;
   int i=0;
 
   fprintf( logstream, "SESSIONS info:\n");
@@ -184,7 +186,11 @@ void print_allsession( sessionlist_param_t *sessionlist)
   while( ptr != NULL){
     fprintf( logstream, "session No.%d\n", i++);
     print_allchannel( ptr->channellist);
-    print_alltarget( ptr->targetlist);
+    cachemodel = ptr->cachemodellist->first;
+    while( cachemodel){
+      print_target( cachemodel->target);
+      cachemodel = cachemodel->next;
+    }
     ptr=ptr->next;
   }
 }
index fba62ab1f12cce5c614d385a2a248293019f866f..d4d55e8237467101a84ea5d6f05f7d5f307e4632 100644 (file)
 
 #include "bool.h"
 #include "channel_manager.h"
-#include "target_manager.h"
+#include "cachemodel_manager.h"
 
 //! Session parameters
 typedef struct session_param{
-  channellist_param_t *channellist; //!< channel list pointer
-  targetlist_param_t  *targetlist;  //!< target  list pointer
-  struct session_param *next;       //!< pointer to the next session
+  channellist_param_t *channellist;        //!< channel list pointer
+  cachemodellist_param_t *cachemodellist; //!< cache list pointer
+  struct session_param *next;              //!< pointer to the next session
 } session_param_t;
 
 //! Session list parameters
@@ -80,12 +80,12 @@ bool search_session_and_channel( char cid[],
                                 channel_param_t **foundchannel);
 
 /**
- * insert a target into a session
+ * insert a cache model into a session
  *
- * @param[in] session session pointer
- * @param[in] target target pointer
+ * @param[in] session    session pointer
+ * @param[in] cachemodel cachemodel pointer
  */
-void insert_target_into_session( session_param_t *session, target_param_t *target);
+void insert_cachemodel_into_session( session_param_t *session, cachemodel_param_t *cachemodel);
 
 
 /**
index 43422e50181448bb993b2d620b71e6d1df976427..b1b34b70174cc8064ee7dda7aa75aacab1880b5d 100644 (file)
@@ -1,26 +1,32 @@
 SET(INDEXER_SRCS
-${CMAKE_CURRENT_SOURCE_DIR}/bio.c
-${CMAKE_CURRENT_SOURCE_DIR}/cio.c
-${CMAKE_CURRENT_SOURCE_DIR}/index_create.c
-${CMAKE_CURRENT_SOURCE_DIR}/int.c
-${CMAKE_CURRENT_SOURCE_DIR}/jp2.c
-${CMAKE_CURRENT_SOURCE_DIR}/jpip.c
-${CMAKE_CURRENT_SOURCE_DIR}/pi.c
-${CMAKE_CURRENT_SOURCE_DIR}/t2.c
-${CMAKE_CURRENT_SOURCE_DIR}/tcd.c
-${CMAKE_CURRENT_SOURCE_DIR}/tgt.c
+${CMAKE_CURRENT_SOURCE_DIR}/j2k_to_idxjp2.c
+${CMAKE_CURRENT_SOURCE_DIR}/cidx_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/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}/phix_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/ppix_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/thix_manager.c
+${CMAKE_CURRENT_SOURCE_DIR}/tpix_manager.c
 )
 
+# Headers file are located here:
+INCLUDE_DIRECTORIES(
+  ${OPENJPEG_SOURCE_DIR}/libopenjpeg
+  )
+
 # Build executable
 
-ADD_EXECUTABLE(index_create ${INDEXER_SRCS})
+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(index_create m)
+  TARGET_LINK_LIBRARIES(j2k_to_idxjp2 m)
 ENDIF(UNIX)
 # Install exe
-INSTALL(TARGETS index_create
+INSTALL(TARGETS j2k_to_idxjp2
   EXPORT OpenJPEGTargets
   DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
-)
\ No newline at end of file
+)
index c0803e90fcd8266ff50e37df369dae6756a2fae8..8207020dbe5b7da4a94bfb2aa9f8a7e2abb8d336 100644 (file)
@@ -1,34 +1,32 @@
-MAINTAINERCLEANFILES = Makefile.in\r
-\r
-bin_PROGRAMS = index_create\r
-\r
-index_create_CPPFLAGS = \\r
--I. \\r
--I$(top_srcdir)/applications/libopenjpip/tools/indexer \\r
--I$(top_builddir)/applications/libopenjpip/tools/indexer\r
-index_create_CFLAGS = \r
-index_create_LDADD = -lm\r
-index_create_SOURCES = \\r
-bio.c \\r
-bio.h \\r
-cio.c \\r
-cio.h \\r
-index_create.c \\r
-int.c \\r
-int.h \\r
-j2k.h \\r
-jp2.c \\r
-jp2.h \\r
-jpip.c \\r
-jpip.h \\r
-pi.c \\r
-pi.h \\r
-t2.c \\r
-t2.h \\r
-tcd.c \\r
-tcd.h \\r
-tgt.c \\r
-tgt.h\r
-\r
-install-data-hook:\r
-       @echo -e " (B)\t$(bindir)/index_create$(EXEEXT)" >> $(top_builddir)/report.txt\r
+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 = \
+cidx_manager.c \
+cidx_manager.h \
+cio_ext.c \
+cio_ext.h \
+j2k_to_idxjp2.c \
+j2k_to_idxjp2.h \
+event_mgr_handler.c \
+event_mgr_handler.h \
+idxjp2_manager.c \
+j2k_decoder.c \
+indexbox_manager.h \
+phix_manager.c \
+ppix_manager.c \
+thix_manager.c \
+tpix_manager.c 
+
+install-data-hook:
+       @echo -e " (B)\t$(bindir)/j2k_to_idxjp2$(EXEEXT)" >> $(top_builddir)/report.txt
+
index 1003cb61f35cb3b5a0ea80c5c35fbffe8293261c..4ea2b8c67871e7aeadd4d824b9a7ddb4d66b2094 100644 (file)
@@ -1,23 +1,14 @@
-CC = gcc
+INCDIR = ../../../../libopenjpeg
+LIBDIR = $(INCDIR)/.libs
+LIBFNAME = $(LIBDIR)/libopenjpeg.a
+CFLAGS  = -O3 -Wall -I$(INCDIR)
+LDFLAGS = -L$(LIBDIR) -lm 
 
-LDFLAGS = -lm
-CFLAGS = -Wall
+ALL = j2k_to_idxjp2
 
-all: index_create
-
-
-bio.o : bio.c bio.h
-cio.o : cio.c cio.h
-int.o : int.c
-pi.o  : pi.c pi.h int.h
-index_create.o : index_create.c j2k.h cio.h tcd.h int.h
-t2.o  : t2.c t2.h tcd.h bio.h j2k.h pi.h tgt.h int.h cio.h
-tgt.o : tgt.c bio.h tgt.h
-tcd.o : tcd.c tcd.h t2.h int.h
-jpip.o : jpip.c j2k.h cio.h tcd.h int.h
-jp2.o : jp2.c j2k.h cio.h tcd.h int.h
-
-index_create : bio.o cio.o int.o pi.o t2.o tgt.o tcd.o index_create.o jpip.o jp2.o
+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)
+       $(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 $@
 clean:
-       rm -rf index_create *.o *.*~ *~ core.*
+       rm -f $(ALL) *.o *~
diff --git a/applications/jpip/tools/indexer/bio.c b/applications/jpip/tools/indexer/bio.c
deleted file mode 100644 (file)
index 2c989e5..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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 "bio.h"
-#include <setjmp.h>
-
-static unsigned char *bio_start, *bio_end, *bio_bp;
-static unsigned int bio_buf;
-static int bio_ct;
-
-extern jmp_buf j2k_error;
-
-/// <summary>
-/// Number of bytes written.
-/// </summary>
-int bio_numbytes() {
-    return bio_bp-bio_start;
-}
-
-/// <summary>
-/// Init decoder.
-/// </summary>
-/// <param name="bp">Input buffer</param>
-/// <param name="len">Input buffer length</param>
-void bio_init_dec(unsigned char *bp, int len) {
-    bio_start=bp;
-    bio_end=bp+len;
-    bio_bp=bp;
-    bio_buf=0;
-    bio_ct=0;
-}
-
-int bio_byteout()
-{
-       bio_buf = (bio_buf << 8) & 0xffff;
-       bio_ct = bio_buf == 0xff00 ? 7 : 8;
-       if (bio_bp >= bio_end)
-               return 1;
-       *bio_bp++ = bio_buf >> 8;
-       return 0;
-}
-
-/// <summary>
-/// Read byte. 
-/// </summary>
-int bio_bytein() {
-    bio_buf=(bio_buf<<8)&0xffff;
-    bio_ct=bio_buf==0xff00?7:8;
-    if (bio_bp>=bio_end) return 1; //longjmp(j2k_error, 1);
-    bio_buf|=*bio_bp++;
-    return 0;
-}
-
-/// <summary>
-/// Read bit.
-/// </summary>
-int bio_getbit() {
-    if (bio_ct==0) {
-        bio_bytein();
-    }
-    bio_ct--;
-    return (bio_buf>>bio_ct)&1;
-}
-
-/// <summary>
-/// Read bits.
-/// </summary>
-/// <param name="n">Number of bits to read</param>
-int bio_read(int n) {
-    int i, v;
-    v=0;
-    for (i=n-1; i>=0; i--) {
-        v+=bio_getbit()<<i;
-    }
-    return v;
-}
-
-/// <summary>
-/// Flush bits.
-/// </summary>
-int bio_flush() {
-    bio_ct=0;
-    bio_byteout();
-    if (bio_ct==7) {
-        bio_ct=0;
-       if ( bio_byteout()) return 1;;
-    }
-    return 0;
-}
-
-/// <summary>
-/// </summary>
-int bio_inalign() {
-    bio_ct=0;
-    if ((bio_buf&0xff)==0xff) {
-       if( bio_bytein()) return 1;
-        bio_ct=0;
-    }
-    return 0;
-}
diff --git a/applications/jpip/tools/indexer/cidx_manager.c b/applications/jpip/tools/indexer/cidx_manager.c
new file mode 100644 (file)
index 0000000..b8112da
--- /dev/null
@@ -0,0 +1,213 @@
+/*
+ * $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;
+}
similarity index 62%
rename from applications/jpip/tools/indexer/cio.h
rename to applications/jpip/tools/indexer/cidx_manager.h
index 3e29789760ca4a98baa8c98fcb3b098df79894a5..f83a98020d881f97d2d17018ff032b6e94cacf92 100644 (file)
@@ -1,7 +1,10 @@
 /*
- * Copyright (c) 2001-2002, David Janssens
+ * $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) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
+ * Copyright (c) 2010-2011, Kaori Hagihara
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef __CIO_H
-#define __CIO_H
-
-int cio_tell();
-void cio_seek(int pos);
-int cio_numbytes();
-int cio_numbytesleft();
-unsigned char *cio_getbp();
-void cio_init(unsigned char *bp, int len);
-/* void cio_write(unsigned int v, int n); */
-void cio_write(long long v, int n);
-/* unsigned int cio_read(int n); */
-long long cio_read(int n);
-void cio_skip(int n);
-
-#endif
+/*! \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_ */
diff --git a/applications/jpip/tools/indexer/cio.c b/applications/jpip/tools/indexer/cio.c
deleted file mode 100644 (file)
index 29f160e..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "cio.h"
-#include <setjmp.h>
-
-static unsigned char *cio_start, *cio_end, *cio_bp;
-
-extern jmp_buf j2k_error;
-
-/// <summary>
-/// Number of bytes written.
-/// </summary>
-int cio_numbytes() {
-    return cio_bp-cio_start;
-}
-
-/// <summary>
-/// Get position in byte stream.
-/// </summary>
-int cio_tell() {
-    return cio_bp-cio_start;
-}
-
-/// <summary>
-/// Set position in byte stream.
-/// </summary>
-void cio_seek(int pos) {
-    cio_bp=cio_start+pos;
-}
-
-/// <summary>
-/// Number of bytes left before the end of the stream.
-/// </summary>
-int cio_numbytesleft() {
-    return cio_end-cio_bp;
-}
-
-/// <summary>
-/// Get pointer to the current position in the stream.
-/// </summary>
-unsigned char *cio_getbp() {
-    return cio_bp;
-}
-
-/// <summary>
-/// Initialize byte IO.
-/// </summary>
-void cio_init(unsigned char *bp, int len) {
-    cio_start=bp;
-    cio_end=bp+len;
-    cio_bp=bp;
-}
-
-/// <summary>
-/// Write a byte.
-/// </summary>
-void cio_byteout(unsigned char v) {
-  if (cio_bp>=cio_end) longjmp(j2k_error, 1);
-  *cio_bp++=v;
-    
-}
-
-/// <summary>
-/// Read a byte.
-/// </summary>
-unsigned char cio_bytein() {
-    if (cio_bp>=cio_end) longjmp(j2k_error, 1);
-    return *cio_bp++;
-}
-
-/// <summary>
-/// Write a byte.
-/// </summary>
-//void cio_write(unsigned int v, int n) {
-void cio_write(long long v, int n) {
-    int i;
-    for (i=n-1; i>=0; i--) 
-      {
-       cio_byteout((unsigned char)((v>>(i<<3))&0xff));
-      }
-}
-
-/// <summary>
-/// Read some bytes.
-/// </summary>
-/* unsigned int cio_read(int n) { */
-long long cio_read(int n) {
-    int i;
-    /*unsigned int v;*/
-    long long v;
-    v=0;
-    for (i=n-1; i>=0; i--) {
-      v+=cio_bytein()<<(i<<3);
-    }
-    return v;
-}
-
-/// <summary>
-/// Write some bytes.
-/// </summary>
-void cio_skip(int n) {
-    cio_bp+=n;
-}
similarity index 57%
rename from applications/jpip/tools/indexer/jpip.h
rename to applications/jpip/tools/indexer/cio_ext.c
index 84df3554604fcb553bce78884c22d5623dc4c1cc..d507cc9fddc96252dec78e266023728ebd6d71d8 100644 (file)
@@ -1,6 +1,13 @@
 /*
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
+ * $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
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef __JPIP_H
-#define __JPIP_H
-
-#include "j2k.h"
+#include "cio_ext.h"
+#include "event.h"
 
-// Codestream index box (superbox)
-int jpip_write_cidx(int offset, info_image_t img, j2k_cp_t *j2k_cp, int version);
 
-// Index Finder Box
-void jpip_write_iptr(int offset, int length);
+/*
+ * Write a byte.
+ */
+opj_bool cio_ext_byteout(opj_cio_t *cio, unsigned char v);
 
-// File Index Box
-int jpip_write_fidx(int offset_jp2c, int length_jp2c, int offset_idx, int length_idx);
+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;
+}
 
-#endif
+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;
+}
similarity index 65%
rename from applications/jpip/tools/indexer/t2.h
rename to applications/jpip/tools/indexer/cio_ext.h
index f49510794700c9832ad8e2f8e2f8a725155fa5b5..42f138df6335f619dbd87297d62c88067c551d51 100644 (file)
@@ -1,7 +1,9 @@
 /*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
+ * $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
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef __T2_H
-#define __T2_H
+/*! \file
+ *  \brief Additional functions to libopenjpeg/cio.h
+ */
+
+#ifndef  CIO_EXT_H_
+# define CIO_EXT_H_
+
+#include "openjpeg.h"
 
-#include "tcd.h"
-#include "j2k.h"
 
 /*
- * Decode the packets of a tile from a source buffer
- * src: the source buffer
- * len: length of the source buffer
- * img: destination image
- * cp: image coding parameters
- * tileno: number that identifies the tile for which to decode the packets
- * tile: tile for which to decode the packets
+ * 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
  */
-int t2_decode_packets(unsigned char *src, int len, j2k_image_t *img, j2k_cp_t *cp, int tileno, tcd_tile_t *tile, info_image_t *imgg);
+unsigned int cio_ext_write( opj_cio_t *cio, unsigned long long int v, int n);
 
-#endif
+#endif      /* !CIO_EXT_H_ */
diff --git a/applications/jpip/tools/indexer/event_mgr_handler.c b/applications/jpip/tools/indexer/event_mgr_handler.c
new file mode 100644 (file)
index 0000000..d6d57ba
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * $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);
+}
similarity index 74%
rename from applications/jpip/tools/indexer/jp2.h
rename to applications/jpip/tools/indexer/event_mgr_handler.h
index d5510f5aa142b17df7d782598327f10695d2a15f..1fd40f1cbc3e59c85d04248096f3ffbc1013fe34 100644 (file)
@@ -1,6 +1,9 @@
 /*
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
+ * $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
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-#ifndef __JP2_H
-#define __JP2_H
-
-#include "j2k.h"
-
-void jp2_write_url(char *Idx_file);
-
-void jp2_write_dbtl(char *Idx_file);
 
-void jp2_write_jp2h(j2k_image_t *j2k_img);
+#ifndef  EVENT_MG_HANDLER_H_
+# define EVENT_MG_HANDLER_H_
 
-void jp2_write_ftyp();
+#include "openjpeg.h"
 
-int jp2_write_jp2c(char *J2K_file);
-
-void jp2_write_jp();
+/* 
+ * Set default event message handler
+ *
+ * @return event message handler
+ */
+opj_event_mgr_t set_default_event_mgr();
 
-#endif
+#endif      /* !EVENT_MG_HANDLER_H_ */
diff --git a/applications/jpip/tools/indexer/idxjp2_manager.c b/applications/jpip/tools/indexer/idxjp2_manager.c
new file mode 100644 (file)
index 0000000..08c9217
--- /dev/null
@@ -0,0 +1,306 @@
+/*
+ * $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 <string.h>
+#include <stdlib.h>
+#include "event_mgr_handler.h"
+#include "cio.h"
+#include "cio_ext.h"
+#include "j2k_to_idxjp2.h"
+#include "cidx_manager.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)
+{
+  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(&parameters);
+  
+  /* 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, &parameters, 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( (opj_jp2_t*)cinfo->jp2_handle, 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);
+}
+
+/* 
+ * 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);
+}
diff --git a/applications/jpip/tools/indexer/index_create.c b/applications/jpip/tools/indexer/index_create.c
deleted file mode 100644 (file)
index 1e90152..0000000
+++ /dev/null
@@ -1,1227 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003-2004, Yannick Verschueren
- * Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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 <string.h>
-#include <setjmp.h>
-#include <math.h>
-#include <unistd.h>
-
-#include "j2k.h"
-#include "cio.h"
-#include "tcd.h"
-#include "int.h"
-#include "jpip.h"
-#include "jp2.h"
-
-#define J2K_MS_SOC 0xff4f
-#define J2K_MS_SOT 0xff90
-#define J2K_MS_SOD 0xff93
-#define J2K_MS_EOC 0xffd9
-#define J2K_MS_SIZ 0xff51
-#define J2K_MS_COD 0xff52
-#define J2K_MS_COC 0xff53
-#define J2K_MS_RGN 0xff5e
-#define J2K_MS_QCD 0xff5c
-#define J2K_MS_QCC 0xff5d
-#define J2K_MS_POC 0xff5f
-#define J2K_MS_TLM 0xff55
-#define J2K_MS_PLM 0xff57
-#define J2K_MS_PLT 0xff58
-#define J2K_MS_PPM 0xff60
-#define J2K_MS_PPT 0xff61
-#define J2K_MS_SOP 0xff91
-#define J2K_MS_EPH 0xff92
-#define J2K_MS_CRG 0xff63
-#define J2K_MS_COM 0xff64
-
-#define J2K_STATE_MHSOC 0x0001
-#define J2K_STATE_MHSIZ 0x0002
-#define J2K_STATE_MH 0x0004
-#define J2K_STATE_TPHSOT 0x0008
-#define J2K_STATE_TPH 0x0010
-#define J2K_STATE_MT 0x0020
-
-#define START_NB 10
-#define INCREMENT 5
-
-jmp_buf j2k_error;
-
-static int j2k_state;
-static int j2k_curtileno;
-static j2k_tcp_t j2k_default_tcp;
-static unsigned char *j2k_eot;
-
-static j2k_image_t *j2k_img;
-static j2k_cp_t *j2k_cp;
-
-static unsigned char **j2k_tile_data;
-static int *j2k_tile_len;
-
-static info_image_t img;
-
-
-void j2k_clean() {
-  int tileno = 0;
-  int compno=0, resno=0, precno=0;
-
-  tcd_free(j2k_img, j2k_cp);
-  for (tileno = 0; tileno < j2k_cp->tw * j2k_cp->th; tileno++) {
-    info_tile_t *tile_Idx = &img.tile[tileno];
-    
-    for (compno = 0; compno < img.Comp; compno++)
-      {
-       info_compo_t *compo_Idx = &tile_Idx->compo[compno];
-       for(resno = 0; resno < img.Decomposition + 1; resno++)
-         {
-           info_reso_t *reso_Idx = &compo_Idx->reso[resno];
-           for (precno = 0; precno < img.tile[tileno].pw * img.tile[tileno].ph; precno++)
-             {
-               info_prec_t *prec_Idx = &reso_Idx->prec[precno];
-               free(prec_Idx->layer);
-             }
-           free(reso_Idx->prec);
-         }
-       free(compo_Idx->reso);
-      }
-    free(tile_Idx->compo);
-    free(tile_Idx->marker);
-    free(tile_Idx->tile_parts);
-    free(tile_Idx->marker_mul.COC);
-    free(tile_Idx->marker_mul.RGN);
-    free(tile_Idx->marker_mul.QCC);
-    free(tile_Idx->marker_mul.PLT);
-    free(tile_Idx->marker_mul.PPT);
-    free(tile_Idx->marker_mul.COM);
-}
-  free(img.tile);
-  free(img.marker);
-  free(img.marker_mul.COC);
-  free(img.marker_mul.RGN);
-  free(img.marker_mul.QCC);
-  free(img.marker_mul.PLM);
-  free(img.marker_mul.PPM);
-  free(img.marker_mul.COM);
-}
-
-
-
-void j2k_read_soc() {
-  j2k_state=J2K_STATE_MHSIZ;
-}
-
-
-
-void j2k_read_siz() {
-    int len, i;
-    info_tile_t *tile;
-
-    len = cio_read(2);
-
-    /* <INDEX> [MHIX BOX] */
-    img.marker[img.num_marker].type = J2K_MS_SIZ;
-    img.marker[img.num_marker].start_pos = cio_tell()-2;
-    img.marker[img.num_marker].len = len;
-    img.num_marker++;
-    /* </INDEX> [MHIX BOX] */
-    
-    cio_read(2);                      /* Rsiz (capabilities) */
-    j2k_img->x1 = cio_read(4);        /* Xsiz                */
-    j2k_img->y1 = cio_read(4);        /* Ysiz                */
-    j2k_img->x0 = cio_read(4);        /* X0siz               */
-    j2k_img->y0 = cio_read(4);        /* Y0siz               */
-    j2k_cp->tdx = cio_read(4);        /* XTsiz               */
-    j2k_cp->tdy = cio_read(4);        /* YTsiz               */
-    j2k_cp->tx0 = cio_read(4);        /* XT0siz              */
-    j2k_cp->ty0 = cio_read(4);        /* YTOsiz              */
-
-    j2k_img->numcomps = cio_read(2);  /* Csiz                */
-    j2k_img->comps = (j2k_comp_t*)malloc(j2k_img->numcomps * sizeof(j2k_comp_t));
-    for (i = 0; i < j2k_img->numcomps; i++) {
-        int tmp, w, h;
-        tmp = cio_read(1);
-        j2k_img->comps[i].prec = (tmp & 0x7f) + 1;
-        j2k_img->comps[i].sgnd = tmp >> 7;
-        j2k_img->comps[i].dx = cio_read(1);
-        j2k_img->comps[i].dy = cio_read(1);
-        w = int_ceildiv(j2k_img->x1-j2k_img->x0, j2k_img->comps[i].dx);
-        h = int_ceildiv(j2k_img->y1-j2k_img->y0, j2k_img->comps[i].dy);
-        j2k_img->comps[i].data = (int*)malloc(sizeof(int) * w * h);
-    }
-    j2k_cp->tw = int_ceildiv(j2k_img->x1 - j2k_cp->tx0, j2k_cp->tdx);
-    j2k_cp->th = int_ceildiv(j2k_img->y1 - j2k_cp->ty0, j2k_cp->tdy);
-
-    j2k_cp->tcps = (j2k_tcp_t*)calloc((j2k_cp->tw * j2k_cp->th), sizeof(j2k_tcp_t));
-
-    for (i = 0; i < j2k_cp->tw * j2k_cp->th; i++)
-      {
-       j2k_cp->tcps[i].POC = 0;
-       j2k_cp->tcps[i].numpocs = 0;
-       // j2k_cp->tcps[i].first=1;
-      }
-
-    /* Initialization for PPM marker */
-    j2k_cp->ppm = 0;
-    j2k_cp->ppm_data = NULL;
-    j2k_cp->ppm_previous = 0;
-    j2k_cp->ppm_store = 0;
-
-    j2k_default_tcp.tccps = (j2k_tccp_t*)malloc(j2k_img->numcomps * sizeof(j2k_tccp_t));
-    for (i = 0; i < j2k_cp->tw * j2k_cp->th; i++) {
-       j2k_cp->tcps[i].tccps = (j2k_tccp_t*)malloc(j2k_img->numcomps * sizeof(j2k_tccp_t));
-    }
-    j2k_tile_data = (unsigned char**)calloc(j2k_cp->tw * j2k_cp->th, sizeof(char*));
-    j2k_tile_len = (int*)calloc(j2k_cp->tw * j2k_cp->th, sizeof(int));
-    j2k_state = J2K_STATE_MH;
-
-    /* <INDEX> */
-    img.Im_w = j2k_img->x1 - j2k_img->x0;
-    img.Im_h = j2k_img->y1 - j2k_img->y0;
-    img.Tile_x = j2k_cp->tdx;
-    img.Tile_y = j2k_cp->tdy;
-    img.Comp = j2k_img->numcomps;
-    img.tw = j2k_cp->tw;
-    img.th = j2k_cp->th;
-    img.tile = (info_tile_t*)malloc(img.tw * img.th * sizeof(info_tile_t));
-
-    for (i = 0; i < img.tw * img.th; i++)
-      {
-       tile = &img.tile[i];
-       tile->marker = (info_marker_t*)malloc(32 * sizeof(info_marker_t));
-       tile->num_marker = 0;
-       tile->marker_mul.num_COC = 0;
-       tile->marker_mul.CzCOC = START_NB;
-       tile->marker_mul.num_RGN = 0;
-       tile->marker_mul.CzRGN = START_NB;
-       tile->marker_mul.num_QCC = 0;
-       tile->marker_mul.CzQCC = START_NB;
-       tile->marker_mul.num_PLT = 0;
-       tile->marker_mul.CzPLT = START_NB;
-       tile->marker_mul.num_PPT = 0;
-       tile->marker_mul.CzPPT = START_NB;
-       tile->marker_mul.num_COM = 0;
-       tile->marker_mul.CzCOM = START_NB;
-      }
-    /* </INDEX> */
-
-
- }
-
-void j2k_read_com() {
-    int len;
-    info_tile_t *tile;
-    info_marker_t *tmp;
-
-    len = cio_read(2);
-
-    /* <INDEX> [MHIX BOX] */
-    if (j2k_state == J2K_STATE_MH)
-      {
-       if (!img.marker_mul.num_COM) 
-         img.marker_mul.COM = (info_marker_t*)malloc(img.marker_mul.CzCOM * sizeof(info_marker_t));
-       if (img.marker_mul.num_COM >= img.marker_mul.CzCOM)
-         {
-           tmp = (info_marker_t*)malloc(2 * img.marker_mul.CzCOM * sizeof(info_marker_t));
-           memcpy(tmp,img.marker_mul.COM,img.marker_mul.CzCOM);
-           img.marker_mul.CzCOM *= 2;
-           free(img.marker_mul.COM);
-           img.marker_mul.COM = tmp;
-         }
-
-       img.marker_mul.COM[img.marker_mul.num_COM].type = J2K_MS_COM;
-       img.marker_mul.COM[img.marker_mul.num_COM].start_pos = cio_tell()-2;
-       img.marker_mul.COM[img.marker_mul.num_COM].len = len;
-       img.marker_mul.num_COM++;
-      } else
-       {
-         tile = &img.tile[j2k_curtileno];
-         if (!tile->marker_mul.num_COM)
-           tile->marker_mul.COM = (info_marker_t*)calloc(START_NB, sizeof(info_marker_t));
-         if (tile->marker_mul.num_COM >= tile->marker_mul.CzCOM)
-           {
-             tmp = (info_marker_t*)malloc(2 * tile->marker_mul.CzCOM * sizeof(info_marker_t));
-             memcpy(tmp,tile->marker_mul.COM,tile->marker_mul.CzCOM);
-             tile->marker_mul.CzCOM *= 2;
-             free(tile->marker_mul.COM);
-             tile->marker_mul.COM = tmp;
-           }
-         tile->marker_mul.COM[tile->marker_mul.num_COM].type = J2K_MS_COM;
-         tile->marker_mul.COM[tile->marker_mul.num_COM].start_pos = cio_tell()-2;
-         tile->marker_mul.COM[tile->marker_mul.num_COM].len = len;
-         tile->marker_mul.num_COM++;
-       }
-    /* </INDEX> [MHIX BOX] */
-
-    cio_skip(len - 2);
-}
-
-
-
-
-void j2k_read_cox(int compno) {
-    int i;
-    j2k_tcp_t *tcp;
-    j2k_tccp_t *tccp;
-
-    tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
-    tccp = &tcp->tccps[compno];
-    tccp->numresolutions = cio_read(1) + 1;
-
-    img.Decomposition = tccp->numresolutions - 1; /* <INDEX> */
-
-    tccp->cblkw = cio_read(1) + 2;
-    tccp->cblkh = cio_read(1) + 2;
-    tccp->cblksty = cio_read(1);
-    tccp->qmfbid = cio_read(1);
-    if (tccp->csty&J2K_CP_CSTY_PRT) {
-        for (i = 0; i < tccp->numresolutions; i++) {
-            int tmp = cio_read(1);
-            tccp->prcw[i] = tmp&0xf;
-            tccp->prch[i] = tmp>>4; 
-        }
-    }
-}
-
-
-
-
-void j2k_read_cod() {
-    int len, i, pos;
-    j2k_tcp_t *tcp;
-    info_tile_t *tile;
-
-    tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
-    len = cio_read(2);
-
-    /* <INDEX> [MHIX BOX] */
-    if (j2k_state == J2K_STATE_MH)
-      {
-       img.marker[img.num_marker].type = J2K_MS_COD;
-       img.marker[img.num_marker].start_pos = cio_tell()-2;
-       img.marker[img.num_marker].len = len;
-       img.num_marker++;
-      }
-    else
-      {
-       tile = &img.tile[j2k_curtileno];
-       tile->marker[tile->num_marker].type = J2K_MS_COD;
-       tile->marker[tile->num_marker].start_pos = cio_tell()-2;
-       tile->marker[tile->num_marker].len = len;
-       tile->num_marker++;
-  }
-    /* </INDEX> [MHIX BOX] */
-    
-    tcp->csty = cio_read(1);
-    tcp->prg = cio_read(1);
-    tcp->numlayers = cio_read(2);
-    tcp->mct = cio_read(1);
-
-    pos = cio_tell();
-    for (i = 0; i < j2k_img->numcomps; i++) {
-        tcp->tccps[i].csty = tcp->csty&J2K_CP_CSTY_PRT;
-        cio_seek(pos);
-        j2k_read_cox(i);
-    }
-    
-    /* <INDEX> */
-    img.Prog = tcp->prg;
-    img.Layer = tcp->numlayers;
-    /* </INDEX> */
-}
-
-
-
-
-void j2k_read_coc() {
-    int len, compno;
-    j2k_tcp_t *tcp;
-    info_tile_t *tile;
-    info_marker_t *tmp;
-
-    tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
-    len = cio_read(2);
-    
-    /* <INDEX> [MHIX BOX] */
-    if (j2k_state == J2K_STATE_MH)
-      {
-       if (!img.marker_mul.num_COC)
-         img.marker_mul.COC = (info_marker_t*)malloc(img.marker_mul.CzCOC * sizeof(info_marker_t));
-       if (img.marker_mul.num_COC >= img.marker_mul.CzCOC)
-         {
-           tmp = (info_marker_t*)malloc((INCREMENT + img.marker_mul.CzCOC) * sizeof(info_marker_t));
-           memcpy(tmp,img.marker_mul.COC,img.marker_mul.CzCOC);
-           img.marker_mul.CzCOC += INCREMENT;
-           free(img.marker_mul.COC);
-           img.marker_mul.COC = tmp;
-         }
-       img.marker_mul.COC[img.marker_mul.num_COC].type = J2K_MS_COC;
-       img.marker_mul.COC[img.marker_mul.num_COC].start_pos = cio_tell()-2;
-       img.marker_mul.COC[img.marker_mul.num_COC].len = len;
-       img.marker_mul.num_COC++;
-      } else
-       {
-         tile = &img.tile[j2k_curtileno];
-         if (!tile->marker_mul.num_COC)
-           tile->marker_mul.COC = (info_marker_t*)malloc(tile->marker_mul.CzCOC * sizeof(info_marker_t));
-         if (tile->marker_mul.num_COC >= tile->marker_mul.CzCOC)
-           {
-             tmp = (info_marker_t*)malloc((INCREMENT + tile->marker_mul.CzCOC) * sizeof(info_marker_t));
-             memcpy(tmp,tile->marker_mul.COC,tile->marker_mul.CzCOC);
-             tile->marker_mul.CzCOC += INCREMENT;
-             free(tile->marker_mul.COC);
-             tile->marker_mul.COC = tmp;
-           }
-         tile->marker_mul.COC[tile->marker_mul.num_COC].type = J2K_MS_COC;
-         tile->marker_mul.COC[tile->marker_mul.num_COC].start_pos = cio_tell() - 2;
-         tile->marker_mul.COC[tile->marker_mul.num_COC].len = len;
-         tile->marker_mul.num_COC++;
-       }
-    /* </INDEX> [MHIX BOX] */
-    
-    compno =cio_read(j2k_img->numcomps <= 256 ? 1 : 2);
-
-    tcp->tccps[compno].csty = cio_read(1);
-    j2k_read_cox(compno);
-}
-
-
-
-
-void j2k_read_qcx(int compno, int len) {
-    int tmp;
-    j2k_tcp_t *tcp;
-    j2k_tccp_t *tccp;
-    int bandno, numbands;
-
-    tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
-    tccp = &tcp->tccps[compno];
-    tmp = cio_read(1);
-    tccp->qntsty = tmp & 0x1f;
-    tccp->numgbits = tmp >> 5;
-    numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT ? len - 1 : (len - 1) / 2);
-    for (bandno = 0; bandno < numbands; bandno++) {
-        int expn, mant;
-        if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { /* WHY STEPSIZES WHEN NOQNT ? */
-            expn = cio_read(1) >> 3;
-            mant = 0;
-        } else {
-            tmp = cio_read(2);
-            expn = tmp >> 11;
-            mant = tmp & 0x7ff;
-        }
-        tccp->stepsizes[bandno].expn = expn;
-        tccp->stepsizes[bandno].mant = mant;
-    }
-}
-
-
-
-
-void j2k_read_qcd() {
-    int len, i, pos;
-    info_tile_t *tile;
-
-    len = cio_read(2);    
-
-    /* <INDEX> [MHIX BOX] */
-    if (j2k_state == J2K_STATE_MH)
-      {
-       img.marker[img.num_marker].type = J2K_MS_QCD;
-       img.marker[img.num_marker].start_pos = cio_tell()-2;
-       img.marker[img.num_marker].len = len;
-       img.num_marker++;
-      }         else
-       {
-         tile = &img.tile[j2k_curtileno];
-         tile->marker[tile->num_marker].type = J2K_MS_QCD;
-         tile->marker[tile->num_marker].start_pos = cio_tell()-2;
-         tile->marker[tile->num_marker].len = len;
-         tile->num_marker++;
-       }
-    /* </INDEX> [MHIX BOX] */
-    
-    
-    pos=cio_tell();
-    for (i = 0; i < j2k_img->numcomps; i++) {
-        cio_seek(pos);
-        j2k_read_qcx(i, len - 2);
-    }
-}
-
-
-
-
-void j2k_read_qcc() {
-  int len, compno;
-  info_tile_t *tile;
-  info_marker_t *tmp;
-
-  len = cio_read(2);  
-  /* <INDEX> [MHIX BOX] */
-  if (j2k_state == J2K_STATE_MH)
-    {
-      if (!img.marker_mul.num_QCC)
-       img.marker_mul.QCC = (info_marker_t*)malloc(img.marker_mul.CzQCC * sizeof(info_marker_t));
-       if (img.marker_mul.num_QCC >= img.marker_mul.CzQCC)
-         {
-           tmp = (info_marker_t*)malloc((INCREMENT + img.marker_mul.CzQCC) * sizeof(info_marker_t));
-           memcpy(tmp,img.marker_mul.QCC,img.marker_mul.CzQCC);
-           img.marker_mul.CzQCC += INCREMENT;
-           free(img.marker_mul.QCC);
-           img.marker_mul.QCC = tmp;
-         }
-      img.marker_mul.QCC[img.marker_mul.num_QCC].type = J2K_MS_QCC;
-      img.marker_mul.QCC[img.marker_mul.num_QCC].start_pos = cio_tell() - 2;
-      img.marker_mul.QCC[img.marker_mul.num_QCC].len = len;
-      img.marker_mul.num_QCC++;
-    } else
-      {
-       tile = &img.tile[j2k_curtileno];
-       if (!tile->marker_mul.num_QCC)
-         tile->marker_mul.QCC = (info_marker_t*)malloc(tile->marker_mul.CzQCC * sizeof(info_marker_t));
-       if (tile->marker_mul.num_QCC >= tile->marker_mul.CzQCC)
-         {
-           tmp = (info_marker_t*)malloc((INCREMENT + tile->marker_mul.CzQCC) * sizeof(info_marker_t));
-           memcpy(tmp,tile->marker_mul.QCC,tile->marker_mul.CzQCC);
-           tile->marker_mul.CzQCC += INCREMENT;
-           free(tile->marker_mul.QCC);
-           tile->marker_mul.QCC = tmp;
-         }
-       tile->marker_mul.QCC[tile->marker_mul.num_QCC].type = J2K_MS_QCC;
-       tile->marker_mul.QCC[tile->marker_mul.num_QCC].start_pos = cio_tell()-2;
-       tile->marker_mul.QCC[tile->marker_mul.num_QCC].len = len;
-       tile->marker_mul.num_QCC++;
-      }
-  /* </INDEX> [MHIX BOX] */
-  compno = cio_read(j2k_img->numcomps <= 256 ? 1 : 2);
-  j2k_read_qcx(compno, len - 2 - (j2k_img->numcomps <= 256 ? 1 : 2));
-}
-
-
-
-
-void j2k_read_poc() {
-  int len, numpchgs, i, old_poc;
-  j2k_tcp_t *tcp;
-  j2k_tccp_t *tccp;
-  info_tile_t *tile;
-
-  tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
-  old_poc = tcp->POC ? tcp->numpocs+1 : 0;
-  tcp->POC = 1;
-  tccp = &tcp->tccps[0];
-  len = cio_read(2);
-  
-  /* <INDEX> [MHIX BOX] */
-  if (j2k_state == J2K_STATE_MH)
-    {
-      img.marker[img.num_marker].type = J2K_MS_POC;
-      img.marker[img.num_marker].start_pos = cio_tell()-2;
-      img.marker[img.num_marker].len = len;
-      img.num_marker++;
-    } else
-      {
-       tile = &img.tile[j2k_curtileno];
-       tile->marker[tile->num_marker].type = J2K_MS_POC;
-       tile->marker[tile->num_marker].start_pos = cio_tell()-2;
-       tile->marker[tile->num_marker].len = len;
-       tile->num_marker++;
-      }
-  /* </INDEX> [MHIX BOX] */
-
-    numpchgs = (len - 2) / (5 + 2 * (j2k_img->numcomps <= 256 ? 1 : 2));
-    for (i = 0; i < numpchgs; i++) {
-      j2k_poc_t *poc;
-      poc = &tcp->pocs[i];
-      poc->resno0 = cio_read(1);
-      poc->compno0 = cio_read(j2k_img->numcomps <= 256 ? 1 : 2);
-      poc->layno1 = int_min(cio_read(2), tcp->numlayers);
-      poc->resno1 = int_min(cio_read(1), tccp->numresolutions);
-      poc->compno1 = int_min(cio_read(j2k_img->numcomps <= 256 ? 1 : 2), j2k_img->numcomps);
-      poc->prg = cio_read(1);
-    }
-
-    tcp->numpocs = numpchgs + old_poc - 1;
-}
-
-
-
-
-void j2k_read_crg() {
-    int len, i, Xcrg_i, Ycrg_i;
-
-    len = cio_read(2);
-
-    /* <INDEX> [MHIX BOX] */
-    img.marker[img.num_marker].type = J2K_MS_CRG;
-    img.marker[img.num_marker].start_pos = cio_tell()-2;
-    img.marker[img.num_marker].len = len;
-    img.num_marker++;
-    /* </INDEX> [MHIX BOX] */
-
-    for (i = 0; i < j2k_img->numcomps; i++)
-      {  
-       Xcrg_i = cio_read(2);
-       Ycrg_i = cio_read(2);
-      }
-}
-
-
-
-
-void j2k_read_tlm() {
-    int len, Ztlm, Stlm, ST, SP, tile_tlm, i;
-    long int Ttlm_i, Ptlm_i;
-    info_marker_t *tmp;
-
-    len = cio_read(2);
-
-    /* <INDEX> [MHIX BOX] */
-    if (!img.marker_mul.num_TLM)
-      img.marker_mul.TLM = (info_marker_t*)malloc(img.marker_mul.CzTLM * sizeof(info_marker_t));
-    if (img.marker_mul.num_TLM >= img.marker_mul.CzTLM)
-      {
-       tmp = (info_marker_t*)malloc((INCREMENT + img.marker_mul.CzTLM) * sizeof(info_marker_t));
-       memcpy(tmp,img.marker_mul.TLM,img.marker_mul.CzTLM);
-       img.marker_mul.CzTLM += INCREMENT;
-       free(img.marker_mul.TLM);
-       img.marker_mul.TLM = tmp;
-      }
-    img.marker_mul.TLM[img.marker_mul.num_TLM].type = J2K_MS_TLM;
-    img.marker_mul.TLM[img.marker_mul.num_TLM].start_pos = cio_tell()-2;
-    img.marker_mul.TLM[img.marker_mul.num_TLM].len = len;
-    img.marker_mul.num_TLM++;
-    /* </INDEX> [MHIX BOX] */
-    
-    Ztlm = cio_read(1);
-    Stlm = cio_read(1);
-    ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02);
-    SP = (Stlm >> 6) & 0x01;
-    tile_tlm = (len - 4) / ((SP + 1) * 2 + ST);
-    for (i = 0; i < tile_tlm; i++)
-      {
-       Ttlm_i = cio_read(ST);
-       Ptlm_i = cio_read(SP ? 4 : 2);
-      }
-}
-
-
-
-
-void j2k_read_plm() {
-    int len, i, Z_plm, N_plm, add, packet_len=0;
-    info_marker_t *tmp;
-
-    len=cio_read(2);
-
-    /* <INDEX> [MHIX BOX] */
-    if (!img.marker_mul.num_PLM)
-      img.marker_mul.PLM = (info_marker_t*)malloc(img.marker_mul.CzPLM * sizeof(info_marker_t));
-    if (img.marker_mul.num_PLM >= img.marker_mul.CzPLM)
-      {
-       tmp = (info_marker_t*)malloc((INCREMENT + img.marker_mul.CzPLM) * sizeof(info_marker_t));
-       memcpy(tmp,img.marker_mul.PLM,img.marker_mul.CzPLM);
-       img.marker_mul.CzPLM += INCREMENT;
-       free(img.marker_mul.PLM);
-       img.marker_mul.PLM = tmp;
-      }
-    img.marker_mul.PLM[img.marker_mul.num_PLM].type = J2K_MS_PLM;
-    img.marker_mul.PLM[img.marker_mul.num_PLM].start_pos = cio_tell()-2;
-    img.marker_mul.PLM[img.marker_mul.num_PLM].len = len;
-    img.marker_mul.num_PLM++;
-    /* </INDEX> [MHIX BOX] */
-
-    Z_plm = cio_read(1);
-    len -= 3;
-    while (len > 0)
-      {
-       N_plm = cio_read(4);
-       len -= 4;
-       for (i = N_plm ; i > 0 ; i--)
-         {
-           add = cio_read(1);
-           len--;
-           packet_len = (packet_len << 7) + add;
-           if ((add & 0x80) == 0)
-             {
-               /* New packet */
-               packet_len = 0;
-             }
-           if (len <= 0) break;
-         } 
-      }
-}
-
-
-
-
-void j2k_read_plt() {
-    int len, i, Zplt, packet_len=0, add;
-    info_tile_t *tile;
-    info_marker_t *tmp;
-;
-    len = cio_read(2);
-    /* <INDEX> [MHIX BOX] */
-    tile = &img.tile[j2k_curtileno];
-    if (!tile->marker_mul.num_PLT)
-      tile->marker_mul.PLT = (info_marker_t*)malloc(tile->marker_mul.CzPLT * sizeof(info_marker_t));
-    if (tile->marker_mul.num_PLT >= tile->marker_mul.CzPLT)
-      {
-       tmp = (info_marker_t*)malloc((INCREMENT + tile->marker_mul.CzPLT) * sizeof(info_marker_t));
-       memcpy(tmp,tile->marker_mul.PLT,tile->marker_mul.CzPLT);
-       tile->marker_mul.CzPLT += INCREMENT;
-       free(tile->marker_mul.PLT);
-       tile->marker_mul.PLT = tmp;
-      }
-
-    tile->marker_mul.PLT[tile->marker_mul.num_PLT].type = J2K_MS_PLT;
-    tile->marker_mul.PLT[tile->marker_mul.num_PLT].start_pos = cio_tell()-2;
-    tile->marker_mul.PLT[tile->marker_mul.num_PLT].len = len;
-    tile->marker_mul.num_PLT++;
-    /* </INDEX> [MHIX BOX] */
-    
-    Zplt = cio_read(1);
-    for (i = len-3; i > 0; i--)
-      {
-       add = cio_read(1);
-       packet_len = (packet_len << 7) + add;
-       if ((add & 0x80) == 0)
-         {
-           /* New packet */
-           packet_len = 0;
-         }
-      }
-}
-
-
-
-
-void j2k_read_ppm() {
-    int len, Z_ppm, i, j;
-    int N_ppm;
-    info_marker_t *tmp;
-
-    len = cio_read(2);
-    
-    /* <INDEX> [MHIX BOX] */
-    if (!img.marker_mul.num_PPM)
-      img.marker_mul.PPM = (info_marker_t*)malloc(img.marker_mul.CzPPM * sizeof(info_marker_t));
-    if (img.marker_mul.num_PPM >= img.marker_mul.CzPPM)
-      {
-       tmp = (info_marker_t*)malloc((INCREMENT + img.marker_mul.CzPPM) * sizeof(info_marker_t));
-       memcpy(tmp,img.marker_mul.PPM,img.marker_mul.CzPPM);
-       img.marker_mul.CzPPM += INCREMENT;
-       free(img.marker_mul.PPM);
-       img.marker_mul.PPM = tmp;
-      }
-    img.marker_mul.PLM[img.marker_mul.num_PPM].type = J2K_MS_PPM;
-    img.marker_mul.PLM[img.marker_mul.num_PPM].start_pos = cio_tell()-2;
-    img.marker_mul.PLM[img.marker_mul.num_PPM].len = len;
-    img.marker_mul.num_PPM++;
-    /* </INDEX> [MHIX BOX] */
-    
-    j2k_cp->ppm = 1;
-    
-    Z_ppm = cio_read(1); /* Z_ppm */
-    len -= 3;
-    while (len > 0)
-      {
-       if (j2k_cp->ppm_previous == 0)
-         {
-           N_ppm = cio_read(4); /* N_ppm */
-           len -= 4;
-         } else
-           {
-             N_ppm = j2k_cp->ppm_previous;
-           }
-       
-       j = j2k_cp->ppm_store;
-       if (Z_ppm == 0) /* First PPM marker */
-         j2k_cp->ppm_data = (unsigned char*)calloc(N_ppm, sizeof(unsigned char));
-       else      /* NON-first PPM marker */
-         j2k_cp->ppm_data = (unsigned char*)realloc(j2k_cp->ppm_data, (N_ppm + j2k_cp->ppm_store) * sizeof(unsigned char));
-       
-       for (i = N_ppm ; i > 0 ; i--) /* Read packet header */
-         {
-           j2k_cp->ppm_data[j] = cio_read(1);
-           j++;
-           len--;
-           if (len == 0) break; /* Case of non-finished packet header in present marker but finished in next one */
-         }
-       
-       j2k_cp->ppm_previous = i - 1;
-       j2k_cp->ppm_store = j;
-      }
-}
-
-
-
-
-void j2k_read_ppt() {
-    int len, Z_ppt, i, j = 0;
-    j2k_tcp_t *tcp;
-    info_tile_t *tile;
-    len=cio_read(2);
-
-    /* <INDEX> [MHIX BOX] */
-    tile = & img.tile[j2k_curtileno];
-    tile->marker[tile->num_marker].type = J2K_MS_PPT;
-    tile->marker[tile->num_marker].start_pos = cio_tell()-2;
-    tile->marker[tile->num_marker].len = len;
-    tile->num_marker++;
-    /* </INDEX> [MHIX BOX] */
-
-    Z_ppt = cio_read(1);
-    tcp = &j2k_cp->tcps[j2k_curtileno];
-    tcp->ppt = 1;
-    if (Z_ppt == 0) /* First PPT marker */
-      {
-       tcp->ppt_data = (unsigned char*)calloc(len - 3, sizeof(unsigned char));
-       tcp->ppt_store = 0;
-      }
-    else      /* NON-first PPT marker */
-      tcp->ppt_data = (unsigned char*)realloc(tcp->ppt_data, (len - 3 + tcp->ppt_store) * sizeof(unsigned char));
-    
-    j = tcp->ppt_store;
-    for (i = len - 3 ; i > 0 ; i--)
-      {
-       tcp->ppt_data[j] = cio_read(1);
-       j++;
-      }
-    tcp->ppt_store = j;
-}
-
-
-
-
-void j2k_read_sot() {
-    int len, tileno, totlen, partno, numparts, i;
-    j2k_tcp_t *tcp;
-    j2k_tccp_t *tmp;
-    info_tile_t *tile;
-    info_tile_part_t *tilepart_tmp;
-    
-    //fprintf(stderr,"SOT\n");
-    len = cio_read(2);
-    tileno = cio_read(2);
-    /* <INDEX> [MHIX BOX] */
-    tile = & img.tile[tileno];
-    tile->marker[tile->num_marker].type = J2K_MS_SOT;
-    tile->marker[tile->num_marker].start_pos = cio_tell() - 4;
-    tile->marker[tile->num_marker].len = len;
-    tile->num_marker++;
-    /* </INDEX> [MHIX BOX] */
-    totlen = cio_read(4);
-    if (!totlen) totlen = cio_numbytesleft() + 8;
-    partno = cio_read(1);
-    numparts = cio_read(1);
-
-    /* <INDEX> */
-    if (tileno == 0 && partno == 0 ) 
-      img.Main_head_end = cio_tell() - 12;  /* Correction End = First byte of first SOT */
-    
-    img.tile[tileno].num_tile = tileno;
-    /* </INDEX> */
-  
-    tile->numparts = partno + 1;                                               /* INDEX : Number of tile_parts for the tile */ 
-    img.num_max_tile_parts = int_max(tile->numparts, img.num_max_tile_parts);  /* INDEX : Maximum number of tile_part per tile */
-
-    if (partno == 0)
-    {
-      tile->tile_parts = (info_tile_part_t*)malloc(START_NB * sizeof(info_tile_part_t*));
-      tile->Cztile_parts = START_NB;
-    }
-    if (partno >= tile->Cztile_parts)
-      {
-       tilepart_tmp = (info_tile_part_t*)malloc((INCREMENT + tile->Cztile_parts) * sizeof(info_tile_part_t));
-       memcpy(tilepart_tmp, tile->tile_parts, tile->Cztile_parts); /*add tilepart_ a tmp*/
-       tile->Cztile_parts += INCREMENT;
-       free(tile->tile_parts);
-       tile->tile_parts = tilepart_tmp;
-      }
-
-    tile->tile_parts[partno].start_pos = cio_tell() - 12;        /* INDEX : start_pos of the tile_part       */
-    tile->tile_parts[partno].length = totlen;                    /* INDEX : length of the tile_part          */  
-    tile->tile_parts[partno].end_pos = totlen + cio_tell() - 12; /* INDEX : end position of the tile_part    */
-    //tile->tile_parts[partno].num_reso_AUX = j2k_default_tcp.tccps[0].numresolutions;
-
-    j2k_curtileno = tileno;
-    j2k_eot = cio_getbp() - 12 + totlen;
-    j2k_state = J2K_STATE_TPH;
-    tcp = &j2k_cp->tcps[j2k_curtileno];
-
-     if (partno == 0)
-       //  if (tcp->first == 1) 
-      {
-       tmp = tcp->tccps;
-       *tcp = j2k_default_tcp;
-       /* Initialization PPT */
-       tcp->ppt = 0; 
-       tcp->ppt_data = NULL;
-       
-       tcp->tccps = tmp;
-       for (i = 0; i < j2k_img->numcomps; i++) {
-         tcp->tccps[i] = j2k_default_tcp.tccps[i];
-       }
-       //j2k_cp->tcps[j2k_curtileno].first=0;
-      }
-     //   tile->tile_parts[numparts].num_reso_AUX = tcp->tccps[0].numresolutions; /* INDEX : AUX value for TPIX       */
-}
-
-
-
-void j2k_read_rgn() {
-    int len, compno, roisty;
-    j2k_tcp_t *tcp;
-    info_tile_t *tile;
-    info_marker_t *tmp;
-    // fprintf(stderr,"RGN\n");
-    tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
-    len = cio_read(2);
-    
-    /* <INDEX> [MHIX BOX]*/
-    if (j2k_state == J2K_STATE_MH)
-      {
-       if (!img.marker_mul.num_RGN)
-         img.marker_mul.RGN = (info_marker_t*)malloc(img.marker_mul.CzRGN * sizeof(info_marker_t));
-       if (img.marker_mul.num_RGN >= img.marker_mul.CzRGN)
-         {
-           tmp = (info_marker_t*)malloc((INCREMENT + img.marker_mul.CzRGN) * sizeof(info_marker_t));
-           memcpy(tmp,img.marker_mul.RGN, img.marker_mul.CzRGN);
-           img.marker_mul.CzRGN += INCREMENT;
-           free(img.marker_mul.RGN);
-           img.marker_mul.RGN = tmp;
-         }
-       img.marker_mul.RGN[img.marker_mul.num_RGN].type = J2K_MS_RGN;
-       img.marker_mul.RGN[img.marker_mul.num_RGN].start_pos = cio_tell() - 2;
-       img.marker_mul.RGN[img.marker_mul.num_RGN].len = len;
-       img.marker_mul.num_RGN++;
-      } else
-      {
-       tile = &img.tile[j2k_curtileno];
-       if (!tile->marker_mul.num_RGN)
-         tile->marker_mul.RGN = (info_marker_t*)malloc(tile->marker_mul.CzRGN * sizeof(info_marker_t));
-       if (tile->marker_mul.num_RGN >= tile->marker_mul.CzRGN)
-         {
-           tmp = (info_marker_t*)malloc((INCREMENT + tile->marker_mul.CzRGN) * sizeof(info_marker_t));
-           memcpy(tmp,tile->marker_mul.RGN,tile->marker_mul.CzRGN);
-           tile->marker_mul.CzRGN += INCREMENT;
-           free(tile->marker_mul.RGN);
-           tile->marker_mul.RGN = tmp;
-         }
-
-       tile->marker_mul.RGN[tile->marker_mul.num_RGN].type = J2K_MS_RGN;
-       tile->marker_mul.RGN[tile->marker_mul.num_RGN].start_pos = cio_tell() - 2;
-        tile->marker_mul.RGN[tile->marker_mul.num_RGN].len = len;
-       tile->marker_mul.num_RGN++;
-      }
-    /* </INDEX> [MHIX BOX] */
-    
-    compno = cio_read(j2k_img->numcomps <= 256 ? 1 : 2);
-    roisty = cio_read(1);
-    tcp->tccps[compno].roishift = cio_read(1);
-}
-
-
-
-
-
-void j2k_read_sod() {
-    int len, i;
-    unsigned char *data;
-    info_tile_t *tile;
-    info_tile_part_t *tile_part;
-    /* <INDEX> [MHIX BOX] */
-    tile = &img.tile[j2k_curtileno];
-    tile->marker[tile->num_marker].type = J2K_MS_SOD;
-    tile->marker[tile->num_marker].start_pos = cio_tell();
-    tile->marker[tile->num_marker].len = 0;
-    tile->num_marker++;
-    /* </INDEX> [MHIX BOX] */
-
-    tile_part = &tile->tile_parts[tile->numparts - 1];                   /* INDEX : Current tilepart of a tile                  */
-    tile_part->length_header = cio_tell() - 1 - tile_part->start_pos;    /* INDEX : length of the tile-part header              */
-    tile_part->end_header = cio_tell() - 1;                              /* INDEX : end header position of the tile-part header */
-
-    len = int_min(j2k_eot - cio_getbp(), cio_numbytesleft());
-
-    data = (unsigned char*)malloc((j2k_tile_len[j2k_curtileno] + len) * sizeof(unsigned char));
-
-    for (i=0; i<j2k_tile_len[j2k_curtileno]; i++)
-      data[i] = j2k_tile_data[j2k_curtileno][i];
-    for (i=0 ; i<len ; i++)
-      data[i+j2k_tile_len[j2k_curtileno]] = cio_read(1);
-    
-    j2k_tile_len[j2k_curtileno] += len;
-/*
-    free(j2k_tile_data[j2k_curtileno]);
- */
-    j2k_tile_data[j2k_curtileno] = data;       
-    data = NULL;
-
-    j2k_state = J2K_STATE_TPHSOT;
-}
-
-void j2k_read_eoc() {
-    int tileno;
-
-    tcd_init(j2k_img, j2k_cp, &img);
-    for (tileno = 0; tileno<j2k_cp->tw * j2k_cp->th; tileno++) {
-        tcd_decode_tile(j2k_tile_data[tileno], j2k_tile_len[tileno], tileno, &img);
-    }
-
-    j2k_state = J2K_STATE_MT;
-     longjmp(j2k_error, 1);
-}
-
-
-
-
-void j2k_read_unk() {
-    fprintf(stderr, "warning: unknown marker\n");
-}
-
-
-
-
-int j2k_index_JPIP(char *Idx_file, char *J2K_file, int len, int version){
-  FILE *dest;
-  unsigned char *index;
-  int pos_iptr, end_pos;
-  int len_cidx, pos_cidx;
-  int len_jp2c, pos_jp2c;
-  int len_fidx, pos_fidx;
-
-  dest=fopen(Idx_file, "wb");
-  if (!dest) {
-    fprintf(stderr, "Failed to open %s for reading !!\n", Idx_file);
-    return 0;
-  }
-
-  /* INDEX MODE JPIP */
- index = (unsigned char*)malloc(len); 
- cio_init(index, len);
- jp2_write_jp();
- jp2_write_ftyp();
- jp2_write_jp2h(j2k_img);
- jp2_write_dbtl(Idx_file);
-
- pos_iptr=cio_tell();
- cio_skip(24); /* IPTR further ! */
- pos_jp2c = cio_tell();
- len_jp2c = jp2_write_jp2c(J2K_file);
-
- pos_cidx = cio_tell();
- len_cidx = jpip_write_cidx(pos_jp2c + 8,img, j2k_cp, version); /* Correction len_jp2C --> pos_jp2c + 8 */  
-
- pos_fidx = cio_tell();
- len_fidx = jpip_write_fidx(pos_jp2c, len_jp2c, pos_cidx, len_cidx);
-
-end_pos = cio_tell();
-
- cio_seek(pos_iptr);
- jpip_write_iptr(pos_fidx,len_fidx);
- cio_seek(end_pos);
- fwrite(index, 1, cio_tell(), dest);
- free(index);
-
- fclose(dest);
- return 1;
-}
-
-
-
-typedef struct {
-  int id;
-    int states;
-    void (*handler)();
-} j2k_dec_mstabent_t;
-
-j2k_dec_mstabent_t j2k_dec_mstab[]={
-    {J2K_MS_SOC, J2K_STATE_MHSOC, j2k_read_soc},
-    {J2K_MS_SOT, J2K_STATE_MH|J2K_STATE_TPHSOT, j2k_read_sot},
-    {J2K_MS_SOD, J2K_STATE_TPH, j2k_read_sod},
-    {J2K_MS_EOC, J2K_STATE_TPHSOT, j2k_read_eoc},
-    {J2K_MS_SIZ, J2K_STATE_MHSIZ, j2k_read_siz},
-    {J2K_MS_COD, J2K_STATE_MH|J2K_STATE_TPH, j2k_read_cod},
-    {J2K_MS_COC, J2K_STATE_MH|J2K_STATE_TPH, j2k_read_coc},
-    {J2K_MS_RGN, J2K_STATE_MH|J2K_STATE_TPH, j2k_read_rgn},
-    {J2K_MS_QCD, J2K_STATE_MH|J2K_STATE_TPH, j2k_read_qcd},
-    {J2K_MS_QCC, J2K_STATE_MH|J2K_STATE_TPH, j2k_read_qcc},
-    {J2K_MS_POC, J2K_STATE_MH|J2K_STATE_TPH, j2k_read_poc},
-    {J2K_MS_TLM, J2K_STATE_MH, j2k_read_tlm},
-    {J2K_MS_PLM, J2K_STATE_MH, j2k_read_plm},
-    {J2K_MS_PLT, J2K_STATE_TPH, j2k_read_plt},
-    {J2K_MS_PPM, J2K_STATE_MH, j2k_read_ppm},
-    {J2K_MS_PPT, J2K_STATE_TPH, j2k_read_ppt},
-    {J2K_MS_SOP, 0, 0},
-    {J2K_MS_CRG, J2K_STATE_MH, j2k_read_crg},
-    {J2K_MS_COM, J2K_STATE_MH|J2K_STATE_TPH, j2k_read_com},
-    {0, J2K_STATE_MH|J2K_STATE_TPH, j2k_read_unk}
-};
-
-j2k_dec_mstabent_t *j2k_dec_mstab_lookup(int id) {
-    j2k_dec_mstabent_t *e;
-    for (e = j2k_dec_mstab; e->id != 0; e++) {
-        if (e->id == id) {
-            break;
-        }
-    }
-    return e;
-}
-
-int j2k_decode(unsigned char *src, int len, j2k_image_t **image, j2k_cp_t **cp) {
-    if (setjmp(j2k_error)) {
-        if (j2k_state != J2K_STATE_MT) {
-            fprintf(stderr, "WARNING: incomplete bitstream\n");
-            return 0;
-        }
-        return cio_numbytes();
-    }
-    j2k_img = (j2k_image_t*)calloc(1, sizeof(j2k_image_t));
-    j2k_cp = (j2k_cp_t*)calloc(1, sizeof(j2k_cp_t));
-    *image = j2k_img;
-    *cp = j2k_cp;
-    j2k_state = J2K_STATE_MHSOC;
-    cio_init(src, len);
-    for (;;) {
-        j2k_dec_mstabent_t *e;
-        int id = cio_read(2);
-        if (id >> 8 != 0xff) {
-            fprintf(stderr, "%.8x: expected a marker instead of %x\n", cio_tell() - 2, id);
-            return 0;
-        }
-        e = j2k_dec_mstab_lookup(id);
-        if (!(j2k_state & e->states)) {
-            fprintf(stderr, "%.8x: unexpected marker %x\n", cio_tell() - 2, id);
-            return 0;
-        }
-        if (e->handler) {
-            (*e->handler)();
-        }
-    }
-
-}
-
-
-#ifdef WIN32
-#include <windows.h>
-
-BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
-    switch (ul_reason_for_call) {
-               case DLL_PROCESS_ATTACH:
-               case DLL_THREAD_ATTACH:
-               case DLL_THREAD_DETACH:
-               case DLL_PROCESS_DETACH:
-                       break;
-    }
-    return TRUE;
-}
-#endif
-
-int main(int argc, char **argv)
-{  
-  FILE *src;
-  int totlen;
-  unsigned char *j2kfile;
-  j2k_image_t *imgg;
-  j2k_cp_t *cp;
-  int version;
-
-  if (argc != 4)
-    {
-      fprintf(stderr,"\nERROR in entry : index_create J2K-file JP2-file version\n\nVersion : 0, 1, 2 or 3\n0 : [faix] 4-byte and no AUX fields\n1 : [faix] 8-byte and no AUX fields\n2 : [faix] 4-byte and AUX fields\n3 : [faix] 8-byte and AUX fields\n");
-      return 1;
-    }
-
-  src=fopen(argv[1], "rb");
-  if (!src) {
-    fprintf(stderr, "Failed to open %s for reading !!\n", argv[1]);
-    return 1;
-  }
-
-  /* length of the codestream */
-  fseek(src, 0, SEEK_END);
-  totlen = ftell(src);
-  fseek(src, 0, SEEK_SET);
-  
-  j2kfile = (unsigned char*)malloc(totlen);
-  fread(j2kfile, 1, totlen, src);
-  fclose(src);
-
-  img.marker = (info_marker_t*)malloc(32 * sizeof(info_marker_t));
-  img.num_marker = 0;
-  img.num_max_tile_parts = 0;
-  img.marker_mul.num_COC = 0;
-  img.marker_mul.CzCOC = START_NB;
-  img.marker_mul.num_RGN = 0;
-  img.marker_mul.CzRGN = START_NB;
-  img.marker_mul.num_QCC = 0;
-  img.marker_mul.CzQCC = START_NB;
-  img.marker_mul.num_TLM = 0;
-  img.marker_mul.CzTLM = START_NB;
-  img.marker_mul.num_PLM = 0;
-  img.marker_mul.CzPLM = START_NB;
-  img.marker_mul.num_PPM = 0;
-  img.marker_mul.CzPPM = START_NB;
-  img.marker_mul.num_COM = 0;
-  img.marker_mul.CzCOM = START_NB;
-
-  /* decode */ 
-
-  if (!j2k_decode(j2kfile, totlen, &imgg, &cp)) {
-    fprintf(stderr, "Index_creator: failed to decode image!\n");
-    return 1;
-  }
-  free(j2kfile);
-  
-  // fseek(src, 0, SEEK_SET);
-  img.codestream_size = totlen;
-  sscanf(argv[3], "%d", &version);
-  if (version > 3)
-    {
-      fprintf(stderr,"Error : value of version unauthorized !!  Value accepted : 0, 1, 2 or 3 !!\n");
-      return 0;
-    }
-
-  j2k_index_JPIP(argv[2], argv[1], totlen * 2 > 60000 ? totlen * 2 : 60000, version);
-  
-  j2k_clean();
-  return 0;
-}
diff --git a/applications/jpip/tools/indexer/indexbox_manager.h b/applications/jpip/tools/indexer/indexbox_manager.h
new file mode 100644 (file)
index 0000000..ea4f493
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * $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_ */
diff --git a/applications/jpip/tools/indexer/int.c b/applications/jpip/tools/indexer/int.c
deleted file mode 100644 (file)
index 29f778c..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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.
- */
-
-/// <summary>
-/// Get the minimum of two integers.
-/// </summary>
-int int_min(int a, int b) {
-    return a<b?a:b;
-}
-
-/// <summary>
-/// Get the maximum of two integers.
-/// </summary>
-int int_max(int a, int b) {
-    return a>b?a:b;
-}
-
-/// <summary>
-/// Clamp an integer inside an interval.
-/// </summary>
-int int_clamp(int a, int min, int max) {
-    if (a<min) return min;
-    if (a>max) return max;
-    return a;
-}
-
-/// <summary>
-/// Get absolute value of integer.
-/// </summary>
-int int_abs(int a) {
-    return a<0?-a:a;
-}
-
-/// <summary>
-/// Divide an integer and round upwards.
-/// </summary>
-int int_ceildiv(int a, int b) {
-    return (a+b-1)/b;
-}
-
-/// <summary>
-/// Divide an integer by a power of 2 and round upwards.
-/// </summary>
-int int_ceildivpow2(int a, int b) {
-    return (a+(1<<b)-1)>>b;
-}
-
-/// <summary>
-/// Divide an integer by a power of 2 and round downwards.
-/// </summary>
-int int_floordivpow2(int a, int b) {
-    return a>>b;
-}
-
-/// <summary>
-/// Get logarithm of an integer and round downwards.
-/// </summary>
-int int_floorlog2(int a) {
-    int l;
-    for (l=0; a>1; l++) {
-        a>>=1;
-    }
-    return l;
-}
diff --git a/applications/jpip/tools/indexer/int.h b/applications/jpip/tools/indexer/int.h
deleted file mode 100644 (file)
index 4921ff4..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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 __INT_H
-#define __INT_H
-
-int int_min(int a, int b);
-int int_max(int a, int b);
-int int_clamp(int a, int min, int max);
-int int_abs(int a);
-int int_ceildiv(int a, int b);
-int int_ceildivpow2(int a, int b);
-int int_floordivpow2(int a, int b);
-int int_floorlog2(int a);
-
-#endif
diff --git a/applications/jpip/tools/indexer/j2k.h b/applications/jpip/tools/indexer/j2k.h
deleted file mode 100644 (file)
index c43e091..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003-2004, Yannick Verschueren
- * Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * All rights reserved. 
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#define VERSION "0.0.8"
-
-#ifdef WIN32
-#ifdef LIBJ2K_EXPORTS
-#define LIBJ2K_API __declspec(dllexport)
-#else
-#define LIBJ2K_API __declspec(dllimport)
-#endif
-#else
-#define LIBJ2K_API
-#endif
-
-#ifndef __J2K_H
-#define __J2K_H
-
-#define J2K_MAXRLVLS 33
-#define J2K_MAXBANDS (3*J2K_MAXRLVLS+1)
-
-#define J2K_CP_CSTY_PRT 0x01
-#define J2K_CP_CSTY_SOP 0x02
-#define J2K_CP_CSTY_EPH 0x04
-#define J2K_CCP_CSTY_PRT 0x01
-#define J2K_CCP_CBLKSTY_LAZY 0x01
-#define J2K_CCP_CBLKSTY_RESET 0x02
-#define J2K_CCP_CBLKSTY_TERMALL 0x04
-#define J2K_CCP_CBLKSTY_VSC 0x08
-#define J2K_CCP_CBLKSTY_PTERM 0x10
-#define J2K_CCP_CBLKSTY_SEGSYM 0x20
-#define J2K_CCP_QNTSTY_NOQNT 0
-#define J2K_CCP_QNTSTY_SIQNT 1
-#define J2K_CCP_QNTSTY_SEQNT 2
-
-typedef struct 
-{
-  int dx, dy;   /* XRsiz, YRsiz            */
-  int prec;     /* precision               */
-  int bpp;      /* deapth of image in bits */
-  int sgnd;     /* signed                  */
-  int *data;    /* image-component data    */
-} j2k_comp_t;
-
-typedef struct {
-  int version;
-  int x0, y0;          /* XOsiz, YOsiz              */
-  int x1, y1;          /* Xsiz, Ysiz                */ 
-  int numcomps;        /* number of components      */
-  int index_on;        /* 0 = no index || 1 = index */
-  j2k_comp_t *comps;   /* image-components          */
-} j2k_image_t;
-
-typedef struct {
-  int expn;     /* exponent */
-  int mant;     /* mantissa */
-} j2k_stepsize_t;
-
-typedef struct {
-  int csty;                                /* coding style                          */
-  int numresolutions;                      /* number of resolutions                 */
-  int cblkw;                               /* width of code-blocks                  */
-  int cblkh;                               /* height of code-blocks                 */
-  int cblksty;                             /* code-block coding style               */
-  int qmfbid;                              /* discrete wavelet transform identifier */
-  int qntsty;                              /* quantisation style                    */
-  j2k_stepsize_t stepsizes[J2K_MAXBANDS];  /* stepsizes used for quantisation       */
-  int numgbits;                            /* number of guard bits                  */
-  int roishift;                            /* Region of Interest shift              */
-  int prcw[J2K_MAXRLVLS];                  /* Precinct width                        */
-  int prch[J2K_MAXRLVLS];                  /* Precinct height                       */
-} j2k_tccp_t;
-
-typedef struct {
-    int resno0, compno0; 
-    int layno1, resno1, compno1;
-    int prg;
-    int tile;
-    char progorder[4];
-} j2k_poc_t;
-
-typedef struct {
-  //int first;
-  int csty;                  /* coding style                                                            */  
-  int prg;                   /* progression order                                                       */
-  int numlayers;             /* number of layers                                                        */
-  int mct;                   /* multi-component transform identifier                                    */
-  int rates[100];            /* rates of layers                                                         */
-  int numpocs;               /* number of progression order changes                                     */
-  int POC;                   /* Precise if a POC marker has been used O:NO, 1:YES                       */
-  j2k_poc_t pocs[32];        /* progression order changes                                               */
-  unsigned char *ppt_data;   /* packet header store there for futur use in t2_decode_packet             */
-  int ppt;                   /* If ppt == 1 --> there was a PPT marker for the present tile             */
-  int ppt_store;             /* Use in case of multiple marker PPT (number of info already store)       */
-  j2k_tccp_t *tccps;         /* tile-component coding parameters                                        */
-} j2k_tcp_t;
-
-typedef struct {
-  int tx0, ty0;              /* XTOsiz, YTOsiz                                                          */
-  int tdx, tdy;              /* XTsiz, YTsiz                                                            */
-  int tw, th;
-  unsigned char *ppm_data;   /* packet header store there for futur use in t2_decode_packet             */
-  int ppm;                   /* If ppm == 1 --> there was a PPM marker for the present tile             */
-  int ppm_store;             /* Use in case of multiple marker PPM (number of info already store)       */
-  int ppm_previous;          /* Use in case of multiple marker PPM (case on non-finished previous info) */
-  j2k_tcp_t *tcps;           /* tile coding parameters                                                  */
-} j2k_cp_t;
-
-
-
-
-
-/* Packet information : Layer level */
-typedef struct {  
-  int len;               /* Length of the body of the packet   */
-  int len_header;        /* Length of the header of the packet */
-  int offset;            /* Offset of the body of the packet   */
-  int offset_header;     /* Offset of the header of the packet */
-} info_layer_t;
-
-
-/* Access to packet information : precinct level */
-typedef struct {  
-  info_layer_t *layer;
-} info_prec_t;
-
-
-/* Access to packet information : resolution level */
-typedef struct {  
-  info_prec_t *prec;
-} info_reso_t;
-
-
-/* Access to packet information : component level */
-typedef struct {  
-  info_reso_t *reso;
-} info_compo_t;
-
-
-/* Information about the marker */
-typedef struct {
-  int type;       /* type of marker [SIZ, QCD, POC, PPM, CRG, COD] appearing only once */
-  int start_pos;  /* Start position of the marker                                      */
-  int len;        /* Length of the marker                                              */
-} info_marker_t;
-
-
-/* Multiple marker in tile header */
-typedef struct{
-  info_marker_t *COC;    /* COC markers                    */
-  int num_COC;           /* Number of COC marker           */
-  int CzCOC;             /* Current size of the vector COC */
-  
-  info_marker_t *RGN;    /* RGN markers                    */
-  int num_RGN;           /* Number of RGN marker           */
-  int CzRGN;             /* Current size of the vector RGN */
-  
-  info_marker_t *QCC;    /* QCC markers                    */
-  int num_QCC;           /* Number of QCC marker           */
-  int CzQCC;             /* Current size of the vector QCC */
-  
-  info_marker_t *PLT;    /* PLT markers                    */
-  int num_PLT;           /* Number of PLT marker           */
-  int CzPLT;             /* Current size of the vector PLT */
-  
-  info_marker_t *PPT;    /* PPT markers                    */
-  int num_PPT;           /* Number of PPT marker           */
-  int CzPPT;             /* Current size of the vector PPT */
-  
-  info_marker_t *COM;    /* COM markers                    */
-  int num_COM;           /* Number of COM marker           */
-  int CzCOM;             /* Current size of the vector COC */
-} info_marker_mul_tile_t; 
-
-
-/* Information about each tile_part for a particulary tile */
-typedef struct{
-  int start_pos;                      /* Start position of the tile_part       */ 
-  int length;                         /* Length of the tile_part header + body */
-  int length_header;                  /* Length of the header                  */
-  int end_pos;                        /* End position of the tile part         */
-  int end_header;                     /* End position of the tile part header  */
-  int num_reso_AUX;                   /* Number of resolution level completed  */
-} info_tile_part_t;
-
-
-/* Information about each tile */
-typedef struct {
-  int num_tile;                       /* Number of Tile                                                    */
-  int pw, ph;                         /* number of precinct by tile                                        */
-  int num_packet;                     /* number of packet in the tile                                      */
-  info_compo_t *compo;                /* component [packet]                                                */
-  
-  info_marker_t *marker;              /* information concerning markers inside image [only one apparition] */
-  info_marker_mul_tile_t marker_mul;  /* information concerning markers inside image [multiple apparition] */ 
-  int num_marker;                     /* number of marker                                                  */
-  
-  int numparts;                       /* number of tile_part for this tile                                 */
-  info_tile_part_t *tile_parts;       /* Information about each tile_part                                  */
-  int Cztile_parts;                   /* Current size of the tile_parts vector                             */
-} info_tile_t;                        /* index struct                                                      */
-
-
-/* Multiple marker in main header */
-typedef struct{
-  info_marker_t *COC;    /* COC markers                    */
-  int num_COC;           /* Number of COC marker           */
-  int CzCOC;             /* Current size of the vector COC */
-  info_marker_t *RGN;    /* RGN markers                    */
-  int num_RGN;           /* Number of RGN marker           */
-  int CzRGN;             /* Current size of the vector RGN */
-  
-  info_marker_t *QCC;    /* QCC markers                    */
-  int num_QCC;           /* Number of QCC marker           */
-  int CzQCC;             /* Current size of the vector QCC */
-  
-  info_marker_t *TLM;    /* TLM markers                    */
-  int num_TLM;           /* Number of TLM marker           */
-  int CzTLM;             /* Current size of the vector TLM */
-  
-  info_marker_t *PLM;    /* PLM markers                    */
-  int num_PLM;           /* Number of PLM marker           */
-  int CzPLM;             /* Current size of the vector PLM */
-  
-  info_marker_t *PPM;    /* PPM markers                    */
-  int num_PPM;           /* Number of PPM marker           */
-  int CzPPM;             /* Current size of the vector PPM */
-  
-  info_marker_t *COM;    /* COM markers                    */
-  int num_COM;           /* Number of COM marker           */
-  int CzCOM;             /* Current size of the vector COM */
-} info_marker_mul_t; /* index struct */
-
-
-/* Information about image */
-typedef struct {
-  int Im_w, Im_h;                /* Image width and Height                                            */
-  int Tile_x, Tile_y;            /* Number of Tile in X and Y                                         */
-  int tw, th;
-  int pw, ph;                    /* nombre precinct in X and Y                                        */
-  int pdx, pdy;                  /* size of precinct in X and Y                                       */
-
-  int Prog;                      /* progression order                                                 */
-  int Comp;                      /* Component numbers                                                 */
-  int Layer;                     /* number of layer                                                   */
-  int Decomposition;             /* number of decomposition                                           */
-
-  int Main_head_end;             /* Main header position                                              */
-  int codestream_size;           /* codestream's size                                                 */
-
-  info_marker_t *marker;         /* information concerning markers inside image [only one apparition] */
-  info_marker_mul_t marker_mul;  /* information concerning markers inside image [multiple apparition] */ 
-  int num_marker;                /* number of marker                                                  */
-
-  int num_packet_max;            /* Maximum number of packet                                          */
-
-  int num_max_tile_parts;        /* Maximum number of tile-part                                       */
-  info_tile_t *tile;             /* information concerning tiles inside image                         */
-} info_image_t; /* index struct */
-
-
-#endif
diff --git a/applications/jpip/tools/indexer/j2k_decoder.c b/applications/jpip/tools/indexer/j2k_decoder.c
new file mode 100644 (file)
index 0000000..6e62503
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * $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 "j2k_to_idxjp2.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 *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(&parameters);
+
+  /* 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, &parameters);
+
+  /* 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;
+}
+
+
+/* 
+ * 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;
+}
diff --git a/applications/jpip/tools/indexer/j2k_to_idxjp2.c b/applications/jpip/tools/indexer/j2k_to_idxjp2.c
new file mode 100644 (file)
index 0000000..8239401
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * $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;
+}
similarity index 56%
rename from applications/jpip/tools/indexer/bio.h
rename to applications/jpip/tools/indexer/j2k_to_idxjp2.h
index eea6cff0a18abe5a5200b0a28e4d1a9fcf736590..45a4a432d78c38bb0b37ad0722f9467c670f09d0 100644 (file)
@@ -1,7 +1,9 @@
 /*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003-2004, Yannick Verschueren
- * Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
+ * $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
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef __BIO_H
-#define __BIO_H
+#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);
+
 
-int bio_numbytes();
-void bio_init_dec(unsigned char *bp, int len);
-int bio_read(int n);
-int bio_flush();
-int bio_inalign();
+/* 
+ * 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
+#endif      /* !J2K_TO_IDXJP2S_H_ */
diff --git a/applications/jpip/tools/indexer/jp2.c b/applications/jpip/tools/indexer/jp2.c
deleted file mode 100644 (file)
index 1c193ad..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * Copyright (c) 2003-2004, Yannick Verschueren
- * Copyright (c) 2003-2004,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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 <string.h>
-
-#include "j2k.h"
-#include "cio.h"
-#include "tcd.h"
-#include "int.h"
-
-#define JPIP_JPIP 0x6a706970
-
-#define JP2_JP   0x6a502020
-#define JP2_FTYP 0x66747970
-#define JP2_JP2H 0x6a703268
-#define JP2_IHDR 0x69686472
-#define JP2_COLR 0x636f6c72
-#define JP2_JP2C 0x6a703263
-#define JP2_URL  0x75726c20
-#define JP2_DBTL 0x6474626c
-#define JP2_BPCC 0x62706363
-#define JP2      0x6a703220
-
-
-void jp2_write_url(char *Idx_file)
-{
-  int len, lenp, i;
-  char str[256];
-
-  sprintf(str, "%s", Idx_file);
-  lenp=cio_tell();
-  cio_skip(4);
-  cio_write(JP2_URL, 4);  // DBTL
-  cio_write(0,1);          // VERS
-  cio_write(0,3);          // FLAG
-
-  for (i=0; i<strlen(str); i++) {
-        cio_write(str[i], 1);
-    }
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len,4);         // L
-  cio_seek(lenp+len);
-}
-
-void jp2_write_dbtl(char *Idx_file)
-{
-  int len, lenp;
-
-  lenp=cio_tell();
-  cio_skip(4);
-  cio_write(JP2_DBTL, 4);  // DBTL
-  cio_write(1,2);           // NDR : Only 1
-  
-  jp2_write_url(Idx_file); // URL Box
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len,4);         // L
-  cio_seek(lenp+len);
-}
-
-int jp2_write_ihdr(j2k_image_t *j2k_img)
-{
-  int len, lenp,i; 
-  int depth_0,depth, sign, BPC_ok=1;
-
-  lenp=cio_tell();
-  cio_skip(4);
-  cio_write(JP2_IHDR, 4);  // IHDR
-
-  cio_write(j2k_img->y1-j2k_img->x0,4);   // HEIGHT
-  cio_write(j2k_img->x1-j2k_img->x0,4);   // WIDTH
-  cio_write(j2k_img->numcomps,2);   // NC
-
-  depth_0=j2k_img->comps[0].prec-1;
-  sign=j2k_img->comps[0].sgnd;
-
-  for(i=1;i<j2k_img->numcomps;i++)
-    {
-      depth=j2k_img->comps[i].prec-1;
-      sign=j2k_img->comps[i].sgnd;
-      if(depth_0!=depth) BPC_ok=0;
-    }
-  
-  if (BPC_ok)
-    cio_write(depth_0+(sign<<7),1);
-  else
-    cio_write(255,1);
-
-  cio_write(7,1);          // C : Always 7
-  cio_write(1,1);          // UnkC, colorspace unknow
-  cio_write(0,1);          // IPR, no intellectual property
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len,4);         // L
-  cio_seek(lenp+len);
-
-  return BPC_ok;
-}
-
-void jp2_write_bpcc(j2k_image_t *j2k_img)
-{
-  int len, lenp, i;
-  
-  lenp=cio_tell();
-  cio_skip(4);
-  cio_write(JP2_BPCC, 4);  // BPCC
-  
-  for(i=0;i<j2k_img->numcomps;i++)
-    cio_write(j2k_img->comps[i].prec-1+(j2k_img->comps[i].sgnd<<7),1);
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len,4);         // L
-  cio_seek(lenp+len);
-}
-
-void jp2_write_colr(int BPC_ok, j2k_image_t *j2k_img)
-{
-  int len, lenp, meth;
-  
-  lenp=cio_tell();
-  cio_skip(4);
-  cio_write(JP2_COLR, 4);  // COLR
-
-  if ((j2k_img->numcomps==1 || j2k_img->numcomps==3) && (BPC_ok && j2k_img->comps[0].prec==8))
-    meth=1;
-  else
-    meth=2;
-
-  cio_write(meth,1);       // METH
-  cio_write(0,1);          // PREC
-  cio_write(0,1);          // APPROX
-  
-  if (meth==1)
-    cio_write(j2k_img->numcomps>1?16:17,4);          // EnumCS
-
-  if (meth==2)
-    cio_write(0,1);        // PROFILE (??) 
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len,4);         // L
-  cio_seek(lenp+len);
-}
-
-/*
- * Write the JP2H box
- *
- * JP2 Header box
- *
- */
-void jp2_write_jp2h(j2k_image_t *j2k_img)
-{
-  int len, lenp, BPC_ok;
-  
-  lenp=cio_tell();
-  cio_skip(4);
-  cio_write(JP2_JP2H, 4);           /* JP2H */
-
-  BPC_ok=jp2_write_ihdr(j2k_img);
-
-  if (!BPC_ok)
-    jp2_write_bpcc(j2k_img);
-  jp2_write_colr(BPC_ok, j2k_img);
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len,4);         /* L */
-  cio_seek(lenp+len);
-}
-
-/*
- * Write the FTYP box
- *
- * File type box
- *
- */
-void jp2_write_ftyp()
-{
-  int len, lenp;
-  
-  lenp=cio_tell();
-  cio_skip(4);
-  cio_write(JP2_FTYP, 4);   /* FTYP       */
-
-  cio_write(JP2,4);         /* BR         */
-  cio_write(0,4);           /* MinV       */
-  cio_write(JP2,4);         /* CL0 : JP2  */
-  cio_write(JPIP_JPIP,4);   /* CL1 : JPIP */
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len,4);         /* L          */
-  cio_seek(lenp+len);
-}
-
-/*
- * Read the FTYP box
- *
- * File type box
- *
- */
-void jp2_read_ftyp(int length)
-{
-  int BR, MinV, type, i;
-
-  BR = cio_read(4);         /* BR              */
-  MinV = cio_read(4);       /* MinV            */
-  length-=8;
-  
-  for (i=length/4;i>0;i--)
-    type = cio_read(4);     /* CLi : JP2, JPIP */
-}
-
-int jp2_write_jp2c(char *J2K_file)
-{
-  int len, lenp, totlen, i;
-  FILE *src;
-  char *j2kfile;
-
-  lenp=cio_tell();
-  cio_skip(4);
-  cio_write(JP2_JP2C, 4);  // JP2C
-
-  src=fopen(J2K_file, "rb");
-  fseek(src, 0, SEEK_END);
-  totlen=ftell(src);
-  fseek(src, 0, SEEK_SET);
-  
-  j2kfile=(char*)malloc(totlen);
-  fread(j2kfile, 1, totlen, src);
-  fclose(src);
-
-  for (i=0;i<totlen;i++)
-    cio_write(j2kfile[i],1);
-  
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len,4);         // L
-  cio_seek(lenp+len);
-  return lenp;
-}
-
-void jp2_write_jp()
-{
-  int len, lenp;
-  
-  lenp=cio_tell();
-  cio_skip(4);
-  cio_write(JP2_JP, 4);  // JP
-  cio_write(0x0d0a870a,4);
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len,4);         // L
-  cio_seek(lenp+len);
-}
-
-/*
- * Read the JP box
- *
- * JPEG 2000 signature
- *
- * return 1 if error else 0
- */
-int jp2_read_jp()
-{
-  if (0x0d0a870a!=cio_read(4))
-    return 1;
-  else
-    return 0;
-}
diff --git a/applications/jpip/tools/indexer/jpip.c b/applications/jpip/tools/indexer/jpip.c
deleted file mode 100644 (file)
index 2e3ef91..0000000
+++ /dev/null
@@ -1,778 +0,0 @@
-/*
- * Copyright (c) 2003-2004, Yannick Verschueren
- * Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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 <string.h>
-#include <setjmp.h>
-#include <math.h>
-#include <unistd.h>
-
-#include "j2k.h"
-#include "cio.h"
-#include "tcd.h"
-#include "int.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                    */
-
-#define JP2C      0x6a703263
-
-//static info_marker_t marker_jpip[32], marker_local_jpip[32];  /* SIZE to precise ! */
-//static int num_marker_jpip, num_marker_local_jpip;
-
-/* 
- * Write the CPTR box
- *
- * Codestream finder box (box)
- *
- */
-void jpip_write_cptr(int offset, info_image_t img)
-{
-  int len, lenp;
-
-  lenp=cio_tell(); 
-  cio_skip(4);                       /* L [at the end]     */
-  cio_write(JPIP_CPTR,4);            /* T                  */
-  cio_write(0,2);                    /* DR  A PRECISER !!  */
-  cio_write(0,2);                    /* CONT               */
-  cio_write(offset,8);               /* COFF A PRECISER !! */
-  cio_write(img.codestream_size,8);  /* CLEN               */
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len, 4);                 /* L                  */
-  cio_seek(lenp+len);
-}
-
-/* 
- * Read the CPTR box
- *
- * Codestream finder box (box)
- *
- */
-void jpip_read_cptr()
-{
-  int DR, CONT;
-  long long Coff, codestream_size;
-
-  DR = cio_read(2);               /* DR   */
-  CONT = cio_read(2);             /* CONT */
-  Coff = cio_read(8);             /* COFF */
-  codestream_size = cio_read(8);  /* CLEN */
-}
-
-/* 
- * Write the MANF box
- *
- * Manifest box (box)
- *
- */
-void jpip_write_manf(int second, int v, info_marker_t *marker)
-{
-  int len, lenp, i;
-  lenp=cio_tell(); 
-  cio_skip(4);                         /* L [at the end]                    */
-  cio_write(JPIP_MANF,4);              /* T                                 */
-
-  if (second)                          /* Write only during the second pass */
-    {
-      for(i=0;i<v;i++)
-       {
-         cio_write(marker[i].len,4);  /* Marker length                     */ 
-         cio_write(marker[i].type,4); /* Marker type                       */
-       }
-    }
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len, 4);                   /* L                                 */
-  cio_seek(lenp+len);
-}
-
-/* 
- * Read the MANF box
- *
- * Manifest box (box)
- *
- */
-void jpip_read_manf(int len)
-{
-  int i, v, marker_len, marker_type;
-  
-  v = (len - 8)/ 8;
-  
-  for(i=0;i<v;i++)
-    {
-      marker_len = cio_read(4);       /* Marker length */ 
-      marker_type = cio_read(4);      /* Marker type   */
-    }
-}
-
-/* 
- * Write the MHIX box
- *
- * Main Header Index Table (box)
- *
- */
-int jpip_write_mhix(info_image_t img, int status, int tileno)
-{
-  int len, lenp, i;
-  info_tile_t *tile;
-  lenp=cio_tell();
-  cio_skip(4);                               /* L [at the end]                    */
-  cio_write(JPIP_MHIX, 4);                   /* MHIX                              */
-
-  if (status==0) /* MAIN HEADER */
-    {
-      cio_write(img.Main_head_end,8);        /* TLEN                              */
-      
-      for(i = 0; i < img.num_marker; i++)    /* Marker restricted to 1 apparition */
-       {
-         cio_write(img.marker[i].type, 2);
-         cio_write(0, 2);
-         cio_write(img.marker[i].start_pos, 8);
-         cio_write(img.marker[i].len, 2);
-       }
-      
-      /* Marker NOT restricted to 1 apparition */
-      for(i = img.marker_mul.num_COC - 1; i >= 0; i--) /* COC */
-       {
-         cio_write(img.marker_mul.COC[i].type, 2);
-         cio_write(i, 2);
-         cio_write(img.marker_mul.COC[i].start_pos, 8);
-         cio_write(img.marker_mul.COC[i].len, 2);
-       }
-      
-      for(i = img.marker_mul.num_RGN - 1; i >= 0; i--) /* RGN */
-       {
-         cio_write(img.marker_mul.RGN[i].type, 2);
-         cio_write(i, 2);
-         cio_write(img.marker_mul.RGN[i].start_pos, 8);
-         cio_write(img.marker_mul.RGN[i].len, 2);
-       }
-      
-      for(i = img.marker_mul.num_QCC - 1; i >= 0; i--) /* QCC */
-       {
-         cio_write(img.marker_mul.QCC[i].type, 2);
-         cio_write(i, 2);
-         cio_write(img.marker_mul.QCC[i].start_pos, 8);
-         cio_write(img.marker_mul.QCC[i].len, 2);
-       }
-      
-      for(i = img.marker_mul.num_TLM - 1; i >= 0; i--) /* TLM */
-       {
-         cio_write(img.marker_mul.TLM[i].type, 2);
-         cio_write(i, 2);
-         cio_write(img.marker_mul.TLM[i].start_pos, 8);
-         cio_write(img.marker_mul.TLM[i].len, 2);
-       }
-      
-      for(i = img.marker_mul.num_PLM - 1; i >= 0; i--) /* PLM */
-       {
-         cio_write(img.marker_mul.PLM[i].type, 2);
-         cio_write(i, 2);
-         cio_write(img.marker_mul.PLM[i].start_pos, 8);
-         cio_write(img.marker_mul.PLM[i].len, 2);
-       }
-      
-      for(i = img.marker_mul.num_PPM - 1; i >= 0; i--) /* PPM */
-       {
-         cio_write(img.marker_mul.PPM[i].type, 2);
-         cio_write(i, 2);
-         cio_write(img.marker_mul.PPM[i].start_pos, 8);
-         cio_write(img.marker_mul.PPM[i].len, 2);
-       }
-
-      for(i = img.marker_mul.num_COM - 1; i >= 0; i--) /* COM */
-       {
-         cio_write(img.marker_mul.COM[i].type, 2);
-         cio_write(i, 2);
-         cio_write(img.marker_mul.COM[i].start_pos, 8);
-         cio_write(img.marker_mul.COM[i].len, 2);
-       }
-    } 
-  else /* TILE HEADER */
-    {
-      tile = &img.tile[tileno];
-      cio_write(tile->tile_parts[0].length_header, 8);  /* TLEN                              */ 
-      
-      for(i = 0; i < tile->num_marker; i++)             /* Marker restricted to 1 apparition */
-       {
-         cio_write(tile->marker[i].type, 2);
-         cio_write(0, 2);
-         cio_write(tile->marker[i].start_pos, 8);
-         cio_write(tile->marker[i].len, 2);
-       }
-      
-      /* Marker NOT restricted to 1 apparition */
-      for(i = tile->marker_mul.num_COC - 1; i >= 0; i--) /* COC */
-       {
-         cio_write(tile->marker_mul.COC[i].type, 2);
-         cio_write(i, 2);
-         cio_write(tile->marker_mul.COC[i].start_pos, 8);
-         cio_write(tile->marker_mul.COC[i].len, 2);
-       }
-      
-      for(i = tile->marker_mul.num_RGN - 1; i >= 0; i--) /* RGN */
-       {
-         cio_write(tile->marker_mul.RGN[i].type, 2);
-         cio_write(i, 2);
-         cio_write(tile->marker_mul.RGN[i].start_pos, 8);
-         cio_write(tile->marker_mul.RGN[i].len, 2);
-       }
-      
-      for(i = tile->marker_mul.num_QCC - 1; i >= 0; i--) /* QCC */
-       {
-         cio_write(tile->marker_mul.QCC[i].type, 2);
-         cio_write(i, 2);
-         cio_write(tile->marker_mul.QCC[i].start_pos, 8);
-         cio_write(tile->marker_mul.QCC[i].len, 2);
-       }
-      
-      for(i = tile->marker_mul.num_PLT - 1; i >= 0; i--) /* PLT */
-       {
-         cio_write(tile->marker_mul.PLT[i].type,2);
-         cio_write(i,2);
-         cio_write(tile->marker_mul.PLT[i].start_pos,8);
-         cio_write(tile->marker_mul.PLT[i].len,2);
-       }
-      
-      for(i = tile->marker_mul.num_PPT - 1; i >= 0; i--) /* PPT */
-       {
-         cio_write(tile->marker_mul.PPT[i].type, 2);
-         cio_write(i, 2);
-         cio_write(tile->marker_mul.PPT[i].start_pos, 8);
-         cio_write(tile->marker_mul.PPT[i].len, 2);
-       }
-      
-      for(i = tile->marker_mul.num_COM - 1; i >= 0; i--) /* COM */
-       {
-         cio_write(tile->marker_mul.COM[i].type, 2);
-         cio_write(i, 2);
-         cio_write(tile->marker_mul.COM[i].start_pos, 8);
-         cio_write(tile->marker_mul.COM[i].len, 2);
-       } 
-    }      
-  
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len, 4);        /* L           */
-  cio_seek(lenp+len);
-  
-  return len;
-}
-
-/* 
- * Read the MHIX box
- *
- * Main Header Index Table (box)
- *
- */
-void jpip_read_mhix(int len)
-{
-  int i, v, marker_type, marker_start_pos, marker_len, marker_remains;
-
-  v = (len - 8) / 14;
-
-  for (i=0; i<v ; i++)
-    {
-      marker_type = cio_read(2);       /* Type of the marker               */ 
-      marker_remains = cio_read(2);    /* Number of same markers following */
-      marker_start_pos = cio_read(2);  /* Start position of the marker     */
-      marker_len = cio_read(2);        /* Length of the marker             */
-    }
-}
-
-/* 
- * Write the FAIX box
- *
- * Fragment array Index box (box)
- *
- */
-int jpip_write_faix(int v, int compno, info_image_t img, j2k_cp_t *j2k_cp, int version)
-{
-  int len, lenp, i, j;
-  int Aux;
-  int tileno, resno, precno, layno, num_packet=0;
-
-  lenp=cio_tell();
-  cio_skip(4);              /* L [at the end]      */
-  cio_write(JPIP_FAIX, 4);  /* FAIX                */ 
-  cio_write(version,1);     /* Version 0 = 4 bytes */
-  
-  switch(v)
-    {
-    case 0:   /* TPIX */
-      cio_write(img.num_max_tile_parts,(version & 0x01)?8:4);                      /* NMAX           */
-      cio_write(img.tw*img.th,(version & 0x01)?8:4);                               /* M              */
-      for (i = 0; i < img.tw*img.th; i++)
-       {
-         for (j = 0; j < img.tile[i].numparts ; j++)
-           {
-             cio_write(img.tile[i].tile_parts[j].start_pos,(version & 0x01)?8:4); /* start position */
-             cio_write(img.tile[i].tile_parts[j].length,(version & 0x01)?8:4);    /* length         */
-             if (version & 0x02)
-               {
-                 if (img.tile[i].numparts == 1 && img.Decomposition > 1)
-                   Aux = img.Decomposition + 1;
-                 else
-                   Aux = j + 1;
-                 
-                 cio_write(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 < img.num_max_tile_parts)
-           {
-             cio_write(0,(version & 0x01)?8:4); /* start position            */
-             cio_write(0,(version & 0x01)?8:4); /* length                    */
-             if (version & 0x02)
-               cio_write(0,4);                  /* Aux_i,j : Auxiliary value */
-             j++;
-           }
-       }
-      break;
-      
-      /*   case 1: */   /* THIX */
-      /* cio_write(1,(version & 0x01)?8:4);  */           /* NMAX */
-      /* cio_write(img.tw*img.th,(version & 0x01)?8:4); */ /* M    */
-      /* for (i=0;i<img.tw*img.th;i++) */
-      /* { */
-      /* cio_write(img.tile[i].start_pos,(version & 0x01)?8:4); */                         /* start position */
-      /* cio_write(img.tile[i].end_header-img.tile[i].start_pos,(version & 0x01)?8:4); */  /* length         */
-      /* if (version & 0x02)*/
-      /* cio_write(0,4); */ /* Aux_i,j : Auxiliary value */
-      /* } */
-      /* break; */
-
-    case 2:  /* PPIX  NOT FINISHED !! */
-      cio_write(img.num_packet_max,(version & 0x01)?8:4); /* NMAX */
-      cio_write(img.tw*img.th,(version & 0x01)?8:4);      /* M    */
-      for(tileno=0;tileno<img.tw*img.th;tileno++)
-       {
-         info_tile_t *tile_Idx = &img.tile[tileno];
-         info_compo_t *compo_Idx = &tile_Idx->compo[compno];
-         int correction;
-         
-         num_packet=0;
-         
-         if(j2k_cp->tcps[tileno].csty&J2K_CP_CSTY_EPH)
-           correction=3;
-         else
-           correction=1;
-         for(resno=0;resno<img.Decomposition+1;resno++)
-           {
-             info_reso_t *reso_Idx = &compo_Idx->reso[resno];
-             for (precno=0;precno<img.tile[tileno].pw*img.tile[tileno].ph;precno++)
-               {
-                 info_prec_t *prec_Idx = &reso_Idx->prec[precno];
-                 for(layno=0;layno<img.Layer;layno++)
-                   {
-                     info_layer_t *layer_Idx = &prec_Idx->layer[layno];
-                     cio_write(layer_Idx->offset,(version & 0x01)?8:4);                                   /* start position */
-                     cio_write((layer_Idx->len_header-correction)?0:layer_Idx->len,(version & 0x01)?8:4); /* length         */
-                     if (version & 0x02)
-                       cio_write(0,4); /* Aux_i,j : Auxiliary value */
-                     num_packet++;
-                   }
-               }
-           }
-         /* PADDING */
-         while (num_packet < img.num_packet_max)
-           {
-             cio_write(0,(version & 0x01)?8:4); /* start position            */
-             cio_write(0,(version & 0x01)?8:4); /* length                    */
-             if (version & 0x02)
-               cio_write(0,4);                  /* Aux_i,j : Auxiliary value */
-             num_packet++;
-           }
-       }
-      
-      break;
-      
-    case 3:  /* PHIX NOT FINISHED !! */
-      cio_write(img.num_packet_max,(version & 0x01)?8:4); /* NMAX */
-      cio_write(img.tw*img.th,(version & 0x01)?8:4);      /* M    */
-      for(tileno=0;tileno<img.tw*img.th;tileno++)
-       {
-         info_tile_t *tile_Idx = &img.tile[tileno];
-         info_compo_t *compo_Idx = &tile_Idx->compo[compno];
-         int correction;
-
-         num_packet = 0;
-         if(j2k_cp->tcps[tileno].csty&J2K_CP_CSTY_EPH)
-           correction=3;
-         else
-           correction=1;
-         for(resno=0;resno<img.Decomposition+1;resno++)
-           {
-             info_reso_t *reso_Idx = &compo_Idx->reso[resno];
-             for (precno=0;precno<img.tile[tileno].pw*img.tile[tileno].ph;precno++)
-               {
-                 info_prec_t *prec_Idx = &reso_Idx->prec[precno];
-                 for(layno=0;layno<img.Layer;layno++)
-                   {
-                     info_layer_t *layer_Idx = &prec_Idx->layer[layno];
-                     cio_write(layer_Idx->offset_header,(version & 0x01)?8:4);                                   /* start position */
-                     cio_write((layer_Idx->len_header-correction)?0:layer_Idx->len_header,(version & 0x01)?8:4); /* length         */
-                     if (version & 0x02)
-                       cio_write(0,4); /* Aux_i,j : Auxiliary value */
-                     num_packet++;
-                   }
-               }
-           }
-         /* PADDING */
-         while (num_packet<img.num_packet_max)
-           {
-             cio_write(0,(version & 0x01)?8:4); /* start position            */
-             cio_write(0,(version & 0x01)?8:4); /* length                    */
-             if (version & 0x02)
-               cio_write(0,4);                  /* Aux_i,j : Auxiliary value */
-             num_packet++;
-           }
-       }
-      break;
-    }
-  
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len, 4);        /* L  */
-  cio_seek(lenp+len);
-
-  return len;
-}
-
-/* 
- * Write the TPIX box
- *
- * Tile-part Index table box (superbox)
- *
- */
-int jpip_write_tpix(info_image_t img, j2k_cp_t *j2k_cp, int version)
-{
-  int len, lenp;
-  lenp=cio_tell();
-  cio_skip(4);              /* L [at the end] */
-  cio_write(JPIP_TPIX, 4);  /* TPIX           */
-  
-  jpip_write_faix(0,0,img, j2k_cp, version);
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len, 4);        /* L              */
-  cio_seek(lenp+len);
-
-  return len;
-}
-
-/* 
- * Write the THIX box
- *
- * Tile header Index table box (superbox)
- *
- */
-//int jpip_write_thix(info_image_t img, j2k_cp_t *j2k_cp)
-//  {
-//  int len, lenp;
-//  lenp=cio_tell();
-//  cio_skip(4);              /* L [at the end] */
-//  cio_write(JPIP_THIX, 4);  /* THIX           */
-  
-//  jpip_write_faix(1,0,img, j2k_cp);
-
-//  len=cio_tell()-lenp;
-//  cio_seek(lenp);
-//  cio_write(len, 4);        /* L              */
-//  cio_seek(lenp+len);
-
-//  return len;
-//}
-
-int jpip_write_thix(info_image_t img, j2k_cp_t *j2k_cp)
-{
-  int len, lenp, i;
-  int tileno;
-  info_marker_t *marker;
-  int num_marker_local_jpip;
-
-  marker = (info_marker_t*)calloc(sizeof(info_marker_t), j2k_cp->tw*j2k_cp->th);
-
-  for ( i = 0; i < 2 ; i++ )
-    {
-      if (i) cio_seek(lenp);
-      
-      lenp = cio_tell();
-      cio_skip(4);              /* L [at the end] */
-      cio_write(JPIP_THIX, 4);  /* THIX           */
-      jpip_write_manf(i, j2k_cp->tw*j2k_cp->th, marker);
-      num_marker_local_jpip=img.Comp;
-      
-      for (tileno = 0; tileno < j2k_cp->tw*j2k_cp->th; tileno++)
-       {
-         marker[tileno].len = jpip_write_mhix(img, 1, tileno);
-         marker[tileno].type = JPIP_MHIX;
-       }
-      
-      len=cio_tell()-lenp;
-      cio_seek(lenp);
-      cio_write(len, 4);        /* L              */
-      cio_seek(lenp+len);
-    }
-
-  free(marker);
-
-  return len;
-}
-/* 
- * Write the PPIX box
- *
- * Precinct Packet Index table box (superbox)
- *
- */
-int jpip_write_ppix(info_image_t img,j2k_cp_t *j2k_cp)
-{
-  int len, lenp, compno, i;
-  info_marker_t *marker;
-  int num_marker_local_jpip;
-  marker = (info_marker_t*)calloc(sizeof(info_marker_t), img.Comp);
-  
-  for (i=0;i<2;i++)
-    {
-      if (i) cio_seek(lenp);
-      
-      lenp=cio_tell();
-      cio_skip(4);              /* L [at the end] */
-      cio_write(JPIP_PPIX, 4);  /* PPIX           */
-      jpip_write_manf(i,img.Comp,marker);
-      num_marker_local_jpip=img.Comp;
-      
-      for (compno=0; compno<img.Comp; compno++)
-       {
-         marker[compno].len=jpip_write_faix(2,compno,img, j2k_cp, 0);
-         marker[compno].type=JPIP_FAIX;
-       }
-   
-      len=cio_tell()-lenp;
-      cio_seek(lenp);
-      cio_write(len, 4);        /* L              */
-      cio_seek(lenp+len);
-    }
-  
-  free(marker);
-
-  return len;
-}
-
-/* 
- * Write the PHIX box
- *
- * Packet Header Index table box (superbox)
- *
- */
-int jpip_write_phix(info_image_t img, j2k_cp_t *j2k_cp)
-{
-  int len, lenp=0, compno, i;
-  info_marker_t *marker;
-
-  marker = (info_marker_t*)calloc(sizeof(info_marker_t), img.Comp);
-
-  for (i=0;i<2;i++)
-    {
-      if (i) cio_seek(lenp);
-      
-      lenp=cio_tell();
-      cio_skip(4);              /* L [at the end] */
-      cio_write(JPIP_PHIX, 4);  /* PHIX           */
-      
-      jpip_write_manf(i,img.Comp,marker);
-
-      for (compno=0; compno<img.Comp; compno++)
-       {       
-         marker[compno].len=jpip_write_faix(3,compno,img, j2k_cp, 0);
-         marker[compno].type=JPIP_FAIX;
-       }
-
-      len=cio_tell()-lenp;
-      cio_seek(lenp);
-      cio_write(len, 4);        /* L              */
-      cio_seek(lenp+len);
-    }
-
-  free(marker);
-
-  return len;
-}
-
-/* 
- * Write the CIDX box
- *
- * Codestream Index box (superbox)
- *
- */
-int jpip_write_cidx(int offset, info_image_t img, j2k_cp_t *j2k_cp, int version)
-{
-  int len, lenp = 0, i;
-  info_marker_t *marker_jpip;
-  int num_marker_jpip = 0;
-
-  marker_jpip = (info_marker_t*)calloc(sizeof(info_marker_t), 32);
-
-  for (i=0;i<2;i++)
-    {
-      if(i)
-       cio_seek(lenp);
-
-      lenp=cio_tell();
-
-      cio_skip(4);              /* L [at the end] */
-      cio_write(JPIP_CIDX, 4);  /* CIDX           */
-      jpip_write_cptr(offset, img);
-
-      jpip_write_manf(i,num_marker_jpip, marker_jpip);
-
-      num_marker_jpip=0;
-      marker_jpip[num_marker_jpip].len=jpip_write_mhix(img, 0, 0);
-      marker_jpip[num_marker_jpip].type=JPIP_MHIX;
-      num_marker_jpip++;
-
-      marker_jpip[num_marker_jpip].len=jpip_write_tpix(img, j2k_cp, version);
-      marker_jpip[num_marker_jpip].type=JPIP_TPIX;
-      num_marker_jpip++;
-
-      marker_jpip[num_marker_jpip].len=jpip_write_thix(img, j2k_cp);
-      marker_jpip[num_marker_jpip].type=JPIP_THIX;
-      num_marker_jpip++;
-
-      marker_jpip[num_marker_jpip].len=jpip_write_ppix(img, j2k_cp);
-      marker_jpip[num_marker_jpip].type=JPIP_PPIX;
-      num_marker_jpip++;
-
-      marker_jpip[num_marker_jpip].len=jpip_write_phix(img, j2k_cp);
-      marker_jpip[num_marker_jpip].type=JPIP_PHIX;
-      num_marker_jpip++;
-
-      len=cio_tell()-lenp;
-      cio_seek(lenp);
-      cio_write(len, 4);        /* L             */
-      cio_seek(lenp+len);
-    }
-
-  free(marker_jpip);
-
-  return len;
-
-}
-
-/* 
- * Write the IPTR box
- *
- * Index Finder box
- *
- */
-void jpip_write_iptr(int offset, int length)
-{
-  int len, lenp;
-  lenp=cio_tell();
-  cio_skip(4);              /* L [at the end] */
-  cio_write(JPIP_IPTR, 4);  /* IPTR           */
-  
-  cio_write(offset,8);
-  cio_write(length,8);
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len, 4);        /* L             */
-  cio_seek(lenp+len);
-}
-
-/* 
- * Write the PRXY box
- *
- * proxy (box)
- *
- */
-void jpip_write_prxy(int offset_jp2c, int length_jp2c, int offset_idx, int length_idx)
-{
-  int len, lenp;
-  lenp=cio_tell();
-  cio_skip(4);              /* L [at the end] */
-  cio_write(JPIP_PRXY, 4);  /* IPTR           */
-  
-  cio_write(offset_jp2c,8); /* OOFF           */
-  cio_write(length_jp2c,4); /* OBH part 1     */
-  cio_write(JP2C,4);        /* OBH part 2     */
-  
-  cio_write(1,1);           /* NI             */
-
-  cio_write(offset_idx,8);  /* IOFF           */
-  cio_write(length_idx,4);  /* IBH part 1     */
-  cio_write(JPIP_CIDX,4);   /* IBH part 2     */
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len, 4);        /* L              */
-  cio_seek(lenp+len);
-}
-
-
-/* 
- * Write the FIDX box
- *
- * File Index (superbox)
- *
- */
-int jpip_write_fidx(int offset_jp2c, int length_jp2c, int offset_idx, int length_idx)
-{
-  int len, lenp;
-  lenp=cio_tell();
-  cio_skip(4);              /* L [at the end] */
-  cio_write(JPIP_FIDX, 4);  /* IPTR           */
-  
-  jpip_write_prxy(offset_jp2c, length_jp2c, offset_idx, offset_jp2c);
-
-  len=cio_tell()-lenp;
-  cio_seek(lenp);
-  cio_write(len, 4);        /* L              */
-  cio_seek(lenp+len);
-
-  return len;
-}
diff --git a/applications/jpip/tools/indexer/phix_manager.c b/applications/jpip/tools/indexer/phix_manager.c
new file mode 100644 (file)
index 0000000..da7a6ae
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * $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 <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;
+    
+  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 */
+  
+  cio_ext_write( cio, cstr_info.packno, 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];
+         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 < cstr_info.packno){
+      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;
+}
diff --git a/applications/jpip/tools/indexer/pi.c b/applications/jpip/tools/indexer/pi.c
deleted file mode 100644 (file)
index 691ef49..0000000
+++ /dev/null
@@ -1,465 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003-2004, Yannick Verschueren
- * Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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 "pi.h"
-#include "int.h"
-#include <stdlib.h>
-#include <stdio.h>
-
-
-/* <summary> */
-/* Create a packet iterator.   */
-/* </summary> */
-pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
-{
-       int p, q;
-       int compno, resno, pino;
-       int maxres = 0;
-       pi_iterator_t *pi;
-       j2k_tcp_t *tcp;
-       j2k_tccp_t *tccp;
-
-       tcp = &cp->tcps[tileno];
-       pi = (pi_iterator_t *) malloc((tcp->numpocs + 1) * sizeof(pi_iterator_t));
-
-       for (pino = 0; pino < tcp->numpocs + 1; pino++) {       /* change */
-               p = tileno % cp->tw;
-               q = tileno / cp->tw;
-
-               pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, img->x0);
-               pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, img->y0);
-               pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, img->x1);
-               pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, img->y1);
-               pi[pino].numcomps = img->numcomps;
-               pi[pino].comps = (pi_comp_t *) malloc(img->numcomps * sizeof(pi_comp_t));
-
-               for (compno = 0; compno < pi->numcomps; compno++) {
-                       int tcx0, tcy0, tcx1, tcy1;
-                       pi_comp_t *comp = &pi[pino].comps[compno];
-                       tccp = &tcp->tccps[compno];
-                       comp->dx = img->comps[compno].dx;
-                       comp->dy = img->comps[compno].dy;
-                       comp->numresolutions = tccp->numresolutions;
-                       comp->resolutions =
-                               (pi_resolution_t *) malloc(comp->numresolutions *
-                                                                                                                                        sizeof(pi_resolution_t));
-                       tcx0 = int_ceildiv(pi->tx0, comp->dx);
-                       tcy0 = int_ceildiv(pi->ty0, comp->dy);
-                       tcx1 = int_ceildiv(pi->tx1, comp->dx);
-                       tcy1 = int_ceildiv(pi->ty1, comp->dy);
-                       if (comp->numresolutions > maxres) {
-                               maxres = comp->numresolutions;
-                       }
-                       for (resno = 0; resno < comp->numresolutions; resno++) {
-                               int levelno;
-                               int rx0, ry0, rx1, ry1;
-                               int px0, py0, px1, py1;
-                               pi_resolution_t *res = &comp->resolutions[resno];
-                               if (tccp->csty & J2K_CCP_CSTY_PRT) {
-                                       res->pdx = tccp->prcw[resno];
-                                       res->pdy = tccp->prch[resno];
-                               } else {
-                                       res->pdx = 15;
-                                       res->pdy = 15;
-                               }
-                               levelno = comp->numresolutions - 1 - resno;
-                               rx0 = int_ceildivpow2(tcx0, levelno);
-                               ry0 = int_ceildivpow2(tcy0, levelno);
-                               rx1 = int_ceildivpow2(tcx1, levelno);
-                               ry1 = int_ceildivpow2(tcy1, levelno);
-                               px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
-                               py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
-                               px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
-                               py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
-                               res->pw = (px1 - px0) >> res->pdx;
-                               res->ph = (py1 - py0) >> res->pdy;
-                       }
-               }
-               
-               tccp = &tcp->tccps[0];
-               pi[pino].step_p=1;
-               pi[pino].step_c=100*pi[pino].step_p;
-               pi[pino].step_r=img->numcomps*pi[pino].step_c;
-               pi[pino].step_l=maxres*pi[pino].step_r;
-               
-               if (pino==0)
-                 pi[pino].include=(short int*)calloc(img->numcomps*maxres*tcp->numlayers*100,sizeof(short int));
-               else
-                 pi[pino].include=pi[pino-1].include;
-
-               /*if (pino == tcp->numpocs) {*/
-                 if (tcp->POC == 0) {
-                       pi[pino].first = 1;
-                       pi[pino].poc.resno0 = 0;
-                       pi[pino].poc.compno0 = 0;
-                       pi[pino].poc.layno1 = tcp->numlayers;
-                       pi[pino].poc.resno1 = maxres;
-                       pi[pino].poc.compno1 = img->numcomps;
-                       pi[pino].poc.prg = tcp->prg;
-               } else {
-                       pi[pino].first = 1;
-                       pi[pino].poc.resno0 = tcp->pocs[pino].resno0;
-                       pi[pino].poc.compno0 = tcp->pocs[pino].compno0;
-                       pi[pino].poc.layno1 = tcp->pocs[pino].layno1;
-                       pi[pino].poc.resno1 = tcp->pocs[pino].resno1;
-                       pi[pino].poc.compno1 = tcp->pocs[pino].compno1;
-                       pi[pino].poc.prg = tcp->pocs[pino].prg;
-               }
-       }
-       return pi;
-}
-
-/* <summary> */
-/* Get next packet in layer=resolution-component-precinct order.   */
-/* </summary> */
-int pi_next_lrcp(pi_iterator_t * pi)
-{
-       pi_comp_t *comp;
-       pi_resolution_t *res;
-
-       if (!pi->first) {
-               comp = &pi->comps[pi->compno];
-               res = &comp->resolutions[pi->resno];
-               goto skip;
-       } else {
-               pi->first = 0;
-       }
-       for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
-               for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
-                                pi->resno++) {
-                       for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
-                                        pi->compno++) {
-                               comp = &pi->comps[pi->compno];
-                               if (pi->resno >= comp->numresolutions) {
-
-                                       continue;
-                               }
-                               res = &comp->resolutions[pi->resno];
-                               for (pi->precno = 0; pi->precno < res->pw * res->ph; pi->precno++) {
-                                 if (!pi->include[pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p]){
-                                   pi->include[pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p] = 1;
-                                   return 1;
-                                       }
-                               skip:;
-                               }
-                       }
-               }
-       }
-       return 0;
-}
-
-/* <summary> */
-/* Get next packet in resolution-layer-component-precinct order.   */
-/* </summary> */
-int pi_next_rlcp(pi_iterator_t * pi)
-{
-       pi_comp_t *comp;
-       pi_resolution_t *res;
-       if (!pi->first) {
-               comp = &pi->comps[pi->compno];
-               res = &comp->resolutions[pi->resno];
-               goto skip;
-       } else {
-               pi->first = 0;
-       }
-       for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
-               for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
-                       for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
-                                        pi->compno++) {
-                               comp = &pi->comps[pi->compno];
-                               if (pi->resno >= comp->numresolutions) {
-                                       continue;
-                               }
-                               res = &comp->resolutions[pi->resno];
-                               for (pi->precno = 0; pi->precno < res->pw * res->ph; pi->precno++) {
-                                 if (!pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p]){
-                                   pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p] = 1;
-                                   return 1;
-                                 }
-                               skip:;
-                               }
-                       }
-               }
-       }
-       return 0;
-}
-
-/* <summary> */
-/* Get next packet in resolution-precinct-component-layer order.   */
-/* </summary> */
-int pi_next_rpcl(pi_iterator_t * pi)
-{
-       pi_comp_t *comp;
-       pi_resolution_t *res;
-       if (!pi->first) {
-               goto skip;
-       } else {
-               int compno, resno;
-               pi->first = 0;
-               pi->dx = 0;
-               pi->dy = 0;
-               for (compno = 0; compno < pi->numcomps; compno++) {
-                       comp = &pi->comps[compno];
-                       for (resno = 0; resno < comp->numresolutions; resno++) {
-                               int dx, dy;
-                               res = &comp->resolutions[resno];
-                               dx =
-                                       comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
-                               dy =
-                                       comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
-                               pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
-                               pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
-                       }
-               }
-       }
-       for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
-               for (pi->y = pi->ty0; pi->y < pi->ty1;
-                                pi->y += pi->dy - (pi->y % pi->dy)) {
-                       for (pi->x = pi->tx0; pi->x < pi->tx1;
-                                        pi->x += pi->dx - (pi->x % pi->dx)) {
-                               for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
-                                                pi->compno++) {
-                                       int levelno;
-                                       int trx0, try0;
-                                       int rpx, rpy;
-                                       int prci, prcj;
-                                       comp = &pi->comps[pi->compno];
-                                       if (pi->resno >= comp->numresolutions) {
-                                               continue;
-                                       }
-                                       res = &comp->resolutions[pi->resno];
-                                       levelno = comp->numresolutions - 1 - pi->resno;
-                                       trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
-                                       try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
-                                       rpx = res->pdx + levelno;
-                                       rpy = res->pdy + levelno;
-                                       if (!
-                                                       (pi->x % (comp->dx << rpx) == 0
-                                                        || (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
-                                               continue;
-                                       }
-                                       if (!
-                                                       (pi->y % (comp->dy << rpy) == 0
-                                                        || (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
-                                               continue;
-                                       }
-                                       prci =
-                                               int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno),
-                                                                                                                res->pdx) - int_floordivpow2(trx0, res->pdx);
-                                       prcj =
-                                               int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno),
-                                                                                                                res->pdy) - int_floordivpow2(try0, res->pdy);
-                                       pi->precno = prci + prcj * res->pw;
-                                       for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
-                                         if (!pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p]){
-                                           pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p] = 1;
-                                           return 1;
-                                               }
-                                       skip:;
-                                       }
-                               }
-                       }
-               }
-       }
-       return 0;
-}
-
-/* <summary> */
-/* Get next packet in precinct-component-resolution-layer order.   */
-/* </summary> */
-int pi_next_pcrl(pi_iterator_t * pi)
-{
-       pi_comp_t *comp;
-       pi_resolution_t *res;
-       if (!pi->first) {
-               comp = &pi->comps[pi->compno];
-               goto skip;
-       } else {
-               int compno, resno;
-               pi->first = 0;
-               pi->dx = 0;
-               pi->dy = 0;
-               for (compno = 0; compno < pi->numcomps; compno++) {
-                       comp = &pi->comps[compno];
-                       for (resno = 0; resno < comp->numresolutions; resno++) {
-                               int dx, dy;
-                               res = &comp->resolutions[resno];
-                               dx =
-                                       comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
-                               dy =
-                                       comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
-                               pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
-                               pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
-                       }
-               }
-       }
-       for (pi->y = pi->ty0; pi->y < pi->ty1;
-                        pi->y += pi->dy - (pi->y % pi->dy)) {
-               for (pi->x = pi->tx0; pi->x < pi->tx1;
-                                pi->x += pi->dx - (pi->x % pi->dx)) {
-                       for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
-                                        pi->compno++) {
-                               comp = &pi->comps[pi->compno];
-                               for (pi->resno = pi->poc.resno0;
-                                                pi->resno < int_min(pi->poc.resno1, comp->numresolutions);
-                                                pi->resno++) {
-                                       int levelno;
-                                       int trx0, try0;
-                                       int rpx, rpy;
-                                       int prci, prcj;
-                                       res = &comp->resolutions[pi->resno];
-                                       levelno = comp->numresolutions - 1 - pi->resno;
-                                       trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
-                                       try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
-                                       rpx = res->pdx + levelno;
-                                       rpy = res->pdy + levelno;
-                                       if (!
-                                                       (pi->x % (comp->dx << rpx) == 0
-                                                        || (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
-                                               continue;
-                                       }
-                                       if (!
-                                                       (pi->y % (comp->dy << rpy) == 0
-                                                        || (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
-                                               continue;
-                                       }
-                                       prci =
-                                               int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno),
-                                                                                                                res->pdx) - int_floordivpow2(trx0, res->pdx);
-                                       prcj =
-                                               int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno),
-                                                                                                                res->pdy) - int_floordivpow2(try0, res->pdy);
-                                       pi->precno = prci + prcj * res->pw;
-                                       for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
-                                         if (! pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p]){
-                                           pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p] = 1;
-                                                       return 1;
-                                               }
-                                       skip:;
-                                       }
-                               }
-                       }
-               }
-       }
-       return 0;
-}
-
-/* <summary> */
-/* Get next packet in component-precinct-resolution-layer order.   */
-/* </summary> */
-int pi_next_cprl(pi_iterator_t * pi)
-{
-       pi_comp_t *comp;
-       pi_resolution_t *res;
-       if (!pi->first) {
-               comp = &pi->comps[pi->compno];
-               goto skip;
-       } else {
-               pi->first = 0;
-       }
-       for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
-                        pi->compno++) {
-               int resno;
-               comp = &pi->comps[pi->compno];
-               pi->dx = 0;
-               pi->dy = 0;
-               for (resno = 0; resno < comp->numresolutions; resno++) {
-                       int dx, dy;
-                       res = &comp->resolutions[resno];
-                       dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
-                       dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
-                       pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
-                       pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
-               }
-               for (pi->y = pi->ty0; pi->y < pi->ty1;
-                                pi->y += pi->dy - (pi->y % pi->dy)) {
-                       for (pi->x = pi->tx0; pi->x < pi->tx1;
-                                        pi->x += pi->dx - (pi->x % pi->dx)) {
-                               for (pi->resno = pi->poc.resno0;
-                                                pi->resno < int_min(pi->poc.resno1, comp->numresolutions);
-                                                pi->resno++) {
-                                       int levelno;
-                                       int trx0, try0;
-                                       int rpx, rpy;
-                                       int prci, prcj;
-                                       res = &comp->resolutions[pi->resno];
-                                       levelno = comp->numresolutions - 1 - pi->resno;
-                                       trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
-                                       try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
-                                       rpx = res->pdx + levelno;
-                                       rpy = res->pdy + levelno;
-                                       if (!
-                                                       (pi->x % (comp->dx << rpx) == 0
-                                                        || (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
-                                               continue;
-                                       }
-                                       if (!
-                                                       (pi->y % (comp->dy << rpy) == 0
-                                                        || (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
-                                               continue;
-                                       }
-                                       prci =
-                                               int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno),
-                                                                                                                res->pdx) - int_floordivpow2(trx0, res->pdx);
-                                       prcj =
-                                               int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno),
-                                                                                                                res->pdy) - int_floordivpow2(try0, res->pdy);
-                                       pi->precno = prci + prcj * res->pw;
-                                       for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
-                                         if (! pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p]){
-                                           pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p] = 1;
-                                           return 1;
-                                               }
-                                       skip:;
-                                       }
-                               }
-                       }
-               }
-       }
-       return 0;
-}
-
-/* <summary> */
-/* Get next packet.   */
-/* </summary> */
-int pi_next(pi_iterator_t * pi)
-{
-       switch (pi->poc.prg) {
-       case 0:
-               return pi_next_lrcp(pi);
-       case 1:
-               return pi_next_rlcp(pi);
-       case 2:
-               return pi_next_rpcl(pi);
-       case 3:
-               return pi_next_pcrl(pi);
-       case 4:
-               return pi_next_cprl(pi);
-       }
-       return 0;
-}
diff --git a/applications/jpip/tools/indexer/pi.h b/applications/jpip/tools/indexer/pi.h
deleted file mode 100644 (file)
index b300b9e..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * 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 __PI_H
-#define __PI_H
-
-#include "j2k.h"
-#include "tcd.h"
-
-typedef struct {
-       int pdx, pdy;
-       int pw, ph;
-} pi_resolution_t;
-
-typedef struct {
-       int dx, dy;
-       int numresolutions;
-       pi_resolution_t *resolutions;
-} pi_comp_t;
-
-typedef struct {
-       short int *include;
-  int step_l, step_r, step_c, step_p; 
-       int compno, resno, precno, layno;       /* component, resolution, precinct and layer that indentify the packet */
-       int first;
-       j2k_poc_t poc;
-       int numcomps;
-       pi_comp_t *comps;
-       int tx0, ty0, tx1, ty1;
-       int x, y, dx, dy;
-} pi_iterator_t;                                                               /* packet iterator */
-
-/*
- * Create a packet iterator
- * img: raw image for which the packets will be listed
- * cp: coding paremeters
- * tileno: number that identifies the tile for which to list the packets
- * return value: returns a packet iterator that points to the first packet of the tile
- */
-pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno);
-
-/* 
- * Modify the packet iterator to point to the next packet
- * pi: packet iterator to modify
- * return value: returns 0 if pi pointed to the last packet or else returns 1 
- */
-int pi_next(pi_iterator_t * pi);
-
-#endif
diff --git a/applications/jpip/tools/indexer/ppix_manager.c b/applications/jpip/tools/indexer/ppix_manager.c
new file mode 100644 (file)
index 0000000..4fd45f8
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * $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;
+
+  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 */
+
+  cio_ext_write( cio, cstr_info.packno, 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];
+         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 < cstr_info.packno){
+      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;
+
+}
diff --git a/applications/jpip/tools/indexer/t2.c b/applications/jpip/tools/indexer/t2.c
deleted file mode 100644 (file)
index 14a44be..0000000
+++ /dev/null
@@ -1,389 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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 "t2.h"
-#include "tcd.h"
-#include "bio.h"
-#include "j2k.h"
-#include "pi.h"
-#include "tgt.h"
-#include "int.h"
-#include "cio.h"
-#include <stdio.h>
-#include <setjmp.h>
-#include <string.h>
-#include <stdlib.h> 
-
-#define RESTART 0x04
-
-extern jmp_buf j2k_error;
-
-int t2_getcommacode() {
-    int n;
-    for (n=0; bio_read(1); n++) {}
-    return n;
-}
-
-int t2_getnumpasses()
-{
-    int n;
-    if (!bio_read(1)) return 1;
-    if (!bio_read(1)) return 2;
-    if ((n=bio_read(2))!=3) return 3+n;
-    if ((n=bio_read(5))!=31) return 6+n;
-    return 37+bio_read(7);
-}
-
-void t2_init_seg(tcd_seg_t *seg, int cblksty) {
-    seg->numpasses=0;
-    seg->len=0;
-    seg->maxpasses=cblksty&J2K_CCP_CBLKSTY_TERMALL?1:100;
-}
-
-int t2_decode_packet(unsigned char *src, int len, tcd_tile_t *tile, j2k_cp_t * cp, j2k_tcp_t *tcp, int compno, int resno, int precno, int layno, info_layer_t *layer_Idx) {
-    int bandno, cblkno;
-    tcd_tilecomp_t *tilec = &tile->comps[compno];
-    tcd_resolution_t *res = &tilec->resolutions[resno];
-    unsigned char *c = src;
-    unsigned char *d = c;
-    int e;
-    int present;
-
-    if (layno == 0) {
-        for (bandno = 0; bandno < res->numbands; bandno++) {
-            tcd_band_t *band = &res->bands[bandno];
-            tcd_precinct_t *prc = &band->precincts[precno];
-            tgt_reset(prc->incltree);
-            tgt_reset(prc->imsbtree);
-            for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
-                tcd_cblk_t *cblk = &prc->cblks[cblkno];
-                cblk->numsegs = 0;
-            }
-        }  
-    }
-    /* INDEX */
-    layer_Idx->len_header = 0;
-
-    /* When the marker PPT/PPM is used the packet header are store in PPT/PPM marker
-       This part deal with this caracteristic
-       step 1: Read packet header in the saved structure
-       step 2: (futher) return to codestream for decoding */
-    if (cp->ppm == 1) /* PPM */
-      {            
-       c = cp->ppm_data;
-       d = c;
-       bio_init_dec(c, 1000);
-      } else 
-       {
-         if (tcp->ppt == 1) /* PPT */
-           {
-             c = tcp->ppt_data;
-             d = c;
-             bio_init_dec(c, 1000);
-           } else /* Normal Case */
-             {
-               if (tcp->csty & J2K_CP_CSTY_SOP) 
-                 {
-                   if ((*c) != 255 || (*(c+1) != 145)) {printf("Error : expected SOP marker [1]!!!\n");}
-                   c += 6;
-                 }
-               bio_init_dec(c, src + len - c);
-               layer_Idx->len_header = -6;
-             }
-       }
-    
-    present = bio_read(1);
-    
-    if (!present) 
-      {
-       bio_inalign();
-       /* Normal case */
-       c += bio_numbytes();
-       if (tcp->csty & J2K_CP_CSTY_EPH) 
-         {
-           if ((*c) != 255 || (*(c+1) != 146)) {printf("Error : expected EPH marker [1]!!!\n");}
-           c += 2;
-         }
-       /* INDEX */
-       layer_Idx->len_header += (c-d);
-
-       /* PPT and PPM dealing */
-       if (cp->ppm == 1) /* PPM */
-         {     
-           cp->ppm_data = c;       
-           return 0;
-         }
-       if (tcp->ppt == 1) /* PPT */
-         {
-           tcp->ppt_data = c;
-           return 0;
-         }
-       return c - src;
-      }
-    
-    for (bandno=0; bandno<res->numbands; bandno++) {
-        tcd_band_t *band = &res->bands[bandno];
-        tcd_precinct_t *prc = &band->precincts[precno];
-        for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
-            int included, increment, n;
-            tcd_cblk_t *cblk = &prc->cblks[cblkno];
-            tcd_seg_t *seg;
-            if (!cblk->numsegs) {
-                included = tgt_decode(prc->incltree, cblkno, layno+1);
-            } else {
-                included = bio_read(1);
-            }
-            if (!included) {
-                cblk->numnewpasses = 0;
-                continue;
-            }
-            if (!cblk->numsegs) {
-                int i, numimsbs;
-                for (i = 0; !tgt_decode(prc->imsbtree, cblkno, i); i++) {}
-                numimsbs = i-1;
-                cblk->numbps = band->numbps - numimsbs;
-                cblk->numlenbits = 3;
-            }
-            cblk->numnewpasses = t2_getnumpasses();
-            increment = t2_getcommacode();
-            cblk->numlenbits += increment;
-            if (!cblk->numsegs) {
-                seg = &cblk->segs[0];
-                t2_init_seg(seg, tcp->tccps[compno].cblksty);
-            } else {
-                seg = &cblk->segs[cblk->numsegs - 1];
-                if (seg->numpasses == seg->maxpasses) {
-                    t2_init_seg(++seg, tcp->tccps[compno].cblksty);
-                }
-            }
-            n = cblk->numnewpasses;
-            do {
-                seg->numnewpasses = int_min(seg->maxpasses-seg->numpasses, n);
-                seg->newlen = bio_read(cblk->numlenbits + int_floorlog2(seg->numnewpasses));
-                n -= seg->numnewpasses;
-                if (n > 0) {
-                    t2_init_seg(++seg, tcp->tccps[compno].cblksty);
-                }
-            } while (n > 0);
-        }
-    }
-    if(bio_inalign()) return -999;
-    c += bio_numbytes();
-
-    if (tcp->csty & J2K_CP_CSTY_EPH) { /* EPH marker */
-      if ((*c) != 255 || (*(c+1) != 146)) {printf("Error : expected EPH marker [2]!!!\n"); }
-      c += 2;
-    }
-    
-    /* INDEX */
-    layer_Idx->len_header += (c-d);
-
-    /* PPT Step 2 : see above for details */
-    if (cp->ppm == 1)
-      {
-       cp->ppm_data = c; /* Update pointer */
-
-       /* INDEX */
-       layer_Idx->len_header = c-d;
-
-       c = src;
-       d = c;
-       if (tcp->csty & J2K_CP_CSTY_SOP) 
-         {
-           if ((*c) != 255 || (*(c+1) != 145)) {printf("Error : expected SOP marker [2] !!!\n"); }
-           c += 6;
-         }
-       bio_init_dec(c, src + len - c);
-      } else 
-       {
-         if (tcp->ppt == 1)
-           { 
-             tcp->ppt_data = c; /* Update pointer */
-             /* INDEX */
-             layer_Idx->len_header = c-d;
-
-             c = src;
-             d = c;
-             if (tcp->csty & J2K_CP_CSTY_SOP) /* SOP marker */
-               { 
-                 if ((*c) != 255 || (*(c+1) != 145)) {printf("Error : expected SOP marker [2] !!!\n"); }
-                 c += 6;
-               }
-             bio_init_dec(c, src + len - c);
-             
-           }
-       }
-
-    for (bandno = 0; bandno < res->numbands; bandno++) {
-        tcd_band_t *band = &res->bands[bandno];
-        tcd_precinct_t *prc = &band->precincts[precno];
-        for (cblkno = 0; cblkno < prc->cw*prc->ch; cblkno++) {
-            tcd_cblk_t *cblk = &prc->cblks[cblkno];
-            tcd_seg_t *seg;
-            if (!cblk->numnewpasses) continue;
-            if (!cblk->numsegs) {
-                seg = &cblk->segs[cblk->numsegs++];
-                cblk->len = 0;
-            } else {
-                seg = &cblk->segs[cblk->numsegs-1];
-                if (seg->numpasses == seg->maxpasses) {
-                    seg++;
-                    cblk->numsegs++;
-                }
-            }
-            do {
-             if (c + seg->newlen > src + len) return -999;
-                memcpy(cblk->data + cblk->len, c, seg->newlen);
-                if (seg->numpasses == 0) {
-                    seg->data = cblk->data + cblk->len;
-                }
-                c += seg->newlen;
-                cblk->len += seg->newlen;
-                seg->len += seg->newlen;
-                seg->numpasses += seg->numnewpasses;
-                cblk->numnewpasses -= seg->numnewpasses;
-                if (cblk->numnewpasses > 0) {
-                    seg++;
-                    cblk->numsegs++;
-                }
-            } while (cblk->numnewpasses > 0);
-        }
-    }
-    /* <INDEX> */
-    e = c-d;
-    layer_Idx->len = e;
-    /* </INDEX> */
-
-    return c-src;
-}
-
-void t2_init_info_packets(info_image_t *img, j2k_cp_t *cp)
-{
-  int compno, tileno, resno, precno, layno;
-
-  for(compno = 0; compno < img->Comp; compno++)
-    {
-      for(tileno = 0; tileno < img->tw*img->th; tileno++)
-       {
-         info_tile_t *tile_Idx = &img->tile[tileno];
-         info_compo_t *compo_Idx = &tile_Idx->compo[compno];
-         for(resno = 0; resno < img->Decomposition + 1 ; resno++)
-           {
-             info_reso_t *reso_Idx = &compo_Idx->reso[resno];
-             for (precno = 0; precno < img->tile[tileno].pw * img->tile[tileno].ph; precno++)
-               {
-                 info_prec_t *prec_Idx = &reso_Idx->prec[precno];
-                 for(layno = 0; layno < img->Layer ; layno++)
-                   {
-                     info_layer_t *layer_Idx = &prec_Idx->layer[layno];
-                     layer_Idx->offset = 0;        /* start position */
-                     layer_Idx->len_header = 0;    /* length         */
-                   }
-               }
-           }
-       }
-    }
-}
-
-int t2_decode_packets(unsigned char *src, int len, j2k_image_t *img, j2k_cp_t *cp, int tileno, tcd_tile_t *tile, info_image_t *imgg) {
-    unsigned char *c = src;
-    pi_iterator_t *pi;
-    int pino, compno,e;
-    int partno;
-    info_tile_part_t *tile_part;
-    int position;
-    int length_read;
-    info_tile_t *tile_Idx;
-    info_compo_t *compo_Idx;
-    info_reso_t *reso_Idx;
-    info_prec_t *prec_Idx;
-    info_layer_t *layer_Idx;
-
-    t2_init_info_packets(imgg, cp); /* Initialize the packets information : LEN and OFFSET to 0 */
-
-    tile_Idx = &imgg->tile[tileno];
-    tile_Idx->num_packet = 0;
-    pi = pi_create(img, cp, tileno);
-    partno = 0;
-    tile_part = &tile_Idx->tile_parts[partno];
-    position = tile_part->end_header + 1;
-    length_read = 0;
-
-    for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++)
-      {
-       while (pi_next(&pi[pino])) 
-         {   
-           compo_Idx = &tile_Idx->compo[pi[pino].compno];
-           reso_Idx = &compo_Idx->reso[pi[pino].resno];
-           prec_Idx = &reso_Idx->prec[pi[pino].precno];
-           layer_Idx = &prec_Idx->layer[pi[pino].layno];
-           
-           layer_Idx->offset = position;
-           layer_Idx->offset_header = position;
-           
-           e = t2_decode_packet(c, src+len-c, tile, cp, &cp->tcps[tileno], pi[pino].compno, pi[pino].resno, pi[pino].precno, pi[pino].layno,layer_Idx);
-           if (e == -999)
-             {
-               break;
-             } else
-               c += e;
-           position += e;
-           
-           /* Update position in case of multiple tile-parts for a tile >> */
-           length_read += e;
-           if (length_read >= (tile_part->end_pos - tile_part->end_header))
-             {
-               partno++;
-               tile_part = &tile_Idx->tile_parts[partno];
-               position = tile_part->end_header + 1;
-               length_read = 0;
-             }
-           /* << end_update */
-           
-           tile_Idx->num_packet++;
-         }
-       
-       // FREE space memory taken by pi
-       for (compno = 0; compno < pi[pino].numcomps; compno++) 
-         { 
-           free(pi[pino].comps[compno].resolutions);
-         } 
-       free(pi[pino].comps);
-      }
-    
-    free(pi[0].include);
-    free(pi);
-    if (e==-999)
-      return e;
-    else
-      {
-       imgg->num_packet_max=int_max(imgg->num_packet_max,tile_Idx->num_packet);
-       return c-src;
-      }
-}
diff --git a/applications/jpip/tools/indexer/tcd.c b/applications/jpip/tools/indexer/tcd.c
deleted file mode 100644 (file)
index c4045c7..0000000
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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 "tcd.h"
-#include "int.h"
-#include "t2.h"
-#include <setjmp.h>
-#include <float.h>
-#include <stdio.h>
-#include <time.h>
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-
-static tcd_image_t tcd_image;
-
-static j2k_image_t *tcd_img;
-static j2k_cp_t *tcd_cp;
-
-extern jmp_buf j2k_error;
-
-void tcd_init(j2k_image_t *img, j2k_cp_t *cp, info_image_t *imgg) {
-    int tileno, compno, resno, bandno, precno, cblkno;
-    tcd_img=img;
-    tcd_cp=cp;
-    tcd_image.tw=cp->tw;
-    tcd_image.th=cp->th;
-    tcd_image.tiles=(tcd_tile_t*)malloc(cp->tw*cp->th*sizeof(tcd_tile_t));
-    for (tileno=0; tileno<cp->tw*cp->th; tileno++) {
-        j2k_tcp_t *tcp=&cp->tcps[tileno];
-        tcd_tile_t *tile=&tcd_image.tiles[tileno];
-        // cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000)
-        int p=tileno%cp->tw;  // si numerotation matricielle ..
-        int q=tileno/cp->tw;  // .. coordonnees de la tile (q,p) q pour ligne et p pour colonne
-       info_tile_t *tile_Idx=&imgg->tile[tileno]; // INDEX
-
-       // 4 borders of the tile rescale on the image if necessary
-        tile->x0=int_max(cp->tx0+p*cp->tdx, img->x0);
-        tile->y0=int_max(cp->ty0+q*cp->tdy, img->y0);
-        tile->x1=int_min(cp->tx0+(p+1)*cp->tdx, img->x1);
-        tile->y1=int_min(cp->ty0+(q+1)*cp->tdy, img->y1);
-       
-        tile->numcomps=img->numcomps;
-        tile->comps=(tcd_tilecomp_t*)malloc(img->numcomps*sizeof(tcd_tilecomp_t));
-        tile_Idx->compo=(info_compo_t*)malloc(img->numcomps*sizeof(info_compo_t)); // INDEX
-       for (compno=0; compno<tile->numcomps; compno++) {
-            j2k_tccp_t *tccp=&tcp->tccps[compno];
-            tcd_tilecomp_t *tilec=&tile->comps[compno];
-           info_compo_t *compo_Idx=&tile_Idx->compo[compno]; // INDEX
-
-           // border of each tile component (global)
-            tilec->x0=int_ceildiv(tile->x0, img->comps[compno].dx);
-            tilec->y0=int_ceildiv(tile->y0, img->comps[compno].dy);
-           tilec->x1=int_ceildiv(tile->x1, img->comps[compno].dx);
-            tilec->y1=int_ceildiv(tile->y1, img->comps[compno].dy);
-           
-            tilec->data=(int*)malloc(sizeof(int)*(tilec->x1-tilec->x0)*(tilec->y1-tilec->y0));
-            tilec->numresolutions=tccp->numresolutions;
-            tilec->resolutions=(tcd_resolution_t*)malloc(tilec->numresolutions*sizeof(tcd_resolution_t));
-           compo_Idx->reso=(info_reso_t*)malloc(tilec->numresolutions*sizeof(info_reso_t)); // INDEX
-            for (resno=0; resno<tilec->numresolutions; resno++) {
-                int pdx, pdy;
-                int levelno=tilec->numresolutions-1-resno;
-                int tlprcxstart, tlprcystart, brprcxend, brprcyend;
-                int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend;
-                int cbgwidthexpn, cbgheightexpn;
-                int cblkwidthexpn, cblkheightexpn;
-                tcd_resolution_t *res=&tilec->resolutions[resno];
-               info_reso_t *res_Idx=&compo_Idx->reso[resno]; // INDEX
-               int precno_Idx; // INDEX
-
-               // border for each resolution level (global)
-                res->x0=int_ceildivpow2(tilec->x0, levelno);
-                res->y0=int_ceildivpow2(tilec->y0, levelno);
-                res->x1=int_ceildivpow2(tilec->x1, levelno);
-                res->y1=int_ceildivpow2(tilec->y1, levelno);
-               
-               res->numbands=resno==0?1:3;
-               // p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000)
-                if (tccp->csty&J2K_CCP_CSTY_PRT) {
-                    pdx=tccp->prcw[resno];
-                    pdy=tccp->prch[resno];
-               } else {
-                    pdx=15;
-                    pdy=15;
-                }
-               // p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) 
-                tlprcxstart=int_floordivpow2(res->x0, pdx)<<pdx;
-                tlprcystart=int_floordivpow2(res->y0, pdy)<<pdy;
-                brprcxend=int_ceildivpow2(res->x1, pdx)<<pdx;
-                brprcyend=int_ceildivpow2(res->y1, pdy)<<pdy;
-                res->pw=(brprcxend-tlprcxstart)>>pdx;
-                res->ph=(brprcyend-tlprcystart)>>pdy;
-
-               // <INDEX>
-               imgg->tile[tileno].pw=res->pw;
-               imgg->tile[tileno].ph=res->ph;
-               
-               res_Idx->prec=(info_prec_t*)malloc(res->pw*res->ph*sizeof(info_prec_t));
-               for (precno_Idx=0;precno_Idx<res->pw*res->ph;precno_Idx++)
-                 {
-                   info_prec_t *prec_Idx = &res_Idx->prec[precno_Idx];
-                   prec_Idx->layer=(info_layer_t*)malloc(imgg->Layer*sizeof(info_layer_t));
-                 }
-               
-               imgg->pw=res->pw;  // old parser version
-               imgg->ph=res->ph;  // old parser version
-               imgg->pdx=1<<pdx;
-               imgg->pdy=1<<pdy;
-               // </INDEX>
-
-                if (resno==0) {
-                    tlcbgxstart=tlprcxstart;
-                    tlcbgystart=tlprcystart;
-                    brcbgxend=brprcxend;
-                    brcbgyend=brprcyend;
-                    cbgwidthexpn=pdx;
-                    cbgheightexpn=pdy;
-                } else {
-                    tlcbgxstart=int_ceildivpow2(tlprcxstart, 1);
-                    tlcbgystart=int_ceildivpow2(tlprcystart, 1);
-                    brcbgxend=int_ceildivpow2(brprcxend, 1);
-                    brcbgyend=int_ceildivpow2(brprcyend, 1);
-                    cbgwidthexpn=pdx-1;
-                    cbgheightexpn=pdy-1;
-                }
-
-                cblkwidthexpn=int_min(tccp->cblkw, cbgwidthexpn);
-                cblkheightexpn=int_min(tccp->cblkh, cbgheightexpn);
-
-                for (bandno=0; bandno<res->numbands; bandno++) {
-                    int x0b, y0b;
-                    tcd_band_t *band=&res->bands[bandno];
-                    band->bandno=resno==0?0:bandno+1;
-                    x0b=(band->bandno==1)||(band->bandno==3)?1:0;
-                    y0b=(band->bandno==2)||(band->bandno==3)?1:0;
-
-                    if (band->bandno==0) {
-                     // band border (global)
-                     band->x0=int_ceildivpow2(tilec->x0, levelno);
-                     band->y0=int_ceildivpow2(tilec->y0, levelno);
-                     band->x1=int_ceildivpow2(tilec->x1, levelno);
-                     band->y1=int_ceildivpow2(tilec->y1, levelno);
-                    } else {
-                     // band border (global)
-                     band->x0=int_ceildivpow2(tilec->x0-(1<<levelno)*x0b, levelno+1);
-                     band->y0=int_ceildivpow2(tilec->y0-(1<<levelno)*y0b, levelno+1);
-                     band->x1=int_ceildivpow2(tilec->x1-(1<<levelno)*x0b, levelno+1);
-                     band->y1=int_ceildivpow2(tilec->y1-(1<<levelno)*y0b, levelno+1);
-                    }
-
-                    band->precincts=(tcd_precinct_t*)malloc(res->pw*res->ph*sizeof(tcd_precinct_t));
-
-                    for (precno=0; precno<res->pw*res->ph; precno++) {
-                        int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend;
-                        int cbgxstart=tlcbgxstart+(precno%res->pw)*(1<<cbgwidthexpn);
-                        int cbgystart=tlcbgystart+(precno/res->pw)*(1<<cbgheightexpn);
-                        int cbgxend=cbgxstart+(1<<cbgwidthexpn);
-                        int cbgyend=cbgystart+(1<<cbgheightexpn);
-                        tcd_precinct_t *prc=&band->precincts[precno];
-                       // precinct size (global)
-                        prc->x0=int_max(cbgxstart, band->x0);
-                        prc->y0=int_max(cbgystart, band->y0);
-                        prc->x1=int_min(cbgxend, band->x1);
-                        prc->y1=int_min(cbgyend, band->y1);
-
-                        tlcblkxstart=int_floordivpow2(prc->x0, cblkwidthexpn)<<cblkwidthexpn;
-                        tlcblkystart=int_floordivpow2(prc->y0, cblkheightexpn)<<cblkheightexpn;
-                        brcblkxend=int_ceildivpow2(prc->x1, cblkwidthexpn)<<cblkwidthexpn;
-                        brcblkyend=int_ceildivpow2(prc->y1, cblkheightexpn)<<cblkheightexpn;
-                        prc->cw=(brcblkxend-tlcblkxstart)>>cblkwidthexpn;
-                        prc->ch=(brcblkyend-tlcblkystart)>>cblkheightexpn;
-
-                        prc->cblks=(tcd_cblk_t*)malloc(prc->cw*prc->ch*sizeof(tcd_cblk_t));
-
-                        prc->incltree=tgt_create(prc->cw, prc->ch);
-                        prc->imsbtree=tgt_create(prc->cw, prc->ch);
-
-                        for (cblkno=0; cblkno<prc->cw*prc->ch; cblkno++) {
-                            int cblkxstart=tlcblkxstart+(cblkno%prc->cw)*(1<<cblkwidthexpn);
-                            int cblkystart=tlcblkystart+(cblkno/prc->cw)*(1<<cblkheightexpn);
-                            int cblkxend=cblkxstart+(1<<cblkwidthexpn);
-                            int cblkyend=cblkystart+(1<<cblkheightexpn);
-                            tcd_cblk_t *cblk=&prc->cblks[cblkno];
-                           // code-block size (global)
-                            cblk->x0=int_max(cblkxstart, prc->x0);
-                            cblk->y0=int_max(cblkystart, prc->y0);
-                            cblk->x1=int_min(cblkxend, prc->x1);
-                            cblk->y1=int_min(cblkyend, prc->y1);
-                        }
-                    }
-                }
-            }
-        }
-    }
-}
-
-
-void tcd_free(j2k_image_t *img, j2k_cp_t *cp) {
-  int tileno, compno, resno, bandno, precno;
-  tcd_img=img;
-  tcd_cp=cp;
-  tcd_image.tw=cp->tw;
-  tcd_image.th=cp->th;
-  for (tileno=0; tileno<tcd_image.tw*tcd_image.th; tileno++) 
-    {
-      //  j2k_tcp_t *tcp=&cp->tcps[curtileno];
-      tcd_tile_t *tile=&tcd_image.tiles[tileno];
-      for (compno=0; compno<tile->numcomps; compno++) 
-       {
-        tcd_tilecomp_t *tilec=&tile->comps[compno];
-         for (resno=0; resno<tilec->numresolutions; resno++) 
-           {
-             tcd_resolution_t *res=&tilec->resolutions[resno];
-             for (bandno=0; bandno<res->numbands; bandno++) 
-               {
-                tcd_band_t *band=&res->bands[bandno];
-                 for (precno=0; precno<res->pw*res->ph; precno++) 
-                   {
-                    tcd_precinct_t *prc=&band->precincts[precno];
-                     
-                     if (prc->incltree!=NULL)
-                       tgt_destroy(prc->incltree);
-                     if (prc->imsbtree!=NULL)
-                       tgt_destroy(prc->imsbtree);
-                     free(prc->cblks);
-                   } // for (precno
-                 free(band->precincts);
-               } // for (bandno
-           }   // for (resno
-         free(tilec->resolutions);
-       }       // for (compno
-      free(tile->comps);
-    }  // for (tileno
-  free(tcd_image.tiles);
-}
-
-
-int tcd_decode_tile(unsigned char *src, int len, int tileno, info_image_t *imgg) {
-    int l;
-    int eof=0;
-    tcd_tile_t *tile;
-
-    tile = &tcd_image.tiles[tileno];
-
-    l = t2_decode_packets(src, len, tcd_img, tcd_cp, tileno, tile, imgg);
-
-    if (l==-999)
-      {
-       eof=1;
-       fprintf(stderr, "tcd_decode: incomplete bistream\n");
-      }
-    
-     if (eof) {
-       longjmp(j2k_error, 1);
-     }
-
-    l=1;
-    return l;
-}
diff --git a/applications/jpip/tools/indexer/tcd.h b/applications/jpip/tools/indexer/tcd.h
deleted file mode 100644 (file)
index 9a31723..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __TCD_H
-#define __TCD_H
-
-#include "j2k.h"
-#include "tgt.h"
-
-typedef struct {
-    int numpasses;
-    int len;
-    unsigned char *data;
-    int maxpasses;
-    int numnewpasses;
-    int newlen;
-} tcd_seg_t;
-
-typedef struct {
-    int rate;
-    double distortiondec;
-} tcd_pass_t;
-
-typedef struct {
-    int numpasses;
-    int len;
-    unsigned char *data;
-} tcd_layer_t;
-
-typedef struct {
-    int x0, y0, x1, y1;
-    int numbps;
-    int numlenbits;
-    int len;
-    int numpasses;
-    int numnewpasses;
-    int numsegs;
-    tcd_seg_t segs[100];
-    unsigned char data[8192];
-    int numpassesinlayers;
-    tcd_layer_t layers[100];
-    int totalpasses;
-    tcd_pass_t passes[100];
-} tcd_cblk_t;
-
-typedef struct {
-    int x0, y0, x1, y1;
-    int cw, ch;
-    tcd_cblk_t *cblks;
-    tgt_tree_t *incltree;
-    tgt_tree_t *imsbtree;
-} tcd_precinct_t;
-
-typedef struct {
-    int x0, y0, x1, y1;
-    int bandno;
-    tcd_precinct_t *precincts;
-    int numbps;
-    int stepsize;
-} tcd_band_t;
-
-typedef struct {
-    int x0, y0, x1, y1;  
-  int previous_x0, previous_y0, previous_x1, previous_y1; // usefull for the DWT
-  int cas_col, cas_row; // usefull for the DWT
-    int pw, ph;
-    int numbands;
-    tcd_band_t bands[3];
-} tcd_resolution_t;
-
-typedef struct {
-    int x0, y0, x1, y1;
-  int previous_row, previous_col; // usefull for the DWT
-    int numresolutions;
-    tcd_resolution_t *resolutions;
-    int *data;
-} tcd_tilecomp_t;
-
-typedef struct {
-    int x0, y0, x1, y1;
-    int numcomps;
-  //int PPT;
-  //int len_ppt;
-    tcd_tilecomp_t *comps;
-} tcd_tile_t;
-
-typedef struct {
-    int tw, th;
-    tcd_tile_t *tiles;
-} tcd_image_t;
-
-/*
- * Initialize the tile coder/decoder
- * img: raw image
- * cp: coding parameters
- * imgg: creation of index file
- */
-
-void tcd_init(j2k_image_t *img, j2k_cp_t *cp, info_image_t *imgg);
-
-void tcd_free(j2k_image_t *img, j2k_cp_t *cp);
-
-/*
- * Decode a tile from a buffer into a raw image
- * src: source buffer
- * len: length of the source buffer
- * tileno: number that identifies the tile that will be decoded
- * imgg : Structure for index file
- */
-int tcd_decode_tile(unsigned char *src, int len, int tileno, info_image_t *imgg);
-
-#endif
diff --git a/applications/jpip/tools/indexer/tgt.c b/applications/jpip/tools/indexer/tgt.c
deleted file mode 100644 (file)
index c2b4682..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tgt.h"
-#include "bio.h"
-#include <stdlib.h>
-#include <stdio.h>
-
-/// <summary>
-/// Reset tag-tree.
-/// </summary>
-void tgt_reset(tgt_tree_t *tree)
-{
-    int i;
-    for (i=0; i<tree->numnodes; i++) {
-        tree->nodes[i].value=999;
-        tree->nodes[i].low=0;
-        tree->nodes[i].known=0;
-    }
-}
-
-/// <summary>
-/// Create tag-tree.
-/// </summary>
-tgt_tree_t *tgt_create(int numleafsh, int numleafsv)
-{
-    int nplh[32];
-    int nplv[32];
-    tgt_node_t *node;
-    tgt_node_t *parentnode;
-    tgt_node_t *parentnode0;
-    tgt_tree_t *tree;
-    int i, j, k;
-    int numlvls;
-    int n;
-
-    tree=(tgt_tree_t*)malloc(sizeof(tgt_tree_t));
-    tree->numleafsh=numleafsh;
-    tree->numleafsv=numleafsv;
-
-    numlvls=0;
-    nplh[0]=numleafsh;
-    nplv[0]=numleafsv;
-    tree->numnodes=0;
-    do {
-        n=nplh[numlvls]*nplv[numlvls];
-        nplh[numlvls+1]=(nplh[numlvls]+1)/2;
-        nplv[numlvls+1]=(nplv[numlvls]+1)/2;
-        tree->numnodes+=n;
-        ++numlvls;
-    } while (n>1);
-
-    tree->nodes=(tgt_node_t*)malloc(tree->numnodes*sizeof(tgt_node_t));
-
-    node=tree->nodes;
-    parentnode=&tree->nodes[tree->numleafsh*tree->numleafsv];
-    parentnode0=parentnode;
-
-    for (i=0; i<numlvls-1; ++i) {
-        for (j=0; j<nplv[i]; ++j) {
-            k=nplh[i];
-            while (--k>=0) {
-                node->parent=parentnode;
-                ++node;
-                if (--k >= 0) {
-                    node->parent=parentnode;
-                    ++node;
-                }
-                ++parentnode;
-            }
-            if ((j&1)||j==nplv[i]-1) {
-                parentnode0=parentnode;
-            } else {
-                parentnode=parentnode0;
-                parentnode0+=nplh[i];
-            }
-        }
-    }
-    node->parent=0;
-
-    tgt_reset(tree);
-
-    return tree;
-}
-
-/// <summary>
-/// Destroy tag-tree.
-/// </summary>
-void tgt_destroy(tgt_tree_t *t) {
-    free(t->nodes);
-    free(t);
-}
-
-/// <summary>
-/// Set the value of a leaf of the tag-tree.
-/// </summary>
-void tgt_setvalue(tgt_tree_t *tree, int leafno, int value) {
-    tgt_node_t *node;
-    node=&tree->nodes[leafno];
-    while (node && node->value>value) {
-        node->value=value;
-        node=node->parent;
-    }
-}
-
-/// <summary>
-/// Decode the value of a leaf of the tag-tree.
-/// </summary>
-int tgt_decode(tgt_tree_t *tree, int leafno, int threshold)
-{
-    tgt_node_t *stk[31];
-    tgt_node_t **stkptr;
-    tgt_node_t *node;
-    int low;
-
-    stkptr=stk;
-    node=&tree->nodes[leafno];
-    while (node->parent) {
-        *stkptr++=node;
-        node=node->parent;
-    }
-
-    low=0;
-    for (;;) {
-        if (low>node->low) {
-            node->low=low;
-        } else {
-            low=node->low;
-        }
-        while (low<threshold && low<node->value) {
-            if (bio_read(1)) {
-                node->value=low;
-            } else {
-                ++low;
-            }
-        }
-        node->low=low;
-        if (stkptr==stk) {
-            break;
-        }
-        node=*--stkptr;
-    }
-
-    return (node->value<threshold)?1:0;
-}
diff --git a/applications/jpip/tools/indexer/tgt.h b/applications/jpip/tools/indexer/tgt.h
deleted file mode 100644 (file)
index 9d85ade..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2001-2002, David Janssens
- * Copyright (c) 2003, Yannick Verschueren
- * Copyright (c) 2003,  Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
- * 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 __TGT_H
-#define __TGT_H
-
-typedef struct tgt_node {
-       struct tgt_node *parent;
-       int value;
-       int low;
-       int known;
-} tgt_node_t;
-
-typedef struct {
-       int numleafsh;
-       int numleafsv;
-       int numnodes;
-       tgt_node_t *nodes;
-} tgt_tree_t;
-
-/*
- * Create a tag-tree
- * numleafsh: width of the array of leafs of the tree
- * numleafsv: height of the array of leafs of the tree
- */
-tgt_tree_t *tgt_create(int numleafsh, int numleafsv);
-
-/*
- * Reset a tag-tree (set all leafs to 0)
- * tree: tag-tree to reset
- */
-void tgt_reset(tgt_tree_t *tree);
-
-/*
- * Destroy a tag-tree, liberating memory
- * tree: tag-tree to destroy
- */
-void tgt_destroy(tgt_tree_t *tree);
-
-/*
- * Set the value of a leaf of a tag-tree
- * tree: tag-tree to modify
- * leafno: number that identifies the leaf to modify
- * value: new value of the leaf
- */
-void tgt_setvalue(tgt_tree_t *tree, int leafno, int value);
-
-/*
- * Decode the value of a leaf of the tag-tree up to a given threshold
- * leafno: number that identifies the leaf to decode
- * threshold: threshold to use when decoding value of the leaf
- */
-int tgt_decode(tgt_tree_t *tree, int leafno, int threshold);
-
-#endif
diff --git a/applications/jpip/tools/indexer/thix_manager.c b/applications/jpip/tools/indexer/thix_manager.c
new file mode 100644 (file)
index 0000000..dbe1b1b
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * $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;
+}
diff --git a/applications/jpip/tools/indexer/tpix_manager.c b/applications/jpip/tools/indexer/tpix_manager.c
new file mode 100644 (file)
index 0000000..1f71ce6
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * $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 <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;
+}
index 49d7b36e496da05543060a37d4560da27655a2ef..5cdf640b424f854f996bbb1597ec07988130a1e5 100644 (file)
@@ -26,7 +26,7 @@ AC_CONFIG_HEADERS([opj_config.h])
 AC_CANONICAL_SYSTEM
 AC_CANONICAL_HOST
 
-AM_INIT_AUTOMAKE(1[.11 foreign dist-bzip2])
+AM_INIT_AUTOMAKE([1.11 foreign dist-bzip2])
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 MAJOR_NR=OPJ_MAJOR