sdl/surface: implement Set() for ARGB4444
@@ -76,10 +76,12 @@ static inline SDL_Surface* SDL_CreateRGBSurfaceWithFormatFrom(void* pixels, int
#endif
*/
import "C"
-import "unsafe"
-import "reflect"
-import "image"
-import "image/color"
+import (
+ "image"
+ "image/color"
+ "reflect"
+ "unsafe"
+)
// Surface flags (internal use)
const (
@@ -543,6 +545,8 @@ func (surface *Surface) ColorModel() color.Model {
return BGR555Model
case PIXELFORMAT_BGR565:
return BGR565Model
+ case PIXELFORMAT_ARGB4444:
+ return ARGB4444Model
default:
panic("Not implemented yet")
}
@@ -643,6 +647,14 @@ func (surface *Surface) Set(x, y int, c color.Color) {
g := uint32(col.G) >> 3 & 0xFF
b := uint32(col.B) >> 3 & 0xFF
*buf = b<<10 | g<<5 | r
+ case PIXELFORMAT_ARGB4444:
+ col := surface.ColorModel().Convert(c).(color.RGBA)
+ buf := (*uint32)(unsafe.Pointer(&pix[i]))
+ a := uint32(col.A) >> 4 & 0x0F
+ r := uint32(col.R) >> 4 & 0x0F
+ g := uint32(col.G) >> 4 & 0x0F
+ b := uint32(col.B) >> 4 & 0x0F
+ *buf = a<<12 | r<<8 | g<<4 | b
default:
panic("Unknown pixel format!")
}
