Use BreakBeforeBraces: Linux for clang-format

This commit is contained in:
Aleksandr Karpinskii 2024-07-07 19:18:31 +04:00
parent 94a8fccfa7
commit 0d684f408c
84 changed files with 2223 additions and 1200 deletions

View File

@ -6,7 +6,7 @@ AllowShortIfStatementsOnASingleLine: false
AlignAfterOpenBracket: AlwaysBreak AlignAfterOpenBracket: AlwaysBreak
BinPackArguments: false BinPackArguments: false
BinPackParameters: false BinPackParameters: false
BreakBeforeBraces: Attach BreakBeforeBraces: Linux
ColumnLimit: 88 ColumnLimit: 88
DerivePointerAlignment: false DerivePointerAlignment: false
IndentGotoLabels: false IndentGotoLabels: false

View File

@ -55,7 +55,8 @@ static Tk_PhotoGetImage_t TK_PHOTO_GET_IMAGE;
static Tk_PhotoPutBlock_t TK_PHOTO_PUT_BLOCK; static Tk_PhotoPutBlock_t TK_PHOTO_PUT_BLOCK;
static Imaging static Imaging
ImagingFind(const char *name) { ImagingFind(const char *name)
{
Py_ssize_t id; Py_ssize_t id;
/* FIXME: use CObject instead? */ /* FIXME: use CObject instead? */
@ -73,7 +74,8 @@ ImagingFind(const char *name) {
static int static int
PyImagingPhotoPut( PyImagingPhotoPut(
ClientData clientdata, Tcl_Interp *interp, int argc, const char **argv) { ClientData clientdata, Tcl_Interp *interp, int argc, const char **argv)
{
Imaging im; Imaging im;
Tk_PhotoHandle photo; Tk_PhotoHandle photo;
Tk_PhotoImageBlock block; Tk_PhotoImageBlock block;
@ -135,7 +137,8 @@ PyImagingPhotoPut(
static int static int
PyImagingPhotoGet( PyImagingPhotoGet(
ClientData clientdata, Tcl_Interp *interp, int argc, const char **argv) { ClientData clientdata, Tcl_Interp *interp, int argc, const char **argv)
{
Imaging im; Imaging im;
Tk_PhotoHandle photo; Tk_PhotoHandle photo;
Tk_PhotoImageBlock block; Tk_PhotoImageBlock block;
@ -177,7 +180,8 @@ PyImagingPhotoGet(
} }
void void
TkImaging_Init(Tcl_Interp *interp) { TkImaging_Init(Tcl_Interp *interp)
{
TCL_CREATE_COMMAND( TCL_CREATE_COMMAND(
interp, interp,
"PyImagingPhoto", "PyImagingPhoto",
@ -215,7 +219,8 @@ TkImaging_Init(Tcl_Interp *interp) {
#define TKINTER_PKG "tkinter" #define TKINTER_PKG "tkinter"
FARPROC FARPROC
_dfunc(HMODULE lib_handle, const char *func_name) { _dfunc(HMODULE lib_handle, const char *func_name)
{
/* /*
* Load function `func_name` from `lib_handle`. * Load function `func_name` from `lib_handle`.
* Set Python exception if we can't find `func_name` in `lib_handle`. * Set Python exception if we can't find `func_name` in `lib_handle`.
@ -233,7 +238,8 @@ _dfunc(HMODULE lib_handle, const char *func_name) {
} }
int int
get_tcl(HMODULE hMod) { get_tcl(HMODULE hMod)
{
/* /*
* Try to fill Tcl global vars with function pointers. Return 0 for no * Try to fill Tcl global vars with function pointers. Return 0 for no
* functions found, 1 for all functions found, -1 for some but not all * functions found, 1 for all functions found, -1 for some but not all
@ -251,7 +257,8 @@ get_tcl(HMODULE hMod) {
} }
int int
get_tk(HMODULE hMod) { get_tk(HMODULE hMod)
{
/* /*
* Try to fill Tk global vars with function pointers. Return 0 for no * Try to fill Tk global vars with function pointers. Return 0 for no
* functions found, 1 for all functions found, -1 for some but not all * functions found, 1 for all functions found, -1 for some but not all
@ -274,7 +281,8 @@ get_tk(HMODULE hMod) {
} }
int int
load_tkinter_funcs(void) { load_tkinter_funcs(void)
{
/* /*
* Load Tcl and Tk functions by searching all modules in current process. * Load Tcl and Tk functions by searching all modules in current process.
* Return 0 for success, non-zero for failure. * Return 0 for success, non-zero for failure.
@ -352,7 +360,8 @@ load_tkinter_funcs(void) {
#include <dlfcn.h> #include <dlfcn.h>
void * void *
_dfunc(void *lib_handle, const char *func_name) { _dfunc(void *lib_handle, const char *func_name)
{
/* /*
* Load function `func_name` from `lib_handle`. * Load function `func_name` from `lib_handle`.
* Set Python exception if we can't find `func_name` in `lib_handle`. * Set Python exception if we can't find `func_name` in `lib_handle`.
@ -371,7 +380,8 @@ _dfunc(void *lib_handle, const char *func_name) {
} }
int int
_func_loader(void *lib) { _func_loader(void *lib)
{
/* /*
* Fill global function pointers from dynamic lib. * Fill global function pointers from dynamic lib.
* Return 1 if any pointer is NULL, 0 otherwise. * Return 1 if any pointer is NULL, 0 otherwise.
@ -398,7 +408,8 @@ _func_loader(void *lib) {
} }
int int
load_tkinter_funcs(void) { load_tkinter_funcs(void)
{
/* /*
* Load tkinter global funcs from tkinter compiled module. * Load tkinter global funcs from tkinter compiled module.
* Return 0 for success, non-zero for failure. * Return 0 for success, non-zero for failure.

File diff suppressed because it is too large Load Diff

View File

@ -84,7 +84,8 @@ static PyTypeObject CmsProfile_Type;
#define CmsProfile_Check(op) (Py_TYPE(op) == &CmsProfile_Type) #define CmsProfile_Check(op) (Py_TYPE(op) == &CmsProfile_Type)
static PyObject * static PyObject *
cms_profile_new(cmsHPROFILE profile) { cms_profile_new(cmsHPROFILE profile)
{
CmsProfileObject *self; CmsProfileObject *self;
self = PyObject_New(CmsProfileObject, &CmsProfile_Type); self = PyObject_New(CmsProfileObject, &CmsProfile_Type);
@ -98,7 +99,8 @@ cms_profile_new(cmsHPROFILE profile) {
} }
static PyObject * static PyObject *
cms_profile_open(PyObject *self, PyObject *args) { cms_profile_open(PyObject *self, PyObject *args)
{
cmsHPROFILE hProfile; cmsHPROFILE hProfile;
char *sProfile; char *sProfile;
@ -116,7 +118,8 @@ cms_profile_open(PyObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
cms_profile_frombytes(PyObject *self, PyObject *args) { cms_profile_frombytes(PyObject *self, PyObject *args)
{
cmsHPROFILE hProfile; cmsHPROFILE hProfile;
char *pProfile; char *pProfile;
@ -135,7 +138,8 @@ cms_profile_frombytes(PyObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
cms_profile_tobytes(PyObject *self, PyObject *args) { cms_profile_tobytes(PyObject *self, PyObject *args)
{
char *pProfile = NULL; char *pProfile = NULL;
cmsUInt32Number nProfile; cmsUInt32Number nProfile;
PyObject *CmsProfile; PyObject *CmsProfile;
@ -173,7 +177,8 @@ cms_profile_tobytes(PyObject *self, PyObject *args) {
} }
static void static void
cms_profile_dealloc(CmsProfileObject *self) { cms_profile_dealloc(CmsProfileObject *self)
{
(void)cmsCloseProfile(self->profile); (void)cmsCloseProfile(self->profile);
PyObject_Del(self); PyObject_Del(self);
} }
@ -189,7 +194,8 @@ static PyTypeObject CmsTransform_Type;
#define CmsTransform_Check(op) (Py_TYPE(op) == &CmsTransform_Type) #define CmsTransform_Check(op) (Py_TYPE(op) == &CmsTransform_Type)
static PyObject * static PyObject *
cms_transform_new(cmsHTRANSFORM transform) { cms_transform_new(cmsHTRANSFORM transform)
{
CmsTransformObject *self; CmsTransformObject *self;
self = PyObject_New(CmsTransformObject, &CmsTransform_Type); self = PyObject_New(CmsTransformObject, &CmsTransform_Type);
@ -203,7 +209,8 @@ cms_transform_new(cmsHTRANSFORM transform) {
} }
static void static void
cms_transform_dealloc(CmsTransformObject *self) { cms_transform_dealloc(CmsTransformObject *self)
{
cmsDeleteTransform(self->transform); cmsDeleteTransform(self->transform);
PyObject_Del(self); PyObject_Del(self);
} }
@ -212,7 +219,8 @@ cms_transform_dealloc(CmsTransformObject *self) {
/* internal functions */ /* internal functions */
static cmsUInt32Number static cmsUInt32Number
findLCMStype(char *PILmode) { findLCMStype(char *PILmode)
{
if (strcmp(PILmode, "RGB") == 0 || strcmp(PILmode, "RGBA") == 0 || if (strcmp(PILmode, "RGB") == 0 || strcmp(PILmode, "RGBA") == 0 ||
strcmp(PILmode, "RGBX") == 0) { strcmp(PILmode, "RGBX") == 0) {
return TYPE_RGBA_8; return TYPE_RGBA_8;
@ -245,7 +253,8 @@ findLCMStype(char *PILmode) {
#define Cms_Min(a, b) ((a) < (b) ? (a) : (b)) #define Cms_Min(a, b) ((a) < (b) ? (a) : (b))
static int static int
pyCMSgetAuxChannelChannel(cmsUInt32Number format, int auxChannelNdx) { pyCMSgetAuxChannelChannel(cmsUInt32Number format, int auxChannelNdx)
{
int numColors = T_CHANNELS(format); int numColors = T_CHANNELS(format);
int numExtras = T_EXTRA(format); int numExtras = T_EXTRA(format);
@ -273,7 +282,8 @@ pyCMSgetAuxChannelChannel(cmsUInt32Number format, int auxChannelNdx) {
} }
static void static void
pyCMScopyAux(cmsHTRANSFORM hTransform, Imaging imDst, const Imaging imSrc) { pyCMScopyAux(cmsHTRANSFORM hTransform, Imaging imDst, const Imaging imSrc)
{
cmsUInt32Number dstLCMSFormat; cmsUInt32Number dstLCMSFormat;
cmsUInt32Number srcLCMSFormat; cmsUInt32Number srcLCMSFormat;
int numSrcExtras; int numSrcExtras;
@ -338,7 +348,8 @@ pyCMScopyAux(cmsHTRANSFORM hTransform, Imaging imDst, const Imaging imSrc) {
} }
static int static int
pyCMSdoTransform(Imaging im, Imaging imOut, cmsHTRANSFORM hTransform) { pyCMSdoTransform(Imaging im, Imaging imOut, cmsHTRANSFORM hTransform)
{
int i; int i;
if (im->xsize > imOut->xsize || im->ysize > imOut->ysize) { if (im->xsize > imOut->xsize || im->ysize > imOut->ysize) {
@ -348,7 +359,8 @@ pyCMSdoTransform(Imaging im, Imaging imOut, cmsHTRANSFORM hTransform) {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
// transform color channels only // transform color channels only
for (i = 0; i < im->ysize; i++) { for (i = 0; i < im->ysize; i++)
{
cmsDoTransform(hTransform, im->image[i], imOut->image[i], im->xsize); cmsDoTransform(hTransform, im->image[i], imOut->image[i], im->xsize);
} }
@ -373,7 +385,8 @@ _buildTransform(
char *sInMode, char *sInMode,
char *sOutMode, char *sOutMode,
int iRenderingIntent, int iRenderingIntent,
cmsUInt32Number cmsFLAGS) { cmsUInt32Number cmsFLAGS)
{
cmsHTRANSFORM hTransform; cmsHTRANSFORM hTransform;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
@ -405,7 +418,8 @@ _buildProofTransform(
char *sOutMode, char *sOutMode,
int iRenderingIntent, int iRenderingIntent,
int iProofIntent, int iProofIntent,
cmsUInt32Number cmsFLAGS) { cmsUInt32Number cmsFLAGS)
{
cmsHTRANSFORM hTransform; cmsHTRANSFORM hTransform;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
@ -434,7 +448,8 @@ _buildProofTransform(
/* Python callable functions */ /* Python callable functions */
static PyObject * static PyObject *
buildTransform(PyObject *self, PyObject *args) { buildTransform(PyObject *self, PyObject *args)
{
CmsProfileObject *pInputProfile; CmsProfileObject *pInputProfile;
CmsProfileObject *pOutputProfile; CmsProfileObject *pOutputProfile;
char *sInMode; char *sInMode;
@ -474,7 +489,8 @@ buildTransform(PyObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
buildProofTransform(PyObject *self, PyObject *args) { buildProofTransform(PyObject *self, PyObject *args)
{
CmsProfileObject *pInputProfile; CmsProfileObject *pInputProfile;
CmsProfileObject *pOutputProfile; CmsProfileObject *pOutputProfile;
CmsProfileObject *pProofProfile; CmsProfileObject *pProofProfile;
@ -521,7 +537,8 @@ buildProofTransform(PyObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
cms_transform_apply(CmsTransformObject *self, PyObject *args) { cms_transform_apply(CmsTransformObject *self, PyObject *args)
{
Py_ssize_t idIn; Py_ssize_t idIn;
Py_ssize_t idOut; Py_ssize_t idOut;
Imaging im; Imaging im;
@ -545,7 +562,8 @@ cms_transform_apply(CmsTransformObject *self, PyObject *args) {
/* Python-Callable On-The-Fly profile creation functions */ /* Python-Callable On-The-Fly profile creation functions */
static PyObject * static PyObject *
createProfile(PyObject *self, PyObject *args) { createProfile(PyObject *self, PyObject *args)
{
char *sColorSpace; char *sColorSpace;
cmsHPROFILE hProfile; cmsHPROFILE hProfile;
cmsFloat64Number dColorTemp = 0.0; cmsFloat64Number dColorTemp = 0.0;
@ -590,7 +608,8 @@ createProfile(PyObject *self, PyObject *args) {
/* profile methods */ /* profile methods */
static PyObject * static PyObject *
cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args) { cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args)
{
cmsBool result; cmsBool result;
int intent; int intent;
@ -616,7 +635,8 @@ cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args) {
#endif #endif
static PyObject * static PyObject *
cms_get_display_profile_win32(PyObject *self, PyObject *args) { cms_get_display_profile_win32(PyObject *self, PyObject *args)
{
char filename[MAX_PATH]; char filename[MAX_PATH];
DWORD filename_size; DWORD filename_size;
BOOL ok; BOOL ok;
@ -651,7 +671,8 @@ cms_get_display_profile_win32(PyObject *self, PyObject *args) {
/* Helper functions. */ /* Helper functions. */
static PyObject * static PyObject *
_profile_read_mlu(CmsProfileObject *self, cmsTagSignature info) { _profile_read_mlu(CmsProfileObject *self, cmsTagSignature info)
{
PyObject *uni; PyObject *uni;
char *lc = "en"; char *lc = "en";
char *cc = cmsNoCountry; char *cc = cmsNoCountry;
@ -693,7 +714,8 @@ _profile_read_mlu(CmsProfileObject *self, cmsTagSignature info) {
} }
static PyObject * static PyObject *
_profile_read_int_as_string(cmsUInt32Number nr) { _profile_read_int_as_string(cmsUInt32Number nr)
{
PyObject *ret; PyObject *ret;
char buf[5]; char buf[5];
buf[0] = (char)((nr >> 24) & 0xff); buf[0] = (char)((nr >> 24) & 0xff);
@ -707,7 +729,8 @@ _profile_read_int_as_string(cmsUInt32Number nr) {
} }
static PyObject * static PyObject *
_profile_read_signature(CmsProfileObject *self, cmsTagSignature info) { _profile_read_signature(CmsProfileObject *self, cmsTagSignature info)
{
unsigned int *sig; unsigned int *sig;
if (!cmsIsTag(self->profile, info)) { if (!cmsIsTag(self->profile, info)) {
@ -725,7 +748,8 @@ _profile_read_signature(CmsProfileObject *self, cmsTagSignature info) {
} }
static PyObject * static PyObject *
_xyz_py(cmsCIEXYZ *XYZ) { _xyz_py(cmsCIEXYZ *XYZ)
{
cmsCIExyY xyY; cmsCIExyY xyY;
cmsXYZ2xyY(&xyY, XYZ); cmsXYZ2xyY(&xyY, XYZ);
return Py_BuildValue( return Py_BuildValue(
@ -733,7 +757,8 @@ _xyz_py(cmsCIEXYZ *XYZ) {
} }
static PyObject * static PyObject *
_xyz3_py(cmsCIEXYZ *XYZ) { _xyz3_py(cmsCIEXYZ *XYZ)
{
cmsCIExyY xyY[3]; cmsCIExyY xyY[3];
cmsXYZ2xyY(&xyY[0], &XYZ[0]); cmsXYZ2xyY(&xyY[0], &XYZ[0]);
cmsXYZ2xyY(&xyY[1], &XYZ[1]); cmsXYZ2xyY(&xyY[1], &XYZ[1]);
@ -762,7 +787,8 @@ _xyz3_py(cmsCIEXYZ *XYZ) {
} }
static PyObject * static PyObject *
_profile_read_ciexyz(CmsProfileObject *self, cmsTagSignature info, int multi) { _profile_read_ciexyz(CmsProfileObject *self, cmsTagSignature info, int multi)
{
cmsCIEXYZ *XYZ; cmsCIEXYZ *XYZ;
if (!cmsIsTag(self->profile, info)) { if (!cmsIsTag(self->profile, info)) {
@ -783,7 +809,8 @@ _profile_read_ciexyz(CmsProfileObject *self, cmsTagSignature info, int multi) {
} }
static PyObject * static PyObject *
_profile_read_ciexyy_triple(CmsProfileObject *self, cmsTagSignature info) { _profile_read_ciexyy_triple(CmsProfileObject *self, cmsTagSignature info)
{
cmsCIExyYTRIPLE *triple; cmsCIExyYTRIPLE *triple;
if (!cmsIsTag(self->profile, info)) { if (!cmsIsTag(self->profile, info)) {
@ -813,7 +840,8 @@ _profile_read_ciexyy_triple(CmsProfileObject *self, cmsTagSignature info) {
} }
static PyObject * static PyObject *
_profile_read_named_color_list(CmsProfileObject *self, cmsTagSignature info) { _profile_read_named_color_list(CmsProfileObject *self, cmsTagSignature info)
{
cmsNAMEDCOLORLIST *ncl; cmsNAMEDCOLORLIST *ncl;
int i, n; int i, n;
char name[cmsMAX_PATH]; char name[cmsMAX_PATH];
@ -853,7 +881,8 @@ _profile_read_named_color_list(CmsProfileObject *self, cmsTagSignature info) {
} }
static cmsBool static cmsBool
_calculate_rgb_primaries(CmsProfileObject *self, cmsCIEXYZTRIPLE *result) { _calculate_rgb_primaries(CmsProfileObject *self, cmsCIEXYZTRIPLE *result)
{
double input[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; double input[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
cmsHPROFILE hXYZ; cmsHPROFILE hXYZ;
cmsHTRANSFORM hTransform; cmsHTRANSFORM hTransform;
@ -889,7 +918,8 @@ _check_intent(
int clut, int clut,
cmsHPROFILE hProfile, cmsHPROFILE hProfile,
cmsUInt32Number Intent, cmsUInt32Number Intent,
cmsUInt32Number UsedDirection) { cmsUInt32Number UsedDirection)
{
if (clut) { if (clut) {
return cmsIsCLUT(hProfile, Intent, UsedDirection); return cmsIsCLUT(hProfile, Intent, UsedDirection);
} else { } else {
@ -900,7 +930,8 @@ _check_intent(
#define INTENTS 200 #define INTENTS 200
static PyObject * static PyObject *
_is_intent_supported(CmsProfileObject *self, int clut) { _is_intent_supported(CmsProfileObject *self, int clut)
{
PyObject *result; PyObject *result;
int n; int n;
int i; int i;
@ -976,48 +1007,57 @@ static struct PyMethodDef cms_profile_methods[] = {
}; };
static PyObject * static PyObject *
cms_profile_getattr_rendering_intent(CmsProfileObject *self, void *closure) { cms_profile_getattr_rendering_intent(CmsProfileObject *self, void *closure)
{
return PyLong_FromLong(cmsGetHeaderRenderingIntent(self->profile)); return PyLong_FromLong(cmsGetHeaderRenderingIntent(self->profile));
} }
/* New-style unicode interfaces. */ /* New-style unicode interfaces. */
static PyObject * static PyObject *
cms_profile_getattr_copyright(CmsProfileObject *self, void *closure) { cms_profile_getattr_copyright(CmsProfileObject *self, void *closure)
{
return _profile_read_mlu(self, cmsSigCopyrightTag); return _profile_read_mlu(self, cmsSigCopyrightTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_target(CmsProfileObject *self, void *closure) { cms_profile_getattr_target(CmsProfileObject *self, void *closure)
{
return _profile_read_mlu(self, cmsSigCharTargetTag); return _profile_read_mlu(self, cmsSigCharTargetTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_manufacturer(CmsProfileObject *self, void *closure) { cms_profile_getattr_manufacturer(CmsProfileObject *self, void *closure)
{
return _profile_read_mlu(self, cmsSigDeviceMfgDescTag); return _profile_read_mlu(self, cmsSigDeviceMfgDescTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_model(CmsProfileObject *self, void *closure) { cms_profile_getattr_model(CmsProfileObject *self, void *closure)
{
return _profile_read_mlu(self, cmsSigDeviceModelDescTag); return _profile_read_mlu(self, cmsSigDeviceModelDescTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_profile_description(CmsProfileObject *self, void *closure) { cms_profile_getattr_profile_description(CmsProfileObject *self, void *closure)
{
return _profile_read_mlu(self, cmsSigProfileDescriptionTag); return _profile_read_mlu(self, cmsSigProfileDescriptionTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_screening_description(CmsProfileObject *self, void *closure) { cms_profile_getattr_screening_description(CmsProfileObject *self, void *closure)
{
return _profile_read_mlu(self, cmsSigScreeningDescTag); return _profile_read_mlu(self, cmsSigScreeningDescTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_viewing_condition(CmsProfileObject *self, void *closure) { cms_profile_getattr_viewing_condition(CmsProfileObject *self, void *closure)
{
return _profile_read_mlu(self, cmsSigViewingCondDescTag); return _profile_read_mlu(self, cmsSigViewingCondDescTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_creation_date(CmsProfileObject *self, void *closure) { cms_profile_getattr_creation_date(CmsProfileObject *self, void *closure)
{
cmsBool result; cmsBool result;
struct tm ct; struct tm ct;
@ -1032,18 +1072,21 @@ cms_profile_getattr_creation_date(CmsProfileObject *self, void *closure) {
} }
static PyObject * static PyObject *
cms_profile_getattr_version(CmsProfileObject *self, void *closure) { cms_profile_getattr_version(CmsProfileObject *self, void *closure)
{
cmsFloat64Number version = cmsGetProfileVersion(self->profile); cmsFloat64Number version = cmsGetProfileVersion(self->profile);
return PyFloat_FromDouble(version); return PyFloat_FromDouble(version);
} }
static PyObject * static PyObject *
cms_profile_getattr_icc_version(CmsProfileObject *self, void *closure) { cms_profile_getattr_icc_version(CmsProfileObject *self, void *closure)
{
return PyLong_FromLong((long)cmsGetEncodedICCversion(self->profile)); return PyLong_FromLong((long)cmsGetEncodedICCversion(self->profile));
} }
static PyObject * static PyObject *
cms_profile_getattr_attributes(CmsProfileObject *self, void *closure) { cms_profile_getattr_attributes(CmsProfileObject *self, void *closure)
{
cmsUInt64Number attr; cmsUInt64Number attr;
cmsGetHeaderAttributes(self->profile, &attr); cmsGetHeaderAttributes(self->profile, &attr);
/* This works just as well on Windows (LLP64), 32-bit Linux /* This works just as well on Windows (LLP64), 32-bit Linux
@ -1052,72 +1095,85 @@ cms_profile_getattr_attributes(CmsProfileObject *self, void *closure) {
} }
static PyObject * static PyObject *
cms_profile_getattr_header_flags(CmsProfileObject *self, void *closure) { cms_profile_getattr_header_flags(CmsProfileObject *self, void *closure)
{
cmsUInt32Number flags = cmsGetHeaderFlags(self->profile); cmsUInt32Number flags = cmsGetHeaderFlags(self->profile);
return PyLong_FromLong(flags); return PyLong_FromLong(flags);
} }
static PyObject * static PyObject *
cms_profile_getattr_header_manufacturer(CmsProfileObject *self, void *closure) { cms_profile_getattr_header_manufacturer(CmsProfileObject *self, void *closure)
{
return _profile_read_int_as_string(cmsGetHeaderManufacturer(self->profile)); return _profile_read_int_as_string(cmsGetHeaderManufacturer(self->profile));
} }
static PyObject * static PyObject *
cms_profile_getattr_header_model(CmsProfileObject *self, void *closure) { cms_profile_getattr_header_model(CmsProfileObject *self, void *closure)
{
return _profile_read_int_as_string(cmsGetHeaderModel(self->profile)); return _profile_read_int_as_string(cmsGetHeaderModel(self->profile));
} }
static PyObject * static PyObject *
cms_profile_getattr_device_class(CmsProfileObject *self, void *closure) { cms_profile_getattr_device_class(CmsProfileObject *self, void *closure)
{
return _profile_read_int_as_string(cmsGetDeviceClass(self->profile)); return _profile_read_int_as_string(cmsGetDeviceClass(self->profile));
} }
static PyObject * static PyObject *
cms_profile_getattr_connection_space(CmsProfileObject *self, void *closure) { cms_profile_getattr_connection_space(CmsProfileObject *self, void *closure)
{
return _profile_read_int_as_string(cmsGetPCS(self->profile)); return _profile_read_int_as_string(cmsGetPCS(self->profile));
} }
static PyObject * static PyObject *
cms_profile_getattr_xcolor_space(CmsProfileObject *self, void *closure) { cms_profile_getattr_xcolor_space(CmsProfileObject *self, void *closure)
{
return _profile_read_int_as_string(cmsGetColorSpace(self->profile)); return _profile_read_int_as_string(cmsGetColorSpace(self->profile));
} }
static PyObject * static PyObject *
cms_profile_getattr_profile_id(CmsProfileObject *self, void *closure) { cms_profile_getattr_profile_id(CmsProfileObject *self, void *closure)
{
cmsUInt8Number id[16]; cmsUInt8Number id[16];
cmsGetHeaderProfileID(self->profile, id); cmsGetHeaderProfileID(self->profile, id);
return PyBytes_FromStringAndSize((char *)id, 16); return PyBytes_FromStringAndSize((char *)id, 16);
} }
static PyObject * static PyObject *
cms_profile_getattr_is_matrix_shaper(CmsProfileObject *self, void *closure) { cms_profile_getattr_is_matrix_shaper(CmsProfileObject *self, void *closure)
{
return PyBool_FromLong((long)cmsIsMatrixShaper(self->profile)); return PyBool_FromLong((long)cmsIsMatrixShaper(self->profile));
} }
static PyObject * static PyObject *
cms_profile_getattr_technology(CmsProfileObject *self, void *closure) { cms_profile_getattr_technology(CmsProfileObject *self, void *closure)
{
return _profile_read_signature(self, cmsSigTechnologyTag); return _profile_read_signature(self, cmsSigTechnologyTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_colorimetric_intent(CmsProfileObject *self, void *closure) { cms_profile_getattr_colorimetric_intent(CmsProfileObject *self, void *closure)
{
return _profile_read_signature(self, cmsSigColorimetricIntentImageStateTag); return _profile_read_signature(self, cmsSigColorimetricIntentImageStateTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_perceptual_rendering_intent_gamut( cms_profile_getattr_perceptual_rendering_intent_gamut(
CmsProfileObject *self, void *closure) { CmsProfileObject *self, void *closure)
{
return _profile_read_signature(self, cmsSigPerceptualRenderingIntentGamutTag); return _profile_read_signature(self, cmsSigPerceptualRenderingIntentGamutTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_saturation_rendering_intent_gamut( cms_profile_getattr_saturation_rendering_intent_gamut(
CmsProfileObject *self, void *closure) { CmsProfileObject *self, void *closure)
{
return _profile_read_signature(self, cmsSigSaturationRenderingIntentGamutTag); return _profile_read_signature(self, cmsSigSaturationRenderingIntentGamutTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_red_colorant(CmsProfileObject *self, void *closure) { cms_profile_getattr_red_colorant(CmsProfileObject *self, void *closure)
{
if (!cmsIsMatrixShaper(self->profile)) { if (!cmsIsMatrixShaper(self->profile)) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@ -1126,7 +1182,8 @@ cms_profile_getattr_red_colorant(CmsProfileObject *self, void *closure) {
} }
static PyObject * static PyObject *
cms_profile_getattr_green_colorant(CmsProfileObject *self, void *closure) { cms_profile_getattr_green_colorant(CmsProfileObject *self, void *closure)
{
if (!cmsIsMatrixShaper(self->profile)) { if (!cmsIsMatrixShaper(self->profile)) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@ -1135,7 +1192,8 @@ cms_profile_getattr_green_colorant(CmsProfileObject *self, void *closure) {
} }
static PyObject * static PyObject *
cms_profile_getattr_blue_colorant(CmsProfileObject *self, void *closure) { cms_profile_getattr_blue_colorant(CmsProfileObject *self, void *closure)
{
if (!cmsIsMatrixShaper(self->profile)) { if (!cmsIsMatrixShaper(self->profile)) {
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@ -1144,8 +1202,8 @@ cms_profile_getattr_blue_colorant(CmsProfileObject *self, void *closure) {
} }
static PyObject * static PyObject *
cms_profile_getattr_media_white_point_temperature( cms_profile_getattr_media_white_point_temperature(CmsProfileObject *self, void *closure)
CmsProfileObject *self, void *closure) { {
cmsCIEXYZ *XYZ; cmsCIEXYZ *XYZ;
cmsCIExyY xyY; cmsCIExyY xyY;
cmsFloat64Number tempK; cmsFloat64Number tempK;
@ -1173,32 +1231,38 @@ cms_profile_getattr_media_white_point_temperature(
} }
static PyObject * static PyObject *
cms_profile_getattr_media_white_point(CmsProfileObject *self, void *closure) { cms_profile_getattr_media_white_point(CmsProfileObject *self, void *closure)
{
return _profile_read_ciexyz(self, cmsSigMediaWhitePointTag, 0); return _profile_read_ciexyz(self, cmsSigMediaWhitePointTag, 0);
} }
static PyObject * static PyObject *
cms_profile_getattr_media_black_point(CmsProfileObject *self, void *closure) { cms_profile_getattr_media_black_point(CmsProfileObject *self, void *closure)
{
return _profile_read_ciexyz(self, cmsSigMediaBlackPointTag, 0); return _profile_read_ciexyz(self, cmsSigMediaBlackPointTag, 0);
} }
static PyObject * static PyObject *
cms_profile_getattr_luminance(CmsProfileObject *self, void *closure) { cms_profile_getattr_luminance(CmsProfileObject *self, void *closure)
{
return _profile_read_ciexyz(self, cmsSigLuminanceTag, 0); return _profile_read_ciexyz(self, cmsSigLuminanceTag, 0);
} }
static PyObject * static PyObject *
cms_profile_getattr_chromatic_adaptation(CmsProfileObject *self, void *closure) { cms_profile_getattr_chromatic_adaptation(CmsProfileObject *self, void *closure)
{
return _profile_read_ciexyz(self, cmsSigChromaticAdaptationTag, 1); return _profile_read_ciexyz(self, cmsSigChromaticAdaptationTag, 1);
} }
static PyObject * static PyObject *
cms_profile_getattr_chromaticity(CmsProfileObject *self, void *closure) { cms_profile_getattr_chromaticity(CmsProfileObject *self, void *closure)
{
return _profile_read_ciexyy_triple(self, cmsSigChromaticityTag); return _profile_read_ciexyy_triple(self, cmsSigChromaticityTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_red_primary(CmsProfileObject *self, void *closure) { cms_profile_getattr_red_primary(CmsProfileObject *self, void *closure)
{
cmsBool result = 0; cmsBool result = 0;
cmsCIEXYZTRIPLE primaries; cmsCIEXYZTRIPLE primaries;
@ -1214,7 +1278,8 @@ cms_profile_getattr_red_primary(CmsProfileObject *self, void *closure) {
} }
static PyObject * static PyObject *
cms_profile_getattr_green_primary(CmsProfileObject *self, void *closure) { cms_profile_getattr_green_primary(CmsProfileObject *self, void *closure)
{
cmsBool result = 0; cmsBool result = 0;
cmsCIEXYZTRIPLE primaries; cmsCIEXYZTRIPLE primaries;
@ -1230,7 +1295,8 @@ cms_profile_getattr_green_primary(CmsProfileObject *self, void *closure) {
} }
static PyObject * static PyObject *
cms_profile_getattr_blue_primary(CmsProfileObject *self, void *closure) { cms_profile_getattr_blue_primary(CmsProfileObject *self, void *closure)
{
cmsBool result = 0; cmsBool result = 0;
cmsCIEXYZTRIPLE primaries; cmsCIEXYZTRIPLE primaries;
@ -1246,27 +1312,32 @@ cms_profile_getattr_blue_primary(CmsProfileObject *self, void *closure) {
} }
static PyObject * static PyObject *
cms_profile_getattr_colorant_table(CmsProfileObject *self, void *closure) { cms_profile_getattr_colorant_table(CmsProfileObject *self, void *closure)
{
return _profile_read_named_color_list(self, cmsSigColorantTableTag); return _profile_read_named_color_list(self, cmsSigColorantTableTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_colorant_table_out(CmsProfileObject *self, void *closure) { cms_profile_getattr_colorant_table_out(CmsProfileObject *self, void *closure)
{
return _profile_read_named_color_list(self, cmsSigColorantTableOutTag); return _profile_read_named_color_list(self, cmsSigColorantTableOutTag);
} }
static PyObject * static PyObject *
cms_profile_getattr_is_intent_supported(CmsProfileObject *self, void *closure) { cms_profile_getattr_is_intent_supported(CmsProfileObject *self, void *closure)
{
return _is_intent_supported(self, 0); return _is_intent_supported(self, 0);
} }
static PyObject * static PyObject *
cms_profile_getattr_is_clut(CmsProfileObject *self, void *closure) { cms_profile_getattr_is_clut(CmsProfileObject *self, void *closure)
{
return _is_intent_supported(self, 1); return _is_intent_supported(self, 1);
} }
static const char * static const char *
_illu_map(int i) { _illu_map(int i)
{
switch (i) { switch (i) {
case 0: case 0:
return "unknown"; return "unknown";
@ -1292,7 +1363,8 @@ _illu_map(int i) {
} }
static PyObject * static PyObject *
cms_profile_getattr_icc_measurement_condition(CmsProfileObject *self, void *closure) { cms_profile_getattr_icc_measurement_condition(CmsProfileObject *self, void *closure)
{
cmsICCMeasurementConditions *mc; cmsICCMeasurementConditions *mc;
cmsTagSignature info = cmsSigMeasurementTag; cmsTagSignature info = cmsSigMeasurementTag;
const char *geo; const char *geo;
@ -1333,7 +1405,8 @@ cms_profile_getattr_icc_measurement_condition(CmsProfileObject *self, void *clos
} }
static PyObject * static PyObject *
cms_profile_getattr_icc_viewing_condition(CmsProfileObject *self, void *closure) { cms_profile_getattr_icc_viewing_condition(CmsProfileObject *self, void *closure)
{
cmsICCViewingConditions *vc; cmsICCViewingConditions *vc;
cmsTagSignature info = cmsSigViewingConditionsTag; cmsTagSignature info = cmsSigViewingConditionsTag;
@ -1484,7 +1557,8 @@ static PyTypeObject CmsTransform_Type = {
}; };
static int static int
setup_module(PyObject *m) { setup_module(PyObject *m)
{
PyObject *d; PyObject *d;
PyObject *v; PyObject *v;
int vn; int vn;
@ -1519,7 +1593,8 @@ setup_module(PyObject *m) {
} }
PyMODINIT_FUNC PyMODINIT_FUNC
PyInit__imagingcms(void) { PyInit__imagingcms(void)
{
PyObject *m; PyObject *m;
static PyModuleDef module_def = { static PyModuleDef module_def = {

View File

@ -42,7 +42,9 @@
#define FT_ERRORDEF(e, v, s) {e, s}, #define FT_ERRORDEF(e, v, s) {e, s},
#define FT_ERROR_START_LIST { #define FT_ERROR_START_LIST {
#define FT_ERROR_END_LIST \ #define FT_ERROR_END_LIST \
{ 0, 0 } \ { \
0, 0 \
} \
} \ } \
; ;
@ -94,7 +96,8 @@ static PyTypeObject Font_Type;
#define PIXEL(x) ((((x) + 32) & -64) >> 6) #define PIXEL(x) ((((x) + 32) & -64) >> 6)
static PyObject * static PyObject *
geterror(int code) { geterror(int code)
{
int i; int i;
for (i = 0; ft_errors[i].message; i++) { for (i = 0; ft_errors[i].message; i++) {
@ -109,7 +112,8 @@ geterror(int code) {
} }
static PyObject * static PyObject *
getfont(PyObject *self_, PyObject *args, PyObject *kw) { getfont(PyObject *self_, PyObject *args, PyObject *kw)
{
/* create a font object from a file name and a size (in pixels) */ /* create a font object from a file name and a size (in pixels) */
FontObject *self; FontObject *self;
@ -242,7 +246,8 @@ text_layout_raqm(
const char *dir, const char *dir,
PyObject *features, PyObject *features,
const char *lang, const char *lang,
GlyphInfo **glyph_info) { GlyphInfo **glyph_info)
{
size_t i = 0, count = 0, start = 0; size_t i = 0, count = 0, start = 0;
raqm_t *rq; raqm_t *rq;
raqm_glyph_t *glyphs = NULL; raqm_glyph_t *glyphs = NULL;
@ -398,7 +403,8 @@ text_layout_fallback(
const char *lang, const char *lang,
GlyphInfo **glyph_info, GlyphInfo **glyph_info,
int mask, int mask,
int color) { int color)
{
int error, load_flags, i; int error, load_flags, i;
char *buffer = NULL; char *buffer = NULL;
FT_ULong ch; FT_ULong ch;
@ -482,7 +488,8 @@ text_layout(
const char *lang, const char *lang,
GlyphInfo **glyph_info, GlyphInfo **glyph_info,
int mask, int mask,
int color) { int color)
{
size_t count; size_t count;
#ifdef HAVE_RAQM #ifdef HAVE_RAQM
if (have_raqm && self->layout_engine == LAYOUT_RAQM) { if (have_raqm && self->layout_engine == LAYOUT_RAQM) {
@ -497,7 +504,8 @@ text_layout(
} }
static PyObject * static PyObject *
font_getlength(FontObject *self, PyObject *args) { font_getlength(FontObject *self, PyObject *args)
{
int length; /* length along primary axis, in 26.6 precision */ int length; /* length along primary axis, in 26.6 precision */
GlyphInfo *glyph_info = NULL; /* computed text layout */ GlyphInfo *glyph_info = NULL; /* computed text layout */
size_t i, count; /* glyph_info index and length */ size_t i, count; /* glyph_info index and length */
@ -555,7 +563,8 @@ bounding_box_and_anchors(
int *width, int *width,
int *height, int *height,
int *x_offset, int *x_offset,
int *y_offset) { int *y_offset)
{
int position; /* pen position along primary axis, in 26.6 precision */ int position; /* pen position along primary axis, in 26.6 precision */
int advanced; /* pen position along primary axis, in pixels */ int advanced; /* pen position along primary axis, in pixels */
int px, py; /* position of current glyph, in pixels */ int px, py; /* position of current glyph, in pixels */
@ -721,7 +730,8 @@ bad_anchor:
} }
static PyObject * static PyObject *
font_getsize(FontObject *self, PyObject *args) { font_getsize(FontObject *self, PyObject *args)
{
int width, height, x_offset, y_offset; int width, height, x_offset, y_offset;
int load_flags; /* FreeType load_flags parameter */ int load_flags; /* FreeType load_flags parameter */
int error; int error;
@ -785,7 +795,8 @@ font_getsize(FontObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
font_render(FontObject *self, PyObject *args) { font_render(FontObject *self, PyObject *args)
{
int x, y; /* pen position, in 26.6 precision */ int x, y; /* pen position, in 26.6 precision */
int px, py; /* position of current glyph, in pixels */ int px, py; /* position of current glyph, in pixels */
int x_min, y_max; /* text offset in 26.6 precision */ int x_min, y_max; /* text offset in 26.6 precision */
@ -1190,7 +1201,8 @@ glyph_error:
#if FREETYPE_MAJOR > 2 || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR > 9) || \ #if FREETYPE_MAJOR > 2 || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR > 9) || \
(FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 9 && FREETYPE_PATCH == 1) (FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 9 && FREETYPE_PATCH == 1)
static PyObject * static PyObject *
font_getvarnames(FontObject *self) { font_getvarnames(FontObject *self)
{
int error; int error;
FT_UInt i, j, num_namedstyles, name_count; FT_UInt i, j, num_namedstyles, name_count;
FT_MM_Var *master; FT_MM_Var *master;
@ -1237,7 +1249,8 @@ font_getvarnames(FontObject *self) {
} }
static PyObject * static PyObject *
font_getvaraxes(FontObject *self) { font_getvaraxes(FontObject *self)
{
int error; int error;
FT_UInt i, j, num_axis, name_count; FT_UInt i, j, num_axis, name_count;
FT_MM_Var *master; FT_MM_Var *master;
@ -1305,7 +1318,8 @@ font_getvaraxes(FontObject *self) {
} }
static PyObject * static PyObject *
font_setvarname(FontObject *self, PyObject *args) { font_setvarname(FontObject *self, PyObject *args)
{
int error; int error;
int instance_index; int instance_index;
@ -1323,7 +1337,8 @@ font_setvarname(FontObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
font_setvaraxes(FontObject *self, PyObject *args) { font_setvaraxes(FontObject *self, PyObject *args)
{
int error; int error;
PyObject *axes, *item; PyObject *axes, *item;
@ -1372,7 +1387,8 @@ font_setvaraxes(FontObject *self, PyObject *args) {
#endif #endif
static void static void
font_dealloc(FontObject *self) { font_dealloc(FontObject *self)
{
if (self->face) { if (self->face) {
FT_Done_Face(self->face); FT_Done_Face(self->face);
} }
@ -1396,7 +1412,8 @@ static PyMethodDef font_methods[] = {
{NULL, NULL}}; {NULL, NULL}};
static PyObject * static PyObject *
font_getattr_family(FontObject *self, void *closure) { font_getattr_family(FontObject *self, void *closure)
{
if (self->face->family_name) { if (self->face->family_name) {
return PyUnicode_FromString(self->face->family_name); return PyUnicode_FromString(self->face->family_name);
} }
@ -1404,7 +1421,8 @@ font_getattr_family(FontObject *self, void *closure) {
} }
static PyObject * static PyObject *
font_getattr_style(FontObject *self, void *closure) { font_getattr_style(FontObject *self, void *closure)
{
if (self->face->style_name) { if (self->face->style_name) {
return PyUnicode_FromString(self->face->style_name); return PyUnicode_FromString(self->face->style_name);
} }
@ -1412,32 +1430,38 @@ font_getattr_style(FontObject *self, void *closure) {
} }
static PyObject * static PyObject *
font_getattr_ascent(FontObject *self, void *closure) { font_getattr_ascent(FontObject *self, void *closure)
{
return PyLong_FromLong(PIXEL(self->face->size->metrics.ascender)); return PyLong_FromLong(PIXEL(self->face->size->metrics.ascender));
} }
static PyObject * static PyObject *
font_getattr_descent(FontObject *self, void *closure) { font_getattr_descent(FontObject *self, void *closure)
{
return PyLong_FromLong(-PIXEL(self->face->size->metrics.descender)); return PyLong_FromLong(-PIXEL(self->face->size->metrics.descender));
} }
static PyObject * static PyObject *
font_getattr_height(FontObject *self, void *closure) { font_getattr_height(FontObject *self, void *closure)
{
return PyLong_FromLong(PIXEL(self->face->size->metrics.height)); return PyLong_FromLong(PIXEL(self->face->size->metrics.height));
} }
static PyObject * static PyObject *
font_getattr_x_ppem(FontObject *self, void *closure) { font_getattr_x_ppem(FontObject *self, void *closure)
{
return PyLong_FromLong(self->face->size->metrics.x_ppem); return PyLong_FromLong(self->face->size->metrics.x_ppem);
} }
static PyObject * static PyObject *
font_getattr_y_ppem(FontObject *self, void *closure) { font_getattr_y_ppem(FontObject *self, void *closure)
{
return PyLong_FromLong(self->face->size->metrics.y_ppem); return PyLong_FromLong(self->face->size->metrics.y_ppem);
} }
static PyObject * static PyObject *
font_getattr_glyphs(FontObject *self, void *closure) { font_getattr_glyphs(FontObject *self, void *closure)
{
return PyLong_FromLong(self->face->num_glyphs); return PyLong_FromLong(self->face->num_glyphs);
} }
@ -1489,7 +1513,8 @@ static PyMethodDef _functions[] = {
{"getfont", (PyCFunction)getfont, METH_VARARGS | METH_KEYWORDS}, {NULL, NULL}}; {"getfont", (PyCFunction)getfont, METH_VARARGS | METH_KEYWORDS}, {NULL, NULL}};
static int static int
setup_module(PyObject *m) { setup_module(PyObject *m)
{
PyObject *d; PyObject *d;
PyObject *v; PyObject *v;
int major, minor, patch; int major, minor, patch;
@ -1559,7 +1584,8 @@ setup_module(PyObject *m) {
} }
PyMODINIT_FUNC PyMODINIT_FUNC
PyInit__imagingft(void) { PyInit__imagingft(void)
{
PyObject *m; PyObject *m;
static PyModuleDef module_def = { static PyModuleDef module_def = {

View File

@ -24,7 +24,8 @@
#define MIN_INT32 -2147483648.0 #define MIN_INT32 -2147483648.0
#define UNOP(name, op, type) \ #define UNOP(name, op, type) \
void name(Imaging out, Imaging im1) { \ void name(Imaging out, Imaging im1) \
{ \
int x, y; \ int x, y; \
for (y = 0; y < out->ysize; y++) { \ for (y = 0; y < out->ysize; y++) { \
type *p0 = (type *)out->image[y]; \ type *p0 = (type *)out->image[y]; \
@ -38,7 +39,8 @@
} }
#define BINOP(name, op, type) \ #define BINOP(name, op, type) \
void name(Imaging out, Imaging im1, Imaging im2) { \ void name(Imaging out, Imaging im1, Imaging im2) \
{ \
int x, y; \ int x, y; \
for (y = 0; y < out->ysize; y++) { \ for (y = 0; y < out->ysize; y++) { \
type *p0 = (type *)out->image[y]; \ type *p0 = (type *)out->image[y]; \
@ -87,7 +89,8 @@
#define MOD_F(type, v1, v2) ((v2) != 0.0F) ? fmod((v1), (v2)) : 0.0F #define MOD_F(type, v1, v2) ((v2) != 0.0F) ? fmod((v1), (v2)) : 0.0F
static int static int
powi(int x, int y) { powi(int x, int y)
{
double v = pow(x, y) + 0.5; double v = pow(x, y) + 0.5;
if (errno == EDOM) { if (errno == EDOM) {
return 0; return 0;
@ -163,7 +166,8 @@ BINOP(gt_F, GT, FLOAT32)
BINOP(ge_F, GE, FLOAT32) BINOP(ge_F, GE, FLOAT32)
static PyObject * static PyObject *
_unop(PyObject *self, PyObject *args) { _unop(PyObject *self, PyObject *args)
{
Imaging out; Imaging out;
Imaging im1; Imaging im1;
void (*unop)(Imaging, Imaging); void (*unop)(Imaging, Imaging);
@ -185,7 +189,8 @@ _unop(PyObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
_binop(PyObject *self, PyObject *args) { _binop(PyObject *self, PyObject *args)
{
Imaging out; Imaging out;
Imaging im1; Imaging im1;
Imaging im2; Imaging im2;
@ -212,7 +217,8 @@ static PyMethodDef _functions[] = {
{"unop", _unop, 1}, {"binop", _binop, 1}, {NULL, NULL}}; {"unop", _unop, 1}, {"binop", _binop, 1}, {NULL, NULL}};
static void static void
install(PyObject *d, char *name, void *value) { install(PyObject *d, char *name, void *value)
{
PyObject *v = PyLong_FromSsize_t((Py_ssize_t)value); PyObject *v = PyLong_FromSsize_t((Py_ssize_t)value);
if (!v || PyDict_SetItemString(d, name, v)) { if (!v || PyDict_SetItemString(d, name, v)) {
PyErr_Clear(); PyErr_Clear();
@ -221,7 +227,8 @@ install(PyObject *d, char *name, void *value) {
} }
static int static int
setup_module(PyObject *m) { setup_module(PyObject *m)
{
PyObject *d = PyModule_GetDict(m); PyObject *d = PyModule_GetDict(m);
install(d, "abs_I", abs_I); install(d, "abs_I", abs_I);
@ -273,7 +280,8 @@ setup_module(PyObject *m) {
} }
PyMODINIT_FUNC PyMODINIT_FUNC
PyInit__imagingmath(void) { PyInit__imagingmath(void)
{
PyObject *m; PyObject *m;
static PyModuleDef module_def = { static PyModuleDef module_def = {

View File

@ -28,7 +28,8 @@
Returns number of changed pixels. Returns number of changed pixels.
*/ */
static PyObject * static PyObject *
apply(PyObject *self, PyObject *args) { apply(PyObject *self, PyObject *args)
{
const char *lut; const char *lut;
PyObject *py_lut; PyObject *py_lut;
Py_ssize_t lut_len, i0, i1; Py_ssize_t lut_len, i0, i1;
@ -127,7 +128,8 @@ apply(PyObject *self, PyObject *args) {
Returns list of matching pixels. Returns list of matching pixels.
*/ */
static PyObject * static PyObject *
match(PyObject *self, PyObject *args) { match(PyObject *self, PyObject *args)
{
const char *lut; const char *lut;
PyObject *py_lut; PyObject *py_lut;
Py_ssize_t lut_len, i0; Py_ssize_t lut_len, i0;
@ -214,7 +216,8 @@ match(PyObject *self, PyObject *args) {
This is faster than match as only 1x1 lookup is made. This is faster than match as only 1x1 lookup is made.
*/ */
static PyObject * static PyObject *
get_on_pixels(PyObject *self, PyObject *args) { get_on_pixels(PyObject *self, PyObject *args)
{
Py_ssize_t i0; Py_ssize_t i0;
Imaging img; Imaging img;
UINT8 **rows; UINT8 **rows;
@ -256,7 +259,8 @@ static PyMethodDef functions[] = {
{NULL, NULL, 0, NULL}}; {NULL, NULL, 0, NULL}};
PyMODINIT_FUNC PyMODINIT_FUNC
PyInit__imagingmorph(void) { PyInit__imagingmorph(void)
{
PyObject *m; PyObject *m;
static PyModuleDef module_def = { static PyModuleDef module_def = {

View File

@ -24,7 +24,8 @@ extern int
load_tkinter_funcs(void); load_tkinter_funcs(void);
static PyObject * static PyObject *
_tkinit(PyObject *self, PyObject *args) { _tkinit(PyObject *self, PyObject *args)
{
Tcl_Interp *interp; Tcl_Interp *interp;
PyObject *arg; PyObject *arg;
@ -48,7 +49,8 @@ static PyMethodDef functions[] = {
}; };
PyMODINIT_FUNC PyMODINIT_FUNC
PyInit__imagingtk(void) { PyInit__imagingtk(void)
{
static PyModuleDef module_def = { static PyModuleDef module_def = {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
"_imagingtk", /* m_name */ "_imagingtk", /* m_name */

View File

@ -22,12 +22,14 @@
#endif #endif
void void
ImagingSectionEnter(ImagingSectionCookie *cookie) { ImagingSectionEnter(ImagingSectionCookie *cookie)
{
*cookie = (PyThreadState *)PyEval_SaveThread(); *cookie = (PyThreadState *)PyEval_SaveThread();
} }
void void
ImagingSectionLeave(ImagingSectionCookie *cookie) { ImagingSectionLeave(ImagingSectionCookie *cookie)
{
PyEval_RestoreThread((PyThreadState *)*cookie); PyEval_RestoreThread((PyThreadState *)*cookie);
} }
@ -45,7 +47,8 @@ static const char *const kErrorMessages[-WEBP_MUX_NOT_ENOUGH_DATA + 1] = {
"WEBP_MUX_NOT_ENOUGH_DATA"}; "WEBP_MUX_NOT_ENOUGH_DATA"};
PyObject * PyObject *
HandleMuxError(WebPMuxError err, char *chunk) { HandleMuxError(WebPMuxError err, char *chunk)
{
char message[100]; char message[100];
int message_len; int message_len;
assert(err <= WEBP_MUX_NOT_FOUND && err >= WEBP_MUX_NOT_ENOUGH_DATA); assert(err <= WEBP_MUX_NOT_FOUND && err >= WEBP_MUX_NOT_ENOUGH_DATA);
@ -115,7 +118,8 @@ static PyTypeObject WebPAnimDecoder_Type;
// Encoder functions // Encoder functions
PyObject * PyObject *
_anim_encoder_new(PyObject *self, PyObject *args) { _anim_encoder_new(PyObject *self, PyObject *args)
{
int width, height; int width, height;
uint32_t bgcolor; uint32_t bgcolor;
int loop_count; int loop_count;
@ -179,14 +183,16 @@ _anim_encoder_new(PyObject *self, PyObject *args) {
} }
void void
_anim_encoder_dealloc(PyObject *self) { _anim_encoder_dealloc(PyObject *self)
{
WebPAnimEncoderObject *encp = (WebPAnimEncoderObject *)self; WebPAnimEncoderObject *encp = (WebPAnimEncoderObject *)self;
WebPPictureFree(&(encp->frame)); WebPPictureFree(&(encp->frame));
WebPAnimEncoderDelete(encp->enc); WebPAnimEncoderDelete(encp->enc);
} }
PyObject * PyObject *
_anim_encoder_add(PyObject *self, PyObject *args) { _anim_encoder_add(PyObject *self, PyObject *args)
{
uint8_t *rgb; uint8_t *rgb;
Py_ssize_t size; Py_ssize_t size;
int timestamp; int timestamp;
@ -262,7 +268,8 @@ _anim_encoder_add(PyObject *self, PyObject *args) {
} }
PyObject * PyObject *
_anim_encoder_assemble(PyObject *self, PyObject *args) { _anim_encoder_assemble(PyObject *self, PyObject *args)
{
uint8_t *icc_bytes; uint8_t *icc_bytes;
uint8_t *exif_bytes; uint8_t *exif_bytes;
uint8_t *xmp_bytes; uint8_t *xmp_bytes;
@ -357,7 +364,8 @@ _anim_encoder_assemble(PyObject *self, PyObject *args) {
// Decoder functions // Decoder functions
PyObject * PyObject *
_anim_decoder_new(PyObject *self, PyObject *args) { _anim_decoder_new(PyObject *self, PyObject *args)
{
PyBytesObject *webp_string; PyBytesObject *webp_string;
const uint8_t *webp; const uint8_t *webp;
Py_ssize_t size; Py_ssize_t size;
@ -403,14 +411,16 @@ _anim_decoder_new(PyObject *self, PyObject *args) {
} }
void void
_anim_decoder_dealloc(PyObject *self) { _anim_decoder_dealloc(PyObject *self)
{
WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self; WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self;
WebPDataClear(&(decp->data)); WebPDataClear(&(decp->data));
WebPAnimDecoderDelete(decp->dec); WebPAnimDecoderDelete(decp->dec);
} }
PyObject * PyObject *
_anim_decoder_get_info(PyObject *self) { _anim_decoder_get_info(PyObject *self)
{
WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self; WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self;
WebPAnimInfo *info = &(decp->info); WebPAnimInfo *info = &(decp->info);
@ -425,7 +435,8 @@ _anim_decoder_get_info(PyObject *self) {
} }
PyObject * PyObject *
_anim_decoder_get_chunk(PyObject *self, PyObject *args) { _anim_decoder_get_chunk(PyObject *self, PyObject *args)
{
char *mode; char *mode;
WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self; WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self;
const WebPDemuxer *demux; const WebPDemuxer *demux;
@ -448,7 +459,8 @@ _anim_decoder_get_chunk(PyObject *self, PyObject *args) {
} }
PyObject * PyObject *
_anim_decoder_get_next(PyObject *self) { _anim_decoder_get_next(PyObject *self)
{
uint8_t *buf; uint8_t *buf;
int timestamp; int timestamp;
int ok; int ok;
@ -475,7 +487,8 @@ _anim_decoder_get_next(PyObject *self) {
} }
PyObject * PyObject *
_anim_decoder_reset(PyObject *self) { _anim_decoder_reset(PyObject *self)
{
WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self; WebPAnimDecoderObject *decp = (WebPAnimDecoderObject *)self;
WebPAnimDecoderReset(decp->dec); WebPAnimDecoderReset(decp->dec);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -576,7 +589,8 @@ static PyTypeObject WebPAnimDecoder_Type = {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
WebPEncode_wrapper(PyObject *self, PyObject *args) { WebPEncode_wrapper(PyObject *self, PyObject *args)
{
int width; int width;
int height; int height;
int lossless; int lossless;
@ -772,7 +786,8 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {
} }
PyObject * PyObject *
WebPDecode_wrapper(PyObject *self, PyObject *args) { WebPDecode_wrapper(PyObject *self, PyObject *args)
{
PyBytesObject *webp_string; PyBytesObject *webp_string;
const uint8_t *webp; const uint8_t *webp;
Py_ssize_t size; Py_ssize_t size;
@ -884,13 +899,15 @@ end:
// Return the decoder's version number, packed in hexadecimal using 8bits for // Return the decoder's version number, packed in hexadecimal using 8bits for
// each of major/minor/revision. E.g: v2.5.7 is 0x020507. // each of major/minor/revision. E.g: v2.5.7 is 0x020507.
PyObject * PyObject *
WebPDecoderVersion_wrapper() { WebPDecoderVersion_wrapper()
{
return Py_BuildValue("i", WebPGetDecoderVersion()); return Py_BuildValue("i", WebPGetDecoderVersion());
} }
// Version as string // Version as string
const char * const char *
WebPDecoderVersion_str(void) { WebPDecoderVersion_str(void)
{
static char version[20]; static char version[20];
int version_number = WebPGetDecoderVersion(); int version_number = WebPGetDecoderVersion();
sprintf( sprintf(
@ -907,12 +924,14 @@ WebPDecoderVersion_str(void) {
* Files that are valid with 0.3 are reported as being invalid. * Files that are valid with 0.3 are reported as being invalid.
*/ */
int int
WebPDecoderBuggyAlpha(void) { WebPDecoderBuggyAlpha(void)
{
return WebPGetDecoderVersion() == 0x0103; return WebPGetDecoderVersion() == 0x0103;
} }
PyObject * PyObject *
WebPDecoderBuggyAlpha_wrapper() { WebPDecoderBuggyAlpha_wrapper()
{
return Py_BuildValue("i", WebPDecoderBuggyAlpha()); return Py_BuildValue("i", WebPDecoderBuggyAlpha());
} }
@ -935,7 +954,8 @@ static PyMethodDef webpMethods[] = {
{NULL, NULL}}; {NULL, NULL}};
void void
addMuxFlagToModule(PyObject *m) { addMuxFlagToModule(PyObject *m)
{
PyObject *have_webpmux; PyObject *have_webpmux;
#ifdef HAVE_WEBPMUX #ifdef HAVE_WEBPMUX
have_webpmux = Py_True; have_webpmux = Py_True;
@ -947,7 +967,8 @@ addMuxFlagToModule(PyObject *m) {
} }
void void
addAnimFlagToModule(PyObject *m) { addAnimFlagToModule(PyObject *m)
{
PyObject *have_webpanim; PyObject *have_webpanim;
#ifdef HAVE_WEBPANIM #ifdef HAVE_WEBPANIM
have_webpanim = Py_True; have_webpanim = Py_True;
@ -959,7 +980,8 @@ addAnimFlagToModule(PyObject *m) {
} }
void void
addTransparencyFlagToModule(PyObject *m) { addTransparencyFlagToModule(PyObject *m)
{
PyObject *have_transparency = PyBool_FromLong(!WebPDecoderBuggyAlpha()); PyObject *have_transparency = PyBool_FromLong(!WebPDecoderBuggyAlpha());
if (PyModule_AddObject(m, "HAVE_TRANSPARENCY", have_transparency)) { if (PyModule_AddObject(m, "HAVE_TRANSPARENCY", have_transparency)) {
Py_DECREF(have_transparency); Py_DECREF(have_transparency);
@ -967,7 +989,8 @@ addTransparencyFlagToModule(PyObject *m) {
} }
static int static int
setup_module(PyObject *m) { setup_module(PyObject *m)
{
#ifdef HAVE_WEBPANIM #ifdef HAVE_WEBPANIM
/* Ready object types */ /* Ready object types */
if (PyType_Ready(&WebPAnimDecoder_Type) < 0 || if (PyType_Ready(&WebPAnimDecoder_Type) < 0 ||
@ -988,7 +1011,8 @@ setup_module(PyObject *m) {
} }
PyMODINIT_FUNC PyMODINIT_FUNC
PyInit__webp(void) { PyInit__webp(void)
{
PyObject *m; PyObject *m;
static PyModuleDef module_def = { static PyModuleDef module_def = {

View File

@ -57,7 +57,8 @@ typedef struct {
static PyTypeObject ImagingDecoderType; static PyTypeObject ImagingDecoderType;
static ImagingDecoderObject * static ImagingDecoderObject *
PyImaging_DecoderNew(int contextsize) { PyImaging_DecoderNew(int contextsize)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
void *context; void *context;
@ -103,7 +104,8 @@ PyImaging_DecoderNew(int contextsize) {
} }
static void static void
_dealloc(ImagingDecoderObject *decoder) { _dealloc(ImagingDecoderObject *decoder)
{
if (decoder->cleanup) { if (decoder->cleanup) {
decoder->cleanup(&decoder->state); decoder->cleanup(&decoder->state);
} }
@ -115,7 +117,8 @@ _dealloc(ImagingDecoderObject *decoder) {
} }
static PyObject * static PyObject *
_decode(ImagingDecoderObject *decoder, PyObject *args) { _decode(ImagingDecoderObject *decoder, PyObject *args)
{
Py_buffer buffer; Py_buffer buffer;
int status; int status;
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
@ -139,7 +142,8 @@ _decode(ImagingDecoderObject *decoder, PyObject *args) {
} }
static PyObject * static PyObject *
_decode_cleanup(ImagingDecoderObject *decoder, PyObject *args) { _decode_cleanup(ImagingDecoderObject *decoder, PyObject *args)
{
int status = 0; int status = 0;
if (decoder->cleanup) { if (decoder->cleanup) {
@ -153,7 +157,8 @@ extern Imaging
PyImaging_AsImaging(PyObject *op); PyImaging_AsImaging(PyObject *op);
static PyObject * static PyObject *
_setimage(ImagingDecoderObject *decoder, PyObject *args) { _setimage(ImagingDecoderObject *decoder, PyObject *args)
{
PyObject *op; PyObject *op;
Imaging im; Imaging im;
ImagingCodecState state; ImagingCodecState state;
@ -217,7 +222,8 @@ _setimage(ImagingDecoderObject *decoder, PyObject *args) {
} }
static PyObject * static PyObject *
_setfd(ImagingDecoderObject *decoder, PyObject *args) { _setfd(ImagingDecoderObject *decoder, PyObject *args)
{
PyObject *fd; PyObject *fd;
ImagingCodecState state; ImagingCodecState state;
@ -235,7 +241,8 @@ _setfd(ImagingDecoderObject *decoder, PyObject *args) {
} }
static PyObject * static PyObject *
_get_pulls_fd(ImagingDecoderObject *decoder, void *closure) { _get_pulls_fd(ImagingDecoderObject *decoder, void *closure)
{
return PyBool_FromLong(decoder->pulls_fd); return PyBool_FromLong(decoder->pulls_fd);
} }
@ -292,7 +299,8 @@ static PyTypeObject ImagingDecoderType = {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int int
get_unpacker(ImagingDecoderObject *decoder, const char *mode, const char *rawmode) { get_unpacker(ImagingDecoderObject *decoder, const char *mode, const char *rawmode)
{
int bits; int bits;
ImagingShuffler unpack; ImagingShuffler unpack;
@ -314,7 +322,8 @@ get_unpacker(ImagingDecoderObject *decoder, const char *mode, const char *rawmod
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_BitDecoderNew(PyObject *self, PyObject *args) { PyImaging_BitDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -354,7 +363,8 @@ PyImaging_BitDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_BcnDecoderNew(PyObject *self, PyObject *args) { PyImaging_BcnDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -406,7 +416,8 @@ PyImaging_BcnDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_FliDecoderNew(PyObject *self, PyObject *args) { PyImaging_FliDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
decoder = PyImaging_DecoderNew(0); decoder = PyImaging_DecoderNew(0);
@ -424,7 +435,8 @@ PyImaging_FliDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_GifDecoderNew(PyObject *self, PyObject *args) { PyImaging_GifDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -459,7 +471,8 @@ PyImaging_GifDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_HexDecoderNew(PyObject *self, PyObject *args) { PyImaging_HexDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -493,7 +506,8 @@ PyImaging_HexDecoderNew(PyObject *self, PyObject *args) {
#include <string.h> #include <string.h>
PyObject * PyObject *
PyImaging_LibTiffDecoderNew(PyObject *self, PyObject *args) { PyImaging_LibTiffDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
char *rawmode; char *rawmode;
@ -534,7 +548,8 @@ PyImaging_LibTiffDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_PackbitsDecoderNew(PyObject *self, PyObject *args) { PyImaging_PackbitsDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -562,7 +577,8 @@ PyImaging_PackbitsDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_PcdDecoderNew(PyObject *self, PyObject *args) { PyImaging_PcdDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
decoder = PyImaging_DecoderNew(0); decoder = PyImaging_DecoderNew(0);
@ -585,7 +601,8 @@ PyImaging_PcdDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_PcxDecoderNew(PyObject *self, PyObject *args) { PyImaging_PcxDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -616,7 +633,8 @@ PyImaging_PcxDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_RawDecoderNew(PyObject *self, PyObject *args) { PyImaging_RawDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -650,7 +668,8 @@ PyImaging_RawDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_SgiRleDecoderNew(PyObject *self, PyObject *args) { PyImaging_SgiRleDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -684,7 +703,8 @@ PyImaging_SgiRleDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_SunRleDecoderNew(PyObject *self, PyObject *args) { PyImaging_SunRleDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -712,7 +732,8 @@ PyImaging_SunRleDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_TgaRleDecoderNew(PyObject *self, PyObject *args) { PyImaging_TgaRleDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -745,7 +766,8 @@ PyImaging_TgaRleDecoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_XbmDecoderNew(PyObject *self, PyObject *args) { PyImaging_XbmDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
decoder = PyImaging_DecoderNew(0); decoder = PyImaging_DecoderNew(0);
@ -771,7 +793,8 @@ PyImaging_XbmDecoderNew(PyObject *self, PyObject *args) {
#include "libImaging/ZipCodecs.h" #include "libImaging/ZipCodecs.h"
PyObject * PyObject *
PyImaging_ZipDecoderNew(PyObject *self, PyObject *args) { PyImaging_ZipDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -821,7 +844,8 @@ PyImaging_ZipDecoderNew(PyObject *self, PyObject *args) {
#include "libImaging/Jpeg.h" #include "libImaging/Jpeg.h"
PyObject * PyObject *
PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) { PyImaging_JpegDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
char *mode; char *mode;
@ -876,7 +900,8 @@ PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) {
#include "libImaging/Jpeg2K.h" #include "libImaging/Jpeg2K.h"
PyObject * PyObject *
PyImaging_Jpeg2KDecoderNew(PyObject *self, PyObject *args) { PyImaging_Jpeg2KDecoderNew(PyObject *self, PyObject *args)
{
ImagingDecoderObject *decoder; ImagingDecoderObject *decoder;
JPEG2KDECODESTATE *context; JPEG2KDECODESTATE *context;

View File

@ -47,7 +47,8 @@ typedef struct {
static PyTypeObject ImagingDisplayType; static PyTypeObject ImagingDisplayType;
static ImagingDisplayObject * static ImagingDisplayObject *
_new(const char *mode, int xsize, int ysize) { _new(const char *mode, int xsize, int ysize)
{
ImagingDisplayObject *display; ImagingDisplayObject *display;
if (PyType_Ready(&ImagingDisplayType) < 0) { if (PyType_Ready(&ImagingDisplayType) < 0) {
@ -69,7 +70,8 @@ _new(const char *mode, int xsize, int ysize) {
} }
static void static void
_delete(ImagingDisplayObject *display) { _delete(ImagingDisplayObject *display)
{
if (display->dib) { if (display->dib) {
ImagingDeleteDIB(display->dib); ImagingDeleteDIB(display->dib);
} }
@ -77,7 +79,8 @@ _delete(ImagingDisplayObject *display) {
} }
static PyObject * static PyObject *
_expose(ImagingDisplayObject *display, PyObject *args) { _expose(ImagingDisplayObject *display, PyObject *args)
{
HDC hdc; HDC hdc;
if (!PyArg_ParseTuple(args, F_HANDLE, &hdc)) { if (!PyArg_ParseTuple(args, F_HANDLE, &hdc)) {
return NULL; return NULL;
@ -90,7 +93,8 @@ _expose(ImagingDisplayObject *display, PyObject *args) {
} }
static PyObject * static PyObject *
_draw(ImagingDisplayObject *display, PyObject *args) { _draw(ImagingDisplayObject *display, PyObject *args)
{
HDC hdc; HDC hdc;
int dst[4]; int dst[4];
int src[4]; int src[4];
@ -119,7 +123,8 @@ extern Imaging
PyImaging_AsImaging(PyObject *op); PyImaging_AsImaging(PyObject *op);
static PyObject * static PyObject *
_paste(ImagingDisplayObject *display, PyObject *args) { _paste(ImagingDisplayObject *display, PyObject *args)
{
Imaging im; Imaging im;
PyObject *op; PyObject *op;
@ -147,7 +152,8 @@ _paste(ImagingDisplayObject *display, PyObject *args) {
} }
static PyObject * static PyObject *
_query_palette(ImagingDisplayObject *display, PyObject *args) { _query_palette(ImagingDisplayObject *display, PyObject *args)
{
HDC hdc; HDC hdc;
int status; int status;
@ -161,7 +167,8 @@ _query_palette(ImagingDisplayObject *display, PyObject *args) {
} }
static PyObject * static PyObject *
_getdc(ImagingDisplayObject *display, PyObject *args) { _getdc(ImagingDisplayObject *display, PyObject *args)
{
HWND window; HWND window;
HDC dc; HDC dc;
@ -179,7 +186,8 @@ _getdc(ImagingDisplayObject *display, PyObject *args) {
} }
static PyObject * static PyObject *
_releasedc(ImagingDisplayObject *display, PyObject *args) { _releasedc(ImagingDisplayObject *display, PyObject *args)
{
HWND window; HWND window;
HDC dc; HDC dc;
@ -194,7 +202,8 @@ _releasedc(ImagingDisplayObject *display, PyObject *args) {
} }
static PyObject * static PyObject *
_frombytes(ImagingDisplayObject *display, PyObject *args) { _frombytes(ImagingDisplayObject *display, PyObject *args)
{
Py_buffer buffer; Py_buffer buffer;
if (!PyArg_ParseTuple(args, "y*:frombytes", &buffer)) { if (!PyArg_ParseTuple(args, "y*:frombytes", &buffer)) {
@ -215,7 +224,8 @@ _frombytes(ImagingDisplayObject *display, PyObject *args) {
} }
static PyObject * static PyObject *
_tobytes(ImagingDisplayObject *display, PyObject *args) { _tobytes(ImagingDisplayObject *display, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":tobytes")) { if (!PyArg_ParseTuple(args, ":tobytes")) {
return NULL; return NULL;
} }
@ -237,12 +247,14 @@ static struct PyMethodDef methods[] = {
}; };
static PyObject * static PyObject *
_getattr_mode(ImagingDisplayObject *self, void *closure) { _getattr_mode(ImagingDisplayObject *self, void *closure)
{
return Py_BuildValue("s", self->dib->mode); return Py_BuildValue("s", self->dib->mode);
} }
static PyObject * static PyObject *
_getattr_size(ImagingDisplayObject *self, void *closure) { _getattr_size(ImagingDisplayObject *self, void *closure)
{
return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize); return Py_BuildValue("ii", self->dib->xsize, self->dib->ysize);
} }
@ -283,7 +295,8 @@ static PyTypeObject ImagingDisplayType = {
}; };
PyObject * PyObject *
PyImaging_DisplayWin32(PyObject *self, PyObject *args) { PyImaging_DisplayWin32(PyObject *self, PyObject *args)
{
ImagingDisplayObject *display; ImagingDisplayObject *display;
char *mode; char *mode;
int xsize, ysize; int xsize, ysize;
@ -301,7 +314,8 @@ PyImaging_DisplayWin32(PyObject *self, PyObject *args) {
} }
PyObject * PyObject *
PyImaging_DisplayModeWin32(PyObject *self, PyObject *args) { PyImaging_DisplayModeWin32(PyObject *self, PyObject *args)
{
char *mode; char *mode;
int size[2]; int size[2];
@ -316,7 +330,8 @@ PyImaging_DisplayModeWin32(PyObject *self, PyObject *args) {
typedef HANDLE(__stdcall *Func_SetThreadDpiAwarenessContext)(HANDLE); typedef HANDLE(__stdcall *Func_SetThreadDpiAwarenessContext)(HANDLE);
PyObject * PyObject *
PyImaging_GrabScreenWin32(PyObject *self, PyObject *args) { PyImaging_GrabScreenWin32(PyObject *self, PyObject *args)
{
int x = 0, y = 0, width, height; int x = 0, y = 0, width, height;
int includeLayeredWindows = 0, all_screens = 0; int includeLayeredWindows = 0, all_screens = 0;
HBITMAP bitmap; HBITMAP bitmap;
@ -426,7 +441,8 @@ error:
/* Windows clipboard grabber */ /* Windows clipboard grabber */
PyObject * PyObject *
PyImaging_GrabClipboardWin32(PyObject *self, PyObject *args) { PyImaging_GrabClipboardWin32(PyObject *self, PyObject *args)
{
HANDLE handle = NULL; HANDLE handle = NULL;
int size; int size;
void *data; void *data;
@ -484,7 +500,8 @@ PyImaging_GrabClipboardWin32(PyObject *self, PyObject *args) {
static int mainloop = 0; static int mainloop = 0;
static void static void
callback_error(const char *handler) { callback_error(const char *handler)
{
PyObject *sys_stderr; PyObject *sys_stderr;
sys_stderr = PySys_GetObject("stderr"); sys_stderr = PySys_GetObject("stderr");
@ -500,7 +517,8 @@ callback_error(const char *handler) {
} }
static LRESULT CALLBACK static LRESULT CALLBACK
windowCallback(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) { windowCallback(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps; PAINTSTRUCT ps;
PyObject *callback = NULL; PyObject *callback = NULL;
PyObject *result; PyObject *result;
@ -625,7 +643,8 @@ windowCallback(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) {
} }
PyObject * PyObject *
PyImaging_CreateWindowWin32(PyObject *self, PyObject *args) { PyImaging_CreateWindowWin32(PyObject *self, PyObject *args)
{
HWND wnd; HWND wnd;
WNDCLASS windowClass; WNDCLASS windowClass;
@ -690,10 +709,12 @@ PyImaging_CreateWindowWin32(PyObject *self, PyObject *args) {
} }
PyObject * PyObject *
PyImaging_EventLoopWin32(PyObject *self, PyObject *args) { PyImaging_EventLoopWin32(PyObject *self, PyObject *args)
{
MSG msg; MSG msg;
Py_BEGIN_ALLOW_THREADS while (mainloop && GetMessage(&msg, NULL, 0, 0)) { Py_BEGIN_ALLOW_THREADS while (mainloop && GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} }
@ -709,7 +730,8 @@ PyImaging_EventLoopWin32(PyObject *self, PyObject *args) {
#define GET32(p, o) ((DWORD *)(p + o))[0] #define GET32(p, o) ((DWORD *)(p + o))[0]
PyObject * PyObject *
PyImaging_DrawWmf(PyObject *self, PyObject *args) { PyImaging_DrawWmf(PyObject *self, PyObject *args)
{
HBITMAP bitmap; HBITMAP bitmap;
HENHMETAFILE meta; HENHMETAFILE meta;
BITMAPCOREHEADER core; BITMAPCOREHEADER core;
@ -822,7 +844,8 @@ error:
/* X11 screen grabber */ /* X11 screen grabber */
PyObject * PyObject *
PyImaging_GrabScreenX11(PyObject *self, PyObject *args) { PyImaging_GrabScreenX11(PyObject *self, PyObject *args)
{
int width, height; int width, height;
char *display_name; char *display_name;
xcb_connection_t *connection; xcb_connection_t *connection;

View File

@ -49,7 +49,8 @@ typedef struct {
static PyTypeObject ImagingEncoderType; static PyTypeObject ImagingEncoderType;
static ImagingEncoderObject * static ImagingEncoderObject *
PyImaging_EncoderNew(int contextsize) { PyImaging_EncoderNew(int contextsize)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
void *context; void *context;
@ -92,7 +93,8 @@ PyImaging_EncoderNew(int contextsize) {
} }
static void static void
_dealloc(ImagingEncoderObject *encoder) { _dealloc(ImagingEncoderObject *encoder)
{
if (encoder->cleanup) { if (encoder->cleanup) {
encoder->cleanup(&encoder->state); encoder->cleanup(&encoder->state);
} }
@ -104,7 +106,8 @@ _dealloc(ImagingEncoderObject *encoder) {
} }
static PyObject * static PyObject *
_encode_cleanup(ImagingEncoderObject *encoder, PyObject *args) { _encode_cleanup(ImagingEncoderObject *encoder, PyObject *args)
{
int status = 0; int status = 0;
if (encoder->cleanup) { if (encoder->cleanup) {
@ -115,7 +118,8 @@ _encode_cleanup(ImagingEncoderObject *encoder, PyObject *args) {
} }
static PyObject * static PyObject *
_encode(ImagingEncoderObject *encoder, PyObject *args) { _encode(ImagingEncoderObject *encoder, PyObject *args)
{
PyObject *buf; PyObject *buf;
PyObject *result; PyObject *result;
int status; int status;
@ -149,7 +153,8 @@ _encode(ImagingEncoderObject *encoder, PyObject *args) {
} }
static PyObject * static PyObject *
_encode_to_pyfd(ImagingEncoderObject *encoder) { _encode_to_pyfd(ImagingEncoderObject *encoder)
{
PyObject *result; PyObject *result;
int status; int status;
@ -167,7 +172,8 @@ _encode_to_pyfd(ImagingEncoderObject *encoder) {
} }
static PyObject * static PyObject *
_encode_to_file(ImagingEncoderObject *encoder, PyObject *args) { _encode_to_file(ImagingEncoderObject *encoder, PyObject *args)
{
UINT8 *buf; UINT8 *buf;
int status; int status;
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
@ -217,7 +223,8 @@ extern Imaging
PyImaging_AsImaging(PyObject *op); PyImaging_AsImaging(PyObject *op);
static PyObject * static PyObject *
_setimage(ImagingEncoderObject *encoder, PyObject *args) { _setimage(ImagingEncoderObject *encoder, PyObject *args)
{
PyObject *op; PyObject *op;
Imaging im; Imaging im;
ImagingCodecState state; ImagingCodecState state;
@ -280,7 +287,8 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) {
} }
static PyObject * static PyObject *
_setfd(ImagingEncoderObject *encoder, PyObject *args) { _setfd(ImagingEncoderObject *encoder, PyObject *args)
{
PyObject *fd; PyObject *fd;
ImagingCodecState state; ImagingCodecState state;
@ -298,7 +306,8 @@ _setfd(ImagingEncoderObject *encoder, PyObject *args) {
} }
static PyObject * static PyObject *
_get_pushes_fd(ImagingEncoderObject *encoder, void *closure) { _get_pushes_fd(ImagingEncoderObject *encoder, void *closure)
{
return PyBool_FromLong(encoder->pushes_fd); return PyBool_FromLong(encoder->pushes_fd);
} }
@ -357,7 +366,8 @@ static PyTypeObject ImagingEncoderType = {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int int
get_packer(ImagingEncoderObject *encoder, const char *mode, const char *rawmode) { get_packer(ImagingEncoderObject *encoder, const char *mode, const char *rawmode)
{
int bits; int bits;
ImagingShuffler pack; ImagingShuffler pack;
@ -379,7 +389,8 @@ get_packer(ImagingEncoderObject *encoder, const char *mode, const char *rawmode)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_EpsEncoderNew(PyObject *self, PyObject *args) { PyImaging_EpsEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
encoder = PyImaging_EncoderNew(0); encoder = PyImaging_EncoderNew(0);
@ -397,7 +408,8 @@ PyImaging_EpsEncoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_GifEncoderNew(PyObject *self, PyObject *args) { PyImaging_GifEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
char *mode; char *mode;
@ -430,7 +442,8 @@ PyImaging_GifEncoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_PcxEncoderNew(PyObject *self, PyObject *args) { PyImaging_PcxEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
char *mode; char *mode;
@ -460,7 +473,8 @@ PyImaging_PcxEncoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_RawEncoderNew(PyObject *self, PyObject *args) { PyImaging_RawEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
char *mode; char *mode;
@ -494,7 +508,8 @@ PyImaging_RawEncoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_TgaRleEncoderNew(PyObject *self, PyObject *args) { PyImaging_TgaRleEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
char *mode; char *mode;
@ -526,7 +541,8 @@ PyImaging_TgaRleEncoderNew(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyImaging_XbmEncoderNew(PyObject *self, PyObject *args) { PyImaging_XbmEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
encoder = PyImaging_EncoderNew(0); encoder = PyImaging_EncoderNew(0);
@ -552,7 +568,8 @@ PyImaging_XbmEncoderNew(PyObject *self, PyObject *args) {
#include "libImaging/ZipCodecs.h" #include "libImaging/ZipCodecs.h"
PyObject * PyObject *
PyImaging_ZipEncoderNew(PyObject *self, PyObject *args) { PyImaging_ZipEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
char *mode; char *mode;
@ -628,7 +645,8 @@ PyImaging_ZipEncoderNew(PyObject *self, PyObject *args) {
#include <string.h> #include <string.h>
PyObject * PyObject *
PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) { PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
char *mode; char *mode;
@ -970,7 +988,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
#include "libImaging/Jpeg.h" #include "libImaging/Jpeg.h"
static unsigned int * static unsigned int *
get_qtables_arrays(PyObject *qtables, int *qtablesLen) { get_qtables_arrays(PyObject *qtables, int *qtablesLen)
{
PyObject *tables; PyObject *tables;
PyObject *table; PyObject *table;
PyObject *table_data; PyObject *table_data;
@ -1033,7 +1052,8 @@ JPEG_QTABLES_ERR:
} }
PyObject * PyObject *
PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) { PyImaging_JpegEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
char *mode; char *mode;
@ -1188,7 +1208,8 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
#include "libImaging/Jpeg2K.h" #include "libImaging/Jpeg2K.h"
static void static void
j2k_decode_coord_tuple(PyObject *tuple, int *x, int *y) { j2k_decode_coord_tuple(PyObject *tuple, int *x, int *y)
{
*x = *y = 0; *x = *y = 0;
if (tuple && PyTuple_Check(tuple) && PyTuple_GET_SIZE(tuple) == 2) { if (tuple && PyTuple_Check(tuple) && PyTuple_GET_SIZE(tuple) == 2) {
@ -1205,7 +1226,8 @@ j2k_decode_coord_tuple(PyObject *tuple, int *x, int *y) {
} }
PyObject * PyObject *
PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) { PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args)
{
ImagingEncoderObject *encoder; ImagingEncoderObject *encoder;
JPEG2KENCODESTATE *context; JPEG2KENCODESTATE *context;

View File

@ -18,7 +18,8 @@
static struct ImagingAccessInstance access_table[ACCESS_TABLE_SIZE]; static struct ImagingAccessInstance access_table[ACCESS_TABLE_SIZE];
static inline UINT32 static inline UINT32
hash(const char *mode) { hash(const char *mode)
{
UINT32 i = ACCESS_TABLE_HASH; UINT32 i = ACCESS_TABLE_HASH;
while (*mode) { while (*mode) {
i = ((i << 5) + i) ^ (UINT8)*mode++; i = ((i << 5) + i) ^ (UINT8)*mode++;
@ -27,7 +28,8 @@ hash(const char *mode) {
} }
static ImagingAccess static ImagingAccess
add_item(const char *mode) { add_item(const char *mode)
{
UINT32 i = hash(mode); UINT32 i = hash(mode);
/* printf("hash %s => %d\n", mode, i); */ /* printf("hash %s => %d\n", mode, i); */
if (access_table[i].mode && strcmp(access_table[i].mode, mode) != 0) { if (access_table[i].mode && strcmp(access_table[i].mode, mode) != 0) {
@ -46,7 +48,8 @@ add_item(const char *mode) {
/* fetch individual pixel */ /* fetch individual pixel */
static void static void
get_pixel_32_2bands(Imaging im, int x, int y, void *color) { get_pixel_32_2bands(Imaging im, int x, int y, void *color)
{
char *out = color; char *out = color;
UINT8 *p = (UINT8 *)&im->image32[y][x]; UINT8 *p = (UINT8 *)&im->image32[y][x];
out[0] = p[0]; out[0] = p[0];
@ -54,13 +57,15 @@ get_pixel_32_2bands(Imaging im, int x, int y, void *color) {
} }
static void static void
get_pixel_8(Imaging im, int x, int y, void *color) { get_pixel_8(Imaging im, int x, int y, void *color)
{
char *out = color; char *out = color;
out[0] = im->image8[y][x]; out[0] = im->image8[y][x];
} }
static void static void
get_pixel_16L(Imaging im, int x, int y, void *color) { get_pixel_16L(Imaging im, int x, int y, void *color)
{
UINT8 *in = (UINT8 *)&im->image[y][x + x]; UINT8 *in = (UINT8 *)&im->image[y][x + x];
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
UINT16 out = in[0] + (in[1] << 8); UINT16 out = in[0] + (in[1] << 8);
@ -71,7 +76,8 @@ get_pixel_16L(Imaging im, int x, int y, void *color) {
} }
static void static void
get_pixel_16B(Imaging im, int x, int y, void *color) { get_pixel_16B(Imaging im, int x, int y, void *color)
{
UINT8 *in = (UINT8 *)&im->image[y][x + x]; UINT8 *in = (UINT8 *)&im->image[y][x + x];
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
memcpy(color, in, sizeof(UINT16)); memcpy(color, in, sizeof(UINT16));
@ -82,7 +88,8 @@ get_pixel_16B(Imaging im, int x, int y, void *color) {
} }
static void static void
get_pixel_BGR15(Imaging im, int x, int y, void *color) { get_pixel_BGR15(Imaging im, int x, int y, void *color)
{
UINT8 *in = (UINT8 *)&im->image8[y][x * 2]; UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
UINT16 pixel = in[0] + (in[1] << 8); UINT16 pixel = in[0] + (in[1] << 8);
char *out = color; char *out = color;
@ -92,7 +99,8 @@ get_pixel_BGR15(Imaging im, int x, int y, void *color) {
} }
static void static void
get_pixel_BGR16(Imaging im, int x, int y, void *color) { get_pixel_BGR16(Imaging im, int x, int y, void *color)
{
UINT8 *in = (UINT8 *)&im->image8[y][x * 2]; UINT8 *in = (UINT8 *)&im->image8[y][x * 2];
UINT16 pixel = in[0] + (in[1] << 8); UINT16 pixel = in[0] + (in[1] << 8);
char *out = color; char *out = color;
@ -102,17 +110,20 @@ get_pixel_BGR16(Imaging im, int x, int y, void *color) {
} }
static void static void
get_pixel_BGR24(Imaging im, int x, int y, void *color) { get_pixel_BGR24(Imaging im, int x, int y, void *color)
{
memcpy(color, &im->image8[y][x * 3], sizeof(UINT8) * 3); memcpy(color, &im->image8[y][x * 3], sizeof(UINT8) * 3);
} }
static void static void
get_pixel_32(Imaging im, int x, int y, void *color) { get_pixel_32(Imaging im, int x, int y, void *color)
{
memcpy(color, &im->image32[y][x], sizeof(INT32)); memcpy(color, &im->image32[y][x], sizeof(INT32));
} }
static void static void
get_pixel_32L(Imaging im, int x, int y, void *color) { get_pixel_32L(Imaging im, int x, int y, void *color)
{
UINT8 *in = (UINT8 *)&im->image[y][x * 4]; UINT8 *in = (UINT8 *)&im->image[y][x * 4];
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
INT32 out = in[0] + (in[1] << 8) + (in[2] << 16) + (in[3] << 24); INT32 out = in[0] + (in[1] << 8) + (in[2] << 16) + (in[3] << 24);
@ -123,7 +134,8 @@ get_pixel_32L(Imaging im, int x, int y, void *color) {
} }
static void static void
get_pixel_32B(Imaging im, int x, int y, void *color) { get_pixel_32B(Imaging im, int x, int y, void *color)
{
UINT8 *in = (UINT8 *)&im->image[y][x * 4]; UINT8 *in = (UINT8 *)&im->image[y][x * 4];
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
memcpy(color, in, sizeof(INT32)); memcpy(color, in, sizeof(INT32));
@ -136,17 +148,20 @@ get_pixel_32B(Imaging im, int x, int y, void *color) {
/* store individual pixel */ /* store individual pixel */
static void static void
put_pixel_8(Imaging im, int x, int y, const void *color) { put_pixel_8(Imaging im, int x, int y, const void *color)
{
im->image8[y][x] = *((UINT8 *)color); im->image8[y][x] = *((UINT8 *)color);
} }
static void static void
put_pixel_16L(Imaging im, int x, int y, const void *color) { put_pixel_16L(Imaging im, int x, int y, const void *color)
{
memcpy(&im->image8[y][x + x], color, 2); memcpy(&im->image8[y][x + x], color, 2);
} }
static void static void
put_pixel_16B(Imaging im, int x, int y, const void *color) { put_pixel_16B(Imaging im, int x, int y, const void *color)
{
const char *in = color; const char *in = color;
UINT8 *out = (UINT8 *)&im->image8[y][x + x]; UINT8 *out = (UINT8 *)&im->image8[y][x + x];
out[0] = in[1]; out[0] = in[1];
@ -154,22 +169,26 @@ put_pixel_16B(Imaging im, int x, int y, const void *color) {
} }
static void static void
put_pixel_BGR1516(Imaging im, int x, int y, const void *color) { put_pixel_BGR1516(Imaging im, int x, int y, const void *color)
{
memcpy(&im->image8[y][x * 2], color, 2); memcpy(&im->image8[y][x * 2], color, 2);
} }
static void static void
put_pixel_BGR24(Imaging im, int x, int y, const void *color) { put_pixel_BGR24(Imaging im, int x, int y, const void *color)
{
memcpy(&im->image8[y][x * 3], color, 3); memcpy(&im->image8[y][x * 3], color, 3);
} }
static void static void
put_pixel_32L(Imaging im, int x, int y, const void *color) { put_pixel_32L(Imaging im, int x, int y, const void *color)
{
memcpy(&im->image8[y][x * 4], color, 4); memcpy(&im->image8[y][x * 4], color, 4);
} }
static void static void
put_pixel_32B(Imaging im, int x, int y, const void *color) { put_pixel_32B(Imaging im, int x, int y, const void *color)
{
const char *in = color; const char *in = color;
UINT8 *out = (UINT8 *)&im->image8[y][x * 4]; UINT8 *out = (UINT8 *)&im->image8[y][x * 4];
out[0] = in[3]; out[0] = in[3];
@ -179,12 +198,14 @@ put_pixel_32B(Imaging im, int x, int y, const void *color) {
} }
static void static void
put_pixel_32(Imaging im, int x, int y, const void *color) { put_pixel_32(Imaging im, int x, int y, const void *color)
{
memcpy(&im->image32[y][x], color, sizeof(INT32)); memcpy(&im->image32[y][x], color, sizeof(INT32));
} }
void void
ImagingAccessInit() { ImagingAccessInit()
{
#define ADD(mode_, get_pixel_, put_pixel_) \ #define ADD(mode_, get_pixel_, put_pixel_) \
{ \ { \
ImagingAccess access = add_item(mode_); \ ImagingAccess access = add_item(mode_); \
@ -225,7 +246,8 @@ ImagingAccessInit() {
} }
ImagingAccess ImagingAccess
ImagingAccessNew(Imaging im) { ImagingAccessNew(Imaging im)
{
ImagingAccess access = &access_table[hash(im->mode)]; ImagingAccess access = &access_table[hash(im->mode)];
if (im->mode[0] != access->mode[0] || strcmp(im->mode, access->mode) != 0) { if (im->mode[0] != access->mode[0] || strcmp(im->mode, access->mode) != 0) {
return NULL; return NULL;
@ -234,4 +256,6 @@ ImagingAccessNew(Imaging im) {
} }
void void
_ImagingAccessDelete(Imaging im, ImagingAccess access) {} _ImagingAccessDelete(Imaging im, ImagingAccess access)
{
}

View File

@ -20,7 +20,8 @@ typedef struct {
} rgba8; } rgba8;
Imaging Imaging
ImagingAlphaComposite(Imaging imDst, Imaging imSrc) { ImagingAlphaComposite(Imaging imDst, Imaging imSrc)
{
Imaging imOut; Imaging imOut;
int x, y; int x, y;

View File

@ -18,7 +18,8 @@
#include "Imaging.h" #include "Imaging.h"
Imaging Imaging
ImagingGetBand(Imaging imIn, int band) { ImagingGetBand(Imaging imIn, int band)
{
Imaging imOut; Imaging imOut;
int x, y; int x, y;
@ -66,7 +67,8 @@ ImagingGetBand(Imaging imIn, int band) {
} }
int int
ImagingSplit(Imaging imIn, Imaging bands[4]) { ImagingSplit(Imaging imIn, Imaging bands[4])
{
int i, j, x, y; int i, j, x, y;
/* Check arguments */ /* Check arguments */
@ -167,7 +169,8 @@ ImagingSplit(Imaging imIn, Imaging bands[4]) {
} }
Imaging Imaging
ImagingPutBand(Imaging imOut, Imaging imIn, int band) { ImagingPutBand(Imaging imOut, Imaging imIn, int band)
{
int x, y; int x, y;
/* Check arguments */ /* Check arguments */
@ -208,7 +211,8 @@ ImagingPutBand(Imaging imOut, Imaging imIn, int band) {
} }
Imaging Imaging
ImagingFillBand(Imaging imOut, int band, int color) { ImagingFillBand(Imaging imOut, int band, int color)
{
int x, y; int x, y;
/* Check arguments */ /* Check arguments */
@ -240,7 +244,8 @@ ImagingFillBand(Imaging imOut, int band, int color) {
} }
Imaging Imaging
ImagingMerge(const char *mode, Imaging bands[4]) { ImagingMerge(const char *mode, Imaging bands[4])
{
int i, x, y; int i, x, y;
int bandsCount = 0; int bandsCount = 0;
Imaging imOut; Imaging imOut;

View File

@ -43,14 +43,16 @@ typedef struct {
#define LOAD32(p) (p)[0] | ((p)[1] << 8) | ((p)[2] << 16) | ((p)[3] << 24) #define LOAD32(p) (p)[0] | ((p)[1] << 8) | ((p)[2] << 16) | ((p)[3] << 24)
static void static void
bc1_color_load(bc1_color *dst, const UINT8 *src) { bc1_color_load(bc1_color *dst, const UINT8 *src)
{
dst->c0 = LOAD16(src); dst->c0 = LOAD16(src);
dst->c1 = LOAD16(src + 2); dst->c1 = LOAD16(src + 2);
dst->lut = LOAD32(src + 4); dst->lut = LOAD32(src + 4);
} }
static rgba static rgba
decode_565(UINT16 x) { decode_565(UINT16 x)
{
rgba c; rgba c;
int r, g, b; int r, g, b;
r = (x & 0xf800) >> 8; r = (x & 0xf800) >> 8;
@ -67,7 +69,8 @@ decode_565(UINT16 x) {
} }
static void static void
decode_bc1_color(rgba *dst, const UINT8 *src, int separate_alpha) { decode_bc1_color(rgba *dst, const UINT8 *src, int separate_alpha)
{
bc1_color col; bc1_color col;
rgba p[4]; rgba p[4];
int n, cw; int n, cw;
@ -110,7 +113,8 @@ decode_bc1_color(rgba *dst, const UINT8 *src, int separate_alpha) {
} }
static void static void
decode_bc3_alpha(char *dst, const UINT8 *src, int stride, int o, int sign) { decode_bc3_alpha(char *dst, const UINT8 *src, int stride, int o, int sign)
{
UINT16 a0, a1; UINT16 a0, a1;
UINT8 a[8]; UINT8 a[8];
int n, lut1, lut2, aw; int n, lut1, lut2, aw;
@ -158,12 +162,14 @@ decode_bc3_alpha(char *dst, const UINT8 *src, int stride, int o, int sign) {
} }
static void static void
decode_bc1_block(rgba *col, const UINT8 *src) { decode_bc1_block(rgba *col, const UINT8 *src)
{
decode_bc1_color(col, src, 0); decode_bc1_color(col, src, 0);
} }
static void static void
decode_bc2_block(rgba *col, const UINT8 *src) { decode_bc2_block(rgba *col, const UINT8 *src)
{
int n, bitI, byI, av; int n, bitI, byI, av;
decode_bc1_color(col, src + 8, 1); decode_bc1_color(col, src + 8, 1);
for (n = 0; n < 16; n++) { for (n = 0; n < 16; n++) {
@ -176,18 +182,21 @@ decode_bc2_block(rgba *col, const UINT8 *src) {
} }
static void static void
decode_bc3_block(rgba *col, const UINT8 *src) { decode_bc3_block(rgba *col, const UINT8 *src)
{
decode_bc1_color(col, src + 8, 1); decode_bc1_color(col, src + 8, 1);
decode_bc3_alpha((char *)col, src, sizeof(col[0]), 3, 0); decode_bc3_alpha((char *)col, src, sizeof(col[0]), 3, 0);
} }
static void static void
decode_bc4_block(lum *col, const UINT8 *src) { decode_bc4_block(lum *col, const UINT8 *src)
{
decode_bc3_alpha((char *)col, src, sizeof(col[0]), 0, 0); decode_bc3_alpha((char *)col, src, sizeof(col[0]), 0, 0);
} }
static void static void
decode_bc5_block(rgba *col, const UINT8 *src, int sign) { decode_bc5_block(rgba *col, const UINT8 *src, int sign)
{
decode_bc3_alpha((char *)col, src, sizeof(col[0]), 0, sign); decode_bc3_alpha((char *)col, src, sizeof(col[0]), 0, sign);
decode_bc3_alpha((char *)col, src + 8, sizeof(col[0]), 1, sign); decode_bc3_alpha((char *)col, src + 8, sizeof(col[0]), 1, sign);
} }
@ -197,14 +206,16 @@ decode_bc5_block(rgba *col, const UINT8 *src, int sign) {
*/ */
static UINT8 static UINT8
get_bit(const UINT8 *src, int bit) { get_bit(const UINT8 *src, int bit)
{
int by = bit >> 3; int by = bit >> 3;
bit &= 7; bit &= 7;
return (src[by] >> bit) & 1; return (src[by] >> bit) & 1;
} }
static UINT8 static UINT8
get_bits(const UINT8 *src, int bit, int count) { get_bits(const UINT8 *src, int bit, int count)
{
UINT8 v; UINT8 v;
int x; int x;
int by = bit >> 3; int by = bit >> 3;
@ -296,7 +307,8 @@ static const char bc7_weights4[] = {
0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64}; 0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64};
static const char * static const char *
bc7_get_weights(int n) { bc7_get_weights(int n)
{
if (n == 2) { if (n == 2) {
return bc7_weights2; return bc7_weights2;
} }
@ -307,7 +319,8 @@ bc7_get_weights(int n) {
} }
static int static int
bc7_get_subset(int ns, int partition, int n) { bc7_get_subset(int ns, int partition, int n)
{
if (ns == 2) { if (ns == 2) {
return 1 & (bc7_si2[partition] >> n); return 1 & (bc7_si2[partition] >> n);
} }
@ -318,13 +331,15 @@ bc7_get_subset(int ns, int partition, int n) {
} }
static UINT8 static UINT8
expand_quantized(UINT8 v, int bits) { expand_quantized(UINT8 v, int bits)
{
v = v << (8 - bits); v = v << (8 - bits);
return v | (v >> bits); return v | (v >> bits);
} }
static void static void
bc7_lerp(rgba *dst, const rgba *e, int s0, int s1) { bc7_lerp(rgba *dst, const rgba *e, int s0, int s1)
{
int t0 = 64 - s0; int t0 = 64 - s0;
int t1 = 64 - s1; int t1 = 64 - s1;
dst->r = (UINT8)((t0 * e[0].r + s0 * e[1].r + 32) >> 6); dst->r = (UINT8)((t0 * e[0].r + s0 * e[1].r + 32) >> 6);
@ -334,7 +349,8 @@ bc7_lerp(rgba *dst, const rgba *e, int s0, int s1) {
} }
static void static void
decode_bc7_block(rgba *col, const UINT8 *src) { decode_bc7_block(rgba *col, const UINT8 *src)
{
rgba endpoints[6]; rgba endpoints[6];
int bit = 0, cibit, aibit; int bit = 0, cibit, aibit;
int mode = src[0]; int mode = src[0];
@ -594,7 +610,8 @@ static const UINT8 bc6_bit_packings[][75] = {
64, 65, 66, 67, 31, 30, 29, 28, 27, 26, 80, 81, 82, 83, 47, 46, 45, 44, 43, 42}}; 64, 65, 66, 67, 31, 30, 29, 28, 27, 26, 80, 81, 82, 83, 47, 46, 45, 44, 43, 42}};
static void static void
bc6_sign_extend(UINT16 *v, int prec) { bc6_sign_extend(UINT16 *v, int prec)
{
int x = *v; int x = *v;
if (x & (1 << (prec - 1))) { if (x & (1 << (prec - 1))) {
x |= -1 << prec; x |= -1 << prec;
@ -603,7 +620,8 @@ bc6_sign_extend(UINT16 *v, int prec) {
} }
static int static int
bc6_unquantize(UINT16 v, int prec, int sign) { bc6_unquantize(UINT16 v, int prec, int sign)
{
int s = 0; int s = 0;
int x; int x;
if (!sign) { if (!sign) {
@ -644,7 +662,8 @@ bc6_unquantize(UINT16 v, int prec, int sign) {
} }
static float static float
half_to_float(UINT16 h) { half_to_float(UINT16 h)
{
/* https://gist.github.com/rygorous/2144712 */ /* https://gist.github.com/rygorous/2144712 */
union { union {
UINT32 u; UINT32 u;
@ -662,7 +681,8 @@ half_to_float(UINT16 h) {
} }
static float static float
bc6_finalize(int v, int sign) { bc6_finalize(int v, int sign)
{
if (sign) { if (sign) {
if (v < 0) { if (v < 0) {
v = ((-v) * 31) / 32; v = ((-v) * 31) / 32;
@ -676,7 +696,8 @@ bc6_finalize(int v, int sign) {
} }
static UINT8 static UINT8
bc6_clamp(float value) { bc6_clamp(float value)
{
if (value < 0.0f) { if (value < 0.0f) {
return 0; return 0;
} else if (value > 1.0f) { } else if (value > 1.0f) {
@ -687,7 +708,8 @@ bc6_clamp(float value) {
} }
static void static void
bc6_lerp(rgba *col, int *e0, int *e1, int s, int sign) { bc6_lerp(rgba *col, int *e0, int *e1, int s, int sign)
{
int r, g, b; int r, g, b;
int t = 64 - s; int t = 64 - s;
r = (e0[0] * t + e1[0] * s) >> 6; r = (e0[0] * t + e1[0] * s) >> 6;
@ -699,7 +721,8 @@ bc6_lerp(rgba *col, int *e0, int *e1, int s, int sign) {
} }
static void static void
decode_bc6_block(rgba *col, const UINT8 *src, int sign) { decode_bc6_block(rgba *col, const UINT8 *src, int sign)
{
UINT16 endpoints[12]; /* storage for r0, g0, b0, r1, ... */ UINT16 endpoints[12]; /* storage for r0, g0, b0, r1, ... */
int ueps[12]; int ueps[12];
int i, i0, ib2, di, dw, mask, numep, s; int i, i0, ib2, di, dw, mask, numep, s;
@ -782,7 +805,8 @@ decode_bc6_block(rgba *col, const UINT8 *src, int sign) {
} }
static void static void
put_block(Imaging im, ImagingCodecState state, const char *col, int sz, int C) { put_block(Imaging im, ImagingCodecState state, const char *col, int sz, int C)
{
int width = state->xsize; int width = state->xsize;
int height = state->ysize; int height = state->ysize;
int xmax = width + state->xoff; int xmax = width + state->xoff;
@ -830,7 +854,8 @@ decode_bcn(
int bytes, int bytes,
int N, int N,
int C, int C,
char *pixel_format) { char *pixel_format)
{
int ymax = state->ysize + state->yoff; int ymax = state->ysize + state->yoff;
const UINT8 *ptr = src; const UINT8 *ptr = src;
switch (N) { switch (N) {
@ -889,7 +914,8 @@ decode_bcn(
} }
int int
ImagingBcnDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingBcnDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
int N = state->state & 0xf; int N = state->state & 0xf;
int width = state->xsize; int width = state->xsize;
int height = state->ysize; int height = state->ysize;

View File

@ -18,7 +18,8 @@
#include "Bit.h" #include "Bit.h"
int int
ImagingBitDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingBitDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
BITSTATE *bitstate = state->context; BITSTATE *bitstate = state->context;
UINT8 *ptr; UINT8 *ptr;

View File

@ -18,7 +18,8 @@
#include "Imaging.h" #include "Imaging.h"
Imaging Imaging
ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha) { ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha)
{
Imaging imOut; Imaging imOut;
int x, y; int x, y;

View File

@ -13,7 +13,8 @@ void static inline ImagingLineBoxBlur32(
int edgeA, int edgeA,
int edgeB, int edgeB,
UINT32 ww, UINT32 ww,
UINT32 fw) { UINT32 fw)
{
int x; int x;
UINT32 acc[4]; UINT32 acc[4];
UINT32 bulk[4]; UINT32 bulk[4];
@ -109,7 +110,8 @@ void static inline ImagingLineBoxBlur8(
int edgeA, int edgeA,
int edgeB, int edgeB,
UINT32 ww, UINT32 ww,
UINT32 fw) { UINT32 fw)
{
int x; int x;
UINT32 acc; UINT32 acc;
UINT32 bulk; UINT32 bulk;
@ -167,7 +169,8 @@ void static inline ImagingLineBoxBlur8(
} }
Imaging Imaging
ImagingHorizontalBoxBlur(Imaging imOut, Imaging imIn, float floatRadius) { ImagingHorizontalBoxBlur(Imaging imOut, Imaging imIn, float floatRadius)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int y; int y;
@ -230,7 +233,8 @@ ImagingHorizontalBoxBlur(Imaging imOut, Imaging imIn, float floatRadius) {
} }
Imaging Imaging
ImagingBoxBlur(Imaging imOut, Imaging imIn, float xradius, float yradius, int n) { ImagingBoxBlur(Imaging imOut, Imaging imIn, float xradius, float yradius, int n)
{
int i; int i;
Imaging imTransposed; Imaging imTransposed;
@ -296,7 +300,8 @@ ImagingBoxBlur(Imaging imOut, Imaging imIn, float xradius, float yradius, int n)
} }
static float static float
_gaussian_blur_radius(float radius, int passes) { _gaussian_blur_radius(float radius, int passes)
{
float sigma2, L, l, a; float sigma2, L, l, a;
sigma2 = radius * radius / passes; sigma2 = radius * radius / passes;
@ -314,7 +319,8 @@ _gaussian_blur_radius(float radius, int passes) {
Imaging Imaging
ImagingGaussianBlur( ImagingGaussianBlur(
Imaging imOut, Imaging imIn, float xradius, float yradius, int passes) { Imaging imOut, Imaging imIn, float xradius, float yradius, int passes)
{
return ImagingBoxBlur( return ImagingBoxBlur(
imOut, imOut,
imIn, imIn,

View File

@ -60,7 +60,8 @@
return imOut; return imOut;
static Imaging static Imaging
create(Imaging im1, Imaging im2, char *mode) { create(Imaging im1, Imaging im2, char *mode)
{
int xsize, ysize; int xsize, ysize;
if (!im1 || !im2 || im1->type != IMAGING_TYPE_UINT8 || if (!im1 || !im2 || im1->type != IMAGING_TYPE_UINT8 ||
@ -78,67 +79,80 @@ create(Imaging im1, Imaging im2, char *mode) {
} }
Imaging Imaging
ImagingChopLighter(Imaging imIn1, Imaging imIn2) { ImagingChopLighter(Imaging imIn1, Imaging imIn2)
{
CHOP((in1[x] > in2[x]) ? in1[x] : in2[x]); CHOP((in1[x] > in2[x]) ? in1[x] : in2[x]);
} }
Imaging Imaging
ImagingChopDarker(Imaging imIn1, Imaging imIn2) { ImagingChopDarker(Imaging imIn1, Imaging imIn2)
{
CHOP((in1[x] < in2[x]) ? in1[x] : in2[x]); CHOP((in1[x] < in2[x]) ? in1[x] : in2[x]);
} }
Imaging Imaging
ImagingChopDifference(Imaging imIn1, Imaging imIn2) { ImagingChopDifference(Imaging imIn1, Imaging imIn2)
{
CHOP(abs((int)in1[x] - (int)in2[x])); CHOP(abs((int)in1[x] - (int)in2[x]));
} }
Imaging Imaging
ImagingChopMultiply(Imaging imIn1, Imaging imIn2) { ImagingChopMultiply(Imaging imIn1, Imaging imIn2)
{
CHOP((int)in1[x] * (int)in2[x] / 255); CHOP((int)in1[x] * (int)in2[x] / 255);
} }
Imaging Imaging
ImagingChopScreen(Imaging imIn1, Imaging imIn2) { ImagingChopScreen(Imaging imIn1, Imaging imIn2)
{
CHOP(255 - ((int)(255 - in1[x]) * (int)(255 - in2[x])) / 255); CHOP(255 - ((int)(255 - in1[x]) * (int)(255 - in2[x])) / 255);
} }
Imaging Imaging
ImagingChopAdd(Imaging imIn1, Imaging imIn2, float scale, int offset) { ImagingChopAdd(Imaging imIn1, Imaging imIn2, float scale, int offset)
{
CHOP(((int)in1[x] + (int)in2[x]) / scale + offset); CHOP(((int)in1[x] + (int)in2[x]) / scale + offset);
} }
Imaging Imaging
ImagingChopSubtract(Imaging imIn1, Imaging imIn2, float scale, int offset) { ImagingChopSubtract(Imaging imIn1, Imaging imIn2, float scale, int offset)
{
CHOP(((int)in1[x] - (int)in2[x]) / scale + offset); CHOP(((int)in1[x] - (int)in2[x]) / scale + offset);
} }
Imaging Imaging
ImagingChopAnd(Imaging imIn1, Imaging imIn2) { ImagingChopAnd(Imaging imIn1, Imaging imIn2)
{
CHOP2((in1[x] && in2[x]) ? 255 : 0, "1"); CHOP2((in1[x] && in2[x]) ? 255 : 0, "1");
} }
Imaging Imaging
ImagingChopOr(Imaging imIn1, Imaging imIn2) { ImagingChopOr(Imaging imIn1, Imaging imIn2)
{
CHOP2((in1[x] || in2[x]) ? 255 : 0, "1"); CHOP2((in1[x] || in2[x]) ? 255 : 0, "1");
} }
Imaging Imaging
ImagingChopXor(Imaging imIn1, Imaging imIn2) { ImagingChopXor(Imaging imIn1, Imaging imIn2)
{
CHOP2(((in1[x] != 0) ^ (in2[x] != 0)) ? 255 : 0, "1"); CHOP2(((in1[x] != 0) ^ (in2[x] != 0)) ? 255 : 0, "1");
} }
Imaging Imaging
ImagingChopAddModulo(Imaging imIn1, Imaging imIn2) { ImagingChopAddModulo(Imaging imIn1, Imaging imIn2)
{
CHOP2(in1[x] + in2[x], NULL); CHOP2(in1[x] + in2[x], NULL);
} }
Imaging Imaging
ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2) { ImagingChopSubtractModulo(Imaging imIn1, Imaging imIn2)
{
CHOP2(in1[x] - in2[x], NULL); CHOP2(in1[x] - in2[x], NULL);
} }
Imaging Imaging
ImagingChopSoftLight(Imaging imIn1, Imaging imIn2) { ImagingChopSoftLight(Imaging imIn1, Imaging imIn2)
{
CHOP2( CHOP2(
(((255 - in1[x]) * (in1[x] * in2[x])) / 65536) + (((255 - in1[x]) * (in1[x] * in2[x])) / 65536) +
(in1[x] * (255 - ((255 - in1[x]) * (255 - in2[x]) / 255))) / 255, (in1[x] * (255 - ((255 - in1[x]) * (255 - in2[x]) / 255))) / 255,
@ -146,7 +160,8 @@ ImagingChopSoftLight(Imaging imIn1, Imaging imIn2) {
} }
Imaging Imaging
ImagingChopHardLight(Imaging imIn1, Imaging imIn2) { ImagingChopHardLight(Imaging imIn1, Imaging imIn2)
{
CHOP2( CHOP2(
(in2[x] < 128) ? ((in1[x] * in2[x]) / 127) (in2[x] < 128) ? ((in1[x] * in2[x]) / 127)
: 255 - (((255 - in2[x]) * (255 - in1[x])) / 127), : 255 - (((255 - in2[x]) * (255 - in1[x])) / 127),
@ -154,7 +169,8 @@ ImagingChopHardLight(Imaging imIn1, Imaging imIn2) {
} }
Imaging Imaging
ImagingOverlay(Imaging imIn1, Imaging imIn2) { ImagingOverlay(Imaging imIn1, Imaging imIn2)
{
CHOP2( CHOP2(
(in1[x] < 128) ? ((in1[x] * in2[x]) / 127) (in1[x] < 128) ? ((in1[x] * in2[x]) / 127)
: 255 - (((255 - in1[x]) * (255 - in2[x])) / 127), : 255 - (((255 - in1[x]) * (255 - in2[x])) / 127),

View File

@ -16,19 +16,22 @@
#define SHIFT_BITS (16 - 1) #define SHIFT_BITS (16 - 1)
static inline UINT8 static inline UINT8
clip8(int in) { clip8(int in)
{
return clip8_lookups[(in + PRECISION_ROUNDING) >> PRECISION_BITS]; return clip8_lookups[(in + PRECISION_ROUNDING) >> PRECISION_BITS];
} }
static inline void static inline void
interpolate3(INT16 out[3], const INT16 a[3], const INT16 b[3], INT16 shift) { interpolate3(INT16 out[3], const INT16 a[3], const INT16 b[3], INT16 shift)
{
out[0] = (a[0] * ((1 << SHIFT_BITS) - shift) + b[0] * shift) >> SHIFT_BITS; out[0] = (a[0] * ((1 << SHIFT_BITS) - shift) + b[0] * shift) >> SHIFT_BITS;
out[1] = (a[1] * ((1 << SHIFT_BITS) - shift) + b[1] * shift) >> SHIFT_BITS; out[1] = (a[1] * ((1 << SHIFT_BITS) - shift) + b[1] * shift) >> SHIFT_BITS;
out[2] = (a[2] * ((1 << SHIFT_BITS) - shift) + b[2] * shift) >> SHIFT_BITS; out[2] = (a[2] * ((1 << SHIFT_BITS) - shift) + b[2] * shift) >> SHIFT_BITS;
} }
static inline void static inline void
interpolate4(INT16 out[4], const INT16 a[4], const INT16 b[4], INT16 shift) { interpolate4(INT16 out[4], const INT16 a[4], const INT16 b[4], INT16 shift)
{
out[0] = (a[0] * ((1 << SHIFT_BITS) - shift) + b[0] * shift) >> SHIFT_BITS; out[0] = (a[0] * ((1 << SHIFT_BITS) - shift) + b[0] * shift) >> SHIFT_BITS;
out[1] = (a[1] * ((1 << SHIFT_BITS) - shift) + b[1] * shift) >> SHIFT_BITS; out[1] = (a[1] * ((1 << SHIFT_BITS) - shift) + b[1] * shift) >> SHIFT_BITS;
out[2] = (a[2] * ((1 << SHIFT_BITS) - shift) + b[2] * shift) >> SHIFT_BITS; out[2] = (a[2] * ((1 << SHIFT_BITS) - shift) + b[2] * shift) >> SHIFT_BITS;
@ -36,7 +39,8 @@ interpolate4(INT16 out[4], const INT16 a[4], const INT16 b[4], INT16 shift) {
} }
static inline int static inline int
table_index3D(int index1D, int index2D, int index3D, int size1D, int size1D_2D) { table_index3D(int index1D, int index2D, int index3D, int size1D, int size1D_2D)
{
return index1D + index2D * size1D + index3D * size1D_2D; return index1D + index2D * size1D + index3D * size1D_2D;
} }
@ -63,7 +67,8 @@ ImagingColorLUT3D_linear(
int size1D, int size1D,
int size2D, int size2D,
int size3D, int size3D,
INT16 *table) { INT16 *table)
{
/* This float to int conversion doesn't have rounding /* This float to int conversion doesn't have rounding
error compensation (+0.5) for two reasons: error compensation (+0.5) for two reasons:
1. As we don't hit the highest value, 1. As we don't hit the highest value,

View File

@ -48,13 +48,15 @@
/* ------------------- */ /* ------------------- */
static void static void
bit2l(UINT8 *out, const UINT8 *in, int xsize) { bit2l(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) *out++ = (*in++ != 0) ? 255 : 0; for (x = 0; x < xsize; x++) *out++ = (*in++ != 0) ? 255 : 0;
} }
static void static void
bit2rgb(UINT8 *out, const UINT8 *in, int xsize) { bit2rgb(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
UINT8 v = (*in++ != 0) ? 255 : 0; UINT8 v = (*in++ != 0) ? 255 : 0;
@ -66,7 +68,8 @@ bit2rgb(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
bit2cmyk(UINT8 *out, const UINT8 *in, int xsize) { bit2cmyk(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
*out++ = 0; *out++ = 0;
@ -77,7 +80,8 @@ bit2cmyk(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
bit2ycbcr(UINT8 *out, const UINT8 *in, int xsize) { bit2ycbcr(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
*out++ = (*in++ != 0) ? 255 : 0; *out++ = (*in++ != 0) ? 255 : 0;
@ -88,7 +92,8 @@ bit2ycbcr(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
bit2hsv(UINT8 *out, const UINT8 *in, int xsize) { bit2hsv(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, out += 4) { for (x = 0; x < xsize; x++, out += 4) {
UINT8 v = (*in++ != 0) ? 255 : 0; UINT8 v = (*in++ != 0) ? 255 : 0;
@ -104,7 +109,8 @@ bit2hsv(UINT8 *out, const UINT8 *in, int xsize) {
/* ----------------- */ /* ----------------- */
static void static void
l2bit(UINT8 *out, const UINT8 *in, int xsize) { l2bit(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
*out++ = (*in++ >= 128) ? 255 : 0; *out++ = (*in++ >= 128) ? 255 : 0;
@ -112,7 +118,8 @@ l2bit(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
lA2la(UINT8 *out, const UINT8 *in, int xsize) { lA2la(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
unsigned int alpha, pixel, tmp; unsigned int alpha, pixel, tmp;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
@ -128,7 +135,8 @@ lA2la(UINT8 *out, const UINT8 *in, int xsize) {
/* RGBa -> RGBA conversion to remove premultiplication /* RGBa -> RGBA conversion to remove premultiplication
Needed for correct transforms/resizing on RGBA images */ Needed for correct transforms/resizing on RGBA images */
static void static void
la2lA(UINT8 *out, const UINT8 *in, int xsize) { la2lA(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
unsigned int alpha, pixel; unsigned int alpha, pixel;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
@ -146,7 +154,8 @@ la2lA(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
l2la(UINT8 *out, const UINT8 *in, int xsize) { l2la(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
UINT8 v = *in++; UINT8 v = *in++;
@ -158,7 +167,8 @@ l2la(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
l2rgb(UINT8 *out, const UINT8 *in, int xsize) { l2rgb(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
UINT8 v = *in++; UINT8 v = *in++;
@ -170,7 +180,8 @@ l2rgb(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
l2hsv(UINT8 *out, const UINT8 *in, int xsize) { l2hsv(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, out += 4) { for (x = 0; x < xsize; x++, out += 4) {
UINT8 v = *in++; UINT8 v = *in++;
@ -182,7 +193,8 @@ l2hsv(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
la2l(UINT8 *out, const UINT8 *in, int xsize) { la2l(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
*out++ = in[0]; *out++ = in[0];
@ -190,7 +202,8 @@ la2l(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
la2rgb(UINT8 *out, const UINT8 *in, int xsize) { la2rgb(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
UINT8 v = in[0]; UINT8 v = in[0];
@ -202,7 +215,8 @@ la2rgb(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
la2hsv(UINT8 *out, const UINT8 *in, int xsize) { la2hsv(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out += 4) { for (x = 0; x < xsize; x++, in += 4, out += 4) {
UINT8 v = in[0]; UINT8 v = in[0];
@ -214,7 +228,8 @@ la2hsv(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgb2bit(UINT8 *out, const UINT8 *in, int xsize) { rgb2bit(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */
@ -223,7 +238,8 @@ rgb2bit(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgb2l(UINT8 *out, const UINT8 *in, int xsize) { rgb2l(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */
@ -232,7 +248,8 @@ rgb2l(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgb2la(UINT8 *out, const UINT8 *in, int xsize) { rgb2la(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out += 4) { for (x = 0; x < xsize; x++, in += 4, out += 4) {
/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */
@ -242,7 +259,8 @@ rgb2la(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgb2i(UINT8 *out_, const UINT8 *in, int xsize) { rgb2i(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out_ += 4) { for (x = 0; x < xsize; x++, in += 4, out_ += 4) {
INT32 v = L24(in) >> 16; INT32 v = L24(in) >> 16;
@ -251,7 +269,8 @@ rgb2i(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
rgb2i16l(UINT8 *out_, const UINT8 *in, int xsize) { rgb2i16l(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
*out_++ = L24(in) >> 16; *out_++ = L24(in) >> 16;
@ -260,7 +279,8 @@ rgb2i16l(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
rgb2i16b(UINT8 *out_, const UINT8 *in, int xsize) { rgb2i16b(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
*out_++ = 0; *out_++ = 0;
@ -269,7 +289,8 @@ rgb2i16b(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
rgb2f(UINT8 *out_, const UINT8 *in, int xsize) { rgb2f(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out_ += 4) { for (x = 0; x < xsize; x++, in += 4, out_ += 4) {
FLOAT32 v = (float)L(in) / 1000.0F; FLOAT32 v = (float)L(in) / 1000.0F;
@ -278,7 +299,8 @@ rgb2f(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
rgb2bgr15(UINT8 *out_, const UINT8 *in, int xsize) { rgb2bgr15(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out_ += 2) { for (x = 0; x < xsize; x++, in += 4, out_ += 2) {
UINT16 v = ((((UINT16)in[0]) << 7) & 0x7c00) + UINT16 v = ((((UINT16)in[0]) << 7) & 0x7c00) +
@ -289,7 +311,8 @@ rgb2bgr15(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
rgb2bgr16(UINT8 *out_, const UINT8 *in, int xsize) { rgb2bgr16(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out_ += 2) { for (x = 0; x < xsize; x++, in += 4, out_ += 2) {
UINT16 v = ((((UINT16)in[0]) << 8) & 0xf800) + UINT16 v = ((((UINT16)in[0]) << 8) & 0xf800) +
@ -300,7 +323,8 @@ rgb2bgr16(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
rgb2bgr24(UINT8 *out, const UINT8 *in, int xsize) { rgb2bgr24(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
*out++ = in[2]; *out++ = in[2];
@ -310,7 +334,8 @@ rgb2bgr24(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgb2hsv_row(UINT8 *out, const UINT8 *in) { // following colorsys.py rgb2hsv_row(UINT8 *out, const UINT8 *in)
{ // following colorsys.py
float h, s, rc, gc, bc, cr; float h, s, rc, gc, bc, cr;
UINT8 maxc, minc; UINT8 maxc, minc;
UINT8 r, g, b; UINT8 r, g, b;
@ -350,7 +375,8 @@ rgb2hsv_row(UINT8 *out, const UINT8 *in) { // following colorsys.py
} }
static void static void
rgb2hsv(UINT8 *out, const UINT8 *in, int xsize) { rgb2hsv(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out += 4) { for (x = 0; x < xsize; x++, in += 4, out += 4) {
rgb2hsv_row(out, in); rgb2hsv_row(out, in);
@ -359,7 +385,8 @@ rgb2hsv(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
hsv2rgb(UINT8 *out, const UINT8 *in, int xsize) { // following colorsys.py hsv2rgb(UINT8 *out, const UINT8 *in, int xsize)
{ // following colorsys.py
int p, q, t; int p, q, t;
UINT8 up, uq, ut; UINT8 up, uq, ut;
@ -430,7 +457,8 @@ hsv2rgb(UINT8 *out, const UINT8 *in, int xsize) { // following colorsys.py
/* ---------------- */ /* ---------------- */
static void static void
rgb2rgba(UINT8 *out, const UINT8 *in, int xsize) { rgb2rgba(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
*out++ = *in++; *out++ = *in++;
@ -442,7 +470,8 @@ rgb2rgba(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgba2la(UINT8 *out, const UINT8 *in, int xsize) { rgba2la(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out += 4) { for (x = 0; x < xsize; x++, in += 4, out += 4) {
/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */ /* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */
@ -452,7 +481,8 @@ rgba2la(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgba2rgb(UINT8 *out, const UINT8 *in, int xsize) { rgba2rgb(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
*out++ = *in++; *out++ = *in++;
@ -464,7 +494,8 @@ rgba2rgb(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgbA2rgba(UINT8 *out, const UINT8 *in, int xsize) { rgbA2rgba(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
unsigned int alpha, tmp; unsigned int alpha, tmp;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
@ -479,7 +510,8 @@ rgbA2rgba(UINT8 *out, const UINT8 *in, int xsize) {
/* RGBa -> RGBA conversion to remove premultiplication /* RGBa -> RGBA conversion to remove premultiplication
Needed for correct transforms/resizing on RGBA images */ Needed for correct transforms/resizing on RGBA images */
static void static void
rgba2rgbA(UINT8 *out, const UINT8 *in, int xsize) { rgba2rgbA(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
unsigned int alpha; unsigned int alpha;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
@ -498,7 +530,8 @@ rgba2rgbA(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgba2rgb_(UINT8 *out, const UINT8 *in, int xsize) { rgba2rgb_(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
unsigned int alpha; unsigned int alpha;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
@ -523,7 +556,8 @@ rgba2rgb_(UINT8 *out, const UINT8 *in, int xsize) {
*/ */
static void static void
rgbT2a(UINT8 *out, UINT8 *in, int xsize, int r, int g, int b, int premultiplied) { rgbT2a(UINT8 *out, UINT8 *in, int xsize, int r, int g, int b, int premultiplied)
{
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
UINT32 trns = ((r & 0xff) << 24) | ((g & 0xff) << 16) | ((b & 0xff) << 8) | 0xff; UINT32 trns = ((r & 0xff) << 24) | ((g & 0xff) << 16) | ((b & 0xff) << 8) | 0xff;
UINT32 repl = premultiplied ? 0 : (trns & 0xffffff00); UINT32 repl = premultiplied ? 0 : (trns & 0xffffff00);
@ -549,7 +583,8 @@ rgbT2a(UINT8 *out, UINT8 *in, int xsize, int r, int g, int b, int premultiplied)
/* ---------------- */ /* ---------------- */
static void static void
l2cmyk(UINT8 *out, const UINT8 *in, int xsize) { l2cmyk(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
*out++ = 0; *out++ = 0;
@ -560,7 +595,8 @@ l2cmyk(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
la2cmyk(UINT8 *out, const UINT8 *in, int xsize) { la2cmyk(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
*out++ = 0; *out++ = 0;
@ -571,7 +607,8 @@ la2cmyk(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
rgb2cmyk(UINT8 *out, const UINT8 *in, int xsize) { rgb2cmyk(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
/* Note: no undercolour removal */ /* Note: no undercolour removal */
@ -584,7 +621,8 @@ rgb2cmyk(UINT8 *out, const UINT8 *in, int xsize) {
} }
void void
cmyk2rgb(UINT8 *out, const UINT8 *in, int xsize) { cmyk2rgb(UINT8 *out, const UINT8 *in, int xsize)
{
int x, nk, tmp; int x, nk, tmp;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
nk = 255 - in[3]; nk = 255 - in[3];
@ -598,7 +636,8 @@ cmyk2rgb(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
cmyk2hsv(UINT8 *out, const UINT8 *in, int xsize) { cmyk2hsv(UINT8 *out, const UINT8 *in, int xsize)
{
int x, nk, tmp; int x, nk, tmp;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
nk = 255 - in[3]; nk = 255 - in[3];
@ -617,7 +656,8 @@ cmyk2hsv(UINT8 *out, const UINT8 *in, int xsize) {
/* ------------- */ /* ------------- */
static void static void
bit2i(UINT8 *out_, const UINT8 *in, int xsize) { bit2i(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, out_ += 4) { for (x = 0; x < xsize; x++, out_ += 4) {
INT32 v = (*in++ != 0) ? 255 : 0; INT32 v = (*in++ != 0) ? 255 : 0;
@ -626,7 +666,8 @@ bit2i(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
l2i(UINT8 *out_, const UINT8 *in, int xsize) { l2i(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, out_ += 4) { for (x = 0; x < xsize; x++, out_ += 4) {
INT32 v = *in++; INT32 v = *in++;
@ -635,7 +676,8 @@ l2i(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
i2l(UINT8 *out, const UINT8 *in_, int xsize) { i2l(UINT8 *out, const UINT8 *in_, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, out++, in_ += 4) { for (x = 0; x < xsize; x++, out++, in_ += 4) {
INT32 v; INT32 v;
@ -651,7 +693,8 @@ i2l(UINT8 *out, const UINT8 *in_, int xsize) {
} }
static void static void
i2f(UINT8 *out_, const UINT8 *in_, int xsize) { i2f(UINT8 *out_, const UINT8 *in_, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in_ += 4, out_ += 4) { for (x = 0; x < xsize; x++, in_ += 4, out_ += 4) {
INT32 i; INT32 i;
@ -663,7 +706,8 @@ i2f(UINT8 *out_, const UINT8 *in_, int xsize) {
} }
static void static void
i2rgb(UINT8 *out, const UINT8 *in_, int xsize) { i2rgb(UINT8 *out, const UINT8 *in_, int xsize)
{
int x; int x;
INT32 *in = (INT32 *)in_; INT32 *in = (INT32 *)in_;
for (x = 0; x < xsize; x++, in++, out += 4) { for (x = 0; x < xsize; x++, in++, out += 4) {
@ -679,7 +723,8 @@ i2rgb(UINT8 *out, const UINT8 *in_, int xsize) {
} }
static void static void
i2hsv(UINT8 *out, const UINT8 *in_, int xsize) { i2hsv(UINT8 *out, const UINT8 *in_, int xsize)
{
int x; int x;
INT32 *in = (INT32 *)in_; INT32 *in = (INT32 *)in_;
for (x = 0; x < xsize; x++, in++, out += 4) { for (x = 0; x < xsize; x++, in++, out += 4) {
@ -701,7 +746,8 @@ i2hsv(UINT8 *out, const UINT8 *in_, int xsize) {
/* ------------- */ /* ------------- */
static void static void
bit2f(UINT8 *out_, const UINT8 *in, int xsize) { bit2f(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, out_ += 4) { for (x = 0; x < xsize; x++, out_ += 4) {
FLOAT32 f = (*in++ != 0) ? 255.0F : 0.0F; FLOAT32 f = (*in++ != 0) ? 255.0F : 0.0F;
@ -710,7 +756,8 @@ bit2f(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
l2f(UINT8 *out_, const UINT8 *in, int xsize) { l2f(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, out_ += 4) { for (x = 0; x < xsize; x++, out_ += 4) {
FLOAT32 f = (FLOAT32)*in++; FLOAT32 f = (FLOAT32)*in++;
@ -719,7 +766,8 @@ l2f(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
f2l(UINT8 *out, const UINT8 *in_, int xsize) { f2l(UINT8 *out, const UINT8 *in_, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, out++, in_ += 4) { for (x = 0; x < xsize; x++, out++, in_ += 4) {
FLOAT32 v; FLOAT32 v;
@ -735,7 +783,8 @@ f2l(UINT8 *out, const UINT8 *in_, int xsize) {
} }
static void static void
f2i(UINT8 *out_, const UINT8 *in_, int xsize) { f2i(UINT8 *out_, const UINT8 *in_, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in_ += 4, out_ += 4) { for (x = 0; x < xsize; x++, in_ += 4, out_ += 4) {
FLOAT32 f; FLOAT32 f;
@ -753,7 +802,8 @@ f2i(UINT8 *out_, const UINT8 *in_, int xsize) {
/* See ConvertYCbCr.c for RGB/YCbCr tables */ /* See ConvertYCbCr.c for RGB/YCbCr tables */
static void static void
l2ycbcr(UINT8 *out, const UINT8 *in, int xsize) { l2ycbcr(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
*out++ = *in++; *out++ = *in++;
@ -764,7 +814,8 @@ l2ycbcr(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
la2ycbcr(UINT8 *out, const UINT8 *in, int xsize) { la2ycbcr(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
*out++ = in[0]; *out++ = in[0];
@ -775,7 +826,8 @@ la2ycbcr(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
ycbcr2l(UINT8 *out, const UINT8 *in, int xsize) { ycbcr2l(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
*out++ = in[0]; *out++ = in[0];
@ -783,7 +835,8 @@ ycbcr2l(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
ycbcr2la(UINT8 *out, const UINT8 *in, int xsize) { ycbcr2la(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out += 4) { for (x = 0; x < xsize; x++, in += 4, out += 4) {
out[0] = out[1] = out[2] = in[0]; out[0] = out[1] = out[2] = in[0];
@ -796,7 +849,8 @@ ycbcr2la(UINT8 *out, const UINT8 *in, int xsize) {
/* ------------------------- */ /* ------------------------- */
static void static void
I_I16L(UINT8 *out, const UINT8 *in_, int xsize) { I_I16L(UINT8 *out, const UINT8 *in_, int xsize)
{
int x, v; int x, v;
for (x = 0; x < xsize; x++, in_ += 4) { for (x = 0; x < xsize; x++, in_ += 4) {
INT32 i; INT32 i;
@ -808,7 +862,8 @@ I_I16L(UINT8 *out, const UINT8 *in_, int xsize) {
} }
static void static void
I_I16B(UINT8 *out, const UINT8 *in_, int xsize) { I_I16B(UINT8 *out, const UINT8 *in_, int xsize)
{
int x, v; int x, v;
for (x = 0; x < xsize; x++, in_ += 4) { for (x = 0; x < xsize; x++, in_ += 4) {
INT32 i; INT32 i;
@ -820,7 +875,8 @@ I_I16B(UINT8 *out, const UINT8 *in_, int xsize) {
} }
static void static void
I16L_I(UINT8 *out_, const UINT8 *in, int xsize) { I16L_I(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 2, out_ += 4) { for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
INT32 v = in[0] + ((int)in[1] << 8); INT32 v = in[0] + ((int)in[1] << 8);
@ -829,7 +885,8 @@ I16L_I(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
I16B_I(UINT8 *out_, const UINT8 *in, int xsize) { I16B_I(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 2, out_ += 4) { for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
INT32 v = in[1] + ((int)in[0] << 8); INT32 v = in[1] + ((int)in[0] << 8);
@ -838,7 +895,8 @@ I16B_I(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
I16L_F(UINT8 *out_, const UINT8 *in, int xsize) { I16L_F(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 2, out_ += 4) { for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
FLOAT32 v = in[0] + ((int)in[1] << 8); FLOAT32 v = in[0] + ((int)in[1] << 8);
@ -847,7 +905,8 @@ I16L_F(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
I16B_F(UINT8 *out_, const UINT8 *in, int xsize) { I16B_F(UINT8 *out_, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 2, out_ += 4) { for (x = 0; x < xsize; x++, in += 2, out_ += 4) {
FLOAT32 v = in[1] + ((int)in[0] << 8); FLOAT32 v = in[1] + ((int)in[0] << 8);
@ -856,7 +915,8 @@ I16B_F(UINT8 *out_, const UINT8 *in, int xsize) {
} }
static void static void
L_I16L(UINT8 *out, const UINT8 *in, int xsize) { L_I16L(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in++) { for (x = 0; x < xsize; x++, in++) {
*out++ = *in; *out++ = *in;
@ -865,7 +925,8 @@ L_I16L(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
L_I16B(UINT8 *out, const UINT8 *in, int xsize) { L_I16B(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in++) { for (x = 0; x < xsize; x++, in++) {
*out++ = 0; *out++ = 0;
@ -874,7 +935,8 @@ L_I16B(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
I16L_L(UINT8 *out, const UINT8 *in, int xsize) { I16L_L(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 2) { for (x = 0; x < xsize; x++, in += 2) {
if (in[1] != 0) { if (in[1] != 0) {
@ -886,7 +948,8 @@ I16L_L(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
I16B_L(UINT8 *out, const UINT8 *in, int xsize) { I16B_L(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 2) { for (x = 0; x < xsize; x++, in += 2) {
if (in[0] != 0) { if (in[0] != 0) {
@ -898,7 +961,8 @@ I16B_L(UINT8 *out, const UINT8 *in, int xsize) {
} }
static void static void
I16_RGB(UINT8 *out, const UINT8 *in, int xsize) { I16_RGB(UINT8 *out, const UINT8 *in, int xsize)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 2) { for (x = 0; x < xsize; x++, in += 2) {
UINT8 v = in[1] == 0 ? in[0] : 255; UINT8 v = in[1] == 0 ? in[0] : 255;
@ -1053,7 +1117,8 @@ static struct {
/* ------------------- */ /* ------------------- */
static void static void
p2bit(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2bit(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
/* FIXME: precalculate grayscale palette? */ /* FIXME: precalculate grayscale palette? */
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
@ -1062,7 +1127,8 @@ p2bit(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
pa2bit(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { pa2bit(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
/* FIXME: precalculate grayscale palette? */ /* FIXME: precalculate grayscale palette? */
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
@ -1071,7 +1137,8 @@ pa2bit(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
p2l(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2l(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
/* FIXME: precalculate grayscale palette? */ /* FIXME: precalculate grayscale palette? */
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
@ -1080,7 +1147,8 @@ p2l(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
pa2l(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { pa2l(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
/* FIXME: precalculate grayscale palette? */ /* FIXME: precalculate grayscale palette? */
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
@ -1089,7 +1157,8 @@ pa2l(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
pa2p(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { pa2p(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
*out++ = in[0]; *out++ = in[0];
@ -1097,7 +1166,8 @@ pa2p(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
p2pa(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2pa(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
int rgb = strcmp(palette->mode, "RGB"); int rgb = strcmp(palette->mode, "RGB");
for (x = 0; x < xsize; x++, in++) { for (x = 0; x < xsize; x++, in++) {
@ -1110,7 +1180,8 @@ p2pa(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
p2la(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2la(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
/* FIXME: precalculate grayscale palette? */ /* FIXME: precalculate grayscale palette? */
for (x = 0; x < xsize; x++, out += 4) { for (x = 0; x < xsize; x++, out += 4) {
@ -1121,7 +1192,8 @@ p2la(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
pa2la(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { pa2la(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
/* FIXME: precalculate grayscale palette? */ /* FIXME: precalculate grayscale palette? */
for (x = 0; x < xsize; x++, in += 4, out += 4) { for (x = 0; x < xsize; x++, in += 4, out += 4) {
@ -1131,7 +1203,8 @@ pa2la(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
p2i(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette) { p2i(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
for (x = 0; x < xsize; x++, out_ += 4) { for (x = 0; x < xsize; x++, out_ += 4) {
INT32 v = L24(&palette->palette[in[x] * 4]) >> 16; INT32 v = L24(&palette->palette[in[x] * 4]) >> 16;
@ -1140,7 +1213,8 @@ p2i(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
pa2i(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette) { pa2i(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
INT32 *out = (INT32 *)out_; INT32 *out = (INT32 *)out_;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
@ -1149,7 +1223,8 @@ pa2i(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
p2f(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette) { p2f(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
for (x = 0; x < xsize; x++, out_ += 4) { for (x = 0; x < xsize; x++, out_ += 4) {
FLOAT32 v = L(&palette->palette[in[x] * 4]) / 1000.0F; FLOAT32 v = L(&palette->palette[in[x] * 4]) / 1000.0F;
@ -1158,7 +1233,8 @@ p2f(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
pa2f(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette) { pa2f(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
FLOAT32 *out = (FLOAT32 *)out_; FLOAT32 *out = (FLOAT32 *)out_;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
@ -1167,7 +1243,8 @@ pa2f(UINT8 *out_, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
p2rgb(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2rgb(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
const UINT8 *rgb = &palette->palette[*in++ * 4]; const UINT8 *rgb = &palette->palette[*in++ * 4];
@ -1179,7 +1256,8 @@ p2rgb(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
pa2rgb(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { pa2rgb(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
const UINT8 *rgb = &palette->palette[in[0] * 4]; const UINT8 *rgb = &palette->palette[in[0] * 4];
@ -1191,7 +1269,8 @@ pa2rgb(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
p2hsv(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2hsv(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
for (x = 0; x < xsize; x++, out += 4) { for (x = 0; x < xsize; x++, out += 4) {
const UINT8 *rgb = &palette->palette[*in++ * 4]; const UINT8 *rgb = &palette->palette[*in++ * 4];
@ -1201,7 +1280,8 @@ p2hsv(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
pa2hsv(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { pa2hsv(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4, out += 4) { for (x = 0; x < xsize; x++, in += 4, out += 4) {
const UINT8 *rgb = &palette->palette[in[0] * 4]; const UINT8 *rgb = &palette->palette[in[0] * 4];
@ -1211,7 +1291,8 @@ pa2hsv(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
p2rgba(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2rgba(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
for (x = 0; x < xsize; x++) { for (x = 0; x < xsize; x++) {
const UINT8 *rgba = &palette->palette[*in++ * 4]; const UINT8 *rgba = &palette->palette[*in++ * 4];
@ -1223,7 +1304,8 @@ p2rgba(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
pa2rgba(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { pa2rgba(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
int x; int x;
for (x = 0; x < xsize; x++, in += 4) { for (x = 0; x < xsize; x++, in += 4) {
const UINT8 *rgb = &palette->palette[in[0] * 4]; const UINT8 *rgb = &palette->palette[in[0] * 4];
@ -1235,31 +1317,36 @@ pa2rgba(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) {
} }
static void static void
p2cmyk(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2cmyk(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
p2rgb(out, in, xsize, palette); p2rgb(out, in, xsize, palette);
rgb2cmyk(out, out, xsize); rgb2cmyk(out, out, xsize);
} }
static void static void
pa2cmyk(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { pa2cmyk(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
pa2rgb(out, in, xsize, palette); pa2rgb(out, in, xsize, palette);
rgb2cmyk(out, out, xsize); rgb2cmyk(out, out, xsize);
} }
static void static void
p2ycbcr(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { p2ycbcr(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
p2rgb(out, in, xsize, palette); p2rgb(out, in, xsize, palette);
ImagingConvertRGB2YCbCr(out, out, xsize); ImagingConvertRGB2YCbCr(out, out, xsize);
} }
static void static void
pa2ycbcr(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette) { pa2ycbcr(UINT8 *out, const UINT8 *in, int xsize, ImagingPalette palette)
{
pa2rgb(out, in, xsize, palette); pa2rgb(out, in, xsize, palette);
ImagingConvertRGB2YCbCr(out, out, xsize); ImagingConvertRGB2YCbCr(out, out, xsize);
} }
static Imaging static Imaging
frompalette(Imaging imOut, Imaging imIn, const char *mode) { frompalette(Imaging imOut, Imaging imIn, const char *mode)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int alpha; int alpha;
int y; int y;
@ -1328,11 +1415,8 @@ frompalette(Imaging imOut, Imaging imIn, const char *mode) {
#endif #endif
static Imaging static Imaging
topalette( topalette(
Imaging imOut, Imaging imOut, Imaging imIn, const char *mode, ImagingPalette inpalette, int dither)
Imaging imIn, {
const char *mode,
ImagingPalette inpalette,
int dither) {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int alpha; int alpha;
int x, y; int x, y;
@ -1529,7 +1613,8 @@ topalette(
} }
static Imaging static Imaging
tobilevel(Imaging imOut, Imaging imIn) { tobilevel(Imaging imOut, Imaging imIn)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int x, y; int x, y;
int *errors; int *errors;
@ -1623,7 +1708,8 @@ tobilevel(Imaging imOut, Imaging imIn) {
static Imaging static Imaging
convert( convert(
Imaging imOut, Imaging imIn, const char *mode, ImagingPalette palette, int dither) { Imaging imOut, Imaging imIn, const char *mode, ImagingPalette palette, int dither)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
ImagingShuffler convert; ImagingShuffler convert;
int y; int y;
@ -1697,17 +1783,20 @@ convert(
} }
Imaging Imaging
ImagingConvert(Imaging imIn, const char *mode, ImagingPalette palette, int dither) { ImagingConvert(Imaging imIn, const char *mode, ImagingPalette palette, int dither)
{
return convert(NULL, imIn, mode, palette, dither); return convert(NULL, imIn, mode, palette, dither);
} }
Imaging Imaging
ImagingConvert2(Imaging imOut, Imaging imIn) { ImagingConvert2(Imaging imOut, Imaging imIn)
{
return convert(imOut, imIn, imOut->mode, NULL, 0); return convert(imOut, imIn, imOut->mode, NULL, 0);
} }
Imaging Imaging
ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) { ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
ImagingShuffler convert; ImagingShuffler convert;
Imaging imOut = NULL; Imaging imOut = NULL;
@ -1778,7 +1867,8 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) {
} }
Imaging Imaging
ImagingConvertInPlace(Imaging imIn, const char *mode) { ImagingConvertInPlace(Imaging imIn, const char *mode)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
ImagingShuffler convert; ImagingShuffler convert;
int y; int y;

View File

@ -315,7 +315,8 @@ static INT16 B_Cb[] = {
13836, 13949, 14063, 14176, 14289, 14403}; 13836, 13949, 14063, 14176, 14289, 14403};
void void
ImagingConvertRGB2YCbCr(UINT8 *out, const UINT8 *in, int pixels) { ImagingConvertRGB2YCbCr(UINT8 *out, const UINT8 *in, int pixels)
{
int x; int x;
UINT8 a; UINT8 a;
int r, g, b; int r, g, b;
@ -339,7 +340,8 @@ ImagingConvertRGB2YCbCr(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingConvertYCbCr2RGB(UINT8 *out, const UINT8 *in, int pixels) { ImagingConvertYCbCr2RGB(UINT8 *out, const UINT8 *in, int pixels)
{
int x; int x;
UINT8 a; UINT8 a;
int r, g, b; int r, g, b;

View File

@ -18,7 +18,8 @@
#include "Imaging.h" #include "Imaging.h"
static Imaging static Imaging
_copy(Imaging imOut, Imaging imIn) { _copy(Imaging imOut, Imaging imIn)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int y; int y;
@ -47,11 +48,13 @@ _copy(Imaging imOut, Imaging imIn) {
} }
Imaging Imaging
ImagingCopy(Imaging imIn) { ImagingCopy(Imaging imIn)
{
return _copy(NULL, imIn); return _copy(NULL, imIn);
} }
Imaging Imaging
ImagingCopy2(Imaging imOut, Imaging imIn) { ImagingCopy2(Imaging imOut, Imaging imIn)
{
return _copy(imOut, imIn); return _copy(imOut, imIn);
} }

View File

@ -18,7 +18,8 @@
#include "Imaging.h" #include "Imaging.h"
Imaging Imaging
ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1) { ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1)
{
Imaging imOut; Imaging imOut;
int xsize, ysize; int xsize, ysize;
int dx0, dy0, dx1, dy1; int dx0, dy0, dx1, dy1;

View File

@ -26,7 +26,8 @@
#include "ImDib.h" #include "ImDib.h"
char * char *
ImagingGetModeDIB(int size_out[2]) { ImagingGetModeDIB(int size_out[2])
{
/* Get device characteristics */ /* Get device characteristics */
HDC dc; HDC dc;
@ -53,7 +54,8 @@ ImagingGetModeDIB(int size_out[2]) {
} }
ImagingDIB ImagingDIB
ImagingNewDIB(const char *mode, int xsize, int ysize) { ImagingNewDIB(const char *mode, int xsize, int ysize)
{
/* Create a Windows bitmap */ /* Create a Windows bitmap */
ImagingDIB dib; ImagingDIB dib;
@ -207,7 +209,8 @@ ImagingNewDIB(const char *mode, int xsize, int ysize) {
} }
void void
ImagingPasteDIB(ImagingDIB dib, Imaging im, int xy[4]) { ImagingPasteDIB(ImagingDIB dib, Imaging im, int xy[4])
{
/* Paste image data into a bitmap */ /* Paste image data into a bitmap */
/* FIXME: check size! */ /* FIXME: check size! */
@ -223,7 +226,8 @@ ImagingPasteDIB(ImagingDIB dib, Imaging im, int xy[4]) {
} }
void void
ImagingExposeDIB(ImagingDIB dib, void *dc) { ImagingExposeDIB(ImagingDIB dib, void *dc)
{
/* Copy bitmap to display */ /* Copy bitmap to display */
if (dib->palette != 0) { if (dib->palette != 0) {
@ -233,7 +237,8 @@ ImagingExposeDIB(ImagingDIB dib, void *dc) {
} }
void void
ImagingDrawDIB(ImagingDIB dib, void *dc, int dst[4], int src[4]) { ImagingDrawDIB(ImagingDIB dib, void *dc, int dst[4], int src[4])
{
/* Copy bitmap to printer/display */ /* Copy bitmap to printer/display */
if (GetDeviceCaps((HDC)dc, RASTERCAPS) & RC_STRETCHDIB) { if (GetDeviceCaps((HDC)dc, RASTERCAPS) & RC_STRETCHDIB) {
@ -273,7 +278,8 @@ ImagingDrawDIB(ImagingDIB dib, void *dc, int dst[4], int src[4]) {
} }
int int
ImagingQueryPaletteDIB(ImagingDIB dib, void *dc) { ImagingQueryPaletteDIB(ImagingDIB dib, void *dc)
{
/* Install bitmap palette */ /* Install bitmap palette */
int n; int n;
@ -294,7 +300,8 @@ ImagingQueryPaletteDIB(ImagingDIB dib, void *dc) {
} }
void void
ImagingDeleteDIB(ImagingDIB dib) { ImagingDeleteDIB(ImagingDIB dib)
{
/* Clean up */ /* Clean up */
if (dib->palette) { if (dib->palette) {

View File

@ -66,7 +66,8 @@ typedef struct {
typedef void (*hline_handler)(Imaging, int, int, int, int); typedef void (*hline_handler)(Imaging, int, int, int, int);
static inline void static inline void
point8(Imaging im, int x, int y, int ink) { point8(Imaging im, int x, int y, int ink)
{
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) { if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
if (strncmp(im->mode, "I;16", 4) == 0) { if (strncmp(im->mode, "I;16", 4) == 0) {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
@ -83,14 +84,16 @@ point8(Imaging im, int x, int y, int ink) {
} }
static inline void static inline void
point32(Imaging im, int x, int y, int ink) { point32(Imaging im, int x, int y, int ink)
{
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) { if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
im->image32[y][x] = ink; im->image32[y][x] = ink;
} }
} }
static inline void static inline void
point32rgba(Imaging im, int x, int y, int ink) { point32rgba(Imaging im, int x, int y, int ink)
{
unsigned int tmp; unsigned int tmp;
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) { if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
@ -103,7 +106,8 @@ point32rgba(Imaging im, int x, int y, int ink) {
} }
static inline void static inline void
hline8(Imaging im, int x0, int y0, int x1, int ink) { hline8(Imaging im, int x0, int y0, int x1, int ink)
{
int pixelwidth; int pixelwidth;
if (y0 >= 0 && y0 < im->ysize) { if (y0 >= 0 && y0 < im->ysize) {
@ -128,7 +132,8 @@ hline8(Imaging im, int x0, int y0, int x1, int ink) {
} }
static inline void static inline void
hline32(Imaging im, int x0, int y0, int x1, int ink) { hline32(Imaging im, int x0, int y0, int x1, int ink)
{
INT32 *p; INT32 *p;
if (y0 >= 0 && y0 < im->ysize) { if (y0 >= 0 && y0 < im->ysize) {
@ -150,7 +155,8 @@ hline32(Imaging im, int x0, int y0, int x1, int ink) {
} }
static inline void static inline void
hline32rgba(Imaging im, int x0, int y0, int x1, int ink) { hline32rgba(Imaging im, int x0, int y0, int x1, int ink)
{
unsigned int tmp; unsigned int tmp;
if (y0 >= 0 && y0 < im->ysize) { if (y0 >= 0 && y0 < im->ysize) {
@ -179,7 +185,8 @@ hline32rgba(Imaging im, int x0, int y0, int x1, int ink) {
} }
static inline void static inline void
line8(Imaging im, int x0, int y0, int x1, int y1, int ink) { line8(Imaging im, int x0, int y0, int x1, int y1, int ink)
{
int i, n, e; int i, n, e;
int dx, dy; int dx, dy;
int xs, ys; int xs, ys;
@ -251,7 +258,8 @@ line8(Imaging im, int x0, int y0, int x1, int y1, int ink) {
} }
static inline void static inline void
line32(Imaging im, int x0, int y0, int x1, int y1, int ink) { line32(Imaging im, int x0, int y0, int x1, int y1, int ink)
{
int i, n, e; int i, n, e;
int dx, dy; int dx, dy;
int xs, ys; int xs, ys;
@ -323,7 +331,8 @@ line32(Imaging im, int x0, int y0, int x1, int y1, int ink) {
} }
static inline void static inline void
line32rgba(Imaging im, int x0, int y0, int x1, int y1, int ink) { line32rgba(Imaging im, int x0, int y0, int x1, int y1, int ink)
{
int i, n, e; int i, n, e;
int dx, dy; int dx, dy;
int xs, ys; int xs, ys;
@ -395,7 +404,8 @@ line32rgba(Imaging im, int x0, int y0, int x1, int y1, int ink) {
} }
static int static int
x_cmp(const void *x0, const void *x1) { x_cmp(const void *x0, const void *x1)
{
float diff = *((float *)x0) - *((float *)x1); float diff = *((float *)x0) - *((float *)x1);
if (diff < 0) { if (diff < 0) {
return -1; return -1;
@ -408,7 +418,8 @@ x_cmp(const void *x0, const void *x1) {
static void static void
draw_horizontal_lines( draw_horizontal_lines(
Imaging im, int n, Edge *e, int ink, int *x_pos, int y, hline_handler hline) { Imaging im, int n, Edge *e, int ink, int *x_pos, int y, hline_handler hline)
{
int i; int i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (e[i].ymin == y && e[i].ymin == e[i].ymax) { if (e[i].ymin == y && e[i].ymin == e[i].ymax) {
@ -440,13 +451,8 @@ draw_horizontal_lines(
*/ */
static inline int static inline int
polygon_generic( polygon_generic(
Imaging im, Imaging im, int n, Edge *e, int ink, int eofill, hline_handler hline, int hasAlpha)
int n, {
Edge *e,
int ink,
int eofill,
hline_handler hline,
int hasAlpha) {
Edge **edge_table; Edge **edge_table;
float *xx; float *xx;
int edge_count = 0; int edge_count = 0;
@ -599,22 +605,26 @@ polygon_generic(
} }
static inline int static inline int
polygon8(Imaging im, int n, Edge *e, int ink, int eofill) { polygon8(Imaging im, int n, Edge *e, int ink, int eofill)
{
return polygon_generic(im, n, e, ink, eofill, hline8, 0); return polygon_generic(im, n, e, ink, eofill, hline8, 0);
} }
static inline int static inline int
polygon32(Imaging im, int n, Edge *e, int ink, int eofill) { polygon32(Imaging im, int n, Edge *e, int ink, int eofill)
{
return polygon_generic(im, n, e, ink, eofill, hline32, 0); return polygon_generic(im, n, e, ink, eofill, hline32, 0);
} }
static inline int static inline int
polygon32rgba(Imaging im, int n, Edge *e, int ink, int eofill) { polygon32rgba(Imaging im, int n, Edge *e, int ink, int eofill)
{
return polygon_generic(im, n, e, ink, eofill, hline32rgba, 1); return polygon_generic(im, n, e, ink, eofill, hline32rgba, 1);
} }
static inline void static inline void
add_edge(Edge *e, int x0, int y0, int x1, int y1) { add_edge(Edge *e, int x0, int y0, int x1, int y1)
{
/* printf("edge %d %d %d %d\n", x0, y0, x1, y1); */ /* printf("edge %d %d %d %d\n", x0, y0, x1, y1); */
if (x0 <= x1) { if (x0 <= x1) {
@ -674,7 +684,8 @@ DRAW draw32rgba = {point32rgba, hline32rgba, line32rgba, polygon32rgba};
} }
int int
ImagingDrawPoint(Imaging im, int x0, int y0, const void *ink_, int op) { ImagingDrawPoint(Imaging im, int x0, int y0, const void *ink_, int op)
{
DRAW *draw; DRAW *draw;
INT32 ink; INT32 ink;
@ -686,7 +697,8 @@ ImagingDrawPoint(Imaging im, int x0, int y0, const void *ink_, int op) {
} }
int int
ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void *ink_, int op) { ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void *ink_, int op)
{
DRAW *draw; DRAW *draw;
INT32 ink; INT32 ink;
@ -699,7 +711,8 @@ ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void *ink_, in
int int
ImagingDrawWideLine( ImagingDrawWideLine(
Imaging im, int x0, int y0, int x1, int y1, const void *ink_, int width, int op) { Imaging im, int x0, int y0, int x1, int y1, const void *ink_, int width, int op)
{
DRAW *draw; DRAW *draw;
INT32 ink; INT32 ink;
int dx, dy; int dx, dy;
@ -752,7 +765,8 @@ ImagingDrawRectangle(
const void *ink_, const void *ink_,
int fill, int fill,
int width, int width,
int op) { int op)
{
int i; int i;
int y; int y;
int tmp; int tmp;
@ -800,7 +814,8 @@ ImagingDrawRectangle(
int int
ImagingDrawPolygon( ImagingDrawPolygon(
Imaging im, int count, int *xy, const void *ink_, int fill, int width, int op) { Imaging im, int count, int *xy, const void *ink_, int fill, int width, int op)
{
int i, n, x0, y0, x1, y1; int i, n, x0, y0, x1, y1;
DRAW *draw; DRAW *draw;
INT32 ink; INT32 ink;
@ -875,7 +890,8 @@ ImagingDrawPolygon(
} }
int int
ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap, const void *ink, int op) { ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap, const void *ink, int op)
{
return ImagingFill2( return ImagingFill2(
im, ink, bitmap, x0, y0, x0 + bitmap->xsize, y0 + bitmap->ysize); im, ink, bitmap, x0, y0, x0 + bitmap->xsize, y0 + bitmap->ysize);
} }
@ -895,7 +911,8 @@ typedef struct {
} quarter_state; } quarter_state;
void void
quarter_init(quarter_state *s, int32_t a, int32_t b) { quarter_init(quarter_state *s, int32_t a, int32_t b)
{
if (a < 0 || b < 0) { if (a < 0 || b < 0) {
s->finished = 1; s->finished = 1;
} else { } else {
@ -915,12 +932,14 @@ quarter_init(quarter_state *s, int32_t a, int32_t b) {
// deviation of the point from ellipse curve, basically a substitution // deviation of the point from ellipse curve, basically a substitution
// of the point into the ellipse equation // of the point into the ellipse equation
int64_t int64_t
quarter_delta(quarter_state *s, int64_t x, int64_t y) { quarter_delta(quarter_state *s, int64_t x, int64_t y)
{
return llabs(s->a2 * y * y + s->b2 * x * x - s->a2b2); return llabs(s->a2 * y * y + s->b2 * x * x - s->a2b2);
} }
int8_t int8_t
quarter_next(quarter_state *s, int32_t *ret_x, int32_t *ret_y) { quarter_next(quarter_state *s, int32_t *ret_x, int32_t *ret_y)
{
if (s->finished) { if (s->finished) {
return -1; return -1;
} }
@ -971,7 +990,8 @@ typedef struct {
} ellipse_state; } ellipse_state;
void void
ellipse_init(ellipse_state *s, int32_t a, int32_t b, int32_t w) { ellipse_init(ellipse_state *s, int32_t a, int32_t b, int32_t w)
{
s->bufcnt = 0; s->bufcnt = 0;
s->leftmost = a % 2; s->leftmost = a % 2;
quarter_init(&s->st_o, a, b); quarter_init(&s->st_o, a, b);
@ -985,7 +1005,8 @@ ellipse_init(ellipse_state *s, int32_t a, int32_t b, int32_t w) {
} }
int8_t int8_t
ellipse_next(ellipse_state *s, int32_t *ret_x0, int32_t *ret_y, int32_t *ret_x1) { ellipse_next(ellipse_state *s, int32_t *ret_x0, int32_t *ret_y, int32_t *ret_x1)
{
if (s->bufcnt == 0) { if (s->bufcnt == 0) {
if (s->finished) { if (s->finished) {
return -1; return -1;
@ -1068,7 +1089,8 @@ typedef struct event_list {
// Mirrors all the clipping nodes of the tree relative to the y = x line. // Mirrors all the clipping nodes of the tree relative to the y = x line.
void void
clip_tree_transpose(clip_node *root) { clip_tree_transpose(clip_node *root)
{
if (root != NULL) { if (root != NULL) {
if (root->type == CT_CLIP) { if (root->type == CT_CLIP) {
double t = root->a; double t = root->a;
@ -1085,8 +1107,8 @@ clip_tree_transpose(clip_node *root) {
// Combining nodes (AND, OR) may also accept sequences for intersecting // Combining nodes (AND, OR) may also accept sequences for intersecting
// segments, i.e. something like correct bracket sequences. // segments, i.e. something like correct bracket sequences.
int int
clip_tree_do_clip( clip_tree_do_clip(clip_node *root, int32_t x0, int32_t y, int32_t x1, event_list **ret)
clip_node *root, int32_t x0, int32_t y, int32_t x1, event_list **ret) { {
if (root == NULL) { if (root == NULL) {
event_list *start = malloc(sizeof(event_list)); event_list *start = malloc(sizeof(event_list));
if (!start) { if (!start) {
@ -1226,7 +1248,8 @@ typedef void (*clip_ellipse_init)(
clip_ellipse_state *, int32_t, int32_t, int32_t, float, float); clip_ellipse_state *, int32_t, int32_t, int32_t, float, float);
void void
debug_clip_tree(clip_node *root, int space) { debug_clip_tree(clip_node *root, int space)
{
if (root == NULL) { if (root == NULL) {
return; return;
} }
@ -1252,7 +1275,8 @@ debug_clip_tree(clip_node *root, int space) {
// Resulting angles will satisfy 0 <= al < 360, al <= ar <= al + 360 // Resulting angles will satisfy 0 <= al < 360, al <= ar <= al + 360
void void
normalize_angles(float *al, float *ar) { normalize_angles(float *al, float *ar)
{
if (*ar - *al >= 360) { if (*ar - *al >= 360) {
*al = 0; *al = 0;
*ar = 360; *ar = 360;
@ -1264,7 +1288,8 @@ normalize_angles(float *al, float *ar) {
// An arc with caps orthogonal to the ellipse curve. // An arc with caps orthogonal to the ellipse curve.
void void
arc_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar) { arc_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar)
{
if (a < b) { if (a < b) {
// transpose the coordinate system // transpose the coordinate system
arc_init(s, b, a, w, 90 - ar, 90 - al); arc_init(s, b, a, w, 90 - ar, 90 - al);
@ -1335,7 +1360,8 @@ arc_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float
// A chord line. // A chord line.
void void
chord_line_init( chord_line_init(
clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar) { clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar)
{
ellipse_init(&s->st, a, b, a + b + 1); ellipse_init(&s->st, a, b, a + b + 1);
s->head = NULL; s->head = NULL;
@ -1361,8 +1387,8 @@ chord_line_init(
// Pie side. // Pie side.
void void
pie_side_init( pie_side_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float _)
clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float _) { {
ellipse_init(&s->st, a, b, a + b + 1); ellipse_init(&s->st, a, b, a + b + 1);
s->head = NULL; s->head = NULL;
@ -1405,7 +1431,8 @@ pie_side_init(
// A chord. // A chord.
void void
chord_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar) { chord_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar)
{
ellipse_init(&s->st, a, b, w); ellipse_init(&s->st, a, b, w);
s->head = NULL; s->head = NULL;
@ -1424,7 +1451,8 @@ chord_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, flo
// A pie. Can also be used to draw an arc with ugly sharp caps. // A pie. Can also be used to draw an arc with ugly sharp caps.
void void
pie_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar) { pie_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar)
{
ellipse_init(&s->st, a, b, w); ellipse_init(&s->st, a, b, w);
s->head = NULL; s->head = NULL;
@ -1468,7 +1496,8 @@ pie_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float
} }
void void
clip_ellipse_free(clip_ellipse_state *s) { clip_ellipse_free(clip_ellipse_state *s)
{
while (s->head != NULL) { while (s->head != NULL) {
event_list *t = s->head; event_list *t = s->head;
s->head = s->head->next; s->head = s->head->next;
@ -1478,7 +1507,8 @@ clip_ellipse_free(clip_ellipse_state *s) {
int8_t int8_t
clip_ellipse_next( clip_ellipse_next(
clip_ellipse_state *s, int32_t *ret_x0, int32_t *ret_y, int32_t *ret_x1) { clip_ellipse_state *s, int32_t *ret_x0, int32_t *ret_y, int32_t *ret_x1)
{
int32_t x0, y, x1; int32_t x0, y, x1;
while (s->head == NULL && ellipse_next(&s->st, &x0, &y, &x1) >= 0) { while (s->head == NULL && ellipse_next(&s->st, &x0, &y, &x1) >= 0) {
if (clip_tree_do_clip(s->root, x0, y, x1, &s->head) < 0) { if (clip_tree_do_clip(s->root, x0, y, x1, &s->head) < 0) {
@ -1512,7 +1542,8 @@ ellipseNew(
const void *ink_, const void *ink_,
int fill, int fill,
int width, int width,
int op) { int op)
{
DRAW *draw; DRAW *draw;
INT32 ink; INT32 ink;
DRAWINIT(); DRAWINIT();
@ -1547,7 +1578,8 @@ clipEllipseNew(
const void *ink_, const void *ink_,
int width, int width,
int op, int op,
clip_ellipse_init init) { clip_ellipse_init init)
{
DRAW *draw; DRAW *draw;
INT32 ink; INT32 ink;
DRAWINIT(); DRAWINIT();
@ -1580,7 +1612,8 @@ arcNew(
float end, float end,
const void *ink_, const void *ink_,
int width, int width,
int op) { int op)
{
return clipEllipseNew(im, x0, y0, x1, y1, start, end, ink_, width, op, arc_init); return clipEllipseNew(im, x0, y0, x1, y1, start, end, ink_, width, op, arc_init);
} }
@ -1595,7 +1628,8 @@ chordNew(
float end, float end,
const void *ink_, const void *ink_,
int width, int width,
int op) { int op)
{
return clipEllipseNew(im, x0, y0, x1, y1, start, end, ink_, width, op, chord_init); return clipEllipseNew(im, x0, y0, x1, y1, start, end, ink_, width, op, chord_init);
} }
@ -1610,7 +1644,8 @@ chordLineNew(
float end, float end,
const void *ink_, const void *ink_,
int width, int width,
int op) { int op)
{
return clipEllipseNew( return clipEllipseNew(
im, x0, y0, x1, y1, start, end, ink_, width, op, chord_line_init); im, x0, y0, x1, y1, start, end, ink_, width, op, chord_line_init);
} }
@ -1626,7 +1661,8 @@ pieNew(
float end, float end,
const void *ink_, const void *ink_,
int width, int width,
int op) { int op)
{
return clipEllipseNew(im, x0, y0, x1, y1, start, end, ink_, width, op, pie_init); return clipEllipseNew(im, x0, y0, x1, y1, start, end, ink_, width, op, pie_init);
} }
@ -1640,7 +1676,8 @@ pieSideNew(
float start, float start,
const void *ink_, const void *ink_,
int width, int width,
int op) { int op)
{
return clipEllipseNew(im, x0, y0, x1, y1, start, 0, ink_, width, op, pie_side_init); return clipEllipseNew(im, x0, y0, x1, y1, start, 0, ink_, width, op, pie_side_init);
} }
@ -1654,7 +1691,8 @@ ImagingDrawEllipse(
const void *ink, const void *ink,
int fill, int fill,
int width, int width,
int op) { int op)
{
return ellipseNew(im, x0, y0, x1, y1, ink, fill, width, op); return ellipseNew(im, x0, y0, x1, y1, ink, fill, width, op);
} }
@ -1669,7 +1707,8 @@ ImagingDrawArc(
float end, float end,
const void *ink, const void *ink,
int width, int width,
int op) { int op)
{
normalize_angles(&start, &end); normalize_angles(&start, &end);
if (start + 360 == end) { if (start + 360 == end) {
return ImagingDrawEllipse(im, x0, y0, x1, y1, ink, 0, width, op); return ImagingDrawEllipse(im, x0, y0, x1, y1, ink, 0, width, op);
@ -1692,7 +1731,8 @@ ImagingDrawChord(
const void *ink, const void *ink,
int fill, int fill,
int width, int width,
int op) { int op)
{
normalize_angles(&start, &end); normalize_angles(&start, &end);
if (start + 360 == end) { if (start + 360 == end) {
return ImagingDrawEllipse(im, x0, y0, x1, y1, ink, fill, width, op); return ImagingDrawEllipse(im, x0, y0, x1, y1, ink, fill, width, op);
@ -1722,7 +1762,8 @@ ImagingDrawPieslice(
const void *ink, const void *ink,
int fill, int fill,
int width, int width,
int op) { int op)
{
normalize_angles(&start, &end); normalize_angles(&start, &end);
if (start + 360 == end) { if (start + 360 == end) {
return ellipseNew(im, x0, y0, x1, y1, ink, fill, width, op); return ellipseNew(im, x0, y0, x1, y1, ink, fill, width, op);
@ -1764,7 +1805,8 @@ struct ImagingOutlineInstance {
}; };
ImagingOutline ImagingOutline
ImagingOutlineNew(void) { ImagingOutlineNew(void)
{
ImagingOutline outline; ImagingOutline outline;
outline = calloc(1, sizeof(struct ImagingOutlineInstance)); outline = calloc(1, sizeof(struct ImagingOutlineInstance));
@ -1781,7 +1823,8 @@ ImagingOutlineNew(void) {
} }
void void
ImagingOutlineDelete(ImagingOutline outline) { ImagingOutlineDelete(ImagingOutline outline)
{
if (!outline) { if (!outline) {
return; return;
} }
@ -1794,7 +1837,8 @@ ImagingOutlineDelete(ImagingOutline outline) {
} }
static Edge * static Edge *
allocate(ImagingOutline outline, int extra) { allocate(ImagingOutline outline, int extra)
{
Edge *e; Edge *e;
if (outline->count + extra > outline->size) { if (outline->count + extra > outline->size) {
@ -1824,7 +1868,8 @@ allocate(ImagingOutline outline, int extra) {
} }
int int
ImagingOutlineMove(ImagingOutline outline, float x0, float y0) { ImagingOutlineMove(ImagingOutline outline, float x0, float y0)
{
outline->x = outline->x0 = x0; outline->x = outline->x0 = x0;
outline->y = outline->y0 = y0; outline->y = outline->y0 = y0;
@ -1832,7 +1877,8 @@ ImagingOutlineMove(ImagingOutline outline, float x0, float y0) {
} }
int int
ImagingOutlineLine(ImagingOutline outline, float x1, float y1) { ImagingOutlineLine(ImagingOutline outline, float x1, float y1)
{
Edge *e; Edge *e;
e = allocate(outline, 1); e = allocate(outline, 1);
@ -1850,13 +1896,8 @@ ImagingOutlineLine(ImagingOutline outline, float x1, float y1) {
int int
ImagingOutlineCurve( ImagingOutlineCurve(
ImagingOutline outline, ImagingOutline outline, float x1, float y1, float x2, float y2, float x3, float y3)
float x1, {
float y1,
float x2,
float y2,
float x3,
float y3) {
Edge *e; Edge *e;
int i; int i;
float xo, yo; float xo, yo;
@ -1897,7 +1938,8 @@ ImagingOutlineCurve(
} }
int int
ImagingOutlineClose(ImagingOutline outline) { ImagingOutlineClose(ImagingOutline outline)
{
if (outline->x == outline->x0 && outline->y == outline->y0) { if (outline->x == outline->x0 && outline->y == outline->y0) {
return 0; return 0;
} }
@ -1905,7 +1947,8 @@ ImagingOutlineClose(ImagingOutline outline) {
} }
int int
ImagingOutlineTransform(ImagingOutline outline, double a[6]) { ImagingOutlineTransform(ImagingOutline outline, double a[6])
{
Edge *eIn; Edge *eIn;
Edge *eOut; Edge *eOut;
int i, n; int i, n;
@ -1970,7 +2013,8 @@ ImagingOutlineTransform(ImagingOutline outline, double a[6]) {
int int
ImagingDrawOutline( ImagingDrawOutline(
Imaging im, ImagingOutline outline, const void *ink_, int fill, int op) { Imaging im, ImagingOutline outline, const void *ink_, int fill, int op)
{
DRAW *draw; DRAW *draw;
INT32 ink; INT32 ink;

View File

@ -20,7 +20,8 @@
#include <math.h> #include <math.h>
Imaging Imaging
ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality) { ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality)
{
/* Generate a Mandelbrot set covering the given extent */ /* Generate a Mandelbrot set covering the given extent */
Imaging im; Imaging im;
@ -72,7 +73,8 @@ ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality) {
} }
Imaging Imaging
ImagingEffectNoise(int xsize, int ysize, float sigma) { ImagingEffectNoise(int xsize, int ysize, float sigma)
{
/* Generate Gaussian noise centered around 128 */ /* Generate Gaussian noise centered around 128 */
Imaging imOut; Imaging imOut;
@ -114,7 +116,8 @@ ImagingEffectNoise(int xsize, int ysize, float sigma) {
} }
Imaging Imaging
ImagingEffectSpread(Imaging imIn, int distance) { ImagingEffectSpread(Imaging imIn, int distance)
{
/* Randomly spread pixels in an image */ /* Randomly spread pixels in an image */
Imaging imOut; Imaging imOut;

View File

@ -20,7 +20,8 @@
#include "Imaging.h" #include "Imaging.h"
int int
ImagingEpsEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) { ImagingEpsEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
{
enum { HEXBYTE = 1, NEWLINE }; enum { HEXBYTE = 1, NEWLINE };
const char *hex = "0123456789abcdef"; const char *hex = "0123456789abcdef";

View File

@ -24,29 +24,34 @@
/* exception state */ /* exception state */
void * void *
ImagingError_OSError(void) { ImagingError_OSError(void)
{
fprintf(stderr, "*** exception: file access error\n"); fprintf(stderr, "*** exception: file access error\n");
return NULL; return NULL;
} }
void * void *
ImagingError_MemoryError(void) { ImagingError_MemoryError(void)
{
fprintf(stderr, "*** exception: out of memory\n"); fprintf(stderr, "*** exception: out of memory\n");
return NULL; return NULL;
} }
void * void *
ImagingError_ModeError(void) { ImagingError_ModeError(void)
{
return ImagingError_ValueError("bad image mode"); return ImagingError_ValueError("bad image mode");
} }
void * void *
ImagingError_Mismatch(void) { ImagingError_Mismatch(void)
{
return ImagingError_ValueError("images don't match"); return ImagingError_ValueError("images don't match");
} }
void * void *
ImagingError_ValueError(const char *message) { ImagingError_ValueError(const char *message)
{
if (!message) { if (!message) {
message = "exception: bad argument to function"; message = "exception: bad argument to function";
} }
@ -55,18 +60,21 @@ ImagingError_ValueError(const char *message) {
} }
void void
ImagingError_Clear(void) { ImagingError_Clear(void)
{
/* nop */; /* nop */;
} }
/* thread state */ /* thread state */
void void
ImagingSectionEnter(ImagingSectionCookie *cookie) { ImagingSectionEnter(ImagingSectionCookie *cookie)
{
/* pass */ /* pass */
} }
void void
ImagingSectionLeave(ImagingSectionCookie *cookie) { ImagingSectionLeave(ImagingSectionCookie *cookie)
{
/* pass */ /* pass */
} }

View File

@ -20,7 +20,8 @@
#include <ctype.h> #include <ctype.h>
int int
ImagingSaveRaw(Imaging im, FILE *fp) { ImagingSaveRaw(Imaging im, FILE *fp)
{
int x, y, i; int x, y, i;
if (strcmp(im->mode, "1") == 0 || strcmp(im->mode, "L") == 0) { if (strcmp(im->mode, "1") == 0 || strcmp(im->mode, "L") == 0) {
@ -44,7 +45,8 @@ ImagingSaveRaw(Imaging im, FILE *fp) {
} }
int int
ImagingSavePPM(Imaging im, const char *outfile) { ImagingSavePPM(Imaging im, const char *outfile)
{
FILE *fp; FILE *fp;
if (!im) { if (!im) {

View File

@ -20,7 +20,8 @@
#include "math.h" #include "math.h"
Imaging Imaging
ImagingFill(Imaging im, const void *colour) { ImagingFill(Imaging im, const void *colour)
{
int x, y; int x, y;
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
@ -68,7 +69,8 @@ ImagingFill(Imaging im, const void *colour) {
} }
Imaging Imaging
ImagingFillLinearGradient(const char *mode) { ImagingFillLinearGradient(const char *mode)
{
Imaging im; Imaging im;
int y; int y;
@ -102,7 +104,8 @@ ImagingFillLinearGradient(const char *mode) {
} }
Imaging Imaging
ImagingFillRadialGradient(const char *mode) { ImagingFillRadialGradient(const char *mode)
{
Imaging im; Imaging im;
int x, y; int x, y;
int d; int d;

View File

@ -27,7 +27,8 @@
#include "Imaging.h" #include "Imaging.h"
static inline UINT8 static inline UINT8
clip8(float in) { clip8(float in)
{
if (in <= 0.0) { if (in <= 0.0) {
return 0; return 0;
} }
@ -38,7 +39,8 @@ clip8(float in) {
} }
static inline INT32 static inline INT32
clip32(float in) { clip32(float in)
{
if (in <= 0.0) { if (in <= 0.0) {
return 0; return 0;
} }
@ -49,7 +51,8 @@ clip32(float in) {
} }
Imaging Imaging
ImagingExpand(Imaging imIn, int xmargin, int ymargin) { ImagingExpand(Imaging imIn, int xmargin, int ymargin)
{
Imaging imOut; Imaging imOut;
int x, y; int x, y;
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
@ -105,7 +108,8 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin) {
} }
void void
ImagingFilter3x3(Imaging imOut, Imaging im, const float *kernel, float offset) { ImagingFilter3x3(Imaging imOut, Imaging im, const float *kernel, float offset)
{
#define KERNEL1x3(in0, x, kernel, d) \ #define KERNEL1x3(in0, x, kernel, d) \
(_i2f(in0[x - d]) * (kernel)[0] + _i2f(in0[x]) * (kernel)[1] + \ (_i2f(in0[x - d]) * (kernel)[0] + _i2f(in0[x]) * (kernel)[1] + \
_i2f(in0[x + d]) * (kernel)[2]) _i2f(in0[x + d]) * (kernel)[2])
@ -223,7 +227,8 @@ ImagingFilter3x3(Imaging imOut, Imaging im, const float *kernel, float offset) {
} }
void void
ImagingFilter5x5(Imaging imOut, Imaging im, const float *kernel, float offset) { ImagingFilter5x5(Imaging imOut, Imaging im, const float *kernel, float offset)
{
#define KERNEL1x5(in0, x, kernel, d) \ #define KERNEL1x5(in0, x, kernel, d) \
(_i2f(in0[x - d - d]) * (kernel)[0] + _i2f(in0[x - d]) * (kernel)[1] + \ (_i2f(in0[x - d - d]) * (kernel)[0] + _i2f(in0[x - d]) * (kernel)[1] + \
_i2f(in0[x]) * (kernel)[2] + _i2f(in0[x + d]) * (kernel)[3] + \ _i2f(in0[x]) * (kernel)[2] + _i2f(in0[x + d]) * (kernel)[3] + \
@ -377,7 +382,8 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float *kernel, float offset) {
} }
Imaging Imaging
ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32 *kernel, FLOAT32 offset) { ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32 *kernel, FLOAT32 offset)
{
Imaging imOut; Imaging imOut;
ImagingSectionCookie cookie; ImagingSectionCookie cookie;

View File

@ -27,7 +27,8 @@
} }
int int
ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingFliDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
UINT8 *ptr; UINT8 *ptr;
int framesize; int framesize;
int c, chunks, advance; int c, chunks, advance;

View File

@ -15,7 +15,8 @@
/* Transpose operations */ /* Transpose operations */
Imaging Imaging
ImagingFlipLeftRight(Imaging imOut, Imaging imIn) { ImagingFlipLeftRight(Imaging imOut, Imaging imIn)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int x, y, xr; int x, y, xr;
@ -58,7 +59,8 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn) {
} }
Imaging Imaging
ImagingFlipTopBottom(Imaging imOut, Imaging imIn) { ImagingFlipTopBottom(Imaging imOut, Imaging imIn)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int y, yr; int y, yr;
@ -84,7 +86,8 @@ ImagingFlipTopBottom(Imaging imOut, Imaging imIn) {
} }
Imaging Imaging
ImagingRotate90(Imaging imOut, Imaging imIn) { ImagingRotate90(Imaging imOut, Imaging imIn)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int x, y, xx, yy, xr, xxsize, yysize; int x, y, xx, yy, xr, xxsize, yysize;
int xxx, yyy, xxxsize, yyysize; int xxx, yyy, xxxsize, yyysize;
@ -144,7 +147,8 @@ ImagingRotate90(Imaging imOut, Imaging imIn) {
} }
Imaging Imaging
ImagingTranspose(Imaging imOut, Imaging imIn) { ImagingTranspose(Imaging imOut, Imaging imIn)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int x, y, xx, yy, xxsize, yysize; int x, y, xx, yy, xxsize, yysize;
int xxx, yyy, xxxsize, yyysize; int xxx, yyy, xxxsize, yyysize;
@ -203,7 +207,8 @@ ImagingTranspose(Imaging imOut, Imaging imIn) {
} }
Imaging Imaging
ImagingTransverse(Imaging imOut, Imaging imIn) { ImagingTransverse(Imaging imOut, Imaging imIn)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int x, y, xr, yr, xx, yy, xxsize, yysize; int x, y, xr, yr, xx, yy, xxsize, yysize;
int xxx, yyy, xxxsize, yyysize; int xxx, yyy, xxxsize, yyysize;
@ -264,7 +269,8 @@ ImagingTransverse(Imaging imOut, Imaging imIn) {
} }
Imaging Imaging
ImagingRotate180(Imaging imOut, Imaging imIn) { ImagingRotate180(Imaging imOut, Imaging imIn)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int x, y, xr, yr; int x, y, xr, yr;
@ -308,7 +314,8 @@ ImagingRotate180(Imaging imOut, Imaging imIn) {
} }
Imaging Imaging
ImagingRotate270(Imaging imOut, Imaging imIn) { ImagingRotate270(Imaging imOut, Imaging imIn)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int x, y, xx, yy, yr, xxsize, yysize; int x, y, xx, yy, yr, xxsize, yysize;
int xxx, yyy, xxxsize, yyysize; int xxx, yyy, xxxsize, yyysize;
@ -373,7 +380,8 @@ ImagingRotate270(Imaging imOut, Imaging imIn) {
/* transform primitives (ImagingTransformMap) */ /* transform primitives (ImagingTransformMap) */
static int static int
affine_transform(double *xout, double *yout, int x, int y, void *data) { affine_transform(double *xout, double *yout, int x, int y, void *data)
{
/* full moon tonight. your compiler will generate bogus code /* full moon tonight. your compiler will generate bogus code
for simple expressions, unless you reorganize the code, or for simple expressions, unless you reorganize the code, or
install Service Pack 3 */ install Service Pack 3 */
@ -396,7 +404,8 @@ affine_transform(double *xout, double *yout, int x, int y, void *data) {
} }
static int static int
perspective_transform(double *xout, double *yout, int x, int y, void *data) { perspective_transform(double *xout, double *yout, int x, int y, void *data)
{
double *a = (double *)data; double *a = (double *)data;
double a0 = a[0]; double a0 = a[0];
double a1 = a[1]; double a1 = a[1];
@ -417,7 +426,8 @@ perspective_transform(double *xout, double *yout, int x, int y, void *data) {
} }
static int static int
quad_transform(double *xout, double *yout, int x, int y, void *data) { quad_transform(double *xout, double *yout, int x, int y, void *data)
{
/* quad warp: map quadrilateral to rectangle */ /* quad warp: map quadrilateral to rectangle */
double *a = (double *)data; double *a = (double *)data;
@ -442,7 +452,8 @@ quad_transform(double *xout, double *yout, int x, int y, void *data) {
/* transform filters (ImagingTransformFilter) */ /* transform filters (ImagingTransformFilter) */
static int static int
nearest_filter8(void *out, Imaging im, double xin, double yin) { nearest_filter8(void *out, Imaging im, double xin, double yin)
{
int x = COORD(xin); int x = COORD(xin);
int y = COORD(yin); int y = COORD(yin);
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) { if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) {
@ -453,7 +464,8 @@ nearest_filter8(void *out, Imaging im, double xin, double yin) {
} }
static int static int
nearest_filter16(void *out, Imaging im, double xin, double yin) { nearest_filter16(void *out, Imaging im, double xin, double yin)
{
int x = COORD(xin); int x = COORD(xin);
int y = COORD(yin); int y = COORD(yin);
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) { if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) {
@ -464,7 +476,8 @@ nearest_filter16(void *out, Imaging im, double xin, double yin) {
} }
static int static int
nearest_filter32(void *out, Imaging im, double xin, double yin) { nearest_filter32(void *out, Imaging im, double xin, double yin)
{
int x = COORD(xin); int x = COORD(xin);
int y = COORD(yin); int y = COORD(yin);
if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) { if (x < 0 || x >= im->xsize || y < 0 || y >= im->ysize) {
@ -511,7 +524,8 @@ nearest_filter32(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bilinear_filter8(void *out, Imaging im, double xin, double yin) { bilinear_filter8(void *out, Imaging im, double xin, double yin)
{
BILINEAR_HEAD(UINT8); BILINEAR_HEAD(UINT8);
BILINEAR_BODY(UINT8, im->image8, 1, 0); BILINEAR_BODY(UINT8, im->image8, 1, 0);
((UINT8 *)out)[0] = (UINT8)v1; ((UINT8 *)out)[0] = (UINT8)v1;
@ -519,7 +533,8 @@ bilinear_filter8(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bilinear_filter32I(void *out, Imaging im, double xin, double yin) { bilinear_filter32I(void *out, Imaging im, double xin, double yin)
{
INT32 k; INT32 k;
BILINEAR_HEAD(INT32); BILINEAR_HEAD(INT32);
BILINEAR_BODY(INT32, im->image32, 1, 0); BILINEAR_BODY(INT32, im->image32, 1, 0);
@ -529,7 +544,8 @@ bilinear_filter32I(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bilinear_filter32F(void *out, Imaging im, double xin, double yin) { bilinear_filter32F(void *out, Imaging im, double xin, double yin)
{
FLOAT32 k; FLOAT32 k;
BILINEAR_HEAD(FLOAT32); BILINEAR_HEAD(FLOAT32);
BILINEAR_BODY(FLOAT32, im->image32, 1, 0); BILINEAR_BODY(FLOAT32, im->image32, 1, 0);
@ -539,7 +555,8 @@ bilinear_filter32F(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bilinear_filter32LA(void *out, Imaging im, double xin, double yin) { bilinear_filter32LA(void *out, Imaging im, double xin, double yin)
{
BILINEAR_HEAD(UINT8); BILINEAR_HEAD(UINT8);
BILINEAR_BODY(UINT8, im->image, 4, 0); BILINEAR_BODY(UINT8, im->image, 4, 0);
((UINT8 *)out)[0] = (UINT8)v1; ((UINT8 *)out)[0] = (UINT8)v1;
@ -551,7 +568,8 @@ bilinear_filter32LA(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bilinear_filter32RGB(void *out, Imaging im, double xin, double yin) { bilinear_filter32RGB(void *out, Imaging im, double xin, double yin)
{
int b; int b;
BILINEAR_HEAD(UINT8); BILINEAR_HEAD(UINT8);
for (b = 0; b < im->bands; b++) { for (b = 0; b < im->bands; b++) {
@ -623,7 +641,8 @@ bilinear_filter32RGB(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bicubic_filter8(void *out, Imaging im, double xin, double yin) { bicubic_filter8(void *out, Imaging im, double xin, double yin)
{
BICUBIC_HEAD(UINT8); BICUBIC_HEAD(UINT8);
BICUBIC_BODY(UINT8, im->image8, 1, 0); BICUBIC_BODY(UINT8, im->image8, 1, 0);
if (v1 <= 0.0) { if (v1 <= 0.0) {
@ -637,7 +656,8 @@ bicubic_filter8(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bicubic_filter32I(void *out, Imaging im, double xin, double yin) { bicubic_filter32I(void *out, Imaging im, double xin, double yin)
{
INT32 k; INT32 k;
BICUBIC_HEAD(INT32); BICUBIC_HEAD(INT32);
BICUBIC_BODY(INT32, im->image32, 1, 0); BICUBIC_BODY(INT32, im->image32, 1, 0);
@ -647,7 +667,8 @@ bicubic_filter32I(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bicubic_filter32F(void *out, Imaging im, double xin, double yin) { bicubic_filter32F(void *out, Imaging im, double xin, double yin)
{
FLOAT32 k; FLOAT32 k;
BICUBIC_HEAD(FLOAT32); BICUBIC_HEAD(FLOAT32);
BICUBIC_BODY(FLOAT32, im->image32, 1, 0); BICUBIC_BODY(FLOAT32, im->image32, 1, 0);
@ -657,7 +678,8 @@ bicubic_filter32F(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bicubic_filter32LA(void *out, Imaging im, double xin, double yin) { bicubic_filter32LA(void *out, Imaging im, double xin, double yin)
{
BICUBIC_HEAD(UINT8); BICUBIC_HEAD(UINT8);
BICUBIC_BODY(UINT8, im->image, 4, 0); BICUBIC_BODY(UINT8, im->image, 4, 0);
if (v1 <= 0.0) { if (v1 <= 0.0) {
@ -685,7 +707,8 @@ bicubic_filter32LA(void *out, Imaging im, double xin, double yin) {
} }
static int static int
bicubic_filter32RGB(void *out, Imaging im, double xin, double yin) { bicubic_filter32RGB(void *out, Imaging im, double xin, double yin)
{
int b; int b;
BICUBIC_HEAD(UINT8); BICUBIC_HEAD(UINT8);
for (b = 0; b < im->bands; b++) { for (b = 0; b < im->bands; b++) {
@ -706,7 +729,8 @@ bicubic_filter32RGB(void *out, Imaging im, double xin, double yin) {
#undef BICUBIC_BODY #undef BICUBIC_BODY
static ImagingTransformFilter static ImagingTransformFilter
getfilter(Imaging im, int filterid) { getfilter(Imaging im, int filterid)
{
switch (filterid) { switch (filterid) {
case IMAGING_TRANSFORM_NEAREST: case IMAGING_TRANSFORM_NEAREST:
if (im->image8) { if (im->image8) {
@ -781,7 +805,8 @@ ImagingGenericTransform(
ImagingTransformMap transform, ImagingTransformMap transform,
void *transform_data, void *transform_data,
int filterid, int filterid,
int fill) { int fill)
{
/* slow generic transformation. use ImagingTransformAffine or /* slow generic transformation. use ImagingTransformAffine or
ImagingScaleAffine where possible. */ ImagingScaleAffine where possible. */
@ -836,14 +861,8 @@ ImagingGenericTransform(
static Imaging static Imaging
ImagingScaleAffine( ImagingScaleAffine(
Imaging imOut, Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, double a[6], int fill)
Imaging imIn, {
int x0,
int y0,
int x1,
int y1,
double a[6],
int fill) {
/* scale, nearest neighbour resampling */ /* scale, nearest neighbour resampling */
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
@ -933,7 +952,8 @@ ImagingScaleAffine(
} }
static inline int static inline int
check_fixed(double a[6], int x, int y) { check_fixed(double a[6], int x, int y)
{
return ( return (
fabs(x * a[0] + y * a[1] + a[2]) < 32768.0 && fabs(x * a[0] + y * a[1] + a[2]) < 32768.0 &&
fabs(x * a[3] + y * a[4] + a[5]) < 32768.0); fabs(x * a[3] + y * a[4] + a[5]) < 32768.0);
@ -949,7 +969,8 @@ affine_fixed(
int y1, int y1,
double a[6], double a[6],
int filterid, int filterid,
int fill) { int fill)
{
/* affine transform, nearest neighbour resampling, fixed point /* affine transform, nearest neighbour resampling, fixed point
arithmetics */ arithmetics */
@ -1026,7 +1047,8 @@ ImagingTransformAffine(
int y1, int y1,
double a[6], double a[6],
int filterid, int filterid,
int fill) { int fill)
{
/* affine transform, nearest neighbour resampling, floating point /* affine transform, nearest neighbour resampling, floating point
arithmetics*/ arithmetics*/
@ -1134,7 +1156,8 @@ ImagingTransform(
int y1, int y1,
double a[8], double a[8],
int filterid, int filterid,
int fill) { int fill)
{
ImagingTransformMap transform; ImagingTransformMap transform;
switch (method) { switch (method) {

View File

@ -19,7 +19,8 @@
#include "Imaging.h" #include "Imaging.h"
int int
ImagingGetBBox(Imaging im, int bbox[4], int alpha_only) { ImagingGetBBox(Imaging im, int bbox[4], int alpha_only)
{
/* Get the bounding box for any non-zero data in the image.*/ /* Get the bounding box for any non-zero data in the image.*/
int x, y; int x, y;
@ -81,7 +82,8 @@ ImagingGetBBox(Imaging im, int bbox[4], int alpha_only) {
} }
int int
ImagingGetProjection(Imaging im, UINT8 *xproj, UINT8 *yproj) { ImagingGetProjection(Imaging im, UINT8 *xproj, UINT8 *yproj)
{
/* Get projection arrays for non-zero data in the image.*/ /* Get projection arrays for non-zero data in the image.*/
int x, y; int x, y;
@ -119,7 +121,8 @@ ImagingGetProjection(Imaging im, UINT8 *xproj, UINT8 *yproj) {
} }
int int
ImagingGetExtrema(Imaging im, void *extrema) { ImagingGetExtrema(Imaging im, void *extrema)
{
int x, y; int x, y;
INT32 imin, imax; INT32 imin, imax;
FLOAT32 fmin, fmax; FLOAT32 fmin, fmax;
@ -223,13 +226,15 @@ static ImagingColorItem *
getcolors32(Imaging im, int maxcolors, int *size); getcolors32(Imaging im, int maxcolors, int *size);
ImagingColorItem * ImagingColorItem *
ImagingGetColors(Imaging im, int maxcolors, int *size) { ImagingGetColors(Imaging im, int maxcolors, int *size)
{
/* FIXME: add support for 8-bit images */ /* FIXME: add support for 8-bit images */
return getcolors32(im, maxcolors, size); return getcolors32(im, maxcolors, size);
} }
static ImagingColorItem * static ImagingColorItem *
getcolors32(Imaging im, int maxcolors, int *size) { getcolors32(Imaging im, int maxcolors, int *size)
{
unsigned int h; unsigned int h;
unsigned int i, incr; unsigned int i, incr;
int colors; int colors;

View File

@ -56,7 +56,8 @@
} }
int int
ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes) { ImagingGifDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes)
{
UINT8 *p; UINT8 *p;
UINT8 *out; UINT8 *out;
int c, i; int c, i;

View File

@ -55,7 +55,8 @@ enum {
enum { PUT_HEAD, PUT_INIT_CLEAR, PUT_CLEAR, PUT_LAST_HEAD, PUT_END }; enum { PUT_HEAD, PUT_INIT_CLEAR, PUT_CLEAR, PUT_LAST_HEAD, PUT_END };
static void static void
glzwe_reset(GIFENCODERSTATE *st) { glzwe_reset(GIFENCODERSTATE *st)
{
st->next_code = st->end_code + 1; st->next_code = st->end_code + 1;
st->max_code = 2 * st->clear_code - 1; st->max_code = 2 * st->clear_code - 1;
st->code_width = st->bits + 1; st->code_width = st->bits + 1;
@ -63,7 +64,8 @@ glzwe_reset(GIFENCODERSTATE *st) {
} }
static void static void
glzwe_init(GIFENCODERSTATE *st) { glzwe_init(GIFENCODERSTATE *st)
{
st->clear_code = 1 << st->bits; st->clear_code = 1 << st->bits;
st->end_code = st->clear_code + 1; st->end_code = st->clear_code + 1;
glzwe_reset(st); glzwe_reset(st);
@ -79,7 +81,8 @@ glzwe(
UINT8 *out_ptr, UINT8 *out_ptr,
UINT32 *in_avail, UINT32 *in_avail,
UINT32 *out_avail, UINT32 *out_avail,
UINT32 end_of_data) { UINT32 end_of_data)
{
switch (st->entry_state) { switch (st->entry_state) {
case LZW_TRY_IN1: case LZW_TRY_IN1:
get_first_byte: get_first_byte:
@ -217,7 +220,8 @@ flush_code_buffer: /* jump here after put_code */
/* -END- GIF LZW encoder. */ /* -END- GIF LZW encoder. */
int int
ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) { ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
{
UINT8 *ptr; UINT8 *ptr;
UINT8 *sub_block_ptr; UINT8 *sub_block_ptr;
UINT8 *sub_block_limit; UINT8 *sub_block_limit;

View File

@ -22,7 +22,8 @@
: -1) : -1)
int int
ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
UINT8 *ptr; UINT8 *ptr;
int a, b; int a, b;

View File

@ -25,7 +25,8 @@
*/ */
void void
ImagingHistogramDelete(ImagingHistogram h) { ImagingHistogramDelete(ImagingHistogram h)
{
if (h) { if (h) {
if (h->histogram) { if (h->histogram) {
free(h->histogram); free(h->histogram);
@ -35,7 +36,8 @@ ImagingHistogramDelete(ImagingHistogram h) {
} }
ImagingHistogram ImagingHistogram
ImagingHistogramNew(Imaging im) { ImagingHistogramNew(Imaging im)
{
ImagingHistogram h; ImagingHistogram h;
/* Create histogram descriptor */ /* Create histogram descriptor */
@ -57,7 +59,8 @@ ImagingHistogramNew(Imaging im) {
} }
ImagingHistogram ImagingHistogram
ImagingGetHistogram(Imaging im, Imaging imMask, void *minmax) { ImagingGetHistogram(Imaging im, Imaging imMask, void *minmax)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int x, y, i; int x, y, i;
ImagingHistogram h; ImagingHistogram h;

View File

@ -32,7 +32,8 @@
See: https://stackoverflow.com/a/26588074/253146 */ See: https://stackoverflow.com/a/26588074/253146 */
#if defined(__x86_64__) && defined(__SSE__) && !defined(__NO_INLINE__) && \ #if defined(__x86_64__) && defined(__SSE__) && !defined(__NO_INLINE__) && \
!defined(__clang__) && defined(GCC_VERSION) && (GCC_VERSION < 40900) !defined(__clang__) && defined(GCC_VERSION) && (GCC_VERSION < 40900)
static float __attribute__((always_inline)) inline _i2f(int v) { static float __attribute__((always_inline)) inline _i2f(int v)
{
float x; float x;
__asm__("xorps %0, %0; cvtsi2ss %1, %0" : "=x"(x) : "r"(v)); __asm__("xorps %0, %0; cvtsi2ss %1, %0" : "=x"(x) : "r"(v));
return x; return x;

View File

@ -32,7 +32,8 @@ typedef struct {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
static void static void
j2k_error(const char *msg, void *client_data) { j2k_error(const char *msg, void *client_data)
{
JPEG2KDECODESTATE *state = (JPEG2KDECODESTATE *)client_data; JPEG2KDECODESTATE *state = (JPEG2KDECODESTATE *)client_data;
free((void *)state->error_msg); free((void *)state->error_msg);
state->error_msg = strdup(msg); state->error_msg = strdup(msg);
@ -43,7 +44,8 @@ j2k_error(const char *msg, void *client_data) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
static OPJ_SIZE_T static OPJ_SIZE_T
j2k_read(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data) { j2k_read(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
{
ImagingCodecState state = (ImagingCodecState)p_user_data; ImagingCodecState state = (ImagingCodecState)p_user_data;
size_t len = _imaging_read_pyFd(state->fd, p_buffer, p_nb_bytes); size_t len = _imaging_read_pyFd(state->fd, p_buffer, p_nb_bytes);
@ -52,7 +54,8 @@ j2k_read(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data) {
} }
static OPJ_OFF_T static OPJ_OFF_T
j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data) { j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data)
{
off_t pos; off_t pos;
ImagingCodecState state = (ImagingCodecState)p_user_data; ImagingCodecState state = (ImagingCodecState)p_user_data;
@ -79,7 +82,8 @@ struct j2k_decode_unpacker {
}; };
static inline unsigned static inline unsigned
j2ku_shift(unsigned x, int n) { j2ku_shift(unsigned x, int n)
{
if (n < 0) { if (n < 0) {
return x >> -n; return x >> -n;
} else { } else {
@ -89,10 +93,8 @@ j2ku_shift(unsigned x, int n) {
static void static void
j2ku_gray_l( j2ku_gray_l(
opj_image_t *in, opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im)
const JPEG2KTILEINFO *tileinfo, {
const UINT8 *tiledata,
Imaging im) {
unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
unsigned w = tileinfo->x1 - tileinfo->x0; unsigned w = tileinfo->x1 - tileinfo->x0;
unsigned h = tileinfo->y1 - tileinfo->y0; unsigned h = tileinfo->y1 - tileinfo->y0;
@ -145,10 +147,8 @@ j2ku_gray_l(
static void static void
j2ku_gray_i( j2ku_gray_i(
opj_image_t *in, opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im)
const JPEG2KTILEINFO *tileinfo, {
const UINT8 *tiledata,
Imaging im) {
unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
unsigned w = tileinfo->x1 - tileinfo->x0; unsigned w = tileinfo->x1 - tileinfo->x0;
unsigned h = tileinfo->y1 - tileinfo->y0; unsigned h = tileinfo->y1 - tileinfo->y0;
@ -204,10 +204,8 @@ j2ku_gray_i(
static void static void
j2ku_gray_rgb( j2ku_gray_rgb(
opj_image_t *in, opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im)
const JPEG2KTILEINFO *tileinfo, {
const UINT8 *tiledata,
Imaging im) {
unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
unsigned w = tileinfo->x1 - tileinfo->x0; unsigned w = tileinfo->x1 - tileinfo->x0;
unsigned h = tileinfo->y1 - tileinfo->y0; unsigned h = tileinfo->y1 - tileinfo->y0;
@ -268,10 +266,8 @@ j2ku_gray_rgb(
static void static void
j2ku_graya_la( j2ku_graya_la(
opj_image_t *in, opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im)
const JPEG2KTILEINFO *tileinfo, {
const UINT8 *tiledata,
Imaging im) {
unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
unsigned w = tileinfo->x1 - tileinfo->x0; unsigned w = tileinfo->x1 - tileinfo->x0;
unsigned h = tileinfo->y1 - tileinfo->y0; unsigned h = tileinfo->y1 - tileinfo->y0;
@ -347,10 +343,8 @@ j2ku_graya_la(
static void static void
j2ku_srgb_rgb( j2ku_srgb_rgb(
opj_image_t *in, opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im)
const JPEG2KTILEINFO *tileinfo, {
const UINT8 *tiledata,
Imaging im) {
unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
unsigned w = tileinfo->x1 - tileinfo->x0; unsigned w = tileinfo->x1 - tileinfo->x0;
unsigned h = tileinfo->y1 - tileinfo->y0; unsigned h = tileinfo->y1 - tileinfo->y0;
@ -413,10 +407,8 @@ j2ku_srgb_rgb(
static void static void
j2ku_sycc_rgb( j2ku_sycc_rgb(
opj_image_t *in, opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im)
const JPEG2KTILEINFO *tileinfo, {
const UINT8 *tiledata,
Imaging im) {
unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
unsigned w = tileinfo->x1 - tileinfo->x0; unsigned w = tileinfo->x1 - tileinfo->x0;
unsigned h = tileinfo->y1 - tileinfo->y0; unsigned h = tileinfo->y1 - tileinfo->y0;
@ -482,10 +474,8 @@ j2ku_sycc_rgb(
static void static void
j2ku_srgba_rgba( j2ku_srgba_rgba(
opj_image_t *in, opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im)
const JPEG2KTILEINFO *tileinfo, {
const UINT8 *tiledata,
Imaging im) {
unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
unsigned w = tileinfo->x1 - tileinfo->x0; unsigned w = tileinfo->x1 - tileinfo->x0;
unsigned h = tileinfo->y1 - tileinfo->y0; unsigned h = tileinfo->y1 - tileinfo->y0;
@ -547,10 +537,8 @@ j2ku_srgba_rgba(
static void static void
j2ku_sycca_rgba( j2ku_sycca_rgba(
opj_image_t *in, opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im)
const JPEG2KTILEINFO *tileinfo, {
const UINT8 *tiledata,
Imaging im) {
unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0; unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
unsigned w = tileinfo->x1 - tileinfo->x0; unsigned w = tileinfo->x1 - tileinfo->x0;
unsigned h = tileinfo->y1 - tileinfo->y0; unsigned h = tileinfo->y1 - tileinfo->y0;
@ -647,7 +635,8 @@ enum {
}; };
static int static int
j2k_decode_entry(Imaging im, ImagingCodecState state) { j2k_decode_entry(Imaging im, ImagingCodecState state)
{
JPEG2KDECODESTATE *context = (JPEG2KDECODESTATE *)state->context; JPEG2KDECODESTATE *context = (JPEG2KDECODESTATE *)state->context;
opj_stream_t *stream = NULL; opj_stream_t *stream = NULL;
opj_image_t *image = NULL; opj_image_t *image = NULL;
@ -945,7 +934,8 @@ quick_exit:
} }
int int
ImagingJpeg2KDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingJpeg2KDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
if (bytes) { if (bytes) {
state->errcode = IMAGING_CODEC_BROKEN; state->errcode = IMAGING_CODEC_BROKEN;
state->state = J2K_STATE_FAILED; state->state = J2K_STATE_FAILED;
@ -975,7 +965,8 @@ ImagingJpeg2KDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int int
ImagingJpeg2KDecodeCleanup(ImagingCodecState state) { ImagingJpeg2KDecodeCleanup(ImagingCodecState state)
{
JPEG2KDECODESTATE *context = (JPEG2KDECODESTATE *)state->context; JPEG2KDECODESTATE *context = (JPEG2KDECODESTATE *)state->context;
if (context->error_msg) { if (context->error_msg) {
@ -988,7 +979,8 @@ ImagingJpeg2KDecodeCleanup(ImagingCodecState state) {
} }
const char * const char *
ImagingJpeg2KVersion(void) { ImagingJpeg2KVersion(void)
{
return opj_version(); return opj_version();
} }

View File

@ -29,14 +29,16 @@
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
static void static void
j2k_error(const char *msg, void *client_data) { j2k_error(const char *msg, void *client_data)
{
JPEG2KENCODESTATE *state = (JPEG2KENCODESTATE *)client_data; JPEG2KENCODESTATE *state = (JPEG2KENCODESTATE *)client_data;
free((void *)state->error_msg); free((void *)state->error_msg);
state->error_msg = strdup(msg); state->error_msg = strdup(msg);
} }
static void static void
j2k_warn(const char *msg, void *client_data) { j2k_warn(const char *msg, void *client_data)
{
// Null handler // Null handler
} }
@ -45,7 +47,8 @@ j2k_warn(const char *msg, void *client_data) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
static OPJ_SIZE_T static OPJ_SIZE_T
j2k_write(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data) { j2k_write(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data)
{
ImagingCodecState state = (ImagingCodecState)p_user_data; ImagingCodecState state = (ImagingCodecState)p_user_data;
unsigned int result; unsigned int result;
@ -55,7 +58,8 @@ j2k_write(void *p_buffer, OPJ_SIZE_T p_nb_bytes, void *p_user_data) {
} }
static OPJ_OFF_T static OPJ_OFF_T
j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data) { j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data)
{
ImagingCodecState state = (ImagingCodecState)p_user_data; ImagingCodecState state = (ImagingCodecState)p_user_data;
char *buffer; char *buffer;
int result; int result;
@ -74,7 +78,8 @@ j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data) {
} }
static OPJ_BOOL static OPJ_BOOL
j2k_seek(OPJ_OFF_T p_nb_bytes, void *p_user_data) { j2k_seek(OPJ_OFF_T p_nb_bytes, void *p_user_data)
{
ImagingCodecState state = (ImagingCodecState)p_user_data; ImagingCodecState state = (ImagingCodecState)p_user_data;
off_t pos = 0; off_t pos = 0;
@ -92,7 +97,8 @@ typedef void (*j2k_pack_tile_t)(
Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h); Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h);
static void static void
j2k_pack_l(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h) { j2k_pack_l(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h)
{
UINT8 *ptr = buf; UINT8 *ptr = buf;
unsigned x, y; unsigned x, y;
for (y = 0; y < h; ++y) { for (y = 0; y < h; ++y) {
@ -104,7 +110,8 @@ j2k_pack_l(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigne
} }
static void static void
j2k_pack_i16(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h) { j2k_pack_i16(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h)
{
UINT8 *ptr = buf; UINT8 *ptr = buf;
unsigned x, y; unsigned x, y;
for (y = 0; y < h; ++y) { for (y = 0; y < h; ++y) {
@ -124,7 +131,8 @@ j2k_pack_i16(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsig
} }
static void static void
j2k_pack_la(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h) { j2k_pack_la(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h)
{
UINT8 *ptr = buf; UINT8 *ptr = buf;
UINT8 *ptra = buf + w * h; UINT8 *ptra = buf + w * h;
unsigned x, y; unsigned x, y;
@ -139,7 +147,8 @@ j2k_pack_la(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsign
} }
static void static void
j2k_pack_rgb(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h) { j2k_pack_rgb(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h)
{
UINT8 *pr = buf; UINT8 *pr = buf;
UINT8 *pg = pr + w * h; UINT8 *pg = pr + w * h;
UINT8 *pb = pg + w * h; UINT8 *pb = pg + w * h;
@ -156,8 +165,8 @@ j2k_pack_rgb(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsig
} }
static void static void
j2k_pack_rgba( j2k_pack_rgba(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h)
Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h) { {
UINT8 *pr = buf; UINT8 *pr = buf;
UINT8 *pg = pr + w * h; UINT8 *pg = pr + w * h;
UINT8 *pb = pg + w * h; UINT8 *pb = pg + w * h;
@ -182,7 +191,8 @@ enum {
}; };
static void static void
j2k_set_cinema_params(Imaging im, int components, opj_cparameters_t *params) { j2k_set_cinema_params(Imaging im, int components, opj_cparameters_t *params)
{
float rate; float rate;
int n; int n;
@ -263,7 +273,8 @@ j2k_set_cinema_params(Imaging im, int components, opj_cparameters_t *params) {
} }
static int static int
j2k_encode_entry(Imaging im, ImagingCodecState state) { j2k_encode_entry(Imaging im, ImagingCodecState state)
{
JPEG2KENCODESTATE *context = (JPEG2KENCODESTATE *)state->context; JPEG2KENCODESTATE *context = (JPEG2KENCODESTATE *)state->context;
opj_stream_t *stream = NULL; opj_stream_t *stream = NULL;
opj_image_t *image = NULL; opj_image_t *image = NULL;
@ -608,7 +619,8 @@ quick_exit:
} }
int int
ImagingJpeg2KEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) { ImagingJpeg2KEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
{
if (state->state == J2K_STATE_FAILED) { if (state->state == J2K_STATE_FAILED) {
return -1; return -1;
} }
@ -627,7 +639,8 @@ ImagingJpeg2KEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int int
ImagingJpeg2KEncodeCleanup(ImagingCodecState state) { ImagingJpeg2KEncodeCleanup(ImagingCodecState state)
{
JPEG2KENCODESTATE *context = (JPEG2KENCODESTATE *)state->context; JPEG2KENCODESTATE *context = (JPEG2KENCODESTATE *)state->context;
if (context->quality_layers) { if (context->quality_layers) {

View File

@ -48,7 +48,8 @@ char *libjpeg_turbo_version = NULL;
#endif #endif
int int
ImagingJpegUseJCSExtensions() { ImagingJpegUseJCSExtensions()
{
int use_jcs_extensions = 0; int use_jcs_extensions = 0;
#ifdef JCS_EXTENSIONS #ifdef JCS_EXTENSIONS
#if defined(LIBJPEG_TURBO_VERSION_NUMBER) #if defined(LIBJPEG_TURBO_VERSION_NUMBER)
@ -72,13 +73,15 @@ METHODDEF(void)
stub(j_decompress_ptr cinfo) { /* empty */ } stub(j_decompress_ptr cinfo) { /* empty */ }
METHODDEF(boolean) METHODDEF(boolean)
fill_input_buffer(j_decompress_ptr cinfo) { fill_input_buffer(j_decompress_ptr cinfo)
{
/* Suspension */ /* Suspension */
return FALSE; return FALSE;
} }
METHODDEF(void) METHODDEF(void)
skip_input_data(j_decompress_ptr cinfo, long num_bytes) { skip_input_data(j_decompress_ptr cinfo, long num_bytes)
{
JPEGSOURCE *source = (JPEGSOURCE *)cinfo->src; JPEGSOURCE *source = (JPEGSOURCE *)cinfo->src;
if (num_bytes > (long)source->pub.bytes_in_buffer) { if (num_bytes > (long)source->pub.bytes_in_buffer) {
@ -96,7 +99,8 @@ skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
} }
GLOBAL(void) GLOBAL(void)
jpeg_buffer_src(j_decompress_ptr cinfo, JPEGSOURCE *source) { jpeg_buffer_src(j_decompress_ptr cinfo, JPEGSOURCE *source)
{
cinfo->src = (void *)source; cinfo->src = (void *)source;
/* Prepare for suspending reader */ /* Prepare for suspending reader */
@ -115,7 +119,8 @@ jpeg_buffer_src(j_decompress_ptr cinfo, JPEGSOURCE *source) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
METHODDEF(void) METHODDEF(void)
error(j_common_ptr cinfo) { error(j_common_ptr cinfo)
{
JPEGERROR *error; JPEGERROR *error;
error = (JPEGERROR *)cinfo->err; error = (JPEGERROR *)cinfo->err;
longjmp(error->setjmp_buffer, 1); longjmp(error->setjmp_buffer, 1);
@ -129,7 +134,8 @@ output(j_common_ptr cinfo) { /* nothing */ }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int int
ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
JPEGSTATE *context = (JPEGSTATE *)state->context; JPEGSTATE *context = (JPEGSTATE *)state->context;
int ok; int ok;
@ -290,7 +296,8 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t by
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int int
ImagingJpegDecodeCleanup(ImagingCodecState state) { ImagingJpegDecodeCleanup(ImagingCodecState state)
{
/* called to free the decompression engine when the decode terminates /* called to free the decompression engine when the decode terminates
due to a corrupt or truncated image due to a corrupt or truncated image
*/ */

View File

@ -42,13 +42,15 @@ METHODDEF(void)
stub(j_compress_ptr cinfo) { /* empty */ } stub(j_compress_ptr cinfo) { /* empty */ }
METHODDEF(boolean) METHODDEF(boolean)
empty_output_buffer(j_compress_ptr cinfo) { empty_output_buffer(j_compress_ptr cinfo)
{
/* Suspension */ /* Suspension */
return FALSE; return FALSE;
} }
GLOBAL(void) GLOBAL(void)
jpeg_buffer_dest(j_compress_ptr cinfo, JPEGDESTINATION *destination) { jpeg_buffer_dest(j_compress_ptr cinfo, JPEGDESTINATION *destination)
{
cinfo->dest = (void *)destination; cinfo->dest = (void *)destination;
destination->pub.init_destination = stub; destination->pub.init_destination = stub;
@ -61,7 +63,8 @@ jpeg_buffer_dest(j_compress_ptr cinfo, JPEGDESTINATION *destination) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
METHODDEF(void) METHODDEF(void)
error(j_common_ptr cinfo) { error(j_common_ptr cinfo)
{
JPEGERROR *error; JPEGERROR *error;
error = (JPEGERROR *)cinfo->err; error = (JPEGERROR *)cinfo->err;
(*cinfo->err->output_message)(cinfo); (*cinfo->err->output_message)(cinfo);
@ -73,7 +76,8 @@ error(j_common_ptr cinfo) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int int
ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) { ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
{
JPEGENCODERSTATE *context = (JPEGENCODERSTATE *)state->context; JPEGENCODERSTATE *context = (JPEGENCODERSTATE *)state->context;
int ok; int ok;
@ -376,7 +380,8 @@ cleanup:
} }
const char * const char *
ImagingJpegVersion(void) { ImagingJpegVersion(void)
{
static char version[20]; static char version[20];
sprintf(version, "%d.%d", JPEG_LIB_VERSION / 10, JPEG_LIB_VERSION % 10); sprintf(version, "%d.%d", JPEG_LIB_VERSION / 10, JPEG_LIB_VERSION % 10);
return version; return version;

View File

@ -18,7 +18,8 @@
#define CLIPF(v) ((v <= 0.0) ? 0 : (v >= 255.0F) ? 255 : (UINT8)v) #define CLIPF(v) ((v <= 0.0) ? 0 : (v >= 255.0F) ? 255 : (UINT8)v)
Imaging Imaging
ImagingConvertMatrix(Imaging im, const char *mode, float m[]) { ImagingConvertMatrix(Imaging im, const char *mode, float m[])
{
Imaging imOut; Imaging imOut;
int x, y; int x, y;
ImagingSectionCookie cookie; ImagingSectionCookie cookie;

View File

@ -16,7 +16,8 @@
#include "Imaging.h" #include "Imaging.h"
Imaging Imaging
ImagingModeFilter(Imaging im, int size) { ImagingModeFilter(Imaging im, int size)
{
Imaging imOut; Imaging imOut;
int x, y, i; int x, y, i;
int xx, yy; int xx, yy;

View File

@ -19,7 +19,8 @@
#include "Imaging.h" #include "Imaging.h"
Imaging Imaging
ImagingNegative(Imaging im) { ImagingNegative(Imaging im)
{
Imaging imOut; Imaging imOut;
int x, y; int x, y;

View File

@ -17,7 +17,8 @@
#include "Imaging.h" #include "Imaging.h"
Imaging Imaging
ImagingOffset(Imaging im, int xoffset, int yoffset) { ImagingOffset(Imaging im, int xoffset, int yoffset)
{
int x, y; int x, y;
Imaging imOut; Imaging imOut;

View File

@ -80,7 +80,8 @@
#endif #endif
static void static void
pack1(UINT8 *out, const UINT8 *in, int pixels) { pack1(UINT8 *out, const UINT8 *in, int pixels)
{
int i, m, b; int i, m, b;
/* bilevel (black is 0) */ /* bilevel (black is 0) */
b = 0; b = 0;
@ -102,7 +103,8 @@ pack1(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
pack1I(UINT8 *out, const UINT8 *in, int pixels) { pack1I(UINT8 *out, const UINT8 *in, int pixels)
{
int i, m, b; int i, m, b;
/* bilevel (black is 1) */ /* bilevel (black is 1) */
b = 0; b = 0;
@ -124,7 +126,8 @@ pack1I(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
pack1R(UINT8 *out, const UINT8 *in, int pixels) { pack1R(UINT8 *out, const UINT8 *in, int pixels)
{
int i, m, b; int i, m, b;
/* bilevel, lsb first (black is 0) */ /* bilevel, lsb first (black is 0) */
b = 0; b = 0;
@ -146,7 +149,8 @@ pack1R(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
pack1IR(UINT8 *out, const UINT8 *in, int pixels) { pack1IR(UINT8 *out, const UINT8 *in, int pixels)
{
int i, m, b; int i, m, b;
/* bilevel, lsb first (black is 1) */ /* bilevel, lsb first (black is 1) */
b = 0; b = 0;
@ -168,7 +172,8 @@ pack1IR(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
pack1L(UINT8 *out, const UINT8 *in, int pixels) { pack1L(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* bilevel, stored as bytes */ /* bilevel, stored as bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -177,7 +182,8 @@ pack1L(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packP4(UINT8 *out, const UINT8 *in, int pixels) { packP4(UINT8 *out, const UINT8 *in, int pixels)
{
while (pixels >= 2) { while (pixels >= 2) {
*out++ = (in[0] << 4) | (in[1] & 15); *out++ = (in[0] << 4) | (in[1] & 15);
in += 2; in += 2;
@ -190,7 +196,8 @@ packP4(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packP2(UINT8 *out, const UINT8 *in, int pixels) { packP2(UINT8 *out, const UINT8 *in, int pixels)
{
while (pixels >= 4) { while (pixels >= 4) {
*out++ = (in[0] << 6) | ((in[1] & 3) << 4) | ((in[2] & 3) << 2) | (in[3] & 3); *out++ = (in[0] << 6) | ((in[1] & 3) << 4) | ((in[2] & 3) << 2) | (in[3] & 3);
in += 4; in += 4;
@ -210,7 +217,8 @@ packP2(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packL16(UINT8 *out, const UINT8 *in, int pixels) { packL16(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* L -> L;16, e.g: \xff77 -> \x00\xff\x00\x77 */ /* L -> L;16, e.g: \xff77 -> \x00\xff\x00\x77 */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -221,7 +229,8 @@ packL16(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packL16B(UINT8 *out, const UINT8 *in, int pixels) { packL16B(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* L -> L;16B, e.g: \xff77 -> \xff\x00\x77\x00 */ /* L -> L;16B, e.g: \xff77 -> \xff\x00\x77\x00 */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -232,7 +241,8 @@ packL16B(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packLA(UINT8 *out, const UINT8 *in, int pixels) { packLA(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* LA, pixel interleaved */ /* LA, pixel interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -244,7 +254,8 @@ packLA(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packLAL(UINT8 *out, const UINT8 *in, int pixels) { packLAL(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* LA, line interleaved */ /* LA, line interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -255,7 +266,8 @@ packLAL(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingPackRGB(UINT8 *out, const UINT8 *in, int pixels) { ImagingPackRGB(UINT8 *out, const UINT8 *in, int pixels)
{
int i = 0; int i = 0;
/* RGB triplets */ /* RGB triplets */
#ifdef __sparc #ifdef __sparc
@ -282,7 +294,8 @@ ImagingPackRGB(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingPackXRGB(UINT8 *out, const UINT8 *in, int pixels) { ImagingPackXRGB(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* XRGB, triplets with left padding */ /* XRGB, triplets with left padding */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -296,7 +309,8 @@ ImagingPackXRGB(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingPackBGR(UINT8 *out, const UINT8 *in, int pixels) { ImagingPackBGR(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGB, reversed bytes */ /* RGB, reversed bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -309,7 +323,8 @@ ImagingPackBGR(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingPackBGRX(UINT8 *out, const UINT8 *in, int pixels) { ImagingPackBGRX(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* BGRX, reversed bytes with right padding */ /* BGRX, reversed bytes with right padding */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -323,7 +338,8 @@ ImagingPackBGRX(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingPackXBGR(UINT8 *out, const UINT8 *in, int pixels) { ImagingPackXBGR(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* XBGR, reversed bytes with left padding */ /* XBGR, reversed bytes with left padding */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -337,7 +353,8 @@ ImagingPackXBGR(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingPackBGRA(UINT8 *out, const UINT8 *in, int pixels) { ImagingPackBGRA(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* BGRA, reversed bytes with right alpha */ /* BGRA, reversed bytes with right alpha */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -351,7 +368,8 @@ ImagingPackBGRA(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingPackABGR(UINT8 *out, const UINT8 *in, int pixels) { ImagingPackABGR(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* ABGR, reversed bytes with left alpha */ /* ABGR, reversed bytes with left alpha */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -365,7 +383,8 @@ ImagingPackABGR(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingPackBGRa(UINT8 *out, const UINT8 *in, int pixels) { ImagingPackBGRa(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* BGRa, reversed bytes with premultiplied alpha */ /* BGRa, reversed bytes with premultiplied alpha */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -380,7 +399,8 @@ ImagingPackBGRa(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packRGBL(UINT8 *out, const UINT8 *in, int pixels) { packRGBL(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGB, line interleaved */ /* RGB, line interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -392,7 +412,8 @@ packRGBL(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packRGBXL(UINT8 *out, const UINT8 *in, int pixels) { packRGBXL(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGBX, line interleaved */ /* RGBX, line interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -405,7 +426,8 @@ packRGBXL(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packI16B(UINT8 *out, const UINT8 *in_, int pixels) { packI16B(UINT8 *out, const UINT8 *in_, int pixels)
{
int i; int i;
UINT16 tmp_; UINT16 tmp_;
UINT8 *tmp = (UINT8 *)&tmp_; UINT8 *tmp = (UINT8 *)&tmp_;
@ -426,7 +448,8 @@ packI16B(UINT8 *out, const UINT8 *in_, int pixels) {
} }
static void static void
packI16N_I16B(UINT8 *out, const UINT8 *in, int pixels) { packI16N_I16B(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
UINT8 *tmp = (UINT8 *)in; UINT8 *tmp = (UINT8 *)in;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -436,7 +459,8 @@ packI16N_I16B(UINT8 *out, const UINT8 *in, int pixels) {
} }
} }
static void static void
packI16N_I16(UINT8 *out, const UINT8 *in, int pixels) { packI16N_I16(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
UINT8 *tmp = (UINT8 *)in; UINT8 *tmp = (UINT8 *)in;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -447,7 +471,8 @@ packI16N_I16(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
packI32S(UINT8 *out, const UINT8 *in, int pixels) { packI32S(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
UINT8 *tmp = (UINT8 *)in; UINT8 *tmp = (UINT8 *)in;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -458,7 +483,8 @@ packI32S(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingPackLAB(UINT8 *out, const UINT8 *in, int pixels) { ImagingPackLAB(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* LAB triplets */ /* LAB triplets */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -471,31 +497,36 @@ ImagingPackLAB(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
copy1(UINT8 *out, const UINT8 *in, int pixels) { copy1(UINT8 *out, const UINT8 *in, int pixels)
{
/* L, P */ /* L, P */
memcpy(out, in, pixels); memcpy(out, in, pixels);
} }
static void static void
copy2(UINT8 *out, const UINT8 *in, int pixels) { copy2(UINT8 *out, const UINT8 *in, int pixels)
{
/* I;16, etc */ /* I;16, etc */
memcpy(out, in, pixels * 2); memcpy(out, in, pixels * 2);
} }
static void static void
copy3(UINT8 *out, const UINT8 *in, int pixels) { copy3(UINT8 *out, const UINT8 *in, int pixels)
{
/* BGR;24, etc */ /* BGR;24, etc */
memcpy(out, in, pixels * 3); memcpy(out, in, pixels * 3);
} }
static void static void
copy4(UINT8 *out, const UINT8 *in, int pixels) { copy4(UINT8 *out, const UINT8 *in, int pixels)
{
/* RGBA, CMYK quadruples */ /* RGBA, CMYK quadruples */
memcpy(out, in, 4 * pixels); memcpy(out, in, 4 * pixels);
} }
static void static void
copy4I(UINT8 *out, const UINT8 *in, int pixels) { copy4I(UINT8 *out, const UINT8 *in, int pixels)
{
/* RGBA, CMYK quadruples, inverted */ /* RGBA, CMYK quadruples, inverted */
int i; int i;
for (i = 0; i < pixels * 4; i++) { for (i = 0; i < pixels * 4; i++) {
@ -504,7 +535,8 @@ copy4I(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band0(UINT8 *out, const UINT8 *in, int pixels) { band0(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++, in += 4) { for (i = 0; i < pixels; i++, in += 4) {
out[i] = in[0]; out[i] = in[0];
@ -512,7 +544,8 @@ band0(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band1(UINT8 *out, const UINT8 *in, int pixels) { band1(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++, in += 4) { for (i = 0; i < pixels; i++, in += 4) {
out[i] = in[1]; out[i] = in[1];
@ -520,7 +553,8 @@ band1(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band2(UINT8 *out, const UINT8 *in, int pixels) { band2(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++, in += 4) { for (i = 0; i < pixels; i++, in += 4) {
out[i] = in[2]; out[i] = in[2];
@ -528,7 +562,8 @@ band2(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band3(UINT8 *out, const UINT8 *in, int pixels) { band3(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++, in += 4) { for (i = 0; i < pixels; i++, in += 4) {
out[i] = in[3]; out[i] = in[3];
@ -676,7 +711,8 @@ static struct {
}; };
ImagingShuffler ImagingShuffler
ImagingFindPacker(const char *mode, const char *rawmode, int *bits_out) { ImagingFindPacker(const char *mode, const char *rawmode, int *bits_out)
{
int i; int i;
/* find a suitable pixel packer */ /* find a suitable pixel packer */

View File

@ -16,8 +16,8 @@
#include "Imaging.h" #include "Imaging.h"
int int
ImagingPackbitsDecode( ImagingPackbitsDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { {
UINT8 n; UINT8 n;
UINT8 *ptr; UINT8 *ptr;
int i; int i;

View File

@ -21,7 +21,8 @@
#include <math.h> #include <math.h>
ImagingPalette ImagingPalette
ImagingPaletteNew(const char *mode) { ImagingPaletteNew(const char *mode)
{
/* Create a palette object */ /* Create a palette object */
int i; int i;
@ -48,7 +49,8 @@ ImagingPaletteNew(const char *mode) {
} }
ImagingPalette ImagingPalette
ImagingPaletteNewBrowser(void) { ImagingPaletteNewBrowser(void)
{
/* Create a standard "browser" palette object */ /* Create a standard "browser" palette object */
int i, r, g, b; int i, r, g, b;
@ -81,7 +83,8 @@ ImagingPaletteNewBrowser(void) {
} }
ImagingPalette ImagingPalette
ImagingPaletteDuplicate(ImagingPalette palette) { ImagingPaletteDuplicate(ImagingPalette palette)
{
/* Duplicate palette descriptor */ /* Duplicate palette descriptor */
ImagingPalette new_palette; ImagingPalette new_palette;
@ -104,7 +107,8 @@ ImagingPaletteDuplicate(ImagingPalette palette) {
} }
void void
ImagingPaletteDelete(ImagingPalette palette) { ImagingPaletteDelete(ImagingPalette palette)
{
/* Destroy palette object */ /* Destroy palette object */
if (palette) { if (palette) {
@ -151,7 +155,8 @@ ImagingPaletteDelete(ImagingPalette palette) {
#define BOXVOLUME BOX *BOX *BOX #define BOXVOLUME BOX *BOX *BOX
void void
ImagingPaletteCacheUpdate(ImagingPalette palette, int r, int g, int b) { ImagingPaletteCacheUpdate(ImagingPalette palette, int r, int g, int b)
{
int i, j; int i, j;
unsigned int dmin[256], dmax; unsigned int dmin[256], dmax;
int r0, g0, b0; int r0, g0, b0;
@ -270,7 +275,8 @@ ImagingPaletteCacheUpdate(ImagingPalette palette, int r, int g, int b) {
} }
int int
ImagingPaletteCachePrepare(ImagingPalette palette) { ImagingPaletteCachePrepare(ImagingPalette palette)
{
/* Add a colour cache to a palette */ /* Add a colour cache to a palette */
int i; int i;
@ -297,7 +303,8 @@ ImagingPaletteCachePrepare(ImagingPalette palette) {
} }
void void
ImagingPaletteCacheDelete(ImagingPalette palette) { ImagingPaletteCacheDelete(ImagingPalette palette)
{
/* Release the colour cache, if any */ /* Release the colour cache, if any */
if (palette && palette->cache) { if (palette && palette->cache) {

View File

@ -33,7 +33,8 @@ paste(
int sy, int sy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* paste opaque region */ /* paste opaque region */
int y; int y;
@ -59,7 +60,8 @@ paste_mask_1(
int sy, int sy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* paste with mode "1" mask */ /* paste with mode "1" mask */
int x, y; int x, y;
@ -120,7 +122,8 @@ paste_mask_L(
int sy, int sy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* paste with mode "L" matte */ /* paste with mode "L" matte */
int x, y; int x, y;
@ -167,7 +170,8 @@ paste_mask_RGBA(
int sy, int sy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* paste with mode "RGBA" matte */ /* paste with mode "RGBA" matte */
int x, y; int x, y;
@ -214,7 +218,8 @@ paste_mask_RGBa(
int sy, int sy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* paste with mode "RGBa" matte */ /* paste with mode "RGBa" matte */
int x, y; int x, y;
@ -252,7 +257,8 @@ paste_mask_RGBa(
int int
ImagingPaste( ImagingPaste(
Imaging imOut, Imaging imIn, Imaging imMask, int dx0, int dy0, int dx1, int dy1) { Imaging imOut, Imaging imIn, Imaging imMask, int dx0, int dy0, int dx1, int dy1)
{
int xsize, ysize; int xsize, ysize;
int pixelsize; int pixelsize;
int sx0, sy0; int sx0, sy0;
@ -340,7 +346,8 @@ fill(
int dy, int dy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* fill opaque region */ /* fill opaque region */
int x, y; int x, y;
@ -378,7 +385,8 @@ fill_mask_1(
int sy, int sy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* fill with mode "1" mask */ /* fill with mode "1" mask */
int x, y; int x, y;
@ -425,7 +433,8 @@ fill_mask_L(
int sy, int sy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* fill with mode "L" matte */ /* fill with mode "L" matte */
int x, y, i; int x, y, i;
@ -484,7 +493,8 @@ fill_mask_RGBA(
int sy, int sy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* fill with mode "RGBA" matte */ /* fill with mode "RGBA" matte */
int x, y, i; int x, y, i;
@ -529,7 +539,8 @@ fill_mask_RGBa(
int sy, int sy,
int xsize, int xsize,
int ysize, int ysize,
int pixelsize) { int pixelsize)
{
/* fill with mode "RGBa" matte */ /* fill with mode "RGBa" matte */
int x, y, i; int x, y, i;
@ -565,13 +576,8 @@ fill_mask_RGBa(
int int
ImagingFill2( ImagingFill2(
Imaging imOut, Imaging imOut, const void *ink, Imaging imMask, int dx0, int dy0, int dx1, int dy1)
const void *ink, {
Imaging imMask,
int dx0,
int dy0,
int dx1,
int dy1) {
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int xsize, ysize; int xsize, ysize;
int pixelsize; int pixelsize;

View File

@ -22,7 +22,8 @@
#include "Imaging.h" #include "Imaging.h"
int int
ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
int x; int x;
int chunk; int chunk;
UINT8 *out; UINT8 *out;

View File

@ -16,7 +16,8 @@
#include "Imaging.h" #include "Imaging.h"
int int
ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
UINT8 n; UINT8 n;
UINT8 *ptr; UINT8 *ptr;

View File

@ -21,7 +21,8 @@ enum { INIT, FETCH, ENCODE };
#define LAST ystep #define LAST ystep
int int
ImagingPcxEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) { ImagingPcxEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
{
UINT8 *ptr; UINT8 *ptr;
int this; int this;
int bytes_per_line = 0; int bytes_per_line = 0;

View File

@ -26,7 +26,8 @@ typedef struct {
} im_point_context; } im_point_context;
static void static void
im_point_8_8(Imaging imOut, Imaging imIn, im_point_context *context) { im_point_8_8(Imaging imOut, Imaging imIn, im_point_context *context)
{
int x, y; int x, y;
/* 8-bit source, 8-bit destination */ /* 8-bit source, 8-bit destination */
UINT8 *table = (UINT8 *)context->table; UINT8 *table = (UINT8 *)context->table;
@ -40,7 +41,8 @@ im_point_8_8(Imaging imOut, Imaging imIn, im_point_context *context) {
} }
static void static void
im_point_2x8_2x8(Imaging imOut, Imaging imIn, im_point_context *context) { im_point_2x8_2x8(Imaging imOut, Imaging imIn, im_point_context *context)
{
int x, y; int x, y;
/* 2x8-bit source, 2x8-bit destination */ /* 2x8-bit source, 2x8-bit destination */
UINT8 *table = (UINT8 *)context->table; UINT8 *table = (UINT8 *)context->table;
@ -57,7 +59,8 @@ im_point_2x8_2x8(Imaging imOut, Imaging imIn, im_point_context *context) {
} }
static void static void
im_point_3x8_3x8(Imaging imOut, Imaging imIn, im_point_context *context) { im_point_3x8_3x8(Imaging imOut, Imaging imIn, im_point_context *context)
{
int x, y; int x, y;
/* 3x8-bit source, 3x8-bit destination */ /* 3x8-bit source, 3x8-bit destination */
UINT8 *table = (UINT8 *)context->table; UINT8 *table = (UINT8 *)context->table;
@ -75,7 +78,8 @@ im_point_3x8_3x8(Imaging imOut, Imaging imIn, im_point_context *context) {
} }
static void static void
im_point_4x8_4x8(Imaging imOut, Imaging imIn, im_point_context *context) { im_point_4x8_4x8(Imaging imOut, Imaging imIn, im_point_context *context)
{
int x, y; int x, y;
/* 4x8-bit source, 4x8-bit destination */ /* 4x8-bit source, 4x8-bit destination */
UINT8 *table = (UINT8 *)context->table; UINT8 *table = (UINT8 *)context->table;
@ -94,7 +98,8 @@ im_point_4x8_4x8(Imaging imOut, Imaging imIn, im_point_context *context) {
} }
static void static void
im_point_8_32(Imaging imOut, Imaging imIn, im_point_context *context) { im_point_8_32(Imaging imOut, Imaging imIn, im_point_context *context)
{
int x, y; int x, y;
/* 8-bit source, 32-bit destination */ /* 8-bit source, 32-bit destination */
char *table = (char *)context->table; char *table = (char *)context->table;
@ -108,7 +113,8 @@ im_point_8_32(Imaging imOut, Imaging imIn, im_point_context *context) {
} }
static void static void
im_point_32_8(Imaging imOut, Imaging imIn, im_point_context *context) { im_point_32_8(Imaging imOut, Imaging imIn, im_point_context *context)
{
int x, y; int x, y;
/* 32-bit source, 8-bit destination */ /* 32-bit source, 8-bit destination */
UINT8 *table = (UINT8 *)context->table; UINT8 *table = (UINT8 *)context->table;
@ -128,7 +134,8 @@ im_point_32_8(Imaging imOut, Imaging imIn, im_point_context *context) {
} }
Imaging Imaging
ImagingPoint(Imaging imIn, const char *mode, const void *table) { ImagingPoint(Imaging imIn, const char *mode, const void *table)
{
/* lookup table transform */ /* lookup table transform */
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
@ -202,7 +209,8 @@ mode_mismatch:
} }
Imaging Imaging
ImagingPointTransform(Imaging imIn, double scale, double offset) { ImagingPointTransform(Imaging imIn, double scale, double offset)
{
/* scale/offset transform */ /* scale/offset transform */
ImagingSectionCookie cookie; ImagingSectionCookie cookie;

View File

@ -78,12 +78,14 @@ typedef struct _BoxNode {
((q)->c.b = (p)->c.b >> (s)) ((q)->c.b = (p)->c.b >> (s))
static uint32_t static uint32_t
unshifted_pixel_hash(const HashTable *h, const Pixel pixel) { unshifted_pixel_hash(const HashTable *h, const Pixel pixel)
{
return PIXEL_HASH(pixel.c.r, pixel.c.g, pixel.c.b); return PIXEL_HASH(pixel.c.r, pixel.c.g, pixel.c.b);
} }
static int static int
unshifted_pixel_cmp(const HashTable *h, const Pixel pixel1, const Pixel pixel2) { unshifted_pixel_cmp(const HashTable *h, const Pixel pixel1, const Pixel pixel2)
{
if (pixel1.c.r == pixel2.c.r) { if (pixel1.c.r == pixel2.c.r) {
if (pixel1.c.g == pixel2.c.g) { if (pixel1.c.g == pixel2.c.g) {
if (pixel1.c.b == pixel2.c.b) { if (pixel1.c.b == pixel2.c.b) {
@ -100,14 +102,16 @@ unshifted_pixel_cmp(const HashTable *h, const Pixel pixel1, const Pixel pixel2)
} }
static uint32_t static uint32_t
pixel_hash(const HashTable *h, const Pixel pixel) { pixel_hash(const HashTable *h, const Pixel pixel)
{
PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h); PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h);
return PIXEL_HASH( return PIXEL_HASH(
pixel.c.r >> d->scale, pixel.c.g >> d->scale, pixel.c.b >> d->scale); pixel.c.r >> d->scale, pixel.c.g >> d->scale, pixel.c.b >> d->scale);
} }
static int static int
pixel_cmp(const HashTable *h, const Pixel pixel1, const Pixel pixel2) { pixel_cmp(const HashTable *h, const Pixel pixel1, const Pixel pixel2)
{
PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h); PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h);
uint32_t A, B; uint32_t A, B;
A = PIXEL_HASH( A = PIXEL_HASH(
@ -118,25 +122,29 @@ pixel_cmp(const HashTable *h, const Pixel pixel1, const Pixel pixel2) {
} }
static void static void
exists_count_func(const HashTable *h, const Pixel key, uint32_t *val) { exists_count_func(const HashTable *h, const Pixel key, uint32_t *val)
{
*val += 1; *val += 1;
} }
static void static void
new_count_func(const HashTable *h, const Pixel key, uint32_t *val) { new_count_func(const HashTable *h, const Pixel key, uint32_t *val)
{
*val = 1; *val = 1;
} }
static void static void
rehash_collide( rehash_collide(
const HashTable *h, Pixel *keyp, uint32_t *valp, Pixel newkey, uint32_t newval) { const HashTable *h, Pixel *keyp, uint32_t *valp, Pixel newkey, uint32_t newval)
{
*valp += newval; *valp += newval;
} }
/* %% */ /* %% */
static HashTable * static HashTable *
create_pixel_hash(Pixel *pixelData, uint32_t nPixels) { create_pixel_hash(Pixel *pixelData, uint32_t nPixels)
{
PixelHashData *d; PixelHashData *d;
HashTable *hash; HashTable *hash;
uint32_t i; uint32_t i;
@ -184,7 +192,8 @@ create_pixel_hash(Pixel *pixelData, uint32_t nPixels) {
} }
static void static void
destroy_pixel_hash(HashTable *hash) { destroy_pixel_hash(HashTable *hash)
{
PixelHashData *d = (PixelHashData *)hashtable_get_user_data(hash); PixelHashData *d = (PixelHashData *)hashtable_get_user_data(hash);
if (d) { if (d) {
free(d); free(d);
@ -201,7 +210,8 @@ destroy_pixel_hash(HashTable *hash) {
/* 7. map each pixel to nearest average. */ /* 7. map each pixel to nearest average. */
static int static int
compute_box_volume(BoxNode *b) { compute_box_volume(BoxNode *b)
{
unsigned char rl, rh, gl, gh, bl, bh; unsigned char rl, rh, gl, gh, bl, bh;
if (b->volume >= 0) { if (b->volume >= 0) {
return b->volume; return b->volume;
@ -221,7 +231,8 @@ compute_box_volume(BoxNode *b) {
} }
static void static void
hash_to_list(const HashTable *h, const Pixel pixel, const uint32_t count, void *u) { hash_to_list(const HashTable *h, const Pixel pixel, const uint32_t count, void *u)
{
PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h); PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h);
PixelList **pl = (PixelList **)u; PixelList **pl = (PixelList **)u;
PixelList *p; PixelList *p;
@ -250,7 +261,8 @@ hash_to_list(const HashTable *h, const Pixel pixel, const uint32_t count, void *
} }
static PixelList * static PixelList *
mergesort_pixels(PixelList *head, int i) { mergesort_pixels(PixelList *head, int i)
{
PixelList *c, *t, *a, *b, *p; PixelList *c, *t, *a, *b, *p;
if (!head || !head->next[i]) { if (!head || !head->next[i]) {
if (head) { if (head) {
@ -301,7 +313,8 @@ mergesort_pixels(PixelList *head, int i) {
#if defined(TEST_MERGESORT) || defined(TEST_SORTED) #if defined(TEST_MERGESORT) || defined(TEST_SORTED)
static int static int
test_sorted(PixelList *pl[3]) { test_sorted(PixelList *pl[3])
{
int i, n, l; int i, n, l;
PixelList *t; PixelList *t;
@ -319,7 +332,8 @@ test_sorted(PixelList *pl[3]) {
#endif #endif
static int static int
box_heap_cmp(const Heap *h, const void *A, const void *B) { box_heap_cmp(const Heap *h, const void *A, const void *B)
{
BoxNode *a = (BoxNode *)A; BoxNode *a = (BoxNode *)A;
BoxNode *b = (BoxNode *)B; BoxNode *b = (BoxNode *)B;
return (int)a->pixelCount - (int)b->pixelCount; return (int)a->pixelCount - (int)b->pixelCount;
@ -335,7 +349,8 @@ splitlists(
PixelList *nt[2][3], PixelList *nt[2][3],
uint32_t nCount[2], uint32_t nCount[2],
int axis, int axis,
uint32_t pixelCount) { uint32_t pixelCount)
{
uint32_t left; uint32_t left;
PixelList *l, *r, *c, *n; PixelList *l, *r, *c, *n;
@ -488,7 +503,8 @@ splitlists(
} }
static int static int
split(BoxNode *node) { split(BoxNode *node)
{
unsigned char rl, rh, gl, gh, bl, bh; unsigned char rl, rh, gl, gh, bl, bh;
int f[3]; int f[3];
int best, axis; int best, axis;
@ -644,7 +660,8 @@ split(BoxNode *node) {
} }
static BoxNode * static BoxNode *
median_cut(PixelList *hl[3], uint32_t imPixelCount, int nPixels) { median_cut(PixelList *hl[3], uint32_t imPixelCount, int nPixels)
{
PixelList *tl[3]; PixelList *tl[3];
int i; int i;
BoxNode *root; BoxNode *root;
@ -690,7 +707,8 @@ done:
} }
static void static void
free_box_tree(BoxNode *n) { free_box_tree(BoxNode *n)
{
PixelList *p, *pp; PixelList *p, *pp;
if (n->l) { if (n->l) {
free_box_tree(n->l); free_box_tree(n->l);
@ -707,7 +725,8 @@ free_box_tree(BoxNode *n) {
#ifdef TEST_SPLIT_INTEGRITY #ifdef TEST_SPLIT_INTEGRITY
static int static int
checkContained(BoxNode *n, Pixel *pp) { checkContained(BoxNode *n, Pixel *pp)
{
if (n->l && n->r) { if (n->l && n->r) {
return checkContained(n->l, pp) + checkContained(n->r, pp); return checkContained(n->l, pp) + checkContained(n->r, pp);
} }
@ -727,7 +746,8 @@ checkContained(BoxNode *n, Pixel *pp) {
#endif #endif
static int static int
annotate_hash_table(BoxNode *n, HashTable *h, uint32_t *box) { annotate_hash_table(BoxNode *n, HashTable *h, uint32_t *box)
{
PixelList *p; PixelList *p;
PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h); PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h);
Pixel q; Pixel q;
@ -761,7 +781,8 @@ typedef struct {
} DistanceWithIndex; } DistanceWithIndex;
static int static int
_distance_index_cmp(const void *a, const void *b) { _distance_index_cmp(const void *a, const void *b)
{
DistanceWithIndex *A = (DistanceWithIndex *)a; DistanceWithIndex *A = (DistanceWithIndex *)a;
DistanceWithIndex *B = (DistanceWithIndex *)b; DistanceWithIndex *B = (DistanceWithIndex *)b;
if (*A->distance == *B->distance) { if (*A->distance == *B->distance) {
@ -772,7 +793,8 @@ _distance_index_cmp(const void *a, const void *b) {
static int static int
resort_distance_tables( resort_distance_tables(
uint32_t *avgDist, uint32_t **avgDistSortKey, Pixel *p, uint32_t nEntries) { uint32_t *avgDist, uint32_t **avgDistSortKey, Pixel *p, uint32_t nEntries)
{
uint32_t i, j, k; uint32_t i, j, k;
uint32_t **skRow; uint32_t **skRow;
uint32_t *skElt; uint32_t *skElt;
@ -801,7 +823,8 @@ resort_distance_tables(
static int static int
build_distance_tables( build_distance_tables(
uint32_t *avgDist, uint32_t **avgDistSortKey, Pixel *p, uint32_t nEntries) { uint32_t *avgDist, uint32_t **avgDistSortKey, Pixel *p, uint32_t nEntries)
{
uint32_t i, j; uint32_t i, j;
DistanceWithIndex *dwi; DistanceWithIndex *dwi;
@ -841,7 +864,8 @@ map_image_pixels(
uint32_t nPaletteEntries, uint32_t nPaletteEntries,
uint32_t *avgDist, uint32_t *avgDist,
uint32_t **avgDistSortKey, uint32_t **avgDistSortKey,
uint32_t *pixelArray) { uint32_t *pixelArray)
{
uint32_t *aD, **aDSK; uint32_t *aD, **aDSK;
uint32_t idx; uint32_t idx;
uint32_t i, j; uint32_t i, j;
@ -888,7 +912,8 @@ map_image_pixels_from_quantized_pixels(
uint32_t **avgDistSortKey, uint32_t **avgDistSortKey,
uint32_t *pixelArray, uint32_t *pixelArray,
uint32_t *avg[3], uint32_t *avg[3],
uint32_t *count) { uint32_t *count)
{
uint32_t *aD, **aDSK; uint32_t *aD, **aDSK;
uint32_t idx; uint32_t idx;
uint32_t i, j; uint32_t i, j;
@ -946,7 +971,8 @@ map_image_pixels_from_median_box(
HashTable *medianBoxHash, HashTable *medianBoxHash,
uint32_t *avgDist, uint32_t *avgDist,
uint32_t **avgDistSortKey, uint32_t **avgDistSortKey,
uint32_t *pixelArray) { uint32_t *pixelArray)
{
uint32_t *aD, **aDSK; uint32_t *aD, **aDSK;
uint32_t idx; uint32_t idx;
uint32_t i, j; uint32_t i, j;
@ -998,7 +1024,8 @@ compute_palette_from_median_cut(
uint32_t nPixels, uint32_t nPixels,
HashTable *medianBoxHash, HashTable *medianBoxHash,
Pixel **palette, Pixel **palette,
uint32_t nPaletteEntries) { uint32_t nPaletteEntries)
{
uint32_t i; uint32_t i;
uint32_t paletteEntry; uint32_t paletteEntry;
Pixel *p; Pixel *p;
@ -1092,7 +1119,8 @@ compute_palette_from_median_cut(
static int static int
recompute_palette_from_averages( recompute_palette_from_averages(
Pixel *palette, uint32_t nPaletteEntries, uint32_t *avg[3], uint32_t *count) { Pixel *palette, uint32_t nPaletteEntries, uint32_t *avg[3], uint32_t *count)
{
uint32_t i; uint32_t i;
for (i = 0; i < nPaletteEntries; i++) { for (i = 0; i < nPaletteEntries; i++) {
@ -1111,7 +1139,8 @@ compute_palette_from_quantized_pixels(
uint32_t nPaletteEntries, uint32_t nPaletteEntries,
uint32_t *avg[3], uint32_t *avg[3],
uint32_t *count, uint32_t *count,
uint32_t *qp) { uint32_t *qp)
{
uint32_t i; uint32_t i;
memset(count, 0, sizeof(uint32_t) * nPaletteEntries); memset(count, 0, sizeof(uint32_t) * nPaletteEntries);
@ -1145,7 +1174,8 @@ k_means(
Pixel *paletteData, Pixel *paletteData,
uint32_t nPaletteEntries, uint32_t nPaletteEntries,
uint32_t *qp, uint32_t *qp,
int threshold) { int threshold)
{
uint32_t *avg[3]; uint32_t *avg[3];
uint32_t *count; uint32_t *count;
uint32_t i; uint32_t i;
@ -1273,7 +1303,8 @@ quantize(
Pixel **palette, Pixel **palette,
uint32_t *paletteLength, uint32_t *paletteLength,
uint32_t **quantizedPixels, uint32_t **quantizedPixels,
int kmeans) { int kmeans)
{
PixelList *hl[3]; PixelList *hl[3];
HashTable *h; HashTable *h;
BoxNode *root; BoxNode *root;
@ -1522,7 +1553,8 @@ typedef struct {
} DistanceData; } DistanceData;
static void static void
compute_distances(const HashTable *h, const Pixel pixel, uint32_t *dist, void *u) { compute_distances(const HashTable *h, const Pixel pixel, uint32_t *dist, void *u)
{
DistanceData *data = (DistanceData *)u; DistanceData *data = (DistanceData *)u;
uint32_t oldDist = *dist; uint32_t oldDist = *dist;
uint32_t newDist; uint32_t newDist;
@ -1545,7 +1577,8 @@ quantize2(
Pixel **palette, Pixel **palette,
uint32_t *paletteLength, uint32_t *paletteLength,
uint32_t **quantizedPixels, uint32_t **quantizedPixels,
int kmeans) { int kmeans)
{
HashTable *h; HashTable *h;
uint32_t i; uint32_t i;
uint32_t mean[3]; uint32_t mean[3];
@ -1635,7 +1668,8 @@ error_1:
} }
Imaging Imaging
ImagingQuantize(Imaging im, int colors, int mode, int kmeans) { ImagingQuantize(Imaging im, int colors, int mode, int kmeans)
{
int i, j; int i, j;
int x, y, v; int x, y, v;
UINT8 *pp; UINT8 *pp;

View File

@ -45,7 +45,8 @@ static int
_hashtable_insert_node(HashTable *, HashNode *, int, int, CollisionFunc); _hashtable_insert_node(HashTable *, HashNode *, int, int, CollisionFunc);
HashTable * HashTable *
hashtable_new(HashFunc hf, HashCmpFunc cf) { hashtable_new(HashFunc hf, HashCmpFunc cf)
{
HashTable *h; HashTable *h;
h = malloc(sizeof(HashTable)); h = malloc(sizeof(HashTable));
if (!h) { if (!h) {
@ -66,7 +67,8 @@ hashtable_new(HashFunc hf, HashCmpFunc cf) {
} }
static uint32_t static uint32_t
_findPrime(uint32_t start, int dir) { _findPrime(uint32_t start, int dir)
{
static int unit[] = {0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0}; static int unit[] = {0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0};
uint32_t t; uint32_t t;
while (start > 1) { while (start > 1) {
@ -88,7 +90,8 @@ _findPrime(uint32_t start, int dir) {
} }
static void static void
_hashtable_rehash(HashTable *h, CollisionFunc cf, uint32_t newSize) { _hashtable_rehash(HashTable *h, CollisionFunc cf, uint32_t newSize)
{
HashNode **oldTable = h->table; HashNode **oldTable = h->table;
uint32_t i; uint32_t i;
HashNode *n, *nn; HashNode *n, *nn;
@ -112,7 +115,8 @@ _hashtable_rehash(HashTable *h, CollisionFunc cf, uint32_t newSize) {
} }
static void static void
_hashtable_resize(HashTable *h) { _hashtable_resize(HashTable *h)
{
uint32_t newSize; uint32_t newSize;
uint32_t oldSize; uint32_t oldSize;
oldSize = h->length; oldSize = h->length;
@ -132,7 +136,8 @@ _hashtable_resize(HashTable *h) {
static int static int
_hashtable_insert_node( _hashtable_insert_node(
HashTable *h, HashNode *node, int resize, int update, CollisionFunc cf) { HashTable *h, HashNode *node, int resize, int update, CollisionFunc cf)
{
uint32_t hash = h->hashFunc(h, node->key) % h->length; uint32_t hash = h->hashFunc(h, node->key) % h->length;
HashNode **n, *nv; HashNode **n, *nv;
int i; int i;
@ -170,7 +175,8 @@ _hashtable_insert_node(
} }
static int static int
_hashtable_insert(HashTable *h, HashKey_t key, HashVal_t val, int resize, int update) { _hashtable_insert(HashTable *h, HashKey_t key, HashVal_t val, int resize, int update)
{
HashNode **n, *nv; HashNode **n, *nv;
HashNode *t; HashNode *t;
int i; int i;
@ -207,7 +213,8 @@ _hashtable_insert(HashTable *h, HashKey_t key, HashVal_t val, int resize, int up
int int
hashtable_insert_or_update_computed( hashtable_insert_or_update_computed(
HashTable *h, HashKey_t key, ComputeFunc newFunc, ComputeFunc existsFunc) { HashTable *h, HashKey_t key, ComputeFunc newFunc, ComputeFunc existsFunc)
{
HashNode **n, *nv; HashNode **n, *nv;
HashNode *t; HashNode *t;
int i; int i;
@ -246,12 +253,14 @@ hashtable_insert_or_update_computed(
} }
int int
hashtable_insert(HashTable *h, HashKey_t key, HashVal_t val) { hashtable_insert(HashTable *h, HashKey_t key, HashVal_t val)
{
return _hashtable_insert(h, key, val, 1, 0); return _hashtable_insert(h, key, val, 1, 0);
} }
void void
hashtable_foreach_update(HashTable *h, IteratorUpdateFunc i, void *u) { hashtable_foreach_update(HashTable *h, IteratorUpdateFunc i, void *u)
{
HashNode *n; HashNode *n;
uint32_t x; uint32_t x;
@ -265,7 +274,8 @@ hashtable_foreach_update(HashTable *h, IteratorUpdateFunc i, void *u) {
} }
void void
hashtable_foreach(HashTable *h, IteratorFunc i, void *u) { hashtable_foreach(HashTable *h, IteratorFunc i, void *u)
{
HashNode *n; HashNode *n;
uint32_t x; uint32_t x;
@ -279,7 +289,8 @@ hashtable_foreach(HashTable *h, IteratorFunc i, void *u) {
} }
void void
hashtable_free(HashTable *h) { hashtable_free(HashTable *h)
{
HashNode *n, *nn; HashNode *n, *nn;
uint32_t i; uint32_t i;
@ -296,12 +307,14 @@ hashtable_free(HashTable *h) {
} }
void void
hashtable_rehash_compute(HashTable *h, CollisionFunc cf) { hashtable_rehash_compute(HashTable *h, CollisionFunc cf)
{
_hashtable_rehash(h, cf, h->length); _hashtable_rehash(h, cf, h->length);
} }
int int
hashtable_lookup(const HashTable *h, const HashKey_t key, HashVal_t *valp) { hashtable_lookup(const HashTable *h, const HashKey_t key, HashVal_t *valp)
{
uint32_t hash = h->hashFunc(h, key) % h->length; uint32_t hash = h->hashFunc(h, key) % h->length;
HashNode *n; HashNode *n;
int i; int i;
@ -319,17 +332,20 @@ hashtable_lookup(const HashTable *h, const HashKey_t key, HashVal_t *valp) {
} }
uint32_t uint32_t
hashtable_get_count(const HashTable *h) { hashtable_get_count(const HashTable *h)
{
return h->count; return h->count;
} }
void * void *
hashtable_get_user_data(const HashTable *h) { hashtable_get_user_data(const HashTable *h)
{
return h->userData; return h->userData;
} }
void * void *
hashtable_set_user_data(HashTable *h, void *data) { hashtable_set_user_data(HashTable *h, void *data)
{
void *r = h->userData; void *r = h->userData;
h->userData = data; h->userData = data;
return r; return r;

View File

@ -41,13 +41,15 @@ _heap_test(Heap *);
#endif #endif
void void
ImagingQuantHeapFree(Heap *h) { ImagingQuantHeapFree(Heap *h)
{
free(h->heap); free(h->heap);
free(h); free(h);
} }
static int static int
_heap_grow(Heap *h, unsigned int newsize) { _heap_grow(Heap *h, unsigned int newsize)
{
void *newheap; void *newheap;
if (!newsize) { if (!newsize) {
newsize = h->heapsize << 1; newsize = h->heapsize << 1;
@ -73,7 +75,8 @@ _heap_grow(Heap *h, unsigned int newsize) {
#ifdef DEBUG #ifdef DEBUG
static int static int
_heap_test(Heap *h) { _heap_test(Heap *h)
{
unsigned int k; unsigned int k;
for (k = 1; k * 2 <= h->heapcount; k++) { for (k = 1; k * 2 <= h->heapcount; k++) {
if (h->cf(h, h->heap[k], h->heap[k * 2]) < 0) { if (h->cf(h, h->heap[k], h->heap[k * 2]) < 0) {
@ -90,7 +93,8 @@ _heap_test(Heap *h) {
#endif #endif
int int
ImagingQuantHeapRemove(Heap *h, void **r) { ImagingQuantHeapRemove(Heap *h, void **r)
{
unsigned int k, l; unsigned int k, l;
void *v; void *v;
@ -122,7 +126,8 @@ ImagingQuantHeapRemove(Heap *h, void **r) {
} }
int int
ImagingQuantHeapAdd(Heap *h, void *val) { ImagingQuantHeapAdd(Heap *h, void *val)
{
int k; int k;
if (h->heapcount == h->heapsize - 1) { if (h->heapcount == h->heapsize - 1) {
_heap_grow(h, 0); _heap_grow(h, 0);
@ -146,7 +151,8 @@ ImagingQuantHeapAdd(Heap *h, void *val) {
} }
int int
ImagingQuantHeapTop(Heap *h, void **r) { ImagingQuantHeapTop(Heap *h, void **r)
{
if (!h->heapcount) { if (!h->heapcount) {
return 0; return 0;
} }
@ -155,7 +161,8 @@ ImagingQuantHeapTop(Heap *h, void **r) {
} }
Heap * Heap *
ImagingQuantHeapNew(HeapCmpFunc cf) { ImagingQuantHeapNew(HeapCmpFunc cf)
{
Heap *h; Heap *h;
/* malloc check ok, small constant allocation */ /* malloc check ok, small constant allocation */

View File

@ -52,7 +52,8 @@ typedef struct _ColorCube {
#define MAX(a, b) (a) > (b) ? (a) : (b) #define MAX(a, b) (a) > (b) ? (a) : (b)
static ColorCube static ColorCube
new_color_cube(int r, int g, int b, int a) { new_color_cube(int r, int g, int b, int a)
{
ColorCube cube; ColorCube cube;
/* malloc check ok, small constant allocation */ /* malloc check ok, small constant allocation */
@ -98,7 +99,8 @@ new_color_cube(int r, int g, int b, int a) {
} }
static void static void
free_color_cube(ColorCube cube) { free_color_cube(ColorCube cube)
{
if (cube != NULL) { if (cube != NULL) {
free(cube->buckets); free(cube->buckets);
free(cube); free(cube);
@ -111,13 +113,15 @@ color_bucket_offset_pos(
unsigned int r, unsigned int r,
unsigned int g, unsigned int g,
unsigned int b, unsigned int b,
unsigned int a) { unsigned int a)
{
return r << cube->rOffset | g << cube->gOffset | b << cube->bOffset | return r << cube->rOffset | g << cube->gOffset | b << cube->bOffset |
a << cube->aOffset; a << cube->aOffset;
} }
static long static long
color_bucket_offset(const ColorCube cube, const Pixel *p) { color_bucket_offset(const ColorCube cube, const Pixel *p)
{
unsigned int r = p->c.r >> (8 - cube->rBits); unsigned int r = p->c.r >> (8 - cube->rBits);
unsigned int g = p->c.g >> (8 - cube->gBits); unsigned int g = p->c.g >> (8 - cube->gBits);
unsigned int b = p->c.b >> (8 - cube->bBits); unsigned int b = p->c.b >> (8 - cube->bBits);
@ -126,13 +130,15 @@ color_bucket_offset(const ColorCube cube, const Pixel *p) {
} }
static ColorBucket static ColorBucket
color_bucket_from_cube(const ColorCube cube, const Pixel *p) { color_bucket_from_cube(const ColorCube cube, const Pixel *p)
{
unsigned int offset = color_bucket_offset(cube, p); unsigned int offset = color_bucket_offset(cube, p);
return &cube->buckets[offset]; return &cube->buckets[offset];
} }
static void static void
add_color_to_color_cube(const ColorCube cube, const Pixel *p) { add_color_to_color_cube(const ColorCube cube, const Pixel *p)
{
ColorBucket bucket = color_bucket_from_cube(cube, p); ColorBucket bucket = color_bucket_from_cube(cube, p);
bucket->count += 1; bucket->count += 1;
bucket->r += p->c.r; bucket->r += p->c.r;
@ -142,7 +148,8 @@ add_color_to_color_cube(const ColorCube cube, const Pixel *p) {
} }
static unsigned long static unsigned long
count_used_color_buckets(const ColorCube cube) { count_used_color_buckets(const ColorCube cube)
{
unsigned long usedBuckets = 0; unsigned long usedBuckets = 0;
unsigned long i; unsigned long i;
for (i = 0; i < cube->size; i++) { for (i = 0; i < cube->size; i++) {
@ -154,7 +161,8 @@ count_used_color_buckets(const ColorCube cube) {
} }
static void static void
avg_color_from_color_bucket(const ColorBucket bucket, Pixel *dst) { avg_color_from_color_bucket(const ColorBucket bucket, Pixel *dst)
{
float count = bucket->count; float count = bucket->count;
if (count != 0) { if (count != 0) {
dst->c.r = CLIP8((int)(bucket->r / count)); dst->c.r = CLIP8((int)(bucket->r / count));
@ -170,12 +178,14 @@ avg_color_from_color_bucket(const ColorBucket bucket, Pixel *dst) {
} }
static int static int
compare_bucket_count(const ColorBucket a, const ColorBucket b) { compare_bucket_count(const ColorBucket a, const ColorBucket b)
{
return b->count - a->count; return b->count - a->count;
} }
static ColorBucket static ColorBucket
create_sorted_color_palette(const ColorCube cube) { create_sorted_color_palette(const ColorCube cube)
{
ColorBucket buckets; ColorBucket buckets;
if (cube->size > LONG_MAX / sizeof(struct _ColorBucket)) { if (cube->size > LONG_MAX / sizeof(struct _ColorBucket)) {
return NULL; return NULL;
@ -197,7 +207,8 @@ create_sorted_color_palette(const ColorCube cube) {
} }
void void
add_bucket_values(ColorBucket src, ColorBucket dst) { add_bucket_values(ColorBucket src, ColorBucket dst)
{
dst->count += src->count; dst->count += src->count;
dst->r += src->r; dst->r += src->r;
dst->g += src->g; dst->g += src->g;
@ -212,7 +223,8 @@ copy_color_cube(
unsigned int rBits, unsigned int rBits,
unsigned int gBits, unsigned int gBits,
unsigned int bBits, unsigned int bBits,
unsigned int aBits) { unsigned int aBits)
{
unsigned int r, g, b, a; unsigned int r, g, b, a;
long src_pos, dst_pos; long src_pos, dst_pos;
unsigned int src_reduce[4] = {0}, dst_reduce[4] = {0}; unsigned int src_reduce[4] = {0}, dst_reduce[4] = {0};
@ -279,7 +291,8 @@ copy_color_cube(
} }
void void
subtract_color_buckets(ColorCube cube, ColorBucket buckets, long nBuckets) { subtract_color_buckets(ColorCube cube, ColorBucket buckets, long nBuckets)
{
ColorBucket minuend, subtrahend; ColorBucket minuend, subtrahend;
long i; long i;
Pixel p; Pixel p;
@ -302,19 +315,22 @@ subtract_color_buckets(ColorCube cube, ColorBucket buckets, long nBuckets) {
} }
static void static void
set_lookup_value(const ColorCube cube, const Pixel *p, long value) { set_lookup_value(const ColorCube cube, const Pixel *p, long value)
{
ColorBucket bucket = color_bucket_from_cube(cube, p); ColorBucket bucket = color_bucket_from_cube(cube, p);
bucket->count = value; bucket->count = value;
} }
uint64_t uint64_t
lookup_color(const ColorCube cube, const Pixel *p) { lookup_color(const ColorCube cube, const Pixel *p)
{
ColorBucket bucket = color_bucket_from_cube(cube, p); ColorBucket bucket = color_bucket_from_cube(cube, p);
return bucket->count; return bucket->count;
} }
void void
add_lookup_buckets(ColorCube cube, ColorBucket palette, long nColors, long offset) { add_lookup_buckets(ColorCube cube, ColorBucket palette, long nColors, long offset)
{
long i; long i;
Pixel p; Pixel p;
for (i = offset + nColors - 1; i >= offset; i--) { for (i = offset + nColors - 1; i >= offset; i--) {
@ -328,7 +344,8 @@ combined_palette(
ColorBucket bucketsA, ColorBucket bucketsA,
unsigned long nBucketsA, unsigned long nBucketsA,
ColorBucket bucketsB, ColorBucket bucketsB,
unsigned long nBucketsB) { unsigned long nBucketsB)
{
ColorBucket result; ColorBucket result;
if (nBucketsA > LONG_MAX - nBucketsB || if (nBucketsA > LONG_MAX - nBucketsB ||
(nBucketsA + nBucketsB) > LONG_MAX / sizeof(struct _ColorBucket)) { (nBucketsA + nBucketsB) > LONG_MAX / sizeof(struct _ColorBucket)) {
@ -345,7 +362,8 @@ combined_palette(
} }
static Pixel * static Pixel *
create_palette_array(const ColorBucket palette, unsigned int paletteLength) { create_palette_array(const ColorBucket palette, unsigned int paletteLength)
{
Pixel *paletteArray; Pixel *paletteArray;
unsigned int i; unsigned int i;
@ -366,7 +384,8 @@ map_image_pixels(
const Pixel *pixelData, const Pixel *pixelData,
uint32_t nPixels, uint32_t nPixels,
const ColorCube lookupCube, const ColorCube lookupCube,
uint32_t *pixelArray) { uint32_t *pixelArray)
{
long i; long i;
for (i = 0; i < nPixels; i++) { for (i = 0; i < nPixels; i++) {
pixelArray[i] = lookup_color(lookupCube, &pixelData[i]); pixelArray[i] = lookup_color(lookupCube, &pixelData[i]);
@ -384,7 +403,8 @@ quantize_octree(
Pixel **palette, Pixel **palette,
uint32_t *paletteLength, uint32_t *paletteLength,
uint32_t **quantizedPixels, uint32_t **quantizedPixels,
int withAlpha) { int withAlpha)
{
ColorCube fineCube = NULL; ColorCube fineCube = NULL;
ColorCube coarseCube = NULL; ColorCube coarseCube = NULL;
ColorCube lookupCube = NULL; ColorCube lookupCube = NULL;

View File

@ -26,7 +26,8 @@ quantize_pngquant(
Pixel **palette, Pixel **palette,
uint32_t *paletteLength, uint32_t *paletteLength,
uint32_t **quantizedPixels, uint32_t **quantizedPixels,
int withAlpha) { int withAlpha)
{
int result = 0; int result = 0;
liq_image *image = NULL; liq_image *image = NULL;
liq_attr *attr = NULL; liq_attr *attr = NULL;
@ -122,7 +123,8 @@ err:
} }
const char * const char *
ImagingImageQuantVersion(void) { ImagingImageQuantVersion(void)
{
static char version[20]; static char version[20];
int number = liq_version(); int number = liq_version();
sprintf(version, "%d.%d.%d", number / 10000, (number / 100) % 100, number % 100); sprintf(version, "%d.%d.%d", number / 10000, (number / 100) % 100, number % 100);

View File

@ -25,7 +25,8 @@
} }
#define MakeRankFunction(type) \ #define MakeRankFunction(type) \
static type Rank##type(type a[], int n, int k) { \ static type Rank##type(type a[], int n, int k) \
{ \
register int i, j, l, m; \ register int i, j, l, m; \
register type x; \ register type x; \
l = 0; \ l = 0; \
@ -59,7 +60,8 @@
MakeRankFunction(UINT8) MakeRankFunction(INT32) MakeRankFunction(FLOAT32) MakeRankFunction(UINT8) MakeRankFunction(INT32) MakeRankFunction(FLOAT32)
Imaging ImagingRankFilter(Imaging im, int size, int rank) { Imaging ImagingRankFilter(Imaging im, int size, int rank)
{
Imaging imOut = NULL; Imaging imOut = NULL;
int x, y; int x, y;
int i, margin, size2; int i, margin, size2;

View File

@ -18,7 +18,8 @@
#include "Raw.h" #include "Raw.h"
int int
ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
enum { LINE = 1, SKIP }; enum { LINE = 1, SKIP };
RAWSTATE *rawstate = state->context; RAWSTATE *rawstate = state->context;

View File

@ -20,7 +20,8 @@
#include "Imaging.h" #include "Imaging.h"
int int
ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) { ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
{
UINT8 *ptr; UINT8 *ptr;
if (!state->state) { if (!state->state) {

View File

@ -5,14 +5,16 @@
#define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F)) #define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F))
UINT32 UINT32
division_UINT32(int divider, int result_bits) { division_UINT32(int divider, int result_bits)
{
UINT32 max_dividend = (1 << result_bits) * divider; UINT32 max_dividend = (1 << result_bits) * divider;
float max_int = (1 << 30) * 4.0; float max_int = (1 << 30) * 4.0;
return (UINT32)(max_int / max_dividend); return (UINT32)(max_int / max_dividend);
} }
void void
ImagingReduceNxN(Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale) { ImagingReduceNxN(Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale)
{
/* The most general implementation for any xscale and yscale /* The most general implementation for any xscale and yscale
*/ */
int x, y, xx, yy; int x, y, xx, yy;
@ -180,7 +182,8 @@ ImagingReduceNxN(Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale
} }
void void
ImagingReduce1xN(Imaging imOut, Imaging imIn, int box[4], int yscale) { ImagingReduce1xN(Imaging imOut, Imaging imIn, int box[4], int yscale)
{
/* Optimized implementation for xscale = 1. /* Optimized implementation for xscale = 1.
*/ */
int x, y, yy; int x, y, yy;
@ -287,7 +290,8 @@ ImagingReduce1xN(Imaging imOut, Imaging imIn, int box[4], int yscale) {
} }
void void
ImagingReduceNx1(Imaging imOut, Imaging imIn, int box[4], int xscale) { ImagingReduceNx1(Imaging imOut, Imaging imIn, int box[4], int xscale)
{
/* Optimized implementation for yscale = 1. /* Optimized implementation for yscale = 1.
*/ */
int x, y, xx; int x, y, xx;
@ -384,7 +388,8 @@ ImagingReduceNx1(Imaging imOut, Imaging imIn, int box[4], int xscale) {
} }
void void
ImagingReduce1x2(Imaging imOut, Imaging imIn, int box[4]) { ImagingReduce1x2(Imaging imOut, Imaging imIn, int box[4])
{
/* Optimized implementation for xscale = 1 and yscale = 2. /* Optimized implementation for xscale = 1 and yscale = 2.
*/ */
int xscale = 1, yscale = 2; int xscale = 1, yscale = 2;
@ -449,7 +454,8 @@ ImagingReduce1x2(Imaging imOut, Imaging imIn, int box[4]) {
} }
void void
ImagingReduce2x1(Imaging imOut, Imaging imIn, int box[4]) { ImagingReduce2x1(Imaging imOut, Imaging imIn, int box[4])
{
/* Optimized implementation for xscale = 2 and yscale = 1. /* Optimized implementation for xscale = 2 and yscale = 1.
*/ */
int xscale = 2, yscale = 1; int xscale = 2, yscale = 1;
@ -512,7 +518,8 @@ ImagingReduce2x1(Imaging imOut, Imaging imIn, int box[4]) {
} }
void void
ImagingReduce2x2(Imaging imOut, Imaging imIn, int box[4]) { ImagingReduce2x2(Imaging imOut, Imaging imIn, int box[4])
{
/* Optimized implementation for xscale = 2 and yscale = 2. /* Optimized implementation for xscale = 2 and yscale = 2.
*/ */
int xscale = 2, yscale = 2; int xscale = 2, yscale = 2;
@ -586,7 +593,8 @@ ImagingReduce2x2(Imaging imOut, Imaging imIn, int box[4]) {
} }
void void
ImagingReduce1x3(Imaging imOut, Imaging imIn, int box[4]) { ImagingReduce1x3(Imaging imOut, Imaging imIn, int box[4])
{
/* Optimized implementation for xscale = 1 and yscale = 3. /* Optimized implementation for xscale = 1 and yscale = 3.
*/ */
int xscale = 1, yscale = 3; int xscale = 1, yscale = 3;
@ -661,7 +669,8 @@ ImagingReduce1x3(Imaging imOut, Imaging imIn, int box[4]) {
} }
void void
ImagingReduce3x1(Imaging imOut, Imaging imIn, int box[4]) { ImagingReduce3x1(Imaging imOut, Imaging imIn, int box[4])
{
/* Optimized implementation for xscale = 3 and yscale = 1. /* Optimized implementation for xscale = 3 and yscale = 1.
*/ */
int xscale = 3, yscale = 1; int xscale = 3, yscale = 1;
@ -732,7 +741,8 @@ ImagingReduce3x1(Imaging imOut, Imaging imIn, int box[4]) {
} }
void void
ImagingReduce3x3(Imaging imOut, Imaging imIn, int box[4]) { ImagingReduce3x3(Imaging imOut, Imaging imIn, int box[4])
{
/* Optimized implementation for xscale = 3 and yscale = 3. /* Optimized implementation for xscale = 3 and yscale = 3.
*/ */
int xscale = 3, yscale = 3; int xscale = 3, yscale = 3;
@ -827,7 +837,8 @@ ImagingReduce3x3(Imaging imOut, Imaging imIn, int box[4]) {
} }
void void
ImagingReduce4x4(Imaging imOut, Imaging imIn, int box[4]) { ImagingReduce4x4(Imaging imOut, Imaging imIn, int box[4])
{
/* Optimized implementation for xscale = 4 and yscale = 4. /* Optimized implementation for xscale = 4 and yscale = 4.
*/ */
int xscale = 4, yscale = 4; int xscale = 4, yscale = 4;
@ -944,7 +955,8 @@ ImagingReduce4x4(Imaging imOut, Imaging imIn, int box[4]) {
} }
void void
ImagingReduce5x5(Imaging imOut, Imaging imIn, int box[4]) { ImagingReduce5x5(Imaging imOut, Imaging imIn, int box[4])
{
/* Fast special case for xscale = 5 and yscale = 5. /* Fast special case for xscale = 5 and yscale = 5.
*/ */
int xscale = 5, yscale = 5; int xscale = 5, yscale = 5;
@ -1101,7 +1113,8 @@ ImagingReduce5x5(Imaging imOut, Imaging imIn, int box[4]) {
} }
void void
ImagingReduceCorners(Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale) { ImagingReduceCorners(Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale)
{
/* Fill the last row and the last column for any xscale and yscale. /* Fill the last row and the last column for any xscale and yscale.
*/ */
int x, y, xx, yy; int x, y, xx, yy;
@ -1239,8 +1252,8 @@ ImagingReduceCorners(Imaging imOut, Imaging imIn, int box[4], int xscale, int ys
} }
void void
ImagingReduceNxN_32bpc( ImagingReduceNxN_32bpc(Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale)
Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale) { {
/* The most general implementation for any xscale and yscale /* The most general implementation for any xscale and yscale
*/ */
int x, y, xx, yy; int x, y, xx, yy;
@ -1313,7 +1326,8 @@ ImagingReduceNxN_32bpc(
void void
ImagingReduceCorners_32bpc( ImagingReduceCorners_32bpc(
Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale) { Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale)
{
/* Fill the last row and the last column for any xscale and yscale. /* Fill the last row and the last column for any xscale and yscale.
*/ */
int x, y, xx, yy; int x, y, xx, yy;
@ -1414,7 +1428,8 @@ ImagingReduceCorners_32bpc(
} }
Imaging Imaging
ImagingReduce(Imaging imIn, int xscale, int yscale, int box[4]) { ImagingReduce(Imaging imIn, int xscale, int yscale, int box[4])
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
Imaging imOut = NULL; Imaging imOut = NULL;

View File

@ -10,7 +10,8 @@ struct filter {
}; };
static inline double static inline double
box_filter(double x) { box_filter(double x)
{
if (x > -0.5 && x <= 0.5) { if (x > -0.5 && x <= 0.5) {
return 1.0; return 1.0;
} }
@ -18,7 +19,8 @@ box_filter(double x) {
} }
static inline double static inline double
bilinear_filter(double x) { bilinear_filter(double x)
{
if (x < 0.0) { if (x < 0.0) {
x = -x; x = -x;
} }
@ -29,7 +31,8 @@ bilinear_filter(double x) {
} }
static inline double static inline double
hamming_filter(double x) { hamming_filter(double x)
{
if (x < 0.0) { if (x < 0.0) {
x = -x; x = -x;
} }
@ -44,7 +47,8 @@ hamming_filter(double x) {
} }
static inline double static inline double
bicubic_filter(double x) { bicubic_filter(double x)
{
/* https://en.wikipedia.org/wiki/Bicubic_interpolation#Bicubic_convolution_algorithm /* https://en.wikipedia.org/wiki/Bicubic_interpolation#Bicubic_convolution_algorithm
*/ */
#define a -0.5 #define a -0.5
@ -62,7 +66,8 @@ bicubic_filter(double x) {
} }
static inline double static inline double
sinc_filter(double x) { sinc_filter(double x)
{
if (x == 0.0) { if (x == 0.0) {
return 1.0; return 1.0;
} }
@ -71,7 +76,8 @@ sinc_filter(double x) {
} }
static inline double static inline double
lanczos_filter(double x) { lanczos_filter(double x)
{
/* truncated sinc */ /* truncated sinc */
if (-3.0 <= x && x < 3.0) { if (-3.0 <= x && x < 3.0) {
return sinc_filter(x) * sinc_filter(x / 3); return sinc_filter(x) * sinc_filter(x / 3);
@ -174,7 +180,8 @@ UINT8 _clip8_lookups[1280] = {
UINT8 *clip8_lookups = &_clip8_lookups[640]; UINT8 *clip8_lookups = &_clip8_lookups[640];
static inline UINT8 static inline UINT8
clip8(int in) { clip8(int in)
{
return clip8_lookups[in >> PRECISION_BITS]; return clip8_lookups[in >> PRECISION_BITS];
} }
@ -186,7 +193,8 @@ precompute_coeffs(
int outSize, int outSize,
struct filter *filterp, struct filter *filterp,
int **boundsp, int **boundsp,
double **kkp) { double **kkp)
{
double support, scale, filterscale; double support, scale, filterscale;
double center, ww, ss; double center, ww, ss;
int xx, x, ksize, xmin, xmax; int xx, x, ksize, xmin, xmax;
@ -266,7 +274,8 @@ precompute_coeffs(
} }
void void
normalize_coeffs_8bpc(int outSize, int ksize, double *prekk) { normalize_coeffs_8bpc(int outSize, int ksize, double *prekk)
{
int x; int x;
INT32 *kk; INT32 *kk;
@ -284,7 +293,8 @@ normalize_coeffs_8bpc(int outSize, int ksize, double *prekk) {
void void
ImagingResampleHorizontal_8bpc( ImagingResampleHorizontal_8bpc(
Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *prekk) { Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *prekk)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int ss0, ss1, ss2, ss3; int ss0, ss1, ss2, ss3;
int xx, yy, x, xmin, xmax; int xx, yy, x, xmin, xmax;
@ -376,7 +386,8 @@ ImagingResampleHorizontal_8bpc(
void void
ImagingResampleVertical_8bpc( ImagingResampleVertical_8bpc(
Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *prekk) { Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *prekk)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
int ss0, ss1, ss2, ss3; int ss0, ss1, ss2, ss3;
int xx, yy, y, ymin, ymax; int xx, yy, y, ymin, ymax;
@ -459,7 +470,8 @@ ImagingResampleVertical_8bpc(
void void
ImagingResampleHorizontal_32bpc( ImagingResampleHorizontal_32bpc(
Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk) { Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
double ss; double ss;
int xx, yy, x, xmin, xmax; int xx, yy, x, xmin, xmax;
@ -502,7 +514,8 @@ ImagingResampleHorizontal_32bpc(
void void
ImagingResampleVertical_32bpc( ImagingResampleVertical_32bpc(
Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk) { Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
double ss; double ss;
int xx, yy, y, ymin, ymax; int xx, yy, y, ymin, ymax;
@ -557,7 +570,8 @@ ImagingResampleInner(
ResampleFunction ResampleVertical); ResampleFunction ResampleVertical);
Imaging Imaging
ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4]) { ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4])
{
struct filter *filterp; struct filter *filterp;
ResampleFunction ResampleHorizontal; ResampleFunction ResampleHorizontal;
ResampleFunction ResampleVertical; ResampleFunction ResampleVertical;
@ -620,7 +634,8 @@ ImagingResampleInner(
struct filter *filterp, struct filter *filterp,
float box[4], float box[4],
ResampleFunction ResampleHorizontal, ResampleFunction ResampleHorizontal,
ResampleFunction ResampleVertical) { ResampleFunction ResampleVertical)
{
Imaging imTemp = NULL; Imaging imTemp = NULL;
Imaging imOut = NULL; Imaging imOut = NULL;

View File

@ -21,7 +21,8 @@
#define RLE_MAX_RUN 0x7f #define RLE_MAX_RUN 0x7f
static void static void
read4B(UINT32 *dest, UINT8 *buf) { read4B(UINT32 *dest, UINT8 *buf)
{
*dest = (UINT32)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); *dest = (UINT32)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
} }
@ -61,7 +62,8 @@ read4B(UINT32 *dest, UINT8 *buf) {
*/ */
static int static int
expandrow(UINT8 *dest, UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer) { expandrow(UINT8 *dest, UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer)
{
/* /*
* n here is the number of rlechunks * n here is the number of rlechunks
* z is the number of channels, for calculating the interleave * z is the number of channels, for calculating the interleave
@ -113,8 +115,8 @@ expandrow(UINT8 *dest, UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer
} }
static int static int
expandrow2( expandrow2(UINT8 *dest, const UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer)
UINT8 *dest, const UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer) { {
UINT8 pixel, count; UINT8 pixel, count;
int x = 0; int x = 0;
@ -159,7 +161,8 @@ expandrow2(
} }
int int
ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
UINT8 *ptr; UINT8 *ptr;
SGISTATE *c; SGISTATE *c;
int err = 0; int err = 0;

View File

@ -42,7 +42,8 @@
*/ */
Imaging Imaging
ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) { ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size)
{
Imaging im; Imaging im;
/* linesize overflow check, roughly the current largest space req'd */ /* linesize overflow check, roughly the current largest space req'd */
@ -225,13 +226,15 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
} }
Imaging Imaging
ImagingNewPrologue(const char *mode, int xsize, int ysize) { ImagingNewPrologue(const char *mode, int xsize, int ysize)
{
return ImagingNewPrologueSubtype( return ImagingNewPrologueSubtype(
mode, xsize, ysize, sizeof(struct ImagingMemoryInstance)); mode, xsize, ysize, sizeof(struct ImagingMemoryInstance));
} }
void void
ImagingDelete(Imaging im) { ImagingDelete(Imaging im)
{
if (!im) { if (!im) {
return; return;
} }
@ -271,7 +274,8 @@ struct ImagingMemoryArena ImagingDefaultArena = {
}; };
int int
ImagingMemorySetBlocksMax(ImagingMemoryArena arena, int blocks_max) { ImagingMemorySetBlocksMax(ImagingMemoryArena arena, int blocks_max)
{
void *p; void *p;
/* Free already cached blocks */ /* Free already cached blocks */
ImagingMemoryClearCache(arena, blocks_max); ImagingMemoryClearCache(arena, blocks_max);
@ -298,7 +302,8 @@ ImagingMemorySetBlocksMax(ImagingMemoryArena arena, int blocks_max) {
} }
void void
ImagingMemoryClearCache(ImagingMemoryArena arena, int new_size) { ImagingMemoryClearCache(ImagingMemoryArena arena, int new_size)
{
while (arena->blocks_cached > new_size) { while (arena->blocks_cached > new_size) {
arena->blocks_cached -= 1; arena->blocks_cached -= 1;
free(arena->blocks_pool[arena->blocks_cached].ptr); free(arena->blocks_pool[arena->blocks_cached].ptr);
@ -307,7 +312,8 @@ ImagingMemoryClearCache(ImagingMemoryArena arena, int new_size) {
} }
ImagingMemoryBlock ImagingMemoryBlock
memory_get_block(ImagingMemoryArena arena, int requested_size, int dirty) { memory_get_block(ImagingMemoryArena arena, int requested_size, int dirty)
{
ImagingMemoryBlock block = {NULL, 0}; ImagingMemoryBlock block = {NULL, 0};
if (arena->blocks_cached > 0) { if (arena->blocks_cached > 0) {
@ -344,7 +350,8 @@ memory_get_block(ImagingMemoryArena arena, int requested_size, int dirty) {
} }
void void
memory_return_block(ImagingMemoryArena arena, ImagingMemoryBlock block) { memory_return_block(ImagingMemoryArena arena, ImagingMemoryBlock block)
{
if (arena->blocks_cached < arena->blocks_max) { if (arena->blocks_cached < arena->blocks_max) {
// Reduce block size // Reduce block size
if (block.size > arena->block_size) { if (block.size > arena->block_size) {
@ -360,7 +367,8 @@ memory_return_block(ImagingMemoryArena arena, ImagingMemoryBlock block) {
} }
static void static void
ImagingDestroyArray(Imaging im) { ImagingDestroyArray(Imaging im)
{
int y = 0; int y = 0;
if (im->blocks) { if (im->blocks) {
@ -373,7 +381,8 @@ ImagingDestroyArray(Imaging im) {
} }
Imaging Imaging
ImagingAllocateArray(Imaging im, int dirty, int block_size) { ImagingAllocateArray(Imaging im, int dirty, int block_size)
{
int y, line_in_block, current_block; int y, line_in_block, current_block;
ImagingMemoryArena arena = &ImagingDefaultArena; ImagingMemoryArena arena = &ImagingDefaultArena;
ImagingMemoryBlock block = {NULL, 0}; ImagingMemoryBlock block = {NULL, 0};
@ -442,14 +451,16 @@ ImagingAllocateArray(Imaging im, int dirty, int block_size) {
/* Allocate image as a single block. */ /* Allocate image as a single block. */
static void static void
ImagingDestroyBlock(Imaging im) { ImagingDestroyBlock(Imaging im)
{
if (im->block) { if (im->block) {
free(im->block); free(im->block);
} }
} }
Imaging Imaging
ImagingAllocateBlock(Imaging im) { ImagingAllocateBlock(Imaging im)
{
Py_ssize_t y, i; Py_ssize_t y, i;
/* overflow check for malloc */ /* overflow check for malloc */
@ -486,7 +497,8 @@ ImagingAllocateBlock(Imaging im) {
*/ */
Imaging Imaging
ImagingNewInternal(const char *mode, int xsize, int ysize, int dirty) { ImagingNewInternal(const char *mode, int xsize, int ysize, int dirty)
{
Imaging im; Imaging im;
if (xsize < 0 || ysize < 0) { if (xsize < 0 || ysize < 0) {
@ -514,17 +526,20 @@ ImagingNewInternal(const char *mode, int xsize, int ysize, int dirty) {
} }
Imaging Imaging
ImagingNew(const char *mode, int xsize, int ysize) { ImagingNew(const char *mode, int xsize, int ysize)
{
return ImagingNewInternal(mode, xsize, ysize, 0); return ImagingNewInternal(mode, xsize, ysize, 0);
} }
Imaging Imaging
ImagingNewDirty(const char *mode, int xsize, int ysize) { ImagingNewDirty(const char *mode, int xsize, int ysize)
{
return ImagingNewInternal(mode, xsize, ysize, 1); return ImagingNewInternal(mode, xsize, ysize, 1);
} }
Imaging Imaging
ImagingNewBlock(const char *mode, int xsize, int ysize) { ImagingNewBlock(const char *mode, int xsize, int ysize)
{
Imaging im; Imaging im;
if (xsize < 0 || ysize < 0) { if (xsize < 0 || ysize < 0) {
@ -545,7 +560,8 @@ ImagingNewBlock(const char *mode, int xsize, int ysize) {
} }
Imaging Imaging
ImagingNew2Dirty(const char *mode, Imaging imOut, Imaging imIn) { ImagingNew2Dirty(const char *mode, Imaging imOut, Imaging imIn)
{
/* allocate or validate output image */ /* allocate or validate output image */
if (imOut) { if (imOut) {
@ -566,7 +582,8 @@ ImagingNew2Dirty(const char *mode, Imaging imOut, Imaging imIn) {
} }
void void
ImagingCopyPalette(Imaging destination, Imaging source) { ImagingCopyPalette(Imaging destination, Imaging source)
{
if (source->palette) { if (source->palette) {
if (destination->palette) { if (destination->palette) {
ImagingPaletteDelete(destination->palette); ImagingPaletteDelete(destination->palette);

View File

@ -18,7 +18,8 @@
#include "Imaging.h" #include "Imaging.h"
int int
ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
int n; int n;
UINT8 *ptr; UINT8 *ptr;
UINT8 extra_data = 0; UINT8 extra_data = 0;

View File

@ -17,7 +17,8 @@
#include "Imaging.h" #include "Imaging.h"
int int
ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
int n, depth; int n, depth;
UINT8 *ptr; UINT8 *ptr;
int extra_bytes = 0; int extra_bytes = 0;

View File

@ -5,13 +5,15 @@
#include <string.h> #include <string.h>
static int static int
comparePixels(const UINT8 *buf, int x, int bytesPerPixel) { comparePixels(const UINT8 *buf, int x, int bytesPerPixel)
{
buf += x * bytesPerPixel; buf += x * bytesPerPixel;
return memcmp(buf, buf + bytesPerPixel, bytesPerPixel) == 0; return memcmp(buf, buf + bytesPerPixel, bytesPerPixel) == 0;
} }
int int
ImagingTgaRleEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) { ImagingTgaRleEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
{
UINT8 *dst; UINT8 *dst;
int bytesPerPixel; int bytesPerPixel;

View File

@ -37,7 +37,8 @@
#endif #endif
void void
dump_state(const TIFFSTATE *state) { dump_state(const TIFFSTATE *state)
{
TRACE( TRACE(
("State: Location %u size %d eof %d data: %p ifd: %d\n", ("State: Location %u size %d eof %d data: %p ifd: %d\n",
(uint)state->loc, (uint)state->loc,
@ -52,7 +53,8 @@ dump_state(const TIFFSTATE *state) {
*/ */
tsize_t tsize_t
_tiffReadProc(thandle_t hdata, tdata_t buf, tsize_t size) { _tiffReadProc(thandle_t hdata, tdata_t buf, tsize_t size)
{
TIFFSTATE *state = (TIFFSTATE *)hdata; TIFFSTATE *state = (TIFFSTATE *)hdata;
tsize_t to_read; tsize_t to_read;
@ -78,7 +80,8 @@ _tiffReadProc(thandle_t hdata, tdata_t buf, tsize_t size) {
} }
tsize_t tsize_t
_tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) { _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size)
{
TIFFSTATE *state = (TIFFSTATE *)hdata; TIFFSTATE *state = (TIFFSTATE *)hdata;
tsize_t to_write; tsize_t to_write;
@ -119,7 +122,8 @@ _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) {
} }
toff_t toff_t
_tiffSeekProc(thandle_t hdata, toff_t off, int whence) { _tiffSeekProc(thandle_t hdata, toff_t off, int whence)
{
TIFFSTATE *state = (TIFFSTATE *)hdata; TIFFSTATE *state = (TIFFSTATE *)hdata;
TRACE(("_tiffSeekProc: off: %u whence: %d \n", (uint)off, whence)); TRACE(("_tiffSeekProc: off: %u whence: %d \n", (uint)off, whence));
@ -140,7 +144,8 @@ _tiffSeekProc(thandle_t hdata, toff_t off, int whence) {
} }
int int
_tiffCloseProc(thandle_t hdata) { _tiffCloseProc(thandle_t hdata)
{
TIFFSTATE *state = (TIFFSTATE *)hdata; TIFFSTATE *state = (TIFFSTATE *)hdata;
TRACE(("_tiffCloseProc \n")); TRACE(("_tiffCloseProc \n"));
@ -150,7 +155,8 @@ _tiffCloseProc(thandle_t hdata) {
} }
toff_t toff_t
_tiffSizeProc(thandle_t hdata) { _tiffSizeProc(thandle_t hdata)
{
TIFFSTATE *state = (TIFFSTATE *)hdata; TIFFSTATE *state = (TIFFSTATE *)hdata;
TRACE(("_tiffSizeProc \n")); TRACE(("_tiffSizeProc \n"));
@ -160,7 +166,8 @@ _tiffSizeProc(thandle_t hdata) {
} }
int int
_tiffMapProc(thandle_t hdata, tdata_t *pbase, toff_t *psize) { _tiffMapProc(thandle_t hdata, tdata_t *pbase, toff_t *psize)
{
TIFFSTATE *state = (TIFFSTATE *)hdata; TIFFSTATE *state = (TIFFSTATE *)hdata;
TRACE(("_tiffMapProc input size: %u, data: %p\n", (uint)*psize, *pbase)); TRACE(("_tiffMapProc input size: %u, data: %p\n", (uint)*psize, *pbase));
@ -173,7 +180,8 @@ _tiffMapProc(thandle_t hdata, tdata_t *pbase, toff_t *psize) {
} }
int int
_tiffNullMapProc(thandle_t hdata, tdata_t *pbase, toff_t *psize) { _tiffNullMapProc(thandle_t hdata, tdata_t *pbase, toff_t *psize)
{
(void)hdata; (void)hdata;
(void)pbase; (void)pbase;
(void)psize; (void)psize;
@ -181,7 +189,8 @@ _tiffNullMapProc(thandle_t hdata, tdata_t *pbase, toff_t *psize) {
} }
void void
_tiffUnmapProc(thandle_t hdata, tdata_t base, toff_t size) { _tiffUnmapProc(thandle_t hdata, tdata_t base, toff_t size)
{
TRACE(("_tiffUnMapProc\n")); TRACE(("_tiffUnMapProc\n"));
(void)hdata; (void)hdata;
(void)base; (void)base;
@ -189,7 +198,8 @@ _tiffUnmapProc(thandle_t hdata, tdata_t base, toff_t size) {
} }
int int
ImagingLibTiffInit(ImagingCodecState state, int fp, uint32_t offset) { ImagingLibTiffInit(ImagingCodecState state, int fp, uint32_t offset)
{
TIFFSTATE *clientstate = (TIFFSTATE *)state->context; TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
TRACE(("initing libtiff\n")); TRACE(("initing libtiff\n"));
@ -226,7 +236,8 @@ _pickUnpackers(
ImagingCodecState state, ImagingCodecState state,
TIFF *tiff, TIFF *tiff,
uint16_t planarconfig, uint16_t planarconfig,
ImagingShuffler *unpackers) { ImagingShuffler *unpackers)
{
// if number of bands is 1, there is no difference with contig case // if number of bands is 1, there is no difference with contig case
if (planarconfig == PLANARCONFIG_SEPARATE && im->bands > 1) { if (planarconfig == PLANARCONFIG_SEPARATE && im->bands > 1) {
uint16_t bits_per_sample = 8; uint16_t bits_per_sample = 8;
@ -259,7 +270,8 @@ _pickUnpackers(
} }
int int
_decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) { _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff)
{
// To avoid dealing with YCbCr subsampling and other complications, let libtiff // To avoid dealing with YCbCr subsampling and other complications, let libtiff
// handle it Use a TIFFRGBAImage wrapping the tiff image, and let libtiff handle all // handle it Use a TIFFRGBAImage wrapping the tiff image, and let libtiff handle all
// of the conversion. Metadata read from the TIFFRGBAImage could be different from // of the conversion. Metadata read from the TIFFRGBAImage could be different from
@ -374,7 +386,8 @@ _decodeTile(
ImagingCodecState state, ImagingCodecState state,
TIFF *tiff, TIFF *tiff,
int planes, int planes,
ImagingShuffler *unpackers) { ImagingShuffler *unpackers)
{
INT32 x, y, tile_y, current_tile_length, current_tile_width; INT32 x, y, tile_y, current_tile_length, current_tile_width;
UINT32 tile_width, tile_length; UINT32 tile_width, tile_length;
tsize_t tile_bytes_size, row_byte_size; tsize_t tile_bytes_size, row_byte_size;
@ -477,7 +490,8 @@ _decodeStrip(
ImagingCodecState state, ImagingCodecState state,
TIFF *tiff, TIFF *tiff,
int planes, int planes,
ImagingShuffler *unpackers) { ImagingShuffler *unpackers)
{
INT32 strip_row = 0; INT32 strip_row = 0;
UINT8 *new_data; UINT8 *new_data;
UINT32 rows_per_strip; UINT32 rows_per_strip;
@ -577,7 +591,8 @@ _decodeStrip(
int int
ImagingLibTiffDecode( ImagingLibTiffDecode(
Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes) { Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes)
{
TIFFSTATE *clientstate = (TIFFSTATE *)state->context; TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
char *filename = "tempfile.tif"; char *filename = "tempfile.tif";
char *mode = "rC"; char *mode = "rC";
@ -773,7 +788,8 @@ decode_err:
} }
int int
ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp) { ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp)
{
// Open the FD or the pointer as a tiff file, for writing. // Open the FD or the pointer as a tiff file, for writing.
// We may have to do some monkeying around to make this really work. // We may have to do some monkeying around to make this really work.
// If we have a fp, then we're good. // If we have a fp, then we're good.
@ -852,7 +868,8 @@ ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp) {
int int
ImagingLibTiffMergeFieldInfo( ImagingLibTiffMergeFieldInfo(
ImagingCodecState state, TIFFDataType field_type, int key, int is_var_length) { ImagingCodecState state, TIFFDataType field_type, int key, int is_var_length)
{
// Refer to libtiff docs (http://www.simplesystems.org/libtiff/addingtags.html) // Refer to libtiff docs (http://www.simplesystems.org/libtiff/addingtags.html)
TIFFSTATE *clientstate = (TIFFSTATE *)state->context; TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
uint32_t n; uint32_t n;
@ -889,7 +906,8 @@ ImagingLibTiffMergeFieldInfo(
} }
int int
ImagingLibTiffSetField(ImagingCodecState state, ttag_t tag, ...) { ImagingLibTiffSetField(ImagingCodecState state, ttag_t tag, ...)
{
// after tif_dir.c->TIFFSetField. // after tif_dir.c->TIFFSetField.
TIFFSTATE *clientstate = (TIFFSTATE *)state->context; TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
va_list ap; va_list ap;
@ -902,7 +920,8 @@ ImagingLibTiffSetField(ImagingCodecState state, ttag_t tag, ...) {
} }
int int
ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes) { ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes)
{
/* One shot encoder. Encode everything to the tiff in the clientstate. /* One shot encoder. Encode everything to the tiff in the clientstate.
If we're running off of a FD, then run once, we're good, everything If we're running off of a FD, then run once, we're good, everything
ends up in the file, we close and we're done. ends up in the file, we close and we're done.
@ -1027,7 +1046,8 @@ ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int byt
} }
const char * const char *
ImagingTiffVersion(void) { ImagingTiffVersion(void)
{
return TIFFGetVersion(); return TIFFGetVersion();
} }

View File

@ -109,7 +109,8 @@ static UINT8 BITFLIP[] = {
/* Unpack to "1" image */ /* Unpack to "1" image */
static void static void
unpack1(UINT8 *out, const UINT8 *in, int pixels) { unpack1(UINT8 *out, const UINT8 *in, int pixels)
{
/* bits (msb first, white is non-zero) */ /* bits (msb first, white is non-zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -143,7 +144,8 @@ unpack1(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpack1I(UINT8 *out, const UINT8 *in, int pixels) { unpack1I(UINT8 *out, const UINT8 *in, int pixels)
{
/* bits (msb first, white is zero) */ /* bits (msb first, white is zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -177,7 +179,8 @@ unpack1I(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpack1R(UINT8 *out, const UINT8 *in, int pixels) { unpack1R(UINT8 *out, const UINT8 *in, int pixels)
{
/* bits (lsb first, white is non-zero) */ /* bits (lsb first, white is non-zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -211,7 +214,8 @@ unpack1R(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpack1IR(UINT8 *out, const UINT8 *in, int pixels) { unpack1IR(UINT8 *out, const UINT8 *in, int pixels)
{
/* bits (lsb first, white is zero) */ /* bits (lsb first, white is zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -245,7 +249,8 @@ unpack1IR(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpack18(UINT8 *out, const UINT8 *in, int pixels) { unpack18(UINT8 *out, const UINT8 *in, int pixels)
{
/* Unpack a '|b1' image, which is a numpy boolean. /* Unpack a '|b1' image, which is a numpy boolean.
1 == true, 0==false, in bytes */ 1 == true, 0==false, in bytes */
@ -258,7 +263,8 @@ unpack18(UINT8 *out, const UINT8 *in, int pixels) {
/* Unpack to "L" image */ /* Unpack to "L" image */
static void static void
unpackL2(UINT8 *out, const UINT8 *in, int pixels) { unpackL2(UINT8 *out, const UINT8 *in, int pixels)
{
/* nibbles (msb first, white is non-zero) */ /* nibbles (msb first, white is non-zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -280,7 +286,8 @@ unpackL2(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackL2I(UINT8 *out, const UINT8 *in, int pixels) { unpackL2I(UINT8 *out, const UINT8 *in, int pixels)
{
/* nibbles (msb first, white is zero) */ /* nibbles (msb first, white is zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -302,7 +309,8 @@ unpackL2I(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackL2R(UINT8 *out, const UINT8 *in, int pixels) { unpackL2R(UINT8 *out, const UINT8 *in, int pixels)
{
/* nibbles (bit order reversed, white is non-zero) */ /* nibbles (bit order reversed, white is non-zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -325,7 +333,8 @@ unpackL2R(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackL2IR(UINT8 *out, const UINT8 *in, int pixels) { unpackL2IR(UINT8 *out, const UINT8 *in, int pixels)
{
/* nibbles (bit order reversed, white is zero) */ /* nibbles (bit order reversed, white is zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -348,7 +357,8 @@ unpackL2IR(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackL4(UINT8 *out, const UINT8 *in, int pixels) { unpackL4(UINT8 *out, const UINT8 *in, int pixels)
{
/* nibbles (msb first, white is non-zero) */ /* nibbles (msb first, white is non-zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -364,7 +374,8 @@ unpackL4(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackL4I(UINT8 *out, const UINT8 *in, int pixels) { unpackL4I(UINT8 *out, const UINT8 *in, int pixels)
{
/* nibbles (msb first, white is zero) */ /* nibbles (msb first, white is zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -380,7 +391,8 @@ unpackL4I(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackL4R(UINT8 *out, const UINT8 *in, int pixels) { unpackL4R(UINT8 *out, const UINT8 *in, int pixels)
{
/* nibbles (bit order reversed, white is non-zero) */ /* nibbles (bit order reversed, white is non-zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -397,7 +409,8 @@ unpackL4R(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackL4IR(UINT8 *out, const UINT8 *in, int pixels) { unpackL4IR(UINT8 *out, const UINT8 *in, int pixels)
{
/* nibbles (bit order reversed, white is zero) */ /* nibbles (bit order reversed, white is zero) */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -414,7 +427,8 @@ unpackL4IR(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackLA(UINT8 *_out, const UINT8 *in, int pixels) { unpackLA(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* LA, pixel interleaved */ /* LA, pixel interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -426,7 +440,8 @@ unpackLA(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackLAL(UINT8 *_out, const UINT8 *in, int pixels) { unpackLAL(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* LA, line interleaved */ /* LA, line interleaved */
for (i = 0; i < pixels; i++, _out += 4) { for (i = 0; i < pixels; i++, _out += 4) {
@ -436,7 +451,8 @@ unpackLAL(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackLI(UINT8 *out, const UINT8 *in, int pixels) { unpackLI(UINT8 *out, const UINT8 *in, int pixels)
{
/* negative */ /* negative */
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -445,7 +461,8 @@ unpackLI(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackLR(UINT8 *out, const UINT8 *in, int pixels) { unpackLR(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGB, bit reversed */ /* RGB, bit reversed */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -454,7 +471,8 @@ unpackLR(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackL16(UINT8 *out, const UINT8 *in, int pixels) { unpackL16(UINT8 *out, const UINT8 *in, int pixels)
{
/* int16 (upper byte, little endian) */ /* int16 (upper byte, little endian) */
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -464,7 +482,8 @@ unpackL16(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackL16B(UINT8 *out, const UINT8 *in, int pixels) { unpackL16B(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* int16 (upper byte, big endian) */ /* int16 (upper byte, big endian) */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -476,7 +495,8 @@ unpackL16B(UINT8 *out, const UINT8 *in, int pixels) {
/* Unpack to "P" image */ /* Unpack to "P" image */
static void static void
unpackP1(UINT8 *out, const UINT8 *in, int pixels) { unpackP1(UINT8 *out, const UINT8 *in, int pixels)
{
/* bits */ /* bits */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -510,7 +530,8 @@ unpackP1(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackP2(UINT8 *out, const UINT8 *in, int pixels) { unpackP2(UINT8 *out, const UINT8 *in, int pixels)
{
/* bit pairs */ /* bit pairs */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -532,7 +553,8 @@ unpackP2(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackP4(UINT8 *out, const UINT8 *in, int pixels) { unpackP4(UINT8 *out, const UINT8 *in, int pixels)
{
/* nibbles */ /* nibbles */
while (pixels > 0) { while (pixels > 0) {
UINT8 byte = *in++; UINT8 byte = *in++;
@ -548,7 +570,8 @@ unpackP4(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackP2L(UINT8 *out, const UINT8 *in, int pixels) { unpackP2L(UINT8 *out, const UINT8 *in, int pixels)
{
int i, j, m, s; int i, j, m, s;
/* bit layers */ /* bit layers */
m = 128; m = 128;
@ -563,7 +586,8 @@ unpackP2L(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackP4L(UINT8 *out, const UINT8 *in, int pixels) { unpackP4L(UINT8 *out, const UINT8 *in, int pixels)
{
int i, j, m, s; int i, j, m, s;
/* bit layers (trust the optimizer ;-) */ /* bit layers (trust the optimizer ;-) */
m = 128; m = 128;
@ -581,7 +605,8 @@ unpackP4L(UINT8 *out, const UINT8 *in, int pixels) {
/* Unpack to "RGB" image */ /* Unpack to "RGB" image */
void void
ImagingUnpackRGB(UINT8 *_out, const UINT8 *in, int pixels) { ImagingUnpackRGB(UINT8 *_out, const UINT8 *in, int pixels)
{
int i = 0; int i = 0;
/* RGB triplets */ /* RGB triplets */
for (; i < pixels - 1; i++) { for (; i < pixels - 1; i++) {
@ -601,7 +626,8 @@ ImagingUnpackRGB(UINT8 *_out, const UINT8 *in, int pixels) {
} }
void void
unpackRGB16L(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGB16L(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* 16-bit RGB triplets, little-endian order */ /* 16-bit RGB triplets, little-endian order */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -613,7 +639,8 @@ unpackRGB16L(UINT8 *_out, const UINT8 *in, int pixels) {
} }
void void
unpackRGB16B(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGB16B(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* 16-bit RGB triplets, big-endian order */ /* 16-bit RGB triplets, big-endian order */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -625,7 +652,8 @@ unpackRGB16B(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBL(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBL(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGB, line interleaved */ /* RGB, line interleaved */
for (i = 0; i < pixels; i++, _out += 4) { for (i = 0; i < pixels; i++, _out += 4) {
@ -635,7 +663,8 @@ unpackRGBL(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBR(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBR(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGB, bit reversed */ /* RGB, bit reversed */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -647,7 +676,8 @@ unpackRGBR(UINT8 *_out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackBGR(UINT8 *_out, const UINT8 *in, int pixels) { ImagingUnpackBGR(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGB, reversed bytes */ /* RGB, reversed bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -659,7 +689,8 @@ ImagingUnpackBGR(UINT8 *_out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackRGB15(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackRGB15(UINT8 *out, const UINT8 *in, int pixels)
{
int i, pixel; int i, pixel;
/* RGB, 5 bits per pixel */ /* RGB, 5 bits per pixel */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -674,7 +705,8 @@ ImagingUnpackRGB15(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackRGBA15(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackRGBA15(UINT8 *out, const UINT8 *in, int pixels)
{
int i, pixel; int i, pixel;
/* RGB, 5/5/5/1 bits per pixel */ /* RGB, 5/5/5/1 bits per pixel */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -689,7 +721,8 @@ ImagingUnpackRGBA15(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackBGR15(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackBGR15(UINT8 *out, const UINT8 *in, int pixels)
{
int i, pixel; int i, pixel;
/* RGB, reversed bytes, 5 bits per pixel */ /* RGB, reversed bytes, 5 bits per pixel */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -704,7 +737,8 @@ ImagingUnpackBGR15(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackBGRA15(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackBGRA15(UINT8 *out, const UINT8 *in, int pixels)
{
int i, pixel; int i, pixel;
/* RGB, rearranged channels, 5/5/5/1 bits per pixel */ /* RGB, rearranged channels, 5/5/5/1 bits per pixel */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -719,7 +753,8 @@ ImagingUnpackBGRA15(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackBGRA15Z(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackBGRA15Z(UINT8 *out, const UINT8 *in, int pixels)
{
int i, pixel; int i, pixel;
/* RGB, rearranged channels, 5/5/5/1 bits per pixel, inverted alpha */ /* RGB, rearranged channels, 5/5/5/1 bits per pixel, inverted alpha */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -734,7 +769,8 @@ ImagingUnpackBGRA15Z(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackRGB16(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackRGB16(UINT8 *out, const UINT8 *in, int pixels)
{
int i, pixel; int i, pixel;
/* RGB, 5/6/5 bits per pixel */ /* RGB, 5/6/5 bits per pixel */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -749,7 +785,8 @@ ImagingUnpackRGB16(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackBGR16(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackBGR16(UINT8 *out, const UINT8 *in, int pixels)
{
int i, pixel; int i, pixel;
/* RGB, reversed bytes, 5/6/5 bits per pixel */ /* RGB, reversed bytes, 5/6/5 bits per pixel */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -764,7 +801,8 @@ ImagingUnpackBGR16(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackRGB4B(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackRGB4B(UINT8 *out, const UINT8 *in, int pixels)
{
int i, pixel; int i, pixel;
/* RGB, 4 bits per pixel */ /* RGB, 4 bits per pixel */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -779,7 +817,8 @@ ImagingUnpackRGB4B(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackRGBA4B(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackRGBA4B(UINT8 *out, const UINT8 *in, int pixels)
{
int i, pixel; int i, pixel;
/* RGBA, 4 bits per pixel */ /* RGBA, 4 bits per pixel */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -794,7 +833,8 @@ ImagingUnpackRGBA4B(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
ImagingUnpackBGRX(UINT8 *_out, const UINT8 *in, int pixels) { ImagingUnpackBGRX(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGB, reversed bytes with padding */ /* RGB, reversed bytes with padding */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -806,7 +846,8 @@ ImagingUnpackBGRX(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
ImagingUnpackBGXR(UINT8 *_out, const UINT8 *in, int pixels) { ImagingUnpackBGXR(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
UINT32 iv = MAKE_UINT32(in[3], in[1], in[0], 255); UINT32 iv = MAKE_UINT32(in[3], in[1], in[0], 255);
@ -817,7 +858,8 @@ ImagingUnpackBGXR(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
ImagingUnpackXRGB(UINT8 *_out, const UINT8 *in, int pixels) { ImagingUnpackXRGB(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGB, leading pad */ /* RGB, leading pad */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -829,7 +871,8 @@ ImagingUnpackXRGB(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
ImagingUnpackXBGR(UINT8 *_out, const UINT8 *in, int pixels) { ImagingUnpackXBGR(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGB, reversed bytes, leading pad */ /* RGB, reversed bytes, leading pad */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -843,7 +886,8 @@ ImagingUnpackXBGR(UINT8 *_out, const UINT8 *in, int pixels) {
/* Unpack to "RGBA" image */ /* Unpack to "RGBA" image */
static void static void
unpackRGBALA(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBALA(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* grayscale with alpha */ /* grayscale with alpha */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -855,7 +899,8 @@ unpackRGBALA(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBALA16B(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBALA16B(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* 16-bit grayscale with alpha, big-endian */ /* 16-bit grayscale with alpha, big-endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -867,7 +912,8 @@ unpackRGBALA16B(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBa16L(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBa16L(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* premultiplied 16-bit RGBA, little-endian */ /* premultiplied 16-bit RGBA, little-endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -891,7 +937,8 @@ unpackRGBa16L(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBa16B(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBa16B(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* premultiplied 16-bit RGBA, big-endian */ /* premultiplied 16-bit RGBA, big-endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -915,7 +962,8 @@ unpackRGBa16B(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBa(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBa(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* premultiplied RGBA */ /* premultiplied RGBA */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -939,7 +987,8 @@ unpackRGBa(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBaskip1(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBaskip1(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
UINT32 *out = (UINT32 *)_out; UINT32 *out = (UINT32 *)_out;
/* premultiplied RGBA */ /* premultiplied RGBA */
@ -961,7 +1010,8 @@ unpackRGBaskip1(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBaskip2(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBaskip2(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
UINT32 *out = (UINT32 *)_out; UINT32 *out = (UINT32 *)_out;
/* premultiplied RGBA */ /* premultiplied RGBA */
@ -983,7 +1033,8 @@ unpackRGBaskip2(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackBGRa(UINT8 *_out, const UINT8 *in, int pixels) { unpackBGRa(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* premultiplied BGRA */ /* premultiplied BGRA */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1007,7 +1058,8 @@ unpackBGRa(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBAI(UINT8 *out, const UINT8 *in, int pixels) { unpackRGBAI(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGBA, inverted RGB bytes (FlashPix) */ /* RGBA, inverted RGB bytes (FlashPix) */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1021,7 +1073,8 @@ unpackRGBAI(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackRGBAL(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBAL(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGBA, line interleaved */ /* RGBA, line interleaved */
for (i = 0; i < pixels; i++, _out += 4) { for (i = 0; i < pixels; i++, _out += 4) {
@ -1035,7 +1088,8 @@ unpackRGBAL(UINT8 *_out, const UINT8 *in, int pixels) {
} }
void void
unpackRGBA16L(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBA16L(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* 16-bit RGBA, little-endian order */ /* 16-bit RGBA, little-endian order */
for (i = 0; i < pixels; i++, _out += 4) { for (i = 0; i < pixels; i++, _out += 4) {
@ -1046,7 +1100,8 @@ unpackRGBA16L(UINT8 *_out, const UINT8 *in, int pixels) {
} }
void void
unpackRGBA16B(UINT8 *_out, const UINT8 *in, int pixels) { unpackRGBA16B(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* 16-bit RGBA, big-endian order */ /* 16-bit RGBA, big-endian order */
for (i = 0; i < pixels; i++, _out += 4) { for (i = 0; i < pixels; i++, _out += 4) {
@ -1057,7 +1112,8 @@ unpackRGBA16B(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackARGB(UINT8 *_out, const UINT8 *in, int pixels) { unpackARGB(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGBA, leading pad */ /* RGBA, leading pad */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1069,7 +1125,8 @@ unpackARGB(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackABGR(UINT8 *_out, const UINT8 *in, int pixels) { unpackABGR(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGBA, reversed bytes */ /* RGBA, reversed bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1081,7 +1138,8 @@ unpackABGR(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackBGRA(UINT8 *_out, const UINT8 *in, int pixels) { unpackBGRA(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* RGBA, rearranged channels */ /* RGBA, rearranged channels */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1093,7 +1151,8 @@ unpackBGRA(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackBGRA16L(UINT8 *_out, const UINT8 *in, int pixels) { unpackBGRA16L(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* 16-bit RGBA, little-endian order, rearranged channels */ /* 16-bit RGBA, little-endian order, rearranged channels */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1105,7 +1164,8 @@ unpackBGRA16L(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackBGRA16B(UINT8 *_out, const UINT8 *in, int pixels) { unpackBGRA16B(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* 16-bit RGBA, big-endian order, rearranged channels */ /* 16-bit RGBA, big-endian order, rearranged channels */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1117,7 +1177,8 @@ unpackBGRA16B(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
unpackBGAR(UINT8 *_out, const UINT8 *in, int pixels) { unpackBGAR(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
UINT32 iv = MAKE_UINT32(in[3], in[1], in[0], in[2]); UINT32 iv = MAKE_UINT32(in[3], in[1], in[0], in[2]);
@ -1130,7 +1191,8 @@ unpackBGAR(UINT8 *_out, const UINT8 *in, int pixels) {
/* Unpack to "CMYK" image */ /* Unpack to "CMYK" image */
static void static void
unpackCMYKI(UINT8 *_out, const UINT8 *in, int pixels) { unpackCMYKI(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
/* CMYK, inverted bytes (Photoshop 2.5) */ /* CMYK, inverted bytes (Photoshop 2.5) */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1153,7 +1215,8 @@ unpackCMYKI(UINT8 *_out, const UINT8 *in, int pixels) {
internally, and we'll unshift for saving and whatnot. internally, and we'll unshift for saving and whatnot.
*/ */
void void
ImagingUnpackLAB(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackLAB(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* LAB triplets */ /* LAB triplets */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1167,7 +1230,8 @@ ImagingUnpackLAB(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackI16N_I16B(UINT8 *out, const UINT8 *in, int pixels) { unpackI16N_I16B(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
UINT8 *tmp = (UINT8 *)out; UINT8 *tmp = (UINT8 *)out;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1177,7 +1241,8 @@ unpackI16N_I16B(UINT8 *out, const UINT8 *in, int pixels) {
} }
} }
static void static void
unpackI16N_I16(UINT8 *out, const UINT8 *in, int pixels) { unpackI16N_I16(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
UINT8 *tmp = (UINT8 *)out; UINT8 *tmp = (UINT8 *)out;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1187,7 +1252,8 @@ unpackI16N_I16(UINT8 *out, const UINT8 *in, int pixels) {
} }
} }
static void static void
unpackI16B_I16(UINT8 *out, const UINT8 *in, int pixels) { unpackI16B_I16(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[0] = in[1]; out[0] = in[1];
@ -1197,7 +1263,8 @@ unpackI16B_I16(UINT8 *out, const UINT8 *in, int pixels) {
} }
} }
static void static void
unpackI16R_I16(UINT8 *out, const UINT8 *in, int pixels) { unpackI16R_I16(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[0] = BITFLIP[in[0]]; out[0] = BITFLIP[in[0]];
@ -1208,7 +1275,8 @@ unpackI16R_I16(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
unpackI12_I16(UINT8 *out, const UINT8 *in, int pixels) { unpackI12_I16(UINT8 *out, const UINT8 *in, int pixels)
{
/* Fillorder 1/MSB -> LittleEndian, for 12bit integer grayscale tiffs. /* Fillorder 1/MSB -> LittleEndian, for 12bit integer grayscale tiffs.
According to the TIFF spec: According to the TIFF spec:
@ -1265,31 +1333,36 @@ unpackI12_I16(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
copy1(UINT8 *out, const UINT8 *in, int pixels) { copy1(UINT8 *out, const UINT8 *in, int pixels)
{
/* L, P */ /* L, P */
memcpy(out, in, pixels); memcpy(out, in, pixels);
} }
static void static void
copy2(UINT8 *out, const UINT8 *in, int pixels) { copy2(UINT8 *out, const UINT8 *in, int pixels)
{
/* I;16 */ /* I;16 */
memcpy(out, in, pixels * 2); memcpy(out, in, pixels * 2);
} }
static void static void
copy3(UINT8 *out, const UINT8 *in, int pixels) { copy3(UINT8 *out, const UINT8 *in, int pixels)
{
/* BGR;24 */ /* BGR;24 */
memcpy(out, in, pixels * 3); memcpy(out, in, pixels * 3);
} }
static void static void
copy4(UINT8 *out, const UINT8 *in, int pixels) { copy4(UINT8 *out, const UINT8 *in, int pixels)
{
/* RGBA, CMYK quadruples */ /* RGBA, CMYK quadruples */
memcpy(out, in, 4 * pixels); memcpy(out, in, 4 * pixels);
} }
static void static void
copy4skip1(UINT8 *_out, const UINT8 *in, int pixels) { copy4skip1(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
memcpy(_out, in, 4); memcpy(_out, in, 4);
@ -1299,7 +1372,8 @@ copy4skip1(UINT8 *_out, const UINT8 *in, int pixels) {
} }
static void static void
copy4skip2(UINT8 *_out, const UINT8 *in, int pixels) { copy4skip2(UINT8 *_out, const UINT8 *in, int pixels)
{
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
memcpy(_out, in, 4); memcpy(_out, in, 4);
@ -1311,7 +1385,8 @@ copy4skip2(UINT8 *_out, const UINT8 *in, int pixels) {
/* Unpack to "I" and "F" images */ /* Unpack to "I" and "F" images */
#define UNPACK_RAW(NAME, GET, INTYPE, OUTTYPE) \ #define UNPACK_RAW(NAME, GET, INTYPE, OUTTYPE) \
static void NAME(UINT8 *out_, const UINT8 *in, int pixels) { \ static void NAME(UINT8 *out_, const UINT8 *in, int pixels) \
{ \
int i; \ int i; \
OUTTYPE *out = (OUTTYPE *)out_; \ OUTTYPE *out = (OUTTYPE *)out_; \
for (i = 0; i < pixels; i++, in += sizeof(INTYPE)) { \ for (i = 0; i < pixels; i++, in += sizeof(INTYPE)) { \
@ -1320,7 +1395,8 @@ copy4skip2(UINT8 *_out, const UINT8 *in, int pixels) {
} }
#define UNPACK(NAME, COPY, INTYPE, OUTTYPE) \ #define UNPACK(NAME, COPY, INTYPE, OUTTYPE) \
static void NAME(UINT8 *out_, const UINT8 *in, int pixels) { \ static void NAME(UINT8 *out_, const UINT8 *in, int pixels) \
{ \
int i; \ int i; \
OUTTYPE *out = (OUTTYPE *)out_; \ OUTTYPE *out = (OUTTYPE *)out_; \
INTYPE tmp_; \ INTYPE tmp_; \
@ -1372,7 +1448,8 @@ UNPACK(unpackF64NF, C64N, FLOAT64, FLOAT32)
/* Misc. unpackers */ /* Misc. unpackers */
static void static void
band0(UINT8 *out, const UINT8 *in, int pixels) { band0(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 0 only */ /* band 0 only */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1382,7 +1459,8 @@ band0(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band1(UINT8 *out, const UINT8 *in, int pixels) { band1(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 1 only */ /* band 1 only */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1392,7 +1470,8 @@ band1(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band2(UINT8 *out, const UINT8 *in, int pixels) { band2(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 2 only */ /* band 2 only */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1402,7 +1481,8 @@ band2(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band3(UINT8 *out, const UINT8 *in, int pixels) { band3(UINT8 *out, const UINT8 *in, int pixels)
{
/* band 3 only */ /* band 3 only */
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1412,7 +1492,8 @@ band3(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band0I(UINT8 *out, const UINT8 *in, int pixels) { band0I(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 0 only */ /* band 0 only */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1422,7 +1503,8 @@ band0I(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band1I(UINT8 *out, const UINT8 *in, int pixels) { band1I(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 1 only */ /* band 1 only */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1432,7 +1514,8 @@ band1I(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band2I(UINT8 *out, const UINT8 *in, int pixels) { band2I(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 2 only */ /* band 2 only */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1442,7 +1525,8 @@ band2I(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band3I(UINT8 *out, const UINT8 *in, int pixels) { band3I(UINT8 *out, const UINT8 *in, int pixels)
{
/* band 3 only */ /* band 3 only */
int i; int i;
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1452,7 +1536,8 @@ band3I(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band016B(UINT8 *out, const UINT8 *in, int pixels) { band016B(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 0 only, big endian */ /* band 0 only, big endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1463,7 +1548,8 @@ band016B(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band116B(UINT8 *out, const UINT8 *in, int pixels) { band116B(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 1 only, big endian */ /* band 1 only, big endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1474,7 +1560,8 @@ band116B(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band216B(UINT8 *out, const UINT8 *in, int pixels) { band216B(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 2 only, big endian */ /* band 2 only, big endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1485,7 +1572,8 @@ band216B(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band316B(UINT8 *out, const UINT8 *in, int pixels) { band316B(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 3 only, big endian */ /* band 3 only, big endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1496,7 +1584,8 @@ band316B(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band016L(UINT8 *out, const UINT8 *in, int pixels) { band016L(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 0 only, little endian */ /* band 0 only, little endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1507,7 +1596,8 @@ band016L(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band116L(UINT8 *out, const UINT8 *in, int pixels) { band116L(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 1 only, little endian */ /* band 1 only, little endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1518,7 +1608,8 @@ band116L(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band216L(UINT8 *out, const UINT8 *in, int pixels) { band216L(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 2 only, little endian */ /* band 2 only, little endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1529,7 +1620,8 @@ band216L(UINT8 *out, const UINT8 *in, int pixels) {
} }
static void static void
band316L(UINT8 *out, const UINT8 *in, int pixels) { band316L(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* band 3 only, little endian */ /* band 3 only, little endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -1845,7 +1937,8 @@ static struct {
}; };
ImagingShuffler ImagingShuffler
ImagingFindUnpacker(const char *mode, const char *rawmode, int *bits_out) { ImagingFindUnpacker(const char *mode, const char *rawmode, int *bits_out)
{
int i; int i;
/* find a suitable pixel unpacker */ /* find a suitable pixel unpacker */

View File

@ -133,7 +133,8 @@ static INT16 GR[] = {
} }
void void
ImagingUnpackYCC(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackYCC(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* PhotoYCC triplets */ /* PhotoYCC triplets */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
@ -145,7 +146,8 @@ ImagingUnpackYCC(UINT8 *out, const UINT8 *in, int pixels) {
} }
void void
ImagingUnpackYCCA(UINT8 *out, const UINT8 *in, int pixels) { ImagingUnpackYCCA(UINT8 *out, const UINT8 *in, int pixels)
{
int i; int i;
/* PhotoYCC triplets plus premultiplied alpha */ /* PhotoYCC triplets plus premultiplied alpha */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {

View File

@ -11,7 +11,8 @@
typedef UINT8 pixel[4]; typedef UINT8 pixel[4];
static inline UINT8 static inline UINT8
clip8(int in) { clip8(int in)
{
if (in >= 255) { if (in >= 255) {
return 255; return 255;
} }
@ -23,7 +24,8 @@ clip8(int in) {
Imaging Imaging
ImagingUnsharpMask( ImagingUnsharpMask(
Imaging imOut, Imaging imIn, float radius, int percent, int threshold) { Imaging imOut, Imaging imIn, float radius, int percent, int threshold)
{
ImagingSectionCookie cookie; ImagingSectionCookie cookie;
Imaging result; Imaging result;

View File

@ -22,7 +22,8 @@
: 0) : 0)
int int
ImagingXbmDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingXbmDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
enum { BYTE = 1, SKIP }; enum { BYTE = 1, SKIP };
UINT8 *ptr; UINT8 *ptr;

View File

@ -16,7 +16,8 @@
#include "Imaging.h" #include "Imaging.h"
int int
ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) { ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
{
const char *hex = "0123456789abcdef"; const char *hex = "0123456789abcdef";
UINT8 *ptr = buf; UINT8 *ptr = buf;

View File

@ -30,7 +30,8 @@ static const int ROW_INCREMENT[] = {8, 8, 8, 4, 4, 2, 2};
/* Get the length in bytes of a scanline in the pass specified, /* Get the length in bytes of a scanline in the pass specified,
* for interlaced images */ * for interlaced images */
static int static int
get_row_len(ImagingCodecState state, int pass) { get_row_len(ImagingCodecState state, int pass)
{
int row_len = (state->xsize + OFFSET[pass]) / COL_INCREMENT[pass]; int row_len = (state->xsize + OFFSET[pass]) / COL_INCREMENT[pass];
return ((row_len * state->bits) + 7) / 8; return ((row_len * state->bits) + 7) / 8;
} }
@ -40,7 +41,8 @@ get_row_len(ImagingCodecState state, int pass) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int int
ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) { ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes)
{
ZIPSTATE *context = (ZIPSTATE *)state->context; ZIPSTATE *context = (ZIPSTATE *)state->context;
int err; int err;
int n; int n;
@ -281,7 +283,8 @@ ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
} }
int int
ImagingZipDecodeCleanup(ImagingCodecState state) { ImagingZipDecodeCleanup(ImagingCodecState state)
{
/* called to free the decompression engine when the decode terminates /* called to free the decompression engine when the decode terminates
due to a corrupt or truncated image due to a corrupt or truncated image
*/ */

View File

@ -21,7 +21,8 @@
#include "ZipCodecs.h" #include "ZipCodecs.h"
int int
ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) { ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
{
ZIPSTATE *context = (ZIPSTATE *)state->context; ZIPSTATE *context = (ZIPSTATE *)state->context;
int err; int err;
int compress_level, compress_type; int compress_level, compress_type;
@ -348,7 +349,8 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int int
ImagingZipEncodeCleanup(ImagingCodecState state) { ImagingZipEncodeCleanup(ImagingCodecState state)
{
ZIPSTATE *context = (ZIPSTATE *)state->context; ZIPSTATE *context = (ZIPSTATE *)state->context;
if (context->dictionary) { if (context->dictionary) {
@ -360,7 +362,8 @@ ImagingZipEncodeCleanup(ImagingCodecState state) {
} }
const char * const char *
ImagingZipVersion(void) { ImagingZipVersion(void)
{
return zlibVersion(); return zlibVersion();
} }

View File

@ -2,7 +2,8 @@
#include "Imaging.h" #include "Imaging.h"
Py_ssize_t Py_ssize_t
_imaging_read_pyFd(PyObject *fd, char *dest, Py_ssize_t bytes) { _imaging_read_pyFd(PyObject *fd, char *dest, Py_ssize_t bytes)
{
/* dest should be a buffer bytes long, returns length of read /* dest should be a buffer bytes long, returns length of read
-1 on error */ -1 on error */
@ -33,7 +34,8 @@ err:
} }
Py_ssize_t Py_ssize_t
_imaging_write_pyFd(PyObject *fd, char *src, Py_ssize_t bytes) { _imaging_write_pyFd(PyObject *fd, char *src, Py_ssize_t bytes)
{
PyObject *result; PyObject *result;
PyObject *byteObj; PyObject *byteObj;
@ -47,7 +49,8 @@ _imaging_write_pyFd(PyObject *fd, char *src, Py_ssize_t bytes) {
} }
int int
_imaging_seek_pyFd(PyObject *fd, Py_ssize_t offset, int whence) { _imaging_seek_pyFd(PyObject *fd, Py_ssize_t offset, int whence)
{
PyObject *result; PyObject *result;
result = PyObject_CallMethod(fd, "seek", "ni", offset, whence); result = PyObject_CallMethod(fd, "seek", "ni", offset, whence);
@ -57,7 +60,8 @@ _imaging_seek_pyFd(PyObject *fd, Py_ssize_t offset, int whence) {
} }
Py_ssize_t Py_ssize_t
_imaging_tell_pyFd(PyObject *fd) { _imaging_tell_pyFd(PyObject *fd)
{
PyObject *result; PyObject *result;
Py_ssize_t location; Py_ssize_t location;

View File

@ -41,7 +41,8 @@ typedef struct ImagingBufferInstance {
} ImagingBufferInstance; } ImagingBufferInstance;
static void static void
mapping_destroy_buffer(Imaging im) { mapping_destroy_buffer(Imaging im)
{
ImagingBufferInstance *buffer = (ImagingBufferInstance *)im; ImagingBufferInstance *buffer = (ImagingBufferInstance *)im;
PyBuffer_Release(&buffer->view); PyBuffer_Release(&buffer->view);
@ -49,7 +50,8 @@ mapping_destroy_buffer(Imaging im) {
} }
PyObject * PyObject *
PyImaging_MapBuffer(PyObject *self, PyObject *args) { PyImaging_MapBuffer(PyObject *self, PyObject *args)
{
Py_ssize_t y, size; Py_ssize_t y, size;
Imaging im; Imaging im;

View File

@ -33,7 +33,8 @@ static PyTypeObject OutlineType;
#define PyOutline_Check(op) (Py_TYPE(op) == &OutlineType) #define PyOutline_Check(op) (Py_TYPE(op) == &OutlineType)
static OutlineObject * static OutlineObject *
_outline_new(void) { _outline_new(void)
{
OutlineObject *self; OutlineObject *self;
if (PyType_Ready(&OutlineType) < 0) { if (PyType_Ready(&OutlineType) < 0) {
@ -51,13 +52,15 @@ _outline_new(void) {
} }
static void static void
_outline_dealloc(OutlineObject *self) { _outline_dealloc(OutlineObject *self)
{
ImagingOutlineDelete(self->outline); ImagingOutlineDelete(self->outline);
PyObject_Del(self); PyObject_Del(self);
} }
ImagingOutline ImagingOutline
PyOutline_AsOutline(PyObject *outline) { PyOutline_AsOutline(PyObject *outline)
{
if (PyOutline_Check(outline)) { if (PyOutline_Check(outline)) {
return ((OutlineObject *)outline)->outline; return ((OutlineObject *)outline)->outline;
} }
@ -69,7 +72,8 @@ PyOutline_AsOutline(PyObject *outline) {
/* Factories */ /* Factories */
PyObject * PyObject *
PyOutline_Create(PyObject *self, PyObject *args) { PyOutline_Create(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":outline")) { if (!PyArg_ParseTuple(args, ":outline")) {
return NULL; return NULL;
} }
@ -81,7 +85,8 @@ PyOutline_Create(PyObject *self, PyObject *args) {
/* Methods */ /* Methods */
static PyObject * static PyObject *
_outline_move(OutlineObject *self, PyObject *args) { _outline_move(OutlineObject *self, PyObject *args)
{
float x0, y0; float x0, y0;
if (!PyArg_ParseTuple(args, "ff", &x0, &y0)) { if (!PyArg_ParseTuple(args, "ff", &x0, &y0)) {
return NULL; return NULL;
@ -94,7 +99,8 @@ _outline_move(OutlineObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
_outline_line(OutlineObject *self, PyObject *args) { _outline_line(OutlineObject *self, PyObject *args)
{
float x1, y1; float x1, y1;
if (!PyArg_ParseTuple(args, "ff", &x1, &y1)) { if (!PyArg_ParseTuple(args, "ff", &x1, &y1)) {
return NULL; return NULL;
@ -107,7 +113,8 @@ _outline_line(OutlineObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
_outline_curve(OutlineObject *self, PyObject *args) { _outline_curve(OutlineObject *self, PyObject *args)
{
float x1, y1, x2, y2, x3, y3; float x1, y1, x2, y2, x3, y3;
if (!PyArg_ParseTuple(args, "ffffff", &x1, &y1, &x2, &y2, &x3, &y3)) { if (!PyArg_ParseTuple(args, "ffffff", &x1, &y1, &x2, &y2, &x3, &y3)) {
return NULL; return NULL;
@ -120,7 +127,8 @@ _outline_curve(OutlineObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
_outline_close(OutlineObject *self, PyObject *args) { _outline_close(OutlineObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":close")) { if (!PyArg_ParseTuple(args, ":close")) {
return NULL; return NULL;
} }
@ -132,7 +140,8 @@ _outline_close(OutlineObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
_outline_transform(OutlineObject *self, PyObject *args) { _outline_transform(OutlineObject *self, PyObject *args)
{
double a[6]; double a[6];
if (!PyArg_ParseTuple(args, "(dddddd)", a + 0, a + 1, a + 2, a + 3, a + 4, a + 5)) { if (!PyArg_ParseTuple(args, "(dddddd)", a + 0, a + 1, a + 2, a + 3, a + 4, a + 5)) {
return NULL; return NULL;

View File

@ -49,7 +49,8 @@ typedef struct {
static PyTypeObject PyPathType; static PyTypeObject PyPathType;
static double * static double *
alloc_array(Py_ssize_t count) { alloc_array(Py_ssize_t count)
{
double *xy; double *xy;
if (count < 0) { if (count < 0) {
return ImagingError_MemoryError(); return ImagingError_MemoryError();
@ -65,7 +66,8 @@ alloc_array(Py_ssize_t count) {
} }
static PyPathObject * static PyPathObject *
path_new(Py_ssize_t count, double *xy, int duplicate) { path_new(Py_ssize_t count, double *xy, int duplicate)
{
PyPathObject *path; PyPathObject *path;
if (duplicate) { if (duplicate) {
@ -96,7 +98,8 @@ path_new(Py_ssize_t count, double *xy, int duplicate) {
} }
static void static void
path_dealloc(PyPathObject *path) { path_dealloc(PyPathObject *path)
{
free(path->xy); free(path->xy);
PyObject_Del(path); PyObject_Del(path);
} }
@ -108,7 +111,8 @@ path_dealloc(PyPathObject *path) {
#define PyPath_Check(op) (Py_TYPE(op) == &PyPathType) #define PyPath_Check(op) (Py_TYPE(op) == &PyPathType)
Py_ssize_t Py_ssize_t
PyPath_Flatten(PyObject *data, double **pxy) { PyPath_Flatten(PyObject *data, double **pxy)
{
Py_ssize_t i, j, n; Py_ssize_t i, j, n;
double *xy; double *xy;
@ -228,7 +232,8 @@ PyPath_Flatten(PyObject *data, double **pxy) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
PyObject * PyObject *
PyPath_Create(PyObject *self, PyObject *args) { PyPath_Create(PyObject *self, PyObject *args)
{
PyObject *data; PyObject *data;
Py_ssize_t count; Py_ssize_t count;
double *xy; double *xy;
@ -261,7 +266,8 @@ PyPath_Create(PyObject *self, PyObject *args) {
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
static PyObject * static PyObject *
path_compact(PyPathObject *self, PyObject *args) { path_compact(PyPathObject *self, PyObject *args)
{
/* Simple-minded method to shorten path. A point is removed if /* Simple-minded method to shorten path. A point is removed if
the city block distance to the previous point is less than the the city block distance to the previous point is less than the
given distance */ given distance */
@ -297,7 +303,8 @@ path_compact(PyPathObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
path_getbbox(PyPathObject *self, PyObject *args) { path_getbbox(PyPathObject *self, PyObject *args)
{
/* Find bounding box */ /* Find bounding box */
Py_ssize_t i; Py_ssize_t i;
double *xy; double *xy;
@ -336,7 +343,8 @@ path_getbbox(PyPathObject *self, PyObject *args) {
} }
static PyObject * static PyObject *
path_getitem(PyPathObject *self, Py_ssize_t i) { path_getitem(PyPathObject *self, Py_ssize_t i)
{
if (i < 0) { if (i < 0) {
i = self->count + i; i = self->count + i;
} }
@ -349,7 +357,8 @@ path_getitem(PyPathObject *self, Py_ssize_t i) {
} }
static PyObject * static PyObject *
path_getslice(PyPathObject *self, Py_ssize_t ilow, Py_ssize_t ihigh) { path_getslice(PyPathObject *self, Py_ssize_t ilow, Py_ssize_t ihigh)
{
/* adjust arguments */ /* adjust arguments */
if (ilow < 0) { if (ilow < 0) {
ilow = 0; ilow = 0;
@ -369,12 +378,14 @@ path_getslice(PyPathObject *self, Py_ssize_t ilow, Py_ssize_t ihigh) {
} }
static Py_ssize_t static Py_ssize_t
path_len(PyPathObject *self) { path_len(PyPathObject *self)
{
return self->count; return self->count;
} }
static PyObject * static PyObject *
path_map(PyPathObject *self, PyObject *args) { path_map(PyPathObject *self, PyObject *args)
{
/* Map coordinate set through function */ /* Map coordinate set through function */
Py_ssize_t i; Py_ssize_t i;
double *xy; double *xy;
@ -405,7 +416,8 @@ path_map(PyPathObject *self, PyObject *args) {
} }
static int static int
path_setitem(PyPathObject *self, Py_ssize_t i, PyObject *op) { path_setitem(PyPathObject *self, Py_ssize_t i, PyObject *op)
{
double *xy; double *xy;
if (i < 0 || i >= self->count) { if (i < 0 || i >= self->count) {
@ -428,7 +440,8 @@ path_setitem(PyPathObject *self, Py_ssize_t i, PyObject *op) {
} }
static PyObject * static PyObject *
path_tolist(PyPathObject *self, PyObject *args) { path_tolist(PyPathObject *self, PyObject *args)
{
PyObject *list; PyObject *list;
Py_ssize_t i; Py_ssize_t i;
@ -473,7 +486,8 @@ error:
} }
static PyObject * static PyObject *
path_transform(PyPathObject *self, PyObject *args) { path_transform(PyPathObject *self, PyObject *args)
{
/* Apply affine transform to coordinate set */ /* Apply affine transform to coordinate set */
Py_ssize_t i; Py_ssize_t i;
double *xy; double *xy;
@ -526,14 +540,16 @@ static struct PyMethodDef methods[] = {
}; };
static PyObject * static PyObject *
path_getattr_id(PyPathObject *self, void *closure) { path_getattr_id(PyPathObject *self, void *closure)
{
return Py_BuildValue("n", (Py_ssize_t)self->xy); return Py_BuildValue("n", (Py_ssize_t)self->xy);
} }
static struct PyGetSetDef getsetters[] = {{"id", (getter)path_getattr_id}, {NULL}}; static struct PyGetSetDef getsetters[] = {{"id", (getter)path_getattr_id}, {NULL}};
static PyObject * static PyObject *
path_subscript(PyPathObject *self, PyObject *item) { path_subscript(PyPathObject *self, PyObject *item)
{
if (PyIndex_Check(item)) { if (PyIndex_Check(item)) {
Py_ssize_t i; Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError); i = PyNumber_AsSsize_t(item, PyExc_IndexError);