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

Side by Side Diff: dm/DMWriteTask.cpp

Issue 139943002: DM: don't change byte order when unpremultiplying to compare to PNGs. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: reorder headers Created 6 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "DMWriteTask.h" 1 #include "DMWriteTask.h"
2 2
3 #include "DMUtil.h" 3 #include "DMUtil.h"
4 #include "SkColorPriv.h"
4 #include "SkCommandLineFlags.h" 5 #include "SkCommandLineFlags.h"
5 #include "SkImageDecoder.h" 6 #include "SkImageDecoder.h"
6 #include "SkImageEncoder.h" 7 #include "SkImageEncoder.h"
7 #include "SkString.h" 8 #include "SkString.h"
8 #include "SkUnPreMultiply.h" 9 #include "SkUnPreMultiply.h"
9 10
10 DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs."); 11 DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs.");
11 12
12 namespace DM { 13 namespace DM {
13 14
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 130 }
130 SkASSERT(expected.config() == bitmap.config()); 131 SkASSERT(expected.config() == bitmap.config());
131 132
132 // Manually unpremultiply 8888 bitmaps to match expected. 133 // Manually unpremultiply 8888 bitmaps to match expected.
133 // Their pixels are shared, concurrently even, so we must copy them. 134 // Their pixels are shared, concurrently even, so we must copy them.
134 if (info.fColorType == kPMColor_SkColorType) { 135 if (info.fColorType == kPMColor_SkColorType) {
135 SkBitmap unpremul; 136 SkBitmap unpremul;
136 unpremul.setConfig(info); 137 unpremul.setConfig(info);
137 unpremul.allocPixels(); 138 unpremul.allocPixels();
138 139
140 // Unpremultiply without changing native byte order.
139 SkAutoLockPixels lockSrc(bitmap), lockDst(unpremul); 141 SkAutoLockPixels lockSrc(bitmap), lockDst(unpremul);
140 const SkPMColor* src = (SkPMColor*)bitmap.getPixels(); 142 const SkPMColor* src = (SkPMColor*)bitmap.getPixels();
141 SkColor* dst = (SkColor*)unpremul.getPixels(); 143 uint32_t* dst = (uint32_t*)unpremul.getPixels();
142
143 for (size_t i = 0; i < bitmap.getSize()/4; i++) { 144 for (size_t i = 0; i < bitmap.getSize()/4; i++) {
144 dst[i] = SkUnPreMultiply::PMColorToColor(src[i]); 145 const U8CPU a = SkGetPackedA32(src[i]);
146 const SkUnPreMultiply::Scale s = SkUnPreMultiply::GetScale(a);
147 dst[i] = SkPackARGB32NoCheck(a,
148 SkUnPreMultiply::ApplyScale(s, SkGetPac kedR32(src[i])),
149 SkUnPreMultiply::ApplyScale(s, SkGetPac kedG32(src[i])),
150 SkUnPreMultiply::ApplyScale(s, SkGetPac kedB32(src[i])));
145 } 151 }
146 bitmap.swap(unpremul); 152 bitmap.swap(unpremul);
147 } 153 }
148 154
149 return BitmapsEqual(expected, bitmap); 155 return BitmapsEqual(expected, bitmap);
150 } 156 }
151 157
152 } // namespace DM 158 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698