From e468e60fc55b7f54b1d4b08fb009785dafc781b6 Mon Sep 17 00:00:00 2001 From: Leni Aniva <v@leni.sh> Date: Thu, 10 Apr 2025 15:23:06 -0700 Subject: [PATCH] feat: Temporal-dependent packing stub --- src/image.jl | 8 ++++++++ src/tdpacking.jl | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/image.jl create mode 100644 src/tdpacking.jl diff --git a/src/image.jl b/src/image.jl new file mode 100644 index 0000000..a34f334 --- /dev/null +++ b/src/image.jl @@ -0,0 +1,8 @@ +using Images + +""" +Converts image to grayscale +""" +function greyscale(c::Images.RGB)::UInt8 + return c.r +end diff --git a/src/tdpacking.jl b/src/tdpacking.jl new file mode 100644 index 0000000..a39c8d4 --- /dev/null +++ b/src/tdpacking.jl @@ -0,0 +1,39 @@ +# Time-dependent packing +struct Rect + pos::Tuple{UInt,UInt} + size::Tuple{UInt,UInt} + color::Real +end + +""" + divide_image(img::BitMatrix, size_min::UInt=16, size_max::UInt=256) + +Divides an image into rectangles of the same colour. The rectangles are not +allowed to have extreme aspect ratios. There is a minimal size of each retangle. +""" +function divide_image(img::Matrix{}, size_min::UInt=16, size_max::UInt=256)::Array{Rect} + result = Rect[] + + # Remaining area + area = sizeof(img) + + # Loop until the entire field is filled + while area > 0 + pos = (9, 9) + size = (threshold, threshold) + region = img.size + + # Try to expand this rectangle to the maximum size + + while size[1] < region[1] || size[2] < region[2] + end + + color = 0.5 + push!(result, Rect(pos, size, color)) + + # Update the boundary markers for the next iteration + area -= size[1] * size[2] + end + + return result +end