Shop OBEX P1 Docs P2 Docs Learn Events
Checking values in bitmap — Parallax Forums

Checking values in bitmap

Harry1Harry1 Posts: 29
edited 2007-01-18 21:18 in Propeller 1
I am wondering if there was a way for me to retrieve values from a bitmap by inputing a coordinate e.g (3,2)

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-18 20:43
    There's no ready-made code to do it, but the pixel information is in the bitmap. This is usually an array of longs with 16 horizontal pixels of 2 bits each. Obviously, the width of each row in longs depends on the width in pixels. Here's an example of what you might do. The details depend on which driver you're using.
    con
      width = 256 ' bitmap width in pixels
      height = 128 ' bitmap height in pixels
    var
      long bitmap[noparse][[/noparse]height*width/16]
    pub pixelValue(x,y)
    ' First compute the index of the long containing the pixel: (x + y*width) >> 4
    ' Then shift the long to bring the pixel into the lower 2 bits: long >> (x << 1 & $1F)
    ' Then mask off the actual pixel value: shifted long & 3
      return bitmap[noparse][[/noparse](x + y*width)>>4] >> (x<<1&$1F) & 3
    
  • Harry1Harry1 Posts: 29
    edited 2007-01-18 21:18
    okay i'll try it out. Thank you!! ^^
Sign In or Register to comment.