Skip to content

Commit

Permalink
Merge remote-tracking branch 'Brandon502/2byte-mapping2' into 2byte-m…
Browse files Browse the repository at this point in the history
…apping
  • Loading branch information
ewoudwijma committed Jul 27, 2024
2 parents a2e1c58 + 31a56f2 commit dc5ce3b
Showing 1 changed file with 46 additions and 18 deletions.
64 changes: 46 additions & 18 deletions src/App/LedEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -2812,35 +2812,61 @@ class Byte2TestEffect2: public Effect {

CRGB color;

if (colorMode == 0) {
if (colorMode == 0) { // Palette
color = ColorFromPalette(leds.palette, random8(), 255);
} else if (colorMode == 1) {
} else if (colorMode == 1) { // Random
color = CRGB(random8(), random8(), random8());
} else if (colorMode == 2) {
} else if (colorMode == 2) { // Custom
color = CRGB(customColor.x, customColor.y, customColor.z);
}

CRGB rColor;

// Define masks for different bit depths
const uint8_t MASK_6BIT = 0xFC; // 6 bits: 1111 1100
const uint8_t MASK_5BIT = 0xF8; // 5 bits: 1111 1000
const uint8_t MASK_4BIT = 0xF0; // 4 bits: 1111 0000
const uint8_t MASK_3BIT = 0xE0; // 3 bits: 1110 0000

// Apply different draw methods using the masks
if (drawMethod == 0) { // 653
rColor.r = (color.r >> 2) << 2; // 6 bit
rColor.g = (color.g >> 3) << 3; // 5 bit
rColor.b = (color.b >> 5) << 5; // 3 bit
rColor.r = color.r & MASK_6BIT; // 6 bit
rColor.g = color.g & MASK_5BIT; // 5 bit
rColor.b = color.b & MASK_3BIT; // 3 bit
}
else if (drawMethod == 1) { // 653 rounding b
rColor.r = (color.r >> 2) << 2; // 6 bit
rColor.g = (color.g >> 3) << 3; // 5 bit
rColor.b = (min(color.b + 15, 255) >> 5) << 5; // 3 bit
rColor.r = color.r & MASK_6BIT; // 6 bit
rColor.g = color.g & MASK_5BIT; // 5 bit
rColor.b = (min(color.b + 15, 255)) & MASK_3BIT; // 3 bit
}
else if (drawMethod == 2) { // 554
rColor.r = (color.r >> 3) << 3; // 5 bit
rColor.g = (color.g >> 3) << 3; // 5 bit
rColor.b = (color.b >> 4) << 4; // 4 bit
}
else if (drawMethod == 3) { // 554 offset
rColor.r = (min(color.r + 4, 255) >> 3) << 3; // 5 bit
rColor.g = (min(color.g + 4, 255) >> 3) << 3; // 5 bit
rColor.b = (min(color.b + 8, 255) >> 4) << 4; // 4 bit
rColor.r = color.r & MASK_5BIT; // 5 bit
rColor.g = color.g & MASK_5BIT; // 5 bit
rColor.b = color.b & MASK_4BIT; // 4 bit
}
else if (drawMethod == 3) { // 554 with offset (offset would be added in getPixelColor)
rColor.r = (color.r & MASK_5BIT); // 5 bit
rColor.g = (color.g & MASK_5BIT); // 5 bit
rColor.b = (color.b & MASK_4BIT); // 4 bit
if (rColor.r == 248) rColor.r += 6; else rColor.r += 4; // + offset
if (rColor.g == 248) rColor.g += 6; else rColor.g += 4; // + offset
if (rColor.b == 240) rColor.b += 12; else rColor.b += 8; // + offset
}
else if (drawMethod == 4) { // 554 with rounding
rColor.r = (min(color.r + 3, 255)) & MASK_5BIT; // 5 bit
rColor.g = (min(color.g + 3, 255)) & MASK_5BIT; // 5 bit
rColor.b = (min(color.b + 7, 255)) & MASK_4BIT; // 4 bit
}
else if (drawMethod == 5) { // 554 custom (random methods)
rColor.r = color.r & MASK_5BIT; // 5 bit
rColor.g = color.g & MASK_5BIT; // 5 bit
rColor.b = color.b & MASK_4BIT; // 4 bit
if (rColor.r == 248) rColor.r += 2;
if (rColor.g == 248) rColor.g += 2;
if (rColor.b == 240) rColor.b += 4;
if (rColor.r > 0) rColor.r += 4;
if (rColor.g > 0) rColor.g += 4;
if (rColor.b > 0) rColor.b += 8;
}

int half = leds.size.x/2;
Expand All @@ -2852,7 +2878,7 @@ class Byte2TestEffect2: public Effect {
}

if (debugPrint) {
ppf("Left: %3d,%3d,%3d Right: %3d,%3d,%3d Difference: %d, %d, %d\n", color.r, color.g, color.b, rColor.r, rColor.g, rColor.b, abs(color.r - rColor.r), abs(color.g - rColor.g), abs(color.b - rColor.b));
ppf("Left: %3d,%3d,%3d Right: %3d,%3d,%3d Difference: %d, %d, %d\n", color.r, color.g, color.b, rColor.r, rColor.g, rColor.b, rColor.r - color.r, rColor.g - color.g, rColor.b - color.b);
}

*step = sys->now;
Expand Down Expand Up @@ -2880,6 +2906,8 @@ class Byte2TestEffect2: public Effect {
options.add("653 round b");
options.add("554");
options.add("554 offset");
options.add("554 rounding");
options.add("554 custom");
return true;
}
default: return false;
Expand Down

0 comments on commit dc5ce3b

Please sign in to comment.