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

Side by Side Diff: src/utils/mac/SkCreateCGImageRef.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 | « src/utils/SkPDFRasterizer.cpp ('k') | tests/ARGBImageEncoderTest.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkCGUtils.h" 8 #include "SkCGUtils.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 if (NULL == page) { 214 if (NULL == page) {
215 return false; 215 return false;
216 } 216 }
217 217
218 CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); 218 CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
219 219
220 int w = (int)CGRectGetWidth(bounds); 220 int w = (int)CGRectGetWidth(bounds);
221 int h = (int)CGRectGetHeight(bounds); 221 int h = (int)CGRectGetHeight(bounds);
222 222
223 SkBitmap bitmap; 223 SkBitmap bitmap;
224 if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) { 224 if (!bitmap.tryAllocN32Pixels(w, h)) {
225 return false; 225 return false;
226 } 226 }
227 bitmap.eraseColor(SK_ColorWHITE); 227 bitmap.eraseColor(SK_ColorWHITE);
228 228
229 size_t bitsPerComponent; 229 size_t bitsPerComponent;
230 CGBitmapInfo info; 230 CGBitmapInfo info;
231 getBitmapInfo(bitmap, &bitsPerComponent, &info, NULL); 231 getBitmapInfo(bitmap, &bitsPerComponent, &info, NULL);
232 232
233 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); 233 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
234 CGContextRef ctx = CGBitmapContextCreate(bitmap.getPixels(), w, h, 234 CGContextRef ctx = CGBitmapContextCreate(bitmap.getPixels(), w, h,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 CGContextRelease(cg); 280 CGContextRelease(cg);
281 return true; 281 return true;
282 } 282 }
283 283
284 bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef image, SkISize* scaleTo Fit) { 284 bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef image, SkISize* scaleTo Fit) {
285 const int width = scaleToFit ? scaleToFit->width() : SkToInt(CGImageGetWidth (image)); 285 const int width = scaleToFit ? scaleToFit->width() : SkToInt(CGImageGetWidth (image));
286 const int height = scaleToFit ? scaleToFit->height() : SkToInt(CGImageGetHei ght(image)); 286 const int height = scaleToFit ? scaleToFit->height() : SkToInt(CGImageGetHei ght(image));
287 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 287 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
288 288
289 SkBitmap tmp; 289 SkBitmap tmp;
290 if (!tmp.allocPixels(info)) { 290 if (!tmp.tryAllocPixels(info)) {
291 return false; 291 return false;
292 } 292 }
293 293
294 if (!SkCopyPixelsFromCGImage(tmp.info(), tmp.rowBytes(), tmp.getPixels(), im age)) { 294 if (!SkCopyPixelsFromCGImage(tmp.info(), tmp.rowBytes(), tmp.getPixels(), im age)) {
295 return false; 295 return false;
296 } 296 }
297 297
298 CGImageAlphaInfo cgInfo = CGImageGetAlphaInfo(image); 298 CGImageAlphaInfo cgInfo = CGImageGetAlphaInfo(image);
299 switch (cgInfo) { 299 switch (cgInfo) {
300 case kCGImageAlphaNone: 300 case kCGImageAlphaNone:
301 case kCGImageAlphaNoneSkipLast: 301 case kCGImageAlphaNoneSkipLast:
302 case kCGImageAlphaNoneSkipFirst: 302 case kCGImageAlphaNoneSkipFirst:
303 SkASSERT(SkBitmap::ComputeIsOpaque(tmp)); 303 SkASSERT(SkBitmap::ComputeIsOpaque(tmp));
304 tmp.setAlphaType(kOpaque_SkAlphaType); 304 tmp.setAlphaType(kOpaque_SkAlphaType);
305 break; 305 break;
306 default: 306 default:
307 // we don't know if we're opaque or not, so compute it. 307 // we don't know if we're opaque or not, so compute it.
308 if (SkBitmap::ComputeIsOpaque(tmp)) { 308 if (SkBitmap::ComputeIsOpaque(tmp)) {
309 tmp.setAlphaType(kOpaque_SkAlphaType); 309 tmp.setAlphaType(kOpaque_SkAlphaType);
310 } 310 }
311 } 311 }
312 312
313 *dst = tmp; 313 *dst = tmp;
314 return true; 314 return true;
315 } 315 }
OLDNEW
« no previous file with comments | « src/utils/SkPDFRasterizer.cpp ('k') | tests/ARGBImageEncoderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698