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 -
269 (unsigned char *) malloc(256 * sizeof(unsigned char));
271 (unsigned char *) malloc(256 * sizeof(unsigned char));
273 (unsigned char *) malloc(256 * sizeof(unsigned char));
275 for (i = 0; i < Info_h.biClrUsed; i++) {
276 table_B[i] = getc(IN);
277 table_G[i] = getc(IN);
278 table_R[i] = getc(IN);
280 if (table_R[i] != table_G[i] && table_R[i] != table_B[i]
281 && table_G[i] != table_B[i])
285 /* Place the cursor at the beginning of the image information */
286 fseek(IN, 0, SEEK_SET);
287 fseek(IN, File_h.bfOffBits, SEEK_SET);
291 if (Info_h.biWidth % 2)
294 RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char));
296 fread(RGB, sizeof(unsigned char), W * H, IN);
300 (j2k_comp_t *) malloc(img->numcomps *
302 img->comps[0].prec = 8;
303 img->comps[0].bpp = 8;
304 img->comps[0].sgnd = 0;
305 img->comps[0].dx = subsampling_dx;
306 img->comps[0].dy = subsampling_dy;
307 Compo0 = fopen("Compo0", "wb");
310 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
312 for (i = 0; i < W * H; i++) {
313 if ((i % W < W - 1 && Info_h.biWidth % 2)
314 || !(Info_h.biWidth % 2))
315 fprintf(Compo0, "%c",
317 [W * H - ((i) / (W) + 1) * W +
324 (j2k_comp_t *) malloc(img->numcomps *
326 for (i = 0; i < img->numcomps; i++) {
327 img->comps[i].prec = 8;
328 img->comps[i].bpp = 8;
329 img->comps[i].sgnd = 0;
330 img->comps[i].dx = subsampling_dx;
331 img->comps[i].dy = subsampling_dy;
334 Compo0 = fopen("Compo0", "wb");
337 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
339 Compo1 = fopen("Compo1", "wb");
342 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
344 Compo2 = fopen("Compo2", "wb");
347 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
350 for (i = 0; i < W * H; i++) {
351 if ((i % W < W - 1 && Info_h.biWidth % 2)
352 || !(Info_h.biWidth % 2)) {
353 fprintf(Compo0, "%c",
355 [W * H - ((i) / (W) + 1) * W +
357 fprintf(Compo1, "%c",
359 [W * H - ((i) / (W) + 1) * W +
361 fprintf(Compo2, "%c",
363 [W * H - ((i) / (W) + 1) * W +
374 } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) {
378 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
382 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
387 (unsigned char *) malloc(256 * sizeof(unsigned char));
389 (unsigned char *) malloc(256 * sizeof(unsigned char));
391 (unsigned char *) malloc(256 * sizeof(unsigned char));
393 for (i = 0; i < Info_h.biClrUsed; i++) {
394 table_B[i] = getc(IN);
395 table_G[i] = getc(IN);
396 table_R[i] = getc(IN);
398 if (table_R[i] != table_G[i] && table_R[i] != table_B[i]
399 && table_G[i] != table_B[i])
403 /* Place the cursor at the beginning of the image information */
404 fseek(IN, 0, SEEK_SET);
405 fseek(IN, File_h.bfOffBits, SEEK_SET);
409 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
410 img->comps[0].prec = 8;
411 img->comps[0].bpp = 8;
412 img->comps[0].sgnd = 0;
413 img->comps[0].dx = subsampling_dx;
414 img->comps[0].dy = subsampling_dy;
415 Compo0 = fopen("Compo0", "wb");
418 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
423 (j2k_comp_t *) malloc(img->numcomps *
425 for (i = 0; i < img->numcomps; i++) {
426 img->comps[i].prec = 8;
427 img->comps[i].bpp = 8;
428 img->comps[i].sgnd = 0;
429 img->comps[i].dx = subsampling_dx;
430 img->comps[i].dy = subsampling_dy;
432 Compo0 = fopen("Compo0", "wb");
435 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
437 Compo1 = fopen("Compo1", "wb");
440 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
442 Compo2 = fopen("Compo2", "wb");
445 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
450 (unsigned char *) malloc(Info_h.biWidth * Info_h.biHeight *
451 sizeof(unsigned char));
453 while (not_end_file) {
457 for (i = 0; i < (int) v; i++) {
458 RGB[line * Info_h.biWidth + col] = v2;
473 printf("No Delta supported\n");
477 for (i = 0; i < v; i++) {
479 RGB[line * Info_h.biWidth + col] = v2;
488 for (line = 0; line < Info_h.biHeight; line++)
489 for (col = 0; col < Info_h.biWidth; col++)
490 fprintf(Compo0, "%c",
492 RGB[(Info_h.biHeight - line -
493 1) * Info_h.biWidth + col]]);
496 for (line = 0; line < Info_h.biHeight; line++)
497 for (col = 0; col < Info_h.biWidth; col++) {
498 fprintf(Compo0, "%c",
500 RGB[(Info_h.biHeight - line -
501 1) * Info_h.biWidth + col]]);
502 fprintf(Compo1, "%c",
504 RGB[(Info_h.biHeight - line -
505 1) * Info_h.biWidth + col]]);
506 fprintf(Compo2, "%c",
508 RGB[(Info_h.biHeight - line -
509 1) * Info_h.biWidth + col]]);
518 "Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n",
526 /* -->> -->> -->> -->>
530 <<-- <<-- <<-- <<-- */
533 unsigned char readuchar(FILE * f)
540 unsigned short readushort(FILE * f, int bigendian)
542 unsigned char c1, c2;
546 return (c1 << 8) + c2;
548 return (c2 << 8) + c1;
551 unsigned int readuint(FILE * f, int bigendian)
553 unsigned char c1, c2, c3, c4;
559 return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4;
561 return (c4 << 24) + (c3 << 16) + (c2 << 8) + c1;
564 int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
565 int subsampling_dx, int subsampling_dy, int Dim[2],
570 int i, compno, bandno;
571 char str[256], endian[16];
577 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
578 for (compno = 0; compno < img->numcomps; compno++) {
583 comp = &img->comps[compno];
584 sprintf(str, "%s", filename);
585 f = fopen(str, "rb");
587 fprintf(stderr, "Failed to open %s for reading !\n", str);
590 if (fscanf(f, "PG %s %c %d %d %d", endian, &sign, &prec, &w, &h) ==
593 if (!strcmp(endian, "ML"))
601 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
605 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
609 if (w != img->x1 || h != img->y1)
619 comp->dx = subsampling_dx;
620 comp->dy = subsampling_dy;
623 Y1 = cp.ty0 + bandno * cp.tdy <
624 img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
627 sprintf(tmp, "bandtile%d", bandno); /* bandtile file */
628 src = fopen(tmp, "wb");
630 fprintf(stderr, "failed to open %s for writing !\n", tmp);
632 for (i = 0; i < w * h; i++) {
634 if (i == Y1 * w / subsampling_dy && tdy != -1) { /* bandtile is full */
637 sprintf(tmp, "bandtile%d", bandno);
638 src = fopen(tmp, "wb");
641 "failed to open %s for writing !\n", tmp);
643 Y1 = cp.ty0 + bandno * cp.tdy <
644 img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
647 if (comp->prec <= 8) {
651 v = (char) readuchar(f);
653 } else if (comp->prec <= 16) {
655 v = readushort(f, bigendian);
657 v = (short) readushort(f, bigendian);
661 v = readuint(f, bigendian);
663 v = (int) readuint(f, bigendian);
668 fprintf(src, "%d ", v);
675 comp->bpp = int_floorlog2(max) + 1;
680 /* -->> -->> -->> -->>
684 <<-- <<-- <<-- <<-- */
686 int pnmtoimage(char *filename, j2k_image_t * img, int subsampling_dx,
687 int subsampling_dy, int Dim[2])
690 FILE *Compo0, *Compo1, *Compo2;
696 f = fopen(filename, "rb");
699 "\033[0;33mFailed to open %s for reading !!\033[0;39m\n",
710 if (fgetc(f) == '#') {
711 fseek(f, 0, SEEK_SET);
713 fgets(comment, 256, f);
714 fscanf(f, "%d %d\n255", &w, &h);
716 fseek(f, 0, SEEK_SET);
717 fscanf(f, "P2\n%d %d\n255", &w, &h);
724 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
728 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
733 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
734 img->comps[0].prec = 8;
735 img->comps[0].bpp = 8;
736 img->comps[0].sgnd = 0;
737 img->comps[0].dx = subsampling_dx;
738 img->comps[0].dy = subsampling_dy;
740 Compo0 = fopen("Compo0", "wb");
743 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
745 for (i = 0; i < w * h; i++) {
748 fprintf(Compo0, "%c", l);
751 } else if (value == '5') {
753 if (fgetc(f) == '#') {
754 fseek(f, 0, SEEK_SET);
756 fgets(comment, 256, f);
757 fscanf(f, "%d %d\n255", &w, &h);
759 fseek(f, 0, SEEK_SET);
760 fscanf(f, "P5\n%d %d\n255", &w, &h);
767 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
771 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
776 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
777 img->comps[0].prec = 8;
778 img->comps[0].bpp = 8;
779 img->comps[0].sgnd = 0;
780 img->comps[0].dx = subsampling_dx;
781 img->comps[0].dy = subsampling_dy;
782 Compo0 = fopen("Compo0", "wb");
785 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
787 for (i = 0; i < w * h; i++) {
790 fwrite(&l, 1, 1, Compo0);
793 } else if (value == '3') {
795 if (fgetc(f) == '#') {
796 fseek(f, 0, SEEK_SET);
798 fgets(comment, 256, f);
799 fscanf(f, "%d %d\n255", &w, &h);
801 fseek(f, 0, SEEK_SET);
802 fscanf(f, "P3\n%d %d\n255", &w, &h);
809 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
813 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
818 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
819 for (i = 0; i < img->numcomps; i++) {
820 img->comps[i].prec = 8;
821 img->comps[i].bpp = 8;
822 img->comps[i].sgnd = 0;
823 img->comps[i].dx = subsampling_dx;
824 img->comps[i].dy = subsampling_dy;
826 Compo0 = fopen("Compo0", "wb");
829 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
832 Compo1 = fopen("Compo1", "wb");
835 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
838 Compo2 = fopen("Compo2", "wb");
841 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
844 for (i = 0; i < w * h; i++) {
845 unsigned int r, g, b;
849 fprintf(Compo0, "%c", r);
850 fprintf(Compo1, "%c", g);
851 fprintf(Compo2, "%c", b);
856 } else if (value == '6') {
858 if (fgetc(f) == '#') {
859 fseek(f, 0, SEEK_SET);
861 fgets(comment, 256, f);
862 fscanf(f, "%d %d\n255", &w, &h);
864 fseek(f, 0, SEEK_SET);
865 fscanf(f, "P6\n%d %d\n255", &w, &h);
872 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
876 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
881 (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
882 for (i = 0; i < img->numcomps; i++) {
883 img->comps[i].prec = 8;
884 img->comps[i].bpp = 8;
885 img->comps[i].sgnd = 0;
886 img->comps[i].dx = subsampling_dx;
887 img->comps[i].dy = subsampling_dy;
889 Compo0 = fopen("Compo0", "wb");
892 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
895 Compo1 = fopen("Compo1", "wb");
898 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
901 Compo2 = fopen("Compo2", "wb");
904 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
907 for (i = 0; i < w * h; i++) {
908 unsigned char r, g, b;
912 fwrite(&r, 1, 1, Compo0);
913 fwrite(&g, 1, 1, Compo1);
914 fwrite(&b, 1, 1, Compo2);