diff --git a/bgr565.go b/bgr565.go index efec3e2..7b501cd 100644 --- a/bgr565.go +++ b/bgr565.go @@ -43,7 +43,7 @@ func (i *BGR565) SetRGB(x, y int, c RGBColor) { n := i.PixOffset(x, y) pix := i.Pix[n:] - clr := (uint16(c.G)<<11) | (uint16(c.G)<<5) | uint16(c.R) + clr := (uint16(c.G) << 11) | (uint16(c.G) << 5) | uint16(c.R) pix[0] = uint8(clr) pix[1] = uint8(clr >> 8) diff --git a/canvas.go b/canvas.go index b286905..5ad6bb7 100644 --- a/canvas.go +++ b/canvas.go @@ -457,6 +457,7 @@ func (c *Canvas) CurrentMode() (*DisplayMode, error) { dm.VMode = int(v.vmode) var pf PixelFormat + pf.Depth = uint8(v.bits_per_pixel) pf.RedBits = uint8(v.red.length) pf.RedShift = uint8(v.red.offset) pf.GreenBits = uint8(v.green.length) diff --git a/pixelformat.go b/pixelformat.go index c4accdc..2547e7e 100644 --- a/pixelformat.go +++ b/pixelformat.go @@ -53,6 +53,7 @@ const ( // a := (pixel >> alpha_shift) & alpha_mask // type PixelFormat struct { + Depth uint8 // Total bit count for each pixel. RedBits uint8 // Bit count for the red channel. RedShift uint8 // Shift offset for the red channel. GreenBits uint8 // Bit count for the green channel. @@ -65,7 +66,7 @@ type PixelFormat struct { // Stride returns the width, in bytes, for a single pixel. func (p PixelFormat) Stride() int { - return (int(p.RedBits) + int(p.GreenBits) + int(p.BlueBits) + int(p.AlphaBits) + 7) / 8 + return (p.Depth + 7) / 8 } // Type returns an integer constant from the PF_XXX list, which