diff --git a/go/heif/heif.go b/go/heif/heif.go index d0c9287c15..f6d76a3e91 100644 --- a/go/heif/heif.go +++ b/go/heif/heif.go @@ -1322,6 +1322,10 @@ 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: return nil, fmt.Errorf("unsupported subsample ratio: %s", sr.String()) } @@ -1339,13 +1343,23 @@ func imageFromYCbCr(i *image.YCbCr) (*Image, error) { pY.setData([]byte(i.Y), i.YStride) // TODO: Might need to be updated for other SubsampleRatio values. - halfW, halfH := (w+1)/2, (h+1)/2 - pCb, err := out.NewPlane(ChannelCb, halfW, halfH, depth) + var cw, ch int + switch cm { + case Chroma420: + cw, ch = (w+1)/2, (h+1)/2 + case Chroma444: + cw, ch = w, h + case Chroma422: + cw, ch = (w+1)/2, h + default: + return nil, fmt.Errorf("cm not support: %v", cm) + } + pCb, err := out.NewPlane(ChannelCb, cw, ch, 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, halfH, depth) + pCr, err := out.NewPlane(ChannelCr, cw, ch, depth) if err != nil { return nil, fmt.Errorf("failed to add Cr plane: %v", err) }