dl
dl_image.h
浏览该文件的文档.
1
16#pragma once
17
18#include <string>
19
20#include "base/dl_vector2.h"
21#include "dl_type.h"
22#include "base/dl_range_any.h"
23#include "memory/dl_buffer.h"
24
25namespace dl
26{
27
29
36Image* createImage(const Size& size, const Color& col);
42Image* createImage(std::string_view path_name);
43
50Image* createImageSvg(std::string_view path_name, const Size& size);
51
58Image* createImageWebp(std::string_view path_name);
59
60
62
66bool saveImage(const Image* img, std::string_view path_name);
67
68namespace Img
69{
76inline bool IsSupportFormat(std::string_view str, bool read)
77{
78 constexpr std::array<std::string_view, 8> ARRAY_READ = {
79 "jpg", "png", "tga", "bmp", "psd", "gif", "hdr", "pic"
80 };
81 constexpr std::array<std::string_view, 3> ARRAY_WRITE = {
82 "png", "tag", "bmp"
83 };
84 return read ? Any::Equal(ARRAY_READ, str) : Any::Equal(ARRAY_WRITE, str);
85}
86
87
88constexpr std::string_view REGEX_FORMAT = ".(jpg|png|tag|bmp|psd|gif|hdr|pic)$";
89
90
95void CalcLeastRect(const Image* img, RectU& rect);
96
97
102bool IsHaveTranslucent(const Image* img, const RectU& rect);
103
112void AddImageRect(Image* img_tar, const Image* img_src, const RectU& rect, const PointU& tar_xy);
113
117void SetAlphaZero(const Image* img);
118
124Image* ResizeImage(const Image* img, const Size& size);
125
126Image* ResizeImage(const Image* img, Float scale);
127
128enum class ExtendMode
129{
130 ZERO, // 填充0
131 COPY, // 复制边缘颜色
132};
133
138Image* Extend(const Image* img, unsigned i, ExtendMode mode = ExtendMode::ZERO);
139
145void BuildBorder(Image* img, unsigned i);
146
147}
148}
表示一段内存
范围操作 任一满足条件
通用类型
2维vector
bool Equal(const C &container, const V &v)
判断容器任意元素等于某值
void CalcLeastRect(const Image *img, RectU &rect)
计算返回最小包围盒(去除边缘的全透明像素)
Image * Extend(const Image *img, unsigned i, ExtendMode mode=ExtendMode::ZERO)
拓展图像边缘像素
bool IsSupportFormat(std::string_view str, bool read)
是否支持的格式
bool IsHaveTranslucent(const Image *img, const RectU &rect)
返回是否包含非透明颜色
constexpr std::string_view REGEX_FORMAT
Image * ResizeImage(const Image *img, const Size &size)
缩放图像
void AddImageRect(Image *img_tar, const Image *img_src, const RectU &rect, const PointU &tar_xy)
添加另一个图像的部分到自己的位置上
void SetAlphaZero(const Image *img)
设置透明色颜色为0,针对于某些颜色透明,但是其他通道非0
void BuildBorder(Image *img, unsigned i)
填充边缘像素按最近的像素
std::span< std::byte > BufferView
float Float
bool saveImage(const Image *img, std::string_view path_name)
保存到图像
Vector2< uint32_t > Image
Point2U PointU
Image * createImageSvg(std::string_view path_name, const Size &size)
创建图像 从svg
Image * createImageWebp(std::string_view path_name)
创建图像 从webp
Image * createImage(const Size &size, const Color &col)
创建图像
Point4U RectU
std::array< float, 4 > Color
PointU Size