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
30
32namespace Img
33{
40inline bool IsSupportFormat(std::string_view str, bool read)
41{
42 constexpr std::array<std::string_view, 9> ARRAY_READ = {
43 "jpg", "jpeg", "png", "tga", "bmp", "psd", "gif", "hdr", "pic"
44 };
45 constexpr std::array<std::string_view, 3> ARRAY_WRITE = {
46 "png", "tag", "bmp"
47 };
48 return read ? Any::Equal(ARRAY_READ, str) : Any::Equal(ARRAY_WRITE, str);
49}
50
51// 不读取psd
52constexpr std::string_view REGEX_FORMAT = ".(jpg|jpeg|png|tag|bmp|gif|hdr|pic)$";
53
54
55
62Image* Create(const Size& size, const Color& col);
68Image* Create(std::string_view path_name);
69
70
77Image* CreateSvg(std::string_view path_name, const Size& size);
78
85Image* CreateWebp(std::string_view path_name);
86
87
89
93bool Save(const Image* img, std::string_view path_name);
94
98bool SaveKtx(std::span<Image*> vec_img, std::string_view path_name);
99inline bool SaveKtx(Image* img, std::string_view path_name)
100{
101 std::array<Image*, 1> arr = { img };
102 return SaveKtx(arr, path_name);
103}
104
111void CalcLeastRect(const Image* img, RectU& rect);
112
113
118bool IsHaveTranslucent(const Image* img, const RectU& rect);
119
128void AddRect(Image* img_tar, const Image* img_src, const RectU& rect, const PointU& tar_xy);
129
139void SetAlphaZero(Image* img, uint8_t a, uint32_t col_new = 0);
140
141
147Image* Resize(const Image* img, const Size& size);
148
149Image* Resize(const Image* img, Float scale);
150
151enum class ExtendMode
152{
153 ZERO, // 填充0
154 COPY, // 复制边缘颜色
155};
156
161Image* Extend(const Image* img, unsigned i, ExtendMode mode = ExtendMode::ZERO);
162
168void BuildBorder(Image* img, unsigned i);
169
176
177}
178
179}
表示一段内存
范围操作 任一满足条件
通用类型
2维vector
bool Equal(const C &container, const V &v)
判断容器任意元素等于某值
图像操作
void SetAlphaZero(Image *img)
设置透明色颜色为0,针对于某些颜色透明,但是其他通道非0
Image * CreateWebp(std::string_view path_name)
创建图像 从webp
void CalcLeastRect(const Image *img, RectU &rect)
计算返回最小包围盒(去除边缘的全透明像素)
Image * Extend(const Image *img, unsigned i, ExtendMode mode=ExtendMode::ZERO)
拓展图像边缘像素
void AddRect(Image *img_tar, const Image *img_src, const RectU &rect, const PointU &tar_xy)
添加另一个图像的部分到自己的位置上
bool IsSupportFormat(std::string_view str, bool read)
是否支持的格式
void CvtEffect2Normal(Image *img)
特效图片转普通图片
Image * CreateSvg(std::string_view path_name, const Size &size)
创建图像 从svg
bool IsHaveTranslucent(const Image *img, const RectU &rect)
返回是否包含非透明颜色
constexpr std::string_view REGEX_FORMAT
bool SaveKtx(std::span< Image * > vec_img, std::string_view path_name)
保存到图像(ktx格式)
bool Save(const Image *img, std::string_view path_name)
保存到图像
Image * Create(const Size &size, const Color &col)
创建图像
Image * Resize(const Image *img, const Size &size)
缩放图像
void BuildBorder(Image *img, unsigned i)
填充边缘像素按最近的像素
float Float
Point2U PointU
Array< float, 4 > Color
Vector2< uint32_t, unsigned > Image
Point4U RectU
PointU Size