Texture help
Blitz3D Forums/Blitz3D Beginners Area/Texture help
| ||
I will use a simply 64,64 .bmp Image and make fast a copy of this image in the half colour values as the original is. Can anybody help me, i use ReadPixelFast and WritePixelFast. How i can read the colour values of the Pixels and change them?? thx for help Blacky |
| ||
oldCol = ReadPixelFast newcol = 0 for i = 0 to 2 val = ((oldcol shr 2^(i +3) ) and $FF) shr 1 ; shr 1 = /2 newcol = newcol + (val shl 2^(i +3) ) next WritePixelFast newcol ... |
| ||
Use any image ; Load and draw an image on to the screen - can be anything pic=LoadImage("test.bmp") DrawImage pic,0,0 ; Initialise an array big enough to fit all the color information of the screen Dim pix(GraphicsWidth(),GraphicsHeight()) ; Lock buffer before using ReadPixelFast LockBuffer ; ; Use ReadPixel to get all the color information of the screen For y=0 To GraphicsHeight()-1 For x=0 To GraphicsWidth()-1 pix(x,y)=ReadPixelFast(x,y) Next Next ; Lock buffer after using ReadPixelFast UnlockBuffer ; Lock buffer before using WritePixelFast LockBuffer ; Use WritePixel to redraw the screen using the color information we got earlier For y=0 To GraphicsHeight()-1 For x=0 To GraphicsWidth()-1 WritePixelFast x,y,pix(x,y) Next Next ; Unlock buffer after using WritePixelFast UnlockBuffer WaitKey() |
| ||
; Load and draw an image on to the screen - can be anything pic=LoadImage("test.bmp") DrawImage pic,0,0 ; Initialise an array big enough to fit all the color information of the screen Dim pix(GraphicsWidth(),GraphicsHeight()) ; Lock buffer before using ReadPixelFast LockBuffer ; ; Use ReadPixel to get all the color information of the screen For y=0 To GraphicsHeight()-1 For x=0 To GraphicsWidth()-1 pix(x,y)= ReadPixelFast(x,y) Next Next ; Lock buffer after using ReadPixelFast UnlockBuffer ; Lock buffer before using WritePixelFast LockBuffer ; Use WritePixel to redraw the screen using the color information we got earlier For y=0 To GraphicsHeight()-1 For x=0 To GraphicsWidth()-1 newCol = 0 for i = 0 to 2 newCol = newCol +(( ( (pix(x,y) shr 2^(i +3) ) and $FF ) shr 1 ) shl 2^(i +3) ) next WritePixelFast x,y, newCol Next Next ; Unlock buffer after using WritePixelFast UnlockBuffer WaitKey() As shown in my code above already |
| ||
many thx for help Dreamora, but if you look at the image after is dark blue allways and its not like a shadow of the pic with the half brightness. What is wrong here? i have enclosed a code who do this well but its very very slow. ; GetColor Example Graphics 1280,1024 SetBuffer BackBuffer() pic=LoadImage("C:\Programme\Blitz3D\Samples\Blitz 3D Samples\1\Pics\Rüstung\test.bmp") DrawImage pic,0,0 Dim pix(1200,1200,2) For y=0 To 250 For x=0 To 250 GetColor(x,y) pix(y,x,0) = ColorRed() pix(y,x,1) = ColorGreen() pix(y,x,2) = ColorBlue() Next Next For y = 0 To 250 For x = 0 To 250 Color pix(y,x,0)/2,pix(y,x,1)/2,pix(y,x,2)/2 : Plot 0+x,0+y Next Next Flip While Not KeyHit(1) Wend |
| ||
Was an error in my code. Retry now should work. |
| ||
Sorry i have tried your code, but is the same as before. Look at my code with the slow getcolor() it will do fine. Something must be wrong, maybe you have done a mistake. |
| ||
stupid me, copied the wrong thing over. now it works |
| ||
yes its works now. First of all many thx for the fast help. My last questions to understand the code. Can you explain me a little bit the formular u used That i can understand what goes on |
| ||
shr will shift the bits of the color ( stored as RGB in an image) Each color component has a length of 8 Bit After you shift it, you need to cut out only the color of interest, this is done by "and $FF", this will make anything but the last byte (8Bit) 0 The SHR 1 actually is just a different way to write / 2 (int) The SHL afterwards just puts the before modified bits back in the correct position of the Int that represents the color 2^(3+i) : 2^3 = 8, the (3+i) above there is the same as (i*8) straight there so you potentially could toy with that directly. could potentially even be faster *forgot that Blitz3D is faster at multiplication than ^ with 3 and higher for the potence* |