2 * Copyright (c) 2001-2003, David Janssens
3 * Copyright (c) 2002-2003, Yannick Verschueren
4 * Copyright (c) 2002-2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
35 /* -->> -->> -->> -->>
39 <<-- <<-- <<-- <<-- */
41 /* UINT2 defines a two byte word */
42 typedef unsigned short int UINT2;
44 /* UINT4 defines a four byte word */
45 typedef unsigned long int UINT4;
48 UINT2 bfType; /* 'BM' for Bitmap (19776) */
49 UINT4 bfSize; /* Size of the file */
50 UINT2 bfReserved1; /* Reserved : 0 */
51 UINT2 bfReserved2; /* Reserved : 0 */
52 UINT4 bfOffBits; /* Offset */
56 UINT4 biSize; /* Size of the structure in bytes */
57 UINT4 biWidth; /* Width of the image in pixels */
58 UINT4 biHeight; /* Heigth of the image in pixels */
59 UINT2 biPlanes; /* 1 */
60 UINT2 biBitCount; /* Number of color bits by pixels */
61 UINT4 biCompression; /* Type of encoding 0: none 1: RLE8 2: RLE4 */
62 UINT4 biSizeImage; /* Size of the image in bytes */
63 UINT4 biXpelsPerMeter; /* Horizontal (X) resolution in pixels/meter */
64 UINT4 biYpelsPerMeter; /* Vertical (Y) resolution in pixels/meter */
65 UINT4 biClrUsed; /* Number of color used in the image (0: ALL) */
66 UINT4 biClrImportant; /* Number of important color (0: ALL) */
69 int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx,
70 int subsampling_dy, int Dim[2])
73 FILE *Compo0 = NULL, *Compo1 = NULL, *Compo2 = NULL;
74 BITMAPFILEHEADER_t File_h;
75 BITMAPINFOHEADER_t Info_h;
77 unsigned char *table_R, *table_G, *table_B;
78 int i, w, h, PAD, type = 0;
79 int gray_scale = 1, not_end_file = 1, line = 0, col = 0;
83 IN = fopen(filename, "rb");
86 "\033[0;33mFailed to open %s for reading !!\033[0;39m\n",
91 File_h.bfType = getc(IN);
92 File_h.bfType = (getc(IN) << 8) + File_h.bfType;
94 if (File_h.bfType != 19778) {
95 printf("Error, not a BMP file!\n");
100 File_h.bfSize = getc(IN);
101 File_h.bfSize = (getc(IN) << 8) + File_h.bfSize;
102 File_h.bfSize = (getc(IN) << 16) + File_h.bfSize;
103 File_h.bfSize = (getc(IN) << 24) + File_h.bfSize;
105 File_h.bfReserved1 = getc(IN);
106 File_h.bfReserved1 = (getc(IN) << 8) + File_h.bfReserved1;
108 File_h.bfReserved2 = getc(IN);
109 File_h.bfReserved2 = (getc(IN) << 8) + File_h.bfReserved2;
111 File_h.bfOffBits = getc(IN);
112 File_h.bfOffBits = (getc(IN) << 8) + File_h.bfOffBits;
113 File_h.bfOffBits = (getc(IN) << 16) + File_h.bfOffBits;
114 File_h.bfOffBits = (getc(IN) << 24) + File_h.bfOffBits;
119 Info_h.biSize = getc(IN);
120 Info_h.biSize = (getc(IN) << 8) + Info_h.biSize;
121 Info_h.biSize = (getc(IN) << 16) + Info_h.biSize;
122 Info_h.biSize = (getc(IN) << 24) + Info_h.biSize;
124 Info_h.biWidth = getc(IN);
125 Info_h.biWidth = (getc(IN) << 8) + Info_h.biWidth;
126 Info_h.biWidth = (getc(IN) << 16) + Info_h.biWidth;
127 Info_h.biWidth = (getc(IN) << 24) + Info_h.biWidth;
130 Info_h.biHeight = getc(IN);
131 Info_h.biHeight = (getc(IN) << 8) + Info_h.biHeight;
132 Info_h.biHeight = (getc(IN) << 16) + Info_h.biHeight;
133 Info_h.biHeight = (getc(IN) << 24) + Info_h.biHeight;
136 Info_h.biPlanes = getc(IN);
137 Info_h.biPlanes = (getc(IN) << 8) + Info_h.biPlanes;
139 Info_h.biBitCount = getc(IN);
140 Info_h.biBitCount = (getc(IN) << 8) + Info_h.biBitCount;
142 Info_h.biCompression = getc(IN);
143 Info_h.biCompression = (getc(IN) << 8) + Info_h.biCompression;
144 Info_h.biCompression = (getc(IN) << 16) + Info_h.biCompression;
145 Info_h.biCompression = (getc(IN) << 24) + Info_h.biCompression;
147 Info_h.biSizeImage = getc(IN);
148 Info_h.biSizeImage = (getc(IN) << 8) + Info_h.biSizeImage;
149 Info_h.biSizeImage = (getc(IN) << 16) + Info_h.biSizeImage;
150 Info_h.biSizeImage = (getc(IN) << 24) + Info_h.biSizeImage;
152 Info_h.biXpelsPerMeter = getc(IN);
153 Info_h.biXpelsPerMeter = (getc(IN) << 8) + Info_h.biXpelsPerMeter;
154 Info_h.biXpelsPerMeter = (getc(IN) << 16) + Info_h.biXpelsPerMeter;
155 Info_h.biXpelsPerMeter = (getc(IN) << 24) + Info_h.biXpelsPerMeter;
157 Info_h.biYpelsPerMeter = getc(IN);
158 Info_h.biYpelsPerMeter = (getc(IN) << 8) + Info_h.biYpelsPerMeter;
159 Info_h.biYpelsPerMeter = (getc(IN) << 16) + Info_h.biYpelsPerMeter;
160 Info_h.biYpelsPerMeter = (getc(IN) << 24) + Info_h.biYpelsPerMeter;
162 Info_h.biClrUsed = getc(IN);
163 Info_h.biClrUsed = (getc(IN) << 8) + Info_h.biClrUsed;
164 Info_h.biClrUsed = (getc(IN) << 16) + Info_h.biClrUsed;
165 Info_h.biClrUsed = (getc(IN) << 24) + Info_h.biClrUsed;
167 Info_h.biClrImportant = getc(IN);
168 Info_h.biClrImportant = (getc(IN) << 8) + Info_h.biClrImportant;
169 Info_h.biClrImportant = (getc(IN) << 16) + Info_h.biClrImportant;
170 Info_h.biClrImportant = (getc(IN) << 24) + Info_h.biClrImportant;
172 /* Read the data and store them in the OUT file */
174 if (Info_h.biBitCount == 24) {
178 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
182 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
187 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
188 for (i = 0; i < img->numcomps; i++) {
189 img->comps[i].prec = 8;
190 img->comps[i].bpp = 8;
191 img->comps[i].sgnd = 0;
192 img->comps[i].dx = subsampling_dx;
193 img->comps[i].dy = subsampling_dy;
195 Compo0 = fopen("Compo0", "wb");
198 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
200 Compo1 = fopen("Compo1", "wb");
203 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
205 Compo2 = fopen("Compo2", "wb");
208 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
211 /* Place the cursor at the beginning of the image information */
212 fseek(IN, 0, SEEK_SET);
213 fseek(IN, File_h.bfOffBits, SEEK_SET);
218 // PAD = 4 - (3 * W) % 4;
219 // PAD = (PAD == 4) ? 0 : PAD;
220 PAD = (3 * W) % 4 ? 4 - (3 * W) % 4 : 0;
224 (unsigned char *) malloc((3 * W + PAD) * H *
225 sizeof(unsigned char));
227 fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN);
229 for (i = 0; i < (3 * W + PAD) * H; i++) {
231 int Wp = 3 * W + PAD;
233 elmt = RGB[(H - (i / Wp + 1)) * Wp + i % Wp];
234 if ((i % Wp) < (3 * W)) {
237 fprintf(Compo2, "%c", elmt);
241 fprintf(Compo1, "%c", elmt);
245 fprintf(Compo0, "%c", elmt);
256 } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 0) {
260 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
264 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
268 table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
269 table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
270 table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
272 for (i = 0; i < Info_h.biClrUsed; i++) {
273 table_B[i] = getc(IN);
274 table_G[i] = getc(IN);
275 table_R[i] = getc(IN);
277 if (table_R[i] != table_G[i] && table_R[i] != table_B[i]
278 && table_G[i] != table_B[i])
282 /* Place the cursor at the beginning of the image information */
283 fseek(IN, 0, SEEK_SET);
284 fseek(IN, File_h.bfOffBits, SEEK_SET);
288 if (Info_h.biWidth % 2)
291 RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char));
293 fread(RGB, sizeof(unsigned char), W * H, IN);
297 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
298 img->comps[0].prec = 8;
299 img->comps[0].bpp = 8;
300 img->comps[0].sgnd = 0;
301 img->comps[0].dx = subsampling_dx;
302 img->comps[0].dy = subsampling_dy;
303 Compo0 = fopen("Compo0", "wb");
306 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
308 for (i = 0; i < W * H; i++) {
309 if ((i % W < W - 1 && Info_h.biWidth % 2)
310 || !(Info_h.biWidth % 2))
311 fprintf(Compo0, "%c",
312 table_R[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
318 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
319 for (i = 0; i < img->numcomps; i++) {
320 img->comps[i].prec = 8;
321 img->comps[i].bpp = 8;
322 img->comps[i].sgnd = 0;
323 img->comps[i].dx = subsampling_dx;
324 img->comps[i].dy = subsampling_dy;
327 Compo0 = fopen("Compo0", "wb");
330 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
332 Compo1 = fopen("Compo1", "wb");
335 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
337 Compo2 = fopen("Compo2", "wb");
340 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
343 for (i = 0; i < W * H; i++) {
344 if ((i % W < W - 1 && Info_h.biWidth % 2)
345 || !(Info_h.biWidth % 2)) {
346 fprintf(Compo0, "%c",
347 table_R[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
348 fprintf(Compo1, "%c",
349 table_G[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
350 fprintf(Compo2, "%c",
351 table_B[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
361 } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) {
365 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
369 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
373 table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
374 table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
375 table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
377 for (i = 0; i < Info_h.biClrUsed; i++) {
378 table_B[i] = getc(IN);
379 table_G[i] = getc(IN);
380 table_R[i] = getc(IN);
382 if (table_R[i] != table_G[i] && table_R[i] != table_B[i]
383 && table_G[i] != table_B[i])
387 /* Place the cursor at the beginning of the image information */
388 fseek(IN, 0, SEEK_SET);
389 fseek(IN, File_h.bfOffBits, SEEK_SET);
393 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
394 img->comps[0].prec = 8;
395 img->comps[0].bpp = 8;
396 img->comps[0].sgnd = 0;
397 img->comps[0].dx = subsampling_dx;
398 img->comps[0].dy = subsampling_dy;
399 Compo0 = fopen("Compo0", "wb");
402 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
407 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
408 for (i = 0; i < img->numcomps; i++) {
409 img->comps[i].prec = 8;
410 img->comps[i].bpp = 8;
411 img->comps[i].sgnd = 0;
412 img->comps[i].dx = subsampling_dx;
413 img->comps[i].dy = subsampling_dy;
415 Compo0 = fopen("Compo0", "wb");
418 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
420 Compo1 = fopen("Compo1", "wb");
423 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
425 Compo2 = fopen("Compo2", "wb");
428 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
433 (unsigned char *) malloc(Info_h.biWidth * Info_h.biHeight *
434 sizeof(unsigned char));
436 while (not_end_file) {
440 for (i = 0; i < (int) v; i++) {
441 RGB[line * Info_h.biWidth + col] = v2;
456 printf("No Delta supported\n");
460 for (i = 0; i < v; i++) {
462 RGB[line * Info_h.biWidth + col] = v2;
471 for (line = 0; line < Info_h.biHeight; line++)
472 for (col = 0; col < Info_h.biWidth; col++)
473 fprintf(Compo0, "%c", table_R[(int)
474 RGB[(Info_h.biHeight - line -
475 1) * Info_h.biWidth +
479 for (line = 0; line < Info_h.biHeight; line++)
480 for (col = 0; col < Info_h.biWidth; col++) {
481 fprintf(Compo0, "%c", table_R[(int)
482 RGB[(Info_h.biHeight - line -
483 1) * Info_h.biWidth +
485 fprintf(Compo1, "%c", table_G[(int)
486 RGB[(Info_h.biHeight - line -
487 1) * Info_h.biWidth +
489 fprintf(Compo2, "%c", table_B[(int)
490 RGB[(Info_h.biHeight - line -
491 1) * Info_h.biWidth +
501 "Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n",
509 /* -->> -->> -->> -->>
513 <<-- <<-- <<-- <<-- */
516 unsigned char readuchar(FILE * f)
523 unsigned short readushort(FILE * f, int bigendian)
525 unsigned char c1, c2;
529 return (c1 << 8) + c2;
531 return (c2 << 8) + c1;
534 unsigned int readuint(FILE * f, int bigendian)
536 unsigned char c1, c2, c3, c4;
542 return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4;
544 return (c4 << 24) + (c3 << 16) + (c2 << 8) + c1;
547 int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
548 int subsampling_dx, int subsampling_dy, int Dim[2],
553 int i, compno, bandno;
554 char str[256], endian[16];
560 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
561 for (compno = 0; compno < img->numcomps; compno++) {
566 comp = &img->comps[compno];
567 sprintf(str, "%s", filename);
568 f = fopen(str, "rb");
570 fprintf(stderr, "Failed to open %s for reading !\n", str);
573 if (fscanf(f, "PG %s %c %d %d %d", endian, &sign, &prec, &w, &h) == 5) {
575 if (!strcmp(endian, "ML"))
583 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
587 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
591 if (w != img->x1 || h != img->y1)
601 comp->dx = subsampling_dx;
602 comp->dy = subsampling_dy;
605 Y1 = cp.ty0 + bandno * cp.tdy <
606 img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
609 sprintf(tmp, "bandtile%d", bandno); /* bandtile file */
610 src = fopen(tmp, "wb");
612 fprintf(stderr, "failed to open %s for writing !\n", tmp);
614 for (i = 0; i < w * h; i++) {
616 if (i == Y1 * w / subsampling_dy && tdy != -1) { /* bandtile is full */
619 sprintf(tmp, "bandtile%d", bandno);
620 src = fopen(tmp, "wb");
622 fprintf(stderr, "failed to open %s for writing !\n", tmp);
624 Y1 = cp.ty0 + bandno * cp.tdy <
625 img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
628 if (comp->prec <= 8) {
632 v = (char) readuchar(f);
634 } else if (comp->prec <= 16) {
636 v = readushort(f, bigendian);
638 v = (short) readushort(f, bigendian);
642 v = readuint(f, bigendian);
644 v = (int) readuint(f, bigendian);
649 fprintf(src, "%d ", v);
656 comp->bpp = int_floorlog2(max) + 1;
661 /* -->> -->> -->> -->>
665 <<-- <<-- <<-- <<-- */
667 int pnmtoimage(char *filename, j2k_image_t * img, int subsampling_dx,
668 int subsampling_dy, int Dim[2])
671 FILE *Compo0, *Compo1, *Compo2;
677 f = fopen(filename, "rb");
680 "\033[0;33mFailed to open %s for reading !!\033[0;39m\n",
691 if (fgetc(f) == '#') {
692 fseek(f, 0, SEEK_SET);
694 fgets(comment, 256, f);
695 fscanf(f, "%d %d\n255", &w, &h);
697 fseek(f, 0, SEEK_SET);
698 fscanf(f, "P2\n%d %d\n255", &w, &h);
705 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
709 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
714 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
715 img->comps[0].prec = 8;
716 img->comps[0].bpp = 8;
717 img->comps[0].sgnd = 0;
718 img->comps[0].dx = subsampling_dx;
719 img->comps[0].dy = subsampling_dy;
721 Compo0 = fopen("Compo0", "wb");
724 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
726 for (i = 0; i < w * h; i++) {
729 fprintf(Compo0, "%c", l);
732 } else if (value == '5') {
734 if (fgetc(f) == '#') {
735 fseek(f, 0, SEEK_SET);
737 fgets(comment, 256, f);
738 fscanf(f, "%d %d\n255", &w, &h);
740 fseek(f, 0, SEEK_SET);
741 fscanf(f, "P5\n%d %d\n255", &w, &h);
748 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
752 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
757 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
758 img->comps[0].prec = 8;
759 img->comps[0].bpp = 8;
760 img->comps[0].sgnd = 0;
761 img->comps[0].dx = subsampling_dx;
762 img->comps[0].dy = subsampling_dy;
763 Compo0 = fopen("Compo0", "wb");
766 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
768 for (i = 0; i < w * h; i++) {
771 fwrite(&l, 1, 1, Compo0);
774 } else if (value == '3') {
776 if (fgetc(f) == '#') {
777 fseek(f, 0, SEEK_SET);
779 fgets(comment, 256, f);
780 fscanf(f, "%d %d\n255", &w, &h);
782 fseek(f, 0, SEEK_SET);
783 fscanf(f, "P3\n%d %d\n255", &w, &h);
790 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
794 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
798 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
799 for (i = 0; i < img->numcomps; i++) {
800 img->comps[i].prec = 8;
801 img->comps[i].bpp = 8;
802 img->comps[i].sgnd = 0;
803 img->comps[i].dx = subsampling_dx;
804 img->comps[i].dy = subsampling_dy;
806 Compo0 = fopen("Compo0", "wb");
809 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
812 Compo1 = fopen("Compo1", "wb");
815 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
818 Compo2 = fopen("Compo2", "wb");
821 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
824 for (i = 0; i < w * h; i++) {
825 unsigned int r, g, b;
829 fprintf(Compo0, "%c", r);
830 fprintf(Compo1, "%c", g);
831 fprintf(Compo2, "%c", b);
836 } else if (value == '6') {
838 if (fgetc(f) == '#') {
839 fseek(f, 0, SEEK_SET);
841 fgets(comment, 256, f);
842 fscanf(f, "%d %d\n255", &w, &h);
844 fseek(f, 0, SEEK_SET);
845 fscanf(f, "P6\n%d %d\n255", &w, &h);
852 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
856 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
860 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
861 for (i = 0; i < img->numcomps; i++) {
862 img->comps[i].prec = 8;
863 img->comps[i].bpp = 8;
864 img->comps[i].sgnd = 0;
865 img->comps[i].dx = subsampling_dx;
866 img->comps[i].dy = subsampling_dy;
868 Compo0 = fopen("Compo0", "wb");
871 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
874 Compo1 = fopen("Compo1", "wb");
877 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
880 Compo2 = fopen("Compo2", "wb");
883 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
886 for (i = 0; i < w * h; i++) {
887 unsigned char r, g, b;
891 fwrite(&r, 1, 1, Compo0);
892 fwrite(&g, 1, 1, Compo1);
893 fwrite(&b, 1, 1, Compo2);