Haio
0.2.X
Homebrew Asset IO/CDN
Toggle main menu visibility
Loading...
Searching...
No Matches
haio_pipeline.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
haio_codec.hpp
"
4
#include "
haio_common.hpp
"
5
#include "
haio_formats.hpp
"
6
#include "
haio_object.hpp
"
7
#include "
haio_palette.hpp
"
8
#include "
haio_transform.hpp
"
9
10
#include <chrono>
11
#include <optional>
12
#include <span>
13
#include <unordered_map>
14
15
namespace
Haio
{
16
17
enum class
TokenKind
{
18
Source,
19
DecodeAuto,
20
Decode
,
21
Crop,
22
Resize,
23
Radius,
24
Palette,
25
Encode
26
};
27
28
struct
Token
{
29
TokenKind
kind
=
TokenKind::DecodeAuto
;
30
std::string
bucket
;
31
std::string
path
;
32
Format
format
=
Format::RAW
;
33
34
/**
35
* Encode only: which colour to store inside the container, when somebody named
36
* one. nothing named is not the same as rgba8888: it means the container picks,
37
* which for most of them is the only colour they write anyway.
38
*/
39
std::optional<Color>
color
;
40
41
Rect
rect
;
42
Size
size
;
43
44
/** Resize only: a share of the incoming picture, when the size was written as one */
45
int
percent
= 0;
46
int
radius
= 0;
47
48
/** Palette only: which colours, how to fit into them, and how many to keep */
49
std::string
palette
;
50
Dither
dither
=
Dither::Nearest
;
51
size_t
limit
= 0;
52
Limit
limitHow
=
Limit::Spread
;
53
};
54
55
/** a conversion described at runtime, which is what a url query builds */
56
class
Pipeline
{
57
public
:
58
Pipeline
&
operator|=
(
Token
token);
59
const
std::vector<Token>&
tokens
()
const
;
60
61
private
:
62
std::vector<Token> tokens_;
63
};
64
65
namespace
Tokens
{
66
Token
Source
(std::string bucket, std::string path);
67
Token
DecodeAuto
();
68
Token
Decode
(
Format
format);
69
Token
Crop
(
Rect
rect);
70
Token
Resize
(
Size
size);
71
Token
ResizeByPercent
(
int
percent);
72
Token
Radius
(
int
radius);
73
Token
Palette
(std::string palette,
Dither
dither,
size_t
limit,
Limit
limitHow);
74
Token
Encode
(
Format
format, std::optional<Color> color = std::nullopt);
75
}
76
77
Format
formatFromExtension
(std::string_view path);
78
Format
formatFromContentType
(std::string_view contentType);
79
std::string_view
extensionFor
(
Format
format);
80
std::string_view
contentTypeFor
(
Format
format);
81
82
/**
83
* a deadline of none lets it run as long as it takes.
84
*
85
* it is checked between stages rather than inside them, so the bound is really "one
86
* more stage after the clock runs out". that is enough for what it defends against: a
87
* query naming a thousand operations is stopped after the first one or two, and a
88
* single stage is already bounded by max_size.
89
*/
90
Result<Blob>
runPipeline
(
Blob
input,
const
Pipeline
& pipeline,
91
std::optional<std::chrono::steady_clock::time_point> deadline = std::nullopt);
92
93
std::vector<Token>
parseQueryTokens
(std::string_view query);
94
std::unordered_map<std::string, std::string>
parseQueryMap
(std::string_view query);
95
96
}
Haio::Pipeline
Definition
haio_pipeline.hpp:56
Haio::Pipeline::tokens
const std::vector< Token > & tokens() const
Definition
pipeline.cpp:16
Haio::Pipeline::operator|=
Pipeline & operator|=(Token token)
Definition
pipeline.cpp:11
haio_codec.hpp
haio_common.hpp
haio_formats.hpp
haio_object.hpp
haio_palette.hpp
haio_transform.hpp
Haio::Tokens
Definition
haio_pipeline.hpp:65
Haio::Tokens::Palette
Token Palette(std::string palette, Dither dither, size_t limit, Limit limitHow)
Definition
pipeline.cpp:57
Haio::Tokens::Encode
Token Encode(Format format, std::optional< Color > color=std::nullopt)
Definition
pipeline.cpp:73
Haio::Tokens::Decode
Token Decode(Format format)
Definition
pipeline.cpp:32
Haio::Tokens::Source
Token Source(std::string bucket, std::string path)
Definition
pipeline.cpp:21
Haio::Tokens::Resize
Token Resize(Size size)
Definition
pipeline.cpp:44
Haio::Tokens::DecodeAuto
Token DecodeAuto()
Definition
pipeline.cpp:28
Haio::Tokens::ResizeByPercent
Token ResizeByPercent(int percent)
Definition
pipeline.cpp:50
Haio::Tokens::Crop
Token Crop(Rect rect)
Definition
pipeline.cpp:38
Haio::Tokens::Radius
Token Radius(int radius)
Definition
pipeline.cpp:67
Haio
Definition
haio.hpp:11
Haio::Encode
Result< Blob > Encode(Image< Color::RGBA8888 > image, Format to, std::optional< Color > as=std::nullopt)
Definition
haio_registry.hpp:229
Haio::Limit
Limit
Definition
haio_palette.hpp:71
Haio::Limit::Spread
@ Spread
Definition
haio_palette.hpp:89
Haio::Token::rect
Rect rect
Definition
haio_pipeline.hpp:41
Haio::formatFromContentType
Format formatFromContentType(std::string_view contentType)
Definition
format.cpp:41
Haio::Token::limitHow
Limit limitHow
Definition
haio_pipeline.hpp:52
Haio::Token::bucket
std::string bucket
Definition
haio_pipeline.hpp:30
Haio::Token::color
std::optional< Color > color
Definition
haio_pipeline.hpp:39
Haio::parseQueryTokens
std::vector< Token > parseQueryTokens(std::string_view query)
Definition
pipeline.cpp:100
Haio::formatFromExtension
Format formatFromExtension(std::string_view path)
Definition
format.cpp:33
Haio::Token::size
Size size
Definition
haio_pipeline.hpp:42
Haio::runPipeline
Result< Blob > runPipeline(Blob input, const Pipeline &pipeline, std::optional< std::chrono::steady_clock::time_point > deadline=std::nullopt)
Definition
convert.cpp:15
Haio::Token::kind
TokenKind kind
Definition
haio_pipeline.hpp:29
Haio::Result
std::expected< T, Error > Result
Definition
haio_codec.hpp:32
Haio::Token::radius
int radius
Definition
haio_pipeline.hpp:46
Haio::TokenKind
TokenKind
Definition
haio_pipeline.hpp:17
Haio::TokenKind::DecodeAuto
@ DecodeAuto
Definition
haio_pipeline.hpp:19
Haio::Decode
Result< Image< Color::RGBA8888 > > Decode(const Blob &blob)
Definition
haio_registry.hpp:154
Haio::contentTypeFor
std::string_view contentTypeFor(Format format)
Definition
format.cpp:62
Haio::extensionFor
std::string_view extensionFor(Format format)
Definition
format.cpp:54
Haio::Token::path
std::string path
Definition
haio_pipeline.hpp:31
Haio::Format
Format
Definition
haio_formats.hpp:17
Haio::Format::RAW
@ RAW
Definition
haio_formats.hpp:19
Haio::Token::palette
std::string palette
Definition
haio_pipeline.hpp:49
Haio::Token::percent
int percent
Definition
haio_pipeline.hpp:45
Haio::Token::limit
size_t limit
Definition
haio_pipeline.hpp:51
Haio::Token::dither
Dither dither
Definition
haio_pipeline.hpp:50
Haio::Dither
Dither
Definition
haio_palette.hpp:44
Haio::Dither::Nearest
@ Nearest
Definition
haio_palette.hpp:45
Haio::parseQueryMap
std::unordered_map< std::string, std::string > parseQueryMap(std::string_view query)
Definition
pipeline.cpp:81
Haio::Token::format
Format format
Definition
haio_pipeline.hpp:32
Haio::Blob
Definition
haio_codec.hpp:122
Haio::Rect
Definition
haio_object.hpp:5
Haio::Size
Definition
haio_object.hpp:12
Haio::Token
Definition
haio_pipeline.hpp:28
include
haio_pipeline.hpp
Generated by
1.18.0