bool SkBitmapScaler::Resize(const SkPixmap& result, const SkPixmap& source, ResizeMethod method) { if (!valid_for_resize(source, result.width(), result.height())) { return false; } if (!result.addr() || result.colorType() != source.colorType()) { return false; } SkConvolutionProcs convolveProcs= { 0, nullptr, nullptr, nullptr, nullptr }; PlatformConvolutionProcs(&convolveProcs); SkRect destSubset = SkRect::MakeIWH(result.width(), result.height()); SkResizeFilter filter(method, source.width(), source.height(), result.width(), result.height(), destSubset, convolveProcs); // Get a subset encompassing this touched area. We construct the // offsets and row strides such that it looks like a new bitmap, while // referring to the old data. const uint8_t* sourceSubset = reinterpret_cast<const uint8_t*>(source.addr()); return BGRAConvolve2D(sourceSubset, static_cast<int>(source.rowBytes()), !source.isOpaque(), filter.xFilter(), filter.yFilter(), static_cast<int>(result.rowBytes()), static_cast<unsigned char*>(result.writable_addr()), convolveProcs, true); }
bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeMethod method, int destWidth, int destHeight, SkBitmap::Allocator* allocator) { // Preflight some of the checks, to avoid allocating the result if we don't need it. if (!valid_for_resize(source, destWidth, destHeight)) { return false; } SkBitmap result; result.setInfo(SkImageInfo::MakeN32(destWidth, destHeight, source.alphaType())); result.allocPixels(allocator, nullptr); SkPixmap resultPM; if (!result.peekPixels(&resultPM) || !Resize(resultPM, source, method)) { return false; } *resultPtr = result; resultPtr->lockPixels(); SkASSERT(resultPtr->getPixels()); return true; }
bool SkBitmapScaler::Resize(SkBitmap* resultPtr, const SkPixmap& source, ResizeMethod method, int destWidth, int destHeight, SkBitmap::Allocator* allocator) { // Preflight some of the checks, to avoid allocating the result if we don't need it. if (!valid_for_resize(source, destWidth, destHeight)) { return false; } SkBitmap result; // Note: pass along the profile information even thought this is no the right answer because // this could be scaling in sRGB. result.setInfo(SkImageInfo::MakeN32(destWidth, destHeight, source.alphaType(), sk_ref_sp(source.info().colorSpace()))); result.allocPixels(allocator, nullptr); SkPixmap resultPM; if (!result.peekPixels(&resultPM) || !Resize(resultPM, source, method)) { return false; } *resultPtr = result; resultPtr->lockPixels(); SkASSERT(resultPtr->getPixels()); return true; }