Design ideas about iterators

Cyrille Berger cyb at lepi.org
Wed Mar 3 01:49:40 CET 2004


> GEGL seems to try to achieve color models and bit depths by generating C
> code using a special language that combines algorithms and specifications
> -- if I understood the documentation and code correctly. That looks a lot
> like templates, I guess, but I'm not sure.
1) It looks like oriented object in C too.
Templates are powerfull, but they can destroy us, a bit like the Dark Side... 
If we want to use them, we will have to check what are the common functions.

I see that  composite.h could be transform using templates like that :
template < int depth, QUANTUM (*f)(QUANTUM, QUANTUM, double, double), QUANTUM 
(*g)(double, double)>
void compositeIn(Q_INT32 stride,
		 QUANTUM *dst, 
		 Q_INT32 dststride,
		 QUANTUM *src, 
		 Q_INT32 srcstride,
		 Q_INT32 rows, 
		 Q_INT32 cols, 
		 QUANTUM opacity = OPACITY_OPAQUE)
{
	if (opacity == OPACITY_TRANSPARENT) 
		return;
	QUANTUM *d;
	QUANTUM *s;
	Q_INT32 i;
	double sAlpha, dAlpha;
	double alpha;
	while (rows-- > 0) {
		d = dst;
		s = src;
		for (i = cols; i > 0; i--, d += stride, s += stride) {
			if (s[PIXEL_ALPHA] == OPACITY_TRANSPARENT)
			{
				memcpy(d, s, stride * sizeof(QUANTUM));
				continue;
			}
			if (d[PIXEL_ALPHA] == OPACITY_TRANSPARENT)
				continue;
			sAlpha = QUANTUM_MAX - s[PIXEL_ALPHA];
			dAlpha = QUANTUM_MAX - d[PIXEL_ALPHA];
			for( int i = 0; i < depth; i++)
			{
				d[ i ]=f( s[ i ], sAlpha, d[ i ], dAlpha );
			}
			d[PIXEL_ALPHA]=g(salpha, dalpha);
		}
		dst += dststride;
		src += srcstride;
	}
}

And so we can define an only tileBlt for all colorspace. And we may get ride 
of enum CompositeOp.
But I can't see how we can get ride of some constant, such as const 
REDCHANNEL, GREENCHANNEL, BLUECHANNEL, GRAYCHANNEL, INDEXEDCHANNEL, 
ALPHACHANNEL...

And we still need "enum enumImgType", even with template. Even if it is just 
to say the user : "it's a CMYB image".


2) I just sea an interesting idea for iterators in GEGL's documentation, we 
should do an iterator that return an other iterator which will contain a 
line. I don't think I am clear, we may have an iterator called iteratorLine 
which return an iteratorPixel.
We may use them this way :
for( iteratorLine iL = image->getIterator() ; iL != iL.end(); iL++)
// go through lines
{
	for( iteratorPixel iP = *iL; iP != iP.end(); iP++)
	{
		*iP = 0; // Clear the pixel
	}
}

-- 
--- Cyrille Berger ---


More information about the kimageshop mailing list