Update rounding/clamping comments on sk_linear_to_srgb().

Rounding is enough.  No need for an explicit clamp if the inputs are in range.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2161223002

Review-Url: https://codereview.chromium.org/2161223002
This commit is contained in:
mtklein 2016-07-19 13:36:03 -07:00 committed by Commit bot
parent 4bcb4c7a25
commit d1bd2082c5
2 changed files with 5 additions and 4 deletions

View File

@ -14,14 +14,14 @@
*
* Current best practices:
* - for sRGB -> linear, lookup R,G,B in sk_linear_from_srgb;
* - for linear -> sRGB, call sk_linear_to_srgb() for R,G,B, clamp to 255, and round;
* - for linear -> sRGB, call sk_linear_to_srgb() for R,G,B, and round;
* - the alpha channel is linear in both formats, needing at most *(1/255.0f) or *255.0f.
*
* sk_linear_to_srgb()'s output requires rounding; it does not round for you.
*
* Given inputs in [0,1], sk_linear_to_srgb() will not underflow 0 but may overflow 255.
* The overflow is small enough that you can safely either clamp then round or round then clamp.
* (If you don't trust the inputs are in [0,1], you'd better clamp both sides immediately.)
* The overflow is small enough to be handled by rounding.
* (But if you don't trust the inputs are in [0,1], you'd better clamp both sides immediately.)
*
* sk_linear_to_srgb() will run a little faster than usual when compiled with SSE4.1+.
*/

View File

@ -11,7 +11,8 @@
#include <math.h>
static uint8_t linear_to_srgb(float l) {
return (uint8_t)roundf(sk_linear_to_srgb(Sk4f{l})[0]);
// Round float to int, truncate that to uint8_t.
return (uint8_t)Sk4f_round( sk_linear_to_srgb(Sk4f{l}) )[0];
}
DEF_TEST(sk_linear_to_srgb, r) {