Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
pipeline_builder.cpp
Go to the documentation of this file.
1#include <haio_cli.hpp>
2
3#include <stdexcept>
4
5namespace Haio::Cli {
6namespace {
7
8std::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
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) {
37 if (!token.rect) throw tokenError("default -crop is not supported yet", token.value);
38 pipeline |= Tokens::Crop(*token.rect);
39 break;
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;
51 pipeline |= Tokens::Palette(token.value, token.dither, token.limit, token.limitHow);
52 break;
53
55 pipeline |= Tokens::Radius(token.radius);
56 break;
58 throw tokenError("-fx is not supported by the pipeline yet", token.value);
61 throw tokenError("generator inputs are not supported yet", token.value);
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
68 break;
69 }
70 }
71
72 pipeline |= Tokens::Encode(command.outputFormat, command.outputColor);
73 return pipeline;
74}
75
76} // namespace Haio::Cli
ParseError error
Definition haio_cli.hpp:56
std::string inputPath
Definition haio_cli.hpp:78
std::vector< Token > tokens
Definition haio_cli.hpp:89
Pipeline buildPipeline(const Command &command)
std::string outputFormatName
Definition haio_cli.hpp:81
std::string outputPath
Definition haio_cli.hpp:79
std::optional< Color > outputColor
Definition haio_cli.hpp:86
Token Palette(std::string palette, Dither dither, size_t limit, Limit limitHow)
Definition pipeline.cpp:57
Token Encode(Format format, std::optional< Color > color=std::nullopt)
Definition pipeline.cpp:73
Token Decode(Format format)
Definition pipeline.cpp:32
Token Source(std::string bucket, std::string path)
Definition pipeline.cpp:21
Token Resize(Size size)
Definition pipeline.cpp:44
Token ResizeByPercent(int percent)
Definition pipeline.cpp:50
Token Crop(Rect rect)
Definition pipeline.cpp:38
Token Radius(int radius)
Definition pipeline.cpp:67
std::string message
Definition haio_cli.hpp:34