Displayer.SetPixel should use color.Color

オープン
#837 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
go
領域
embedded-iot

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
756
フォーク
251
平均マージ
7日 12時間
マージ済み PR(30日)
8

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tinygo-org/drivers のほかの issue

tinygo-org/drivers の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。