change one specific color to another

A forum dedicated to George scripting questions
User avatar
ryberg
Posts: 93
Joined: 10 Mar 2009, 20:43
Location: CPH
Contact:

change one specific color to another

Post by ryberg »

I know there are several ways to do this, but I would like to create an action like the "Tint Blue" brush and "All Blue" action.

I've looked into the code of these actions but I can't get my head around it. Stuff like this doesn't make much sense to me:

Code: Select all

tv_cmd Heads tv_pixelmatrix 0 0 0 0 0   0 0 0 0.588 0   0 0 0 1 0   0 0 0 1 0
I'd like it to work like the "All Blue" action above, only it just turns red into blue and not black, so red becomes blue and black stays black
User avatar
Eric Scholl
Posts: 1303
Joined: 04 Apr 2011, 14:40

Re: change one specific color to another

Post by Eric Scholl »

ryberg wrote:I know there are several ways to do this, but I would like to create an action like the "Tint Blue" brush and "All Blue" action.

I've looked into the code of these actions but I can't get my head around it. Stuff like this doesn't make much sense to me:

Code: Select all

tv_cmd Heads tv_pixelmatrix 0 0 0 0 0   0 0 0 0.588 0   0 0 0 1 0   0 0 0 1 0
I'd like it to work like the "All Blue" action above, only it just turns red into blue and not black, so red becomes blue and black stays black
This should be the correct one ( Red to Blue ):

Code: Select all

tv_cmd Heads tv_pixelmatrix 0 0 0 0 0   0 1 0 0 0   1 0 1 0 0   0 0 0 1 0
User avatar
ryberg
Posts: 93
Joined: 10 Mar 2009, 20:43
Location: CPH
Contact:

Re: change one specific color to another

Post by ryberg »

Yeah, that is exactly what I was looking for, almost :wink:
I just want it to change into the light sketching blue rather than the dark one. Sorry for being difficult.

Also, how do you read RGBA values out of those codes, are there any available simple explanation on this anywhere? Just being curious and trying to understand these codes so I won't need to ask for help every time I dive into it.

Thanks a lot Eric.
User avatar
ryberg
Posts: 93
Joined: 10 Mar 2009, 20:43
Location: CPH
Contact:

Re: change one specific color to another

Post by ryberg »

I'm looking at this and trying to understand it. I'd love if it came with a text explaining it.

http://wiki.tvpaint.fr/index.php?title=Tv_PixelMatrix

I get that, 0 represent turned off and 1 is on since the value is multiplied with 255 in order to get the rgba value, but what is k, black? and what are capital R, G, B, A?
User avatar
Eric Scholl
Posts: 1303
Joined: 04 Apr 2011, 14:40

Re: change one specific color to another

Post by Eric Scholl »

Here is how it basically works :

you have 4 groups : R G B A

In each group, you have 5 numbers : r g b a k

The 4 firsts numbers are factors which determines how much the channel of the current color will impact on the final channel.

For example, if in my pixel I want to use the value of the blue channel as the value of the red, I'll do this in the first group (R):

Code: Select all

    R
r g b a k
0 0 1 0 0 
If I want a channel to keep the same value, I'll do this :

Code: Select all

    R
r g b a k
1 0 0 0 0
So in my example, if I only want to change the red value, I need to do this:

Code: Select all

    R              G              B             A
r g b a k      r g b a k      r g b a k     r g b a k
0 0 1 0 0      0 1 0 0 0      0 0 1 0 0     0 0 0 1 0


The 'k' value is constant which is added to the result.
Second example, let's say I have these color values :

Code: Select all

R = 255    G = 100   B = 255    A = 255
I want the red to have the green value + 50, so I do this :

Code: Select all

    R
r g b a k
0 1 0 0 50
And if I want the red to have the green value - 50, I do this :

Code: Select all

    R
r g b a k
0 1 0 0 -50
Here's my complete sequence for the second example :

Code: Select all

    R            G              B             A
r g b a k    r g b a k      r g b a k     r g b a k
0 1 0 0 50   0 1 0 0 0      0 0 1 0 0     0 0 0 1 0

The result will be :

Code: Select all

R = 150    G = 100   B = 255    A = 255
I hope this will help you, I know it's complicated.
User avatar
ryberg
Posts: 93
Joined: 10 Mar 2009, 20:43
Location: CPH
Contact:

Re: change one specific color to another

Post by ryberg »

thank you so much! For the first time, it makes sense. Now I need to test it to see if I got it but you really explained it quite well.
User avatar
Eric Scholl
Posts: 1303
Joined: 04 Apr 2011, 14:40

Re: change one specific color to another

Post by Eric Scholl »

Thank you :)

One more things, If you want to change a color to another one, it will work with basic colors, but you cannot do it with a precise color.
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18
Location: Viborg,Denmark
Contact:

Re: change one specific color to another

Post by Mads Juul »

Great explanation Eric. I put it into the wiki.
-Mads
Mads Juul
Storyboard Artist
blog: http://mjstoryboard.blogspot.dk/
Mail: mjstoryboard@gmail .com

Windows 10, 64 bit i7-4790 CPU 4.00 Hz,32 GB RAM, With TVP Animation 11 Pro (11.0.2-64bits)
2 Monitors 1920X1080 pixels + 1 Wacom Cintiq 21UX 2
User avatar
Eric Scholl
Posts: 1303
Joined: 04 Apr 2011, 14:40

Re: change one specific color to another

Post by Eric Scholl »

madsjuul wrote:Great explanation Eric. I put it into the wiki.
-Mads
Thank you Mads :D
I thought no one would understand ... :mrgreen:
User avatar
Mads Juul
Posts: 3992
Joined: 02 May 2007, 19:18
Location: Viborg,Denmark
Contact:

Re: change one specific color to another

Post by Mads Juul »

:-)
Mads Juul
Storyboard Artist
blog: http://mjstoryboard.blogspot.dk/
Mail: mjstoryboard@gmail .com

Windows 10, 64 bit i7-4790 CPU 4.00 Hz,32 GB RAM, With TVP Animation 11 Pro (11.0.2-64bits)
2 Monitors 1920X1080 pixels + 1 Wacom Cintiq 21UX 2
User avatar
ryberg
Posts: 93
Joined: 10 Mar 2009, 20:43
Location: CPH
Contact:

Re: change one specific color to another

Post by ryberg »

well, I need to practise it a lot more cause none of my scripts I just tried have worked as I thought.
User avatar
ryberg
Posts: 93
Joined: 10 Mar 2009, 20:43
Location: CPH
Contact:

Re: change one specific color to another

Post by ryberg »

after your thorough explanation, I thought I got it but as I try it out it makes less and less sense. I am completely lost here.

What I am trying to do is to turn red into light blue:

source (red):

Code: Select all

R = 255	G = 0		B = 0		A = 255
goal (light blue):

Code: Select all

R = 0	G = 150	B = 255	A = 255

So I am thinking this:

Code: Select all

0 0.588 1 0 0   0 1 0 0 0   0 0 1 0 0   0 0 0 1 0
but that create weird results.

Also, when a value is entered as 0.something decimals, I assume it equals 0.588*255 in order to return the right 255 level value of the rgba chart, am I right?

I noticed in the erase actions that negative values are present like -1, I assume this is a way to erase a color but then I ask myself what 0 is if it takes -1 to erase something. Is 0 null? does it represent unchanged values.

I am absolutely confused.
User avatar
ZigOtto
Posts: 4102
Joined: 17 Feb 2006, 22:50
Location: south-Petazonia

Re: change one specific color to another

Post by ZigOtto »

try this :

Code: Select all

tv_cmd Heads tv_pixelmatrix 0 0 0 0 0   0.588 1 0 0 0   1 0 1 0 0   0 0 0 1 0
I think it should turn the Red lines into light-Blue. :wink:
User avatar
Eric Scholl
Posts: 1303
Joined: 04 Apr 2011, 14:40

Re: change one specific color to another

Post by Eric Scholl »

ryberg wrote: So I am thinking this:

Code: Select all

0 0.588 1 0 0   0 1 0 0 0   0 0 1 0 0   0 0 0 1 0
This is not working because you applied your modification on the Red Channel (the first 5 numbers group).

You should do this :

First group ( R ), erase the red :

0 0 0 0 0

Second group ( G ), use the value of the red color with a ratio ( 255->150) but keep the green value :

0.588 1 0 0 0

First group ( B ), use the red value and keep the blue value :

1 0 1 0 0

Last group ( A ), just keep the Alpha value :

0 0 0 1 0

So you do this :
ZigOtto wrote:

Code: Select all

tv_cmd Heads tv_pixelmatrix 0 0 0 0 0   0.588 1 0 0 0   1 0 1 0 0   0 0 0 1 0
User avatar
ryberg
Posts: 93
Joined: 10 Mar 2009, 20:43
Location: CPH
Contact:

Re: change one specific color to another

Post by ryberg »

thank you guys for being so patient with me, I guess I got confused with source and result. It's really nice to get this covered, I've been wondering about this for a long time.

This takes some practise. :D

First, I thought I needed to type in values in the first group (R) in order to change that into green, but I see it simply needs to be erased.

So in the second group (B), the change from red to light blue (partial green, aka green), happens when I put in a value in "r" the first number that represents red. If I would leave the value 1, it will turn red into full green (combined with a full blue the result will be dark blue (r: 0 g: 255 b: 255)).
And I need to put in 1 in "b" the third number representing blue in order to maintain blue colors in whatever this action is applied to.

Third group is basically the same as Second group, only "r" value needs to be turned into full blue hence 1.


Am I slowly getting this now? :)
Post Reply