A Script Request (RWPaint user) - RealWorld forums

Log-in or register.

A Script Request (RWPaint user)

plus an idea for forum expansion
on September 2nd 2013

Hi, I've been using RWPaint for all my art projets for the past 2-3 years. It was so perfect for my needs that I didn't need to ask for anything.

Because I didn't know ( :-( ) it's scripting capabilities.

Now I need something: Can you whip up a script to replace a particular exact color with another?

also, it might be a good and useful idea to create a forum section for hosting nifty scripts many users have surely come up with.

on September 2nd 2013

If you go to "Effect"->"Custom operation..." and paste this into the Configuration tab:

Configuration.AddColorButton("src", "Original", "", 0);
Configuration.AddColorButton("dst", "Replace by", "", 0xffffff);

...and this into the Execution tab:

var img = Document.RasterImage;
var src = Configuration.src;
var dst = Configuration.dst;
var sizeX = img.sizeX;
var sizeY = img.sizeY;

for (var x=0; x<sizeX; ++x)
	for (var y=0; y<sizeY; ++y)
		if (img.GetPixelAlpha(x, y, 0, 0) != 0 &&
			img.GetPixelColor(x, y, 0, 0) == src)
			img.SetPixelColor(x, y, 0, 0, dst);

it should do what you want.

If you have the 2013.1 version, you can also download this and drag and drop it onto the toolbar with "Adjust exposure", "Drop shadow" and other effects and it will add a new button with the above pre-configured.

on September 2nd 2013

Perfect!!! You just made my day!!!
This does exactly what I needed.

now, what about the scripts forum I talked about?

on September 2nd 2013

Well, if people start to contribute scripts or talk about them, I'll make the forum section. But at this moment, it would be almost empty. There is also another possibility - registered users may create or modify pages in the Help section, so that is an alternative. The Javascript operation page may be a good candidate, where to place links to scripts.

on September 3rd 2013

I'll learn and try to contribute.

Meanwhile, there seems to be a problem with the color replacing script. if I execute the script in a selection, why does the whole selected region sometimes go up a few pixels when clicked outside the selection?

on September 3rd 2013

You are talking about the floating selection, right? (The script or the way it is plugged into the application would have to be modified if it should work with the non-floating selections.)

I did a few tests and did not notice the region moving up. I noticed the region being trimmed if there is empty space selected, but the valid pixels remained in place. Could you find a situation, in which the pixels move after clicking outside and describe it here so I can replicate it?

on September 3rd 2013

Sorry for the delay, I was out on an errand.

Anyways, as I've said the problem happens irregularly. but it seems to occur if I do the replace operation 3-4 times. Here's a video (~300KB): https://www.dropbox.com/s/ovw62feg3azjqwo/20130903_153843.asf.
So perhaps you can create a new file and randomly execute the script a few times on different areas with different colors.
I removed my previous AppData folder to ensure it's due to no customization.

on September 3rd 2013

Great, I'll see what can be done about it. It looks like an error.

In the meantime, here is an alternative script that also works with image mask. So you can select a region with one of the tools in the first group (to the left of Transformation) and apply the effect on that region.

on September 4th 2013

Alright. Thanks again.

on September 5th 2013

A (hopefully working) fix is available. After downloading RWDrawing.dll, overwrite the old file and it should not move the selection anymore.

on September 5th 2013

Great! This works flawlessly.
I'll keep using the replacement script, which works with both types of selection, Remove the first script?

on September 18th 2013

This is such an awesome feature of RWPaint, to be able to create effects on-the-fly using JavaScript.

Here's something quick I threw together for a customizable scanline effect. Horizontal, vertical or both scanlines are possible with the scanline_x and scanline_y variables and the alpha value of the effect can be adjusted with scanline_alpha.

var img = Document.RasterImage;
var sizeX = img.sizeX;
var sizeY = img.sizeY;
var scanline_x = 2;
var scanline_y = 0;
var scanline_alpha = 0;
for (var x = 0; x < sizeX; x += 1) {
  for (var y = 0; y < sizeY; y += 1) {
		if (x%scanline_x === 0) {
			img.SetPixelAlpha(x, y, 0, 0, scanline_alpha);
		if (y%scanline_y === 0) {
			img.SetPixelAlpha(x, y, 0, 0, scanline_alpha);

I also posted this up as a Gist:

Again, awesome feature. Thanks Vlasta for an incredible editor!

on September 18th 2013

Hmm, how do we properly format code here?

on September 18th 2013

space in front of every line will make it look like code - I just did it

on November 4th 2013


I love it, works perfectly!

Now to work on my spritesheet recolor project!

on November 4th 2013

Hey Anonymous,
If your thinking of doing a sprite recolour thingy have you thought of doing like a colour mask style thing.
Instead of changing one colour to another (which can get real tricky if youve got shades) have another layer that has a mask for the colours.
So you could have 4 colours that can be changed, you draw a mask for each color over the sprite with a different color for each area.
Then you could write a script that has a configuration panel allowing you to pick a colour for each colour mask.
Then instead of changing one colour to another you just change the hue (and maybe saturation, but just hue is the safe one) of these pixels. This way the pixels keep their shade.
Prob is theres no hue/saturation picker for the configuration so it might not have the expected behaviour for a user, but youll know whats going on if its just for you.
If you wanted to change the lightness aswell you could always scan the whole mask, find the highest lightness value and map a gradient according to that. So that the lightness of the selected color is the maximum lightness for that colour mask.
Anyways, just thinking out loud ;-)

on November 4th 2013

Actually you can do this now without scripting.
On top of the sprites layer create a separate layer for each colour mask.
Then set each of these colour masks blend mode to Replace hue.
Now what ever pixels are under them will change colour but not lightness or saturation.
Then you can just use Adjustments - more adjustments - Shift Hue, to change the colour of each mask layer.

on June 12th 2015

Another variation that replaces all invalid transparent pixels (reason)

Set up a new command like this:

Command  : Document Operation
Name     : [0409]Replace Invalid Pixels
Operation: JavaScript
  Operation: Raster Image - Mask
  Execution: // Paste the following js in the Execution textbox
// replaces non-black 100%-transparent
// pixels in selection / document with
// 100%-transparent black pixels.
var img   = Document.RasterImage;
var invisiblack = 0x00000000;
var sizeX = img.sizeX, sizeY = img.sizeY;
for (var x=0; x<sizeX; ++x) {
  for (var y=0; y<sizeY; ++y) {
    if (img.GetPixelAlpha(x, y, 0, 0) == 0)
      img.SetPixel(x, y, 0, 0, invisiblack);
on September 27th 2016

It's not working on RealWorld Cursor Editor. It says img.sizeX is null or not an object. I want it to be used on RealWorld Cursor Editor.

on December 2nd 2021

Could be add something like "Color replace" in the title? (It could helps users ^^)

The Vlasta script is very good. :-) Thank you very much. :-)
But, I see a little problem: I want to replace 1 color by another... The first one is obviously in the image, the second one, is not. I want to use the #568353 color. I can't paste it in the replace box.
If I put it in the color panel at the right of the RW-Paint window, when I "pick color", it became #568352.
As a work-around, I opened an image (full of #568353 color) next to RW-Paint to be able to pick the color. ^^

Also, I wanted to replace multiple colors at once, for example:
from: 854242,7B0000,652828,723232,941818,AC2020,BD3031
to: 568353,16615B,3E4F58,456B52,167E86,119B85,14B485

on June 2nd

Bug found.
Some colors can not be replaced by this script.

Seems the "pick color tool" somehow is not always taking the real color.
482413 become 482414 with the "pick color tool"
("Ctrl + click" is accurate, but works only in the window.)
Only very dark colors have this bug?

2B170E >> pick color >> 271006 (it is quite different color...)

Color picker is taking the right color outside the RWPaint window, but is mistaking the color when picking inside the RWPaint Window.
(with the same image, one open in RWPaint, the other open in irfanview)

If the #colorcode could be editable, the script would gain the ability to copy/paste #color codes. (and also can give the ability to pass through this bug)

RWPaint64 bits 2023.1
Original: 471214
Replace by: B05F63

Page views: 5342       Posts: 21      
What about ICL files?
I wish there were...
Vista & Win 7 icons