Added New{Memory,Video}Bitmap functions to create memory/video bitmap directly.

Added new bitmap flags to New{Memory,Bitmap,}Bitmap methods.
This commit is contained in:
Sander Schobers 2018-02-26 19:46:53 +01:00
parent 5f12bfe3ef
commit 499dff7a96

View File

@ -51,8 +51,17 @@ type Rotation struct {
Center bool Center bool
} }
// NewBitmap creates a new bitmap of given width and height func newBitmap(width, height int, mut func(m FlagMutation), flags []NewBitmapFlag) (*Bitmap, error) {
func NewBitmap(width, height int) (*Bitmap, error) { var newBmpFlags = CaptureNewBitmapFlags()
defer newBmpFlags.Revert()
newBmpFlags.Mutate(func(m FlagMutation) {
if nil != mut {
mut(m)
}
for _, f := range flags {
m.Set(f)
}
})
b := C.al_create_bitmap(C.int(width), C.int(height)) b := C.al_create_bitmap(C.int(width), C.int(height))
if nil == b { if nil == b {
return nil, errors.New("error creating bitmap") return nil, errors.New("error creating bitmap")
@ -60,6 +69,27 @@ func NewBitmap(width, height int) (*Bitmap, error) {
return &Bitmap{b, width, height}, nil return &Bitmap{b, width, height}, nil
} }
// NewBitmap creates a new bitmap of given width and height and optional flags
func NewBitmap(width, height int, flags ...NewBitmapFlag) (*Bitmap, error) {
return newBitmap(width, height, nil, flags)
}
// NewVideoBitmap creates a new video bitmap of given width and height and optional flags
func NewVideoBitmap(width, height int, flags ...NewBitmapFlag) (*Bitmap, error) {
return newBitmap(width, height, func(m FlagMutation) {
m.Unset(NewBitmapFlagMemoryBitmap)
m.Set(NewBitmapFlagVideoBitmap)
}, flags)
}
// NewMemoryBitmap creates a new video bitmap of given width and height and optional flags
func NewMemoryBitmap(width, height int, flags ...NewBitmapFlag) (*Bitmap, error) {
return newBitmap(width, height, func(m FlagMutation) {
m.Unset(NewBitmapFlagVideoBitmap)
m.Set(NewBitmapFlagMemoryBitmap)
}, flags)
}
// NewBitmapFromImage creates a new bitmap starting from a Go native image (image.Image) // NewBitmapFromImage creates a new bitmap starting from a Go native image (image.Image)
func NewBitmapFromImage(im image.Image, video bool) (*Bitmap, error) { func NewBitmapFromImage(im image.Image, video bool) (*Bitmap, error) {
var newBmpFlags = CaptureNewBitmapFlags() var newBmpFlags = CaptureNewBitmapFlags()