Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode/
.vscode/
.DS_Store
*.dSYM/
979 changes: 979 additions & 0 deletions hyw_out.ppm

Large diffs are not rendered by default.

Binary file added imgtool
Binary file not shown.
13 changes: 13 additions & 0 deletions imgtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct Options {
int resize_w = 0;
int resize_h = 0;
enum class ResizeAlg { NEAREST, BILINEAR } resize_alg = ResizeAlg::BILINEAR;
bool open_window = false;
};
struct OptionDef {
string name;
Expand Down Expand Up @@ -75,6 +76,9 @@ vector<OptionDef> register_options() {
{"--decode", "", "Decode a compressed image", 0,
[](Options& opt, const vector<string>&){ opt.decode_compressed = true; },
[](const Options& opt){ return opt.decode_compressed; }},
{"--open", "", "Open resulting .ppm in an external OpenCV viewer (non-blocking)", 0,
[](Options& opt, const vector<string>&){ opt.open_window = true; },
[](const Options& opt){ return opt.open_window; }},
{"-h", "", "Show help message", 0,
[](Options& opt, const vector<string>&){ opt.show_help = true; },
[](const Options& opt){ return opt.show_help; }},
Expand Down Expand Up @@ -204,6 +208,15 @@ int main(int argc, char* argv[]) {
}
}
cout << "Done: output saved to " << opt.output << "\n";
// If requested, launch the viewer in background so the window remains
// but does not block this process. We rely on the `viewer` executable
// being present in the current working directory.
if (opt.open_window) {
string cmd = "./viewer \"" + opt.output + "\" &";
cerr << "Launching viewer: " << cmd << "\n";
// Use system to spawn the viewer process; appending '&' sends it to background
int rc = system(cmd.c_str()); (void)rc;
}
}
catch (const exception& e) {
cerr << "Fatal error: " << e.what() << "\n";
Expand Down
Binary file added viewer
Binary file not shown.
22 changes: 22 additions & 0 deletions viewer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Simple OpenCV viewer for .ppm files
#include <opencv2/opencv.hpp>
#include <iostream>

int main(int argc, char* argv[]) {
if (argc < 2) {
std::cerr << "Usage: viewer <file.ppm>\n";
return 1;
}
std::string path = argv[1];
cv::Mat img = cv::imread(path, cv::IMREAD_UNCHANGED);
if (img.empty()) {
std::cerr << "Failed to open image: " << path << "\n";
return 2;
}
const std::string win = "viewer - " + path;
cv::namedWindow(win, cv::WINDOW_AUTOSIZE);
cv::imshow(win, img);
// Wait until user presses a key or closes the window
cv::waitKey(0);
return 0;
}