#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#define JPEG_INTERNALS
#include <jpeglib.h>
#include <jerror.h>
#include <setjmp.h>
+#include <jinclude.h>
#include "./turbojpeg.h"
#include "./rrutil.h"
#include "transupp.h"
int init;
} tjinstance;
-static const int pixelsize[NUMSUBOPT]={3, 3, 3, 1, 3};
+static const int pixelsize[TJ_NUMSAMP]={3, 3, 3, 1, 3};
-static const JXFORM_CODE xformtypes[TJ_NUMXOP]={
+static const JXFORM_CODE xformtypes[TJ_NUMXOP]=
+{
JXFORM_NONE, JXFORM_FLIP_H, JXFORM_FLIP_V, JXFORM_TRANSPOSE,
JXFORM_TRANSVERSE, JXFORM_ROT_90, JXFORM_ROT_180, JXFORM_ROT_270
};
/* Make an initial call so it will create the destination manager */
jpeg_mem_dest_tj(&this->cinfo, &buf, &size, 0);
- this->init=COMPRESS;
+ this->init|=COMPRESS;
return (tjhandle)this;
}
tjinstance *this=NULL;
if((this=(tjinstance *)malloc(sizeof(tjinstance)))==NULL)
{
- snprintf(errStr, JMSG_LENGTH_MAX, "Memory allocation failure");
+ snprintf(errStr, JMSG_LENGTH_MAX,
+ "tjInitCompress(): Memory allocation failure");
return NULL;
}
- memset(this, 0, sizeof(tjinstance));
+ MEMZERO(this, sizeof(tjinstance));
return _tjInitCompress(this);
}
{
unsigned long retval=0;
if(width<1 || height<1)
- _throw("Invalid argument in TJBUFSIZE()");
+ _throw("TJBUFSIZE(): Invalid argument");
// 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 before.)
- retval=((width+15)&(~15)) * ((height+15)&(~15)) * 6 + 2048;
+ retval=PAD(width, 16) * PAD(height, 16) * 6 + 2048;
bailout:
return retval;
unsigned long retval=0;
int pw, ph, cw, ch;
if(width<1 || height<1 || subsamp<0 || subsamp>=NUMSUBOPT)
- _throw("Invalid argument in TJBUFSIZEYUV()");
+ _throw("TJBUFSIZEYUV(): Invalid argument");
pw=PAD(width, tjMCUWidth[subsamp]/8);
ph=PAD(height, tjMCUHeight[subsamp]/8);
cw=pw*8/tjMCUWidth[subsamp]; ch=ph*8/tjMCUHeight[subsamp];
getinstance(handle)
if((this->init&COMPRESS)==0)
- _throw("Instance has not been initialized for compression");
+ _throw("tjCompress2(): Instance has not been initialized for compression");
if(srcBuf==NULL || width<=0 || pitch<0 || height<=0 || pixelFormat<0
|| pixelFormat>=TJ_NUMPF || jpegBuf==NULL || jpegSize==NULL
|| jpegSubsamp<0 || jpegSubsamp>=NUMSUBOPT || jpegQual<0 || jpegQual>100)
- _throw("tjCompress(): Invalid argument");
+ _throw("tjCompress2(): Invalid argument");
if(setjmp(this->jerr.setjmp_buffer))
{
jpeg_start_compress(cinfo, TRUE);
if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*height))==NULL)
- _throw("Memory allocation failed in tjCompress()");
+ _throw("tjCompress2(): Memory allocation failure");
for(i=0; i<height; i++)
{
if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pitch];
getinstance(handle);
if((this->init&COMPRESS)==0)
- _throw("Instance has not been initialized for compression");
+ _throw("tjEncodeYUV2(): Instance has not been initialized for compression");
for(i=0; i<MAX_COMPONENTS; i++)
{
ph=PAD(height, cinfo->max_v_samp_factor);
if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL)
- _throw("Memory allocation failed in tjCompress()");
+ _throw("tjEncodeYUV2(): Memory allocation failure");
for(i=0; i<height; i++)
{
if(flags&TJFLAG_BOTTOMUP) row_pointer[i]=&srcBuf[(height-i-1)*pitch];
_tmpbuf[i]=(JSAMPLE *)malloc(
PAD((compptr->width_in_blocks*cinfo->max_h_samp_factor*DCTSIZE)
/compptr->h_samp_factor, 16) * cinfo->max_v_samp_factor + 16);
- if(!_tmpbuf[i]) _throw("Memory allocation failure");
+ if(!_tmpbuf[i]) _throw("tjEncodeYUV2(): Memory allocation failure");
tmpbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*cinfo->max_v_samp_factor);
- if(!tmpbuf[i]) _throw("Memory allocation failure");
+ if(!tmpbuf[i]) _throw("tjEncodeYUV2(): Memory allocation failure");
for(row=0; row<cinfo->max_v_samp_factor; row++)
{
unsigned char *_tmpbuf_aligned=
}
_tmpbuf2[i]=(JSAMPLE *)malloc(PAD(compptr->width_in_blocks*DCTSIZE, 16)
* compptr->v_samp_factor + 16);
- if(!_tmpbuf2[i]) _throw("Memory allocation failure");
+ if(!_tmpbuf2[i]) _throw("tjEncodeYUV2(): Memory allocation failure");
tmpbuf2[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*compptr->v_samp_factor);
- if(!tmpbuf2[i]) _throw("Memory allocation failure");
+ if(!tmpbuf2[i]) _throw("tjEncodeYUV2(): Memory allocation failure");
for(row=0; row<compptr->v_samp_factor; row++)
{
unsigned char *_tmpbuf2_aligned=
cw[i]=pw*compptr->h_samp_factor/cinfo->max_h_samp_factor;
ch[i]=ph*compptr->v_samp_factor/cinfo->max_v_samp_factor;
outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]);
- if(!outbuf[i]) _throw("Memory allocation failure");
+ if(!outbuf[i]) _throw("tjEncodeYUV2(): Memory allocation failure");
for(row=0; row<ch[i]; row++)
{
outbuf[i][row]=ptr;
/* Make an initial call so it will create the source manager */
jpeg_mem_src_tj(&this->dinfo, buffer, 1);
- this->init=DECOMPRESS;
+ this->init|=DECOMPRESS;
return (tjhandle)this;
}
tjinstance *this;
if((this=(tjinstance *)malloc(sizeof(tjinstance)))==NULL)
{
- snprintf(errStr, JMSG_LENGTH_MAX, "Memory allocation failure");
+ snprintf(errStr, JMSG_LENGTH_MAX,
+ "tjInitDecompress(): Memory allocation failure");
return NULL;
}
- memset(this, 0, sizeof(tjinstance));
+ MEMZERO(this, sizeof(tjinstance));
return _tjInitDecompress(this);
}
getinstance(handle);
if((this->init&DECOMPRESS)==0)
- _throw("Instance has not been initialized for decompression");
+ _throw("tjDecompressHeader2(): Instance has not been initialized for decompression");
if(jpegBuf==NULL || jpegSize<=0 || width==NULL || height==NULL
|| jpegSubsamp==NULL)
jpeg_abort_decompress(dinfo);
if(*jpegSubsamp<0)
- _throw("Could not determine subsampling type for JPEG image");
- if(*width<1 || *height<1) _throw("Invalid data returned in header");
+ _throw("tjDecompressHeader2(): Could not determine subsampling type for JPEG image");
+ if(*width<1 || *height<1)
+ _throw("tjDecompressHeader2(): Invalid data returned in header");
bailout:
return retval;
if(numscalingfactors==NULL)
{
snprintf(errStr, JMSG_LENGTH_MAX,
- "Invalid argument in tjGetScalingFactors()");
+ "tjGetScalingFactors(): Invalid argument");
return NULL;
}
getinstance(handle);
if((this->init&DECOMPRESS)==0)
- _throw("Instance has not been initialized for decompression");
+ _throw("tjDecompress2(): Instance has not been initialized for decompression");
if(jpegBuf==NULL || jpegSize<=0 || dstBuf==NULL || width<0 || pitch<0
|| height<0 || pixelFormat<0 || pixelFormat>=TJ_NUMPF)
break;
}
if(scaledw>width || scaledh>height)
- _throw("Could not scale down to desired image dimensions");
+ _throw("tjDecompress2(): Could not scale down to desired image dimensions");
width=scaledw; height=scaledh;
dinfo->scale_num=sf[i].num;
dinfo->scale_denom=sf[i].denom;
if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat];
if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)
*dinfo->output_height))==NULL)
- _throw("Memory allocation failed in tjInitDecompress()");
+ _throw("tjDecompress2(): Memory allocation failure");
for(i=0; i<(int)dinfo->output_height; i++)
{
if(flags&TJFLAG_BOTTOMUP)
getinstance(handle);
if((this->init&DECOMPRESS)==0)
- _throw("Instance has not been initialized for decompression");
+ _throw("tjDecompressToYUV(): Instance has not been initialized for decompression");
for(i=0; i<MAX_COMPONENTS; i++)
{
th[i]=compptr->v_samp_factor*DCTSIZE;
tmpbufsize+=iw[i]*th[i];
if((outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]))==NULL)
- _throw("Memory allocation failed in tjDecompress()");
+ _throw("tjDecompressToYUV(): Memory allocation failure");
for(row=0; row<ch[i]; row++)
{
outbuf[i][row]=ptr;
if(usetmpbuf)
{
if((_tmpbuf=(JSAMPLE *)malloc(sizeof(JSAMPLE)*tmpbufsize))==NULL)
- _throw("Memory allocation failed in tjDecompress()");
+ _throw("tjDecompressToYUV(): Memory allocation failure");
ptr=_tmpbuf;
for(i=0; i<dinfo->num_components; i++)
{
if((tmpbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*th[i]))==NULL)
- _throw("Memory allocation failed in tjDecompress()");
+ _throw("tjDecompressToYUV(): Memory allocation failure");
for(row=0; row<th[i]; row++)
{
tmpbuf[i][row]=ptr;
tjinstance *this=NULL; tjhandle handle=NULL;
if((this=(tjinstance *)malloc(sizeof(tjinstance)))==NULL)
{
- snprintf(errStr, JMSG_LENGTH_MAX, "Memory allocation failure");
+ snprintf(errStr, JMSG_LENGTH_MAX,
+ "tjInitTransform(): Memory allocation failure");
return NULL;
}
- memset(this, 0, sizeof(tjinstance));
+ MEMZERO(this, sizeof(tjinstance));
handle=_tjInitCompress(this);
if(!handle) return NULL;
handle=_tjInitDecompress(this);
getinstance(handle);
if((this->init&COMPRESS)==0 || (this->init&DECOMPRESS)==0)
- _throw("Instance has not been initialized for transformation");
+ _throw("tjTransform(): Instance has not been initialized for transformation");
if(jpegBuf==NULL || jpegSize<=0 || n<1 || dstBufs==NULL || dstSizes==NULL
|| t==NULL || flags<0)
if((xinfo=(jpeg_transform_info *)malloc(sizeof(jpeg_transform_info)*n))
==NULL)
- _throw("Memory allocation failed in tjTransform()");
- memset(xinfo, 0, sizeof(jpeg_transform_info)*n);
+ _throw("tjTransform(): Memory allocation failure");
+ MEMZERO(xinfo, sizeof(jpeg_transform_info)*n);
for(i=0; i<n; i++)
{
for(i=0; i<n; i++)
{
if(!jtransform_request_workspace(dinfo, &xinfo[i]))
- _throw("Transform is not perfect");
+ _throw("tjTransform(): Transform is not perfect");
if(xinfo[i].crop)
{