blob: 5a0ec57f5954d7a0c3c5abfee64f39418e849c75 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkFDot6_DEFINED
11#define SkFDot6_DEFINED
12
bungeman@google.com8ff8a192012-09-25 20:38:28 +000013#include "SkScalar.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkMath.h"
15
16typedef int32_t SkFDot6;
17
mike@reedtribe.orgbcc1d332011-04-09 19:16:54 +000018#define SK_FDot6One (64)
reed@android.com8a1c16f2008-12-17 15:59:43 +000019#define SK_FDot6Half (32)
20
21#ifdef SK_DEBUG
mike@reedtribe.orgbcc1d332011-04-09 19:16:54 +000022 inline SkFDot6 SkIntToFDot6(S16CPU x) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000023 SkASSERT(SkToS16(x) == x);
24 return x << 6;
25 }
26#else
27 #define SkIntToFDot6(x) ((x) << 6)
28#endif
29
30#define SkFDot6Floor(x) ((x) >> 6)
31#define SkFDot6Ceil(x) (((x) + 63) >> 6)
32#define SkFDot6Round(x) (((x) + 32) >> 6)
33
34#define SkFixedToFDot6(x) ((x) >> 10)
35
mike@reedtribe.orgbcc1d332011-04-09 19:16:54 +000036inline SkFixed SkFDot6ToFixed(SkFDot6 x) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000037 SkASSERT((x << 10 >> 10) == x);
38
39 return x << 10;
40}
41
reed@google.com8f4d2302013-12-17 16:44:46 +000042#define SkScalarToFDot6(x) (SkFDot6)((x) * 64)
43#define SkFDot6ToScalar(x) ((SkScalar)(x) * 0.015625f)
reed@android.com8a1c16f2008-12-17 15:59:43 +000044
mike@reedtribe.orgbcc1d332011-04-09 19:16:54 +000045inline SkFixed SkFDot6Div(SkFDot6 a, SkFDot6 b) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000046 SkASSERT(b != 0);
47
mike@reedtribe.orgbcc1d332011-04-09 19:16:54 +000048 if (a == (int16_t)a) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000049 return (a << 16) / b;
mike@reedtribe.orgbcc1d332011-04-09 19:16:54 +000050 } else {
reed@android.com8a1c16f2008-12-17 15:59:43 +000051 return SkFixedDiv(a, b);
mike@reedtribe.orgbcc1d332011-04-09 19:16:54 +000052 }
reed@android.com8a1c16f2008-12-17 15:59:43 +000053}
54
55#endif