-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathalgo.h
82 lines (64 loc) · 3.1 KB
/
algo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2020-2023 Sami Väisänen
// Copyright (C) 2020-2023 Ensisoft http://www.ensisoft.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "config.h"
#include "warnpush.h"
# include <glm/mat3x3.hpp>
#include "warnpop.h"
#include <string>
#include <memory>
#include "graphics/bitmap.h"
namespace gfx
{
class Device;
class Texture;
namespace algo {
enum class BlurDirection {
BiDirectional,
Horizontal,
Vertical
};
// Extract source color values that exceed the threshold magnitude on the color axis.
// This is the basis of bloom effect. Extract the color map, then blur it it and blend
// with the source image.
void ExtractColor(const gfx::Texture* src, gfx::Texture* dst, gfx::Device* device,
const gfx::Color4f& color, float threshold);
// Create a color texture from alpha texture. In other words expand a texture which originally
// only has alpha channel into a RGBA texture while keeping it as a "logical alpha" mask
void ColorTextureFromAlpha(const std::string& gpu_id, gfx::Texture* texture, gfx::Device* device);
// Apply a blur kernel on the texture. The input texture is used both as a source
// and as destination for rendering while doing multiple blur passes (defined by iterations).
// Important requirements for the texture.
// * The texture must have RGBA format.
// * The texture must use filtering mode that doesn't require mips.
// Iterations must be an even number, otherwise the result of the last blurring pass
// will not be in the input texture.
void ApplyBlur(const std::string& gpu_id, gfx::Texture* texture, gfx::Device* device,
unsigned iterations = 4, BlurDirection direction = BlurDirection::BiDirectional);
void DetectSpriteEdges(const gfx::Texture* src, gfx::Texture* dst, gfx::Device* device,
const gfx::Color4f& edge_color = gfx::Color::White);
void DetectSpriteEdges(const std::string& gpu_id, gfx::Texture* texture, gfx::Device* device,
const gfx::Color4f& edge_color = gfx::Color::White);
void CopyTexture(const gfx::Texture* src, gfx::Texture* dst, gfx::Device* device, const glm::mat3& matrix = glm::mat3(1.0f));
enum class FlipDirection {
Horizontal,
Vertical
};
void FlipTexture(const std::string& gpu_id, gfx::Texture* texture, gfx::Device* device, FlipDirection direction);
std::unique_ptr<IBitmap> ReadTexture(const gfx::Texture* texture, gfx::Device* device);
void ClearTexture(gfx::Texture* texture, gfx::Device* device, const gfx::Color4f& clear_color);
} // namespace
} // namespace