~eda-qa/dhlib/main

« back to all changes in this revision

Viewing changes to lib/flashx/filter/Color.hx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* <license>
 
2
 * This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
 
3
 * For full copyright and license information please refer to doc/license.txt.
 
4
 * </license> 
 
5
 */
 
6
package flashx.filter;
 
7
 
 
8
import flash.filters.ColorMatrixFilter;
 
9
 
 
10
/**
 
11
 * A series of helpers to create Color filters
 
12
 */
 
13
class Color
 
14
{
 
15
        /**
 
16
         * This performs a pseudo-grayscale conversion, that is, based
 
17
         * on the average intensity of the pixels -- since there is no filter
 
18
         * to do true grayscale (based on max or min value of the pixels)
 
19
         */
 
20
        static public function grayscale( ) : ColorMatrixFilter
 
21
        {
 
22
                var matrix = [
 
23
                        1.0/3, 1.0/3, 1.0/3, 0,0, // red
 
24
                1.0/3, 1.0/3, 1.0/3, 0,0, // green
 
25
                1.0/3, 1.0/3, 1.0/3, 0,0, // blue
 
26
                0, 0, 0, 1.0,0 // alpha
 
27
                ];
 
28
        return new ColorMatrixFilter( matrix );
 
29
        }
 
30
        
 
31
        static public function rgb( r  : Float, g : Float, b : Float ) : ColorMatrixFilter
 
32
        {
 
33
                var matrix = [
 
34
                        r*1.0/3, r*1.0/3, r*1.0/3, 0,0, // red
 
35
                g*1.0/3, g*1.0/3, g*1.0/3, 0,0, // green
 
36
                b*1.0/3, b*1.0/3, b*1.0/3, 0,0, // blue
 
37
                0, 0, 0, 1.0,0 // alpha
 
38
                ];
 
39
        return new ColorMatrixFilter( matrix );
 
40
        }
 
41
        
 
42
        /**
 
43
         * Like rgb but only applies at a certain level (That is, only partially colorizes)
 
44
         *
 
45
         * @param t [in] 0 <= t <= 1 for level of tinge
 
46
         */
 
47
        static public function rgbTinge( r  : Float, g : Float, b : Float, t : Float ) : ColorMatrixFilter
 
48
        {
 
49
                var ts = 1.0/3 * t;
 
50
                var tp = 1 - t;
 
51
                
 
52
                var matrix = [
 
53
                        tp + r*ts, r*ts, r*ts, 0,0, // red
 
54
                g*ts, tp + g*ts, g*ts, 0,0, // green
 
55
                b*ts, b*1.0/3, tp + b*ts, 0,0, // blue
 
56
                0, 0, 0, 1.0,0 // alpha
 
57
                ];
 
58
        return new ColorMatrixFilter( matrix );
 
59
        }
 
60
}