Check to see if a bitmap is a solid color
Ceagon Xylas

Like the topic title indicates, I'm asking what is the fastest way to check if a bitmap's a solid color?
I'm trying to check and see if a 32x32 bitmap is solid magic pink.

miran

EDIT: nm, I misunderstood the question.

The real answer: two for loops.

Ceagon Xylas

And getpixel I assume? I guess it's not too slow for only loading bitmap routines.

miran

You can also use direct access. Or one of the colour depth specific access functions that don't do bounds checking.

Ceagon Xylas

Okee doke. Thanks :)

GullRaDriel

Perhaps this from exfire.c, with some little change you can adjust it to fit your need:

1 /* It is even faster if we transfer the data in 32 bit chunks, rather
2 * than only one pixel at a time. This method may not work on really
3 * unusual machine architectures, but should be ok on just about
4 * anything that you are practically likely to come across.
5 */
6 while (!keypressed()) {
7 acquire_screen();
8 draw_bottom_line_of_fire();
9 
10 bmp_select(screen);
11 
12 for (y=64; y<SCREEN_H-1; y++) {
13 /* get an address for reading line y+1 */
14 address = bmp_read_line(screen, y+1);
15 
16 /* read line in 32 bit chunks */
17 for (x=0; x<SCREEN_W; x += sizeof(uint32_t))
18 *((uint32_t *)&temp[x]) = bmp_read32(address+x);
19 
20 /* adjust it */
21 for (x=0; x<SCREEN_W; x++)
22 if (temp[x] > 0)
23 temp[x]--;
24 
25 /* get an address for writing line y */
26 address = bmp_write_line(screen, y);
27 
28 /* write line in 32 bit chunks */
29 for (x=0; x<SCREEN_W; x += sizeof(uint32_t))
30 bmp_write32(address+x, *((uint32_t *)&temp[x]));
31 }
32 
33 bmp_unwrite_line(screen);
34 release_screen();
35 }
36 
37 free(temp);
38 
39 return 0;
40}

This article from Gamedev about digital processing can help too for implementing gaussian blur.
_

Onewing
//Untested 
bool is_solid_color(BITMAP *src, int col)
{
  int x = 0, y = 0;
  int check_col = -1;
  while(y < src->h && (check_col = getpixel(src,x++,y)) == col)
    if(x == src->w) {  x = 0; y++;   }

  if(check_col != col)
    return false;
  return true;
}

Funny thing about this is the worst case scenario is when the bitmap IS the given solid color. :)

Rampage

Onewing Phipps:

bool is_solid_color(BITMAP *src, int col)
{
  int x = 0, y = 0;
  int check_col = -1;
  while(y < src->h && (check_col = getpixel(src,x++,y)) == col)
    if(x == src->w) {  x = 0; y++;   }

  // just a minor improvement
  return check_col == col;
}

Ceagon Xylas

;D

Thread #590844. Printed from Allegro.cc