forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

image filters library with pics

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
flattspott



Joined: 22 Aug 2005
Posts: 22

PostPosted: Mon Oct 17, 2005 2:43 pm    Post subject: image filters library with pics Reply with quote

I wanted to contribute a little something. It may be a bit slow but it's not too bad and it/they work(s). Perhaps someone can get some use from them.

Code:

function brightness(img, amount)   --must be between 100 and -100
   output = Image.createEmpty(img:height(), img:width())
   for x = 1, img:width()-1 do
      for y = 1, img:height()-1 do
         p = img:pixel(y, x)
         r = p:colors().r+amount
         if r < 0 then r = 0 end
         if r > 255 then r = 255 end
         g = p:colors().g+amount
         if g < 0 then g = 0 end
         if g > 255 then g = 255 end
         b = p:colors().b+amount
         if b < 0 then b = 0 end
         if b > 255 then b = 255 end
         c = Color.new(r,g,b)
         output:pixel(y, x, c)
      end
   end
   return output
end

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

function contrast(img, amount) -- must be between 100 and -100
   if amount < -100 then amount = -100 end
   if amount > 100 then amount = 100 end
   amount = amount + 100
   amount = amount / 100
   amount = amount * amount
   output = Image.createEmpty(img:height(), img:width())
   for x = 1, img:width()-1 do
      for y = 1, img:height()-1 do
         p = img:pixel(y, x)
         r = p:colors().r
         r = r / 255
         r = r - 0.5
         r = r * amount
         r = r + 0.5
         r = r * 255
         if r < 0 then r = 0 end
         if r > 255 then r = 255 end
         g = p:colors().g
         g = g / 255
         g = g - 0.5
         g = g * amount
         g = g + 0.5
         g = g * 255
         if g < 0 then g = 0 end
         if g > 255 then g = 255 end
         b = p:colors().b
         b = b / 255
         b = b - 0.5
         b = b * amount
         b = b + 0.5
         b = b * 255
         if b < 0 then b = 0 end
         if b > 255 then b = 255 end
         c = Color.new(r,g,b)
         output:pixel(y, x, c)
      end
   end
   return output
end

function stripcolor(img, red, green, blue) -- 1 mean strip that color, 0 means leave it
   output = Image.createEmpty(img:height(), img:width())
   for x = 1, img:width()-1 do
      for y = 1, img:height()-1 do
         p = img:pixel(y, x)
         r = p:colors().r
         g = p:colors().g
         b = p:colors().b
         if red == 0 then r = r end
         if red == 1 then r = -255 end
         if green == 0 then g = g end
         if green == 1 then g = -255 end
         if blue == 0 then b = b end
         if blue == 1 then b = -255 end
         c = Color.new(r,g,b)
         output:pixel(y, x, c)
      end
   end
   return output
end

test = Image.load("64.png")
screen:blit(30, 26, test) -- the original image
screen:blit(106, 36, invert(test))
screen:blit(40, 102, stripcolor(test, 1, 1, 0)) -- make it blue
screen:blit(106, 102, stripcolor(test, 0, 1, 1)) -- make it red
screen:blit(172, 102, stripcolor(test, 1, 0, 1)) -- make it green
screen:blit(40, 168, contrast(test, 50)) -- increase by 50
screen:blit(106, 168, contrast(test, -50)) -- decrease by -50
screen:blit(172, 168, brightness(test, 50)) -- increase by 50
screen:blit(238, 168, brightness(test, -50)) -- decrease by -50
screen:flip()
screen.waitVblankStart(600)
--screen:save("filters.png")


The source image i used


and the various things you can do
Back to top
View user's profile Send private message
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Mon Oct 17, 2005 8:50 pm    Post subject: Reply with quote

hehe i already inplemented those functions in C
(to be compiled with luaplayer) which should be way faster than the lua code :)
current status is up on my page
also have blur and so on online
_________________
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group