Displayer.SetPixel should use color.Color

Abierto
#837 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
go
Área
embedded-iot

Línea de trabajo

Start by locating the Displayer interface and its SetPixel implementations across the drivers repository. Review how each device converts or handles color values, then assess the impact of changing the interface to accept color.Color. Done means the interface and affected drivers consistently support the proposed color input; the issue does not name specific files or tests.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Go
Estrellas
756
Forks
251
Merge medio
7 d 12 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tinygo-org/drivers

Todos los issues de tinygo-org/drivers

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.