lateropatero
2005-11-16 14:05:55 UTC
Hi folks,
I'm something of a PB newcomer, so I'm sorry if I'm missing something
obvious here. I've written a proggram that loads a bitmap from a path
and reads RGB values from individual pixels in that Bitmap using GET
PIXEL. I can't figure out how to break the result of the GET PIXEL
operation up into its individual Red, Green, Blue values, so I can
assign them to individual variables like Redvar, Greenvar, Bluevar and
perform math operations with them before recomposing the processed
RGB() and writing it back to the pixel. Done it in other programming
languages but I can't figure out the syntax to get R, G, B as
individual integers from the GET PIXEL result in Powerbasic.
Also tried the DIB way as suggested in the helpfile example:
---------------------------------------------------------------------------------------------
' Change all red pixels to blue
LOCAL PixelPtr AS LONG PTR
GRAPHIC GET BITS TO bmp$
xsize& = CVL(bmp$,1)
ysize& = CVL(bmp$,5)
PixelPtr = STRPTR(bmp$) + 8
FOR i& = 1 TO xsize& * ysize&
IF @PixelPtr = BGR(%red) THEN @PixelPtr = BGR(%blue)
INCR PixelPtr
NEXT
GRAPHIC SET BITS bmp$
---------------------------------------------------------------------------------------------
-
Works fine (and fast!) but again, how do I go from the result
@PixelPtr to individual Red, Green, Blue values that I can assign to my
Redvar, Greenvar, Bluevar etc variables as 0 - 255 Integer values? The
reverse is a no brainer (e.g. RGB(Redvar, Greenvar, Bluevar).
Any help or pointers would be much appreciated. =}
I'm something of a PB newcomer, so I'm sorry if I'm missing something
obvious here. I've written a proggram that loads a bitmap from a path
and reads RGB values from individual pixels in that Bitmap using GET
PIXEL. I can't figure out how to break the result of the GET PIXEL
operation up into its individual Red, Green, Blue values, so I can
assign them to individual variables like Redvar, Greenvar, Bluevar and
perform math operations with them before recomposing the processed
RGB() and writing it back to the pixel. Done it in other programming
languages but I can't figure out the syntax to get R, G, B as
individual integers from the GET PIXEL result in Powerbasic.
Also tried the DIB way as suggested in the helpfile example:
---------------------------------------------------------------------------------------------
' Change all red pixels to blue
LOCAL PixelPtr AS LONG PTR
GRAPHIC GET BITS TO bmp$
xsize& = CVL(bmp$,1)
ysize& = CVL(bmp$,5)
PixelPtr = STRPTR(bmp$) + 8
FOR i& = 1 TO xsize& * ysize&
IF @PixelPtr = BGR(%red) THEN @PixelPtr = BGR(%blue)
INCR PixelPtr
NEXT
GRAPHIC SET BITS bmp$
---------------------------------------------------------------------------------------------
-
Works fine (and fast!) but again, how do I go from the result
@PixelPtr to individual Red, Green, Blue values that I can assign to my
Redvar, Greenvar, Bluevar etc variables as 0 - 255 Integer values? The
reverse is a no brainer (e.g. RGB(Redvar, Greenvar, Bluevar).
Any help or pointers would be much appreciated. =}