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

Side by Side Diff: src/utils/mac/SkCreateCGImageRef.cpp

Issue 243463005: expose CGImage -> SkBitmap (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 CGColorSpaceRelease(cs); 224 CGColorSpaceRelease(cs);
225 225
226 if (ctx) { 226 if (ctx) {
227 CGContextDrawPDFPage(ctx, page); 227 CGContextDrawPDFPage(ctx, page);
228 CGContextRelease(ctx); 228 CGContextRelease(ctx);
229 } 229 }
230 230
231 output->swap(bitmap); 231 output->swap(bitmap);
232 return true; 232 return true;
233 } 233 }
234
235 //////////////////////////////////////////////////////////////////////////////// ///////////////////
236
237 SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, vo id* pixels,
238 CGImageRef image) {
239 uint32_t cg_bitmap_info = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipli edLast;
240 // TODO: update cg_bitmap_info based on colortype
241 switch (info.colorType()) {
242 case kRGB_565_SkColorType:
243 break;
244 case kRGBA_8888_SkColorType:
245 break;
246 case kBGRA_8888_SkColorType:
247 break;
248 default:
249 return false; // no other colortypes are supported (afaik)
250 }
251
252 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
253 CGContextRef cg = CGBitmapContextCreate(pixels, info.width(), info.height(), 8, rowBytes, cs,
scroggo 2014/04/21 20:18:44 Isn't this 8 specific to 8888? If info.colorType()
reed1 2014/04/21 20:44:41 Yes. that is specfic, and so is the cg_bitmap_info
254 cg_bitmap_info);
255 CFRelease(cs);
256 if (NULL == cg) {
257 return false;
258 }
259
260 // use this blend mode, to avoid having to erase the pixels first, and to av oid CG performing
261 // any blending (which could introduce errors and be slower).
262 CGContextSetBlendMode(cg, kCGBlendModeCopy);
263
264 CGContextDrawImage(cg, CGRectMake(0, 0, info.width(), info.height()), image) ;
265 CGContextRelease(cg);
266 return true;
267 }
268
269 bool SkCreateBitmapFromCGImage(SkBitmap* dst, CGImageRef image, SkISize* scaleTo Fit) {
270 const int width = scaleToFit ? scaleToFit->width() : SkToInt(CGImageGetWidth (image));
271 const int height = scaleToFit ? scaleToFit->height() : SkToInt(CGImageGetHei ght(image));
272 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
273
274 SkBitmap tmp;
275 if (!tmp.allocPixels(info)) {
276 return false;
277 }
278
279 if (!SkCopyPixelsFromCGImage(tmp.info(), tmp.rowBytes(), tmp.getPixels(), im age)) {
280 return false;
281 }
282
283 CGImageAlphaInfo cgInfo = CGImageGetAlphaInfo(image);
scroggo 2014/04/21 20:18:44 I'm not a big fan of this duplicated code, if we c
reed1 2014/04/21 20:44:41 Working on it, but haven't seen how to share yet.
284 switch (cgInfo) {
285 case kCGImageAlphaNone:
286 case kCGImageAlphaNoneSkipLast:
287 case kCGImageAlphaNoneSkipFirst:
288 SkASSERT(SkBitmap::ComputeIsOpaque(tmp));
289 tmp.setAlphaType(kOpaque_SkAlphaType);
290 break;
291 default:
292 // we don't know if we're opaque or not, so compute it.
293 if (SkBitmap::ComputeIsOpaque(tmp)) {
294 tmp.setAlphaType(kOpaque_SkAlphaType);
295 }
296 }
297
298 *dst = tmp;
299 return true;
300 }
301
OLDNEW
« src/ports/SkImageDecoder_CG.cpp ('K') | « src/ports/SkImageDecoder_CG.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698