From 4c52dabaabcb4da2e47bf97532afcf9ff26f03b2 Mon Sep 17 00:00:00 2001 From: AnotherCommander Date: Wed, 11 Sep 2024 21:07:25 +0300 Subject: [PATCH] Now signing our exr snapshots. --- src/SDL/EXRSnapshotSupport/OOSaveEXRSnapshot.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/SDL/EXRSnapshotSupport/OOSaveEXRSnapshot.cpp b/src/SDL/EXRSnapshotSupport/OOSaveEXRSnapshot.cpp index 5f17ed92e..7313d9e33 100644 --- a/src/SDL/EXRSnapshotSupport/OOSaveEXRSnapshot.cpp +++ b/src/SDL/EXRSnapshotSupport/OOSaveEXRSnapshot.cpp @@ -1,5 +1,6 @@ #include #include +#include #include extern "C" { @@ -44,6 +45,21 @@ int SaveEXRSnapshot(const char* outfilename, int width, int height, const float* header.num_channels = 3; header.compression_type = TINYEXR_COMPRESSIONTYPE_ZIP; header.channels = (EXRChannelInfo *)malloc(sizeof(EXRChannelInfo) * header.num_channels); + + // sign our snapshot + header.num_custom_attributes = 1; + header.custom_attributes = static_cast(malloc(sizeof(EXRAttribute))); + strncpy(header.custom_attributes[0].name, "signature", 255); + strncpy(header.custom_attributes[0].type, "string", 255); + std::time_t timestamp; + std::time(×tamp); + char signatureStringIntro[255] = "Generated by Oolite "; + char *signatureString = strcat(signatureStringIntro, std::ctime(×tamp)); + // ctime adds a newline at the end of the string, strip it + signatureString[strlen(signatureString) - 1] = '\0'; + header.custom_attributes[0].value = reinterpret_cast(signatureString); + header.custom_attributes[0].size = strlen(signatureString); + // Must be BGR(A) order, since most of EXR viewers expect this channel order. strncpy(header.channels[0].name, "B", 255); header.channels[0].name[strlen("B")] = '\0'; strncpy(header.channels[1].name, "G", 255); header.channels[1].name[strlen("G")] = '\0';