Eliminate all of the __memalign() mess and just handle the alignment ourselves
This commit is contained in:
54
turbojpegl.c
54
turbojpegl.c
@@ -23,32 +23,6 @@
|
|||||||
#include <jerror.h>
|
#include <jerror.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include "./turbojpeg.h"
|
#include "./turbojpeg.h"
|
||||||
#ifdef sun
|
|
||||||
#include <malloc.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void *__memalign(size_t boundary, size_t size)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
return _aligned_malloc(size, boundary);
|
|
||||||
#else
|
|
||||||
#ifdef __APPLE__
|
|
||||||
return malloc(size);
|
|
||||||
#else
|
|
||||||
#ifdef sun
|
|
||||||
return memalign(boundary, size);
|
|
||||||
#else
|
|
||||||
void *ptr=NULL;
|
|
||||||
posix_memalign(&ptr, boundary, size);
|
|
||||||
return ptr;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
#define _aligned_free(addr) free(addr)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef min
|
#ifndef min
|
||||||
#define min(a,b) ((a)<(b)?(a):(b))
|
#define min(a,b) ((a)<(b)?(a):(b))
|
||||||
@@ -204,9 +178,9 @@ DLLEXPORT int DLLCALL tjCompress(tjhandle h,
|
|||||||
for(i=0; i<MAX_COMPONENTS; i++)
|
for(i=0; i<MAX_COMPONENTS; i++)
|
||||||
{
|
{
|
||||||
if(tmpbuf[i]!=NULL) free(tmpbuf[i]);
|
if(tmpbuf[i]!=NULL) free(tmpbuf[i]);
|
||||||
if(_tmpbuf[i]!=NULL) _aligned_free(_tmpbuf[i]);
|
if(_tmpbuf[i]!=NULL) free(_tmpbuf[i]);
|
||||||
if(tmpbuf2[i]!=NULL) free(tmpbuf2[i]);
|
if(tmpbuf2[i]!=NULL) free(tmpbuf2[i]);
|
||||||
if(_tmpbuf2[i]!=NULL) _aligned_free(_tmpbuf2[i]);
|
if(_tmpbuf2[i]!=NULL) free(_tmpbuf2[i]);
|
||||||
if(outbuf[i]!=NULL) free(outbuf[i]);
|
if(outbuf[i]!=NULL) free(outbuf[i]);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
@@ -255,24 +229,32 @@ DLLEXPORT int DLLCALL tjCompress(tjhandle h,
|
|||||||
for(i=0; i<cinfo->num_components; i++)
|
for(i=0; i<cinfo->num_components; i++)
|
||||||
{
|
{
|
||||||
compptr=&cinfo->comp_info[i];
|
compptr=&cinfo->comp_info[i];
|
||||||
_tmpbuf[i]=(JSAMPLE *)__memalign(16,
|
_tmpbuf[i]=(JSAMPLE *)malloc(
|
||||||
PAD((compptr->width_in_blocks*cinfo->max_h_samp_factor*DCTSIZE)
|
PAD((compptr->width_in_blocks*cinfo->max_h_samp_factor*DCTSIZE)
|
||||||
/compptr->h_samp_factor, 16) * cinfo->max_v_samp_factor);
|
/compptr->h_samp_factor, 16) * cinfo->max_v_samp_factor + 16);
|
||||||
if(!_tmpbuf[i]) _throw("Memory allocation failure");
|
if(!_tmpbuf[i]) _throw("Memory allocation failure");
|
||||||
tmpbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*cinfo->max_v_samp_factor);
|
tmpbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*cinfo->max_v_samp_factor);
|
||||||
if(!tmpbuf[i]) _throw("Memory allocation failure");
|
if(!tmpbuf[i]) _throw("Memory allocation failure");
|
||||||
for(row=0; row<cinfo->max_v_samp_factor; row++)
|
for(row=0; row<cinfo->max_v_samp_factor; row++)
|
||||||
tmpbuf[i][row]=&_tmpbuf[i][
|
{
|
||||||
|
unsigned char *_tmpbuf_aligned=
|
||||||
|
(unsigned char *)PAD((size_t)_tmpbuf[i], 16);
|
||||||
|
tmpbuf[i][row]=&_tmpbuf_aligned[
|
||||||
PAD((compptr->width_in_blocks*cinfo->max_h_samp_factor*DCTSIZE)
|
PAD((compptr->width_in_blocks*cinfo->max_h_samp_factor*DCTSIZE)
|
||||||
/compptr->h_samp_factor, 16) * row];
|
/compptr->h_samp_factor, 16) * row];
|
||||||
_tmpbuf2[i]=(JSAMPLE *)__memalign(16,
|
}
|
||||||
PAD(compptr->width_in_blocks*DCTSIZE, 16) * compptr->v_samp_factor);
|
_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("Memory allocation failure");
|
||||||
tmpbuf2[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*compptr->v_samp_factor);
|
tmpbuf2[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*compptr->v_samp_factor);
|
||||||
if(!tmpbuf2[i]) _throw("Memory allocation failure");
|
if(!tmpbuf2[i]) _throw("Memory allocation failure");
|
||||||
for(row=0; row<compptr->v_samp_factor; row++)
|
for(row=0; row<compptr->v_samp_factor; row++)
|
||||||
tmpbuf2[i][row]=&_tmpbuf2[i][
|
{
|
||||||
|
unsigned char *_tmpbuf2_aligned=
|
||||||
|
(unsigned char *)PAD((size_t)_tmpbuf2[i], 16);
|
||||||
|
tmpbuf2[i][row]=&_tmpbuf2_aligned[
|
||||||
PAD(compptr->width_in_blocks*DCTSIZE, 16) * row];
|
PAD(compptr->width_in_blocks*DCTSIZE, 16) * row];
|
||||||
|
}
|
||||||
cw[i]=pw*compptr->h_samp_factor/cinfo->max_h_samp_factor;
|
cw[i]=pw*compptr->h_samp_factor/cinfo->max_h_samp_factor;
|
||||||
ch[i]=ph*compptr->v_samp_factor/cinfo->max_v_samp_factor;
|
ch[i]=ph*compptr->v_samp_factor/cinfo->max_v_samp_factor;
|
||||||
outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]);
|
outbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]);
|
||||||
@@ -323,9 +305,9 @@ DLLEXPORT int DLLCALL tjCompress(tjhandle h,
|
|||||||
for(i=0; i<MAX_COMPONENTS; i++)
|
for(i=0; i<MAX_COMPONENTS; i++)
|
||||||
{
|
{
|
||||||
if(tmpbuf[i]!=NULL) free(tmpbuf[i]);
|
if(tmpbuf[i]!=NULL) free(tmpbuf[i]);
|
||||||
if(_tmpbuf[i]!=NULL) _aligned_free(_tmpbuf[i]);
|
if(_tmpbuf[i]!=NULL) free(_tmpbuf[i]);
|
||||||
if(tmpbuf2[i]!=NULL) free(tmpbuf2[i]);
|
if(tmpbuf2[i]!=NULL) free(tmpbuf2[i]);
|
||||||
if(_tmpbuf2[i]!=NULL) _aligned_free(_tmpbuf2[i]);
|
if(_tmpbuf2[i]!=NULL) free(_tmpbuf2[i]);
|
||||||
if(outbuf[i]!=NULL) free(outbuf[i]);
|
if(outbuf[i]!=NULL) free(outbuf[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user