From 09854f57dcb615f2fff0c5b1bc1e28670d6892ac Mon Sep 17 00:00:00 2001 From: DRC Date: Thu, 4 Nov 2010 22:39:59 +0000 Subject: [PATCH] Grayscale bitmap support in TurboJPEG/OSS git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@288 632fc199-4ca6-4c93-a231-07263d6284db --- ChangeLog.txt | 2 ++ jpegut.c | 28 ++++++++++++++++++++++++++++ turbojpegl.c | 14 +++++++++----- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 5f485d5..1cabc2c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,8 @@ README-turbo.txt for more details. This feature was sponsored by CamTrace SAS. [2] Created a new CMake-based build system for the Visual C++ and MinGW builds. +[3] TurboJPEG/OSS can now compress from/decompress to grayscale bitmaps. + Significant changes since 1.0.0 =============================== diff --git a/jpegut.c b/jpegut.c index cec0f72..db46b6d 100644 --- a/jpegut.c +++ b/jpegut.c @@ -46,6 +46,28 @@ void initbuf(unsigned char *buf, int w, int h, int ps, int flags) _i, j; if(flags&TJ_ALPHAFIRST) {roffset++; goffset++; boffset++;} memset(buf, 0, w*h*ps); + if(ps==1) + { + for(_i=0; _i<16; _i++) + { + if(flags&TJ_BOTTOMUP) i=h-_i-1; else i=_i; + for(j=0; j %s Q%d ... ", pixformat, (flags&TJ_BOTTOMUP)?"Bottom-Up":"Top-Down ", _subnamel[subsamp], qual); @@ -247,6 +271,7 @@ void gentestbmp(tjhandle hnd, unsigned char *jpegbuf, unsigned long jpegsize, if(ps==3) pixformat="RGB"; else {if(flags&TJ_ALPHAFIRST) pixformat="ARGB"; else pixformat="RGBA";} } + if(ps==1) pixformat="Grayscale"; printf("JPEG -> %s %s ... ", pixformat, (flags&TJ_BOTTOMUP)?"Bottom-Up":"Top-Down "); _catch(tjDecompressHeader(hnd, jpegbuf, jpegsize, &_w, &_h)); @@ -292,6 +317,8 @@ void dotest(int w, int h, int ps, int subsamp, char *basefilename) gentestjpeg(hnd, jpegbuf, &size, w, h, ps, basefilename, subsamp, 100, 0); gentestbmp(dhnd, jpegbuf, size, w, h, ps, basefilename, subsamp, 100, 0); + if(ps==1) goto finally; + gentestjpeg(hnd, jpegbuf, &size, w, h, ps, basefilename, subsamp, 100, TJ_BGR); gentestbmp(dhnd, jpegbuf, size, w, h, ps, basefilename, subsamp, 100, TJ_BGR); @@ -379,6 +406,7 @@ int main(int argc, char *argv[]) { dotest(35, 41, 3, TJ_444, "test"); dotest(35, 41, 4, TJ_444, "test"); + dotest(35, 41, 1, TJ_GRAYSCALE, "test"); dotest(35, 41, 3, TJ_GRAYSCALE, "test"); dotest(35, 41, 4, TJ_GRAYSCALE, "test"); dotest1(); diff --git a/turbojpegl.c b/turbojpegl.c index c3694c8..03833c5 100644 --- a/turbojpegl.c +++ b/turbojpegl.c @@ -1,6 +1,6 @@ /* Copyright (C)2004 Landmark Graphics Corporation * Copyright (C)2005 Sun Microsystems, Inc. - * Copyright (C)2009 D. R. Commander + * Copyright (C)2009-2010 D. R. Commander * * This library is free software and may be redistributed and/or modified under * the terms of the wxWindows Library License, Version 3.1 or (at your option) @@ -124,7 +124,8 @@ DLLEXPORT int DLLCALL tjCompress(tjhandle h, || dstbuf==NULL || size==NULL || jpegsub<0 || jpegsub>=NUMSUBOPT || qual<0 || qual>100) _throw("Invalid argument in tjCompress()"); - if(ps!=3 && ps!=4) _throw("This compressor can only take 24-bit or 32-bit RGB input"); + if(ps!=3 && ps!=4 && ps!=1) + _throw("This compressor can only handle 24-bit and 32-bit RGB or 8-bit grayscale input"); if(!j->initc) _throw("Instance has not been initialized for compression"); if(pitch==0) pitch=width*ps; @@ -133,8 +134,9 @@ DLLEXPORT int DLLCALL tjCompress(tjhandle h, j->cinfo.image_height = height; j->cinfo.input_components = ps; + if(ps==1) j->cinfo.in_color_space = JCS_GRAYSCALE; #if JCS_EXTENSIONS==1 - j->cinfo.in_color_space = JCS_EXT_RGB; + else j->cinfo.in_color_space = JCS_EXT_RGB; if(ps==3 && (flags&TJ_BGR)) j->cinfo.in_color_space = JCS_EXT_BGR; else if(ps==4 && !(flags&TJ_BGR) && !(flags&TJ_ALPHAFIRST)) @@ -287,7 +289,8 @@ DLLEXPORT int DLLCALL tjDecompress(tjhandle h, if(srcbuf==NULL || size<=0 || dstbuf==NULL || width<=0 || pitch<0 || height<=0) _throw("Invalid argument in tjDecompress()"); - if(ps!=3 && ps!=4) _throw("This compressor can only take 24-bit or 32-bit RGB input"); + if(ps!=3 && ps!=4 && ps!=1) + _throw("This decompressor can only handle 24-bit and 32-bit RGB or 8-bit grayscale output"); if(!j->initd) _throw("Instance has not been initialized for decompression"); if(pitch==0) pitch=width*ps; @@ -315,8 +318,9 @@ DLLEXPORT int DLLCALL tjDecompress(tjhandle h, else row_pointer[i]= &dstbuf[i*pitch]; } + if(ps==1) j->dinfo.out_color_space = JCS_GRAYSCALE; #if JCS_EXTENSIONS==1 - j->dinfo.out_color_space = JCS_EXT_RGB; + else j->dinfo.out_color_space = JCS_EXT_RGB; if(ps==3 && (flags&TJ_BGR)) j->dinfo.out_color_space = JCS_EXT_BGR; else if(ps==4 && !(flags&TJ_BGR) && !(flags&TJ_ALPHAFIRST)) -- 2.40.0