Loading a large image?

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

Moderators: Shine, Insert_witty_name

Post Reply
tmaster
Posts: 11
Joined: Fri Oct 21, 2005 5:32 am
Location: Ireland

Loading a large image?

Post by tmaster »

I want to be able to load a map on to the screen.
image size is around 5000 by 5000.
i know the max size image is only 512 by 512.

how do i go about loading my map and be able to scroll around the map?
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Use your scissors. ;)

Can't resist.

PS Sorry...
Geo Massar
Retired Engineer
yossistarz2
Posts: 21
Joined: Mon Apr 10, 2006 5:26 am
Contact:

Post by yossistarz2 »

This is nice solution you can use:
You cut the image into pisses (512X512 or what ever) and use this object
To do what ever you like. (Like image but a little bit different).

Code: Select all

NewImage = 
{
	Images = {},
}

-- Creates new image.
function NewImage:New()

	local c = {}

	setmetatable(c,self)
	self.__index =  self

	c.Images = {}
	return (c)
end

-- Loads image as part of the image in the x,y pos in the global image
function NewImage:LoadImage(x,y,str)

	local  img = Image.load(str)
	local tempImg = {}
	
	tempImg.Image = img
	tempImg.X = x
	tempImg.Y = y

	self.Images[table.getn(self.Images) + 1]  = tempImg 
end

-- Draws the image on the img. x1,y1,x2,y2 is part of the image to draw..
function NewImage:Draw(x,y,img,x1,y1,x2,y2)

	local indx
	local maximg = table.getn(self.Images) 

	if (x1 == nil) then

		x1 = 0
	end

	if (y1 == nil) then

		y1 = 0
	end

	if (x2 == nil) then

		x2 = img:width()
	end

	if (y2 == nil) then

		y2 = img:height()
	end

	for indx = 1,maximg  do

		local temp = self.Images[indx] 

		local xx1
		local xx2
		local yy1
		local yy2

		if (temp.X >= x1) then

			xx1 = 0
		else
			xx1 = x1 - temp.X
		end

		if (temp.Y >= y1) then

			yy1 = 0
		else
			yy1 = y1 - temp.Y
		end

		if &#40;temp.X + temp.Image&#58;width&#40;&#41; <= x2&#41; then

			xx2 = temp.Image&#58;width&#40;&#41;
		else
			xx2 = x2 - temp.X
		end

		if &#40;temp.Y + temp.Image&#58;height&#40;&#41;  <= y2&#41; then

			yy2 = temp.Image&#58;height&#40;&#41;
		else
			yy2 = y2 - temp.Y
		end

		img&#58;blit&#40;x + temp.X ,y + temp.Y,temp.Image,xx1,yy1,xx2,yy2&#41;
	end
end

-- blits image img to this new image.
function NewImage&#58;blit&#40;x,y,img&#41;

	local indx
	local maximg = table.getn&#40;self.Images&#41; 

	for indx = 1,maximg  do

		local temp = self.Images&#91;indx&#93; 
		local ToDraw = true

		local xx1
		local xx2
		local yy1
		local yy2

		local xxx1
		local yyy1

		if &#40;x >= temp.X&#41; then

			xx1 = x -  temp.X
			xxx1 = 0
		else
			xx1 = 0
			xxx1 = temp.X - x
		end

		if &#40;y >= temp.Y&#41; then

			yy1 = y - temp.Y
			yyy1 = 0
		else
			yy1 = 0
			yyy1 =  temp.Y - y
		end

		if &#40;x + img&#58;width&#40;&#41; <= temp.X + temp.Image&#58;width&#40;&#41;&#41; then

			xx2 = img&#58;width&#40;&#41; - xxx1
		else
			xx2 = temp.Image&#58;width&#40;&#41; - xxx1
		end

		if &#40;y + img&#58;height&#40;&#41; <= temp.Y + temp.Image&#58;height&#40;&#41;&#41; then

			yy2 = img&#58;height&#40;&#41;  - yyy1
		else
			yy2 = temp.Image&#58;height&#40;&#41; - yyy1
		end

		temp.Image&#58;blit&#40;xx1,yy1,img,xxx1,yyy1,xx2,yy2&#41;
	end
end

img = NewImage&#58;New&#40;&#41;
img&#58;LoadImage&#40;0,0,"1.png"&#41;
img&#58;LoadImage&#40;200,0,"2.png"&#41;
img&#58;LoadImage&#40;0,200,"2.png"&#41;
img&#58;LoadImage&#40;100,200,"1.png"&#41;
img&#58;LoadImage&#40;400,0,"1.png"&#41;

img&#58;blit&#40;160,190,Image.load&#40;"3.png"&#41;&#41;

while true do

	img&#58;Draw&#40;0,0,screen,0,0,400,240&#41;
	screen&#58;flip&#40;&#41;
end
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Post by DiabloTerrorGF »

yos... you have a lot of free time, don't you?
yossistarz2
Posts: 21
Joined: Mon Apr 10, 2006 5:26 am
Contact:

Post by yossistarz2 »

Well I am on a holly day ^_^.
So … yes.

But the question is if it helps?
tmaster
Posts: 11
Joined: Fri Oct 21, 2005 5:32 am
Location: Ireland

Post by tmaster »

Great work thanks.
Post Reply