This commit is contained in:
Kovid Goyal
2025-10-09 09:25:47 +05:30
parent 4ec94c786d
commit c6582e9f51
2 changed files with 12 additions and 12 deletions

View File

@@ -438,15 +438,3 @@ func NewNRGBWithContiguousRGBPixels(p []byte, width, height int) (*NRGB, error)
Rect: image.Rectangle{image.Point{}, image.Point{width, height}},
}, nil
}
func NewNRGBAWithContiguousRGBAPixels(p []byte, width, height int) (*image.NRGBA, error) {
const bpp = 4
if expected := bpp * width * height; expected != len(p) {
return nil, fmt.Errorf("the image width and height dont match the size of the specified pixel data: width=%d height=%d sz=%d != %d", width, height, len(p), expected)
}
return &image.NRGBA{
Pix: p,
Stride: bpp * width,
Rect: image.Rectangle{image.Point{}, image.Point{width, height}},
}, nil
}

View File

@@ -405,3 +405,15 @@ func FitImage(width, height, pwidth, pheight int) (final_width int, final_height
return width, height
}
func NewNRGBAWithContiguousRGBAPixels(p []byte, width, height int) (*image.NRGBA, error) {
const bpp = 4
if expected := bpp * width * height; expected != len(p) {
return nil, fmt.Errorf("the image width and height dont match the size of the specified pixel data: width=%d height=%d sz=%d != %d", width, height, len(p), expected)
}
return &image.NRGBA{
Pix: p,
Stride: bpp * width,
Rect: image.Rectangle{image.Point{}, image.Point{width, height}},
}, nil
}