Re: Lightning-Fast Bitmap Cropping

new topic     » goto parent     » topic index » view thread      » older message » newer message

>Elementary lesson in Euphoria optimization, almost entirely dedicated
>to you, Mike the Spike...
>
>
>yours:
>
>global function crop_image(sequence bmp,sequence rect)
>sequence ret
>integer y
>ret = repeat(repeat(0,rect[3]-rect[1]),rect[4]-rect[2])
>y = 1
>
>for i = rect[2] to rect[4]-1 do -- To the height of the cropping rect
>     ret[y][1..rect[3]-rect[1]] = bmp[2][i][rect[1]..rect[3]-1]
>     y = y + 1
>end for
>return ret
>end function
>
>
>mine:
>
>global function crop(sequence bmp,integer x,integer y,integer
>w,integer h)
>     sequence s
>     integer x2
>     s = repeat(repeat(0,w),h)
>     x2 = x+w-1
>     for i = 1 to h do
>         s[i] = bmp[y][x..x2]
>         y += 1
>     end for
>     return s
>end function
>
>Much prettier, eh, pal?! Much faster too! I grabbed the first bitmap
>I spotted on my drive, a 320x200x256 pic, ran it through 1000
>iterations, removing a 20 pixel border from it, just for the heck of
>it. Your "Lightning-Fast", routine took 6.63 seconds, my plain effort
>just 3.49 seconds. I did not bother with any more tests, it's just not
>worth it. I hope even you can appreciate the difference. jiri
>
>Btw, your routine cheats: it does not show both the last column and
>the last row of pixels of the cropped image.;)

Jiri, I put your routine in my code, and only changed the parameters from
integers to a sequence (like my routine), now it seems that yours  is slow
after all.
Here is your routine, with the parameters set like my routine, try it out:

global function cropBitmap(sequence bmp,sequence rect)
    sequence s
    integer x2
    s = repeat(repeat(0,rect[3]),rect[4])
    x2 = rect[1]+rect[3]-1
    for i = 1 to rect[4] do
        s[i] = bmp[rect[2]][rect[1]..rect[3]]
        rect[2] = rect[2] + 1
    end for
    return s
end function


Mike The Spike
PS. Sequences are slower then integers...
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu