Skip to content

Commit

Permalink
Merge pull request #1437 from ywwzwb/master
Browse files Browse the repository at this point in the history
Update heif.go
  • Loading branch information
farindk authored Jan 6, 2025
2 parents 33ec3d6 + 6e59270 commit 1630460
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions go/heif/heif.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 1630460

Please sign in to comment.