[Lua Functions] Image Rotate & Image Scale

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
arrggg
Posts: 11
Joined: Thu Sep 29, 2005 10:07 am

[Lua Functions] Image Rotate & Image Scale

Post by arrggg »

Here's some functions I came up with; I hope someone finds them useful.

Code: Select all

function rotateImage(theImage)
   newImage = Image.createEmpty(theImage:height(), theImage:width())
   for x = 1, theImage:width() do
      for y = 1, theImage:height() do
         newImage:blit(y, x, theImage, x, y, 1, 1)
      end
   end
   return newImage
end -- rotateImage

function scaleImage(newX, newY, theImage)
   newImage = Image.createEmpty(newX, newY)
   for x = 1, newX do
      for y = 1, newY do
         newImage:blit(x,y , theImage, math.floor(x*(theImage:width()/newX)),math.floor(y*(theI  mage:height()/newY)), 1, 1)
      end
   end
   return newImage
end --scaleImage

--main program
smile = Image.load("smiley.png")
screen:blit(0, 0, smile)
screen:blit(100, 0, rotateImage(smile))
screen:blit(0,100, scaleImage(100,150, smile))
screen:flip()
screen.waitVblankStart(600)
Zenurb
Posts: 106
Joined: Fri Sep 30, 2005 8:33 am
Location: United Kingdom
Contact:

Post by Zenurb »

Probably get very slow with big images.
Proud Dvorak User
US 1.5 PSP (Original)
arrggg
Posts: 11
Joined: Thu Sep 29, 2005 10:07 am

Post by arrggg »

it's not that bad really.
Post Reply