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

Function setupImageInspect

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

Source from the content-addressed store, hash-verified

30{
31
32static void setupImageInspect(CLI::App& image)
33{
34 auto* cmd = image.add_subcommand("inspect", "Inspect PAA/PAC texture file");
35 static std::string inputPath;
36 cmd->add_option("input", inputPath, "Input PAA/PAC file path")->required()->check(CLI::ExistingFile);
37
38 cmd->callback(
39 []()
40 {
41 auto info = Poseidon::InspectTexture(inputPath);
42 if (!info.valid)
43 {
44 std::cerr << "Error: Failed to read texture: " << inputPath << std::endl;
45 throw CLI::RuntimeError(1);
46 }
47
48 std::cout << "File: " << info.path << std::endl;
49 std::cout << "Type: " << info.typeName << std::endl;
50 if (info.formatName != "P8")
51 std::cout << "Format: " << info.formatName << " (0x" << std::hex << info.magic << std::dec << ")"
52 << std::endl;
53 else
54 std::cout << "Format: P8 (palette-based)" << std::endl;
55 std::cout << "Dimensions: " << info.width << "x" << info.height << std::endl;
56 std::cout << "Mipmaps: " << info.mipmapCount << std::endl;
57 if (info.paletteColors > 0)
58 std::cout << "Palette: " << info.paletteColors << " colors" << std::endl;
59 if (info.magic == 0xFF01)
60 std::cout << "Transparency: "
61 << (info.hasTransparentBlocks ? "yes (1-bit alpha blocks detected)" : "no") << std::endl;
62
63 // Alpha classification (opaque / cutout / blend) — decode the top mip and
64 // classify its alpha channel via the shared ClassifyAlpha (the same signal a
65 // section-sort renderer uses): only a "blend" texture (partial-alpha texels)
66 // must be deferred to the back-to-front pass; opaque and cutout occlude.
67 Poseidon::DecodedImage img = Poseidon::DecodePAAFile(inputPath);
68 if (img.valid())
69 {
70 const size_t n = static_cast<size_t>(img.width) * static_cast<size_t>(img.height);
71 const Poseidon::AlphaStats a = Poseidon::ClassifyAlpha(img.rgba.data(), n);
72 const char* route =
73 a.kind == Poseidon::AlphaStats::Blend ? "back-to-front alpha pass, NO depth-write (see-through)"
74 : a.kind == Poseidon::AlphaStats::Cutout ? "opaque pass, depth-write, discard holes (occludes)"
75 : "opaque pass, depth-write (occludes)";
76 std::cout << std::fixed << std::setprecision(1);
77 std::cout << "Alpha: min=" << a.aMin << " max=" << a.aMax << " mean=" << a.aMean
78 << " (clear a=0: " << a.pctClear << "% opaque a=255: " << a.pctOpaque
79 << "% partial 0<a<255: " << a.pctPartial << "%)" << std::endl;
80 std::cout << "Classification: " << Poseidon::AlphaKindName(a.kind) << std::endl;
81 std::cout << " -> route: " << route << std::endl;
82 }
83 });
84}
85
86static void setupImageConvert(CLI::App& image)
87{

Callers 1

SetupMethod · 0.85

Calls 5

InspectTextureFunction · 0.85
DecodePAAFileFunction · 0.85
ClassifyAlphaFunction · 0.85
AlphaKindNameFunction · 0.85
validMethod · 0.45

Tested by

no test coverage detected