PureBasic DLL + Blitz image
Blitz3D Forums/Blitz3D Programming/PureBasic DLL + Blitz image
| ||
Hi it is possible to send a blitzimage to a purebasic dll ??? I have try some stuff but nothing ;( I have try this purebasic code ProcedureDLL Pixelate(*bank.byte) Result = CatchImage(0, *bank) Result = StartDrawing(ImageOutput() ) y = 0 #StepX = 10 StepY = Round(#StepX*Height/Width, 0) For x = 0 To Width/2-5 Step #StepX Box(x, y, Width-2*x, Height-2*y ,RGB(Random(255),Random(255),Random(255))) y + StepY ; the same as y = y + StepY Next x StopDrawing() MessageRequester("Information",Str(ImageWidth()) ,#PB_MessageRequester_Ok) EndProcedure And this blitz code Graphics 640,480,16,2 MyImage=CreateImage(256,256,1) Pixelate(MyImage) DrawImage MyIMage,0,0 WaitKey The Decls : .lib "Examples.dll" Pixelate%(bank*) |
| ||
As far as I know, the variable MyImage will not point directly to the bank of the image. You would have to use lockedpixels() to find the address. You can do this in BlitzPlus, and in B3D with the functions, that Andreas Blixt made, which adds lockedpixels() command to b3d, and posted on Blitzcoder in the showcase section. |
| ||
Thx zawran |
| ||
no problem :) |
| ||
I have made some tests and here is the code :) i hope help you :); Taille : ; Byte = 1 ; Word=2 ; Float = 4 ; Long=4 Graphics 640,480,16,2 SetBuffer BackBuffer() ;OutPut=CreateGridImage(200,200,32) MyIMage=LoadImage("K:\Blitz3D - Test\TOK Sample\samples/GALVPLAT.JPG") Output=ApplyImageEffect(MyIMage,1) While Not KeyHit(1) Cls DrawImage Output,10,10 DrawImage Output,MouseX(),MouseY() Flip Wend WaitKey End Function CreateGridImage(Width,Height,Size) MyBank=CreateImageBank(Width,Height) DLL_CreateGridImage(MyBank,BankSize(MyBank),Size) Output=BankToImage( MyBank) FreeBank MyBank Return Output End Function Function ApplyImageEffect(Image,Effect) MyBank=ImageToBank( Image) DLL_ApplyImageEffect(MyBank,BankSize(MyBank),Effect) Output=BankToImage( MyBank) FreeBank MyBank Return Output End Function Function CreateImageBank(SizeX,SizeY) bankImage = CreateBank(5) SizeOfImage =SizeX*SizeY ResizeBank bankImage, (SizeOfImage*12) + 9 ;(12 bytes per long for the image info + 9 extra bytes for header) Poke_L bankImage,0,SizeX Poke_L bankImage,4,SizeY Return bankImage End Function Function ImageToBank( bufferImage) bankImage = CreateBank(5) Bank_OldBuffer = GraphicsBuffer();get the handle for the current buffer SizeOfImage = ImageWidth(bufferImage)*ImageHeight(bufferImage) ResizeBank bankImage, (SizeOfImage*12) + 9 ;(12 bytes per long for the image info + 9 extra bytes for header) Poke_L bankImage,0,ImageWidth(bufferImage);store the width in the bank Poke_L bankImage,4,ImageHeight(bufferImage);store the height iBankPointer =8 : Steping=4 SetBuffer ImageBuffer(bufferImage) LockBuffer ImageBuffer(bufferImage) For iLoopX = 0 To ImageWidth(bufferImage)-1 For iLoopY = 0 To ImageHeight(bufferImage)-1 argb=ReadPixelFast(iLoopX,iLoopY) col_red = (ARGB Shr 16) And $ff col_green =(ARGB Shr 8) And $ff col_blue = ARGB And $ff Poke_L bankImage,ibankPointer,col_red iBankPointer = iBankPointer + steping Poke_L bankImage,ibankPointer,col_green iBankPointer = iBankPointer + steping Poke_L bankImage,ibankPointer,col_blue iBankPointer = iBankPointer + steping Next Next UnlockBuffer ImageBuffer(bufferImage) SetBuffer Bank_OldBuffer Return bankImage End Function Function BankToImage( bankImage) Width=Peek_L (bankImage,0) Height=Peek_L (bankImage,4) bufferImage=CreateImage(Width,Height) iBankPointer =8 : Steping=4 Bank_OldBuffer = GraphicsBuffer() SetBuffer ImageBuffer(bufferImage) LockBuffer ImageBuffer(bufferImage) For iLoopX = 0 To ImageWidth(bufferImage)-1 For iLoopY = 0 To ImageHeight(bufferImage)-1 Red=PeekByte (bankImage,ibankPointer) iBankPointer = iBankPointer + steping Green=PeekByte (bankImage,ibankPointer) iBankPointer = iBankPointer + steping Blue=PeekByte (bankImage,ibankPointer) iBankPointer = iBankPointer + steping WritePixelFast(iLoopX,iLoopY,ARGB(Red,Green,Blue)) Next Next UnlockBuffer ImageBuffer(bufferImage) SetBuffer Bank_OldBuffer Return bufferImage End Function Function ARGB(Red,Green,Blue) Return (blue Or (green Shl 8) Or (red Shl 16) Or ($ff000000)) End Function ;pure code ProcedureDLL Peek_L(*bank,offset) ProcedureReturn PeekL(*bank+offset) EndProcedure ProcedureDLL.f Peek_F(*bank,offset) ProcedureReturn PeekF(*bank+offset) EndProcedure ProcedureDLL.w Peek_W(*bank,offset) ProcedureReturn PeekW(*bank+offset) EndProcedure ProcedureDLL.b Peek_B(*bank,offset) ProcedureReturn PeekB(*bank+offset) EndProcedure ProcedureDLL.s Peek_S(*bank,offset) ProcedureReturn PeekS(*bank+offset) EndProcedure ProcedureDLL Poke_L(*bank,offset,value.l) PokeL(*bank+offset,value.l) EndProcedure ProcedureDLL Poke_F(*bank,offset,value.f) PokeF(*bank+offset,value.f) EndProcedure ProcedureDLL Poke_W(*bank,offset,value.w) PokeW(*bank+offset,value.w) EndProcedure ProcedureDLL Poke_B(*bank,offset,value.b) PokeB(*bank+offset,value.b) EndProcedure ProcedureDLL Poke_S(*bank,offset,value.s) PokeS(*bank+offset,value.s) EndProcedure ProcedureDLL.l DLL_ApplyImageEffect(*bank,banksize,Effect) SizeX=PeekL(*bank) SizeY=PeekL(*bank+4) TotalSize=(SizeX+SizeY*12)+9 iBankPointer =8 steping=4 If CreateImage(0, SizeX, SizeY) StartDrawing(ImageOutput()) For x=0 To SizeX-1 For y=0 To SizeY-1 r=PeekL(*bank+iBankPointer) iBankPointer = iBankPointer + steping g=PeekL(*bank+iBankPointer) iBankPointer = iBankPointer + steping b=PeekL(*bank+iBankPointer) iBankPointer = iBankPointer + steping Plot (x,y,RGB(r,g,b)) Next Next Select Effect Case 1 For x=0 To SizeX-1 Step 8 For y=0 To SizeY-1 Step 8 Line(0, y, SizeY*2, 0,RGB(0,0,0)) Line(x, 0, 0, SizeX*2,RGB(0,0,0)) Next Next EndSelect iBankPointer =8 steping=4 For x=0 To SizeX-1 For y=0 To SizeY-1 Col=Point(x,y) PokeL(*bank+iBankPointer,Red(Col)) iBankPointer = iBankPointer + steping PokeL(*bank+iBankPointer,Green(Col)) iBankPointer = iBankPointer + steping PokeL(*bank+iBankPointer,Blue(Col)) iBankPointer = iBankPointer + steping Next Next StopDrawing() FreeImage(0) EndIf EndProcedure ProcedureDLL.l DLL_CreateGridImage(*bank,banksize,GridSize) SizeX=PeekL(*bank) SizeY=PeekL(*bank+4) TotalSize=(SizeX+SizeY*12)+9 StepX=((SizeX)/GridSize) StepY=((SizeY)/GridSize) If CreateImage(0, SizeX , SizeY ) StartDrawing(ImageOutput()) For x=0 To SizeX-1 For y=0 To SizeY-1 Pos_X=Pos_X+StepX Pos_Y=Pos_Y+StepY Line(0, Pos_Y , SizeY , 0 ,RGB(255,255,0)) Line(Pos_X , 0 , 0 , SizeX ,RGB(255,255,0)) Next Next iBankPointer =8 steping=4 For x=0 To SizeX-1 For y=0 To SizeY-1 Col=Point(x,y) PokeL(*bank+iBankPointer,Red(Col)) iBankPointer = iBankPointer + steping PokeL(*bank+iBankPointer,Green(Col)) iBankPointer = iBankPointer + steping PokeL(*bank+iBankPointer,Blue(Col)) iBankPointer = iBankPointer + steping Next Next StopDrawing() FreeImage(0) EndIf EndProcedure ; Delcs file .lib "Examples.dll" Peek_L%(bank*,offset) Peek_F#(bank*,offset) Peek_W%(bank*,offset) Peek_S$(bank*,offset) Peek_B%(bank*,offset) Poke_L(bank*,offset,value%) Poke_F(bank*,offset,value#) Poke_W(bank*,offset,value%) Poke_S(bank*,offset,value$) Poke_B(bank*,offset,value%) DLL_ApplyImageEffect%(bank*,size,effect) DLL_CreateGridImage%(bank*,size,step) GetImageWidth%(bank*) GetImageHeight%(bank*) |
| ||
Don't know if you know, but with lockedpixels() you can actually peek and poke into image buffer directly from blitz. |
| ||
How ?? do you think it's more speed ? |
| ||
Peeking & Poking from a DLL works out about the same speed. Filax: If it's of any use, PeekMemInt(ImageBuffer(img)+12) & PeekMemInt(TextureBuffer(tex)+12) are both valid IDirectDrawSurface pointers and can be passed to a DLL and manipulated with the DX7SDK. You can do surface Blits, access mipmaps, all kinds of stuff. Tom |
| ||
The attempts I did with purebasic dll and blitz pointed towards it being just as fast to do the pixel manipulations directly from blitz with the lockedpixels() command and peek/poke. Don't know if a dll made with C++ would help, as I don't know how to program in that language. I will find an example of using the peek/poke directly on an imagebuffer when I get home, and post it. |
| ||
i use powerbasic with inline asm for that and it is realy fast |
| ||
This isn't the best effect ever, but it shows how you can poke directly into imagebuffers: |
| ||
Panno: Can you come on Irc later tonight? (you the guy into eyetoy/webcam stuff right?) I got something I want you to test. I have a DirectShow based Webcam DLL working that grabs direct to a BB image ( <2ms to capture a 320*240 frame ), and, no crappy extra webcam windows open! You can also pop open the native Filter/Pin windows to adjust your stream settings e.t.c I'll be on Irc from 7pm+ tonight if you can make it there. Or mail me, address is in my profile. Cya! Tom 'Scouse' @ irc.blitzed.org #blitzbasic |
| ||
ok tom send u a mail and meet u in #blitzbasic this night |
| ||
Anybody have the fonction LockedPixel ? i have try to download her from blitzcoder but the link seem down ? |
| ||
http://zac-interactive.dk/temp/lockedpixels.zip |
| ||
Thanks :) |