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 unsigned int j, w, h, PAD, type = 0;
80 int gray_scale = 1, not_end_file = 1;
81 unsigned int line = 0, col = 0;
85 IN = fopen(filename, "rb");
88 "\033[0;33mFailed to open %s for reading !!\033[0;39m\n",
93 File_h.bfType = getc(IN);
94 File_h.bfType = (getc(IN) << 8) + File_h.bfType;
96 if (File_h.bfType != 19778) {
97 printf("Error, not a BMP file!\n");
102 File_h.bfSize = getc(IN);
103 File_h.bfSize = (getc(IN) << 8) + File_h.bfSize;
104 File_h.bfSize = (getc(IN) << 16) + File_h.bfSize;
105 File_h.bfSize = (getc(IN) << 24) + File_h.bfSize;
107 File_h.bfReserved1 = getc(IN);
108 File_h.bfReserved1 = (getc(IN) << 8) + File_h.bfReserved1;
110 File_h.bfReserved2 = getc(IN);
111 File_h.bfReserved2 = (getc(IN) << 8) + File_h.bfReserved2;
113 File_h.bfOffBits = getc(IN);
114 File_h.bfOffBits = (getc(IN) << 8) + File_h.bfOffBits;
115 File_h.bfOffBits = (getc(IN) << 16) + File_h.bfOffBits;
116 File_h.bfOffBits = (getc(IN) << 24) + File_h.bfOffBits;
121 Info_h.biSize = getc(IN);
122 Info_h.biSize = (getc(IN) << 8) + Info_h.biSize;
123 Info_h.biSize = (getc(IN) << 16) + Info_h.biSize;
124 Info_h.biSize = (getc(IN) << 24) + Info_h.biSize;
126 Info_h.biWidth = getc(IN);
127 Info_h.biWidth = (getc(IN) << 8) + Info_h.biWidth;
128 Info_h.biWidth = (getc(IN) << 16) + Info_h.biWidth;
129 Info_h.biWidth = (getc(IN) << 24) + Info_h.biWidth;
132 Info_h.biHeight = getc(IN);
133 Info_h.biHeight = (getc(IN) << 8) + Info_h.biHeight;
134 Info_h.biHeight = (getc(IN) << 16) + Info_h.biHeight;
135 Info_h.biHeight = (getc(IN) << 24) + Info_h.biHeight;
138 Info_h.biPlanes = getc(IN);
139 Info_h.biPlanes = (getc(IN) << 8) + Info_h.biPlanes;
141 Info_h.biBitCount = getc(IN);
142 Info_h.biBitCount = (getc(IN) << 8) + Info_h.biBitCount;
144 Info_h.biCompression = getc(IN);
145 Info_h.biCompression = (getc(IN) << 8) + Info_h.biCompression;
146 Info_h.biCompression = (getc(IN) << 16) + Info_h.biCompression;
147 Info_h.biCompression = (getc(IN) << 24) + Info_h.biCompression;
149 Info_h.biSizeImage = getc(IN);
150 Info_h.biSizeImage = (getc(IN) << 8) + Info_h.biSizeImage;
151 Info_h.biSizeImage = (getc(IN) << 16) + Info_h.biSizeImage;
152 Info_h.biSizeImage = (getc(IN) << 24) + Info_h.biSizeImage;
154 Info_h.biXpelsPerMeter = getc(IN);
155 Info_h.biXpelsPerMeter = (getc(IN) << 8) + Info_h.biXpelsPerMeter;
156 Info_h.biXpelsPerMeter = (getc(IN) << 16) + Info_h.biXpelsPerMeter;
157 Info_h.biXpelsPerMeter = (getc(IN) << 24) + Info_h.biXpelsPerMeter;
159 Info_h.biYpelsPerMeter = getc(IN);
160 Info_h.biYpelsPerMeter = (getc(IN) << 8) + Info_h.biYpelsPerMeter;
161 Info_h.biYpelsPerMeter = (getc(IN) << 16) + Info_h.biYpelsPerMeter;
162 Info_h.biYpelsPerMeter = (getc(IN) << 24) + Info_h.biYpelsPerMeter;
164 Info_h.biClrUsed = getc(IN);
165 Info_h.biClrUsed = (getc(IN) << 8) + Info_h.biClrUsed;
166 Info_h.biClrUsed = (getc(IN) << 16) + Info_h.biClrUsed;
167 Info_h.biClrUsed = (getc(IN) << 24) + Info_h.biClrUsed;
169 Info_h.biClrImportant = getc(IN);
170 Info_h.biClrImportant = (getc(IN) << 8) + Info_h.biClrImportant;
171 Info_h.biClrImportant = (getc(IN) << 16) + Info_h.biClrImportant;
172 Info_h.biClrImportant = (getc(IN) << 24) + Info_h.biClrImportant;
174 /* Read the data and store them in the OUT file */
176 if (Info_h.biBitCount == 24) {
180 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
184 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
189 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
190 for (i = 0; i < img->numcomps; i++) {
191 img->comps[i].prec = 8;
192 img->comps[i].bpp = 8;
193 img->comps[i].sgnd = 0;
194 img->comps[i].dx = subsampling_dx;
195 img->comps[i].dy = subsampling_dy;
197 Compo0 = fopen("Compo0", "wb");
200 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
202 Compo1 = fopen("Compo1", "wb");
205 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
207 Compo2 = fopen("Compo2", "wb");
210 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
213 /* Place the cursor at the beginning of the image information */
214 fseek(IN, 0, SEEK_SET);
215 fseek(IN, File_h.bfOffBits, SEEK_SET);
220 // PAD = 4 - (3 * W) % 4;
221 // PAD = (PAD == 4) ? 0 : PAD;
222 PAD = (3 * W) % 4 ? 4 - (3 * W) % 4 : 0;
226 (unsigned char *) malloc((3 * W + PAD) * H *
227 sizeof(unsigned char));
229 fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN);
231 for (j = 0; j < (3 * W + PAD) * H; j++) {
233 int Wp = 3 * W + PAD;
235 elmt = RGB[(H - (j / Wp + 1)) * Wp + j % Wp];
236 if ((j % Wp) < (3 * W)) {
239 fprintf(Compo2, "%c", elmt);
243 fprintf(Compo1, "%c", elmt);
247 fprintf(Compo0, "%c", elmt);
258 } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 0) {
262 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
266 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
270 table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
271 table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
272 table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
274 for (j = 0; j < Info_h.biClrUsed; j++) {
275 table_B[j] = getc(IN);
276 table_G[j] = getc(IN);
277 table_R[j] = getc(IN);
279 if (table_R[j] != table_G[j] && table_R[j] != table_B[j]
280 && table_G[j] != table_B[j])
284 /* Place the cursor at the beginning of the image information */
285 fseek(IN, 0, SEEK_SET);
286 fseek(IN, File_h.bfOffBits, SEEK_SET);
290 if (Info_h.biWidth % 2)
293 RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char));
295 fread(RGB, sizeof(unsigned char), W * H, IN);
299 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
300 img->comps[0].prec = 8;
301 img->comps[0].bpp = 8;
302 img->comps[0].sgnd = 0;
303 img->comps[0].dx = subsampling_dx;
304 img->comps[0].dy = subsampling_dy;
305 Compo0 = fopen("Compo0", "wb");
308 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
310 for (j = 0; j < W * H; j++) {
311 if ((j % W < W - 1 && Info_h.biWidth % 2)
312 || !(Info_h.biWidth % 2))
313 fprintf(Compo0, "%c",
314 table_R[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]);
320 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
321 for (i = 0; i < img->numcomps; i++) {
322 img->comps[i].prec = 8;
323 img->comps[i].bpp = 8;
324 img->comps[i].sgnd = 0;
325 img->comps[i].dx = subsampling_dx;
326 img->comps[i].dy = subsampling_dy;
329 Compo0 = fopen("Compo0", "wb");
332 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
334 Compo1 = fopen("Compo1", "wb");
337 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
339 Compo2 = fopen("Compo2", "wb");
342 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
345 for (j = 0; j < W * H; j++) {
346 if ((j % W < W - 1 && Info_h.biWidth % 2)
347 || !(Info_h.biWidth % 2)) {
348 fprintf(Compo0, "%c",
349 table_R[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]);
350 fprintf(Compo1, "%c",
351 table_G[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]);
352 fprintf(Compo2, "%c",
353 table_B[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]);
363 } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) {
367 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
371 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
375 table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
376 table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
377 table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
379 for (j = 0; j < Info_h.biClrUsed; j++) {
380 table_B[j] = getc(IN);
381 table_G[j] = getc(IN);
382 table_R[j] = getc(IN);
384 if (table_R[j] != table_G[j] && table_R[j] != table_B[j]
385 && table_G[j] != table_B[j])
389 /* Place the cursor at the beginning of the image information */
390 fseek(IN, 0, SEEK_SET);
391 fseek(IN, File_h.bfOffBits, SEEK_SET);
395 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
396 img->comps[0].prec = 8;
397 img->comps[0].bpp = 8;
398 img->comps[0].sgnd = 0;
399 img->comps[0].dx = subsampling_dx;
400 img->comps[0].dy = subsampling_dy;
401 Compo0 = fopen("Compo0", "wb");
404 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
409 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
410 for (i = 0; i < img->numcomps; i++) {
411 img->comps[i].prec = 8;
412 img->comps[i].bpp = 8;
413 img->comps[i].sgnd = 0;
414 img->comps[i].dx = subsampling_dx;
415 img->comps[i].dy = subsampling_dy;
417 Compo0 = fopen("Compo0", "wb");
420 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
422 Compo1 = fopen("Compo1", "wb");
425 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
427 Compo2 = fopen("Compo2", "wb");
430 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
435 (unsigned char *) malloc(Info_h.biWidth * Info_h.biHeight *
436 sizeof(unsigned char));
438 while (not_end_file) {
442 for (i = 0; i < (int) v; i++) {
443 RGB[line * Info_h.biWidth + col] = v2;
458 printf("No Delta supported\n");
462 for (i = 0; i < v; i++) {
464 RGB[line * Info_h.biWidth + col] = v2;
473 for (line = 0; line < Info_h.biHeight; line++)
474 for (col = 0; col < Info_h.biWidth; col++)
475 fprintf(Compo0, "%c", table_R[(int)
476 RGB[(Info_h.biHeight - line -
477 1) * Info_h.biWidth +
481 for (line = 0; line < Info_h.biHeight; line++)
482 for (col = 0; col < Info_h.biWidth; col++) {
483 fprintf(Compo0, "%c", table_R[(int)
484 RGB[(Info_h.biHeight - line -
485 1) * Info_h.biWidth +
487 fprintf(Compo1, "%c", table_G[(int)
488 RGB[(Info_h.biHeight - line -
489 1) * Info_h.biWidth +
491 fprintf(Compo2, "%c", table_B[(int)
492 RGB[(Info_h.biHeight - line -
493 1) * Info_h.biWidth +
503 "Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n",
511 /* -->> -->> -->> -->>
515 <<-- <<-- <<-- <<-- */
518 unsigned char readuchar(FILE * f)
525 unsigned short readushort(FILE * f, int bigendian)
527 unsigned char c1, c2;
531 return (c1 << 8) + c2;
533 return (c2 << 8) + c1;
536 unsigned int readuint(FILE * f, int bigendian)
538 unsigned char c1, c2, c3, c4;
544 return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4;
546 return (c4 << 24) + (c3 << 16) + (c2 << 8) + c1;
549 int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
550 int subsampling_dx, int subsampling_dy, int Dim[2],
555 int i, compno, bandno;
556 char str[256], endian[16];
562 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
563 for (compno = 0; compno < img->numcomps; compno++) {
568 comp = &img->comps[compno];
569 sprintf(str, "%s", filename);
570 f = fopen(str, "rb");
572 fprintf(stderr, "Failed to open %s for reading !\n", str);
575 if (fscanf(f, "PG %s %c %d %d %d", endian, &sign, &prec, &w, &h) == 5) {
577 if (!strcmp(endian, "ML"))
585 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
589 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
593 if (w != img->x1 || h != img->y1)
603 comp->dx = subsampling_dx;
604 comp->dy = subsampling_dy;
607 Y1 = cp.ty0 + bandno * cp.tdy <
608 img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
611 sprintf(tmp, "bandtile%d", bandno); /* bandtile file */
612 src = fopen(tmp, "wb");
614 fprintf(stderr, "failed to open %s for writing !\n", tmp);
616 for (i = 0; i < w * h; i++) {
618 if (i == Y1 * w / subsampling_dy && tdy != -1) { /* bandtile is full */
621 sprintf(tmp, "bandtile%d", bandno);
622 src = fopen(tmp, "wb");
624 fprintf(stderr, "failed to open %s for writing !\n", tmp);
626 Y1 = cp.ty0 + bandno * cp.tdy <
627 img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
630 if (comp->prec <= 8) {
634 v = (char) readuchar(f);
636 } else if (comp->prec <= 16) {
638 v = readushort(f, bigendian);
640 v = (short) readushort(f, bigendian);
644 v = readuint(f, bigendian);
646 v = (int) readuint(f, bigendian);
651 fprintf(src, "%d ", v);
658 comp->bpp = int_floorlog2(max) + 1;
663 /* -->> -->> -->> -->>
667 <<-- <<-- <<-- <<-- */
669 int pnmtoimage(char *filename, j2k_image_t * img, int subsampling_dx,
670 int subsampling_dy, int Dim[2])
673 FILE *Compo0, *Compo1, *Compo2;
679 f = fopen(filename, "rb");
682 "\033[0;33mFailed to open %s for reading !!\033[0;39m\n",
693 if (fgetc(f) == '#') {
694 fseek(f, 0, SEEK_SET);
696 fgets(comment, 256, f);
697 fscanf(f, "%d %d\n255", &w, &h);
699 fseek(f, 0, SEEK_SET);
700 fscanf(f, "P2\n%d %d\n255", &w, &h);
707 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
711 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
716 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
717 img->comps[0].prec = 8;
718 img->comps[0].bpp = 8;
719 img->comps[0].sgnd = 0;
720 img->comps[0].dx = subsampling_dx;
721 img->comps[0].dy = subsampling_dy;
723 Compo0 = fopen("Compo0", "wb");
726 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
728 for (i = 0; i < w * h; i++) {
731 fprintf(Compo0, "%c", l);
734 } else if (value == '5') {
736 if (fgetc(f) == '#') {
737 fseek(f, 0, SEEK_SET);
739 fgets(comment, 256, f);
740 fscanf(f, "%d %d\n255", &w, &h);
742 fseek(f, 0, SEEK_SET);
743 fscanf(f, "P5\n%d %d\n255", &w, &h);
750 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
754 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
759 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
760 img->comps[0].prec = 8;
761 img->comps[0].bpp = 8;
762 img->comps[0].sgnd = 0;
763 img->comps[0].dx = subsampling_dx;
764 img->comps[0].dy = subsampling_dy;
765 Compo0 = fopen("Compo0", "wb");
768 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
770 for (i = 0; i < w * h; i++) {
773 fwrite(&l, 1, 1, Compo0);
776 } else if (value == '3') {
778 if (fgetc(f) == '#') {
779 fseek(f, 0, SEEK_SET);
781 fgets(comment, 256, f);
782 fscanf(f, "%d %d\n255", &w, &h);
784 fseek(f, 0, SEEK_SET);
785 fscanf(f, "P3\n%d %d\n255", &w, &h);
792 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
796 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
800 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
801 for (i = 0; i < img->numcomps; i++) {
802 img->comps[i].prec = 8;
803 img->comps[i].bpp = 8;
804 img->comps[i].sgnd = 0;
805 img->comps[i].dx = subsampling_dx;
806 img->comps[i].dy = subsampling_dy;
808 Compo0 = fopen("Compo0", "wb");
811 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
814 Compo1 = fopen("Compo1", "wb");
817 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
820 Compo2 = fopen("Compo2", "wb");
823 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
826 for (i = 0; i < w * h; i++) {
827 unsigned int r, g, b;
831 fprintf(Compo0, "%c", r);
832 fprintf(Compo1, "%c", g);
833 fprintf(Compo2, "%c", b);
838 } else if (value == '6') {
840 if (fgetc(f) == '#') {
841 fseek(f, 0, SEEK_SET);
843 fgets(comment, 256, f);
844 fscanf(f, "%d %d\n255", &w, &h);
846 fseek(f, 0, SEEK_SET);
847 fscanf(f, "P6\n%d %d\n255", &w, &h);
854 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
858 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
862 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
863 for (i = 0; i < img->numcomps; i++) {
864 img->comps[i].prec = 8;
865 img->comps[i].bpp = 8;
866 img->comps[i].sgnd = 0;
867 img->comps[i].dx = subsampling_dx;
868 img->comps[i].dy = subsampling_dy;
870 Compo0 = fopen("Compo0", "wb");
873 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
876 Compo1 = fopen("Compo1", "wb");
879 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
882 Compo2 = fopen("Compo2", "wb");
885 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
888 for (i = 0; i < w * h; i++) {
889 unsigned char r, g, b;
893 fwrite(&r, 1, 1, Compo0);
894 fwrite(&g, 1, 1, Compo1);
895 fwrite(&b, 1, 1, Compo2);