[fpc-pascal] fpimage BMP and X11 implementation

Michael Van Canneyt michael.vancanneyt at wisa.be
Tue Jul 3 11:26:16 CEST 2007



On Tue, 3 Jul 2007, Graeme Geldenhuys wrote:

> Hi,
> 
> I'm trying to implement fpimage support in the fpGUI widget framework.
> I'm really confused at the moment. :)   The following queries apply
> to X11 (xlib) only. My GDI (windows) support will come later.
> 
> My current BMP image implementation (which doesn't use the fpimage
> unit) has an internal TXImage. One for the Mask and one for the Image
> Data.
> 
> Now creating a descendant of TFPCustomImage, I know I need to
> implement the following two methods.
> 
>    procedure SetInternalPixel(x, y: integer; Value: integer); override;
>    function  GetInternalPixel(x, y: integer): integer; override;
> 
> 1) Those are the only abstract methods. So where am I supposed to
> create the instance of TXImage and assign it the internal data? When
> am I supposed to assign the internal data?

See below.

> 
> 2) Am I supposed to descend from TFPCustomImage or TFPMemoryImage?
> What's the difference?

You must descend from TFPCustomImage.

The difference is that TFPCustomImage provides no storage for the actual
image data: all methods rely on the SetInternalPixel and GetInternalPixel
methods. Careful, these are palette based. There are 2 other virtual calls
which retrieve/set the actual colors:

      procedure SetInternalColor (x,y:integer; const Value:TFPColor); virtual;
      function GetInternalColor (x,y:integer) : TFPColor; virtual;

By default, these work with the palette using the index retrieved/provided
by SetInternalPixel and GetInternalPixel.

It may make more sense to you to reverse the situation, depending on your 
storage format.

TFPMemoryImage actually stores the data in an array in memory, independent
of any device. (it stores the RGB values directly or using a palette)

You should create a TFPCustomImage descendent which handles the storage
through the TXImage auxiliary object.

What you should do:

Create a descendent of TFPCustomImage, say TFPGUIImage. It has an internal
TXImage field. When the dimensions are set of the image (in SetSize), 
you allocate the TXImage with the correct dimensions: So I think the best is
to override setsize, and create the TXImage there. Override destroy to free
The TXImage. Then you override SetInternalColor, GetInternalColor, and 
SetInternalPixel and GetInternalPixel so they work as expected: they'll
probably simply access the TXImage instance methods, and convert the internal 
format of TXImage to TFPColors.

I hope this makes sense. If not, shoot :-)

Michael.



More information about the fpc-pascal mailing list