更新到最新进度

This commit is contained in:
2025-10-28 16:44:44 +08:00
parent f615f8cfa8
commit 616aebbb4f
4 changed files with 31 additions and 17 deletions

View File

@ -2,6 +2,9 @@
#include <math.h>
#include <string.h>
#define DATA_HIGH 0b00011111
#define DATA_LOW 0b00000011
Color hex_to_color(int hex) {
Color color;
@ -60,15 +63,27 @@ Color hsv_to_color(double h, double s, double v) {
return color;
}
Color fix_color(const Color color) {
Color result;
result.r = color.r * color.r / 0xff;
result.g = color.g * color.g * 0x88 / 0xff / 0xff;
result.b = color.b * color.b * 0x66 / 0xff / 0xff;
return result;
}
void set_color(uint8_t* buffer, const Color color) {
for (int i = 7; i >= 0; i--)
*buffer++ = (color.g & (1 << i)) ? 0b11111000 : 0b10000000;
// *buffer++ = 0x00;
for (int i = 7; i >= 0; i--)
*buffer++ = (color.r & (1 << i)) ? 0b11111000 : 0b10000000;
*buffer++ = (color.g & (1 << i)) ? DATA_HIGH : DATA_LOW;
for (int i = 7; i >= 0; i--)
*buffer++ = (color.b & (1 << i)) ? 0b11111000 : 0b10000000;
*buffer++ = (color.r & (1 << i)) ? DATA_HIGH : DATA_LOW;
for (int i = 7; i >= 0; i--)
*buffer++ = (color.b & (1 << i)) ? DATA_HIGH : DATA_LOW;
}
int construct_buffer(uint8_t* buffer,
@ -79,7 +94,8 @@ int construct_buffer(uint8_t* buffer,
const int data_size = num_leds * color_bytes + res_bytes;
memset(buffer, 0, data_size);
for (int i = 0; i < num_leds; i++) {
set_color(buffer + i * color_bytes, colors[i]);
// set_color(buffer + i * color_bytes, colors[i]);
set_color(buffer + i * color_bytes, fix_color(colors[i]));
}
return data_size;
}
}