Export equirectangular JPEGs through paint renderer

This commit is contained in:
2026-06-05 21:22:06 +02:00
parent 875a0127d9
commit bd416f8473
11 changed files with 604 additions and 96 deletions

View File

@@ -5,10 +5,14 @@
#include <cstddef>
#include <cstdint>
#include <span>
#include <string_view>
#include <vector>
using pp::assets::decode_png_rgba8;
using pp::assets::decode_jpeg_rgba8;
using pp::assets::encode_jpeg_rgba8;
using pp::assets::encode_png_rgba8;
using pp::assets::inject_gpano_xmp_into_jpeg;
using pp::foundation::StatusCode;
namespace {
@@ -75,6 +79,66 @@ void encodes_rgba8_pixels_to_decodable_png(pp::tests::Harness& h)
PP_EXPECT(h, decoded.value().pixels == pixels);
}
void encodes_rgba8_pixels_to_decodable_jpeg(pp::tests::Harness& h)
{
const std::vector<std::uint8_t> pixels {
255, 0, 0, 255,
0, 255, 0, 255,
0, 0, 255, 255,
255, 255, 255, 255,
};
const auto encoded = encode_jpeg_rgba8(2, 2, pixels, 95);
PP_EXPECT(h, encoded.ok());
PP_EXPECT(h, encoded.value().size() > 4U);
PP_EXPECT(h, encoded.value()[0] == std::byte { 0xff });
PP_EXPECT(h, encoded.value()[1] == std::byte { 0xd8 });
const auto decoded = decode_jpeg_rgba8(encoded.value());
PP_EXPECT(h, decoded.ok());
PP_EXPECT(h, decoded.value().width == 2U);
PP_EXPECT(h, decoded.value().height == 2U);
PP_EXPECT(h, decoded.value().pixels.size() == pixels.size());
}
void injects_gpano_xmp_into_jpeg(pp::tests::Harness& h)
{
const std::vector<std::uint8_t> pixels {
10, 20, 30, 255,
40, 50, 60, 255,
};
const auto encoded = encode_jpeg_rgba8(2, 1, pixels, 90);
PP_EXPECT(h, encoded);
if (!encoded) {
return;
}
const auto with_xmp = inject_gpano_xmp_into_jpeg(encoded.value());
PP_EXPECT(h, with_xmp);
if (!with_xmp) {
return;
}
PP_EXPECT(h, with_xmp.value().size() > encoded.value().size());
PP_EXPECT(h, with_xmp.value()[0] == std::byte { 0xff });
PP_EXPECT(h, with_xmp.value()[1] == std::byte { 0xd8 });
PP_EXPECT(h, with_xmp.value()[2] == std::byte { 0xff });
PP_EXPECT(h, with_xmp.value()[3] == std::byte { 0xe1 });
const std::string_view text(
reinterpret_cast<const char*>(with_xmp.value().data()),
with_xmp.value().size());
PP_EXPECT(h, text.find("GPano:ProjectionType") != std::string_view::npos);
PP_EXPECT(h, text.find("equirectangular") != std::string_view::npos);
const auto decoded = decode_jpeg_rgba8(with_xmp.value());
PP_EXPECT(h, decoded);
if (decoded) {
PP_EXPECT(h, decoded.value().width == 2U);
PP_EXPECT(h, decoded.value().height == 1U);
}
}
void rejects_invalid_png_encode_inputs(pp::tests::Harness& h)
{
const std::vector<std::uint8_t> pixels { 0, 0, 0, 0 };
@@ -88,6 +152,29 @@ void rejects_invalid_png_encode_inputs(pp::tests::Harness& h)
PP_EXPECT(h, wrong_payload_size.status().code == StatusCode::invalid_argument);
}
void rejects_invalid_jpeg_inputs(pp::tests::Harness& h)
{
const std::vector<std::uint8_t> pixels { 0, 0, 0, 255 };
const std::byte corrupt[] { std::byte { 0x00 }, std::byte { 0x01 } };
const auto no_size = encode_jpeg_rgba8(0, 1, pixels, 90);
const auto bad_quality = encode_jpeg_rgba8(1, 1, pixels, 0);
const auto wrong_payload_size = encode_jpeg_rgba8(2, 1, pixels, 90);
const auto corrupt_decode = decode_jpeg_rgba8(corrupt);
const auto corrupt_xmp = inject_gpano_xmp_into_jpeg(corrupt);
PP_EXPECT(h, !no_size.ok());
PP_EXPECT(h, no_size.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !bad_quality.ok());
PP_EXPECT(h, bad_quality.status().code == StatusCode::out_of_range);
PP_EXPECT(h, !wrong_payload_size.ok());
PP_EXPECT(h, wrong_payload_size.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !corrupt_decode.ok());
PP_EXPECT(h, corrupt_decode.status().code == StatusCode::invalid_argument);
PP_EXPECT(h, !corrupt_xmp.ok());
PP_EXPECT(h, corrupt_xmp.status().code == StatusCode::invalid_argument);
}
}
int main()
@@ -96,6 +183,9 @@ int main()
harness.run("decodes_png_to_rgba8_pixels", decodes_png_to_rgba8_pixels);
harness.run("rejects_corrupt_png_payload", rejects_corrupt_png_payload);
harness.run("encodes_rgba8_pixels_to_decodable_png", encodes_rgba8_pixels_to_decodable_png);
harness.run("encodes_rgba8_pixels_to_decodable_jpeg", encodes_rgba8_pixels_to_decodable_jpeg);
harness.run("injects_gpano_xmp_into_jpeg", injects_gpano_xmp_into_jpeg);
harness.run("rejects_invalid_png_encode_inputs", rejects_invalid_png_encode_inputs);
harness.run("rejects_invalid_jpeg_inputs", rejects_invalid_jpeg_inputs);
return harness.finish();
}