bug fixes to enable cmake compilation on WIN32 platform (see CHANGES for details)
[openjpeg.git] / 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 "../libopenjpeg/j2k.h"
49 #include "../libopenjpeg/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() {
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,"\n");
96 }
97
98 /* -------------------------------------------------------------------------- */
99 static void j2k_dump_image(FILE *fd, opj_image_t * img);
100 static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp);
101
102 int get_num_images(char *imgdirpath){
103         DIR *dir;
104         struct dirent* content; 
105         int num_images = 0;
106
107         /*Reading the input images from given input directory*/
108
109         dir= opendir(imgdirpath);
110         if(!dir){
111                 fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
112                 return 0;
113         }
114         
115         while((content=readdir(dir))!=NULL){
116                 if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
117                         continue;
118                 num_images++;
119         }
120         return num_images;
121 }
122
123 int load_images(dircnt_t *dirptr, char *imgdirpath){
124         DIR *dir;
125         struct dirent* content; 
126         int i = 0;
127
128         /*Reading the input images from given input directory*/
129
130         dir= opendir(imgdirpath);
131         if(!dir){
132                 fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
133                 return 1;
134         }else   {
135                 fprintf(stderr,"Folder opened successfully\n");
136         }
137         
138         while((content=readdir(dir))!=NULL){
139                 if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
140                         continue;
141
142                 strcpy(dirptr->filename[i],content->d_name);
143                 i++;
144         }
145         return 0;       
146 }
147
148 int get_file_format(char *filename) {
149         unsigned int i;
150         static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc"  };
151         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 };
152         char * ext = strrchr(filename, '.');
153         if (ext == NULL)
154                 return -1;
155         ext++;
156         if(ext) {
157                 for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
158                         if(_strnicmp(ext, extension[i], 3) == 0) {
159                                 return format[i];
160                         }
161                 }
162         }
163
164         return -1;
165 }
166
167 char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
168         char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
169         char *temp_p, temp1[OPJ_PATH_LEN]="";
170
171         strcpy(image_filename,dirptr->filename[imageno]);
172         fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename);
173         parameters->decod_format = get_file_format(image_filename);
174         if (parameters->decod_format == -1)
175                 return 1;
176         sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
177         strncpy(parameters->infile, infilename, sizeof(infilename));
178
179         //Set output file
180         strcpy(temp_ofname,strtok(image_filename,"."));
181         while((temp_p = strtok(NULL,".")) != NULL){
182                 strcat(temp_ofname,temp1);
183                 sprintf(temp1,".%s",temp_p);
184         }
185         if(img_fol->set_out_format==1){
186                 sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
187                 strncpy(parameters->outfile, outfilename, sizeof(outfilename));
188         }
189         return 0;
190 }
191
192 /* -------------------------------------------------------------------------- */
193 int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
194         /* parse the command line */
195         int totlen;
196         option_t long_option[]={
197                 {"ImgDir",REQ_ARG, NULL ,'y'},
198         };
199
200         const char optlist[] = "i:h";
201         totlen=sizeof(long_option);
202         img_fol->set_out_format = 0;
203         while (1) {
204                 int c = getopt_long(argc, argv,optlist,long_option,totlen);
205                 if (c == -1)
206                         break;
207                 switch (c) {
208                         case 'i':                       /* input file */
209                         {
210                                 char *infile = optarg;
211                                 parameters->decod_format = get_file_format(infile);
212                                 switch(parameters->decod_format) {
213                                         case J2K_CFMT:
214                                         case JP2_CFMT:
215                                         case JPT_CFMT:
216                                                 break;
217                                         default:
218                                                 fprintf(stderr, 
219                                                         "!! Unrecognized format for infile : %s [accept only *.j2k, *.jp2, *.jpc or *.jpt] !!\n\n", 
220                                                         infile);
221                                                 return 1;
222                                 }
223                                 strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
224                         }
225                         break;
226                                 
227                                 /* ----------------------------------------------------- */
228
229                         case 'h':                       /* display an help description */
230                                 decode_help_display();
231                                 return 1;                               
232
233                                 /* ------------------------------------------------------ */
234
235                         case 'y':                       /* Image Directory path */
236                                 {
237                                         img_fol->imgdirpath = (char*)malloc(strlen(optarg) + 1);
238                                         strcpy(img_fol->imgdirpath,optarg);
239                                         img_fol->set_imgdir=1;
240                                 }
241                                 break;
242
243                                 /* ----------------------------------------------------- */
244                         
245                         default:
246                                 fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, optarg);
247                                 break;
248                 }
249         }
250
251         /* check for possible errors */
252         if(img_fol->set_imgdir==1){
253                 if(!(parameters->infile[0]==0)){
254                         fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
255                         return 1;
256                 }
257                 if(img_fol->set_out_format == 0){
258                         fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
259                         fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n");
260                         return 1;
261                 }
262                 if(!((parameters->outfile[0] == 0))){
263                         fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
264                         return 1;
265                 }
266         }else{
267                 if((parameters->infile[0] == 0) ) {
268                         fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]);
269                         fprintf(stderr, "    Try: %s -h\n",argv[0]);
270                         return 1;
271                 }
272         }
273
274         return 0;
275 }
276
277 /* -------------------------------------------------------------------------- */
278
279 /**
280 sample error callback expecting a FILE* client object
281 */
282 void error_callback(const char *msg, void *client_data) {
283         FILE *stream = (FILE*)client_data;
284         fprintf(stream, "[ERROR] %s", msg);
285 }
286 /**
287 sample warning callback expecting a FILE* client object
288 */
289 void warning_callback(const char *msg, void *client_data) {
290         FILE *stream = (FILE*)client_data;
291         fprintf(stream, "[WARNING] %s", msg);
292 }
293 /**
294 sample debug callback expecting no client object
295 */
296 void info_callback(const char *msg, void *client_data) {
297         (void)client_data;
298         fprintf(stdout, "[INFO] %s", msg);
299 }
300
301 /* -------------------------------------------------------------------------- */
302
303 int main(int argc, char *argv[])
304 {
305         opj_dparameters_t parameters;   /* decompression parameters */
306         img_fol_t img_fol;
307         opj_event_mgr_t event_mgr;              /* event manager */
308         opj_image_t *image = NULL;
309         FILE *fsrc = NULL;
310         unsigned char *src = NULL;
311         int file_length;
312         int num_images;
313         int i,imageno;
314         dircnt_t *dirptr = NULL;
315         opj_dinfo_t* dinfo = NULL;      /* handle to a decompressor */
316         opj_cio_t *cio = NULL;
317         opj_codestream_info_t cstr_info;  /* Codestream information structure */
318         char indexfilename[OPJ_PATH_LEN];       /* index file name */
319
320         /* configure the event callbacks (not required) */
321         memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
322         event_mgr.error_handler = error_callback;
323         event_mgr.warning_handler = warning_callback;
324         event_mgr.info_handler = info_callback;
325
326         /* set decoding parameters to default values */
327         opj_set_default_decoder_parameters(&parameters);
328
329         /* Initialize indexfilename and img_fol */
330         *indexfilename = 0;
331         memset(&img_fol,0,sizeof(img_fol_t));
332
333         /* parse input and get user encoding parameters */
334         if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol, indexfilename) == 1) {
335                 return 1;
336         }
337
338         /* Initialize reading of directory */
339         if(img_fol.set_imgdir==1){      
340                 num_images=get_num_images(img_fol.imgdirpath);
341
342                 dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
343                 if(dirptr){
344                         dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char));     // Stores at max 10 image file names
345                         dirptr->filename = (char**) malloc(num_images*sizeof(char*));
346
347                         if(!dirptr->filename_buf){
348                                 return 1;
349                         }
350                         for(i=0;i<num_images;i++){
351                                 dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
352                         }
353                 }
354                 if(load_images(dirptr,img_fol.imgdirpath)==1){
355                         return 1;
356                 }
357                 if (num_images==0){
358                         fprintf(stdout,"Folder is empty\n");
359                         return 1;
360                 }
361         }else{
362                 num_images=1;
363         }
364
365         /*Encoding image one by one*/
366         for(imageno = 0; imageno < num_images ; imageno++)
367   {
368                 image = NULL;
369                 fprintf(stderr,"\n");
370
371                 if(img_fol.set_imgdir==1){
372                         if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
373                                 fprintf(stderr,"skipping file...\n");
374                                 continue;
375                         }
376                 }
377
378                 /* read the input file and put it in memory */
379                 /* ---------------------------------------- */
380                 fsrc = fopen(parameters.infile, "rb");
381                 if (!fsrc) {
382                         fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
383                         return 1;
384                 }
385                 fseek(fsrc, 0, SEEK_END);
386                 file_length = ftell(fsrc);
387                 fseek(fsrc, 0, SEEK_SET);
388                 src = (unsigned char *) malloc(file_length);
389                 fread(src, 1, file_length, fsrc);
390                 fclose(fsrc);
391
392                 /* decode the code-stream */
393                 /* ---------------------- */
394
395                 switch(parameters.decod_format) {
396                 case J2K_CFMT:
397                 {
398                         /* JPEG-2000 codestream */
399
400                         /* get a decoder handle */
401                         dinfo = opj_create_decompress(CODEC_J2K);
402
403                         /* catch events using our callbacks and give a local context */
404                         opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
405
406                         /* setup the decoder decoding parameters using user parameters */
407                         opj_setup_decoder(dinfo, &parameters);
408
409                         /* open a byte stream */
410                         cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
411
412                         /* decode the stream and fill the image structure */
413                         if (*indexfilename)                             // If need to extract codestream information
414                                 image = opj_decode_with_info(dinfo, cio, &cstr_info);
415                         else
416                                 image = opj_decode(dinfo, cio);
417                         if(!image) {
418                                 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
419                                 opj_destroy_decompress(dinfo);
420                                 opj_cio_close(cio);
421                                 return 1;
422                         }
423                         /* dump image */
424       j2k_dump_image(stdout, image);
425
426                         /* dump cp */
427       j2k_dump_cp(stdout, image, ((opj_j2k_t*)dinfo->j2k_handle)->cp);
428
429                         /* close the byte stream */
430                         opj_cio_close(cio);
431
432                         /* Write the index to disk */
433                         if (*indexfilename) {
434                                 char bSuccess;
435                                 bSuccess = write_index_file(&cstr_info, indexfilename);
436                                 if (bSuccess) {
437                                         fprintf(stderr, "Failed to output index file\n");
438                                 }
439                         }
440                 }
441                 break;
442
443                 case JP2_CFMT:
444                 {
445                         /* JPEG 2000 compressed image data */
446
447                         /* get a decoder handle */
448                         dinfo = opj_create_decompress(CODEC_JP2);
449
450                         /* catch events using our callbacks and give a local context */
451                         opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
452
453                         /* setup the decoder decoding parameters using the current image and user parameters */
454                         opj_setup_decoder(dinfo, &parameters);
455
456                         /* open a byte stream */
457                         cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
458
459                         /* decode the stream and fill the image structure */
460                         if (*indexfilename)                             // If need to extract codestream information
461                                 image = opj_decode_with_info(dinfo, cio, &cstr_info);
462                         else
463                                 image = opj_decode(dinfo, cio);                 
464                         if(!image) {
465                                 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
466                                 opj_destroy_decompress(dinfo);
467                                 opj_cio_close(cio);
468                                 return 1;
469                         }
470                         /* dump image */
471           if(image->icc_profile_buf)
472          {
473           free(image->icc_profile_buf); image->icc_profile_buf = NULL;
474          }      
475       j2k_dump_image(stdout, image);
476
477                         /* dump cp */
478       j2k_dump_cp(stdout, image, ((opj_jp2_t*)dinfo->jp2_handle)->j2k->cp);
479
480                         /* close the byte stream */
481                         opj_cio_close(cio);
482
483                         /* Write the index to disk */
484                         if (*indexfilename) {
485                                 char bSuccess;
486                                 bSuccess = write_index_file(&cstr_info, indexfilename);
487                                 if (bSuccess) {
488                                         fprintf(stderr, "Failed to output index file\n");
489                                 }
490                         }
491                 }
492                 break;
493
494                 case JPT_CFMT:
495                 {
496                         /* JPEG 2000, JPIP */
497
498                         /* get a decoder handle */
499                         dinfo = opj_create_decompress(CODEC_JPT);
500
501                         /* catch events using our callbacks and give a local context */
502                         opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
503
504                         /* setup the decoder decoding parameters using user parameters */
505                         opj_setup_decoder(dinfo, &parameters);
506
507                         /* open a byte stream */
508                         cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
509
510                         /* decode the stream and fill the image structure */
511                         if (*indexfilename)                             // If need to extract codestream information
512                                 image = opj_decode_with_info(dinfo, cio, &cstr_info);
513                         else
514                                 image = opj_decode(dinfo, cio);
515                         if(!image) {
516                                 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
517                                 opj_destroy_decompress(dinfo);
518                                 opj_cio_close(cio);
519                                 return 1;
520                         }
521
522                         /* close the byte stream */
523                         opj_cio_close(cio);
524
525                         /* Write the index to disk */
526                         if (*indexfilename) {
527                                 char bSuccess;
528                                 bSuccess = write_index_file(&cstr_info, indexfilename);
529                                 if (bSuccess) {
530                                         fprintf(stderr, "Failed to output index file\n");
531                                 }
532                         }
533                 }
534                 break;
535
536                 default:
537                         fprintf(stderr, "skipping file..\n");
538                         continue;
539         }
540
541                 /* free the memory containing the code-stream */
542                 free(src);
543                 src = NULL;
544
545                 /* free remaining structures */
546                 if(dinfo) {
547                         opj_destroy_decompress(dinfo);
548                 }
549                 /* free codestream information structure */
550                 if (*indexfilename)     
551                         opj_destroy_cstr_info(&cstr_info);
552                 /* free image data structure */
553                 opj_image_destroy(image);
554
555         }
556
557   return EXIT_SUCCESS;
558 }
559
560
561 static void j2k_dump_image(FILE *fd, opj_image_t * img) {
562         int compno;
563         fprintf(fd, "image {\n");
564         fprintf(fd, "  x0=%d, y0=%d, x1=%d, y1=%d\n", img->x0, img->y0, img->x1, img->y1);
565         fprintf(fd, "  numcomps=%d\n", img->numcomps);
566         for (compno = 0; compno < img->numcomps; compno++) {
567                 opj_image_comp_t *comp = &img->comps[compno];
568                 fprintf(fd, "  comp %d {\n", compno);
569                 fprintf(fd, "    dx=%d, dy=%d\n", comp->dx, comp->dy);
570                 fprintf(fd, "    prec=%d\n", comp->prec);
571                 //fprintf(fd, "    bpp=%d\n", comp->bpp);
572                 fprintf(fd, "    sgnd=%d\n", comp->sgnd);
573                 fprintf(fd, "  }\n");
574         }
575         fprintf(fd, "}\n");
576 }
577
578 static void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp) {
579         int tileno, compno, layno, bandno, resno, numbands;
580         fprintf(fd, "coding parameters {\n");
581         fprintf(fd, "  tx0=%d, ty0=%d\n", cp->tx0, cp->ty0);
582         fprintf(fd, "  tdx=%d, tdy=%d\n", cp->tdx, cp->tdy);
583         fprintf(fd, "  tw=%d, th=%d\n", cp->tw, cp->th);
584         for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
585                 opj_tcp_t *tcp = &cp->tcps[tileno];
586                 fprintf(fd, "  tile %d {\n", tileno);
587                 fprintf(fd, "    csty=%x\n", tcp->csty);
588                 fprintf(fd, "    prg=%d\n", tcp->prg);
589                 fprintf(fd, "    numlayers=%d\n", tcp->numlayers);
590                 fprintf(fd, "    mct=%d\n", tcp->mct);
591                 fprintf(fd, "    rates=");
592                 for (layno = 0; layno < tcp->numlayers; layno++) {
593                         fprintf(fd, "%.1f ", tcp->rates[layno]);
594                 }
595                 fprintf(fd, "\n");
596                 for (compno = 0; compno < img->numcomps; compno++) {
597                         opj_tccp_t *tccp = &tcp->tccps[compno];
598                         fprintf(fd, "    comp %d {\n", compno);
599                         fprintf(fd, "      csty=%x\n", tccp->csty);
600                         fprintf(fd, "      numresolutions=%d\n", tccp->numresolutions);
601                         fprintf(fd, "      cblkw=%d\n", tccp->cblkw);
602                         fprintf(fd, "      cblkh=%d\n", tccp->cblkh);
603                         fprintf(fd, "      cblksty=%x\n", tccp->cblksty);
604                         fprintf(fd, "      qmfbid=%d\n", tccp->qmfbid);
605                         fprintf(fd, "      qntsty=%d\n", tccp->qntsty);
606                         fprintf(fd, "      numgbits=%d\n", tccp->numgbits);
607                         fprintf(fd, "      roishift=%d\n", tccp->roishift);
608                         fprintf(fd, "      stepsizes=");
609                         numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2;
610                         for (bandno = 0; bandno < numbands; bandno++) {
611                                 fprintf(fd, "(%d,%d) ", tccp->stepsizes[bandno].mant,
612                                         tccp->stepsizes[bandno].expn);
613                         }
614                         fprintf(fd, "\n");
615                         
616                         if (tccp->csty & J2K_CCP_CSTY_PRT) {
617                                 fprintf(fd, "      prcw=");
618                                 for (resno = 0; resno < tccp->numresolutions; resno++) {
619                                         fprintf(fd, "%d ", tccp->prcw[resno]);
620                                 }
621                                 fprintf(fd, "\n");
622                                 fprintf(fd, "      prch=");
623                                 for (resno = 0; resno < tccp->numresolutions; resno++) {
624                                         fprintf(fd, "%d ", tccp->prch[resno]);
625                                 }
626                                 fprintf(fd, "\n");
627                         }
628                         fprintf(fd, "    }\n");
629                 }
630                 fprintf(fd, "  }\n");
631         }
632         fprintf(fd, "}\n");
633 }
634