1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "SkImagePriv.h" 9 #include "SkCanvas.h" 10 #include "SkPicture.h" 11 12 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { 13 const SkImageInfo info = bm.info(); 14 if (kUnknown_SkColorType == info.colorType()) { 15 return NULL; 16 } 17 18 SkImage* image = NULL; 19 if (canSharePixelRef || bm.isImmutable()) { 20 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); 21 } else { 22 bm.lockPixels(); 23 if (bm.getPixels()) { 24 image = SkImage::NewRasterCopy(info, bm.getPixels(), bm.rowBytes()); 25 } 26 bm.unlockPixels(); 27 } 28 return image; 29 } 30