draw: update the inlined YCbCr.RGBA code to use 16 bit color.

This matches the standard library change at
https://go-review.googlesource.com/#/c/8073/

Change-Id: I216028e18678a70e449167cd9ab910c63d37adcc
Reviewed-on: https://go-review.googlesource.com/8075
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Nigel Tao 2015-03-26 19:33:18 +11:00
parent 500a27f912
commit d5c5125b57
5 changed files with 792 additions and 950 deletions

View File

@ -479,16 +479,10 @@ func expnDollar(prefix, dollar, suffix string, d *data) string {
fmt.Fprintf(buf, ""+ fmt.Fprintf(buf, ""+
"%si := %s\n"+ "%si := %s\n"+
"%sj := %s\n"+ "%sj := %s\n"+
"%s\n"+ "%s\n",
"%sr%s := uint32(%sr8) * 0x101\n"+
"%sg%s := uint32(%sg8) * 0x101\n"+
"%sb%s := uint32(%sb8) * 0x101\n",
lhs, pixOffset("src", args[0], args[1], "", "*src.YStride"), lhs, pixOffset("src", args[0], args[1], "", "*src.YStride"),
lhs, cOffset(args[0], args[1], d.sratio), lhs, cOffset(args[0], args[1], d.sratio),
ycbcrToRGB(lhs), ycbcrToRGB(lhs, tmp),
lhs, tmp, lhs,
lhs, tmp, lhs,
lhs, tmp, lhs,
) )
} }
@ -643,34 +637,34 @@ func cOffset(x, y, sratio string) string {
return fmt.Sprintf("unsupported sratio %q", sratio) return fmt.Sprintf("unsupported sratio %q", sratio)
} }
// TODO: should we have a color.YCbCrToRGB48 function that returns 16-bit func ycbcrToRGB(lhs, tmp string) string {
// color? s := `
// This is an inline version of image/color/ycbcr.go's YCbCr.RGBA method.
func ycbcrToRGB(lhs string) string {
return strings.Replace(`
// This is an inline version of image/color/ycbcr.go's func YCbCrToRGB.
$yy1 := int(src.Y[$i])<<16 + 1<<15 $yy1 := int(src.Y[$i])<<16 + 1<<15
$cb1 := int(src.Cb[$j]) - 128 $cb1 := int(src.Cb[$j]) - 128
$cr1 := int(src.Cr[$j]) - 128 $cr1 := int(src.Cr[$j]) - 128
$r8 := ($yy1 + 91881*$cr1) >> 16 $r@ := ($yy1 + 91881*$cr1) >> 8
$g8 := ($yy1 - 22554*$cb1 - 46802*$cr1) >> 16 $g@ := ($yy1 - 22554*$cb1 - 46802*$cr1) >> 8
$b8 := ($yy1 + 116130*$cb1) >> 16 $b@ := ($yy1 + 116130*$cb1) >> 8
if $r8 < 0 { if $r@ < 0 {
$r8 = 0 $r@ = 0
} else if $r8 > 0xff { } else if $r@ > 0xffff {
$r8 = 0xff $r@ = 0xffff
} }
if $g8 < 0 { if $g@ < 0 {
$g8 = 0 $g@ = 0
} else if $g8 > 0xff { } else if $g@ > 0xffff {
$g8 = 0xff $g@ = 0xffff
} }
if $b8 < 0 { if $b@ < 0 {
$b8 = 0 $b@ = 0
} else if $b8 > 0xff { } else if $b@ > 0xffff {
$b8 = 0xff $b@ = 0xffff
} }
`, "$", lhs, -1) `
s = strings.Replace(s, "$", lhs, -1)
s = strings.Replace(s, "@", tmp, -1)
return s
} }
func split(s, sep string) (string, string) { func split(s, sep string) (string, string) {

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB