Image Resizeing

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

Moderators: Shine, Insert_witty_name

Post Reply
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Image Resizeing

Post by romero126 »

Is there any easy way to resize an image down to a certain specified size?

Possibly a 3d way to do that?
cools
Posts: 46
Joined: Sat Mar 04, 2006 12:57 pm

Post by cools »

There is a way to do it. I think someone posted this function, I just modified it a bit.

Code: Select all

function scaleImage(newX, newY, theImage)
newImage = Image.createEmpty(newX, newY)
	for x = 0, newX do
		for y = 0, newY do
			newImage:blit(x,y , theImage, math.floor(x*(theImage:width()/newX)),math.floor(y*(theImage:height()/newY)), 1, 1)
		end
	end
	return newImage
end
image = Image.load("blah")
scaledimage = scaleImage(newx,newy,image)
If you wanted to use the Gu/Gum functions to scale the image you would need to add sceGumScale() to lua player.

Code: Select all

static int lua_sceGumScale(lua_State *L) {
	int argc = lua_gettop(L); 
	if (argc != 3) return luaL_error(L, "wrong number of arguments"); 
	ScePspFVector3 v;
	v.x = luaL_checknumber(L, 1);
	v.y = luaL_checknumber(L, 2);
	v.z = luaL_checknumber(L, 3);
	sceGumScale(&v);
	return 0;
}

and {"scale", lua_sceGumScale}, in the correct spot
and then to scale the image, lets say 2x, in lua after your regular 3d stuff:

Code: Select all

Gum.scale(2,2,1)
It will resize the x and y by 2 and keep the z the same.

You can expect to see the function in lua player mod 4.
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

Thanks!
Post Reply