本文整理汇总了C++中NativeImageSkia::isDataComplete方法的典型用法代码示例。如果您正苦于以下问题:C++ NativeImageSkia::isDataComplete方法的具体用法?C++ NativeImageSkia::isDataComplete怎么用?C++ NativeImageSkia::isDataComplete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NativeImageSkia
的用法示例。
在下文中一共展示了NativeImageSkia::isDataComplete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadBufferingImageData
static void loadBufferingImageData()
{
static bool loaded = false;
if (!loaded) {
static Image* bufferingIcon = Image::loadPlatformResource("vidbuffer").leakRef();
NativeImageSkia* nativeImage = bufferingIcon->nativeImageForCurrentFrame();
if (!nativeImage)
return;
if (!nativeImage->isDataComplete())
return;
loaded = true;
nativeImage->bitmap().lockPixels();
int bufSize = nativeImage->bitmap().width() * nativeImage->bitmap().height() * 4;
s_bufferingImageWidth = nativeImage->bitmap().width();
s_bufferingImageHeight = nativeImage->bitmap().height();
s_bufferingImageData = static_cast<char*>(malloc(bufSize));
memcpy(s_bufferingImageData, nativeImage->bitmap().getPixels(), bufSize);
nativeImage->bitmap().unlockPixels();
bufferingIcon->deref();
}
}
示例2: computeResamplingMode
static ResamplingMode computeResamplingMode(const SkMatrix& matrix, const NativeImageSkia& bitmap, float srcWidth, float srcHeight, float destWidth, float destHeight)
{
// The percent change below which we will not resample. This usually means
// an off-by-one error on the web page, and just doing nearest neighbor
// sampling is usually good enough.
const float kFractionalChangeThreshold = 0.025f;
// Images smaller than this in either direction are considered "small" and
// are not resampled ever (see below).
const int kSmallImageSizeThreshold = 8;
// The amount an image can be stretched in a single direction before we
// say that it is being stretched so much that it must be a line or
// background that doesn't need resampling.
const float kLargeStretch = 3.0f;
// Figure out if we should resample this image. We try to prune out some
// common cases where resampling won't give us anything, since it is much
// slower than drawing stretched.
float diffWidth = fabs(destWidth - srcWidth);
float diffHeight = fabs(destHeight - srcHeight);
bool widthNearlyEqual = diffWidth < std::numeric_limits<float>::epsilon();
bool heightNearlyEqual = diffHeight < std::numeric_limits<float>::epsilon();
// We don't need to resample if the source and destination are the same.
if (widthNearlyEqual && heightNearlyEqual)
return RESAMPLE_NONE;
if (srcWidth <= kSmallImageSizeThreshold
|| srcHeight <= kSmallImageSizeThreshold
|| destWidth <= kSmallImageSizeThreshold
|| destHeight <= kSmallImageSizeThreshold) {
// Never resample small images. These are often used for borders and
// rules (think 1x1 images used to make lines).
return RESAMPLE_NONE;
}
if (srcHeight * kLargeStretch <= destHeight || srcWidth * kLargeStretch <= destWidth) {
// Large image detected.
// Don't resample if it is being stretched a lot in only one direction.
// This is trying to catch cases where somebody has created a border
// (which might be large) and then is stretching it to fill some part
// of the page.
if (widthNearlyEqual || heightNearlyEqual)
return RESAMPLE_NONE;
// The image is growing a lot and in more than one direction. Resampling
// is slow and doesn't give us very much when growing a lot.
return RESAMPLE_LINEAR;
}
if ((diffWidth / srcWidth < kFractionalChangeThreshold)
&& (diffHeight / srcHeight < kFractionalChangeThreshold)) {
// It is disappointingly common on the web for image sizes to be off by
// one or two pixels. We don't bother resampling if the size difference
// is a small fraction of the original size.
return RESAMPLE_NONE;
}
// When the image is not yet done loading, use linear. We don't cache the
// partially resampled images, and as they come in incrementally, it causes
// us to have to resample the whole thing every time.
if (!bitmap.isDataComplete())
return RESAMPLE_LINEAR;
// Everything else gets resampled.
// High quality interpolation only enabled for scaling and translation.
if (!(matrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)))
return RESAMPLE_AWESOME;
return RESAMPLE_LINEAR;
}
示例3: computeResamplingMode
static ResamplingMode computeResamplingMode(PlatformContextSkia* platformContext, const NativeImageSkia& bitmap, int srcWidth, int srcHeight, float destWidth, float destHeight)
{
if (platformContext->hasImageResamplingHint()) {
IntSize srcSize;
FloatSize dstSize;
platformContext->getImageResamplingHint(&srcSize, &dstSize);
srcWidth = srcSize.width();
srcHeight = srcSize.height();
destWidth = dstSize.width();
destHeight = dstSize.height();
}
int destIWidth = static_cast<int>(destWidth);
int destIHeight = static_cast<int>(destHeight);
// The percent change below which we will not resample. This usually means
// an off-by-one error on the web page, and just doing nearest neighbor
// sampling is usually good enough.
const float kFractionalChangeThreshold = 0.025f;
// Images smaller than this in either direction are considered "small" and
// are not resampled ever (see below).
const int kSmallImageSizeThreshold = 8;
// The amount an image can be stretched in a single direction before we
// say that it is being stretched so much that it must be a line or
// background that doesn't need resampling.
const float kLargeStretch = 3.0f;
// Figure out if we should resample this image. We try to prune out some
// common cases where resampling won't give us anything, since it is much
// slower than drawing stretched.
if (srcWidth == destIWidth && srcHeight == destIHeight) {
// We don't need to resample if the source and destination are the same.
return RESAMPLE_NONE;
}
if (srcWidth <= kSmallImageSizeThreshold
|| srcHeight <= kSmallImageSizeThreshold
|| destWidth <= kSmallImageSizeThreshold
|| destHeight <= kSmallImageSizeThreshold) {
// Never resample small images. These are often used for borders and
// rules (think 1x1 images used to make lines).
return RESAMPLE_NONE;
}
if (srcHeight * kLargeStretch <= destHeight || srcWidth * kLargeStretch <= destWidth) {
// Large image detected.
// Don't resample if it is being stretched a lot in only one direction.
// This is trying to catch cases where somebody has created a border
// (which might be large) and then is stretching it to fill some part
// of the page.
if (srcWidth == destWidth || srcHeight == destHeight)
return RESAMPLE_NONE;
// The image is growing a lot and in more than one direction. Resampling
// is slow and doesn't give us very much when growing a lot.
return RESAMPLE_LINEAR;
}
if ((fabs(destWidth - srcWidth) / srcWidth < kFractionalChangeThreshold)
&& (fabs(destHeight - srcHeight) / srcHeight < kFractionalChangeThreshold)) {
// It is disappointingly common on the web for image sizes to be off by
// one or two pixels. We don't bother resampling if the size difference
// is a small fraction of the original size.
return RESAMPLE_NONE;
}
// When the image is not yet done loading, use linear. We don't cache the
// partially resampled images, and as they come in incrementally, it causes
// us to have to resample the whole thing every time.
if (!bitmap.isDataComplete())
return RESAMPLE_LINEAR;
// Everything else gets resampled.
// If the platform context permits high quality interpolation, use it.
// High quality interpolation only enabled for scaling and translation.
if (platformContext->interpolationQuality() == InterpolationHigh
&& !(platformContext->canvas()->getTotalMatrix().getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)))
return RESAMPLE_AWESOME;
return RESAMPLE_LINEAR;
}