Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(RimeWithWeasel): blend_colors algorithm, fix issue like rime#1405 #1481

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

fxliang
Copy link
Contributor

@fxliang fxliang commented Jan 21, 2025

fix #1405

@lotem
Copy link
Member

lotem commented Jan 22, 2025

這樣 * 2 不會溢出麼?

@lotem
Copy link
Member

lotem commented Jan 22, 2025

原來的代碼就有錯吧。
如果原來的 Alpha 是不透明色 0xFF, 0xFF,按公式算出來就是 (0xFF + 0x7F) % 0x100 = 0x7E,那可不就成了透明的。

@lotem
Copy link
Member

lotem commented Jan 22, 2025

若兩個疊加的顏色都是半透明,則疊加後的透光率爲 0.5 * 0.5 = 0.25,因此 Alpha = 0.75。得這麼算。
但我文科生,數學不好,不知道怎麼優化。

@fxliang
Copy link
Contributor Author

fxliang commented Jan 22, 2025

這樣 * 2 不會溢出麼?

dword 中只有低8位(不大于0xff)有数据离溢出还远着吧

@fxliang
Copy link
Contributor Author

fxliang commented Jan 22, 2025

原來的代碼就有錯吧。 如果原來的 Alpha 是不透明色 0xFF, 0xFF,按公式算出來就是 (0xFF + 0x7F) % 0x100 = 0x7E,那可不就成了透明的。

忘记引入Alpha的时候哪抄的计算,但是结果是如issue那种情况发生,这次干脆强化前景色的Alpha为主这样

@lotem
Copy link
Member

lotem commented Jan 22, 2025

這樣 * 2 不會溢出麼?

dword 中只有低8位(不大于0xff)有数据离溢出还远着吧

不是!RGBA 各佔 8 位!超出範圍,有效數值就取模了!

試試這個算法:有能力的話請優化:

int((1.0 - (1.0 - x.alpha / 255.0) * (1.0 - y.alpha / 255.0)) * 255)

@lotem
Copy link
Member

lotem commented Jan 22, 2025

改之前的 Alpha 算法溢出了。所以顏色變淺。
RGB 的混合算法不會溢出,不過用在 Alpha 上結果不合理。
試想,一個完全不透明,一個完全透明,疊加起來的結果並不是半透明,而是不透明。
兩層半透明的有色玻璃板疊加,結果是更不透明一些。

@fxliang
Copy link
Contributor Author

fxliang commented Jan 22, 2025

改之前的 Alpha 算法溢出了。所以顏色變淺。 RGB 的混合算法不會溢出,不過用在 Alpha 上結果不合理。 試想,一個完全不透明,一個完全透明,疊加起來的結果並不是半透明,而是不透明。 兩層半透明的有色玻璃板疊加,結果是更不透明一些。

改了,目前这个计算方法,试验了下
输入(ABGR) 前景色0x7f0000f0和 背景色0xfff90000,计算得到0xff7c0077
有这两个色前后绘制,然后屏幕截图得到的显示色号是#78007d,基本可以接受的偏差了

@fxliang fxliang requested a review from lotem January 22, 2025 15:07
@lotem
Copy link
Member

lotem commented Jan 22, 2025

厲害。同意。

squirrel 的算法只能混合不透明的顏色。考慮 Alpha 值的話,確實 RGB 也需要加權。

@fxliang fxliang changed the title fix(RimeWithWeasel): make the blended color more visiable fix(RimeWithWeasel): blend_colors algorithm, fix issue like rime#1405 Jan 23, 2025
@fxliang fxliang merged commit 5dbafbb into rime:master Jan 23, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Making the text in highlighted candidate in the "ink" theme more visable
2 participants