载入中...
搜索中...
未找到
FrameContactSheet.cpp
浏览该文件的文档.
2
3#include <algorithm>
4
5namespace eve::dev {
6Result<FramePreview> frameContactSheet(std::span<const FrameCaptureBuffer> frames,
8 const auto invalid = [](std::string message) {
10 Diagnostic::error(DiagnosticCode::InvalidArgument, std::move(message), "frame_contact_sheet"));
11 };
12 if (frames.empty() || frames.size() > 16 || options.columns == 0 || options.columns > frames.size() ||
13 !options.cellWidth || !options.cellHeight || options.cellWidth > 2048 || options.cellHeight > 2048 ||
14 options.maxBytes < 1024 || options.maxBytes > 16777216)
15 return invalid("InvalidContactSheetOptions");
16 const auto rows = static_cast<uint32_t>((frames.size() + options.columns - 1) / options.columns);
17 const uint32_t width = options.columns * options.cellWidth, height = rows * options.cellHeight;
18 if (width > 2048 || height > 2048) return invalid("ContactSheetPixelBudgetExceeded");
19 for (const auto& frame : frames) {
20 if (frame.attachment != FrameAttachment::Final ||
21 (frame.format != FramePixelFormat::Rgba8 && frame.format != FramePixelFormat::Bgra8) || !frame.bytes ||
22 !frame.width || !frame.height || frame.bytes->size() % 4 != 0 ||
23 uint64_t(frame.width) * frame.height != frame.bytes->size() / 4)
24 return invalid("InvalidFinalColorStorage");
25 }
26 auto pixels = std::make_shared<std::vector<uint8_t>>(size_t(width) * height * 4, 0);
27 for (size_t p = 3; p < pixels->size(); p += 4) (*pixels)[p] = 255;
28 for (size_t index = 0; index < frames.size(); ++index) {
29 const auto& frame = frames[index];
30 const double scale =
31 (std::min)({1.0, double(options.cellWidth) / frame.width, double(options.cellHeight) / frame.height});
32 const auto drawWidth = (std::max)(1u, static_cast<uint32_t>(frame.width * scale));
33 const auto drawHeight = (std::max)(1u, static_cast<uint32_t>(frame.height * scale));
34 const auto left =
35 static_cast<uint32_t>(index % options.columns) * options.cellWidth + (options.cellWidth - drawWidth) / 2;
36 const auto top =
37 static_cast<uint32_t>(index / options.columns) * options.cellHeight + (options.cellHeight - drawHeight) / 2;
38 for (uint32_t y = 0; y < drawHeight; ++y) {
39 for (uint32_t x = 0; x < drawWidth; ++x) {
40 const size_t source = (size_t(uint64_t(y) * frame.height / drawHeight) * frame.width +
41 size_t(uint64_t(x) * frame.width / drawWidth)) *
42 4;
43 const size_t destination = (size_t(top + y) * width + left + x) * 4;
44 const bool bgra = frame.format == FramePixelFormat::Bgra8;
45 (*pixels)[destination] = (*frame.bytes)[source + (bgra ? 2 : 0)];
46 (*pixels)[destination + 1] = (*frame.bytes)[source + 1];
47 (*pixels)[destination + 2] = (*frame.bytes)[source + (bgra ? 0 : 2)];
48 }
49 }
50 }
51 FrameCaptureBuffer combined;
52 combined.width = width;
53 combined.height = height;
54 combined.bytes = std::move(pixels);
55 FramePreviewOptions preview;
56 preview.maxWidth = width;
57 preview.maxHeight = height;
58 preview.maxBytes = options.maxBytes;
59 preview.view = "rawChannels";
60 return frameCapturePreview(combined, preview);
61}
62} // namespace eve::dev
double y
double x
glm::vec4 p[6]
int rows
std::string message
HexVec3 left
std::uint32_t height
std::uint32_t width
std::array< float, 3 > scale
ssq::Object frame
uint8_t * pixels
std::string_view source
const SquirrelValueOptions & options
uint32_t index
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
SQInteger top
Definition Snapshot.cpp:115
Result< FramePreview > frameCapturePreview(const FrameCaptureBuffer &b, const FramePreviewOptions &o)
Result< FramePreview > frameContactSheet(std::span< const FrameCaptureBuffer > frames, const FrameContactSheetOptions &options)
Immutable CPU attachment with producer-provided decoding metadata.
std::shared_ptr< const std::vector< uint8_t > > bytes
Bounded, row-major contact sheet of immutable final-color captures.
Explicit CPU preview transformation, separate from costly GPU capture.