Skip to content

Commit

Permalink
added custom color
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Burnette committed Sep 7, 2024
1 parent d62f9e3 commit 74f632d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ run the program with the following options (the default zig install directory is
- ` --sigma1 <float>`: set the sigma1 value for DoG filter (optional, default: 0.3)
- ` --sigma2 <float>`: set the sigma2 value for DoG filter (optional, default: 1.0)
- `-b, --brightness_boost <float>`: increase/decrease perceived brightness (optional, default: 1.0)

advanced options (your image will break, probably, but you might get some cool results):
- ` --full_characters`: Uses full spectrum of characters in image.
- ` --ascii_chars <string>`: Use what characters you want to use in the image. (default: " .:-=+*%@#")
- ` --disable_sort`: Prevents sorting of the ascii_chars by size.
- ` --block_size <u8>`: Set the size of the blocks. (default: 8)
- ` --threshold_disabled`: Disables the threshold.

set a custom color value
- ` --custom_color`: Enables custom color from the --r, --g, --b parameters
- ` --r`: Sets the r color.
- ` --g`: Sets the g color.
- ` --b`: Sets the b color.

2. examples:

basic usage:
Expand Down
59 changes: 46 additions & 13 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ const Args = struct {
disable_sort: bool,
block_size: u8,
threshold_disabled: bool,
custom_color: bool,
r: u8,
g: u8,
b: u8,
};

const Image = struct {
Expand Down Expand Up @@ -189,6 +193,10 @@ fn parseArgs(allocator: std.mem.Allocator) !Args {
\\ --disable_sort Prevents sorting of the ascii_chars by size.
\\ --block_size <u8> Set the size of the blocks. (default: 8)
\\ --threshold_disabled Disables the threshold.
\\ --custom_color Enables custom color from the --r, --g, --b parameters.
\\ --r <u8> Sets the r color.
\\ --g <u8> Sets the g color.
\\ --b <u8> Sets the b color.
);

var diag = clap.Diagnostic{};
Expand Down Expand Up @@ -248,6 +256,10 @@ fn parseArgs(allocator: std.mem.Allocator) !Args {
.disable_sort = res.args.disable_sort != 0,
.block_size = res.args.block_size orelse 8,
.threshold_disabled = res.args.threshold_disabled != 0,
.custom_color = res.args.custom_color != 0,
.r = res.args.r orelse 128,
.g = res.args.g orelse 128,
.b = res.args.b orelse 128,
};
}

Expand Down Expand Up @@ -775,21 +787,38 @@ fn selectAsciiChar(block_info: BlockInfo, args: Args) u8 {

fn calculateAverageColor(block_info: BlockInfo, args: Args) [3]u8 {
if (args.color) {
var color = [3]u8{
@intCast(block_info.sum_color[0] / block_info.pixel_count),
@intCast(block_info.sum_color[1] / block_info.pixel_count),
@intCast(block_info.sum_color[2] / block_info.pixel_count),
};

if (args.invert_color) {
color[0] = 255 - color[0];
color[1] = 255 - color[1];
color[2] = 255 - color[2];
if (args.custom_color) {
const color = [3]u8{
args.r,
args.g,
args.b,
};
return color;
} else {
var color = [3]u8{
@intCast(block_info.sum_color[0] / block_info.pixel_count),
@intCast(block_info.sum_color[1] / block_info.pixel_count),
@intCast(block_info.sum_color[2] / block_info.pixel_count),
};

if (args.invert_color) {
color[0] = 255 - color[0];
color[1] = 255 - color[1];
color[2] = 255 - color[2];
}
return color;
}

return color;
} else {
return .{ 255, 255, 255 };
if (args.custom_color) {
const color = [3]u8{
args.r,
args.g,
args.b,
};
return color;
} else {
return .{ 255, 255, 255 };
}
}
}

Expand Down Expand Up @@ -839,6 +868,10 @@ test "test_ascii_generation" {
.disable_sort = false,
.block_size = 8,
.threshold_disabled = false,
.custom_color = false,
.r = 0,
.g = 0,
.b = 0,
};

// Run the main function with test arguments
Expand Down

0 comments on commit 74f632d

Please sign in to comment.