Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: src/ports/SkImageEncoder_WIC.cpp

Issue 2246203002: Revert of Fix WIC encoder to support kJPEG_Type (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/images/SkForceLinking.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkImageEncoder_WIC.cpp
diff --git a/src/ports/SkImageEncoder_WIC.cpp b/src/ports/SkImageEncoder_WIC.cpp
index ff651d32fa07ee42ae34518a34f276445804e4e7..5523ea2e11e267e13ad049e48752043a5bf5c9e8 100644
--- a/src/ports/SkImageEncoder_WIC.cpp
+++ b/src/ports/SkImageEncoder_WIC.cpp
@@ -83,55 +83,34 @@
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;
@@ -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;
« no previous file with comments | « src/images/SkForceLinking.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698