Source code: com/anotherbigidea/flash/structs/AlphaTransform.java
1 /****************************************************************
2 * Copyright (c) 2001, David N. Main, All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the
6 * following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 *
17 * 3. The name of the author may not be used to endorse or
18 * promote products derived from this software without specific
19 * prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ****************************************************************/
34 package com.anotherbigidea.flash.structs;
35
36 import java.io.*;
37 import com.anotherbigidea.io.*;
38
39 public class AlphaTransform extends ColorTransform
40 {
41 public double getMultAlpha() { return multAlpha; }
42 public int getAddAlpha() { return addAlpha; }
43
44 public void setMultAlpha( double multAlpha ) { this.multAlpha = multAlpha; }
45 public void setAddAlpha ( int addAlpha ) { this.addAlpha = addAlpha; }
46
47 /**
48 * An identity transform
49 */
50 public AlphaTransform() {}
51
52 /**
53 * Copy another transform
54 */
55 public AlphaTransform( ColorTransform copy )
56 {
57 if( copy == null ) return;
58 this.addRed = copy.addRed;
59 this.addGreen = copy.addGreen;
60 this.addBlue = copy.addBlue;
61 this.addAlpha = copy.addAlpha;
62
63 this.multRed = copy.multRed;
64 this.multGreen = copy.multGreen;
65 this.multBlue = copy.multBlue;
66 this.multAlpha = copy.multAlpha;
67 }
68
69 public AlphaTransform( double multRed, double multGreen, double multBlue,
70 double multAlpha,
71 int addRed, int addGreen, int addBlue,
72 int addAlpha )
73 {
74 super( multRed, multGreen, multBlue, addRed, addGreen, addBlue );
75 this.multAlpha = multAlpha;
76 this.addAlpha = addAlpha;
77 }
78
79 public AlphaTransform( int addRed, int addGreen, int addBlue, int addAlpha )
80 {
81 super( addRed, addGreen, addBlue );
82 this.addAlpha = addAlpha;
83 }
84
85 public AlphaTransform( double multRed, double multGreen, double multBlue,
86 double multAplha )
87 {
88 super( multRed, multGreen, multBlue );
89 this.multAlpha = multAlpha;
90 }
91
92 public AlphaTransform( InStream in ) throws IOException
93 {
94 in.synchBits();
95
96 //--Add and mult are reversed
97 boolean hasAddTerms = ( in.readUBits(1) == 1 );
98 boolean hasMultTerms = ( in.readUBits(1) == 1 );
99
100 int numBits = (int)in.readUBits(4);
101
102 if( hasMultTerms )
103 {
104 multRed = ((double)in.readSBits( numBits ))/256.0;
105 multGreen = ((double)in.readSBits( numBits ))/256.0;
106 multBlue = ((double)in.readSBits( numBits ))/256.0;
107 multAlpha = ((double)in.readSBits( numBits ))/256.0;
108 }
109
110 if( hasAddTerms )
111 {
112 addRed = in.readSBits( numBits );
113 addGreen = in.readSBits( numBits );
114 addBlue = in.readSBits( numBits );
115 addAlpha = in.readSBits( numBits );
116 }
117 }
118
119 public void write( OutStream out ) throws IOException
120 {
121 writeWithAlpha( out );
122 }
123
124 public void writeWithoutAlpha( OutStream out ) throws IOException
125 {
126 super.write( out );
127 }
128
129 public String toString()
130 {
131 return " cxform(+rgba,*rgba)=(" + addRed + "," + addGreen + "," + addBlue
132 + "," + addAlpha + "," + multRed + "," + multGreen + "," +
133 multBlue + "," + multAlpha + ")";
134 }
135 }