Bitmap Color Functions

● ARCHIVED · READ-ONLY
Started by Copern 7 posts View original ↗
  1. Introduction

    This is a DLL with accompanying Ruby script for modifying bitmap colors. It adds two functions for recoloring bitmaps or changing bitmap color levels.

    Features

    - Recolor a bitmap maintaining the original brightness.

    - Recolor a bitmap with a mask to determine brightness and blending.

    - Modify the color levels of a bitmap.

    Instructions

    Spoiler
    Let us say our original bitmap is the RPGMaker cloak, blown up for better viewing.

    Alright, so let's say we simply want to turn it into an orange color.



    Code:
    bitmap.colorify!( Color.new(200, 100, 0, 255) )
    We'll end up with something like this.

    Spoiler
    Alright so how about this time we use a mask image and a red color instead. I'll show a variety of different brightness and alpha values for quick demonstration. The transparency layer was made visible for better viewing.

    Spoiler



    Code:
    bitmap.colorify_masked!( Color.new(200, 50, 50, 255), bitmapmask, false )
    If your mask image is smaller than the target bitmap, you can tell it to repeat the pattern (false by default). Here's what we end up with.

    Spoiler
    A value of 128 on the mask is essentially the original brightness. A higher value will make the pixels brighter than the original towards max brightness. A lower value will make the pixels darker than the original towards minimum brightness (black in this case). The alpha layer does just what you would expect by alpha blending with the original color.

    Next up we have the "set levels" function. With this we can modify specific channels and ranges of values as well as the brightness.

    Alright let's put a heavy emphasis on green values, tone down the red, nearly drop the blue, and highlight mid values while making higher values darker. I'll probably see about making color levels less cumbersome to use.

    Spoiler
    color_levels = Color_Levels.new
    color_levels.set_point( :blue, 190, 80 )
    color_levels.set_point( :blue, 255, 80 )
    color_levels.set_point( :green, 100, 80 )
    color_levels.set_point( :green, 150, 135 )
    color_levels.set_point( :green, 185, 255 )
    color_levels.set_point( :red, 205, 105 )
    color_levels.set_point( :red, 253, 140 )
    color_levels.set_point( :red, 255, 160 )
    color_levels.set_point( :value, 135, 170 )
    color_levels.set_point( :value, 255, 140 )
    bitmap.set_levels!(color_levels)

    Code:
    Now we end up with this.

    How about something really bizzare this time.

    Spoiler
    color_levels = Color_Levels.new
    color_levels.set_point( :green, 85, 140 )
    color_levels.set_point( :green, 165, 140 )
    color_levels.set_point( :green, 185, 50 )
    color_levels.set_point( :green, 255, 50 )
    color_levels.set_point( :value, 0, 170 )
    color_levels.set_point( :value, 60, 170 )
    color_levels.set_point( :value, 145, 50 )
    color_levels.set_point( :value, 200, 130 )
    color_levels.set_point( :value, 255, 130 )
    bitmap.set_levels!(color_levels)

    Code:
    Prepare yourself, it's not pretty.


    This is still work in progress and some things may be subject to change before release. I don't get much time to work on it; however, it is mostly complete. It's mainly a matter of what license I want to use, if any. I do want to allow commercial projects to be able to use it (with permission) though.

    So how useful would people find this and any suggestions?
  2. I'd totally consider using this for a few RM-based generators I want to work on. Nice job, man. :)
  3. This seems like it would be super interesting for games with randomly generated items. You could apply colors/masks based on random magical properties and have equipment that changes appearance based on what it does.
  4. It's kinda a "recolor function"? Very cool! Just to alter hue and saturation isn't enough to do the true palette swapping. The masking trick was incredibly cool, I really liked this feature. When it will be released? Want help with this?

    I suggest you making it to change the hue, saturation, etc, in determined color ranges, and the swapping of a determined color by another. Well, there were a lot of [bitmap processing libraries] already! It's so awesome!

    When I finish my current project on C++/RGSS, I'll take a look on this subject. Sounds promising.
  5. It should be out tomorrow hopefully. Apologies for the delay, just never enough time.

    Unless I'm reading that incorrectly, I believe what you are asking is what the Color Levels function already does. You can change specific (or range of) values in a channel to another value. Think of the "Adjust Color Curves" in GIMP, Photoshop, etc. That's the way it works, except as lines instead of curves.

    As an aside, there are absolutely no floating point operations or color space conversions in this.
  6. Alright folks, it has been posted (pending review). Looking forward to seeing what you guys use it with.

    Edit: And it's up.
  7. Since the script is complete and released. This topic will be closed.