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 #include "SkTypes.h" | 9 #include "SkTypes.h" |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 kDecodeFormat_WICMode, | 54 kDecodeFormat_WICMode, |
55 kDecodeBounds_WICMode, | 55 kDecodeBounds_WICMode, |
56 kDecodePixels_WICMode, | 56 kDecodePixels_WICMode, |
57 }; | 57 }; |
58 | 58 |
59 /** | 59 /** |
60 * Helper function to decode an SkStream. | 60 * Helper function to decode an SkStream. |
61 * @param stream SkStream to decode. Must be at the beginning. | 61 * @param stream SkStream to decode. Must be at the beginning. |
62 * @param bm SkBitmap to decode into. Only used if wicMode is kDecodeBoun
ds_WICMode or | 62 * @param bm SkBitmap to decode into. Only used if wicMode is kDecodeBoun
ds_WICMode or |
63 * kDecodePixels_WICMode, in which case it must not be NULL. | 63 * kDecodePixels_WICMode, in which case it must not be NULL. |
64 * @param format Out parameter for the SkImageDecoder::Format of the SkStre
am. Only used if | 64 * @param format Out parameter for the SkEncodedFormat of the SkStream. Onl
y used if |
65 * wicMode is kDecodeFormat_WICMode. | 65 * wicMode is kDecodeFormat_WICMode. |
66 */ | 66 */ |
67 bool decodeStream(SkStream* stream, SkBitmap* bm, WICModes wicMode, Format*
format) const; | 67 bool decodeStream(SkStream* stream, SkBitmap* bm, WICModes wicMode, |
| 68 SkEncodedFormat* format) const; |
68 | 69 |
69 protected: | 70 protected: |
70 Result onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE; | 71 Result onDecode(SkStream* stream, SkBitmap* bm, Mode mode) SK_OVERRIDE; |
71 }; | 72 }; |
72 | 73 |
73 struct FormatConversion { | 74 struct FormatConversion { |
74 GUID fGuidFormat; | 75 GUID fGuidFormat; |
75 SkImageDecoder::Format fFormat; | 76 SkEncodedFormat fFormat; |
76 }; | 77 }; |
77 | 78 |
78 static const FormatConversion gFormatConversions[] = { | 79 static const FormatConversion gFormatConversions[] = { |
79 { GUID_ContainerFormatBmp, SkImageDecoder::kBMP_Format }, | 80 { GUID_ContainerFormatBmp, kBMP_SkEncodedFormat }, |
80 { GUID_ContainerFormatGif, SkImageDecoder::kGIF_Format }, | 81 { GUID_ContainerFormatGif, kGIF_SkEncodedFormat }, |
81 { GUID_ContainerFormatIco, SkImageDecoder::kICO_Format }, | 82 { GUID_ContainerFormatIco, kICO_SkEncodedFormat }, |
82 { GUID_ContainerFormatJpeg, SkImageDecoder::kJPEG_Format }, | 83 { GUID_ContainerFormatJpeg, kJPEG_SkEncodedFormat }, |
83 { GUID_ContainerFormatPng, SkImageDecoder::kPNG_Format }, | 84 { GUID_ContainerFormatPng, kPNG_SkEncodedFormat }, |
84 }; | 85 }; |
85 | 86 |
86 static SkImageDecoder::Format GuidContainerFormat_to_Format(REFGUID guid) { | 87 static SkEncodedFormat GuidContainerFormat_to_Format(REFGUID guid) { |
87 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) { | 88 for (size_t i = 0; i < SK_ARRAY_COUNT(gFormatConversions); i++) { |
88 if (IsEqualGUID(guid, gFormatConversions[i].fGuidFormat)) { | 89 if (IsEqualGUID(guid, gFormatConversions[i].fGuidFormat)) { |
89 return gFormatConversions[i].fFormat; | 90 return gFormatConversions[i].fFormat; |
90 } | 91 } |
91 } | 92 } |
92 return SkImageDecoder::kUnknown_Format; | 93 return kUnknown_SkEncodedFormat; |
93 } | 94 } |
94 | 95 |
95 SkImageDecoder::Result SkImageDecoder_WIC::onDecode(SkStream* stream, SkBitmap*
bm, Mode mode) { | 96 SkImageDecoder::Result SkImageDecoder_WIC::onDecode(SkStream* stream, SkBitmap*
bm, Mode mode) { |
96 WICModes wicMode; | 97 WICModes wicMode; |
97 switch (mode) { | 98 switch (mode) { |
98 case SkImageDecoder::kDecodeBounds_Mode: | 99 case SkImageDecoder::kDecodeBounds_Mode: |
99 wicMode = kDecodeBounds_WICMode; | 100 wicMode = kDecodeBounds_WICMode; |
100 break; | 101 break; |
101 case SkImageDecoder::kDecodePixels_Mode: | 102 case SkImageDecoder::kDecodePixels_Mode: |
102 wicMode = kDecodePixels_WICMode; | 103 wicMode = kDecodePixels_WICMode; |
103 break; | 104 break; |
104 } | 105 } |
105 return this->decodeStream(stream, bm, wicMode, NULL) ? kSuccess : kFailure; | 106 return this->decodeStream(stream, bm, wicMode, NULL) ? kSuccess : kFailure; |
106 } | 107 } |
107 | 108 |
108 bool SkImageDecoder_WIC::decodeStream(SkStream* stream, SkBitmap* bm, WICModes w
icMode, | 109 bool SkImageDecoder_WIC::decodeStream(SkStream* stream, SkBitmap* bm, WICModes w
icMode, |
109 Format* format) const { | 110 SkEncodedFormat* format) const { |
110 //Initialize COM. | 111 //Initialize COM. |
111 SkAutoCoInitialize scopedCo; | 112 SkAutoCoInitialize scopedCo; |
112 if (!scopedCo.succeeded()) { | 113 if (!scopedCo.succeeded()) { |
113 return false; | 114 return false; |
114 } | 115 } |
115 | 116 |
116 HRESULT hr = S_OK; | 117 HRESULT hr = S_OK; |
117 | 118 |
118 //Create Windows Imaging Component ImagingFactory. | 119 //Create Windows Imaging Component ImagingFactory. |
119 SkTScopedComPtr<IWICImagingFactory> piImagingFactory; | 120 SkTScopedComPtr<IWICImagingFactory> piImagingFactory; |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 hr = piEncoder->Commit(); | 433 hr = piEncoder->Commit(); |
433 } | 434 } |
434 | 435 |
435 return SUCCEEDED(hr); | 436 return SUCCEEDED(hr); |
436 } | 437 } |
437 | 438 |
438 /////////////////////////////////////////////////////////////////////////////// | 439 /////////////////////////////////////////////////////////////////////////////// |
439 | 440 |
440 static SkImageEncoder* sk_imageencoder_wic_factory(SkImageEncoder::Type t) { | 441 static SkImageEncoder* sk_imageencoder_wic_factory(SkImageEncoder::Type t) { |
441 switch (t) { | 442 switch (t) { |
442 case SkImageEncoder::kBMP_Type: | 443 case kBMP_SkEncodedFormat: |
443 case SkImageEncoder::kICO_Type: | 444 case kICO_SkEncodedFormat: |
444 case SkImageEncoder::kJPEG_Type: | 445 case kJPEG_SkEncodedFormat: |
445 case SkImageEncoder::kPNG_Type: | 446 case kPNG_SkEncodedFormat: |
446 break; | 447 break; |
447 default: | 448 default: |
448 return NULL; | 449 return NULL; |
449 } | 450 } |
450 return SkNEW_ARGS(SkImageEncoder_WIC, (t)); | 451 return SkNEW_ARGS(SkImageEncoder_WIC, (t)); |
451 } | 452 } |
452 | 453 |
453 static SkImageEncoder_EncodeReg gEReg(sk_imageencoder_wic_factory); | 454 static SkImageEncoder_EncodeReg gEReg(sk_imageencoder_wic_factory); |
454 | 455 |
455 static SkImageDecoder::Format get_format_wic(SkStreamRewindable* stream) { | 456 static SkEncodedFormat get_format_wic(SkStreamRewindable* stream) { |
456 SkImageDecoder::Format format; | 457 SkEncodedFormat format; |
457 SkImageDecoder_WIC codec; | 458 SkImageDecoder_WIC codec; |
458 if (!codec.decodeStream(stream, NULL, SkImageDecoder_WIC::kDecodeFormat_WICM
ode, &format)) { | 459 if (!codec.decodeStream(stream, NULL, SkImageDecoder_WIC::kDecodeFormat_WICM
ode, &format)) { |
459 format = SkImageDecoder::kUnknown_Format; | 460 format = kUnknown_SkEncodedFormat; |
460 } | 461 } |
461 return format; | 462 return format; |
462 } | 463 } |
463 | 464 |
464 static SkImageDecoder_FormatReg gFormatReg(get_format_wic); | 465 static SkImageDecoder_FormatReg gFormatReg(get_format_wic); |
OLD | NEW |