{
unsigned char *bmpbuf=NULL;
const char *pixformat; int _hdrw=0, _hdrh=0, _hdrsubsamp=-1; double t;
- unsigned long size=0;
- int hsf=_hsf[subsamp], vsf=_vsf[subsamp];
- int pw=PAD(w, hsf), ph=PAD(h, vsf);
int _w=(w+scalefactor-1)/scalefactor, _h=(h+scalefactor-1)/scalefactor;
- int cw=pw/hsf, ch=ph/vsf;
- int ypitch=PAD(pw, 4), uvpitch=PAD(cw, 4);
+ unsigned long size=0;
if(yuv==YUVDECODE) flags|=TJ_YUV;
else if(yuv==YUVENCODE) return;
}
if(yuv==YUVDECODE)
- size=ypitch*ph + (subsamp==TJ_GRAYSCALE? 0:uvpitch*ch*2);
+ size=TJBUFSIZEYUV(w, h, subsamp);
else
size=_w*_h*ps;
if((bmpbuf=(unsigned char *)malloc(size+1))==NULL)
if(yuv==YUVDECODE)
{
- if(checkbufyuv(bmpbuf, size, pw, ph, subsamp))
+ if(checkbufyuv(bmpbuf, size, w, h, subsamp))
printf("Passed.");
else {printf("FAILED!"); exitstatus=-1;}
}
unsigned char *dstbuf, unsigned long *size,
int jpegsubsamp, int jpegqual, int flags);
+/*
+ unsigned long TJBUFSIZE(int width, int height)
+
+ Convenience function which returns the maximum size of the buffer required to
+ hold a JPEG image with the given width and height
+
+ RETURNS: -1 if arguments are out of bounds
+*/
DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height);
+/*
+ unsigned long TJBUFSIZEYUV(int width, int height, int subsamp)
+
+ Convenience function which returns the size of the buffer required to
+ hold a YUV planar image with the given width, height, and level of
+ chrominance subsampling
+
+ RETURNS: -1 if arguments are out of bounds
+*/
+DLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height,
+ int subsamp);
+
/*
tjhandle tjInitDecompress(void)
DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height)
{
- // This allows enough room in case the image doesn't compress
- return ((width+15)&(~15)) * ((height+15)&(~15)) * 6 + 2048;
+ unsigned long retval=0;
+ if(width<1 || height<1)
+ _throw("Invalid argument in TJBUFSIZE()");
+
+ // This allows for rare corner cases in which a JPEG image can actually be
+ // larger than the uncompressed input (we wouldn't mention it if it hadn't
+ // happened.)
+ retval=((width+15)&(~15)) * ((height+15)&(~15)) * 6 + 2048;
+
+ bailout:
+ return retval;
+}
+
+DLLEXPORT unsigned long DLLCALL TJBUFSIZEYUV(int width, int height,
+ int subsamp)
+{
+ unsigned long retval=0;
+ int pw, ph, cw, ch;
+ if(width<1 || height<1 || subsamp<0 || subsamp>=NUMSUBOPT)
+ _throw("Invalid argument in TJBUFSIZEYUV()");
+ pw=PAD(width, hsampfactor[subsamp]);
+ ph=PAD(height, vsampfactor[subsamp]);
+ cw=pw/hsampfactor[subsamp]; ch=ph/vsampfactor[subsamp];
+ retval=PAD(pw, 4)*ph + (subsamp==TJ_GRAYSCALE? 0:PAD(cw, 4)*ch*2);
+
+ bailout:
+ return retval;
}
DLLEXPORT int DLLCALL tjCompress(tjhandle h,