Documentation ¶
Overview ¶
Package pixel contains pixel format definitions used in various displays and fast operations on them.
This package is just a base for pixel operations, it is _not_ a graphics library. It doesn't define circles, lines, etc - just the bare minimum graphics operations needed plus the ones that need to be specialized per pixel format.
Index ¶
- func NewColor[T Color](r, g, b uint8) T
- func NewLinearColor[T Color](r, g, b uint8) T
- type BaseColor
- type Color
- type Image
- func (img Image[T]) FillSolidColor(color T)
- func (img Image[T]) Get(x, y int) T
- func (img Image[T]) Len() int
- func (img Image[T]) LimitHeight(height int) Image[T]
- func (img Image[T]) RawBuffer() []uint8
- func (img Image[T]) Rescale(width, height int) Image[T]
- func (img Image[T]) Set(x, y int, c T)
- func (img Image[T]) Size() (int, int)
- type Monochrome
- type RGB444BE
- type RGB555
- type RGB565BE
- type RGB888
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewColor ¶
NewColor returns the given color based on the RGB values passed in the parameters. The input value is assumed to be in sRGB color space.
func NewLinearColor ¶
NewLinearColor returns the given color based on the linear RGB values passed in the parameters. Use this if the RGB values are actually linear colors (like those that are used in most RGB LEDs) and not when it is in the usual sRGB color space (which is not linear).
The input is assumed to be in the linear sRGB color space.
Types ¶
type BaseColor ¶
type BaseColor interface { // The number of bits when stored. // This means for example that RGB555 (which is still stored as a 16-bit // integer) returns 16, while RGB444 returns 12. BitsPerPixel() int // Return the given color in color.RGBA format, which is always sRGB. The // alpha channel is always 255. RGBA() color.RGBA }
BaseColor contains all the methods needed in a color format. This can be used in display drivers that want to define their own Color type with just the pixel formats the display supports.
type Color ¶
Pixel with a particular color, matching the underlying hardware of a particular display. Each pixel is at least 1 byte in size. The color format is sRGB (or close to it) in all cases except for 1-bit.
type Image ¶
type Image[T Color] struct { // contains filtered or unexported fields }
Image buffer, used for working with the native image format of various displays. It works a lot like a slice: it can be rescaled while reusing the underlying buffer and should be passed around by value.
func NewImageFromBytes ¶ added in v0.29.0
NewImageFromBytes creates a new image of the given size using an existing data slice of bytes.
func (Image[T]) FillSolidColor ¶
func (img Image[T]) FillSolidColor(color T)
FillSolidColor fills the entire image with the given color. This may be faster than setting individual pixels.
func (Image[T]) LimitHeight ¶
LimitHeight returns a subimage with the bottom part cut off, as specified by height.
func (Image[T]) RawBuffer ¶
RawBuffer returns a byte slice that can be written directly to the screen using DrawRGBBitmap8.
func (Image[T]) Rescale ¶
Rescale returns a new Image buffer based on the img buffer. The contents is undefined after the Rescale operation, and any modification to the returned image will overwrite the underlying image buffer in undefined ways. It will panic if width*height is larger than img.Len().
type Monochrome ¶ added in v0.28.0
type Monochrome bool
func NewMonochrome ¶ added in v0.28.0
func NewMonochrome(r, g, b uint8) Monochrome
func (Monochrome) BitsPerPixel ¶ added in v0.28.0
func (c Monochrome) BitsPerPixel() int
func (Monochrome) RGBA ¶ added in v0.28.0
func (c Monochrome) RGBA() color.RGBA
type RGB444BE ¶
type RGB444BE uint16
Color format that is supported by the ST7789 for example. It may be a bit faster to use than RGB565BE on very slow SPI buses.
The color format is native endian as a uint16 (0000rrrr_ggggbbbb), not big endian which you might expect. I tried swapping the bytes, but it didn't have much of a performance impact and made the code harder to read. It is stored as a 12-bit big endian value in Image[RGB444BE] though.
func NewRGB444BE ¶
func (RGB444BE) BitsPerPixel ¶
type RGB555 ¶
type RGB555 uint16
Color format used on the GameBoy Advance among others.
Colors are stored as native endian values, with bits 0bbbbbgg_gggrrrrr (red is least significant, blue is most significant).
func (RGB555) BitsPerPixel ¶
type RGB565BE ¶
type RGB565BE uint16
RGB565 as used in many SPI displays. Stored as a big endian value.
The color format in integer form is gggbbbbb_rrrrrggg on little endian systems, which is the standard RGB565 format but with the top and bottom bytes swapped.
There are a few alternatives to this weird big-endian format, but they're not great:
- Storing the value in two 8-bit stores (to make the code endian-agnostic) incurs too much of a performance penalty.
- Swapping the upper and lower bits just before storing. This is still less efficient than it could be, since colors are usually constructed once and then reused in many store operations. Doing the swap once instead of many times for each store is a performance win.
func NewRGB565BE ¶
func (RGB565BE) BitsPerPixel ¶
type RGB888 ¶
type RGB888 struct {
R, G, B uint8
}
RGB888 format, more commonly used in other places (desktop PC displays, CSS, etc). Less commonly used on embedded displays due to the higher memory usage.