_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<w; j++)
+ {
+ if(((_i/8)+(j/8))%2==0) buf[w*i+j]=255;
+ else buf[w*i+j]=76;
+ }
+ }
+ for(_i=16; _i<h; _i++)
+ {
+ if(flags&TJ_BOTTOMUP) i=h-_i-1; else i=_i;
+ for(j=0; j<w; j++)
+ {
+ if(((_i/8)+(j/8))%2==0) buf[w*i+j]=0;
+ else buf[w*i+j]=226;
+ }
+ }
+ return;
+ }
for(_i=0; _i<16; _i++)
{
if(flags&TJ_BOTTOMUP) i=h-_i-1; else i=_i;
int roffset=(flags&TJ_BGR)?2:0, goffset=1, boffset=(flags&TJ_BGR)?0:2, i,
_i, j;
if(flags&TJ_ALPHAFIRST) {roffset++; goffset++; boffset++;}
+ if(ps==1) roffset=goffset=boffset=0;
if(subsamp==TJ_GRAYSCALE)
{
for(_i=0; _i<16; _i++)
if(ps==3) pixformat="RGB";
else {if(flags&TJ_ALPHAFIRST) pixformat="ARGB"; else pixformat="RGBA";}
}
+ if(ps==1) pixformat="Grayscale";
printf("%s %s -> %s Q%d ... ", pixformat,
(flags&TJ_BOTTOMUP)?"Bottom-Up":"Top-Down ", _subnamel[subsamp], qual);
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));
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);
{
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();
/* 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)
|| 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;
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))
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;
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))