| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "gm.h" | 7 #include "gm.h" |
| 8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkBlurDrawLooper.h" | 9 #include "SkBlurDrawLooper.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 __SK_FORCE_IMAGE_DECODER_LINKING; | 22 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 23 | 23 |
| 24 // Defined in SampleColorFilter.cpp | 24 // Defined in SampleColorFilter.cpp |
| 25 extern SkShader* createChecker(); | 25 extern SkShader* createChecker(); |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Interprets c as an unpremultiplied color, and returns the | 28 * Interprets c as an unpremultiplied color, and returns the |
| 29 * premultiplied equivalent. | 29 * premultiplied equivalent. |
| 30 */ | 30 */ |
| 31 SkPMColor SkPreMultiplyUnPMColor(SkPMColor c) { | 31 static SkPMColor premultiply_unpmcolor(SkPMColor c) { |
| 32 U8CPU a = SkGetPackedA32(c); | 32 U8CPU a = SkGetPackedA32(c); |
| 33 U8CPU r = SkGetPackedR32(c); | 33 U8CPU r = SkGetPackedR32(c); |
| 34 U8CPU g = SkGetPackedG32(c); | 34 U8CPU g = SkGetPackedG32(c); |
| 35 U8CPU b = SkGetPackedB32(c); | 35 U8CPU b = SkGetPackedB32(c); |
| 36 return SkPreMultiplyARGB(a, r, g, b); | 36 return SkPreMultiplyARGB(a, r, g, b); |
| 37 } | 37 } |
| 38 | 38 |
| 39 class UnpremulView : public SampleView { | 39 class UnpremulView : public SampleView { |
| 40 public: | 40 public: |
| 41 UnpremulView(SkString res) | 41 UnpremulView(SkString res) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 bm.setConfig(SkBitmap::kARGB_8888_Config, fBitmap.width(), | 125 bm.setConfig(SkBitmap::kARGB_8888_Config, fBitmap.width(), |
| 126 fBitmap.height()); | 126 fBitmap.height()); |
| 127 SkASSERT(fBitmap.config() == SkBitmap::kARGB_8888_Config); | 127 SkASSERT(fBitmap.config() == SkBitmap::kARGB_8888_Config); |
| 128 if (!bm.allocPixels()) { | 128 if (!bm.allocPixels()) { |
| 129 SkString errMsg("allocPixels failed"); | 129 SkString errMsg("allocPixels failed"); |
| 130 canvas->drawText(errMsg.c_str(), errMsg.size(), 0, height, paint
); | 130 canvas->drawText(errMsg.c_str(), errMsg.size(), 0, height, paint
); |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 for (int i = 0; i < fBitmap.width(); ++i) { | 133 for (int i = 0; i < fBitmap.width(); ++i) { |
| 134 for (int j = 0; j < fBitmap.height(); ++j) { | 134 for (int j = 0; j < fBitmap.height(); ++j) { |
| 135 *bm.getAddr32(i, j) = SkPreMultiplyUnPMColor(*fBitmap.getAdd
r32(i, j)); | 135 *bm.getAddr32(i, j) = premultiply_unpmcolor(*fBitmap.getAddr
32(i, j)); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 canvas->drawBitmap(bm, 0, 0); | 138 canvas->drawBitmap(bm, 0, 0); |
| 139 } else { | 139 } else { |
| 140 canvas->drawBitmap(fBitmap, 0, 0); | 140 canvas->drawBitmap(fBitmap, 0, 0); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 const SkString fResPath; | 145 const SkString fResPath; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 typedef SampleView INHERITED; | 196 typedef SampleView INHERITED; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 ////////////////////////////////////////////////////////////////////////////// | 199 ////////////////////////////////////////////////////////////////////////////// |
| 200 | 200 |
| 201 static SkView* MyFactory() { | 201 static SkView* MyFactory() { |
| 202 return new UnpremulView(skiagm::GM::GetResourcePath()); | 202 return new UnpremulView(skiagm::GM::GetResourcePath()); |
| 203 } | 203 } |
| 204 static SkViewRegister reg(MyFactory); | 204 static SkViewRegister reg(MyFactory); |
| OLD | NEW |