• Martin Möhrmann's avatar
    image/color: optimize YCbCrToRGB · f0c5b8b9
    Martin Möhrmann authored
    Use one comparison to detect underflow and overflow simultaneously.
    Use a shift, bitwise complement and uint8 type conversion to handle
    clamping to upper and lower bound without additional branching.
    
    Overall the new code is faster for a mix of
    common case, underflow and overflow.
    
    name     old time/op  new time/op  delta
    YCbCr-2  1.12ms ± 0%  0.64ms ± 0%  -43.01%  (p=0.000 n=48+47)
    
    name              old time/op  new time/op  delta
    YCbCrToRGB/0-2    5.52ns ± 0%  5.77ns ± 0%  +4.48%  (p=0.000 n=50+49)
    YCbCrToRGB/128-2  6.05ns ± 0%  5.52ns ± 0%  -8.69%  (p=0.000 n=39+50)
    YCbCrToRGB/255-2  5.80ns ± 0%  5.77ns ± 0%  -0.58%  (p=0.000 n=50+49)
    
    Found in collaboration with Josh Bleecher Snyder and Ralph Corderoy.
    
    Change-Id: Ic5020320f704966f545fdc1ae6bc24ddb5d3d09a
    Reviewed-on: https://go-review.googlesource.com/21910Reviewed-by: 's avatarJosh Bleecher Snyder <josharian@gmail.com>
    Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    f0c5b8b9
Name
Last commit
Last update
..
color Loading commit data...
draw Loading commit data...
gif Loading commit data...
internal/imageutil Loading commit data...
jpeg Loading commit data...
png Loading commit data...
testdata Loading commit data...
decode_example_test.go Loading commit data...
decode_test.go Loading commit data...
format.go Loading commit data...
geom.go Loading commit data...
geom_test.go Loading commit data...
image.go Loading commit data...
image_test.go Loading commit data...
names.go Loading commit data...
ycbcr.go Loading commit data...
ycbcr_test.go Loading commit data...