Copern's Bitmap Color Functions

Copern

Villager
Member
Joined
Jul 6, 2012
Messages
8
Reaction score
7
First Language
English
Primarily Uses
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

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.

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.




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.

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.

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.

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.
 

Rafael_Sol_Maker

Almighty God Jabu
Veteran
Joined
May 8, 2012
Messages
129
Reaction score
57
First Language
Portuguese
Primarily Uses
RMMV
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.
 
Last edited by a moderator:

Copern

Villager
Member
Joined
Jul 6, 2012
Messages
8
Reaction score
7
First Language
English
Primarily Uses
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?
 
Last edited by a moderator:

Rafael_Sol_Maker

Almighty God Jabu
Veteran
Joined
May 8, 2012
Messages
129
Reaction score
57
First Language
Portuguese
Primarily Uses
RMMV
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. ;-)
 
Joined
May 21, 2012
Messages
83
Reaction score
4
First Language
English
Primarily Uses
@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.
 

Latest Threads

Latest Posts

Latest Profile Posts

I've started up Pillars of Eternity. It's interesting how the game does a "select choice" cutscene using still image art for dramatic flair. I wonder if that might work for my RPGMaker project.
The self-righteous indignation of family when you expect them to pay back money you've leant to them never ceases to amaze me.
Gamedev for relaxing? yes or no?
I've been having a rough couple of months and as such let down some friends of mine in the RPG Maker community. I still need time to get back to my normal self, but it's nice to be back, to read articles, and to design again (albeit at a slow pace). Hope to give updates on Kid Crescent soon.
Friendly reminder that you don't have to be able to do absolutely everything. It's okay to scale back features or assets if things are too much - especially if you're the only one working on the game! And you can always add things in later. <3

Forum statistics

Threads
107,735
Messages
1,031,744
Members
139,871
Latest member
jitomaynez
Top