user icon___xed___ on September 2nd 2013
5734 views

topic icontopic iconA Script Request (RWPaint user)

plus an idea for forum expansion

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.

Show older posts
user iconUgotsta on September 18th 2013 0

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:
https://gist.github.com/Ugotsta/6613836

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

user iconUgotsta on September 18th 2013 0

Hmm, how do we properly format code here?

user iconVlasta on September 18th 2013 0

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

user iconAnonymous on November 4th 2013 0

+1

I love it, works perfectly!

Now to work on my spritesheet recolor project!

user iconPAEz on November 4th 2013 0

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 πŸ˜‰

user iconPAEz on November 4th 2013 0

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.

user icon___xed___ on June 12th 2015 0

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);
  }
}
user iconnibbler on September 27th 2016 0

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.

user iconGodRage on December 2nd 2021 0

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

user iconGodRage on June 2nd 2023 0

Bug found.
Some colors can not be replaced by this script.
471214
531B1E
5C2220

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
https://imgur.com/4zlvl3N
Original: 471214
Replace by: B05F63

user icon