Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Additional Bitmap Methods

Untra

Sponsor

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!
1-2.png

Brightens a bitmap by X shades
(image brightened by 64 shades)
2-1.png

Darkens a bitmap by X shades
(image darkened by 64 shades)
3-3.png

Inverts a bitmaps colors
4.png

Puts a bitmaps colors into grayscale
5.png

Pixelates an image to X by X squares
(image pixelated to 8 by 8 squares)
6.png

Randomly scatters an images pixels over X passes (frosting it)
(image frosted over four passes)
8.png

Heavily contrasts the bitmap with its surroundings.
9.png

Similar to grayscale, but puts greater contrast between blacks, whites and grays.
10.png

Embosses the bitmap (still buggy- not all colors are embossed)
11.png

Puts the bitmap into a sepia tone.
12.png

Sharpens the bitmap.
13.png

Softens the bitmap.
7.png

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.
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
Version v0.9
http://www.box.net/shared/9m54d8hkzu

Code:
#==============================================================================

# ** 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

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.
 

Untra

Sponsor

Glitchfinder":ukfsm658 said:
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.

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.
 

Untra

Sponsor

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:
7.png
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.

C++:
<span style="color: #339900;">#include <cstdlib>

<span style="color: #339900;">#include <ctime>

<span style="color: #339900;">#include <ctype.h>

<span style="color: #339900;">#include <math.h>

<span style="color: #339900;">#include <stddef.h>

<span style="color: #339900;">#include <stdio.h>

<span style="color: #339900;">#include <stdlib.h>

<span style="color: #339900;">#include <string.h>

<span style="color: #339900;">#include <windows.h>

 

BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {

    switch (ul_reason_for_call) {

        case DLL_PROCESS_ATTACH:

        case DLL_THREAD_ATTACH:

        case DLL_THREAD_DETACH:

        case DLL_PROCESS_DETACH:

        break;

    }

    return true;

}

 

typedef struct {

    DWORD flags;

    DWORD klass;

    void (*dmark) (void*);

    void (*dfree) (void*);

    double *data; //red is index 2, green is index 1, blue 0, alpha 3

} RGSSCOLOR;

 

typedef struct{

    DWORD unk1;

    DWORD unk2;

    BITMAPINFOHEADER *infoheader;

    RGSSCOLOR *firstRow;

    RGBQUAD *lastRow;

} RGSSBMINFO;

 

typedef struct{

    DWORD unk1;

    DWORD unk2;

    RGSSBMINFO *bminfo;

} BITMAPSTRUCT;

 

typedef struct{

    DWORD flags;

    DWORD klass;

    void (*dmark) (void*);

    void (*dfree) (void*);

    BITMAPSTRUCT *bm;

} RGSSBITMAP;

 

<span style="color: #339900;">#define ASSERT(x) if(!x){DebugOut("Failed: %s: %d", #x, __LINE__);}

 

extern <span style="color: #666666;">"C" _declspec (dllexport) BOOL Blank(long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #0000dd;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    long x, y;

    int red, green, blue;

    if(!bitmap) return false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #0000dd;">4;

    row = (LPBYTE) (bitmap -> firstRow);

    for ( y = <span style="color: #0000dd;">0; y < (int) height; y++) {

        LPBYTE thisrow = row;

        for ( x = <span style="color: #0000dd;">0; x < (int) width; x++) {

            red = thisrow[<span style="color: #0000dd;">2];

            green = thisrow[<span style="color: #0000dd;">1];

            blue = thisrow[<span style="color: #0000dd;">0];

            thisrow += <span style="color: #0000dd;">4;

        }

        row -= rowsize;

    }

    return true;

}
 

Untra

Sponsor

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":32qzjxbx said:
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__
 

Untra

Sponsor

I'm getting a few errors trying to compile:
Code:
 

1>c:\documents and settings...uabm.cpp(57) : error C2065: 'object' : undeclared identifier

1>c:\documents and settings...uabm.cpp(57) : error C2227: left of '->bm' must point to class/struct/union/generic type

1>c:\documents and settings...uabm.cpp(57) : error C2227: left of '->bminfo' must point to class/struct/union/generic type

 

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.
 

Untra

Sponsor

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:
Code:
extern "C" _declspec (dllexport) BOOL Brighten(long object)

{

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    long x, y;

    int red, green, blue;

    if(!bitmap) return false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * 4;

    row = (LPBYTE) (bitmap -> firstRow);

    for ( y = 0; y < (int) height; y++) {

        LPBYTE thisrow = row;

        for ( x = 0; x < (int) width; x++) {

            red = (thisrow[2] + object);

            green = (thisrow[1] + object);

            blue = (thisrow[0] + object);

            thisrow[2] = (BYTE) red;

            thisrow[1] = (BYTE) green;

            thisrow[0] = (BYTE) blue;

            thisrow += 4;

        }

        row -= rowsize;

    }

    return true;

}
 
First you have to get a properly compiled .dll file. Then you'll do the following:

[rgss]dllcall = Win32API.new("dll name", "function name", "LlIiNnPp", "LlIiNnPpVv")
dllcall.call(arg1, arg2...)
[/rgss]

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.
 

Untra

Sponsor

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:
Code:
class Bitmap

  Brighten = Win32API.new("uabm.dll", "Brighten", "l", "v")

  

  #--------------------------------------------------------------------------

  # * Brighten

  #--------------------------------------------------------------------------

  def brighten(amount)

    Brighten.call(amount)

  end

end

 

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:

C++:
   <span style="color: #0000dd;">1. extern <span style="color: #666666;">"C" _declspec (dllexport) BOOL Brighten(long object, int amount)

   <span style="color: #0000dd;">2. {

   <span style="color: #0000dd;">3.     RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #0000dd;">1)) -> bm -> bminfo;

   <span style="color: #0000dd;">4.     DWORD rowsize;

   <span style="color: #0000dd;">5.     DWORD width, height;

   <span style="color: #0000dd;">6.     LPBYTE row;

   <span style="color: #0000dd;">7.     long x, y;

   <span style="color: #0000dd;">8.     int red, green, blue;

   <span style="color: #0000dd;">9.     if(!bitmap) return false;

  <span style="color: #0000dd;">10.     width = bitmap -> infoheader -> biWidth;

  <span style="color: #0000dd;">11.     height = bitmap -> infoheader -> biHeight;

  <span style="color: #0000dd;">12.     rowsize = width * <span style="color: #0000dd;">4;

  <span style="color: #0000dd;">13.     row = (LPBYTE) (bitmap -> firstRow);

  <span style="color: #0000dd;">14.     for ( y = <span style="color: #0000dd;">0; y < (int) height; y++) {

  <span style="color: #0000dd;">15.         LPBYTE thisrow = row;

  <span style="color: #0000dd;">16.         for ( x = <span style="color: #0000dd;">0; x < (int) width; x++) {

  <span style="color: #0000dd;">17.             red = (thisrow[<span style="color: #0000dd;">2] + amount);

  <span style="color: #0000dd;">18.             green = (thisrow[<span style="color: #0000dd;">1] + amount);

  <span style="color: #0000dd;">19.             blue = (thisrow[<span style="color: #0000dd;">0] + amount);

  <span style="color: #0000dd;">20.             thisrow[<span style="color: #0000dd;">2] = (BYTE) red;

  <span style="color: #0000dd;">21.             thisrow[<span style="color: #0000dd;">1] = (BYTE) green;

  <span style="color: #0000dd;">22.             thisrow[<span style="color: #0000dd;">0] = (BYTE) blue;

  <span style="color: #0000dd;">23.             thisrow += <span style="color: #0000dd;">4;

  <span style="color: #0000dd;">24.         }

  <span style="color: #0000dd;">25.         row -= rowsize;

  <span style="color: #0000dd;">26.     }

  <span style="color: #0000dd;">27.     return true;

  <span style="color: #0000dd;">28. }

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.
 

Untra

Sponsor

nbf.png

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!
 

Untra

Sponsor

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


Code:
 

#==============================================================================

# ** 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

 

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:
[rgss]class Sprite_Character < RPG::Sprite
  def brighten_by(x)
    self.bitmap.brighten(x)
  end
end
 
[/rgss]
I could be doing it wrong, though.
 

Untra

Sponsor

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":2n9fg8ie said:
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.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top