Comparison of image rotation methods

Discussions related to graphics (2D and 3D), animation and games programming
RichardRussell

Comparison of image rotation methods

Post by RichardRussell »

I don't claim that this is very scientific, but I've attempted to compare the performance of GFXLIB2 (specifically the PlotRotateScaleBilinear module) and GDIPLUS (specifically the GdipDrawImageFX function) for plotting rotated images, with both using bilinear interpolation. The test image was a 256x256 pixel PNG with alpha channel (so not all pixels end up being plotted); I compared the times for plotting the image 10000 times using each method, at angles from 0 to 360°.

The results, for what it's worth, were:

Code: Select all

GFXLIB2: 941 cs
GDIPLUS: 866 cs
suggesting that GDI+ is fractionally faster, but probably not with much statistical significance. The code I used was as follows; you may have your own views on its legitimacy:

Code: Select all

      REM Program to compare performance of GFXLIB2 and GDIPLUS with image rotation
      REM As a proxy for GFXLIB2 the program uses PROC_gfxPlot2 from BOX2DGFX (this
      REM is effectively the same code as in GFXLIB2's PlotRotateScaleBilinear.bbc)
      REM and for GDI+ it uses PROC_imgPlot from IMGLIB which is also Bilinear mode

      VDU 23,22,640;500;8,16,16,128

      REM Load libraries:
      INSTALL @lib$ + "BOX2DGFX"
      INSTALL @lib$ + "IMGLIB"

      img$ = "C:\users\richard\onedrive\bbcbasic\sdl32\source\bbc256x.png"

      REM GFXLIB2 method:
      PROC_gfxInit(g{}, 640, 500, 1.0)

      PROC_gfxLoad(i{}, img$, 1.0)

      TIME = 0
      FOR a = 0 TO 2 * PI STEP 2 * PI / 10000
        PROC_gfxPlot2(g{}, i{}, 320, 250, a)
      NEXT
      t1% = TIME
      SYS "InvalidateRect", @hwnd%, 0, 0
      *REFRESH

      PROC_gfxExit

      REM GDIPLUS method:
      PROC_imgInit

      i% = FN_imgLoad(img$)

      TIME = 0
      FOR a = 0 TO -360 STEP -360 / 10000
        PROC_imgPlot(i%, 640, 500, 1.0, a, FALSE)
      NEXT
      t2% = TIME
      SYS "InvalidateRect", @hwnd%, 0, 0
      *REFRESH

      PROC_imgExit

      PRINT "GFXLIB2: "; t1%
      PRINT "GDIPLUS: "; t2%
rotate_compare.png
You do not have the required permissions to view the files attached to this post.