Fix GetImageData
This commit is contained in:
parent
680e87e395
commit
759568193c
2 changed files with 19 additions and 16 deletions
|
@ -1045,18 +1045,6 @@ type Image struct {
|
|||
Format PixelFormat
|
||||
}
|
||||
|
||||
// ToImage converts a Image to Go image.Image
|
||||
func (i *Image) ToImage() image.Image {
|
||||
img := image.NewRGBA(image.Rect(0, 0, int(i.Width), int(i.Height)))
|
||||
|
||||
// Get pixel data from image (RGBA 32bit)
|
||||
pixels := GetImageData(i)
|
||||
|
||||
img.Pix = pixels
|
||||
|
||||
return img
|
||||
}
|
||||
|
||||
// NewImage - Returns new Image
|
||||
func NewImage(data []byte, width, height, mipmaps int32, format PixelFormat) *Image {
|
||||
d := unsafe.Pointer(&data[0])
|
||||
|
|
|
@ -7,6 +7,7 @@ package raylib
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"image"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -15,6 +16,20 @@ func (i *Image) cptr() *C.Image {
|
|||
return (*C.Image)(unsafe.Pointer(i))
|
||||
}
|
||||
|
||||
// ToImage converts a Image to Go image.Image
|
||||
func (i *Image) ToImage() image.Image {
|
||||
img := image.NewRGBA(image.Rect(0, 0, int(i.Width), int(i.Height)))
|
||||
|
||||
// Get pixel data from image (RGBA 32bit)
|
||||
cimg := i.cptr()
|
||||
ret := C.GetImageData(*cimg)
|
||||
pixels := (*[1 << 30]uint8)(unsafe.Pointer(ret))[0 : i.Width*i.Height*4]
|
||||
|
||||
img.Pix = pixels
|
||||
|
||||
return img
|
||||
}
|
||||
|
||||
// cptr returns C pointer
|
||||
func (t *Texture2D) cptr() *C.Texture2D {
|
||||
return (*C.Texture2D)(unsafe.Pointer(t))
|
||||
|
@ -113,10 +128,10 @@ func UnloadRenderTexture(target RenderTexture2D) {
|
|||
}
|
||||
|
||||
// GetImageData - Get pixel data from image
|
||||
func GetImageData(image *Image) []byte {
|
||||
cimage := image.cptr()
|
||||
ret := C.GetImageData(*cimage)
|
||||
return (*[1 << 30]uint8)(unsafe.Pointer(ret))[:]
|
||||
func GetImageData(img *Image) []Color {
|
||||
cimg := img.cptr()
|
||||
ret := C.GetImageData(*cimg)
|
||||
return (*[1 << 30]Color)(unsafe.Pointer(ret))[0 : img.Width*img.Height]
|
||||
}
|
||||
|
||||
// GetPixelDataSize - Get pixel data size in bytes (image or texture)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue