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 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 canvas->drawText(header.c_str(), header.size(), 0, height, paint); | 121 canvas->drawText(header.c_str(), header.size(), 0, height, paint); |
122 | 122 |
123 // Now draw the image itself. | 123 // Now draw the image itself. |
124 canvas->translate(height * 2, height * 2); | 124 canvas->translate(height * 2, height * 2); |
125 if (!fPremul) { | 125 if (!fPremul) { |
126 // A premultiplied bitmap cannot currently be drawn. | 126 // A premultiplied bitmap cannot currently be drawn. |
127 SkAutoLockPixels alp(fBitmap); | 127 SkAutoLockPixels alp(fBitmap); |
128 // Copy it to a bitmap which can be drawn, converting | 128 // Copy it to a bitmap which can be drawn, converting |
129 // to premultiplied: | 129 // to premultiplied: |
130 SkBitmap bm; | 130 SkBitmap bm; |
131 if (!bm.allocN32Pixels(fBitmap.width(), fBitmap.height())) { | 131 bm.allocN32Pixels(fBitmap.width(), fBitmap.height()); |
132 SkString errMsg("allocPixels failed"); | |
133 canvas->drawText(errMsg.c_str(), errMsg.size(), 0, height, paint
); | |
134 return; | |
135 } | |
136 for (int i = 0; i < fBitmap.width(); ++i) { | 132 for (int i = 0; i < fBitmap.width(); ++i) { |
137 for (int j = 0; j < fBitmap.height(); ++j) { | 133 for (int j = 0; j < fBitmap.height(); ++j) { |
138 *bm.getAddr32(i, j) = premultiply_unpmcolor(*fBitmap.getAddr
32(i, j)); | 134 *bm.getAddr32(i, j) = premultiply_unpmcolor(*fBitmap.getAddr
32(i, j)); |
139 } | 135 } |
140 } | 136 } |
141 canvas->drawBitmap(bm, 0, 0); | 137 canvas->drawBitmap(bm, 0, 0); |
142 } else { | 138 } else { |
143 canvas->drawBitmap(fBitmap, 0, 0); | 139 canvas->drawBitmap(fBitmap, 0, 0); |
144 } | 140 } |
145 } | 141 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 193 |
198 typedef SampleView INHERITED; | 194 typedef SampleView INHERITED; |
199 }; | 195 }; |
200 | 196 |
201 ////////////////////////////////////////////////////////////////////////////// | 197 ////////////////////////////////////////////////////////////////////////////// |
202 | 198 |
203 static SkView* MyFactory() { | 199 static SkView* MyFactory() { |
204 return new UnpremulView(GetResourcePath()); | 200 return new UnpremulView(GetResourcePath()); |
205 } | 201 } |
206 static SkViewRegister reg(MyFactory); | 202 static SkViewRegister reg(MyFactory); |
OLD | NEW |