Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset b22b449d in mainline


Ignore:
Timestamp:
2017-02-26T20:02:29Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial
Children:
5b46ec8
Parents:
443a0bc
Message:

Alpha compositing does not need floating point.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/softrend/compose.c

    r443a0bc rb22b449d  
    5353pixel_t compose_over(pixel_t fg, pixel_t bg)
    5454{
    55         double mul;
    56         double mul_cmp;
     55        uint16_t mf;
     56        uint16_t mb;
    5757
    58         double res_a;
    59         double res_r;
    60         double res_g;
    61         double res_b;
     58        uint8_t res_a;
     59        uint8_t res_r;
     60        uint8_t res_g;
     61        uint8_t res_b;
    6262
    63         if (ALPHA(bg) == 255) {
    64                 res_a = 1;
    65                 mul = ((double) ALPHA(fg)) / 255.0;
    66                 mul_cmp = 1 - mul;
    67         } else {
    68                 double fg_a = ((double) ALPHA(fg)) / 255.0;
    69                 double bg_a = ((double) ALPHA(bg)) / 255.0;
     63        res_a = (ALPHA(fg) * 255 + (255 - ALPHA(fg)) * ALPHA(bg)) / 255;
     64        mf = ALPHA(fg);
     65        mb = (255 * 255 - ALPHA(fg) * ALPHA(bg)) / 255;
    7066
    71                 res_a = 1 - (1 - fg_a) * (1 - bg_a);
    72                 mul = fg_a / res_a;
    73                 mul_cmp = 1 - mul;
    74         }
     67        res_r = (mf * RED(fg) + mb * RED(bg)) / 255;
     68        res_g = (mf * GREEN(fg) + mb * GREEN(bg)) / 255;
     69        res_b = (mf * BLUE(fg) + mb * BLUE(bg)) / 255;
    7570
    76         res_r = mul * ((double) RED(fg)) + mul_cmp * ((double) RED(bg));
    77         res_g = mul * ((double) GREEN(fg)) + mul_cmp * ((double) GREEN(bg));
    78         res_b = mul * ((double) BLUE(fg)) + mul_cmp * ((double) BLUE(bg));
    79 
    80         return PIXEL((unsigned) (res_a * 255),
    81             (unsigned) res_r, (unsigned) res_g, (unsigned) res_b);
     71        return PIXEL(res_a, res_r, res_g, res_b);
    8272}
    8373
Note: See TracChangeset for help on using the changeset viewer.