Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update heif.go #1437

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading