| OLD | NEW |
| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if (NULL == page) { | 202 if (NULL == page) { |
| 203 return false; | 203 return false; |
| 204 } | 204 } |
| 205 | 205 |
| 206 CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); | 206 CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox); |
| 207 | 207 |
| 208 int w = (int)CGRectGetWidth(bounds); | 208 int w = (int)CGRectGetWidth(bounds); |
| 209 int h = (int)CGRectGetHeight(bounds); | 209 int h = (int)CGRectGetHeight(bounds); |
| 210 | 210 |
| 211 SkBitmap bitmap; | 211 SkBitmap bitmap; |
| 212 bitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); | 212 if (!bitmap.allocPixels(SkImageInfo::MakeN32Premul(w, h))) { |
| 213 bitmap.allocPixels(); | 213 return false; |
| 214 } |
| 214 bitmap.eraseColor(SK_ColorWHITE); | 215 bitmap.eraseColor(SK_ColorWHITE); |
| 215 | 216 |
| 216 size_t bitsPerComponent; | 217 size_t bitsPerComponent; |
| 217 CGBitmapInfo info; | 218 CGBitmapInfo info; |
| 218 getBitmapInfo(bitmap, &bitsPerComponent, &info, NULL); | 219 getBitmapInfo(bitmap, &bitsPerComponent, &info, NULL); |
| 219 | 220 |
| 220 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); | 221 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); |
| 221 CGContextRef ctx = CGBitmapContextCreate(bitmap.getPixels(), w, h, | 222 CGContextRef ctx = CGBitmapContextCreate(bitmap.getPixels(), w, h, |
| 222 bitsPerComponent, bitmap.rowBytes()
, | 223 bitsPerComponent, bitmap.rowBytes()
, |
| 223 cs, info); | 224 cs, info); |
| 224 CGColorSpaceRelease(cs); | 225 CGColorSpaceRelease(cs); |
| 225 | 226 |
| 226 if (ctx) { | 227 if (ctx) { |
| 227 CGContextDrawPDFPage(ctx, page); | 228 CGContextDrawPDFPage(ctx, page); |
| 228 CGContextRelease(ctx); | 229 CGContextRelease(ctx); |
| 229 } | 230 } |
| 230 | 231 |
| 231 output->swap(bitmap); | 232 output->swap(bitmap); |
| 232 return true; | 233 return true; |
| 233 } | 234 } |
| OLD | NEW |