diff options
author | 2011-08-01 19:37:43 +0000 | |
---|---|---|
committer | 2011-08-01 19:37:43 +0000 | |
commit | 22b4950f60c18d79b985bceb39784840e3d30004 (patch) | |
tree | 115618ebf18dbb5e20c51545fd68c2298ffae388 | |
parent | 030302ce69ce777c49f7b3ce5f53f02610bc9f48 (diff) |
Windows image decoder should handle all bitmap formats.
http://codereview.appspot.com/4801070/
git-svn-id: http://skia.googlecode.com/svn/trunk@2015 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | src/ports/SkImageDecoder_WIC.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/ports/SkImageDecoder_WIC.cpp b/src/ports/SkImageDecoder_WIC.cpp index 94508d7f5e..fc15ef4a74 100644 --- a/src/ports/SkImageDecoder_WIC.cpp +++ b/src/ports/SkImageDecoder_WIC.cpp @@ -162,7 +162,7 @@ private: }; bool SkImageEncoder_WIC::onEncode(SkWStream* stream - , const SkBitmap& bm + , const SkBitmap& bitmapOrig , int quality) { GUID type; @@ -177,6 +177,18 @@ bool SkImageEncoder_WIC::onEncode(SkWStream* stream return false; } + //Convert to 8888 if needed. + const SkBitmap* bitmap; + SkBitmap bitmapCopy; + if (SkBitmap::kARGB_8888_Config == bitmapOrig.config()) { + bitmap = &bitmapOrig; + } else { + if (!bitmapOrig.copyTo(&bitmapCopy, SkBitmap::kARGB_8888_Config)) { + return false; + } + bitmap = &bitmapCopy; + } + //Initialize COM. AutoCoInitialize scopedCo; HRESULT hr = scopedCo.getHR(); @@ -237,8 +249,8 @@ bool SkImageEncoder_WIC::onEncode(SkWStream* stream } //Set the size of the frame. - const UINT width = bm.width(); - const UINT height = bm.height(); + const UINT width = bitmap->width(); + const UINT height = bitmap->height(); if (SUCCEEDED(hr)) { hr = piBitmapFrameEncode->SetSize(width, height); } @@ -258,9 +270,9 @@ bool SkImageEncoder_WIC::onEncode(SkWStream* stream if (SUCCEEDED(hr)) { hr = piBitmapFrameEncode->WritePixels( height - , bm.rowBytes() - , bm.rowBytes()*height - , reinterpret_cast<BYTE*>(bm.getPixels())); + , bitmap->rowBytes() + , bitmap->rowBytes()*height + , reinterpret_cast<BYTE*>(bitmap->getPixels())); } if (SUCCEEDED(hr)) { |