Additonal Bitmap Methods v0.9 By: Untra and Glitchfinder
Introduction
This is a set of additional methods that can be applied to desired bitmaps by scripters to make interesting things happen to them. Most of them are irreversible, but I intend to change this in the future so that the effects are not only reversible, but also so that they can be applied to the course of entire viewports, or the whole screen so as to make unique transitions or screen effects. Would probably go well coupled with an anti-lag script, or a faster computer :/
Current Features
Brighten
Brightens a bitmap by X shades
(image brightened by 64 shades)
Darken
Darkens a bitmap by X shades
(image darkened by 64 shades)
Invert
Inverts a bitmaps colors
Grayscale
Puts a bitmaps colors into grayscale
Pixelate (in v0.5 only)
Pixelates an image to X by X squares
(image pixelated to 8 by 8 squares)
Frost (in v0.5 only
Randomly scatters an images pixels over X passes (frosting it)
(image frosted over four passes)
Hyper Contrast
Heavily contrasts the bitmap with its surroundings.
Monochrome
Similar to grayscale, but puts greater contrast between blacks, whites and grays.
Emboss (still buggy)
Embosses the bitmap (still buggy- not all colors are embossed)
Sepia
Puts the bitmap into a sepia tone.
Sharpen
Sharpens the bitmap.
Soften
Softens the bitmap.
Crosseye (coming soon)
Makes two copies of the bitmap, sets them at half transparency and pushes both copies X pixels away from the center on a Y rotation.
Script
There are two versions currently out; v0.9 and v0.5. Version 0.5 has the frost and pixelate methods, while version 0.85 works with a .dll that makes the methods work instantaneously, and comes with many more additional methods. The v1.0 release should have a functional Frost working.
Â
#==============================================================================
# ** Additional Bitmap Methods
#------------------------------------------------------------------------------
# Â By Untra and Glitchfinder
# Â 6/3/10
# Â v0.9
#==============================================================================
class Bitmap
#------------------------------------------------------------------------------
#Make sure you have uabm.dll in your project folder.
#You can get it from (assuming link is not dead):
#http://www.box.net/shared/9m54d8hkzu
#------------------------------------------------------------------------------
 Brighten = Win32API.new("uabm.dll", "Brighten", "li", "v")
 Darken = Win32API.new("uabm.dll", "Darken", "li", "v")
 Invert = Win32API.new("uabm.dll", "Invert", "l", "v")
 Grayscale = Win32API.new("uabm.dll", "Grayscale", "l", "v")
 Hcontrast = Win32API.new("uabm.dll", "Hcontrast", "l", "v")
 Monochrome = Win32API.new("uabm.dll", "Monochrome", "l", "v")
 Emboss = Win32API.new("uabm.dll", "Emboss", "l", "v")
 Sepia = Win32API.new("uabm.dll", "Sepia", "l", "v")
 Sharpen = Win32API.new("uabm.dll", "Sharpen", "l", "v")
 Soften = Win32API.new("uabm.dll", "Soften", "l", "v")
 #--------------------------------------------------------------------------
 # * Brighten (0...255)
 #--------------------------------------------------------------------------
 def brighten(amount)
  Brighten.call(self.__id__, amount)
 end
 #--------------------------------------------------------------------------
 # * Darken (0...255)
 #--------------------------------------------------------------------------
 def darken(amount)
  Darken.call(self.__id__, amount)
 end
 #--------------------------------------------------------------------------
 # * Invert
 #--------------------------------------------------------------------------
 def invert
  Invert.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Grayscale
 #--------------------------------------------------------------------------
 def grayscale
  Grayscale.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Hyper Contrast
 #--------------------------------------------------------------------------
 def hyper_contrast
  Hcontrast.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Monochrome
 #--------------------------------------------------------------------------
 def monochrome
  Monochrome.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Emboss {buggy}
 #--------------------------------------------------------------------------
 def emboss
  Emboss.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Sepia
 #--------------------------------------------------------------------------
 def sepia
  Sepia.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Sharpen {will update with numeric value options}
 #--------------------------------------------------------------------------
 def sharpen
  Sharpen.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Soften {will update with numeric value options}
 #--------------------------------------------------------------------------
 def soften
  Soften.call(self.__id__)
 end
end
v0.5
Code:
#==============================================================================
# ** Additional Bitmap Methods
#------------------------------------------------------------------------------
# Â By Untra
# Â 5/5/10
# Â v0.5
#==============================================================================
class Bitmap
 #--------------------------------------------------------------------------
 # * Brighten
 #--------------------------------------------------------------------------
  def brighten(amount)
   for w in 0..(width - 1)
     for h in 0..(height - 1)
      color = get_pixel(w, h)
      set_pixel(w, h, Color.new([color.red + amount, 255].min, [color.green + amount, 255].min, [color.blue + amount, 255].min, color.alpha)) if color.alpha > 0
     end
   end
   return self
  end
 #--------------------------------------------------------------------------
 # * Darken
 #--------------------------------------------------------------------------
  def darken(amount)
   for w in 0...width
     for h in 0...height
      color = get_pixel(w, h)
      set_pixel(w, h, Color.new([color.red - amount, 0].max, [color.green - amount, 0].max, [color.blue - amount, 0].max, color.alpha)) if color.alpha > 0
     end
   end
   return self
  end
 #--------------------------------------------------------------------------
 # * Invert
 #  WARNING: Inverting colors is especially process consuming, and with
 #   frequent use can lag a game indefinitely. Use sparringly. Â
 #  NOTE: calling an invert color method a second time will bring its colors
 #   back to normal, assuming you didn't change its colors while in negative.
 #--------------------------------------------------------------------------
  def invert
   for w in 0..(width - 1)
     for h in 0..(height - 1)
      color = get_pixel(w, h)
      set_pixel(w, h, Color.new(255 - color.red, 255 - color.green, 255 - color.blue, color.alpha)) if color.alpha > 0
     end
   end
   return self
  end
 #--------------------------------------------------------------------------
 # * Grayscale
 #  WARNING: Putting a bitmap into grayscale is process consuming, and cannot
 #   be undone without recalling the bitmap. Use caution.
 #  NOTE: calling this method repeatedly has no effect on the bitmap, but will
 #   still waste processing power. Do not call it repeatedly.
 #--------------------------------------------------------------------------
  def grayscale
   for w in 0...width
     for h in 0...height
      color = get_pixel(w, h)
      a = color.alpha
      if a > 0
        num = (color.red + color.green + color.blue) / 3
        set_pixel(w, h, Color.new(num, num, num, a))
      end
     end
   end
   return self
  end
 #--------------------------------------------------------------------------
 # * Pixelate  {buggy}
 #  WARNING: Pixelating a bitmap is process consuming, and cannot be undone.
 #  NOTE: Funky things happen if you pixelate a bitmap to single pixels (which
 #   is the original bitmap). Its incredibly process consuming, so the method
 #   will return nil if you so attempt it.
 #  NOTE: Pixelateing bitmaps to a larger pixel size is less process consuming.
 #   for best results, don't pixelate to numbers below four.
 #  NOTE: This works much better for solid images, due to bugs.
 #--------------------------------------------------------------------------
  def pixelate(size)
   if size <= 1
    return nil
   else
    for w in 0..((width - 1) / size)
     w *= size
     for h in 0..((height - 1) / size)
      h *= size
      r, g, b, a = 0, 0, 0, 0
      size.times do |i|
        color = get_pixel(w, h)
        r += color.red ; g += color.green ; b += color.blue ; a += color.alpha
        color = get_pixel(w + i, h)
        r += color.red ; g += color.green ; b += color.blue ; a += color.alpha
        color = get_pixel(w, h + i)
        r += color.red ; g += color.green ; b += color.blue ; a += color.alpha
      end
      fill_rect(w, h, size, size, Color.new( (r / size**2) * Math.sqrt(size), (g / size**2) * Math.sqrt(size), (b / size**2) * Math.sqrt(size), (a / size**2) * Math.sqrt(size)))
     end
    end
   end
  end
 #--------------------------------------------------------------------------
 # * Frost
 #  WARNING: Frosting a bitmap is process consuming, and cannot be undone.
 #  NOTE: Frosting a bitmap randomly scatters its pixels. As such, Consistant
 #   results are impossible to get.
 #  NOTE: Frosting a bitmap beyond eight won't result in a more scattered image.
 #--------------------------------------------------------------------------
  def frost(passes)
   for pass in 1..passes
     for w in 0...width
      for h in 0...height
        set_pixel(w, h, get_pixel(w + rand(3) - 1, h + rand(3) - 1))
      end
     end
   end
   return self
  end
end
Instructions
Stick right above main, like you know you should.
This script is mostly for more advanced scripters that want to do more complex things with graphics. Its still buggy, and I intend to add more features.
FAQ
maybe later.
Compatibility
Not that I know of.
Credits and Thanks
To the makers of the MACL; that script inspired me to write this
And to Paint.Net, which helped me figure out how to make the Frost and Pixelate methods.
Authors Note Feel free to ask for some new features. If they're not too complex, I might (try to) add them in.
Terms and Conditions
Licensed under the WTFPL public licence. Click here for more information.
Â
#==============================================================================
# ** Additional Bitmap Methods
#------------------------------------------------------------------------------
# Â By Untra and Glitchfinder
# Â 5/29/10
# Â v0.85
#==============================================================================
class Bitmap
#------------------------------------------------------------------------------
#Make sure you have uabm.dll in your project folder.
#You can get it from (assuming link is not dead):
#http://www.box.net/shared/9m54d8hkzu
#------------------------------------------------------------------------------
 Brighten = Win32API.new("uabm.dll", "Brighten", "li", "v")
 Darken = Win32API.new("uabm.dll", "Darken", "li", "v")
 Invert = Win32API.new("uabm.dll", "Invert", "l", "v")
 Grayscale = Win32API.new("uabm.dll", "Grayscale", "l", "v")
 #--------------------------------------------------------------------------
 # * Brighten
 #--------------------------------------------------------------------------
 def brighten(amount)
  Brighten.call(self.__id__, amount)
 end
 #--------------------------------------------------------------------------
 # * Darken
 #--------------------------------------------------------------------------
 def darken(amount)
  Darken.call(self.__id__, amount)
 end
 #--------------------------------------------------------------------------
 # * Invert
 #--------------------------------------------------------------------------
 def invert
  Invert.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Grayscale
 #--------------------------------------------------------------------------
  def grayscale
   Grayscale.call(self.__id__)
  end
end
Â
#==============================================================================
# ** Additional Bitmap Methods
#------------------------------------------------------------------------------
# Â By Untra and Glitchfinder
# Â 6/3/10
# Â v0.9
#==============================================================================
class Bitmap
#------------------------------------------------------------------------------
#Make sure you have uabm.dll in your project folder.
#You can get it from (assuming link is not dead):
#http://www.box.net/shared/9m54d8hkzu
#------------------------------------------------------------------------------
 Brighten = Win32API.new("uabm.dll", "Brighten", "li", "v")
 Darken = Win32API.new("uabm.dll", "Darken", "li", "v")
 Invert = Win32API.new("uabm.dll", "Invert", "l", "v")
 Grayscale = Win32API.new("uabm.dll", "Grayscale", "l", "v")
 Hcontrast = Win32API.new("uabm.dll", "Hcontrast", "l", "v")
 Monochrome = Win32API.new("uabm.dll", "Monochrome", "l", "v")
 Emboss = Win32API.new("uabm.dll", "Emboss", "l", "v")
 Sepia = Win32API.new("uabm.dll", "Sepia", "l", "v")
 Sharpen = Win32API.new("uabm.dll", "Sharpen", "l", "v")
 Soften = Win32API.new("uabm.dll", "Soften", "l", "v")
 #--------------------------------------------------------------------------
 # * Brighten (0...255)
 #--------------------------------------------------------------------------
 def brighten(amount)
  Brighten.call(self.__id__, amount)
 end
 #--------------------------------------------------------------------------
 # * Darken (0...255)
 #--------------------------------------------------------------------------
 def darken(amount)
  Darken.call(self.__id__, amount)
 end
 #--------------------------------------------------------------------------
 # * Invert
 #--------------------------------------------------------------------------
 def invert
  Invert.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Grayscale
 #--------------------------------------------------------------------------
 def grayscale
  Grayscale.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Hyper Contrast
 #--------------------------------------------------------------------------
 def hyper_contrast
  Hcontrast.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Monochrome
 #--------------------------------------------------------------------------
 def monochrome
  Monochrome.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Emboss {buggy}
 #--------------------------------------------------------------------------
 def emboss
  Emboss.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Sepia
 #--------------------------------------------------------------------------
 def sepia
  Sepia.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Sharpen {will update with numeric value options}
 #--------------------------------------------------------------------------
 def sharpen
  Sharpen.call(self.__id__)
 end
 #--------------------------------------------------------------------------
 # * Soften {will update with numeric value options}
 #--------------------------------------------------------------------------
 def soften
  Soften.call(self.__id__)
 end
end
Thanks for all of the compliments everybody! This will probably wind up being my summer project, so if you have anything you'd like to request, I'm more than happy to (attempt) putting it in.
As for the radial blur, its possible but fairly difficult. As soon as I figure out Crosseye, radial blur should be far easier.