Revert of Fix WIC encoder to support kJPEG_Type (patchset #3 id:140001 of https://codereview.chromium.org/2245453002/ )
Reason for revert:
Broken Windows bot.
Original issue's description:
> Fix WIC encoder to support kJPEG_Type
>
> (1) Add support for kJPEG to WIC
> (2) Add encoding test.
> (3) Turn on WIC jpeg encoder on Windows and CG jpeg
> encoder on Mac.
>
> A follow-up may make Skia's encoders the default on all
> platforms. But, in order to do that, I think we need
> to write better encoding unit tests for CG and WIC.
>
> BUG=skia:3969
> BUG=skia:5632
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2245453002
>
> Committed: https://skia.googlesource.com/skia/+/b3a7ef1fc0adc24859d2498aee54d3ec2cbcac3a
TBR=mtklein@google.com,mtklein@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:3969
Review-Url: https://codereview.chromium.org/2246203002
diff --git a/gm/encode.cpp b/gm/encode.cpp
deleted file mode 100644
index 3b6d43de..0000000
--- a/gm/encode.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "gm.h"
-#include "SkCanvas.h"
-#include "SkData.h"
-#include "SkImageEncoder.h"
-#include "Resources.h"
-
-namespace skiagm {
-
-class EncodeGM : public GM {
-public:
- EncodeGM() {}
-
-protected:
- SkString onShortName() override {
- return SkString("encode");
- }
-
- SkISize onISize() override {
- return SkISize::Make(1024, 600);
- }
-
- void onDraw(SkCanvas* canvas) override {
- SkBitmap orig;
- GetResourceAsBitmap("mandrill_512_q075.jpg", &orig);
- sk_sp<SkData> pngData(SkImageEncoder::EncodeData(orig, SkImageEncoder::kPNG_Type, 100));
- sk_sp<SkData> jpegData(SkImageEncoder::EncodeData(orig, SkImageEncoder::kJPEG_Type, 100));
-
- sk_sp<SkImage> pngImage = SkImage::MakeFromEncoded(pngData);
- sk_sp<SkImage> jpegImage = SkImage::MakeFromEncoded(jpegData);
- canvas->drawImage(pngImage.get(), 0.0f, 0.0f);
- canvas->drawImage(jpegImage.get(), 512.0f, 0.0f);
-
- SkPaint paint;
- sk_tool_utils::set_portable_typeface(&paint);
- const char text[] = "Images should look more-or-less the same.";
- canvas->drawText(text, sizeof(text) - 1, 450.0f, 550.0f, paint);
- }
-
-private:
- typedef GM INHERITED;
-};
-
-DEF_GM( return new EncodeGM; )
-}
diff --git a/src/images/SkForceLinking.cpp b/src/images/SkForceLinking.cpp
index 2afe719..e97106f 100644
--- a/src/images/SkForceLinking.cpp
+++ b/src/images/SkForceLinking.cpp
@@ -14,8 +14,7 @@
int SkForceLinking(bool doNotPassTrue) {
if (doNotPassTrue) {
SkASSERT(false);
-#if !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_IOS) && \
- defined(SK_HAS_JPEG_LIBRARY)
+#if defined(SK_HAS_JPEG_LIBRARY)
CreateJPEGImageEncoder();
#endif
#if defined(SK_HAS_WEBP_LIBRARY)
diff --git a/src/ports/SkImageEncoder_WIC.cpp b/src/ports/SkImageEncoder_WIC.cpp
index ff651d3..5523ea2 100644
--- a/src/ports/SkImageEncoder_WIC.cpp
+++ b/src/ports/SkImageEncoder_WIC.cpp
@@ -83,56 +83,35 @@
return false;
}
- // First convert to BGRA if necessary.
+ //Convert to 8888 if needed.
const SkBitmap* bitmap;
SkBitmap bitmapCopy;
- if (kBGRA_8888_SkColorType == bitmapOrig.colorType()) {
+ if (kN32_SkColorType == bitmapOrig.colorType() && bitmapOrig.isOpaque()) {
bitmap = &bitmapOrig;
} else {
- if (!bitmapOrig.copyTo(&bitmapCopy, kBGRA_8888_SkColorType)) {
+ if (!bitmapOrig.copyTo(&bitmapCopy, kN32_SkColorType)) {
return false;
}
bitmap = &bitmapCopy;
}
- // WIC expects unpremultiplied pixels. Unpremultiply if necessary.
- if (kPremul_SkAlphaType == bitmap->alphaType()) {
+ // We cannot use PBGRA so we need to unpremultiply ourselves
+ if (!bitmap->isOpaque()) {
SkAutoLockPixels alp(*bitmap);
+
uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap->getPixels());
for (int y = 0; y < bitmap->height(); ++y) {
for (int x = 0; x < bitmap->width(); ++x) {
uint8_t* bytes = pixels + y * bitmap->rowBytes() + x * bitmap->bytesPerPixel();
+
SkPMColor* src = reinterpret_cast<SkPMColor*>(bytes);
SkColor* dst = reinterpret_cast<SkColor*>(bytes);
+
*dst = SkUnPreMultiply::PMColorToColor(*src);
}
}
}
- // Finally, if we are performing a jpeg encode, we must convert to BGR.
- void* pixels = bitmap->getPixels();
- size_t rowBytes = bitmap->rowBytes();
- SkAutoMalloc pixelStorage;
- WICPixelFormatGUID formatDesired = GUID_WICPixelFormat32bppBGRA;
- if (kJPEG_Type == fType) {
- formatDesired = GUID_WICPixelFormat24bppBGR;
- rowBytes = SkAlign4(bitmap->width() * 3);
- pixelStorage.reset(rowBytes * bitmap->height());
- for (int y = 0; y < bitmap->height(); y++) {
- uint8_t* dstRow = SkTAddOffset<uint8_t>(pixelStorage.get(), y * rowBytes);
- for (int x = 0; x < bitmap->width(); x++) {
- uint32_t bgra = *bitmap->getAddr32(x, y);
- dstRow[0] = (uint8_t) (bgra >> 0);
- dstRow[1] = (uint8_t) (bgra >> 8);
- dstRow[2] = (uint8_t) (bgra >> 16);
- dstRow += 3;
- }
- }
-
- pixels = pixelStorage.get();
- }
-
-
//Initialize COM.
SkAutoCoInitialize scopedCo;
if (!scopedCo.succeeded()) {
@@ -205,6 +184,7 @@
//Set the pixel format of the frame. If native encoded format cannot match BGRA,
//it will choose the closest pixel format that it supports.
+ const WICPixelFormatGUID formatDesired = GUID_WICPixelFormat32bppBGRA;
WICPixelFormatGUID formatGUID = formatDesired;
if (SUCCEEDED(hr)) {
hr = piBitmapFrameEncode->SetPixelFormat(&formatGUID);
@@ -217,10 +197,12 @@
//Write the pixels into the frame.
if (SUCCEEDED(hr)) {
SkAutoLockPixels alp(*bitmap);
- hr = piBitmapFrameEncode->WritePixels(height,
- (UINT) rowBytes,
- (UINT) rowBytes * height,
- reinterpret_cast<BYTE*>(pixels));
+ const UINT stride = (UINT) bitmap->rowBytes();
+ hr = piBitmapFrameEncode->WritePixels(
+ height
+ , stride
+ , stride * height
+ , reinterpret_cast<BYTE*>(bitmap->getPixels()));
}
if (SUCCEEDED(hr)) {
@@ -241,7 +223,6 @@
case SkImageEncoder::kBMP_Type:
case SkImageEncoder::kICO_Type:
case SkImageEncoder::kPNG_Type:
- case SkImageEncoder::kJPEG_Type:
break;
default:
return nullptr;