10.03.2019 - Round 1 results of our "A Love Letter For FreeBASIC" game dev competition have been published. Please be sure to check the results thread: http://games.freebasic.net/forum/index.php?topic=629.0. Don't forget that the competition is continuing with a round 2, lasting till 29th of April, 300 USD first prize. Stay tuned!

Author Topic: Scale2x routine in high level language.  (Read 3397 times)

Bermex

  • Amoeba
  • *
  • Posts: 1
    • View Profile
    • Email
Scale2x routine in high level language.
« on: June 19, 2012, 12:08:50 AM »
  This code is a Scale2x routine programed only in Free Basic using high level language code optimized and Free Basic graphic library.

Sub copyx2(x As Short, y As Short, spr As Any Ptr, scr As Any Ptr)
    Dim As Integer w, h, size
    Dim As Integer pitch, bypp
    Dim As Any Ptr pixels, pixelsx, pixelsy
    ImageInfo( spr, w, h, bypp, pitch, pixels )
    Dim As Integer sw, sh
    Dim As Integer spitch, sbypp
    Dim As Any Ptr spixels, spixelsx, spixelsy
    If scr <> 0 Then
        ImageInfo( scr, sw, sh, sbypp, spitch, spixels )
    Else
        Screeninfo sw, sh, , sbypp, spitch
        spixels  = Screenptr()
    EndIf                 
    Dim As UInteger Ptr spixpointer1, spixpointer2, spixpointer3, spixpointer4
    Dim pixpointer As UInteger Ptr
    Dim As Integer i, j
    spixels += x*sbypp + y*spitch
    pixelsy = pixels
    spixelsy = spixels
    For i=0 To h-1 Step 1
        spixelsx = spixelsy
        pixelsx = pixelsy
        For j=0 To w-1 Step 1
            pixpointer = pixelsx
            spixpointer1 = spixelsx
            spixpointer2 = spixelsx+sbypp
            spixpointer3 = spixelsx+spitch
            spixpointer4 = spixelsx+sbypp+spitch
            *spixpointer1 = *pixpointer
            *spixpointer2 = *pixpointer
            *spixpointer3 = *pixpointer
            *spixpointer4 = *pixpointer
            spixelsx = spixelsx+sbypp+sbypp
            pixelsx = pixelsx+bypp
        Next j     
        spixelsy = spixelsy+spitch+spitch
        pixelsy = pixelsy+pitch
    Next i 
End Sub


  Simply to get high speed use "sbypp" and "spitch" for the target image and "bypp", "pitch" for source image. Adding this to target and source pointers. "sbypp" and "bypp" in the inner loop (columns) and "spitch" and "pitch" in the outter loop (rows).