本文整理汇总了C++中SkMatrix::getMinMaxScales方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::getMinMaxScales方法的具体用法?C++ SkMatrix::getMinMaxScales怎么用?C++ SkMatrix::getMinMaxScales使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::getMinMaxScales方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ShouldUseBicubic
bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix,
GrTextureParams::FilterMode* filterMode) {
if (matrix.isIdentity()) {
*filterMode = GrTextureParams::kNone_FilterMode;
return false;
}
SkScalar scales[2];
if (!matrix.getMinMaxScales(scales) || scales[0] < SK_Scalar1) {
// Bicubic doesn't handle arbitrary minimization well, as src texels can be skipped
// entirely,
*filterMode = GrTextureParams::kMipMap_FilterMode;
return false;
}
// At this point if scales[1] == SK_Scalar1 then the matrix doesn't do any scaling.
if (scales[1] == SK_Scalar1) {
if (matrix.rectStaysRect() && SkScalarIsInt(matrix.getTranslateX()) &&
SkScalarIsInt(matrix.getTranslateY())) {
*filterMode = GrTextureParams::kNone_FilterMode;
} else {
// Use bilerp to handle rotation or fractional translation.
*filterMode = GrTextureParams::kBilerp_FilterMode;
}
return false;
}
// When we use the bicubic filtering effect each sample is read from the texture using
// nearest neighbor sampling.
*filterMode = GrTextureParams::kNone_FilterMode;
return true;
}
示例2: draw
void draw(SkCanvas* canvas) {
SkMatrix matrix;
matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 0);
if (matrix.invert(&matrix)) {
SkScalar factor[2] = {2, 2};
bool result = matrix.getMinMaxScales(factor);
SkDebugf("matrix.getMinMaxScales() %s %g %g\n",
result ? "true" : "false", factor[0], factor[1]);
}
}
示例3: test_matrix_min_max_scale
static void test_matrix_min_max_scale(skiatest::Reporter* reporter) {
SkScalar scales[2];
bool success;
SkMatrix identity;
identity.reset();
REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 == identity.getMaxScale());
success = identity.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]);
SkMatrix scale;
scale.setScale(SK_Scalar1 * 2, SK_Scalar1 * 4);
REPORTER_ASSERT(reporter, SK_Scalar1 * 2 == scale.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 * 4 == scale.getMaxScale());
success = scale.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success && SK_Scalar1 * 2 == scales[0] && SK_Scalar1 * 4 == scales[1]);
SkMatrix rot90Scale;
rot90Scale.setRotate(90 * SK_Scalar1);
rot90Scale.postScale(SK_Scalar1 / 4, SK_Scalar1 / 2);
REPORTER_ASSERT(reporter, SK_Scalar1 / 4 == rot90Scale.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 / 2 == rot90Scale.getMaxScale());
success = rot90Scale.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success && SK_Scalar1 / 4 == scales[0] && SK_Scalar1 / 2 == scales[1]);
SkMatrix rotate;
rotate.setRotate(128 * SK_Scalar1);
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMinScale(), SK_ScalarNearlyZero));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, rotate.getMaxScale(), SK_ScalarNearlyZero));
success = rotate.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success);
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[0], SK_ScalarNearlyZero));
REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SK_Scalar1, scales[1], SK_ScalarNearlyZero));
SkMatrix translate;
translate.setTranslate(10 * SK_Scalar1, -5 * SK_Scalar1);
REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMinScale());
REPORTER_ASSERT(reporter, SK_Scalar1 == translate.getMaxScale());
success = translate.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success && SK_Scalar1 == scales[0] && SK_Scalar1 == scales[1]);
SkMatrix perspX;
perspX.reset();
perspX.setPerspX(SkScalarToPersp(SK_Scalar1 / 1000));
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMinScale());
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspX.getMaxScale());
// Verify that getMinMaxScales() doesn't update the scales array on failure.
scales[0] = -5;
scales[1] = -5;
success = perspX.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * SK_Scalar1 == scales[1]);
SkMatrix perspY;
perspY.reset();
perspY.setPerspY(SkScalarToPersp(-SK_Scalar1 / 500));
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMinScale());
REPORTER_ASSERT(reporter, -SK_Scalar1 == perspY.getMaxScale());
scales[0] = -5;
scales[1] = -5;
success = perspY.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, !success && -5 * SK_Scalar1 == scales[0] && -5 * SK_Scalar1 == scales[1]);
SkMatrix baseMats[] = {scale, rot90Scale, rotate,
translate, perspX, perspY};
SkMatrix mats[2*SK_ARRAY_COUNT(baseMats)];
for (size_t i = 0; i < SK_ARRAY_COUNT(baseMats); ++i) {
mats[i] = baseMats[i];
bool invertable = mats[i].invert(&mats[i + SK_ARRAY_COUNT(baseMats)]);
REPORTER_ASSERT(reporter, invertable);
}
SkRandom rand;
for (int m = 0; m < 1000; ++m) {
SkMatrix mat;
mat.reset();
for (int i = 0; i < 4; ++i) {
int x = rand.nextU() % SK_ARRAY_COUNT(mats);
mat.postConcat(mats[x]);
}
SkScalar minScale = mat.getMinScale();
SkScalar maxScale = mat.getMaxScale();
REPORTER_ASSERT(reporter, (minScale < 0) == (maxScale < 0));
REPORTER_ASSERT(reporter, (maxScale < 0) == mat.hasPerspective());
SkScalar scales[2];
bool success = mat.getMinMaxScales(scales);
REPORTER_ASSERT(reporter, success == !mat.hasPerspective());
REPORTER_ASSERT(reporter, !success || (scales[0] == minScale && scales[1] == maxScale));
if (mat.hasPerspective()) {
m -= 1; // try another non-persp matrix
continue;
}
// test a bunch of vectors. All should be scaled by between minScale and maxScale
// (modulo some error) and we should find a vector that is scaled by almost each.
static const SkScalar gVectorScaleTol = (105 * SK_Scalar1) / 100;
static const SkScalar gCloseScaleTol = (97 * SK_Scalar1) / 100;
SkScalar max = 0, min = SK_ScalarMax;
//.........这里部分代码省略.........