Structure DrawingInfoStruct
Type.l
Window.l
DC.l
ReleaseProcedure.l
PixelBuffer.l
Pitch.l
Width.l
Height.l
Depth.l
PixelFormat.l
StopDirectAccess.l
StartDirectAccess.l
EndStructure
Global FastImgOutputID.DrawingInfoStruct
Procedure ___ReleaseFastImageOutput()
If FastImgOutputID\DC:DeleteDC_(FastImgOutputID\DC):FastImgOutputID\DC=0:EndIf ; free the created memory DC
EndProcedure
Procedure ___StopDirectAccess()
ProcedureReturn FastImgOutputID\DC
EndProcedure
Procedure ___StartDirectAccess()
GetPixel_(FastImgOutputID\DC,0,0) ; make sure all GDI operations are finished
ProcedureReturn FastImgOutputID\PixelBuffer
EndProcedure
; FastImageOutput() provides a faster pixel access for 32-,24- and 15 bit images(DIBSesctions).
; However, for now only plot(x,y,color) works faster. (point(x,y) seems to be not optimized for direct memory access at the moment. You can use the PointFast() command from the E2D Userlib to get a faster point command.)
Procedure FastImageOutput(Image)
If GetObject_(ImageID(Image),SizeOf(DIBSECTION),ds.DIBSECTION)=0
ProcedureReturn 0 ; no BITMAP/DIBSECTION
EndIf
If ds\dsBm\bmBits=0
ProcedureReturn 0 ; no DIBSECTION
EndIf
FastImgOutputID\Type=7 ; allows direct memory access
FastImgOutputID\ReleaseProcedure=@___ReleaseFastImageOutput()
FastImgOutputID\PixelBuffer=ds\dsBm\bmBits+ds\dsBm\bmWidthBytes*(ds\dsBm\bmHeight-1) ;needed because the image if top down
FastImgOutputID\Pitch=-ds\dsBm\bmWidthBytes
FastImgOutputID\Width=ds\dsBm\bmWidth
FastImgOutputID\Height=ds\dsBm\bmHeight
Select ds\dsBm\bmBitsPixel
Case 32
FastImgOutputID\Depth=32
FastImgOutputID\PixelFormat=#PB_PixelFormat_32Bits_BGR
Case 24
FastImgOutputID\Depth=24
FastImgOutputID\PixelFormat=#PB_PixelFormat_24Bits_BGR
Case 16
FastImgOutputID\Depth=15
FastImgOutputID\PixelFormat=#PB_PixelFormat_15Bits
Default
ProcedureReturn 0 ; only 32-,24- and 15bit DIBSections are supported
EndSelect
MemDC=CreateCompatibleDC_(0)
If MemDC=0:ProcedureReturn 0:EndIf ; the memory DC cannot be created
SelectObject_(MemDC,ImageID(Image))
FastImgOutputID\DC=MemDC
FastImgOutputID\StopDirectAccess=@___StopDirectAccess()
FastImgOutputID\StartDirectAccess=@___StartDirectAccess()
ProcedureReturn FastImgOutputID
EndProcedure
;Test:
OpenWindow(1,0,0,600,500,"FastImageOutput Test")
CreateImage(1,600,500,32) ; only 32bit seems to be really faster...
Start=GetTickCount_()
StartDrawing(FastImageOutput(1)) ; replace this by ImageOutput(1)
For Y=0 To 499
For X=0 To 599
Plot(X,Y,X*Y)
Next
Next
StopDrawing()
Result=GetTickCount_()-Start
StartDrawing(WindowOutput(1))
DrawImage(ImageID(1),0,0)
StopDrawing()
MessageRequester("Result:",Str(Result)+" ms")
For Y=0 To 500 ;-1
For X=0 To 600 ;-1
Plot(X,Y,X*Y)
Next
Next
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
GetTickCount_() is too low-res for something this fast. When I turned the debugger off it was always showing 0 ms. So I added this routine and turned the debugger off, it executes in 5 ms vs. 193 ms normal ImageOutput():
you do you think that this difference of speed is due to the fact that FastImageOutput() is not protected against writing out of the image area ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Flype wrote:you do you think that this difference of speed is due to the fact that FastImageOutput() is not protected against writing out of the image area ?
Not possible, the checking should only be done with the Debug library ?
Structure DrawingInfoStruct
Type.l ; Type of the DC
Window.l ; Window associated to the DC (if any)
DC.l ; DC
ReleaseProcedure.l ; Address to a procedure to release the DC when StopDrawing() is called
PixelBuffer.l ; Address of the memory pixel buffer (DirectX)
Pitch.l ; Pitch
Width.l
Height.l
Depth.l
EndStructure
Dr. Dri wrote:where did you get the DrawingInfoStruct structure ?
Reverse Engineering (whitout dissasembling anything)
I just looked at the pointer which SpriteOutput() returns.