Skip to content

Displayer.SetPixel should use color.Color #837

@nealey

Description

@nealey

I want to be able to do this:

display.FillRectangle(x, 5, 5, 5, color.White)

But beause Displayer.SetPixel takes color.RGBA, I must do this:

dispay.FillRectangle(x, 5, 5, 5, color.RGBAModel.Convert(color.White).(color.RGBA))

color.Color is meant to provide an interface for all colors:

type Color interface {
	// RGBA returns the alpha-premultiplied red, green, blue and alpha values
	// for the color. Each value ranges within [0, 0xffff], but is represented
	// by a uint32 so that multiplying by a blend factor up to 0xffff will not
	// overflow.
	//
	// An alpha-premultiplied color component c has been scaled by alpha (a),
	// so has valid values 0 <= c <= a.
	RGBA() (r, g, b, a uint32)
}

I know this is going to be painful, because so many things use it, but I propose Displayer be redefined as follows, so that it may use the color package as intended:

type Displayer interface {
        // Size returns the current size of the display.
        Size() (x, y int16)

        // SetPixel modifies the internal buffer.
        SetPixel(x, y int16, c color.Color)

        // Display sends the buffer (if any) to the screen.
        Display() error
}

It should then be up to each device implementing Displayer to decide how to handle the 16-bit color. Probably most of them will shift R, G, and B right by 8, and continue to ignore A.

Existing code (other than drivers) will not be impacted by this change, since color.RGBA already implements color.Color. If performance is a concern, type matching can be used to check whether c is a color.RGBA and avoid the bit shifts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions