summaryrefslogtreecommitdiff
path: root/applications/codec
diff options
context:
space:
mode:
authorMickael Savinaud <savmickael@users.noreply.github.com>2011-09-19 16:01:49 +0000
committerMickael Savinaud <savmickael@users.noreply.github.com>2011-09-19 16:01:49 +0000
commitd44375aece5dea2af83ffb8c9de4ade2ad35c593 (patch)
tree9c4c43b99c704852d3c55c501206e02aaf4e39ad /applications/codec
parentcf37058d7c5ba3560e86e40244556b58e4349e8c (diff)
WIP: create a new framework to output file information
Diffstat (limited to 'applications/codec')
-rw-r--r--applications/codec/index.c106
-rw-r--r--applications/codec/index.h2
-rw-r--r--applications/codec/j2k_dump.c67
3 files changed, 167 insertions, 8 deletions
diff --git a/applications/codec/index.c b/applications/codec/index.c
index 3765819b..2879f47f 100644
--- a/applications/codec/index.c
+++ b/applications/codec/index.c
@@ -742,3 +742,109 @@ int write_index_file_v2(FILE* stream, opj_codestream_info_t *cstr_info) {
return EXIT_SUCCESS;
}
+
+/* ------------------------------------------------------------------------------------ */
+
+/**
+Dump the file info structure into a file
+@param stream output stream
+@param file_info informations read into the JPG2000 file
+@return Returns 0 if successful, returns 1 otherwise
+*/
+int dump_file_info(FILE* stream, opj_file_info_t *file_info)
+{
+ /* IMAGE HEADER */
+ if ( file_info->file_info_flag & OPJ_IMG_INFO ) {
+ opj_image_header_t img_header = file_info->img_info;
+ int compno;
+
+ fprintf(stream, "Image info {\n");
+ fprintf(stream, "\t x0=%d, y0=%d\n",img_header.x0, img_header.y0);
+ fprintf(stream, "\t x1=%d, y1=%d\n",img_header.x1, img_header.y1);
+ fprintf(stream, "\t numcomps=%d\n", img_header.numcomps);
+ for (compno = 0; compno < img_header.numcomps; compno++) {
+ opj_image_comp_header_t comp = img_header.comps[compno];
+
+ fprintf(stream, "\t component %d {\n", compno);
+ fprintf(stream, "\t\t dx=%d, dy=%d\n", comp.dx, comp.dy);
+ fprintf(stream, "\t\t prec=%d\n", comp.prec);
+ fprintf(stream, "\t\t sgnd=%d\n", comp.sgnd);
+ fprintf(stream, "\t}\n");
+ }
+ fprintf(stream, "}\n");
+ }
+
+ /* CODESTREAM INFO */
+ if ( file_info->file_info_flag & OPJ_J2K_INFO ) {
+ opj_codestream_info_v2_t cstr_info = file_info->codestream_info;
+ int tileno, compno, layno, bandno, resno, numbands;
+
+ fprintf(stream, "Codestream info {\n");
+ fprintf(stream, "\t tx0=%d, ty0=%d\n", cstr_info.tx0, cstr_info.ty0);
+ fprintf(stream, "\t tdx=%d, tdy=%d\n", cstr_info.tdx, cstr_info.tdy);
+ fprintf(stream, "\t tw=%d, th=%d\n", cstr_info.tw, cstr_info.th);
+
+ for (tileno = 0; tileno < cstr_info.tw * cstr_info.th; tileno++) {
+ opj_tile_info_v2_t tile_info = cstr_info.tile[tileno];
+
+ fprintf(stream, "\t tile %d {\n", tileno);
+ fprintf(stream, "\t\t csty=%x\n", tile_info.csty);
+ fprintf(stream, "\t\t prg=%d\n", tile_info.prg);
+ fprintf(stream, "\t\t numlayers=%d\n", tile_info.numlayers);
+ fprintf(stream, "\t\t mct=%d\n", tile_info.mct);
+ fprintf(stream, "\t\t rates=");
+
+ for (layno = 0; layno < tile_info.numlayers; layno++) {
+ fprintf(stream, "%.1f ", tile_info.rates[layno]);
+ }
+ fprintf(stream, "\n");
+
+ for (compno = 0; compno < cstr_info.numcomps; compno++) {
+ opj_tccp_info_t tccp_info = tile_info.tccp_info[compno];
+
+ fprintf(stream, "\t\t comp %d {\n", compno);
+ fprintf(stream, "\t\t\t csty=%x\n", tccp_info.csty);
+ fprintf(stream, "\t\t\t numresolutions=%d\n", tccp_info.numresolutions);
+ fprintf(stream, "\t\t\t cblkw=%d\n", tccp_info.cblkw);
+ fprintf(stream, "\t\t\t cblkh=%d\n", tccp_info.cblkh);
+ fprintf(stream, "\t\t\t cblksty=%x\n", tccp_info.cblksty);
+ fprintf(stream, "\t\t\t qmfbid=%d\n", tccp_info.qmfbid);
+ fprintf(stream, "\t\t\t qntsty=%d\n", tccp_info.qntsty);
+ fprintf(stream, "\t\t\t numgbits=%d\n", tccp_info.numgbits);
+ fprintf(stream, "\t\t\t roishift=%d\n", tccp_info.roishift);
+
+#ifdef TODO_MSD
+ fprintf(stream, "\t\t\t stepsizes=");
+ numbands = tccp_info->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp_info->numresolutions * 3 - 2;
+ for (bandno = 0; bandno < numbands; bandno++) {
+ fprintf(stream, "(%d,%d) ", tccp_info->stepsizes[bandno].mant,
+ tccp_info->stepsizes[bandno].expn);
+ }
+ fprintf(stream, "\n");
+
+ if (tccp_info->csty & J2K_CCP_CSTY_PRT) {
+ fprintf(stream, " prcw=");
+ for (resno = 0; resno < tccp_info->numresolutions; resno++) {
+ fprintf(stream, "%d ", tccp_info->prcw[resno]);
+ }
+ fprintf(stream, "\n");
+
+ fprintf(stream, " prch=");
+ for (resno = 0; resno < tccp_info->numresolutions; resno++) {
+ fprintf(stream, "%d ", tccp_info->prch[resno]);
+ }
+ fprintf(stream, "\n");
+ }
+#endif
+ fprintf(stream, "\t\t\t }\n");
+ } /*end of component*/
+ fprintf(stream, "\t\t }\n");
+ } /*end of tile */
+ fprintf(stream, "\t }\n");
+ }
+
+ if ( file_info->file_info_flag & OPJ_JP2_INFO ) {
+ // not yet coded
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/applications/codec/index.h b/applications/codec/index.h
index 29f673a1..aefce665 100644
--- a/applications/codec/index.h
+++ b/applications/codec/index.h
@@ -41,6 +41,8 @@ Write a structured index to a file
*/
int write_index_file(opj_codestream_info_t *cstr_info, char *index);
+int dump_file_info(FILE* stream, opj_file_info_t *file_info);
+
#ifdef __cplusplus
}
#endif
diff --git a/applications/codec/j2k_dump.c b/applications/codec/j2k_dump.c
index 7f584400..d1c1fb69 100644
--- a/applications/codec/j2k_dump.c
+++ b/applications/codec/j2k_dump.c
@@ -201,7 +201,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
};
- const char optlist[] = "i:o:h";
+ const char optlist[] = "i:o:d:h";
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
@@ -257,7 +257,19 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
break;
/* ----------------------------------------------------- */
+ case 'd': /* Input decode ROI */
+ {
+ int size_optarg = (int)strlen(optarg) + 1;
+ char *ROI_values = (char*) malloc(size_optarg);
+ ROI_values[0] = '\0';
+ strncpy(ROI_values, optarg, strlen(optarg));
+ ROI_values[strlen(optarg)] = '\0';
+ printf("ROI_values = %s [%d / %d]\n", ROI_values, strlen(ROI_values), size_optarg );
+ parse_ROI_values( ROI_values, &parameters->ROI_x0, &parameters->ROI_y0, &parameters->ROI_x1, &parameters->ROI_y1);
+ }
+ break;
+ /* ----------------------------------------------------- */
default:
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
break;
@@ -290,6 +302,34 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
return 0;
}
+/*******************************************************************************
+ * Parse ROI input values
+ * separator = ","
+ *******************************************************************************/
+int parse_ROI_values( char* inArg, unsigned int *ROI_x0, unsigned int *ROI_y0, unsigned int *ROI_x1, unsigned int *ROI_y1)
+{
+ int it = 0;
+ int values[4];
+ char delims[] = ",";
+ char *result = NULL;
+ result = strtok( inArg, delims );
+
+ while( (result != NULL) && (it < 4 ) ) {
+ values[it] = atoi(result);
+ result = strtok( NULL, delims );
+ it++;
+ }
+
+ if (it != 4) {
+ return EXIT_FAILURE;
+ }
+ else{
+ *ROI_x0 = values[0]; *ROI_y0 = values[1];
+ *ROI_x1 = values[2]; *ROI_y1 = values[3];
+ return EXIT_SUCCESS;
+ }
+}
+
/* -------------------------------------------------------------------------- */
/**
@@ -323,6 +363,7 @@ int main(int argc, char *argv[])
img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */
opj_image_header_t* image = NULL;
+ opj_file_info_t file_info;
FILE *fsrc = NULL, *fout = NULL;
int num_images;
int i,imageno;
@@ -394,7 +435,7 @@ int main(int argc, char *argv[])
/* Read the header of each image one by one */
for(imageno = 0; imageno < num_images ; imageno++){
- image = NULL;
+
fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){
@@ -404,7 +445,6 @@ int main(int argc, char *argv[])
}
}
- /*NEW V2 STYLE*/
/* read the input file and put it in memory */
/* ---------------------------------------- */
fsrc = fopen(parameters.infile, "rb");
@@ -414,6 +454,10 @@ int main(int argc, char *argv[])
}
cio = opj_stream_create_default_file_stream(fsrc,1);
+ if (!cio){
+ fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
+ return EXIT_FAILURE;
+ }
/* decode the code-stream */
/* ---------------------- */
@@ -449,7 +493,7 @@ int main(int argc, char *argv[])
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder_v2(dinfo, &parameters, &event_mgr);
- if(! opj_read_header(cio, dinfo, &image, &cstr_info)){
+ if(! opj_read_header(cio, dinfo, &file_info, OPJ_IMG_INFO | OPJ_J2K_INFO)){
fprintf(stderr, "ERROR -> j2k_dump: failed to read the header\n");
opj_stream_destroy(cio);
fclose(fsrc);
@@ -457,8 +501,14 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- /* Dump file informations from header */
+ printf("Setting decoding area to %d,%d,%d,%d\n",
+ parameters.ROI_x0, parameters.ROI_y0, parameters.ROI_x1, parameters.ROI_x1);
+ opj_set_decode_area(dinfo,
+ parameters.ROI_x0, parameters.ROI_y0,
+ parameters.ROI_x1, parameters.ROI_x1);
+ /* Dump file informations from header */
+ dump_file_info(fout, &file_info);
/* close the byte stream */
opj_stream_destroy(cio);
@@ -471,9 +521,10 @@ int main(int argc, char *argv[])
opj_image_header_destroy(image);
+ //FIXME opj_file_info_destroy(file_info);
}
-/*NEW V2 STYLE*/
+
/* Close the output file */
fclose(fout);
@@ -496,8 +547,8 @@ static void j2k_dump_image(FILE *fd, opj_image_header_t * img) {
fprintf(fd, " sgnd=%d\n", comp->sgnd);
fprintf(fd, " }\n");
}
- fprintf(fd, " XTOsiz=%d, YTOsiz=%d, XTsiz=%d, YTsiz=%d\n", img->tile_x0, img->tile_y0, img->tile_width, img->tile_height);
- fprintf(fd, " Nb of tiles in x direction=%d, Nb of tiles in y direction=%d\n", img->nb_tiles_x, img->nb_tiles_y);
+ //fprintf(fd, " XTOsiz=%d, YTOsiz=%d, XTsiz=%d, YTsiz=%d\n", img->tile_x0, img->tile_y0, img->tile_width, img->tile_height);
+ //fprintf(fd, " Nb of tiles in x direction=%d, Nb of tiles in y direction=%d\n", img->nb_tiles_x, img->nb_tiles_y);
fprintf(fd, "}\n");
}