Skip to content

Commit

Permalink
Merge pull request seatedro#4 from gabe-burnette/main
Browse files Browse the repository at this point in the history
Inverted colors
  • Loading branch information
seatedro authored Aug 31, 2024
2 parents bb93cb9 + 0656771 commit eb8943d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ run the program with the following options (the default zig install directory is
- `-i, --input <file>`: specify the input image file path (local path/URL) (required)
- `-o, --output <file>`: specify the output image file (optional, default: `<input>_ascii.jpg`)
- `-c, --color`: use color ascii characters (optional)
- `-n, --invert_color`: Inverts the color values (optional)
- `-s, --scale <float>`: set the downscale or upscale factor (optional, default: 1)
- `-e, --detect_edges`: enable edge detection (optional)
- `--sigma1 <float>`: set the sigma1 value for DoG filter (optional, default: 0.3)
Expand Down
20 changes: 16 additions & 4 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const Args = struct {
input: []const u8,
output: []const u8,
color: bool,
invert_color: bool,
scale: f32,
detect_edges: bool,
sigma1: f32,
Expand All @@ -174,10 +175,11 @@ fn parseArgs(allocator: std.mem.Allocator) !Args {
\\-i, --input <str> Input image file
\\-o, --output <str> Output image file
\\-c, --color Use color ASCII characters
\\-s, --scale <f32> Scale factor (default: 8)
\\-n, --invert_color Inverts the color values
\\-s, --scale <f32> Scale factor (default: 8)
\\-e, --detect_edges Detect edges
\\ --sigma1 <f32> Sigma 1 for DoG filter (default: 0.5)
\\ --sigma2 <f32> Sigma 2 for DoG filter (default: 1.0)
\\ --sigma1 <f32> Sigma 1 for DoG filter (default: 0.5)
\\ --sigma2 <f32> Sigma 2 for DoG filter (default: 1.0)
\\-b, --brightness_boost <f32> Brightness boost (default: 1.0)
);

Expand Down Expand Up @@ -211,6 +213,7 @@ fn parseArgs(allocator: std.mem.Allocator) !Args {
break :blk std.fs.path.join(allocator, &.{ current_dir, output_filename }) catch unreachable;
},
.color = res.args.color != 0,
.invert_color = res.args.invert_color != 0,
.scale = res.args.scale orelse 1.0,
.detect_edges = res.args.detect_edges != 0,
.sigma1 = res.args.sigma1 orelse 0.5,
Expand Down Expand Up @@ -698,11 +701,19 @@ fn selectAsciiChar(block_info: BlockInfo, args: Args) u8 {

fn calculateAverageColor(block_info: BlockInfo, args: Args) [3]u8 {
if (args.color) {
return .{
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;
} else {
return .{ 255, 255, 255 };
}
Expand Down Expand Up @@ -743,6 +754,7 @@ test "test_ascii_generation" {
.input = "https://w.wallhaven.cc/full/p9/wallhaven-p9gr2p.jpg",
.output = tmp_path,
.color = false,
.invert_color = false,
.scale = 8.0,
.detect_edges = false,
.sigma1 = 0.5,
Expand Down

0 comments on commit eb8943d

Please sign in to comment.