Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
flutter::ImageDescriptor Class Reference

Creates an image descriptor for encoded or decoded image data, describing the width, height, and bytes per pixel for that image. This class will hold a reference on the underlying image data, and in the case of compressed data, an ImageGenerator for the data. The Codec initialization actually happens in initEncoded, making initstantiateCodec a lightweight operation. More...

#include <image_descriptor.h>

Inheritance diagram for flutter::ImageDescriptor:
flutter::RefCountedDartWrappable< ImageDescriptor > fml::RefCountedThreadSafe< T > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Types

enum  PixelFormat { kRGBA8888 , kBGRA8888 , kRGBAFloat32 }
 
- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields { kPeerIndex , kNumberOfNativeFields }
 

Public Member Functions

 ~ImageDescriptor () override=default
 
void instantiateCodec (Dart_Handle codec, int target_width, int target_height)
 Associates a flutter::Codec object with the dart.ui Codec handle.
 
int width () const
 The width of this image, EXIF oriented if applicable.
 
int height () const
 The height of this image. EXIF oriented if applicable.
 
int bytesPerPixel () const
 The bytes per pixel of the image.
 
int row_bytes () const
 The byte length of the first row of the image. Defaults to width() * 4.
 
bool should_resize (int target_width, int target_height) const
 Whether the given target_width or target_height differ from width() and height() respectively.
 
sk_sp< SkDatadata () const
 The underlying buffer for this image.
 
sk_sp< SkImageimage () const
 
bool is_compressed () const
 Whether this descriptor represents compressed (encoded) data or not.
 
const SkImageInfoimage_info () const
 The orientation corrected image info for this image.
 
SkISize get_scaled_dimensions (float scale)
 Gets the scaled dimensions of this image, if backed by an ImageGenerator that can perform efficient subpixel scaling.
 
bool get_pixels (const SkPixmap &pixmap) const
 Gets pixels for this image transformed based on the EXIF orientation tag, if applicable.
 
void dispose ()
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< ImageDescriptor >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< T >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static Dart_Handle initEncoded (Dart_Handle descriptor_handle, ImmutableBuffer *immutable_buffer, Dart_Handle callback_handle)
 Asynchronously initializes an ImageDescriptor for an encoded image, as long as the format is recognized by an encoder installed in the ImageGeneratorRegistry. Calling this method will create an ImageGenerator and read EXIF corrected dimensions from the image data.
 
static void initRaw (Dart_Handle descriptor_handle, const fml::RefPtr< ImmutableBuffer > &data, int width, int height, int row_bytes, PixelFormat pixel_format)
 Synchronously initializes an ImageDescriptor for decompressed image data as specified by the PixelFormat.
 

Friends

class ImageDecoderFixtureTest
 

Additional Inherited Members

- Protected Member Functions inherited from fml::RefCountedThreadSafe< T >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Creates an image descriptor for encoded or decoded image data, describing the width, height, and bytes per pixel for that image. This class will hold a reference on the underlying image data, and in the case of compressed data, an ImageGenerator for the data. The Codec initialization actually happens in initEncoded, making initstantiateCodec a lightweight operation.

See also
ImageGenerator

Definition at line 32 of file image_descriptor.h.

Member Enumeration Documentation

◆ PixelFormat

Enumerator
kRGBA8888 
kBGRA8888 
kRGBAFloat32 

Definition at line 37 of file image_descriptor.h.

Constructor & Destructor Documentation

◆ ~ImageDescriptor()

flutter::ImageDescriptor::~ImageDescriptor ( )
overridedefault

Member Function Documentation

◆ bytesPerPixel()

int flutter::ImageDescriptor::bytesPerPixel ( ) const
inline

The bytes per pixel of the image.

Definition at line 72 of file image_descriptor.h.

72{ return image_info_.bytesPerPixel(); }
int bytesPerPixel() const

◆ data()

sk_sp< SkData > flutter::ImageDescriptor::data ( ) const
inline

The underlying buffer for this image.

Definition at line 88 of file image_descriptor.h.

88{ return buffer_; }

◆ dispose()

void flutter::ImageDescriptor::dispose ( )
inline

Definition at line 113 of file image_descriptor.h.

113 {
114 buffer_.reset();
115 generator_.reset();
117 }
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310

◆ get_pixels()

bool flutter::ImageDescriptor::get_pixels ( const SkPixmap pixmap) const

Gets pixels for this image transformed based on the EXIF orientation tag, if applicable.

Definition at line 128 of file image_descriptor.cc.

128 {
129 FML_DCHECK(generator_);
130 return generator_->GetPixels(pixmap.info(), pixmap.writable_addr(),
131 pixmap.rowBytes());
132}
size_t rowBytes() const
Definition SkPixmap.h:145
const SkImageInfo & info() const
Definition SkPixmap.h:135
void * writable_addr() const
Definition SkPixmap.h:483
#define FML_DCHECK(condition)
Definition logging.h:103

◆ get_scaled_dimensions()

SkISize flutter::ImageDescriptor::get_scaled_dimensions ( float  scale)
inline

Gets the scaled dimensions of this image, if backed by an ImageGenerator that can perform efficient subpixel scaling.

See also
ImageGenerator::GetScaledDimensions

Definition at line 102 of file image_descriptor.h.

102 {
103 if (generator_) {
104 return generator_->GetScaledDimensions(scale);
105 }
106 return image_info_.dimensions();
107 }
const Scalar scale
SkISize dimensions() const

◆ height()

int flutter::ImageDescriptor::height ( ) const
inline

The height of this image. EXIF oriented if applicable.

Definition at line 69 of file image_descriptor.h.

69{ return image_info_.height(); }
int height() const

◆ image()

sk_sp< SkImage > flutter::ImageDescriptor::image ( ) const

Definition at line 124 of file image_descriptor.cc.

124 {
125 return generator_->GetImage();
126}

◆ image_info()

const SkImageInfo & flutter::ImageDescriptor::image_info ( ) const
inline

The orientation corrected image info for this image.

Definition at line 97 of file image_descriptor.h.

97{ return image_info_; }

◆ initEncoded()

Dart_Handle flutter::ImageDescriptor::initEncoded ( Dart_Handle  descriptor_handle,
ImmutableBuffer immutable_buffer,
Dart_Handle  callback_handle 
)
static

Asynchronously initializes an ImageDescriptor for an encoded image, as long as the format is recognized by an encoder installed in the ImageGeneratorRegistry. Calling this method will create an ImageGenerator and read EXIF corrected dimensions from the image data.

See also
ImageGeneratorRegistry

Definition at line 40 of file image_descriptor.cc.

42 {
43 if (!Dart_IsClosure(callback_handle)) {
44 return tonic::ToDart("Callback must be a function");
45 }
46
47 if (!immutable_buffer) {
48 return tonic::ToDart("Buffer parameter must not be null");
49 }
50
51 // This has to be valid because this method is called from Dart.
52 auto dart_state = UIDartState::Current();
53 auto registry = dart_state->GetImageGeneratorRegistry();
54
55 if (!registry) {
56 return tonic::ToDart(
57 "Failed to access the internal image decoder "
58 "registry on this isolate. Please file a bug on "
59 "https://github.com/flutter/flutter/issues.");
60 }
61
62 auto generator =
63 registry->CreateCompatibleGenerator(immutable_buffer->data());
64
65 if (!generator) {
66 // No compatible image decoder was found.
67 return tonic::ToDart("Invalid image data");
68 }
69
70 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(
71 immutable_buffer->data(), std::move(generator));
72
73 FML_DCHECK(descriptor);
74
75 descriptor->AssociateWithDartWrapper(descriptor_handle);
76 tonic::DartInvoke(callback_handle, {Dart_TypeVoid()});
77
78 return Dart_Null();
79}
static UIDartState * Current()
DART_EXPORT Dart_Handle Dart_TypeVoid(void)
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT bool Dart_IsClosure(Dart_Handle object)
Dart_Handle ToDart(const T &object)
Dart_Handle DartInvoke(Dart_Handle closure, std::initializer_list< Dart_Handle > args)

◆ initRaw()

void flutter::ImageDescriptor::initRaw ( Dart_Handle  descriptor_handle,
const fml::RefPtr< ImmutableBuffer > &  data,
int  width,
int  height,
int  row_bytes,
PixelFormat  pixel_format 
)
static

Synchronously initializes an ImageDescriptor for decompressed image data as specified by the PixelFormat.

Definition at line 81 of file image_descriptor.cc.

86 {
89 switch (pixel_format) {
92 break;
95 break;
97 // `PixelFormat.rgbaFloat32` is documented to not use premultiplied alpha.
100 break;
101 }
104 auto descriptor = fml::MakeRefCounted<ImageDescriptor>(
105 data->data(), std::move(image_info),
106 row_bytes == -1 ? std::nullopt : std::optional<size_t>(row_bytes));
107 descriptor->AssociateWithDartWrapper(descriptor_handle);
108}
kUnpremul_SkAlphaType
SkAlphaType
Definition SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
SkColorType
Definition SkColorType.h:19
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition SkColorType.h:40
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
const void * data() const
Definition SkData.h:37
const SkImageInfo & image_info() const
The orientation corrected image info for this image.
int row_bytes() const
The byte length of the first row of the image. Defaults to width() * 4.
sk_sp< SkData > data() const
The underlying buffer for this image.
Definition ref_ptr.h:256
uint32_t color_type
int32_t height
int32_t width
uint32_t alpha_type
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ instantiateCodec()

void flutter::ImageDescriptor::instantiateCodec ( Dart_Handle  codec,
int  target_width,
int  target_height 
)

Associates a flutter::Codec object with the dart.ui Codec handle.

Definition at line 110 of file image_descriptor.cc.

112 {
113 fml::RefPtr<Codec> ui_codec;
114 if (!generator_ || generator_->GetFrameCount() == 1) {
115 ui_codec = fml::MakeRefCounted<SingleFrameCodec>(
116 static_cast<fml::RefPtr<ImageDescriptor>>(this), target_width,
117 target_height);
118 } else {
119 ui_codec = fml::MakeRefCounted<MultiFrameCodec>(generator_);
120 }
121 ui_codec->AssociateWithDartWrapper(codec_handle);
122}

◆ is_compressed()

bool flutter::ImageDescriptor::is_compressed ( ) const
inline

Whether this descriptor represents compressed (encoded) data or not.

Definition at line 94 of file image_descriptor.h.

94{ return !!generator_; }

◆ row_bytes()

int flutter::ImageDescriptor::row_bytes ( ) const
inline

The byte length of the first row of the image. Defaults to width() * 4.

Definition at line 76 of file image_descriptor.h.

76 {
77 return row_bytes_.value_or(
78 static_cast<size_t>(image_info_.width() * image_info_.bytesPerPixel()));
79 }
int width() const

◆ should_resize()

bool flutter::ImageDescriptor::should_resize ( int  target_width,
int  target_height 
) const
inline

Whether the given target_width or target_height differ from width() and height() respectively.

Definition at line 83 of file image_descriptor.h.

83 {
84 return target_width != width() || target_height != height();
85 }

◆ width()

int flutter::ImageDescriptor::width ( ) const
inline

The width of this image, EXIF oriented if applicable.

Definition at line 66 of file image_descriptor.h.

66{ return image_info_.width(); }

Friends And Related Symbol Documentation

◆ ImageDecoderFixtureTest

friend class ImageDecoderFixtureTest
friend

Definition at line 137 of file image_descriptor.h.


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