Skip to content

Commit

Permalink
HueSaturation color mode
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Sep 24, 2024
1 parent 1ceff48 commit cf62de5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
67 changes: 47 additions & 20 deletions Source/Object/Component/components/color/ColorComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ColorComponent::ColorComponent(Object* o, var params) :
useDimmerForOpacity = addBoolParameter("Use Dimmer for Opacity", "If checked, use the dimmer component for color opacity", false);

colorMode = addEnumParameter("Color Mode", "Color mode for this object");
colorMode->addOption("RGB", RGB)->addOption("RGBW", RGBW)->addOption("WRGB", WRGB)->addOption("RGBAW", RGBAW)->addOption("RGBWA", RGBWA)->addOption("CMY", CMY);
colorMode->addOption("RGB", RGB)->addOption("RGBW", RGBW)->addOption("WRGB", WRGB)->addOption("RGBAW", RGBAW)->addOption("RGBWA", RGBWA)->addOption("CMY", CMY)->addOption("Hue-Saturation", HS);

fineMode = addEnumParameter("Fine Mode", "Fine Color Mode for this object. None means not using fine channels. Alternate means R/R fine, G/G fine, etc. Follow means R/G/B/R fine/G fine/ B fine, etc.");
fineMode->addOption("None", None)->addOption("Alternate", Alternate)->addOption("Follow", Follow);
Expand Down Expand Up @@ -196,7 +196,24 @@ void ColorComponent::fillInterfaceDataInternal(Interface* i, var data, var param

FineMode fm = fineMode->getValueDataAsEnum<FineMode>();

int colorSize = (cm == RGB || cm == CMY) ? 3 : (cm == RGBW || cm == WRGB) ? 4 : 5;
int colorSize = 3;

switch (cm)
{
case HS:
colorSize = 2;
break;

case RGBW:
case WRGB:
colorSize = 4;
break;

default:
colorSize = 3;
break;
}

int finalColorSize = fm == None ? colorSize : colorSize * 2;


Expand All @@ -205,19 +222,41 @@ void ColorComponent::fillInterfaceDataInternal(Interface* i, var data, var param
for (int i = 0; i < outColors.size(); i++)
{
var c;
if (cm == RGBW || cm == WRGB) c = ColorHelpers::getRGBWFromRGB(outColors[i], temp);
else if (cm == RGBWA || cm == RGBAW) c = ColorHelpers::getRGBWAFromRGB(outColors[i], temp);
else if (cm == CMY)

switch (cm)
{

case HS:
{
float h, s, b;
outColors[i].getHSB(h, s, b);

c.append(h);
c.append(s);
}
break;

case RGBW:
case WRGB:
c = ColorHelpers::getRGBWFromRGB(outColors[i], temp);
break;

case RGBAW:
case RGBWA:
c = ColorHelpers::getRGBWAFromRGB(outColors[i], temp);
break;

case CMY:
c.append(1 - outColors[i].getFloatRed());
c.append(1 - outColors[i].getFloatGreen());
c.append(1 - outColors[i].getFloatBlue());
}
else
{
break;

default:
c.append(outColors[i].getFloatRed());
c.append(outColors[i].getFloatGreen());
c.append(outColors[i].getFloatBlue());
break;
}

int ch = targetChannel + i * finalColorSize;
Expand Down Expand Up @@ -257,18 +296,6 @@ void ColorComponent::fillInterfaceDataInternal(Interface* i, var data, var param
ObjectComponent::fillInterfaceDataInternal(i, data, params);
}

//void ColorComponent::fillOutValueMap(HashMap<int, float>& channelValueMap, int startChannel, bool ignoreChannelOffset)
//{
// int index = startChannel + (ignoreChannelOffset ? 0 : channelOffset);
// for (auto& c : outColors)
// {
// channelValueMap.set(index++, c.getFloatRed());
// channelValueMap.set(index++, c.getFloatGreen());
// channelValueMap.set(index++, c.getFloatBlue());
// //if(useAlpha) channelValueMap.set(index++, c.getFloatAlpha());
// }
//}

void ColorComponent::onContainerParameterChangedInternal(Parameter* p)
{
ObjectComponent::onContainerParameterChangedInternal(p);
Expand Down
5 changes: 3 additions & 2 deletions Source/Object/Component/components/color/ColorComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ class ColorComponent :

std::unique_ptr<PixelShape> pixelShape;

enum ColorMode { RGB, RGBW, WRGB, RGBAW, RGBWA, CMY, MODES_MAX };
enum ColorMode { RGB, RGBW, WRGB, RGBAW, RGBWA, CMY, HS, MODES_MAX };
const int colorModeIndices[MODES_MAX][5] = {
{ 0, 1, 2, -1, -1},
{ 0, 1, 2, 3, -1 },
{ 3, 0, 1, 2, -1 },
{ 0, 1, 2, 4, 3 },
{ 0, 1, 2, 3, 4 },
{0,1,2,-1,-1 }
{ 0, 1, 2, -1, -1},
{ 0, 1, -1, -1, -1}
};

enum FineMode { None, Alternate, Follow };
Expand Down

0 comments on commit cf62de5

Please sign in to comment.