4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
32 * \brief j2k_to_idxjp2 is a program to make jp2 file with index box from j2k file
34 * \section impinst Implementing instructions
35 * This program takes two arguments. \n
36 * -# Input J2K image file\n
37 * -# Output JP2 file name\n
38 * % ./j2k_to_idxjp2 image.j2k image.jp2\n
45 #include "j2k_to_idxjp2.h"
51 * @param[in] filename file name
52 * @param[out] lenoffile pointer to feed file length
55 unsigned char * read_binaryfile( char filename[], int *lenoffile);
57 int main(int argc, char **argv)
59 opj_image_t *image = NULL;
60 opj_codestream_info_t cstr_info; /* Codestream information structure */
61 unsigned char *j2kstream;
65 fprintf(stderr,"\nERROR in entry : j2k_to_idxjp2 J2K-file JP2-file\n");
69 j2kstream = read_binaryfile( argv[1], &j2klen);
71 image = decode_j2k( j2kstream, j2klen, &cstr_info);
77 fwrite_idxjp2( argv[2], j2kstream, j2klen, image, cstr_info);
81 /* free image data structure */
82 opj_image_destroy(image);
87 unsigned char * read_binaryfile( char filename[], int *lenoffile)
90 unsigned char *bytecode;
92 fp = fopen( filename, "rb");
94 fprintf(stderr, "Failed to open %s for reading !!\n", filename);
98 /* length of the codestream */
99 fseek( fp, 0, SEEK_END);
100 *lenoffile = ftell(fp);
101 fseek( fp, 0, SEEK_SET);
103 bytecode = (unsigned char*)malloc(*lenoffile);
104 fread( bytecode, *lenoffile, 1, fp);