Added support for creating image from a sub image.

- With a non-zero Min coordinate.
This commit is contained in:
Sander Schobers 2019-06-21 10:47:10 +02:00
parent eee707c4ec
commit 4e6d089efe

View File

@ -103,10 +103,11 @@ func NewBitmapFromImage(src image.Image, video bool) (*Bitmap, error) {
return nil, errors.New("unable to lock bitmap")
}
dst := (*[1 << 30]uint8)(region.data)
left, top := bnd.Min.X, bnd.Min.Y
for y := 0; y < height; y++ {
row := dst[y*int(region.pitch):]
for x := 0; x < width; x++ {
r, g, b, a := src.At(x, y).RGBA()
r, g, b, a := src.At(left+x, top+y).RGBA()
row[x*4] = uint8(r >> 8)
row[x*4+1] = uint8(g >> 8)
row[x*4+2] = uint8(b >> 8)