Copern's Bitmap Color Functions

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

    This is a DLL with accompanying Ruby script for modifying bitmap colors. It adds a few methods 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). A value of 0 skips processing of that pixel. 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.

    Spoiler
    color_levels = Color_Levels.new
    color_levels.set_point:)blue, 190, 80).set_point:)blue, 255, 80)
    greens = {100 => 80, 150 => 135, 185 => 255}
    reds = {205 => 105, 253 => 140, 255 => 160}
    values = {135 => 170, 255 => 140}
    color_levels.set_points:)green, greens).set_points:)red, reds).set_points:)value, values)
    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
    greens = {85 => 140, 165 => 140, 185 => 50, 255 => 50}
    values = {0 => 170, 60 => 170, 145 => 50, 200 => 130, 255 => 130}
    color_levels.set_points:)green, greens)
    color_levels.set_points:)value, values)
    bitmap.set_levels!(color_levels)

    Code:
    Prepare yourself, it's not pretty.

    Further instructions can be found in the script comments at the top.

    Additional Notes

    This should theoretically work for VX and earlier but I do not have a way of testing it. If it doesn't work for VX, please let me know.

    Download

    DLL Download

    http://www.4shared.c...rnbmcolors.html

    Script

    http://pastebin.com/AHheHtHC

    Terms of Use

    See script for terms of use.
  2. Genial!

    Really good to see that it's finally released. Congratulations for this new bitmap manipulation library, I'll add it to my personal collection. =D

    As I've posted on the previous topic, can you consider adding a feature to change color (or colorify, as you say) in a determined color range?

    I think it would be rather easy to do, and because to add lots of masks to change various colors (to replicate the "palette swapping effect" I said) would be a bit boring to achieve, if the image has many colors to change.
  3. So if I understand correctly, you want to specify a color for the bitmap to become BUT only certain colors within a range you specify will change to it? So it would work something like this.

    colorify_within(target_color, color_start, color_end)

    And similar for colorify_masked.

    So if you say... colorify_within(Color.new(100, 100, 200), Color.new(100, 50, 0), Color.new(200, 100, 50))

    It will change only the colors within

    Red: 100-200, Green: 50-100, and Blue: 0-50

    to approximately

    Red: 100, Green: 100, Blue: 200.

    Maybe you would prefer the range to be based on Hue rather than RGB? So that would be colorify_within(target_color, hue_start, hue_end) instead.

    Do you want to go even further with it and specify multiple target colors as well as multiple ranges to change?

    I really need to know what kind of range you mean. We are talking colors here after all. RGB, HSL, or HSB range? Hue only range?
  4. Hmm, all functions you listed there are cool.

    I said color range, RGB based, and specific color change (1:1) but defining things by HSL is a good idea too, makes the color manipulating pretty flexible, althought I don't use HSL color space.

    Well, as I said in PM, I'll be waiting for the result. ;-)
  5. @copern - Do you have the code that you used to get and modify the pixels of the bitmap? I have the code for RMXP, but it doesn't seem to work in RMVXA.