MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / setupImageShow

Function setupImageShow

apps/tools/Tools/commands/ImageCommand.cpp:157–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157static void setupImageShow(CLI::App& image)
158{
159 auto* cmd = image.add_subcommand("show", "Display texture in a window");
160 static std::string inputPath;
161 static std::string screenshotPath;
162 cmd->add_option("input", inputPath, "Input file (PAA/PAC/PNG/BMP/TGA/JPG)")->required()->check(CLI::ExistingFile);
163 cmd->add_option("--screenshot", screenshotPath, "Save screenshot to file and exit");
164
165 cmd->callback(
166 []()
167 {
168 auto img = Poseidon::Image::FromFile(inputPath);
169 if (!img.valid())
170 {
171 std::cerr << "Error: Failed to load texture" << std::endl;
172 throw CLI::RuntimeError(1);
173 }
174
175 auto rgba = img.ToRGBA();
176 if (!rgba.valid())
177 {
178 std::cerr << "Error: Failed to convert to RGBA" << std::endl;
179 throw CLI::RuntimeError(1);
180 }
181
182 if (!screenshotPath.empty())
183 {
184 Poseidon::PreviewImage preview;
185 preview.width = rgba.width();
186 preview.height = rgba.height();
187 preview.data.assign(rgba.data().begin(), rgba.data().end());
188 if (!preview.saveToFile(screenshotPath))
189 {
190 std::cerr << "Error: Failed to write screenshot" << std::endl;
191 throw CLI::RuntimeError(1);
192 }
193 std::cout << "Screenshot: " << screenshotPath << " (" << rgba.width() << "x" << rgba.height() << ")"
194 << std::endl;
195 return;
196 }
197
198 char title[256];
199 std::snprintf(title, sizeof(title), "PoseidonTools - %s (%dx%d)", inputPath.c_str(), rgba.width(),
200 rgba.height());
201 DisplayWindowRGBA(title, rgba.width(), rgba.height(), rgba.data().data());
202 });
203}
204
205static void setupImageFormats(CLI::App& image)
206{

Callers 1

SetupMethod · 0.85

Calls 7

DisplayWindowRGBAFunction · 0.85
ToRGBAMethod · 0.80
saveToFileMethod · 0.80
validMethod · 0.45
emptyMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected