English Amiga Board Image manipulation formulas
 Register Amiga FAQ Rules & Help Members List  /  Moderators List Today's Posts Mark Forums Read

 11 February 2015, 22:04 #1 AGS XoXo/Tasko Developer   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 ....
 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.
 11 February 2015, 23:47 #3 AGS XoXo/Tasko Developer   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?
 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.
 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?
 12 February 2015, 10:49 #6 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 I implemented Leffmann's idea and everything ist well.
12 February 2015, 11:00   #7
pandy71
Registered User

Join Date: Jun 2010
Location: PL
Posts: 1,653
Quote:
 Originally Posted by AGS 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.

 12 February 2015, 11:08 #8 AGS XoXo/Tasko Developer   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?
12 February 2015, 12:27   #9
pandy71
Registered User

Join Date: Jun 2010
Location: PL
Posts: 1,653
Quote:
 Originally Posted by AGS 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...

 12 February 2015, 12:43 #10 AGS XoXo/Tasko Developer   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.
12 February 2015, 14:15   #11
pandy71
Registered User

Join Date: Jun 2010
Location: PL
Posts: 1,653
Quote:
 Originally Posted by AGS 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.

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

 Similar Threads Thread Thread Starter Forum Replies Last Post AF2013 Coders. AMOS 6 21 December 2013 23:36 StoneOakvalley request.Other 4 05 September 2012 10:42 Nuadin Retrogaming General Discussion 4 22 April 2009 12:44 komunita New to Emulation or Amiga scene 5 16 June 2006 16:28 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News Main     Amiga scene     Retrogaming General Discussion     Nostalgia & memories Support     New to Emulation or Amiga scene         Member Introductions     support.WinUAE     support.WinFellow     support.OtherUAE     support.FS-UAE         project.AmigaLive     support.Hardware         Hardware mods         Hardware pics     support.Games     support.Demos     support.Apps     support.Amiga Forever     support.Amix     support.Other Requests     request.UAE Wishlist     request.Old Rare Games     request.Demos     request.Apps     request.Modules     request.Music     request.Other     Looking for a game name ?     Games images which need to be WHDified abime.net - Hall Of Light     HOL news     HOL suggestions and feedback     HOL data problems     HOL contributions abime.net - Amiga Magazine Rack     AMR news     AMR suggestions and feedback     AMR data problems     AMR contributions abime.net - Home Projects     project.Amiga Lore     project.EAB     project.IRC     project.Mods Jukebox     project.Wiki abime.net - Hosted Projects     project.aGTW     project.APoV     project.ClassicWB     project.Jambo!     project.Green Amiga Alien GUIDES     project.Maptapper     project.Sprites     project.WinUAE - Kaillera Other Projects     project.Amiga Demo DVD     project.Amiga Game Factory     project.CARE     project.EAB File Server     project.CD32 Conversion     project.Game Cover Art         GCA.Feedback and Suggestions         GCA.Work in Progress         GCA.Cover Requests         GCA.Usefull Programs         GCA.Helpdesk     project.KGLoad     project.MAGE     project.Missing Full Shareware Games     project.SPS (was CAPS)     project.TOSEC (amiga only)     project.WHDLoad         project.Killergorilla's WHD packs Misc     Amiga websites reviews     MarketPlace         Swapshop     Collections     EAB's competition Coders     Coders. General         Coders. Releases         Coders. Tutorials     Coders. Asm / Hardware     Coders. System         Coders. Scripting         Coders. Nextgen     Coders. Language         Coders. C/C++         Coders. AMOS         Coders. Blitz Basic     Coders. Contest         Coders. Entries Off Topic     OT - General     OT - Entertainment     OT - Sports     OT - Technical     OT - Gaming

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

 -- EAB3 skin ---- EAB2 skin ---- Mobile skin Archive - Top