Skip to content

Commit

Permalink
Add support for *image.NRGBA in "EncodeFromImage".
Browse files Browse the repository at this point in the history
  • Loading branch information
fancycode committed Sep 4, 2024
1 parent 226d97f commit a79acad
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions encode_highlevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ func imageFromRGBA(i *image.RGBA) (*Image, error) {
return out, nil
}

func imageFromNRGBA(i *image.NRGBA) (*Image, error) {
min := i.Bounds().Min
max := i.Bounds().Max
w := max.X - min.X
h := max.Y - min.Y

out, err := NewImage(w, h, ColorspaceRGB, ChromaInterleavedRGBA)
if err != nil {
return nil, fmt.Errorf("failed to create image: %v", err)
}

p, err := out.NewPlane(ChannelInterleaved, w, h, 8)
if err != nil {
return nil, fmt.Errorf("failed to add plane: %v", err)
}
p.setData([]byte(i.Pix), w*4)

return out, nil
}

func imageFromRGBA64(i *image.RGBA64) (*Image, error) {
min := i.Bounds().Min
max := i.Bounds().Max
Expand Down Expand Up @@ -197,6 +217,12 @@ func EncodeFromImage(img image.Image, compression CompressionFormat, quality int
return nil, fmt.Errorf("failed to create image: %v", err)
}
out = tmp
case *image.NRGBA:
tmp, err := imageFromNRGBA(i)
if err != nil {
return nil, fmt.Errorf("failed to create image: %v", err)
}
out = tmp
case *image.RGBA64:
tmp, err := imageFromRGBA64(i)
if err != nil {
Expand Down

0 comments on commit a79acad

Please sign in to comment.