Source File
ycbcr.go
Belonging Package
image
package image
import (
)
type YCbCrSubsampleRatio int
const (
YCbCrSubsampleRatio444 YCbCrSubsampleRatio = iota
YCbCrSubsampleRatio422
YCbCrSubsampleRatio420
YCbCrSubsampleRatio440
YCbCrSubsampleRatio411
YCbCrSubsampleRatio410
)
func ( YCbCrSubsampleRatio) () string {
switch {
case YCbCrSubsampleRatio444:
return "YCbCrSubsampleRatio444"
case YCbCrSubsampleRatio422:
return "YCbCrSubsampleRatio422"
case YCbCrSubsampleRatio420:
return "YCbCrSubsampleRatio420"
case YCbCrSubsampleRatio440:
return "YCbCrSubsampleRatio440"
case YCbCrSubsampleRatio411:
return "YCbCrSubsampleRatio411"
case YCbCrSubsampleRatio410:
return "YCbCrSubsampleRatio410"
}
return "YCbCrSubsampleRatioUnknown"
}
type YCbCr struct {
Y, Cb, Cr []uint8
YStride int
CStride int
SubsampleRatio YCbCrSubsampleRatio
Rect Rectangle
}
func ( *YCbCr) () color.Model {
return color.YCbCrModel
}
func ( *YCbCr) () Rectangle {
return .Rect
}
func ( *YCbCr) (, int) color.Color {
return .YCbCrAt(, )
}
func ( *YCbCr) (, int) color.YCbCr {
if !(Point{, }.In(.Rect)) {
return color.YCbCr{}
}
:= .YOffset(, )
:= .COffset(, )
return color.YCbCr{
.Y[],
.Cb[],
.Cr[],
}
}
func ( *YCbCr) (, int) int {
switch .SubsampleRatio {
case YCbCrSubsampleRatio422:
return (-.Rect.Min.Y)*.CStride + (/2 - .Rect.Min.X/2)
case YCbCrSubsampleRatio420:
return (/2-.Rect.Min.Y/2)*.CStride + (/2 - .Rect.Min.X/2)
case YCbCrSubsampleRatio440:
return (/2-.Rect.Min.Y/2)*.CStride + ( - .Rect.Min.X)
case YCbCrSubsampleRatio411:
return (-.Rect.Min.Y)*.CStride + (/4 - .Rect.Min.X/4)
case YCbCrSubsampleRatio410:
return (/2-.Rect.Min.Y/2)*.CStride + (/4 - .Rect.Min.X/4)
if .Empty() {
return &YCbCr{
SubsampleRatio: .SubsampleRatio,
}
}
:= .YOffset(.Min.X, .Min.Y)
:= .COffset(.Min.X, .Min.Y)
return &YCbCr{
Y: .Y[:],
Cb: .Cb[:],
Cr: .Cr[:],
SubsampleRatio: .SubsampleRatio,
YStride: .YStride,
CStride: .CStride,
Rect: ,
}
}
func ( *YCbCr) () bool {
return true
}
func ( Rectangle, YCbCrSubsampleRatio) (, , , int) {
, = .Dx(), .Dy()
switch {
case YCbCrSubsampleRatio422:
= (.Max.X+1)/2 - .Min.X/2
=
case YCbCrSubsampleRatio420:
= (.Max.X+1)/2 - .Min.X/2
= (.Max.Y+1)/2 - .Min.Y/2
case YCbCrSubsampleRatio440:
=
= (.Max.Y+1)/2 - .Min.Y/2
case YCbCrSubsampleRatio411:
= (.Max.X+3)/4 - .Min.X/4
=
case YCbCrSubsampleRatio410:
= (.Max.X+3)/4 - .Min.X/4
= (.Max.Y+1)/2 - .Min.Y/2
=
=
}
return
}
func ( Rectangle, YCbCrSubsampleRatio) *YCbCr {
, , , := yCbCrSize(, )
:= add2NonNeg(
mul3NonNeg(1, , ),
mul3NonNeg(2, , ),
)
if < 0 {
panic("image: NewYCbCr Rectangle has huge or negative dimensions")
}
:= * + 0**
:= * + 1**
:= * + 2**
:= make([]byte, )
return &YCbCr{
Y: [::],
Cb: [::],
Cr: [::],
SubsampleRatio: ,
YStride: ,
CStride: ,
Rect: ,
}
}
type NYCbCrA struct {
YCbCr
A []uint8
AStride int
}
func ( *NYCbCrA) () color.Model {
return color.NYCbCrAModel
}
func ( *NYCbCrA) (, int) color.Color {
return .NYCbCrAAt(, )
}
func ( *NYCbCrA) (, int) color.NYCbCrA {
if !(Point{X: , Y: }.In(.Rect)) {
return color.NYCbCrA{}
}
:= .YOffset(, )
:= .COffset(, )
:= .AOffset(, )
return color.NYCbCrA{
color.YCbCr{
Y: .Y[],
Cb: .Cb[],
Cr: .Cr[],
},
.A[],
}
}
if .Empty() {
return &NYCbCrA{
YCbCr: YCbCr{
SubsampleRatio: .SubsampleRatio,
},
}
}
:= .YOffset(.Min.X, .Min.Y)
:= .COffset(.Min.X, .Min.Y)
:= .AOffset(.Min.X, .Min.Y)
return &NYCbCrA{
YCbCr: YCbCr{
Y: .Y[:],
Cb: .Cb[:],
Cr: .Cr[:],
SubsampleRatio: .SubsampleRatio,
YStride: .YStride,
CStride: .CStride,
Rect: ,
},
A: .A[:],
AStride: .AStride,
}
}
func ( Rectangle, YCbCrSubsampleRatio) *NYCbCrA {
, , , := yCbCrSize(, )
:= add2NonNeg(
mul3NonNeg(2, , ),
mul3NonNeg(2, , ),
)
if < 0 {
panic("image: NewNYCbCrA Rectangle has huge or negative dimension")
}
:= 1** + 0**
:= 1** + 1**
:= 1** + 2**
:= 2** + 2**
:= make([]byte, )
return &NYCbCrA{
YCbCr: YCbCr{
Y: [::],
Cb: [::],
Cr: [::],
SubsampleRatio: ,
YStride: ,
CStride: ,
Rect: ,
},
A: [:],
AStride: ,
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |