SkBitmap::pixmap

Change-Id: I6d062b9ae1d242970be140d5a1885639c8c45f77
Reviewed-on: https://skia-review.googlesource.com/85320
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Yuqian Li <liyuqian@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
Hal Canary 2017-12-14 15:33:23 -05:00 committed by Skia Commit-Bot
parent f6e6be2da1
commit a088365e2f
3 changed files with 18 additions and 12 deletions

View File

@ -211,10 +211,9 @@ static void make_color_test_bitmap_variant(
SkASSERT(alphaType == kPremul_SkAlphaType || alphaType == kUnpremul_SkAlphaType);
bm->allocPixels(
SkImageInfo::Make(SCALE, SCALE, colorType, alphaType, colorSpace));
SkPixmap pm;
bm->peekPixels(&pm);
for (int y = 0; y < bm->height(); y++) {
for (int x = 0; x < bm->width(); x++) {
SkPixmap pm = bm->pixmap();
for (int y = 0; y < pm.height(); y++) {
for (int x = 0; x < pm.width(); x++) {
*pm.writable_addr32(x, y) = make_pixel(x, y, alphaType);
}
}

View File

@ -99,6 +99,17 @@ public:
*/
void swap(SkBitmap& other);
/** Returns a SkPixmap with the SkBitmap pixel address, row bytes, and
SkImageInfo to pixmap, if address is available. If pixel address
is not available, return an empty SkPixmap.
The SkPixmap contents become invalid on any future change to SkBitmap.
@return new SkPixmap describing this SkBitmap.
*/
SkPixmap pixmap() const { return fPixels ? SkPixmap(fInfo, fPixels, fRowBytes) : SkPixmap(); }
/** Returns width, height, SkAlphaType, SkColorType, and SkColorSpace.
@return reference to SkImageInfo
@ -337,8 +348,7 @@ public:
@return true if all pixels have opaque values or SkColorType is opaque
*/
static bool ComputeIsOpaque(const SkBitmap& bm) {
SkPixmap pmap;
return bm.peekPixels(&pmap) && pmap.computeIsOpaque();
return bm.pixmap().computeIsOpaque();
}
/** Returns SkRect { 0, 0, width(), height() }.
@ -840,9 +850,7 @@ public:
@return pixel converted to unpremultiplied color
*/
SkColor getColor(int x, int y) const {
SkPixmap pixmap;
SkAssertResult(this->peekPixels(&pixmap));
return pixmap.getColor(x, y);
return this->pixmap().getColor(x, y);
}
/** Returns pixel address at (x, y).

View File

@ -430,9 +430,8 @@ sk_sp<SkPDFObject> SkPDFCreateBitmapObject(sk_sp<SkImage> image,
#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
if (pixelSerializer) {
SkBitmap bm;
SkPixmap pmap;
if (SkPDFUtils::ToBitmap(image.get(), &bm) && bm.peekPixels(&pmap)) {
data = pixelSerializer->encodeToData(pmap);
if (SkPDFUtils::ToBitmap(image.get(), &bm)) {
data = pixelSerializer->encodeToData(bm.pixmap());
if (data && SkIsJFIF(data.get(), &info)) {
bool yuv = info.fType == SkJFIFInfo::kYCbCr;
if (info.fSize == image->dimensions()) { // Sanity check.