Haio
0.2.X
Homebrew Asset IO/CDN
Toggle main menu visibility
Loading...
Searching...
No Matches
pipeline_builder.cpp
Go to the documentation of this file.
1
#include <
haio_cli.hpp
>
2
3
#include <stdexcept>
4
5
namespace
Haio::Cli
{
6
namespace
{
7
8
std::runtime_error tokenError(std::string message,
const
std::string& token = {}) {
9
if
(!token.empty()) message +=
": "
+ token;
10
return
std::runtime_error(std::move(message));
11
}
12
13
}
14
15
Pipeline
buildPipeline
(
const
Command
& command) {
16
if
(command.
error
)
throw
tokenError(command.
error
.
message
, command.
error
.
token
);
17
if
(command.
hasGenerator
)
throw
tokenError(
"generator inputs are not supported yet"
);
18
if
(command.
inputFormat
==
Format::RAW
)
throw
tokenError(
"unknown input format"
, command.
inputPath
);
19
20
/**
21
* "raw:" is the container that is not one: the pixels as they are, in whatever
22
* -pix_fmt asked for. it has to be named rather than guessed, because a file
23
* extension never means it, which is exactly what tells it apart from a format
24
* nobody recognised.
25
*/
26
if
(command.
outputFormat
==
Format::RAW
&& command.
outputFormatName
.empty()) {
27
throw
tokenError(
"unknown output format"
, command.
outputPath
);
28
}
29
30
Pipeline
pipeline;
31
pipeline |=
Tokens::Source
(
"file"
, command.
inputPath
);
32
pipeline |=
Tokens::Decode
(command.
inputFormat
);
33
34
for
(
const
auto
& token : command.
tokens
) {
35
switch
(token.type) {
36
case
TokenType::FilterCrop
:
37
if
(!token.rect)
throw
tokenError(
"default -crop is not supported yet"
, token.value);
38
pipeline |=
Tokens::Crop
(*token.rect);
39
break
;
40
case
TokenType::FilterResize
:
41
// a share carries no size, and is not meant to: what it comes to is
42
// not known until there is a picture to take a share of
43
if
(token.percent != 0) {
44
pipeline |=
Tokens::ResizeByPercent
(token.percent);
45
break
;
46
}
47
if
(!token.size)
throw
tokenError(
"invalid resize size"
, token.value);
48
pipeline |=
Tokens::Resize
(*token.size);
49
break
;
50
case
TokenType::FilterPalette
:
51
pipeline |=
Tokens::Palette
(token.value, token.dither, token.limit, token.limitHow);
52
break
;
53
54
case
TokenType::FilterRadius
:
55
pipeline |=
Tokens::Radius
(token.radius);
56
break
;
57
case
TokenType::FilterFx
:
58
throw
tokenError(
"-fx is not supported by the pipeline yet"
, token.value);
59
case
TokenType::GeneratorXc
:
60
case
TokenType::GeneratorGradient
:
61
throw
tokenError(
"generator inputs are not supported yet"
, token.value);
62
case
TokenType::InputFile
:
63
case
TokenType::OutputFile
:
64
case
TokenType::FilterFormat
:
65
// both of these are answered by the encode token below rather than in
66
// place: they say what comes out, and nothing comes out until the end
67
case
TokenType::FilterPixFmt
:
68
break
;
69
}
70
}
71
72
pipeline |=
Tokens::Encode
(command.
outputFormat
, command.
outputColor
);
73
return
pipeline;
74
}
75
76
}
// namespace Haio::Cli
Haio::Pipeline
Definition
haio_pipeline.hpp:56
haio_cli.hpp
Haio::Cli
Definition
haio_cli.hpp:17
Haio::Cli::Command::error
ParseError error
Definition
haio_cli.hpp:56
Haio::Cli::Command::inputPath
std::string inputPath
Definition
haio_cli.hpp:78
Haio::Cli::Command::hasGenerator
bool hasGenerator
Definition
haio_cli.hpp:76
Haio::Cli::Command::outputFormat
Format outputFormat
Definition
haio_cli.hpp:83
Haio::Cli::Command::tokens
std::vector< Token > tokens
Definition
haio_cli.hpp:89
Haio::Cli::buildPipeline
Pipeline buildPipeline(const Command &command)
Definition
pipeline_builder.cpp:15
Haio::Cli::Command::outputFormatName
std::string outputFormatName
Definition
haio_cli.hpp:81
Haio::Cli::Command::inputFormat
Format inputFormat
Definition
haio_cli.hpp:82
Haio::Cli::TokenType::FilterCrop
@ FilterCrop
Definition
haio_cli.hpp:24
Haio::Cli::TokenType::FilterResize
@ FilterResize
Definition
haio_cli.hpp:25
Haio::Cli::TokenType::FilterFormat
@ FilterFormat
Definition
haio_cli.hpp:27
Haio::Cli::TokenType::GeneratorXc
@ GeneratorXc
Definition
haio_cli.hpp:22
Haio::Cli::TokenType::GeneratorGradient
@ GeneratorGradient
Definition
haio_cli.hpp:23
Haio::Cli::TokenType::InputFile
@ InputFile
Definition
haio_cli.hpp:20
Haio::Cli::TokenType::FilterPixFmt
@ FilterPixFmt
Definition
haio_cli.hpp:30
Haio::Cli::TokenType::FilterPalette
@ FilterPalette
Definition
haio_cli.hpp:29
Haio::Cli::TokenType::FilterRadius
@ FilterRadius
Definition
haio_cli.hpp:26
Haio::Cli::TokenType::FilterFx
@ FilterFx
Definition
haio_cli.hpp:28
Haio::Cli::TokenType::OutputFile
@ OutputFile
Definition
haio_cli.hpp:21
Haio::Cli::Command::outputPath
std::string outputPath
Definition
haio_cli.hpp:79
Haio::Cli::Command::outputColor
std::optional< Color > outputColor
Definition
haio_cli.hpp:86
Haio::Cli::Command
Definition
haio_cli.hpp:55
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::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::Format::RAW
@ RAW
Definition
haio_formats.hpp:19
Haio::Cli::ParseError::message
std::string message
Definition
haio_cli.hpp:34
Haio::Cli::ParseError::token
std::string token
Definition
haio_cli.hpp:35
library
frontend
convert
pipeline_builder.cpp
Generated by
1.18.0