mirror of
https://github.com/talgo-cloud/talgo-libwebp.git
synced 2026-03-16 10:45:59 -07:00
initial commit
This commit is contained in:
commit
5af6d93b3b
26 changed files with 1165 additions and 0 deletions
56
webp/yuva_image.go
Normal file
56
webp/yuva_image.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue