English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 11 February 2015, 22:04   #1
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 43
Posts: 450
Image manipulation formulas

Hi,

now I would like to desaturate my Image(s) as a variant of 'ghosting' toolbar icons. I found these formulas:

Code:
ITU-R Recommendation BT.709
l = 0.2125 * r + 0.7154 * g + 0.0721 * b

NTSC and PAL
l = 0.299 * r + 0.587 * g + 0.114 * b

Gray = Green * 0.59 + Blue * 0.11 + Red * 0.30;
I understand the logic behind these but again I have no comma registers. How can I perform these calculations with ASM?

After desaturating I apply more transparence unto them ....
AGS is offline  
Old 11 February 2015, 23:29   #2
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,203
Just multiply with an approximate fraction, f.ex. R*(9/32) + G*(19/32) + B*(4/32)

Code:
lsl.w  #2, D2 ; 4*B

add.w  D0, D2
lsl.w  #3, D0
add.w  D0, D2 ; 9*R + 4*B

add.w  D1, D2
add.w  D1, D1
add.w  D1, D2
lsl.w  #3, D1
add.w  D1, D2  ; 9*R + 19*G + 4*B

lsr.w  #5, D2  ; (9*R + 19*G + 4*B)/32  =  0.28*R + 0.59*G + 0.13*B
It doesn't have to be EXACTLY like the formulas above, it will still look fine on the screen, and you can make the code even faster if you're willing to use other values.

Last edited by Leffmann; 11 February 2015 at 23:38.
Leffmann is online now  
Old 11 February 2015, 23:47   #3
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 43
Posts: 450
Thanks but I yet do not understand what the optimized instructions mean. You use d0 at start ... what is in d0? What is in d2 and in d1?
AGS is offline  
Old 12 February 2015, 00:13   #4
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,203
D0-D2 are the red, green, and blue components. You could just use
mulu.w #19, D1
etc. instead, but this is faster on 68000-68040.
Leffmann is online now  
Old 12 February 2015, 10:13   #5
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL
Posts: 1,653
Go for YCgCo (YCoCg) way simpler for Amiga and fully reversible.
http://en.wikipedia.org/wiki/YCgCo

And desaturation is simple operation - just nullify Cg and Co plane / saturation increase/decrease just apply contrast operator.

Btw - perhaps some simple codec for Amiga around YCgCo?
pandy71 is offline  
Old 12 February 2015, 10:49   #6
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 43
Posts: 450
I implemented Leffmann's idea and everything ist well.
AGS is offline  
Old 12 February 2015, 11:00   #7
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL
Posts: 1,653
Quote:
Originally Posted by AGS View Post
I implemented Leffmann's idea and everything ist well.
Perfect!

But in future it can be better to go for very simple and integer format (should be faster too).

Quote:
Originally Posted by http://sipl.technion.ac.il/new/Archive/Special_Events/H264-2004/H264-FR-Extensions.pdf
YCgCo has the following advantages over
YCbCr:
– Much simpler conversion from RGB (only additions
and shifts)
– Higher coding gain
– If one additional is used for each chroma component,
RGB conversion rounding errors are avoided
– In 4:4:4 color format there’s also a trick to eliminate
conversion rounding errors without the two additional
bits (residual color transform)

Last edited by pandy71; 12 February 2015 at 11:08.
pandy71 is offline  
Old 12 February 2015, 11:08   #8
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 43
Posts: 450
I yet don't understand the formulas in your link. Why should I recode the core of my png library and how?
AGS is offline  
Old 12 February 2015, 12:27   #9
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL
Posts: 1,653
Quote:
Originally Posted by AGS View Post
I yet don't understand the formulas in your link. Why should I recode the core of my png library and how?
Formulas are same as yours only coefficient different and as they are equal 0.5 and 0.25 then simple add and shift can be used.

Gray = Green * 0.5 + Blue * 0.25 + Red * 0.25 or (Green * 2 + Blue + Red)/4

And i'm not forcing you to do anything - you asked how to desaturate (adjust saturation) and provided formula for YCbCr - Y calculations - i pointed that same or even better result can be achieved by use other coefficients in different color space.
Not sure what is your intention - YCoCg is not popular even if have some advantages over YCbCr - people or don't know about YCoCg or they prefer to choose YCbCr as they don't trust YCoCg - i believe that for Amiga where each cycle counts going for YCoCg can be more beneficial than insist to stuck with YCbCr but once again don't know what is your goal...
pandy71 is offline  
Old 12 February 2015, 12:43   #10
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 43
Posts: 450
It's all ok, I just thought your suggestions might bring me an important change in speed and flexibility. My goal is to tune my png library that can load and draw alpha png and now has an option to draw the image in 'ghosted' state.
AGS is offline  
Old 12 February 2015, 14:15   #11
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL
Posts: 1,653
Quote:
Originally Posted by AGS View Post
It's all ok, I just thought your suggestions might bring me an important change in speed and flexibility. My goal is to tune my png library that can load and draw alpha png and now has an option to draw the image in 'ghosted' state.
Well i believe that YCoCg is faster to calculate than YCbCr (especially if you are interested in accurate results) - didn't count how many cycles can be saved but few for sure.
pandy71 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
PC Image to Amiga Image? AF2013 Coders. AMOS 6 21 December 2013 23:36
Anyone know where this image came from, what is it? StoneOakvalley request.Other 4 05 September 2012 10:42
Looking for A game Dealing With Time Manipulation (lots of info) Nuadin Retrogaming General Discussion 4 22 April 2009 12:44
Save Image komunita New to Emulation or Amiga scene 5 16 June 2006 16:28
file manipulation jaypee support.WinUAE 6 01 July 2002 17:18

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 23:34.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.12230 seconds with 13 queries