I have a program that loops through a bitmap and extracts smaller bitmaps, e.g. 16x16 pixels - it's a tile extraction program. It then adds these to a list, but first checks the bitmap doesn't already exist in the list. The code to check if the bitmaps are the same (they are always the same depth) is :
bool IsBitmapSame(BITMAP* Checking,BITMAP* Current)
For an average bitmap which would have a few hundred tiled bitmaps within it works 99% of the time, however on certain extracted bitmaps it is returning a match on the very first bitmap in the list despite the bitmaps being completely different. If I change either of the above _getpixel to getpixel it works a treat, so it appears _getpixel is doing something when _getpixel is ran twice in succession? This was tested only on windows.
From analysis (well, somebody elses) it seems to be getting it wrong for bitmaps where oly the last 3 pixels on a line differ. Though this could be a red herring., but it's definitely something to do with the bitmap data.
Attached is a bitmap showing it. It is a cut down portion of a larger map. As you can see the version using getpixel finds all three tiles, but the version running _getpixel seems to match the first half of the circle with the first all blue tile. The larger image below shows a flag made up of 4 white parts, the bottom left tile is actually just 1 white pixel, but this is also skipped and the tile becomes the first all blue one again - hence why the comment above regarding the 3 pixels.
Tracing the code through for the two bitmaps passed in, for the ones that fail, it seems to be getting the same colour back for both images, despite their being different!
The code below is a snippet showing how the two bitmaps are generated:
|1||std::vector<BITMAP*> BitmapList; //array of unique bitmaps|
|12||//loop all rows in the bitmap|
|13||//calcheight is the size of the large bitmap, currenttilesize is the tile size|
|14||in pixels, e.g. 16|
|18|| //loop through all the bitmaps from start to end|
|19|| //loop all columns in each row|
|20|| for(int x=0;x<CalcWidth/CurrentTileSize;x++)|
|23|| //loop through what we've got - blit to a temp bitmap|
|24||just to make it easy|
|25|| //loadedfile is the big bitmap we are mapping|
|32|| //check if the bitmap has already been stored|
|37|| //loop through all bitmaps from start upto the|
|38||current outer loop|
|40|| if(same) |
|45|| //tile does not exist, add it|
|46|| if(!same) |