flat assembler
Message board for the users of flat assembler.

Index > Main > how did multiply gray on rgb color ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 12 Feb 2025, 14:32
I have rgb color one byte to channel.
And gray image.

gray DB 255,255,255
rgb DB 1,120,200

gray*rgb result rgb = 1,120,200

gray DB 128,128,128
rgb DB 1,120,200

gray*rgb result rgb = 0,60,100
Post 12 Feb 2025, 14:32
View user's profile Send private message Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 353
Location: Poland
macgub 12 Feb 2025, 14:46
Perhaps something like:
gray = A_r, A_g, A_b
rgb = B_r, B_g, B_b
result = (A_r*B_r) shr 8, (A_g*B_g) shr 8, (A_b*B_b) shr 8
Post 12 Feb 2025, 14:46
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 12 Feb 2025, 15:12
Thanks.
Post 12 Feb 2025, 15:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20517
Location: In your JS exploiting you and your system
revolution 12 Feb 2025, 16:27
Using "shr 8" gives inaccurate results.

Use "/ 255" instead to retain the full resolution.

Compare:
Code:
(255 * 255) shr 8 == 254 <--- off-by-one
(255 * 255) / 255 == 255 <--- correct value    
Post 12 Feb 2025, 16:27
View user's profile Send private message Visit poster's website Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 353
Location: Poland
macgub 13 Feb 2025, 11:42
Thanks for correction.
It can be importand, but for me kind of nuance. For me shr is more convenient to use. But all depends upon concrete implementation.
Post 13 Feb 2025, 11:42
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.