diff options
| author | Nigel Tao <nigeltao@golang.org> | 2015-07-15 14:55:02 +1000 |
|---|---|---|
| committer | Nigel Tao <nigeltao@golang.org> | 2015-07-15 05:29:00 +0000 |
| commit | c2023a07915cccff1ffba9b96e160f444f77aeae (patch) | |
| tree | eef9b6a62e8fee1a22d0fe9d95466858acb4010e /src/image/decode_example_test.go | |
| parent | 5a4cc600b79075d8ad6304809c70a7d94da628cd (diff) | |
| download | go-c2023a07915cccff1ffba9b96e160f444f77aeae.tar.xz | |
image/color: tweak the YCbCr to RGBA conversion formula.
Before, calling the RGBA method of YCbCr color would return red values
in the range [0x0080, 0xff80]. After, the range is [0x0000, 0xffff] and
is consistent with what Gray colors' RGBA method returns. In particular,
pure black, pure white and every Gray color in between are now exactly
representable as a YCbCr color.
This fixes a regression from Go 1.4 (where YCbCr{0x00, 0x80, 0x80} was
no longer equivalent to pure black), introduced by golang.org/cl/8073 in
the Go 1.5 development cycle. In Go 1.4, the +0x80 rounding was not
noticable when Cb == 0x80 && Cr == 0x80, because the YCbCr to RGBA
conversion truncated to 8 bits before multiplying by 0x101, so the
output range was [0x0000, 0xffff].
The TestYCbCrRoundtrip fuzzy-match tolerance grows from 1 to 2 because
the YCbCr to RGB conversion now maps to an ever-so-slightly larger
range, along with the usual imprecision of accumulating rounding errors.
Also s/int/int32/ in ycbcr.go. The conversion shouldn't overflow either
way, as int is always at least 32 bits, but it does make it clearer that
the computation doesn't depend on sizeof(int).
Fixes #11691
Change-Id: I538ca0adf7e040fa96c5bc8b3aef4454535126b9
Reviewed-on: https://go-review.googlesource.com/12220
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/image/decode_example_test.go')
| -rw-r--r-- | src/image/decode_example_test.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/image/decode_example_test.go b/src/image/decode_example_test.go index 21e90fea4f..81fa0378e1 100644 --- a/src/image/decode_example_test.go +++ b/src/image/decode_example_test.go @@ -61,22 +61,22 @@ func Example() { } // Output: // bin red green blue alpha - // 0x0000-0x0fff: 353 759 7228 0 - // 0x1000-0x1fff: 629 2944 1036 0 - // 0x2000-0x2fff: 1075 2319 984 0 - // 0x3000-0x3fff: 838 2291 988 0 - // 0x4000-0x4fff: 540 1302 542 0 - // 0x5000-0x5fff: 319 971 263 0 - // 0x6000-0x6fff: 316 377 178 0 - // 0x7000-0x7fff: 581 280 216 0 - // 0x8000-0x8fff: 3457 228 274 0 - // 0x9000-0x9fff: 2294 237 334 0 - // 0xa000-0xafff: 938 283 370 0 - // 0xb000-0xbfff: 322 338 401 0 - // 0xc000-0xcfff: 229 386 295 0 - // 0xd000-0xdfff: 263 416 281 0 - // 0xe000-0xefff: 538 433 312 0 - // 0xf000-0xffff: 2758 1886 1748 15450 + // 0x0000-0x0fff: 364 790 7242 0 + // 0x1000-0x1fff: 645 2967 1039 0 + // 0x2000-0x2fff: 1072 2299 979 0 + // 0x3000-0x3fff: 820 2266 980 0 + // 0x4000-0x4fff: 537 1305 541 0 + // 0x5000-0x5fff: 319 962 261 0 + // 0x6000-0x6fff: 322 375 177 0 + // 0x7000-0x7fff: 601 279 214 0 + // 0x8000-0x8fff: 3478 227 273 0 + // 0x9000-0x9fff: 2260 234 329 0 + // 0xa000-0xafff: 921 282 373 0 + // 0xb000-0xbfff: 321 335 397 0 + // 0xc000-0xcfff: 229 388 298 0 + // 0xd000-0xdfff: 260 414 277 0 + // 0xe000-0xefff: 516 428 298 0 + // 0xf000-0xffff: 2785 1899 1772 15450 } const data = ` |
