Skip to content

Commit

Permalink
Support encoding SubsampleRatio of Chroma422.
Browse files Browse the repository at this point in the history
  • Loading branch information
fancycode committed Sep 5, 2024
1 parent 78d469d commit 8fded96
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions encode_highlevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func imageFromYCbCr(i *image.YCbCr) (*Image, error) {
switch sr := i.SubsampleRatio; sr {
case image.YCbCrSubsampleRatio420:
cm = Chroma420
case image.YCbCrSubsampleRatio422:
cm = Chroma422
case image.YCbCrSubsampleRatio444:
cm = Chroma444
default:
Expand Down Expand Up @@ -184,6 +186,18 @@ func imageFromYCbCr(i *image.YCbCr) (*Image, error) {
return nil, fmt.Errorf("failed to add Cr plane: %v", err)
}
pCr.setData([]byte(i.Cr), i.CStride)
case Chroma422:
halfW := (w + 1) / 2
pCb, err := out.NewPlane(ChannelCb, halfW, h, depth)
if err != nil {
return nil, fmt.Errorf("failed to add Cb plane: %v", err)
}
pCb.setData([]byte(i.Cb), i.CStride)
pCr, err := out.NewPlane(ChannelCr, halfW, h, depth)
if err != nil {
return nil, fmt.Errorf("failed to add Cr plane: %v", err)
}
pCr.setData([]byte(i.Cr), i.CStride)
case Chroma444:
pCb, err := out.NewPlane(ChannelCb, w, h, depth)
if err != nil {
Expand Down

0 comments on commit 8fded96

Please sign in to comment.