64 const auto failure = [](
const char* detail)
68 error.detail = detail;
69 return std::unexpected(std::move(
error));
72 bytes.size() >
static_cast<std::size_t
>(std::numeric_limits<int>::max()))
73 return failure(
"modern encoded image exceeds its byte budget or is empty");
81 return failure(
"modern image content does not match its PNG/JPEG MIME type");
84 return failure(
"modern image header cannot be decoded");
89 static_cast<std::size_t
>(
height))
90 return failure(
"modern decoded image exceeds its dimension or RGBA byte budget");
95 if (!pixels)
return failure(
"modern PNG/JPEG decode failed or exhausted working storage");
99 return failure(
"modern image dimensions changed during decode");
100 auto result = std::make_shared<ModernTextureImage>();
101 result->width =
static_cast<std::uint32_t
>(
width);
102 result->height =
static_cast<std::uint32_t
>(
height);
103 result->rgba.assign(pixels.get(), pixels.get() +
decodedBytes);
104 return std::shared_ptr<const ModernTextureImage>(std::move(result));
106 catch (
const std::bad_alloc&)
108 MeshRuntimeError
error;
110 error.detail =
"modern image pixel allocation failed";
111 return std::unexpected(std::move(
error));
113 catch (
const std::length_error&)
115 MeshRuntimeError
error;
117 error.detail =
"modern image pixel allocation exceeds container limits";
118 return std::unexpected(std::move(
error));
std::vector< std::byte > bytes