2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "SWFCxForm.h"
25 #include "GnashNumeric.h"
29 // Concatenate SWFCxForm c onto ours. When
30 // transforming colors, c's transform is applied
33 SWFCxForm::concatenate(const SWFCxForm
& c
)
35 // embrace all the overflows intentionally.
36 rb
+= (ra
* c
.rb
>> 8);
37 gb
+= (ga
* c
.gb
>> 8);
38 bb
+= (ba
* c
.bb
>> 8);
39 ab
+= (aa
* c
.ab
>> 8);
49 SWFCxForm::transform(const rgba
& in
) const
51 rgba
result(in
.m_r
, in
.m_g
, in
.m_b
, in
.m_a
);
53 transform(result
.m_r
, result
.m_g
, result
.m_b
, result
.m_a
);
57 // transform the given color with our SWFCxForm.
59 SWFCxForm::transform(boost::uint8_t& r
, boost::uint8_t& g
, boost::uint8_t& b
,
60 boost::uint8_t& a
) const
62 // force conversion to int16 first, kind of optimization.
63 boost::int16_t rt
= r
;
64 boost::int16_t gt
= g
;
65 boost::int16_t bt
= b
;
66 boost::int16_t at
= a
;
68 rt
= (rt
* ra
>> 8) + rb
;
69 gt
= (gt
* ga
>> 8) + gb
;
70 bt
= (bt
* ba
>> 8) + bb
;
71 at
= (at
* aa
>> 8) + ab
;
73 r
= clamp
<boost::int16_t>(rt
, 0, 255);
74 g
= clamp
<boost::int16_t>(gt
, 0, 255);
75 b
= clamp
<boost::int16_t>(bt
, 0, 255);
76 a
= clamp
<boost::int16_t>(at
, 0, 255);
80 operator<<(std::ostream
& os
, const SWFCxForm
& cx
)
82 // For integers up to 256
83 const short fieldWidth
= 3;
87 << "| r: * " << std::setw(fieldWidth
) << cx
.ra
88 << " + " << std::setw(fieldWidth
) << cx
.rb
<< " |"
90 << "| g: * " << std::setw(fieldWidth
) << cx
.ga
91 << " + " << std::setw(fieldWidth
) << cx
.gb
<< " |"
93 << "| b: * " << std::setw(fieldWidth
) << cx
.ba
94 << " + " << std::setw(fieldWidth
) << cx
.bb
<< " |"
96 << "| a: * " << std::setw(fieldWidth
) << cx
.aa
97 << " + " << std::setw(fieldWidth
) << cx
.ab
<< " |";
110 // indent-tabs-mode: t