Resizing images

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

Moderators: Shine, Insert_witty_name

Post Reply
User avatar
JoshDB
Posts: 87
Joined: Wed Oct 05, 2005 3:54 am

Resizing images

Post by JoshDB »

Hey all. So far I've displayed and centered images in my image viewer using this -

Code: Select all

function ImageViewer(loc)
	tempimage = Image.load(loc)
	if tempimage&#58;width&#40;&#41; > 480 and tempimage&#58;height&#40;&#41; < 258 then
		minusc = tempimage&#58;width&#40;&#41; - 480
	elseif tempimage&#58;height&#40;&#41; > 272 and tempimage&#58;width&#40;&#41; < 481 then
		minusc = tempimage&#58;height&#40;&#41; - 258
	elseif tempimage&#58;width&#40;&#41; > 480 and tempimage&#58;height&#40;&#41; > 258 then
		if tempimage&#58;width&#40;&#41; > tempimage&#58;height&#40;&#41; then
			minusc = tempimage&#58;width&#40;&#41; - 480
		else
			minusc = tempimage&#58;height&#40;&#41; - 258
		end
	end
	if minusc == nil then
		tempcentx = tempimage&#58;width&#40;&#41;/2
		tempcenty = tempimage&#58;height&#40;&#41;/2
	else
		tempcentx = tempimage&#58;width&#40;&#41; - minusc
		tempcenty = tempimage&#58;height&#40;&#41; - minusc
		tempcentx = tempcentx/2
		tempcenty = tempcenty/2
	end
	centerx = 480/2 - tempcentx
		
	centery = 258/2 - tempcenty
	minusc = 0
	while true do
		screen&#58;clear&#40;&#41;
		screen&#58;blit&#40;0,0,white&#41;
		screen&#58;blit&#40;centerx,centery,tempimage,0,0,tempimage&#58;width&#40;&#41; - minusc,tempimage&#58;height&#40;&#41; - minusc&#41;
		screen&#58;blit&#40;0,0,ivt&#41;
		button = Controls.read&#40;&#41;
		if button&#58;cross&#40;&#41; then
			screen.waitVblankStart&#40;10&#41;
			break
			screen.waitVblankStart&#40;1&#41;
		end
		screen.flip&#40;&#41;
	end
	screen.flip&#40;&#41;
end
I thought screen:blit(centerx,centery,tempimage,0,0,tempimage:width() - minusc,tempimage:height() - minusc) would also resize the image, but no. It just displays certain portions of the image, and the rest is cut off.

Is there some way to do this?
Durante
Posts: 65
Joined: Sun Oct 02, 2005 6:07 am
Location: Austria

Post by Durante »

Sure, use screen.blitScaled() in my version :P

But seriously, there's no scaling in standard LuaPlayer as of now that I know of. It would also be really slow if you do it in software.
User avatar
JoshDB
Posts: 87
Joined: Wed Oct 05, 2005 3:54 am

Post by JoshDB »

I found something kinda helped me.

Code: Select all

function Image&#58;magnify&#40;mag&#41; 
  mag = mag or 2           -- 2 times in size by default 
  local w = self&#58;width&#40;&#41;  
  local h = self&#58;height&#40;&#41; 
  local result = Image.createEmpty&#40;mag*w, mag*h&#41; 
  for x = 0, w-1 do 
    for y = 0, h-1 do 
      result&#58;fillRect&#40;mag*x, mag*y, mag,mag, self&#58;pixel&#40;x,y&#41;&#41; 
    end 
  end 
  return result 
end 
But it resize by a fraction, and I haven't tested to see if it works for small fractions like 0.5.

Thanks in advance for any help.
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

I modified the code you posted above. It does not do some fraction. Only double, triple, etc. of a given image. Sorry.

Perhaps, the new version 0.12 would do the trick. I haven't taken a look into it, yet.
Geo Massar
Retired Engineer
Post Reply