mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-20 12:34:19 +02:00
support full_color option
This commit is contained in:
parent
dc1793d2ff
commit
d6751451b1
3 changed files with 35 additions and 6 deletions
|
|
@ -200,6 +200,8 @@ fg = 0x00FFFFFF
|
|||
# TB_WHITE 0x0008
|
||||
# If full color is off, the styling options still work. The colors are
|
||||
# always 32-bit values with the styling in the most significant byte.
|
||||
# Note: If using the dur_file animation option and the dur file's color range
|
||||
# is saved as 256 with this option disabled, the file will not be drawn.
|
||||
full_color = true
|
||||
|
||||
# Game of Life entropy interval (0 = disabled, >0 = add entropy every N generations)
|
||||
|
|
|
|||
|
|
@ -172,8 +172,27 @@ const DurFormat = struct {
|
|||
}
|
||||
};
|
||||
|
||||
const tb_color_16 = [16]u32{
|
||||
0x00000001, // black
|
||||
0x00000002, // red
|
||||
0x00000003, // green
|
||||
0x00000004, // yellow
|
||||
0x00000005, // blue
|
||||
0x00000006, // magenta
|
||||
0x00000007, // cyan
|
||||
0x00000008, // light gray
|
||||
0x01000001, // gray (bright black)
|
||||
0x01000002, // bright red
|
||||
0x01000003, // bright green
|
||||
0x01000004, // bright yellow
|
||||
0x01000005, // bright blue
|
||||
0x01000006, // bright magenta
|
||||
0x01000007, // bright cyan
|
||||
0x01000008 // white
|
||||
};
|
||||
|
||||
// Using bold for bright colors allows for all 16 colors to be rendered on tty term
|
||||
const color16 = [16]u32{
|
||||
const rgb_color_16 = [16]u32{
|
||||
0x00000000, // black
|
||||
0x00800000, // red
|
||||
0x00008000, // green
|
||||
|
|
@ -233,7 +252,7 @@ fn convert_256_to_rgb(color_256: u32) u32 {
|
|||
var rgb_color: u32 = 0;
|
||||
|
||||
if (color_256 < 16) {
|
||||
rgb_color = color16[color_256];
|
||||
rgb_color = rgb_color_16[color_256];
|
||||
}
|
||||
else if (color_256 < 232) {
|
||||
rgb_color |= sixcube_to_channel(((color_256 - 16) / 36) % 6 ) << 16;
|
||||
|
|
@ -257,6 +276,7 @@ frames: u64,
|
|||
time_previous: i64,
|
||||
x_offset: u32,
|
||||
y_offset: u32,
|
||||
full_color: bool,
|
||||
dur_movie: DurFormat,
|
||||
|
||||
pub fn init(allocator: Allocator,
|
||||
|
|
@ -264,7 +284,8 @@ pub fn init(allocator: Allocator,
|
|||
log_writer: *std.io.Writer,
|
||||
file_path: []const u8,
|
||||
x_offset: u32,
|
||||
y_offset: u32) !DurFile {
|
||||
y_offset: u32,
|
||||
full_color: bool) !DurFile {
|
||||
var dur_movie: DurFormat = .init(allocator);
|
||||
|
||||
// error state when DurParseError is recoverable and results in no background
|
||||
|
|
@ -290,6 +311,7 @@ pub fn init(allocator: Allocator,
|
|||
.time_previous = std.time.milliTimestamp(),
|
||||
.x_offset = std.math.clamp(x_offset, 0, buf_width - 1),
|
||||
.y_offset = std.math.clamp(y_offset, 0, buf_height - 1),
|
||||
.full_color = full_color,
|
||||
.dur_movie = dur_movie,
|
||||
};
|
||||
}
|
||||
|
|
@ -307,6 +329,8 @@ fn realloc(_: *DurFile) anyerror!void {}
|
|||
fn draw(self: *DurFile) void {
|
||||
// dur_movie will be invalid if DurParseError errored out in init
|
||||
if (!self.dur_movie.valid()) return;
|
||||
// 4 bit mode with 256 color is unsupported
|
||||
if (!self.full_color and eql(u8, self.dur_movie.colorFormat.?, "256")) return;
|
||||
|
||||
const buf_width: u32 = @intCast(self.terminal_buffer.width);
|
||||
const buf_height: u32 = @intCast(self.terminal_buffer.height);
|
||||
|
|
@ -336,10 +360,13 @@ fn draw(self: *DurFile) void {
|
|||
color_map_1 = durcolor_table_to_color16[color_map_1 + 1]; // Add 1, dur source stores it like this for some reason
|
||||
}
|
||||
|
||||
const fg_color = if(self.full_color) convert_256_to_rgb(color_map_0) else tb_color_16[color_map_0];
|
||||
const bg_color = if(self.full_color) convert_256_to_rgb(color_map_1) else tb_color_16[color_map_1];
|
||||
|
||||
const cell = Cell {
|
||||
.ch = @intCast(codepoint),
|
||||
.fg = convert_256_to_rgb(color_map_0),
|
||||
.bg = convert_256_to_rgb(color_map_1)
|
||||
.fg = fg_color,
|
||||
.bg = bg_color
|
||||
};
|
||||
|
||||
cell.put(x + self.x_offset, y + self.y_offset);
|
||||
|
|
|
|||
|
|
@ -574,7 +574,7 @@ pub fn main() !void {
|
|||
animation = game_of_life.animation();
|
||||
},
|
||||
.dur_file => {
|
||||
var dur = try DurFile.init(allocator, &buffer, log_writer, config.dur_file_path, config.dur_x_offset, config.dur_y_offset);
|
||||
var dur = try DurFile.init(allocator, &buffer, log_writer, config.dur_file_path, config.dur_x_offset, config.dur_y_offset, config.full_color);
|
||||
animation = dur.animation();
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue