Explicitly set alpha type of bitmaps with JPEG data to opaque
Actually fixes #11245.
This commit is contained in:
parent
c0c983d28d
commit
b9ed7380aa
2 changed files with 15 additions and 2 deletions
|
@ -17,6 +17,8 @@
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "net/base/data_url.h"
|
#include "net/base/data_url.h"
|
||||||
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
|
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||||
#include "third_party/skia/include/core/SkPixelRef.h"
|
#include "third_party/skia/include/core/SkPixelRef.h"
|
||||||
#include "ui/base/layout.h"
|
#include "ui/base/layout.h"
|
||||||
#include "ui/base/webui/web_ui_util.h"
|
#include "ui/base/webui/web_ui_util.h"
|
||||||
|
@ -93,9 +95,20 @@ bool AddImageSkiaRep(gfx::ImageSkia* image,
|
||||||
std::unique_ptr<SkBitmap> decoded(new SkBitmap());
|
std::unique_ptr<SkBitmap> decoded(new SkBitmap());
|
||||||
|
|
||||||
// Try PNG first.
|
// Try PNG first.
|
||||||
if (!gfx::PNGCodec::Decode(data, size, decoded.get()))
|
if (!gfx::PNGCodec::Decode(data, size, decoded.get())) {
|
||||||
// Try JPEG.
|
// Try JPEG.
|
||||||
decoded = gfx::JPEGCodec::Decode(data, size);
|
decoded = gfx::JPEGCodec::Decode(data, size);
|
||||||
|
if (decoded) {
|
||||||
|
// `JPEGCodec::Decode()` doesn't tell `SkBitmap` instance it creates
|
||||||
|
// that all of its pixels are opaque, that's why the bitmap gets
|
||||||
|
// an alpha type `kPremul_SkAlphaType` instead of `kOpaque_SkAlphaType`.
|
||||||
|
// Let's fix it here.
|
||||||
|
// TODO(alexeykuzmin): This workaround should be removed
|
||||||
|
// when the `JPEGCodec::Decode()` code is fixed.
|
||||||
|
// See https://github.com/electron/electron/issues/11294.
|
||||||
|
decoded->setAlphaType(SkAlphaType::kOpaque_SkAlphaType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!decoded) {
|
if (!decoded) {
|
||||||
// Try Bitmap
|
// Try Bitmap
|
||||||
|
|
|
@ -29,7 +29,7 @@ describe('nativeImage module', () => {
|
||||||
width: 1
|
width: 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAFUlEQVQYlWP8////fwYGBgYmBigAAD34BABBrq9BAAAAAElFTkSuQmCC',
|
dataUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVQYlWP8//8/AwMDEwMDAwMDAwAkBgMBBMzldwAAAABJRU5ErkJggg==',
|
||||||
filename: '2x2.jpg',
|
filename: '2x2.jpg',
|
||||||
format: ImageFormat.JPEG,
|
format: ImageFormat.JPEG,
|
||||||
hasAlphaChannel: false,
|
hasAlphaChannel: false,
|
||||||
|
|
Loading…
Reference in a new issue