21 void log(int16_t golden, int16_t candidate) {
22 int64_t diff = candidate - golden;
38static float golden_bilerp(
float tx,
float ty, int16_t p00, int16_t p10, int16_t p01, int16_t p11) {
39 return (1.0f-tx) * (1.0f-ty) * p00
40 + (1.0f-tx) * ty * p01
41 + (1.0f-ty) * tx * p10
46 float tx,
float ty, int16_t p00, int16_t p10, int16_t p01, int16_t p11) {
48 double dtx(tx), dty(ty);
50 double top = (1.0 - dtx) * p00 + dtx * p10;
51 double bottom = (1.0 - dtx) * p01 + dtx * p11;
53 return (1.0 - dty) * top + dty * bottom;
57 float tx,
float ty, int16_t p00, int16_t p10, int16_t p01, int16_t p11) {
58 int32_t ftx(
floor(tx * 65536.0f + 0.5f));
59 int64_t top = ftx * (p10 - p00) + 65536 * p00;
60 int64_t bottom = ftx * (p11 - p01) + 65536 * p01;
62 int64_t fty(
floor(ty * 65536.0f + 0.5f));
63 int64_t temp = fty * (bottom - top) + top * 65536LL;
64 int64_t rounded = temp + (1LL << 31);
69static int16_t
bilerp_1(
float tx,
float ty, int16_t p00, int16_t p10, int16_t p01, int16_t p11) {
70 const int logPixelScale = 7;
71 const int16_t half = 1 << logPixelScale;
72 I16 qtx =
floor(tx * 65536.0f - 32768.0f + 0.5f);
73 I16 qw = (p10 - p00) << logPixelScale;
74 U16 qm = (p10 + p00) << logPixelScale;
77 qw = (p11 - p01) << logPixelScale;
78 qm = (p11 + p01) << logPixelScale;
82 I16 qty =
floor(ty * 65536.0f - 32768.0f + 0.5f);
85 qm = (
U16)bottom + (
U16)top;
88 return (scaledAnswer[0] + half) >> (logPixelScale + 1);
91template <
typename Bilerp>
95 auto interesting = {0, 1, 2, 3, 4, 5, 6, 7, 8, 60, 61, 62, 63, 64, 65, 66, 67, 68, 124, 125,
96 126, 127, 128, 129, 130, 131, 132, 188, 189, 190, 191, 192, 193, 194,
97 195, 196, 248, 249, 250, 251, 252, 253, 254, 255};
98 for (
float tx : {0.0f, 0.25f, 0.5f, 0.75f, 1.0f - 1.0f/65536.0f})
99 for (
float ty : {0.0f, 0.25f, 0.5f, 0.75f, 1.0f - 1.0f/65536.0f})
100 for (
int p00 : interesting)
101 for (
int p01 : interesting)
102 for (
int p10 : interesting)
103 for (
int p11 : interesting) {
106 int16_t golden =
floor(l + 0.5);
109 int16_t candidate =
bilerp(tx, ty, p00, p10, p01, p11);
110 stats.log(golden, candidate);
118 printf(
"\nUsing trunc_bilerp...\n");
122 printf(
"\nUsing full_res_bilerp...\n");
static int step(int x, SkScalar min, SkScalar max)
static I16 simulate_ssse3_mm_mulhrs_epi16(I16 a, I16 b)
static U16 constrained_add(I16 a, U16 b)
static SkScalar bilerp(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01, SkScalar c11)
static double golden_bilerp2(float tx, float ty, int16_t p00, int16_t p10, int16_t p01, int16_t p11)
static int16_t full_res_bilerp(float tx, float ty, int16_t p00, int16_t p10, int16_t p01, int16_t p11)
static Stats check_bilerp(Bilerp bilerp)
static float golden_bilerp(float tx, float ty, int16_t p00, int16_t p10, int16_t p01, int16_t p11)
static int16_t bilerp_1(float tx, float ty, int16_t p00, int16_t p10, int16_t p01, int16_t p11)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
SIN Vec< N, float > floor(const Vec< N, float > &x)
void log(int16_t golden, int16_t candidate)