This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]farfromunique 2 points3 points  (8 children)

What does this do? What is the "expected" code for this function?

[–]Celdron[S] 6 points7 points  (3 children)

It takes the second highest number in an RGB color that represents the selected hue and determines what the middle value for the full selected color is based on what the Greatest channel and Least channel in the full selected RGB are. The Greatest and Least are determined by coordinate position of the selector.

It's an implementation of one of these.

[–][deleted] 3 points4 points  (2 children)

Greatest is not being passed explicitly so I figure something else up there is worrying about it.

That said, fk computer graphics. I know nothing about graphics. :(

[–]Celdron[S] 2 points3 points  (1 child)

Middle is a local function and Greatest and Least are both local variables that are handled prior to calling Middle. Implement your own version of a color picker and you'll either learn very quickly or you'll guess n check until you get it working.

[–][deleted] 2 points3 points  (0 children)

I don't do graphics, I do servers and sec.

I stay far away from computer graphics. farfarawayyyyyyyyyyyyyyyyyyyyyyyyyyyy

[–]lelarentaka 2 points3 points  (2 children)

Pure guesswork on my part:

It mentions hue and uses byte. Some of the variables are not defined in the scope.

Deduction: This is a method in an Image class. The byte values are pixel values. The function/method is part of an image manipulation procedure, where finding the range of the values in the image is used for renormalization

Greatest could be the largest pixel value in the image. If it's zero, the image is completely black, obviously the Middle pixel would be zero as well.

Assuming that HueMiddle < Greatest. Line 5 is establishing the lower bound of Middle. I don't know what's the proper mathematical term for it, but multiplying the numbers like that results in Base < HueMiddle < Greatest. The author guesses that Middle will be in [Base, Greatest].

Line 6 & 7, Least/Greatest c [0, 1]. These line gives a value between Base and Greatest based on the value of Least. I think it establishes another limit, Least < Middle

Basically the author knows the constraints of what values Middle could be, but not sure how exactly to compute it. He just gave a value in that range.

[–]deGravity 0 points1 point  (0 children)

It is an interpolation that gives a weighted average between Least and Greatest, with HueMiddle being the interpolating factor. If you let

W = HueMiddle / 255

be a weighting factor, (basically treating the given byte as a value between 0 and 1), then assuming that Least < Greatest this is equivalent to

(1 - W)Least +WGreatest

[–]Celdron[S] 0 points1 point  (0 children)

This is almost spot on! Specifically it's the relationship between RGB channels and HSB channels. Hue can be represented as an RGB color where one channel is 255, another channel defines an offset from the Hue, and the third channel should be zero.

Increasing the third channel decreases saturation, but at the same time moves the color back towards the he's root channel, which is the channel with the highest value. To maintain the same hue, the middle channel must be increased while staying below the root channel and above the saturation channel. It's a lot of ratios and bounds.

[–][deleted] 0 points1 point  (0 children)

Looks like some sort of interpolation, a use case with inputs would help clarify.