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.
36 /* -->> -->> -->> -->>
40 <<-- <<-- <<-- <<-- */
42 /* UINT2 defines a two byte word */
43 typedef unsigned short int UINT2;
45 /* UINT4 defines a four byte word */
46 typedef unsigned long int UINT4;
49 UINT2 bfType; /* 'BM' for Bitmap (19776) */
50 UINT4 bfSize; /* Size of the file */
51 UINT2 bfReserved1; /* Reserved : 0 */
52 UINT2 bfReserved2; /* Reserved : 0 */
53 UINT4 bfOffBits; /* Offset */
57 UINT4 biSize; /* Size of the structure in bytes */
58 UINT4 biWidth; /* Width of the image in pixels */
59 UINT4 biHeight; /* Heigth of the image in pixels */
60 UINT2 biPlanes; /* 1 */
61 UINT2 biBitCount; /* Number of color bits by pixels */
62 UINT4 biCompression; /* Type of encoding 0: none 1: RLE8 2: RLE4 */
63 UINT4 biSizeImage; /* Size of the image in bytes */
64 UINT4 biXpelsPerMeter; /* Horizontal (X) resolution in pixels/meter */
65 UINT4 biYpelsPerMeter; /* Vertical (Y) resolution in pixels/meter */
66 UINT4 biClrUsed; /* Number of color used in the image (0: ALL) */
67 UINT4 biClrImportant; /* Number of important color (0: ALL) */
70 int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, 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");
85 fprintf(stderr, "\033[0;33mFailed to open %s for reading !!\033[0;39m\n", filename);
89 File_h.bfType = getc(IN);
90 File_h.bfType = (getc(IN) << 8) + File_h.bfType;
92 if (File_h.bfType != 19778) {
93 printf("Error, not a BMP file!\n");
98 File_h.bfSize = getc(IN);
99 File_h.bfSize = (getc(IN) << 8) + File_h.bfSize;
100 File_h.bfSize = (getc(IN) << 16) + File_h.bfSize;
101 File_h.bfSize = (getc(IN) << 24) + File_h.bfSize;
103 File_h.bfReserved1 = getc(IN);
104 File_h.bfReserved1 = (getc(IN) << 8) + File_h.bfReserved1;
106 File_h.bfReserved2 = getc(IN);
107 File_h.bfReserved2 = (getc(IN) << 8) + File_h.bfReserved2;
109 File_h.bfOffBits = getc(IN);
110 File_h.bfOffBits = (getc(IN) << 8) + File_h.bfOffBits;
111 File_h.bfOffBits = (getc(IN) << 16) + File_h.bfOffBits;
112 File_h.bfOffBits = (getc(IN) << 24) + File_h.bfOffBits;
117 Info_h.biSize = getc(IN);
118 Info_h.biSize = (getc(IN) << 8) + Info_h.biSize;
119 Info_h.biSize = (getc(IN) << 16) + Info_h.biSize;
120 Info_h.biSize = (getc(IN) << 24) + Info_h.biSize;
122 Info_h.biWidth = getc(IN);
123 Info_h.biWidth = (getc(IN) << 8) + Info_h.biWidth;
124 Info_h.biWidth = (getc(IN) << 16) + Info_h.biWidth;
125 Info_h.biWidth = (getc(IN) << 24) + Info_h.biWidth;
128 Info_h.biHeight = getc(IN);
129 Info_h.biHeight = (getc(IN) << 8) + Info_h.biHeight;
130 Info_h.biHeight = (getc(IN) << 16) + Info_h.biHeight;
131 Info_h.biHeight = (getc(IN) << 24) + Info_h.biHeight;
134 Info_h.biPlanes = getc(IN);
135 Info_h.biPlanes = (getc(IN) << 8) + Info_h.biPlanes;
137 Info_h.biBitCount = getc(IN);
138 Info_h.biBitCount = (getc(IN) << 8) + Info_h.biBitCount;
140 Info_h.biCompression = getc(IN);
141 Info_h.biCompression = (getc(IN) << 8) + Info_h.biCompression;
142 Info_h.biCompression = (getc(IN) << 16) + Info_h.biCompression;
143 Info_h.biCompression = (getc(IN) << 24) + Info_h.biCompression;
145 Info_h.biSizeImage = getc(IN);
146 Info_h.biSizeImage = (getc(IN) << 8) + Info_h.biSizeImage;
147 Info_h.biSizeImage = (getc(IN) << 16) + Info_h.biSizeImage;
148 Info_h.biSizeImage = (getc(IN) << 24) + Info_h.biSizeImage;
150 Info_h.biXpelsPerMeter = getc(IN);
151 Info_h.biXpelsPerMeter = (getc(IN) << 8) + Info_h.biXpelsPerMeter;
152 Info_h.biXpelsPerMeter = (getc(IN) << 16) + Info_h.biXpelsPerMeter;
153 Info_h.biXpelsPerMeter = (getc(IN) << 24) + Info_h.biXpelsPerMeter;
155 Info_h.biYpelsPerMeter = getc(IN);
156 Info_h.biYpelsPerMeter = (getc(IN) << 8) + Info_h.biYpelsPerMeter;
157 Info_h.biYpelsPerMeter = (getc(IN) << 16) + Info_h.biYpelsPerMeter;
158 Info_h.biYpelsPerMeter = (getc(IN) << 24) + Info_h.biYpelsPerMeter;
160 Info_h.biClrUsed = getc(IN);
161 Info_h.biClrUsed = (getc(IN) << 8) + Info_h.biClrUsed;
162 Info_h.biClrUsed = (getc(IN) << 16) + Info_h.biClrUsed;
163 Info_h.biClrUsed = (getc(IN) << 24) + Info_h.biClrUsed;
165 Info_h.biClrImportant = getc(IN);
166 Info_h.biClrImportant = (getc(IN) << 8) + Info_h.biClrImportant;
167 Info_h.biClrImportant = (getc(IN) << 16) + Info_h.biClrImportant;
168 Info_h.biClrImportant = (getc(IN) << 24) + Info_h.biClrImportant;
170 /* Read the data and store them in the OUT file */
172 if (Info_h.biBitCount == 24) {
175 img->x1 = !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w - 1) * subsampling_dx + 1;
176 img->y1 = !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h - 1) * subsampling_dy + 1;
178 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
179 for (i = 0; i < img->numcomps; i++) {
180 img->comps[i].prec = 8;
181 img->comps[i].bpp = 8;
182 img->comps[i].sgnd = 0;
183 img->comps[i].dx = subsampling_dx;
184 img->comps[i].dy = subsampling_dy;
186 Compo0 = fopen("Compo0", "wb");
188 fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
190 Compo1 = fopen("Compo1", "wb");
192 fprintf(stderr, "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
194 Compo2 = fopen("Compo2", "wb");
196 fprintf(stderr, "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
199 /* Place the cursor at the beginning of the image information */
200 fseek(IN, 0, SEEK_SET);
201 fseek(IN, File_h.bfOffBits, SEEK_SET);
206 PAD = 4 - (3 * W) % 4;
208 RGB = (unsigned char *) malloc((3 * W + PAD) * H * sizeof(unsigned char));
210 fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN);
212 for (i = 0; i < (3 * W + PAD) * H; i++)
215 int Wp = 3 * W + PAD;
217 elmt = RGB[(H - (i/Wp + 1)) * Wp + i % Wp];
218 if ((i % Wp) < (3 * W))
223 fprintf(Compo2, "%c", elmt);
227 fprintf(Compo1, "%c", elmt);
231 fprintf(Compo0, "%c", elmt);
242 } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 0) {
245 img->x1 = !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w - 1) * subsampling_dx + 1;
246 img->y1 = !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h - 1) * subsampling_dy + 1;
248 table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
249 table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
250 table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
252 for (i = 0; i < Info_h.biClrUsed; i++) {
253 table_B[i] = getc(IN);
254 table_G[i] = getc(IN);
255 table_R[i] = getc(IN);
257 if (table_R[i] != table_G[i] && table_R[i] != table_B[i] && table_G[i] != table_B[i])
261 /* Place the cursor at the beginning of the image information */
262 fseek(IN, 0, SEEK_SET);
263 fseek(IN, File_h.bfOffBits, SEEK_SET);
267 if (Info_h.biWidth % 2)
270 RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char));
272 fread(RGB, sizeof(unsigned char), W * H, IN);
275 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
276 img->comps[0].prec = 8;
277 img->comps[0].bpp = 8;
278 img->comps[0].sgnd = 0;
279 img->comps[0].dx = subsampling_dx;
280 img->comps[0].dy = subsampling_dy;
281 Compo0 = fopen("Compo0", "wb");
283 fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
285 for (i = 0; i < W * H; i++) {
286 if ((i % W < W - 1 && Info_h.biWidth % 2) || !(Info_h.biWidth % 2))
287 fprintf(Compo0, "%c", table_R[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
292 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
293 for (i = 0; i < img->numcomps; i++) {
294 img->comps[i].prec = 8;
295 img->comps[i].bpp = 8;
296 img->comps[i].sgnd = 0;
297 img->comps[i].dx = subsampling_dx;
298 img->comps[i].dy = subsampling_dy;
301 Compo0 = fopen("Compo0", "wb");
303 fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
305 Compo1 = fopen("Compo1", "wb");
307 fprintf(stderr, "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
309 Compo2 = fopen("Compo2", "wb");
311 fprintf(stderr, "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
314 for (i = 0; i < W * H; i++) {
315 if ((i % W < W - 1 && Info_h.biWidth % 2) || !(Info_h.biWidth % 2)) {
316 fprintf(Compo0, "%c", table_R[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
317 fprintf(Compo1, "%c", table_G[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
318 fprintf(Compo2, "%c", table_B[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
328 } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) {
331 img->x1 = !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w - 1) * subsampling_dx + 1;
332 img->y1 = !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h - 1) * subsampling_dy + 1;
334 table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
335 table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
336 table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
338 for (i = 0; i < Info_h.biClrUsed; i++) {
339 table_B[i] = getc(IN);
340 table_G[i] = getc(IN);
341 table_R[i] = getc(IN);
343 if (table_R[i] != table_G[i] && table_R[i] != table_B[i] && table_G[i] != table_B[i])
347 /* Place the cursor at the beginning of the image information */
348 fseek(IN, 0, SEEK_SET);
349 fseek(IN, File_h.bfOffBits, SEEK_SET);
353 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
354 img->comps[0].prec = 8;
355 img->comps[0].bpp = 8;
356 img->comps[0].sgnd = 0;
357 img->comps[0].dx = subsampling_dx;
358 img->comps[0].dy = subsampling_dy;
359 Compo0 = fopen("Compo0", "wb");
361 fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
365 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
366 for (i = 0; i < img->numcomps; i++) {
367 img->comps[i].prec = 8;
368 img->comps[i].bpp = 8;
369 img->comps[i].sgnd = 0;
370 img->comps[i].dx = subsampling_dx;
371 img->comps[i].dy = subsampling_dy;
373 Compo0 = fopen("Compo0", "wb");
375 fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
377 Compo1 = fopen("Compo1", "wb");
379 fprintf(stderr, "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
381 Compo2 = fopen("Compo2", "wb");
383 fprintf(stderr, "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
387 RGB = (unsigned char *) malloc(Info_h.biWidth * Info_h.biHeight * sizeof(unsigned char));
389 while (not_end_file) {
393 for (i = 0; i < (int) v; i++) {
394 RGB[line * Info_h.biWidth + col] = v2;
409 printf("No Delta supported\n");
413 for (i = 0; i < v; i++) {
415 RGB[line * Info_h.biWidth + col] = v2;
424 for (line = 0; line < Info_h.biHeight; line++)
425 for (col = 0; col < Info_h.biWidth; col++)
426 fprintf(Compo0, "%c", table_R[(int)RGB[(Info_h.biHeight - line - 1) * Info_h.biWidth + col]]);
429 for (line = 0; line < Info_h.biHeight; line++)
430 for (col = 0; col < Info_h.biWidth; col++) {
431 fprintf(Compo0, "%c", table_R[(int)RGB[(Info_h.biHeight - line - 1) * Info_h.biWidth + col]]);
432 fprintf(Compo1, "%c", table_G[(int)RGB[(Info_h.biHeight - line - 1) * Info_h.biWidth + col]]);
433 fprintf(Compo2, "%c", table_B[(int)RGB[(Info_h.biHeight - line - 1) * Info_h.biWidth + col]]);
441 fprintf(stderr,"Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n",
449 /* -->> -->> -->> -->>
453 <<-- <<-- <<-- <<-- */
456 unsigned char readuchar(FILE * f)
463 unsigned short readushort(FILE * f, int bigendian)
465 unsigned char c1, c2;
469 return (c1 << 8) + c2;
471 return (c2 << 8) + c1;
474 unsigned int readuint(FILE * f, int bigendian)
476 unsigned char c1, c2, c3, c4;
482 return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4;
484 return (c4 << 24) + (c3 << 16) + (c2 << 8) + c1;
487 int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
488 int subsampling_dx, int subsampling_dy, int Dim[2],
493 int i, compno, bandno;
494 char str[256], endian[16];
500 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
501 for (compno = 0; compno < img->numcomps; compno++) {
506 comp = &img->comps[compno];
507 sprintf(str, "%s", filename);
508 f = fopen(str, "rb");
510 fprintf(stderr, "Failed to open %s for reading !\n", str);
513 if (fscanf(f, "PG %s %c %d %d %d", endian, &sign, &prec, &w, &h) == 5)
516 if (!strcmp(endian, "ML"))
524 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
528 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
532 if (w != img->x1 || h != img->y1)
542 comp->dx = subsampling_dx;
543 comp->dy = subsampling_dy;
547 cp.ty0 + bandno * cp.tdy <
548 img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
551 sprintf(tmp, "bandtile%d", bandno); /* bandtile file */
552 src = fopen(tmp, "wb");
554 fprintf(stderr, "failed to open %s for writing !\n", tmp);
556 for (i = 0; i < w * h; i++) {
558 if (i == Y1 * w / subsampling_dy && tdy != -1) { /* bandtile is full */
561 sprintf(tmp, "bandtile%d", bandno);
562 src = fopen(tmp, "wb");
564 fprintf(stderr, "failed to open %s for writing !\n", tmp);
567 cp.ty0 + bandno * cp.tdy <
568 img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
571 if (comp->prec <= 8) {
575 v = (char) readuchar(f);
577 } else if (comp->prec <= 16) {
579 v = readushort(f, bigendian);
581 v = (short) readushort(f, bigendian);
585 v = readuint(f, bigendian);
587 v = (int) readuint(f, bigendian);
592 fprintf(src, "%d ", v);
599 comp->bpp = int_floorlog2(max) + 1;
604 /* -->> -->> -->> -->>
608 <<-- <<-- <<-- <<-- */
610 int pnmtoimage(char *filename, j2k_image_t * img, int subsampling_dx,
611 int subsampling_dy, int Dim[2])
614 FILE *Compo0, *Compo1, *Compo2;
620 f = fopen(filename, "rb");
623 "\033[0;33mFailed to open %s for reading !!\033[0;39m\n",
634 if (fgetc(f) == '#') {
635 fseek(f, 0, SEEK_SET);
637 fgets(comment, 256, f);
638 fscanf(f, "%d %d\n255", &w, &h);
640 fseek(f, 0, SEEK_SET);
641 fscanf(f, "P2\n%d %d\n255", &w, &h);
648 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
652 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
657 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
658 img->comps[0].prec = 8;
659 img->comps[0].bpp = 8;
660 img->comps[0].sgnd = 0;
661 img->comps[0].dx = subsampling_dx;
662 img->comps[0].dy = subsampling_dy;
664 Compo0 = fopen("Compo0", "wb");
667 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
669 for (i = 0; i < w * h; i++) {
672 fprintf(Compo0, "%c", l);
675 } else if (value == '5') {
677 if (fgetc(f) == '#') {
678 fseek(f, 0, SEEK_SET);
680 fgets(comment, 256, f);
681 fscanf(f, "%d %d\n255", &w, &h);
683 fseek(f, 0, SEEK_SET);
684 fscanf(f, "P5\n%d %d\n255", &w, &h);
691 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
695 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
700 img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
701 img->comps[0].prec = 8;
702 img->comps[0].bpp = 8;
703 img->comps[0].sgnd = 0;
704 img->comps[0].dx = subsampling_dx;
705 img->comps[0].dy = subsampling_dy;
706 Compo0 = fopen("Compo0", "wb");
709 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
711 for (i = 0; i < w * h; i++) {
714 fwrite(&l, 1, 1, Compo0);
717 } else if (value == '3') {
719 if (fgetc(f) == '#') {
720 fseek(f, 0, SEEK_SET);
722 fgets(comment, 256, f);
723 fscanf(f, "%d %d\n255", &w, &h);
725 fseek(f, 0, SEEK_SET);
726 fscanf(f, "P3\n%d %d\n255", &w, &h);
733 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
737 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
741 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
742 for (i = 0; i < img->numcomps; i++) {
743 img->comps[i].prec = 8;
744 img->comps[i].bpp = 8;
745 img->comps[i].sgnd = 0;
746 img->comps[i].dx = subsampling_dx;
747 img->comps[i].dy = subsampling_dy;
749 Compo0 = fopen("Compo0", "wb");
752 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
755 Compo1 = fopen("Compo1", "wb");
758 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
761 Compo2 = fopen("Compo2", "wb");
764 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
767 for (i = 0; i < w * h; i++) {
768 unsigned int r, g, b;
772 fprintf(Compo0, "%c", r);
773 fprintf(Compo1, "%c", g);
774 fprintf(Compo2, "%c", b);
779 } else if (value == '6') {
781 if (fgetc(f) == '#') {
782 fseek(f, 0, SEEK_SET);
784 fgets(comment, 256, f);
785 fscanf(f, "%d %d\n255", &w, &h);
787 fseek(f, 0, SEEK_SET);
788 fscanf(f, "P6\n%d %d\n255", &w, &h);
795 !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
799 !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
803 img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
804 for (i = 0; i < img->numcomps; i++) {
805 img->comps[i].prec = 8;
806 img->comps[i].bpp = 8;
807 img->comps[i].sgnd = 0;
808 img->comps[i].dx = subsampling_dx;
809 img->comps[i].dy = subsampling_dy;
811 Compo0 = fopen("Compo0", "wb");
814 "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
817 Compo1 = fopen("Compo1", "wb");
820 "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
823 Compo2 = fopen("Compo2", "wb");
826 "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
829 for (i = 0; i < w * h; i++) {
830 unsigned char r, g, b;
834 fwrite(&r, 1, 1, Compo0);
835 fwrite(&g, 1, 1, Compo1);
836 fwrite(&b, 1, 1, Compo2);