X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fbin%2Fjp2%2Fconvertbmp.c;h=2715fdf2411cad1724928ced819d0e1159234f3b;hb=2cd30c2b06ce332dede81cccad8b334cde997281;hp=0bc9c9f352f2bf906c955a9986cff57c865117e9;hpb=28d2eabca79d06378843d1e94fecfb4a5e22178d;p=openjpeg.git diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c index 0bc9c9f3..2715fdf2 100644 --- a/src/bin/jp2/convertbmp.c +++ b/src/bin/jp2/convertbmp.c @@ -56,7 +56,7 @@ typedef struct { typedef struct { OPJ_UINT32 biSize; /* Size of the structure in bytes */ OPJ_UINT32 biWidth; /* Width of the image in pixels */ - OPJ_UINT32 biHeight; /* Heigth of the image in pixels */ + OPJ_UINT32 biHeight; /* Height of the image in pixels */ OPJ_UINT16 biPlanes; /* 1 */ OPJ_UINT16 biBitCount; /* Number of color bits by pixels */ OPJ_UINT32 biCompression; /* Type of encoding 0: none 1: RLE8 2: RLE4 */ @@ -392,6 +392,10 @@ static OPJ_BOOL bmp_read_info_header(FILE* IN, OPJ_BITMAPINFOHEADER* header) header->biBitCount = (OPJ_UINT16)getc(IN); header->biBitCount |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); + if (header->biBitCount == 0) { + fprintf(stderr, "Error, invalid biBitCount %d\n", 0); + return OPJ_FALSE; + } if (header->biSize >= 40U) { header->biCompression = (OPJ_UINT32)getc(IN); @@ -832,7 +836,8 @@ int imagetobmp(opj_image_t * image, const char *outfile) int adjustR, adjustG, adjustB; if (image->comps[0].prec < 8) { - fprintf(stderr, "Unsupported number of components: %d\n", image->comps[0].prec); + fprintf(stderr, "imagetobmp: Unsupported precision: %d\n", + image->comps[0].prec); return 1; } if (image->numcomps >= 3 && image->comps[0].dx == image->comps[1].dx @@ -840,7 +845,9 @@ int imagetobmp(opj_image_t * image, const char *outfile) && image->comps[0].dy == image->comps[1].dy && image->comps[1].dy == image->comps[2].dy && image->comps[0].prec == image->comps[1].prec - && image->comps[1].prec == image->comps[2].prec) { + && image->comps[1].prec == image->comps[2].prec + && image->comps[0].sgnd == image->comps[1].sgnd + && image->comps[1].sgnd == image->comps[2].sgnd) { /* -->> -->> -->> -->> 24 bits color @@ -926,7 +933,9 @@ int imagetobmp(opj_image_t * image, const char *outfile) r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + if (adjustR > 0) { + r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + } if (r > 255) { r = 255; } else if (r < 0) { @@ -936,7 +945,9 @@ int imagetobmp(opj_image_t * image, const char *outfile) g = image->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - g = ((g >> adjustG) + ((g >> (adjustG - 1)) % 2)); + if (adjustG > 0) { + g = ((g >> adjustG) + ((g >> (adjustG - 1)) % 2)); + } if (g > 255) { g = 255; } else if (g < 0) { @@ -946,7 +957,9 @@ int imagetobmp(opj_image_t * image, const char *outfile) b = image->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - b = ((b >> adjustB) + ((b >> (adjustB - 1)) % 2)); + if (adjustB > 0) { + b = ((b >> adjustB) + ((b >> (adjustB - 1)) % 2)); + } if (b > 255) { b = 255; } else if (b < 0) { @@ -974,6 +987,10 @@ int imagetobmp(opj_image_t * image, const char *outfile) fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); return 1; } + if (image->numcomps > 1) { + fprintf(stderr, "imagetobmp: only first component of %d is used.\n", + image->numcomps); + } w = (int)image->comps[0].w; h = (int)image->comps[0].h; @@ -1037,7 +1054,9 @@ int imagetobmp(opj_image_t * image, const char *outfile) r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + if (adjustR > 0) { + r = ((r >> adjustR) + ((r >> (adjustR - 1)) % 2)); + } if (r > 255) { r = 255; } else if (r < 0) {