Changed the OpenJPEG library interface to enable users to access information regarding the codestream (also called index).
This commit is contained in:
parent
d07fa5d9d0
commit
acfe0ad645
|
@ -5,6 +5,11 @@ What's New for OpenJPEG
|
|||
! : 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
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "openjpeg.h"
|
||||
#include "compat/getopt.h"
|
||||
|
@ -146,10 +147,10 @@ void encode_help_display() {
|
|||
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 ");
|
||||
|
@ -384,7 +385,6 @@ int get_file_format(char *filename) {
|
|||
return format[i];
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -483,7 +483,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
|
|||
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;
|
||||
|
@ -549,6 +549,233 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
|
|||
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
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;
|
||||
|
@ -1465,6 +1692,7 @@ int main(int argc, char **argv) {
|
|||
int imageno;
|
||||
dircnt_t *dirptr;
|
||||
raw_cparameters_t raw_cp;
|
||||
opj_codestream_info_t cstr_info;
|
||||
|
||||
/*
|
||||
configure the event callbacks (not required)
|
||||
|
@ -1501,19 +1729,15 @@ int main(int argc, char **argv) {
|
|||
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;
|
||||
}
|
||||
|
@ -1532,13 +1756,10 @@ int main(int argc, char **argv) {
|
|||
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");
|
||||
|
@ -1644,7 +1865,7 @@ int main(int argc, char **argv) {
|
|||
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");
|
||||
|
@ -1665,9 +1886,16 @@ int main(int argc, char **argv) {
|
|||
/* 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;
|
||||
|
@ -1687,7 +1915,7 @@ int main(int argc, char **argv) {
|
|||
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");
|
||||
|
@ -1707,6 +1935,14 @@ int main(int argc, char **argv) {
|
|||
/* 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);
|
||||
|
||||
|
@ -1722,5 +1958,3 @@ int main(int argc, char **argv) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
56
jpwl/jpwl.c
56
jpwl/jpwl.c
|
@ -179,7 +179,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
(unsigned char) j2k->cp->sens_MH, /* sensitivity method */
|
||||
j2k->cp->sens_size, /* sensitivity size */
|
||||
-1, /* this ESD is in main header */
|
||||
0 /*j2k->image_info->num*/, /* number of packets in codestream */
|
||||
0 /*j2k->cstr_info->num*/, /* number of packets in codestream */
|
||||
NULL /*sensval*/ /* pointer to sensitivity data of packets */
|
||||
)) {
|
||||
|
||||
|
@ -215,21 +215,21 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
/* cycle through TPHs */
|
||||
sens = -1; /* default spec: no ESD */
|
||||
tilespec = 0; /* first tile spec */
|
||||
for (tileno = 0; tileno < j2k->image_info->tw * j2k->image_info->th; tileno++) {
|
||||
for (tileno = 0; tileno < j2k->cstr_info->tw * j2k->cstr_info->th; tileno++) {
|
||||
|
||||
int sot_len, Psot, Psotp, mm;
|
||||
unsigned long sot_pos, post_sod_pos;
|
||||
|
||||
unsigned long int left_THmarks_len;
|
||||
|
||||
sot_pos = j2k->image_info->tile[tileno].start_pos;
|
||||
sot_pos = j2k->cstr_info->tile[tileno].start_pos;
|
||||
cio_seek(cio, sot_pos + 2);
|
||||
sot_len = cio_read(cio, 2); /* SOT Len */
|
||||
cio_skip(cio, 2);
|
||||
Psotp = cio_tell(cio);
|
||||
Psot = cio_read(cio, 4); /* tile length */
|
||||
|
||||
post_sod_pos = j2k->image_info->tile[tileno].end_header + 1;
|
||||
post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1;
|
||||
left_THmarks_len = post_sod_pos - sot_pos;
|
||||
|
||||
/* add all the lengths of the markers which are len-ready and stay within SOT and SOD */
|
||||
|
@ -269,7 +269,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
if (jwmarker_num < JPWL_MAX_NO_MARKERS) {
|
||||
jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */
|
||||
jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */
|
||||
jwmarker[jwmarker_num].pos = j2k->image_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */
|
||||
jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */
|
||||
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */
|
||||
jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */
|
||||
jwmarker[jwmarker_num].len_ready = true; /* ready, yet */
|
||||
|
@ -307,7 +307,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
int mm;
|
||||
|
||||
/* position of SOT */
|
||||
unsigned int sot_pos = j2k->image_info->main_head_end + 1;
|
||||
unsigned int sot_pos = j2k->cstr_info->main_head_end + 1;
|
||||
|
||||
/* how much space is there between end of SIZ and beginning of SOT? */
|
||||
int left_MHmarks_len = sot_pos - socsiz_len;
|
||||
|
@ -371,15 +371,15 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
lastileno = 0;
|
||||
packspec = 0;
|
||||
pprot = -1;
|
||||
for (tileno = 0; tileno < j2k->image_info->tw * j2k->image_info->th; tileno++) {
|
||||
for (tileno = 0; tileno < j2k->cstr_info->tw * j2k->cstr_info->th; tileno++) {
|
||||
|
||||
int sot_len, Psot, Psotp, mm, epb_index = 0, prot_len = 0;
|
||||
unsigned long sot_pos, post_sod_pos;
|
||||
unsigned long int left_THmarks_len, epbs_len = 0;
|
||||
int startpack = 0, stoppack = j2k->image_info->num;
|
||||
int startpack = 0, stoppack = j2k->cstr_info->num;
|
||||
jpwl_epb_ms_t *tph_epb = NULL;
|
||||
|
||||
sot_pos = j2k->image_info->tile[tileno].start_pos;
|
||||
sot_pos = j2k->cstr_info->tile[tileno].start_pos;
|
||||
cio_seek(cio, sot_pos + 2);
|
||||
sot_len = cio_read(cio, 2); /* SOT Len */
|
||||
cio_skip(cio, 2);
|
||||
|
@ -387,7 +387,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
Psot = cio_read(cio, 4); /* tile length */
|
||||
|
||||
/* a-priori length of the data dwelling between SOT and SOD */
|
||||
post_sod_pos = j2k->image_info->tile[tileno].end_header + 1;
|
||||
post_sod_pos = j2k->cstr_info->tile[tileno].end_header + 1;
|
||||
left_THmarks_len = post_sod_pos - (sot_pos + sot_len + 2);
|
||||
|
||||
/* add all the lengths of the JPWL markers which are len-ready and stay within SOT and SOD */
|
||||
|
@ -426,7 +426,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
if (jwmarker_num < JPWL_MAX_NO_MARKERS) {
|
||||
jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */
|
||||
jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */
|
||||
jwmarker[jwmarker_num].pos = j2k->image_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */
|
||||
jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; /* after SOT */
|
||||
jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */
|
||||
jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */
|
||||
jwmarker[jwmarker_num].len_ready = true; /* ready */
|
||||
|
@ -457,7 +457,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
|
||||
startpack = 0;
|
||||
/* EPB MSs for UEP packet data protection in Tile Parts */
|
||||
for (packno = 0; packno < j2k->image_info->num; packno++) {
|
||||
for (packno = 0; packno < j2k->cstr_info->num; packno++) {
|
||||
|
||||
if ((packspec < JPWL_MAX_NO_PACKSPECS) &&
|
||||
(j2k->cp->pprot_tileno[packspec] == tileno) && (j2k->cp->pprot_packno[packspec] == packno)) {
|
||||
|
@ -471,19 +471,19 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
tileno,
|
||||
startpack,
|
||||
stoppack,
|
||||
j2k->image_info->tile[tileno].packet[startpack].start_pos,
|
||||
j2k->image_info->tile[tileno].packet[stoppack].end_pos,
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos,
|
||||
j2k->cstr_info->tile[tileno].packet[stoppack].end_pos,
|
||||
pprot);
|
||||
|
||||
prot_len = j2k->image_info->tile[tileno].packet[stoppack].end_pos + 1 -
|
||||
j2k->image_info->tile[tileno].packet[startpack].start_pos;
|
||||
prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos;
|
||||
|
||||
/*
|
||||
particular case: if this is the last header and the last packet,
|
||||
then it is better to protect even the EOC marker
|
||||
*/
|
||||
if ((tileno == ((j2k->image_info->tw * j2k->image_info->th) - 1)) &&
|
||||
(stoppack == (j2k->image_info->num - 1)))
|
||||
if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&
|
||||
(stoppack == (j2k->cstr_info->num - 1)))
|
||||
/* add the EOC len */
|
||||
prot_len += 2;
|
||||
|
||||
|
@ -497,7 +497,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
false, /* inside MH */
|
||||
&epb_index, /* pointer to EPB index */
|
||||
pprot, /* protection type */
|
||||
(double) (j2k->image_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */
|
||||
(double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */
|
||||
tileno, /* number of tile */
|
||||
0, /* length of pre-data */
|
||||
prot_len /*4000*/ /* length of post-data */
|
||||
|
@ -521,19 +521,19 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
tileno,
|
||||
startpack,
|
||||
stoppack,
|
||||
j2k->image_info->tile[tileno].packet[startpack].start_pos,
|
||||
j2k->image_info->tile[tileno].packet[stoppack].end_pos,
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos,
|
||||
j2k->cstr_info->tile[tileno].packet[stoppack].end_pos,
|
||||
pprot);
|
||||
|
||||
prot_len = j2k->image_info->tile[tileno].packet[stoppack].end_pos + 1 -
|
||||
j2k->image_info->tile[tileno].packet[startpack].start_pos;
|
||||
prot_len = j2k->cstr_info->tile[tileno].packet[stoppack].end_pos + 1 -
|
||||
j2k->cstr_info->tile[tileno].packet[startpack].start_pos;
|
||||
|
||||
/*
|
||||
particular case: if this is the last header and the last packet,
|
||||
then it is better to protect even the EOC marker
|
||||
*/
|
||||
if ((tileno == ((j2k->image_info->tw * j2k->image_info->th) - 1)) &&
|
||||
(stoppack == (j2k->image_info->num - 1)))
|
||||
if ((tileno == ((j2k->cstr_info->tw * j2k->cstr_info->th) - 1)) &&
|
||||
(stoppack == (j2k->cstr_info->num - 1)))
|
||||
/* add the EOC len */
|
||||
prot_len += 2;
|
||||
|
||||
|
@ -547,7 +547,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
false, /* inside MH */
|
||||
&epb_index, /* pointer to EPB index */
|
||||
pprot, /* protection type */
|
||||
(double) (j2k->image_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */
|
||||
(double) (j2k->cstr_info->tile[tileno].start_pos + sot_len + 2) + 0.0001, /* position */
|
||||
tileno, /* number of tile */
|
||||
0, /* length of pre-data */
|
||||
prot_len /*4000*/ /* length of post-data */
|
||||
|
@ -575,7 +575,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
||||
|
||||
int mm;
|
||||
unsigned long int old_size = j2k->image_info->codestream_size;
|
||||
unsigned long int old_size = j2k->cstr_info->codestream_size;
|
||||
unsigned long int new_size = old_size;
|
||||
int ciopos = cio_tell(cio);
|
||||
unsigned char *jpwl_buf, *orig_buf;
|
||||
|
@ -655,7 +655,7 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
|
|||
update info file based on added markers
|
||||
*/
|
||||
if (!jpwl_update_info(j2k, jwmarker, jwmarker_num))
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not update OPJ image_info structure\n");
|
||||
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not update OPJ cstr_info structure\n");
|
||||
|
||||
/* now we need to repass some markers and fill their data fields */
|
||||
|
||||
|
|
|
@ -1216,7 +1216,7 @@ jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, un
|
|||
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;
|
||||
|
||||
|
@ -1225,7 +1225,7 @@ jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, un
|
|||
/* 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;
|
||||
|
||||
|
@ -1246,17 +1246,17 @@ jpwl_esd_ms_t *jpwl_esd_create(opj_j2k_t *j2k, int comp, unsigned char addrm, un
|
|||
/* 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;
|
||||
|
||||
}
|
||||
|
@ -1356,26 +1356,26 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
|
|||
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);
|
||||
|
@ -1391,9 +1391,9 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
|
|||
/* 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 */
|
||||
|
@ -1417,7 +1417,7 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
|
|||
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 */
|
||||
|
@ -1425,8 +1425,8 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
|
|||
|
||||
} 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 */
|
||||
|
@ -1484,7 +1484,7 @@ bool jpwl_esd_fill(opj_j2k_t *j2k, jpwl_esd_ms_t *esd, unsigned char *buf) {
|
|||
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 */
|
||||
|
@ -1657,7 +1657,7 @@ bool jpwl_update_info(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int jwmarker_num)
|
|||
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 ) {
|
||||
|
|
|
@ -139,7 +139,7 @@ bool cio_byteout(opj_cio_t *cio, unsigned char v) {
|
|||
*/
|
||||
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++;
|
||||
|
|
|
@ -1340,7 +1340,7 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
|
|||
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;
|
||||
|
@ -1355,13 +1355,13 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
|
|||
}
|
||||
|
||||
/* 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 */
|
||||
|
@ -1370,11 +1370,11 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
|
|||
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;
|
||||
|
@ -1901,18 +1901,17 @@ void j2k_destroy_compress(opj_j2k_t *j2k) {
|
|||
|
||||
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;
|
||||
|
@ -1970,9 +1969,6 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
|
|||
|
||||
/* 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;
|
||||
|
@ -2198,241 +2194,8 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
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 */
|
||||
|
@ -2445,23 +2208,26 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
|
|||
/* 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 */
|
||||
|
||||
|
@ -2496,8 +2262,8 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
|
|||
}
|
||||
|
||||
/* 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 ***/
|
||||
|
@ -2506,7 +2272,6 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
|
|||
tcd = tcd_create(j2k->cinfo);
|
||||
|
||||
/* encode each tile */
|
||||
|
||||
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
|
||||
int pino;
|
||||
int tilepartno=0;
|
||||
|
@ -2525,9 +2290,9 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
|
|||
}
|
||||
|
||||
/* 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 */
|
||||
|
||||
|
@ -2559,8 +2324,8 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *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 */
|
||||
|
||||
|
@ -2591,21 +2356,16 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
|
|||
|
||||
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);
|
||||
|
@ -2616,23 +2376,11 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
|
|||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -304,92 +304,6 @@ typedef struct opj_cp {
|
|||
/* <<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
|
||||
*/
|
||||
|
@ -445,7 +359,7 @@ typedef struct opj_j2k {
|
|||
/** 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;
|
||||
|
@ -513,10 +427,11 @@ Encode an image into a JPEG-2000 codestream
|
|||
@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);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
|
|
|
@ -69,8 +69,17 @@ Allocate memory aligned to a 16 byte boundry
|
|||
#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 */
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ Read the FTYP box - File type box
|
|||
@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);
|
||||
/**
|
||||
|
@ -404,7 +404,7 @@ static bool jp2_read_ftyp(opj_jp2_t *jp2, 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;
|
||||
|
||||
|
@ -416,7 +416,7 @@ static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, ch
|
|||
|
||||
/* 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;
|
||||
}
|
||||
|
@ -686,7 +686,7 @@ void jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_
|
|||
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
|
@ -699,7 +699,7 @@ bool jp2_encode(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, char *index)
|
|||
|
||||
/* 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;
|
||||
}
|
||||
|
|
|
@ -163,10 +163,10 @@ Encode an image into a JPEG-2000 file stream
|
|||
@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);
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/*@}*/
|
||||
|
||||
|
|
|
@ -287,13 +287,13 @@ void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *param
|
|||
}
|
||||
}
|
||||
|
||||
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:
|
||||
|
@ -303,5 +303,3 @@ bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *im
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -580,6 +580,98 @@ typedef struct opj_image_comptparm {
|
|||
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
|
||||
|
@ -730,9 +822,9 @@ Set encoding parameters to default values, that means :
|
|||
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);
|
||||
/**
|
||||
|
@ -740,10 +832,10 @@ Encode an image into a JPEG-2000 codestream
|
|||
@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
|
||||
}
|
||||
|
|
|
@ -53,11 +53,11 @@ Encode a packet of a tile to a destination buffer
|
|||
@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
|
||||
|
@ -126,7 +126,7 @@ static int t2_getnumpasses(opj_bio_t *bio) {
|
|||
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;
|
||||
|
@ -148,8 +148,8 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
|
|||
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;
|
||||
|
@ -278,12 +278,12 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
|
|||
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> */
|
||||
|
@ -564,7 +564,7 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
|
|||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
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;
|
||||
|
@ -590,7 +590,7 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
|
|||
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;
|
||||
|
@ -613,26 +613,26 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
|
|||
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 */
|
||||
}
|
||||
|
|
|
@ -64,12 +64,12 @@ Encode the packets of a tile to a destination buffer
|
|||
@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
|
||||
|
|
|
@ -979,7 +979,7 @@ 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) {
|
||||
int compno, resno, bandno, precno, cblkno, passno, layno;
|
||||
double min, max;
|
||||
double cumdisto[100]; /* fixed_quality */
|
||||
|
@ -1048,8 +1048,8 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
|
|||
} /* 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));
|
||||
|
@ -1068,7 +1068,11 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
|
|||
/* 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++) {
|
||||
|
@ -1080,7 +1084,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
|
|||
|
||||
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;
|
||||
|
@ -1106,7 +1110,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
|
|||
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) {
|
||||
|
@ -1129,8 +1133,8 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
|
|||
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);
|
||||
|
||||
|
@ -1141,7 +1145,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
|
|||
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;
|
||||
|
@ -1166,20 +1170,20 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
|
|||
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 */
|
||||
|
||||
|
@ -1251,12 +1255,12 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
|
|||
/*-----------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);
|
||||
|
@ -1265,12 +1269,12 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
|
|||
/*--------------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-------------------*/
|
||||
|
|
|
@ -238,17 +238,17 @@ void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp,
|
|||
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
|
||||
|
|
|
@ -141,8 +141,6 @@ void help_display()
|
|||
(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
|
||||
|
@ -279,7 +277,7 @@ int main(int argc, char **argv)
|
|||
|
||||
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) {
|
||||
|
@ -462,14 +460,6 @@ int main(int argc, char **argv)
|
|||
}
|
||||
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];
|
||||
|
@ -743,7 +733,7 @@ int main(int argc, char **argv)
|
|||
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");
|
||||
|
|
Loading…
Reference in New Issue