6 个版本

0.2.3 2022 年 8 月 25 日
0.2.2 2022 年 8 月 25 日
0.2.1 2022 年 4 月 17 日
0.1.1 2022 年 1 月 27 日

#557 in 图像

30 次每月下载

自定义许可

48KB
1K SLoC

Arko

Arko 是一个提供三种像素操作算法的小型库

  • 刷子:创建某种类型的刷子效果
  • 细长:在相同的行或列上复制像素到一个随机的像素数
  • 排序:经典的像素排序

该库还包含一个最小化的图像转换工具(支持png和jpg)。

如何使用

所有算法都可以在四个方向上使用

  • 从下到上
  • 从左到右
  • 从右到左
  • 从上到下

对于使用颜色的算法,以下是可用的完整颜色列表:"white","black","grey","red","yellow","green","cyan","blue","magenta"。

刷子

参数

  • in_img(str) : 输入图像的路径
  • out_img(str) : 输出图像的路径
  • force_ouput_overwrite(bool) : 允许覆盖输出图像的标志
  • proba(i32) : 算法对像素产生影响的概率
  • min(i32) : 算法开始时受影响的像素的最小值
  • max(i32) : 算法开始时受影响的像素的最大值

示例

arko::brush_bottom_to_top("input.png", "btt.png",true, 100, 4, 20);
arko::brush_left_to_right("input.png", "ltr.png",true, 100, 4, 20);
arko::brush_right_to_left("input.png", "rtl.png",true, 100, 4, 20);
arko::brush_top_to_bottom("input.png", "ttb.png",true, 100, 4, 20);

细长

全局概率

使用这些函数时,概率适用于所有颜色。

参数

  • in_img(str) : 输入图像的路径
  • out_img(str) : 输出图像的路径
  • force_ouput_overwrite(bool) : 允许覆盖输出图像的标志
  • proba(i32) : 算法激活时对下一个像素产生影响的概率
  • colors(Vec) : 算法影响的颜色列表

示例

let colors = vec![Colors::Red, Colors::Yellow, Colors::Green];
arko::slim_bottom_to_top_global("input.png", "btt.png",true, 40, colors);
arko::slim_left_to_right_global("input.png", "ltr.png",true, 40, colors);
arko::slim_right_to_left_global("input.png", "rtl.png",true, 40, colors);
arko::slim_top_to_bottom_global("input.png", "ttb.png",true, 40, colors);

按颜色概率

使用这些函数时,概率按颜色提供。

参数

  • in_img(str) : 输入图像的路径
  • out_img(str) : 输出图像的路径
  • force_ouput_overwrite(bool) : 允许覆盖输出图像的标志
  • colors_proba(Vec<(Colors, i32)>) : 受影响的颜色及其概率

示例

arko::slim_bottom_to_top_per_color("input.png", "btt.png",true, vec![(Colors::Red, 20), (Colors::Yellow, 34), (Colors::Green, 56), (Colors::Cyan, 45), (Colors::Blue, 64), (Colors::Magenta, 23)]);
arko::slim_left_to_right_per_color("input.png", "ltr.png",true, vec![(Colors::Red, 20), (Colors::Yellow, 34), (Colors::Green, 56)]);
arko::slim_right_to_left_per_color("input.png", "rtl.png",true, vec![(Colors::Green, 56), (Colors::Cyan, 45), (Colors::Blue, 64)]);
arko::slim_top_to_bottom_per_color("input.png", "ttb.png",true, vec![(Colors::Cyan, 45), (Colors::Blue, 64), (Colors::Magenta, 23)]);

排序

暴力

这些函数将影响整个图像,并按水平或垂直对像素进行排序。

参数

  • in_img(str) : 输入图像的路径
  • out_img(str) : 输出图像的路径
  • force_ouput_overwrite(bool) : 允许覆盖输出图像的标志

示例

arko::sort_brut_bottom_to_top("input.png", "btt.png", true);
arko::sort_brut_left_to_right("input.png", "ltr.png", true);
arko::sort_brut_right_to_left("input.png", "rtl.png", true);
arko::sort_brut_top_to_bottom("input.png", "ttb.png", true);

智能

参数

  • in_img(str) : 输入图像的路径
  • out_img(str) : 输出图像的路径
  • force_ouput_overwrite(bool) : 允许覆盖输出图像的标志
  • detection_type(i32)
    • 0 : 根据亮度检测
    • 1 : 根据颜色组检测
  • detection_min(i32) : 算法开始时受影响的像素的最小值(第一个范围)
  • detection_max(i32) : 算法开始时受影响的像素的最大值(第一个范围)
  • multiple_range(bool) : 使用一个或两个范围
  • detection_min_2(i32) : 算法开始时受影响的像素的最小值(第二个范围)
  • detection_max_2(i32) : 算法开始时受影响的像素的最大值(第二个范围)
  • sorting_by(i32)
    • 0 : 根据色调排序
    • 1 : 根据饱和度排序

示例

arko::sort_bottom_to_top("input.png", "btt.png", true, 0, 50, 360, false, 0, 0, 1);
arko::sort_left_to_right("input.png", "ltr.png", true, 0, 50, 360, false, 0, 0, 0);
arko::sort_right_to_left("input.png", "rtl.png", true, 0, 50, 60, true, 70, 80, 1);
arko::sort_top_to_bottom("input.png", "ttb.png", true, 0, 50, 60, true, 90, 100, 0);

转换器

参数

  • in_img(str) : 输入图像的路径
  • out_img(str) : 输出图像的路径
  • force_ouput_overwrite(bool) : 允许覆盖输出图像的标志

示例

arko::convert("input.png", "output.jpg", true);

依赖项

~16MB
~136K SLoC