skia2/experimental/SkSetPoly3To3_D.cpp

76 lines
2.4 KiB
C++
Raw Normal View History

Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
/*
* 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 "SkMatrix.h"
#include "SkMemory.h"
// FIXME: needs to be in a header
bool SkSetPoly3To3_D(SkMatrix* matrix, const SkPoint src[3], const SkPoint dst[3]);
typedef int64_t SkDScalar;
static SkScalar SkDScalar_toScalar(SkDScalar value) {
SkDScalar result = (value + (1 << 15)) >> 16;
SkDEBUGCODE(int top = static_cast<int>(result >> 31);)
SkASSERT(top == 0 || top == -1);
return (SkScalar)result;
}
static SkDScalar SkDScalar_setMul(SkScalar a, SkScalar b) {
return (SkDScalar) ((SkDScalar) a * (SkDScalar) b);
}
static void computeOuterProduct(SkMatrix* matrix,
const SkPoint pts0[3], const SkPoint& ave0,
const SkPoint pts1[3], const SkPoint& ave1) {
SkDScalar tmp[4];
sk_bzero(tmp, sizeof(tmp));
for (int i = 0; i < 3; i++) {
SkScalar x0 = pts0[i].fX - ave0.fX;
SkScalar y0 = pts0[i].fY - ave0.fY;
SkScalar x1 = pts1[i].fX - ave1.fX;
SkScalar y1 = pts1[i].fY - ave1.fY;
tmp[0] += SkDScalar_setMul(x0, x1);
tmp[1] += SkDScalar_setMul(x0, y1);
tmp[2] += SkDScalar_setMul(y0, x1);
tmp[3] += SkDScalar_setMul(y0, y1);
}
matrix->reset();
matrix->setScaleX(SkDScalar_toScalar(tmp[0]));
matrix->setSkewY( SkDScalar_toScalar(tmp[1]));
matrix->setSkewX( SkDScalar_toScalar(tmp[2]));
matrix->setScaleY(SkDScalar_toScalar(tmp[3]));
}
static SkScalar dot(SkScalar ax, SkScalar ay, SkScalar bx, SkScalar by) {
return SkDScalar_toScalar(SkDScalar_setMul(ax, bx) +
SkDScalar_setMul(ay, by));
}
bool SkSetPoly3To3_D(SkMatrix* matrix, const SkPoint src[3], const SkPoint dst[3]) {
const SkPoint& srcAve = src[0];
const SkPoint& dstAve = dst[0];
SkMatrix srcOP, dstOP;
computeOuterProduct(&srcOP, src, srcAve, src, srcAve);
if (!srcOP.invert(&srcOP)) {
return false;
}
computeOuterProduct(&dstOP, src, srcAve, dst, dstAve);
matrix->setConcat(dstOP, srcOP);
matrix->setTranslateX(dstAve.fX - dot(srcAve.fX, srcAve.fY,
matrix->getScaleX(), matrix->getSkewX()));
matrix->setTranslateY(dstAve.fY - dot(srcAve.fX, srcAve.fY,
matrix->getSkewY(), matrix->getScaleY()));
return true;
}