Commit 4ae40616 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

backport video scaling

parent 1984933c
This diff is collapsed.
......@@ -62,6 +62,7 @@ public:
unsigned int _dataPalette[0x10000];
mode _mode;
};
public:
template<class IN> static void map_on_min_max_val(const IN *data,unsigned int *anImagePt,
int column,int row,Palette &aPalette,
......@@ -72,5 +73,73 @@ public:
int column,int row,
Palette&,mapping_meth,
IN dataMin,IN dataMax);
// function to transform raw video format into rgb(32bits BGRA8888) image
class Scaling
{
public:
friend class LUT;
struct luma;
enum image_type {UNDEF,
Y8, // monochrome 8bits
Y16, // monochrome 16bits
Y32, // monochrome 32bits
Y64, // monochrome 64bits
I420, // YVU 8bits
RGB555,
RGB565,
RGB24,
RGB32,
BGR24,
BGR32,
BAYER_RG8, // BAYER RG 8bits (prosilica)
BAYER_RG16, // BAYER RG 16bits (prosilica)
BAYER_BG8, // BAYER BG 8bits (basler)
BAYER_BG16, // BAYER BG 16bits (basler)
YUV411,
YUV422,
YUV444};
enum mode {UNACTIVE,QUICK,ACCURATE,COLOR_MAPPED};
Scaling();
~Scaling();
void current_type(image_type &aType) const;
void min_max_mapping(double &minVal,double &maxVal) const;
void set_custom_mapping(double minVal,double maxVal);
void get_mode(mode&) const;
void set_mode(mode);
void fill_palette(LUT::Palette::palette_type);
void set_palette_mapping_meth(LUT::mapping_meth);
void autoscale_min_max(const unsigned char *data,int column,int row,
image_type aType);
void autoscale_plus_minus_sigma(const unsigned char *data,int column,int row,
image_type aType,double aSigmaFactor);
private:
mutable pthread_mutex_t _lock;
double _minValue,_maxValue; // min max
luma *_Luma;
mode _mode;
void _get_minmax_and_mode(double &minVal,double &maxVal,
mode &aMode);
};
static bool raw_video_2_image(const unsigned char *data,unsigned int *anImagePt,
int column,int row,
LUT::Scaling::image_type anImageType,
Scaling &aScaling);
static unsigned char* raw_video_2_luma(const unsigned char *data,
int column,int row,
LUT::Scaling::image_type anImageType);
};
#endif
......@@ -222,6 +222,55 @@ template<class IN> void _create_palette_from_data(unsigned int *aDestPalette,con
double R1,double G1,double B1,
double R2,double G2,double B2) throw(LutError);
};
class Scaling
{
%TypeHeaderCode
#include <pixmaptools_lut.h>
%End
public:
enum image_type {UNDEF,
Y8, // monochrome 8bits
Y16, // monochrome 16bits
Y32, // monochrome 32bits
Y64, // monochrome 64bits
I420, // YVU 8bits
RGB555,
RGB565,
RGB24,
RGB32,
BGR24,
BGR32,
BAYER_RG8, // BAYER RG 8bits (prosilica)
BAYER_RG16, // BAYER RG 16bits (prosilica)
BAYER_BG8, // BAYER BG 8bits (basler)
BAYER_BG16, // BAYER BG 16bits (basler)
YUV411,
YUV422,
YUV444};
enum mode {UNACTIVE,QUICK,ACCURATE,COLOR_MAPPED};
Scaling();
~Scaling();
void current_type(LUT::Scaling::image_type &aType /Out/) const;
void min_max_mapping(double &minVal /Out/,double &maxVal /Out/) const;
void set_custom_mapping(double minVal,double maxVal);
void get_mode(LUT::Scaling::mode& /Out/) const;
void set_mode(LUT::Scaling::mode);
void fill_palette(LUT::Palette::palette_type);
void set_palette_mapping_meth(LUT::mapping_meth);
void autoscale_min_max(const unsigned char *data,int column,int row,
LUT::Scaling::image_type aType);
void autoscale_plus_minus_sigma(const unsigned char *data,int column,int row,
LUT::Scaling::image_type aType,double aSigmaFactor);
};
%TypeCode
#define PY_ARRAY_UNIQUE_SYMBOL _PixmapNumpyArray
#define NO_IMPORT_ARRAY
......@@ -374,7 +423,58 @@ MAP_FUNCTION
Py_END_ALLOW_THREADS;
MAP_FUNCTION
%End
static SIP_PYTUPLE raw_video_2_image(const unsigned char *data,int column,int row,
LUT::Scaling::image_type anImageType,
LUT::Scaling &aScaling);
%MethodCode
bool aReturnFlag;
QImage aMappedImage(a1,a2,32);
Py_BEGIN_ALLOW_THREADS;
aReturnFlag = LUT::raw_video_2_image(a0,(unsigned int*)aMappedImage.bits(),a1,a2,
a3,*a4);
Py_END_ALLOW_THREADS;
PyObject *aRImage = sipConvertFromNewInstance(new QImage(aMappedImage),sipClass_QImage,NULL);
sipRes = Py_BuildValue("(O,N))",aReturnFlag ? Py_True : Py_False,aRImage);
%End
static SIP_PYOBJECT raw_video_2_luma(const unsigned char *data,int column,int row,
LUT::Scaling::image_type anImageType);
%MethodCode
unsigned char* luma = NULL;
Py_BEGIN_ALLOW_THREADS;
luma = LUT::raw_video_2_luma(a0,a1,a2,a3);
Py_END_ALLOW_THREADS;
npy_intp dims[] = {a2,a1};
if(luma)
{
switch(a3)
{
case LUT::Scaling::Y8:
case LUT::Scaling::RGB555:
case LUT::Scaling::RGB565:
case LUT::Scaling::RGB24:
case LUT::Scaling::RGB32:
case LUT::Scaling::BGR24:
case LUT::Scaling::BGR32:
case LUT::Scaling::BAYER_RG8:
case LUT::Scaling::YUV411:
case LUT::Scaling::YUV422:
case LUT::Scaling::YUV444:
sipRes = PyArray_SimpleNewFromData(2,dims,NPY_UBYTE,luma);break;
case LUT::Scaling::Y16:
case LUT::Scaling::BAYER_RG16:
sipRes = PyArray_SimpleNewFromData(2,dims,NPY_USHORT,luma);break;
case LUT::Scaling::Y32:
sipRes = PyArray_SimpleNewFromData(2,dims,NPY_INT32,luma);break;
default:
sipRes = NULL;
}
if(sipRes)
((PyArrayObject*)sipRes)->flags |= NPY_OWNDATA;
}
else
sipRes = NULL;
%End
};
class LutError
{
......@@ -536,4 +636,6 @@ static SIP_PYOBJECT histo(SIP_PYOBJECT,int,double = 0,double = 0);
_histo((TYPE*)src->data,nbElem,(NPY_TYPES)src->descr->type_num,Y,X,a1,minVal,maxVal);
HISTO_FUNCTION
%End
};
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