Skip to content

Commit

Permalink
Now signing our exr snapshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnotherCommander committed Sep 11, 2024
1 parent 7c10dce commit 4c52dab
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/SDL/EXRSnapshotSupport/OOSaveEXRSnapshot.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <vector>

extern "C" {
Expand Down Expand Up @@ -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<EXRAttribute *>(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(&timestamp);
char signatureStringIntro[255] = "Generated by Oolite ";
char *signatureString = strcat(signatureStringIntro, std::ctime(&timestamp));
// ctime adds a newline at the end of the string, strip it
signatureString[strlen(signatureString) - 1] = '\0';
header.custom_attributes[0].value = reinterpret_cast<uint8_t *>(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';
Expand Down

0 comments on commit 4c52dab

Please sign in to comment.