OLD | NEW |
1 #include "DMWriteTask.h" | 1 #include "DMWriteTask.h" |
2 | 2 |
3 #include "DMUtil.h" | 3 #include "DMUtil.h" |
4 #include "SkColorPriv.h" | 4 #include "SkColorPriv.h" |
5 #include "SkCommandLineFlags.h" | 5 #include "SkCommandLineFlags.h" |
6 #include "SkImageDecoder.h" | 6 #include "SkImageDecoder.h" |
7 #include "SkImageEncoder.h" | 7 #include "SkImageEncoder.h" |
8 #include "SkString.h" | 8 #include "SkString.h" |
9 #include "SkUnPreMultiply.h" | 9 #include "SkUnPreMultiply.h" |
10 | 10 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 SkDebugf("Could not read %s.\n", path.c_str()); | 106 SkDebugf("Could not read %s.\n", path.c_str()); |
107 return false; | 107 return false; |
108 } | 108 } |
109 | 109 |
110 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream)); | 110 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream)); |
111 if (NULL == decoder.get()) { | 111 if (NULL == decoder.get()) { |
112 SkDebugf("Could not find a decoder for %s.\n", path.c_str()); | 112 SkDebugf("Could not find a decoder for %s.\n", path.c_str()); |
113 return false; | 113 return false; |
114 } | 114 } |
115 | 115 |
116 SkImageInfo info; | 116 const SkImageInfo info = bitmap.info(); |
117 SkAssertResult(bitmap.asImageInfo(&info)); | |
118 | 117 |
119 SkBitmap expected; | 118 SkBitmap expected; |
120 expected.setConfig(info); | 119 expected.allocPixels(info); |
121 expected.allocPixels(); | |
122 | 120 |
123 // expected will be unpremultiplied. | 121 // expected will be unpremultiplied. |
124 decoder->setRequireUnpremultipliedColors(true); | 122 decoder->setRequireUnpremultipliedColors(true); |
125 if (!decoder->decode(stream, &expected, SkImageDecoder::kDecodePixels_Mode))
{ | 123 if (!decoder->decode(stream, &expected, SkImageDecoder::kDecodePixels_Mode))
{ |
126 SkDebugf("Could not decode %s.\n", path.c_str()); | 124 SkDebugf("Could not decode %s.\n", path.c_str()); |
127 return false; | 125 return false; |
128 } | 126 } |
129 | 127 |
130 // We always seem to decode to 8888. This puts 565 back in 565. | 128 // We always seem to decode to 8888. This puts 565 back in 565. |
131 if (expected.config() != bitmap.config()) { | 129 if (expected.colorType() != bitmap.colorType()) { |
132 SkBitmap converted; | 130 SkBitmap converted; |
133 SkAssertResult(expected.copyTo(&converted, bitmap.config())); | 131 SkAssertResult(expected.copyTo(&converted, bitmap.colorType())); |
134 expected.swap(converted); | 132 expected.swap(converted); |
135 } | 133 } |
136 SkASSERT(expected.config() == bitmap.config()); | 134 SkASSERT(expected.config() == bitmap.config()); |
137 | 135 |
138 // Manually unpremultiply 8888 bitmaps to match expected. | 136 // Manually unpremultiply 8888 bitmaps to match expected. |
139 // Their pixels are shared, concurrently even, so we must copy them. | 137 // Their pixels are shared, concurrently even, so we must copy them. |
140 if (info.fColorType == kPMColor_SkColorType) { | 138 if (info.colorType() == kPMColor_SkColorType) { |
141 SkBitmap unpremul; | 139 SkBitmap unpremul; |
142 unpremul.setConfig(info); | 140 unpremul.allocPixels(info); |
143 unpremul.allocPixels(); | |
144 | 141 |
145 SkAutoLockPixels lockSrc(bitmap), lockDst(unpremul); | 142 SkAutoLockPixels lockSrc(bitmap), lockDst(unpremul); |
146 const SkPMColor* src = (SkPMColor*)bitmap.getPixels(); | 143 const SkPMColor* src = (SkPMColor*)bitmap.getPixels(); |
147 uint32_t* dst = (uint32_t*)unpremul.getPixels(); | 144 uint32_t* dst = (uint32_t*)unpremul.getPixels(); |
148 for (size_t i = 0; i < bitmap.getSize()/4; i++) { | 145 for (size_t i = 0; i < bitmap.getSize()/4; i++) { |
149 dst[i] = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(src[i]); | 146 dst[i] = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(src[i]); |
150 } | 147 } |
151 bitmap.swap(unpremul); | 148 bitmap.swap(unpremul); |
152 } | 149 } |
153 | 150 |
154 return BitmapsEqual(expected, bitmap); | 151 return BitmapsEqual(expected, bitmap); |
155 } | 152 } |
156 | 153 |
157 } // namespace DM | 154 } // namespace DM |
OLD | NEW |