View Single Post
Old 01 September 2014, 09:53   #1020
Registered User
Join Date: Apr 2005
Location: Hangover
Posts: 2,183
Originally Posted by AGS View Post
Why not? Here is my func. All you have to do is to check if the alpha value you read is $00, then skip the muls and divs! Not? You also can take an alpha value of $FF as a special case where you just copy a pixel.

calc_pixels    ; apply ARGB data onto RGB data
        moveq    #0,d0            ; image
        moveq    #0,d1            ; screen
        moveq    #0,d2            ; alpha
        move.w    #255,d3
.loop        move.b    (a0)+,d2        ; get alpha value
        move.b    (a0)+,d0
        move.b    (a1),d1
        sub.w    d1,d0
        muls.w    d2,d0
        divs.w    d3,d0
        add.w    d1,d0
        move.b    d0,(a1)+
        dbf    d7,.loop
Why not instead of dividing by 255 doing a multiplication with 257 and a simple swap of D0, which means dividing by 65536 ??

1 / 255 = 0,00392156
257 / 65536 = 0,00392150

And you can calculate alpha * 257 just once and re-use it for all three RGB components.
So, you will need only one LSL #8,D2 plus ADD and three MULS.L plus SWAP instructions, but no DIVS.W.

Last edited by PeterK; 01 September 2014 at 10:41.
PeterK is offline  
Page generated in 0.04304 seconds with 10 queries