Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "BW" Grayscale and "A" Alpha channel support #2314

Merged
merged 15 commits into from
Nov 18, 2018
Merged
13 changes: 11 additions & 2 deletions nodes/analyzer/evaluate_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ def sv_init(self, context):
self.inputs.new('VerticesSocket', "Verts UV")
self.inputs.new('StringsSocket', "U domain").prop_name = 'domU'
self.inputs.new('StringsSocket', "V domain").prop_name = 'domV'
self.outputs.new('StringsSocket', "BW")
self.outputs.new('StringsSocket', "R")
self.outputs.new('StringsSocket', "G")
self.outputs.new('StringsSocket', "B")
self.outputs.new('StringsSocket', "A")

def draw_buttons(self, context, layout):
layout.label(text="Image:")
Expand Down Expand Up @@ -133,11 +135,13 @@ def process(self):
else: domV = self.domV

# outputs
bw = [[]]
red = [[]]
alpha = [[]]
green = [[]]
blue = [[]]

if outputs['R'].is_linked or outputs['G'].is_linked or outputs['B'].is_linked:
if outputs['R'].is_linked or outputs['G'].is_linked or outputs['B'].is_linked or outputs['A'].is_linked or outputs['BW'].is_linked:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if any(socket.is_linked for socket in self.outputs):
    ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's magic :D
Unfortunately I'll be on vacation for two weeks (Mexico with no PC). I will be able to handle that only at beginning of December. If you want to fix that in the meanwhile, fell free to modify it. Otherwise I'll take care of it when I'll be back.

imag = bpy.data.images[self.image_name].pixels[:]
sizeU = bpy.data.images[self.image_name].size[0]
sizeV = bpy.data.images[self.image_name].size[1]
Expand All @@ -163,7 +167,6 @@ def process(self):
elif self.boundU == 'EXTEND':
u = max(0,min(u,sizeU-1))


if self.shift_mode_V == 'ALTERNATE':
if (u0//sizeU)%2: v += floor(sizeV*self.shiftV)
if self.shift_mode_V == 'CONSTANT':
Expand All @@ -183,10 +186,16 @@ def process(self):
red[0].append(imag[index])
green[0].append(imag[index+1])
blue[0].append(imag[index+2])
alpha[0].append(imag[index+3])
else:
red[0].append(0)
green[0].append(0)
blue[0].append(0)
alpha[0].append(0)
if outputs['BW'].is_linked:
bw[0] = [(r+g+b)/3 for r,g,b in zip(red[0], green[0], blue[0])]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(r+g+b)/3 ?
not to be picky but...
image
https://en.wikipedia.org/wiki/Grayscale

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not picky, it's my bad. I was to hurried :P, I'll fix that ;)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: ]

outputs['BW'].sv_set(bw)
outputs['A'].sv_set(alpha)
outputs['R'].sv_set(red)
outputs['G'].sv_set(green)
outputs['B'].sv_set(blue)
Expand Down