Additional Bitmap Methods

Additonal Bitmap Methodsv0.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 (as well as make battle animations more interesting). The script comes coupled with a .dll file that makes the affect instantaneous, minimizing stress on the game process.

Current Features
I swear to god I'll remake this mountain of spoiler tags. Argh!
Brighten Show
Image
Brightens a bitmap by X shades
(image brightened by 64 shades)

Darken Show
Image
Darkens a bitmap by X shades
(image darkened by 64 shades)

Invert Show
Image
Inverts a bitmaps colors

Grayscale Show
Image
Puts a bitmaps colors into grayscale

Pixelate (in v0.5 only) Show
Image
Pixelates an image to X by X squares
(image pixelated to 8 by 8 squares)

Frost (in v0.5 only Show
Image
Randomly scatters an images pixels over X passes (frosting it)
(image frosted over four passes)

Hyper Contrast Show
Image
Heavily contrasts the bitmap with its surroundings.

Monochrome Show
Image
Similar to grayscale, but puts greater contrast between blacks, whites and grays.

Emboss (still buggy) Show
Image
Embosses the bitmap (still buggy- not all colors are embossed)

Sepia Show
Image
Puts the bitmap into a sepia tone.

Sharpen Show
Image
Sharpens the bitmap.

Soften Show
Image
Softens the bitmap.

Crosseye (coming soon) Show
Image
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.
v0.5 Show
  1. #==============================================================================
  2. # ** Additional Bitmap Methods
  3. #------------------------------------------------------------------------------
  4. #   By Untra
  5. #   5/5/10
  6. #   v0.5
  7. #==============================================================================
  8. class Bitmap
  9.   #--------------------------------------------------------------------------
  10.   # * Brighten
  11.   #--------------------------------------------------------------------------
  12.    def brighten(amount)
  13.       for w in 0..(width - 1)
  14.          for h in 0..(height - 1)
  15.             color = get_pixel(w, h)
  16.             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
  17.          end
  18.       end
  19.       return self
  20.    end
  21.   #--------------------------------------------------------------------------
  22.   # * Darken
  23.   #--------------------------------------------------------------------------
  24.    def darken(amount)
  25.       for w in 0...width
  26.          for h in 0...height
  27.             color = get_pixel(w, h)
  28.             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
  29.          end
  30.       end
  31.       return self
  32.     end
  33.   #--------------------------------------------------------------------------
  34.   # * Invert
  35.   #   WARNING: Inverting colors is especially process consuming, and with
  36.   #     frequent use can lag a game indefinitely. Use sparringly.  
  37.   #   NOTE: calling an invert color method a second time will bring its colors
  38.   #     back to normal, assuming you didn't change its colors while in negative.
  39.   #--------------------------------------------------------------------------
  40.    def invert
  41.       for w in 0..(width - 1)
  42.          for h in 0..(height - 1)
  43.             color = get_pixel(w, h)
  44.             set_pixel(w, h, Color.new(255 - color.red, 255 - color.green, 255 - color.blue, color.alpha)) if color.alpha > 0
  45.          end
  46.       end
  47.       return self
  48.    end
  49.   #--------------------------------------------------------------------------
  50.   # * Grayscale
  51.   #   WARNING: Putting a bitmap into grayscale is process consuming, and cannot
  52.   #     be undone without recalling the bitmap. Use caution.
  53.   #   NOTE: calling this method repeatedly has no effect on the bitmap, but will
  54.   #     still waste processing power. Do not call it repeatedly.
  55.   #--------------------------------------------------------------------------
  56.    def grayscale
  57.       for w in 0...width
  58.          for h in 0...height
  59.             color = get_pixel(w, h)
  60.             a = color.alpha
  61.             if a > 0
  62.                num = (color.red + color.green + color.blue) / 3
  63.                set_pixel(w, h, Color.new(num, num, num, a))
  64.             end
  65.          end
  66.       end
  67.       return self
  68.    end
  69.   #--------------------------------------------------------------------------
  70.   # * Pixelate  {buggy}
  71.   #   WARNING: Pixelating a bitmap is process consuming, and cannot be undone.
  72.   #   NOTE: Funky things happen if you pixelate a bitmap to single pixels (which
  73.   #     is the original bitmap). Its incredibly process consuming, so the method
  74.   #     will return nil if you so attempt it.
  75.   #   NOTE: Pixelateing bitmaps to a larger pixel size is less process consuming.
  76.   #     for best results, don't pixelate to numbers below four.
  77.   #   NOTE: This works much better for solid images, due to bugs.
  78.   #--------------------------------------------------------------------------
  79.    def pixelate(size)
  80.      if size <= 1
  81.        return nil
  82.      else
  83.        for w in 0..((width - 1) / size)
  84.          w *= size
  85.          for h in 0..((height - 1) / size)
  86.             h *= size
  87.             r, g, b, a = 0, 0, 0, 0
  88.             size.times do |i|
  89.                color = get_pixel(w, h)
  90.                r += color.red ; g += color.green ; b += color.blue ; a += color.alpha
  91.                color = get_pixel(w + i, h)
  92.                r += color.red ; g += color.green ; b += color.blue ; a += color.alpha
  93.                color = get_pixel(w, h + i)
  94.                r += color.red ; g += color.green ; b += color.blue ; a += color.alpha
  95.             end
  96.             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)))
  97.           end
  98.         end
  99.      end
  100.    end
  101.   #--------------------------------------------------------------------------
  102.   # * Frost
  103.   #   WARNING: Frosting a bitmap is process consuming, and cannot be undone.
  104.   #   NOTE: Frosting a bitmap randomly scatters its pixels. As such, Consistant
  105.   #     results are impossible to get.
  106.   #   NOTE: Frosting a bitmap beyond eight won't result in a more scattered image.
  107.   #--------------------------------------------------------------------------
  108.    def frost(passes)
  109.       for pass in 1..passes
  110.          for w in 0...width
  111.             for h in 0...height
  112.                set_pixel(w, h, get_pixel(w + rand(3) - 1, h + rand(3) - 1))
  113.             end
  114.          end
  115.       end
  116.       return self
  117.    end
  118. end
Expand to see the code.

v0.9 Show
Version v0.9
http://www.box.net/shared/9m54d8hkzu

  1. #==============================================================================
  2. # ** Additional Bitmap Methods
  3. #------------------------------------------------------------------------------
  4. #   By Untra and Glitchfinder
  5. #   6/3/10
  6. #   v0.9
  7. #==============================================================================
  8. class Bitmap
  9. #------------------------------------------------------------------------------
  10. #Make sure you have uabm.dll in your project folder.
  11. #You can get it from (assuming link is not dead):
  12. #http://www.box.net/shared/9m54d8hkzu
  13. #------------------------------------------------------------------------------
  14.   Brighten = Win32API.new("uabm.dll", "Brighten", "li", "v")
  15.   Darken = Win32API.new("uabm.dll", "Darken", "li", "v")
  16.   Invert = Win32API.new("uabm.dll", "Invert", "l", "v")
  17.   Grayscale = Win32API.new("uabm.dll", "Grayscale", "l", "v")
  18.   Hcontrast = Win32API.new("uabm.dll", "Hcontrast", "l", "v")
  19.   Monochrome = Win32API.new("uabm.dll", "Monochrome", "l", "v")
  20.   Emboss = Win32API.new("uabm.dll", "Emboss", "l", "v")
  21.   Sepia = Win32API.new("uabm.dll", "Sepia", "l", "v")
  22.   Sharpen = Win32API.new("uabm.dll", "Sharpen", "l", "v")
  23.   Soften = Win32API.new("uabm.dll", "Soften", "l", "v")
  24.   #--------------------------------------------------------------------------
  25.   # * Brighten (0...255)
  26.   #--------------------------------------------------------------------------
  27.   def brighten(amount)
  28.     Brighten.call(self.__id__, amount)
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # * Darken (0...255)
  32.   #--------------------------------------------------------------------------
  33.   def darken(amount)
  34.     Darken.call(self.__id__, amount)
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # * Invert
  38.   #--------------------------------------------------------------------------
  39.   def invert
  40.     Invert.call(self.__id__)
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   # * Grayscale
  44.   #--------------------------------------------------------------------------
  45.   def grayscale
  46.     Grayscale.call(self.__id__)
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # * Hyper Contrast
  50.   #--------------------------------------------------------------------------
  51.   def hyper_contrast
  52.     Hcontrast.call(self.__id__)
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # * Monochrome
  56.   #--------------------------------------------------------------------------
  57.   def monochrome
  58.     Monochrome.call(self.__id__)
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # * Emboss {buggy}
  62.   #--------------------------------------------------------------------------
  63.   def emboss
  64.     Emboss.call(self.__id__)
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # * Sepia
  68.   #--------------------------------------------------------------------------
  69.   def sepia
  70.     Sepia.call(self.__id__)
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # * Sharpen {will update with numeric value options}
  74.   #--------------------------------------------------------------------------
  75.   def sharpen
  76.     Sharpen.call(self.__id__)
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # * Soften {will update with numeric value options}
  80.   #--------------------------------------------------------------------------
  81.   def soften
  82.     Soften.call(self.__id__)
  83.   end
  84. end
Expand to see the code.


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 a tad buggy, and more features will come (if sporadicly.)

FAQ

maybe later.

Compatibility

Not that I know of.

Credits and Thanks
To Glitchfinder, who deserves just as much credit for this as I do.
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.
My first impression of this script is favorable, since it is well formatted and properly commented. Regarding your comments about speed, you might find that, for the most part, it will be slow on any computer. This is because RMXP uses a very poorly designed series of methods to edit and display graphics, and it does not significantly improve on faster computers.

As to reversing the effects, it can't really be done. The closest you can do for some of these methods is cloning the bitmap and saving it to use later. On others, like the brighten, it is possible to undo, but to a point. For example, it won't be able to undo the changes made to a bitmap when the colors hit their maximum or minimum values before the process is finished. The grayscale is also impossible to undo without cloning the image first, since you are effectively removing the color information and modifying the remnants.
Glitchfinder wrote:
My first impression of this script is favorable, since it is well formatted and properly commented. Regarding your comments about speed, you might find that, for the most part, it will be slow on any computer. This is because RMXP uses a very poorly designed series of methods to edit and display graphics, and it does not significantly improve on faster computers.


Heh, I kinda imagined that might be the case. I'm banking on a future release of the ARGSS being able to tackle the issue, so more complex methods can be added on a broader scale. My goal: Touch fuzzy get dizzy effects.

Quote:
As to reversing the effects, it can't really be done. The closest you can do for some of these methods is cloning the bitmap and saving it to use later. On others, like the brighten, it is possible to undo, but to a point. For example, it won't be able to undo the changes made to a bitmap when the colors hit their maximum or minimum values before the process is finished. The grayscale is also impossible to undo without cloning the image first, since you are effectively removing the color information and modifying the remnants.


I'm thinking of possibly making a method to refresh any bitmap that was changed by certain effects by recalling it, or by adding additional properties to it by using alias to change the RPG::Cache module. I'm not sure what the next step to take is regarding this. (This is especially frustrating if you want to pixelate a bitmap from a higher value to single pixels, to create the look that the screen is transitioning, as it requires the original bitmap to be recalled and redrawn every iteration.)

egh...
You almost entirely qualify for The Third Man's Golden Left-Sided Shoe Of Great Scripting, however, you sadly used the very weird indentation of 3 spaces. We're sorry to announce to you that you're a failure.
(seriously now, I can only second what Glitch said: Well coded, well documented - you just made me happy! :grin: )

As far as the performance issues go, the bottleneck very rarely is the hardware. I don't know about you, but I'm running a 2.4GHz core2quad, 3GB RAM machine that was not too bad a year ago; nevertheless, I get performance issues with RPG Maker games (more precisely, RGSS Player games) on a regular basis, and everyone knowing me knows it's not because of my inefficient scripting :p The RGSS Player is known as a relatively slow interpreter, so while I'm not trying to discourage you, I think getting the effects you linked to work via an effect (as opposed to moving 1px-wide images up and down or something) would be pretty much close to impossible if you aim for a broad user spec (which, as a game designer, you do).

Oh, and in general, very nice effects you got there! :D

Keep up the good work (and maybe get your very own Golden Left-Sided Shoe Of Great Scripting next time!).
To continue what BlueScope said, an alternative to scripting this via the slow RGSS-based Ruby interpreter might be programming a .dll file in a much faster language, such as C++. In point of fact, I could even provide you with the necessary code to get you started with bitmap methods in a .dll file, since I've dabbled with it myself. (Including creating several of the filters you have here) It is much faster, with no noticeable lag, and if you code it correctly, it will produce the exact same effect.
I know very little C++ to actually code in it, but If you provided me the code for what I've done so far I could teach myself by looking at your code and working from there.

In terms of software to work with, all I have is Microsoft Visual C++ 2008. Would this be enough?

I haven't made a ton of progress in terms of finding out how to "refresh" an altered bitmap, but I have been working on something else:
Crosseye Show
Image

It makes two copies of the same bitmap at half transparency and moves them both x pixels away from the center. Still a bit buggy, and I'd like to figure out how to also make them move at a degree measure as opposed to just left and right.
All right. Sorry for taking so long to get back to you with the code, but I have it right here. Right now, it's a mix of C and C++, but it works as long as you set it to compile as a .dll file. Some of the header files I included are for things that I had in my dll, such as the time classes used for random number generation for a splatter effect. You might want to note that RMXP and RMVX store bitmaps in the BGRA format, instead of the more common RGBA format, which is reflected in the example bitmap method below. Microsoft Visual C++ should be enough, though I would recommend getting the newest version, which was just released.

  1. #include <cstdlib>
  2. #include <ctime>
  3. #include <ctype.h>
  4. #include <math.h>
  5. #include <stddef.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <windows.h>
  10.  
  11. BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {
  12.     switch (ul_reason_for_call) {
  13.         case DLL_PROCESS_ATTACH:
  14.         case DLL_THREAD_ATTACH:
  15.         case DLL_THREAD_DETACH:
  16.         case DLL_PROCESS_DETACH:
  17.         break;
  18.     }
  19.     return true;
  20. }
  21.  
  22. typedef struct {
  23.     DWORD flags;
  24.     DWORD klass;
  25.     void (*dmark) (void*);
  26.     void (*dfree) (void*);
  27.     double *data; //red is index 2, green is index 1, blue 0, alpha 3
  28. } RGSSCOLOR;
  29.  
  30. typedef struct{
  31.     DWORD unk1;
  32.     DWORD unk2;
  33.     BITMAPINFOHEADER *infoheader;
  34.     RGSSCOLOR *firstRow;
  35.     RGBQUAD *lastRow;
  36. } RGSSBMINFO;
  37.  
  38. typedef struct{
  39.     DWORD unk1;
  40.     DWORD unk2;
  41.     RGSSBMINFO *bminfo;
  42. } BITMAPSTRUCT;
  43.  
  44. typedef struct{
  45.     DWORD flags;
  46.     DWORD klass;
  47.     void (*dmark) (void*);
  48.     void (*dfree) (void*);
  49.     BITMAPSTRUCT *bm;
  50. } RGSSBITMAP;
  51.  
  52. #define ASSERT(x) if(!x){DebugOut("Failed: %s: %d", #x, __LINE__);}
  53.  
  54. extern "C" _declspec (dllexport) BOOL Blank(long object){
  55.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  56.     DWORD rowsize;
  57.     DWORD width, height;
  58.     LPBYTE row;
  59.     long x, y;
  60.     int red, green, blue;
  61.     if(!bitmap) return false;
  62.     width = bitmap -> infoheader -> biWidth;
  63.     height = bitmap -> infoheader -> biHeight;
  64.     rowsize = width * 4;
  65.     row = (LPBYTE) (bitmap -> firstRow);
  66.     for ( y = 0; y < (int) height; y++) {
  67.         LPBYTE thisrow = row;
  68.         for ( x = 0; x < (int) width; x++) {
  69.             red = thisrow[2];
  70.             green = thisrow[1];
  71.             blue = thisrow[0];
  72.             thisrow += 4;
  73.         }
  74.         row -= rowsize;
  75.     }
  76.     return true;
  77. }
Expand to see the code.
Hey thanks! I'll take a better look into this and see where to begin coding these into C. Once I get a few methods working, I'll see how calling them through the .dll improves the latency. This will keep me busy once school lets out.
Thanks a million :thumb:
Untra wrote:
Hey thanks! I'll take a better look into this and see where to begin coding these into C. Once I get a few methods working, I'll see how calling them through the .dll improves the latency. This will keep me busy once school lets out.
Thanks a million :thumb:


Trust me, it improves the latency by quite a bit. By the way, if RMXP crashes when you call the .dll file, it's probably because you are trying to read or set pixels that are outside the bitmap's range, or because of some other error caused by your input. Also, to send a bitmap to the .dll file, you have to use the .__id__ method. Basically, bitmap_variable.__id__
I'm getting a few errors trying to compile:
  1.  
  2. 1>c:\documents and settings...uabm.cpp(57) : error C2065: 'object' : undeclared identifier
  3. 1>c:\documents and settings...uabm.cpp(57) : error C2227: left of '->bm' must point to class/struct/union/generic type
  4. 1>c:\documents and settings...uabm.cpp(57) : error C2227: left of '->bminfo' must point to class/struct/union/generic type
  5.  
Expand to see the code.


That line (57) is:
RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;

I'm not quite sure what to do. Help?
you left the arguments out of the method name. Note that the method was named as method_name(long object). In this case, the method would be fed one bitmap, following the bitmap.__id__ advice I gave you earlier. Don't drop the long, or the object, or you'll get an error.
Thanks! I got it working!

http://www.box.net/shared/9m54d8hkzu

Alright, first working dll... Now what? :huh:
I'm not quite sure how to go about calling it though. Win32API.new of course, but just what arguments would I put in it?
I feel so very, very new at this... :blush:

Edit: for reference, heres the sole working method:
  1. extern "C" _declspec (dllexport) BOOL Brighten(long object)
  2. {
  3.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  4.     DWORD rowsize;
  5.     DWORD width, height;
  6.     LPBYTE row;
  7.     long x, y;
  8.     int red, green, blue;
  9.     if(!bitmap) return false;
  10.     width = bitmap -> infoheader -> biWidth;
  11.     height = bitmap -> infoheader -> biHeight;
  12.     rowsize = width * 4;
  13.     row = (LPBYTE) (bitmap -> firstRow);
  14.     for ( y = 0; y < (int) height; y++) {
  15.         LPBYTE thisrow = row;
  16.         for ( x = 0; x < (int) width; x++) {
  17.             red = (thisrow[2] + object);
  18.             green = (thisrow[1] + object);
  19.             blue = (thisrow[0] + object);
  20.             thisrow[2] = (BYTE) red;
  21.             thisrow[1] = (BYTE) green;
  22.             thisrow[0] = (BYTE) blue;
  23.             thisrow += 4;
  24.         }
  25.         row -= rowsize;
  26.     }
  27.     return true;
  28. }
Expand to see the code.
First you have to get a properly compiled .dll file. Then you'll do the following:

  1. dllcall = Win32API.new("dll name", "function name", "LlIiNnPp", "LlIiNnPpVv")
  2. dllcall.call(arg1, arg2...)
Expand to see the code.


Let me explain.

"dll name": the name of the dll file, with or without the extension. (case insensitive, crashes if not found)
"function name": The name of the function you wish to call. (case sensitive, crashes if not found)
"LlIiNnPp": The arguments. This is a string of characters, which are explained below.
"LlIiNnPpVv": The return value. A single character, follows the same rules as the arguments.

Arguments:
"L" or "l", "N" or "n": A long number. This can be used to pass booleans, where 0 is false and anything else is true.
"I" or "i": An int. This can be used to pass booleans. (see above)
"P" or "p": A pointer to a string. With more advanced programming, can be used to pass other variable types, such as structures.
"V" or "v": Void. May only be used as a return value.

One other thing I would like to note is that if the dll crashes, so will RMXP or RMVX, and that you will receive a non-specific error message regarding the event.
Ah, I see what I did with the dll. This should be it fixed then:
http://www.box.net/shared/9m54d8hkzu

It did however crash. :sad:
  1. class Bitmap
  2.   Brighten = Win32API.new("uabm.dll", "Brighten", "l", "v")
  3.  
  4.   #--------------------------------------------------------------------------
  5.   # * Brighten
  6.   #--------------------------------------------------------------------------
  7.   def brighten(amount)
  8.     Brighten.call(amount)
  9.   end
  10. end
  11.  
Expand to see the code.


I cannot thank you enough for all your help Glitchfinder! Ive learned a lot working with this code, and you've helped me just about every step of the way. You kick ass, sir.
Instead of feeding it amount, you need to feed it bitmap.__id__, and, if you need the amount, you need to make a second argument for the function in the .dll file, so that it can take the amount as an int. This is because it takes object, which is essentially a pointer to the bitmap in system memory, and uses it to access the bitmap data. So, try this:

  1.   1. extern "C" _declspec (dllexport) BOOL Brighten(long object, int amount)
  2.    2. {
  3.    3.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  4.    4.     DWORD rowsize;
  5.    5.     DWORD width, height;
  6.    6.     LPBYTE row;
  7.    7.     long x, y;
  8.    8.     int red, green, blue;
  9.    9.     if(!bitmap) return false;
  10.   10.     width = bitmap -> infoheader -> biWidth;
  11.   11.     height = bitmap -> infoheader -> biHeight;
  12.   12.     rowsize = width * 4;
  13.   13.     row = (LPBYTE) (bitmap -> firstRow);
  14.   14.     for ( y = 0; y < (int) height; y++) {
  15.   15.         LPBYTE thisrow = row;
  16.   16.         for ( x = 0; x < (int) width; x++) {
  17.   17.             red = (thisrow[2] + amount);
  18.   18.             green = (thisrow[1] + amount);
  19.   19.             blue = (thisrow[0] + amount);
  20.   20.             thisrow[2] = (BYTE) red;
  21.   21.             thisrow[1] = (BYTE) green;
  22.   22.             thisrow[0] = (BYTE) blue;
  23.   23.             thisrow += 4;
  24.   24.         }
  25.   25.         row -= rowsize;
  26.   26.     }
  27.   27.     return true;
  28.   28. }
Expand to see the code.


Keep in mind that you'll also want to add a bit of checking to force the values for the new colors into the proper range, since they will give an error if they are less than 0 or greater than 255.
It works! Show
Image


I tested a 640x480 image of a julia fractal brightened by 100, which would normally kill it outright. It took less than a second. :thumb:
I'll finish the rest of the methods before I release the full .dll.
You've helped a ton! Thanks!
Version v0.85
http://www.box.net/shared/9m54d8hkzu


  1.  
  2. #==============================================================================
  3. # ** Additional Bitmap Methods
  4. #------------------------------------------------------------------------------
  5. #   By Untra and Glitchfinder
  6. #   5/29/10
  7. #   v0.85
  8. #==============================================================================
  9. class Bitmap
  10. #------------------------------------------------------------------------------
  11. #Make sure you have uabm.dll in your project folder.
  12. #You can get it from (assuming link is not dead):
  13. #http://www.box.net/shared/9m54d8hkzu
  14. #------------------------------------------------------------------------------
  15.   Brighten = Win32API.new("uabm.dll", "Brighten", "li", "v")
  16.   Darken = Win32API.new("uabm.dll", "Darken", "li", "v")
  17.   Invert = Win32API.new("uabm.dll", "Invert", "l", "v")
  18.   Grayscale = Win32API.new("uabm.dll", "Grayscale", "l", "v")
  19.   #--------------------------------------------------------------------------
  20.   # * Brighten
  21.   #--------------------------------------------------------------------------
  22.   def brighten(amount)
  23.     Brighten.call(self.__id__, amount)
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # * Darken
  27.   #--------------------------------------------------------------------------
  28.   def darken(amount)
  29.     Darken.call(self.__id__, amount)
  30.   end
  31.   #--------------------------------------------------------------------------
  32.   # * Invert
  33.   #--------------------------------------------------------------------------
  34.   def invert
  35.     Invert.call(self.__id__)
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # * Grayscale
  39.   #--------------------------------------------------------------------------
  40.    def grayscale
  41.       Grayscale.call(self.__id__)
  42.    end
  43. end
  44.  
Expand to see the code.


The first four methods work like a charm!

But Pixelate and Frost don't change the colors of each pixel; they either redraw the pixels over a set course or draw them somewhere else. I'm gonna do some more research on how to write them (as you've helped more than enough), but otherwise these first four work quickly and flawlessly.
It's working great, :)

I may have found a bug: when I change an event's graphic with this, every other event with the same sprite/tile also change.
I'm doing something like:
  1. class Sprite_Character < RPG::Sprite
  2.   def brighten_by(x)
  3.     self.bitmap.brighten(x)
  4.   end
  5. end
  6.  
Expand to see the code.

I could be doing it wrong, though.
Thats because they all share the same bitmap id. Hmm... I'll take a look into how you could force it onto just one event. Its not so much a bug than a simple oversight.
Untra wrote:
Thats because they all share the same bitmap id. Hmm... I'll take a look into how you could force it onto just one event. Its not so much a bug than a simple oversight.


You'd have to make individual events clone the bitmap before using it. I've encountered this issue in the past.
  1. #==============================================================================
  2. # ** Additional Bitmap Methods
  3. #------------------------------------------------------------------------------
  4. #   By Untra and Glitchfinder
  5. #   5/29/10
  6. #   v0.85
  7. #==============================================================================
  8. class Bitmap
  9. #------------------------------------------------------------------------------
  10. #Make sure you have uabm.dll in your project folder.
  11. #You can get it from (assuming link is not dead):
  12. #http://www.box.net/shared/9m54d8hkzu
  13. #------------------------------------------------------------------------------
  14.   Brighten = Win32API.new("uabm.dll", "Brighten", "li", "v")
  15.   Darken = Win32API.new("uabm.dll", "Darken", "li", "v")
  16.   Invert = Win32API.new("uabm.dll", "Invert", "l", "v")
  17.   Grayscale = Win32API.new("uabm.dll", "Grayscale", "l", "v")
  18.   #--------------------------------------------------------------------------
  19.   # * Brighten
  20.   #--------------------------------------------------------------------------
  21.   def brighten(amount)
  22.     Brighten.call(self.__id__, amount)
  23.   end
  24.   #--------------------------------------------------------------------------
  25.   # * Darken
  26.   #--------------------------------------------------------------------------
  27.   def darken(amount)
  28.     Darken.call(self.__id__, amount)
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # * Invert
  32.   #--------------------------------------------------------------------------
  33.   def invert
  34.     Invert.call(self.__id__)
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # * Grayscale
  38.   #--------------------------------------------------------------------------
  39.    def grayscale
  40.       Grayscale.call(self.__id__)
  41.    end
  42. end
  43.  
  44. #==============================================================================
  45. # * Edit by Silver Wind
  46. #==============================================================================
  47. class Game_Event
  48.  
  49.   def name
  50.     return @event.name
  51.   end
  52.  
  53. end
  54. #-------------------------------------------------------------------------#
  55. class Game_Map
  56.   def get_event(key)
  57.      if key.is_a?(String)
  58.       return get_event_by_name(key)
  59.     else
  60.       return get_event_by_id(key)
  61.     end
  62.   end
  63.  
  64.   def get_event_by_name(name)
  65.     for i in @map.events.keys
  66.       ev = @events[i]
  67.       return ev if ev.name == name
  68.     end
  69.     # Error: No such event
  70.     return nil
  71.   end
  72.  
  73.   def get_event_by_id(i)
  74.     for k in @map.events.keys
  75.       ev = @events[k]
  76.       return ev if ev.id== i
  77.     end
  78.     # Error: No such event
  79.     return nil
  80.   end
  81. end
  82. #-------------------------------------------------------------------------#
  83. class Scene_Map
  84.  
  85.   def bitmap_effect(event, action, amount=nil)
  86.     ev = $game_map.get_event(event)
  87.     sprite = @spriteset.get_sprite(ev)
  88.     return if ev.nil?
  89.     case (action)
  90.     when 'brighten'
  91.       sprite.brighten_by(amount)
  92.     when 'darken'
  93.       sprite.darken_by(amount)
  94.     when 'invert'
  95.       sprite.invert
  96.     when 'grayscale'
  97.       sprite.grayscale
  98.     end
  99.   end
  100.  
  101. end
  102. #-------------------------------------------------------------------------#
  103. class Spriteset_Map
  104.  
  105.   def get_sprite(event)
  106.     for sprite in @character_sprites
  107.       ev = sprite.character
  108.       # if it's the same Game_Event object.
  109.       if ev.object_id == event.object_id  
  110.         target_sprite = sprite
  111.       end
  112.     end
  113.     return target_sprite
  114.   end
  115.  
  116. end
  117. #-------------------------------------------------------------------------#
  118. class Sprite_Character < RPG::Sprite
  119.   def brighten_by(x)
  120.     self.bitmap.brighten(x)
  121.   end
  122.  
  123.   def darken_by(x)
  124.     self.bitmap.darken(x)
  125.   end
  126.  
  127.   def invert
  128.     self.bitmap.invert
  129.   end
  130.  
  131.   def grayscale
  132.     self.bitmap.grayscale
  133.   end
  134.  
  135.   def update
  136.     super
  137.     # If tile ID, file name, or hue are different from current ones
  138.     if @tile_id != @character.tile_id or
  139.        @character_name != @character.character_name or
  140.        @character_hue != @character.character_hue
  141.       # Remember tile ID, file name, and hue
  142.       @tile_id = @character.tile_id
  143.       @character_name = @character.character_name
  144.       @character_hue = @character.character_hue
  145.       # If tile ID value is valid
  146.       if @tile_id >= 384
  147.         #----------------------------- edit -----------------------------#
  148.         # clone the bitmap before using it for an event.
  149.         bitmap = RPG::Cache.tile($game_map.tileset_name,
  150.           @tile_id, @character.character_hue)
  151.         self.bitmap = bitmap.clone
  152.         #----------------------------------------------------------------#
  153.         self.src_rect.set(0, 0, 32, 32)
  154.         self.ox = 16
  155.         self.oy = 32
  156.       # If tile ID value is invalid
  157.       else
  158.         #----------------------------- edit -----------------------------#
  159.         # clone the bitmap before using it for an event.
  160.         bitmap = RPG::Cache.character(@character.character_name,
  161.           @character.character_hue)
  162.         self.bitmap = bitmap.clone
  163.         #----------------------------------------------------------------#
  164.         @cw = bitmap.width / 4
  165.         @ch = bitmap.height / 4
  166.         self.ox = @cw / 2
  167.         self.oy = @ch
  168.       end
  169.     end
  170.     # Set visible situation
  171.     self.visible = (not @character.transparent)
  172.     # If graphic is character
  173.     if @tile_id == 0
  174.       # Set rectangular transfer
  175.       sx = @character.pattern * @cw
  176.       sy = (@character.direction - 2) / 2 * @ch
  177.       self.src_rect.set(sx, sy, @cw, @ch)
  178.     end
  179.     # Set sprite coordinates
  180.     self.x = @character.screen_x
  181.     self.y = @character.screen_y
  182.     self.z = @character.screen_z(@ch)
  183.     # Set opacity level, blend method, and bush depth
  184.     self.opacity = @character.opacity
  185.     self.blend_type = @character.blend_type
  186.     self.bush_depth = @character.bush_depth
  187.     # Animation
  188.     if @character.animation_id != 0
  189.       animation = $data_animations[@character.animation_id]
  190.       animation(animation, true)
  191.       @character.animation_id = 0
  192.     end
  193.   end
  194.  
  195. end
  196. #-------------------------------------------------------------------------#
  197.  
  198. def brighten(event,amount)
  199.   #return unless $scene.is_a?(Scene_Map)
  200.   $scene.bitmap_effect(event,'brighten',amount)
  201. end
  202.  
  203. def darken(event,amount)
  204.   $scene.bitmap_effect(event,'darken',amount)
  205. end
  206.  
  207. def invert(event)
  208.   $scene.bitmap_effect(event,'invert')
  209. end
  210.  
  211. def grayscale(event)
  212.   $scene.bitmap_effect(event,'grayscale')
  213. end
Expand to see the code.

Tiny edit. only 170 lines o.o;
The 4 last methods are meant to keep the call short in the script box.
Send the event name or number as parameter:
brighten("EV001",64)
invert(2)
Silver Wind, were you aware that any methods or variables defined within the Interpreter class (Or Game_Interpreter for VX) will be accessible to the evented "call script..." command? That means that you would only have to define those methods inside the interpreter, instead of making them globally accessible. Another thing to note is that the Interpreter has a neat little method called get_character(parameter), that will return $game_player if the parameter is -1, or the event that called it, if it is 0, or, even better, will return the event whose ID you gave it as a parameter, if the parameter is above 0. This makes it extraordinarily easy to modify events on the fly. Another thing to note is that you never want to use the variable @index in the "call script..." command, because that is used to determine where in the event's command list you are operating from, and will result in an infinitely looping event, or, even worse, a crash. (You can define instance variables with @variable_name that will be accessible by future call scripts, if you want to.)
Thanks for the tip :)
I'll modified my script to use get_character.
I never touched @index, but yeah, better leave it alone :P
aanndd... I'm stuck.
  1.  
  2. //Pixelate
  3. extern "C" _declspec (dllexport) BOOL Pixelate(long object, int size)
  4. {
  5.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  6.     DWORD rowsize;
  7.     DWORD width, height;
  8.     LPBYTE row;
  9.     long x, y, z;
  10.     int red, green, blue, alpha;
  11.     if(!bitmap) return false;
  12.     if(size <= 1) return false;
  13.     width = bitmap -> infoheader -> biWidth;
  14.     height = bitmap -> infoheader -> biHeight;
  15.     rowsize = width * 4;
  16.     row = (LPBYTE) (bitmap -> firstRow);
  17.     for ( y = 0; y < (int) height - 1 / size; y++) {
  18.         y *= size;
  19.         for ( x = 0; x < (int) width - 1 / size; x++) {
  20.             x *= size;
  21.             red, green, blue, alpha = 0;
  22.             LPBYTE thisrow = row;
  23.             for ( z = 0; z == size; z++){
  24.                 //row
  25.                 thisrow = row;
  26.                 red += (thisrow[2]);
  27.                 green += (thisrow[1]);
  28.                 blue += (thisrow[0]);
  29.                 alpha += (thisrow[3]);
  30.                 //row
  31.                 x += z;
  32.                 thisrow = row;
  33.                 red += (thisrow[2]);
  34.                 green += (thisrow[1]);
  35.                 blue += (thisrow[0]);
  36.                 alpha += (thisrow[3]);
  37.                 x -= z;
  38.                 //row your boat
  39.                 y += z;
  40.                 thisrow = row;
  41.                 red += (thisrow[2]);
  42.                 green += (thisrow[1]);
  43.                 blue += (thisrow[0]);
  44.                 alpha += (thisrow[3]);
  45.                 y -= z;
  46.             }
  47.             double block = size;
  48.             double r = red / pow(block,2);
  49.             r *=  sqrt(block);
  50.             double g = green / pow(block,2);
  51.             g *=  sqrt(block);
  52.             double b = blue / pow(block,2);
  53.             b *=  sqrt(block);
  54.             double a = alpha / pow(block,2);
  55.             a *=  sqrt(block);
  56.  
  57.             if(r > 255) r = 255;
  58.             if(g > 255) g = 255;
  59.             if(b > 255) b = 255;
  60.             if(a > 255) a = 255;
  61.             if(r < 0) r = 0;
  62.             if(g < 0) g = 0;
  63.             if(b < 0) b = 0;
  64.             if(a < 0) a = 0;
  65.             thisrow[2] = (BYTE) r;
  66.             thisrow[1] = (BYTE) g;
  67.             thisrow[0] = (BYTE) b;
  68.             thisrow[3] = (BYTE) a;
  69.             thisrow += 4;
  70.         }
  71.         row -= rowsize;
  72.     }
  73.     return true;
  74. }
  75.  
Expand to see the code.

I think I'm completely off by line 25 there. This would be a lot easier with a set_pixel function :sad:
Edit: Sudden realization the original RGSS Method would be useful for comparison:
  1.   def pixelate(size)
  2.      if size <= 1
  3.        return nil
  4.      else
  5.        for w in 0..((width - 1) / size)
  6.          w *= size
  7.          for h in 0..((height - 1) / size)
  8.             h *= size
  9.             r, g, b, a = 0, 0, 0, 0
  10.             size.times do |i|
  11.                color = get_pixel(w, h)
  12.                r += color.red ; g += color.green ; b += color.blue ; a += color.alpha
  13.                color = get_pixel(w + i, h)
  14.                r += color.red ; g += color.green ; b += color.blue ; a += color.alpha
  15.                color = get_pixel(w, h + i)
  16.                r += color.red ; g += color.green ; b += color.blue ; a += color.alpha
  17.             end
  18.             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)))
  19.           end
  20.         end
  21.      end
  22.    end
Expand to see the code.
I think you're in need of some more source code. Here's the full source code of my .dll file, from the last time I updated it. At the time, I was working on adding in all the effects from theory's Character Shaders. Go ahead and add effects from that to your project, since all of them were open source or unsourced ruby code that has been floating around foreign-language RM* communities for years.

  1. #include <cstdlib>
  2. #include <ctime>
  3. #include <ctype.h>
  4. #include <math.h>
  5. #include <stddef.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <windows.h>
  10.  
  11. BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {
  12.     switch (ul_reason_for_call) {
  13.         case DLL_PROCESS_ATTACH:
  14.         case DLL_THREAD_ATTACH:
  15.         case DLL_THREAD_DETACH:
  16.         case DLL_PROCESS_DETACH:
  17.         break;
  18.     }
  19.     return true;
  20. }
  21.  
  22. typedef struct {
  23.     DWORD flags;
  24.     DWORD klass;
  25.     void (*dmark) (void*);
  26.     void (*dfree) (void*);
  27.     double *data; //red is index 1, green is index 2, blue 3, alpha 0
  28. } RGSSCOLOR;
  29.  
  30. typedef struct{
  31.     DWORD unk1;
  32.     DWORD unk2;
  33.     BITMAPINFOHEADER *infoheader;
  34.     RGSSCOLOR *firstRow;
  35.     RGBQUAD *lastRow;
  36. } RGSSBMINFO;
  37.  
  38. typedef struct{
  39.     DWORD unk1;
  40.     DWORD unk2;
  41.     RGSSBMINFO *bminfo;
  42. } BITMAPSTRUCT;
  43.  
  44. typedef struct{
  45.     DWORD flags;
  46.     DWORD klass;
  47.     void (*dmark) (void*);
  48.     void (*dfree) (void*);
  49.     BITMAPSTRUCT *bm;
  50. } RGSSBITMAP;
  51.  
  52. #define ASSERT(x) if(!x){DebugOut("Failed: %s: %d", #x, __LINE__);}
  53.  
  54. extern "C" _declspec (dllexport) BOOL AlienTwo(long object){
  55.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  56.     DWORD rowsize;
  57.     DWORD width, height;
  58.     LPBYTE row, pixel1, pixel2, pixel3, pixel4;
  59.     long x, y;
  60.     double red, green, blue;
  61.     if(!bitmap) return false;
  62.     width = bitmap -> infoheader -> biWidth;
  63.     height = bitmap -> infoheader -> biHeight;
  64.     rowsize = width * 4;
  65.     row = (LPBYTE) (bitmap -> firstRow);
  66.     for ( y = 0; y < (int) height; y++) {
  67.         pixel1 = row;
  68.         pixel2 = row;
  69.         pixel3 = row;
  70.         pixel4 = row;
  71.         if((y >= 0) && ((y + 1) < (int) height)) {
  72.             pixel2 -= rowsize;
  73.             pixel3 -= rowsize;
  74.         }
  75.         for ( x = 0; x < (int) width; x++) {
  76.             if(((y + 1) < (int) height) && ((x + 1) < (int) width)) {
  77.                 pixel2 += 4;
  78.                 pixel4 += 4;
  79.                 red = sqrt(pow(((double) pixel1[2] - pixel2[2]), 2) + pow(((double) pixel3[2] - pixel4[2]), 2));
  80.                 green = sqrt(pow(((double) pixel1[1] - pixel2[1]), 2) + pow(((double) pixel3[1] - pixel4[1]), 2));
  81.                 blue = sqrt(pow(((double) pixel1[0] - pixel2[0]), 2) + pow(((double) pixel3[0] - pixel4[0]), 2));
  82.             }
  83.             else if(((y + 1) >= (int) height) && ((x + 1) < (int) width)) {
  84.                 pixel2 += 4;
  85.                 pixel4 += 4;
  86.                 red = sqrt(pow((double) pixel1[2], 2) + pow((double) pixel4[2], 2));
  87.                 green = sqrt(pow((double) pixel1[1], 2) + pow((double) pixel4[1], 2));
  88.                 blue = sqrt(pow((double) pixel1[0], 2) + pow((double) pixel4[0], 2));
  89.             }
  90.             else if(((y + 1) < (int) height) && ((x + 1) >= (int) width)) {
  91.                 red = sqrt(pow((double) pixel1[2], 2) + pow((double) pixel3[2], 2));
  92.                 green = sqrt(pow((double) pixel1[1], 2) + pow((double) pixel3[1], 2));
  93.                 blue = sqrt(pow((double) pixel1[0], 2) + pow((double) pixel3[0], 2));
  94.             }
  95.             else {
  96.                 red = pixel1[2];
  97.                 green = pixel1[1];
  98.                 blue = pixel1[0];
  99.             }
  100.             if((red + green + blue) > (double) 60) {
  101.                 if((red >= green) && (red >= blue)) {
  102.                     red += 20;
  103.                 }
  104.                 else if((green >= red) && (green >= blue)) {
  105.                     green += 20;
  106.                 }
  107.                 else {
  108.                     blue += 20;
  109.                 }
  110.                 if(red > 255) red = 255;
  111.                 if(green > 255) green = 255;
  112.                 if(blue > 255) blue = 255;
  113.                 pixel1[2] = (BYTE) red;
  114.                 pixel1[1] = (BYTE) green;
  115.                 pixel1[0] = (BYTE) blue;
  116.             }
  117.             else {
  118.                 pixel1[2] = 0;
  119.                 pixel1[1] = 0;
  120.                 pixel1[0] = 0;
  121.             }
  122.             pixel1 += 4;
  123.             pixel3 += 4;
  124.         }
  125.         row -= rowsize;
  126.     }
  127.     return true;
  128. }
  129.  
  130. extern "C" _declspec (dllexport) BOOL BlackAndWhite(long object){
  131.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  132.     DWORD rowsize;
  133.     DWORD width, height;
  134.     LPBYTE row;
  135.     long x, y;
  136.     int shade;
  137.     if(!bitmap) return false;
  138.     width = bitmap -> infoheader -> biWidth;
  139.     height = bitmap -> infoheader -> biHeight;
  140.     rowsize = width * 4;
  141.     row = (LPBYTE) (bitmap -> firstRow);
  142.     for ( y = 0; y < (int) height; y++) {
  143.         LPBYTE thisrow = row;
  144.         for ( x = 0; x < (int) width; x++) {
  145.             shade = ((thisrow[2] + thisrow[1] + thisrow[0]) / 3);
  146.             thisrow[2] = shade;
  147.             thisrow[1] = shade;
  148.             thisrow[0] = shade;
  149.             thisrow += 4;
  150.         }
  151.         row -= rowsize;
  152.     }
  153.     return true;
  154. }
  155.  
  156. extern "C" _declspec (dllexport) BOOL BlackAndWhite2(long object){
  157.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  158.     DWORD rowsize;
  159.     DWORD width, height;
  160.     LPBYTE row;
  161.     long x, y;
  162.     int red, green, blue, shade;
  163.     if(!bitmap) return false;
  164.     width = bitmap -> infoheader -> biWidth;
  165.     height = bitmap -> infoheader -> biHeight;
  166.     rowsize = width * 4;
  167.     row = (LPBYTE)(bitmap -> firstRow);
  168.     for ( y = 0; y < (int) height; y++) {
  169.         LPBYTE thisrow = row;
  170.         for ( x = 0; x < (int) width; x++) {
  171.             red = (thisrow[1] - thisrow[0] + thisrow[1] + thisrow[2]);
  172.             red = (red * thisrow[2] / 256);
  173.             if(red > 255) red = 255;
  174.             green = (thisrow[0] - thisrow[1] + thisrow[0] + thisrow[2]);
  175.             green = (green * thisrow[1] / 256);
  176.             if(green > 255) green = 255;
  177.             blue = (thisrow[0] - thisrow[1] + thisrow[0] + thisrow[2]);
  178.             blue = (blue * thisrow[0] / 256);
  179.             if(blue > 255) blue = 255;
  180.             shade = ((red + green + blue) / 3);
  181.             thisrow[2] = shade;
  182.             thisrow[1] = shade;
  183.             thisrow[0] = shade;
  184.             thisrow += 4;
  185.         }
  186.         row -= rowsize;
  187.     }
  188.     return true;
  189. }
  190.  
  191. extern "C" _declspec (dllexport) BOOL Emboss(long object){
  192.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  193.     DWORD rowsize;
  194.     DWORD width, height;
  195.     LPBYTE row;
  196.     long x, y;
  197.     int red, green, blue;
  198.     if(!bitmap) return false;
  199.     width = bitmap -> infoheader -> biWidth;
  200.     height = bitmap -> infoheader -> biHeight;
  201.     rowsize = width * 4;
  202.     row = (LPBYTE)(bitmap -> firstRow);
  203.     for ( y = 0; y < (int) height; y++) {
  204.         LPBYTE thisrow = row;
  205.         LPBYTE nextrow = row;
  206.         if((y > 0) && ((y + 1) < (int) height)) {
  207.             nextrow -= (width * 4);
  208.         }
  209.         for ( x = 0; x < (int) width; x++) {
  210.             if(((y + 1) < (int) height) && ((x + 1) < (int) width)) {
  211.                 nextrow += 4;
  212.                 red = (thisrow[2] - nextrow[2] + 128);
  213.                 green = (thisrow[1] - nextrow[1] + 128);
  214.                 blue = (thisrow[0] - nextrow[0] + 128);
  215.             }
  216.             else {
  217.                 red = (thisrow[2] + 128);
  218.                 green = (thisrow[1] + 128);
  219.                 blue = (thisrow[0] + 128);
  220.             }
  221.             red = abs(red);
  222.             green = abs(green);
  223.             blue = abs(blue);
  224.             if(red > 255) red = 255;
  225.             if(green > 255) green = 255;
  226.             if(blue > 255) blue = 255;
  227.             thisrow[2] = red;
  228.             thisrow[1] = green;
  229.             thisrow[0] = blue;
  230.             thisrow += 4;
  231.         }
  232.         row -= rowsize;
  233.     }
  234.     return true;
  235. }
  236.  
  237. extern "C" _declspec (dllexport) BOOL MinusTwo(long object){
  238.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  239.     DWORD rowsize;
  240.     DWORD width, height;
  241.     LPBYTE row;
  242.     long x, y;
  243.     double color1, color2;
  244.     if(!bitmap) return false;
  245.     width = bitmap -> infoheader -> biWidth;
  246.     height = bitmap -> infoheader -> biHeight;
  247.     rowsize = width * 4;
  248.     row = (LPBYTE)(bitmap -> firstRow);
  249.     for ( y = 0; y < (int) height; y++) {
  250.         LPBYTE thisrow = row;
  251.         LPBYTE nextrow = row;
  252.         if((y > 0) && ((y + 1) < (int) height)) {
  253.             nextrow -= (width * 4);
  254.         }
  255.         for ( x = 0; x < (int) width; x++) {
  256.             if(((y + 1) < (int) height) && ((x + 1) < (int) width)) {
  257.                 nextrow += 4;
  258.                 color2 = (((nextrow[2] * 0.3) + (nextrow[1] * 0.6) + (nextrow[0] * 0.1)) / 10);
  259.             }
  260.             else {
  261.                 color2 = 0;
  262.             }
  263.             color1 = (((thisrow[2] * 0.3) + (thisrow[1] * 0.6) + (thisrow[0] * 0.1)) / 10);
  264.             if((color1 - color2) > 0.2) {
  265.                 thisrow[2] = 0;
  266.                 thisrow[1] = 0;
  267.                 thisrow[0] = 0;
  268.             }
  269.             else {
  270.                 thisrow[2] = 255;
  271.                 thisrow[1] = 255;
  272.                 thisrow[0] = 255;
  273.             }
  274.             thisrow += 4;
  275.         }
  276.         row -= rowsize;
  277.     }
  278.     return true;
  279. }
  280.  
  281. extern "C" _declspec (dllexport) BOOL Sepia(long object){
  282.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  283.     DWORD rowsize;
  284.     DWORD width, height;
  285.     LPBYTE row;
  286.     long x, y;
  287.     double red, green, blue;
  288.     if(!bitmap) return false;
  289.     width = bitmap -> infoheader -> biWidth;
  290.     height = bitmap -> infoheader -> biHeight;
  291.     rowsize = width * 4;
  292.     row = (LPBYTE)(bitmap -> firstRow);
  293.     for ( y = 0; y < (int) height; y++) {
  294.         LPBYTE thisrow = row;
  295.         for ( x = 0; x < (int) width; x++) {
  296.             red = ((thisrow[2] * 0.393) + (thisrow[1] * 0.769) + (thisrow[0] * 0.189));
  297.             green = ((thisrow[2] * 0.349) + (thisrow[1] * 0.686) + (thisrow[0] * 0.168));
  298.             blue = ((thisrow[2] * 0.272) + (thisrow[1] * 0.534) + (thisrow[0] * 0.131));
  299.             if(red > 255) red = 255;
  300.             if(green > 255) green = 255;
  301.             if(blue > 255) blue = 255;
  302.             thisrow[2] = (BYTE) red;
  303.             thisrow[1] = (BYTE) green;
  304.             thisrow[0] = (BYTE) blue;
  305.             thisrow += 4;
  306.         }
  307.         row -= rowsize;
  308.     }
  309.     return true;
  310. }
  311.  
  312. extern "C" _declspec (dllexport) BOOL Sharpen(long object){
  313.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  314.     DWORD rowsize;
  315.     DWORD width, height;
  316.     LPBYTE row;
  317.     long x, y;
  318.     double red, green, blue, ap;
  319.     if(!bitmap) return false;
  320.     width = bitmap -> infoheader -> biWidth;
  321.     height = bitmap -> infoheader -> biHeight;
  322.     rowsize = width * 4;
  323.     row = (LPBYTE)(bitmap -> firstRow);
  324.     red = 0;
  325.     green = 0;
  326.     blue = 0;
  327.     ap = 0.8;
  328.     for ( y = 0; y < (int) height; y++) {
  329.         LPBYTE thisrow = row;
  330.         LPBYTE nextrow = row;
  331.         if((y > 0) && ((y + 1) < (int) height)) {
  332.             nextrow -= (width * 4);
  333.         }
  334.         for ( x = 0; x < (int) width; x++) {
  335.             if(((y + 1) < (int) height) && ((x + 1) < (int) width)) {
  336.                 nextrow += 4;
  337.                 red += nextrow[2];
  338.                 green += nextrow[1];
  339.                 blue += nextrow[0];
  340.             }
  341.             red = (((thisrow[2] - (red / 3)) * ap) + thisrow[2]);
  342.             green = (((thisrow[1] - (green / 3)) * ap) + thisrow[1]);
  343.             blue = (((thisrow[0] - (blue / 3)) * ap) + thisrow[0]);
  344.             if(red > 255) red = 255;
  345.             if(green > 255) green = 255;
  346.             if(blue > 255) blue = 255;
  347.             if(red < 0) red = 0;
  348.             if(green < 0) green = 0;
  349.             if(blue < 0) blue = 0;
  350.             thisrow[2] = (BYTE) red;
  351.             thisrow[1] = (BYTE) green;
  352.             thisrow[0] = (BYTE) blue;
  353.             thisrow += 4;
  354.         }
  355.         row -= rowsize;
  356.     }
  357.     return true;
  358. }
  359.  
  360. extern "C" _declspec (dllexport) BOOL Soften(long object){
  361.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  362.     DWORD rowsize;
  363.     DWORD width, height;
  364.     LPBYTE row;
  365.     long x, y, xoffset, yoffset;
  366.     int red, green, blue;
  367.     if(!bitmap) return false;
  368.     width = bitmap -> infoheader -> biWidth;
  369.     height = bitmap -> infoheader -> biHeight;
  370.     rowsize = width * 4;
  371.     row = (LPBYTE) (bitmap -> firstRow);
  372.     for ( y = 0; y < (int) height; y++) {
  373.         LPBYTE thisrow = row;
  374.         for ( x = 0; x < (int) width; x++) {
  375.             red = 0;
  376.             green = 0;
  377.             blue = 0;
  378.             for ( xoffset = -1; xoffset <= 1; xoffset++) {
  379.                 for ( yoffset = -1; yoffset <= 1; yoffset++) {
  380.                     if ((y > 0) && ((y + yoffset) < (int) height) && ((y + yoffset) > 0) && ((x + xoffset) > 0) && ((x + xoffset) < (int) width)) {
  381.                         LPBYTE newrow = thisrow;
  382.                         newrow -= (yoffset * (width * 4));
  383.                         newrow += (xoffset * 4);
  384.                         red += newrow[2];
  385.                         green += newrow[1];
  386.                         blue += newrow[0];
  387.                     }
  388.                 }
  389.             }
  390.             red /= 9;
  391.             green /= 9;
  392.             blue /= 9;
  393.             thisrow[2] = red;
  394.             thisrow[1] = green;
  395.             thisrow[0] = blue;
  396.             thisrow += 4;
  397.         }
  398.         row -= rowsize;
  399.     }
  400.     return true;
  401. }
  402.  
  403. extern "C" _declspec (dllexport) BOOL Splatter(long object){
  404.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  405.     DWORD rowsize;
  406.     DWORD width, height;
  407.     LPBYTE row;
  408.     long x, y;
  409.     int randomx, randomy;
  410.     if(!bitmap) return false;
  411.     width = bitmap -> infoheader -> biWidth;
  412.     height = bitmap -> infoheader -> biHeight;
  413.     rowsize = width * 4;
  414.     row = (LPBYTE) (bitmap -> firstRow);
  415.     srand((unsigned)time(0));
  416.     for ( y = 0; y < (int) height; y++) {
  417.         LPBYTE thisrow = row;
  418.         for ( x = 0; x < (int) width; x++) {
  419.             randomx = ((rand() % 3) + 1);
  420.             randomy = ((rand() % 3) + 1);
  421.             if((y > 0) && ((y + randomy) < (int) height) && ((x + randomx) < (int) width)) {
  422.                 LPBYTE newrow = thisrow;
  423.                 newrow -= (randomy * (width * 4));
  424.                 newrow += (randomx * 4);
  425.                 thisrow[2] = newrow[2];
  426.                 thisrow[1] = newrow[1];
  427.                 thisrow[0] = newrow[0];
  428.                 thisrow[3] = newrow[3];
  429.             }
  430.             else {
  431.                 thisrow[2] = 0;
  432.                 thisrow[1] = 0;
  433.                 thisrow[0] = 0;
  434.                 thisrow[3] = 0;
  435.             }
  436.             thisrow += 4;
  437.         }
  438.         row -= rowsize;
  439.     }
  440.     return true;
  441. }
  442.  
  443. extern "C" _declspec (dllexport) BOOL Swap(long object1, long object2, int index){
  444.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object1<<1)) -> bm -> bminfo;
  445.     RGSSBMINFO *palette = ((RGSSBITMAP*) (object2<<1)) -> bm -> bminfo;
  446.     DWORD rowsize, pRowSize;
  447.     DWORD width, height, pWidth;
  448.     LPBYTE row, originalColor, newColor;
  449.     long x, y;
  450.     int red, green, blue, oldRed, oldGreen, oldBlue;
  451.     if(!bitmap) return false;
  452.     width = bitmap -> infoheader -> biWidth;
  453.     height = bitmap -> infoheader -> biHeight;
  454.     pWidth = palette -> infoheader -> biWidth;
  455.     rowsize = width * 4;
  456.     pRowSize = pWidth * 4;
  457.     row = (LPBYTE) (bitmap -> firstRow);
  458.     for ( y = 0; y < (int) height; y++) {
  459.         LPBYTE thisrow = row;
  460.         for ( x = 0; x < (int) width; x++) {
  461.             red = thisrow[2];
  462.             green = thisrow[1];
  463.             blue = thisrow[0];
  464.             originalColor = (LPBYTE) (palette -> firstRow);
  465.             for ( int i = 0; i < (int) pWidth; i++) {
  466.                 oldRed = originalColor[2];
  467.                 oldGreen = originalColor[1];
  468.                 oldBlue = originalColor[0];
  469.                 if ( (red == oldRed) && (green == oldGreen) && (blue == oldBlue)) {
  470.                     newColor = originalColor - (pRowSize * (index + 1));
  471.                     thisrow[2] = newColor[2];
  472.                     thisrow[1] = newColor[1];
  473.                     thisrow[0] = newColor[0];
  474.                 }
  475.                 originalColor += 4;
  476.                 newColor += 4;
  477.             }
  478.             thisrow += 4;
  479.         }
  480.         row -= rowsize;
  481.     }
  482.     return true;
  483. }
  484.  
  485. extern "C" _declspec (dllexport) BOOL Blank(long object){
  486.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;
  487.     DWORD rowsize;
  488.     DWORD width, height;
  489.     LPBYTE row;
  490.     long x, y;
  491.     int red, green, blue;
  492.     if(!bitmap) return false;
  493.     width = bitmap -> infoheader -> biWidth;
  494.     height = bitmap -> infoheader -> biHeight;
  495.     rowsize = width * 4;
  496.     row = (LPBYTE) (bitmap -> firstRow);
  497.     for ( y = 0; y < (int) height; y++) {
  498.         LPBYTE thisrow = row;
  499.         for ( x = 0; x < (int) width; x++) {
  500.             red = thisrow[2];
  501.             green = thisrow[1];
  502.             blue = thisrow[0];
  503.             thisrow += 4;
  504.         }
  505.         row -= rowsize;
  506.     }
  507.     return true;
  508. }
Expand to see the code.
I've been playing around with these methods, and I'm astounded! All of them work excellently. In particular, I like the splatter method; its code is actually the frost method, making things a ton easier. I'll incorporate all of these into the .dll and release them.

Oh, thank you so much! 😀
Very cool, sorry I can't comment much on the technical side, however these are definately useful and functional, nice work.
Update: New version out now!
v0.9 Show
Version v0.9
http://www.box.net/shared/9m54d8hkzu

  1. #==============================================================================
  2. # ** Additional Bitmap Methods
  3. #------------------------------------------------------------------------------
  4. #   By Untra and Glitchfinder
  5. #   6/3/10
  6. #   v0.9
  7. #==============================================================================
  8. class Bitmap
  9. #------------------------------------------------------------------------------
  10. #Make sure you have uabm.dll in your project folder.
  11. #You can get it from (assuming link is not dead):
  12. #http://www.box.net/shared/9m54d8hkzu
  13. #------------------------------------------------------------------------------
  14.   Brighten = Win32API.new("uabm.dll", "Brighten", "li", "v")
  15.   Darken = Win32API.new("uabm.dll", "Darken", "li", "v")
  16.   Invert = Win32API.new("uabm.dll", "Invert", "l", "v")
  17.   Grayscale = Win32API.new("uabm.dll", "Grayscale", "l", "v")
  18.   Hcontrast = Win32API.new("uabm.dll", "Hcontrast", "l", "v")
  19.   Monochrome = Win32API.new("uabm.dll", "Monochrome", "l", "v")
  20.   Emboss = Win32API.new("uabm.dll", "Emboss", "l", "v")
  21.   Sepia = Win32API.new("uabm.dll", "Sepia", "l", "v")
  22.   Sharpen = Win32API.new("uabm.dll", "Sharpen", "l", "v")
  23.   Soften = Win32API.new("uabm.dll", "Soften", "l", "v")
  24.   #--------------------------------------------------------------------------
  25.   # * Brighten (0...255)
  26.   #--------------------------------------------------------------------------
  27.   def brighten(amount)
  28.     Brighten.call(self.__id__, amount)
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # * Darken (0...255)
  32.   #--------------------------------------------------------------------------
  33.   def darken(amount)
  34.     Darken.call(self.__id__, amount)
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # * Invert
  38.   #--------------------------------------------------------------------------
  39.   def invert
  40.     Invert.call(self.__id__)
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   # * Grayscale
  44.   #--------------------------------------------------------------------------
  45.   def grayscale
  46.     Grayscale.call(self.__id__)
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # * Hyper Contrast
  50.   #--------------------------------------------------------------------------
  51.   def hyper_contrast
  52.     Hcontrast.call(self.__id__)
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # * Monochrome
  56.   #--------------------------------------------------------------------------
  57.   def monochrome
  58.     Monochrome.call(self.__id__)
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # * Emboss {buggy}
  62.   #--------------------------------------------------------------------------
  63.   def emboss
  64.     Emboss.call(self.__id__)
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # * Sepia
  68.   #--------------------------------------------------------------------------
  69.   def sepia
  70.     Sepia.call(self.__id__)
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # * Sharpen {will update with numeric value options}
  74.   #--------------------------------------------------------------------------
  75.   def sharpen
  76.     Sharpen.call(self.__id__)
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # * Soften {will update with numeric value options}
  80.   #--------------------------------------------------------------------------
  81.   def soften
  82.     Soften.call(self.__id__)
  83.   end
  84. end
Expand to see the code.


As for the methods, most of them have been added in, but all of them could certainly use some tweaking. I'm hoping to apply arguments to the Sharpen and Soften methods, and the Sepia looks fairly off (it looks more like its been dipped in a bath of urine than sodium sulfide). I'm still working with the Frost to get it to work more accurately. For some reason, pixels that get pushed off the left side of the bitmap by the frosting wind up on the right, while pixels pushed to the right are simply lost.
Content Hidden Show
Imagescattered to 24
It only becomes really noticeable with smaller bitmaps at higher passes. The answer will come to me, but for now its a strange quirk thats been bothering me.
I thought that, since I provided you with some of the methods, I might as well go a bit further. Here is a more permanent link for the current version of the .dll file. You might also want to try hosting it at [url]bb.ohsk.net[/url], which is hosted by shadow, owner of the Slacked IRC network.

Also, what in particular do you mean when you say that the emboss doesn't get every color. When I tested it, it seemed to work fine. I could be wrong, though. Also, below is the original set of Ruby methods that I was basing this stuff on:

  1. def self.shader_alien2
  2.     for y in 0..@bitmap.height
  3.       for x in 0..@bitmap.width
  4.           pixel1 = @bitmap.get_pixel(x, y)
  5.           pixel2 = @bitmap.get_pixel(x + 1, y + 1)
  6.           pixel3 = @bitmap.get_pixel(x, y + 1)
  7.           pixel4 = @bitmap.get_pixel(x + 1, y)
  8.           red = Math.hypot((pixel1.red - pixel2.red),
  9.             (pixel3.red - pixel4.red))
  10.           green = Math.hypot((pixel1.green - pixel2.green),
  11.             (pixel3.green - pixel4.green))
  12.           blue = Math.hypot((pixel1.blue - pixel2.blue),
  13.             (pixel3.blue - pixel4.blue))
  14.           if (red + green + blue) > 60
  15.             if [red, green, blue].max == red
  16.               @bitmap.set_pixel(x, y, Color.new(red + 20, green, blue,
  17.                 pixel1.alpha))
  18.             elsif [red, green, blue].max == green
  19.               @bitmap.set_pixel(x, y, Color.new(red, green + 20, blue,
  20.                 pixel1.alpha))
  21.             elsif [red, green, blue].max == blue
  22.               @bitmap.set_pixel(x, y, Color.new(red, green, blue + 20,
  23.                 pixel1.alpha))
  24.             end
  25.           else
  26.             @bitmap.set_pixel(x, y, Color.new(0, 0, 0, pixel1.alpha))
  27.           end
  28.       end
  29.       if x % 640 == 0 and x != 0
  30.          self.contents.blt(0, 0, @bitmap, @bitmap.rect)
  31.          Graphics.update
  32.       end
  33.     end
  34.     return @bitmap
  35.   end
  36.  
  37.   def self.shader_bnw
  38.     for y in 0..@bitmap.height
  39.       for x in 0..@bitmap.width
  40.           a = @bitmap.get_pixel(x, y)
  41.           shade = ((a.red + a.green + a.blue) / 3)
  42.           @bitmap.set_pixel(x, y, Color.new(shade, shade, shade, a.alpha))
  43.       end
  44.       if x % 640 == 0 and x != 0
  45.          self.contents.blt(0, 0, @bitmap, @bitmap.rect)
  46.          Graphics.update
  47.       end
  48.     end
  49.     return @bitmap
  50.   end
  51.  
  52.   def self.shader_emboss
  53.     for y in 0..@bitmap.height
  54.       for x in 0..@bitmap.width
  55.         a = @bitmap.get_pixel(x, y)
  56.         b = @bitmap.get_pixel(x + 1, y + 1)
  57.         red = (a.red - b.red + 128)
  58.         red = red.abs
  59.         green = (a.green - b.green + 128)
  60.         green = green.abs
  61.         blue = (a.blue - b.blue + 128)
  62.         blue = blue.abs
  63.         red = 255 if red > 255
  64.         green = 255 if green > 255
  65.         blue = 255 if blue > 255
  66.         @bitmap.set_pixel(x, y, Color.new(red, green, blue, a.alpha))
  67.       end
  68.       if x % 640 == 0 and x != 0
  69.          self.contents.blt(0, 0, @bitmap, @bitmap.rect)
  70.          Graphics.update
  71.       end
  72.     end
  73.     return @bitmap
  74.   end
  75.  
  76.   def self.shader_minustwo
  77.     for y in 0..@bitmap.height
  78.       for x in 0..@bitmap.width
  79.           a = @bitmap.get_pixel(x, y)
  80.           b = @bitmap.get_pixel(x + 1, y + 1)
  81.           color1 = (((a.red * 0.3) + (a.green * 0.6) + (a.blue * 0.1)) / 10)
  82.           color2 = (((b.red * 0.3) + (b.green * 0.6) + (b.blue * 0.1)) / 10)
  83.           if (color1 - color2) > 0.2
  84.             @bitmap.set_pixel(x, y, Color.new(0, 0, 0, a.alpha))
  85.           else
  86.             @bitmap.set_pixel(x, y, Color.new(255, 255, 255, a.alpha))
  87.           end
  88.       end
  89.       if x % 640 == 0 and x != 0
  90.          self.contents.blt(0, 0, @bitmap, @bitmap.rect)
  91.          Graphics.update
  92.       end
  93.     end
  94.     return @bitmap
  95.   end
  96.  
  97.   def self.shader_sepia
  98.     for y in 0..@bitmap.height
  99.       for x in 0..@bitmap.width
  100.           a = @bitmap.get_pixel(x, y)
  101.           red = ((a.red * 0.393) + (a.green * 0.769) + (a.blue * 0.189))
  102.           green = ((a.red * 0.349) + (a.green * 0.686) + (a.blue * 0.168))
  103.           blue = ((a.red * 0.272) + (a.green * 0.534) + (a.blue * 0.131))
  104.           p blue if (y == 0 and x == 0)
  105.           red = 255 if red > 255
  106.           green = 255 if green > 255
  107.           blue = 255 if blue > 255
  108.           @bitmap.set_pixel(x, y, Color.new(red, green, blue, a.alpha))
  109.       end
  110.       if x % 640 == 0 and x != 0
  111.          self.contents.blt(0, 0, @bitmap, @bitmap.rect)
  112.          Graphics.update
  113.       end
  114.     end
  115.     return @bitmap
  116.   end
  117.  
  118.   def self.shader_sharpen
  119.     red = 0
  120.     green = 0
  121.     blue = 0
  122.     ap = 0.8
  123.     for y in 0..@bitmap.height
  124.       for x in 0..@bitmap.width
  125.         a = @bitmap.get_pixel(x + 1, y + 1)
  126.         b = @bitmap.get_pixel(x, y)
  127.         red += a.red
  128.         green += a.green
  129.         blue += a.blue
  130.         red = (b.red - (red / 3)) * ap + b.red
  131.         green = (b.green - (green / 3)) * ap + b.green
  132.         blue =(b.blue - (blue / 3)) * ap + b.blue
  133.         red = 255 if red > 255
  134.         green = 255 if green > 255
  135.         blue = 255 if blue > 255
  136.         red = 0 if red < 0
  137.         green = 0 if green < 0
  138.         blue = 0 if blue < 0
  139.         @bitmap.set_pixel(x, y, Color.new(red, green, blue, b.alpha))
  140.       end
  141.       if x % 640 == 0 and x != 0
  142.          self.contents.blt(0, 0, @bitmap, @bitmap.rect)
  143.          Graphics.update
  144.       end
  145.     end
  146.     return @bitmap
  147.   end
  148.  
  149.   def self.shader_soften
  150.     for y in 0..@bitmap.height
  151.       for x in 0..@bitmap.width
  152.         red = 0
  153.         green = 0
  154.         blue = 0
  155.         for x_offset in -1..1
  156.           for y_offset in -1..1
  157.             a = @bitmap.get_pixel(x + x_offset, y + y_offset)
  158.             red += a.red
  159.             green += a.green
  160.             blue += a.blue
  161.           end
  162.         end
  163.         red /= 9
  164.         green /= 9
  165.         blue /= 9
  166.         b = @bitmap.get_pixel(x, y)
  167.         @bitmap.set_pixel(x, y, Color.new(red, green, blue, b.alpha))
  168.       end
  169.       if x % 640 == 0 and x != 0
  170.          self.contents.blt(0, 0, @bitmap, @bitmap.rect)
  171.          Graphics.update
  172.       end
  173.     end
  174.     return @bitmap
  175.   end
  176.  
  177.   def self.shader_splatter
  178.     for y in 0..@bitmap.height
  179.       for x in 0..@bitmap.width
  180.         x_offset = rand(3) + 1
  181.         y_offset = rand(3) + 1
  182.         b = @bitmap.get_pixel(x + x_offset, y + y_offset)
  183.         @bitmap.set_pixel(x, y, Color.new(b.red, b.green, b.blue, b.alpha))
  184.       end
  185.       if x % 640 == 0 and x != 0
  186.          self.contents.blt(0, 0, @bitmap, @bitmap.rect)
  187.          Graphics.update
  188.       end
  189.     end
  190.     return @bitmap
  191.   end
  192.  
  193.  
  194.  
  195.  
  196.   def self.shader_contrast
  197.     conre = 1 ; ligre = 20
  198.     congr = 2 ; liggr = 20
  199.     conbl = 1 ; ligbl = 20
  200.     ligre =(ligre-127*(conre-1))
  201.     liggr =(liggr-127*(congr-1))
  202.     ligbl =(ligbl-127*(conbl-1))
  203.     for i in 0..@bitmap.height
  204.       for j in 0..@bitmap.width
  205.           a = @bitmap.get_pixel(j,i)
  206.           re = a.red*conre + ligre
  207.           gr = a.green*congr + liggr
  208.           bl = a.blue*conbl + ligbl
  209.           re = 255 if re > 255 ; re = 0 if re < 0
  210.           gr = 255 if gr > 255 ; gr = 0 if gr < 0
  211.           bl = 255 if bl > 255 ; bl = 0 if bl < 0
  212.           @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  213.       end
  214.       if j % 640 == 0 and j != 0
  215.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  216.          Graphics.update
  217.       end
  218.     end
  219.     return @bitmap
  220.   end
  221.  
  222.   def self.shader_negative
  223.     conre = -2 ; ligre = 0
  224.     congr = -2 ; liggr = 0
  225.     conbl = -2 ; ligbl = 0
  226.     ligre =(ligre-127*(conre-1))
  227.     liggr =(liggr-127*(congr-1))
  228.     ligbl =(ligbl-127*(conbl-1))
  229.     for i in 0..@bitmap.height
  230.       for j in 0..@bitmap.width
  231.           a = @bitmap.get_pixel(j,i)
  232.           re = a.red*conre + ligre
  233.           gr = a.green*congr + liggr
  234.           bl = a.blue*conbl + ligbl
  235.           re = 255 if re > 255 ; re = 0 if re < 0
  236.           gr = 255 if gr > 255 ; gr = 0 if gr < 0
  237.           bl = 255 if bl > 255 ; bl = 0 if bl < 0
  238.           @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  239.       end
  240.       if j % 640 == 0 and j != 0
  241.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  242.          Graphics.update
  243.       end
  244.     end
  245.     return @bitmap
  246.   end
  247.  
  248.   def self.shader_cartoon
  249.     for i in 0..@bitmap.height
  250.       for j in 0..@bitmap.width
  251.           a = @bitmap.get_pixel(j,i)
  252.           b = @bitmap.get_pixel(j,i)
  253.           re = a.red+b.red
  254.           gr = a.green+b.green
  255.           bl = a.blue+b.blue
  256.           re = 255 if re > 255 ; re = 0 if re < 0
  257.           gr = 255 if gr > 255 ; gr = 0 if gr < 0
  258.           bl = 255 if bl > 255 ; bl = 0 if bl < 0
  259.           @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  260.       end
  261.       if j % 640 == 0 and j != 0
  262.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  263.          Graphics.update
  264.       end
  265.     end
  266.     return @bitmap
  267.   end
  268.  
  269.   def self.shader_bright
  270.     ra = 50
  271.     for i in 0..@bitmap.height
  272.       for j in 0..@bitmap.width
  273.           a = @bitmap.get_pixel(j,i)
  274.           b = @bitmap.get_pixel(j,i)
  275.           re = (a.red>b.red ? a.red : b.red)
  276.           gr = (a.green>b.green ? a.green : b.green)
  277.           bl = (a.blue>b.blue ? a.blue : b.blue)
  278.           al = (a.alpha>b.alpha ? a.alpha : b.alpha)
  279.           @bitmap.set_pixel(j,i,Color.new(re+ra, gr+ra, bl+ra, al))
  280.       end
  281.       if j % 640 == 0 and j != 0
  282.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  283.          Graphics.update
  284.       end
  285.     end
  286.     return @bitmap
  287.   end
  288.  
  289.   def self.shader_bizarro
  290.     ra = 100
  291.     wh = 50
  292.     for i in 0..@bitmap.height
  293.       for j in 0..@bitmap.width
  294.           a = @bitmap.get_pixel(j,i)
  295.           no = rand(ra)-ra+1
  296.           re = a.red+no+wh ; gr = a.green+no+wh ; bl = a.blue+no+wh
  297.           re = 255 if re > 255 ; re = 0 if re < 0
  298.           gr = 255 if gr > 255 ; gr = 0 if gr < 0
  299.           bl = 255 if bl > 255 ; bl = 0 if bl < 0
  300.           @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  301.       end
  302.       if j % 640 == 0 and j != 0
  303.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  304.          Graphics.update
  305.       end
  306.     end
  307.     return @bitmap
  308.   end
  309.  
  310.   def self.shader_bulletholes
  311.     ra = 10
  312.     for i in 0..@bitmap.height
  313.       for j in 0..@bitmap.width
  314.           a = @bitmap.get_pixel(j,i)
  315.           if rand(101) < ra
  316.              re = rand(256) ; gr = rand(256) ; bl = rand(256)
  317.              @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  318.           end
  319.       end
  320.       if j % 640 == 0 and j != 0
  321.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  322.          Graphics.update
  323.       end
  324.     end
  325.     return @bitmap
  326.   end
  327.  
  328.   def self.shader_sill
  329.     ra = 500
  330.     re = 0 ; gr = 0 ; bl = 0
  331.     for i in 1..(@bitmap.height-1)
  332.       for j in 1..(@bitmap.width-1)
  333.         for m in -1..1
  334.           for n in -1..1
  335.             if m != 0 and n != 0
  336.               a = @bitmap.get_pixel(j+m,i+n)
  337.               re = re + a.red
  338.               gr = gr + a.green
  339.               bl = bl + a.blue
  340.             end
  341.           end
  342.         end
  343.         b = @bitmap.get_pixel(j,i)
  344.         re = (b.red-re/8).abs
  345.         gr = (b.green-gr/8).abs
  346.         bl = (b.blue-bl/8).abs
  347.         if (re+gr+bl) > ra
  348.           @bitmap.set_pixel(j,i,Color.new(255, 255, 255, b.alpha))
  349.         else
  350.           @bitmap.set_pixel(j,i,Color.new(0, 0, 0, b.alpha))
  351.         end
  352.       end
  353.       if j % 639 == 0 and j != 0
  354.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  355.          Graphics.update
  356.       end
  357.     end
  358.     return @bitmap
  359.   end
  360.  
  361.   def self.shader_bw2
  362.     for i in 0..@bitmap.height
  363.       for j in 0..@bitmap.width
  364.           a = @bitmap.get_pixel(j,i)
  365.           re = (a.green-a.blue+a.green+a.red).abs
  366.           re = re*a.red/256
  367.           re = 255 if re > 255
  368.           gr = (a.blue-a.green+a.blue+a.red).abs
  369.           gr = gr*a.red/256
  370.           gr = 255 if gr > 255
  371.           bl = (a.blue-a.green+a.blue+a.red).abs
  372.           bl = bl*a.green/256
  373.           bl = 255 if bl > 255
  374.           ma = (re+gr+bl)/3
  375.           @bitmap.set_pixel(j,i,Color.new(ma, ma, ma, a.alpha))
  376.       end
  377.       if j % 640 == 0 and j != 0
  378.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  379.          Graphics.update
  380.       end
  381.     end
  382.     return @bitmap
  383.   end
  384.  
  385.   def self.shader_alien
  386.     for i in 0..@bitmap.height
  387.       for j in 0..@bitmap.width
  388.           a = @bitmap.get_pixel(j,i)
  389.           re = (a.green-a.blue)**2/128
  390.           re = 255 if re > 255
  391.           gr = (a.red-a.blue)**2/128
  392.           gr = 255 if gr > 255
  393.           bl = (a.red-a.green)**2/128
  394.           bl = 255 if bl > 255
  395.           @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  396.       end
  397.       if j % 640 == 0 and j != 0
  398.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  399.          Graphics.update
  400.       end
  401.     end
  402.     return @bitmap
  403.   end
  404.  
  405.   def self.shader_monotone
  406.     ccr = 255
  407.     ccg = 255
  408.     ccb = 50
  409.     for i in 0..@bitmap.height
  410.       for j in 0..@bitmap.width
  411.           a = @bitmap.get_pixel(j,i)
  412.           ma = (a.red+a.green+a.blue)/3
  413.           re = ma*ccr/255
  414.           gr = ma*ccg/255
  415.           bl = ma*ccb/255
  416.           @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  417.       end
  418.       if j % 640 == 0 and j != 0
  419.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  420.          Graphics.update
  421.       end
  422.     end
  423.     return @bitmap
  424.   end
  425.  
  426.   def self.shader_enhance
  427.     for i in 0..@bitmap.height
  428.       for j in 0..@bitmap.width
  429.           a = @bitmap.get_pixel(j,i)
  430.           re = a.red**2/255
  431.           gr = a.green**2/255
  432.           bl = a.blue**2/255
  433.           @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  434.       end
  435.       if j % 640 == 0 and j != 0
  436.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  437.          Graphics.update
  438.       end
  439.     end
  440.     return @bitmap
  441.   end
  442.  
  443.   def self.shader_undead
  444.     for i in 0..@bitmap.height
  445.       for j in 0..@bitmap.width
  446.           a = @bitmap.get_pixel(j,i)
  447.           re = a.green*a.blue/255
  448.           gr = a.red*a.blue/255
  449.           bl = a.red*a.green/255
  450.           @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  451.       end
  452.       if j % 640 == 0 and j != 0
  453.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  454.          Graphics.update
  455.       end
  456.     end
  457.     return @bitmap
  458.   end
  459.  
  460.   def self.shader_wtf
  461.     for i in 0..@bitmap.height
  462.       for j in 0..@bitmap.width
  463.           a = @bitmap.get_pixel(j,i)
  464.           re = Math.sin(Math.atan2(a.green, a.blue))*255
  465.           gr = Math.sin(Math.atan2(a.blue, a.red))*255
  466.           bl = Math.sin(Math.atan2(a.red, a.green))*255
  467.           @bitmap.set_pixel(j,i,Color.new(re, gr, bl, a.alpha))
  468.       end
  469.       if j % 640 == 0 and j != 0
  470.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  471.          Graphics.update
  472.       end
  473.     end
  474.     return @bitmap
  475.   end
  476.  
  477.   def self.shader_plexiglass
  478.     pow = 200
  479.     lig_x = @bitmap.width/2
  480.     lig_y = @bitmap.height/2
  481.     rr = Math.hypot(lig_x,lig_y)
  482.     rc = rr**2
  483.     for i in 0..@bitmap.height
  484.       for j in 0..@bitmap.width
  485.           a = @bitmap.get_pixel(j,i)
  486.           len = (j-lig_x)**2+(i-lig_y)**2
  487.           if len < rc
  488.              dis = Math.sqrt(len);
  489.              bri = pow*(rr-dis)/rr
  490.              re = a.red+bri
  491.              gr = a.green+bri
  492.              bl = a.blue+bri
  493.              al = a.alpha+bri
  494.              re = 255 if re > 255
  495.              gr = 255 if gr > 255
  496.              bl = 255 if bl > 255
  497.              al = 255 if al > 255
  498.              @bitmap.set_pixel(j,i,Color.new(re, gr, bl, al))
  499.            end
  500.       end
  501.       if j % 640 == 0 and j != 0
  502.          self.contents.blt(0,0,@bitmap,@bitmap.rect)
  503.          Graphics.update
  504.       end
  505.     end
  506.     return @bitmap
  507.   end
Expand to see the code.


As a final note, your "Hyper Emboss" filter is looking very similar to Photoshop's "Glowing Edges" filter.
Those new effects are looking great, especially the sepia.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=70805