Link to home
Start Free TrialLog in
Avatar of bcrotaz
bcrotaz

asked on

Comparing bitmap data fast

I need to compare two identical size bitmaps to see if they are identical (picture data-wise).
At the moment, I iterate through the Canvas.Pixels[x,y] and compare each individual pixel, breaking out if I find a pair that don't match.  Is there a nice Windows graphics call to do this faster?
I'm coding a sort of fractal compressor, which at the moment takes over 10 hours on a P200 to compress a 300x300 image!
On the same lines, how do I find the palette index of a colour in an 8-bit bitmap?  At the moment I'm streaming the RGB colour, which obviously wastes 2 bytes per pixel.

Thanks,
Bryan
ASKER CERTIFIED SOLUTION
Avatar of gysbert1
gysbert1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gysbert1
gysbert1

Oh yes. This TBitmap API structure contains the Palette as well (which you probably know you can get as a property in the Delphi Implementation). The bits pointer points to a c_style array that contains the 8bit, 24bit, 4bit,etc data as specified. This means that for an 8bit bitmap it will point to an array of palette indices. Pixels[x,y] is slow since it does all this every time. it finds the specified pixel in the bits array and converts the color format to the windows TColor which is 32bit and then returns this. Since function calls takes extremely long compared to other operations this accounts for a significant change of execution speed.

I have soem nice C-code with me to do this which I can send to you if you like. (I am not sure if I still have the delphi code).

Avatar of bcrotaz

ASKER

So if it's a 256 col bitmap, the bits array is an array of bytes?
Do the scans run from top down, or bottom up?
How is the palette arranged?
Where is the palette in the structure? I can't see it!

Thanks,
bryan
The scan runs from bottom left to right top if I remember correctly.

The delphi TBitmap object has (as one of it's key properties) a palette of type HPalette.

If you are using TPicture (are you?) the bitmap is one of it's properties
Avatar of bcrotaz

ASKER

The Hpalette is just a handle to a palette, though.
How do I get the structure of the palette and work out what the 256 colours actually are?
Man ! You really could find this in the API help files.

I am a nice guy though so I will still help you ;^)

There is an API call to get the palette if you have the handle. Remember this ! If you have a Handle to anything in windows you have everything you will ever need ... Everything in windows in handled by handles eg. windows, palettes, even some data structures.

Here is a section of the API help files for you. PS.Delphi 2's help really sucks. Delphi 1's help was much, much better.

API Help Entries ...

function GetPaletteEntries(Palette: HPalette; StartIndex, NumEntries: Word; var
 PaletteEntries): Word;

The GetPaletteEntries function retrieves a range of palette entries in a logical palette.

Parameter      Description

Palette      Identifies the logical palette.
StartIndex      Specifies the first logical-palette entry to be retrieved.
NumEntries      Specifies the number of logical-palette entries to be retrieved.
PaletteEntries      An array of TPALETTEENTRY structures that will receive the palette entries. The array must contain at least as many structures as specified by the NumEntries parameter.

Returns

The return value is the number of entries retrieved from the logical palette, if the function is successful. Otherwise, it is zero.

See Also

GetSystemPaletteEntries
TPALETTEENTRY
GDI functions (3.1)
Avatar of bcrotaz

ASKER

Thanks.
I agree about the help.
That's why I'm asking the question, cos I couldn't understand it!
It seems to assume you know all about the concepts.  There's no help for you if you don't.