reduce verbosity
[gnash.git] / libcore / SWFCxForm.cpp
blob1197d530cd717839568008d1f1723bfb8b5cffa4
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // Foundation, Inc
4 //
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.
9 //
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.
14 //
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"
21 #include <iomanip>
23 #include "RGBA.h"
24 #include "log.h"
25 #include "GnashNumeric.h"
27 namespace gnash {
29 // Concatenate SWFCxForm c onto ours. When
30 // transforming colors, c's transform is applied
31 // first, then ours.
32 void
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);
41 ra = ra * c.ra >> 8;
42 ga = ga * c.ga >> 8;
43 ba = ba * c.ba >> 8;
44 aa = aa * c.aa >> 8;
48 rgba
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);
54 return result;
57 // transform the given color with our SWFCxForm.
58 void
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);
79 std::ostream&
80 operator<<(std::ostream& os, const SWFCxForm& cx)
82 // For integers up to 256
83 const short fieldWidth = 3;
86 << std::endl
87 << "| r: * " << std::setw(fieldWidth) << cx.ra
88 << " + " << std::setw(fieldWidth) << cx.rb << " |"
89 << std::endl
90 << "| g: * " << std::setw(fieldWidth) << cx.ga
91 << " + " << std::setw(fieldWidth) << cx.gb << " |"
92 << std::endl
93 << "| b: * " << std::setw(fieldWidth) << cx.ba
94 << " + " << std::setw(fieldWidth) << cx.bb << " |"
95 << std::endl
96 << "| a: * " << std::setw(fieldWidth) << cx.aa
97 << " + " << std::setw(fieldWidth) << cx.ab << " |";
99 return os;
103 } // namespace gnash
106 // Local Variables:
107 // mode: C++
108 // c-basic-offset: 8
109 // tab-width: 8
110 // indent-tabs-mode: t
111 // End: