how can i read a bitmap buffer directly instead of doing point/plot?
i'd like to still be able to do an X and Y for loop but without having to use the aforementioned slow routines.
my image was created using CreateImage so i have a valid handle to work with, i just need to know how to go about this in a nice way. im sure its got something to do with GetDIBits() but im not certain.
thanks
reading a bitmap buffer instead of point/plot
-
- Enthusiast
- Posts: 480
- Joined: Thu Jul 27, 2006 4:06 am
reading a bitmap buffer instead of point/plot


-
- Enthusiast
- Posts: 480
- Joined: Thu Jul 27, 2006 4:06 am
It's all good but the examples make use of peek/poke and im trying to avoid any calls. ideally i would like to either keep the 2 loops or just do 1 loop for the entire run and then whenever i want to be able to retrieve the x and y position out of that given iteration / offset. any examples?
edit: I know that given x and y i can get the linear offset by doing y*width+x but how do i do the opposite? (retrieve x and y from the offset)
edit2: perhaps doing x = (i % Width) : y = (i / Height) ? but how can i avoid the % operator?
edit: I know that given x and y i can get the linear offset by doing y*width+x but how do i do the opposite? (retrieve x and y from the offset)
edit2: perhaps doing x = (i % Width) : y = (i / Height) ? but how can i avoid the % operator?


- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- Joakim Christiansen
- Addict
- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
Re: reading a bitmap buffer instead of point/plot
This works great:superadnim wrote:how can i read a bitmap buffer directly instead of doing point/plot?
Code: Select all
image = CreateImage(#PB_Any,640,480,32)
imageID = ImageID(image)
GetObject_(imageID,SizeOf(BITMAP),@bmp.BITMAP)
imageSize = bmp\bmWidthBytes * bmp\bmHeight
*bits = bmp\bmBits
For x=0 To 640-1
For y=0 To 480-1
pos = (y * bmp\bmWidth + x) << 2
color = PeekL(*bits+pos)
Next
Next
I also wonder about that...edit: I know that given x and y i can get the linear offset by doing y*width+x but how do i do the opposite? (retrieve x and y from the offset)
I like logic, hence I dislike humans but love computers.
Re: reading a bitmap buffer instead of point/plot
As Kaeru indicated...Joakim Christiansen wrote:I also wonder about that...superadnim wrote:edit: I know that given x and y i can get the linear offset by doing y*width+x but how do i do the opposite? (retrieve x and y from the offset)
Code: Select all
pixel = byteOffsetIntoPixelData >> 2
y = pixel / bmp\bmWidth
x = pixel % bmp\bmWidth
Or...
Code: Select all
y = byteOffsetIntoPixelData / bmp\bmWidthBytes
x = (byteOffsetIntoPixelData % bmp\bmWidthBytes) >> 2
I may look like a mule, but I'm not a complete ass.
for 32bit dib using the CopyImageToMemory routine linked a few posts above
Code: Select all
*px.LONG
*px = *mem + ((x + (y * width)) << 2)
R=*px\l & $FF
G=*px\l >> 8 & $FF
B=*px\l >> 16 & $FF