March 28, 2024, 01:32:58 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


ReadPixel

Started by AndrewB, December 14, 2006, 09:47:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AndrewB

December 14, 2006, 09:47:35 PM Last Edit: December 15, 2006, 12:34:53 AM by AndrewB
Hi all, can someone help me with ReadPixel please?

What do I need to do to split the return value up into the R, G and B channels?
So far, I have..

   red = col&255
   blue = col/0x10000

which I found in the Morphing Dots demo but how does that work? Particularly the 0x10000.

thanks,
-andrew


Additionally :

I've combined the SaveBitmap() include to save out the contents of a DX window which works perfectly however, can I save the contents out to a bitmap on a full screen dx window?



Haim

the color value is constructed of the three components in an ascending order of significance: R (nits 0-7), G( bits 8-15) and
B(bits(16-23).

Color & 255 serves to mask out the entire value save for the least significant byte - the value of R
0x10000 is 2 to the power of 16 (2^16) in Hex. So dividing by that number gets rid of the 16 least significant bytes and causes the rest of the bits to "shift" to the right 16 positions.
This is the way to get the next color component value in the rightmost (least significant) byte).

I hope this helps.

Haim



GWS

Don't know if this helps:

RGB colors can be set using the RGB function:

def clr as int
clr = RGB(Red, Green, Blue)ÂÃ,  where the color components range from 0 to 255 (or in Hexadecimal: 00 to FF)

The color can also be expressed in Hexadecimal as 0xBBGGRRÂÃ,  (where BB is the hex value of the blue component, GG the green, andÂÃ,  RR the red)ÂÃ,  ÂÃ,  Note the reversal of the Blue and Red components.

So 0x0 (or just 0) = BlackÂÃ,  ÂÃ,  0xFFFFFF = WhiteÂÃ,  ÂÃ, 0x00FF00 = GreenÂÃ,  0xAAAAAA = Gray
(In fact whenever all three component values are equal, you will get a shade of Gray)

An RGB color can also be specified as an integer value using:

def clr as int
clr = Blue * 65536 + Green * 256 + RedÂÃ,  (where Blue is the integer value you would use in the RGB function, and so on)

You can extract the RGB integer values from an integer color value using:

def r, g, b as int
r = clr & 255
g = (clr / 256) & 255
b = (clr / 65536) & 255

best wishes, :)

Graham
Tomorrow may be too late ..

AndrewB

Thanks very much for the explaination guys, I'm used to RGB and HSV settings, but hex? - i'm getting full colour now  ;D


-ab

AndrewB

Hello again, Just as a continuation of this thread, I have another query...  ;D

I am using EB to do a bunch of image processing for a job we have on at the moment - it's working out fine and is super fast when reading and writing pixels between buffers over a sequence of 2000 frames. (120,787,200 pixels in under 2.5 minutes!)

I am also using the SaveBitmap() function which I realised can grab any screen size and save it - which is awesome for what I need, however, am I right in saying that even though you open a window and attach a DX window that is twice the size of your maximum screen resolution, you still can't write pixels to that 'off screen' area?

I have an alternate method if this is the case, but it requires some extra fiddling about.  ;)

cheers for the ongoing,
-ab





Ionic Wind Support Team

Yes.  You can write to the entire DX buffer
Ionic Wind Support Team

AndrewB

I should have posted an example... :-[  This is just to show what I mean. Check the _saved.bmp in the start path




$include "savebitmap.inc"

Def win:WINDOW
Def dxX, dxY:INT

dxX = 4200
dxY = 3000

OpenWindow win,0,0,dxX, dxY,@NOAUTODRAW|@SIZE,0,"Caption",&handler

If AttachScreen(win, dxX, dxY, 0) < 0
    MessageBox 0,"Error creating screen","Noooooooooo"
    END
End If

FillScreen Rgb(30,30,30)
Flip

For zz = 0 to 20000
WritePixel Rand(1,dxX), Rand(1,dxY),Rgb(Rand(0,255),Rand(0,255),Rand(0,255))
Next zz

Flip

SaveBitmap(GetStartPath + "_saved.bmp",win,0,0,dxX,dxY)

CloseWindow win
END

Sub handler
End Sub






Ionic Wind Support Team

DirectX clips the buffer to the client area of the window.  The SaveBitmap routine will only work properly with visible portions of the client area as a blit won't copy invalid areas.  I am surprised you get anyting actually, I can't create a bitmap that size on my system ;)

Paul.



Ionic Wind Support Team

AndrewB

 ;D The work machines here are beasts 8)

Shame about the buffer clipping but I've gone with my original tiling plan and all remains well. The 2D commands set is awesome, it's my first time using them.

Thanks guys.