Page 1 of 5

[Windows] 2DDrawing commands with AntiAliasing through GDI+

Posted: Sun Jul 24, 2011 6:20 am
by Danilo
Image Image Image Image Image Image Image Image Image Image Image Image Image Image

gDrawing is an Include for Windows that replaces the old Win95-Style PureBasic 2DDrawing commands
with antialiased versions through GDI+.

It has the following drawing functions:
gClear(), gPlot(), gBox(), gRoundBox(), gLine(), gLineXY(), gPie(), gPieXY(),
gArc(), gArcXY(), gEllipse(), gEllipseXY(), gCircle(), gCircleXY(), gBezier(),
gCurve(), gClosedCurve(), gTriangle(), gPoly(),
gDrawImage(), gDrawAlphaImage(), gDrawClippedImage(),
gDrawText(), gDrawRotatedText(), gDrawFormattedText() and more...

gDrawing includes Clipping with gClipBox() and gClipPath().

With gDrawing you can rotate, scale, move and shear all
drawing operations.

gDrawing includes the command gSetUnit() to set an unit like
#UnitMillimeter or #UnitInch to draw at the same size on your
screen and on your printer.

Some demos are included.

DOWNLOAD: gDrawing_v0.85b2.zip or gDrawing_v0.85b2.zip (89k)

Feedback welcome.

The 64bit Bug has been fixed with PureBasic 4.60 and everything works fine now, PB4.60+ (x86 & x64).

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Sun Jul 24, 2011 3:28 pm
by VB6_to_PBx
amazing Code , :shock:
thanks !

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Mon Jul 25, 2011 2:47 pm
by Danilo
VB6_to_PBx wrote:amazing Code , :shock:
thanks !
Thank you too! :)

Its only v0.80 now. Still some things to do and at the end
there should be a documentation.
Filenames and some comments are in german right now,
so just take it as a preview. 'Beispiel' = Example. ;)

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Mon Jul 25, 2011 3:07 pm
by luis
It's really nice, I love antialiasing.... thank you and yes I hope in some brief doc in english if possible :)

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Mon Jul 25, 2011 3:47 pm
by djes
Yeah, it's great!

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Mon Jul 25, 2011 4:28 pm
by venom27
Congratulations on this code of good work. 8)
sorry for the translation I am French.

good luck







@++

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Mon Jul 25, 2011 5:03 pm
by Danilo
Thank you all for the nice comments.

I just added "english gDrawing.chm" to my OneNote gDrawing todo list. ;)

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Tue Jul 26, 2011 8:16 am
by Kwai chang caine
Great..thanks for sharing 8)

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Tue Jul 26, 2011 9:38 am
by ar-s
Very good ! thanks a lot !

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Tue Jul 26, 2011 10:04 pm
by [blendman]
this is just excellent and great !
Thank you very much :D

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Thu Jul 28, 2011 2:22 am
by Poshu
Hell yeah!
Is it (or could it be) GPU accelerated?

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Tue Aug 09, 2011 10:13 am
by ozzie
Functionally this is great - I want to be able to rotate an image and gDrawing includes a facility to do this.:) But the performance of alphablending is an issue for me.:( For a slideshow I want to be able to crossfade between images and I have the following procedure that does this:

Code: Select all

Procedure blendPictures(nVidPicTarget, nBlendFactor)
  Protected fBlendFactor.f
  With grVidPicTarget(nVidPicTarget)
    If nBlendFactor <> \nPrevBlendFactor
      If IsImage(\nSecondaryImageNo)
        CompilerIf #PB_Compiler_OS = #PB_OS_Windows
          fBlendFactor = nBlendFactor / 255
          If gStartDrawing(CanvasOutput(\nTargetCanvasNo))
              gDrawImage(ImageID(\nPrimaryHoldImageNo), 0, 0)
              gDrawAlphaImage(ImageID(\nSecondaryImageNo), 0, 0, -1, -1, fBlendFactor)
            gStopDrawing()
          EndIf
        CompilerElse
          If StartDrawing(CanvasOutput(\nTargetCanvasNo))
              DrawImage(ImageID(\nPrimaryHoldImageNo), 0, 0)
              DrawAlphaImage(ImageID(\nSecondaryImageNo), 0, 0, nBlendFactor)
            StopDrawing()
          EndIf
        CompilerEndIf
      EndIf
      \nPrevBlendFactor = nBlendFactor
    EndIf
  EndWith
EndProcedure
This procedure is called from a dedicated thread which I've set to priority 31. Prior to using gDrawing I just had the PB 2D Drawing commands, and that was working well but I was hoping I could get an even smoother fade using gDrawing, but the gDrawing crossfade is much more stilted. With images that are full screen on a large monitor (1920x1200) I have found that the above procedure takes on average about 50ms using the PB 2D Drawing commands, but around 700ms using the gDrawing commands. Is there something I can do to improve the performance with gDrawing, or shall I stay with PB 2D Drawing for crossfades?

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Wed Aug 10, 2011 6:14 am
by Danilo
ozzie wrote:With images that are full screen on a large monitor (1920x1200) I have found that the above procedure
takes on average about 50ms using the PB 2D Drawing commands, but around 700ms using the gDrawing commands.
Is there something I can do to improve the performance with gDrawing, or shall I stay with PB 2D Drawing for crossfades?
Defaults are higher quality settings for Antialiasing, Compositing Mode etc.

If you don't want quality, you can reduce it:

Code: Select all

If gStartDrawing(...
   gSetAntialiasMode     ( #AntialiasMode_None          )
   gSetInterpolationMode ( #InterpolationModeLowQuality )
   gSetCompositingQuality( #CompositingQualityHighSpeed )
   ...
If your Images are static (they dont change), you could also use

Code: Select all

init:
img = gBufferImage(*ImageID)

;...
later:
gDrawImage(img,...
gDrawAlphaImage(img,...
gDrawClippedImage(img,...

if_you_want:
gFreeImage(img) ; all gImages are freed automatically at gEnd()
and after that you use img with gDrawImage etc.
gBufferImage creates a GDI+ image and buffers it, so with this way it is not
needed internally to convert PB images to GDI+ images on every function call.

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Wed Aug 10, 2011 8:21 am
by ozzie
Those suggestions certainly improved the performance - I implemented all of those recommendations - but it's still taking around 100ms per iteration of the blendPictures() procedure. That's significantly better than the 700ms I was getting before, but if I revert to PB 2D Drawing commands I get around 55ms per iteration. All tests with a compiled executable, not using debugger, and with a rebooted Windows 7 laptop.

Re: [Windows] 2DDrawing commands with AntiAliasing through G

Posted: Sat Aug 13, 2011 8:52 pm
by Zach
Personally I'd like to see something that uses the newer 2D Drawing stuff, I forgot what it is called but its hardware accelerated etc through DirectX I think, and supposedly MS is pushing developers to use this newer stuff, since IIRC GDI was crippled etc by removing hardware acceleration. (A lot of GDI apps perform poorly on Windows 7 for instance).


But that aside, this is a nice effort. Thank you for sharing 8)