solve some obvious warnings for WIN platform, increase number of warning reported...
[openjpeg.git] / applications / codec / j2k_dump.c
1 /*
2  * Copyright (c) 20010, Mathieu Malaterre, GDCM
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #include <math.h>
31
32 #ifdef _WIN32
33 #include "windirent.h"
34 #else
35 #include <dirent.h>
36 #endif /* _WIN32 */
37
38 #ifdef _WIN32
39 #include <windows.h>
40 #else
41 #include <strings.h>
42 #define _stricmp strcasecmp
43 #define _strnicmp strncasecmp
44 #endif /* _WIN32 */
45
46 #include "opj_config.h"
47 #include "openjpeg.h"
48 #include "j2k.h"
49 #include "jp2.h"
50 #include "getopt.h"
51 #include "convert.h"
52 #include "index.h"
53
54 #include "format_defs.h"
55
56 typedef struct dircnt{
57         /** Buffer for holding images read from Directory*/
58         char *filename_buf;
59         /** Pointer to the buffer*/
60         char **filename;
61 }dircnt_t;
62
63
64 typedef struct img_folder{
65         /** The directory path of the folder containing input images*/
66         char *imgdirpath;
67         /** Output format*/
68         const char *out_format;
69         /** Enable option*/
70         char set_imgdir;
71         /** Enable Cod Format for output*/
72         char set_out_format;
73
74 }img_fol_t;
75
76 void decode_help_display(void) {
77         fprintf(stdout,"HELP for j2k_dump\n----\n\n");
78         fprintf(stdout,"- the -h option displays this help information on screen\n\n");
79
80 /* UniPG>> */
81         fprintf(stdout,"List of parameters for the JPEG 2000 "
82 #ifdef USE_JPWL
83                 "+ JPWL "
84 #endif /* USE_JPWL */
85                 "decoder:\n");
86 /* <<UniPG */
87         fprintf(stdout,"\n");
88         fprintf(stdout,"\n");
89         fprintf(stdout,"  -ImgDir \n");
90         fprintf(stdout,"        Image file Directory path \n");
91         fprintf(stdout,"  -i <compressed file>\n");
92         fprintf(stdout,"    REQUIRED only if an Input image directory not specified\n");
93         fprintf(stdout,"    Currently accepts J2K-files, JP2-files and JPT-files. The file type\n");
94         fprintf(stdout,"    is identified based on its suffix.\n");
95         fprintf(stdout,"  -o <output file>\n");
96   fprintf(stdout,"    OPTIONAL\n");
97   fprintf(stdout,"    Output file where file info will be dump.\n");
98   fprintf(stdout,"    By default it will be in the stdout.\n");
99         fprintf(stdout,"\n");
100 }
101
102 /* -------------------------------------------------------------------------- */
103 static void j2k_dump_image(FILE *fd, opj_image_t * img);
104 static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp);
105
106 int get_num_images(char *imgdirpath){
107         DIR *dir;
108         struct dirent* content; 
109         int num_images = 0;
110
111         /*Reading the input images from given input directory*/
112
113         dir= opendir(imgdirpath);
114         if(!dir){
115                 fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
116                 return 0;
117         }
118         
119         while((content=readdir(dir))!=NULL){
120                 if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
121                         continue;
122                 num_images++;
123         }
124         return num_images;
125 }
126
127 int load_images(dircnt_t *dirptr, char *imgdirpath){
128         DIR *dir;
129         struct dirent* content; 
130         int i = 0;
131
132         /*Reading the input images from given input directory*/
133
134         dir= opendir(imgdirpath);
135         if(!dir){
136                 fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
137                 return 1;
138         }else   {
139                 fprintf(stderr,"Folder opened successfully\n");
140         }
141         
142         while((content=readdir(dir))!=NULL){
143                 if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
144                         continue;
145
146                 strcpy(dirptr->filename[i],content->d_name);
147                 i++;
148         }
149         return 0;       
150 }
151
152 int get_file_format(char *filename) {
153         unsigned int i;
154         static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc"  };
155         static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
156         char * ext = strrchr(filename, '.');
157         if (ext == NULL)
158                 return -1;
159         ext++;
160         if(ext) {
161                 for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
162                         if(_strnicmp(ext, extension[i], 3) == 0) {
163                                 return format[i];
164                         }
165                 }
166         }
167
168         return -1;
169 }
170
171 char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
172         char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
173         char *temp_p, temp1[OPJ_PATH_LEN]="";
174
175         strcpy(image_filename,dirptr->filename[imageno]);
176         fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename);
177         parameters->decod_format = get_file_format(image_filename);
178         if (parameters->decod_format == -1)
179                 return 1;
180         sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
181         strncpy(parameters->infile, infilename, sizeof(infilename));
182
183         //Set output file
184         strcpy(temp_ofname,strtok(image_filename,"."));
185         while((temp_p = strtok(NULL,".")) != NULL){
186                 strcat(temp_ofname,temp1);
187                 sprintf(temp1,".%s",temp_p);
188         }
189         if(img_fol->set_out_format==1){
190                 sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
191                 strncpy(parameters->outfile, outfilename, sizeof(outfilename));
192         }
193         return 0;
194 }
195
196 /* -------------------------------------------------------------------------- */
197 int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
198         /* parse the command line */
199         int totlen, c;
200         option_t long_option[]={
201                 {"ImgDir",REQ_ARG, NULL ,'y'},
202         };
203
204         const char optlist[] = "i:o:h";
205         totlen=sizeof(long_option);
206         img_fol->set_out_format = 0;
207         do {
208                 c = getopt_long(argc, argv,optlist,long_option,totlen);
209                 if (c == -1)
210                         break;
211                 switch (c) {
212                         case 'i':                       /* input file */
213                         {
214                                 char *infile = optarg;
215                                 parameters->decod_format = get_file_format(infile);
216                                 switch(parameters->decod_format) {
217                                         case J2K_CFMT:
218                                         case JP2_CFMT:
219                                         case JPT_CFMT:
220                                                 break;
221                                         default:
222                                                 fprintf(stderr, 
223                                                         "!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n", 
224                                                         infile);
225                                                 return 1;
226                                 }
227                                 strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
228                         }
229                         break;
230
231                         /* ------------------------------------------------------ */
232
233                         case 'o':     /* output file */
234                         {
235                           char *outfile = optarg;
236                           strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
237                         }
238                         break;
239                                 
240                                 /* ----------------------------------------------------- */
241
242                         case 'h':                       /* display an help description */
243                                 decode_help_display();
244                                 return 1;                               
245
246                                 /* ------------------------------------------------------ */
247
248                         case 'y':                       /* Image Directory path */
249                                 {
250                                         img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
251                                         strcpy(img_fol->imgdirpath,optarg);
252                                         img_fol->set_imgdir=1;
253                                 }
254                                 break;
255
256                                 /* ----------------------------------------------------- */
257                         
258                         default:
259                                 fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);
260                                 break;
261                 }
262         }while(c != -1);
263
264         /* check for possible errors */
265         if(img_fol->set_imgdir==1){
266                 if(!(parameters->infile[0]==0)){
267                         fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
268                         return 1;
269                 }
270                 if(img_fol->set_out_format == 0){
271                         fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
272                         fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n");
273                         return 1;
274                 }
275                 if(!((parameters->outfile[0] == 0))){
276                         fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
277                         return 1;
278                 }
279         }else{
280                 if((parameters->infile[0] == 0) ) {
281                         fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]);
282                         fprintf(stderr, "    Try: %s -h\n",argv[0]);
283                         return 1;
284                 }
285         }
286
287         return 0;
288 }
289
290 /* -------------------------------------------------------------------------- */
291
292 /**
293 sample error callback expecting a FILE* client object
294 */
295 void error_callback(const char *msg, void *client_data) {
296         FILE *stream = (FILE*)client_data;
297         fprintf(stream, "[ERROR] %s", msg);
298 }
299 /**
300 sample warning callback expecting a FILE* client object
301 */
302 void warning_callback(const char *msg, void *client_data) {
303         FILE *stream = (FILE*)client_data;
304         fprintf(stream, "[WARNING] %s", msg);
305 }
306 /**
307 sample debug callback expecting no client object
308 */
309 void info_callback(const char *msg, void *client_data) {
310         (void)client_data;
311         fprintf(stdout, "[INFO] %s", msg);
312 }
313
314 /* -------------------------------------------------------------------------- */
315
316 int main(int argc, char *argv[])
317 {
318         opj_dparameters_t parameters;   /* decompression parameters */
319         img_fol_t img_fol;
320         opj_event_mgr_t event_mgr;              /* event manager */
321         opj_image_t *image = NULL;
322         FILE *fsrc = NULL, *fout = NULL;
323         unsigned char *src = NULL;
324         int file_length;
325         int num_images;
326         int i,imageno;
327         dircnt_t *dirptr = NULL;
328         opj_dinfo_t* dinfo = NULL;      /* handle to a decompressor */
329         opj_cio_t *cio = NULL;
330         opj_codestream_info_t cstr_info;  /* Codestream information structure */
331         char indexfilename[OPJ_PATH_LEN];       /* index file name */
332
333         /* configure the event callbacks (not required) */
334         memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
335         event_mgr.error_handler = error_callback;
336         event_mgr.warning_handler = warning_callback;
337         event_mgr.info_handler = info_callback;
338
339         /* set decoding parameters to default values */
340         opj_set_default_decoder_parameters(&parameters);
341
342         /* Initialize indexfilename and img_fol */
343         *indexfilename = 0;
344         memset(&img_fol,0,sizeof(img_fol_t));
345
346         /* parse input and get user encoding parameters */
347         if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol, indexfilename) == 1) {
348                 return 1;
349         }
350
351         /* Initialize reading of directory */
352         if(img_fol.set_imgdir==1){      
353                 num_images=get_num_images(img_fol.imgdirpath);
354
355                 dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
356                 if(dirptr){
357                         dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char));     // Stores at max 10 image file names
358                         dirptr->filename = (char**) malloc(num_images*sizeof(char*));
359
360                         if(!dirptr->filename_buf){
361                                 return 1;
362                         }
363                         for(i=0;i<num_images;i++){
364                                 dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
365                         }
366                 }
367                 if(load_images(dirptr,img_fol.imgdirpath)==1){
368                         return 1;
369                 }
370                 if (num_images==0){
371                         fprintf(stdout,"Folder is empty\n");
372                         return 1;
373                 }
374         }else{
375                 num_images=1;
376         }
377
378         //
379         if (parameters.outfile[0] != 0)
380           {
381           fout = fopen(parameters.outfile,"w");
382     if (!fout)
383       {
384       fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.outfile);
385       return 1;
386       }
387           }
388         else
389           fout = stdout;
390
391         /*Encoding image one by one*/
392         for(imageno = 0; imageno < num_images ; imageno++)
393   {
394                 image = NULL;
395                 fprintf(stderr,"\n");
396
397                 if(img_fol.set_imgdir==1){
398                         if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
399                                 fprintf(stderr,"skipping file...\n");
400                                 continue;
401                         }
402                 }
403
404                 /* read the input file and put it in memory */
405                 /* ---------------------------------------- */
406                 fsrc = fopen(parameters.infile, "rb");
407                 if (!fsrc) {
408                         fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
409                         return 1;
410                 }
411                 fseek(fsrc, 0, SEEK_END);
412                 file_length = ftell(fsrc);
413                 fseek(fsrc, 0, SEEK_SET);
414                 src = (unsigned char *) malloc(file_length);
415                 if (fread(src, 1, file_length, fsrc) != (size_t)file_length)
416                 {
417                         free(src);
418                         fclose(fsrc);
419                         fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
420                         return 1;
421                 }
422                 fclose(fsrc);
423
424                 /* decode the code-stream */
425                 /* ---------------------- */
426
427                 switch(parameters.decod_format) {
428                 case J2K_CFMT:
429                 {
430                         /* JPEG-2000 codestream */
431
432                         /* get a decoder handle */
433                         dinfo = opj_create_decompress(CODEC_J2K);
434
435                         /* catch events using our callbacks and give a local context */
436                         opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
437
438                         /* setup the decoder decoding parameters using user parameters */
439                         opj_setup_decoder(dinfo, &parameters);
440
441                         /* open a byte stream */
442                         cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
443
444                         /* decode the stream and fill the image structure */
445                         if (*indexfilename)                             // If need to extract codestream information
446                                 image = opj_decode_with_info(dinfo, cio, &cstr_info);
447                         else
448                                 image = opj_decode(dinfo, cio);
449                         if(!image) {
450                                 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
451                                 opj_destroy_decompress(dinfo);
452                                 opj_cio_close(cio);
453                                 return 1;
454                         }
455                         /* dump image */
456       j2k_dump_image(fout, image);
457
458                         /* dump cp */
459       j2k_dump_cp(fout, image, ((opj_j2k_t*)dinfo->j2k_handle)->cp);
460
461                         /* close the byte stream */
462                         opj_cio_close(cio);
463
464                         /* Write the index to disk */
465                         if (*indexfilename) {
466                                 opj_bool bSuccess;
467                                 bSuccess = write_index_file(&cstr_info, indexfilename);
468                                 if (bSuccess) {
469                                         fprintf(stderr, "Failed to output index file\n");
470                                 }
471                         }
472                 }
473                 break;
474
475                 case JP2_CFMT:
476                 {
477                         /* JPEG 2000 compressed image data */
478
479                         /* get a decoder handle */
480                         dinfo = opj_create_decompress(CODEC_JP2);
481
482                         /* catch events using our callbacks and give a local context */
483                         opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
484
485                         /* setup the decoder decoding parameters using the current image and user parameters */
486                         opj_setup_decoder(dinfo, &parameters);
487
488                         /* open a byte stream */
489                         cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
490
491                         /* decode the stream and fill the image structure */
492                         if (*indexfilename)                             // If need to extract codestream information
493                                 image = opj_decode_with_info(dinfo, cio, &cstr_info);
494                         else
495                                 image = opj_decode(dinfo, cio);                 
496                         if(!image) {
497                                 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
498                                 opj_destroy_decompress(dinfo);
499                                 opj_cio_close(cio);
500                                 return 1;
501                         }
502                         /* dump image */
503           if(image->icc_profile_buf)
504          {
505           free(image->icc_profile_buf); image->icc_profile_buf = NULL;
506          }      
507       j2k_dump_image(fout, image);
508
509                         /* dump cp */
510       j2k_dump_cp(fout, image, ((opj_jp2_t*)dinfo->jp2_handle)->j2k->cp);
511
512                         /* close the byte stream */
513                         opj_cio_close(cio);
514
515                         /* Write the index to disk */
516                         if (*indexfilename) {
517                                 opj_bool bSuccess;
518                                 bSuccess = write_index_file(&cstr_info, indexfilename);
519                                 if (bSuccess) {
520                                         fprintf(stderr, "Failed to output index file\n");
521                                 }
522                         }
523                 }
524                 break;
525
526                 case JPT_CFMT:
527                 {
528                         /* JPEG 2000, JPIP */
529
530                         /* get a decoder handle */
531                         dinfo = opj_create_decompress(CODEC_JPT);
532
533                         /* catch events using our callbacks and give a local context */
534                         opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
535
536                         /* setup the decoder decoding parameters using user parameters */
537                         opj_setup_decoder(dinfo, &parameters);
538
539                         /* open a byte stream */
540                         cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
541
542                         /* decode the stream and fill the image structure */
543                         if (*indexfilename)                             // If need to extract codestream information
544                                 image = opj_decode_with_info(dinfo, cio, &cstr_info);
545                         else
546                                 image = opj_decode(dinfo, cio);
547                         if(!image) {
548                                 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
549                                 opj_destroy_decompress(dinfo);
550                                 opj_cio_close(cio);
551                                 return 1;
552                         }
553
554                         /* close the byte stream */
555                         opj_cio_close(cio);
556
557                         /* Write the index to disk */
558                         if (*indexfilename) {
559                                 opj_bool bSuccess;
560                                 bSuccess = write_index_file(&cstr_info, indexfilename);
561                                 if (bSuccess) {
562                                         fprintf(stderr, "Failed to output index file\n");
563                                 }
564                         }
565                 }
566                 break;
567
568                 default:
569                         fprintf(stderr, "skipping file..\n");
570                         continue;
571         }
572
573                 /* free the memory containing the code-stream */
574                 free(src);
575                 src = NULL;
576
577                 /* free remaining structures */
578                 if(dinfo) {
579                         opj_destroy_decompress(dinfo);
580                 }
581                 /* free codestream information structure */
582                 if (*indexfilename)     
583                         opj_destroy_cstr_info(&cstr_info);
584                 /* free image data structure */
585                 opj_image_destroy(image);
586
587         }
588
589         fclose(fout);
590
591   return EXIT_SUCCESS;
592 }
593
594
595 static void j2k_dump_image(FILE *fd, opj_image_t * img) {
596         int compno;
597         fprintf(fd, "image {\n");
598         fprintf(fd, "  x0=%d, y0=%d, x1=%d, y1=%d\n", img->x0, img->y0, img->x1, img->y1);
599         fprintf(fd, "  numcomps=%d\n", img->numcomps);
600         for (compno = 0; compno < img->numcomps; compno++) {
601                 opj_image_comp_t *comp = &img->comps[compno];
602                 fprintf(fd, "  comp %d {\n", compno);
603                 fprintf(fd, "    dx=%d, dy=%d\n", comp->dx, comp->dy);
604                 fprintf(fd, "    prec=%d\n", comp->prec);
605                 //fprintf(fd, "    bpp=%d\n", comp->bpp);
606                 fprintf(fd, "    sgnd=%d\n", comp->sgnd);
607                 fprintf(fd, "  }\n");
608         }
609         fprintf(fd, "}\n");
610 }
611
612 static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp) {
613         int tileno, compno, layno, bandno, resno, numbands;
614         fprintf(fd, "coding parameters {\n");
615         fprintf(fd, "  tx0=%d, ty0=%d\n", cp->tx0, cp->ty0);
616         fprintf(fd, "  tdx=%d, tdy=%d\n", cp->tdx, cp->tdy);
617         fprintf(fd, "  tw=%d, th=%d\n", cp->tw, cp->th);
618         for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
619                 opj_tcp_t *tcp = &cp->tcps[tileno];
620                 fprintf(fd, "  tile %d {\n", tileno);
621                 fprintf(fd, "    csty=%x\n", tcp->csty);
622                 fprintf(fd, "    prg=%d\n", tcp->prg);
623                 fprintf(fd, "    numlayers=%d\n", tcp->numlayers);
624                 fprintf(fd, "    mct=%d\n", tcp->mct);
625                 fprintf(fd, "    rates=");
626                 for (layno = 0; layno < tcp->numlayers; layno++) {
627                         fprintf(fd, "%.1f ", tcp->rates[layno]);
628                 }
629                 fprintf(fd, "\n");
630                 for (compno = 0; compno < img->numcomps; compno++) {
631                         opj_tccp_t *tccp = &tcp->tccps[compno];
632                         fprintf(fd, "    comp %d {\n", compno);
633                         fprintf(fd, "      csty=%x\n", tccp->csty);
634                         fprintf(fd, "      numresolutions=%d\n", tccp->numresolutions);
635                         fprintf(fd, "      cblkw=%d\n", tccp->cblkw);
636                         fprintf(fd, "      cblkh=%d\n", tccp->cblkh);
637                         fprintf(fd, "      cblksty=%x\n", tccp->cblksty);
638                         fprintf(fd, "      qmfbid=%d\n", tccp->qmfbid);
639                         fprintf(fd, "      qntsty=%d\n", tccp->qntsty);
640                         fprintf(fd, "      numgbits=%d\n", tccp->numgbits);
641                         fprintf(fd, "      roishift=%d\n", tccp->roishift);
642                         fprintf(fd, "      stepsizes=");
643                         numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2;
644                         for (bandno = 0; bandno < numbands; bandno++) {
645                                 fprintf(fd, "(%d,%d) ", tccp->stepsizes[bandno].mant,
646                                         tccp->stepsizes[bandno].expn);
647                         }
648                         fprintf(fd, "\n");
649                         
650                         if (tccp->csty & J2K_CCP_CSTY_PRT) {
651                                 fprintf(fd, "      prcw=");
652                                 for (resno = 0; resno < tccp->numresolutions; resno++) {
653                                         fprintf(fd, "%d ", tccp->prcw[resno]);
654                                 }
655                                 fprintf(fd, "\n");
656                                 fprintf(fd, "      prch=");
657                                 for (resno = 0; resno < tccp->numresolutions; resno++) {
658                                         fprintf(fd, "%d ", tccp->prch[resno]);
659                                 }
660                                 fprintf(fd, "\n");
661                         }
662                         fprintf(fd, "    }\n");
663                 }
664                 fprintf(fd, "  }\n");
665         }
666         fprintf(fd, "}\n");
667 }
668