BITMAPINFOHEADER_t Info_h;
unsigned char *RGB;
unsigned char *table_R, *table_G, *table_B;
- int i, w, h, PAD, type = 0;
- int gray_scale = 1, not_end_file = 1, line = 0, col = 0;
+ unsigned int j, w, h, PAD, type = 0;
+
+ int i;
+ int gray_scale = 1, not_end_file = 1;
+
+ unsigned int line = 0, col = 0;
unsigned char v, v2;
UINT4 W, H;
File_h.bfType = (getc(IN) << 8) + File_h.bfType;
if (File_h.bfType != 19778) {
- printf("Error, not a BMP file!\n");
+ fprintf(stderr,"Error, not a BMP file!\n");
return 0;
} else {
/* FILE HEADER */
1) *
subsampling_dy + 1;
img->numcomps = 3;
+ img->color_space = 1;
img->comps =
(j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
for (i = 0; i < img->numcomps; i++) {
fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN);
- for (i = 0; i < (3 * W + PAD) * H; i++) {
+ for (j = 0; j < (3 * W + PAD) * H; j++) {
unsigned char elmt;
int Wp = 3 * W + PAD;
- elmt = RGB[(H - (i / Wp + 1)) * Wp + i % Wp];
- if ((i % Wp) < (3 * W)) {
+ elmt = RGB[(H - (j / Wp + 1)) * Wp + j % Wp];
+ if ((j % Wp) < (3 * W)) {
switch (type) {
case 0:
fprintf(Compo2, "%c", elmt);
table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
- for (i = 0; i < Info_h.biClrUsed; i++) {
- table_B[i] = getc(IN);
- table_G[i] = getc(IN);
- table_R[i] = getc(IN);
+ for (j = 0; j < Info_h.biClrUsed; j++) {
+ table_B[j] = getc(IN);
+ table_G[j] = getc(IN);
+ table_R[j] = getc(IN);
getc(IN);
- if (table_R[i] != table_G[i] && table_R[i] != table_B[i]
- && table_G[i] != table_B[i])
+ if (table_R[j] != table_G[j] && table_R[j] != table_B[j]
+ && table_G[j] != table_B[j])
gray_scale = 0;
}
fprintf(stderr,
"\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
}
- for (i = 0; i < W * H; i++) {
- if ((i % W < W - 1 && Info_h.biWidth % 2)
+ for (j = 0; j < W * H; j++) {
+ if ((j % W < W - 1 && Info_h.biWidth % 2)
|| !(Info_h.biWidth % 2))
fprintf(Compo0, "%c",
- table_R[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
+ table_R[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]);
}
fclose(Compo0);
} else {
"\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
}
- for (i = 0; i < W * H; i++) {
- if ((i % W < W - 1 && Info_h.biWidth % 2)
+ for (j = 0; j < W * H; j++) {
+ if ((j % W < W - 1 && Info_h.biWidth % 2)
|| !(Info_h.biWidth % 2)) {
fprintf(Compo0, "%c",
- table_R[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
+ table_R[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]);
fprintf(Compo1, "%c",
- table_G[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
+ table_G[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]);
fprintf(Compo2, "%c",
- table_B[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
+ table_B[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]);
}
}
table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
- for (i = 0; i < Info_h.biClrUsed; i++) {
- table_B[i] = getc(IN);
- table_G[i] = getc(IN);
- table_R[i] = getc(IN);
+ for (j = 0; j < Info_h.biClrUsed; j++) {
+ table_B[j] = getc(IN);
+ table_G[j] = getc(IN);
+ table_R[j] = getc(IN);
getc(IN);
- if (table_R[i] != table_G[i] && table_R[i] != table_B[i]
- && table_G[i] != table_B[i])
+ if (table_R[j] != table_G[j] && table_R[j] != table_B[j]
+ && table_G[j] != table_B[j])
gray_scale = 0;
}
not_end_file = 0;
break;
case 2:
- printf("No Delta supported\n");
+ fprintf(stderr,"No Delta supported\n");
return 1;
break;
default:
FILE *f;
int w, h, prec;
int i, compno, bandno;
- char str[256], endian[16];
- char sign;
+ char str[256];
+
+ char endian1,endian2,sign;
+ char signtmp[32];
+
+ char temp[32];
int bigendian;
j2k_comp_t *comp;
img->numcomps = 1;
+ img->color_space = 2;
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
for (compno = 0; compno < img->numcomps; compno++) {
FILE *src;
char tmp[16];
int max = 0;
int Y1;
+
+
comp = &img->comps[compno];
sprintf(str, "%s", filename);
+
+
f = fopen(str, "rb");
if (!f) {
fprintf(stderr, "Failed to open %s for reading !\n", str);
return 0;
}
- if (fscanf(f, "PG %s %c %d %d %d", endian, &sign, &prec, &w, &h) == 5) {
- fgetc(f);
- if (!strcmp(endian, "ML"))
- bigendian = 1;
- else
- bigendian = 0;
- if (compno == 0) {
- img->x0 = Dim[0];
- img->y0 = Dim[1];
- img->x1 =
- !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
- 1) *
- subsampling_dx + 1;
- img->y1 =
- !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
- 1) *
- subsampling_dy + 1;
- } else {
- if (w != img->x1 || h != img->y1)
- return 0;
- }
- if (sign == '-') {
- comp->sgnd = 1;
- } else {
- comp->sgnd = 0;
- }
- comp->prec = prec;
- comp->dx = subsampling_dx;
- comp->dy = subsampling_dy;
- bandno = 1;
-
- Y1 = cp.ty0 + bandno * cp.tdy <
- img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
- Y1 -= img->y0;
-
- sprintf(tmp, "bandtile%d", bandno); /* bandtile file */
- src = fopen(tmp, "wb");
- if (!src) {
- fprintf(stderr, "failed to open %s for writing !\n", tmp);
+
+
+ fseek(f, 0, SEEK_SET);
+
+ fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h);
+
+
+
+ i=0;
+
+ sign='+';
+
+ while (signtmp[i]!='\0') {
+
+ if (signtmp[i]=='-') sign='-';
+
+ i++;
+
+ }
+
+
+
+ fgetc(f);
+ if (endian1=='M' && endian2=='L')
+ bigendian = 1;
+ else if (endian2=='M' && endian1=='L')
+ bigendian = 0;
+
+ else {
+
+ fprintf(stderr, "Bad pgx header, please check input file\n", str);
+
+ return 0;
+
+ }
+
+
+ if (compno == 0) {
+ img->x0 = Dim[0];
+ img->y0 = Dim[1];
+ img->x1 =
+ !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
+ 1) *
+ subsampling_dx + 1;
+ img->y1 =
+ !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
+ 1) *
+ subsampling_dy + 1;
+ } else {
+ if (w != img->x1 || h != img->y1)
+ return 0;
+ }
+
+ if (sign == '-') {
+ comp->sgnd = 1;
+ } else {
+ comp->sgnd = 0;
+ }
+ comp->prec = prec;
+ comp->dx = subsampling_dx;
+ comp->dy = subsampling_dy;
+ bandno = 1;
+
+ Y1 = cp.ty0 + bandno * cp.tdy <
+ img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
+ Y1 -= img->y0;
+
+ sprintf(tmp, "bandtile%d", bandno); /* bandtile file */
+ src = fopen(tmp, "wb");
+ if (!src) {
+ fprintf(stderr, "failed to open %s for writing !\n", tmp);
+ }
+ for (i = 0; i < w * h; i++) {
+ int v;
+ if (i == Y1 * w / subsampling_dy && tdy != -1) { /* bandtile is full */
+ fclose(src);
+ bandno++;
+ sprintf(tmp, "bandtile%d", bandno);
+ src = fopen(tmp, "wb");
+ if (!src) {
+ fprintf(stderr, "failed to open %s for writing !\n", tmp);
+ }
+ Y1 = cp.ty0 + bandno * cp.tdy <
+ img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
+ Y1 -= img->y0;
}
- for (i = 0; i < w * h; i++) {
- int v;
- if (i == Y1 * w / subsampling_dy && tdy != -1) { /* bandtile is full */
- fclose(src);
- bandno++;
- sprintf(tmp, "bandtile%d", bandno);
- src = fopen(tmp, "wb");
- if (!src) {
- fprintf(stderr, "failed to open %s for writing !\n", tmp);
- }
- Y1 = cp.ty0 + bandno * cp.tdy <
- img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
- Y1 -= img->y0;
+ if (comp->prec <= 8) {
+ if (!comp->sgnd) {
+ v = readuchar(f);
+ } else {
+ v = (char) readuchar(f);
}
- if (comp->prec <= 8) {
- if (!comp->sgnd) {
- v = readuchar(f);
- } else {
- v = (char) readuchar(f);
- }
- } else if (comp->prec <= 16) {
- if (!comp->sgnd) {
- v = readushort(f, bigendian);
- } else {
- v = (short) readushort(f, bigendian);
- }
+ } else if (comp->prec <= 16) {
+ if (!comp->sgnd) {
+ v = readushort(f, bigendian);
} else {
- if (!comp->sgnd) {
- v = readuint(f, bigendian);
- } else {
- v = (int) readuint(f, bigendian);
- }
+ v = (short) readushort(f, bigendian);
+ }
+ } else {
+ if (!comp->sgnd) {
+ v = readuint(f, bigendian);
+ } else {
+ v = (int) readuint(f, bigendian);
}
- if (v > max)
- max = v;
- fprintf(src, "%d ", v);
}
- } else {
- return 0;
+ if (v > max)
+ max = v;
+ fprintf(src, "%d ", v);
}
fclose(f);
fclose(src);
subsampling_dy + 1;
img->numcomps = 1;
+ img->color_space = 2;
img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
img->comps[0].prec = 8;
img->comps[0].bpp = 8;
subsampling_dy + 1;
img->numcomps = 1;
+ img->color_space = 2;
img->comps = (j2k_comp_t *) malloc(sizeof(j2k_comp_t));
img->comps[0].prec = 8;
img->comps[0].bpp = 8;
1) *
subsampling_dy + 1;
img->numcomps = 3;
+ img->color_space = 1;
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
for (i = 0; i < img->numcomps; i++) {
img->comps[i].prec = 8;
1) *
subsampling_dy + 1;
img->numcomps = 3;
+ img->color_space = 1;
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
for (i = 0; i < img->numcomps; i++) {
img->comps[i].prec = 8;