Commit 16bb3112 authored by Matias Guijarro's avatar Matias Guijarro
Browse files

new setup.py

parent 713b205c
%Module pixmaptools 0
%Import qt/qtmod.sip
%ModuleHeaderCode
extern "C" { void pixmap_import_array();}
%End
%PostInitialisationCode
pixmap_import_array();
%End
%Doc
<h1>Class IO</h1>
<p>
This class was copied from KPixmapIO and just rename IO
</p>
%End
class IO
{
%TypeHeaderCode
#include <pixmaptools_io.h>
%End
public:
IO();
~IO();
/**
* Convert an image to a pixmap.
* @param image The image to convert.
* @return The pixmap containing the image.
*/
QPixmap convertToPixmap(const QImage&);
/**
* Convert a pixmap to an image.
* @param pixmap The pixmap to convert.
* @return The image.
*/
QImage convertToImage(const QPixmap&);
/**
* Bitblt an image onto a pixmap.
* @param dst The destination pixmap.
* @param dx Destination x offset.
* @param dy Destination y offset.
* @param src The image to load.
*/
void putImage(QPixmap*,int,int,const QImage *);
/**
* This function is identical to the one above. It only differs in the
* arguments it accepts.
*/
void putImage(QPixmap*,const QPoint &,const QImage *);
/**
* Transfer (a part of) a pixmap to an image.
* @param src The source pixmap.
* @param sx Source x offset.
* @param sy Source y offset.
* @param sw Source width.
* @param sh Source height.
* @return The image.
*/
QImage getImage(const QPixmap*,int,int,int,int);
/**
* This function is identical to the one above. It only differs in the
* arguments it accepts.
*/
QImage getImage(const QPixmap*,const QRect&);
/**
* Shared memory allocation policies.
*/
enum ShmPolicies {
ShmDontKeep,
ShmKeepAndGrow
};
/**
* Set the shared memory allocation policy. See the introduction for
* IO for a discussion.
* @param policy The alloction policy.
*/
void setShmPolicy(int);
/**
* Pre-allocate shared memory. IO will be able to transfer images
* up to this size without resizing.
* @param size The size of the image in @em pixels.
*/
void preAllocShm(int);
};
%Doc
<h1>Class LUT</h1>
<p>
This class is a lookup for colormap
</p>
%End
class LUT
{
%TypeHeaderCode
#include <pixmaptools_lut.h>
%End
public :
enum mapping_meth {LINEAR,LOG,SHIFT_LOG};
public:
class Palette
{
%TypeHeaderCode
#include <pixmaptools_lut.h>
%End
public:
enum palette_type {GREYSCALE,TEMP,RED,GREEN,BLUE,REVERSEGREY,MANY,FIT2D,USER};
enum mode {RGBX,BGRX};
enum endian {LSB,MSB};
explicit Palette(palette_type = USER,mode = RGBX);
%TypeCode
#define PY_ARRAY_UNIQUE_SYMBOL _PixmapNumpyArray
#include "numpy/arrayobject.h"
#include <iostream>
using namespace std;
extern "C"
{
void pixmap_import_array()
{
import_array();
}
}
template<class IN> void _create_palette_from_data(unsigned int *aDestPalette,const IN *aSrcPalette)
{
Py_BEGIN_ALLOW_THREADS;
for(int i = 0;i < 0x10000;++i,++aDestPalette,aSrcPalette += 4)
{
*aDestPalette = aSrcPalette[0] & 0xff;
*aDestPalette |= (aSrcPalette[1] & 0xff) << 8;
*aDestPalette |= (aSrcPalette[2] & 0xff) << 16;
*aDestPalette |= (aSrcPalette[3] & 0xff) << 24;
}
Py_END_ALLOW_THREADS;
}
%End
SIP_PYOBJECT getPaletteData();
%MethodCode
unsigned int *aPaletteDataPt;
int aSize;
Py_BEGIN_ALLOW_THREADS;
sipCpp->getPaletteData(aPaletteDataPt,aSize);
Py_END_ALLOW_THREADS;
sipRes = PyString_FromStringAndSize((const char *)aPaletteDataPt,aSize);
delete aPaletteDataPt;
%End
void setPaletteData(SIP_PYOBJECT);
%MethodCode
PyArrayObject *colormapData;
if(!(colormapData = (PyArrayObject*)PyArray_ContiguousFromObject(a0,NPY_NOTYPE,0,0)))
{
LutError *sipExceptionCopy = new LutError("Couldn't create an array");
sipRaiseTypeException(sipType_LutError,sipExceptionCopy);
return NULL;
}
else
{
int aNbVal = 1;
for(int i = 0;i < colormapData->nd;++i)
aNbVal *= colormapData->dimensions[i];
if(aNbVal != (0x10000 * 4))
{
LutError *sipExceptionCopy = new LutError("Palette must have 65536 entry of RBGX or BGRX");
sipRaiseTypeException(sipType_LutError,sipExceptionCopy);
Py_DECREF(colormapData);
return NULL;
}
unsigned int aTmpPalette[0x10000];
switch(colormapData->descr->type_num)
{
case NPY_BYTE:
case NPY_UBYTE:
_create_palette_from_data(aTmpPalette,(unsigned char*)colormapData->data);break;
case NPY_SHORT:
case NPY_USHORT:
_create_palette_from_data(aTmpPalette,(unsigned short*)colormapData->data);break;
case NPY_INT:
case NPY_UINT:
_create_palette_from_data(aTmpPalette,(unsigned int*)colormapData->data);break;
case NPY_LONG:
case NPY_ULONG:
_create_palette_from_data(aTmpPalette,(unsigned long*)colormapData->data);break;
default:
{
LutError *sipExceptionCopy = new LutError("Palette type can by char,int,long,short");
sipRaiseTypeException(sipType_LutError,sipExceptionCopy);
Py_DECREF(colormapData);
return NULL;
}
}
try
{
sipCpp->setPaletteData(aTmpPalette,sizeof(aTmpPalette));
}
catch(LutError &err)
{
LutError *sipExceptionCopy = new LutError(err);
sipRaiseTypeException(sipType_LutError,sipExceptionCopy);
Py_DECREF(colormapData);
return NULL;
}
Py_DECREF(colormapData);
}
%End
void fillPalette(palette_type) throw();
void fillSegment(int from,int to,
double R1,double G1,double B1,
double R2,double G2,double B2) throw(LutError);
};
%TypeCode
#define PY_ARRAY_UNIQUE_SYMBOL _PixmapNumpyArray
#define NO_IMPORT_ARRAY
#include "numpy/arrayobject.h"
#define MAP_FUNCTION \
PyArrayObject *src; \
if(!(src = (PyArrayObject*)PyArray_ContiguousFromObject(a0,NPY_NOTYPE,2,2))) \
{ \
LutError *sipExceptionCopy = new LutError("Input Array must be a 2x2 array"); \
sipRaiseTypeException(sipType_LutError,sipExceptionCopy); \
return NULL; \
} \
int column,row; \
column = src->dimensions[1]; \
row = src->dimensions[0]; \
PyObject *aRImage;\
switch(src->descr->type_num) \
{ \
case NPY_BYTE: \
{ \
MAP_IMAGE(char); \
sipRes = Py_BuildValue("(O(b,b))",aRImage,aMin,aMax); \
break; \
} \
case NPY_UBYTE: \
{ \
MAP_IMAGE(unsigned char); \
sipRes = Py_BuildValue("(O(B,B))",aRImage,aMin,aMax); \
break; \
} \
case NPY_SHORT: \
{ \
MAP_IMAGE(short); \
sipRes = Py_BuildValue("(O(h,h))",aRImage,aMin,aMax); \
break; \
} \
case NPY_USHORT: \
{ \
MAP_IMAGE(unsigned short); \
sipRes = Py_BuildValue("(O(H,H))",aRImage,aMin,aMax); \
break; \
} \
case NPY_INT: \
{ \
MAP_IMAGE(int); \
sipRes = Py_BuildValue("(O(i,i))",aRImage,aMin,aMax); \
break; \
} \
case NPY_UINT: \
{ \
MAP_IMAGE(unsigned int); \
sipRes = Py_BuildValue("(O(I,I))",aRImage,aMin,aMax); \
break; \
} \
case NPY_LONG: \
{ \
MAP_IMAGE(long); \
sipRes = Py_BuildValue("(O(l,l))",aRImage,aMin,aMax); \
break; \
} \
case NPY_ULONG: \
{ \
MAP_IMAGE(unsigned long); \
sipRes = Py_BuildValue("(O(k,k))",aRImage,aMin,aMax); \
break; \
} \
case NPY_FLOAT: \
{ \
MAP_IMAGE(float); \
sipRes = Py_BuildValue("(O(f,f))",aRImage,aMin,aMax); \
break; \
} \
case NPY_DOUBLE: \
{ \
MAP_IMAGE(double); \
sipRes = Py_BuildValue("(O(d,d))",aRImage,aMin,aMax); \
break; \
} \
default: \
{ \
LutError *sipExceptionCopy = new LutError("Input Array type not supported"); \
sipRaiseTypeException(sipType_LutError,sipExceptionCopy); \
Py_DECREF(src); \
return NULL; \
} \
}\
Py_DECREF(src);\
Py_DECREF(aRImage);
%End
static SIP_PYTUPLE map_on_min_max_val(SIP_PYOBJECT,Palette&,mapping_meth);
%MethodCode
#ifdef MAP_IMAGE
#undef MAP_IMAGE
#endif
#define MAP_IMAGE(TYPE)\
TYPE aMin,aMax;\
QImage aMappedImage(column,row,32);\
Py_BEGIN_ALLOW_THREADS;\
LUT::map_on_min_max_val<TYPE>((TYPE*)src->data,(unsigned int*)aMappedImage.bits(),column,row,*a1,a2,aMin,aMax);\
Py_END_ALLOW_THREADS;\
aRImage = sipConvertFromNewInstance(new QImage(aMappedImage),sipClass_QImage,NULL);
MAP_FUNCTION
%End
static SIP_PYTUPLE map(SIP_PYOBJECT,Palette&,mapping_meth,double,double);
%MethodCode
#ifdef MAP_IMAGE
#undef MAP_IMAGE
#endif
#define MAP_IMAGE(TYPE)\
TYPE aMin = (TYPE)a3;\
TYPE aMax = (TYPE)a4;\
QImage aMappedImage(column,row,32);\
Py_BEGIN_ALLOW_THREADS;\
LUT::map<TYPE>((TYPE*)src->data,(unsigned int*)aMappedImage.bits(),column,row,*a1,a2,aMin,aMax);\
Py_END_ALLOW_THREADS;\
aRImage = sipConvertFromNewInstance(new QImage(aMappedImage),sipClass_QImage,NULL);
MAP_FUNCTION
%End
static SIP_PYTUPLE transform_autoscale(SIP_PYOBJECT,Palette&,mapping_meth);
%MethodCode
#ifdef MAP_IMAGE
#undef MAP_IMAGE
#endif
#define MAP_IMAGE(TYPE)\
TYPE aMin,aMax;\
npy_intp dims[] = {row << 2,column};\
aRImage = PyArray_SimpleNew(2,dims,NPY_UBYTE); \
Py_BEGIN_ALLOW_THREADS;\
LUT::map_on_min_max_val<TYPE>((TYPE*)src->data,(unsigned int*)PyArray_DATA(aRImage),column,row,*a1,a2,aMin,aMax);\
Py_END_ALLOW_THREADS;
MAP_FUNCTION
%End
static SIP_PYTUPLE transform(SIP_PYOBJECT,Palette&,mapping_meth,double,double);
%MethodCode
#ifdef MAP_IMAGE
#undef MAP_IMAGE
#endif
#define MAP_IMAGE(TYPE)\
TYPE aMin = (TYPE)a3;\
TYPE aMax = (TYPE)a4;\
npy_intp dims[] = {row << 2,column};\
aRImage = PyArray_SimpleNew(2,dims,NPY_UBYTE); \
Py_BEGIN_ALLOW_THREADS;\
LUT::map<TYPE>((TYPE*)src->data,(unsigned int*)PyArray_DATA(aRImage),column,row,*a1,a2,aMin,aMax);\
Py_END_ALLOW_THREADS;
MAP_FUNCTION
%End
};
class LutError
{
%TypeHeaderCode
#include <pixmaptools_lut.h>
%End
public:
LutError(const char * aMessage);
~LutError();
const char* msg() const;
};
class Stat
{
%TypeHeaderCode
#include <pixmaptools_stat.h>
%End
%TypeCode
#define PY_ARRAY_UNIQUE_SYMBOL _PixmapNumpyArray
#define NO_IMPORT_ARRAY
#include "numpy/arrayobject.h"
template<class IN>
inline void _histo_full(IN* data,int nbElem,NPY_TYPES type,PyObject* &Y,PyObject* &X)
{
std::vector<IN> vectorX;
std::vector<int> vectorY;
Py_BEGIN_ALLOW_THREADS;
Stat::histo_full<IN>(data,nbElem,vectorY,vectorX);
Py_END_ALLOW_THREADS;
npy_intp ydims[] = {vectorY.size()};
Y = PyArray_SimpleNew(1,ydims,NPY_INT);
typename std::vector<int>::iterator i = vectorY.begin();
for(int * Ydata = (int*)((PyArrayObject*)Y)->data;
i != vectorY.end();++i,++Ydata)
*Ydata = *i;
npy_intp xdims[] = {vectorX.size()};
X = PyArray_SimpleNew(1,xdims,type);
typename std::vector<IN>::iterator j = vectorX.begin();
for(IN *Xdata = (IN*)((PyArrayObject*)X)->data;
j != vectorX.end();++j,++Xdata)
*Xdata = *j;
}
template<class IN>
inline void _histo(IN* data,int nbElem,NPY_TYPES type,PyObject* &Y,PyObject* &X,
int bins,const IN aMinVal,const IN aMaxVal)
{
std::vector<IN> vectorX;
std::vector<int> vectorY;
Py_BEGIN_ALLOW_THREADS;
Stat::histo<IN>(data,nbElem,vectorY,vectorX,bins,aMinVal,aMaxVal);
Py_END_ALLOW_THREADS;
npy_intp ydims[] = {vectorY.size()};
Y = PyArray_SimpleNew(1,ydims,NPY_INT);
typename std::vector<int>::iterator i = vectorY.begin();
for(int * Ydata = (int*)((PyArrayObject*)Y)->data;
i != vectorY.end();++i,++Ydata)
*Ydata = *i;
npy_intp xdims[] = {vectorX.size()};
X = PyArray_SimpleNew(1,xdims,type);
typename std::vector<IN>::iterator j = vectorX.begin();
for(IN *Xdata = (IN*)((PyArrayObject*)X)->data;
j != vectorX.end();++j,++Xdata)
*Xdata = *j;
}
#define HISTO_FUNCTION \
PyArrayObject *src; \
if(!(src = (PyArrayObject*)PyArray_ContiguousFromObject(a0,NPY_NOTYPE,0,0))) \
return NULL; \
\
int nbElem = src->dimensions[0]; \
for(int i = 1;i < src->nd;++i) \
nbElem *= src->dimensions[1]; \
PyObject *Y,*X;\
switch(src->descr->type_num) \
{ \
case NPY_BYTE: \
{ \
HISTO(char); \
break; \
} \
case NPY_UBYTE: \
{ \
HISTO(unsigned char); \
break; \
} \
case NPY_SHORT: \
{ \
HISTO(short); \
break; \
} \
case NPY_USHORT: \
{ \
HISTO(unsigned short); \
break; \
} \
case NPY_INT: \
{ \
HISTO(int); \
break; \
} \
case NPY_UINT: \
{ \
HISTO(unsigned int); \
break; \
} \
case NPY_LONG: \
{ \
HISTO(long); \
break; \
} \
case NPY_ULONG: \
{ \
HISTO(unsigned long); \
break; \
} \
case NPY_FLOAT: \
{ \
HISTO(float); \
break; \
} \
case NPY_DOUBLE: \
{ \
HISTO(double); \
break; \
} \
default: \
return NULL; \
}\
sipRes = Py_BuildValue("(O,O)",Y,X); \
Py_DECREF(src);\
Py_DECREF(X);\
Py_DECREF(Y);
%End
public:
static SIP_PYTUPLE histo_full(SIP_PYOBJECT);
%MethodCode
#ifdef HISTO
#undef HISTO
#endif
#define HISTO(TYPE) _histo_full((TYPE*)src->data,nbElem,(NPY_TYPES)src->descr->type_num,Y,X);
HISTO_FUNCTION
%End
static SIP_PYOBJECT histo(SIP_PYOBJECT,int,double = 0,double = 0);
%MethodCode
#ifdef HISTO
#undef HISTO
#endif
#define HISTO(TYPE) \
TYPE maxVal,minVal;\
minVal = (TYPE)a2; \
maxVal = (TYPE)a3; \
_histo((TYPE*)src->data,nbElem,(NPY_TYPES)src->descr->type_num,Y,X,a1,minVal,maxVal);
HISTO_FUNCTION
%End
};
import glob
import platform
from distutils.core import setup,Extension
import sipdistutils
import numpy
import os
QT3=True
if QT3:
print "***** doing setup.py for Qt3 *****"
import pyqtconfig
else:
print "***** doing setup.py for Qt4 *****"
import PyQt4.pyqtconfig as pyqtconfig
# Get the PyQt configuration information.
config = pyqtconfig.Configuration()
if QT3:
sip_flags = config.pyqt_qt_sip_flags.split()
qt_inc_dir = config.qt_inc_dir
else:
sip_flags = config.pyqt_sip_flags
# configure sip build_ext
class my_own_build_ext(sipdistutils.build_ext):
def __init__(self, *args, **kwargs):
sipdistutils.build_ext.__init__(self, *args, **kwargs)
def finalize_options(self):
sipdistutils.build_ext.finalize_options(self)
self.sip_opts = sip_flags
def _sip_sipfiles_dir(self):
config=pyqtconfig.Configuration()
return config.pyqt_sip_dir
if platform.system() == 'Linux' :
try:
if platform.architecture()[0] == '64bit' :
......@@ -42,7 +70,15 @@ mar345_module = Extension(name = "mar345",
extra_link_args = extra_link_args,
include_dirs = ['mar345',numpy.get_include()])
pixmaptools_module = Extension(name = "pixmaptools",
sources = ["pixmaptools/%s.sip" % (QT3 and "pixmaptools_qt3" or "pixmaptools_qt4")]+glob.glob('pixmaptools/pixmaptools_*.cpp'),
extra_compile_args = extra_compile_args,
extra_link_args = extra_link_args,
include_dirs = ['pixmaptools', numpy.get_include(), qt_inc_dir])
setup(name = "QubCTools",version = "1.0",
description = "Some tools written in C for speed",
ext_modules = [polygone_module,dataresize_module,sps_module,mar345_module])
ext_modules = [polygone_module,dataresize_module,sps_module,mar345_module,pixmaptools_module],
cmdclass={'build_ext': my_own_build_ext})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment