! : changed
+ : added
+August 30, 2007
+* [FOD] Changed the OpenJPEG library interface to enable users to access information regarding the codestream (also called codestream index).
+ This index is usefull for all applications requiring to have a scalable acces to the codestream (like JPIP applications, ...)
+ Currently, this information is only available when encoding an image.
+
August 28, 2007
* [FOD] Fixed wrong destructors called in openjpeg.c
* [FOD] Fixed bug in j2k_decode_jpt_stream
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <math.h>
#include "openjpeg.h"
#include "compat/getopt.h"
fprintf(stdout,"\n");
fprintf(stdout,"-h : display the help information \n ");
fprintf(stdout,"\n");
- fprintf(stdout,"-cinema2k : Digital Cinema 2K profile compliant codestream for 2K resolution.(-cinema2k 24 or 48) \n");
+ fprintf(stdout,"-cinema2K : Digital Cinema 2K profile compliant codestream for 2K resolution.(-cinema2k 24 or 48) \n");
fprintf(stdout," Need to specify the frames per second for a 2K resolution. Only 24 or 48 fps is allowed\n");
fprintf(stdout,"\n");
- fprintf(stdout,"-cinema4k : Digital Cinema 4K profile compliant codestream for 4K resolution \n");
+ fprintf(stdout,"-cinema4K : Digital Cinema 4K profile compliant codestream for 4K resolution \n");
fprintf(stdout," Frames per second not required. Default value is 24fps\n");
fprintf(stdout,"\n");
fprintf(stdout,"-r : different compression ratios for successive layers (-r 20,10,5)\n ");
return format[i];
}
}
-
return -1;
}
parameters->numresolution = 6;
}
if (!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))){
- fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3"
+ fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 "
"(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n",
image->comps[0].w,image->comps[0].h);
parameters->cp_rsiz = STD_RSIZ;
/* ------------------------------------------------------------------------------------ */
+/**
+Create an index and write it to a file
+@param cstr_info Codestream information
+@param index Index filename
+@return Returns 0 if successful, returns 1 otherwise
+*/
+int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
+ int tileno, compno, layno, resno, precno, pack_nb, x, y;
+ FILE *stream = NULL;
+ double total_disto = 0;
+
+ if (!cstr_info)
+ return 1;
+
+ stream = fopen(index, "w");
+ if (!stream) {
+ fprintf(stderr, "failed to open index file [%s] for writing\n", index);
+ return 1;
+ }
+
+ fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
+ fprintf(stream, "%d\n", cstr_info->prog);
+ fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
+ fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th);
+ fprintf(stream, "%d\n", cstr_info->comp);
+ fprintf(stream, "%d\n", cstr_info->layer);
+ fprintf(stream, "%d\n", cstr_info->decomposition);
+
+ for (resno = cstr_info->decomposition; resno >= 0; resno--) {
+ fprintf(stream, "[%d,%d] ",
+ (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 */
+ }
+ fprintf(stream, "\n");
+ fprintf(stream, "%d\n", cstr_info->main_head_end);
+ fprintf(stream, "%d\n", cstr_info->codestream_size);
+
+ fprintf(stream, "\nINFO ON TILES\n");
+ fprintf(stream, "tileno start_pos end_hd end_tile disto nbpix disto/nbpix\n");
+ for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
+ fprintf(stream, "%4d %9d %9d %9d %9e %9d %9e\n",
+ cstr_info->tile[tileno].num_tile,
+ cstr_info->tile[tileno].start_pos,
+ cstr_info->tile[tileno].end_header,
+ cstr_info->tile[tileno].end_pos,
+ cstr_info->tile[tileno].distotile, cstr_info->tile[tileno].nbpix,
+ cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].nbpix);
+ }
+
+ for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
+ int start_pos, end_pos;
+ double disto = 0;
+ pack_nb = 0;
+
+ fprintf(stream, "\nTILE %d DETAILS\n", tileno);
+ if (cstr_info->prog == LRCP) { /* LRCP */
+
+ fprintf(stream, "pack_nb tileno layno resno compno precno start_pos end_pos disto\n");
+
+ for (layno = 0; layno < cstr_info->layer; layno++) {
+ for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {
+ for (compno = 0; compno < cstr_info->comp; compno++) {
+ int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ for (precno = 0; precno < prec_max; precno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
+ pack_nb, tileno, layno, resno, compno, precno, start_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }
+ }
+ } /* LRCP */
+ else if (cstr_info->prog == RLCP) { /* RLCP */
+
+ fprintf(stream, "pack_nb tileno resno layno compno precno start_pos end_pos disto\n");
+
+ for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {
+ for (layno = 0; layno < cstr_info->layer; layno++) {
+ for (compno = 0; compno < cstr_info->comp; compno++) {
+ int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ for (precno = 0; precno < prec_max; precno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %8e\n",
+ pack_nb, tileno, resno, layno, compno, precno, start_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }
+ }
+ } /* RLCP */
+ else if (cstr_info->prog == RPCL) { /* RPCL */
+
+ fprintf(stream, "pack_nb tileno resno precno compno layno start_pos end_pos disto\n");
+
+ for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {
+ /* I suppose components have same XRsiz, YRsiz */
+ int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
+ int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
+ int x1 = x0 + cstr_info->tile_x;
+ int y1 = y0 + cstr_info->tile_y;
+ for (compno = 0; compno < cstr_info->comp; compno++) {
+ int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ for (precno = 0; precno < prec_max; precno++) {
+ int pcnx = cstr_info->tile[tileno].pw[resno];
+ int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->decomposition - resno );
+ int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - resno );
+ int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
+ int precno_y = (int) floor( (float)precno/(float)pcnx );
+ for(y = y0; y < y1; y++) {
+ if (precno_y*pcy == y ) {
+ for (x = x0; x < x1; x++) {
+ if (precno_x*pcx == x ) {
+ for (layno = 0; layno < cstr_info->layer; layno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %8e\n",
+ pack_nb, tileno, resno, precno, compno, layno, start_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }/* x = x0..x1 */
+ }
+ } /* y = y0..y1 */
+ } /* precno */
+ } /* compno */
+ } /* resno */
+ } /* RPCL */
+ else if (cstr_info->prog == PCRL) { /* PCRL */
+ /* I suppose components have same XRsiz, YRsiz */
+ int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
+ int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
+ int x1 = x0 + cstr_info->tile_x;
+ int y1 = y0 + cstr_info->tile_y;
+
+ fprintf(stream, "pack_nb tileno precno compno resno layno start_pos end_pos disto\n");
+
+ for (compno = 0; compno < cstr_info->comp; compno++) {
+ for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {
+ int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ for (precno = 0; precno < prec_max; precno++) {
+ int pcnx = cstr_info->tile[tileno].pw[resno];
+ int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->decomposition - resno );
+ int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - resno );
+ int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
+ int precno_y = (int) floor( (float)precno/(float)pcnx );
+ for(y = y0; y < y1; y++) {
+ if (precno_y*pcy == y ) {
+ for (x = x0; x < x1; x++) {
+ if (precno_x*pcx == x ) {
+ for (layno = 0; layno < cstr_info->layer; layno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
+ pack_nb, tileno, precno, compno, resno, layno, start_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }/* x = x0..x1 */
+ }
+ } /* y = y0..y1 */
+ } /* precno */
+ } /* resno */
+ } /* compno */
+ } /* PCRL */
+ else { /* CPRL */
+
+ fprintf(stream, "pack_nb tileno compno precno resno layno start_pos end_pos disto\n");
+
+ for (compno = 0; compno < cstr_info->comp; compno++) {
+ /* I suppose components have same XRsiz, YRsiz */
+ int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
+ int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
+ int x1 = x0 + cstr_info->tile_x;
+ int y1 = y0 + cstr_info->tile_y;
+
+ for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {
+ int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
+ for (precno = 0; precno < prec_max; precno++) {
+ int pcnx = cstr_info->tile[tileno].pw[resno];
+ int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->decomposition - resno );
+ int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - resno );
+ int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
+ int precno_y = (int) floor( (float)precno/(float)pcnx );
+ for(y = y0; y < y1; y++) {
+ if (precno_y*pcy == y ) {
+ for (x = x0; x < x1; x++) {
+ if (precno_x*pcx == x ) {
+ for (layno = 0; layno < cstr_info->layer; layno++) {
+ start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
+ end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
+ disto = cstr_info->tile[tileno].packet[pack_nb].disto;
+ fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
+ pack_nb, tileno, compno, precno, resno, layno, start_pos, end_pos, disto);
+ total_disto += disto;
+ pack_nb++;
+ }
+ }
+ }/* x = x0..x1 */
+ }
+ } /* y = y0..y1 */
+ } /* precno */
+ } /* resno */
+ } /* compno */
+ } /* CPRL */
+ } /* tileno */
+
+ fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
+ fprintf(stream, "%.8e\n", total_disto); /* SE totale */
+ fclose(stream);
+
+ fprintf(stderr,"Generated index file %s\n", index);
+
+ return 0;
+}
+
+/* ------------------------------------------------------------------------------------ */
+
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp) {
int i, j,totlen;
int imageno;
dircnt_t *dirptr;
raw_cparameters_t raw_cp;
+ opj_codestream_info_t cstr_info;
/*
configure the event callbacks (not required)
sprintf(parameters.cp_comment,"%s%s", comment, version);
#endif
/* <<UniPG */
-
}
/* Read directory if necessary */
-
if(img_fol.set_imgdir==1){
num_images=get_num_images(img_fol.imgdirpath);
-
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); // Stores at max 10 image file names
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
-
if(!dirptr->filename_buf){
return 0;
}
num_images=1;
}
/*Encoding image one by one*/
- for(imageno=0;imageno<num_images;imageno++)
- {
-
+ for(imageno=0;imageno<num_images;imageno++) {
image = NULL;
fprintf(stderr,"\n");
-
if(img_fol.set_imgdir==1){
if (get_next_file(imageno, dirptr,&img_fol, ¶meters)) {
fprintf(stderr,"skipping file...\n");
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */
- bSuccess = opj_encode(cinfo, cio, image, parameters.index);
+ bSuccess = opj_encode(cinfo, cio, image, &cstr_info);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");
/* close and free the byte stream */
opj_cio_close(cio);
+ /* Write the index to disk */
+ if (parameters.index_on) {
+ bSuccess = write_index_file(&cstr_info, parameters.index);
+ if (bSuccess) {
+ fprintf(stderr, "Failed to output index file\n");
+ }
+ }
+
/* free remaining compression structures */
opj_destroy_compress(cinfo);
-
} else { /* JP2 format output */
int codestream_length;
opj_cio_t *cio = NULL;
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */
- bSuccess = opj_encode(cinfo, cio, image, parameters.index);
+ bSuccess = opj_encode(cinfo, cio, image, &cstr_info);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");
fprintf(stderr,"Generated outfile %s\n",parameters.outfile);
/* close and free the byte stream */
opj_cio_close(cio);
+
+ /* Write the index to disk */
+ if (parameters.index_on) {
+ bSuccess = write_index_file(&cstr_info, parameters.index);
+ if (bSuccess) {
+ fprintf(stderr, "Failed to output index file\n");
+ }
+ }
/* free remaining compression structures */
opj_destroy_compress(cinfo);
return 0;
}
-
-
(unsigned char) j2k->cp->sens_MH, /* sensitivity method */\r
j2k->cp->sens_size, /* sensitivity size */\r
-1, /* this ESD is in main header */\r
- 0 /*j2k->image_info->num*/, /* number of packets in codestream */\r
+ 0 /*j2k->cstr_info->num*/, /* number of packets in codestream */\r
NULL /*sensval*/ /* pointer to sensitivity data of packets */\r
)) {\r
\r
/* cycle through TPHs */\r
sens = -1; /* default spec: no ESD */\r
tilespec = 0; /* first tile spec */\r
- for (tileno = 0; tileno < j2k->image_info->tw * j2k->image_info->th; tileno++) {\r
+ for (tileno = 0; tileno < j2k->cstr_info->tw * j2k->cstr_info->th; tileno++) {\r
\r
int sot_len, Psot, Psotp, mm;\r
unsigned long sot_pos, post_sod_pos;\r
\r
unsigned long int left_THmarks_len;\r
\r
- sot_pos = j2k->image_info->tile[tileno].start_pos;\r
+ sot_pos = j2k->cstr_info->tile[tileno].start_pos;\r
cio_seek(cio, sot_pos + 2); \r
sot_len = cio_read(cio, 2); /* SOT Len */\r
cio_skip(cio, 2);\r
Psotp = cio_tell(cio);\r
Psot = cio_read(cio, 4); /* tile length */\r
\r
- post_sod_pos = j2k->image_info->tile[tileno].end_header + 1;\r
+ post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1;\r
left_THmarks_len = post_sod_pos - sot_pos;\r
\r
/* add all the lengths of the markers which are len-ready and stay within SOT and SOD */\r
if (jwmarker_num < JPWL_MAX_NO_MARKERS) {\r
jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */\r
jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */\r
- jwmarker[jwmarker_num].pos = j2k->image_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */\r
+ jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */\r
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */\r
jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */\r
jwmarker[jwmarker_num].len_ready = true; /* ready, yet */\r
int mm;\r
\r
/* position of SOT */\r
- unsigned int sot_pos = j2k->image_info->main_head_end + 1;\r
+ unsigned int sot_pos = j2k->cstr_info->main_head_end + 1;\r
\r
/* how much space is there between end of SIZ and beginning of SOT? */\r
int left_MHmarks_len = sot_pos - socsiz_len;\r
lastileno = 0;\r
packspec = 0;\r
pprot = -1;\r
- for (tileno = 0; tileno < j2k->image_info->tw * j2k->image_info->th; tileno++) {\r
+ for (tileno = 0; tileno < j2k->cstr_info->tw * j2k->cstr_info->th; tileno++) {\r
\r
int sot_len, Psot, Psotp, mm, epb_index = 0, prot_len = 0;\r
unsigned long sot_pos, post_sod_pos;\r
unsigned long int left_THmarks_len, epbs_len = 0;\r
- int startpack = 0, stoppack = j2k->image_info->num;\r
+ int startpack = 0, stoppack = j2k->cstr_info->num;\r
jpwl_epb_ms_t *tph_epb = NULL;\r
\r
- sot_pos = j2k->image_info->tile[tileno].start_pos;\r
+ sot_pos = j2k->cstr_info->tile[tileno].start_pos;\r
cio_seek(cio, sot_pos + 2); \r
sot_len = cio_read(cio, 2); /* SOT Len */\r
cio_skip(cio, 2);\r
Psot = cio_read(cio, 4); /* tile length */\r
\r
/* a-priori length of the data dwelling between SOT and SOD */\r
- post_sod_pos = j2k->image_info->tile[tileno].end_header + 1;\r
+ post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1;\r
left_THmarks_len = post_sod_pos - (sot_pos + sot_len + 2);\r
\r
/* add all the lengths of the JPWL markers which are len-ready and stay within SOT and SOD */\r
if (jwmarker_num < JPWL_MAX_NO_MARKERS) {\r
jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */\r
jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */\r
- jwmarker[jwmarker_num].pos = j2k->image_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */\r
+ jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */\r
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */\r
jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */\r
jwmarker[jwmarker_num].len_ready = true; /* ready */\r
\r
startpack = 0;\r
/* EPB MSs for UEP packet data protection in Tile Parts */\r
- for (packno = 0; packno < j2k->image_info->num; packno++) {\r
+ for (packno = 0; packno < j2k->cstr_info->num; packno++) {\r
\r
if ((packspec < JPWL_MAX_NO_PACKSPECS) &&\r
(j2k->cp->pprot_tileno[packspec] == tileno) && (j2k->cp->pprot_packno[packspec] == packno)) {\r
tileno,\r
startpack,\r
stoppack,\r
- j2k->image_info->tile[tileno].packet[startpack].start_pos,\r
- j2k->image_info->tile[tileno].packet[stoppack].end_pos,\r
+ j2k->cstr_info->tile[tileno].packet[startpack].start_pos,\r
+ j2k->cstr_info->tile[tileno].packet[stoppack].end_pos,\r
pprot);\r
\r
- prot_len = j2k->image_info->tile[tileno].packet[stoppack].end_pos + 1 -\r
- j2k->image_info->tile[tileno].packet[startpack].start_pos;\r
+ prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -\r
+ j2k->cstr_info->tile[tileno].packet[startpack].start_pos;\r
\r
/*\r
particular case: if this is the last header and the last packet,\r
then it is better to protect even the EOC marker\r
*/\r
- if ((tileno == ((j2k->image_info->tw * j2k->image_info->th) - 1)) &&\r
- (stoppack == (j2k->image_info->num - 1)))\r
+ if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&\r
+ (stoppack == (j2k->cstr_info->num - 1)))\r
/* add the EOC len */\r
prot_len += 2;\r
\r
false, /* inside MH */\r
&epb_index, /* pointer to EPB index */\r
pprot, /* protection type */\r
- (double) (j2k->image_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */\r
+ (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */\r
tileno, /* number of tile */\r
0, /* length of pre-data */\r
prot_len /*4000*/ /* length of post-data */\r
tileno,\r
startpack,\r
stoppack,\r
- j2k->image_info->tile[tileno].packet[startpack].start_pos,\r
- j2k->image_info->tile[tileno].packet[stoppack].end_pos,\r
+ j2k->cstr_info->tile[tileno].packet[startpack].start_pos,\r
+ j2k->cstr_info->tile[tileno].packet[stoppack].end_pos,\r
pprot);\r
\r
- prot_len = j2k->image_info->tile[tileno].packet[stoppack].end_pos + 1 -\r
- j2k->image_info->tile[tileno].packet[startpack].start_pos;\r
+ prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -\r
+ j2k->cstr_info->tile[tileno].packet[startpack].start_pos;\r
\r
/*\r
particular case: if this is the last header and the last packet,\r
then it is better to protect even the EOC marker\r
*/\r
- if ((tileno == ((j2k->image_info->tw * j2k->image_info->th) - 1)) &&\r
- (stoppack == (j2k->image_info->num - 1)))\r
+ if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&\r
+ (stoppack == (j2k->cstr_info->num - 1)))\r
/* add the EOC len */\r
prot_len += 2;\r
\r
false, /* inside MH */\r
&epb_index, /* pointer to EPB index */\r
pprot, /* protection type */\r
- (double) (j2k->image_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */\r
+ (double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */\r
tileno, /* number of tile */\r
0, /* length of pre-data */\r
prot_len /*4000*/ /* length of post-data */\r
void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {\r
\r
int mm;\r
- unsigned long int old_size = j2k->image_info->codestream_size;\r
+ unsigned long int old_size = j2k->cstr_info->codestream_size;\r
unsigned long int new_size = old_size;\r
int ciopos = cio_tell(cio);\r
unsigned char *jpwl_buf, *orig_buf;\r
update info file based on added markers\r
*/\r
if (!jpwl_update_info(j2k, jwmarker, jwmarker_num))\r
- opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not update OPJ image_info structure\n");\r
+ opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not update OPJ cstr_info structure\n");\r
\r
/* now we need to repass some markers and fill their data fields */\r
\r
if (ad_size == 0)
/* if there are more than 66% of (2^16 - 1) bytes, switch to 4 bytes
(we keep space for possible EPBs being inserted) */
- ad_size = (j2k->image_info->codestream_size > (1 * 65535 / 3)) ? 4 : 2;
+ ad_size = (j2k->cstr_info->codestream_size > (1 * 65535 / 3)) ? 4 : 2;
esd->sensval_size = ad_size + ad_size + se_size;
break;
/* auto sense address size */
if (ad_size == 0)
/* if there are more than 2^16 - 1 packets, switch to 4 bytes */
- ad_size = (j2k->image_info->num > 65535) ? 4 : 2;
+ ad_size = (j2k->cstr_info->num > 65535) ? 4 : 2;
esd->sensval_size = ad_size + ad_size + se_size;
break;
/* just based on the portions of a codestream */
case (0):
/* MH + no. of THs + no. of packets */
- svalnum = 1 + (j2k->image_info->tw * j2k->image_info->th) * (1 + j2k->image_info->num);
+ svalnum = 1 + (j2k->cstr_info->tw * j2k->cstr_info->th) * (1 + j2k->cstr_info->num);
break;
/* all the ones that are based on the packets */
default:
if (tileno < 0)
/* MH: all the packets and all the tiles info is written */
- svalnum = j2k->image_info->tw * j2k->image_info->th * j2k->image_info->num;
+ svalnum = j2k->cstr_info->tw * j2k->cstr_info->th * j2k->cstr_info->num;
else
/* TPH: only that tile info is written */
- svalnum = j2k->image_info->num;
+ svalnum = j2k->cstr_info->num;
break;
}
buf += 7;
/* let's fill the data fields */
- for (vv = (esd->tileno < 0) ? 0 : (j2k->image_info->num * esd->tileno); vv < esd->svalnum; vv++) {
+ for (vv = (esd->tileno < 0) ? 0 : (j2k->cstr_info->num * esd->tileno); vv < esd->svalnum; vv++) {
- int thistile = vv / j2k->image_info->num, thispacket = vv % j2k->image_info->num;
+ int thistile = vv / j2k->cstr_info->num, thispacket = vv % j2k->cstr_info->num;
/* skip for the hack some lines below */
- if (thistile == j2k->image_info->tw * j2k->image_info->th)
+ if (thistile == j2k->cstr_info->tw * j2k->cstr_info->th)
break;
/* starting tile distortion */
if (thispacket == 0) {
- TSE = j2k->image_info->tile[thistile].distotile;
- oldMSE = TSE / j2k->image_info->tile[thistile].nbpix;
+ TSE = j2k->cstr_info->tile[thistile].distotile;
+ oldMSE = TSE / j2k->cstr_info->tile[thistile].nbpix;
oldPSNR = 10.0 * log10(Omax2 / oldMSE);
}
/* TSE */
- TSE -= j2k->image_info->tile[thistile].packet[thispacket].disto;
+ TSE -= j2k->cstr_info->tile[thistile].packet[thispacket].disto;
/* MSE */
- MSE = TSE / j2k->image_info->tile[thistile].nbpix;
+ MSE = TSE / j2k->cstr_info->tile[thistile].nbpix;
/* PSNR */
PSNR = 10.0 * log10(Omax2 / MSE);
/* byte range */
case (1):
/* start address of packet */
- addr1 = (j2k->image_info->tile[thistile].packet[thispacket].start_pos) & addrmask;
+ addr1 = (j2k->cstr_info->tile[thistile].packet[thispacket].start_pos) & addrmask;
/* end address of packet */
- addr2 = (j2k->image_info->tile[thistile].packet[thispacket].end_pos) & addrmask;
+ addr2 = (j2k->cstr_info->tile[thistile].packet[thispacket].end_pos) & addrmask;
break;
/* packet range */
if ((thistile == 0) && !doneMH) {
/* we have to manage MH addresses */
addr1 = 0; /* start of MH */
- addr2 = j2k->image_info->main_head_end; /* end of MH */
+ addr2 = j2k->cstr_info->main_head_end; /* end of MH */
/* set special dvalue for this MH */
dvalue = -10.0;
doneMH = true; /* don't come here anymore */
} else if (!doneTPH) {
/* we have to manage TPH addresses */
- addr1 = j2k->image_info->tile[thistile].start_pos;
- addr2 = j2k->image_info->tile[thistile].end_header;
+ addr1 = j2k->cstr_info->tile[thistile].start_pos;
+ addr2 = j2k->cstr_info->tile[thistile].end_header;
/* set special dvalue for this TPH */
dvalue = -1.0;
doneTPH = true; /* don't come here till the next tile */
else
/* packet: first is most important, and then in decreasing order
down to the last, which counts for 1 */
- dvalue = jpwl_pfp_to_double((unsigned short) (j2k->image_info->num - thispacket), esd->se_size);
+ dvalue = jpwl_pfp_to_double((unsigned short) (j2k->cstr_info->num - thispacket), esd->se_size);
break;
/* MSE */
int mm;
unsigned long int addlen;
- opj_image_info_t *info = j2k->image_info;
+ opj_codestream_info_t *info = j2k->cstr_info;
int tileno, packno, numtiles = info->th * info->tw, numpacks = info->num;
if (!j2k || !jwmarker ) {
*/
unsigned char cio_bytein(opj_cio_t *cio) {
if (cio->bp >= cio->end) {
- opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
+ opj_event_msg(cio->cinfo, EVT_ERROR, "read error: passed the end of the codestream (start = %d, current = %d, end = %d\n", cio->start, cio->bp, cio->end);
return 0;
}
return *cio->bp++;
int l, layno;
int totlen;
opj_tcp_t *tcp = NULL;
- opj_image_info_t *image_info = NULL;
+ opj_codestream_info_t *cstr_info = NULL;
opj_tcd_t *tcd = (opj_tcd_t*)tile_coder; /* cast is needed because of conflicts in header inclusions */
opj_cp_t *cp = j2k->cp;
}
/* INDEX >> */
- image_info = j2k->image_info;
- if (image_info && image_info->index_on) {
+ cstr_info = j2k->cstr_info;
+ if (cstr_info && cstr_info->index_on) {
if (!j2k->cur_tp_num ){
- image_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1;
+ cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1;
}else{
- if(image_info->tile[j2k->curtileno].packet[image_info->num - 1].end_pos < cio_tell(cio))
- image_info->tile[j2k->curtileno].packet[image_info->num].start_pos = cio_tell(cio);
+ if(cstr_info->tile[j2k->curtileno].packet[cstr_info->num - 1].end_pos < cio_tell(cio))
+ cstr_info->tile[j2k->curtileno].packet[cstr_info->num].start_pos = cio_tell(cio);
}
}
/* << INDEX */
for (layno = 0; layno < tcp->numlayers; layno++) {
tcp->rates[layno] -= tcp->rates[layno] ? (j2k->sod_start / (cp->th * cp->tw)) : 0;
}
- if(image_info && (j2k->cur_tp_num == 0)) {
- image_info->num = 0;
+ if(cstr_info && (j2k->cur_tp_num == 0)) {
+ cstr_info->num = 0;
}
- l = tcd_encode_tile(tcd, j2k->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, image_info);
+ l = tcd_encode_tile(tcd, j2k->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, cstr_info);
/* Writing Psot in SOT marker */
totlen = cio_tell(cio) + l - j2k->sot_start;
if(!j2k) return;
- if(j2k->image_info != NULL) {
- opj_image_info_t *image_info = j2k->image_info;
- if (image_info->index_on && j2k->cp) {
+ if(j2k->cstr_info != NULL) {
+ opj_codestream_info_t *cstr_info = j2k->cstr_info;
+ if (cstr_info->index_on && j2k->cp) {
opj_cp_t *cp = j2k->cp;
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
- opj_tile_info_t *tile_info = &image_info->tile[tileno];
+ opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
opj_free(tile_info->thresh);
opj_free(tile_info->packet);
}
- opj_free(image_info->tile);
+ opj_free(cstr_info->tile);
}
- opj_free(image_info);
}
if(j2k->cp != NULL) {
opj_cp_t *cp = j2k->cp;
/* creation of an index file ? */
cp->index_on = parameters->index_on;
- if(cp->index_on) {
- j2k->image_info = (opj_image_info_t*)opj_malloc(sizeof(opj_image_info_t));
- }
/* tiles */
cp->tdx = parameters->cp_tdx;
}
}
-/**
-Create an index file
-@param j2k
-@param cio
-@param image_info
-@param index Index filename
-@return Returns 1 if successful, returns 0 otherwise
-*/
-static int j2k_create_index(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_info_t *image_info, char *index) {
- int tileno, compno, layno, resno, precno, pack_nb, x, y;
- FILE *stream = NULL;
- double total_disto = 0;
-
- image_info->codestream_size = cio_tell(cio) + j2k->pos_correction; /* Correction 14/4/03 suite rmq de Patrick */
-
-
-#ifdef USE_JPWL
- /* if JPWL is enabled and the name coincides with our own set
- then discard the creation of the file: this was just done to
- enable indexing, we do not want an index file
- */
- if (j2k->cp->epc_on && !strcmp(index, JPWL_PRIVATEINDEX_NAME))
- return 1;
-#endif /* USE_JPWL */
-
-
- stream = fopen(index, "w");
- if (!stream) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "failed to open %s for writing\n", index);
- return 0;
- }
-
- fprintf(stream, "%d %d\n", image_info->image_w, image_info->image_h);
- fprintf(stream, "%d\n", image_info->prog);
- fprintf(stream, "%d %d\n", image_info->tile_x, image_info->tile_y);
- fprintf(stream, "%d %d\n", image_info->tw, image_info->th);
- fprintf(stream, "%d\n", image_info->comp);
- fprintf(stream, "%d\n", image_info->layer);
- fprintf(stream, "%d\n", image_info->decomposition);
-
- for (resno = image_info->decomposition; resno >= 0; resno--) {
- fprintf(stream, "[%d,%d] ",
- (1 << image_info->tile[0].pdx[resno]), (1 << image_info->tile[0].pdx[resno])); /* based on tile 0 */
- }
- fprintf(stream, "\n");
- fprintf(stream, "%d\n", image_info->main_head_end);
- fprintf(stream, "%d\n", image_info->codestream_size);
-
- for (tileno = 0; tileno < image_info->tw * image_info->th; tileno++) {
- fprintf(stream, "%4d %9d %9d %9d %9e %9d %9e\n",
- image_info->tile[tileno].num_tile,
- image_info->tile[tileno].start_pos,
- image_info->tile[tileno].end_header,
- image_info->tile[tileno].end_pos,
- image_info->tile[tileno].distotile, image_info->tile[tileno].nbpix,
- image_info->tile[tileno].distotile / image_info->tile[tileno].nbpix);
- }
-
- for (tileno = 0; tileno < image_info->tw * image_info->th; tileno++) {
- int start_pos, end_pos;
- double disto = 0;
- pack_nb = 0;
-
- if (image_info->prog == LRCP) { /* LRCP */
-
- fprintf(stream, "pack_nb tileno layno resno compno precno start_pos end_pos disto\n");
-
- for (layno = 0; layno < image_info->layer; layno++) {
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- for (compno = 0; compno < image_info->comp; compno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
- pack_nb, tileno, layno, resno, compno, precno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }
- }
- } /* LRCP */
- else if (image_info->prog == RLCP) { /* RLCP */
-
- fprintf(stream, "pack_nb tileno resno layno compno precno start_pos end_pos disto\n");
-
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- for (layno = 0; layno < image_info->layer; layno++) {
- for (compno = 0; compno < image_info->comp; compno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %8e\n",
- pack_nb, tileno, resno, layno, compno, precno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }
- }
- } /* RLCP */
- else if (image_info->prog == RPCL) { /* RPCL */
-
- fprintf(stream, "\npack_nb tileno resno precno compno layno start_pos end_pos disto\n");
-
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- /* I suppose components have same XRsiz, YRsiz */
- int x0 = image_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tw * image_info->tile_x;
- int y0 = image_info->tile_Ox + (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tile_y;
- int x1 = x0 + image_info->tile_x;
- int y1 = y0 + image_info->tile_y;
- for (compno = 0; compno < image_info->comp; compno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- int pcnx = image_info->tile[tileno].pw[resno];
- int pcx = (int) pow( 2, image_info->tile[tileno].pdx[resno] + image_info->decomposition - resno );
- int pcy = (int) pow( 2, image_info->tile[tileno].pdy[resno] + image_info->decomposition - resno );
- int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
- int precno_y = (int) floor( (float)precno/(float)pcnx );
- for(y = y0; y < y1; y++) {
- if (precno_y*pcy == y ) {
- for (x = x0; x < x1; x++) {
- if (precno_x*pcx == x ) {
- for (layno = 0; layno < image_info->layer; layno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %8e\n",
- pack_nb, tileno, resno, precno, compno, layno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }/* x = x0..x1 */
- }
- } /* y = y0..y1 */
- } /* precno */
- } /* compno */
- } /* resno */
- } /* RPCL */
- else if (image_info->prog == PCRL) { /* PCRL */
- /* I suppose components have same XRsiz, YRsiz */
- int x0 = image_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tw * image_info->tile_x;
- int y0 = image_info->tile_Ox + (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tile_y;
- int x1 = x0 + image_info->tile_x;
- int y1 = y0 + image_info->tile_y;
-
- fprintf(stream, "\npack_nb tileno precno compno resno layno start_pos end_pos disto\n");
-
- for (compno = 0; compno < image_info->comp; compno++) {
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- int pcnx = image_info->tile[tileno].pw[resno];
- int pcx = (int) pow( 2, image_info->tile[tileno].pdx[resno] + image_info->decomposition - resno );
- int pcy = (int) pow( 2, image_info->tile[tileno].pdy[resno] + image_info->decomposition - resno );
- int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
- int precno_y = (int) floor( (float)precno/(float)pcnx );
- for(y = y0; y < y1; y++) {
- if (precno_y*pcy == y ) {
- for (x = x0; x < x1; x++) {
- if (precno_x*pcx == x ) {
- for (layno = 0; layno < image_info->layer; layno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
- pack_nb, tileno, precno, compno, resno, layno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }/* x = x0..x1 */
- }
- } /* y = y0..y1 */
- } /* precno */
- } /* resno */
- } /* compno */
- } /* PCRL */
- else { /* CPRL */
-
- fprintf(stream, "\npack_nb tileno compno precno resno layno start_pos end_pos disto\n");
-
- for (compno = 0; compno < image_info->comp; compno++) {
- /* I suppose components have same XRsiz, YRsiz */
- int x0 = image_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tw * image_info->tile_x;
- int y0 = image_info->tile_Ox + (int)floor( (float)tileno/(float)image_info->tw ) * image_info->tile_y;
- int x1 = x0 + image_info->tile_x;
- int y1 = y0 + image_info->tile_y;
-
- for (resno = 0; resno < image_info->decomposition + 1; resno++) {
- int prec_max = image_info->tile[tileno].pw[resno] * image_info->tile[tileno].ph[resno];
- for (precno = 0; precno < prec_max; precno++) {
- int pcnx = image_info->tile[tileno].pw[resno];
- int pcx = (int) pow( 2, image_info->tile[tileno].pdx[resno] + image_info->decomposition - resno );
- int pcy = (int) pow( 2, image_info->tile[tileno].pdy[resno] + image_info->decomposition - resno );
- int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
- int precno_y = (int) floor( (float)precno/(float)pcnx );
- for(y = y0; y < y1; y++) {
- if (precno_y*pcy == y ) {
- for (x = x0; x < x1; x++) {
- if (precno_x*pcx == x ) {
- for (layno = 0; layno < image_info->layer; layno++) {
- start_pos = image_info->tile[tileno].packet[pack_nb].start_pos;
- end_pos = image_info->tile[tileno].packet[pack_nb].end_pos;
- disto = image_info->tile[tileno].packet[pack_nb].disto;
- fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
- pack_nb, tileno, compno, precno, resno, layno, start_pos, end_pos, disto);
- total_disto += disto;
- pack_nb++;
- }
- }
- }/* x = x0..x1 */
- }
- } /* y = y0..y1 */
- } /* precno */
- } /* resno */
- } /* compno */
- } /* CPRL */
- } /* tileno */
-
- fprintf(stream, "%8e\n", image_info->D_max); /* SE max */
- fprintf(stream, "%.8e\n", total_disto); /* SE totale */
- fclose(stream);
-
- return 1;
-}
-
-bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index) {
+bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
int tileno, compno;
- opj_image_info_t *image_info = NULL;
opj_cp_t *cp = NULL;
opj_tcd_t *tcd = NULL; /* TCD component */
/* j2k_dump_cp(stdout, image, cp); */
/* INDEX >> */
- image_info = j2k->image_info;
- if (image_info && cp->index_on) {
- image_info->index_on = cp->index_on;
- image_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t));
- image_info->image_w = image->x1 - image->x0;
- image_info->image_h = image->y1 - image->y0;
- image_info->prog = (&cp->tcps[0])->prg;
- image_info->tw = cp->tw;
- image_info->th = cp->th;
- image_info->tile_x = cp->tdx; /* new version parser */
- image_info->tile_y = cp->tdy; /* new version parser */
- image_info->tile_Ox = cp->tx0; /* new version parser */
- image_info->tile_Oy = cp->ty0; /* new version parser */
- image_info->comp = image->numcomps;
- image_info->layer = (&cp->tcps[0])->numlayers;
- image_info->decomposition = (&cp->tcps[0])->tccps->numresolutions - 1;
- image_info->D_max = 0; /* ADD Marcela */
+ j2k->cstr_info = cstr_info;
+ if (cstr_info && cp->index_on) {
+ cstr_info->index_on = cp->index_on;
+ cstr_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tile_info_t));
+ cstr_info->image_w = image->x1 - image->x0;
+ cstr_info->image_h = image->y1 - image->y0;
+ cstr_info->prog = (&cp->tcps[0])->prg;
+ cstr_info->tw = cp->tw;
+ cstr_info->th = cp->th;
+ cstr_info->tile_x = cp->tdx; /* new version parser */
+ cstr_info->tile_y = cp->tdy; /* new version parser */
+ cstr_info->tile_Ox = cp->tx0; /* new version parser */
+ cstr_info->tile_Oy = cp->ty0; /* new version parser */
+ cstr_info->comp = image->numcomps;
+ cstr_info->layer = (&cp->tcps[0])->numlayers;
+ cstr_info->decomposition = (&cp->tcps[0])->tccps->numresolutions - 1;
+ cstr_info->D_max = 0; /* ADD Marcela */
+ }
+ else if (cstr_info) {
+ cstr_info->index_on = 0;
}
/* << INDEX */
}
j2k->totnum_tp = j2k_calculate_tp(cp,image->numcomps,image,j2k);
- /* TLM Marker*/
+ /* TLM Marker*/
if(cp->cinema){
j2k_write_tlm(j2k);
if (cp->cinema == CINEMA4K_24) {
}
/* INDEX >> */
- if(image_info && image_info->index_on) {
- image_info->main_head_end = cio_tell(cio) - 1;
+ if(cstr_info && cstr_info->index_on) {
+ cstr_info->main_head_end = cio_tell(cio) - 1;
}
/* << INDEX */
/**** Main Header ENDS here ***/
tcd = tcd_create(j2k->cinfo);
/* encode each tile */
-
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
int pino;
int tilepartno=0;
}
/* INDEX >> */
- if(image_info && image_info->index_on) {
- image_info->tile[j2k->curtileno].num_tile = j2k->curtileno;
- image_info->tile[j2k->curtileno].start_pos = cio_tell(cio) + j2k->pos_correction;
+ if(cstr_info && cstr_info->index_on) {
+ cstr_info->tile[j2k->curtileno].num_tile = j2k->curtileno;
+ cstr_info->tile[j2k->curtileno].start_pos = cio_tell(cio) + j2k->pos_correction;
}
/* << INDEX */
}
/* INDEX >> */
- if(image_info && image_info->index_on) {
- image_info->tile[j2k->curtileno].end_pos = cio_tell(cio) + j2k->pos_correction - 1;
+ if(cstr_info && cstr_info->index_on) {
+ cstr_info->tile[j2k->curtileno].end_pos = cio_tell(cio) + j2k->pos_correction - 1;
}
/* << INDEX */
free(j2k->cur_totnum_tp);
j2k_write_eoc(j2k);
-
- /* Creation of the index file */
- if(image_info && image_info->index_on) {
- if(!j2k_create_index(j2k, cio, image_info, index)) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "failed to create index file %s\n", index);
- return false;
- }
- }
+ if(cstr_info && cstr_info->index_on) {
+ cstr_info->codestream_size = cio_tell(cio) + j2k->pos_correction;
+ }
#ifdef USE_JPWL
/*
preparation of JPWL marker segments: can be finalized only when the whole
codestream is known
*/
- if(image_info && image_info->index_on && cp->epc_on) {
+ if(cstr_info && cstr_info->index_on && cp->epc_on) {
/* let's begin creating a marker list, according to user wishes */
jpwl_prepare_marks(j2k, cio, image);
/* do not know exactly what is this for,
but it gets called during index creation */
j2k->pos_correction = 0;
-
- /* Re-creation of the index file, with updated info */
- if(image_info && image_info->index_on) {
- if(!j2k_create_index(j2k, cio, image_info, index)) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "failed to re-create index file %s\n", index);
- return false;
- }
- }
-
- /* now we finalize the marker contents */
- /*jpwl_finalize_marks(j2k, cio, image);*/
-
}
#endif /* USE_JPWL */
-
return true;
}
+
/* <<UniPG */
} opj_cp_t;
-/**
-Information concerning a packet inside tile
-*/
-typedef struct opj_packet_info {
- /** start position */
- int start_pos;
- /** end position */
- int end_pos;
- /** ADD for Marcela */
- double disto;
-} opj_packet_info_t;
-
-/**
-Index structure : information regarding tiles inside image
-*/
-typedef struct opj_tile_info {
- /** value of thresh for each layer by tile cfr. Marcela */
- double *thresh;
- /** number of tile */
- int num_tile;
- /** start position */
- int start_pos;
- /** end position of the header */
- int end_header;
- /** end position */
- int end_pos;
- /** precinct number for each resolution level (width) */
- int pw[33];
- /** precinct number for each resolution level (height) */
- int ph[33];
- /** precinct size (in power of 2), in X for each resolution level */
- int pdx[33];
- /** precinct size (in power of 2), in Y for each resolution level */
- int pdy[33];
- /** information concerning packets inside tile */
- opj_packet_info_t *packet;
- /** add fixed_quality */
- int nbpix;
- /** add fixed_quality */
- double distotile;
-} opj_tile_info_t;
-
-/**
-Index structure
-*/
-typedef struct opj_image_info {
- /** 0 = no index || 1 = index */
- int index_on;
- /** maximum distortion reduction on the whole image (add for Marcela) */
- double D_max;
- /** packet number */
- int num;
- /** writing the packet in the index with t2_encode_packets */
- int index_write;
- /** image width */
- int image_w;
- /** image height */
- int image_h;
- /** progression order */
- OPJ_PROG_ORDER prog;
- /** tile size in x */
- int tile_x;
- /** tile size in y */
- int tile_y;
- /** */
- int tile_Ox;
- /** */
- int tile_Oy;
- /** number of tiles in X */
- int tw;
- /** number of tiles in Y */
- int th;
- /** component numbers */
- int comp;
- /** number of layer */
- int layer;
- /** number of decomposition */
- int decomposition;
- /** main header position */
- int main_head_end;
- /** codestream's size */
- int codestream_size;
- /** information regarding tiles inside image */
- opj_tile_info_t *tile;
-} opj_image_info_t;
-
/**
JPEG-2000 codestream reader/writer
*/
/** pointer to the coding parameters */
opj_cp_t *cp;
/** helper used to write the index file */
- opj_image_info_t *image_info;
+ opj_codestream_info_t *cstr_info;
/** pointer to the byte i/o stream */
opj_cio_t *cio;
} opj_j2k_t;
@param j2k J2K compressor handle
@param cio Output buffer stream
@param image Image to encode
-@param index Name of the index file if required, NULL otherwise
+@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
-bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index);
+bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
+
/* ----------------------------------------------------------------------- */
/*@}*/
#include <malloc.h>
#endif
-#define opj_aligned_malloc(size) _mm_malloc(size, 16)
-#define opj_aligned_free(m) _mm_free(m)
+#ifdef _mm_malloc
+ #define opj_aligned_malloc(size) _mm_malloc(size, 16)
+ #else
+ #define opj_aligned_malloc(size) malloc(size)
+ #endif
+
+ #ifdef _mm_free
+ #define opj_aligned_free(m) _mm_free(m)
+ #else
+ #define opj_aligned_free(m) free(m)
+ #endif
#else /* Not WIN32 */
@return Returns true if successful, returns false otherwise
*/
static bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
-static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index);
+static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
static bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_codestream_length, unsigned int *j2k_codestream_offset);
static void jp2_write_jp(opj_cio_t *cio);
/**
return true;
}
-static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index) {
+static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
unsigned int j2k_codestream_offset, j2k_codestream_length;
opj_jp2_box_t box;
/* J2K encoding */
j2k_codestream_offset = cio_tell(cio);
- if(!j2k_encode(j2k, cio, image, index)) {
+ if(!j2k_encode(j2k, cio, image, cstr_info)) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Failed to encode image\n");
return 0;
}
}
-bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index) {
+bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
/* JP2 encoding */
/* J2K encoding */
- if(!jp2_write_jp2c(jp2, cio, image, index)) {
+ if(!jp2_write_jp2c(jp2, cio, image, cstr_info)) {
opj_event_msg(jp2->cinfo, EVT_ERROR, "Failed to encode image\n");
return false;
}
@param jp2 JP2 compressor handle
@param cio Output buffer stream
@param image Image to encode
-@param index Name of the index file if required, NULL otherwise
+@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
-bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index);
+bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
/* ----------------------------------------------------------------------- */
/*@}*/
}
}
-bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
+bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
if(cinfo && cio && image) {
switch(cinfo->codec_format) {
case CODEC_J2K:
- return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, index);
+ return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
case CODEC_JP2:
- return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, index);
+ return jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
case CODEC_JPT:
case CODEC_UNKNOWN:
default:
return false;
}
-
-
int sgnd;
} opj_image_cmptparm_t;
+/*
+==========================================================
+ Information on the JPEG 2000 codestream
+==========================================================
+*/
+
+/**
+Index structure : Information concerning a packet inside tile
+*/
+typedef struct opj_packet_info {
+ /** start position */
+ int start_pos;
+ /** end position */
+ int end_pos;
+ /** packet distorsion */
+ double disto;
+} opj_packet_info_t;
+
+/**
+Index structure : information regarding tiles inside image
+*/
+typedef struct opj_tile_info {
+ /** value of thresh for each layer by tile cfr. Marcela */
+ double *thresh;
+ /** number of tile */
+ int num_tile;
+ /** start position */
+ int start_pos;
+ /** end position of the header */
+ int end_header;
+ /** end position */
+ int end_pos;
+ /** precinct number for each resolution level (width) */
+ int pw[33];
+ /** precinct number for each resolution level (height) */
+ int ph[33];
+ /** precinct size (in power of 2), in X for each resolution level */
+ int pdx[33];
+ /** precinct size (in power of 2), in Y for each resolution level */
+ int pdy[33];
+ /** information concerning packets inside tile */
+ opj_packet_info_t *packet;
+ /** add fixed_quality */
+ int nbpix;
+ /** add fixed_quality */
+ double distotile;
+} opj_tile_info_t;
+
+/**
+Index structure of the codestream
+*/
+typedef struct opj_codestream_info {
+ /** 0 = no index || 1 = index */
+ int index_on;
+ /** maximum distortion reduction on the whole image (add for Marcela) */
+ double D_max;
+ /** packet number */
+ int num;
+ /** writing the packet in the index with t2_encode_packets */
+ int index_write;
+ /** image width */
+ int image_w;
+ /** image height */
+ int image_h;
+ /** progression order */
+ OPJ_PROG_ORDER prog;
+ /** tile size in x */
+ int tile_x;
+ /** tile size in y */
+ int tile_y;
+ /** */
+ int tile_Ox;
+ /** */
+ int tile_Oy;
+ /** number of tiles in X */
+ int tw;
+ /** number of tiles in Y */
+ int th;
+ /** component numbers */
+ int comp;
+ /** number of layer */
+ int layer;
+ /** number of decomposition */
+ int decomposition;
+ /** main header position */
+ int main_head_end;
+ /** codestream's size */
+ int codestream_size;
+ /** information regarding tiles inside image */
+ opj_tile_info_t *tile;
+} opj_codestream_info_t;
+
#ifdef __cplusplus
extern "C" {
#endif
OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
/**
Setup the encoder parameters using the current image and using user parameters.
-@param cinfo compressor handle
-@param parameters compression parameters
-@param image input filled image
+@param cinfo Compressor handle
+@param parameters Compression parameters
+@param image Input filled image
*/
OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image);
/**
@param cinfo compressor handle
@param cio Output buffer stream
@param image Image to encode
-@param index Name of the index file if required, NULL otherwise
+@param cstr_info Codestream information structure if required, NULL otherwise
@return Returns true if successful, returns false otherwise
*/
-OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index);
+OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
#ifdef __cplusplus
}
@param pi Packet identity
@param dest Destination buffer
@param len Length of the destination buffer
-@param image_info Structure to create an index file
+@param cstr_info Codestream information structure
@param tileno Number of the tile encoded
@return
*/
-static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_image_info_t *image_info, int tileno);
+static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_codestream_info_t *cstr_info, int tileno);
/**
@param seg
@param cblksty
return (37 + bio_read(bio, 7));
}
-static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int length, opj_image_info_t * image_info, int tileno) {
+static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int length, opj_codestream_info_t *cstr_info, int tileno) {
int bandno, cblkno;
unsigned char *sop = 0, *eph = 0;
unsigned char *c = dest;
sop[1] = 145;
sop[2] = 0;
sop[3] = 4;
- sop[4] = (image_info->num % 65536) / 256;
- sop[5] = (image_info->num % 65536) % 256;
+ sop[4] = (cstr_info->num % 65536) / 256;
+ sop[5] = (cstr_info->num % 65536) % 256;
memcpy(c, sop, 6);
opj_free(sop);
c += 6;
cblk->numpasses += layer->numpasses;
c += layer->len;
/* ADD for index Cfr. Marcela --> delta disto by packet */
- if(image_info && image_info->index_write && image_info->index_on) {
- opj_tile_info_t *info_TL = &image_info->tile[tileno];
- opj_packet_info_t *info_PK = &info_TL->packet[image_info->num];
+ if(cstr_info && cstr_info->index_write && cstr_info->index_on) {
+ opj_tile_info_t *info_TL = &cstr_info->tile[tileno];
+ opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->num];
info_PK->disto += layer->disto;
- if (image_info->D_max < info_PK->disto) {
- image_info->D_max = info_PK->disto;
+ if (cstr_info->D_max < info_PK->disto) {
+ cstr_info->D_max = info_PK->disto;
}
}
/* </ADD> */
/* ----------------------------------------------------------------------- */
-int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info,int tpnum, int tppos,int pino, J2K_T2_MODE t2_mode){
+int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino, J2K_T2_MODE t2_mode){
unsigned char *c = dest;
int e = 0;
int compno;
pi_create_encode(pi, cp,tileno,poc,tpnum,tppos,t2_mode);
while (pi_next(&pi[poc])) {
if (pi[poc].layno < maxlayers) {
- e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[poc], c, dest + len - c, image_info, tileno);
+ e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[poc], c, dest + len - c, cstr_info, tileno);
comp_len = comp_len + e;
if (e == -999) {
break;
pi_create_encode(pi, cp,tileno,pino,tpnum,tppos,t2_mode);
while (pi_next(&pi[pino])) {
if (pi[pino].layno < maxlayers) {
- e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, image_info, tileno);
+ e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, cstr_info, tileno);
if (e == -999) {
break;
} else {
c += e;
}
/* INDEX >> */
- if(image_info && image_info->index_on) {
- if(image_info->index_write) {
- opj_tile_info_t *info_TL = &image_info->tile[tileno];
- opj_packet_info_t *info_PK = &info_TL->packet[image_info->num];
- if (!image_info->num) {
+ if(cstr_info && cstr_info->index_on) {
+ if(cstr_info->index_write) {
+ opj_tile_info_t *info_TL = &cstr_info->tile[tileno];
+ opj_packet_info_t *info_PK = &info_TL->packet[cstr_info->num];
+ if (!cstr_info->num) {
info_PK->start_pos = info_TL->end_header + 1;
} else {
- info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[image_info->num - 1].end_pos + 1;
+ info_PK->start_pos = (cp->tp_on && info_PK->start_pos) ? info_PK->start_pos : info_TL->packet[cstr_info->num - 1].end_pos + 1;
}
info_PK->end_pos = info_PK->start_pos + e - 1;
}
- image_info->num++;
+ cstr_info->num++;
}
/* << INDEX */
}
@param maxlayers maximum number of layers
@param dest the destination buffer
@param len the length of the destination buffer
-@param image_info structure to create an index file
+@param cstr_info Codestream information structure
@param tpnum Tile part number of the current tile
@param tppos The position of the tile part flag in the progression order
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
*/
-int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info,int tpnum, int tppos,int pino,J2K_T2_MODE t2_mode);
+int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_codestream_info_t *cstr_info,int tpnum, int tppos,int pino,J2K_T2_MODE t2_mode);
/**
Decode the packets of a tile from a source buffer
@param t2 T2 handle
}
}
-bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_info_t * image_info) {
+bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
int compno, resno, bandno, precno, cblkno, passno, layno;
double min, max;
double cumdisto[100]; /* fixed_quality */
} /* compno */
/* index file */
- if(image_info && image_info->index_on) {
- opj_tile_info_t *tile_info = &image_info->tile[tcd->tcd_tileno];
+ if(cstr_info && cstr_info->index_on) {
+ opj_tile_info_t *tile_info = &cstr_info->tile[tcd->tcd_tileno];
tile_info->nbpix = tcd_tile->nbpix;
tile_info->distotile = tcd_tile->distotile;
tile_info->thresh = (double *) opj_malloc(tcd_tcp->numlayers * sizeof(double));
/* fixed_quality */
distotarget = tcd_tile->distotile - ((K * maxSE) / pow((float)10, tcd_tcp->distoratio[layno] / 10));
- if ((tcd_tcp->rates[layno]) || (cp->disto_alloc == 0)) {
+ /* Don't try to find an optimal threshold but rather take everything not included yet, if
+ -r xx,yy,zz,0 (disto_alloc == 1 and rates == 0)
+ -q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0)
+ ==> possible to have some lossy layers and the last layer for sure lossless */
+ if ( ((cp->disto_alloc==1) && (tcd_tcp->rates[layno]>0)) || ((cp->fixed_quality==1) && (tcd_tcp->distoratio[layno]>0))) {
opj_t2_t *t2 = t2_create(tcd->cinfo, tcd->image, cp);
for (i = 0; i < 32; i++) {
if (cp->fixed_quality) { /* fixed_quality */
if(cp->cinema){
- l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC);
+ l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC);
if (l == -999) {
lo = thresh;
continue;
lo = thresh;
}
} else {
- l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC);
+ l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC);
/* TODO: what to do with l ??? seek / tell ??? */
/* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */
if (l == -999) {
return false;
}
- if(image_info && image_info->index_on) { /* Threshold for Marcela Index */
- image_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh;
+ if(cstr_info && cstr_info->index_on) { /* Threshold for Marcela Index */
+ cstr_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh;
}
tcd_makelayer(tcd, layno, goodthresh, 1);
return true;
}
-int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_image_info_t * image_info) {
+int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info) {
int compno;
int l, i, npck = 0;
opj_tcd_tile_t *tile = NULL;
if(tcd->cur_tp_num == 0){
tcd->encoding_time = opj_clock(); /* time needed to encode a tile */
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
- if(image_info && image_info->index_on) {
+ if(cstr_info && cstr_info->index_on) {
opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */
for (i = 0; i < tilec_idx->numresolutions; i++) {
opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i];
- image_info->tile[tileno].pw[i] = res_idx->pw;
- image_info->tile[tileno].ph[i] = res_idx->ph;
+ cstr_info->tile[tileno].pw[i] = res_idx->pw;
+ cstr_info->tile[tileno].ph[i] = res_idx->ph;
npck += res_idx->pw * res_idx->ph;
- image_info->tile[tileno].pdx[i] = tccp->prcw[i];
- image_info->tile[tileno].pdy[i] = tccp->prch[i];
+ cstr_info->tile[tileno].pdx[i] = tccp->prcw[i];
+ cstr_info->tile[tileno].pdy[i] = tccp->prch[i];
}
- image_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(image_info->comp * image_info->layer * npck * sizeof(opj_packet_info_t));
+ cstr_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(cstr_info->comp * cstr_info->layer * npck * sizeof(opj_packet_info_t));
}
/* << INDEX */
/*-----------RATE-ALLOCATE------------------*/
/* INDEX */
- if(image_info) {
- image_info->index_write = 0;
+ if(cstr_info) {
+ cstr_info->index_write = 0;
}
if (cp->disto_alloc || cp->fixed_quality) { /* fixed_quality */
/* Normal Rate/distortion allocation */
- tcd_rateallocate(tcd, dest, len, image_info);
+ tcd_rateallocate(tcd, dest, len, cstr_info);
} else {
/* Fixed layer allocation */
tcd_rateallocate_fixed(tcd);
/*--------------TIER2------------------*/
/* INDEX */
- if(image_info) {
- image_info->index_write = 1;
+ if(cstr_info) {
+ cstr_info->index_write = 1;
}
t2 = t2_create(tcd->cinfo, image, cp);
- l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, image_info,tcd->tp_num,tcd->tp_pos,tcd->cur_pino,FINAL_PASS);
+ l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, cstr_info,tcd->tp_num,tcd->tp_pos,tcd->cur_pino,FINAL_PASS);
t2_destroy(t2);
/*---------------CLEAN-------------------*/
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
void tcd_rateallocate_fixed(opj_tcd_t *tcd);
void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
-bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_info_t * image_info);
+bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
/**
Encode a tile from the raw image into a buffer
@param tcd TCD handle
@param tileno Number that identifies one of the tiles to be encoded
@param dest Destination buffer
@param len Length of destination buffer
-@param image_info Creation of index file
+@param cstr_info Codestream information structure
@return
*/
-int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_image_info_t * image_info);
+int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_codestream_info_t *cstr_info);
/**
Decode a tile from a buffer into a raw image
@param tcd TCD handle
(stdout," Indicate multiple modes by adding their values. \n");
fprintf
(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
- fprintf
- (stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n");
fprintf
(stdout,"-ROI : c=%%d,U=%%d : quantization indices upshifted \n");
fprintf
opj_cinfo_t* cinfo;
bool bSuccess;
int numframes;
- double total_time = 0;
+ double total_time = 0;
/* default value */
/* ------------- */
while (1) {
int c = getopt(argc, argv,
- "i:o:r:q:f:t:n:c:b:x:p:s:d:h P:S:E:M:R:T:C:I:W:F:");
+ "i:o:r:q:f:t:n:c:b:p:s:d:h P:S:E:M:R:T:C:I:W:F:");
if (c == -1)
break;
switch (c) {
}
break;
/* ----------------------------------------------------- */
- case 'x': /* creation of index file */
- {
- char *index = optarg;
- strncpy(j2k_parameters->index, index, sizeof(j2k_parameters->index)-1);
- j2k_parameters->index_on = 1;
- }
- break;
- /* ----------------------------------------------------- */
case 'p': /* progression order */
{
char progression[4];
cio_write(cio, JP2_JP2C, 4); // JP2C
/* encode the image */
- bSuccess = opj_encode(cinfo, cio, img, j2k_parameters->index);
+ bSuccess = opj_encode(cinfo, cio, img, NULL);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");