[fpc-devel] Patch for fpimage.inc bug
ugilio at hotmail.com
Wed Aug 10 02:09:07 CEST 2005
Hi, I found a bug in fpimage.inc and there is a patch.
The problem was in TFPCustomImage.Assign: palette was generated with a
(Src is the image that must be copied in this image).
Build works this way: builds a palette scanning every pixel of the source
Then the data is copied via the pixel[x,y] property.
The problem is that pixel data is relative to palette, but build(src)
generates a palette with the same colors of the original but with a
different order (in fact since it generates the palette scanning the pixel
of the source image, palette order isn't the same as the original!).
The correct way to build the palette is to use
since palette is copied exactly as it is.
Now, about the mail I sent yesterday: I started writing the quantizer stuff,
and I think it's working very well.
I implemented a TFPQuantizer class, which has abstract methods and is the
base class for all quantizers.
Then i wrote a descendant, TFPOctreeQuantizer, which is a quantizer that
implements the Octree algorithm.
Quantizers just return a palette, since their work is to generate a palette
of arbitrary size from a given image.
So i wrote also a TFPBaseDitherer class.
This is the base class for all ditherers, but strictly speaking it isn't
really a ditherer: you give it an image and a palette, and the ditherer
transform the image so that it uses the palette you provide (basically it
finds for every pixel in the image the best color in the palette).
This class has useful protected methods to find the best matching color,
distances between colors and so on.
Descendant classes can use this methods to implement specific dithering
algorithms (maybe I'll write a ditherer that implements the Floyd-Steinberg
So If you want to reduce the color depth of an image you can use the
quantizer to generate a palette from your image, and then pass the image and
the generated palette to the ditherer.
In a very near future we could save images with the bpp we want, and do
palette reductions and so on :)
Is there someone working on tfpcustomimage and related things? I think it
would be better if I talk directly to him instead of bloating the mailing
this is the patch:
--- fpimage.inc (revision 837)
+++ fpimage.inc (working copy)
@@ -398,7 +398,7 @@
If UsePalette then
// Copy image.
More information about the fpc-devel