From e817c077797e7629ae62d990749493d6e7f661bf Mon Sep 17 00:00:00 2001 From: DRC Date: Sun, 19 Nov 2017 08:43:07 -0600 Subject: [PATCH] tjLoadImage(): return TJPF_GRAY for grayscale BMPs ... if *pixelFormat=TJPF_UNKNOWN is passed to the function. --- rdbmp.c | 3 +++ tjunittest.c | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/rdbmp.c b/rdbmp.c index 44a6258..e1c1208 100644 --- a/rdbmp.c +++ b/rdbmp.c @@ -133,6 +133,9 @@ read_colormap (bmp_source_ptr sinfo, int cmaplen, int mapentrysize) break; } + if (sinfo->cinfo->in_color_space == JCS_UNKNOWN && gray) + sinfo->cinfo->in_color_space = JCS_GRAYSCALE; + if (sinfo->cinfo->in_color_space == JCS_GRAYSCALE && !gray) ERREXIT(sinfo->cinfo, JERR_BAD_IN_COLORSPACE); } diff --git a/tjunittest.c b/tjunittest.c index e723a4f..f7d6e61 100644 --- a/tjunittest.c +++ b/tjunittest.c @@ -792,7 +792,7 @@ int doBmpTest(const char *ext, int width, int align, int height, int pf, { char filename[80], *md5sum, md5buf[65]; int ps=tjPixelSize[pf], pitch=PAD(width*ps, align), - loadWidth=0, loadHeight=0, retval=0; + loadWidth=0, loadHeight=0, retval=0, pixelFormat=pf; unsigned char *buf=NULL; char *md5ref; @@ -858,6 +858,22 @@ int doBmpTest(const char *ext, int width, int align, int height, int pf, retval=-1; goto bailout; } } + /* Verify that tjLoadImage() returns the proper "preferred" pixel format for + the file type. */ + tjFree(buf); buf=NULL; + pf=pixelFormat; + pixelFormat=TJPF_UNKNOWN; + if((buf=tjLoadImage(filename, &loadWidth, align, &loadHeight, &pixelFormat, + flags))==NULL) + _throwtj(); + if((pf==TJPF_GRAY && pixelFormat!=TJPF_GRAY) || + (pf!=TJPF_GRAY && !strcasecmp(ext, "bmp") && pixelFormat!=TJPF_BGR) || + (pf!=TJPF_GRAY && !strcasecmp(ext, "ppm") && pixelFormat!=TJPF_RGB)) + { + printf("\n tjLoadImage() returned unexpected pixel format: %s\n", + pixFormatStr[pixelFormat]); + retval=-1; + } unlink(filename); bailout: -- 2.40.0