michael@0: $usage = "Usage: combine.pl { 8 | 16 } < pixman-combine.c.template"; michael@0: michael@0: $#ARGV == 0 or die $usage; michael@0: michael@0: # Get the component size. michael@0: $size = int($ARGV[0]); michael@0: $size == 8 or $size == 16 or die $usage; michael@0: michael@0: $pixel_size = $size * 4; michael@0: $half_pixel_size = $size * 2; michael@0: michael@0: sub mask { michael@0: my $str = shift; michael@0: my $suffix; michael@0: $suffix = "ULL" if $size > 8; michael@0: michael@0: return "0x" . $str . $suffix; michael@0: } michael@0: michael@0: # Generate mask strings. michael@0: $nibbles = $size / 4; michael@0: $mask = "f" x $nibbles; michael@0: $zero_mask = "0" x $nibbles; michael@0: $one_half = "8" . "0" x ($nibbles - 1); michael@0: michael@0: print "/* WARNING: This file is generated by combine.pl from combine.inc.\n"; michael@0: print " Please edit one of those files rather than this one. */\n"; michael@0: print "\n"; michael@0: michael@0: print "#line 1 \"pixman-combine.c.template\"\n"; michael@0: michael@0: $mask_ = mask($mask); michael@0: $one_half_ = mask($one_half); michael@0: $g_mask = mask($mask . $zero_mask); michael@0: $b_mask = mask($mask . $zero_mask x 2); michael@0: $a_mask = mask($mask . $zero_mask x 3); michael@0: $rb_mask = mask($mask . $zero_mask . $mask); michael@0: $ag_mask = mask($mask . $zero_mask . $mask . $zero_mask); michael@0: $rb_one_half = mask($one_half . $zero_mask . $one_half); michael@0: $rb_mask_plus_one = mask("1" . $zero_mask x 2 . "1" . $zero_mask); michael@0: michael@0: while () { michael@0: # Mask and 1/2 value for a single component. michael@0: s/#define COMPONENT_SIZE\b/$& $size/; michael@0: s/#define MASK\b/$& $mask_/; michael@0: s/#define ONE_HALF\b/$& $one_half_/; michael@0: michael@0: # Shifts and masks for green, blue, and alpha. michael@0: s/#define G_SHIFT\b/$& $size/; michael@0: s/#define R_SHIFT\b/$& $size * 2/; michael@0: s/#define A_SHIFT\b/$& $size * 3/; michael@0: s/#define G_MASK\b/$& $g_mask/; michael@0: s/#define R_MASK\b/$& $b_mask/; michael@0: s/#define A_MASK\b/$& $a_mask/; michael@0: michael@0: # Special values for dealing with red + blue at the same time. michael@0: s/#define RB_MASK\b/$& $rb_mask/; michael@0: s/#define AG_MASK\b/$& $ag_mask/; michael@0: s/#define RB_ONE_HALF\b/$& $rb_one_half/; michael@0: s/#define RB_MASK_PLUS_ONE\b/$& $rb_mask_plus_one/; michael@0: michael@0: # Add 32/64 suffix to combining function types. michael@0: s/\bCombineFunc\b/CombineFunc$pixel_size/; michael@0: s/\bFbComposeFunctions\b/FbComposeFunctions$pixel_size/; michael@0: s/combine_width/combine_$pixel_size/; michael@0: s/_pixman_setup_combiner_functions_width/_pixman_setup_combiner_functions_$pixel_size/; michael@0: s/UNc/UN$size/g; michael@0: s/ALPHA_c/ALPHA_$size/g; michael@0: s/RED_c/RED_$size/g; michael@0: s/GREEN_c/GREEN_$size/g; michael@0: s/BLUE_c/BLUE_$size/g; michael@0: michael@0: # Convert comp*_t values into the appropriate real types. michael@0: s/comp1_t/uint${size}_t/g; michael@0: s/comp2_t/uint${half_pixel_size}_t/g; michael@0: s/comp4_t/uint${pixel_size}_t/g; michael@0: michael@0: # Change the function table name for the 64-bit version. michael@0: s/pixman_composeFunctions/pixman_composeFunctions64/ if $size == 16; michael@0: michael@0: # Change the header for the 64-bit version michael@0: s/pixman-combine.h/pixman-combine64.h/ if $size == 16; michael@0: s/pixman-combine.h/pixman-combine32.h/ if $size == 8; michael@0: michael@0: print; michael@0: }