Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-07

fpimage BMP and X11 implementation

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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?

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

Regards,
- Graeme -

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: See below. You must descend from TFPCustomImage. The difference is that TFPCustomImage…
Michael Van Canneyt wrote 10 lines
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 :-)

Brilliant. It makes more sense now. Thanks again for you time... :)

Graeme.

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: I'm trying to implement fpimage support in the fpGUI widget framework. I'm really…
Graeme Geldenhuys wrote 19 lines
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.

Reply by email