|
From: Pierre <pie...@gm...> - 2007-02-03 11:18:26
|
Hi, On 2/2/07, Hans-Bernhard Br=F6ker <HBB...@t-...> wrote: > Ethan Merritt wrote: > > > I noted out in my feature request for libgd that it was unclear what > > sort of interpolation could be done with an indexed colormap. The usual > > shading interpolation routines assume either RGB or CMY colorspace. > > But I think you've answered that question. The gnuplot PM3D grey > > scale palette routines define a single scale within which interpolation > > of the index value does make sense. > > ... for pm3d it does. But the same need not apply for GD at large. > > PM3D doesn't interpolate colours, it interpolates indices, i.e. it > interpolates along a polyline through colour space. The idea being that > all resulting colours should still be on that polyline. > > To give an example, from an RGB palette defined like this: > > 0.0: blue > 0.5: white > 1.0: red > > all colours interpolated by pm3d would currently be pure blue or red at > various levels of saturation. A triangle with these three values at its > corners would have a pure white streak all along the edge from the white > corner to the center of the opposite edge. > > Actual colour interpolation would yield all kinds of violet with pure > white only around the original white vertex. I'm not sure to understand the notion of palette in your example. Which and how many colors do you have in the palette when you start to render a given triangle? About GD in general, it supports indexed colors, it is what we define as palette based image (created by gdImageCreate). The indexes are sequentially incremented: > for(i=3D0;i<N;i++) png_smooth_color[i] =3D gdImageColorAllocate(...) it will create a color from the last existing index. About what Dan said later (sorry, I subscribed only this morning) > I assume you are interested only in linear interpolation and not higher o= rder > approaches like 2D splines. I wrote a sample code including the new shaded triangle function in Ethan's request: http://bugs.libgd.org/?do=3Ddetails&task_id=3D39 It uses a linear interpolation. Only true color images are supported now (no palette, "unlimited" colors). I did not test all cases but the colors on the edges seem to match (see the attached images, a quadrilateral rendered using two triangles). > Does gdlib have indexed colormaps? Yes, see above :) > If not, a gradient triangle fill shouldn't > be too difficult to implement. If we know the resolution of the PNG/JPEG > then it should be straightforward. In GD (or any other bitmap based library), the rendering is resolution independent. It is pixel based. The DPI is meta information to help other applications to know the size in inches but the image itself remains the same. I have a question about the usage of indexed colors, as I understand the need of an indexed intensity palette (well known method for VGA-like devices for example). Is there a reason to keep using them instead of a true color image? True color image are faster to render and the image can be saved as indexed PNG (if size matters). It makes little sense to use indexed colors if JPEG is the target. JPEG output are true color. Feel free to post comment in the issues tracker, our mailing lists or here (privately too but I prefer to keep the process as open as possible). As Ethan said, we have plenty of time to define our respective needs. Thanks for your feedbacks, --Pierre |