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

Side by Side Diff: samplecode/SampleUnpremul.cpp

Issue 510423005: make allocPixels throw on failure (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 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 | « samplecode/SampleFilterFuzz.cpp ('k') | src/core/SkBitmap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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);
OLDNEW
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | src/core/SkBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698