English Amiga Board


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

 
 
Thread Tools
Old 26 August 2014, 19:24   #21
BigFan
Registered User

BigFan's Avatar
 
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
Click image for larger version

Name:	alpha_test.jpg
Views:	113
Size:	15.7 KB
ID:	41241  
BigFan is offline  
AdSense AdSense  
Old 26 August 2014, 19:37   #22
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
Posts: 450
Seems like I have some greyscale involved where none should be?
AGS is offline  
Old 26 August 2014, 19:41   #23
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,591
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!
StingRay is offline  
Old 26 August 2014, 19:48   #24
Leffmann

 
Join Date: Jul 2008
Location: Sweden
Posts: 2,030
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.
Leffmann is offline  
Old 26 August 2014, 20:58   #25
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
Posts: 450
@BigFan

I am sorry I do not get the point. What do you mean?
AGS is offline  
Old 26 August 2014, 21:39   #26
BigFan
Registered User

BigFan's Avatar
 
Join Date: Feb 2014
Location: Germany
Posts: 261
Quote:
Originally Posted by AGS View Post
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 21:46. Reason: spelling
BigFan is offline  
Old 26 August 2014, 21:46   #27
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
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
AGS is offline  
Old 26 August 2014, 22:02   #28
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,202
Quote:
Originally Posted by BigFan View Post
r = c1*a/255 + c2*(255-a)/255 // you have to use inverted alpha on background to match correct output
we already did this

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
Mrs Beanbag is offline  
Old 26 August 2014, 22:14   #29
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
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
AGS is offline  
Old 26 August 2014, 22:22   #30
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
 
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,202
are you sure that the "correct" image is actually correct? how was it created?
Mrs Beanbag is offline  
Old 26 August 2014, 22:26   #31
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
Posts: 450
I created it with gimp and here is it:

ps: I am using pngalpha.library to extract the alpha info
Attached Images
 
AGS is offline  
Old 26 August 2014, 22:36   #32
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
 
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.
Mrs Beanbag is offline  
Old 26 August 2014, 22:47   #33
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
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.
AGS is offline  
Old 26 August 2014, 23:00   #34
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
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.
AGS is offline  
Old 26 August 2014, 23:37   #35
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
 
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.
Mrs Beanbag is offline  
Old 26 August 2014, 23:50   #36
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
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.
AGS is offline  
Old 27 August 2014, 00:28   #37
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
 
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
Mrs Beanbag is offline  
Old 27 August 2014, 00:33   #38
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
Posts: 450
Works!
AGS is offline  
Old 27 August 2014, 00:36   #39
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
 
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
Mrs Beanbag is offline  
Old 27 August 2014, 00:40   #40
AGS
XoXo/Tasko Developer
AGS's Avatar
 
Join Date: Dec 2013
Location: Munich
Age: 42
Posts: 450
Doesnt really do the trick here as I need d2 staying what it is for all three channels.
AGS is offline  
AdSense AdSense  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tool to convert asm to gnu asm (gas) Asman Coders. Asm / Hardware 6 12 October 2013 13:45
TCP/IP stack: Most optimized//small? Akira support.Apps 17 14 June 2008 01:42
Optimized Protracker playroutine? Photon Coders. General 10 11 June 2005 01: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 Jump


All times are GMT +2. The time now is 11:28.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.20328 seconds with 13 queries