The GetImagePitch function returns the Pitch of a selected image. The pitch is the number of bytes that a single row of pixels uses. This information is used to calculate the Y coordinate when manually rendering pixels to a surface.
FACTS:
* The GetImagePtr(), () & GetImageDepth() functions are used to manually read/write pixels to/from PlayBASIC images.
* The image must be locked before you manually access it ! See (LockBuffer)
Mini Tutorial:
This example creates four images then manually Pokes pixels to each of them.
Cls RGB(0,0,255) ; create four images in each in a different video format w=128 h=256 CreateFXImageEx 1,w,h,15 ; 15bit version CreateFXImageEx 2,w,h,16 ; 16bit version CreateFXImageEx 3,w,h,24 ; 24bit version CreateFXImageEx 4,w,h,32 ; 32bit version ; Draw them to the screen Xpos=60 Ypos=50 For i=1 To 4 FillImage(i) Text Xpos,Ypos, "Address:"+Str$(GetImagePtr(i)) Text Xpos,Ypos+20," Pitch:"+Str$(GetImagePitch(i)) Text Xpos,Ypos+40," Depth:"+Str$(GetImageDepth(i)) DrawImage i,Xpos,Ypos+60,false Xpos=Xpos+w+40 Next ; show the screen and wait for user to press a key Sync WaitKey Function FillImage(ThisImage) RenderToImage ThisImage LockBuffer Address =GetImagePtr(ThisImage) Pitch =GetImagePitch(ThisIMage) Depth =GetImageDepth(ThisImage) Colour=0 For ylp=0 To GetImageHeight(ThisImage)-1 Colour2=colour For xlp=0 To GetImageWidth(ThisImage)-1 PokePixel(Address,Pitch,Depth,Xlp,Ylp,Colour2) Colour2=Colour2+1 Next Colour=RgbAlphaAdd(Colour,$020101) Next UnLockBuffer RenderToScreen EndFunction ;*=------------------------------------------------------=* ; >> Generic Poke Pixel Routine << ;*=-----------------------------------------------------=* Psub PokePixel(Address,Pitch,Depth,Xpos,Ypos,Colour) If Address<>0 Select Depth Case 15 ; 16bit RGB 555 format R=LSL16((RgbR(colour) & $f8),7) G=LSL16((RgbG(colour) & $f8),2) B=LSR16((RgbB(colour) & $f8),3) PokeWord Address+(ypos*pitch)+(xpos*2), R | G | B Case 16 R=LSL16((RgbR(colour) & $f8),8) G=LSL16((RgbG(colour) & $fc),3) B=LSR16((RgbB(colour) & $f8),3) PokeWord Address+(ypos*pitch)+(xpos*2), R | G | B Case 24 ; 24bit RGB's R=RgbR(colour) G=RgbG(colour) B=RgbB(colour) Address=Address+(Ypos*pitch)+(xpos*3) PokeByte Address,R PokeByte Address+1,G PokeByte Address+2,B Case 32 ; 32bit RGB either XRGB (-888) format or (ARGB 8888) format PokeInt Address+(Ypos*Pitch)+(Xpos*4),COlour EndSelect EndIf EndPsub |
|