Allow input from stdin
This commit is contained in:
parent
17b32097fe
commit
d4b0ae591d
@ -50,8 +50,8 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
if (optind == argc) {
|
||||
print_help();
|
||||
return EXIT_FAILURE;
|
||||
// no file arg => read from stdin
|
||||
write_image(std::cout);
|
||||
}
|
||||
for (int i = optind; i < argc; ++i) {
|
||||
try {
|
||||
|
@ -8,13 +8,12 @@ static inline int t2p(int val) {
|
||||
return .5 + 5 * val / 255.0;
|
||||
}
|
||||
|
||||
void write_image(std::ostream& os, const std::string& path) {
|
||||
static void write(std::ostream& os, FILE* in) {
|
||||
char* tc = getenv("TRUECOLOR");
|
||||
std::string truecolor {tc ? tc : ""};
|
||||
bool has_truecolor = truecolor.size() > 0;
|
||||
std::unique_ptr<FILE, void(*)(FILE*)> infile {pm_openr(path.c_str()), pm_close};
|
||||
struct pam info;
|
||||
pnm_readpaminit(infile.get(), &info, PAM_STRUCT_SIZE(tuple_type));
|
||||
pnm_readpaminit(in, &info, PAM_STRUCT_SIZE(tuple_type));
|
||||
std::unique_ptr<tuple, void(*)(void*)> row1 {pnm_allocpamrow(&info), pm_freerow};
|
||||
std::unique_ptr<tuple, void(*)(void*)> row2 {pnm_allocpamrow(&info), pm_freerow};
|
||||
for (int y = 0; y < info.height; y += 2) {
|
||||
@ -40,3 +39,12 @@ void write_image(std::ostream& os, const std::string& path) {
|
||||
os << sc::io::reset << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
void write_image(std::ostream& os) {
|
||||
write(os, stdin);
|
||||
}
|
||||
|
||||
void write_image(std::ostream& os, const std::string& path) {
|
||||
std::unique_ptr<FILE, void(*)(FILE*)> infile {pm_openr(path.c_str()), pm_close};
|
||||
write(os, infile.get());
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void write_image(std::ostream& os);
|
||||
void write_image(std::ostream& os, const std::string& path);
|
||||
|
||||
#endif // PIXELS_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user