2
* Copyright (C) Research In Motion Limited 2009. All rights reserved.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
23
#include "AffineTransform.h"
24
#include "FloatRect.h"
25
#include "TransformationMatrix.h"
29
VGMatrix::VGMatrix(const VGfloat data[9])
42
VGMatrix::VGMatrix(const AffineTransform& transformation)
44
m_data[0] = transformation.a();
45
m_data[1] = transformation.b();
47
m_data[3] = transformation.c();
48
m_data[4] = transformation.d();
50
m_data[6] = transformation.e();
51
m_data[7] = transformation.f();
55
VGMatrix::VGMatrix(const TransformationMatrix& matrix)
57
m_data[0] = matrix.m11();
58
m_data[1] = matrix.m12();
59
m_data[2] = matrix.m14();
60
m_data[3] = matrix.m21();
61
m_data[4] = matrix.m22();
62
m_data[5] = matrix.m24();
63
m_data[6] = matrix.m41();
64
m_data[7] = matrix.m42();
65
m_data[8] = matrix.m44();
68
VGMatrix::operator AffineTransform() const
70
AffineTransform transformation(
73
m_data[6], m_data[7]);
74
return transformation;
77
VGMatrix::operator TransformationMatrix() const
79
TransformationMatrix matrix(
80
m_data[0], m_data[1], 0, m_data[2],
81
m_data[3], m_data[4], 0, m_data[5],
83
m_data[6], m_data[7], 0, m_data[8]);
87
AffineTransform::operator VGMatrix() const
89
return VGMatrix(*this);
92
TransformationMatrix::operator VGMatrix() const
94
return VGMatrix(*this);
97
VGRect::VGRect(const VGfloat data[4])
105
VGRect::VGRect(const FloatRect& rect)
107
m_data[0] = rect.x();
108
m_data[1] = rect.y();
109
m_data[2] = rect.width();
110
m_data[3] = rect.height();
113
VGRect::operator FloatRect() const
115
return FloatRect(m_data[0], m_data[1], m_data[2], m_data[3]);
118
FloatRect::operator VGRect() const
120
return VGRect(*this);
123
int VGUtils::bytesForImage(VGImageFormat format, VGint width, VGint height)
125
return width * height * imageFormatBitsPerPixel(format) / 8;
128
int VGUtils::bytesForImageScanline(VGImageFormat format, VGint width)
130
int bits = width * imageFormatBitsPerPixel(format);
131
if (bits % 8 > 1) // If unaligned, round up to the next byte.
132
bits += 8 - (bits % 8);
137
int VGUtils::imageFormatBitsPerPixel(VGImageFormat format)
142
case VG_sRGBA_8888_PRE:
145
case VG_lRGBA_8888_PRE:
148
case VG_sARGB_8888_PRE:
151
case VG_lARGB_8888_PRE:
154
case VG_sBGRA_8888_PRE:
157
case VG_lBGRA_8888_PRE:
160
case VG_sABGR_8888_PRE:
163
case VG_lABGR_8888_PRE:
190
default: // Will only happen when OpenVG extends the enum and we don't.
196
#ifndef WTF_PLATFORM_BIG_ENDIAN
197
VGImageFormat VGUtils::endianAwareImageFormat(VGImageFormat bigEndianFormat)
199
switch (bigEndianFormat) {
200
case VG_sRGBX_8888: return VG_sXBGR_8888;
201
case VG_sRGBA_8888: return VG_sABGR_8888;
202
case VG_sRGBA_8888_PRE: return VG_sABGR_8888_PRE;
203
case VG_lRGBX_8888: return VG_lXBGR_8888;
204
case VG_lRGBA_8888: return VG_lABGR_8888;
205
case VG_lRGBA_8888_PRE: return VG_lABGR_8888_PRE;
206
case VG_sXRGB_8888: return VG_sBGRX_8888;
207
case VG_sARGB_8888: return VG_sBGRA_8888;
208
case VG_sARGB_8888_PRE: return VG_sBGRA_8888_PRE;
209
case VG_lXRGB_8888: return VG_lBGRX_8888;
210
case VG_lARGB_8888: return VG_lBGRA_8888;
211
case VG_lARGB_8888_PRE: return VG_lBGRA_8888_PRE;
212
case VG_sBGRX_8888: return VG_sXRGB_8888;
213
case VG_sBGRA_8888: return VG_sARGB_8888;
214
case VG_sBGRA_8888_PRE: return VG_sARGB_8888_PRE;
215
case VG_lBGRX_8888: return VG_lXRGB_8888;
216
case VG_lBGRA_8888: return VG_lARGB_8888;
217
case VG_lBGRA_8888_PRE: return VG_lARGB_8888_PRE;
218
case VG_sXBGR_8888: return VG_sRGBX_8888;
219
case VG_sABGR_8888: return VG_sRGBA_8888;
220
case VG_sABGR_8888_PRE: return VG_sRGBA_8888_PRE;
221
case VG_lXBGR_8888: return VG_lRGBX_8888;
222
case VG_lABGR_8888: return VG_lRGBA_8888;
223
case VG_lABGR_8888_PRE: return VG_lRGBA_8888_PRE;
224
default: ASSERT(false);
225
return (VGImageFormat) 0;
229
VGImageFormat VGUtils::endianAwareImageFormat(VGImageFormat bigEndianFormat)
231
return bigEndianFormat;