New Function ---- Invert

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

Moderators: Shine, Insert_witty_name

Post Reply
flattspott
Posts: 22
Joined: Mon Aug 22, 2005 4:06 am

New Function ---- Invert

Post by flattspott »

Code: Select all

function invertImage(theImage)
	newImage = Image.createEmpty(theImage:height(), theImage:width())
	for x = 1, theImage:width()-1 do
		for y = 1, theImage:height()-1 do
			p = theImage:pixel(y, x)
			c = Color.new(255-p:colors().r,255-p:colors().g,255-p:colors().b)
			newImage:pixel(y, x, c)
		end
	end
	return newImage
end

test = Image.load("test.png")
p = test:pixel(0, 0)
screen:blit(40, 36, test)
screen:blit(240, 36, invertImage(test))
screen:print(40, 26, "Original", Color.new(255, 255, 255))
screen:print(240, 26, "Inverted", Color.new(255, 255, 255))
screen:print(207, 244, "Invert Function by flattspott", Color.new(255, 255, 255))
screen:flip()
screen.waitVblankStart(600)
The test image:
Image

The screenshot:
Image
Zenurb
Posts: 106
Joined: Fri Sep 30, 2005 8:33 am
Location: United Kingdom
Contact:

Post by Zenurb »

Are you going to add rotate to your image functions library?
Proud Dvorak User
US 1.5 PSP (Original)
Post Reply