summaryrefslogtreecommitdiff
path: root/OPJViewer/source/imagj2k.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'OPJViewer/source/imagj2k.cpp')
-rw-r--r--OPJViewer/source/imagj2k.cpp140
1 files changed, 67 insertions, 73 deletions
diff --git a/OPJViewer/source/imagj2k.cpp b/OPJViewer/source/imagj2k.cpp
index 64c051ff..9ce142df 100644
--- a/OPJViewer/source/imagj2k.cpp
+++ b/OPJViewer/source/imagj2k.cpp
@@ -131,6 +131,7 @@ bool wxJ2KHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
unsigned char *src = NULL;
unsigned char *ptr;
int file_length;
+ opj_codestream_info_t cstr_info; /* Codestream information structure */
// destroy the image
image->Destroy();
@@ -188,7 +189,7 @@ bool wxJ2KHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose,
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
- opjimage = opj_decode(dinfo, cio);
+ opjimage = opj_decode(dinfo, cio, &cstr_info);
if (!opjimage) {
#ifndef __WXGTK__
wxMutexGuiEnter();
@@ -242,6 +243,7 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
int codestream_length;
bool bSuccess;
int i;
+ char indexfilename[OPJ_PATH_LEN] = ""; /* index file name */
/*
configure the event callbacks (not required)
@@ -316,11 +318,8 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
/* indexing file */
if (m_enableidx) {
- strncpy(parameters.index, m_index.c_str(), m_index.Len());
- wxLogMessage("index file is %s", parameters.index);
- parameters.index_on = 1;
- } else {
- parameters.index_on = 0;
+ strncpy(indexfilename, m_index.c_str(), OPJ_PATH_LEN);
+ wxLogMessage("index file is %s", indexfilename);
}
/* if no rate entered, lossless by default */
@@ -479,8 +478,8 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
opj_cio_close(cio);
/* Write the index to disk */
- if (parameters.index_on) {
- bSuccess = write_index_file(&cstr_info, parameters.index);
+ if (*indexfilename) {
+ bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
wxLogError(wxT("Failed to output index file"));
}
@@ -536,67 +535,72 @@ Create an index and write it to a file
bool wxJ2KHandler::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;
+ int tilepartno;
if (!cstr_info)
- return false;
+ return 1;
stream = fopen(index, "w");
if (!stream) {
- wxLogError(wxT("failed to open index file [%s] for writing"), index);
- return false;
+ 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);
+ fprintf(stream, "%d\n", cstr_info->numcomps);
+ fprintf(stream, "%d\n", cstr_info->numlayers);
+ fprintf(stream, "%d\n", cstr_info->numdecompos);
- for (resno = cstr_info->decomposition; resno >= 0; resno--) {
+ for (resno = cstr_info->numdecompos; 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_start);
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");
+ fprintf(stream, "tileno start_pos end_hd end_tile nbparts\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,
+ fprintf(stream, "%4d %9d %9d %9d %9d\n",
+ cstr_info->tile[tileno].tileno,
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);
+ cstr_info->tile[tileno].num_tps);
}
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
int start_pos, end_ph_pos, end_pos;
- double disto = 0;
pack_nb = 0;
- fprintf(stream, "\nTILE %d DETAILS\n", tileno);
+ fprintf(stream, "\nTILE %d DETAILS\n", tileno);
+ fprintf(stream, "part_nb tileno num_packs start_pos end_tph_pos end_pos\n");
+ for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
+ fprintf(stream, "%4d %9d %9d %9d %11d %9d\n",
+ tilepartno, tileno,
+ cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
+ cstr_info->tile[tileno].tp[tilepartno].tp_start_pos,
+ cstr_info->tile[tileno].tp[tilepartno].tp_end_header,
+ cstr_info->tile[tileno].tp[tilepartno].tp_end_pos
+ );
if (cstr_info->prog == LRCP) { /* LRCP */
+ fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos\n");
- fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_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++) {
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
+ for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) {
+ for (compno = 0; compno < cstr_info->numcomps; 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_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_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 %6d %6d %7d %8e\n",
- pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos, disto);
- total_disto += disto;
+ fprintf(stream, "%4d %6d %7d %5d %6d %6d %6d %6d %7d\n",
+ pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos);
pack_nb++;
}
}
@@ -605,20 +609,18 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
} /* LRCP */
else if (cstr_info->prog == RLCP) { /* RLCP */
- fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos disto\n");
+ fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\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++) {
+ for (resno = 0; resno < cstr_info->numdecompos + 1; resno++) {
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
+ for (compno = 0; compno < cstr_info->numcomps; 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_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_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 %7d %8e\n",
- pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos, disto);
- total_disto += disto;
+ fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %7d\n",
+ pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos);
pack_nb++;
}
}
@@ -627,34 +629,32 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
} /* RLCP */
else if (cstr_info->prog == RPCL) { /* RPCL */
- fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos disto\n");
+ fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos\n");
- for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {
+ for (resno = 0; resno < cstr_info->numdecompos + 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++) {
+ for (compno = 0; compno < cstr_info->numcomps; 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 pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno );
+ int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - 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++) {
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_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 %7d %8e\n",
- pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos, disto);
- total_disto += disto;
+ fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %7d\n",
+ pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos);
pack_nb++;
}
}
@@ -672,29 +672,27 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y;
- fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos disto\n");
+ fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos\n");
- for (compno = 0; compno < cstr_info->comp; compno++) {
- for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {
+ for (compno = 0; compno < cstr_info->numcomps; compno++) {
+ for (resno = 0; resno < cstr_info->numdecompos + 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 pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno );
+ int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - 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++) {
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_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 %7d %8e\n",
- pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos, disto);
- total_disto += disto;
+ fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d\n",
+ pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos);
pack_nb++;
}
}
@@ -707,35 +705,33 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
} /* PCRL */
else { /* CPRL */
- fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos disto\n");
+ fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos\n");
- for (compno = 0; compno < cstr_info->comp; compno++) {
+ for (compno = 0; compno < cstr_info->numcomps; 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++) {
+ for (resno = 0; resno < cstr_info->numdecompos + 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 pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos - resno );
+ int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos - 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++) {
+ for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_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 %7d %8e\n",
- pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos, disto);
- total_disto += disto;
+ fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d\n",
+ pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos);
pack_nb++;
}
}
@@ -748,11 +744,9 @@ bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *inde
} /* CPRL */
} /* tileno */
- fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
- fprintf(stream, "%.8e\n", total_disto); /* SE totale */
fclose(stream);
- wxLogError(wxT("Generated index file %s"), index);
+ fprintf(stderr,"Generated index file %s\n", index);
return true;
}