/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBitmapProcState.h"
#include "SkColorPriv.h"
#include "SkFilterProc.h"
#include "SkPaint.h"
#include "SkShader.h" // for tilemodes
#include "SkUtilsArm.h"
#include "SkBitmapScaler.h"
#include "SkMipMap.h"
#include "SkPixelRef.h"
#include "SkScaledImageCache.h"
#include "SkImageEncoder.h"
#if !SK_ARM_NEON_IS_NONE
// These are defined in src/opts/SkBitmapProcState_arm_neon.cpp
extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[];
extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[];
extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, int, uint16_t*);
extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint16_t*, int);
extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint16_t*, int);
extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, int, SkPMColor*);
extern void SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint32_t*, int);
extern void Clamp_SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint32_t*, int);
#endif
#define NAME_WRAP(x) x
#include "SkBitmapProcState_filter.h"
#include "SkBitmapProcState_procs.h"
///////////////////////////////////////////////////////////////////////////////
// true iff the matrix contains, at most, scale and translate elements
static bool matrix_only_scale_translate(const SkMatrix& m) {
return m.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask);
}
/**
* For the purposes of drawing bitmaps, if a matrix is "almost" translate
* go ahead and treat it as if it were, so that subsequent code can go fast.
*/
static bool just_trans_clamp(const SkMatrix& matrix, const SkBitmap& bitmap) {
SkASSERT(matrix_only_scale_translate(matrix));
if (matrix.getType() & SkMatrix::kScale_Mask) {
SkRect src, dst;
bitmap.getBounds(&src);
// Can't call mapRect(), since that will fix up inverted rectangles,
// e.g. when scale is negative, and we don't want to return true for
// those.
matrix.mapPoints(SkTCast<SkPoint*>(&dst),
SkTCast<const SkPoint*>(&src),
2);
// Now round all 4 edges to device space, and then compare the device
// width/height to the original. Note: we must map all 4 and subtract
// rather than map the "width" and compare, since we care about the
// phase (in pixel space) that any translate in the matrix might impart.
SkIRect idst;
dst.round(&idst);
return idst.width() == bitmap.width() && idst.height() == bitmap.height();
}
// if we got here, we're either kTranslate_Mask or identity
return true;
}
static bool just_trans_general(const SkMatrix& matrix) {
SkASSERT(matrix_only_scale_translate(matrix));
if (matrix.getType() & SkMatrix::kScale_Mask) {
const SkScalar tol = SK_Scalar1 / 32768;
if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleX] - SK_Scalar1, tol)) {
return false;
}
if (!SkScalarNearlyZero(matrix[SkMatrix::kMScaleY] - SK_Scalar1, tol)) {
return false;
}
}
// if we got here, treat us as either kTranslate_Mask or identity
return true;
}
///////////////////////////////////////////////////////////////////////////////
static bool valid_for_filtering(unsigned dimension) {
// for filtering, width and height must fit in 14bits, since we use steal
// 2 bits from each to store our 4bit subpixel data
return (dimension & ~0x3FFF) == 0;
}
static SkScalar effective_matrix_scale_sqrd(const SkMatrix& mat) {
SkPoint v1, v2;
v1.fX = mat.getScaleX();
v1.fY = mat.getSkewY();
v2.fX = mat.getSkewX();
v2.fY = mat.getScaleY();
return SkMaxScalar(v1.lengthSqd(), v2.lengthSqd());
}
class AutoScaledCacheUnlocker {
public:
AutoScaledCacheUnlocker(SkScaledImageCache::ID** idPtr) : fIDPtr(idPtr) {}
~AutoScaledCacheUnlocker() {
if (fIDPtr && *fIDPtr) {
SkScaledImageCache::Unlock(*fIDPtr);
*fIDPtr = NULL;
}
}
// forgets the ID, so it won't call Unlock
void release() {
fIDPtr = NULL;
}
private:
SkScaledImageCache::ID** fIDPtr;
};
#define AutoScaledCacheUnlocker(...) SK_REQUIRE_LOCAL_VAR(AutoScaledCacheUnlocker)
// Check to see that the size of the bitmap that would be produced by
// scaling by the given inverted matrix is less than the maximum allowed.
static inline bool cache_size_okay(const SkBitmap& bm, const SkMatrix& invMat) {
size_t maximumAllocation
= SkScaledImageCache::GetSingleAllocationByteLimit();
if (0 == maximumAllocation) {
return true;
}
// float matrixScaleFactor = 1.0 / (invMat.scaleX * invMat.scaleY);
// return ((origBitmapSize * matrixScaleFactor) < maximumAllocationSize);
// Skip the division step:
return bm.info().getSafeSize(bm.info().minRowBytes())
< (maximumAllocation * invMat.getScaleX() * invMat.getScaleY());
}
// TODO -- we may want to pass the clip into this function so we only scale
// the portion of the image that we're going to need. This will complicate
// the interface to the cache, but might be well worth it.
bool SkBitmapProcState::possiblyScaleImage() {
AutoScaledCacheUnlocker unlocker(&fScaledCacheID);
SkASSERT(NULL == fBitmap);
SkASSERT(NULL == fScaledCacheID);
if (fFilterLevel <= SkPaint::kLow_FilterLevel) {
return false;
}
// Check to see if the transformation matrix is simple, and if we're
// doing high quality scaling. If so, do the bitmap scale here and
// remove the scaling component from the matrix.
if (SkPaint::kHigh_FilterLevel == fFilterLevel &&
fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask) &&
kN32_SkColorType == fOrigBitmap.colorType() &&
cache_size_okay(fOrigBitmap, fInvMatrix)) {
SkScalar invScaleX = fInvMatrix.getScaleX();
SkScalar invScaleY = fInvMatrix.getScaleY();
fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap,
invScaleX, invScaleY,
&fScaledBitmap);
if (fScaledCacheID) {
fScaledBitmap.lockPixels();
if (!fScaledBitmap.getPixels()) {
fScaledBitmap.unlockPixels();
// found a purged entry (discardablememory?), release it
SkScaledImageCache::Unlock(fScaledCacheID);
fScaledCacheID = NULL;
// fall through to rebuild
}
}
if (NULL == fScaledCacheID) {
float dest_width = fOrigBitmap.width() / invScaleX;
float dest_height = fOrigBitmap.height() / invScaleY;
// All the criteria are met; let's make a new bitmap.
SkConvolutionProcs simd;
sk_bzero(&simd, sizeof(simd));
this->platformConvolutionProcs(&simd);
if (!SkBitmapScaler::Resize(&fScaledBitmap,
fOrigBitmap,
SkBitmapScaler::RESIZE_BEST,
dest_width,
dest_height,
simd,
SkScaledImageCache::GetAllocator())) {
// we failed to create fScaledBitmap, so just return and let
// the scanline proc handle it.
return false;
}
SkASSERT(NULL != fScaledBitmap.getPixels());
fScaledCacheID = SkScaledImageCache::AddAn
SkBitmapProcState.rar_Go_ Go_ Go!
版权申诉
26 浏览量
2022-09-23
01:02:33
上传
评论
收藏 11KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/3542a6830a364bf6a0adb34bfd72ce9d_weixin_42662605.jpg!1)
APei
- 粉丝: 65
- 资源: 1万+
最新资源
- 使用ASP.NET Core和Entity Framework Core来构建一个基本的进销存系统.rar
- 深度学习经典数据集+FER2013面部表情识别+附带使用方法的python代码
- Python中,要实现连接多个相机并识别多个二维码.rar
- 使用FFT算法对一个信号进行分析.rar
- 171cms游戏应用下载系统源码.zip
- 基于jsp+servlet+mysql蛋糕甜品店购物网站源码+数据库(期末大作业).zip
- Java项目:在线蛋糕商城系统(java+jsp+mysql)源码+数据库+期末大作业.zip
- ZapyaClient10_7-1.apk
- 织梦cms站长导航网站源码.zip
- 基于SSM+MySQL的网络投票调查问卷系统源码+数据库(java期末大作业).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)