Commit 4294330a authored by cclepper's avatar cclepper
Browse files

added yuv and optimizations


git-svn-id: https://pd-gem.svn.sourceforge.net/svnroot/pd-gem/trunk/Gem@163 49b2a0ca-c541-4d49-a7ef-d785e4371512
parent e9991939
......@@ -164,7 +164,11 @@ void pix_convolve :: processImage(imageStruct &image)
int offsetXY = x * tempImg.csize + offsetY;
// skip the alpha value
#ifndef MACOSX
for (int c = 0; c < 3; c++)
#else
for (int c = 1; c < 4; c++)
#endif
{
int new_val = 0;
int offsetXYC = offsetXY + c;
......@@ -174,11 +178,13 @@ void pix_convolve :: processImage(imageStruct &image)
int realMatY = matY * m_rows;
for (int matX = 0; matX < m_rows; matX++)
{
new_val += (int)(tempImg.data[offsetXYCMat + matX * tempImg.csize] *
m_matrix[realMatY + matX]);
new_val += (tempImg.data[offsetXYCMat + matX * tempImg.csize] *
m_imatrix[realMatY + matX])>>8;
}
}
image.data[realPos + c] = CLAMP(new_val/m_range);
//image.data[realPos + c] = CLAMP(new_val/m_range);
image.data[realPos + c] = CLAMP(new_val); //removes insult from injury
}
}
}
......@@ -200,6 +206,7 @@ void pix_convolve :: processImage(imageStruct &image)
// skip the alpha value
for (int c = 0; c < 3; c++)
{
int new_val = 0;
int offsetXYC = offsetXY + c;
......@@ -211,9 +218,11 @@ void pix_convolve :: processImage(imageStruct &image)
{
new_val += MMULT(tempImg.data[offsetXYCMat + matX * tempImg.csize],
m_imatrix[realMatY + matX]);
}
}
image.data[realPos + c] = CLAMP(new_val/m_range);
}
}
}
......@@ -223,8 +232,86 @@ void pix_convolve :: processImage(imageStruct &image)
void pix_convolve :: processYUVImage(imageStruct &image)
{
post("pix_convolve: YUV not yet implemented :-(");
post("\tbut really :: why ?");
image.copy2Image(&tempImg);
//float range = 1;
int initX = m_rows / 2;
int initY = m_cols / 2;
int maxX = tempImg.xsize - initX;
int maxY = tempImg.ysize - initY;
int xTimesc = tempImg.xsize * tempImg.csize;
int initOffset = initY * xTimesc + initX * tempImg.csize;
if (m_chroma) {
for (int y = initY; y < maxY; y++)
{
int realY = y * xTimesc;
int offsetY = realY - initOffset;
for (int x = initX; x < maxX; x++)
{
int realPos = x * tempImg.csize + realY;
int offsetXY = x * tempImg.csize + offsetY;
// skip the UV
for (int c = 1; c < 3; c+=2)
{
int new_val = 0;
int offsetXYC = offsetXY + c;
for (int matY = 0; matY < m_cols; matY++)
{
int offsetXYCMat = matY * xTimesc + offsetXYC;
int realMatY = matY * m_rows;
for (int matX = 0; matX < m_rows; matX++)
{
//new_val += (int)(tempImg.data[offsetXYCMat + matX * tempImg.csize] *
// m_matrix[realMatY + matX]);
new_val += (tempImg.data[offsetXYCMat + matX * tempImg.csize] *
m_imatrix[realMatY + matX])>>8;
}
}
// image.data[realPos + c] = CLAMP(new_val/m_range);
image.data[realPos + c] = CLAMP(new_val);
// image.data[realPos + c-1] = 128; //remove the U+V
}
}
}
}else{
for (int y = initY; y < maxY; y++)
{
int realY = y * xTimesc;
int offsetY = realY - initOffset;
for (int x = initX; x < maxX; x++)
{
int realPos = x * tempImg.csize + realY;
int offsetXY = x * tempImg.csize + offsetY;
// skip the UV
for (int c = 1; c < 3; c+=2)
{
int new_val = 0;
int offsetXYC = offsetXY + c;
for (int matY = 0; matY < m_cols; matY++)
{
int offsetXYCMat = matY * xTimesc + offsetXYC;
int realMatY = matY * m_rows;
for (int matX = 0; matX < m_rows; matX++)
{
//new_val += (int)(tempImg.data[offsetXYCMat + matX * tempImg.csize] *
// m_matrix[realMatY + matX]);
new_val += (tempImg.data[offsetXYCMat + matX * tempImg.csize] *
m_imatrix[realMatY + matX])>>8;
}
}
// image.data[realPos + c] = CLAMP(new_val/m_range);
image.data[realPos + c] = CLAMP(new_val);
image.data[realPos + c-1] = 128; //remove the U+V
}
}
}
}
}
/////////////////////////////////////////////////////////
// rangeMess
......@@ -248,11 +335,12 @@ void pix_convolve :: matrixMess(int argc, t_atom *argv)
error("GEM: pix_convolve: matrix size not correct");
return;
}
int i;
for (i = 0; i < argc; i++) m_matrix[i] = atom_getfloat(&argv[i]);
for (i = 0; i < argc; i++) m_imatrix[i] = (int)(atom_getfloat(&argv[i])*255.);
setPixModified();
}
......@@ -266,6 +354,8 @@ void pix_convolve :: obj_setupCallback(t_class *classPtr)
gensym("matrix"), A_GIMME, A_NULL);
class_addmethod(classPtr, (t_method)&pix_convolve::rangeMessCallback,
gensym("ft1"), A_FLOAT, A_NULL);
class_addmethod(classPtr, (t_method)&pix_convolve::chromaMessCallback,
gensym("chroma"), A_FLOAT, A_NULL);
}
void pix_convolve :: matrixMessCallback(void *data, t_symbol *, int argc, t_atom *argv)
{
......@@ -275,3 +365,8 @@ void pix_convolve :: rangeMessCallback(void *data, t_floatarg range)
{
GetMyClass(data)->rangeMess((float)range);
}
void pix_convolve :: chromaMessCallback(void *data, t_floatarg value)
{
GetMyClass(data)->m_chroma=(int)value;
}
......@@ -88,6 +88,8 @@ class GEM_EXTERN pix_convolve : public GemPixObj
//////////
// The number of columns
int m_cols;
int m_chroma;
private:
imageStruct tempImg;
......@@ -96,6 +98,7 @@ class GEM_EXTERN pix_convolve : public GemPixObj
// Static member functions
static void rangeMessCallback(void *data, t_floatarg range);
static void matrixMessCallback(void *data, t_symbol *, int argc, t_atom *argv);
static void chromaMessCallback(void *data, t_floatarg value);
};
#endif // for header file
Markdown is supported
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