Method: Pixelart::Image#invert
- Defined in:
- lib/pixelart/invert.rb
#invert ⇒ Object
note: invert will only invert r/g/b - and NOT the a(lpha) channel
the a(lpha) channel get passed on as is (1:1)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pixelart/invert.rb', line 12 def invert img = Image.new( @img.width, @img.height ) @img.width.times do |x| @img.height.times do |y| pixel = @img[x,y] ## note: xor (^) with 0 returns the original value unmodified. ## xor (^) with 0xff flips the bits. ## that is we are flipping/inverting r, g and b. ## and keep the a(lpha) channel as is. ## hack - why? why not? ## if transparent e.g. 0x0 than keep as is ## do not use 0xffffff00 - makes a difference? img[x,y] = if pixel == Color::TRANSPARENT # transparent (0) Color::TRANSPARENT else pixel ^ 0xffffff00 end end end img end |