18
18
#include " impeller/base/strings.h"
19
19
#include " impeller/geometry/size.h"
20
20
#include " include/core/SkSize.h"
21
+ #include " third_party/skia/include/core/SkMallocPixelRef.h"
21
22
#include " third_party/skia/include/core/SkPixmap.h"
22
23
23
24
namespace flutter {
@@ -66,23 +67,21 @@ std::shared_ptr<SkBitmap> ImageDecoderImpeller::DecompressTexture(
66
67
return nullptr ;
67
68
}
68
69
69
- if (!descriptor->is_compressed ()) {
70
- FML_DLOG (ERROR)
71
- << " Uncompressed images are not implemented in Impeller yet." ;
72
- return nullptr ;
73
- }
74
70
target_size.set (std::min (static_cast <int32_t >(max_texture_size.width ),
75
71
target_size.width ()),
76
72
std::min (static_cast <int32_t >(max_texture_size.height ),
77
73
target_size.height ()));
78
74
79
75
const SkISize source_size = descriptor->image_info ().dimensions ();
80
- auto decode_size = descriptor->get_scaled_dimensions (std::max (
81
- static_cast <double >(target_size.width ()) / source_size.width (),
82
- static_cast <double >(target_size.height ()) / source_size.height ()));
76
+ auto decode_size = source_size;
77
+ if (descriptor->is_compressed ()) {
78
+ decode_size = descriptor->get_scaled_dimensions (std::max (
79
+ static_cast <double >(target_size.width ()) / source_size.width (),
80
+ static_cast <double >(target_size.height ()) / source_size.height ()));
81
+ }
83
82
84
83
// ----------------------------------------------------------------------------
85
- // / 1. Decode the image into the image generator's closest supported size .
84
+ // / 1. Decode the image.
86
85
// /
87
86
88
87
const auto base_image_info = descriptor->image_info ();
@@ -99,18 +98,26 @@ std::shared_ptr<SkBitmap> ImageDecoderImpeller::DecompressTexture(
99
98
}
100
99
101
100
auto bitmap = std::make_shared<SkBitmap>();
102
- if (!bitmap->tryAllocPixels (image_info)) {
103
- FML_DLOG (ERROR)
104
- << " Could not allocate intermediate for image decompression." ;
105
- return nullptr ;
106
- }
107
-
108
- if (!descriptor->get_pixels (bitmap->pixmap ())) {
109
- FML_DLOG (ERROR) << " Could not decompress image." ;
110
- return nullptr ;
101
+ if (descriptor->is_compressed ()) {
102
+ if (!bitmap->tryAllocPixels (image_info)) {
103
+ FML_DLOG (ERROR)
104
+ << " Could not allocate intermediate for image decompression." ;
105
+ return nullptr ;
106
+ }
107
+ // Decode the image into the image generator's closest supported size.
108
+ if (!descriptor->get_pixels (bitmap->pixmap ())) {
109
+ FML_DLOG (ERROR) << " Could not decompress image." ;
110
+ return nullptr ;
111
+ }
112
+ } else {
113
+ bitmap->setInfo (image_info);
114
+ auto pixel_ref = SkMallocPixelRef::MakeWithData (
115
+ image_info, descriptor->row_bytes (), descriptor->data ());
116
+ bitmap->setPixelRef (pixel_ref, 0 , 0 );
117
+ bitmap->setImmutable ();
111
118
}
112
119
113
- if (decode_size == target_size) {
120
+ if (bitmap-> dimensions () == target_size) {
114
121
return bitmap;
115
122
}
116
123
0 commit comments