1 /* Copyright (c) 2001 David Janssens
2 * Copyright (c) 2002-2003 Yannick Verschueren
3 * Copyright (c) 2002-2003 Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
34 #define _CRTDBG_MAP_ALLOC
36 #include <stdlib.h> /* Must be included first */
50 #ifndef DONT_HAVE_GETOPT
53 #include "compat/getopt.h"
56 void usage_display(char *prgm)
58 fprintf(stdout,"Usage:\n");
59 fprintf(stdout," %s...\n",prgm);
60 fprintf(stdout," -i <compressed file>\n");
61 fprintf(stdout," REQUIRED\n");
62 fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n");
63 fprintf(stdout," is identified based on its suffix.\n");
64 fprintf(stdout," -o <decompressed file>\n");
65 fprintf(stdout," REQUIRED\n");
66 fprintf(stdout," Currently accepts PGM-files, PPM-files, PNM-files, PGX-files and\n");
67 fprintf(stdout," BMP-files. Binary data is written to the file (not ascii). If a PGX\n");
68 fprintf(stdout," filename is given, there will be as many output files as there are\n");
69 fprintf(stdout," components: an indice starting from 0 will then be appended to the\n");
70 fprintf(stdout," output filename, just before the \"pgx\" extension. If a PGM filename\n");
71 fprintf(stdout," is given and there are more than one component, only the first component\n");
72 fprintf(stdout," will be written to the file.\n");
73 fprintf(stdout," -r <reduce factor>\n");
74 fprintf(stdout," Set the number of highest resolution levels to be discarded. The\n");
75 fprintf(stdout," image resolution is effectively divided by 2 to the power of the\n");
76 fprintf(stdout," number of discarded levels. The reduce factor is limited by the\n");
77 fprintf(stdout," smallest total number of decomposition levels among tiles.\n");
78 fprintf(stdout," -l <number of quality layers to decode>\n");
79 fprintf(stdout," Set the maximum number of quality layers to decode. If there are\n");
80 fprintf(stdout," less quality layers than the specified number, all the quality layers\n");
81 fprintf(stdout," are decoded.\n");
82 fprintf(stdout," -u\n");
83 fprintf(stdout," print an usage statement\n");
87 int main(int argc, char **argv)
102 jp2_struct_t *jp2_struct=NULL;
104 int w, wr, wrr, h, hr, hrr, max;
105 int i, compno, pad, j;
114 int c = getopt(argc, argv,"i:o:r:l:u");
134 if ((S1 == 'j' && S2 == '2' && S3 == 'k')
135 || (S1 == 'J' && S2 == '2' && S3 == 'K')
136 || (S1 == 'j' && S2 == '2' && S3 == 'c')
137 || (S1 == 'J' && S2 == '2' && S3 == 'C')) {
138 cp.cod_format=J2K_CFMT;
143 if ((S1 == 'j' && S2 == 'p' && S3 == '2')
144 || (S1 == 'J' && S2 == 'P' && S3 == '2')) {
145 cp.cod_format=JP2_CFMT;
150 if ((S1 == 'j' && S2 == 'p' && S3 == 't')
151 || (S1 == 'J' && S2 == 'P' && S3 == 'T')) {
152 cp.cod_format=JPT_CFMT;
157 "j2k_to_image : Unknown input image format *.%c%c%c [only *.j2k, *.jp2, *.jpc or *.jpt]!! \n",
162 /* ----------------------------------------------------- */
179 if ((S1 == 'p' && S2 == 'g' && S3 == 'x')
180 || (S1 == 'P' && S2 == 'G' && S3 == 'X')) {
181 cp.decod_format = PGX_DFMT;
186 if ((S1 == 'p' && S2 == 'n' && S3 == 'm')
187 || (S1 == 'P' && S2 == 'N' && S3 == 'M')
188 || (S1 == 'p' && S2 == 'g' && S3 == 'm')
189 || (S1 == 'P' && S2 == 'G' && S3 == 'M')
190 || (S1 == 'P' && S2 == 'P' && S3 == 'M')
191 || (S1 == 'p' && S2 == 'p' && S3 == 'm')) {
192 cp.decod_format = PXM_DFMT;
197 if ((S1 == 'b' && S2 == 'm' && S3 == 'p')
198 || (S1 == 'B' && S2 == 'M' && S3 == 'P')) {
199 cp.decod_format = BMP_DFMT;
203 /* otherwise : error */
205 "!! Unrecognized output image format *.%c%c%c [only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n",
211 /* ----------------------------------------------------- */
216 sscanf(tmp, "%d", &cp.reduce);
219 /* ----------------------------------------------------- */
224 sscanf(tmp, "%d", &cp.layer);
227 /* ----------------------------------------------------- */
230 usage_display(argv[0]);
233 /* ----------------------------------------------------- */
236 fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c,optarg);
242 /*Check required arguments*/
243 /*------------------------*/
244 if (!infile || !outfile) {
245 fprintf(stderr,"ERROR -> At least one required argument is missing\nCheck j2k_to_image -u for usage information\n");
249 /*Read the input file and put it in memory*/
250 /*----------------------------------------*/
251 fsrc = fopen(infile, "rb");
253 fprintf(stderr, "ERROR -> failed to open %s for reading\n", infile);
256 fseek(fsrc, 0, SEEK_END);
258 fseek(fsrc, 0, SEEK_SET);
259 src = (char *) malloc(len);
260 fread(src, 1, len, fsrc);
263 /*Decode the code-stream*/
264 /*----------------------*/
265 switch(cp.cod_format) {
268 if (!j2k_decode(src, len, &img, &cp)) {
269 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
275 jp2_struct = (jp2_struct_t *) malloc(sizeof(jp2_struct_t));
276 jp2_struct->image = &img;
278 if (jp2_read_struct(src, jp2_struct, len)) {
279 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode jp2 structure!\n");
283 if (!j2k_decode(src + jp2_struct->j2k_codestream_offset, jp2_struct->j2k_codestream_len, &img, &cp)) {
284 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
288 /* Insert code here if you want to create actions on jp2_struct before deleting it */
294 if (!j2k_decode_jpt_stream(src, len, &img, &cp)) {
295 fprintf(stderr, "ERROR -> j2k_to_image: failed to decode JPT-file!\n");
302 "ERROR -> j2k_to_image : Unknown input image format\n");
307 /*Free the memory containing the code-stream*/
308 /*------------------------------------------*/
313 /*Create output image*/
314 /*-------------------*/
316 /* ---------------------------- / */
318 /* / FORMAT : PNM, PGM or PPM / */
320 /* ---------------------------- / */
322 switch (cp.decod_format) {
323 case PXM_DFMT: /* PNM PGM PPM */
333 if (img.numcomps == 3 && img.comps[0].dx == img.comps[1].dx
334 && img.comps[1].dx == img.comps[2].dx
335 && img.comps[0].dy == img.comps[1].dy
336 && img.comps[1].dy == img.comps[2].dy
337 && img.comps[0].prec == img.comps[1].prec
338 && img.comps[1].prec == img.comps[2].prec
339 && S2 !='g' && S2 !='G') {
341 fdest = fopen(outfile, "wb");
343 fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
347 w = int_ceildiv(img.x1 - img.x0, img.comps[0].dx);
348 /* wr = int_ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor),img.comps[0].dx);*/
350 wrr = int_ceildivpow2(img.comps[0].w, img.comps[0].factor);
352 h = int_ceildiv(img.y1 - img.y0, img.comps[0].dy);
353 /* hr = int_ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), img.comps[0].dy);*/
355 hrr = int_ceildivpow2(img.comps[0].h, img.comps[0].factor);
357 max = img.comps[0].prec > 8 ? 255 : (1 << img.comps[0].prec) - 1;
360 int_ceildivpow2(img.comps[0].x0 -
361 int_ceildiv(img.x0, img.comps[0].dx),
362 img.comps[0].factor);
364 int_ceildivpow2(img.comps[0].y0 -
365 int_ceildiv(img.y0, img.comps[0].dy),
366 img.comps[0].factor);
369 fprintf(fdest, "P6\n%d %d\n%d\n", wrr, hrr, max);
370 adjust = img.comps[0].prec > 8 ? img.comps[0].prec - 8 : 0;
371 for (i = 0; i < wrr * hrr; i++) {
373 unsigned char rc,gc,bc;
374 r = img.comps[0].data[i / wrr * wr + i % wrr];
375 r += (img.comps[0].sgnd ? 1 << (img.comps[0].prec - 1) : 0);
376 rc = (unsigned char) ((r >> adjust)+((r >> (adjust-1))%2));
378 g = img.comps[1].data[i / wrr * wr + i % wrr];
379 g += (img.comps[1].sgnd ? 1 << (img.comps[1].prec - 1) : 0);
380 gc = (unsigned char) ((g >> adjust)+((g >> (adjust-1))%2));
382 b = img.comps[2].data[i / wrr * wr + i % wrr];
383 b += (img.comps[2].sgnd ? 1 << (img.comps[2].prec - 1) : 0);
384 bc = (unsigned char) ((b >> adjust)+((b >> (adjust-1))%2));
386 fprintf(fdest, "%c%c%c", rc, gc, bc);
388 free(img.comps[0].data);
389 free(img.comps[1].data);
390 free(img.comps[2].data);
394 int ncomp=(S2=='g' || S2=='G')?1:img.numcomps;
395 if (img.numcomps>ncomp) {
396 fprintf(stderr,"WARNING -> [PGM files] Only the first component\n");
397 fprintf(stderr," is written to the file\n");
399 for (compno = 0; compno < ncomp; compno++) {
402 sprintf(name, "%d.%s", compno, outfile);
404 sprintf(name, "%s", outfile);
407 fdest = fopen(name, "wb");
409 fprintf(stderr, "ERROR -> failed to open %s for writing\n", name);
413 w = int_ceildiv(img.x1 - img.x0, img.comps[compno].dx);
414 /* wr = int_ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor),img.comps[compno].dx);*/
415 wr = img.comps[compno].w;
417 int_ceildivpow2(img.comps[compno].w, img.comps[compno].factor);
419 h = int_ceildiv(img.y1 - img.y0, img.comps[compno].dy);
420 /* hr = int_ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), img.comps[compno].dy);*/
421 hr = img.comps[compno].h;
423 int_ceildivpow2(img.comps[compno].h, img.comps[compno].factor);
426 img.comps[compno].prec >
427 8 ? 255 : (1 << img.comps[compno].prec) - 1;
429 img.comps[compno].x0 =
430 int_ceildivpow2(img.comps[compno].x0 -
432 img.comps[compno].dx),
433 img.comps[compno].factor);
434 img.comps[compno].y0 =
435 int_ceildivpow2(img.comps[compno].y0 -
437 img.comps[compno].dy),
438 img.comps[compno].factor);
440 fprintf(fdest, "P5\n%d %d\n%d\n", wrr, hrr, max);
442 img.comps[compno].prec > 8 ? img.comps[compno].prec - 8 : 0;
443 for (i = 0; i < wrr * hrr; i++) {
446 l = img.comps[compno].data[i / wrr * wr + i % wrr];
447 l += (img.comps[compno].
448 sgnd ? 1 << (img.comps[compno].prec - 1) : 0);
449 lc = (unsigned char) ((l >> adjust)+((l >> (adjust-1))%2));
450 fprintf(fdest, "%c", lc);
453 free(img.comps[compno].data);
458 /* ------------------------ / */
460 /* / FORMAT : PGX / */
462 /* /----------------------- / */
463 case PGX_DFMT: /* PGX */
464 for (compno = 0; compno < img.numcomps; compno++) {
465 j2k_comp_t *comp = &img.comps[compno];
477 if (img.numcomps > 1)
478 sprintf(name, "%s-%d.pgx", outfile, compno);
480 sprintf(name, "%s.pgx", outfile);
482 fdest = fopen(name, "wb");
484 fprintf(stderr, "ERROR -> failed to open %s for writing\n", name);
488 /* w = int_ceildiv(img.x1 - img.x0, comp->dx);*/
489 /* wr = int_ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor), comp->dx);*/
490 w = img.comps[compno].w;
491 wr = int_ceildivpow2(img.comps[compno].w, img.comps[compno].factor);
493 /* h = int_ceildiv(img.y1 - img.y0, comp->dy);*/
494 /* hr = int_ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), comp->dy); */
495 h = img.comps[compno].h;
496 hr = int_ceildivpow2(img.comps[compno].h, img.comps[compno].factor);
498 fprintf(fdest, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+',
504 else if (comp->prec <= 16)
509 for (i = 0; i < wr * hr; i++) {
510 int v = img.comps[compno].data[i / wr * w + i % wr];
512 for (j = nbytes - 1; j >= 0; j--) {
514 char byte = (char) (v >> (j * 8));
516 fwrite(&byte, 1, 1, fdest);
520 free(img.comps[compno].data);
525 /* ------------------------ / */
527 /* / FORMAT : BMP / */
529 /* /----------------------- / */
531 case BMP_DFMT: /* BMP */
532 if (img.numcomps == 3 && img.comps[0].dx == img.comps[1].dx
533 && img.comps[1].dx == img.comps[2].dx
534 && img.comps[0].dy == img.comps[1].dy
535 && img.comps[1].dy == img.comps[2].dy
536 && img.comps[0].prec == img.comps[1].prec
537 && img.comps[1].prec == img.comps[2].prec) {
538 /* -->> -->> -->> -->>
542 <<-- <<-- <<-- <<-- */
544 fdest = fopen(outfile, "wb");
546 fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
550 /* w = int_ceildiv(img.x1 - img.x0, img.comps[0].dx);*/
551 /* wr = int_ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor), img.comps[0].dx);*/
553 wr = int_ceildivpow2(img.comps[0].w, img.comps[0].factor);
555 /* h = int_ceildiv(img.y1 - img.y0, img.comps[0].dy);*/
556 /* hr = int_ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), img.comps[0].dy); */
558 hr = int_ceildivpow2(img.comps[0].h, img.comps[0].factor);
560 fprintf(fdest, "BM");
564 fprintf(fdest, "%c%c%c%c",
565 (unsigned char) (hr * wr * 3 + 3 * hr * (wr % 2) +
567 (unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2) + 54)
569 (unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2) + 54)
571 (unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2) + 54)
573 fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
574 ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
575 fprintf(fdest, "%c%c%c%c", (54) & 0xff, ((54) >> 8) & 0xff,
576 ((54) >> 16) & 0xff, ((54) >> 24) & 0xff);
580 fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff,
581 ((40) >> 16) & 0xff, ((40) >> 24) & 0xff);
582 fprintf(fdest, "%c%c%c%c", (unsigned char) ((wr) & 0xff),
583 (unsigned char) ((wr) >> 8) & 0xff,
584 (unsigned char) ((wr) >> 16) & 0xff,
585 (unsigned char) ((wr) >> 24) & 0xff);
586 fprintf(fdest, "%c%c%c%c", (unsigned char) ((hr) & 0xff),
587 (unsigned char) ((hr) >> 8) & 0xff,
588 (unsigned char) ((hr) >> 16) & 0xff,
589 (unsigned char) ((hr) >> 24) & 0xff);
590 fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff);
591 fprintf(fdest, "%c%c", (24) & 0xff, ((24) >> 8) & 0xff);
592 fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
593 ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
594 fprintf(fdest, "%c%c%c%c",
595 (unsigned char) (3 * hr * wr +
596 3 * hr * (wr % 2)) & 0xff,
597 (unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2)) >>
599 (unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2)) >>
601 (unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2)) >>
603 fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff,
604 ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
605 fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff,
606 ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
607 fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
608 ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
609 fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
610 ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
612 for (i = 0; i < wr * hr; i++) {
613 unsigned char R, G, B;
615 /* R = img.comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];*/
616 R = img.comps[0].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
617 /* G = img.comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];*/
618 G = img.comps[1].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
619 /* B = img.comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; */
621 B = img.comps[2].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
622 fprintf(fdest, "%c%c%c", B, G, R);
624 if ((i + 1) % wr == 0) {
625 for (pad = (3 * wr) % 4 ? 4 - (3 * wr) % 4 : 0; pad > 0; pad--) /* ADD */
626 fprintf(fdest, "%c", 0);
630 free(img.comps[1].data);
631 free(img.comps[2].data);
632 } else { /* Gray-scale */
634 /* -->> -->> -->> -->>
636 8 bits non code (Gray scale)
638 <<-- <<-- <<-- <<-- */
639 fdest = fopen(outfile, "wb");
640 /* w = int_ceildiv(img.x1 - img.x0, img.comps[0].dx);*/
641 /* wr = int_ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor), img.comps[0].dx);*/
643 wr = int_ceildivpow2(img.comps[0].w, img.comps[0].factor);
645 /* h = int_ceildiv(img.y1 - img.y0, img.comps[0].dy);*/
646 /* hr = int_ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), img.comps[0].dy);*/
648 hr = int_ceildivpow2(img.comps[0].h, img.comps[0].factor);
650 fprintf(fdest, "BM");
654 fprintf(fdest, "%c%c%c%c",
655 (unsigned char) (hr * wr + 54 + 1024 +
656 hr * (wr % 2)) & 0xff,
657 (unsigned char) ((hr * wr + 54 + 1024 + hr * (wr % 2))
659 (unsigned char) ((hr * wr + 54 + 1024 + hr * (wr % 2))
661 (unsigned char) ((hr * wr + 54 + 1024 + wr * (wr % 2))
663 fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
664 ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
665 fprintf(fdest, "%c%c%c%c", (54 + 1024) & 0xff,
666 ((54 + 1024) >> 8) & 0xff, ((54 + 1024) >> 16) & 0xff,
667 ((54 + 1024) >> 24) & 0xff);
671 fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff,
672 ((40) >> 16) & 0xff, ((40) >> 24) & 0xff);
673 fprintf(fdest, "%c%c%c%c", (unsigned char) ((wr) & 0xff),
674 (unsigned char) ((wr) >> 8) & 0xff,
675 (unsigned char) ((wr) >> 16) & 0xff,
676 (unsigned char) ((wr) >> 24) & 0xff);
677 fprintf(fdest, "%c%c%c%c", (unsigned char) ((hr) & 0xff),
678 (unsigned char) ((hr) >> 8) & 0xff,
679 (unsigned char) ((hr) >> 16) & 0xff,
680 (unsigned char) ((hr) >> 24) & 0xff);
681 fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff);
682 fprintf(fdest, "%c%c", (8) & 0xff, ((8) >> 8) & 0xff);
683 fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
684 ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
685 fprintf(fdest, "%c%c%c%c",
686 (unsigned char) (hr * wr + hr * (wr % 2)) & 0xff,
687 (unsigned char) ((hr * wr + hr * (wr % 2)) >> 8) &
689 (unsigned char) ((hr * wr + hr * (wr % 2)) >> 16) &
691 (unsigned char) ((hr * wr + hr * (wr % 2)) >> 24) & 0xff);
692 fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff,
693 ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
694 fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff,
695 ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
696 fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff,
697 ((256) >> 16) & 0xff, ((256) >> 24) & 0xff);
698 fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff,
699 ((256) >> 16) & 0xff, ((256) >> 24) & 0xff);
702 for (i = 0; i < 256; i++) {
703 fprintf(fdest, "%c%c%c%c", i, i, i, 0);
706 for (i = 0; i < wr * hr; i++) {
708 /* fprintf(fdest, "%c", img.comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]);*/
710 img.comps[0].data[w * hr - ((i) / (wr) + 1) * w +
712 /*if (((i + 1) % w == 0 && w % 2))
713 fprintf(fdest, "%c", 0); */
714 if ((i + 1) % wr == 0) {
715 for (pad = wr % 4 ? 4 - wr % 4 : 0; pad > 0; pad--) /* ADD */
716 fprintf(fdest, "%c", 0);
720 free(img.comps[0].data);
725 "ERROR -> j2k_to_image : Unknown output image format\n");
731 /* Free remaining structures*/
732 /*--------------------------*/
737 /* Check memory leaks if debug mode*/
738 /*---------------------------------*/
742 _CrtDumpMemoryLeaks();