| Flutter Impeller |

Public Types | Public Member Functions | List of all members
impeller::DecompressedImage Class Reference

`#include <decompressed_image.h>`

## Public Types
enum class | Format { kInvalid , kGrey , kGreyAlpha , kRGB , kRGBA }

## Public Member Functions
| DecompressedImage ()
| DecompressedImage (ISize size, Format format, std::shared_ptr< const fml::Mapping > allocation)
| ~DecompressedImage ()
const ISize & | GetSize () const
bool | IsValid () const
Format | GetFormat () const
const std::shared_ptr< const fml::Mapping > & | GetAllocation () const
DecompressedImage | ConvertToRGBA () const

## Detailed Description

Definition at line 15 of file decompressed_image.h.

## Member Enumeration Documentation

## ◆ Format

enum impeller::DecompressedImage::Format
| strong

Enumerator
kInvalid |
kGrey |
kGreyAlpha |
kRGB |
kRGBA |

Definition at line 17 of file decompressed_image.h.

17 {
18 kInvalid,
19 kGrey,
20 kGreyAlpha,
21 kRGB,
22 kRGBA,
23 };

## Constructor & Destructor Documentation

## ◆ DecompressedImage() [1/2]

impeller::DecompressedImage::DecompressedImage | ( |  | ) |
| default

## ◆ DecompressedImage() [2/2]

impeller::DecompressedImage::DecompressedImage | ( | ISize | size,
|  | Format | format,
|  | std::shared_ptr< const fml::Mapping > | allocation
| ) |  |

Definition at line 16 of file decompressed_image.cc.

20 : size_(size), format_(format), allocation_(std::move(allocation)) {
21 if (!allocation_ || size.IsEmpty() || format_ == Format::kInvalid) {
22 return;
23 }
24 is_valid_ = true;
25 }
impeller::DecompressedImage::Format::kInvalid
@ kInvalid

## ◆ ~DecompressedImage()

impeller::DecompressedImage::~DecompressedImage | ( |  | ) |
| default

## Member Function Documentation

## ◆ ConvertToRGBA()

DecompressedImage impeller::DecompressedImage::ConvertToRGBA | ( |  | ) | const

Definition at line 62 of file decompressed_image.cc.

62 {
63 if (!is_valid_) {
64 return {};
65 }
66
67 if (format_ == Format::kRGBA) {
68 return DecompressedImage{size_, format_, allocation_};
69 }
70
71 const auto bpp = GetBytesPerPixel(format_);
72 const auto source_byte_size = size_.Area() * bpp;
73 if (allocation_->GetSize() < source_byte_size) {
74 return {};
75 }
76
77 auto rgba_allocation = std::make_shared<Allocation>();
78 if (!rgba_allocation->Truncate(Bytes{size_.Area() * 4u}, false)) {
79 return {};
80 }
81
82 const uint8_t* source = allocation_->GetMapping();
83 uint8_t* dest = rgba_allocation->GetBuffer();
84
85 for (size_t i = 0, j = 0; i < source_byte_size; i += bpp, j += 4u) {
86 switch (format_) {
87 case DecompressedImage::Format::kGrey:
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();
92 break;
93 case DecompressedImage::Format::kGreyAlpha:
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];
98 break;
99 case DecompressedImage::Format::kRGB:
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();
104 break;
105 case DecompressedImage::Format::kInvalid:
106 case DecompressedImage::Format::kRGBA:
107 // Should never happen. The necessary checks have already been
108 // performed.
109 FML_CHECK(false);
110 break;
111 }
112 }
113
114 return DecompressedImage{
115 size_, Format::kRGBA,
116 std::make_shared<fml::NonOwnedMapping>(
117 rgba_allocation->GetBuffer(), //
118 rgba_allocation->GetLength().GetByteSize(), //
119 [rgba_allocation](auto, auto) {}) //
120 };
121 }
impeller::DecompressedImage::DecompressedImage
DecompressedImage()
impeller::DecompressedImage::Format::kGrey
@ kGrey
impeller::DecompressedImage::Format::kRGB
@ kRGB
impeller::DecompressedImage::Format::kGreyAlpha
@ kGreyAlpha
impeller::DecompressedImage::Format::kRGBA
@ kRGBA
impeller::Bytes
AllocationSize< 1u > Bytes
Definition: allocation_size.h:129
impeller::GetBytesPerPixel
static size_t GetBytesPerPixel(DecompressedImage::Format format)
Definition: decompressed_image.cc:46
impeller::TSize::Area
constexpr Type Area() const
Definition: size.h:120

References impeller::TSize< T >::Area(), impeller::GetBytesPerPixel(), kGrey, kGreyAlpha, kInvalid, kRGB, and kRGBA.

## ◆ GetAllocation()

const std::shared_ptr< const fml::Mapping > & impeller::DecompressedImage::GetAllocation | ( |  | ) | const

Definition at line 41 of file decompressed_image.cc.

42 {
43 return allocation_;
44 }

Referenced by impeller::CreateTextureForDecompressedImage().

## ◆ GetFormat()

DecompressedImage::Format impeller::DecompressedImage::GetFormat | ( |  | ) | const

Definition at line 37 of file decompressed_image.cc.

37 {
38 return format_;
39 }

## ◆ GetSize()

const ISize & impeller::DecompressedImage::GetSize | ( |  | ) | const

Definition at line 33 of file decompressed_image.cc.

33 {
34 return size_;
35 }

Referenced by impeller::CreateTextureForDecompressedImage().

## ◆ IsValid()

bool impeller::DecompressedImage::IsValid | ( |  | ) | const

Definition at line 29 of file decompressed_image.cc.

29 {
30 return is_valid_;
31 }

The documentation for this class was generated from the following files:

- impeller/playground/image/decompressed_image.h
- impeller/playground/image/decompressed_image.cc