add and test SkFixed15::to_u8()
Change-Id: Iedbcd2d938122cdc8f6b235745eb6165e348c237 Reviewed-on: https://skia-review.googlesource.com/7108 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Herb Derby <herb@google.com>
This commit is contained in:
parent
eaf0079d81
commit
d32b8177da
@ -32,6 +32,12 @@ public:
|
||||
+ ((val+1)>>8); // All val but 255 are correct. +1 if val == 255 to get 32768.
|
||||
}
|
||||
|
||||
uint8_t to_u8() const {
|
||||
// FromU8() and to_u8() roundtrip all bytes.
|
||||
// There is still much room to tweak this towards the ideal, a rounding scale by 255/32768.
|
||||
return (fVal - (fVal>>8))>>7;
|
||||
}
|
||||
|
||||
SkFixed15 operator +(SkFixed15 o) const { return fVal + o.fVal; }
|
||||
SkFixed15 operator -(SkFixed15 o) const { return fVal - o.fVal; }
|
||||
SkFixed15 operator *(SkFixed15 o) const { return (fVal * o.fVal + (1<<14)) >> 15; }
|
||||
|
@ -26,4 +26,9 @@ DEF_TEST(SkFixed15, r) {
|
||||
for (int x = 0; x < 256; x++) {
|
||||
REPORTER_ASSERT(r, SkFixed15::FromU8(x) == SkFixed15(x * (1/255.0f)));
|
||||
}
|
||||
|
||||
// to_u8() and FromU8() should roundtrip all bytes.
|
||||
for (int x = 0; x < 256; x++) {
|
||||
REPORTER_ASSERT(r, x == SkFixed15::FromU8(x).to_u8());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user