You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
talgo-libwebp/webp/yuva_image.go

57 lines
1.3 KiB

package webp
import "image"
// YUVAImage represents a image of YUV colors with alpha channel image.
//
// We can not insert WebP planer image into image.YCbCr,
// because image.YCbCr is not compatible with ITU-R BT.601, but JFIF/JPEG one.
//
// See: http://en.wikipedia.org/wiki/YCbCr
type YUVAImage struct {
Y, Cb, Cr, A []uint8
YStride int
CStride int
AStride int
ColorSpace ColorSpace
Rect image.Rectangle
}
// NewYUVAImage creates and allocates image buffer.
func NewYUVAImage(r image.Rectangle, c ColorSpace) (image *YUVAImage) {
yw, yh := r.Dx(), r.Dx()
cw, ch := ((r.Max.X+1)/2 - r.Min.X/2), ((r.Max.Y+1)/2 - r.Min.Y/2)
switch c {
case YUV420:
b := make([]byte, yw*yh+2*cw*ch)
image = &YUVAImage{
Y: b[:yw*yh],
Cb: b[yw*yh+0*cw*ch : yw*yh+1*cw*ch],
Cr: b[yw*yh+1*cw*ch : yw*yh+2*cw*ch],
A: nil,
YStride: yw,
CStride: cw,
AStride: 0,
ColorSpace: c,
Rect: r,
}
case YUV420A:
b := make([]byte, 2*yw*yh+2*cw*ch)
image = &YUVAImage{
Y: b[:yw*yh],
Cb: b[yw*yh+0*cw*ch : yw*yh+1*cw*ch],
Cr: b[yw*yh+1*cw*ch : yw*yh+2*cw*ch],
A: b[yw*yh+2*cw*ch:],
YStride: yw,
CStride: cw,
AStride: yw,
ColorSpace: c,
Rect: r,
}
}
return
}