gfx/cairo/libpixman/src/make-combine.pl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 $usage = "Usage: combine.pl { 8 | 16 } < pixman-combine.c.template";
michael@0 2
michael@0 3 $#ARGV == 0 or die $usage;
michael@0 4
michael@0 5 # Get the component size.
michael@0 6 $size = int($ARGV[0]);
michael@0 7 $size == 8 or $size == 16 or die $usage;
michael@0 8
michael@0 9 $pixel_size = $size * 4;
michael@0 10 $half_pixel_size = $size * 2;
michael@0 11
michael@0 12 sub mask {
michael@0 13 my $str = shift;
michael@0 14 my $suffix;
michael@0 15 $suffix = "ULL" if $size > 8;
michael@0 16
michael@0 17 return "0x" . $str . $suffix;
michael@0 18 }
michael@0 19
michael@0 20 # Generate mask strings.
michael@0 21 $nibbles = $size / 4;
michael@0 22 $mask = "f" x $nibbles;
michael@0 23 $zero_mask = "0" x $nibbles;
michael@0 24 $one_half = "8" . "0" x ($nibbles - 1);
michael@0 25
michael@0 26 print "/* WARNING: This file is generated by combine.pl from combine.inc.\n";
michael@0 27 print " Please edit one of those files rather than this one. */\n";
michael@0 28 print "\n";
michael@0 29
michael@0 30 print "#line 1 \"pixman-combine.c.template\"\n";
michael@0 31
michael@0 32 $mask_ = mask($mask);
michael@0 33 $one_half_ = mask($one_half);
michael@0 34 $g_mask = mask($mask . $zero_mask);
michael@0 35 $b_mask = mask($mask . $zero_mask x 2);
michael@0 36 $a_mask = mask($mask . $zero_mask x 3);
michael@0 37 $rb_mask = mask($mask . $zero_mask . $mask);
michael@0 38 $ag_mask = mask($mask . $zero_mask . $mask . $zero_mask);
michael@0 39 $rb_one_half = mask($one_half . $zero_mask . $one_half);
michael@0 40 $rb_mask_plus_one = mask("1" . $zero_mask x 2 . "1" . $zero_mask);
michael@0 41
michael@0 42 while (<STDIN>) {
michael@0 43 # Mask and 1/2 value for a single component.
michael@0 44 s/#define COMPONENT_SIZE\b/$& $size/;
michael@0 45 s/#define MASK\b/$& $mask_/;
michael@0 46 s/#define ONE_HALF\b/$& $one_half_/;
michael@0 47
michael@0 48 # Shifts and masks for green, blue, and alpha.
michael@0 49 s/#define G_SHIFT\b/$& $size/;
michael@0 50 s/#define R_SHIFT\b/$& $size * 2/;
michael@0 51 s/#define A_SHIFT\b/$& $size * 3/;
michael@0 52 s/#define G_MASK\b/$& $g_mask/;
michael@0 53 s/#define R_MASK\b/$& $b_mask/;
michael@0 54 s/#define A_MASK\b/$& $a_mask/;
michael@0 55
michael@0 56 # Special values for dealing with red + blue at the same time.
michael@0 57 s/#define RB_MASK\b/$& $rb_mask/;
michael@0 58 s/#define AG_MASK\b/$& $ag_mask/;
michael@0 59 s/#define RB_ONE_HALF\b/$& $rb_one_half/;
michael@0 60 s/#define RB_MASK_PLUS_ONE\b/$& $rb_mask_plus_one/;
michael@0 61
michael@0 62 # Add 32/64 suffix to combining function types.
michael@0 63 s/\bCombineFunc\b/CombineFunc$pixel_size/;
michael@0 64 s/\bFbComposeFunctions\b/FbComposeFunctions$pixel_size/;
michael@0 65 s/combine_width/combine_$pixel_size/;
michael@0 66 s/_pixman_setup_combiner_functions_width/_pixman_setup_combiner_functions_$pixel_size/;
michael@0 67 s/UNc/UN$size/g;
michael@0 68 s/ALPHA_c/ALPHA_$size/g;
michael@0 69 s/RED_c/RED_$size/g;
michael@0 70 s/GREEN_c/GREEN_$size/g;
michael@0 71 s/BLUE_c/BLUE_$size/g;
michael@0 72
michael@0 73 # Convert comp*_t values into the appropriate real types.
michael@0 74 s/comp1_t/uint${size}_t/g;
michael@0 75 s/comp2_t/uint${half_pixel_size}_t/g;
michael@0 76 s/comp4_t/uint${pixel_size}_t/g;
michael@0 77
michael@0 78 # Change the function table name for the 64-bit version.
michael@0 79 s/pixman_composeFunctions/pixman_composeFunctions64/ if $size == 16;
michael@0 80
michael@0 81 # Change the header for the 64-bit version
michael@0 82 s/pixman-combine.h/pixman-combine64.h/ if $size == 16;
michael@0 83 s/pixman-combine.h/pixman-combine32.h/ if $size == 8;
michael@0 84
michael@0 85 print;
michael@0 86 }

mercurial