[Windows] 2DDrawing commands with AntiAliasing through GDI+

Share your advanced PureBasic knowledge/code with the community.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

[Windows] 2DDrawing commands with AntiAliasing through GDI+

Post 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).
Last edited by Danilo on Wed Sep 17, 2014 7:00 am, edited 7 times in total.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

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

Post by VB6_to_PBx »

amazing Code , :shock:
thanks !
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

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

Post 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. ;)
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post by luis »

It's really nice, I love antialiasing.... thank you and yes I hope in some brief doc in english if possible :)
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

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

Post by djes »

Yeah, it's great!
User avatar
venom27
User
User
Posts: 10
Joined: Mon Sep 14, 2009 5:30 pm
Location: . <------ ici
Contact:

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

Post by venom27 »

Congratulations on this code of good work. 8)
sorry for the translation I am French.

good luck







@++
Windows 10 x64, PureBasic 5.71 Beta 1 x86 & x64
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

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

Post by Danilo »

Thank you all for the nice comments.

I just added "english gDrawing.chm" to my OneNote gDrawing todo list. ;)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

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

Post by Kwai chang caine »

Great..thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 344
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

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

Post by ar-s »

Very good ! thanks a lot !
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
User avatar
[blendman]
Enthusiast
Enthusiast
Posts: 297
Joined: Thu Apr 07, 2011 1:14 pm
Location: 3 arks
Contact:

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

Post by [blendman] »

this is just excellent and great !
Thank you very much :D
Poshu
Enthusiast
Enthusiast
Posts: 459
Joined: Tue Jan 25, 2005 7:01 pm
Location: Canada

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

Post by Poshu »

Hell yeah!
Is it (or could it be) GPU accelerated?
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

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

Post 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?
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

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

Post 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.
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

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

Post 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.
Zach
Addict
Addict
Posts: 1675
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

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

Post 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)
Post Reply