9 #include "flutter/fml/mapping.h"
19 std::shared_ptr<const fml::Mapping> allocation)
20 : size_(size), format_(format), allocation_(
std::move(allocation)) {
72 const auto source_byte_size = size_.
Area() * bpp;
73 if (allocation_->GetSize() < source_byte_size) {
77 auto rgba_allocation = std::make_shared<Allocation>();
78 if (!rgba_allocation->Truncate(
Bytes{size_.Area() * 4u},
false)) {
82 const uint8_t* source = allocation_->GetMapping();
83 uint8_t* dest = rgba_allocation->GetBuffer();
85 for (
size_t i = 0, j = 0; i < source_byte_size; i += bpp, j += 4u) {
88 dest[j + 0] = source[i];
89 dest[j + 1] = source[i];
90 dest[j + 2] = source[i];
91 dest[j + 3] = std::numeric_limits<uint8_t>::max();
94 dest[j + 0] = std::numeric_limits<uint8_t>::max();
95 dest[j + 1] = std::numeric_limits<uint8_t>::max();
96 dest[j + 2] = std::numeric_limits<uint8_t>::max();
97 dest[j + 3] = source[i];
100 dest[j + 0] = source[i + 0];
101 dest[j + 1] = source[i + 1];
102 dest[j + 2] = source[i + 2];
103 dest[j + 3] = std::numeric_limits<uint8_t>::max();
116 std::make_shared<fml::NonOwnedMapping>(
117 rgba_allocation->GetBuffer(),
118 rgba_allocation->GetLength().GetByteSize(),
119 [rgba_allocation](
auto,
auto) {})
DecompressedImage ConvertToRGBA() const
const std::shared_ptr< const fml::Mapping > & GetAllocation() const
const ISize & GetSize() const
static size_t GetBytesPerPixel(DecompressedImage::Format format)
constexpr Type Area() const
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.