| OLD | NEW | 
|---|
| 1 | 1 | 
| 2 /* | 2 /* | 
| 3  * Copyright 2011 Google Inc. | 3  * Copyright 2011 Google Inc. | 
| 4  * | 4  * | 
| 5  * Use of this source code is governed by a BSD-style license that can be | 5  * Use of this source code is governed by a BSD-style license that can be | 
| 6  * found in the LICENSE file. | 6  * found in the LICENSE file. | 
| 7  */ | 7  */ | 
| 8 | 8 | 
| 9 | 9 | 
| 10 #define WIN32_LEAN_AND_MEAN | 10 #define WIN32_LEAN_AND_MEAN | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 22 //All Windows SDKs back to XPSP2 export the CLSID_WICImagingFactory symbol. | 22 //All Windows SDKs back to XPSP2 export the CLSID_WICImagingFactory symbol. | 
| 23 //In the Windows8 SDK the CLSID_WICImagingFactory symbol is still exported | 23 //In the Windows8 SDK the CLSID_WICImagingFactory symbol is still exported | 
| 24 //but CLSID_WICImagingFactory is then #defined to CLSID_WICImagingFactory2. | 24 //but CLSID_WICImagingFactory is then #defined to CLSID_WICImagingFactory2. | 
| 25 //Undo this #define if it has been done so that we link against the symbols | 25 //Undo this #define if it has been done so that we link against the symbols | 
| 26 //we intended to link against on all SDKs. | 26 //we intended to link against on all SDKs. | 
| 27 #if defined(CLSID_WICImagingFactory) | 27 #if defined(CLSID_WICImagingFactory) | 
| 28 #undef CLSID_WICImagingFactory | 28 #undef CLSID_WICImagingFactory | 
| 29 #endif | 29 #endif | 
| 30 | 30 | 
| 31 class SkImageDecoder_WIC : public SkImageDecoder { | 31 class SkImageDecoder_WIC : public SkImageDecoder { | 
|  | 32 public: | 
|  | 33     SkImageDecoder_WIC() | 
|  | 34     : fFormat(kUnknown_Format) {} | 
|  | 35 | 
| 32 protected: | 36 protected: | 
| 33     virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode); | 37     virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode mode); | 
|  | 38 | 
|  | 39 private: | 
|  | 40     Format fFormat; | 
| 34 }; | 41 }; | 
| 35 | 42 | 
|  | 43 struct FormatConversion { | 
|  | 44     GUID                    fGuidFormat; | 
|  | 45     SkImageDecoder::Format  fFormat; | 
|  | 46 }; | 
|  | 47 | 
|  | 48 static const FormatConversion gFormatConversions[] = { | 
|  | 49     { GUID_ContainerFormatBmp, SkImageDecoder::kBMP_Format }, | 
|  | 50     { GUID_ContainerFormatGif, SkImageDecoder::kGIF_Format }, | 
|  | 51     { GUID_ContainerFormatIco, SkImageDecoder::kICO_Format }, | 
|  | 52     { GUID_ContainerFormatJpeg, SkImageDecoder::kJPEG_Format }, | 
|  | 53     { GUID_ContainerFormatPng, SkImageDecoder::kPNG_Format }, | 
|  | 54 }; | 
|  | 55 | 
|  | 56 static SkImageDecoder::Format GuidContainerFormat_to_Format(REFGUID guid) { | 
|  | 57     for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) { | 
|  | 58         if (IsEqualGUID(guid, gFormatConversions[i].fGuidFormat)) { | 
|  | 59             return gFormatConversions[i].fFormat; | 
|  | 60         } | 
|  | 61     } | 
|  | 62     return SkImageDecoder::kUnknown_Format; | 
|  | 63 } | 
|  | 64 | 
| 36 bool SkImageDecoder_WIC::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { | 65 bool SkImageDecoder_WIC::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) { | 
| 37     //Initialize COM. | 66     //Initialize COM. | 
| 38     SkAutoCoInitialize scopedCo; | 67     SkAutoCoInitialize scopedCo; | 
| 39     if (!scopedCo.succeeded()) { | 68     if (!scopedCo.succeeded()) { | 
| 40         return false; | 69         return false; | 
| 41     } | 70     } | 
| 42 | 71 | 
| 43     HRESULT hr = S_OK; | 72     HRESULT hr = S_OK; | 
| 44 | 73 | 
| 45     //Create Windows Imaging Component ImagingFactory. | 74     //Create Windows Imaging Component ImagingFactory. | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 142             NULL,                             //Get all the pixels | 171             NULL,                             //Get all the pixels | 
| 143             stride, | 172             stride, | 
| 144             stride * height, | 173             stride * height, | 
| 145             reinterpret_cast<BYTE *>(bm->getPixels()) | 174             reinterpret_cast<BYTE *>(bm->getPixels()) | 
| 146         ); | 175         ); | 
| 147 | 176 | 
| 148         // Note: we don't need to premultiply here since we specified PBGRA | 177         // Note: we don't need to premultiply here since we specified PBGRA | 
| 149         bm->computeAndSetOpaquePredicate(); | 178         bm->computeAndSetOpaquePredicate(); | 
| 150     } | 179     } | 
| 151 | 180 | 
|  | 181     //Get the format | 
|  | 182     if (SUCCEEDED(hr)) { | 
|  | 183         GUID format; | 
|  | 184         HRESULT result = piBitmapDecoder->GetContainerFormat(&format); | 
|  | 185         if (SUCCEEDED(result)) { | 
|  | 186             fFormat = GuidContainerFormat_to_Format(format); | 
|  | 187         } else { | 
|  | 188             fFormat = kUnknown_Format; | 
|  | 189         } | 
|  | 190     } | 
|  | 191 | 
| 152     return SUCCEEDED(hr); | 192     return SUCCEEDED(hr); | 
| 153 } | 193 } | 
| 154 | 194 | 
| 155 ///////////////////////////////////////////////////////////////////////// | 195 ///////////////////////////////////////////////////////////////////////// | 
| 156 | 196 | 
| 157 extern SkImageDecoder* image_decoder_from_stream(SkStream*); | 197 extern SkImageDecoder* image_decoder_from_stream(SkStream*); | 
| 158 | 198 | 
| 159 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { | 199 SkImageDecoder* SkImageDecoder::Factory(SkStream* stream) { | 
| 160     SkImageDecoder* decoder = image_decoder_from_stream(stream); | 200     SkImageDecoder* decoder = image_decoder_from_stream(stream); | 
| 161     if (NULL == decoder) { | 201     if (NULL == decoder) { | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 187 | 227 | 
| 188 bool SkImageEncoder_WIC::onEncode(SkWStream* stream | 228 bool SkImageEncoder_WIC::onEncode(SkWStream* stream | 
| 189                                 , const SkBitmap& bitmapOrig | 229                                 , const SkBitmap& bitmapOrig | 
| 190                                 , int quality) | 230                                 , int quality) | 
| 191 { | 231 { | 
| 192     GUID type; | 232     GUID type; | 
| 193     switch (fType) { | 233     switch (fType) { | 
| 194         case kBMP_Type: | 234         case kBMP_Type: | 
| 195             type = GUID_ContainerFormatBmp; | 235             type = GUID_ContainerFormatBmp; | 
| 196             break; | 236             break; | 
| 197         case kGIF_Type: |  | 
| 198             type = GUID_ContainerFormatGif; |  | 
| 199             break; |  | 
| 200         case kICO_Type: | 237         case kICO_Type: | 
| 201             type = GUID_ContainerFormatIco; | 238             type = GUID_ContainerFormatIco; | 
| 202             break; | 239             break; | 
| 203         case kJPEG_Type: | 240         case kJPEG_Type: | 
| 204             type = GUID_ContainerFormatJpeg; | 241             type = GUID_ContainerFormatJpeg; | 
| 205             break; | 242             break; | 
| 206         case kPNG_Type: | 243         case kPNG_Type: | 
| 207             type = GUID_ContainerFormatPng; | 244             type = GUID_ContainerFormatPng; | 
| 208             break; | 245             break; | 
| 209         default: | 246         default: | 
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 341     return SUCCEEDED(hr); | 378     return SUCCEEDED(hr); | 
| 342 } | 379 } | 
| 343 | 380 | 
| 344 /////////////////////////////////////////////////////////////////////////////// | 381 /////////////////////////////////////////////////////////////////////////////// | 
| 345 | 382 | 
| 346 #include "SkTRegistry.h" | 383 #include "SkTRegistry.h" | 
| 347 | 384 | 
| 348 static SkImageEncoder* sk_imageencoder_wic_factory(SkImageEncoder::Type t) { | 385 static SkImageEncoder* sk_imageencoder_wic_factory(SkImageEncoder::Type t) { | 
| 349     switch (t) { | 386     switch (t) { | 
| 350         case SkImageEncoder::kBMP_Type: | 387         case SkImageEncoder::kBMP_Type: | 
| 351         case SkImageEncoder::kGIF_Type: |  | 
| 352         case SkImageEncoder::kICO_Type: | 388         case SkImageEncoder::kICO_Type: | 
| 353         case SkImageEncoder::kJPEG_Type: | 389         case SkImageEncoder::kJPEG_Type: | 
| 354         case SkImageEncoder::kPNG_Type: | 390         case SkImageEncoder::kPNG_Type: | 
| 355             break; | 391             break; | 
| 356         default: | 392         default: | 
| 357             return NULL; | 393             return NULL; | 
| 358     } | 394     } | 
| 359     return SkNEW_ARGS(SkImageEncoder_WIC, (t)); | 395     return SkNEW_ARGS(SkImageEncoder_WIC, (t)); | 
| 360 } | 396 } | 
| 361 | 397 | 
| 362 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_imageencoder_
     wic_factory); | 398 static SkTRegistry<SkImageEncoder*, SkImageEncoder::Type> gEReg(sk_imageencoder_
     wic_factory); | 
| OLD | NEW | 
|---|