English Amiga Board Optimized Alpha-Blending in asm?
 Register Amiga FAQ Rules & Help Members List  /  Moderators List Today's Posts Mark Forums Read

 26 August 2014, 18:24 #21 BigFan Registered User   Join Date: Feb 2014 Location: Germany Posts: 261 Before answering your question, here is a little hint so you might get it by yourself Attached Thumbnails
 26 August 2014, 18:37 #22 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 Seems like I have some greyscale involved where none should be?
 26 August 2014, 18:41 #23 StingRay move.l #\$c0ff33,throat   Join Date: Dec 2005 Location: Berlin/Joymoney Posts: 6,080 As for all the "your routine is not exact" comments, I have used it [ Show youtube player ] and it sure looks correct enough to me!
 26 August 2014, 18:48 #24 Leffmann   Join Date: Jul 2008 Location: Sweden Posts: 2,177 Well, dividing by 256 is not the same as dividing by 255, and neither can you replace something like `x/256` with `x>>8` for arbitrary integers. They are not the same, no matter what you think I think a quick division by 256 is acceptable though, but you should remap the alpha component to the range 0..256 f.ex. by adding 1 if it's greater or equal to 128. This way you eliminate sloppy results where you can't get a fully opaque or fully transparent rendering.
 26 August 2014, 19:58 #25 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 @BigFan I am sorry I do not get the point. What do you mean?
26 August 2014, 20:39   #26
BigFan
Registered User

Join Date: Feb 2014
Location: Germany
Posts: 261
Quote:
 Originally Posted by AGS Seems like I have some greyscale involved where none should be?
Playing jeopardy?

Look at your code. Substraction of integer values result in what exactly (if subtrahend is bigger than minuend)?
You can't just substract two colors (components).
Wrong substraction results in a black rectangle on which same alpha channel is applled then. At best, brightness is reduced on background if background color is the bigger value.

Let's say component1 is foreground with alpha and component2 is background without any alpha (alpha is 255 or 100%) then

r = c1*a/255 + c2*(255-a)/255 // you have to use inverted alpha on background to match correct output

This way you keep brightness at it's correct level.

You might figured out yourself already, that every color channel has to be treated seperately.
I suggest using 255 as divider (biggest value of alpha). If you want to speed up things a little (using shift instead of div when 256 is divider) then add a to product then shift by 8.

hope this helps a bit.

Last edited by BigFan; 26 August 2014 at 20:46. Reason: spelling

 26 August 2014, 20:46 #27 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 Well, I am trying to undestand this. But what I do ist the same what was suggested by the others in this thread (who are sure skilled and won't tell me something wrong). Not? ps: I already am handling each channel separately
26 August 2014, 21:02   #28
Mrs Beanbag
Glastonbridge Software

Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,202
Quote:
 Originally Posted by BigFan r = c1*a/255 + c2*(255-a)/255 // you have to use inverted alpha on background to match correct output

c1*a/255 + c2*(255-a)/255 = c1*a/255 + c2 - c2*a/255

= (c1-c2)*a/255 + c2

this is only basic algebra, the fact that it is colour data makes no difference.

@AGS are you sure there is nothing in the upper byte of the words each time?

@Leffman you can replace x/256 by (x+128) >> 8 for correct rounding

 26 August 2014, 21:14 #29 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 @BigFan This is exactly what you suggest (not optimized): Code: ``` mulu.w d2,d0 divu.w #255,d0 move.w #255,d3 sub.w d2,d3 mulu.w d1,d3 divu.w #255,d3 add.w d3,d0 move.w #255,d3``` I get the same result as with my previous code. @Mrs Beanbag I am sure as far I can see. This is what I use to blend a line of pixels: a0 pic a1 screen d4 pixels width - 1 Code: ```calc_pixels move.w #255,d3 .loop moveq #0,d2 move.b 3(a0),d2 ; alpha moveq #0,d0 moveq #0,d1 move.b (a0)+,d0 move.b (a1),d1 bsr .one move.b d0,(a1)+ moveq #0,d0 moveq #0,d1 move.b (a0)+,d0 move.b (a1),d1 bsr .one move.b d0,(a1)+ moveq #0,d0 moveq #0,d1 move.b (a0)+,d0 move.b (a1),d1 bsr .one move.b d0,(a1)+ addq.l #1,a0 ; skip alpha in source dbf d4,.loop rts .one ; d2 alpha, d0 pic, d1 screen, d3 255 ; d0 -> color sub.w d1,d0 muls.w d2,d0 divs.w d3,d0 add.w d1,d0 rts```
 26 August 2014, 21:22 #30 Mrs Beanbag Glastonbridge Software   Join Date: Jan 2012 Location: Edinburgh/Scotland Posts: 2,202 are you sure that the "correct" image is actually correct? how was it created?
 26 August 2014, 21:26 #31 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 I created it with gimp and here is it: ps: I am using pngalpha.library to extract the alpha info Attached Images
 26 August 2014, 21:36 #32 Mrs Beanbag Glastonbridge Software   Join Date: Jan 2012 Location: Edinburgh/Scotland Posts: 2,202 it seems like something odd is happening to the source image at some point, it's like its background colour is being pre-merged into the RGB with alpha. see if hard-coding a red colour value produces the desired result.
 26 August 2014, 21:47 #33 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 You are right. I had a look on the loaded image data and what I see is exactly what your mention. With a hard coded red the result is what I want.
 26 August 2014, 22:00 #34 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 dtimage.library uses datatypes to retrieve the color information and datatypes probabaly do not what we want. I am going to use a custom png parser.
 26 August 2014, 22:37 #35 Mrs Beanbag Glastonbridge Software   Join Date: Jan 2012 Location: Edinburgh/Scotland Posts: 2,202 you could also, of course, just modify your code to take the effect into account, since now you only need to multiply the destination image with the (1-alpha) value and then simply add the source image on.
 26 August 2014, 22:50 #36 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 I think, this is what you write: Code: ``` ; d2 alpha, d0 pic, d1 screen, d3 255 ; d0 -> color move.w d3,d4 sub.w d2,d4 mulu.w d4,d1 add.w d1,d0``` Produces total chaos here.
 26 August 2014, 23:28 #37 Mrs Beanbag Glastonbridge Software   Join Date: Jan 2012 Location: Edinburgh/Scotland Posts: 2,202 you forgot to divide by 255 Code: ``` move.w d3,d4 sub.w d2,d4 mulu.w d4,d1 divu.w d3,d1 add.w d1,d0```
 26 August 2014, 23:33 #38 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 Works!
 26 August 2014, 23:36 #39 Mrs Beanbag Glastonbridge Software   Join Date: Jan 2012 Location: Edinburgh/Scotland Posts: 2,202 could probably optimise that a little since 255-x = not.b x so Code: `not.b d2` once, and then Code: ``` mulu.w d2,d1 divu d3,d1 add.w d1,d0``` for each colour component
 26 August 2014, 23:40 #40 AGS XoXo/Tasko Developer   Join Date: Dec 2013 Location: Munich Age: 43 Posts: 450 Doesnt really do the trick here as I need d2 staying what it is for all three channels.

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

 Similar Threads Thread Thread Starter Forum Replies Last Post Asman Coders. Asm / Hardware 6 12 October 2013 12:45 Akira support.Apps 17 14 June 2008 00:42 Photon Coders. General 10 11 June 2005 00:54

 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 - Technical     OT - Entertainment     OT - Sports     OT - Gaming

All times are GMT +2. The time now is 05:20.

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