aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt87
-rw-r--r--license.txt53
-rw-r--r--readme.txt263
-rw-r--r--ri/include/EGL/egl.h329
-rw-r--r--ri/include/EGL/egl.h.org318
-rw-r--r--ri/include/EGL/eglext.h539
-rw-r--r--ri/include/EGL/eglplatform.h122
-rw-r--r--ri/include/EGL/fbdev_window.h52
-rw-r--r--ri/include/KHR/khrplatform.h273
-rw-r--r--ri/include/VG/openvg.h746
-rw-r--r--ri/include/VG/vgext.h233
-rw-r--r--ri/include/VG/vgplatform.h106
-rw-r--r--ri/include/VG/vgu.h131
-rw-r--r--ri/openvg_ri.dsp203
-rw-r--r--ri/src/linux/riEGLOS.cpp170
-rw-r--r--ri/src/macosx/riEGLOS.cpp409
-rw-r--r--ri/src/null/riEGLOS.cpp160
-rw-r--r--ri/src/riApi.cpp3665
-rw-r--r--ri/src/riArray.h211
-rw-r--r--ri/src/riContext.cpp329
-rw-r--r--ri/src/riContext.h277
-rw-r--r--ri/src/riDefs.h142
-rw-r--r--ri/src/riFont.cpp203
-rw-r--r--ri/src/riFont.h116
-rw-r--r--ri/src/riImage.cpp2674
-rw-r--r--ri/src/riImage.h379
-rw-r--r--ri/src/riMath.cpp75
-rw-r--r--ri/src/riMath.h382
-rw-r--r--ri/src/riMiniEGL.cpp2132
-rw-r--r--ri/src/riPath.cpp2579
-rw-r--r--ri/src/riPath.h188
-rw-r--r--ri/src/riPixelPipe.cpp894
-rw-r--r--ri/src/riPixelPipe.h155
-rw-r--r--ri/src/riRasterizer.cpp499
-rw-r--r--ri/src/riRasterizer.h173
-rw-r--r--ri/src/riVGU.cpp469
-rw-r--r--ri/src/win32/riEGLOS.cpp379
-rw-r--r--samples/samples.dsp98
-rw-r--r--samples/samples.dsw44
-rw-r--r--samples/tiger/main.c471
-rw-r--r--samples/tiger/tiger.c1952
-rw-r--r--samples/tiger/tiger.h45
42 files changed, 22725 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..42d31ac
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,87 @@
+cmake_minimum_required(VERSION 2.8)
+
+# Project Options:
+
+
+set(PROJECT_NAME_STR OpenVG)
+set(VG_LIBRARY_NAME_STR ${PROJECT_NAME_STR})
+set(VGU_LIBRARY_NAME_STR ${PROJECT_NAME_STR}U)
+set(MINIEGL_LIBRARY_NAME_STR MiniEGL)
+project($(PROJECT_NAME_STR))
+
+MESSAGE(STATUS "Project : Khronos OpenVG reference implement Library")
+
+
+
+SET(DEFAULT_DEV_INSTALL_DIR /opt/openvg)
+MESSAGE(STATUS "Install path is ${CMAKE_INSTALL_PREFIX}")
+
+# choose target
+if(TARGET)
+ if(${TARGET} STREQUAL "arm")
+ message ("Building for ${TARGET} with fb\n")
+ set(EGL_LIB_PATH "\"/usr/lib/libEGL.so\"")
+# INCLUDE_DIRECTORIES(/root/Mali_OpenGL_ES_SDK_v2.4.0/inc/EGL)
+# INCLUDE_DIRECTORIES(/root/Mali_OpenGL_ES_SDK_v2.4.0/inc)
+ elseif(${TARGET} STREQUAL "x86")
+ message ("Building for ${TARGET}\n")
+ set(EGL_LIB_PATH "\"/usr/lib/x86_64-linux-gnu/mesa-egl/libEGL.so\"")
+ INCLUDE_DIRECTORIES(/usr/include/EGL)
+ set(CMAKE_C_FLAGS "-DMESA_EGL_NO_X11_HEADERS")
+ set(CMAKE_CXX_FLAGS "-DMESA_EGL_NO_X11_HEADERS -fpermissive")
+ else()
+ MESSAGE(FATAL_ERROR "Target ${TARGET} is not valid. Choices are \"x86\" and \"arm\".")
+ endif()
+else(TARGET)
+ message ("TARGET was not set. Choices are \"x86\" and \"arm\".")
+ message ("Example usage: cmake .. -DTARGET=arm")
+ message ("Now using [arm] as default.\n")
+ set (TARGET "arm")
+ message ("Building for ${TARGET}\n")
+ set(EGL_LIB_PATH "\"/usr/lib/libEGL.so\"")
+
+endif(TARGET)
+message ("EGL PATH:${EGL_LIB_PATH} \n")
+add_definitions( -DEGLLIB=${EGL_LIB_PATH} )
+message ("PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}\n")
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/ri/src)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/ri/include)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/ri/include/EGL)
+INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/ri/include/VG)
+
+
+#LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/src)
+
+set(VG_SOURCEFILES
+ ri/src/riApi.cpp
+ ri/src/riContext.cpp
+ ri/src/riFont.cpp
+ ri/src/riImage.cpp
+ ri/src/riMath.cpp
+ ri/src/riPath.cpp
+ ri/src/riPixelPipe.cpp
+ ri/src/riRasterizer.cpp
+ ri/src/riVGU.cpp
+ ri/src/riMiniEGL.cpp
+ )
+
+set(VGU_SOURCEFILES
+ ri/src/riVGU.cpp
+ ri/src/riMiniEGL.cpp
+ )
+
+set(MINIEGL_SOURCEFILES
+ ri/src/riMiniEGL.cpp
+ ri/src/linux/riEGLOS.cpp
+ ri/src/riMiniEGL.cpp
+ )
+
+#set(SOURCEFILES ${RI_SOURCES} ri/src/null/riEGLOS.cpp)
+message ("VG_SOURCEFILES = ${VG_SOURCEFILES}\n")
+message ("VGU_SOURCEFILES = ${VGU_SOURCEFILES}\n")
+add_library(${VG_LIBRARY_NAME_STR} SHARED ${VG_SOURCEFILES})
+
+add_library(${VGU_LIBRARY_NAME_STR} SHARED ${VGU_SOURCEFILES})
+#target_link_libraries(${PROJECT_NAME_STR})
+
+add_library(${MINIEGL_LIBRARY_NAME_STR} SHARED ${MINIEGL_SOURCEFILES})
diff --git a/license.txt b/license.txt
new file mode 100644
index 0000000..5a6729d
--- /dev/null
+++ b/license.txt
@@ -0,0 +1,53 @@
+OpenVG 1.1 Reference Implementation
+-----------------------------------
+
+Copyright (c) 2007 The Khronos Group Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and /or associated documentation files
+(the "Materials "), to deal in the Materials without restriction,
+including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Materials,
+and to permit persons to whom the Materials are furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Materials.
+
+THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+THE USE OR OTHER DEALINGS IN THE MATERIALS.
+
+
+Path data for the Tiger sample program has been extracted from Ghostscript's
+tiger.eps example file distributed under GNU General Public License.
+
+Ghostscript's License document:
+" The files in the src, lib, toolbin, examples, doc and man
+ directories (folders) and any subdirectories (sub-folders)
+ thereof are part of GPL Ghostscript.
+
+ The files in the Resource directory and any subdirectories thereof
+ are also part of GPL Ghostscript, with the explicit exception of
+ the files in the CMap subdirectory. The CMap files are copyright
+ Adobe Systems Incorporated and covered by a separate license
+ which permits only verbatim distribution.
+
+ GPL Ghostscript is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ GPL Ghostscript is distributed in the hope that it will be
+ useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program so you can know your rights and responsibilities.
+ It should be in a file named doc/COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place Suite 330, Boston, MA
+ 02111-1307, USA."
diff --git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..6845e24
--- /dev/null
+++ b/readme.txt
@@ -0,0 +1,263 @@
+OpenVG 1.1 Reference Implementation
+-----------------------------------
+
+Copyright (c) 2007 The Khronos Group Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and /or associated documentation files
+(the "Materials "), to deal in the Materials without restriction,
+including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Materials,
+and to permit persons to whom the Materials are furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Materials.
+
+THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+THE USE OR OTHER DEALINGS IN THE MATERIALS.
+
+
+Version
+-------
+Official RI for OpenVG 1.1
+Released: May 13, 2008
+
+
+Release Notes
+-------------
+
+This release is based on OpenVG 1.1 and EGL 1.3 specifications.
+This release is Windows-only, although the source code
+compiles at least on Mac OS X 10.5 and Cygwin. Project files are
+provided for MSVC 6.
+
+This archive contains sources for OpenVG RI, VGU and EGL. There's
+also a precompiled libOpenVG.dll that contains OpenVG and EGL implementations.
+
+
+Package Structure
+-----------------
+
+bin
+ win32
+ libOpenVG.dll OpenVG Windows .dll
+ tiger.exe Windows executable of the Tiger sample
+lib
+ libOpenVG.lib MSVC 6 dll import library
+ri
+ openvg_ri.dsp MSVC 6 project file for libOpenVG.dll
+ src .cpp and .h -files of the reference implementation
+ win32 Windows backend for EGL
+ macosx Mac OS X backend for EGL
+ null null backend for EGL
+ include Public OpenVG and EGL headers
+ EGL
+ egl.h
+ VG
+ openvg.h
+ vgu.h
+samples
+ samples.dsw MSVC 6 workspace file for tiger sample and libOpenVG.dll
+ samples.dsp MSVC 6 project file for tiger.exe
+ tiger
+ main.c
+ tiger.c
+ tiger.h
+readme.txt
+license.txt
+
+
+Samples
+-------
+
+Tiger
+
+The release contains a sample application that renders an image of a
+tiger. Note that the sample doesn't start immediately, since it takes
+a few seconds to render the image. Resizing the window rerenders the
+image in the new resolution.
+
+
+Known Issues
+------------
+
+-EGL functionality is incomplete (some functions lack proper error checking, some
+ attribs may not be processed, etc.)
+-When opening samples.dsw, MSVC may complain about missing Perforce connection. Just
+ ignore that.
+
+
+Changes
+-------
+
+Nov 25, 2008
+-Clamp color transform scale to [-127, 127] and bias to [-1, 1]
+
+May 13, 2008
+- Changed 8 sample MSAA configs into 32 sample configs
+- Changed max gaussian std deviation to 16 (was 128)
+- VG_DRAW_IMAGE_MULTIPLY converts luminance to RGB if either paint or image color is RGB
+- Fixes A40102 by storing input floats as is
+
+February 12, 2008
+- fixed arc transformation.
+- fixed point along path corner cases.
+- partially fixed A40102 by not filtering invalid float input.
+
+December 12, 2007
+- fixed an overflow bug in vgFillMaskLayer error handling.
+- increased accuracy for Gaussian blur. The new code avoids an infinite loop with a very small std dev.
+- fixed a bug in Font::find that caused deleted fonts to be returned.
+
+November 20, 2007
+- reimplemented 1,2 & 4 bits per pixel images
+- fixed vgGetParameter for paint
+- fixed https://cvs.khronos.org/bugzilla/show_bug.cgi?id=1095 RI handling of child images with shared storage
+ -vgGetParent: return closest valid ancestor, or image itself if no ancestor was found.
+- EGL refactoring & clean up
+- divided OS native parts of EGL into separate files that should be included in that platform's build
+- added a generic OS backend for EGL (not thread safe, no window rendering)
+- fixed https://cvs.khronos.org/bugzilla/show_bug.cgi?id=1943 RI does not handle channel mask correctly for lL/sL/BW1
+- removed EGL_IMAGE_IN_USE_ERROR from vgDrawGlyph(s)
+- added configs without an alpha mask to facilitate CTS reference image creation
+- implemented more accurate stroking by rendering each stroke part into a coverage buffer and compositing from there
+ -fixes https://cvs.khronos.org/bugzilla/show_bug.cgi?id=2221 RI errors at end of curved strokes.
+- bugfix: joins used path midpoints, interpolateStroke and caps didn't => seams (visible in some G60101 cases)
+- vgCreateMaskLayer returns VG_INVALID_HANDLE if the current surface doesn't have a mask layer
+- vgRenderToMask bugfix: temp buffer is now cleared between fill and stroke
+- bugfix: vgCreateImage returns an error if allowedQuality is zero
+- bugfix: vgSetPaint returns an error if paintModes is zero
+- bugfix: vgCreateFont doesn't return an error if capacityHint is zero
+- bugfix: writeFilteredPixel writes also into luminance formats
+
+October 12, 2007
+-Upgrade to OpenVG 1.1, including
+ -Implemented MSAA, added 4 and 8 sample EGLConfigs
+ -Implemented VG_A_4 and VG_A_1 image formats and EGLConfigs
+ -Implemented Glyph API
+ -Implemented new masking functions
+ -Implemented color transform
+-Implemented native EGL backends for Windows & Mac OS X => Fix for bugzilla 1376 RI uses non-standard EGL implementation
+ *RI now works with CTS generation's native_w32.c (native_ri.c can be removed).
+ *dependency on GLUT has been removed. GLUT code is still included and can be compiled in instead of native by defining RI_USE_GLUT.
+-16 bit EGLConfigs now expose 4 mask bits, 8 bit configs 8, 4 bit configs 4, and 1 bit configs 1. MSAA configs expose one bit per sample.
+-EGL now works with any display, not just EGL_DEFAULT_DISPLAY
+-Simplification: removed code to handle less than 8 bits per pixel. Smaller bit depths always allocate 8 bits per pixel.
+-Changed rasterizer data types to RScalar and RVector2 so that it's possible to alter RIfloat precision without affecting rasterization.
+-Accuracy: increased circularLerp precision
+-Bugfix: matrix inversion now checks if the input matrix is affine and forces the inverted matrix to be affine as well
+-Bugfix: fixed eglCopyBuffers (copied from dst to dst)
+-Bugfix: fixed eglCreatePixmapSurface (allowed only VG_sRGBA_8888, didn't give an error if config had more than one sample per pixel)
+-Bugfix: bugzilla 2465: RI asserts when setting maximum amount of gradient stops
+
+February 27, 2007
+-changed to MIT open source license.
+-bugfix, bugzilla 820: RGB and luminance are now treated as different color spaces.
+-bugfix, bugzilla 1094/1095: vgGetParent now returns the input image in case its parent is already destroyed.
+
+December 1, 2006
+-bugfix, bugzilla 649: allowed image quality is now taken into account when deciding resampling filter.
+-bugfix, bugzilla 650, bad stroking accuracy reported by TK Chan and Mika Tuomi: curve tessellation is now increased from 64 to 256. RI_MAX_EDGES has been increased from 100000 to 262144 to facilitate the increased number of edges.
+-bugfix, reported by Chris Wynn, affects I30206: degenerate gradients in repeat mode now render the first stop color instead of the last one.
+-changed float to RIfloat, added an option to compile RIfloat into a class to test reduced precision float ops
+
+September 6, 2006
+-bugfix, bugzilla 591: CLOSE_PATH followed by a MOVE_TO doesn't produce an extra end cap anymore
+-abs values of arc axis lengths are taken only just before rendering
+-undefined bits of bitfields are now ignored in the API
+
+September 1, 2006
+-changed colorToInt to use mathematical round-to-nearest as recommended by new language in section 3.4.4.
+-implemented VG_PAINT_COLOR_RAMP_PREMULTIPLIED
+-implemented VG_STROKE_DASH_PHASE_RESET
+-implemented new language for filter channelMasks (section 11.2)
+-tangents returned by vgPointAlongPath are now normalized
+-implemented VG_MAX_GAUSSIAN_STD_DEVIATION, rewrote Gaussian blur code
+-vgGetString: if no context, return NULL. VG_VERSION returns the spec version (1.0).
+-bugfix, bugzilla 542: vgSeparableConvolve now convolves the edge color with the horizontal kernel and uses that as the edge color for the vertical pass
+-ellipse rh and rv are replaced by their absolute values whenever read for processing, the absolute values are not written into the path data
+
+August 18, 2006
+-bugfix, M30301: the arguments for vguComputeWarpQuadToQuad were the wrong way around, destination should come before source.
+-bugfix, M10102: check for degeneracy in vguComputeWarpSquareToQuad is done before the affinity check so that degenerate affine matrices also produce the bad warp error
+-bugfix, bugzilla 491: Chris Wynn's vgComputeWarpSquareToQuad -case. There was a wrong mapping between vertices, (1,1) was mapped to (dx2,dy2)
+-bugfix, bugzilla 519: vguPolygon wrong error check. vguPolygon didn't have an error check for the count argument
+-bugfix, bugzilla 518: vgGetParameterfv/iv wrong errors. vgGetParametrtfv/iv error checking was for count < 0 instead of count <= 0.
+-bugfix, bugzilla 517: wrong cap flag checked in vgPathTransformedBounds
+-bugfix, bugzilla 494: egl.h has wrong values for OPENVG_BIT and OPENGL_ES_BIT. Copied the enumerations from the 1.3 egl.h on the Khronos site (OpenKode/egl/egl.h)
+-bugfix, bugzilla 492: gradient filter window was biased
+-bugfix: when appending paths, there was a loop over coordinates to replace arc axis lengths by their absolute values. However, if the path wasn't empty, the loop accessed wrong coordinates. Fixes: Qingping Zhang's cases 2&3.
+-bugfix: image filter write mask was ignored when writing to VG_A_8 images. Fixes: Qingping Zhang's case 13.
+-bugfix: if image filter processing format is premultiplied, color channels are clamped to alpha before conversion to destination format
+-bugfix: in eglReleaseThread the EGL instance was freed when its reference count reached zero, but the pointer wasn't made NULL, causing the use of uninitialized instance.
+-bugfix: vgClearImage didn't clamp the clear color to [0,1] range
+-bugfix: a zero-length dash at a path vertex produces a join
+-bugfix: vgSetParameter now checks paramType for all object types
+-bugfix: convolution filters incorrectly restricted the area read from the source image to the intersection of source and destination image sizes
+-bugfix: EGL surface creation now defaults correctly to EGL_COLOR_SPACE_sRGB
+-antialiasing is done in the linear color space as the spec recommends.
+-image filters clamp the result to [0,1] range.
+-Color::pack and Color::convert assert that their input is in [0,1] range
+-in case a projective transform is used, VGImageMode is always VG_DRAW_IMAGE_NORMAL
+-the default value for VG_FILTER_FORMAT_LINEAR is now VG_FALSE
+-added Matrix::isAffine for easy affinity check
+-Color::clamp clamps color channels to alpha for premultiplied colors
+-VG_BLEND_LIGHTEN: color channels cannot exceed alpha anymore
+-RI now supports flexible pixel formats. Any bit depth for RGBA is now supported.
+-eglGetProcAddress is now properly implemented, it returns a function pointer for eglSetConfigPreferenceHG extension
+-eglQueryString now returns "eglSetConfigPreferenceHG" for EGL_EXTENSIONS
+-location of egl.h in RI. use EGL/egl.h, VG/openvg.h, VG/vgu.h
+-OpenVG 1.0.1 spec changes
+ +use the latest openvg.h
+ +2.8: AA happens in linear space
+ +3.4: alpha channel depth of zero results in alpha=1 when read
+ +4.1: return VG_NO_CONTEXT_ERROR from vgGetError in case no context is current
+ +5.1: VG_SCREEN_LAYOUT (default = screen layout of the display)
+ +5.2, 5.3: vgSet, vgGet, vgSetParameter, vgGetParameter: handling of invalid values of count
+ +5.2.1: new default for VG_FILTER_FORMAT_LINEAR is VG_FALSE
+ +8.5.3: get rid of VG_PATH_DATATYPE_INVALID and VG_IMAGE_FORMAT_INVALID enums
+ +10.2: get rid of old extension image formats, add the official ones
+ +10.5: when reading/writing pixels, clamp color channels to [0, alpha]
+ +10.8: when a projective transform is used, always use VG_DRAW_IMAGE_NORMAL mode
+ +10.8: VG_DRAW_IMAGE_MULTIPLY: if color spaces of paint and image don't match, no conversion takes place, result is in image color space
+ +12.4: clamp the result of additive blend to [0,1]
+
+October 20, 2005
+-Gradients are filtered to avoid aliasing
+-Subpaths that ended with a close path segment were capped and joined incorrectly. Fixed.
+-Alpha mask was allocated per context, not per EGL surface. Fixed.
+
+August 22, 2005
+-Updated to spec amendment
+-Fixed bugs
+-Implemented eglChooseConfig and eglReleaseThread
+
+July 22, 2005
+-Updated to 18th July 2005 version of the OpenVG 1.0 spec.
+-Updated to 20th July 2005 version of the EGL 1.2 spec.
+-Fixed bugs.
+-openvg.h, vgu.h and egl.h are now contained in include/vg directory.
+
+May 4, 2005
+-Updated to April 26th 2005 version of the OpenVG 1.0 spec.
+-Can share images, paths, and paint between contexts.
+-Fixed path tangent computation.
+-Implemented image filters.
+-Fixed bugs.
+-Changed directory structure a bit.
+
+March 29, 2005
+-Updated to March 28th 2005 version of the OpenVG 1.0 spec.
+-Changed rasterizer to use 32 samples per pixel in the high quality
+ mode (renders faster at the expense of some aliasing).
+-EGL allocates sRGB rendering surfaces.
+-Includes GLUT dll against which tiger.exe was linked.
+
+March 24, 2005
+-Initial release.
diff --git a/ri/include/EGL/egl.h b/ri/include/EGL/egl.h
new file mode 100644
index 0000000..99ea342
--- /dev/null
+++ b/ri/include/EGL/egl.h
@@ -0,0 +1,329 @@
+/* -*- mode: c; tab-width: 8; -*- */
+/* vi: set sw=4 ts=8: */
+/* Reference version of egl.h for EGL 1.4.
+ * $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $
+ */
+
+/*
+** Copyright (c) 2007-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+#ifndef __egl_h_
+#define __egl_h_
+
+/* All platform-dependent types and macro boilerplate (such as EGLAPI
+ * and EGLAPIENTRY) should go in eglplatform.h.
+ */
+#include <EGL/eglplatform.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* EGL Types */
+/* EGLint is defined in eglplatform.h */
+typedef unsigned int EGLBoolean;
+typedef unsigned int EGLenum;
+typedef void *EGLConfig;
+typedef void *EGLContext;
+typedef void *EGLDisplay;
+typedef void *EGLSurface;
+typedef void *EGLClientBuffer;
+
+/* EGL Versioning */
+#define EGL_VERSION_1_0 1
+#define EGL_VERSION_1_1 1
+#define EGL_VERSION_1_2 1
+#define EGL_VERSION_1_3 1
+#define EGL_VERSION_1_4 1
+
+/* EGL Enumerants. Bitmasks and other exceptional cases aside, most
+ * enums are assigned unique values starting at 0x3000.
+ */
+
+/* EGL aliases */
+#define EGL_FALSE 0
+#define EGL_TRUE 1
+
+/* Out-of-band handle values */
+#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
+#define EGL_NO_CONTEXT ((EGLContext)0)
+#define EGL_NO_DISPLAY ((EGLDisplay)0)
+#define EGL_NO_SURFACE ((EGLSurface)0)
+
+/* Out-of-band attribute value */
+#define EGL_DONT_CARE ((EGLint)-1)
+
+/* Errors / GetError return values */
+#define EGL_SUCCESS 0x3000
+#define EGL_NOT_INITIALIZED 0x3001
+#define EGL_BAD_ACCESS 0x3002
+#define EGL_BAD_ALLOC 0x3003
+#define EGL_BAD_ATTRIBUTE 0x3004
+#define EGL_BAD_CONFIG 0x3005
+#define EGL_BAD_CONTEXT 0x3006
+#define EGL_BAD_CURRENT_SURFACE 0x3007
+#define EGL_BAD_DISPLAY 0x3008
+#define EGL_BAD_MATCH 0x3009
+#define EGL_BAD_NATIVE_PIXMAP 0x300A
+#define EGL_BAD_NATIVE_WINDOW 0x300B
+#define EGL_BAD_PARAMETER 0x300C
+#define EGL_BAD_SURFACE 0x300D
+#define EGL_CONTEXT_LOST 0x300E /* EGL 1.1 - IMG_power_management */
+
+/* Reserved 0x300F-0x301F for additional errors */
+
+/* Config attributes */
+#define EGL_BUFFER_SIZE 0x3020
+#define EGL_ALPHA_SIZE 0x3021
+#define EGL_BLUE_SIZE 0x3022
+#define EGL_GREEN_SIZE 0x3023
+#define EGL_RED_SIZE 0x3024
+#define EGL_DEPTH_SIZE 0x3025
+#define EGL_STENCIL_SIZE 0x3026
+#define EGL_CONFIG_CAVEAT 0x3027
+#define EGL_CONFIG_ID 0x3028
+#define EGL_LEVEL 0x3029
+#define EGL_MAX_PBUFFER_HEIGHT 0x302A
+#define EGL_MAX_PBUFFER_PIXELS 0x302B
+#define EGL_MAX_PBUFFER_WIDTH 0x302C
+#define EGL_NATIVE_RENDERABLE 0x302D
+#define EGL_NATIVE_VISUAL_ID 0x302E
+#define EGL_NATIVE_VISUAL_TYPE 0x302F
+#define EGL_SAMPLES 0x3031
+#define EGL_SAMPLE_BUFFERS 0x3032
+#define EGL_SURFACE_TYPE 0x3033
+#define EGL_TRANSPARENT_TYPE 0x3034
+#define EGL_TRANSPARENT_BLUE_VALUE 0x3035
+#define EGL_TRANSPARENT_GREEN_VALUE 0x3036
+#define EGL_TRANSPARENT_RED_VALUE 0x3037
+#define EGL_NONE 0x3038 /* Attrib list terminator */
+#define EGL_BIND_TO_TEXTURE_RGB 0x3039
+#define EGL_BIND_TO_TEXTURE_RGBA 0x303A
+#define EGL_MIN_SWAP_INTERVAL 0x303B
+#define EGL_MAX_SWAP_INTERVAL 0x303C
+#define EGL_LUMINANCE_SIZE 0x303D
+#define EGL_ALPHA_MASK_SIZE 0x303E
+#define EGL_COLOR_BUFFER_TYPE 0x303F
+#define EGL_RENDERABLE_TYPE 0x3040
+#define EGL_MATCH_NATIVE_PIXMAP 0x3041 /* Pseudo-attribute (not queryable) */
+#define EGL_CONFORMANT 0x3042
+
+/* Reserved 0x3041-0x304F for additional config attributes */
+
+/* Config attribute values */
+#define EGL_SLOW_CONFIG 0x3050 /* EGL_CONFIG_CAVEAT value */
+#define EGL_NON_CONFORMANT_CONFIG 0x3051 /* EGL_CONFIG_CAVEAT value */
+#define EGL_TRANSPARENT_RGB 0x3052 /* EGL_TRANSPARENT_TYPE value */
+#define EGL_RGB_BUFFER 0x308E /* EGL_COLOR_BUFFER_TYPE value */
+#define EGL_LUMINANCE_BUFFER 0x308F /* EGL_COLOR_BUFFER_TYPE value */
+
+/* More config attribute values, for EGL_TEXTURE_FORMAT */
+#define EGL_NO_TEXTURE 0x305C
+#define EGL_TEXTURE_RGB 0x305D
+#define EGL_TEXTURE_RGBA 0x305E
+#define EGL_TEXTURE_2D 0x305F
+
+/* Config attribute mask bits */
+#define EGL_PBUFFER_BIT 0x0001 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_PIXMAP_BIT 0x0002 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_WINDOW_BIT 0x0004 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_MULTISAMPLE_RESOLVE_BOX_BIT 0x0200 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_SWAP_BEHAVIOR_PRESERVED_BIT 0x0400 /* EGL_SURFACE_TYPE mask bits */
+
+#define EGL_OPENGL_ES_BIT 0x0001 /* EGL_RENDERABLE_TYPE mask bits */
+#define EGL_OPENVG_BIT 0x0002 /* EGL_RENDERABLE_TYPE mask bits */
+#define EGL_OPENGL_ES2_BIT 0x0004 /* EGL_RENDERABLE_TYPE mask bits */
+#define EGL_OPENGL_BIT 0x0008 /* EGL_RENDERABLE_TYPE mask bits */
+
+/* QueryString targets */
+#define EGL_VENDOR 0x3053
+#define EGL_VERSION 0x3054
+#define EGL_EXTENSIONS 0x3055
+#define EGL_CLIENT_APIS 0x308D
+
+/* QuerySurface / SurfaceAttrib / CreatePbufferSurface targets */
+#define EGL_HEIGHT 0x3056
+#define EGL_WIDTH 0x3057
+#define EGL_LARGEST_PBUFFER 0x3058
+#define EGL_TEXTURE_FORMAT 0x3080
+#define EGL_TEXTURE_TARGET 0x3081
+#define EGL_MIPMAP_TEXTURE 0x3082
+#define EGL_MIPMAP_LEVEL 0x3083
+#define EGL_RENDER_BUFFER 0x3086
+#define EGL_VG_COLORSPACE 0x3087
+#define EGL_VG_ALPHA_FORMAT 0x3088
+#define EGL_HORIZONTAL_RESOLUTION 0x3090
+#define EGL_VERTICAL_RESOLUTION 0x3091
+#define EGL_PIXEL_ASPECT_RATIO 0x3092
+#define EGL_SWAP_BEHAVIOR 0x3093
+#define EGL_MULTISAMPLE_RESOLVE 0x3099
+
+/* EGL_RENDER_BUFFER values / BindTexImage / ReleaseTexImage buffer targets */
+#define EGL_BACK_BUFFER 0x3084
+#define EGL_SINGLE_BUFFER 0x3085
+
+/* OpenVG color spaces */
+#define EGL_VG_COLORSPACE_sRGB 0x3089 /* EGL_VG_COLORSPACE value */
+#define EGL_VG_COLORSPACE_LINEAR 0x308A /* EGL_VG_COLORSPACE value */
+
+/* OpenVG alpha formats */
+#define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B /* EGL_ALPHA_FORMAT value */
+#define EGL_VG_ALPHA_FORMAT_PRE 0x308C /* EGL_ALPHA_FORMAT value */
+
+/* Constant scale factor by which fractional display resolutions &
+ * aspect ratio are scaled when queried as integer values.
+ */
+#define EGL_DISPLAY_SCALING 10000
+
+/* Unknown display resolution/aspect ratio */
+#define EGL_UNKNOWN ((EGLint)-1)
+
+/* Back buffer swap behaviors */
+#define EGL_BUFFER_PRESERVED 0x3094 /* EGL_SWAP_BEHAVIOR value */
+#define EGL_BUFFER_DESTROYED 0x3095 /* EGL_SWAP_BEHAVIOR value */
+
+/* CreatePbufferFromClientBuffer buffer types */
+#define EGL_OPENVG_IMAGE 0x3096
+
+/* QueryContext targets */
+#define EGL_CONTEXT_CLIENT_TYPE 0x3097
+
+/* CreateContext attributes */
+#define EGL_CONTEXT_CLIENT_VERSION 0x3098
+
+/* Multisample resolution behaviors */
+#define EGL_MULTISAMPLE_RESOLVE_DEFAULT 0x309A /* EGL_MULTISAMPLE_RESOLVE value */
+#define EGL_MULTISAMPLE_RESOLVE_BOX 0x309B /* EGL_MULTISAMPLE_RESOLVE value */
+
+/* BindAPI/QueryAPI targets */
+#define EGL_OPENGL_ES_API 0x30A0
+#define EGL_OPENVG_API 0x30A1
+#define EGL_OPENGL_API 0x30A2
+
+/* GetCurrentSurface targets */
+#define EGL_DRAW 0x3059
+#define EGL_READ 0x305A
+
+/* WaitNative engines */
+#define EGL_CORE_NATIVE_ENGINE 0x305B
+
+/* EGL 1.2 tokens renamed for consistency in EGL 1.3 */
+#define EGL_COLORSPACE EGL_VG_COLORSPACE
+#define EGL_ALPHA_FORMAT EGL_VG_ALPHA_FORMAT
+#define EGL_COLORSPACE_sRGB EGL_VG_COLORSPACE_sRGB
+#define EGL_COLORSPACE_LINEAR EGL_VG_COLORSPACE_LINEAR
+#define EGL_ALPHA_FORMAT_NONPRE EGL_VG_ALPHA_FORMAT_NONPRE
+#define EGL_ALPHA_FORMAT_PRE EGL_VG_ALPHA_FORMAT_PRE
+
+/* EGL extensions must request enum blocks from the Khronos
+ * API Registrar, who maintains the enumerant registry. Submit
+ * a bug in Khronos Bugzilla against task "Registry".
+ */
+
+
+
+/* EGL Functions */
+
+EGLAPI EGLint EGLAPIENTRY eglGetError(void);
+
+EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id);
+EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor);
+EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy);
+
+EGLAPI const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name);
+
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
+ EGLint config_size, EGLint *num_config);
+EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list,
+ EGLConfig *configs, EGLint config_size,
+ EGLint *num_config);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
+ EGLint attribute, EGLint *value);
+
+EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
+ EGLNativeWindowType win,
+ const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
+ const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
+ EGLNativePixmapType pixmap,
+ const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
+ EGLint attribute, EGLint *value);
+
+EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api);
+EGLAPI EGLenum EGLAPIENTRY eglQueryAPI(void);
+
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void);
+
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void);
+
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer(
+ EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer,
+ EGLConfig config, const EGLint *attrib_list);
+
+EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
+ EGLint attribute, EGLint value);
+EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+
+
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval);
+
+
+EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config,
+ EGLContext share_context,
+ const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx);
+EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw,
+ EGLSurface read, EGLContext ctx);
+
+EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void);
+EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, EGLContext ctx,
+ EGLint attribute, EGLint *value);
+
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine);
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, EGLSurface surface,
+ EGLNativePixmapType target);
+
+/* This is a generic function pointer type, whose name indicates it must
+ * be cast to the proper type *and calling convention* before use.
+ */
+typedef void (*__eglMustCastToProperFunctionPointerType)(void);
+
+/* Now, define eglGetProcAddress using the generic function ptr. type */
+EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY
+ eglGetProcAddress(const char *procname);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __egl_h_ */
diff --git a/ri/include/EGL/egl.h.org b/ri/include/EGL/egl.h.org
new file mode 100644
index 0000000..c95dfc9
--- /dev/null
+++ b/ri/include/EGL/egl.h.org
@@ -0,0 +1,318 @@
+#ifndef __egl_h_
+#define __egl_h_
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief EGL 1.3 API.
+ *//*-------------------------------------------------------------------*/
+
+/* All platform-dependent types and macro boilerplate (such as EGLAPI
+ * and EGLAPIENTRY) should go in eglplatform.h.
+ */
+/*#include <EGL/eglplatform.h>*/
+
+/* Platform-specific types and definitions for egl.h */
+
+#ifndef __eglplatform_h_
+#define __eglplatform_h_
+
+#define EGLAPIENTRY /* empty */
+
+#if defined(EGL_STATIC_LIBRARY)
+# define EGLAPI
+#else
+# if defined(_WIN32) || defined(__VC32__) /* Win32 */
+# if defined (OPENVG_DLL_EXPORTS)
+# define EGLAPI __declspec(dllexport)
+# else
+# define EGLAPI __declspec(dllimport)
+# endif
+# elif defined(__APPLE__) /* Mac OS X */
+# define EGLAPI extern
+# endif
+#endif /* defined(EGL_STATIC_LIBRARY) */
+
+typedef struct
+{
+ int format; /*VGImageFormat cast to int*/
+ int width;
+ int height;
+ int stride; /*in bytes*/
+ void* data;
+} NativePixmap;
+
+typedef void* NativeDisplayType;
+typedef void* NativeWindowType;
+typedef NativePixmap* NativePixmapType;
+
+/* EGL 1.2 types, renamed for consistency in EGL 1.3 */
+typedef NativeDisplayType EGLNativeDisplayType;
+typedef NativePixmapType EGLNativePixmapType;
+typedef NativeWindowType EGLNativeWindowType;
+
+#endif /* __eglplatform_h */
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* EGL Types */
+typedef int EGLint; /* NOTE: official EGL 1.3 header defines this as int32_t */
+typedef unsigned int EGLBoolean;
+typedef unsigned int EGLenum;
+typedef void* EGLConfig;
+typedef void* EGLContext;
+typedef void* EGLDisplay;
+typedef void* EGLSurface;
+typedef void* EGLClientBuffer;
+
+/* EGL Versioning */
+#define EGL_VERSION_1_0 1
+#define EGL_VERSION_1_1 1
+#define EGL_VERSION_1_2 1
+#define EGL_VERSION_1_3 1
+
+/* EGL Enumerants. Bitmasks and other exceptional cases aside, most
+ * enums are assigned unique values starting at 0x3000.
+ */
+
+/* EGL aliases */
+#define EGL_FALSE 0
+#define EGL_TRUE 1
+
+/* Out-of-band handle values */
+#define EGL_DEFAULT_DISPLAY ((void *)0)
+#define EGL_NO_CONTEXT ((EGLContext)0)
+#define EGL_NO_DISPLAY ((EGLDisplay)0)
+#define EGL_NO_SURFACE ((EGLSurface)0)
+
+/* Out-of-band attribute value */
+#define EGL_DONT_CARE ((EGLint)-1)
+
+/* Errors / GetError return values */
+#define EGL_SUCCESS 0x3000
+#define EGL_NOT_INITIALIZED 0x3001
+#define EGL_BAD_ACCESS 0x3002
+#define EGL_BAD_ALLOC 0x3003
+#define EGL_BAD_ATTRIBUTE 0x3004
+#define EGL_BAD_CONFIG 0x3005
+#define EGL_BAD_CONTEXT 0x3006
+#define EGL_BAD_CURRENT_SURFACE 0x3007
+#define EGL_BAD_DISPLAY 0x3008
+#define EGL_BAD_MATCH 0x3009
+#define EGL_BAD_NATIVE_PIXMAP 0x300A
+#define EGL_BAD_NATIVE_WINDOW 0x300B
+#define EGL_BAD_PARAMETER 0x300C
+#define EGL_BAD_SURFACE 0x300D
+#define EGL_CONTEXT_LOST 0x300E /* EGL 1.1 - IMG_power_management */
+
+/* Reserved 0x300F-0x301F for additional errors */
+
+/* Config attributes */
+#define EGL_BUFFER_SIZE 0x3020
+#define EGL_ALPHA_SIZE 0x3021
+#define EGL_BLUE_SIZE 0x3022
+#define EGL_GREEN_SIZE 0x3023
+#define EGL_RED_SIZE 0x3024
+#define EGL_DEPTH_SIZE 0x3025
+#define EGL_STENCIL_SIZE 0x3026
+#define EGL_CONFIG_CAVEAT 0x3027
+#define EGL_CONFIG_ID 0x3028
+#define EGL_LEVEL 0x3029
+#define EGL_MAX_PBUFFER_HEIGHT 0x302A
+#define EGL_MAX_PBUFFER_PIXELS 0x302B
+#define EGL_MAX_PBUFFER_WIDTH 0x302C
+#define EGL_NATIVE_RENDERABLE 0x302D
+#define EGL_NATIVE_VISUAL_ID 0x302E
+#define EGL_NATIVE_VISUAL_TYPE 0x302F
+#define EGL_PRESERVED_RESOURCES 0x3030
+#define EGL_SAMPLES 0x3031
+#define EGL_SAMPLE_BUFFERS 0x3032
+#define EGL_SURFACE_TYPE 0x3033
+#define EGL_TRANSPARENT_TYPE 0x3034
+#define EGL_TRANSPARENT_BLUE_VALUE 0x3035
+#define EGL_TRANSPARENT_GREEN_VALUE 0x3036
+#define EGL_TRANSPARENT_RED_VALUE 0x3037
+#define EGL_NONE 0x3038 /* Attrib list terminator */
+#define EGL_BIND_TO_TEXTURE_RGB 0x3039
+#define EGL_BIND_TO_TEXTURE_RGBA 0x303A
+#define EGL_MIN_SWAP_INTERVAL 0x303B
+#define EGL_MAX_SWAP_INTERVAL 0x303C
+#define EGL_LUMINANCE_SIZE 0x303D
+#define EGL_ALPHA_MASK_SIZE 0x303E
+#define EGL_COLOR_BUFFER_TYPE 0x303F
+#define EGL_RENDERABLE_TYPE 0x3040
+#define EGL_MATCH_NATIVE_PIXMAP 0x3041 /* Pseudo-attribute (not queryable) */
+#define EGL_CONFORMANT 0x3042
+#define EGL_CONFORMANT_KHR EGL_CONFORMANT
+
+/* Reserved 0x3041-0x304F for additional config attributes */
+
+/* Config attribute values */
+#define EGL_SLOW_CONFIG 0x3050 /* EGL_CONFIG_CAVEAT value */
+#define EGL_NON_CONFORMANT_CONFIG 0x3051 /* EGL_CONFIG_CAVEAT value */
+#define EGL_TRANSPARENT_RGB 0x3052 /* EGL_TRANSPARENT_TYPE value */
+#define EGL_RGB_BUFFER 0x308E /* EGL_COLOR_BUFFER_TYPE value */
+#define EGL_LUMINANCE_BUFFER 0x308F /* EGL_COLOR_BUFFER_TYPE value */
+
+/* More config attribute values, for EGL_TEXTURE_FORMAT */
+#define EGL_NO_TEXTURE 0x305C
+#define EGL_TEXTURE_RGB 0x305D
+#define EGL_TEXTURE_RGBA 0x305E
+#define EGL_TEXTURE_2D 0x305F
+
+/* Config attribute mask bits */
+#define EGL_PBUFFER_BIT 0x0001 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_PIXMAP_BIT 0x0002 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_WINDOW_BIT 0x0004 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_VG_COLORSPACE_LINEAR_BIT 0x0020 /* EGL_SURFACE_TYPE mask bits */
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT 0x0040 /* EGL_SURFACE_TYPE mask bits */
+
+#define EGL_OPENGL_ES_BIT 0x0001 /* EGL_RENDERABLE_TYPE mask bits */
+#define EGL_OPENVG_BIT 0x0002 /* EGL_RENDERABLE_TYPE mask bits */
+#define EGL_OPENGL_ES2_BIT 0x0004 /* EGL_RENDERABLE_TYPE mask bits */
+
+/* QueryString targets */
+#define EGL_VENDOR 0x3053
+#define EGL_VERSION 0x3054
+#define EGL_EXTENSIONS 0x3055
+#define EGL_CLIENT_APIS 0x308D
+
+/* QuerySurface / CreatePbufferSurface targets */
+#define EGL_HEIGHT 0x3056
+#define EGL_WIDTH 0x3057
+#define EGL_LARGEST_PBUFFER 0x3058
+#define EGL_TEXTURE_FORMAT 0x3080
+#define EGL_TEXTURE_TARGET 0x3081
+#define EGL_MIPMAP_TEXTURE 0x3082
+#define EGL_MIPMAP_LEVEL 0x3083
+#define EGL_RENDER_BUFFER 0x3086
+#define EGL_VG_COLORSPACE 0x3087
+#define EGL_VG_ALPHA_FORMAT 0x3088
+#define EGL_HORIZONTAL_RESOLUTION 0x3090
+#define EGL_VERTICAL_RESOLUTION 0x3091
+#define EGL_PIXEL_ASPECT_RATIO 0x3092
+#define EGL_SWAP_BEHAVIOR 0x3093
+
+/* EGL_RENDER_BUFFER values / BindTexImage / ReleaseTexImage buffer targets */
+#define EGL_BACK_BUFFER 0x3084
+#define EGL_SINGLE_BUFFER 0x3085
+
+/* OpenVG color spaces */
+#define EGL_VG_COLORSPACE_sRGB 0x3089 /* EGL_VG_COLORSPACE value */
+#define EGL_VG_COLORSPACE_LINEAR 0x308A /* EGL_VG_COLORSPACE value */
+
+/* OpenVG alpha formats */
+#define EGL_VG_ALPHA_FORMAT_NONPRE 0x308B /* EGL_ALPHA_FORMAT value */
+#define EGL_VG_ALPHA_FORMAT_PRE 0x308C /* EGL_ALPHA_FORMAT value */
+
+/* Constant scale factor by which fractional display resolutions &
+ * aspect ratio are scaled when queried as integer values.
+ */
+#define EGL_DISPLAY_SCALING 10000
+
+/* Unknown display resolution/aspect ratio */
+#define EGL_UNKNOWN ((EGLint)-1)
+
+/* Back buffer swap behaviors */
+#define EGL_BUFFER_PRESERVED 0x3094 /* EGL_SWAP_BEHAVIOR value */
+#define EGL_BUFFER_DESTROYED 0x3095 /* EGL_SWAP_BEHAVIOR value */
+
+/* CreatePbufferFromClientBuffer buffer types */
+#define EGL_OPENVG_IMAGE 0x3096
+
+/* QueryContext targets */
+#define EGL_CONTEXT_CLIENT_TYPE 0x3097
+
+/* CreateContext attributes */
+#define EGL_CONTEXT_CLIENT_VERSION 0x3098
+
+/* BindAPI/QueryAPI targets */
+#define EGL_OPENGL_ES_API 0x30A0
+#define EGL_OPENVG_API 0x30A1
+
+/* GetCurrentSurface targets */
+#define EGL_DRAW 0x3059
+#define EGL_READ 0x305A
+
+/* WaitNative engines */
+#define EGL_CORE_NATIVE_ENGINE 0x305B
+
+/* EGL 1.2 tokens renamed for consistency in EGL 1.3 */
+#define EGL_COLORSPACE EGL_VG_COLORSPACE
+#define EGL_ALPHA_FORMAT EGL_VG_ALPHA_FORMAT
+#define EGL_COLORSPACE_sRGB EGL_VG_COLORSPACE_sRGB
+#define EGL_COLORSPACE_LINEAR EGL_VG_COLORSPACE_LINEAR
+#define EGL_ALPHA_FORMAT_NONPRE EGL_VG_ALPHA_FORMAT_NONPRE
+#define EGL_ALPHA_FORMAT_PRE EGL_VG_ALPHA_FORMAT_PRE
+
+
+/* EGL Functions */
+
+EGLAPI EGLint EGLAPIENTRY eglGetError(void);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id);
+EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor);
+EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy);
+EGLAPI const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
+EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api);
+EGLAPI EGLenum EGLAPIENTRY eglQueryAPI(void);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitClient(void);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseThread(void);
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value);
+EGLAPI EGLBoolean EGLAPIENTRY eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval);
+EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx);
+EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
+EGLAPI EGLContext EGLAPIENTRY eglGetCurrentContext(void);
+EGLAPI EGLSurface EGLAPIENTRY eglGetCurrentSurface(EGLint readdraw);
+EGLAPI EGLDisplay EGLAPIENTRY eglGetCurrentDisplay(void);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void);
+EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine);
+EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface);
+EGLAPI EGLBoolean EGLAPIENTRY eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
+EGLAPI void (* EGLAPIENTRY eglGetProcAddress(const char *procname))(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __egl_h_ */
diff --git a/ri/include/EGL/eglext.h b/ri/include/EGL/eglext.h
new file mode 100644
index 0000000..8e9e610
--- /dev/null
+++ b/ri/include/EGL/eglext.h
@@ -0,0 +1,539 @@
+#ifndef __eglext_h_
+#define __eglext_h_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+** Copyright (c) 2007-2012 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+#include <EGL/eglplatform.h>
+
+/*************************************************************/
+
+/* Header file version number */
+/* Current version at http://www.khronos.org/registry/egl/ */
+/* $Revision: 19987 $ on $Date: 2012-12-13 16:46:46 -0800 (Thu, 13 Dec 2012) $ */
+#define EGL_EGLEXT_VERSION 14
+
+#ifndef EGL_KHR_config_attribs
+#define EGL_KHR_config_attribs 1
+#define EGL_CONFORMANT_KHR 0x3042 /* EGLConfig attribute */
+#define EGL_VG_COLORSPACE_LINEAR_BIT_KHR 0x0020 /* EGL_SURFACE_TYPE bitfield */
+#define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR 0x0040 /* EGL_SURFACE_TYPE bitfield */
+#endif
+
+#ifndef EGL_KHR_lock_surface
+#define EGL_KHR_lock_surface 1
+#define EGL_READ_SURFACE_BIT_KHR 0x0001 /* EGL_LOCK_USAGE_HINT_KHR bitfield */
+#define EGL_WRITE_SURFACE_BIT_KHR 0x0002 /* EGL_LOCK_USAGE_HINT_KHR bitfield */
+#define EGL_LOCK_SURFACE_BIT_KHR 0x0080 /* EGL_SURFACE_TYPE bitfield */
+#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100 /* EGL_SURFACE_TYPE bitfield */
+#define EGL_MATCH_FORMAT_KHR 0x3043 /* EGLConfig attribute */
+#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0 /* EGL_MATCH_FORMAT_KHR value */
+#define EGL_FORMAT_RGB_565_KHR 0x30C1 /* EGL_MATCH_FORMAT_KHR value */
+#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2 /* EGL_MATCH_FORMAT_KHR value */
+#define EGL_FORMAT_RGBA_8888_KHR 0x30C3 /* EGL_MATCH_FORMAT_KHR value */
+#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4 /* eglLockSurfaceKHR attribute */
+#define EGL_LOCK_USAGE_HINT_KHR 0x30C5 /* eglLockSurfaceKHR attribute */
+#define EGL_BITMAP_POINTER_KHR 0x30C6 /* eglQuerySurface attribute */
+#define EGL_BITMAP_PITCH_KHR 0x30C7 /* eglQuerySurface attribute */
+#define EGL_BITMAP_ORIGIN_KHR 0x30C8 /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9 /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC /* eglQuerySurface attribute */
+#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD /* eglQuerySurface attribute */
+#define EGL_LOWER_LEFT_KHR 0x30CE /* EGL_BITMAP_ORIGIN_KHR value */
+#define EGL_UPPER_LEFT_KHR 0x30CF /* EGL_BITMAP_ORIGIN_KHR value */
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglLockSurfaceKHR (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglUnlockSurfaceKHR (EGLDisplay display, EGLSurface surface);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNLOCKSURFACEKHRPROC) (EGLDisplay display, EGLSurface surface);
+#endif
+
+#ifndef EGL_KHR_image
+#define EGL_KHR_image 1
+#define EGL_NATIVE_PIXMAP_KHR 0x30B0 /* eglCreateImageKHR target */
+typedef void *EGLImageKHR;
+#define EGL_NO_IMAGE_KHR ((EGLImageKHR)0)
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateImageKHR (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyImageKHR (EGLDisplay dpy, EGLImageKHR image);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
+#endif
+
+#ifndef EGL_KHR_vg_parent_image
+#define EGL_KHR_vg_parent_image 1
+#define EGL_VG_PARENT_IMAGE_KHR 0x30BA /* eglCreateImageKHR target */
+#endif
+
+#ifndef EGL_KHR_gl_texture_2D_image
+#define EGL_KHR_gl_texture_2D_image 1
+#define EGL_GL_TEXTURE_2D_KHR 0x30B1 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_LEVEL_KHR 0x30BC /* eglCreateImageKHR attribute */
+#endif
+
+#ifndef EGL_KHR_gl_texture_cubemap_image
+#define EGL_KHR_gl_texture_cubemap_image 1
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR 0x30B3 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR 0x30B4 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR 0x30B5 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR 0x30B6 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR 0x30B7 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR 0x30B8 /* eglCreateImageKHR target */
+#endif
+
+#ifndef EGL_KHR_gl_texture_3D_image
+#define EGL_KHR_gl_texture_3D_image 1
+#define EGL_GL_TEXTURE_3D_KHR 0x30B2 /* eglCreateImageKHR target */
+#define EGL_GL_TEXTURE_ZOFFSET_KHR 0x30BD /* eglCreateImageKHR attribute */
+#endif
+
+#ifndef EGL_KHR_gl_renderbuffer_image
+#define EGL_KHR_gl_renderbuffer_image 1
+#define EGL_GL_RENDERBUFFER_KHR 0x30B9 /* eglCreateImageKHR target */
+#endif
+
+#if KHRONOS_SUPPORT_INT64 /* EGLTimeKHR requires 64-bit uint support */
+#ifndef EGL_KHR_reusable_sync
+#define EGL_KHR_reusable_sync 1
+
+typedef void* EGLSyncKHR;
+typedef khronos_utime_nanoseconds_t EGLTimeKHR;
+
+#define EGL_SYNC_STATUS_KHR 0x30F1
+#define EGL_SIGNALED_KHR 0x30F2
+#define EGL_UNSIGNALED_KHR 0x30F3
+#define EGL_TIMEOUT_EXPIRED_KHR 0x30F5
+#define EGL_CONDITION_SATISFIED_KHR 0x30F6
+#define EGL_SYNC_TYPE_KHR 0x30F7
+#define EGL_SYNC_REUSABLE_KHR 0x30FA
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_KHR 0x0001 /* eglClientWaitSyncKHR <flags> bitfield */
+#define EGL_FOREVER_KHR 0xFFFFFFFFFFFFFFFFull
+#define EGL_NO_SYNC_KHR ((EGLSyncKHR)0)
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLSyncKHR (EGLAPIENTRYP PFNEGLCREATESYNCKHRPROC) (EGLDisplay dpy, EGLenum type, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBKHRPROC) (EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value);
+#endif
+#endif
+
+#ifndef EGL_KHR_image_base
+#define EGL_KHR_image_base 1
+/* Most interfaces defined by EGL_KHR_image_pixmap above */
+#define EGL_IMAGE_PRESERVED_KHR 0x30D2 /* eglCreateImageKHR attribute */
+#endif
+
+#ifndef EGL_KHR_image_pixmap
+#define EGL_KHR_image_pixmap 1
+/* Interfaces defined by EGL_KHR_image above */
+#endif
+
+#ifndef EGL_IMG_context_priority
+#define EGL_IMG_context_priority 1
+#define EGL_CONTEXT_PRIORITY_LEVEL_IMG 0x3100
+#define EGL_CONTEXT_PRIORITY_HIGH_IMG 0x3101
+#define EGL_CONTEXT_PRIORITY_MEDIUM_IMG 0x3102
+#define EGL_CONTEXT_PRIORITY_LOW_IMG 0x3103
+#endif
+
+#ifndef EGL_KHR_lock_surface2
+#define EGL_KHR_lock_surface2 1
+#define EGL_BITMAP_PIXEL_SIZE_KHR 0x3110
+#endif
+
+#ifndef EGL_NV_coverage_sample
+#define EGL_NV_coverage_sample 1
+#define EGL_COVERAGE_BUFFERS_NV 0x30E0
+#define EGL_COVERAGE_SAMPLES_NV 0x30E1
+#endif
+
+#ifndef EGL_NV_depth_nonlinear
+#define EGL_NV_depth_nonlinear 1
+#define EGL_DEPTH_ENCODING_NV 0x30E2
+#define EGL_DEPTH_ENCODING_NONE_NV 0
+#define EGL_DEPTH_ENCODING_NONLINEAR_NV 0x30E3
+#endif
+
+#if KHRONOS_SUPPORT_INT64 /* EGLTimeNV requires 64-bit uint support */
+#ifndef EGL_NV_sync
+#define EGL_NV_sync 1
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_NV 0x30E6
+#define EGL_SYNC_STATUS_NV 0x30E7
+#define EGL_SIGNALED_NV 0x30E8
+#define EGL_UNSIGNALED_NV 0x30E9
+#define EGL_SYNC_FLUSH_COMMANDS_BIT_NV 0x0001
+#define EGL_FOREVER_NV 0xFFFFFFFFFFFFFFFFull
+#define EGL_ALREADY_SIGNALED_NV 0x30EA
+#define EGL_TIMEOUT_EXPIRED_NV 0x30EB
+#define EGL_CONDITION_SATISFIED_NV 0x30EC
+#define EGL_SYNC_TYPE_NV 0x30ED
+#define EGL_SYNC_CONDITION_NV 0x30EE
+#define EGL_SYNC_FENCE_NV 0x30EF
+#define EGL_NO_SYNC_NV ((EGLSyncNV)0)
+typedef void* EGLSyncNV;
+typedef khronos_utime_nanoseconds_t EGLTimeNV;
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSyncNV EGLAPIENTRY eglCreateFenceSyncNV (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroySyncNV (EGLSyncNV sync);
+EGLAPI EGLBoolean EGLAPIENTRY eglFenceNV (EGLSyncNV sync);
+EGLAPI EGLint EGLAPIENTRY eglClientWaitSyncNV (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+EGLAPI EGLBoolean EGLAPIENTRY eglSignalSyncNV (EGLSyncNV sync, EGLenum mode);
+EGLAPI EGLBoolean EGLAPIENTRY eglGetSyncAttribNV (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLSyncNV (EGLAPIENTRYP PFNEGLCREATEFENCESYNCNVPROC) (EGLDisplay dpy, EGLenum condition, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSYNCNVPROC) (EGLSyncNV sync);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLFENCENVPROC) (EGLSyncNV sync);
+typedef EGLint (EGLAPIENTRYP PFNEGLCLIENTWAITSYNCNVPROC) (EGLSyncNV sync, EGLint flags, EGLTimeNV timeout);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSIGNALSYNCNVPROC) (EGLSyncNV sync, EGLenum mode);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETSYNCATTRIBNVPROC) (EGLSyncNV sync, EGLint attribute, EGLint *value);
+#endif
+#endif
+
+#if KHRONOS_SUPPORT_INT64 /* Dependent on EGL_KHR_reusable_sync which requires 64-bit uint support */
+#ifndef EGL_KHR_fence_sync
+#define EGL_KHR_fence_sync 1
+/* Reuses most tokens and entry points from EGL_KHR_reusable_sync */
+#define EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR 0x30F0
+#define EGL_SYNC_CONDITION_KHR 0x30F8
+#define EGL_SYNC_FENCE_KHR 0x30F9
+#endif
+#endif
+
+#ifndef EGL_HI_clientpixmap
+#define EGL_HI_clientpixmap 1
+
+/* Surface Attribute */
+#define EGL_CLIENT_PIXMAP_POINTER_HI 0x8F74
+/*
+ * Structure representing a client pixmap
+ * (pixmap's data is in client-space memory).
+ */
+struct EGLClientPixmapHI
+{
+ void* pData;
+ EGLint iWidth;
+ EGLint iHeight;
+ EGLint iStride;
+};
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurfaceHI(EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dpy, EGLConfig config, struct EGLClientPixmapHI* pixmap);
+#endif /* EGL_HI_clientpixmap */
+
+#ifndef EGL_HI_colorformats
+#define EGL_HI_colorformats 1
+/* Config Attribute */
+#define EGL_COLOR_FORMAT_HI 0x8F70
+/* Color Formats */
+#define EGL_COLOR_RGB_HI 0x8F71
+#define EGL_COLOR_RGBA_HI 0x8F72
+#define EGL_COLOR_ARGB_HI 0x8F73
+#endif /* EGL_HI_colorformats */
+
+#ifndef EGL_MESA_drm_image
+#define EGL_MESA_drm_image 1
+#define EGL_DRM_BUFFER_FORMAT_MESA 0x31D0 /* CreateDRMImageMESA attribute */
+#define EGL_DRM_BUFFER_USE_MESA 0x31D1 /* CreateDRMImageMESA attribute */
+#define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA 0x31D2 /* EGL_IMAGE_FORMAT_MESA attribute value */
+#define EGL_DRM_BUFFER_MESA 0x31D3 /* eglCreateImageKHR target */
+#define EGL_DRM_BUFFER_STRIDE_MESA 0x31D4
+#define EGL_DRM_BUFFER_USE_SCANOUT_MESA 0x00000001 /* EGL_DRM_BUFFER_USE_MESA bits */
+#define EGL_DRM_BUFFER_USE_SHARE_MESA 0x00000002 /* EGL_DRM_BUFFER_USE_MESA bits */
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLImageKHR EGLAPIENTRY eglCreateDRMImageMESA (EGLDisplay dpy, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglExportDRMImageMESA (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#endif
+
+#ifndef EGL_NV_post_sub_buffer
+#define EGL_NV_post_sub_buffer 1
+#define EGL_POST_SUB_BUFFER_SUPPORTED_NV 0x30BE
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglPostSubBufferNV (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLPOSTSUBBUFFERNVPROC) (EGLDisplay dpy, EGLSurface surface, EGLint x, EGLint y, EGLint width, EGLint height);
+#endif
+
+#ifndef EGL_ANGLE_query_surface_pointer
+#define EGL_ANGLE_query_surface_pointer 1
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean eglQuerySurfacePointerANGLE(EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value);
+#endif
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSURFACEPOINTERANGLEPROC) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, void **value);
+#endif
+
+#ifndef EGL_ANGLE_surface_d3d_texture_2d_share_handle
+#define EGL_ANGLE_surface_d3d_texture_2d_share_handle 1
+#define EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE 0x3200
+#endif
+
+#ifndef EGL_NV_coverage_sample_resolve
+#define EGL_NV_coverage_sample_resolve 1
+#define EGL_COVERAGE_SAMPLE_RESOLVE_NV 0x3131
+#define EGL_COVERAGE_SAMPLE_RESOLVE_DEFAULT_NV 0x3132
+#define EGL_COVERAGE_SAMPLE_RESOLVE_NONE_NV 0x3133
+#endif
+
+#if KHRONOS_SUPPORT_INT64 /* EGLuint64NV requires 64-bit uint support */
+#ifndef EGL_NV_system_time
+#define EGL_NV_system_time 1
+typedef khronos_utime_nanoseconds_t EGLuint64NV;
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeFrequencyNV(void);
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeNV(void);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC) (void);
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC) (void);
+#endif
+#endif
+
+#if KHRONOS_SUPPORT_INT64 /* EGLuint64KHR requires 64-bit uint support */
+#ifndef EGL_KHR_stream
+#define EGL_KHR_stream 1
+typedef void* EGLStreamKHR;
+typedef khronos_uint64_t EGLuint64KHR;
+#define EGL_NO_STREAM_KHR ((EGLStreamKHR)0)
+#define EGL_CONSUMER_LATENCY_USEC_KHR 0x3210
+#define EGL_PRODUCER_FRAME_KHR 0x3212
+#define EGL_CONSUMER_FRAME_KHR 0x3213
+#define EGL_STREAM_STATE_KHR 0x3214
+#define EGL_STREAM_STATE_CREATED_KHR 0x3215
+#define EGL_STREAM_STATE_CONNECTING_KHR 0x3216
+#define EGL_STREAM_STATE_EMPTY_KHR 0x3217
+#define EGL_STREAM_STATE_NEW_FRAME_AVAILABLE_KHR 0x3218
+#define EGL_STREAM_STATE_OLD_FRAME_AVAILABLE_KHR 0x3219
+#define EGL_STREAM_STATE_DISCONNECTED_KHR 0x321A
+#define EGL_BAD_STREAM_KHR 0x321B
+#define EGL_BAD_STATE_KHR 0x321C
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamKHR(EGLDisplay dpy, const EGLint *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglDestroyStreamKHR(EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamAttribKHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamKHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamu64KHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMKHRPROC)(EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYSTREAMKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMATTRIBKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLint *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMU64KHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLuint64KHR *value);
+#endif
+#endif
+
+#ifdef EGL_KHR_stream /* Requires KHR_stream extension */
+#ifndef EGL_KHR_stream_consumer_gltexture
+#define EGL_KHR_stream_consumer_gltexture 1
+#define EGL_CONSUMER_ACQUIRE_TIMEOUT_USEC_KHR 0x321E
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerGLTextureExternalKHR(EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireKHR(EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseKHR(EGLDisplay dpy, EGLStreamKHR stream);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERGLTEXTUREEXTERNALKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream);
+#endif
+#endif
+
+#ifdef EGL_KHR_stream /* Requires KHR_stream extension */
+#ifndef EGL_KHR_stream_producer_eglsurface
+#define EGL_KHR_stream_producer_eglsurface 1
+#define EGL_STREAM_BIT_KHR 0x0800
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLSurface EGLAPIENTRY eglCreateStreamProducerSurfaceKHR(EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATESTREAMPRODUCERSURFACEKHRPROC)(EGLDisplay dpy, EGLConfig config, EGLStreamKHR stream, const EGLint *attrib_list);
+#endif
+#endif
+
+#ifdef EGL_KHR_stream /* Requires KHR_stream extension */
+#ifndef EGL_KHR_stream_producer_aldatalocator
+#define EGL_KHR_stream_producer_aldatalocator 1
+#endif
+#endif
+
+#ifdef EGL_KHR_stream /* Requires KHR_stream extension */
+#ifndef EGL_KHR_stream_fifo
+#define EGL_KHR_stream_fifo 1
+/* reuse EGLTimeKHR */
+#define EGL_STREAM_FIFO_LENGTH_KHR 0x31FC
+#define EGL_STREAM_TIME_NOW_KHR 0x31FD
+#define EGL_STREAM_TIME_CONSUMER_KHR 0x31FE
+#define EGL_STREAM_TIME_PRODUCER_KHR 0x31FF
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamTimeKHR(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMTIMEKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, EGLTimeKHR *value);
+#endif
+#endif
+
+#ifndef EGL_EXT_create_context_robustness
+#define EGL_EXT_create_context_robustness 1
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT 0x30BF
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT 0x3138
+#define EGL_NO_RESET_NOTIFICATION_EXT 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET_EXT 0x31BF
+#endif
+
+#ifndef EGL_ANGLE_d3d_share_handle_client_buffer
+#define EGL_ANGLE_d3d_share_handle_client_buffer 1
+/* reuse EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE */
+#endif
+
+#ifndef EGL_KHR_create_context
+#define EGL_KHR_create_context 1
+#define EGL_CONTEXT_MAJOR_VERSION_KHR EGL_CONTEXT_CLIENT_VERSION
+#define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB
+#define EGL_CONTEXT_FLAGS_KHR 0x30FC
+#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR 0x30FD
+#define EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR 0x31BD
+#define EGL_NO_RESET_NOTIFICATION_KHR 0x31BE
+#define EGL_LOSE_CONTEXT_ON_RESET_KHR 0x31BF
+#define EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR 0x00000001
+#define EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR 0x00000002
+#define EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR 0x00000004
+#define EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR 0x00000001
+#define EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR 0x00000002
+#define EGL_OPENGL_ES3_BIT_KHR 0x00000040
+#endif
+
+#ifndef EGL_KHR_surfaceless_context
+#define EGL_KHR_surfaceless_context 1
+/* No tokens/entry points, just relaxes an error condition */
+#endif
+
+#ifdef EGL_KHR_stream /* Requires KHR_stream extension */
+#ifndef EGL_KHR_stream_cross_process_fd
+#define EGL_KHR_stream_cross_process_fd 1
+typedef int EGLNativeFileDescriptorKHR;
+#define EGL_NO_FILE_DESCRIPTOR_KHR ((EGLNativeFileDescriptorKHR)(-1))
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLNativeFileDescriptorKHR EGLAPIENTRY eglGetStreamFileDescriptorKHR(EGLDisplay dpy, EGLStreamKHR stream);
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamFromFileDescriptorKHR(EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLNativeFileDescriptorKHR (EGLAPIENTRYP PFNEGLGETSTREAMFILEDESCRIPTORKHRPROC)(EGLDisplay dpy, EGLStreamKHR stream);
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMFROMFILEDESCRIPTORKHRPROC)(EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor);
+#endif
+#endif
+
+#ifndef EGL_EXT_multiview_window
+#define EGL_EXT_multiview_window 1
+#define EGL_MULTIVIEW_VIEW_COUNT_EXT 0x3134
+#endif
+
+#ifndef EGL_KHR_wait_sync
+#define EGL_KHR_wait_sync 1
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLint EGLAPIENTRY eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLint (EGLAPIENTRYP PFNEGLWAITSYNCKHRPROC)(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
+#endif
+
+#ifndef EGL_NV_post_convert_rounding
+#define EGL_NV_post_convert_rounding 1
+/* No tokens or entry points, just relaxes behavior of SwapBuffers */
+#endif
+
+#ifndef EGL_NV_native_query
+#define EGL_NV_native_query 1
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeDisplayNV( EGLDisplay dpy, EGLNativeDisplayType* display_id);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativeWindowNV( EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType* window);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryNativePixmapNV( EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType* pixmap);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEDISPLAYNVPROC)(EGLDisplay dpy, EGLNativeDisplayType *display_id);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEWINDOWNVPROC)(EGLDisplay dpy, EGLSurface surf, EGLNativeWindowType *window);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYNATIVEPIXMAPNVPROC)(EGLDisplay dpy, EGLSurface surf, EGLNativePixmapType *pixmap);
+#endif
+
+#ifndef EGL_NV_3dvision_surface
+#define EGL_NV_3dvision_surface 1
+#define EGL_AUTO_STEREO_NV 0x3136
+#endif
+
+#ifndef EGL_ANDROID_framebuffer_target
+#define EGL_ANDROID_framebuffer_target 1
+#define EGL_FRAMEBUFFER_TARGET_ANDROID 0x3147
+#endif
+
+#ifndef EGL_ANDROID_blob_cache
+#define EGL_ANDROID_blob_cache 1
+typedef khronos_ssize_t EGLsizeiANDROID;
+typedef void (*EGLSetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, const void *value, EGLsizeiANDROID valueSize);
+typedef EGLsizeiANDROID (*EGLGetBlobFuncANDROID) (const void *key, EGLsizeiANDROID keySize, void *value, EGLsizeiANDROID valueSize);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI void EGLAPIENTRY eglSetBlobCacheFuncsANDROID(EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef void (EGLAPIENTRYP PFNEGLSETBLOBCACHEFUNCSANDROIDPROC)(EGLDisplay dpy, EGLSetBlobFuncANDROID set, EGLGetBlobFuncANDROID get);
+#endif
+
+#ifndef EGL_ANDROID_image_native_buffer
+#define EGL_ANDROID_image_native_buffer 1
+#define EGL_NATIVE_BUFFER_ANDROID 0x3140
+#endif
+
+#ifndef EGL_ANDROID_native_fence_sync
+#define EGL_ANDROID_native_fence_sync 1
+#define EGL_SYNC_NATIVE_FENCE_ANDROID 0x3144
+#define EGL_SYNC_NATIVE_FENCE_FD_ANDROID 0x3145
+#define EGL_SYNC_NATIVE_FENCE_SIGNALED_ANDROID 0x3146
+#define EGL_NO_NATIVE_FENCE_FD_ANDROID -1
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLint EGLAPIENTRY eglDupNativeFenceFDANDROID( EGLDisplay dpy, EGLSyncKHR);
+#endif /* EGL_EGLEXT_PROTOTYPES */
+typedef EGLint (EGLAPIENTRYP PFNEGLDUPNATIVEFENCEFDANDROIDPROC)(EGLDisplay dpy, EGLSyncKHR);
+#endif
+
+#ifndef EGL_ANDROID_recordable
+#define EGL_ANDROID_recordable 1
+#define EGL_RECORDABLE_ANDROID 0x3142
+#endif
+
+#ifndef EGL_EXT_buffer_age
+#define EGL_EXT_buffer_age 1
+#define EGL_BUFFER_AGE_EXT 0x313D
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __eglext_h_ */
diff --git a/ri/include/EGL/eglplatform.h b/ri/include/EGL/eglplatform.h
new file mode 100644
index 0000000..6d04553
--- /dev/null
+++ b/ri/include/EGL/eglplatform.h
@@ -0,0 +1,122 @@
+#ifndef __eglplatform_h_
+#define __eglplatform_h_
+
+/*
+** Copyright (c) 2007-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Platform-specific types and definitions for egl.h
+ * $Revision: 12306 $ on $Date: 2010-08-25 09:51:28 -0700 (Wed, 25 Aug 2010) $
+ *
+ * Adopters may modify khrplatform.h and this file to suit their platform.
+ * You are encouraged to submit all modifications to the Khronos group so that
+ * they can be included in future versions of this file. Please submit changes
+ * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla)
+ * by filing a bug against product "EGL" component "Registry".
+ */
+
+#include <KHR/khrplatform.h>
+
+/* Macros used in EGL function prototype declarations.
+ *
+ * EGL functions should be prototyped as:
+ *
+ * EGLAPI return-type EGLAPIENTRY eglFunction(arguments);
+ * typedef return-type (EXPAPIENTRYP PFNEGLFUNCTIONPROC) (arguments);
+ *
+ * KHRONOS_APICALL and KHRONOS_APIENTRY are defined in KHR/khrplatform.h
+ */
+
+#ifndef EGLAPI
+#define EGLAPI KHRONOS_APICALL
+#endif
+
+#ifndef EGLAPIENTRY
+#define EGLAPIENTRY KHRONOS_APIENTRY
+#endif
+#define EGLAPIENTRYP EGLAPIENTRY*
+
+/* The types NativeDisplayType, NativeWindowType, and NativePixmapType
+ * are aliases of window-system-dependent types, such as X Display * or
+ * Windows Device Context. They must be defined in platform-specific
+ * code below. The EGL-prefixed versions of Native*Type are the same
+ * types, renamed in EGL 1.3 so all types in the API start with "EGL".
+ *
+ * Khronos STRONGLY RECOMMENDS that you use the default definitions
+ * provided below, since these changes affect both binary and source
+ * portability of applications using EGL running on different EGL
+ * implementations.
+ */
+
+#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#include <windows.h>
+
+typedef HDC EGLNativeDisplayType;
+typedef HBITMAP EGLNativePixmapType;
+typedef HWND EGLNativeWindowType;
+
+#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
+
+typedef int EGLNativeDisplayType;
+typedef void *EGLNativeWindowType;
+typedef void *EGLNativePixmapType;
+
+#elif defined(__arm__) && defined(__gnu_linux__) /* ARM Linux Mali */
+#include <EGL/fbdev_window.h>
+
+typedef void* EGLNativeDisplayType;
+typedef fbdev_pixmap* EGLNativePixmapType;
+typedef fbdev_window* EGLNativeWindowType;
+
+#elif defined(__unix__)
+
+/* X11 (tentative) */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+typedef Display *EGLNativeDisplayType;
+typedef Pixmap EGLNativePixmapType;
+typedef Window EGLNativeWindowType;
+
+#else
+#error "Platform not recognized"
+#endif
+
+/* EGL 1.2 types, renamed for consistency in EGL 1.3 */
+typedef EGLNativeDisplayType NativeDisplayType;
+typedef EGLNativePixmapType NativePixmapType;
+typedef EGLNativeWindowType NativeWindowType;
+
+
+/* Define EGLint. This must be a signed integral type large enough to contain
+ * all legal attribute names and values passed into and out of EGL, whether
+ * their type is boolean, bitmask, enumerant (symbolic constant), integer,
+ * handle, or other. While in general a 32-bit integer will suffice, if
+ * handles are 64 bit types, then EGLint should be defined as a signed 64-bit
+ * integer type.
+ */
+typedef khronos_int32_t EGLint;
+
+#endif /* __eglplatform_h */
diff --git a/ri/include/EGL/fbdev_window.h b/ri/include/EGL/fbdev_window.h
new file mode 100644
index 0000000..caa35f2
--- /dev/null
+++ b/ri/include/EGL/fbdev_window.h
@@ -0,0 +1,52 @@
+/* vim:set sts=4 ts=4 noexpandtab: */
+/*
+ * This confidential and proprietary software may be used only as
+ * authorised by a licensing agreement from ARM Limited
+ * (C) COPYRIGHT 2008,2009 ARM Limited
+ * ALL RIGHTS RESERVED
+ * The entire notice above must be reproduced on all authorised
+ * copies and copies may only be made to the extent permitted
+ * by a licensing agreement from ARM Limited.
+ */
+
+#ifndef _FBDEV_WINDOW_H_
+#define _FBDEV_WINDOW_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum
+{
+ FBDEV_PIXMAP_SUPPORTS_UMP = (1<<0)
+} fbdev_pixmap_flags;
+
+typedef struct fbdev_window
+{
+ unsigned short width;
+ unsigned short height;
+} fbdev_window;
+
+typedef struct fbdev_pixmap
+{
+ unsigned int height;
+ unsigned int width;
+ unsigned int format;
+ unsigned int stride;
+ unsigned int bytes_per_pixel;
+ unsigned char buffer_size;
+ unsigned char red_size;
+ unsigned char green_size;
+ unsigned char blue_size;
+ unsigned char alpha_size;
+ unsigned char luminance_size;
+ fbdev_pixmap_flags flags;
+ unsigned short *data;
+} fbdev_pixmap;
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
diff --git a/ri/include/KHR/khrplatform.h b/ri/include/KHR/khrplatform.h
new file mode 100644
index 0000000..11e873e
--- /dev/null
+++ b/ri/include/KHR/khrplatform.h
@@ -0,0 +1,273 @@
+#ifndef __khrplatform_h_
+#define __khrplatform_h_
+
+/*
+** Copyright (c) 2008-2009 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+*/
+
+/* Khronos platform-specific types and definitions.
+ *
+ * $Revision: 9356 $ on $Date: 2009-10-21 02:52:25 -0700 (Wed, 21 Oct 2009) $
+ *
+ * Adopters may modify this file to suit their platform. Adopters are
+ * encouraged to submit platform specific modifications to the Khronos
+ * group so that they can be included in future versions of this file.
+ * Please submit changes by sending them to the public Khronos Bugzilla
+ * (http://khronos.org/bugzilla) by filing a bug against product
+ * "Khronos (general)" component "Registry".
+ *
+ * A predefined template which fills in some of the bug fields can be
+ * reached using http://tinyurl.com/khrplatform-h-bugreport, but you
+ * must create a Bugzilla login first.
+ *
+ *
+ * See the Implementer's Guidelines for information about where this file
+ * should be located on your system and for more details of its use:
+ * http://www.khronos.org/registry/implementers_guide.pdf
+ *
+ * This file should be included as
+ * #include <KHR/khrplatform.h>
+ * by Khronos client API header files that use its types and defines.
+ *
+ * The types in khrplatform.h should only be used to define API-specific types.
+ *
+ * Types defined in khrplatform.h:
+ * khronos_int8_t signed 8 bit
+ * khronos_uint8_t unsigned 8 bit
+ * khronos_int16_t signed 16 bit
+ * khronos_uint16_t unsigned 16 bit
+ * khronos_int32_t signed 32 bit
+ * khronos_uint32_t unsigned 32 bit
+ * khronos_int64_t signed 64 bit
+ * khronos_uint64_t unsigned 64 bit
+ * khronos_intptr_t signed same number of bits as a pointer
+ * khronos_uintptr_t unsigned same number of bits as a pointer
+ * khronos_ssize_t signed size
+ * khronos_usize_t unsigned size
+ * khronos_float_t signed 32 bit floating point
+ * khronos_time_ns_t unsigned 64 bit time in nanoseconds
+ * khronos_utime_nanoseconds_t unsigned time interval or absolute time in
+ * nanoseconds
+ * khronos_stime_nanoseconds_t signed time interval in nanoseconds
+ * khronos_boolean_enum_t enumerated boolean type. This should
+ * only be used as a base type when a client API's boolean type is
+ * an enum. Client APIs which use an integer or other type for
+ * booleans cannot use this as the base type for their boolean.
+ *
+ * Tokens defined in khrplatform.h:
+ *
+ * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
+ *
+ * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
+ * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
+ *
+ * Calling convention macros defined in this file:
+ * KHRONOS_APICALL
+ * KHRONOS_APIENTRY
+ * KHRONOS_APIATTRIBUTES
+ *
+ * These may be used in function prototypes as:
+ *
+ * KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
+ * int arg1,
+ * int arg2) KHRONOS_APIATTRIBUTES;
+ */
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APICALL
+ *-------------------------------------------------------------------------
+ * This precedes the return type of the function in the function prototype.
+ */
+#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
+# if defined (_DLL_EXPORTS)
+# define KHRONOS_APICALL __declspec(dllexport)
+# else
+# define KHRONOS_APICALL __declspec(dllimport)
+# endif
+#elif defined (__SYMBIAN32__)
+# define KHRONOS_APICALL IMPORT_C
+#else
+# define KHRONOS_APICALL
+#endif
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APIENTRY
+ *-------------------------------------------------------------------------
+ * This follows the return type of the function and precedes the function
+ * name in the function prototype.
+ */
+#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
+ /* Win32 but not WinCE */
+# define KHRONOS_APIENTRY __stdcall
+#else
+# define KHRONOS_APIENTRY
+#endif
+
+/*-------------------------------------------------------------------------
+ * Definition of KHRONOS_APIATTRIBUTES
+ *-------------------------------------------------------------------------
+ * This follows the closing parenthesis of the function prototype arguments.
+ */
+#if defined (__ARMCC_2__)
+#define KHRONOS_APIATTRIBUTES __softfp
+#else
+#define KHRONOS_APIATTRIBUTES
+#endif
+
+/*-------------------------------------------------------------------------
+ * basic type definitions
+ *-----------------------------------------------------------------------*/
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
+
+
+/*
+ * Using <stdint.h>
+ */
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__VMS ) || defined(__sgi)
+
+/*
+ * Using <inttypes.h>
+ */
+#include <inttypes.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
+
+/*
+ * Win32
+ */
+typedef __int32 khronos_int32_t;
+typedef unsigned __int32 khronos_uint32_t;
+typedef __int64 khronos_int64_t;
+typedef unsigned __int64 khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif defined(__sun__) || defined(__digital__)
+
+/*
+ * Sun or Digital
+ */
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#if defined(__arch64__) || defined(_LP64)
+typedef long int khronos_int64_t;
+typedef unsigned long int khronos_uint64_t;
+#else
+typedef long long int khronos_int64_t;
+typedef unsigned long long int khronos_uint64_t;
+#endif /* __arch64__ */
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#elif 0
+
+/*
+ * Hypothetical platform with no float or int64 support
+ */
+typedef int khronos_int32_t;
+typedef unsigned int khronos_uint32_t;
+#define KHRONOS_SUPPORT_INT64 0
+#define KHRONOS_SUPPORT_FLOAT 0
+
+#else
+
+/*
+ * Generic fallback
+ */
+#include <stdint.h>
+typedef int32_t khronos_int32_t;
+typedef uint32_t khronos_uint32_t;
+typedef int64_t khronos_int64_t;
+typedef uint64_t khronos_uint64_t;
+#define KHRONOS_SUPPORT_INT64 1
+#define KHRONOS_SUPPORT_FLOAT 1
+
+#endif
+
+
+/*
+ * Types that are (so far) the same on all platforms
+ */
+typedef signed char khronos_int8_t;
+typedef unsigned char khronos_uint8_t;
+typedef signed short int khronos_int16_t;
+typedef unsigned short int khronos_uint16_t;
+typedef signed long int khronos_intptr_t;
+typedef unsigned long int khronos_uintptr_t;
+typedef signed long int khronos_ssize_t;
+typedef unsigned long int khronos_usize_t;
+
+#if KHRONOS_SUPPORT_FLOAT
+/*
+ * Float type
+ */
+typedef float khronos_float_t;
+#endif
+
+#if KHRONOS_SUPPORT_INT64
+/* Time types
+ *
+ * These types can be used to represent a time interval in nanoseconds or
+ * an absolute Unadjusted System Time. Unadjusted System Time is the number
+ * of nanoseconds since some arbitrary system event (e.g. since the last
+ * time the system booted). The Unadjusted System Time is an unsigned
+ * 64 bit value that wraps back to 0 every 584 years. Time intervals
+ * may be either signed or unsigned.
+ */
+typedef khronos_uint64_t khronos_utime_nanoseconds_t;
+typedef khronos_int64_t khronos_stime_nanoseconds_t;
+#endif
+
+/*
+ * Dummy value used to pad enum types to 32 bits.
+ */
+#ifndef KHRONOS_MAX_ENUM
+#define KHRONOS_MAX_ENUM 0x7FFFFFFF
+#endif
+
+/*
+ * Enumerated boolean type
+ *
+ * Values other than zero should be considered to be true. Therefore
+ * comparisons should not be made against KHRONOS_TRUE.
+ */
+typedef enum {
+ KHRONOS_FALSE = 0,
+ KHRONOS_TRUE = 1,
+ KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
+} khronos_boolean_enum_t;
+
+#endif /* __khrplatform_h_ */
diff --git a/ri/include/VG/openvg.h b/ri/include/VG/openvg.h
new file mode 100644
index 0000000..456a8bb
--- /dev/null
+++ b/ri/include/VG/openvg.h
@@ -0,0 +1,746 @@
+/* $Revision: 6838 $ on $Date:: 2008-11-04 12:46:08 +0100 #$ */
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -------------------------------------
+ *
+ * Copyright (c) 2008 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief OpenVG 1.1 API.
+ *//*-------------------------------------------------------------------*/
+
+#ifndef _OPENVG_H
+#define _OPENVG_H
+
+#include <VG/vgplatform.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define OPENVG_VERSION_1_0 1
+#define OPENVG_VERSION_1_0_1 1
+#define OPENVG_VERSION_1_1 2
+
+#ifndef VG_MAXSHORT
+#define VG_MAXSHORT 0x7FFF
+#endif
+
+#ifndef VG_MAXINT
+#define VG_MAXINT 0x7FFFFFFF
+#endif
+
+#ifndef VG_MAX_ENUM
+#define VG_MAX_ENUM 0x7FFFFFFF
+#endif
+
+typedef VGuint VGHandle;
+
+typedef VGHandle VGPath;
+typedef VGHandle VGImage;
+typedef VGHandle VGMaskLayer;
+typedef VGHandle VGFont;
+typedef VGHandle VGPaint;
+
+#define VG_INVALID_HANDLE ((VGHandle)0)
+
+typedef enum {
+ VG_FALSE = 0,
+ VG_TRUE = 1,
+
+ VG_BOOLEAN_FORCE_SIZE = VG_MAX_ENUM
+} VGboolean;
+
+typedef enum {
+ VG_NO_ERROR = 0,
+ VG_BAD_HANDLE_ERROR = 0x1000,
+ VG_ILLEGAL_ARGUMENT_ERROR = 0x1001,
+ VG_OUT_OF_MEMORY_ERROR = 0x1002,
+ VG_PATH_CAPABILITY_ERROR = 0x1003,
+ VG_UNSUPPORTED_IMAGE_FORMAT_ERROR = 0x1004,
+ VG_UNSUPPORTED_PATH_FORMAT_ERROR = 0x1005,
+ VG_IMAGE_IN_USE_ERROR = 0x1006,
+ VG_NO_CONTEXT_ERROR = 0x1007,
+
+ VG_ERROR_CODE_FORCE_SIZE = VG_MAX_ENUM
+} VGErrorCode;
+
+typedef enum {
+ /* Mode settings */
+ VG_MATRIX_MODE = 0x1100,
+ VG_FILL_RULE = 0x1101,
+ VG_IMAGE_QUALITY = 0x1102,
+ VG_RENDERING_QUALITY = 0x1103,
+ VG_BLEND_MODE = 0x1104,
+ VG_IMAGE_MODE = 0x1105,
+
+ /* Scissoring rectangles */
+ VG_SCISSOR_RECTS = 0x1106,
+
+ /* Color Transformation */
+ VG_COLOR_TRANSFORM = 0x1170,
+ VG_COLOR_TRANSFORM_VALUES = 0x1171,
+
+ /* Stroke parameters */
+ VG_STROKE_LINE_WIDTH = 0x1110,
+ VG_STROKE_CAP_STYLE = 0x1111,
+ VG_STROKE_JOIN_STYLE = 0x1112,
+ VG_STROKE_MITER_LIMIT = 0x1113,
+ VG_STROKE_DASH_PATTERN = 0x1114,
+ VG_STROKE_DASH_PHASE = 0x1115,
+ VG_STROKE_DASH_PHASE_RESET = 0x1116,
+
+ /* Edge fill color for VG_TILE_FILL tiling mode */
+ VG_TILE_FILL_COLOR = 0x1120,
+
+ /* Color for vgClear */
+ VG_CLEAR_COLOR = 0x1121,
+
+ /* Glyph origin */
+ VG_GLYPH_ORIGIN = 0x1122,
+
+ /* Enable/disable alpha masking and scissoring */
+ VG_MASKING = 0x1130,
+ VG_SCISSORING = 0x1131,
+
+ /* Pixel layout information */
+ VG_PIXEL_LAYOUT = 0x1140,
+ VG_SCREEN_LAYOUT = 0x1141,
+
+ /* Source format selection for image filters */
+ VG_FILTER_FORMAT_LINEAR = 0x1150,
+ VG_FILTER_FORMAT_PREMULTIPLIED = 0x1151,
+
+ /* Destination write enable mask for image filters */
+ VG_FILTER_CHANNEL_MASK = 0x1152,
+
+ /* Implementation limits (read-only) */
+ VG_MAX_SCISSOR_RECTS = 0x1160,
+ VG_MAX_DASH_COUNT = 0x1161,
+ VG_MAX_KERNEL_SIZE = 0x1162,
+ VG_MAX_SEPARABLE_KERNEL_SIZE = 0x1163,
+ VG_MAX_COLOR_RAMP_STOPS = 0x1164,
+ VG_MAX_IMAGE_WIDTH = 0x1165,
+ VG_MAX_IMAGE_HEIGHT = 0x1166,
+ VG_MAX_IMAGE_PIXELS = 0x1167,
+ VG_MAX_IMAGE_BYTES = 0x1168,
+ VG_MAX_FLOAT = 0x1169,
+ VG_MAX_GAUSSIAN_STD_DEVIATION = 0x116A,
+
+ VG_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM
+} VGParamType;
+
+typedef enum {
+ VG_RENDERING_QUALITY_NONANTIALIASED = 0x1200,
+ VG_RENDERING_QUALITY_FASTER = 0x1201,
+ VG_RENDERING_QUALITY_BETTER = 0x1202, /* Default */
+
+ VG_RENDERING_QUALITY_FORCE_SIZE = VG_MAX_ENUM
+} VGRenderingQuality;
+
+typedef enum {
+ VG_PIXEL_LAYOUT_UNKNOWN = 0x1300,
+ VG_PIXEL_LAYOUT_RGB_VERTICAL = 0x1301,
+ VG_PIXEL_LAYOUT_BGR_VERTICAL = 0x1302,
+ VG_PIXEL_LAYOUT_RGB_HORIZONTAL = 0x1303,
+ VG_PIXEL_LAYOUT_BGR_HORIZONTAL = 0x1304,
+
+ VG_PIXEL_LAYOUT_FORCE_SIZE = VG_MAX_ENUM
+} VGPixelLayout;
+
+typedef enum {
+ VG_MATRIX_PATH_USER_TO_SURFACE = 0x1400,
+ VG_MATRIX_IMAGE_USER_TO_SURFACE = 0x1401,
+ VG_MATRIX_FILL_PAINT_TO_USER = 0x1402,
+ VG_MATRIX_STROKE_PAINT_TO_USER = 0x1403,
+ VG_MATRIX_GLYPH_USER_TO_SURFACE = 0x1404,
+
+ VG_MATRIX_MODE_FORCE_SIZE = VG_MAX_ENUM
+} VGMatrixMode;
+
+typedef enum {
+ VG_CLEAR_MASK = 0x1500,
+ VG_FILL_MASK = 0x1501,
+ VG_SET_MASK = 0x1502,
+ VG_UNION_MASK = 0x1503,
+ VG_INTERSECT_MASK = 0x1504,
+ VG_SUBTRACT_MASK = 0x1505,
+
+ VG_MASK_OPERATION_FORCE_SIZE = VG_MAX_ENUM
+} VGMaskOperation;
+
+#define VG_PATH_FORMAT_STANDARD 0
+
+typedef enum {
+ VG_PATH_DATATYPE_S_8 = 0,
+ VG_PATH_DATATYPE_S_16 = 1,
+ VG_PATH_DATATYPE_S_32 = 2,
+ VG_PATH_DATATYPE_F = 3,
+
+ VG_PATH_DATATYPE_FORCE_SIZE = VG_MAX_ENUM
+} VGPathDatatype;
+
+typedef enum {
+ VG_ABSOLUTE = 0,
+ VG_RELATIVE = 1,
+
+ VG_PATH_ABS_REL_FORCE_SIZE = VG_MAX_ENUM
+} VGPathAbsRel;
+
+typedef enum {
+ VG_CLOSE_PATH = ( 0 << 1),
+ VG_MOVE_TO = ( 1 << 1),
+ VG_LINE_TO = ( 2 << 1),
+ VG_HLINE_TO = ( 3 << 1),
+ VG_VLINE_TO = ( 4 << 1),
+ VG_QUAD_TO = ( 5 << 1),
+ VG_CUBIC_TO = ( 6 << 1),
+ VG_SQUAD_TO = ( 7 << 1),
+ VG_SCUBIC_TO = ( 8 << 1),
+ VG_SCCWARC_TO = ( 9 << 1),
+ VG_SCWARC_TO = (10 << 1),
+ VG_LCCWARC_TO = (11 << 1),
+ VG_LCWARC_TO = (12 << 1),
+
+ VG_PATH_SEGMENT_FORCE_SIZE = VG_MAX_ENUM
+} VGPathSegment;
+
+typedef enum {
+ VG_MOVE_TO_ABS = VG_MOVE_TO | VG_ABSOLUTE,
+ VG_MOVE_TO_REL = VG_MOVE_TO | VG_RELATIVE,
+ VG_LINE_TO_ABS = VG_LINE_TO | VG_ABSOLUTE,
+ VG_LINE_TO_REL = VG_LINE_TO | VG_RELATIVE,
+ VG_HLINE_TO_ABS = VG_HLINE_TO | VG_ABSOLUTE,
+ VG_HLINE_TO_REL = VG_HLINE_TO | VG_RELATIVE,
+ VG_VLINE_TO_ABS = VG_VLINE_TO | VG_ABSOLUTE,
+ VG_VLINE_TO_REL = VG_VLINE_TO | VG_RELATIVE,
+ VG_QUAD_TO_ABS = VG_QUAD_TO | VG_ABSOLUTE,
+ VG_QUAD_TO_REL = VG_QUAD_TO | VG_RELATIVE,
+ VG_CUBIC_TO_ABS = VG_CUBIC_TO | VG_ABSOLUTE,
+ VG_CUBIC_TO_REL = VG_CUBIC_TO | VG_RELATIVE,
+ VG_SQUAD_TO_ABS = VG_SQUAD_TO | VG_ABSOLUTE,
+ VG_SQUAD_TO_REL = VG_SQUAD_TO | VG_RELATIVE,
+ VG_SCUBIC_TO_ABS = VG_SCUBIC_TO | VG_ABSOLUTE,
+ VG_SCUBIC_TO_REL = VG_SCUBIC_TO | VG_RELATIVE,
+ VG_SCCWARC_TO_ABS = VG_SCCWARC_TO | VG_ABSOLUTE,
+ VG_SCCWARC_TO_REL = VG_SCCWARC_TO | VG_RELATIVE,
+ VG_SCWARC_TO_ABS = VG_SCWARC_TO | VG_ABSOLUTE,
+ VG_SCWARC_TO_REL = VG_SCWARC_TO | VG_RELATIVE,
+ VG_LCCWARC_TO_ABS = VG_LCCWARC_TO | VG_ABSOLUTE,
+ VG_LCCWARC_TO_REL = VG_LCCWARC_TO | VG_RELATIVE,
+ VG_LCWARC_TO_ABS = VG_LCWARC_TO | VG_ABSOLUTE,
+ VG_LCWARC_TO_REL = VG_LCWARC_TO | VG_RELATIVE,
+
+ VG_PATH_COMMAND_FORCE_SIZE = VG_MAX_ENUM
+} VGPathCommand;
+
+typedef enum {
+ VG_PATH_CAPABILITY_APPEND_FROM = (1 << 0),
+ VG_PATH_CAPABILITY_APPEND_TO = (1 << 1),
+ VG_PATH_CAPABILITY_MODIFY = (1 << 2),
+ VG_PATH_CAPABILITY_TRANSFORM_FROM = (1 << 3),
+ VG_PATH_CAPABILITY_TRANSFORM_TO = (1 << 4),
+ VG_PATH_CAPABILITY_INTERPOLATE_FROM = (1 << 5),
+ VG_PATH_CAPABILITY_INTERPOLATE_TO = (1 << 6),
+ VG_PATH_CAPABILITY_PATH_LENGTH = (1 << 7),
+ VG_PATH_CAPABILITY_POINT_ALONG_PATH = (1 << 8),
+ VG_PATH_CAPABILITY_TANGENT_ALONG_PATH = (1 << 9),
+ VG_PATH_CAPABILITY_PATH_BOUNDS = (1 << 10),
+ VG_PATH_CAPABILITY_PATH_TRANSFORMED_BOUNDS = (1 << 11),
+ VG_PATH_CAPABILITY_ALL = (1 << 12) - 1,
+
+ VG_PATH_CAPABILITIES_FORCE_SIZE = VG_MAX_ENUM
+} VGPathCapabilities;
+
+typedef enum {
+ VG_PATH_FORMAT = 0x1600,
+ VG_PATH_DATATYPE = 0x1601,
+ VG_PATH_SCALE = 0x1602,
+ VG_PATH_BIAS = 0x1603,
+ VG_PATH_NUM_SEGMENTS = 0x1604,
+ VG_PATH_NUM_COORDS = 0x1605,
+
+ VG_PATH_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM
+} VGPathParamType;
+
+typedef enum {
+ VG_CAP_BUTT = 0x1700,
+ VG_CAP_ROUND = 0x1701,
+ VG_CAP_SQUARE = 0x1702,
+
+ VG_CAP_STYLE_FORCE_SIZE = VG_MAX_ENUM
+} VGCapStyle;
+
+typedef enum {
+ VG_JOIN_MITER = 0x1800,
+ VG_JOIN_ROUND = 0x1801,
+ VG_JOIN_BEVEL = 0x1802,
+
+ VG_JOIN_STYLE_FORCE_SIZE = VG_MAX_ENUM
+} VGJoinStyle;
+
+typedef enum {
+ VG_EVEN_ODD = 0x1900,
+ VG_NON_ZERO = 0x1901,
+
+ VG_FILL_RULE_FORCE_SIZE = VG_MAX_ENUM
+} VGFillRule;
+
+typedef enum {
+ VG_STROKE_PATH = (1 << 0),
+ VG_FILL_PATH = (1 << 1),
+
+ VG_PAINT_MODE_FORCE_SIZE = VG_MAX_ENUM
+} VGPaintMode;
+
+typedef enum {
+ /* Color paint parameters */
+ VG_PAINT_TYPE = 0x1A00,
+ VG_PAINT_COLOR = 0x1A01,
+ VG_PAINT_COLOR_RAMP_SPREAD_MODE = 0x1A02,
+ VG_PAINT_COLOR_RAMP_PREMULTIPLIED = 0x1A07,
+ VG_PAINT_COLOR_RAMP_STOPS = 0x1A03,
+
+ /* Linear gradient paint parameters */
+ VG_PAINT_LINEAR_GRADIENT = 0x1A04,
+
+ /* Radial gradient paint parameters */
+ VG_PAINT_RADIAL_GRADIENT = 0x1A05,
+
+ /* Pattern paint parameters */
+ VG_PAINT_PATTERN_TILING_MODE = 0x1A06,
+
+ VG_PAINT_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM
+} VGPaintParamType;
+
+typedef enum {
+ VG_PAINT_TYPE_COLOR = 0x1B00,
+ VG_PAINT_TYPE_LINEAR_GRADIENT = 0x1B01,
+ VG_PAINT_TYPE_RADIAL_GRADIENT = 0x1B02,
+ VG_PAINT_TYPE_PATTERN = 0x1B03,
+
+ VG_PAINT_TYPE_FORCE_SIZE = VG_MAX_ENUM
+} VGPaintType;
+
+typedef enum {
+ VG_COLOR_RAMP_SPREAD_PAD = 0x1C00,
+ VG_COLOR_RAMP_SPREAD_REPEAT = 0x1C01,
+ VG_COLOR_RAMP_SPREAD_REFLECT = 0x1C02,
+
+ VG_COLOR_RAMP_SPREAD_MODE_FORCE_SIZE = VG_MAX_ENUM
+} VGColorRampSpreadMode;
+
+typedef enum {
+ VG_TILE_FILL = 0x1D00,
+ VG_TILE_PAD = 0x1D01,
+ VG_TILE_REPEAT = 0x1D02,
+ VG_TILE_REFLECT = 0x1D03,
+
+ VG_TILING_MODE_FORCE_SIZE = VG_MAX_ENUM
+} VGTilingMode;
+
+typedef enum {
+ /* RGB{A,X} channel ordering */
+ VG_sRGBX_8888 = 0,
+ VG_sRGBA_8888 = 1,
+ VG_sRGBA_8888_PRE = 2,
+ VG_sRGB_565 = 3,
+ VG_sRGBA_5551 = 4,
+ VG_sRGBA_4444 = 5,
+ VG_sL_8 = 6,
+ VG_lRGBX_8888 = 7,
+ VG_lRGBA_8888 = 8,
+ VG_lRGBA_8888_PRE = 9,
+ VG_lL_8 = 10,
+ VG_A_8 = 11,
+ VG_BW_1 = 12,
+ VG_A_1 = 13,
+ VG_A_4 = 14,
+
+ /* {A,X}RGB channel ordering */
+ VG_sXRGB_8888 = 0 | (1 << 6),
+ VG_sARGB_8888 = 1 | (1 << 6),
+ VG_sARGB_8888_PRE = 2 | (1 << 6),
+ VG_sARGB_1555 = 4 | (1 << 6),
+ VG_sARGB_4444 = 5 | (1 << 6),
+ VG_lXRGB_8888 = 7 | (1 << 6),
+ VG_lARGB_8888 = 8 | (1 << 6),
+ VG_lARGB_8888_PRE = 9 | (1 << 6),
+
+ /* BGR{A,X} channel ordering */
+ VG_sBGRX_8888 = 0 | (1 << 7),
+ VG_sBGRA_8888 = 1 | (1 << 7),
+ VG_sBGRA_8888_PRE = 2 | (1 << 7),
+ VG_sBGR_565 = 3 | (1 << 7),
+ VG_sBGRA_5551 = 4 | (1 << 7),
+ VG_sBGRA_4444 = 5 | (1 << 7),
+ VG_lBGRX_8888 = 7 | (1 << 7),
+ VG_lBGRA_8888 = 8 | (1 << 7),
+ VG_lBGRA_8888_PRE = 9 | (1 << 7),
+
+ /* {A,X}BGR channel ordering */
+ VG_sXBGR_8888 = 0 | (1 << 6) | (1 << 7),
+ VG_sABGR_8888 = 1 | (1 << 6) | (1 << 7),
+ VG_sABGR_8888_PRE = 2 | (1 << 6) | (1 << 7),
+ VG_sABGR_1555 = 4 | (1 << 6) | (1 << 7),
+ VG_sABGR_4444 = 5 | (1 << 6) | (1 << 7),
+ VG_lXBGR_8888 = 7 | (1 << 6) | (1 << 7),
+ VG_lABGR_8888 = 8 | (1 << 6) | (1 << 7),
+ VG_lABGR_8888_PRE = 9 | (1 << 6) | (1 << 7),
+
+ VG_IMAGE_FORMAT_FORCE_SIZE = VG_MAX_ENUM
+} VGImageFormat;
+
+typedef enum {
+ VG_IMAGE_QUALITY_NONANTIALIASED = (1 << 0),
+ VG_IMAGE_QUALITY_FASTER = (1 << 1),
+ VG_IMAGE_QUALITY_BETTER = (1 << 2),
+
+ VG_IMAGE_QUALITY_FORCE_SIZE = VG_MAX_ENUM
+} VGImageQuality;
+
+typedef enum {
+ VG_IMAGE_FORMAT = 0x1E00,
+ VG_IMAGE_WIDTH = 0x1E01,
+ VG_IMAGE_HEIGHT = 0x1E02,
+
+ VG_IMAGE_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM
+} VGImageParamType;
+
+typedef enum {
+ VG_DRAW_IMAGE_NORMAL = 0x1F00,
+ VG_DRAW_IMAGE_MULTIPLY = 0x1F01,
+ VG_DRAW_IMAGE_STENCIL = 0x1F02,
+
+ VG_IMAGE_MODE_FORCE_SIZE = VG_MAX_ENUM
+} VGImageMode;
+
+typedef enum {
+ VG_RED = (1 << 3),
+ VG_GREEN = (1 << 2),
+ VG_BLUE = (1 << 1),
+ VG_ALPHA = (1 << 0),
+
+ VG_IMAGE_CHANNEL_FORCE_SIZE = VG_MAX_ENUM
+} VGImageChannel;
+
+typedef enum {
+ VG_BLEND_SRC = 0x2000,
+ VG_BLEND_SRC_OVER = 0x2001,
+ VG_BLEND_DST_OVER = 0x2002,
+ VG_BLEND_SRC_IN = 0x2003,
+ VG_BLEND_DST_IN = 0x2004,
+ VG_BLEND_MULTIPLY = 0x2005,
+ VG_BLEND_SCREEN = 0x2006,
+ VG_BLEND_DARKEN = 0x2007,
+ VG_BLEND_LIGHTEN = 0x2008,
+ VG_BLEND_ADDITIVE = 0x2009,
+
+ VG_BLEND_MODE_FORCE_SIZE = VG_MAX_ENUM
+} VGBlendMode;
+
+typedef enum {
+ VG_FONT_NUM_GLYPHS = 0x2F00,
+
+ VG_FONT_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM
+} VGFontParamType;
+
+typedef enum {
+ VG_IMAGE_FORMAT_QUERY = 0x2100,
+ VG_PATH_DATATYPE_QUERY = 0x2101,
+
+ VG_HARDWARE_QUERY_TYPE_FORCE_SIZE = VG_MAX_ENUM
+} VGHardwareQueryType;
+
+typedef enum {
+ VG_HARDWARE_ACCELERATED = 0x2200,
+ VG_HARDWARE_UNACCELERATED = 0x2201,
+
+ VG_HARDWARE_QUERY_RESULT_FORCE_SIZE = VG_MAX_ENUM
+} VGHardwareQueryResult;
+
+typedef enum {
+ VG_VENDOR = 0x2300,
+ VG_RENDERER = 0x2301,
+ VG_VERSION = 0x2302,
+ VG_EXTENSIONS = 0x2303,
+
+ VG_STRING_ID_FORCE_SIZE = VG_MAX_ENUM
+} VGStringID;
+
+/* Function Prototypes */
+
+#ifndef VG_API_CALL
+# error VG_API_CALL must be defined
+#endif
+
+#ifndef VG_API_ENTRY
+# error VG_API_ENTRY must be defined
+#endif
+
+#ifndef VG_API_EXIT
+# error VG_API_EXIT must be defined
+#endif
+
+VG_API_CALL VGErrorCode VG_API_ENTRY vgGetError(void) VG_API_EXIT;
+
+VG_API_CALL void VG_API_ENTRY vgFlush(void) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgFinish(void) VG_API_EXIT;
+
+/* Getters and Setters */
+VG_API_CALL void VG_API_ENTRY vgSetf (VGParamType type, VGfloat value) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSeti (VGParamType type, VGint value) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetfv(VGParamType type, VGint count,
+ const VGfloat * values) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetiv(VGParamType type, VGint count,
+ const VGint * values) VG_API_EXIT;
+
+VG_API_CALL VGfloat VG_API_ENTRY vgGetf(VGParamType type) VG_API_EXIT;
+VG_API_CALL VGint VG_API_ENTRY vgGeti(VGParamType type) VG_API_EXIT;
+VG_API_CALL VGint VG_API_ENTRY vgGetVectorSize(VGParamType type) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgGetfv(VGParamType type, VGint count, VGfloat * values) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgGetiv(VGParamType type, VGint count, VGint * values) VG_API_EXIT;
+
+VG_API_CALL void VG_API_ENTRY vgSetParameterf(VGHandle object,
+ VGint paramType,
+ VGfloat value) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetParameteri(VGHandle object,
+ VGint paramType,
+ VGint value) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetParameterfv(VGHandle object,
+ VGint paramType,
+ VGint count, const VGfloat * values) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetParameteriv(VGHandle object,
+ VGint paramType,
+ VGint count, const VGint * values) VG_API_EXIT;
+
+VG_API_CALL VGfloat VG_API_ENTRY vgGetParameterf(VGHandle object,
+ VGint paramType) VG_API_EXIT;
+VG_API_CALL VGint VG_API_ENTRY vgGetParameteri(VGHandle object,
+ VGint paramType);
+VG_API_CALL VGint VG_API_ENTRY vgGetParameterVectorSize(VGHandle object,
+ VGint paramType) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgGetParameterfv(VGHandle object,
+ VGint paramType,
+ VGint count, VGfloat * values) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgGetParameteriv(VGHandle object,
+ VGint paramType,
+ VGint count, VGint * values) VG_API_EXIT;
+
+/* Matrix Manipulation */
+VG_API_CALL void VG_API_ENTRY vgLoadIdentity(void) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgLoadMatrix(const VGfloat * m) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgGetMatrix(VGfloat * m) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgMultMatrix(const VGfloat * m) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgTranslate(VGfloat tx, VGfloat ty) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgScale(VGfloat sx, VGfloat sy) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgShear(VGfloat shx, VGfloat shy) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgRotate(VGfloat angle) VG_API_EXIT;
+
+/* Masking and Clearing */
+VG_API_CALL void VG_API_ENTRY vgMask(VGHandle mask, VGMaskOperation operation,
+ VGint x, VGint y,
+ VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgRenderToMask(VGPath path,
+ VGbitfield paintModes,
+ VGMaskOperation operation) VG_API_EXIT;
+VG_API_CALL VGMaskLayer VG_API_ENTRY vgCreateMaskLayer(VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgDestroyMaskLayer(VGMaskLayer maskLayer) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgFillMaskLayer(VGMaskLayer maskLayer,
+ VGint x, VGint y,
+ VGint width, VGint height,
+ VGfloat value) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgCopyMask(VGMaskLayer maskLayer,
+ VGint dx, VGint dy,
+ VGint sx, VGint sy,
+ VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgClear(VGint x, VGint y, VGint width, VGint height) VG_API_EXIT;
+
+/* Paths */
+VG_API_CALL VGPath VG_API_ENTRY vgCreatePath(VGint pathFormat,
+ VGPathDatatype datatype,
+ VGfloat scale, VGfloat bias,
+ VGint segmentCapacityHint,
+ VGint coordCapacityHint,
+ VGbitfield capabilities) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgClearPath(VGPath path, VGbitfield capabilities) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgDestroyPath(VGPath path) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgRemovePathCapabilities(VGPath path,
+ VGbitfield capabilities) VG_API_EXIT;
+VG_API_CALL VGbitfield VG_API_ENTRY vgGetPathCapabilities(VGPath path) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgAppendPath(VGPath dstPath, VGPath srcPath) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgAppendPathData(VGPath dstPath,
+ VGint numSegments,
+ const VGubyte * pathSegments,
+ const void * pathData) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgModifyPathCoords(VGPath dstPath, VGint startIndex,
+ VGint numSegments,
+ const void * pathData) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgTransformPath(VGPath dstPath, VGPath srcPath) VG_API_EXIT;
+VG_API_CALL VGboolean VG_API_ENTRY vgInterpolatePath(VGPath dstPath,
+ VGPath startPath,
+ VGPath endPath,
+ VGfloat amount) VG_API_EXIT;
+VG_API_CALL VGfloat VG_API_ENTRY vgPathLength(VGPath path,
+ VGint startSegment, VGint numSegments) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgPointAlongPath(VGPath path,
+ VGint startSegment, VGint numSegments,
+ VGfloat distance,
+ VGfloat * x, VGfloat * y,
+ VGfloat * tangentX, VGfloat * tangentY) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgPathBounds(VGPath path,
+ VGfloat * minX, VGfloat * minY,
+ VGfloat * width, VGfloat * height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgPathTransformedBounds(VGPath path,
+ VGfloat * minX, VGfloat * minY,
+ VGfloat * width, VGfloat * height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgDrawPath(VGPath path, VGbitfield paintModes) VG_API_EXIT;
+
+/* Paint */
+VG_API_CALL VGPaint VG_API_ENTRY vgCreatePaint(void) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgDestroyPaint(VGPaint paint) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetPaint(VGPaint paint, VGbitfield paintModes) VG_API_EXIT;
+VG_API_CALL VGPaint VG_API_ENTRY vgGetPaint(VGPaintMode paintMode) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetColor(VGPaint paint, VGuint rgba) VG_API_EXIT;
+VG_API_CALL VGuint VG_API_ENTRY vgGetColor(VGPaint paint) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgPaintPattern(VGPaint paint, VGImage pattern) VG_API_EXIT;
+
+/* Images */
+VG_API_CALL VGImage VG_API_ENTRY vgCreateImage(VGImageFormat format,
+ VGint width, VGint height,
+ VGbitfield allowedQuality) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgDestroyImage(VGImage image) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgClearImage(VGImage image,
+ VGint x, VGint y, VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgImageSubData(VGImage image,
+ const void * data, VGint dataStride,
+ VGImageFormat dataFormat,
+ VGint x, VGint y, VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgGetImageSubData(VGImage image,
+ void * data, VGint dataStride,
+ VGImageFormat dataFormat,
+ VGint x, VGint y,
+ VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL VGImage VG_API_ENTRY vgChildImage(VGImage parent,
+ VGint x, VGint y, VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL VGImage VG_API_ENTRY vgGetParent(VGImage image) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgCopyImage(VGImage dst, VGint dx, VGint dy,
+ VGImage src, VGint sx, VGint sy,
+ VGint width, VGint height,
+ VGboolean dither) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgDrawImage(VGImage image) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetPixels(VGint dx, VGint dy,
+ VGImage src, VGint sx, VGint sy,
+ VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgWritePixels(const void * data, VGint dataStride,
+ VGImageFormat dataFormat,
+ VGint dx, VGint dy,
+ VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgGetPixels(VGImage dst, VGint dx, VGint dy,
+ VGint sx, VGint sy,
+ VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgReadPixels(void * data, VGint dataStride,
+ VGImageFormat dataFormat,
+ VGint sx, VGint sy,
+ VGint width, VGint height) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgCopyPixels(VGint dx, VGint dy,
+ VGint sx, VGint sy,
+ VGint width, VGint height) VG_API_EXIT;
+
+/* Text */
+VG_API_CALL VGFont VG_API_ENTRY vgCreateFont(VGint glyphCapacityHint) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgDestroyFont(VGFont font) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetGlyphToPath(VGFont font,
+ VGuint glyphIndex,
+ VGPath path,
+ VGboolean isHinted,
+ VGfloat glyphOrigin [2],
+ VGfloat escapement[2]) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSetGlyphToImage(VGFont font,
+ VGuint glyphIndex,
+ VGImage image,
+ VGfloat glyphOrigin [2],
+ VGfloat escapement[2]) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgClearGlyph(VGFont font,VGuint glyphIndex) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgDrawGlyph(VGFont font,
+ VGuint glyphIndex,
+ VGbitfield paintModes,
+ VGboolean allowAutoHinting) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgDrawGlyphs(VGFont font,
+ VGint glyphCount,
+ VGuint *glyphIndices,
+ VGfloat *adjustments_x,
+ VGfloat *adjustments_y,
+ VGbitfield paintModes,
+ VGboolean allowAutoHinting) VG_API_EXIT;
+
+/* Image Filters */
+VG_API_CALL void VG_API_ENTRY vgColorMatrix(VGImage dst, VGImage src,
+ const VGfloat * matrix) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgConvolve(VGImage dst, VGImage src,
+ VGint kernelWidth, VGint kernelHeight,
+ VGint shiftX, VGint shiftY,
+ const VGshort * kernel,
+ VGfloat scale,
+ VGfloat bias,
+ VGTilingMode tilingMode) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgSeparableConvolve(VGImage dst, VGImage src,
+ VGint kernelWidth,
+ VGint kernelHeight,
+ VGint shiftX, VGint shiftY,
+ const VGshort * kernelX,
+ const VGshort * kernelY,
+ VGfloat scale,
+ VGfloat bias,
+ VGTilingMode tilingMode) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgGaussianBlur(VGImage dst, VGImage src,
+ VGfloat stdDeviationX,
+ VGfloat stdDeviationY,
+ VGTilingMode tilingMode) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgLookup(VGImage dst, VGImage src,
+ const VGubyte * redLUT,
+ const VGubyte * greenLUT,
+ const VGubyte * blueLUT,
+ const VGubyte * alphaLUT,
+ VGboolean outputLinear,
+ VGboolean outputPremultiplied) VG_API_EXIT;
+VG_API_CALL void VG_API_ENTRY vgLookupSingle(VGImage dst, VGImage src,
+ const VGuint * lookupTable,
+ VGImageChannel sourceChannel,
+ VGboolean outputLinear,
+ VGboolean outputPremultiplied) VG_API_EXIT;
+
+/* Hardware Queries */
+VG_API_CALL VGHardwareQueryResult VG_API_ENTRY vgHardwareQuery(VGHardwareQueryType key,
+ VGint setting) VG_API_EXIT;
+
+/* Renderer and Extension Information */
+VG_API_CALL const VGubyte * VG_API_ENTRY vgGetString(VGStringID name) VG_API_EXIT;
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* _OPENVG_H */
diff --git a/ri/include/VG/vgext.h b/ri/include/VG/vgext.h
new file mode 100644
index 0000000..ae07d99
--- /dev/null
+++ b/ri/include/VG/vgext.h
@@ -0,0 +1,233 @@
+/* $Revision: 6810 $ on $Date:: 2008-10-29 15:31:37 +0100 #$ */
+
+/*------------------------------------------------------------------------
+ *
+ * VG extensions Reference Implementation
+ * -------------------------------------
+ *
+ * Copyright (c) 2008 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief VG extensions
+ *//*-------------------------------------------------------------------*/
+
+
+
+#ifndef _VGEXT_H
+#define _VGEXT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <VG/openvg.h>
+#include <VG/vgu.h>
+
+#ifndef VG_API_ENTRYP
+# define VG_API_ENTRYP VG_API_ENTRY*
+#endif
+
+#ifndef VGU_API_ENTRYP
+# define VGU_API_ENTRYP VGU_API_ENTRY*
+#endif
+
+/*-------------------------------------------------------------------------------
+ * KHR extensions
+ *------------------------------------------------------------------------------*/
+
+typedef enum {
+
+#ifndef VG_KHR_iterative_average_blur
+ VG_MAX_AVERAGE_BLUR_DIMENSION_KHR = 0x116B,
+ VG_AVERAGE_BLUR_DIMENSION_RESOLUTION_KHR = 0x116C,
+ VG_MAX_AVERAGE_BLUR_ITERATIONS_KHR = 0x116D,
+#endif
+
+ VG_PARAM_TYPE_KHR_FORCE_SIZE = VG_MAX_ENUM
+} VGParamTypeKHR;
+
+#ifndef VG_KHR_EGL_image
+#define VG_KHR_EGL_image 1
+/* VGEGLImageKHR is an opaque handle to an EGLImage */
+typedef void* VGeglImageKHR;
+
+#ifdef VG_VGEXT_PROTOTYPES
+VG_API_CALL VGImage VG_API_ENTRY vgCreateEGLImageTargetKHR(VGeglImageKHR image);
+#endif
+typedef VGImage (VG_API_ENTRYP PFNVGCREATEEGLIMAGETARGETKHRPROC) (VGeglImageKHR image);
+
+#endif
+
+
+#ifndef VG_KHR_iterative_average_blur
+#define VG_KHR_iterative_average_blur 1
+
+#ifdef VG_VGEXT_PROTOTYPES
+VG_API_CALL void vgIterativeAverageBlurKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGTilingMode tilingMode);
+#endif
+typedef void (VG_API_ENTRYP PFNVGITERATIVEAVERAGEBLURKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGTilingMode tilingMode);
+
+#endif
+
+
+#ifndef VG_KHR_advanced_blending
+#define VG_KHR_advanced_blending 1
+
+typedef enum {
+ VG_BLEND_OVERLAY_KHR = 0x2010,
+ VG_BLEND_HARDLIGHT_KHR = 0x2011,
+ VG_BLEND_SOFTLIGHT_SVG_KHR = 0x2012,
+ VG_BLEND_SOFTLIGHT_KHR = 0x2013,
+ VG_BLEND_COLORDODGE_KHR = 0x2014,
+ VG_BLEND_COLORBURN_KHR = 0x2015,
+ VG_BLEND_DIFFERENCE_KHR = 0x2016,
+ VG_BLEND_SUBTRACT_KHR = 0x2017,
+ VG_BLEND_INVERT_KHR = 0x2018,
+ VG_BLEND_EXCLUSION_KHR = 0x2019,
+ VG_BLEND_LINEARDODGE_KHR = 0x201a,
+ VG_BLEND_LINEARBURN_KHR = 0x201b,
+ VG_BLEND_VIVIDLIGHT_KHR = 0x201c,
+ VG_BLEND_LINEARLIGHT_KHR = 0x201d,
+ VG_BLEND_PINLIGHT_KHR = 0x201e,
+ VG_BLEND_HARDMIX_KHR = 0x201f,
+ VG_BLEND_CLEAR_KHR = 0x2020,
+ VG_BLEND_DST_KHR = 0x2021,
+ VG_BLEND_SRC_OUT_KHR = 0x2022,
+ VG_BLEND_DST_OUT_KHR = 0x2023,
+ VG_BLEND_SRC_ATOP_KHR = 0x2024,
+ VG_BLEND_DST_ATOP_KHR = 0x2025,
+ VG_BLEND_XOR_KHR = 0x2026,
+
+ VG_BLEND_MODE_KHR_FORCE_SIZE= VG_MAX_ENUM
+} VGBlendModeKHR;
+#endif
+
+#ifndef VG_KHR_parametric_filter
+#define VG_KHR_parametric_filter 1
+
+typedef enum {
+ VG_PF_OBJECT_VISIBLE_FLAG_KHR = (1 << 0),
+ VG_PF_KNOCKOUT_FLAG_KHR = (1 << 1),
+ VG_PF_OUTER_FLAG_KHR = (1 << 2),
+ VG_PF_INNER_FLAG_KHR = (1 << 3),
+
+ VG_PF_TYPE_KHR_FORCE_SIZE = VG_MAX_ENUM
+} VGPfTypeKHR;
+
+typedef enum {
+ VGU_IMAGE_IN_USE_ERROR = 0xF010,
+
+ VGU_ERROR_CODE_KHR_FORCE_SIZE = VG_MAX_ENUM
+} VGUErrorCodeKHR;
+
+#ifdef VG_VGEXT_PROTOTYPES
+VG_API_CALL void VG_API_ENTRY vgParametricFilterKHR(VGImage dst,VGImage src,VGImage blur,VGfloat strength,VGfloat offsetX,VGfloat offsetY,VGbitfield filterFlags,VGPaint highlightPaint,VGPaint shadowPaint);
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguDropShadowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint shadowColorRGBA);
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGlowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint glowColorRGBA) ;
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguBevelKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint highlightColorRGBA,VGuint shadowColorRGBA);
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGradientGlowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* glowColorRampStops);
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGradientBevelKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* bevelColorRampStops);
+#endif
+typedef void (VG_API_ENTRYP PFNVGPARAMETRICFILTERKHRPROC) (VGImage dst,VGImage src,VGImage blur,VGfloat strength,VGfloat offsetX,VGfloat offsetY,VGbitfield filterFlags,VGPaint highlightPaint,VGPaint shadowPaint);
+typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUDROPSHADOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint shadowColorRGBA);
+typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGLOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint glowColorRGBA);
+typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUBEVELKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint highlightColorRGBA,VGuint shadowColorRGBA);
+typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGRADIENTGLOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* glowColorRampStops);
+typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGRADIENTBEVELKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* bevelColorRampStops);
+
+#endif
+
+
+/*-------------------------------------------------------------------------------
+ * NDS extensions
+ *------------------------------------------------------------------------------*/
+
+#ifndef VG_NDS_paint_generation
+#define VG_NDS_paint_generation 1
+
+typedef enum {
+ VG_PAINT_COLOR_RAMP_LINEAR_NDS = 0x1A10,
+ VG_COLOR_MATRIX_NDS = 0x1A11,
+ VG_PAINT_COLOR_TRANSFORM_LINEAR_NDS = 0x1A12,
+
+ VG_PAINT_PARAM_TYPE_NDS_FORCE_SIZE = VG_MAX_ENUM
+} VGPaintParamTypeNds;
+
+typedef enum {
+ VG_DRAW_IMAGE_COLOR_MATRIX_NDS = 0x1F10,
+
+ VG_IMAGE_MODE_NDS_FORCE_SIZE = VG_MAX_ENUM
+} VGImageModeNds;
+#endif
+
+
+#ifndef VG_NDS_projective_geometry
+#define VG_NDS_projective_geometry 1
+
+typedef enum {
+ VG_CLIP_MODE_NDS = 0x1180,
+ VG_CLIP_LINES_NDS = 0x1181,
+ VG_MAX_CLIP_LINES_NDS = 0x1182,
+
+ VG_PARAM_TYPE_NDS_FORCE_SIZE = VG_MAX_ENUM
+} VGParamTypeNds;
+
+typedef enum {
+ VG_CLIPMODE_NONE_NDS = 0x3000,
+ VG_CLIPMODE_CLIP_CLOSED_NDS = 0x3001,
+ VG_CLIPMODE_CLIP_OPEN_NDS = 0x3002,
+ VG_CLIPMODE_CULL_NDS = 0x3003,
+
+ VG_CLIPMODE_NDS_FORCE_SIZE = VG_MAX_ENUM
+} VGClipModeNds;
+
+typedef enum {
+ VG_RQUAD_TO_NDS = ( 13 << 1 ),
+ VG_RCUBIC_TO_NDS = ( 14 << 1 ),
+
+ VG_PATH_SEGMENT_NDS_FORCE_SIZE = VG_MAX_ENUM
+} VGPathSegmentNds;
+
+typedef enum {
+ VG_RQUAD_TO_ABS_NDS = (VG_RQUAD_TO_NDS | VG_ABSOLUTE),
+ VG_RQUAD_TO_REL_NDS = (VG_RQUAD_TO_NDS | VG_RELATIVE),
+ VG_RCUBIC_TO_ABS_NDS = (VG_RCUBIC_TO_NDS | VG_ABSOLUTE),
+ VG_RCUBIC_TO_REL_NDS = (VG_RCUBIC_TO_NDS | VG_RELATIVE),
+
+ VG_PATH_COMMAND_NDS_FORCE_SIZE = VG_MAX_ENUM
+} VGPathCommandNds;
+
+#ifdef VG_VGEXT_PROTOTYPES
+VG_API_CALL void VG_API_ENTRY vgProjectiveMatrixNDS(VGboolean enable) ;
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguTransformClipLineNDS(const VGfloat Ain,const VGfloat Bin,const VGfloat Cin,const VGfloat* matrix,const VGboolean inverse,VGfloat* Aout,VGfloat* Bout,VGfloat* Cout);
+#endif
+typedef void (VG_API_ENTRYP PFNVGPROJECTIVEMATRIXNDSPROC) (VGboolean enable) ;
+typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUTRANSFORMCLIPLINENDSPROC) (const VGfloat Ain,const VGfloat Bin,const VGfloat Cin,const VGfloat* matrix,const VGboolean inverse,VGfloat* Aout,VGfloat* Bout,VGfloat* Cout);
+
+#endif
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* _VGEXT_H */
diff --git a/ri/include/VG/vgplatform.h b/ri/include/VG/vgplatform.h
new file mode 100644
index 0000000..aa9896e
--- /dev/null
+++ b/ri/include/VG/vgplatform.h
@@ -0,0 +1,106 @@
+/* $Revision: 6810 $ on $Date:: 2008-10-29 15:31:37 +0100 #$ */
+
+/*------------------------------------------------------------------------
+ *
+ * VG platform specific header Reference Implementation
+ * ----------------------------------------------------
+ *
+ * Copyright (c) 2008 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief VG platform specific header
+ *//*-------------------------------------------------------------------*/
+
+#ifndef _VGPLATFORM_H
+#define _VGPLATFORM_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef VG_API_CALL
+#if defined(OPENVG_STATIC_LIBRARY)
+# define VG_API_CALL
+#else
+# if defined(_WIN32) || defined(__VC32__) /* Win32 */
+# if defined (OPENVG_DLL_EXPORTS)
+# define VG_API_CALL __declspec(dllexport)
+# else
+# define VG_API_CALL __declspec(dllimport)
+# endif
+# else
+# define VG_API_CALL extern
+# endif /* defined(_WIN32) ||... */
+#endif /* defined OPENVG_STATIC_LIBRARY */
+#endif /* ifndef VG_API_CALL */
+
+#ifndef VGU_API_CALL
+#if defined(OPENVG_STATIC_LIBRARY)
+# define VGU_API_CALL
+#else
+# if defined(_WIN32) || defined(__VC32__) /* Win32 */
+# if defined (OPENVG_DLL_EXPORTS)
+# define VGU_API_CALL __declspec(dllexport)
+# else
+# define VGU_API_CALL __declspec(dllimport)
+# endif
+# else
+# define VGU_API_CALL extern
+# endif /* defined(_WIN32) ||... */
+#endif /* defined OPENVG_STATIC_LIBRARY */
+#endif /* ifndef VGU_API_CALL */
+
+
+#ifndef VG_API_ENTRY
+#define VG_API_ENTRY
+#endif
+
+#ifndef VG_API_EXIT
+#define VG_API_EXIT
+#endif
+
+#ifndef VGU_API_ENTRY
+#define VGU_API_ENTRY
+#endif
+
+#ifndef VGU_API_EXIT
+#define VGU_API_EXIT
+#endif
+
+typedef float VGfloat;
+typedef signed char VGbyte;
+typedef unsigned char VGubyte;
+typedef signed short VGshort;
+typedef signed int VGint;
+typedef unsigned int VGuint;
+typedef unsigned int VGbitfield;
+
+#ifndef VG_VGEXT_PROTOTYPES
+#define VG_VGEXT_PROTOTYPES
+#endif
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* _VGPLATFORM_H */
diff --git a/ri/include/VG/vgu.h b/ri/include/VG/vgu.h
new file mode 100644
index 0000000..7c814f7
--- /dev/null
+++ b/ri/include/VG/vgu.h
@@ -0,0 +1,131 @@
+/* $Revision: 6810 $ on $Date:: 2008-10-29 15:31:37 +0100 #$ */
+
+/*------------------------------------------------------------------------
+ *
+ * VGU 1.1 Reference Implementation
+ * -------------------------------------
+ *
+ * Copyright (c) 2008 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief VGU 1.1 API.
+ *//*-------------------------------------------------------------------*/
+
+#ifndef _VGU_H
+#define _VGU_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <VG/openvg.h>
+
+#define VGU_VERSION_1_0 1
+#define VGU_VERSION_1_1 2
+
+#ifndef VGU_API_CALL
+# error VGU_API_CALL must be defined
+#endif
+
+#ifndef VGU_API_ENTRY
+# error VGU_API_ENTRY must be defined
+#endif
+
+#ifndef VGU_API_EXIT
+# error VGU_API_EXIT must be defined
+#endif
+
+
+typedef enum {
+ VGU_NO_ERROR = 0,
+ VGU_BAD_HANDLE_ERROR = 0xF000,
+ VGU_ILLEGAL_ARGUMENT_ERROR = 0xF001,
+ VGU_OUT_OF_MEMORY_ERROR = 0xF002,
+ VGU_PATH_CAPABILITY_ERROR = 0xF003,
+ VGU_BAD_WARP_ERROR = 0xF004,
+
+ VGU_ERROR_CODE_FORCE_SIZE = VG_MAX_ENUM
+} VGUErrorCode;
+
+typedef enum {
+ VGU_ARC_OPEN = 0xF100,
+ VGU_ARC_CHORD = 0xF101,
+ VGU_ARC_PIE = 0xF102,
+
+ VGU_ARC_TYPE_FORCE_SIZE = VG_MAX_ENUM
+} VGUArcType;
+
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguLine(VGPath path,
+ VGfloat x0, VGfloat y0,
+ VGfloat x1, VGfloat y1) VGU_API_EXIT;
+
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguPolygon(VGPath path,
+ const VGfloat * points, VGint count,
+ VGboolean closed) VGU_API_EXIT;
+
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguRect(VGPath path,
+ VGfloat x, VGfloat y,
+ VGfloat width, VGfloat height) VGU_API_EXIT;
+
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguRoundRect(VGPath path,
+ VGfloat x, VGfloat y,
+ VGfloat width, VGfloat height,
+ VGfloat arcWidth, VGfloat arcHeight) VGU_API_EXIT;
+
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguEllipse(VGPath path,
+ VGfloat cx, VGfloat cy,
+ VGfloat width, VGfloat height) VGU_API_EXIT;
+
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguArc(VGPath path,
+ VGfloat x, VGfloat y,
+ VGfloat width, VGfloat height,
+ VGfloat startAngle, VGfloat angleExtent,
+ VGUArcType arcType) VGU_API_EXIT;
+
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0,
+ VGfloat sx1, VGfloat sy1,
+ VGfloat sx2, VGfloat sy2,
+ VGfloat sx3, VGfloat sy3,
+ VGfloat * matrix) VGU_API_EXIT;
+
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpSquareToQuad(VGfloat dx0, VGfloat dy0,
+ VGfloat dx1, VGfloat dy1,
+ VGfloat dx2, VGfloat dy2,
+ VGfloat dx3, VGfloat dy3,
+ VGfloat * matrix) VGU_API_EXIT;
+
+VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0,
+ VGfloat dx1, VGfloat dy1,
+ VGfloat dx2, VGfloat dy2,
+ VGfloat dx3, VGfloat dy3,
+ VGfloat sx0, VGfloat sy0,
+ VGfloat sx1, VGfloat sy1,
+ VGfloat sx2, VGfloat sy2,
+ VGfloat sx3, VGfloat sy3,
+ VGfloat * matrix) VGU_API_EXIT;
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* #ifndef _VGU_H */
diff --git a/ri/openvg_ri.dsp b/ri/openvg_ri.dsp
new file mode 100644
index 0000000..5d16957
--- /dev/null
+++ b/ri/openvg_ri.dsp
@@ -0,0 +1,203 @@
+# Microsoft Developer Studio Project File - Name="openvg_ri" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=openvg_ri - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "openvg_ri.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "openvg_ri.mak" CFG="openvg_ri - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "openvg_ri - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "openvg_ri - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName "Perforce Project"
+# PROP Scc_LocalPath "."
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "openvg_ri - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "../lib"
+# PROP Intermediate_Dir "obj/release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OPENVG_RI_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W4 /GX /Zi /O2 /I "include/VG" /I "include" /I "include/EGL" /I "src" /I "../lib" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OPENVG_DLL_EXPORTS" /FD /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /pdb:"bin/openvg_ri.pdb" /machine:I386 /out:"../bin/win32/libOpenVG.dll" /libpath:"../lib"
+# SUBTRACT LINK32 /pdb:none /debug
+
+!ELSEIF "$(CFG)" == "openvg_ri - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "../lib"
+# PROP Intermediate_Dir "obj/debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OPENVG_RI_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W4 /GX /Zi /Od /I "include/VG" /I "include" /I "include/EGL" /I "src" /I "../lib" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "OPENVG_DLL_EXPORTS" /FD /GZ /c
+# SUBTRACT CPP /YX
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:no /pdb:"bin/openvg_ri-dbg.pdb" /debug /machine:I386 /out:"../bin/win32/libOpenVG-dbg.dll" /pdbtype:sept /libpath:"../lib"
+# SUBTRACT LINK32 /pdb:none
+
+!ENDIF
+
+# Begin Target
+
+# Name "openvg_ri - Win32 Release"
+# Name "openvg_ri - Win32 Debug"
+# Begin Group "src"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\src\riApi.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riArray.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riContext.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riContext.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riDefs.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\win32\riEGLOS.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riFont.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riFont.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riImage.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riImage.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riMath.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riMath.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riMiniEGL.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riPath.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riPath.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riPixelPipe.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riPixelPipe.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riRasterizer.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riRasterizer.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\riVGU.cpp
+# End Source File
+# End Group
+# Begin Group "include"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\include\EGL\egl.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\vg\openvg.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\vg\vgext.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\vg\vgplatform.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\vg\vgu.h
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/ri/src/linux/riEGLOS.cpp b/ri/src/linux/riEGLOS.cpp
new file mode 100644
index 0000000..208096c
--- /dev/null
+++ b/ri/src/linux/riEGLOS.cpp
@@ -0,0 +1,170 @@
+/*------------------------------------------------------------------------
+ *
+ * EGL 1.3
+ * -------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Generic OS EGL functionality (not thread safe, no window rendering)
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "egl.h"
+#include "riImage.h"
+#include <pthread.h>
+#include <sys/errno.h>
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void* OSGetCurrentThreadID(void)
+{
+ return (void*)pthread_self(); //TODO this is not safe
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+static pthread_mutex_t mutex;
+static int mutexRefCount = 0;
+static bool mutexInitialized = false;
+//acquired mutex cannot be deinited
+//
+void OSDeinitMutex(void)
+{
+ RI_ASSERT(mutexInitialized);
+ RI_ASSERT(mutexRefCount == 0);
+
+ int ret = pthread_mutex_destroy(&mutex);
+ RI_ASSERT(ret != EINVAL); //assert that the mutex has been initialized
+ RI_ASSERT(ret != EAGAIN); //assert that the maximum number of recursive locks hasn't been exceeded
+ RI_ASSERT(!ret); //check that there aren't other errors
+ RI_UNREF(ret);
+
+}
+void OSAcquireMutex(void)
+{
+ if(!mutexInitialized)
+ {
+ mutexInitialized = true;
+ }
+ mutexRefCount++;
+}
+void OSReleaseMutex(void)
+{
+ RI_ASSERT(mutexInitialized);
+ mutexRefCount--;
+ RI_ASSERT(mutexRefCount >= 0);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+struct OSWindowContext
+{
+ int tmpWidth;
+ int tmpHeight;
+};
+
+void* OSCreateWindowContext(EGLNativeWindowType window)
+{
+ OSWindowContext* ctx = NULL;
+ try
+ {
+ ctx = RI_NEW(OSWindowContext, ());
+ }
+ catch(std::bad_alloc)
+ {
+ return NULL;
+ }
+ ctx->tmpWidth = 0;
+ ctx->tmpHeight = 0;
+ return ctx;
+}
+
+void OSDestroyWindowContext(void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ RI_DELETE(ctx);
+ }
+}
+
+bool OSIsWindow(const void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ return true;
+ }
+ return false;
+}
+
+void OSGetWindowSize(const void* context, int& width, int& height)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ width = ctx->tmpWidth;
+ height = ctx->tmpHeight;
+ }
+ else
+ {
+ width = 0;
+ height = 0;
+ }
+}
+
+void OSBlitToWindow(void* context, const Drawable* drawable)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ ctx->tmpWidth = drawable->getWidth();
+ ctx->tmpHeight = drawable->getHeight();
+ }
+}
+
+EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id)
+{
+ RI_UNREF(display_id);
+ return (EGLDisplay)1; //support only a single display
+}
+
+} //namespace OpenVGRI
diff --git a/ri/src/macosx/riEGLOS.cpp b/ri/src/macosx/riEGLOS.cpp
new file mode 100644
index 0000000..5f581d0
--- /dev/null
+++ b/ri/src/macosx/riEGLOS.cpp
@@ -0,0 +1,409 @@
+/*------------------------------------------------------------------------
+ *
+ * EGL 1.3
+ * -------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Mac OS X specific EGL functionality
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "egl.h"
+#include "riImage.h"
+#include <pthread.h>
+#include <sys/errno.h>
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void* OSGetCurrentThreadID(void)
+{
+ return (void*)pthread_self(); //TODO this is not safe
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static pthread_mutex_t mutex;
+static int mutexRefCount = 0;
+static bool mutexInitialized = false;
+//acquired mutex cannot be deinited
+void OSDeinitMutex(void)
+{
+ RI_ASSERT(mutexInitialized);
+ RI_ASSERT(mutexRefCount == 0);
+ int ret = pthread_mutex_destroy(&mutex);
+ RI_ASSERT(ret != EINVAL); //assert that the mutex has been initialized
+ RI_ASSERT(ret != EAGAIN); //assert that the maximum number of recursive locks hasn't been exceeded
+ RI_ASSERT(!ret); //check that there aren't other errors
+ RI_UNREF(ret);
+}
+void OSAcquireMutex(void)
+{
+ if(!mutexInitialized)
+ {
+ int ret;
+ pthread_mutexattr_t attr;
+ ret = pthread_mutexattr_init(&attr); //initially not locked
+ RI_ASSERT(!ret); //check that there aren't any errors
+ ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); //count the number of recursive locks
+ RI_ASSERT(!ret); //check that there aren't any errors
+ ret = pthread_mutex_init(&mutex, &attr);
+ pthread_mutexattr_destroy(&attr);
+ RI_ASSERT(!ret); //check that there aren't more errors
+ RI_UNREF(ret);
+ mutexInitialized = true;
+ }
+ int ret = pthread_mutex_lock(&mutex);
+ RI_ASSERT(ret != EINVAL); //assert that the mutex has been initialized
+ RI_ASSERT(ret != EAGAIN); //assert that the maximum number of recursive locks hasn't been exceeded
+ RI_ASSERT(ret != EDEADLK); //recursive mutexes shouldn't return this
+ RI_ASSERT(!ret); //check that there aren't other errors
+ RI_UNREF(ret);
+ mutexRefCount++;
+}
+void OSReleaseMutex(void)
+{
+ RI_ASSERT(mutexInitialized);
+ mutexRefCount--;
+ RI_ASSERT(mutexRefCount >= 0);
+ int ret = pthread_mutex_unlock(&mutex);
+ RI_ASSERT(ret != EPERM); //assert that the current thread owns the mutex
+ RI_ASSERT(!ret); //check that there aren't more errors
+ RI_UNREF(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static bool isBigEndian()
+{
+ static const RIuint32 v = 0x12345678u;
+ const RIuint8* p = (const RIuint8*)&v;
+ RI_ASSERT (*p == (RIuint8)0x12u || *p == (RIuint8)0x78u);
+ return (*p == (RIuint8)(0x12)) ? true : false;
+}
+
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+#ifdef RI_USE_GLUT
+# include <OpenGL/gl.h>
+# include <GLUT/glut.h>
+
+struct OSWindowContext
+{
+ int window;
+ unsigned int* tmp;
+ int tmpWidth;
+ int tmpHeight;
+};
+
+OSWindowContext* OSCreateWindowContext(EGLNativeWindowType window)
+{
+ try
+ {
+ OSWindowContext* ctx = RI_NEW(OSWindowContext, ());
+ ctx->window = window;
+ ctx->tmp = NULL;
+ ctx->tmpWidth = 0;
+ ctx->tmpHeight = 0;
+ return ctx;
+ }
+ catch(std::bad_alloc)
+ {
+ return NULL;
+ }
+}
+
+void OSDestroyWindowContext(OSWindowContext* ctx)
+{
+ if(ctx)
+ {
+ RI_DELETE_ARRAY(ctx->tmp);
+ RI_DELETE(ctx);
+ }
+}
+
+bool OSIsWindow(const void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ //TODO implement
+ return true;
+ }
+ return false;
+}
+
+void OSGetWindowSize(const OSWindowContext* ctx, int& width, int& height)
+{
+ if(ctx)
+ {
+ int currWin = glutGetWindow();
+ glutSetWindow((int)ctx->window);
+ width = glutGet(GLUT_WINDOW_WIDTH);
+ height = glutGet(GLUT_WINDOW_HEIGHT);
+ glutSetWindow(currWin);
+ }
+ else
+ {
+ width = 0;
+ height = 0;
+ }
+}
+
+void OSBlitToWindow(OSWindowContext* ctx, const Drawable* drawable)
+{
+ if(ctx)
+ {
+ int w = drawable->getWidth();
+ int h = drawable->getHeight();
+
+ int currWin = glutGetWindow();
+ glutSetWindow((int)ctx->window);
+
+ if(!ctx->tmp || ctx->tmpWidth != w || ctx->tmpHeight != h)
+ {
+ RI_DELETE_ARRAY(ctx->tmp);
+ ctx->tmp = NULL;
+ try
+ {
+ ctx->tmp = RI_NEW_ARRAY(unsigned int, w*h); //throws bad_alloc
+ ctx->tmpWidth = w;
+ ctx->tmpHeight = h;
+ }
+ catch(std::bad_alloc)
+ {
+ //do nothing
+ }
+ }
+
+ if(ctx->tmp)
+ {
+ glViewport(0, 0, w, h);
+ glDisable(GL_DEPTH_TEST);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ //NOTE: we assume here that the display is always in sRGB color space
+ VGImageFormat f = VG_sXBGR_8888;
+ if(isBigEndian())
+ f = VG_sRGBX_8888;
+ vgReadPixels(ctx->tmp, w*sizeof(unsigned int), f, 0, 0, w, h);
+ glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, ctx->tmp);
+ }
+
+ glutSwapBuffers(); //shows the OpenGL frame buffer
+ glutSetWindow(currWin); //restore the current window
+ }
+}
+
+#else
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+//Mac OS X native
+#include <OpenGL/gl.h>
+#include <AGL/agl.h>
+
+struct OSWindowContext
+{
+ AGLPixelFormat aglPixFmt;
+ AGLContext aglContext;
+ WindowPtr window;
+ unsigned int* tmp;
+ int tmpWidth;
+ int tmpHeight;
+};
+
+void* OSCreateWindowContext(EGLNativeWindowType window)
+{
+ OSWindowContext* ctx = NULL;
+ try
+ {
+ ctx = RI_NEW(OSWindowContext, ());
+ }
+ catch(std::bad_alloc)
+ {
+ return NULL;
+ }
+
+ GLint attrib[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_DEPTH_SIZE, 32, AGL_NONE };
+ ctx->aglPixFmt = aglChoosePixelFormat(NULL, 0, attrib);
+ if(!ctx->aglPixFmt)
+ {
+ RI_DELETE(ctx);
+ return NULL;
+ }
+
+ ctx->aglContext = aglCreateContext(ctx->aglPixFmt, NULL);
+ if(!ctx->aglContext)
+ {
+ aglDestroyPixelFormat(ctx->aglPixFmt);
+ RI_DELETE(ctx);
+ return NULL;
+ }
+
+ GLint opaque = 1;
+ GLint sync = 1;
+ aglSetInteger(ctx->aglContext, AGL_SURFACE_OPACITY, &opaque);
+ aglSetInteger(ctx->aglContext, AGL_SWAP_INTERVAL, &sync);
+
+ ctx->window = (WindowPtr)window;
+ ctx->tmp = NULL;
+ ctx->tmpWidth = 0;
+ ctx->tmpHeight = 0;
+ return ctx;
+}
+
+void OSDestroyWindowContext(void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ aglSetDrawable(ctx->aglContext, NULL);
+ aglSetCurrentContext(NULL);
+ aglDestroyContext(ctx->aglContext);
+ aglDestroyPixelFormat(ctx->aglPixFmt);
+ RI_DELETE_ARRAY(ctx->tmp);
+ RI_DELETE(ctx);
+ }
+}
+
+bool OSIsWindow(const void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ if(IsValidWindowPtr(ctx->window))
+ return true;
+ }
+ return false;
+}
+
+void OSGetWindowSize(const void* context, int& width, int& height)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ Rect rectPort;
+ GetWindowPortBounds(ctx->window, &rectPort);
+ width = rectPort.right - rectPort.left;
+ height = rectPort.bottom - rectPort.top;
+ }
+ else
+ {
+ width = 0;
+ height = 0;
+ }
+}
+
+void OSBlitToWindow(void* context, const Drawable* drawable)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ int w = drawable->getWidth();
+ int h = drawable->getHeight();
+
+ GrafPtr portSave = NULL;
+ GetPort(&portSave);
+ SetPort((GrafPtr)GetWindowPort(ctx->window));
+ aglSetDrawable(ctx->aglContext, GetWindowPort(ctx->window));
+ aglSetCurrentContext(ctx->aglContext);
+
+ if(!ctx->tmp || ctx->tmpWidth != w || ctx->tmpHeight != h)
+ {
+ RI_DELETE_ARRAY(ctx->tmp);
+ ctx->tmp = NULL;
+ try
+ {
+ ctx->tmp = RI_NEW_ARRAY(unsigned int, w*h); //throws bad_alloc
+ ctx->tmpWidth = w;
+ ctx->tmpHeight = h;
+ }
+ catch(std::bad_alloc)
+ {
+ //do nothing
+ }
+ }
+
+ if(ctx->tmp)
+ {
+ glViewport(0, 0, w, h);
+ glDisable(GL_DEPTH_TEST);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ //NOTE: we assume here that the display is always in sRGB color space
+ VGImageFormat f = VG_sXBGR_8888;
+ if(isBigEndian())
+ f = VG_sRGBX_8888;
+ vgReadPixels(ctx->tmp, w*sizeof(unsigned int), f, 0, 0, w, h);
+ glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, ctx->tmp);
+ }
+
+ aglSwapBuffers(ctx->aglContext);
+ SetPort(portSave);
+ }
+}
+
+#endif
+
+EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id)
+{
+ RI_UNREF(display_id);
+ return (EGLDisplay)1; //support only a single display
+}
+
+} //namespace OpenVGRI
diff --git a/ri/src/null/riEGLOS.cpp b/ri/src/null/riEGLOS.cpp
new file mode 100644
index 0000000..a1748bc
--- /dev/null
+++ b/ri/src/null/riEGLOS.cpp
@@ -0,0 +1,160 @@
+/*------------------------------------------------------------------------
+ *
+ * EGL 1.3
+ * -------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Generic OS EGL functionality (not thread safe, no window rendering)
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "egl.h"
+#include "riImage.h"
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void* OSGetCurrentThreadID(void)
+{
+ return NULL;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static int mutexRefCount = 0;
+static bool mutexInitialized = false;
+//acquired mutex cannot be deinited
+void OSDeinitMutex(void)
+{
+ RI_ASSERT(mutexInitialized);
+ RI_ASSERT(mutexRefCount == 0);
+}
+void OSAcquireMutex(void)
+{
+ if(!mutexInitialized)
+ {
+ mutexInitialized = true;
+ }
+ mutexRefCount++;
+}
+void OSReleaseMutex(void)
+{
+ RI_ASSERT(mutexInitialized);
+ mutexRefCount--;
+ RI_ASSERT(mutexRefCount >= 0);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+struct OSWindowContext
+{
+ int tmpWidth;
+ int tmpHeight;
+};
+
+void* OSCreateWindowContext(EGLNativeWindowType window)
+{
+ OSWindowContext* ctx = NULL;
+ try
+ {
+ ctx = RI_NEW(OSWindowContext, ());
+ }
+ catch(std::bad_alloc)
+ {
+ return NULL;
+ }
+ ctx->tmpWidth = 0;
+ ctx->tmpHeight = 0;
+ return ctx;
+}
+
+void OSDestroyWindowContext(void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ RI_DELETE(ctx);
+ }
+}
+
+bool OSIsWindow(const void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ return true;
+ }
+ return false;
+}
+
+void OSGetWindowSize(const void* context, int& width, int& height)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ width = ctx->tmpWidth;
+ height = ctx->tmpHeight;
+ }
+ else
+ {
+ width = 0;
+ height = 0;
+ }
+}
+
+void OSBlitToWindow(void* context, const Drawable* drawable)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ ctx->tmpWidth = drawable->getWidth();
+ ctx->tmpHeight = drawable->getHeight();
+ }
+}
+
+EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id)
+{
+ RI_UNREF(display_id);
+ return (EGLDisplay)1; //support only a single display
+}
+
+} //namespace OpenVGRI
diff --git a/ri/src/riApi.cpp b/ri/src/riApi.cpp
new file mode 100644
index 0000000..9532de4
--- /dev/null
+++ b/ri/src/riApi.cpp
@@ -0,0 +1,3665 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Implementations of OpenVG API functions.
+ * \note The actual processing is done in Path, Image, Rasterizer and PixelPipe classes.
+ *//*-------------------------------------------------------------------*/
+
+#include "openvg.h"
+#include "egl.h"
+#include "riContext.h"
+#include "riRasterizer.h"
+#include "riPixelPipe.h"
+#include "riPath.h"
+#include <stdio.h>
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+/* EGL&OS functions for use in an OpenVG implementation */
+void* eglvgGetCurrentVGContext(void);
+bool eglvgIsInUse(void* image);
+void OSAcquireMutex(void);
+void OSReleaseMutex(void);
+
+
+#define RI_NO_RETVAL
+
+//this must be the first line in an API function
+#define RI_GET_CONTEXT(RETVAL) \
+ OSAcquireMutex(); \
+ VGContext* context = (VGContext*)eglvgGetCurrentVGContext(); \
+ if(!context) \
+ { \
+ OSReleaseMutex(); \
+ return RETVAL;\
+ }
+
+#define RI_IF_ERROR(COND, ERRORCODE, RETVAL) \
+ if(COND) { context->setError(ERRORCODE); OSReleaseMutex(); return RETVAL; }
+
+//all API functions must call this as their last operation (also functions that don't return values)
+//NOTE: don't evaluate anything or read state in RETVAL (it'll be executed after the mutex has been released)
+#define RI_RETURN(RETVAL) \
+ { OSReleaseMutex(); \
+ return RETVAL; }
+
+static bool isAligned(const void* ptr, int alignment)
+{
+ RI_ASSERT(alignment == 1 || alignment == 2 || alignment == 4);
+ if(((RIuintptr)ptr) & (alignment-1))
+ return false;
+ return true;
+}
+
+static bool isAligned(const void* ptr, VGImageFormat format)
+{
+ RI_ASSERT(isValidImageFormat(format));
+ int alignment = Color::formatToDescriptor(format).bitsPerPixel >> 3;
+ if(alignment <= 1)
+ return true; //one bit or byte per pixel
+ return isAligned(ptr, alignment);
+}
+
+bool isValidImageFormat(int f)
+{
+ if(f < VG_sRGBX_8888 || f > VG_lABGR_8888_PRE)
+ return false;
+ return true;
+}
+
+} //namespace OpenVGRI
+
+using namespace OpenVGRI;
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgFlush(void)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ //the RI doesn't cache anything, so this is a no-op
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgFinish(void)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ //the RI doesn't cache anything, so this is a no-op
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGErrorCode RI_APIENTRY vgGetError(void)
+{
+ RI_GET_CONTEXT(VG_NO_CONTEXT_ERROR);
+ VGErrorCode error = context->m_error;
+ context->m_error = VG_NO_ERROR;
+ RI_RETURN(error);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+namespace OpenVGRI
+{
+
+RIfloat inputFloat(VGfloat f)
+{
+ //this function is used for all floating point input values
+ if(RI_ISNAN(f)) return 0.0f; //convert NaN to zero
+ return RI_CLAMP(f, -RI_FLOAT_MAX, RI_FLOAT_MAX); //clamp +-inf to +-RIfloat max
+}
+
+Vector2 inputVector2(const Vector2& v)
+{
+ return Vector2(inputFloat(v.x), inputFloat(v.y));
+}
+
+Color inputColor(const Color& c)
+{
+ Color r = c;
+ r.r = inputFloat(r.r);
+ r.g = inputFloat(r.g);
+ r.b = inputFloat(r.b);
+ r.a = inputFloat(r.a);
+ return r;
+}
+
+static int inputFloatToInt(VGfloat value)
+{
+ double v = (double)floor(value);
+ v = v > (double)RI_INT32_MAX ? (double)RI_INT32_MAX : v;
+ v = v < (double)RI_INT32_MIN ? (double)RI_INT32_MIN : v;
+ return (int)v;
+}
+
+static int paramToInt(const void* values, bool floats, int count, int i)
+{
+ RI_ASSERT(i >= 0);
+ if(i >= count || !values)
+ return 0;
+ if(floats)
+ return inputFloatToInt(((const VGfloat*)values)[i]);
+ return (int)((const VGint*)values)[i];
+}
+
+static RIfloat paramToFloat(const void* values, bool floats, int count, int i)
+{
+ RI_ASSERT(i >= 0);
+ if(i >= count || !values)
+ return 0.0f;
+ if(floats)
+ return ((const VGfloat*)values)[i];
+ return (RIfloat)((const VGint*)values)[i];
+}
+
+static void floatToParam(void* output, bool outputFloats, int count, int i, VGfloat value)
+{
+ RI_ASSERT(i >= 0);
+ RI_ASSERT(output);
+ if(i >= count)
+ return;
+ if(outputFloats)
+ ((VGfloat*)output)[i] = value;
+ else
+ ((VGint*)output)[i] = (VGint)inputFloatToInt(value);
+}
+
+static void intToParam(void* output, bool outputFloats, int count, int i, VGint value)
+{
+ RI_ASSERT(i >= 0);
+ RI_ASSERT(output);
+ if(i >= count)
+ return;
+ if(outputFloats)
+ ((VGfloat*)output)[i] = (VGfloat)value;
+ else
+ ((VGint*)output)[i] = value;
+}
+
+} //namespace OpenVGRI
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static void setifv(VGContext* context, VGParamType type, VGint count, const void* values, bool floats)
+{
+ RI_ASSERT(context);
+ RI_ASSERT(!count || (count && values));
+
+ int ivalue = paramToInt(values, floats, count, 0);
+ RIfloat fvalue = paramToFloat(values, floats, count, 0);
+
+ switch(type)
+ {
+ case VG_MATRIX_MODE:
+ if(count != 1 || ivalue < VG_MATRIX_PATH_USER_TO_SURFACE || ivalue > VG_MATRIX_GLYPH_USER_TO_SURFACE) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_matrixMode = (VGMatrixMode)ivalue;
+ break;
+
+ case VG_FILL_RULE:
+ if(count != 1 || ivalue < VG_EVEN_ODD || ivalue > VG_NON_ZERO) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_fillRule = (VGFillRule)ivalue;
+ break;
+
+ case VG_IMAGE_QUALITY:
+ if(count != 1 || ivalue < VG_IMAGE_QUALITY_NONANTIALIASED || ivalue > VG_IMAGE_QUALITY_BETTER) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_imageQuality = (VGImageQuality)ivalue;
+ break;
+
+ case VG_RENDERING_QUALITY:
+ if(count != 1 || ivalue < VG_RENDERING_QUALITY_NONANTIALIASED || ivalue > VG_RENDERING_QUALITY_BETTER) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_renderingQuality = (VGRenderingQuality)ivalue;
+ break;
+
+ case VG_BLEND_MODE:
+ if(count != 1 || ivalue < VG_BLEND_SRC || ivalue > VG_BLEND_ADDITIVE) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_blendMode = (VGBlendMode)ivalue;
+ break;
+
+ case VG_IMAGE_MODE:
+ if(count != 1 || ivalue < VG_DRAW_IMAGE_NORMAL || ivalue > VG_DRAW_IMAGE_STENCIL) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_imageMode = (VGImageMode)ivalue;
+ break;
+
+ case VG_SCISSOR_RECTS:
+ {
+ if(count & 3) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; } //count must be a multiple of four
+ try
+ {
+ Array<Rectangle> scissor;
+ for(int i=0;i<RI_INT_MIN(count, RI_MAX_SCISSOR_RECTANGLES*4);i+=4)
+ {
+ Rectangle s;
+ s.x = paramToInt(values, floats, count, i+0);
+ s.y = paramToInt(values, floats, count, i+1);
+ s.width = paramToInt(values, floats, count, i+2);
+ s.height = paramToInt(values, floats, count, i+3);
+ scissor.push_back(s); //throws bad_alloc
+ }
+ context->m_scissor.swap(scissor); //replace context data
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ break;
+ }
+
+ case VG_COLOR_TRANSFORM:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_colorTransform = ivalue ? VG_TRUE : VG_FALSE;
+ break;
+
+ case VG_COLOR_TRANSFORM_VALUES:
+ if(count != 8 || !values) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ {
+ for(int i=0;i<8;i++)
+ {
+ context->m_inputColorTransformValues[i] = paramToFloat(values, floats, count, i);
+ context->m_colorTransformValues[i] = inputFloat(context->m_inputColorTransformValues[i]);
+ }
+ }
+ break;
+
+ case VG_STROKE_LINE_WIDTH:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_inputStrokeLineWidth = fvalue;
+ context->m_strokeLineWidth = inputFloat(fvalue);
+ break;
+
+ case VG_STROKE_CAP_STYLE:
+ if(count != 1 || ivalue < VG_CAP_BUTT || ivalue > VG_CAP_SQUARE) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_strokeCapStyle = (VGCapStyle)ivalue;
+ break;
+
+ case VG_STROKE_JOIN_STYLE:
+ if(count != 1 || ivalue < VG_JOIN_MITER || ivalue > VG_JOIN_BEVEL) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_strokeJoinStyle = (VGJoinStyle)ivalue;
+ break;
+
+ case VG_STROKE_MITER_LIMIT:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_inputStrokeMiterLimit = fvalue;
+ context->m_strokeMiterLimit = inputFloat(fvalue);
+ break;
+
+ case VG_STROKE_DASH_PATTERN:
+ {
+ try
+ {
+ Array<RIfloat> inputStrokeDashPattern;
+ Array<RIfloat> strokeDashPattern;
+ for(int i=0;i<RI_INT_MIN(count, RI_MAX_DASH_COUNT);i++)
+ {
+ RIfloat v = paramToFloat(values, floats, count, i);
+ inputStrokeDashPattern.push_back(v); //throws bad_alloc
+ strokeDashPattern.push_back(inputFloat(v)); //throws bad_alloc
+ }
+ context->m_inputStrokeDashPattern.swap(inputStrokeDashPattern); //replace context data
+ context->m_strokeDashPattern.swap(strokeDashPattern); //replace context data
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ break;
+ }
+
+ case VG_STROKE_DASH_PHASE:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_inputStrokeDashPhase = fvalue;
+ context->m_strokeDashPhase = inputFloat(fvalue);
+ break;
+
+ case VG_STROKE_DASH_PHASE_RESET:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_strokeDashPhaseReset = ivalue ? VG_TRUE : VG_FALSE;
+ break;
+
+ case VG_TILE_FILL_COLOR:
+ if(count != 4 || !values) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_inputTileFillColor.set(paramToFloat(values, floats, count, 0),
+ paramToFloat(values, floats, count, 1),
+ paramToFloat(values, floats, count, 2),
+ paramToFloat(values, floats, count, 3),
+ Color::sRGBA);
+ context->m_tileFillColor = inputColor(context->m_inputTileFillColor);
+ break;
+
+ case VG_GLYPH_ORIGIN:
+ if(count != 2 || !values) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_inputGlyphOrigin.x = paramToFloat(values, floats, count, 0);
+ context->m_inputGlyphOrigin.y = paramToFloat(values, floats, count, 1);
+ context->m_glyphOrigin = inputVector2(context->m_inputGlyphOrigin);
+ break;
+
+ case VG_CLEAR_COLOR:
+ if(count != 4 || !values) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_inputClearColor.set(paramToFloat(values, floats, count, 0),
+ paramToFloat(values, floats, count, 1),
+ paramToFloat(values, floats, count, 2),
+ paramToFloat(values, floats, count, 3),
+ Color::sRGBA);
+ context->m_clearColor = inputColor(context->m_inputClearColor);
+ break;
+
+ case VG_MASKING:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_masking = ivalue ? VG_TRUE : VG_FALSE;
+ break;
+
+ case VG_SCISSORING:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_scissoring = ivalue ? VG_TRUE : VG_FALSE;
+ break;
+
+ case VG_PIXEL_LAYOUT:
+ if(count != 1 || ivalue < VG_PIXEL_LAYOUT_UNKNOWN || ivalue > VG_PIXEL_LAYOUT_BGR_HORIZONTAL) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_pixelLayout = (VGPixelLayout)ivalue;
+ break;
+
+ case VG_SCREEN_LAYOUT:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ break; //setting read-only values has no effect
+
+ case VG_FILTER_FORMAT_LINEAR:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_filterFormatLinear = ivalue ? VG_TRUE : VG_FALSE;
+ break;
+
+ case VG_FILTER_FORMAT_PREMULTIPLIED:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ context->m_filterFormatPremultiplied = ivalue ? VG_TRUE : VG_FALSE;
+ break;
+
+ case VG_FILTER_CHANNEL_MASK:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ //undefined bits are ignored
+ context->m_filterChannelMask = (VGbitfield)ivalue;
+ break;
+
+ case VG_MAX_SCISSOR_RECTS:
+ case VG_MAX_DASH_COUNT:
+ case VG_MAX_KERNEL_SIZE:
+ case VG_MAX_SEPARABLE_KERNEL_SIZE:
+ case VG_MAX_COLOR_RAMP_STOPS:
+ case VG_MAX_IMAGE_WIDTH:
+ case VG_MAX_IMAGE_HEIGHT:
+ case VG_MAX_IMAGE_PIXELS:
+ case VG_MAX_IMAGE_BYTES:
+ case VG_MAX_FLOAT:
+ case VG_MAX_GAUSSIAN_STD_DEVIATION:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ break; //setting read-only values has no effect
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ break;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetf(VGParamType type, VGfloat value)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(type == VG_SCISSOR_RECTS || type == VG_STROKE_DASH_PATTERN || type == VG_TILE_FILL_COLOR ||
+ type == VG_CLEAR_COLOR, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //vector type value
+ VGfloat values[1] = {value};
+ setifv(context, type, 1, values, true);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSeti(VGParamType type, VGint value)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(type == VG_SCISSOR_RECTS || type == VG_STROKE_DASH_PATTERN || type == VG_TILE_FILL_COLOR ||
+ type == VG_CLEAR_COLOR, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //vector type value
+ VGint values[1] = {value};
+ setifv(context, type, 1, values, false);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetiv(VGParamType type, VGint count, const VGint * values)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(count < 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR((!values && count > 0) || (values && !isAligned(values,4)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ setifv(context, type, count, values, false);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetfv(VGParamType type, VGint count, const VGfloat * values)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(count < 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR((!values && count > 0) || (values && !isAligned(values,4)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ setifv(context, type, count, values, true);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static void getifv(VGContext* context, VGParamType type, VGint count, void* values, bool floats)
+{
+ switch(type)
+ {
+ case VG_MATRIX_MODE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_matrixMode);
+ break;
+
+ case VG_FILL_RULE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_fillRule);
+ break;
+
+ case VG_IMAGE_QUALITY:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_imageQuality);
+ break;
+
+ case VG_RENDERING_QUALITY:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_renderingQuality);
+ break;
+
+ case VG_BLEND_MODE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_blendMode);
+ break;
+
+ case VG_IMAGE_MODE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_imageMode);
+ break;
+
+ case VG_SCISSOR_RECTS:
+ {
+ if(count > context->m_scissor.size()*4) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ for(int i=0;i<context->m_scissor.size();i++)
+ {
+ intToParam(values, floats, count, i*4+0, context->m_scissor[i].x);
+ intToParam(values, floats, count, i*4+1, context->m_scissor[i].y);
+ intToParam(values, floats, count, i*4+2, context->m_scissor[i].width);
+ intToParam(values, floats, count, i*4+3, context->m_scissor[i].height);
+ }
+ break;
+ }
+
+ case VG_COLOR_TRANSFORM:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_colorTransform);
+ break;
+
+ case VG_COLOR_TRANSFORM_VALUES:
+ if(count > 8) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ {
+ for(int i=0;i<count;i++)
+ {
+ floatToParam(values, floats, count, i, context->m_inputColorTransformValues[i]);
+ }
+ }
+ break;
+
+ case VG_STROKE_LINE_WIDTH:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, context->m_inputStrokeLineWidth);
+ break;
+
+ case VG_STROKE_CAP_STYLE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_strokeCapStyle);
+ break;
+
+ case VG_STROKE_JOIN_STYLE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_strokeJoinStyle);
+ break;
+
+ case VG_STROKE_MITER_LIMIT:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, context->m_inputStrokeMiterLimit);
+ break;
+
+ case VG_STROKE_DASH_PATTERN:
+ {
+ if(count > context->m_inputStrokeDashPattern.size()) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ for(int i=0;i<context->m_inputStrokeDashPattern.size();i++)
+ floatToParam(values, floats, count, i, context->m_inputStrokeDashPattern[i]);
+ break;
+ }
+
+ case VG_STROKE_DASH_PHASE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, context->m_inputStrokeDashPhase);
+ break;
+
+ case VG_STROKE_DASH_PHASE_RESET:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_strokeDashPhaseReset);
+ break;
+
+ case VG_TILE_FILL_COLOR:
+ if(count > 4) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, context->m_inputTileFillColor.r);
+ floatToParam(values, floats, count, 1, context->m_inputTileFillColor.g);
+ floatToParam(values, floats, count, 2, context->m_inputTileFillColor.b);
+ floatToParam(values, floats, count, 3, context->m_inputTileFillColor.a);
+ break;
+
+ case VG_CLEAR_COLOR:
+ if(count > 4) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, context->m_inputClearColor.r);
+ floatToParam(values, floats, count, 1, context->m_inputClearColor.g);
+ floatToParam(values, floats, count, 2, context->m_inputClearColor.b);
+ floatToParam(values, floats, count, 3, context->m_inputClearColor.a);
+ break;
+
+ case VG_GLYPH_ORIGIN:
+ if(count > 2) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, context->m_inputGlyphOrigin.x);
+ floatToParam(values, floats, count, 1, context->m_inputGlyphOrigin.y);
+ break;
+
+ case VG_MASKING:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_masking);
+ break;
+
+ case VG_SCISSORING:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_scissoring);
+ break;
+
+ case VG_PIXEL_LAYOUT:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_pixelLayout);
+ break;
+
+ case VG_SCREEN_LAYOUT:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, VG_PIXEL_LAYOUT_UNKNOWN);
+ break;
+
+ case VG_FILTER_FORMAT_LINEAR:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_filterFormatLinear);
+ break;
+
+ case VG_FILTER_FORMAT_PREMULTIPLIED:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_filterFormatPremultiplied);
+ break;
+
+ case VG_FILTER_CHANNEL_MASK:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, context->m_filterChannelMask);
+ break;
+
+ case VG_MAX_SCISSOR_RECTS:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, RI_MAX_SCISSOR_RECTANGLES);
+ break;
+
+ case VG_MAX_DASH_COUNT:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, RI_MAX_DASH_COUNT);
+ break;
+
+ case VG_MAX_KERNEL_SIZE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, RI_MAX_KERNEL_SIZE);
+ break;
+
+ case VG_MAX_SEPARABLE_KERNEL_SIZE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, RI_MAX_SEPARABLE_KERNEL_SIZE);
+ break;
+
+ case VG_MAX_COLOR_RAMP_STOPS:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, RI_MAX_COLOR_RAMP_STOPS);
+ break;
+
+ case VG_MAX_IMAGE_WIDTH:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, RI_MAX_IMAGE_WIDTH);
+ break;
+
+ case VG_MAX_IMAGE_HEIGHT:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, RI_MAX_IMAGE_HEIGHT);
+ break;
+
+ case VG_MAX_IMAGE_PIXELS:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, RI_MAX_IMAGE_PIXELS);
+ break;
+
+ case VG_MAX_IMAGE_BYTES:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, RI_MAX_IMAGE_BYTES);
+ break;
+
+ case VG_MAX_FLOAT:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, RI_FLOAT_MAX);
+ break;
+
+ case VG_MAX_GAUSSIAN_STD_DEVIATION:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, RI_MAX_GAUSSIAN_STD_DEVIATION);
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ break;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGfloat RI_APIENTRY vgGetf(VGParamType type)
+{
+ RI_GET_CONTEXT(0.0f);
+ RI_IF_ERROR(type == VG_SCISSOR_RECTS || type == VG_STROKE_DASH_PATTERN || type == VG_TILE_FILL_COLOR ||
+ type == VG_CLEAR_COLOR, VG_ILLEGAL_ARGUMENT_ERROR, 0.0f); //vector type value
+ RIfloat ret = 0.0f;
+ getifv(context, type, 1, &ret, true);
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGint RI_APIENTRY vgGeti(VGParamType type)
+{
+ RI_GET_CONTEXT(0);
+ RI_IF_ERROR(type == VG_SCISSOR_RECTS || type == VG_STROKE_DASH_PATTERN || type == VG_TILE_FILL_COLOR ||
+ type == VG_CLEAR_COLOR, VG_ILLEGAL_ARGUMENT_ERROR, 0); //vector type value
+ VGint ret = 0;
+ getifv(context, type, 1, &ret, false);
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgGetiv(VGParamType type, VGint count, VGint * values)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(count <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!values || !isAligned(values,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ getifv(context, type, count, values, false);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgGetfv(VGParamType type, VGint count, VGfloat * values)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(count <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!values || !isAligned(values,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ getifv(context, type, count, values, true);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGint RI_APIENTRY vgGetVectorSize(VGParamType type)
+{
+ RI_GET_CONTEXT(0);
+ VGint ret = 0;
+ switch(type)
+ {
+ case VG_MATRIX_MODE:
+ case VG_FILL_RULE:
+ case VG_IMAGE_QUALITY:
+ case VG_RENDERING_QUALITY:
+ case VG_BLEND_MODE:
+ case VG_IMAGE_MODE:
+ ret = 1;
+ break;
+
+ case VG_SCISSOR_RECTS:
+ ret = 4*context->m_scissor.size();
+ break;
+
+ case VG_COLOR_TRANSFORM:
+ ret = 1;
+ break;
+
+ case VG_COLOR_TRANSFORM_VALUES:
+ ret = 8;
+ break;
+
+ case VG_STROKE_LINE_WIDTH:
+ case VG_STROKE_CAP_STYLE:
+ case VG_STROKE_JOIN_STYLE:
+ case VG_STROKE_MITER_LIMIT:
+ ret = 1;
+ break;
+
+ case VG_STROKE_DASH_PATTERN:
+ ret = context->m_inputStrokeDashPattern.size();
+ break;
+
+ case VG_STROKE_DASH_PHASE:
+ case VG_STROKE_DASH_PHASE_RESET:
+ ret = 1;
+ break;
+
+ case VG_TILE_FILL_COLOR:
+ case VG_CLEAR_COLOR:
+ ret = 4;
+ break;
+
+ case VG_GLYPH_ORIGIN:
+ ret = 2;
+ break;
+
+ case VG_MASKING:
+ case VG_SCISSORING:
+ case VG_PIXEL_LAYOUT:
+ case VG_SCREEN_LAYOUT:
+ case VG_FILTER_FORMAT_LINEAR:
+ case VG_FILTER_FORMAT_PREMULTIPLIED:
+ case VG_FILTER_CHANNEL_MASK:
+ case VG_MAX_SCISSOR_RECTS:
+ case VG_MAX_DASH_COUNT:
+ case VG_MAX_KERNEL_SIZE:
+ case VG_MAX_SEPARABLE_KERNEL_SIZE:
+ case VG_MAX_COLOR_RAMP_STOPS:
+ case VG_MAX_IMAGE_WIDTH:
+ case VG_MAX_IMAGE_HEIGHT:
+ case VG_MAX_IMAGE_PIXELS:
+ case VG_MAX_IMAGE_BYTES:
+ case VG_MAX_FLOAT:
+ case VG_MAX_GAUSSIAN_STD_DEVIATION:
+ ret = 1;
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ break;
+ }
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static void setPaintParameterifv(VGContext* context, Paint* paint, VGPaintParamType paramType, VGint count, const void* values, bool floats)
+{
+ RI_ASSERT(context);
+ RI_ASSERT(paint);
+
+ int ivalue = paramToInt(values, floats, count, 0);
+
+ switch(paramType)
+ {
+ case VG_PAINT_TYPE:
+ if(count != 1 || ivalue < VG_PAINT_TYPE_COLOR || ivalue > VG_PAINT_TYPE_PATTERN) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ paint->m_paintType = (VGPaintType)ivalue;
+ break;
+
+ case VG_PAINT_COLOR:
+ if(count != 4) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ paint->m_inputPaintColor.set(paramToFloat(values, floats, count, 0),
+ paramToFloat(values, floats, count, 1),
+ paramToFloat(values, floats, count, 2),
+ paramToFloat(values, floats, count, 3),
+ Color::sRGBA);
+ paint->m_paintColor = inputColor(paint->m_inputPaintColor);
+ paint->m_paintColor.clamp();
+ paint->m_paintColor.premultiply();
+ break;
+
+ case VG_PAINT_COLOR_RAMP_SPREAD_MODE:
+ if(count != 1 || ivalue < VG_COLOR_RAMP_SPREAD_PAD || ivalue > VG_COLOR_RAMP_SPREAD_REFLECT) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ paint->m_colorRampSpreadMode = (VGColorRampSpreadMode)ivalue;
+ break;
+
+ case VG_PAINT_COLOR_RAMP_STOPS:
+ {
+ int numStops = count/5;
+ if(count != numStops*5) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; } //count must be a multiple of five
+ try
+ {
+ Array<Paint::GradientStop> colorRampStops;
+ Array<Paint::GradientStop> inputColorRampStops;
+ RIfloat prevOffset = -RI_FLOAT_MAX;
+ bool valid = true;
+ for(int i=0;i<RI_INT_MIN(numStops, RI_MAX_COLOR_RAMP_STOPS);i++) //NOTE: ignores the final stop if there is not enough parameters
+ {
+ Paint::GradientStop gs;
+ gs.offset = paramToFloat(values, floats, count, i*5);
+ gs.color.set(paramToFloat(values, floats, count, i*5+1),
+ paramToFloat(values, floats, count, i*5+2),
+ paramToFloat(values, floats, count, i*5+3),
+ paramToFloat(values, floats, count, i*5+4),
+ Color::sRGBA);
+ inputColorRampStops.push_back(gs);
+
+ if(gs.offset < prevOffset)
+ valid = false; //decreasing sequence, ignore it
+
+ if(gs.offset >= 0.0f && gs.offset <= 1.0f)
+ {
+ gs.color.clamp();
+
+ if(!colorRampStops.size() && gs.offset > 0.0f)
+ { //the first valid stop is not at 0, replicate the first one
+ RIfloat tmp = gs.offset;
+ gs.offset = 0.0f;
+ colorRampStops.push_back(gs); //throws bad_alloc
+ gs.offset = tmp;
+ }
+ colorRampStops.push_back(gs); //throws bad_alloc
+ }
+ prevOffset = gs.offset;
+ }
+ if(valid && colorRampStops.size() && colorRampStops[colorRampStops.size()-1].offset < 1.0f)
+ { //there is at least one stop, but the last one is not at 1, replicate the last one
+ Paint::GradientStop gs = colorRampStops[colorRampStops.size()-1];
+ gs.offset = 1.0f;
+ colorRampStops.push_back(gs); //throws bad_alloc
+ }
+ if(!valid || !colorRampStops.size())
+ { //there are no valid stops, add implicit stops
+ colorRampStops.clear();
+ Paint::GradientStop gs;
+ gs.offset = 0.0f;
+ gs.color.set(0,0,0,1,Color::sRGBA);
+ colorRampStops.push_back(gs); //throws bad_alloc
+ gs.offset = 1.0f;
+ gs.color.set(1,1,1,1,Color::sRGBA);
+ colorRampStops.push_back(gs); //throws bad_alloc
+ }
+ RI_ASSERT(colorRampStops.size() >= 2 && colorRampStops.size() <= RI_MAX_COLOR_RAMP_STOPS);
+ paint->m_colorRampStops.swap(colorRampStops); //set paint array
+ paint->m_inputColorRampStops.swap(inputColorRampStops); //set paint array
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ break;
+ }
+
+ case VG_PAINT_COLOR_RAMP_PREMULTIPLIED:
+ if(count != 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ paint->m_colorRampPremultiplied = ivalue ? VG_TRUE : VG_FALSE;
+ break;
+
+ case VG_PAINT_LINEAR_GRADIENT:
+ if(count != 4) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ paint->m_inputLinearGradientPoint0.set(paramToFloat(values, floats, count, 0),
+ paramToFloat(values, floats, count, 1));
+ paint->m_inputLinearGradientPoint1.set(paramToFloat(values, floats, count, 2),
+ paramToFloat(values, floats, count, 3));
+ paint->m_linearGradientPoint0 = inputVector2(paint->m_inputLinearGradientPoint0);
+ paint->m_linearGradientPoint1 = inputVector2(paint->m_inputLinearGradientPoint1);
+ break;
+
+ case VG_PAINT_RADIAL_GRADIENT:
+ if(count != 5) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ paint->m_inputRadialGradientCenter.set(paramToFloat(values, floats, count, 0),
+ paramToFloat(values, floats, count, 1));
+ paint->m_inputRadialGradientFocalPoint.set(paramToFloat(values, floats, count, 2),
+ paramToFloat(values, floats, count, 3));
+ paint->m_inputRadialGradientRadius = paramToFloat(values, floats, count, 4);
+ paint->m_radialGradientCenter = inputVector2(paint->m_inputRadialGradientCenter);
+ paint->m_radialGradientFocalPoint = inputVector2(paint->m_inputRadialGradientFocalPoint);
+ paint->m_radialGradientRadius = inputFloat(paint->m_inputRadialGradientRadius);
+ break;
+
+ case VG_PAINT_PATTERN_TILING_MODE:
+ if(count != 1 || ivalue < VG_TILE_FILL || ivalue > VG_TILE_REFLECT) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ paint->m_patternTilingMode = (VGTilingMode)ivalue;
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ break;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetParameterf(VGHandle object, VGint paramType, VGfloat value)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ bool isImage = context->isValidImage(object);
+ bool isPath = context->isValidPath(object);
+ bool isPaint = context->isValidPaint(object);
+ bool isMaskLayer = context->isValidMaskLayer(object);
+ bool isFont = context->isValidFont(object);
+ RI_IF_ERROR(!isImage && !isPath && !isPaint && !isMaskLayer && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
+ RI_IF_ERROR(paramType == VG_PAINT_COLOR || paramType == VG_PAINT_COLOR_RAMP_STOPS || paramType == VG_PAINT_LINEAR_GRADIENT ||
+ paramType == VG_PAINT_RADIAL_GRADIENT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //vector valued parameter
+ VGfloat values[1] = {value};
+ if(isImage)
+ { //read only, the function does nothing
+ RI_ASSERT(!isPath && !isPaint && !isMaskLayer && !isFont);
+ if(paramType < VG_IMAGE_FORMAT || paramType > VG_IMAGE_HEIGHT)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else if(isPath)
+ { //read only, the function does nothing
+ RI_ASSERT(!isImage && !isPaint && !isMaskLayer && !isFont);
+ if(paramType < VG_PATH_FORMAT || paramType > VG_PATH_NUM_COORDS)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else if(isPaint)
+ {
+ RI_ASSERT(!isImage && !isPath && !isMaskLayer && !isFont);
+ setPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, 1, values, true);
+ }
+ else if(isMaskLayer)
+ {
+ RI_ASSERT(!isImage && !isPath && !isPaint && !isFont);
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else
+ { //read only, the function does nothing
+ RI_ASSERT(!isImage && !isPath && !isPaint && !isMaskLayer && isFont);
+ if (paramType != VG_FONT_NUM_GLYPHS)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetParameteri(VGHandle object, VGint paramType, VGint value)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ bool isImage = context->isValidImage(object);
+ bool isPath = context->isValidPath(object);
+ bool isPaint = context->isValidPaint(object);
+ bool isMaskLayer = context->isValidMaskLayer(object);
+ bool isFont = context->isValidFont(object);
+ RI_IF_ERROR(!isImage && !isPath && !isPaint && !isMaskLayer && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
+ RI_IF_ERROR(paramType == VG_PAINT_COLOR || paramType == VG_PAINT_COLOR_RAMP_STOPS || paramType == VG_PAINT_LINEAR_GRADIENT ||
+ paramType == VG_PAINT_RADIAL_GRADIENT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //vector valued parameter
+ VGint values[1] = {value};
+ if(isImage)
+ { //read only, the function does nothing
+ RI_ASSERT(!isPath && !isPaint && !isMaskLayer && !isFont);
+ if(paramType < VG_IMAGE_FORMAT || paramType > VG_IMAGE_HEIGHT)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else if(isPath)
+ { //read only, the function does nothing
+ RI_ASSERT(!isImage && !isPaint && !isMaskLayer && !isFont);
+ if(paramType < VG_PATH_FORMAT || paramType > VG_PATH_NUM_COORDS)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else if(isPaint)
+ {
+ RI_ASSERT(!isImage && !isPath && !isMaskLayer && !isFont);
+ setPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, 1, values, false);
+ }
+ else if(isMaskLayer)
+ {
+ RI_ASSERT(!isImage && !isPath && !isPaint && !isFont);
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else
+ { //read only, the function does nothing
+ RI_ASSERT(!isImage && !isPath && !isPaint && !isMaskLayer && isFont);
+ if (paramType != VG_FONT_NUM_GLYPHS)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetParameterfv(VGHandle object, VGint paramType, VGint count, const VGfloat * values)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(count < 0 || (!values && count > 0) || (values && !isAligned(values,4)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ bool isImage = context->isValidImage(object);
+ bool isPath = context->isValidPath(object);
+ bool isPaint = context->isValidPaint(object);
+ bool isMaskLayer = context->isValidMaskLayer(object);
+ bool isFont = context->isValidFont(object);
+ RI_IF_ERROR(!isImage && !isPath && !isPaint && !isMaskLayer && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
+ if(isImage)
+ { //read only, the function does nothing
+ RI_ASSERT(!isPath && !isPaint && !isMaskLayer && !isFont);
+ if(paramType < VG_IMAGE_FORMAT || paramType > VG_IMAGE_HEIGHT)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else if(isPath)
+ { //read only, the function does nothing
+ RI_ASSERT(!isImage && !isPaint && !isMaskLayer && !isFont);
+ if(paramType < VG_PATH_FORMAT || paramType > VG_PATH_NUM_COORDS)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else if(isPaint)
+ {
+ RI_ASSERT(!isImage && !isPath && !isMaskLayer && !isFont);
+ setPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, count, values, true);
+ }
+ else if(isMaskLayer)
+ {
+ RI_ASSERT(!isImage && !isPath && !isPaint && !isFont);
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else
+ { //read only, the function does nothing
+ RI_ASSERT(!isImage && !isPath && !isPaint && !isMaskLayer && isFont);
+ if (paramType != VG_FONT_NUM_GLYPHS)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetParameteriv(VGHandle object, VGint paramType, VGint count, const VGint * values)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(count < 0 || (!values && count > 0) || (values && !isAligned(values,4)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ bool isImage = context->isValidImage(object);
+ bool isPath = context->isValidPath(object);
+ bool isPaint = context->isValidPaint(object);
+ bool isMaskLayer = context->isValidMaskLayer(object);
+ bool isFont = context->isValidFont(object);
+ RI_IF_ERROR(!isImage && !isPath && !isPaint && !isMaskLayer && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
+ if(isImage)
+ { //read only, the function does nothing
+ RI_ASSERT(!isPath && !isPaint && !isMaskLayer && !isFont);
+ if(paramType < VG_IMAGE_FORMAT || paramType > VG_IMAGE_HEIGHT)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else if(isPath)
+ { //read only, the function does nothing
+ RI_ASSERT(!isImage && !isPaint && !isMaskLayer && !isFont);
+ if(paramType < VG_PATH_FORMAT || paramType > VG_PATH_NUM_COORDS)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else if(isPaint)
+ {
+ RI_ASSERT(!isImage && !isPath && !isMaskLayer && !isFont);
+ setPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, count, values, false);
+ }
+ else if(isMaskLayer)
+ {
+ RI_ASSERT(!isImage && !isPath && !isPaint && !isFont);
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ else
+ { //read only, the function does nothing
+ RI_ASSERT(!isImage && !isPath && !isPaint && !isMaskLayer && isFont);
+ if (paramType != VG_FONT_NUM_GLYPHS)
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static void getPaintParameterifv(VGContext* context, Paint* paint, VGPaintParamType type, VGint count, void* values, bool floats)
+{
+ switch(type)
+ {
+ case VG_PAINT_TYPE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, paint->m_paintType);
+ break;
+
+ case VG_PAINT_COLOR:
+ if(count > 4) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, paint->m_inputPaintColor.r);
+ floatToParam(values, floats, count, 1, paint->m_inputPaintColor.g);
+ floatToParam(values, floats, count, 2, paint->m_inputPaintColor.b);
+ floatToParam(values, floats, count, 3, paint->m_inputPaintColor.a);
+ break;
+
+ case VG_PAINT_COLOR_RAMP_SPREAD_MODE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, paint->m_colorRampSpreadMode);
+ break;
+
+ case VG_PAINT_COLOR_RAMP_STOPS:
+ {
+ if(count > paint->m_inputColorRampStops.size()*5) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ int j = 0;
+ for(int i=0;i<paint->m_inputColorRampStops.size();i++)
+ {
+ floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].offset);
+ floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].color.r);
+ floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].color.g);
+ floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].color.b);
+ floatToParam(values, floats, count, j++, paint->m_inputColorRampStops[i].color.a);
+ }
+ break;
+ }
+
+ case VG_PAINT_COLOR_RAMP_PREMULTIPLIED:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, paint->m_colorRampPremultiplied);
+ break;
+
+ case VG_PAINT_LINEAR_GRADIENT:
+ if(count > 4) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, paint->m_inputLinearGradientPoint0.x);
+ floatToParam(values, floats, count, 1, paint->m_inputLinearGradientPoint0.y);
+ floatToParam(values, floats, count, 2, paint->m_inputLinearGradientPoint1.x);
+ floatToParam(values, floats, count, 3, paint->m_inputLinearGradientPoint1.y);
+ break;
+
+ case VG_PAINT_RADIAL_GRADIENT:
+ if(count > 5) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, paint->m_inputRadialGradientCenter.x);
+ floatToParam(values, floats, count, 1, paint->m_inputRadialGradientCenter.y);
+ floatToParam(values, floats, count, 2, paint->m_inputRadialGradientFocalPoint.x);
+ floatToParam(values, floats, count, 3, paint->m_inputRadialGradientFocalPoint.y);
+ floatToParam(values, floats, count, 4, paint->m_inputRadialGradientRadius);
+ break;
+
+ case VG_PAINT_PATTERN_TILING_MODE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, paint->m_patternTilingMode);
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ break;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static void getPathParameterifv(VGContext* context, Path* path, VGPathParamType type, VGint count, void* values, bool floats)
+{
+ switch(type)
+ {
+ case VG_PATH_FORMAT:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, path->getFormat());
+ break;
+
+ case VG_PATH_DATATYPE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, path->getDatatype());
+ break;
+
+ case VG_PATH_SCALE:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, path->getScale());
+ break;
+
+ case VG_PATH_BIAS:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ floatToParam(values, floats, count, 0, path->getBias());
+ break;
+
+ case VG_PATH_NUM_SEGMENTS:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, path->getNumSegments());
+ break;
+
+ case VG_PATH_NUM_COORDS:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, path->getNumCoordinates());
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ break;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static void getImageParameterifv(VGContext* context, Image* image, VGImageParamType type, VGint count, void* values, bool floats)
+{
+ switch(type)
+ {
+ case VG_IMAGE_FORMAT:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ RI_ASSERT(isValidImageFormat(image->getDescriptor().format));
+ intToParam(values, floats, count, 0, image->getDescriptor().format);
+ break;
+
+ case VG_IMAGE_WIDTH:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, image->getWidth());
+ break;
+
+ case VG_IMAGE_HEIGHT:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, image->getHeight());
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ break;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static void getFontParameterifv(VGContext* context, Font* font, VGFontParamType type, VGint count, void* values, bool floats)
+{
+ switch(type)
+ {
+ case VG_FONT_NUM_GLYPHS:
+ if(count > 1) { context->setError(VG_ILLEGAL_ARGUMENT_ERROR); return; }
+ intToParam(values, floats, count, 0, font->getNumGlyphs());
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid VGParamType
+ break;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGfloat RI_APIENTRY vgGetParameterf(VGHandle object, VGint paramType)
+{
+ RI_GET_CONTEXT(0.0f);
+ RI_IF_ERROR(paramType == VG_PAINT_COLOR || paramType == VG_PAINT_COLOR_RAMP_STOPS || paramType == VG_PAINT_LINEAR_GRADIENT ||
+ paramType == VG_PAINT_RADIAL_GRADIENT, VG_ILLEGAL_ARGUMENT_ERROR, 0.0f); //vector valued parameter
+ bool isImage = context->isValidImage(object);
+ bool isPath = context->isValidPath(object);
+ bool isPaint = context->isValidPaint(object);
+ bool isFont = context->isValidFont(object);
+ RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, 0.0f); //invalid object handle
+ VGfloat ret = 0.0f;
+ if(isImage)
+ {
+ RI_ASSERT(!isPath && !isPaint && !isFont);
+ getImageParameterifv(context, (Image*)object, (VGImageParamType)paramType, 1, &ret, true);
+ }
+ else if(isPath)
+ {
+ RI_ASSERT(!isImage && !isPaint && !isFont);
+ getPathParameterifv(context, (Path*)object, (VGPathParamType)paramType, 1, &ret, true);
+ }
+ else if(isPaint)
+ {
+ RI_ASSERT(!isImage && !isPath && !isFont);
+ getPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, 1, &ret, true);
+ }
+ else
+ {
+ RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
+ getFontParameterifv(context, (Font*)object, (VGFontParamType)paramType, 1, &ret, true);
+ }
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGint RI_APIENTRY vgGetParameteri(VGHandle object, VGint paramType)
+{
+ RI_GET_CONTEXT(0);
+ RI_IF_ERROR(paramType == VG_PAINT_COLOR || paramType == VG_PAINT_COLOR_RAMP_STOPS || paramType == VG_PAINT_LINEAR_GRADIENT ||
+ paramType == VG_PAINT_RADIAL_GRADIENT, VG_ILLEGAL_ARGUMENT_ERROR, 0); //vector valued parameter
+ bool isImage = context->isValidImage(object);
+ bool isPath = context->isValidPath(object);
+ bool isPaint = context->isValidPaint(object);
+ bool isFont = context->isValidFont(object);
+ RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, 0); //invalid object handle
+ VGint ret = 0;
+ if(isImage)
+ {
+ RI_ASSERT(!isPath && !isPaint && !isFont);
+ getImageParameterifv(context, (Image*)object, (VGImageParamType)paramType, 1, &ret, false);
+ }
+ else if(isPath)
+ {
+ RI_ASSERT(!isImage && !isPaint && !isFont);
+ getPathParameterifv(context, (Path*)object, (VGPathParamType)paramType, 1, &ret, false);
+ }
+ else if(isPaint)
+ {
+ RI_ASSERT(!isImage && !isPath && !isFont);
+ getPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, 1, &ret, false);
+ }
+ else
+ {
+ RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
+ getFontParameterifv(context, (Font*)object, (VGFontParamType)paramType, 1, &ret, false);
+ }
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgGetParameterfv(VGHandle object, VGint paramType, VGint count, VGfloat * values)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(count <= 0 || !values || !isAligned(values,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ bool isImage = context->isValidImage(object);
+ bool isPath = context->isValidPath(object);
+ bool isPaint = context->isValidPaint(object);
+ bool isFont = context->isValidFont(object);
+ RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
+ if(isImage)
+ {
+ RI_ASSERT(!isPath && !isPaint && !isFont);
+ getImageParameterifv(context, (Image*)object, (VGImageParamType)paramType, count, values, true);
+ }
+ else if(isPath)
+ {
+ RI_ASSERT(!isImage && !isPaint && !isFont);
+ getPathParameterifv(context, (Path*)object, (VGPathParamType)paramType, count, values, true);
+ }
+ else if(isPaint)
+ {
+ RI_ASSERT(!isImage && !isPath && !isFont);
+ getPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, count, values, true);
+ }
+ else
+ {
+ RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
+ getFontParameterifv(context, (Font*)object, (VGFontParamType)paramType, count, values, true);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgGetParameteriv(VGHandle object, VGint paramType, VGint count, VGint * values)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(count <= 0 || !values || !isAligned(values,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ bool isImage = context->isValidImage(object);
+ bool isPath = context->isValidPath(object);
+ bool isPaint = context->isValidPaint(object);
+ bool isFont = context->isValidFont(object);
+ RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid object handle
+ if(isImage)
+ {
+ RI_ASSERT(!isPath && !isPaint && !isFont);
+ getImageParameterifv(context, (Image*)object, (VGImageParamType)paramType, count, values, false);
+ }
+ else if(isPath)
+ {
+ RI_ASSERT(!isImage && !isPaint && !isFont);
+ getPathParameterifv(context, (Path*)object, (VGPathParamType)paramType, count, values, false);
+ }
+ else if(isPaint)
+ {
+ RI_ASSERT(!isImage && !isPath && !isFont);
+ getPaintParameterifv(context, (Paint*)object, (VGPaintParamType)paramType, count, values, false);
+ }
+ else
+ {
+ RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
+ getFontParameterifv(context, (Font*)object, (VGFontParamType)paramType, count, values, false);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGint RI_APIENTRY vgGetParameterVectorSize(VGHandle object, VGint paramType)
+{
+ RI_GET_CONTEXT(0);
+ bool isImage = context->isValidImage(object);
+ bool isPath = context->isValidPath(object);
+ bool isPaint = context->isValidPaint(object);
+ bool isFont = context->isValidFont(object);
+ RI_IF_ERROR(!isImage && !isPath && !isPaint && !isFont, VG_BAD_HANDLE_ERROR, 0); //invalid object handle
+ int ret = 0;
+ if(isImage)
+ {
+ RI_ASSERT(!isPath && !isPaint && !isFont);
+ switch(paramType)
+ {
+ case VG_IMAGE_FORMAT:
+ case VG_IMAGE_WIDTH:
+ case VG_IMAGE_HEIGHT:
+ ret = 1;
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid paramType
+ break;
+ }
+ }
+ else if(isPath)
+ {
+ RI_ASSERT(!isImage && !isPaint && !isFont);
+ switch(paramType)
+ {
+ case VG_PATH_FORMAT:
+ case VG_PATH_DATATYPE:
+ case VG_PATH_SCALE:
+ case VG_PATH_BIAS:
+ case VG_PATH_NUM_SEGMENTS:
+ case VG_PATH_NUM_COORDS:
+ ret = 1;
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid paramType
+ break;
+ }
+ }
+ else if(isPaint)
+ {
+ RI_ASSERT(!isImage && !isPath && !isFont);
+ switch(paramType)
+ {
+ case VG_PAINT_TYPE:
+ case VG_PAINT_COLOR_RAMP_SPREAD_MODE:
+ case VG_PAINT_PATTERN_TILING_MODE:
+ ret = 1;
+ break;
+
+ case VG_PAINT_COLOR:
+ case VG_PAINT_LINEAR_GRADIENT:
+ ret = 4;
+ break;
+
+ case VG_PAINT_COLOR_RAMP_STOPS:
+ ret = ((Paint*)object)->m_inputColorRampStops.size() * 5;
+ break;
+
+ case VG_PAINT_COLOR_RAMP_PREMULTIPLIED:
+ ret = 1;
+ break;
+
+ case VG_PAINT_RADIAL_GRADIENT:
+ ret = 5;
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid paramType
+ break;
+ }
+ }
+ else
+ {
+ RI_ASSERT(!isImage && !isPath && !isPaint && isFont);
+ switch(paramType)
+ {
+ case VG_FONT_NUM_GLYPHS:
+ ret = 1;
+ break;
+
+ default:
+ context->setError(VG_ILLEGAL_ARGUMENT_ERROR); //invalid paramType
+ break;
+ }
+ }
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static Matrix3x3* getCurrentMatrix(VGContext* context)
+{
+ RI_ASSERT(context);
+ switch(context->m_matrixMode)
+ {
+ case VG_MATRIX_PATH_USER_TO_SURFACE:
+ return &context->m_pathUserToSurface;
+
+ case VG_MATRIX_IMAGE_USER_TO_SURFACE:
+ return &context->m_imageUserToSurface;
+
+ case VG_MATRIX_FILL_PAINT_TO_USER:
+ return &context->m_fillPaintToUser;
+
+ case VG_MATRIX_STROKE_PAINT_TO_USER:
+ return &context->m_strokePaintToUser;
+
+ default:
+ RI_ASSERT(context->m_matrixMode == VG_MATRIX_GLYPH_USER_TO_SURFACE);
+ return &context->m_glyphUserToSurface;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgLoadIdentity(void)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ Matrix3x3* d = getCurrentMatrix(context);
+ d->identity();
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgLoadMatrix(const VGfloat * m)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!m || !isAligned(m,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Matrix3x3* d = getCurrentMatrix(context);
+ d->set(inputFloat(m[0]), inputFloat(m[3]), inputFloat(m[6]),
+ inputFloat(m[1]), inputFloat(m[4]), inputFloat(m[7]),
+ inputFloat(m[2]), inputFloat(m[5]), inputFloat(m[8]));
+ if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
+ {
+ (*d)[2].set(0,0,1);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgGetMatrix(VGfloat * m)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!m || !isAligned(m,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Matrix3x3* d = getCurrentMatrix(context);
+ m[0] = (*d)[0][0];
+ m[1] = (*d)[1][0];
+ m[2] = (*d)[2][0];
+ m[3] = (*d)[0][1];
+ m[4] = (*d)[1][1];
+ m[5] = (*d)[2][1];
+ m[6] = (*d)[0][2];
+ m[7] = (*d)[1][2];
+ m[8] = (*d)[2][2];
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgMultMatrix(const VGfloat * m)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!m || !isAligned(m,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Matrix3x3 n(inputFloat(m[0]), inputFloat(m[3]), inputFloat(m[6]),
+ inputFloat(m[1]), inputFloat(m[4]), inputFloat(m[7]),
+ inputFloat(m[2]), inputFloat(m[5]), inputFloat(m[8]));
+ if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
+ n[2].set(0,0,1);
+
+ Matrix3x3* d = getCurrentMatrix(context);
+ *d *= n;
+ if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
+ {
+ (*d)[2].set(0,0,1); //force affinity
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgTranslate(VGfloat tx, VGfloat ty)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ Matrix3x3 n(1, 0, inputFloat(tx),
+ 0, 1, inputFloat(ty),
+ 0, 0, 1 );
+ Matrix3x3* d = getCurrentMatrix(context);
+ *d *= n;
+ if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
+ {
+ (*d)[2].set(0,0,1); //force affinity
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgScale(VGfloat sx, VGfloat sy)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ Matrix3x3 n(inputFloat(sx), 0, 0,
+ 0, inputFloat(sy), 0,
+ 0, 0, 1 );
+ Matrix3x3* d = getCurrentMatrix(context);
+ *d *= n;
+ if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
+ {
+ (*d)[2].set(0,0,1); //force affinity
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgShear(VGfloat shx, VGfloat shy)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ Matrix3x3 n(1, inputFloat(shx), 0,
+ inputFloat(shy), 1, 0,
+ 0, 0, 1);
+ Matrix3x3* d = getCurrentMatrix(context);
+ *d *= n;
+ if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
+ {
+ (*d)[2].set(0,0,1); //force affinity
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgRotate(VGfloat angle)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RIfloat a = RI_DEG_TO_RAD(inputFloat(angle));
+ Matrix3x3 n((RIfloat)cos(a), -(RIfloat)sin(a), 0,
+ (RIfloat)sin(a), (RIfloat)cos(a), 0,
+ 0, 0, 1 );
+ Matrix3x3* d = getCurrentMatrix(context);
+ *d *= n;
+ if(context->m_matrixMode != VG_MATRIX_IMAGE_USER_TO_SURFACE)
+ {
+ (*d)[2].set(0,0,1); //force affinity
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgMask(VGHandle mask, VGMaskOperation operation, VGint x, VGint y, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ bool isImage = context->isValidImage(mask);
+ bool isMaskLayer = context->isValidMaskLayer(mask);
+ RI_IF_ERROR(operation != VG_CLEAR_MASK && operation != VG_FILL_MASK && !isImage && !isMaskLayer, VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(operation != VG_CLEAR_MASK && operation != VG_FILL_MASK && isImage && eglvgIsInUse((Image*)mask), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(operation < VG_CLEAR_MASK || operation > VG_SUBTRACT_MASK, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Drawable* drawable = context->getCurrentDrawable();
+ RI_IF_ERROR(isMaskLayer && drawable->getNumSamples() != ((Surface*)mask)->getNumSamples(), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ if(!drawable || !drawable->getMaskBuffer())
+ {
+ RI_RETURN(RI_NO_RETVAL); //no EGL surface is current at the moment or context has no mask buffer
+ }
+ if(isImage)
+ drawable->getMaskBuffer()->mask((Image*)mask, operation, x, y, width, height);
+ else
+ drawable->getMaskBuffer()->mask((Surface*)mask, operation, x, y, width, height);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static void renderStroke(const VGContext* context, int w, int h, int numSamples, Path* path, Rasterizer& rasterizer, const PixelPipe* pixelPipe, const Matrix3x3& userToSurface)
+{
+ RI_ASSERT(context);
+ RI_ASSERT(w > 0 && h > 0 && numSamples >= 1 && numSamples <= 32);
+
+ RIuint32* covBuffer = RI_NEW_ARRAY(RIuint32, w*h);
+ memset(covBuffer, 0, w*h*sizeof(RIuint32));
+
+ rasterizer.setup(0, 0, w, h, VG_NON_ZERO, NULL, covBuffer);
+ path->stroke(userToSurface, rasterizer, context->m_strokeDashPattern, context->m_strokeDashPhase, context->m_strokeDashPhaseReset ? true : false,
+ context->m_strokeLineWidth, context->m_strokeCapStyle, context->m_strokeJoinStyle, RI_MAX(context->m_strokeMiterLimit, 1.0f)); //throws bad_alloc
+
+ int sx,sy,ex,ey;
+ rasterizer.getBBox(sx,sy,ex,ey);
+ RI_ASSERT(sx >= 0 && sx <= w);
+ RI_ASSERT(sy >= 0 && sy <= h);
+ RI_ASSERT(ex >= 0 && ex <= w);
+ RI_ASSERT(ey >= 0 && ey <= h);
+
+ for(int j=sy;j<ey;j++)
+ {
+ for(int i=sx;i<ex;i++)
+ {
+ unsigned int c = covBuffer[j*w+i];
+ if(c)
+ {
+ int coverage = 0;
+ for(int k=0;k<numSamples;k++)
+ {
+ if(c & (1<<k))
+ coverage++;
+ }
+ pixelPipe->pixelPipe(i, j, (RIfloat)coverage/(RIfloat)numSamples, c);
+ }
+ }
+ }
+ RI_DELETE_ARRAY(covBuffer);
+}
+
+void RI_APIENTRY vgRenderToMask(VGPath path, VGbitfield paintModes, VGMaskOperation operation)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ RI_IF_ERROR(!paintModes || (paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //invalid paint mode
+ RI_IF_ERROR(operation < VG_CLEAR_MASK || operation > VG_SUBTRACT_MASK, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Drawable* curr = context->getCurrentDrawable();
+ if(!curr || !curr->getMaskBuffer())
+ {
+ RI_RETURN(RI_NO_RETVAL); //no EGL surface is current at the moment or context has no mask buffer
+ }
+
+ if(operation == VG_CLEAR_MASK || operation == VG_FILL_MASK)
+ {
+ Surface* dummy = NULL;
+ curr->getMaskBuffer()->mask(dummy, operation, 0, 0, curr->getWidth(), curr->getHeight());
+ RI_RETURN(RI_NO_RETVAL);
+ }
+
+ try
+ {
+ Drawable drawable(Color::formatToDescriptor(VG_A_8), curr->getWidth(), curr->getHeight(), curr->getNumSamples(), 1); //TODO 0 mask bits (mask buffer is not used)
+
+ Rasterizer rasterizer;
+ if(context->m_scissoring)
+ rasterizer.setScissor(context->m_scissor); //throws bad_alloc
+ int numSamples = rasterizer.setupSamplingPattern(context->m_renderingQuality, drawable.getNumSamples());
+
+ PixelPipe pixelPipe;
+ pixelPipe.setDrawable(&drawable);
+ pixelPipe.setMask(false);
+ pixelPipe.setPaint(NULL); //use default paint (solid color alpha = 1)
+ pixelPipe.setBlendMode(VG_BLEND_SRC); //write solid color * coverage to dest
+
+ Matrix3x3 userToSurface = context->m_pathUserToSurface;
+ userToSurface[2].set(0,0,1); //force affinity
+
+ if(paintModes & VG_FILL_PATH)
+ {
+ drawable.getColorBuffer()->clear(Color(0,0,0,0,drawable.getColorBuffer()->getDescriptor().internalFormat), 0, 0, drawable.getWidth(), drawable.getHeight());
+ ((Path*)path)->fill(userToSurface, rasterizer); //throws bad_alloc
+ rasterizer.setup(0, 0, drawable.getWidth(), drawable.getHeight(), context->m_fillRule, &pixelPipe, NULL);
+ rasterizer.fill(); //throws bad_alloc
+ curr->getMaskBuffer()->mask(drawable.getColorBuffer(), operation, 0, 0, drawable.getWidth(), drawable.getHeight());
+ }
+
+ if(paintModes & VG_STROKE_PATH && context->m_strokeLineWidth > 0.0f)
+ {
+ drawable.getColorBuffer()->clear(Color(0,0,0,0,drawable.getColorBuffer()->getDescriptor().internalFormat), 0, 0, drawable.getWidth(), drawable.getHeight());
+ renderStroke(context, drawable.getWidth(), drawable.getHeight(), numSamples, (Path*)path, rasterizer, &pixelPipe, userToSurface);
+ curr->getMaskBuffer()->mask(drawable.getColorBuffer(), operation, 0, 0, drawable.getWidth(), drawable.getHeight());
+ }
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGMaskLayer RI_APIENTRY vgCreateMaskLayer(VGint width, VGint height)
+{
+ RI_GET_CONTEXT(VG_INVALID_HANDLE);
+ RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
+ RI_IF_ERROR(width > RI_MAX_IMAGE_WIDTH || height > RI_MAX_IMAGE_HEIGHT || width*height > RI_MAX_IMAGE_PIXELS ||
+ width*height > RI_MAX_IMAGE_BYTES, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
+ Drawable* curr = context->getCurrentDrawable();
+ if(!curr || !curr->getMaskBuffer())
+ RI_RETURN(VG_INVALID_HANDLE); //no current drawing surface
+
+ Surface* layer = NULL;
+ try
+ {
+ layer = RI_NEW(Surface, (Color::formatToDescriptor(VG_A_8), width, height, curr->getNumSamples())); //throws bad_alloc
+ RI_ASSERT(layer);
+ context->m_maskLayerManager->addResource(layer, context); //throws bad_alloc
+ layer->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, width, height);
+ RI_RETURN((VGMaskLayer)layer);
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(layer);
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ RI_RETURN(VG_INVALID_HANDLE);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgDestroyMaskLayer(VGMaskLayer maskLayer)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidMaskLayer(maskLayer), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid handle
+
+ context->m_maskLayerManager->removeResource((Surface*)maskLayer);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgFillMaskLayer(VGMaskLayer maskLayer, VGint x, VGint y, VGint width, VGint height, VGfloat value)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidMaskLayer(maskLayer), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid handle
+ RI_IF_ERROR(value < 0.0f || value > 1.0f, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Surface* layer = (Surface*)maskLayer;
+ RI_IF_ERROR(width <= 0 || height <= 0 || x < 0 || y < 0 || x > layer->getWidth()-width || y > layer->getHeight()-height, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ layer->clear(Color(1,1,1,value,Color::sRGBA), x, y, width, height);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgCopyMask(VGMaskLayer maskLayer, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidMaskLayer(maskLayer), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid handle
+ Drawable* drawable = context->getCurrentDrawable();
+ if(!drawable || !drawable->getMaskBuffer())
+ {
+ RI_RETURN(RI_NO_RETVAL); //no EGL surface is current at the moment or context has no mask buffer
+ }
+ Surface* layer = (Surface*)maskLayer;
+ RI_IF_ERROR(width <= 0 || height <= 0 || drawable->getNumSamples() != layer->getNumSamples(), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ try
+ { //copy drawing surface mask to mask layer
+ layer->blit(drawable->getMaskBuffer(), sx, sy, dx, dy, width, height); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgClear(VGint x, VGint y, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Drawable* drawable = context->getCurrentDrawable();
+ if(!drawable)
+ {
+ RI_RETURN(RI_NO_RETVAL); //no EGL surface is current at the moment
+ }
+
+ try
+ {
+ if(context->m_scissoring)
+ drawable->getColorBuffer()->clear(context->m_clearColor, x, y, width, height, context->m_scissor); //throws bad_alloc
+ else
+ drawable->getColorBuffer()->clear(context->m_clearColor, x, y, width, height);
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGPath RI_APIENTRY vgCreatePath(VGint pathFormat, VGPathDatatype datatype, VGfloat scale, VGfloat bias, VGint segmentCapacityHint, VGint coordCapacityHint, VGbitfield capabilities)
+{
+ RI_GET_CONTEXT(VG_INVALID_HANDLE);
+ RI_IF_ERROR(pathFormat != VG_PATH_FORMAT_STANDARD, VG_UNSUPPORTED_PATH_FORMAT_ERROR, VG_INVALID_HANDLE);
+ RI_IF_ERROR(datatype < VG_PATH_DATATYPE_S_8 || datatype > VG_PATH_DATATYPE_F, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
+ RIfloat s = inputFloat(scale);
+ RIfloat b = inputFloat(bias);
+ RI_IF_ERROR(s == 0.0f, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
+ capabilities &= VG_PATH_CAPABILITY_ALL; //undefined bits are ignored
+
+ Path* path = NULL;
+ try
+ {
+ path = RI_NEW(Path, (pathFormat, datatype, s, b, segmentCapacityHint, coordCapacityHint, capabilities)); //throws bad_alloc
+ RI_ASSERT(path);
+ context->m_pathManager->addResource(path, context); //throws bad_alloc
+ RI_RETURN((VGPath)path);
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(path);
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ RI_RETURN(VG_INVALID_HANDLE);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgClearPath(VGPath path, VGbitfield capabilities)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ capabilities &= VG_PATH_CAPABILITY_ALL; //undefined bits are ignored
+ ((Path*)path)->clear(capabilities);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgDestroyPath(VGPath path)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+
+ context->m_pathManager->removeResource((Path*)path);
+
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgRemovePathCapabilities(VGPath path, VGbitfield capabilities)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ capabilities &= VG_PATH_CAPABILITY_ALL; //undefined bits are ignored
+
+ VGbitfield caps = ((Path*)path)->getCapabilities();
+ caps &= ~capabilities;
+ ((Path*)path)->setCapabilities(caps);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGbitfield RI_APIENTRY vgGetPathCapabilities(VGPath path)
+{
+ RI_GET_CONTEXT(0);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, 0); //invalid path handle
+ VGbitfield ret = ((Path*)path)->getCapabilities();
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgAppendPathData(VGPath dstPath, VGint numSegments, const VGubyte * pathSegments, const void * pathData)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(dstPath), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ Path* p = (Path*)dstPath;
+ RI_IF_ERROR(!(p->getCapabilities() & VG_PATH_CAPABILITY_APPEND_TO), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL); //no append cap
+ RI_IF_ERROR(numSegments <= 0 || !pathSegments || !pathData, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //no segments or data
+ RI_IF_ERROR((p->getDatatype() == VG_PATH_DATATYPE_S_16 && !isAligned(pathData,2)) ||
+ ((p->getDatatype() == VG_PATH_DATATYPE_S_32 || p->getDatatype() == VG_PATH_DATATYPE_F) && !isAligned(pathData,4)),
+ VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //invalid alignment
+ for(int i=0;i<numSegments;i++)
+ {
+ VGPathSegment c = (VGPathSegment)(pathSegments[i] & 0x1e);
+ RI_IF_ERROR(c < VG_CLOSE_PATH || c > VG_LCWARC_TO, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //invalid segment
+ RI_IF_ERROR(c & ~0x1f, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //reserved bits are nonzero
+ }
+
+ try
+ {
+ p->appendData((const RIuint8*)pathSegments, numSegments, (const RIuint8*)pathData); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgModifyPathCoords(VGPath dstPath, VGint startIndex, VGint numSegments, const void * pathData)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(dstPath), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ Path* p = (Path*)dstPath;
+ RI_IF_ERROR(!(p->getCapabilities() & VG_PATH_CAPABILITY_MODIFY), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL); //no modify cap
+ RI_IF_ERROR(!pathData || startIndex < 0 || numSegments <= 0 || RI_INT_ADDSATURATE(startIndex, numSegments) > p->getNumSegments(), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //no segments
+ RI_IF_ERROR((p->getDatatype() == VG_PATH_DATATYPE_S_16 && !isAligned(pathData,2)) ||
+ ((p->getDatatype() == VG_PATH_DATATYPE_S_32 || p->getDatatype() == VG_PATH_DATATYPE_F) && !isAligned(pathData,4)),
+ VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //invalid alignment
+ p->modifyCoords(startIndex, numSegments, (const RIuint8*)pathData);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgAppendPath(VGPath dstPath, VGPath srcPath)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(dstPath) || !context->isValidPath(srcPath), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ RI_IF_ERROR(!(((Path*)dstPath)->getCapabilities() & VG_PATH_CAPABILITY_APPEND_TO) ||
+ !(((Path*)srcPath)->getCapabilities() & VG_PATH_CAPABILITY_APPEND_FROM), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL); //invalid caps
+
+ try
+ {
+ ((Path*)dstPath)->append((Path*)srcPath); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgTransformPath(VGPath dstPath, VGPath srcPath)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(dstPath) || !context->isValidPath(srcPath), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ RI_IF_ERROR(!(((Path*)dstPath)->getCapabilities() & VG_PATH_CAPABILITY_TRANSFORM_TO) ||
+ !(((Path*)srcPath)->getCapabilities() & VG_PATH_CAPABILITY_TRANSFORM_FROM), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL); //invalid caps
+ try
+ {
+ ((Path*)dstPath)->transform((Path*)srcPath, context->m_pathUserToSurface); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static bool drawPath(VGContext* context, VGPath path, const Matrix3x3& userToSurfaceMatrix, VGbitfield paintModes)
+{
+ //set up rendering surface and mask buffer
+ Drawable* drawable = context->getCurrentDrawable();
+ if(!drawable)
+ return false; //no EGL surface is current at the moment
+
+ Rasterizer rasterizer;
+ if(context->m_scissoring)
+ rasterizer.setScissor(context->m_scissor); //throws bad_alloc
+ int numSamples = rasterizer.setupSamplingPattern(context->m_renderingQuality, drawable->getNumSamples());
+
+ PixelPipe pixelPipe;
+ pixelPipe.setDrawable(drawable);
+ pixelPipe.setMask(context->m_masking ? true : false);
+ pixelPipe.setBlendMode(context->m_blendMode);
+ pixelPipe.setTileFillColor(context->m_tileFillColor);
+ pixelPipe.setImageQuality(context->m_imageQuality);
+ pixelPipe.setColorTransform(context->m_colorTransform ? true : false, context->m_colorTransformValues);
+
+ Matrix3x3 userToSurface = userToSurfaceMatrix;
+ userToSurface[2].set(0,0,1); //force affinity
+
+ if(paintModes & VG_FILL_PATH)
+ {
+ pixelPipe.setPaint((Paint*)context->m_fillPaint);
+
+ Matrix3x3 surfaceToPaintMatrix = userToSurface * context->m_fillPaintToUser;
+ if(surfaceToPaintMatrix.invert())
+ {
+ surfaceToPaintMatrix[2].set(0,0,1); //force affinity
+ pixelPipe.setSurfaceToPaintMatrix(surfaceToPaintMatrix);
+
+ rasterizer.setup(0, 0, drawable->getWidth(), drawable->getHeight(), context->m_fillRule, &pixelPipe, NULL);
+ ((Path*)path)->fill(userToSurface, rasterizer); //throws bad_alloc
+ rasterizer.fill(); //throws bad_alloc
+ }
+ }
+
+ if(paintModes & VG_STROKE_PATH && context->m_strokeLineWidth > 0.0f)
+ {
+ pixelPipe.setPaint((Paint*)context->m_strokePaint);
+
+ Matrix3x3 surfaceToPaintMatrix = userToSurface * context->m_strokePaintToUser;
+ if(surfaceToPaintMatrix.invert())
+ {
+ surfaceToPaintMatrix[2].set(0,0,1); //force affinity
+ pixelPipe.setSurfaceToPaintMatrix(surfaceToPaintMatrix);
+
+ renderStroke(context, drawable->getWidth(), drawable->getHeight(), numSamples, (Path*)path, rasterizer, &pixelPipe, userToSurface);
+ }
+ }
+ return true;
+}
+
+void RI_APIENTRY vgDrawPath(VGPath path, VGbitfield paintModes)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ RI_IF_ERROR(!paintModes || (paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //invalid paint mode
+
+ try
+ {
+ if(!drawPath(context, path, context->m_pathUserToSurface, paintModes))
+ {
+ RI_RETURN(RI_NO_RETVAL);
+ }
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGfloat RI_APIENTRY vgPathLength(VGPath path, VGint startSegment, VGint numSegments)
+{
+ RI_GET_CONTEXT(-1.0f);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, -1.0f); //invalid path handle
+ Path* p = (Path*)path;
+ RI_IF_ERROR(!(p->getCapabilities() & VG_PATH_CAPABILITY_PATH_LENGTH), VG_PATH_CAPABILITY_ERROR, -1.0f); //invalid caps
+ RI_IF_ERROR(startSegment < 0 || numSegments <= 0 || RI_INT_ADDSATURATE(startSegment, numSegments) > p->getNumSegments(), VG_ILLEGAL_ARGUMENT_ERROR, -1.0f);
+ RIfloat pathLength = -1.0f;
+ try
+ {
+ pathLength = p->getPathLength(startSegment, numSegments); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(pathLength);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgPointAlongPath(VGPath path, VGint startSegment, VGint numSegments, VGfloat distance, VGfloat * x, VGfloat * y, VGfloat * tangentX, VGfloat * tangentY)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ Path* p = (Path*)path;
+ RI_IF_ERROR((x && y && !(p->getCapabilities() & VG_PATH_CAPABILITY_POINT_ALONG_PATH)) ||
+ (tangentX && tangentY && !(p->getCapabilities() & VG_PATH_CAPABILITY_TANGENT_ALONG_PATH)), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL); //invalid caps
+ RI_IF_ERROR(startSegment < 0 || numSegments <= 0 || RI_INT_ADDSATURATE(startSegment, numSegments) > p->getNumSegments(), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!isAligned(x,4) || !isAligned(y,4) || !isAligned(tangentX,4) || !isAligned(tangentY,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ try
+ {
+ Vector2 point, tangent;
+ p->getPointAlong(startSegment, numSegments, distance, point, tangent); //throws bad_alloc
+ if(x && y)
+ {
+ *x = point.x;
+ *y = point.y;
+ }
+ if(tangentX && tangentY)
+ {
+ tangent.normalize();
+ *tangentX = tangent.x;
+ *tangentY = tangent.y;
+ }
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgPathBounds(VGPath path, VGfloat * minx, VGfloat * miny, VGfloat * width, VGfloat * height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ RI_IF_ERROR(!(((Path*)path)->getCapabilities() & VG_PATH_CAPABILITY_PATH_BOUNDS), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL); //invalid caps
+ RI_IF_ERROR(!minx || !miny || !width || !height, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!isAligned(minx,4) || !isAligned(miny,4) || !isAligned(width,4) || !isAligned(height,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ try
+ {
+ RIfloat pminx,pminy,pmaxx,pmaxy;
+ ((Path*)path)->getPathBounds(pminx, pminy, pmaxx, pmaxy); //throws bad_alloc
+ *minx = pminx;
+ *miny = pminy;
+ *width = pmaxx - pminx;
+ *height = pmaxy - pminy;
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgPathTransformedBounds(VGPath path, VGfloat * minx, VGfloat * miny, VGfloat * width, VGfloat * height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ RI_IF_ERROR(!(((Path*)path)->getCapabilities() & VG_PATH_CAPABILITY_PATH_TRANSFORMED_BOUNDS), VG_PATH_CAPABILITY_ERROR, RI_NO_RETVAL); //invalid caps
+ RI_IF_ERROR(!minx || !miny || !width || !height, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!isAligned(minx,4) || !isAligned(miny,4) || !isAligned(width,4) || !isAligned(height,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ try
+ {
+ RIfloat pminx, pminy, pmaxx, pmaxy;
+ ((Path*)path)->getPathTransformedBounds(context->m_pathUserToSurface, pminx, pminy, pmaxx, pmaxy); //throws bad_alloc
+ *minx = pminx;
+ *miny = pminy;
+ *width = pmaxx - pminx;
+ *height = pmaxy - pminy;
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGboolean RI_APIENTRY vgInterpolatePath(VGPath dstPath, VGPath startPath, VGPath endPath, VGfloat amount)
+{
+ RI_GET_CONTEXT(VG_FALSE);
+ RI_IF_ERROR(!context->isValidPath(dstPath) || !context->isValidPath(startPath) || !context->isValidPath(endPath), VG_BAD_HANDLE_ERROR, VG_FALSE); //invalid path handle
+ RI_IF_ERROR(!(((Path*)dstPath)->getCapabilities() & VG_PATH_CAPABILITY_INTERPOLATE_TO) ||
+ !(((Path*)startPath)->getCapabilities() & VG_PATH_CAPABILITY_INTERPOLATE_FROM) ||
+ !(((Path*)endPath)->getCapabilities() & VG_PATH_CAPABILITY_INTERPOLATE_FROM), VG_PATH_CAPABILITY_ERROR, VG_FALSE); //invalid caps
+ VGboolean ret = VG_FALSE;
+ try
+ {
+ if(((Path*)dstPath)->interpolate((const Path*)startPath, (const Path*)endPath, inputFloat(amount))) //throws bad_alloc
+ ret = VG_TRUE;
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGPaint RI_APIENTRY vgCreatePaint(void)
+{
+ RI_GET_CONTEXT(VG_INVALID_HANDLE);
+ Paint* paint = NULL;
+ try
+ {
+ paint = RI_NEW(Paint, ()); //throws bad_alloc
+ RI_ASSERT(paint);
+ context->m_paintManager->addResource(paint, context); //throws bad_alloc
+ RI_RETURN((VGPaint)paint);
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(paint);
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ RI_RETURN(VG_INVALID_HANDLE);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgDestroyPaint(VGPaint paint)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPaint(paint), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid paint handle
+
+ context->m_paintManager->removeResource((Paint*)paint);
+
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetPaint(VGPaint paint, VGbitfield paintModes)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(paint && !context->isValidPaint(paint), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid paint handle
+ RI_IF_ERROR(!paintModes || paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //invalid paint mode
+
+ context->releasePaint(paintModes);
+
+ if(paintModes & VG_FILL_PATH)
+ {
+ if(paint)
+ ((Paint*)paint)->addReference();
+ context->m_fillPaint = paint;
+ }
+ if(paintModes & VG_STROKE_PATH)
+ {
+ if(paint)
+ ((Paint*)paint)->addReference();
+ context->m_strokePaint = paint;
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetColor(VGPaint paint, VGuint rgba)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPaint(paint), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid paint handle
+ Paint* p = (Paint*)paint;
+ p->m_inputPaintColor.unpack(rgba, Color::formatToDescriptor(VG_sRGBA_8888));
+ p->m_paintColor = inputColor(p->m_inputPaintColor);
+ p->m_paintColor.clamp();
+ p->m_paintColor.premultiply();
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGuint RI_APIENTRY vgGetColor(VGPaint paint)
+{
+ RI_GET_CONTEXT(0);
+ RI_IF_ERROR(!context->isValidPaint(paint), VG_BAD_HANDLE_ERROR, 0); //invalid paint handle
+ unsigned int ret = ((Paint*)paint)->m_inputPaintColor.pack(Color::formatToDescriptor(VG_sRGBA_8888));
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGPaint RI_APIENTRY vgGetPaint(VGPaintMode paintMode)
+{
+ RI_GET_CONTEXT(VG_INVALID_HANDLE);
+ RI_IF_ERROR(paintMode != VG_FILL_PATH && paintMode != VG_STROKE_PATH, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE); //invalid paint mode
+
+ if(paintMode == VG_FILL_PATH)
+ {
+ RI_RETURN(context->m_fillPaint);
+ }
+ RI_RETURN(context->m_strokePaint);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgPaintPattern(VGPaint paint, VGImage image)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidPaint(paint) || (image != VG_INVALID_HANDLE && !context->isValidImage(image)), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid handle
+ Image* img = (Image*)image;
+ Paint* pnt = (Paint*)paint;
+ RI_IF_ERROR(image != VG_INVALID_HANDLE && eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ Image* pattern = pnt->m_pattern;
+ if(pattern)
+ {
+ pattern->removeInUse();
+ if(!pattern->removeReference())
+ RI_DELETE(pattern);
+ }
+ pnt->m_pattern = img;
+ if(img)
+ {
+ img->addReference();
+ img->addInUse();
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGImage RI_APIENTRY vgCreateImage(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality)
+{
+ RI_GET_CONTEXT(VG_INVALID_HANDLE);
+ RI_IF_ERROR(!isValidImageFormat(format), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, VG_INVALID_HANDLE);
+ RI_IF_ERROR(width <= 0 || height <= 0 || !allowedQuality ||
+ (allowedQuality & ~(VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER)), VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
+ RI_IF_ERROR(width > RI_MAX_IMAGE_WIDTH || height > RI_MAX_IMAGE_HEIGHT || width*height > RI_MAX_IMAGE_PIXELS ||
+ ((width*Color::formatToDescriptor(format).bitsPerPixel+7)/8)*height > RI_MAX_IMAGE_BYTES, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
+
+ Image* image = NULL;
+ try
+ {
+ image = RI_NEW(Image, (Color::formatToDescriptor(format), width, height, allowedQuality)); //throws bad_alloc
+ RI_ASSERT(image);
+ context->m_imageManager->addResource(image, context); //throws bad_alloc
+ RI_RETURN((VGImage)image);
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(image);
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ RI_RETURN(VG_INVALID_HANDLE);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgDestroyImage(VGImage image)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid image handle
+
+ context->m_imageManager->removeResource((Image*)image);
+
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgClearImage(VGImage image, VGint x, VGint y, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* img = (Image*)image;
+ RI_IF_ERROR(eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ img->clear(context->m_clearColor, x, y, width, height);
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgImageSubData(VGImage image, const void * data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* img = (Image*)image;
+ RI_IF_ERROR(eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!isValidImageFormat(dataFormat), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!data || !isAligned(data, dataFormat) || width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ {
+ Image input(Color::formatToDescriptor(dataFormat), width, height, dataStride, const_cast<RIuint8*>((const RIuint8*)data));
+ input.addReference();
+ try
+ {
+ img->blit(input, 0, 0, x, y, width, height, false); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ input.removeReference();
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgGetImageSubData(VGImage image, void * data, VGint dataStride, VGImageFormat dataFormat, VGint x, VGint y, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* img = (Image*)image;
+ RI_IF_ERROR(eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!isValidImageFormat(dataFormat), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!data || !isAligned(data, dataFormat) || width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ {
+ Image output(Color::formatToDescriptor(dataFormat), width, height, dataStride, (RIuint8*)data);
+ output.addReference();
+ try
+ {
+ output.blit(*img, x, y, 0, 0, width, height, false); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ output.removeReference();
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGImage RI_APIENTRY vgChildImage(VGImage parent, VGint x, VGint y, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(VG_INVALID_HANDLE);
+ RI_IF_ERROR(!context->isValidImage(parent), VG_BAD_HANDLE_ERROR, VG_INVALID_HANDLE);
+ Image* p = (Image*)parent;
+ RI_IF_ERROR(eglvgIsInUse((Image*)parent), VG_IMAGE_IN_USE_ERROR, VG_INVALID_HANDLE);
+ RI_IF_ERROR(x < 0 || x >= p->getWidth() || y < 0 || y >= p->getHeight() ||
+ width <= 0 || height <= 0 || RI_INT_ADDSATURATE(x, width) > p->getWidth() || RI_INT_ADDSATURATE(y, height) > p->getHeight(), VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
+
+ Image* child = NULL;
+ try
+ {
+ child = RI_NEW(Image, (p, x, y, width, height)); //throws bad_alloc
+ RI_ASSERT(child);
+ context->m_imageManager->addResource(child, context); //throws bad_alloc
+ RI_RETURN((VGImage)child);
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(child);
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ RI_RETURN(VG_INVALID_HANDLE);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGImage RI_APIENTRY vgGetParent(VGImage image)
+{
+ RI_GET_CONTEXT(VG_INVALID_HANDLE);
+ RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, VG_INVALID_HANDLE);
+ VGImage ret = image; //if image has no ancestors, image is returned.
+
+ //The vgGetParent function returns the closest valid ancestor (i.e., one that has not been the target of a vgDestroyImage call)
+ // of the given image.
+ Image* im = ((Image*)image)->getParent();
+ for(;im;im = im->getParent())
+ {
+ if(context->isValidImage((VGImage)im))
+ { //the parent is valid and alive
+ ret = (VGImage)im;
+ break;
+ }
+ }
+ RI_RETURN(ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgCopyImage(VGImage dst, VGint dx, VGint dy, VGImage src, VGint sx, VGint sy, VGint width, VGint height, VGboolean dither)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(eglvgIsInUse((Image*)dst) || eglvgIsInUse((Image*)src), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ try
+ {
+ ((Image*)dst)->blit(*(Image*)src, sx, sy, dx, dy, width, height, dither ? true : false); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static bool drawImage(VGContext* context, VGImage image, const Matrix3x3& userToSurfaceMatrix)
+{
+ Drawable* drawable = context->getCurrentDrawable();
+ if(!drawable)
+ return false; //no EGL surface is current at the moment
+
+ Image* img = (Image*)image;
+ //transform image corners into the surface space
+ Vector3 p0(0, 0, 1);
+ Vector3 p1(0, (RIfloat)img->getHeight(), 1);
+ Vector3 p2((RIfloat)img->getWidth(), (RIfloat)img->getHeight(), 1);
+ Vector3 p3((RIfloat)img->getWidth(), 0, 1);
+ p0 = userToSurfaceMatrix * p0;
+ p1 = userToSurfaceMatrix * p1;
+ p2 = userToSurfaceMatrix * p2;
+ p3 = userToSurfaceMatrix * p3;
+ if(p0.z <= 0.0f || p1.z <= 0.0f || p2.z <= 0.0f || p3.z <= 0.0f)
+ return false;
+
+ //projection
+ p0 *= 1.0f/p0.z;
+ p1 *= 1.0f/p1.z;
+ p2 *= 1.0f/p2.z;
+ p3 *= 1.0f/p3.z;
+
+ Rasterizer rasterizer;
+ if(context->m_scissoring)
+ rasterizer.setScissor(context->m_scissor); //throws bad_alloc
+ rasterizer.setupSamplingPattern(context->m_renderingQuality, drawable->getNumSamples());
+
+ PixelPipe pixelPipe;
+ pixelPipe.setTileFillColor(context->m_tileFillColor);
+ pixelPipe.setPaint((Paint*)context->m_fillPaint);
+ pixelPipe.setImageQuality(context->m_imageQuality);
+ pixelPipe.setBlendMode(context->m_blendMode);
+ pixelPipe.setDrawable(drawable);
+ pixelPipe.setMask(context->m_masking ? true : false);
+ pixelPipe.setColorTransform(context->m_colorTransform ? true : false, context->m_colorTransformValues);
+
+ Matrix3x3 surfaceToImageMatrix = userToSurfaceMatrix;
+ Matrix3x3 surfaceToPaintMatrix = userToSurfaceMatrix * context->m_fillPaintToUser;
+ if(surfaceToImageMatrix.invert() && surfaceToPaintMatrix.invert())
+ {
+ VGImageMode imode = context->m_imageMode;
+ if(!surfaceToPaintMatrix.isAffine())
+ imode = VG_DRAW_IMAGE_NORMAL; //if paint matrix is not affine, always use normal image mode
+ surfaceToPaintMatrix[2].set(0,0,1); //force affine
+
+ pixelPipe.setImage(img, imode);
+ pixelPipe.setSurfaceToPaintMatrix(surfaceToPaintMatrix);
+ pixelPipe.setSurfaceToImageMatrix(surfaceToImageMatrix);
+
+ rasterizer.addEdge(Vector2(p0.x,p0.y), Vector2(p1.x,p1.y)); //throws bad_alloc
+ rasterizer.addEdge(Vector2(p1.x,p1.y), Vector2(p2.x,p2.y)); //throws bad_alloc
+ rasterizer.addEdge(Vector2(p2.x,p2.y), Vector2(p3.x,p3.y)); //throws bad_alloc
+ rasterizer.addEdge(Vector2(p3.x,p3.y), Vector2(p0.x,p0.y)); //throws bad_alloc
+ rasterizer.setup(0, 0, drawable->getWidth(), drawable->getHeight(), VG_EVEN_ODD, &pixelPipe, NULL);
+ rasterizer.fill(); //throws bad_alloc
+ }
+ return true;
+}
+
+void RI_APIENTRY vgDrawImage(VGImage image)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* img = (Image*)image;
+ RI_IF_ERROR(eglvgIsInUse(img), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+
+ try
+ {
+ if(!drawImage(context, image, context->m_imageUserToSurface))
+ {
+ RI_RETURN(RI_NO_RETVAL);
+ }
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetPixels(VGint dx, VGint dy, VGImage src, VGint sx, VGint sy, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(eglvgIsInUse((Image*)src), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Drawable* drawable = context->getCurrentDrawable();
+ if(!drawable)
+ {
+ RI_RETURN(RI_NO_RETVAL); //no EGL surface is current at the moment
+ }
+ try
+ {
+ if(context->m_scissoring)
+ drawable->getColorBuffer()->blit(*(Image*)src, sx, sy, dx, dy, width, height, context->m_scissor); //throws bad_alloc
+ else
+ drawable->getColorBuffer()->blit(*(Image*)src, sx, sy, dx, dy, width, height); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgWritePixels(const void * data, VGint dataStride, VGImageFormat dataFormat, VGint dx, VGint dy, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!isValidImageFormat(dataFormat), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!data || !isAligned(data, dataFormat) || width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Drawable* drawable = context->getCurrentDrawable();
+ if(!drawable)
+ {
+ RI_RETURN(RI_NO_RETVAL); //no EGL surface is current at the moment
+ }
+ {
+ Image input(Color::formatToDescriptor(dataFormat), width, height, dataStride, const_cast<RIuint8*>((const RIuint8*)data));
+ input.addReference();
+ try
+ {
+ if(context->m_scissoring)
+ drawable->getColorBuffer()->blit(input, 0, 0, dx, dy, width, height, context->m_scissor); //throws bad_alloc
+ else
+ drawable->getColorBuffer()->blit(input, 0, 0, dx, dy, width, height); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ input.removeReference();
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgGetPixels(VGImage dst, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(dst), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(eglvgIsInUse((Image*)dst), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Drawable* drawable = context->getCurrentDrawable();
+ if(!drawable)
+ {
+ RI_RETURN(RI_NO_RETVAL); //no EGL surface is current at the moment
+ }
+ try
+ {
+ ((Image*)dst)->blit(drawable->getColorBuffer(), sx, sy, dx, dy, width, height); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgReadPixels(void* data, VGint dataStride, VGImageFormat dataFormat, VGint sx, VGint sy, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!isValidImageFormat(dataFormat), VG_UNSUPPORTED_IMAGE_FORMAT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!data || !isAligned(data, dataFormat) || width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Drawable* drawable = context->getCurrentDrawable();
+ if(!drawable)
+ {
+ RI_RETURN(RI_NO_RETVAL); //no EGL surface is current at the moment
+ }
+ {
+ Image output(Color::formatToDescriptor(dataFormat), width, height, dataStride, (RIuint8*)data);
+ output.addReference();
+ try
+ {
+ output.blit(drawable->getColorBuffer(), sx, sy, 0, 0, width, height); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ output.removeReference();
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgCopyPixels(VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(width <= 0 || height <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Drawable* drawable = context->getCurrentDrawable();
+ if(!drawable)
+ {
+ RI_RETURN(RI_NO_RETVAL); //no EGL surface is current at the moment
+ }
+ try
+ {
+ if(context->m_scissoring)
+ drawable->getColorBuffer()->blit(drawable->getColorBuffer(), sx, sy, dx, dy, width, height, context->m_scissor); //throws bad_alloc
+ else
+ drawable->getColorBuffer()->blit(drawable->getColorBuffer(), sx, sy, dx, dy, width, height); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgColorMatrix(VGImage dst, VGImage src, const VGfloat * matrix)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* d = (Image*)dst;
+ Image* s = (Image*)src;
+ RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!matrix || !isAligned(matrix,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA); //undefined bits are ignored
+
+ RIfloat m[20];
+ for(int i=0;i<20;i++)
+ {
+ m[i] = inputFloat(matrix[i]);
+ }
+ try
+ {
+ d->colorMatrix(*s, m, context->m_filterFormatLinear ? true : false, context->m_filterFormatPremultiplied ? true : false, channelMask);
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgConvolve(VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort * kernel, VGfloat scale, VGfloat bias, VGTilingMode tilingMode)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* d = (Image*)dst;
+ Image* s = (Image*)src;
+ RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!kernel || !isAligned(kernel,2) || kernelWidth <= 0 || kernelHeight <= 0 || kernelWidth > RI_MAX_KERNEL_SIZE || kernelHeight > RI_MAX_KERNEL_SIZE, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(tilingMode < VG_TILE_FILL || tilingMode > VG_TILE_REFLECT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA); //undefined bits are ignored
+ try
+ {
+ d->convolve(*s, kernelWidth, kernelHeight, shiftX, shiftY, (const RIint16*)kernel, inputFloat(scale), inputFloat(bias), tilingMode, context->m_tileFillColor, context->m_filterFormatLinear ? true : false, context->m_filterFormatPremultiplied ? true : false, channelMask);
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSeparableConvolve(VGImage dst, VGImage src, VGint kernelWidth, VGint kernelHeight, VGint shiftX, VGint shiftY, const VGshort * kernelX, const VGshort * kernelY, VGfloat scale, VGfloat bias, VGTilingMode tilingMode)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* d = (Image*)dst;
+ Image* s = (Image*)src;
+ RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!kernelX || !kernelY || !isAligned(kernelX,2) || !isAligned(kernelY,2) || kernelWidth <= 0 || kernelHeight <= 0 || kernelWidth > RI_MAX_SEPARABLE_KERNEL_SIZE || kernelHeight > RI_MAX_SEPARABLE_KERNEL_SIZE, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(tilingMode < VG_TILE_FILL || tilingMode > VG_TILE_REFLECT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA); //undefined bits are ignored
+ try
+ {
+ d->separableConvolve(*s, kernelWidth, kernelHeight, shiftX, shiftY, (const RIint16*)kernelX, (const RIint16*)kernelY,
+ inputFloat(scale), inputFloat(bias), tilingMode, context->m_tileFillColor, context->m_filterFormatLinear ? true : false,
+ context->m_filterFormatPremultiplied ? true : false, channelMask);
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgGaussianBlur(VGImage dst, VGImage src, VGfloat stdDeviationX, VGfloat stdDeviationY, VGTilingMode tilingMode)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* d = (Image*)dst;
+ Image* s = (Image*)src;
+ RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RIfloat sx = inputFloat(stdDeviationX);
+ RIfloat sy = inputFloat(stdDeviationY);
+ RI_IF_ERROR(sx <= 0.0f || sy <= 0.0f || sx > (RIfloat)RI_MAX_GAUSSIAN_STD_DEVIATION || sy > (RIfloat)RI_MAX_GAUSSIAN_STD_DEVIATION, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(tilingMode < VG_TILE_FILL || tilingMode > VG_TILE_REFLECT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA); //undefined bits are ignored
+ try
+ {
+ d->gaussianBlur(*s, sx, sy, tilingMode, context->m_tileFillColor, context->m_filterFormatLinear ? true : false,
+ context->m_filterFormatPremultiplied ? true : false, channelMask);
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgLookup(VGImage dst, VGImage src, const VGubyte * redLUT, const VGubyte * greenLUT, const VGubyte * blueLUT, const VGubyte * alphaLUT, VGboolean outputLinear, VGboolean outputPremultiplied)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* d = (Image*)dst;
+ Image* s = (Image*)src;
+ RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!redLUT || !greenLUT || !blueLUT || !alphaLUT, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA); //undefined bits are ignored
+ try
+ {
+ d->lookup(*s, (const RIuint8*)redLUT, (const RIuint8*)greenLUT, (const RIuint8*)blueLUT, (const RIuint8*)alphaLUT,
+ outputLinear ? true : false, outputPremultiplied ? true : false, context->m_filterFormatLinear ? true : false,
+ context->m_filterFormatPremultiplied ? true : false, channelMask);
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgLookupSingle(VGImage dst, VGImage src, const VGuint * lookupTable, VGImageChannel sourceChannel, VGboolean outputLinear, VGboolean outputPremultiplied)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidImage(dst) || !context->isValidImage(src), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL);
+ Image* d = (Image*)dst;
+ Image* s = (Image*)src;
+ RI_IF_ERROR(eglvgIsInUse(d) || eglvgIsInUse(s), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(d->overlaps(s), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(!lookupTable || !isAligned(lookupTable,4), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ const Color::Descriptor& desc = s->getDescriptor();
+ RI_ASSERT(Color::isValidDescriptor(desc));
+ //give an error if src is in rgb format and the source channel is not valid
+ RI_IF_ERROR((!desc.isLuminance() && !desc.isAlphaOnly()) && (sourceChannel != VG_RED && sourceChannel != VG_GREEN && sourceChannel != VG_BLUE && sourceChannel != VG_ALPHA), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ unsigned int channelMask = context->m_filterChannelMask & (VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA); //undefined bits are ignored
+ try
+ {
+ d->lookupSingle(*s, (const RIuint32*)lookupTable, sourceChannel, outputLinear ? true : false, outputPremultiplied ? true : false,
+ context->m_filterFormatLinear ? true : false, context->m_filterFormatPremultiplied ? true : false, channelMask);
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGHardwareQueryResult RI_APIENTRY vgHardwareQuery(VGHardwareQueryType key, VGint setting)
+{
+ RI_GET_CONTEXT(VG_HARDWARE_UNACCELERATED);
+ RI_IF_ERROR(key != VG_IMAGE_FORMAT_QUERY && key != VG_PATH_DATATYPE_QUERY, VG_ILLEGAL_ARGUMENT_ERROR, VG_HARDWARE_UNACCELERATED);
+ RI_IF_ERROR(key == VG_IMAGE_FORMAT_QUERY && !isValidImageFormat(setting), VG_ILLEGAL_ARGUMENT_ERROR, VG_HARDWARE_UNACCELERATED);
+ RI_IF_ERROR(key == VG_PATH_DATATYPE_QUERY && (setting < VG_PATH_DATATYPE_S_8 || setting > VG_PATH_DATATYPE_F), VG_ILLEGAL_ARGUMENT_ERROR, VG_HARDWARE_UNACCELERATED);
+ RI_RETURN(VG_HARDWARE_UNACCELERATED);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+const VGubyte * RI_APIENTRY vgGetString(VGStringID name)
+{
+ static const VGubyte vendor[] = "Khronos Group";
+ static const VGubyte renderer[] = {"OpenVG 1.1 Reference Implementation May 13 2008"};
+ static const VGubyte version[] = "1.1";
+ static const VGubyte extensions[] = "";
+ const VGubyte* r = NULL;
+ RI_GET_CONTEXT(NULL);
+ switch(name)
+ {
+ case VG_VENDOR:
+ r = vendor;
+ break;
+ case VG_RENDERER:
+ r = renderer;
+ break;
+ case VG_VERSION:
+ r = version;
+ break;
+ case VG_EXTENSIONS:
+ r = extensions;
+ break;
+ default:
+ break;
+ }
+ RI_RETURN(r);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGFont RI_APIENTRY vgCreateFont(VGint glyphCapacityHint)
+{
+ RI_GET_CONTEXT(VG_INVALID_HANDLE);
+ RI_IF_ERROR(glyphCapacityHint < 0, VG_ILLEGAL_ARGUMENT_ERROR, VG_INVALID_HANDLE);
+
+ Font* font = NULL;
+ try
+ {
+ font = RI_NEW(Font, (glyphCapacityHint)); //throws bad_alloc
+ RI_ASSERT(font);
+ context->m_fontManager->addResource(font, context); //throws bad_alloc
+ RI_RETURN((VGFont)font);
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(font);
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ RI_RETURN(VG_INVALID_HANDLE);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgDestroyFont(VGFont font)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid font handle
+
+ context->m_fontManager->removeResource((Font*)font);
+
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetGlyphToPath(VGFont font, VGuint glyphIndex, VGPath path, VGboolean isHinted, VGfloat glyphOrigin[2], VGfloat escapement[2])
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid font handle
+ RI_IF_ERROR(path != VG_INVALID_HANDLE && !context->isValidPath(path), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid path handle
+ RI_IF_ERROR(!glyphOrigin || !escapement || !isAligned(glyphOrigin,sizeof(VGfloat)) || !isAligned(escapement,sizeof(VGfloat)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Font* f = (Font*)font;
+
+ try
+ {
+ f->setGlyphToPath(glyphIndex, path, isHinted ? true : false, Vector2(inputFloat(glyphOrigin[0]), inputFloat(glyphOrigin[1])), Vector2(inputFloat(escapement[0]), inputFloat(escapement[1])));
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgSetGlyphToImage(VGFont font, VGuint glyphIndex, VGImage image, VGfloat glyphOrigin[2], VGfloat escapement[2])
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid font handle
+ if(image != VG_INVALID_HANDLE)
+ {
+ RI_IF_ERROR(!context->isValidImage(image), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid image handle
+ RI_IF_ERROR(eglvgIsInUse((Image*)image), VG_IMAGE_IN_USE_ERROR, RI_NO_RETVAL); //image in use
+ }
+ RI_IF_ERROR(!glyphOrigin || !escapement || !isAligned(glyphOrigin,sizeof(VGfloat)) || !isAligned(escapement,sizeof(VGfloat)), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ Font* f = (Font*)font;
+
+ try
+ {
+ f->setGlyphToImage(glyphIndex, image, Vector2(inputFloat(glyphOrigin[0]), inputFloat(glyphOrigin[1])), Vector2(inputFloat(escapement[0]), inputFloat(escapement[1])));
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgClearGlyph(VGFont font, VGuint glyphIndex)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid font handle
+ Font* f = (Font*)font;
+ Font::Glyph* g = f->findGlyph(glyphIndex);
+ RI_IF_ERROR(!g, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //glyphIndex not defined
+
+ f->clearGlyph(g);
+
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgDrawGlyph(VGFont font, VGuint glyphIndex, VGbitfield paintModes, VGboolean allowAutoHinting)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid font handle
+ RI_IF_ERROR(paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //invalid paint mode
+ Font* f = (Font*)font;
+ Font::Glyph* g = f->findGlyph(glyphIndex);
+ RI_IF_ERROR(!g, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //glyphIndex not defined
+ RI_UNREF(allowAutoHinting); //RI doesn't implement autohinting
+
+ try
+ {
+ if(paintModes)
+ {
+ Matrix3x3 userToSurfaceMatrix = context->m_glyphUserToSurface;
+ Vector2 t = context->m_glyphOrigin - g->m_origin;
+ Matrix3x3 n(1, 0, t.x,
+ 0, 1, t.y,
+ 0, 0, 1 );
+ userToSurfaceMatrix *= n;
+ userToSurfaceMatrix[2].set(0,0,1); //force affinity
+
+ bool ret = true;
+ if(g->m_image != VG_INVALID_HANDLE)
+ ret = drawImage(context, g->m_image, userToSurfaceMatrix);
+ else if(g->m_path != VG_INVALID_HANDLE)
+ ret = drawPath(context, g->m_path, userToSurfaceMatrix, paintModes);
+ if(!ret)
+ {
+ RI_RETURN(RI_NO_RETVAL);
+ }
+ }
+
+ context->m_glyphOrigin += g->m_escapement;
+ context->m_inputGlyphOrigin = context->m_glyphOrigin;
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+
+ RI_RETURN(RI_NO_RETVAL);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void RI_APIENTRY vgDrawGlyphs(VGFont font, VGint glyphCount, VGuint *glyphIndices, VGfloat *adjustments_x, VGfloat *adjustments_y, VGbitfield paintModes, VGboolean allowAutoHinting)
+{
+ RI_GET_CONTEXT(RI_NO_RETVAL);
+ RI_IF_ERROR(!context->isValidFont(font), VG_BAD_HANDLE_ERROR, RI_NO_RETVAL); //invalid font handle
+ RI_IF_ERROR(!glyphIndices || !isAligned(glyphIndices, sizeof(VGuint)) || glyphCount <= 0, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR((adjustments_x && !isAligned(adjustments_x, sizeof(VGfloat))) || (adjustments_y && !isAligned(adjustments_y, sizeof(VGfloat))), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL);
+ RI_IF_ERROR(paintModes & ~(VG_FILL_PATH | VG_STROKE_PATH), VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //invalid paint mode
+ Font* f = (Font*)font;
+ for(int i=0;i<glyphCount;i++)
+ {
+ Font::Glyph* g = f->findGlyph(glyphIndices[i]);
+ RI_IF_ERROR(!g, VG_ILLEGAL_ARGUMENT_ERROR, RI_NO_RETVAL); //glyphIndex not defined
+ }
+ RI_UNREF(allowAutoHinting); //RI doesn't implement autohinting
+
+ try
+ {
+ for(int i=0;i<glyphCount;i++)
+ {
+ Font::Glyph* g = f->findGlyph(glyphIndices[i]);
+
+ if(paintModes)
+ {
+ Matrix3x3 userToSurfaceMatrix = context->m_glyphUserToSurface;
+ Vector2 t = context->m_glyphOrigin - g->m_origin;
+ Matrix3x3 n(1, 0, t.x,
+ 0, 1, t.y,
+ 0, 0, 1 );
+ userToSurfaceMatrix *= n;
+ userToSurfaceMatrix[2].set(0,0,1); //force affinity
+
+ bool ret = true;
+ if(g->m_image != VG_INVALID_HANDLE)
+ ret = drawImage(context, g->m_image, userToSurfaceMatrix);
+ else if(g->m_path != VG_INVALID_HANDLE)
+ ret = drawPath(context, g->m_path, userToSurfaceMatrix, paintModes);
+ if(!ret)
+ {
+ RI_RETURN(RI_NO_RETVAL);
+ }
+ }
+
+ context->m_glyphOrigin += g->m_escapement;
+ if(adjustments_x)
+ context->m_glyphOrigin.x += inputFloat(adjustments_x[i]);
+ if(adjustments_y)
+ context->m_glyphOrigin.y += inputFloat(adjustments_y[i]);
+ context->m_inputGlyphOrigin = context->m_glyphOrigin;
+ }
+ }
+ catch(std::bad_alloc)
+ {
+ context->setError(VG_OUT_OF_MEMORY_ERROR);
+ }
+
+ RI_RETURN(RI_NO_RETVAL);
+}
diff --git a/ri/src/riArray.h b/ri/src/riArray.h
new file mode 100644
index 0000000..d7ba315
--- /dev/null
+++ b/ri/src/riArray.h
@@ -0,0 +1,211 @@
+#ifndef __RIARRAY_H
+#define __RIARRAY_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Array class.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#ifndef __RIDEFS_H
+#include "riDefs.h"
+#endif
+
+#include <string.h> //for memcpy
+
+namespace OpenVGRI
+{
+
+//=======================================================================
+
+/*-------------------------------------------------------------------*//*!
+* \brief An array class similar to std::vector.
+* \param
+* \return
+* \note Follows std::vector's naming convention (except resizeAndReallocate).
+*//*-------------------------------------------------------------------*/
+
+template <class Item> class Array
+{
+public:
+ Array() : m_array(NULL), m_size(0), m_allocated(0) {} //throws bad_alloc
+ ~Array()
+ {
+ RI_DELETE_ARRAY(m_array);
+ }
+
+ void swap(Array& s)
+ {
+ Item* tarray = m_array;
+ m_array = s.m_array;
+ s.m_array = tarray;
+
+ int tsize = m_size;
+ m_size = s.m_size;
+ s.m_size = tsize;
+
+ int tallocated = m_allocated;
+ m_allocated = s.m_allocated;
+ s.m_allocated = tallocated;
+ }
+
+ //if more room is needed, reallocate, otherwise return
+ void reserve( int items ) //throws bad_alloc
+ {
+ RI_ASSERT( items >= 0 );
+ if( items <= m_allocated )
+ return; //if there is room already, return
+
+ RI_ASSERT( items > m_allocated );
+
+ Item* newa = RI_NEW_ARRAY(Item, items); //throws bad_alloc if runs out of memory
+ for(int i=0;i<m_size;i++)
+ newa[i] = m_array[i];
+ RI_DELETE_ARRAY(m_array);
+ m_array = newa;
+ m_allocated = items;
+ //doesn't change size
+ }
+
+ //reserve and change size
+ void resize( int items ) //throws bad_alloc
+ {
+ reserve( items ); //throws bad_alloc if runs out of memory
+ m_size = items;
+ }
+
+ //resize and allocate exactly the correct amount of memory
+ void resizeAndReallocate( int items ) //throws bad_alloc
+ {
+ RI_ASSERT( items >= 0 );
+ if( items == m_allocated )
+ {
+ m_size = items;
+ return;
+ }
+
+ if( items == 0 )
+ {
+ RI_DELETE_ARRAY(m_array);
+ m_size = 0;
+ m_allocated = 0;
+ return;
+ }
+
+ Item* newa = RI_NEW_ARRAY(Item, items); //throws bad_alloc if runs out of memory
+ int copySize = (m_size < items) ? m_size : items; //min(m_size,items)
+ for(int i=0;i<copySize;i++)
+ newa[i] = m_array[i];
+ RI_DELETE_ARRAY(m_array);
+ m_array = newa;
+ m_allocated = items;
+ m_size = items; //changes also size
+ }
+ void clear()
+ {
+ m_size = 0;
+ }
+
+ //sort array (needs operator< defined for Item. Define it with < for increasing order and > for decreasing.)
+ void sort()
+ {
+ if(m_size <= 1)
+ return;
+ quicksort(0, m_size - 1);
+ }
+
+ //remove the first occurrence of an item from the array
+ bool remove(const Item& item)
+ {
+ int i=0;
+ for(;i<m_size;i++)
+ {
+ if(m_array[i] == item)
+ break;
+ }
+ if(i >= m_size)
+ return false; //not found
+ for(;i<m_size-1;i++)
+ {
+ m_array[i] = m_array[i+1];
+ }
+ m_size--;
+ return true;
+ }
+
+ RI_INLINE void push_back( const Item& item ) //throws bad_alloc
+ {
+ if( m_size >= m_allocated )
+ reserve( (!m_allocated) ? 8 : m_allocated * 2 ); //by default, reserve 8. throws bad_alloc if runs out of memory
+ m_array[m_size++] = item;
+ }
+ RI_INLINE int size() const { return m_size; }
+ RI_INLINE Item& operator[](int i) { RI_ASSERT(i >= 0 && i < m_size); return m_array[i]; }
+ RI_INLINE const Item& operator[](int i) const { RI_ASSERT(i >= 0 && i < m_size); return m_array[i]; }
+
+private:
+ Array(const Array& s); //!< Not allowed.
+ void operator=(const Array& s); //!< Not allowed.
+
+ void quicksort(int left, int right)
+ {
+ int i = left, j = right;
+ Item x = m_array[(left+right)>>1];
+
+ do
+ {
+ while (m_array[i] < x)
+ i++;
+ while (x < m_array[j])
+ j--;
+ if (i<=j)
+ {
+ Item tmp = m_array[i];
+ m_array[i] = m_array[j];
+ m_array[j] = tmp;
+ i++;
+ j--;
+ }
+ } while (i<=j);
+
+ if(left < j) quicksort(left, j);
+ if(i < right) quicksort(i, right);
+ }
+
+
+ Item* m_array;
+ int m_size;
+ int m_allocated;
+};
+
+//=======================================================================
+
+} //namespace OpenVGRI
+
+#endif /* __RIARRAY_H */
diff --git a/ri/src/riContext.cpp b/ri/src/riContext.cpp
new file mode 100644
index 0000000..2d72c8f
--- /dev/null
+++ b/ri/src/riContext.cpp
@@ -0,0 +1,329 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Implementation of VGContext functions.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "riContext.h"
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief VGContext constructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGContext::VGContext(VGContext* shareContext) :
+ // Mode settings
+ m_matrixMode(VG_MATRIX_PATH_USER_TO_SURFACE),
+ m_fillRule(VG_EVEN_ODD),
+ m_imageQuality(VG_IMAGE_QUALITY_FASTER),
+ m_renderingQuality(VG_RENDERING_QUALITY_BETTER),
+ m_blendMode(VG_BLEND_SRC_OVER),
+ m_imageMode(VG_DRAW_IMAGE_NORMAL),
+
+ // Scissor rectangles
+ m_scissor(),
+
+ // Stroke parameters
+ m_strokeLineWidth(1.0f),
+ m_inputStrokeLineWidth(1.0f),
+ m_strokeCapStyle(VG_CAP_BUTT),
+ m_strokeJoinStyle(VG_JOIN_MITER),
+ m_strokeMiterLimit(4.0f),
+ m_inputStrokeMiterLimit(4.0f),
+ m_strokeDashPattern(),
+ m_inputStrokeDashPattern(),
+ m_strokeDashPhase(0.0f),
+ m_inputStrokeDashPhase(0.0f),
+ m_strokeDashPhaseReset(VG_FALSE),
+
+ // Edge fill color for vgConvolve and pattern paint
+ m_tileFillColor(0,0,0,0, Color::sRGBA),
+ m_inputTileFillColor(0,0,0,0, Color::sRGBA),
+
+ // Color for vgClear
+ m_clearColor(0,0,0,0, Color::sRGBA),
+ m_inputClearColor(0,0,0,0, Color::sRGBA),
+
+ m_glyphOrigin(0.0f, 0.0f),
+ m_inputGlyphOrigin(0.0f, 0.0f),
+
+ m_masking(VG_FALSE),
+ m_scissoring(VG_FALSE),
+
+ m_pixelLayout(VG_PIXEL_LAYOUT_UNKNOWN),
+
+ m_filterFormatLinear(VG_FALSE),
+ m_filterFormatPremultiplied(VG_FALSE),
+ m_filterChannelMask(VG_RED|VG_GREEN|VG_BLUE|VG_ALPHA),
+
+ // Matrices
+ m_pathUserToSurface(),
+ m_imageUserToSurface(),
+ m_glyphUserToSurface(),
+ m_fillPaintToUser(),
+ m_strokePaintToUser(),
+
+ m_fillPaint(VG_INVALID_HANDLE),
+ m_strokePaint(VG_INVALID_HANDLE),
+
+ m_colorTransform(VG_FALSE),
+ m_colorTransformValues(),
+ m_inputColorTransformValues(),
+
+ m_error(VG_NO_ERROR),
+
+ m_imageManager(NULL),
+ m_pathManager(NULL),
+ m_paintManager(NULL),
+ m_fontManager(NULL),
+ m_maskLayerManager(NULL),
+
+ m_eglDrawable(NULL)
+{
+ if(shareContext)
+ {
+ m_imageManager = shareContext->m_imageManager;
+ m_pathManager = shareContext->m_pathManager;
+ m_paintManager = shareContext->m_paintManager;
+ m_fontManager = shareContext->m_fontManager;
+ m_maskLayerManager = shareContext->m_maskLayerManager;
+ }
+ else
+ {
+ try
+ {
+ m_imageManager = RI_NEW(OpenVGRI::ResourceManager<Image>, ()); //throws bad_alloc
+ m_pathManager = RI_NEW(OpenVGRI::ResourceManager<Path>, ()); //throws bad_alloc
+ m_paintManager = RI_NEW(OpenVGRI::ResourceManager<Paint>, ()); //throws bad_alloc
+ m_fontManager = RI_NEW(OpenVGRI::ResourceManager<Font>, ()); //throws bad_alloc
+ m_maskLayerManager = RI_NEW(OpenVGRI::ResourceManager<Surface>, ()); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(m_imageManager);
+ RI_DELETE(m_pathManager);
+ RI_DELETE(m_paintManager);
+ RI_DELETE(m_fontManager);
+ RI_DELETE(m_maskLayerManager);
+ throw;
+ }
+ }
+ RI_ASSERT(m_imageManager);
+ RI_ASSERT(m_pathManager);
+ RI_ASSERT(m_paintManager);
+ RI_ASSERT(m_fontManager);
+ RI_ASSERT(m_maskLayerManager);
+ m_imageManager->addReference();
+ m_pathManager->addReference();
+ m_paintManager->addReference();
+ m_fontManager->addReference();
+ m_maskLayerManager->addReference();
+
+ m_inputColorTransformValues[0] = 1.0f;
+ m_inputColorTransformValues[1] = 1.0f;
+ m_inputColorTransformValues[2] = 1.0f;
+ m_inputColorTransformValues[3] = 1.0f;
+ m_inputColorTransformValues[4] = 0.0f;
+ m_inputColorTransformValues[5] = 0.0f;
+ m_inputColorTransformValues[6] = 0.0f;
+ m_inputColorTransformValues[7] = 0.0f;
+ m_colorTransformValues[0] = 1.0f;
+ m_colorTransformValues[1] = 1.0f;
+ m_colorTransformValues[2] = 1.0f;
+ m_colorTransformValues[3] = 1.0f;
+ m_colorTransformValues[4] = 0.0f;
+ m_colorTransformValues[5] = 0.0f;
+ m_colorTransformValues[6] = 0.0f;
+ m_colorTransformValues[7] = 0.0f;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief VGContext destructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGContext::~VGContext()
+{
+ releasePaint(VG_FILL_PATH | VG_STROKE_PATH);
+ setDefaultDrawable(NULL);
+
+ //destroy own images, paths and paints
+ while(Image* i = m_imageManager->getFirstResource(this))
+ m_imageManager->removeResource(i);
+ while(Path* p = m_pathManager->getFirstResource(this))
+ m_pathManager->removeResource(p);
+ while(Paint* t = m_paintManager->getFirstResource(this))
+ m_paintManager->removeResource(t);
+ while(Font* t = m_fontManager->getFirstResource(this))
+ m_fontManager->removeResource(t);
+ while(Surface* t = m_maskLayerManager->getFirstResource(this))
+ m_maskLayerManager->removeResource(t);
+
+ //decrease the reference count of resource managers
+ if(!m_imageManager->removeReference())
+ RI_DELETE(m_imageManager);
+ if(!m_pathManager->removeReference())
+ RI_DELETE(m_pathManager);
+ if(!m_paintManager->removeReference())
+ RI_DELETE(m_paintManager);
+ if(!m_fontManager->removeReference())
+ RI_DELETE(m_fontManager);
+ if(!m_maskLayerManager->removeReference())
+ RI_DELETE(m_maskLayerManager);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets new default drawable.
+* \param drawable New drawable or NULL when context is unbound
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void VGContext::setDefaultDrawable(Drawable* drawable)
+{
+ if(m_eglDrawable)
+ {
+ if(!m_eglDrawable->removeReference())
+ RI_DELETE(m_eglDrawable);
+ }
+ m_eglDrawable = drawable;
+ if(m_eglDrawable)
+ {
+ m_eglDrawable->addReference();
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns true if the given image is generated through any
+* context that is shared with this one.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool VGContext::isValidImage(VGImage image)
+{
+ return m_imageManager->isValid((Image*)image);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns true if the given path is generated through any
+* context that is shared with this one.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool VGContext::isValidPath(VGPath path)
+{
+ return m_pathManager->isValid((Path*)path);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns true if the given paint is generated through any
+* context that is shared with this one.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool VGContext::isValidPaint(VGPaint paint)
+{
+ return m_paintManager->isValid((Paint*)paint);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns true if the given font is generated through any
+* context that is shared with this one.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool VGContext::isValidFont(VGFont font)
+{
+ return m_fontManager->isValid((Font*)font);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns true if the given mask layer is generated through any
+* context that is shared with this one.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool VGContext::isValidMaskLayer(VGMaskLayer layer)
+{
+ return m_maskLayerManager->isValid((Surface*)layer);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Releases the given paint objects of the context.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void VGContext::releasePaint(VGbitfield paintModes)
+{
+ if(paintModes & VG_FILL_PATH)
+ {
+ //release previous paint
+ Paint* prev = (Paint*)m_fillPaint;
+ if(prev)
+ {
+ if(!prev->removeReference())
+ RI_DELETE(prev);
+ }
+ m_fillPaint = VG_INVALID_HANDLE;
+ }
+ if(paintModes & VG_STROKE_PATH)
+ {
+ //release previous paint
+ Paint* prev = (Paint*)m_strokePaint;
+ if(prev)
+ {
+ if(!prev->removeReference())
+ RI_DELETE(prev);
+ }
+ m_strokePaint = VG_INVALID_HANDLE;
+ }
+}
+
+//==============================================================================================
+
+} //namespace OpenVGRI
diff --git a/ri/src/riContext.h b/ri/src/riContext.h
new file mode 100644
index 0000000..f1493d7
--- /dev/null
+++ b/ri/src/riContext.h
@@ -0,0 +1,277 @@
+#ifndef __RICONTEXT_H
+#define __RICONTEXT_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief VGContext class. Used for storing OpenVG state.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#ifndef OPENVG_H
+#include "openvg.h"
+#endif
+
+#ifndef __RIDEFS_H
+#include "riDefs.h"
+#endif
+
+#ifndef __RIMATH_H
+#include "riMath.h"
+#endif
+
+#ifndef __RIIMAGE_H
+#include "riImage.h"
+#endif
+
+#ifndef __RIPATH_H
+#include "riPath.h"
+#endif
+
+#ifndef __RIFONT_H
+#include "riFont.h"
+#endif
+
+#ifndef __RIARRAY_H
+#include "riArray.h"
+#endif
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+class VGContext;
+
+/*-------------------------------------------------------------------*//*!
+* \brief A list of resources (Images, Paths, or Paints) shared by a
+* set of contexts.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+template <class Resource> class ResourceManager
+{
+public:
+ ResourceManager() :
+ m_referenceCount(0),
+ m_resources()
+ {
+ }
+
+ ~ResourceManager()
+ {
+ RI_ASSERT(m_referenceCount == 0);
+ RI_ASSERT(m_resources.size() == 0);
+ }
+
+ void addReference()
+ {
+ m_referenceCount++;
+ }
+
+ int removeReference()
+ {
+ m_referenceCount--;
+ RI_ASSERT(m_referenceCount >= 0);
+ return m_referenceCount;
+ }
+
+ void addResource(Resource* resource, VGContext* context)
+ {
+ Entry r;
+ r.resource = resource;
+ r.context = context;
+ m_resources.push_back(r); //throws bad_alloc
+ resource->addReference();
+ }
+
+ void removeResource(Resource* resource)
+ {
+ if(!resource->removeReference())
+ RI_DELETE(resource);
+
+ int i=0;
+ bool found = false;
+ for(;i<m_resources.size();i++)
+ {
+ if(m_resources[i].resource == resource)
+ {
+ found = true;
+ break;
+ }
+ }
+ RI_ASSERT(found);
+
+ for(;i<m_resources.size()-1;i++)
+ {
+ m_resources[i] = m_resources[i+1];
+ }
+ m_resources.resize(m_resources.size()-1);
+ }
+
+ bool isValid(Resource* resource)
+ {
+ for(int i=0;i<m_resources.size();i++)
+ {
+ if(m_resources[i].resource == resource)
+ return true;
+ }
+ return false;
+ }
+
+ Resource* getFirstResource(VGContext* context)
+ {
+ for(int i=0;i<m_resources.size();i++)
+ {
+ if(m_resources[i].context == context)
+ return m_resources[i].resource;
+ }
+ return NULL;
+ }
+
+private:
+ ResourceManager(const ResourceManager&);
+ ResourceManager operator=(const ResourceManager&);
+
+ struct Entry
+ {
+ Resource* resource;
+ VGContext* context;
+ };
+
+ int m_referenceCount;
+ Array<Entry> m_resources;
+};
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class VGContext
+{
+public:
+ VGContext(VGContext* shareContext); //throws bad_alloc
+ ~VGContext();
+
+ void setDefaultDrawable(Drawable* drawable); //called from EGL
+ Drawable* getCurrentDrawable() { return m_eglDrawable; }
+
+ bool isValidImage(VGImage image);
+ bool isValidPath(VGPath path);
+ bool isValidPaint(VGPaint paint);
+ bool isValidFont(VGFont font);
+ bool isValidMaskLayer(VGMaskLayer layer);
+
+ void releasePaint(VGbitfield paintModes);
+
+ void setError(VGErrorCode error) { if(m_error == VG_NO_ERROR) m_error = error; }
+
+ // Mode settings
+ VGMatrixMode m_matrixMode;
+ VGFillRule m_fillRule;
+ VGImageQuality m_imageQuality;
+ VGRenderingQuality m_renderingQuality;
+ VGBlendMode m_blendMode;
+ VGImageMode m_imageMode;
+
+ // Scissor rectangles
+ Array<Rectangle> m_scissor;
+
+ // Stroke parameters
+ RIfloat m_strokeLineWidth;
+ RIfloat m_inputStrokeLineWidth;
+ VGCapStyle m_strokeCapStyle;
+ VGJoinStyle m_strokeJoinStyle;
+ RIfloat m_strokeMiterLimit;
+ RIfloat m_inputStrokeMiterLimit;
+ Array<RIfloat> m_strokeDashPattern;
+ Array<RIfloat> m_inputStrokeDashPattern;
+ RIfloat m_strokeDashPhase;
+ RIfloat m_inputStrokeDashPhase;
+ VGboolean m_strokeDashPhaseReset;
+
+ // Edge fill color for vgConvolve and pattern paint
+ Color m_tileFillColor;
+ Color m_inputTileFillColor;
+
+ // Color for vgClear
+ Color m_clearColor;
+ Color m_inputClearColor;
+
+ Vector2 m_glyphOrigin;
+ Vector2 m_inputGlyphOrigin;
+
+ VGboolean m_masking;
+ VGboolean m_scissoring;
+
+ VGPixelLayout m_pixelLayout;
+
+ VGboolean m_filterFormatLinear;
+ VGboolean m_filterFormatPremultiplied;
+ VGbitfield m_filterChannelMask;
+
+ // Matrices
+ Matrix3x3 m_pathUserToSurface;
+ Matrix3x3 m_imageUserToSurface;
+ Matrix3x3 m_glyphUserToSurface;
+ Matrix3x3 m_fillPaintToUser;
+ Matrix3x3 m_strokePaintToUser;
+
+ VGPaint m_fillPaint;
+ VGPaint m_strokePaint;
+
+ VGboolean m_colorTransform;
+ RIfloat m_colorTransformValues[8];
+ RIfloat m_inputColorTransformValues[8];
+
+ VGErrorCode m_error;
+
+ ResourceManager<Image>* m_imageManager;
+ ResourceManager<Path>* m_pathManager;
+ ResourceManager<Paint>* m_paintManager;
+ ResourceManager<Font>* m_fontManager;
+ ResourceManager<Surface>* m_maskLayerManager;
+private:
+ Drawable* m_eglDrawable;
+
+ VGContext(const VGContext&); //!< Not allowed.
+ void operator=(const VGContext&); //!< Not allowed.
+};
+
+//==============================================================================================
+
+} //namespace OpenVGRI
+
+//==============================================================================================
+
+#endif /* __RICONTEXT_H */
diff --git a/ri/src/riDefs.h b/ri/src/riDefs.h
new file mode 100644
index 0000000..c3cf19a
--- /dev/null
+++ b/ri/src/riDefs.h
@@ -0,0 +1,142 @@
+#ifndef __RIDEFS_H
+#define __RIDEFS_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Platform- and compiler-dependent type and macro definitions.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include <float.h>
+#include <math.h>
+#include <assert.h>
+#include <new> //for bad_alloc
+
+namespace OpenVGRI
+{
+
+//make for-clause scope c++ standard compliant on msvc
+#if defined (_MSC_VER)
+# if !defined (for)
+ __forceinline bool getFalse (void) { return false; }
+# define for if(getFalse()); else for
+# endif // for
+
+#pragma warning(disable:4710) //disable function not inlined warning
+#pragma warning(disable:4714) //disable function not __forceinlined warning
+#endif // _MSC_VER
+
+//=======================================================================
+
+typedef int RIint32;
+typedef unsigned int RIuint32;
+typedef short RIint16;
+typedef unsigned short RIuint16;
+typedef signed char RIint8;
+typedef unsigned char RIuint8;
+typedef float RIfloat32;
+//TODO add compile-time assertions to guarantee the sizes
+
+#if defined (_MSC_VER) // MSVC WIN32
+# define RI_INLINE __forceinline
+#elif defined __APPLE__ || defined (__GNUC__) || defined (__GCC32__)
+# define RI_INLINE inline
+#endif
+
+/*!< Unsigned int that can hold a pointer to any type */
+/*!< Signed int that can hold a pointer to any type */
+#if defined (_MSC_VER) && (_MSC_VER >= 1300)
+typedef uintptr_t RIuintptr;
+typedef intptr_t RIintptr;
+#else
+typedef unsigned long RIuintptr;
+typedef signed long RIintptr;
+#endif
+
+#define RI_UINT32_MAX (0xffffffffu)
+#define RI_INT32_MAX (0x7fffffff)
+#define RI_INT32_MIN (-0x7fffffff-1)
+
+/* maximum mantissa is 23 */
+#define RI_MANTISSA_BITS 23
+
+/* maximum exponent is 8 */
+#define RI_EXPONENT_BITS 8
+
+typedef union
+{
+ RIfloat32 f;
+ RIuint32 i;
+} RIfloatInt;
+
+RI_INLINE float getFloatMax()
+{
+ RIfloatInt v;
+ v.i = (((1<<(RI_EXPONENT_BITS-1))-1+127) << 23) | (((1<<RI_MANTISSA_BITS)-1) << (23-RI_MANTISSA_BITS));
+ return v.f;
+}
+#define RI_FLOAT_MAX getFloatMax()
+
+#define RI_MAX_IMAGE_WIDTH 16384
+#define RI_MAX_IMAGE_HEIGHT 16384
+#define RI_MAX_IMAGE_PIXELS (RI_MAX_IMAGE_WIDTH*RI_MAX_IMAGE_HEIGHT)
+#define RI_MAX_IMAGE_BYTES (4*RI_MAX_IMAGE_WIDTH*RI_MAX_IMAGE_HEIGHT)
+#define RI_MAX_DASH_COUNT 256
+#define RI_MAX_COLOR_RAMP_STOPS 256
+#define RI_MAX_KERNEL_SIZE 256
+#define RI_MAX_SEPARABLE_KERNEL_SIZE 256
+#define RI_MAX_GAUSSIAN_STD_DEVIATION 16.0f
+#define RI_MAX_SCISSOR_RECTANGLES 256
+#define RI_MAX_EDGES 262144
+#define RI_MAX_SAMPLES 32
+#define RI_NUM_TESSELLATED_SEGMENTS 256
+
+#define RI_DEBUG
+
+#ifdef RI_DEBUG
+# define RI_ASSERT assert
+#else
+# define RI_ASSERT
+#endif
+
+#define RI_UNREF(X) ((void)(X))
+#define RI_APIENTRY
+
+#define RI_NEW(TYPE, PARAMS) (new TYPE PARAMS)
+#define RI_NEW_ARRAY(TYPE, ITEMS) (new TYPE[ITEMS])
+#define RI_DELETE(PARAMS) (delete (PARAMS))
+#define RI_DELETE_ARRAY(PARAMS) (delete[] (PARAMS))
+
+bool isValidImageFormat(int format);
+
+//=======================================================================
+
+} //namespace OpenVGRI
+
+#endif /* __RIDEFS_H */
diff --git a/ri/src/riFont.cpp b/ri/src/riFont.cpp
new file mode 100644
index 0000000..4a31df8
--- /dev/null
+++ b/ri/src/riFont.cpp
@@ -0,0 +1,203 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Implementation of Font class.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "riFont.h"
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief Font constructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Font::Font(int capacityHint) :
+ m_referenceCount(0),
+ m_glyphs()
+{
+ RI_ASSERT(capacityHint >= 0);
+ m_glyphs.reserve(capacityHint);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Font destructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Font::~Font()
+{
+ //remove references to paths and images
+ for(int i=0;i<m_glyphs.size();i++)
+ clearGlyph(&m_glyphs[i]);
+ RI_ASSERT(m_referenceCount == 0);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Find a glyph based on glyphIndex.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Font::Glyph* Font::findGlyph(unsigned int index)
+{
+ for(int i=0;i<m_glyphs.size();i++)
+ {
+ if(m_glyphs[i].m_state != Glyph::GLYPH_UNINITIALIZED && m_glyphs[i].m_index == index)
+ return &m_glyphs[i];
+ }
+ return NULL;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Find a free glyph or allocate a new one.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Font::Glyph* Font::newGlyph()
+{
+ for(int i=0;i<m_glyphs.size();i++)
+ {
+ if(m_glyphs[i].m_state == Glyph::GLYPH_UNINITIALIZED)
+ return &m_glyphs[i];
+ }
+ m_glyphs.resize(m_glyphs.size()+1);
+ return &m_glyphs[m_glyphs.size()-1];
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Free glyph and its data.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Font::clearGlyph(Glyph* g)
+{
+ RI_ASSERT(g);
+ if(g->m_path != VG_INVALID_HANDLE)
+ {
+ Path* p = (Path*)g->m_path;
+ if(!p->removeReference())
+ RI_DELETE(p);
+ }
+ if(g->m_image != VG_INVALID_HANDLE)
+ {
+ Image* p = (Image*)g->m_image;
+ p->removeInUse();
+ if(!p->removeReference())
+ RI_DELETE(p);
+ }
+ Glyph a;
+ *g = a;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Font::setGlyphToPath(unsigned int index, VGPath path, bool isHinted, const Vector2& origin, const Vector2& escapement)
+{
+ Glyph* g = findGlyph(index);
+ if(g)
+ { //glyph exists, replace
+ clearGlyph(g);
+ }
+ else
+ { //glyph doesn't exist, allocate a new one
+ g = newGlyph();
+ }
+
+ g->m_index = index;
+ g->m_state = Glyph::GLYPH_PATH;
+ g->m_path = path;
+ g->m_image = VG_INVALID_HANDLE;
+ g->m_isHinted = isHinted;
+ g->m_origin = origin;
+ g->m_escapement = escapement;
+
+ if(path != VG_INVALID_HANDLE)
+ {
+ Path* p = (Path*)path;
+ p->addReference();
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Font::setGlyphToImage(unsigned int index, VGImage image, const Vector2& origin, const Vector2& escapement)
+{
+ Glyph* g = findGlyph(index);
+ if(g)
+ { //glyph exists, replace
+ clearGlyph(g);
+ }
+ else
+ { //glyph doesn't exist, allocate a new one
+ g = newGlyph();
+ }
+
+ g->m_index = index;
+ g->m_state = Glyph::GLYPH_IMAGE;
+ g->m_path = VG_INVALID_HANDLE;
+ g->m_image = image;
+ g->m_isHinted = false;
+ g->m_origin = origin;
+ g->m_escapement = escapement;
+
+ if(image != VG_INVALID_HANDLE)
+ {
+ Image* p = (Image*)image;
+ p->addReference();
+ p->addInUse();
+ }
+}
+
+//=======================================================================
+
+} //namespace OpenVGRI
diff --git a/ri/src/riFont.h b/ri/src/riFont.h
new file mode 100644
index 0000000..c03983e
--- /dev/null
+++ b/ri/src/riFont.h
@@ -0,0 +1,116 @@
+#ifndef __RIFONT_H
+#define __RIFONT_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief VGContext class. Used for storing OpenVG state.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#ifndef _OPENVG_H
+#include "openvg.h"
+#endif
+
+#ifndef __RIMATH_H
+#include "riMath.h"
+#endif
+
+#ifndef __RIARRAY_H
+#include "riArray.h"
+#endif
+
+#ifndef __RIPATH_H
+#include "riPath.h"
+#endif
+
+#ifndef __RIIMAGE_H
+#include "riImage.h"
+#endif
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief Storage and operations for VGFont.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class Font
+{
+public:
+ struct Glyph
+ {
+ enum State
+ {
+ GLYPH_UNINITIALIZED = 0,
+ GLYPH_PATH = 1,
+ GLYPH_IMAGE = 2
+ };
+ Glyph() { m_state = GLYPH_UNINITIALIZED; m_path = m_image = VG_INVALID_HANDLE; m_isHinted = false; m_origin.set(0.0f, 0.0f); m_escapement.set(0.0f, 0.0f); }
+ unsigned int m_index;
+ State m_state;
+ VGPath m_path;
+ VGImage m_image;
+ bool m_isHinted;
+ Vector2 m_origin;
+ Vector2 m_escapement;
+ };
+
+ Font(int capacityHint); //throws bad_alloc
+ ~Font();
+
+ int getNumGlyphs() const { int n=0; for(int i=0;i<m_glyphs.size();i++) { if(m_glyphs[i].m_state != Glyph::GLYPH_UNINITIALIZED) n++; } return n; }
+ void addReference() { m_referenceCount++; }
+ int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
+
+ void setGlyphToPath(unsigned int index, VGPath path, bool isHinted, const Vector2& origin, const Vector2& escapement); //throws bad_alloc
+ void setGlyphToImage(unsigned int index, VGImage image, const Vector2& origin, const Vector2& escapement); //throws bad_alloc
+ Glyph* findGlyph(unsigned int index);
+ void clearGlyph(Glyph* g);
+private:
+ Font(const Font&); //!< Not allowed.
+ void operator=(const Font&); //!< Not allowed.
+
+ Glyph* newGlyph(); //throws bad_alloc
+
+ int m_referenceCount;
+ Array<Glyph> m_glyphs;
+};
+
+//=======================================================================
+
+} //namespace OpenVGRI
+
+//=======================================================================
+
+#endif /* __RIFONT_H */
diff --git a/ri/src/riImage.cpp b/ri/src/riImage.cpp
new file mode 100644
index 0000000..a5bbe73
--- /dev/null
+++ b/ri/src/riImage.cpp
@@ -0,0 +1,2674 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Implementation of Color and Image functions.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "riImage.h"
+#include "riRasterizer.h"
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief Converts from numBits into a shifted mask
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static unsigned int bitsToMask(unsigned int bits, unsigned int shift)
+{
+ return ((1<<bits)-1) << shift;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Converts from color (RIfloat) to an int with 1.0f mapped to the
+* given maximum with round-to-nearest semantics.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static unsigned int colorToInt(RIfloat c, int maxc)
+{
+ return RI_INT_MIN(RI_INT_MAX((int)floor(c * (RIfloat)maxc + 0.5f), 0), maxc);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Converts from int to color (RIfloat) with the given maximum
+* mapped to 1.0f.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static RI_INLINE RIfloat intToColor(unsigned int i, unsigned int maxi)
+{
+ return (RIfloat)(i & maxi) / (RIfloat)maxi;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Converts from packed integer in a given format to a Color.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Color::unpack(unsigned int inputData, const Color::Descriptor& inputDesc)
+{
+ int rb = inputDesc.redBits;
+ int gb = inputDesc.greenBits;
+ int bb = inputDesc.blueBits;
+ int ab = inputDesc.alphaBits;
+ int lb = inputDesc.luminanceBits;
+ int rs = inputDesc.redShift;
+ int gs = inputDesc.greenShift;
+ int bs = inputDesc.blueShift;
+ int as = inputDesc.alphaShift;
+ int ls = inputDesc.luminanceShift;
+
+ m_format = inputDesc.internalFormat;
+ if(lb)
+ { //luminance
+ r = g = b = intToColor(inputData >> ls, (1<<lb)-1);
+ a = 1.0f;
+ }
+ else
+ { //rgba
+ r = rb ? intToColor(inputData >> rs, (1<<rb)-1) : (RIfloat)1.0f;
+ g = gb ? intToColor(inputData >> gs, (1<<gb)-1) : (RIfloat)1.0f;
+ b = bb ? intToColor(inputData >> bs, (1<<bb)-1) : (RIfloat)1.0f;
+ a = ab ? intToColor(inputData >> as, (1<<ab)-1) : (RIfloat)1.0f;
+
+ if(isPremultiplied())
+ { //clamp premultiplied color to alpha to enforce consistency
+ r = RI_MIN(r, a);
+ g = RI_MIN(g, a);
+ b = RI_MIN(b, a);
+ }
+ }
+
+ assertConsistency();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Converts from Color to a packed integer in a given format.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+unsigned int Color::pack(const Color::Descriptor& outputDesc) const
+{
+ assertConsistency();
+
+ int rb = outputDesc.redBits;
+ int gb = outputDesc.greenBits;
+ int bb = outputDesc.blueBits;
+ int ab = outputDesc.alphaBits;
+ int lb = outputDesc.luminanceBits;
+ int rs = outputDesc.redShift;
+ int gs = outputDesc.greenShift;
+ int bs = outputDesc.blueShift;
+ int as = outputDesc.alphaShift;
+ int ls = outputDesc.luminanceShift;
+
+ if(lb)
+ { //luminance
+ RI_ASSERT(isLuminance());
+ return colorToInt(r, (1<<lb)-1) << ls;
+ }
+ else
+ { //rgb
+ RI_ASSERT(!isLuminance());
+ unsigned int cr = rb ? colorToInt(r, (1<<rb)-1) : 0;
+ unsigned int cg = gb ? colorToInt(g, (1<<gb)-1) : 0;
+ unsigned int cb = bb ? colorToInt(b, (1<<bb)-1) : 0;
+ unsigned int ca = ab ? colorToInt(a, (1<<ab)-1) : 0;
+ return (cr << rs) | (cg << gs) | (cb << bs) | (ca << as);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Converts from the current internal format to another.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static RIfloat gamma(RIfloat c)
+{
+ if( c <= 0.00304f )
+ c *= 12.92f;
+ else
+ c = 1.0556f * (RIfloat)pow(c, 1.0f/2.4f) - 0.0556f;
+ return c;
+}
+
+static RIfloat invgamma(RIfloat c)
+{
+ if( c <= 0.03928f )
+ c /= 12.92f;
+ else
+ c = (RIfloat)pow((c + 0.0556f)/1.0556f, 2.4f);
+ return c;
+}
+
+static RIfloat lRGBtoL(RIfloat r, RIfloat g, RIfloat b)
+{
+ return 0.2126f*r + 0.7152f*g + 0.0722f*b;
+}
+
+void Color::convert(InternalFormat outputFormat)
+{
+ assertConsistency();
+
+ if( m_format == outputFormat )
+ return;
+
+ if(isPremultiplied())
+ { //unpremultiply
+ RIfloat ooa = (a != 0.0f) ? 1.0f / a : (RIfloat)0.0f;
+ r *= ooa;
+ g *= ooa;
+ b *= ooa;
+ }
+
+ //From Section 3.4.2 of OpenVG spec
+ //1: sRGB = gamma(lRGB)
+ //2: lRGB = invgamma(sRGB)
+ //3: lL = 0.2126 lR + 0.7152 lG + 0.0722 lB
+ //4: lRGB = lL
+ //5: sL = gamma(lL)
+ //6: lL = invgamma(sL)
+ //7: sRGB = sL
+
+ //Source/Dest lRGB sRGB lL sL
+ //lRGB - 1 3 3,5
+ //sRGB 2 - 2,3 2,3,5
+ //lL 4 4,1 - 5
+ //sL 7,2 7 6 -
+
+ const unsigned int shift = 3;
+ unsigned int conversion = (m_format & (NONLINEAR | LUMINANCE)) | ((outputFormat & (NONLINEAR | LUMINANCE)) << shift);
+
+ switch(conversion)
+ {
+ case lRGBA | (sRGBA << shift): r = gamma(r); g = gamma(g); b = gamma(b); break; //1
+ case lRGBA | (lLA << shift) : r = g = b = lRGBtoL(r, g, b); break; //3
+ case lRGBA | (sLA << shift) : r = g = b = gamma(lRGBtoL(r, g, b)); break; //3,5
+ case sRGBA | (lRGBA << shift): r = invgamma(r); g = invgamma(g); b = invgamma(b); break; //2
+ case sRGBA | (lLA << shift) : r = g = b = lRGBtoL(invgamma(r), invgamma(g), invgamma(b)); break; //2,3
+ case sRGBA | (sLA << shift) : r = g = b = gamma(lRGBtoL(invgamma(r), invgamma(g), invgamma(b))); break;//2,3,5
+ case lLA | (lRGBA << shift): break; //4
+ case lLA | (sRGBA << shift): r = g = b = gamma(r); break; //4,1
+ case lLA | (sLA << shift) : r = g = b = gamma(r); break; //5
+ case sLA | (lRGBA << shift): r = g = b = invgamma(r); break; //7,2
+ case sLA | (sRGBA << shift): break; //7
+ case sLA | (lLA << shift) : r = g = b = invgamma(r); break; //6
+ default: RI_ASSERT((m_format & (LUMINANCE | NONLINEAR)) == (outputFormat & (LUMINANCE | NONLINEAR))); break; //nop
+ }
+
+ if(outputFormat & PREMULTIPLIED)
+ { //premultiply
+ r *= a;
+ g *= a;
+ b *= a;
+ }
+ m_format = outputFormat;
+
+ assertConsistency();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Creates a pixel format descriptor out of VGImageFormat
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Color::Descriptor Color::formatToDescriptor(VGImageFormat format)
+{
+ Descriptor desc;
+ memset(&desc, 0, sizeof(Descriptor));
+ RI_ASSERT(isValidImageFormat(format));
+
+ int baseFormat = (int)format & 15;
+ const int numBaseFormats = 15;
+ RI_ASSERT(baseFormat >= 0 && baseFormat < numBaseFormats);
+ int swizzleBits = ((int)format >> 6) & 3;
+
+ /* base formats
+ VG_sRGBX_8888 = 0,
+ VG_sRGBA_8888 = 1,
+ VG_sRGBA_8888_PRE = 2,
+ VG_sRGB_565 = 3,
+ VG_sRGBA_5551 = 4,
+ VG_sRGBA_4444 = 5,
+ VG_sL_8 = 6,
+ VG_lRGBX_8888 = 7,
+ VG_lRGBA_8888 = 8,
+ VG_lRGBA_8888_PRE = 9,
+ VG_lL_8 = 10,
+ VG_A_8 = 11,
+ VG_BW_1 = 12,
+ VG_A_1 = 13,
+ VG_A_4 = 14,
+ */
+
+ static const int redBits[numBaseFormats] = {8, 8, 8, 5, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};
+ static const int greenBits[numBaseFormats] = {8, 8, 8, 6, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};
+ static const int blueBits[numBaseFormats] = {8, 8, 8, 5, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};
+ static const int alphaBits[numBaseFormats] = {0, 8, 8, 0, 1, 4, 0, 0, 8, 8, 0, 8, 0, 1, 4};
+ static const int luminanceBits[numBaseFormats] = {0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 8, 0, 1, 0, 0};
+
+ static const int redShifts[4*numBaseFormats] = {24, 24, 24, 11, 11, 12, 0, 24, 24, 24, 0, 0, 0, 0, 0, //RGBA
+ 16, 16, 16, 11, 10, 8, 0, 16, 16, 16, 0, 0, 0, 0, 0, //ARGB
+ 8, 8, 8, 0, 1, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0, //BGRA
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //ABGR
+
+ static const int greenShifts[4*numBaseFormats] = {16, 16, 16, 5, 6, 8, 0, 16, 16, 16, 0, 0, 0, 0, 0, //RGBA
+ 8, 8, 8, 5, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0, //ARGB
+ 16, 16, 16, 5, 6, 8, 0, 16, 16, 16, 0, 0, 0, 0, 0, //BGRA
+ 8, 8, 8, 5, 5, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0};//ABGR
+
+ static const int blueShifts[4*numBaseFormats] = {8, 8, 8, 0, 1, 4, 0, 8, 8, 8, 0, 0, 0, 0, 0, //RGBA
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //ARGB
+ 24, 24, 24, 11, 11, 12, 0, 24, 24, 24, 0, 0, 0, 0, 0, //BGRA
+ 16, 16, 16, 11, 10, 8, 0, 16, 16, 16, 0, 0, 0, 0, 0};//ABGR
+
+ static const int alphaShifts[4*numBaseFormats] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //RGBA
+ 0, 24, 24, 0, 15, 12, 0, 0, 24, 24, 0, 0, 0, 0, 0, //ARGB
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //BGRA
+ 0, 24, 24, 0, 15, 12, 0, 0, 24, 24, 0, 0, 0, 0, 0};//ABGR
+
+ static const int bpps[numBaseFormats] = {32, 32, 32, 16, 16, 16, 8, 32, 32, 32, 8, 8, 1, 1, 4};
+
+ static const InternalFormat internalFormats[numBaseFormats] = {sRGBA, sRGBA, sRGBA_PRE, sRGBA, sRGBA, sRGBA, sLA, lRGBA, lRGBA, lRGBA_PRE, lLA, lRGBA, lLA, lRGBA, lRGBA};
+
+ desc.redBits = redBits[baseFormat];
+ desc.greenBits = greenBits[baseFormat];
+ desc.blueBits = blueBits[baseFormat];
+ desc.alphaBits = alphaBits[baseFormat];
+ desc.luminanceBits = luminanceBits[baseFormat];
+
+ desc.redShift = redShifts[swizzleBits * numBaseFormats + baseFormat];
+ desc.greenShift = greenShifts[swizzleBits * numBaseFormats + baseFormat];
+ desc.blueShift = blueShifts[swizzleBits * numBaseFormats + baseFormat];
+ desc.alphaShift = alphaShifts[swizzleBits * numBaseFormats + baseFormat];
+ desc.luminanceShift = 0; //always zero
+
+ desc.format = format;
+ desc.bitsPerPixel = bpps[baseFormat];
+ desc.internalFormat = internalFormats[baseFormat];
+
+ return desc;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Checks if the pixel format descriptor is valid (i.e. all the
+* values are supported by the RI)
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool Color::isValidDescriptor(const Color::Descriptor& desc)
+{
+ //A valid descriptor has 1, 2, 4, 8, 16, or 32 bits per pixel, and either luminance or rgba channels, but not both.
+ //Any of the rgba channels can be missing, and not all bits need to be used. Maximum channel bit depth is 8.
+ int rb = desc.redBits;
+ int gb = desc.greenBits;
+ int bb = desc.blueBits;
+ int ab = desc.alphaBits;
+ int lb = desc.luminanceBits;
+ int rs = desc.redShift;
+ int gs = desc.greenShift;
+ int bs = desc.blueShift;
+ int as = desc.alphaShift;
+ int ls = desc.luminanceShift;
+ int bpp = desc.bitsPerPixel;
+
+ int rgbaBits = rb + gb + bb + ab;
+ if(rb < 0 || rb > 8 || rs < 0 || rs + rb > bpp || !(rb || !rs))
+ return false; //invalid channel description
+ if(gb < 0 || gb > 8 || gs < 0 || gs + gb > bpp || !(gb || !gs))
+ return false; //invalid channel description
+ if(bb < 0 || bb > 8 || bs < 0 || bs + bb > bpp || !(bb || !bs))
+ return false; //invalid channel description
+ if(ab < 0 || ab > 8 || as < 0 || as + ab > bpp || !(ab || !as))
+ return false; //invalid channel description
+ if(lb < 0 || lb > 8 || ls < 0 || ls + lb > bpp || !(lb || !ls))
+ return false; //invalid channel description
+
+ if(rgbaBits && lb)
+ return false; //can't have both rgba and luminance
+ if(!rgbaBits && !lb)
+ return false; //must have either rgba or luminance
+ if(rgbaBits)
+ { //rgba
+ if(rb+gb+bb == 0)
+ { //alpha only
+ if(rs || gs || bs || as || ls)
+ return false; //wrong shifts (even alpha shift must be zero)
+ if((ab != 1 && ab != 2 && ab != 4 && ab != 8) || bpp != ab)
+ return false; //alpha size must be 1, 2, 4, or, 8, bpp must match
+ }
+ else
+ { //rgba
+ if(rgbaBits > bpp)
+ return false; //bpp must be greater than or equal to the sum of rgba bits
+ if(!(bpp == 32 || bpp == 16 || bpp == 8))
+ return false; //only 1, 2, and 4 byte formats are supported for rgba
+
+ unsigned int rm = bitsToMask((unsigned int)rb, (unsigned int)rs);
+ unsigned int gm = bitsToMask((unsigned int)gb, (unsigned int)gs);
+ unsigned int bm = bitsToMask((unsigned int)bb, (unsigned int)bs);
+ unsigned int am = bitsToMask((unsigned int)ab, (unsigned int)as);
+ if((rm & gm) || (rm & bm) || (rm & am) || (gm & bm) || (gm & am) || (bm & am))
+ return false; //channels overlap
+ }
+ }
+ else
+ { //luminance
+ if(rs || gs || bs || as || ls)
+ return false; //wrong shifts (even luminance shift must be zero)
+ if(!(lb == 1 || lb == 8) || bpp != lb)
+ return false; //luminance size must be either 1 or 8, bpp must match
+ }
+
+ if(desc.format != -1)
+ {
+ if(!isValidImageFormat(desc.format))
+ return false; //invalid image format
+
+ Descriptor d = formatToDescriptor(desc.format);
+ if(d.redBits != rb || d.greenBits != gb || d.blueBits != bb || d.alphaBits != ab || d.luminanceBits != lb ||
+ d.redShift != rs || d.greenShift != gs || d.blueShift != bs || d.alphaShift != as || d.luminanceShift != ls ||
+ d.bitsPerPixel != bpp)
+ return false; //if the descriptor has a VGImageFormat, it must match the bits, shifts, and bpp
+ }
+
+ if((unsigned int)desc.internalFormat & ~(Color::PREMULTIPLIED | Color::NONLINEAR | Color::LUMINANCE))
+ return false; //invalid internal format
+
+ return true;
+}
+
+//==============================================================================================
+
+
+
+
+//==============================================================================================
+
+/*-------------------------------------------------------------------*//*!
+* \brief Constructs a blank image.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Image::Image(const Color::Descriptor& desc, int width, int height, VGbitfield allowedQuality) :
+ m_desc(desc),
+ m_width(width),
+ m_height(height),
+ m_allowedQuality(allowedQuality),
+ m_inUse(0),
+ m_stride(0),
+ m_data(NULL),
+ m_referenceCount(0),
+ m_ownsData(true),
+ m_parent(NULL),
+ m_storageOffsetX(0),
+ m_storageOffsetY(0),
+ m_mipmapsValid(false),
+ m_mipmaps()
+{
+ RI_ASSERT(Color::isValidDescriptor(m_desc));
+ RI_ASSERT(width > 0 && height > 0);
+
+ m_stride = (m_width*m_desc.bitsPerPixel+7)/8;
+
+ m_data = RI_NEW_ARRAY(RIuint8, m_stride*m_height); //throws bad_alloc
+ memset(m_data, 0, m_stride*m_height); //clear image
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Constructs an image that uses an external array for its data
+* storage.
+* \param
+* \return
+* \note this is meant for internal use to make blitting easier
+*//*-------------------------------------------------------------------*/
+
+Image::Image(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data) :
+ m_desc(desc),
+ m_width(width),
+ m_height(height),
+ m_allowedQuality(0),
+ m_inUse(0),
+ m_stride(stride),
+ m_data(data),
+ m_referenceCount(0),
+ m_ownsData(false),
+ m_parent(NULL),
+ m_storageOffsetX(0),
+ m_storageOffsetY(0),
+ m_mipmapsValid(false),
+ m_mipmaps()
+{
+ RI_ASSERT(Color::isValidDescriptor(m_desc));
+ RI_ASSERT(width > 0 && height > 0);
+ RI_ASSERT(data);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Construcs a child image.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Image::Image(Image* parent, int x, int y, int width, int height) :
+ m_desc(Color::formatToDescriptor(VG_sRGBA_8888)), //dummy initialization, will be overwritten below (can't read from parent->m_desc before knowing the pointer is valid)
+ m_width(width),
+ m_height(height),
+ m_allowedQuality(0),
+ m_inUse(0),
+ m_stride(0),
+ m_data(NULL),
+ m_referenceCount(0),
+ m_ownsData(false),
+ m_parent(parent),
+ m_storageOffsetX(0),
+ m_storageOffsetY(0),
+ m_mipmapsValid(false),
+ m_mipmaps()
+{
+ RI_ASSERT(parent);
+ RI_ASSERT(x >= 0 && y >= 0 && width > 0 && height > 0);
+ RI_ASSERT(RI_INT_ADDSATURATE(x,width) <= parent->m_width && RI_INT_ADDSATURATE(y,height) <= parent->m_height); //child image must be contained in parent
+
+ m_desc = parent->m_desc;
+ RI_ASSERT(Color::isValidDescriptor(m_desc));
+ m_allowedQuality = parent->m_allowedQuality;
+ m_stride = parent->m_stride;
+ m_data = parent->m_data;
+ m_storageOffsetX = parent->m_storageOffsetX + x;
+ m_storageOffsetY = parent->m_storageOffsetY + y;
+
+ //increase the reference and use count of the parent
+ addInUse();
+ parent->addInUse();
+ parent->addReference();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Image destructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Image::~Image()
+{
+ RI_ASSERT(m_referenceCount == 0);
+
+ if(m_parent)
+ {
+ //decrease the reference and use count of the parent
+ removeInUse();
+ m_parent->removeInUse();
+ if(!m_parent->removeReference())
+ RI_DELETE(m_parent);
+ }
+ RI_ASSERT(m_inUse == 0);
+
+ for(int i=0;i<m_mipmaps.size();i++)
+ {
+ if(!m_mipmaps[i]->removeReference())
+ RI_DELETE(m_mipmaps[i]);
+ else
+ {
+ RI_ASSERT(0); //there can't be any other references to the mipmap levels
+ }
+ }
+ m_mipmaps.clear();
+
+ if(m_ownsData)
+ {
+ RI_ASSERT(!m_parent); //can't have parent if owns the data
+ RI_DELETE_ARRAY(m_data); //delete image data if we own it
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns true if the two images share pixels.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool Image::overlaps(const Image* src) const
+{
+ RI_ASSERT(src);
+
+ if(m_data != src->m_data)
+ return false; //images don't share data
+
+ //check if the image storage regions overlap
+ Rectangle r(m_storageOffsetX, m_storageOffsetY, m_width, m_height);
+ r.intersect(Rectangle(src->m_storageOffsetX, src->m_storageOffsetY, src->m_width, src->m_height));
+ if(!r.width || !r.height)
+ return false; //intersection is empty, images don't overlap
+
+ return true;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Clears a rectangular portion of an image with the given clear color.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::clear(const Color& clearColor, int x, int y, int w, int h)
+{
+ RI_ASSERT(m_data);
+ RI_ASSERT(m_referenceCount > 0);
+
+ //intersect clear region with image bounds
+ Rectangle r(0,0,m_width,m_height);
+ r.intersect(Rectangle(x,y,w,h));
+ if(!r.width || !r.height)
+ return; //intersection is empty or one of the rectangles is invalid
+
+ Color col = clearColor;
+ col.clamp();
+ col.convert(m_desc.internalFormat);
+
+ for(int j=r.y;j<r.y + r.height;j++)
+ {
+ for(int i=r.x;i<r.x + r.width;i++)
+ {
+ writePixel(i, j, col);
+ }
+ }
+
+ m_mipmapsValid = false;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Blits a source region to destination. Source and destination
+* can overlap.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static RIfloat ditherChannel(RIfloat c, int bits, RIfloat m)
+{
+ RIfloat fc = c * (RIfloat)((1<<bits)-1);
+ RIfloat ic = (RIfloat)floor(fc);
+ if(fc - ic > m) ic += 1.0f;
+ return RI_MIN(ic / (RIfloat)((1<<bits)-1), 1.0f);
+}
+
+static void computeBlitRegion(int& sx, int& sy, int& dx, int& dy, int& w, int& h, int srcWidth, int srcHeight, int dstWidth, int dstHeight)
+{
+ RI_ASSERT(w > 0 && h > 0);
+ sx = RI_INT_MIN(RI_INT_MAX(sx, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
+ sy = RI_INT_MIN(RI_INT_MAX(sy, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
+ dx = RI_INT_MIN(RI_INT_MAX(dx, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
+ dy = RI_INT_MIN(RI_INT_MAX(dy, (int)(RI_INT32_MIN>>2)), (int)(RI_INT32_MAX>>2));
+ w = RI_INT_MIN(w, (int)(RI_INT32_MAX>>2));
+ h = RI_INT_MIN(h, (int)(RI_INT32_MAX>>2));
+ int srcsx = sx, srcex = sx + w, dstsx = dx, dstex = dx + w;
+ if(srcsx < 0)
+ {
+ dstsx -= srcsx;
+ srcsx = 0;
+ }
+ if(srcex > srcWidth)
+ {
+ dstex -= srcex - srcWidth;
+ srcex = srcWidth;
+ }
+ if(dstsx < 0)
+ {
+ srcsx -= dstsx;
+ dstsx = 0;
+ }
+ if(dstex > dstWidth)
+ {
+ srcex -= dstex - dstWidth;
+ dstex = dstWidth;
+ }
+ RI_ASSERT(srcsx >= 0 && dstsx >= 0 && srcex <= srcWidth && dstex <= dstWidth);
+ w = srcex - srcsx;
+ RI_ASSERT(w == dstex - dstsx);
+
+ int srcsy = sy, srcey = sy + h, dstsy = dy, dstey = dy + h;
+ if(srcsy < 0)
+ {
+ dstsy -= srcsy;
+ srcsy = 0;
+ }
+ if(srcey > srcHeight)
+ {
+ dstey -= srcey - srcHeight;
+ srcey = srcHeight;
+ }
+ if(dstsy < 0)
+ {
+ srcsy -= dstsy;
+ dstsy = 0;
+ }
+ if(dstey > dstHeight)
+ {
+ srcey -= dstey - dstHeight;
+ dstey = dstHeight;
+ }
+ RI_ASSERT(srcsy >= 0 && dstsy >= 0 && srcey <= srcHeight && dstey <= dstHeight);
+ h = srcey - srcsy;
+ RI_ASSERT(h == dstey - dstsy);
+ sx = srcsx;
+ sy = srcsy;
+ dx = dstsx;
+ dy = dstsy;
+}
+
+void Image::blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, bool dither)
+{
+ //img=>img: vgCopyImage
+ //img=>user: vgGetImageSubData
+ //user=>img: vgImageSubData
+ RI_ASSERT(src.m_data); //source exists
+ RI_ASSERT(m_data); //destination exists
+ RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
+
+ computeBlitRegion(sx, sy, dx, dy, w, h, src.m_width, src.m_height, m_width, m_height);
+ if(w <= 0 || h <= 0)
+ return; //zero area
+
+ Array<Color> tmp;
+ tmp.resize(w*h); //throws bad_alloc
+
+ //copy source region to tmp
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color c = src.readPixel(sx + i, sy + j);
+ c.convert(m_desc.internalFormat);
+ tmp[j*w+i] = c;
+ }
+ }
+
+ int rbits = m_desc.redBits, gbits = m_desc.greenBits, bbits = m_desc.blueBits, abits = m_desc.alphaBits;
+ if(m_desc.isLuminance())
+ {
+ rbits = gbits = bbits = m_desc.luminanceBits;
+ abits = 0;
+ }
+
+ //write tmp to destination region
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color col = tmp[j*w+i];
+
+ if(dither)
+ {
+ static const int matrix[16] = {
+ 0, 8, 2, 10,
+ 12, 4, 14, 6,
+ 3, 11, 1, 9,
+ 15, 7, 13, 5};
+ int x = i & 3;
+ int y = j & 3;
+ RIfloat m = matrix[y*4+x] / 16.0f;
+
+ if(rbits) col.r = ditherChannel(col.r, rbits, m);
+ if(gbits) col.g = ditherChannel(col.g, gbits, m);
+ if(bbits) col.b = ditherChannel(col.b, bbits, m);
+ if(abits) col.a = ditherChannel(col.a, abits, m);
+ }
+
+ writePixel(dx + i, dy + j, col);
+ }
+ }
+ m_mipmapsValid = false;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Converts from multisampled format to display format.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h)
+{
+ //fb=>img: vgGetPixels
+ //fb=>user: vgReadPixels
+ RI_ASSERT(!src->isInUse(this));
+
+ computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), m_width, m_height);
+ if(w <= 0 || h <= 0)
+ return; //zero area
+
+ for(int y=0;y<h;y++)
+ {
+ for(int x=0;x<w;x++)
+ {
+ Color r = src->FSAAResolve(sx + x, sy + y);
+ r.convert(getDescriptor().internalFormat);
+ writePixel(dx + x, dy + y, r);
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns the color at pixel (x,y).
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Color Image::readPixel(int x, int y) const
+{
+ RI_ASSERT(m_data);
+ RI_ASSERT(x >= 0 && x < m_width);
+ RI_ASSERT(y >= 0 && y < m_height);
+ RI_ASSERT(m_referenceCount > 0);
+ x += m_storageOffsetX;
+ y += m_storageOffsetY;
+
+ unsigned int p = 0;
+ RIuint8* scanline = m_data + y * m_stride;
+ switch(m_desc.bitsPerPixel)
+ {
+ case 32:
+ {
+ RIuint32* s = (((RIuint32*)scanline) + x);
+ p = (unsigned int)*s;
+ break;
+ }
+
+ case 16:
+ {
+ RIuint16* s = ((RIuint16*)scanline) + x;
+ p = (unsigned int)*s;
+ break;
+ }
+
+ case 8:
+ {
+ RIuint8* s = ((RIuint8*)scanline) + x;
+ p = (unsigned int)*s;
+ break;
+ }
+
+ case 4:
+ {
+ RIuint8* s = ((RIuint8*)scanline) + (x>>1);
+ p = (unsigned int)(*s >> ((x&1)<<2)) & 0xf;
+ break;
+ }
+
+ case 2:
+ {
+ RIuint8* s = ((RIuint8*)scanline) + (x>>2);
+ p = (unsigned int)(*s >> ((x&3)<<1)) & 0x3;
+ break;
+ }
+
+ default:
+ {
+ RI_ASSERT(m_desc.bitsPerPixel == 1);
+ RIuint8* s = ((RIuint8*)scanline) + (x>>3);
+ p = (unsigned int)(*s >> (x&7)) & 0x1;
+ break;
+ }
+ }
+ Color c;
+ c.unpack(p, m_desc);
+ return c;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Writes the color to pixel (x,y). Internal color formats must
+* match.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::writePixel(int x, int y, const Color& c)
+{
+ RI_ASSERT(m_data);
+ RI_ASSERT(x >= 0 && x < m_width);
+ RI_ASSERT(y >= 0 && y < m_height);
+ RI_ASSERT(m_referenceCount > 0);
+ RI_ASSERT(c.getInternalFormat() == m_desc.internalFormat);
+ x += m_storageOffsetX;
+ y += m_storageOffsetY;
+
+ unsigned int p = c.pack(m_desc);
+ RIuint8* scanline = m_data + y * m_stride;
+ switch(m_desc.bitsPerPixel)
+ {
+ case 32:
+ {
+ RIuint32* s = ((RIuint32*)scanline) + x;
+ *s = (RIuint32)p;
+ break;
+ }
+
+ case 16:
+ {
+ RIuint16* s = ((RIuint16*)scanline) + x;
+ *s = (RIuint16)p;
+ break;
+ }
+
+ case 8:
+ {
+ RIuint8* s = ((RIuint8*)scanline) + x;
+ *s = (RIuint8)p;
+ break;
+ }
+ case 4:
+ {
+ RIuint8* s = ((RIuint8*)scanline) + (x>>1);
+ *s = (RIuint8)((p << ((x&1)<<2)) | ((unsigned int)*s & ~(0xf << ((x&1)<<2))));
+ break;
+ }
+
+ case 2:
+ {
+ RIuint8* s = ((RIuint8*)scanline) + (x>>2);
+ *s = (RIuint8)((p << ((x&3)<<1)) | ((unsigned int)*s & ~(0x3 << ((x&3)<<1))));
+ break;
+ }
+
+ default:
+ {
+ RI_ASSERT(m_desc.bitsPerPixel == 1);
+ RIuint8* s = ((RIuint8*)scanline) + (x>>3);
+ *s = (RIuint8)((p << (x&7)) | ((unsigned int)*s & ~(0x1 << (x&7))));
+ break;
+ }
+ }
+ m_mipmapsValid = false;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Writes a filtered color to destination surface
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::writeFilteredPixel(int i, int j, const Color& color, VGbitfield channelMask)
+{
+ //section 3.4.4: before color space conversion, premultiplied colors are
+ //clamped to alpha, and the color is converted to nonpremultiplied format
+ //section 11.2: how to deal with channel mask
+ //step 1
+ Color f = color;
+ f.clamp(); //vgColorMatrix and vgLookups can produce colors that exceed alpha or [0,1] range
+
+ //step 2: color space conversion
+ f.convert((Color::InternalFormat)(m_desc.internalFormat & (Color::NONLINEAR | Color::LUMINANCE)));
+
+ //step 3: read the destination color and convert it to nonpremultiplied
+ Color d = readPixel(i,j);
+ d.unpremultiply();
+ RI_ASSERT(d.getInternalFormat() == f.getInternalFormat());
+
+ //step 4: replace the destination channels specified by the channelMask (channelmask is ignored for luminance formats)
+ if(!m_desc.isLuminance())
+ { //rgba format => use channelmask
+ if(channelMask & VG_RED)
+ d.r = f.r;
+ if(channelMask & VG_GREEN)
+ d.g = f.g;
+ if(channelMask & VG_BLUE)
+ d.b = f.b;
+ if(channelMask & VG_ALPHA)
+ d.a = f.a;
+ }
+ else d = f;
+
+ //step 5: if destination is premultiplied, convert to premultiplied format
+ if(m_desc.isPremultiplied())
+ d.premultiply();
+ //write the color to destination
+ writePixel(i,j,d);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Reads the pixel (x,y) and converts it into an alpha mask value.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+RIfloat Image::readMaskPixel(int x, int y) const
+{
+ RI_ASSERT(m_data);
+ RI_ASSERT(x >= 0 && x < m_width);
+ RI_ASSERT(y >= 0 && y < m_height);
+ RI_ASSERT(m_referenceCount > 0);
+
+ Color c = readPixel(x,y);
+ if(m_desc.isLuminance())
+ {
+ return c.r;
+ }
+ else
+ { //rgba
+ if(m_desc.alphaBits)
+ return c.a;
+ return c.r;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Writes the alpha mask to pixel (x,y).
+* \param
+* \return
+* \note Overwrites color.
+*//*-------------------------------------------------------------------*/
+
+void Image::writeMaskPixel(int x, int y, RIfloat m)
+{
+ RI_ASSERT(m_data);
+ RI_ASSERT(x >= 0 && x < m_width);
+ RI_ASSERT(y >= 0 && y < m_height);
+ RI_ASSERT(m_referenceCount > 0);
+
+ //if luminance or no alpha, red channel will be used, otherwise alpha channel will be used
+ writePixel(x, y, Color(m,m,m,m,m_desc.internalFormat));
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Reads a texel (u,v) at the given mipmap level. Tiling modes and
+* color space conversion are applied. Outputs color in premultiplied
+* format.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Color Image::readTexel(int u, int v, int level, VGTilingMode tilingMode, const Color& tileFillColor) const
+{
+ const Image* image = this;
+ if( level > 0 )
+ {
+ RI_ASSERT(level <= m_mipmaps.size());
+ image = m_mipmaps[level-1];
+ }
+ RI_ASSERT(image);
+
+ Color p;
+ if(tilingMode == VG_TILE_FILL)
+ {
+ if(u < 0 || v < 0 || u >= image->m_width || v >= image->m_height)
+ p = tileFillColor;
+ else
+ p = image->readPixel(u, v);
+ }
+ else if(tilingMode == VG_TILE_PAD)
+ {
+ u = RI_INT_MIN(RI_INT_MAX(u,0),image->m_width-1);
+ v = RI_INT_MIN(RI_INT_MAX(v,0),image->m_height-1);
+ p = image->readPixel(u, v);
+ }
+ else if(tilingMode == VG_TILE_REPEAT)
+ {
+ u = RI_INT_MOD(u, image->m_width);
+ v = RI_INT_MOD(v, image->m_height);
+ p = image->readPixel(u, v);
+ }
+ else
+ {
+ RI_ASSERT(tilingMode == VG_TILE_REFLECT);
+
+ u = RI_INT_MOD(u, image->m_width*2);
+ v = RI_INT_MOD(v, image->m_height*2);
+ if( u >= image->m_width ) u = image->m_width*2-1 - u;
+ if( v >= image->m_height ) v = image->m_height*2-1 - v;
+ p = image->readPixel(u, v);
+ }
+
+ p.premultiply(); //interpolate in premultiplied format
+ return p;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Maps point (x,y) to an image and returns a filtered,
+* premultiplied color value.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Color Image::resample(RIfloat x, RIfloat y, const Matrix3x3& surfaceToImage, VGImageQuality quality, VGTilingMode tilingMode, const Color& tileFillColor) //throws bad_alloc
+{
+ RI_ASSERT(m_referenceCount > 0);
+
+ VGbitfield aq = getAllowedQuality();
+ aq &= (VGbitfield)quality;
+
+ Vector3 uvw(x,y,1.0f);
+ uvw = surfaceToImage * uvw;
+ RIfloat oow = 1.0f / uvw.z;
+ uvw *= oow;
+
+ if(aq & VG_IMAGE_QUALITY_BETTER)
+ { //EWA on mipmaps
+ makeMipMaps(); //throws bad_alloc
+
+ Color::InternalFormat procFormat = (Color::InternalFormat)(m_desc.internalFormat | Color::PREMULTIPLIED);
+
+ RIfloat m_pixelFilterRadius = 1.25f;
+ RIfloat m_resamplingFilterRadius = 1.25f;
+
+ RIfloat Ux = (surfaceToImage[0][0] - uvw.x * surfaceToImage[2][0]) * oow * m_pixelFilterRadius;
+ RIfloat Vx = (surfaceToImage[1][0] - uvw.y * surfaceToImage[2][0]) * oow * m_pixelFilterRadius;
+ RIfloat Uy = (surfaceToImage[0][1] - uvw.x * surfaceToImage[2][1]) * oow * m_pixelFilterRadius;
+ RIfloat Vy = (surfaceToImage[1][1] - uvw.y * surfaceToImage[2][1]) * oow * m_pixelFilterRadius;
+ RIfloat U0 = uvw.x;
+ RIfloat V0 = uvw.y;
+
+ //calculate mip level
+ int level = 0;
+ RIfloat axis1sq = Ux*Ux + Vx*Vx;
+ RIfloat axis2sq = Uy*Uy + Vy*Vy;
+ RIfloat minorAxissq = RI_MIN(axis1sq,axis2sq);
+ while(minorAxissq > 9.0f && level < m_mipmaps.size()) //half the minor axis must be at least three texels
+ {
+ level++;
+ minorAxissq *= 0.25f;
+ }
+
+ RIfloat sx = 1.0f;
+ RIfloat sy = 1.0f;
+ if(level > 0)
+ {
+ sx = (RIfloat)m_mipmaps[level-1]->m_width / (RIfloat)m_width;
+ sy = (RIfloat)m_mipmaps[level-1]->m_height / (RIfloat)m_height;
+ }
+ Ux *= sx;
+ Vx *= sx;
+ U0 *= sx;
+ Uy *= sy;
+ Vy *= sy;
+ V0 *= sy;
+
+ //clamp filter size so that filtering doesn't take excessive amount of time (clamping results in aliasing)
+ RIfloat lim = 100.0f;
+ axis1sq = Ux*Ux + Vx*Vx;
+ axis2sq = Uy*Uy + Vy*Vy;
+ if( axis1sq > lim*lim )
+ {
+ RIfloat s = lim / (RIfloat)sqrt(axis1sq);
+ Ux *= s;
+ Vx *= s;
+ }
+ if( axis2sq > lim*lim )
+ {
+ RIfloat s = lim / (RIfloat)sqrt(axis2sq);
+ Uy *= s;
+ Vy *= s;
+ }
+
+
+ //form elliptic filter by combining texel and pixel filters
+ RIfloat A = Vx*Vx + Vy*Vy + 1.0f;
+ RIfloat B = -2.0f*(Ux*Vx + Uy*Vy);
+ RIfloat C = Ux*Ux + Uy*Uy + 1.0f;
+ //scale by the user-defined size of the kernel
+ A *= m_resamplingFilterRadius;
+ B *= m_resamplingFilterRadius;
+ C *= m_resamplingFilterRadius;
+
+ //calculate bounding box in texture space
+ RIfloat usize = (RIfloat)sqrt(C);
+ RIfloat vsize = (RIfloat)sqrt(A);
+ int u1 = (int)floor(U0 - usize + 0.5f);
+ int u2 = (int)floor(U0 + usize + 0.5f);
+ int v1 = (int)floor(V0 - vsize + 0.5f);
+ int v2 = (int)floor(V0 + vsize + 0.5f);
+ if( u1 == u2 || v1 == v2 )
+ return Color(0,0,0,0,procFormat);
+
+ //scale the filter so that Q = 1 at the cutoff radius
+ RIfloat F = A*C - 0.25f * B*B;
+ if( F <= 0.0f )
+ return Color(0,0,0,0,procFormat); //invalid filter shape due to numerical inaccuracies => return black
+ RIfloat ooF = 1.0f / F;
+ A *= ooF;
+ B *= ooF;
+ C *= ooF;
+
+ //evaluate filter by using forward differences to calculate Q = A*U^2 + B*U*V + C*V^2
+ Color color(0,0,0,0,procFormat);
+ RIfloat sumweight = 0.0f;
+ RIfloat DDQ = 2.0f * A;
+ RIfloat U = (RIfloat)u1 - U0 + 0.5f;
+ for(int v=v1;v<v2;v++)
+ {
+ RIfloat V = (RIfloat)v - V0 + 0.5f;
+ RIfloat DQ = A*(2.0f*U+1.0f) + B*V;
+ RIfloat Q = (C*V+B*U)*V + A*U*U;
+ for(int u=u1;u<u2;u++)
+ {
+ if( Q >= 0.0f && Q < 1.0f )
+ { //Q = r^2, fit gaussian to the range [0,1]
+ RIfloat weight = (RIfloat)exp(-0.5f * 10.0f * Q); //gaussian at radius 10 equals 0.0067
+ color += weight * readTexel(u, v, level, tilingMode, tileFillColor);
+ sumweight += weight;
+ }
+ Q += DQ;
+ DQ += DDQ;
+ }
+ }
+ if( sumweight == 0.0f )
+ return Color(0,0,0,0,procFormat);
+ RI_ASSERT(sumweight > 0.0f);
+ sumweight = 1.0f / sumweight;
+ return color * sumweight;
+ }
+ else if(aq & VG_IMAGE_QUALITY_FASTER)
+ { //bilinear
+ uvw.x -= 0.5f;
+ uvw.y -= 0.5f;
+ int u = (int)floor(uvw.x);
+ int v = (int)floor(uvw.y);
+ Color c00 = readTexel(u,v, 0, tilingMode, tileFillColor);
+ Color c10 = readTexel(u+1,v, 0, tilingMode, tileFillColor);
+ Color c01 = readTexel(u,v+1, 0, tilingMode, tileFillColor);
+ Color c11 = readTexel(u+1,v+1, 0, tilingMode, tileFillColor);
+ RIfloat fu = uvw.x - (RIfloat)u;
+ RIfloat fv = uvw.y - (RIfloat)v;
+ Color c0 = c00 * (1.0f - fu) + c10 * fu;
+ Color c1 = c01 * (1.0f - fu) + c11 * fu;
+ return c0 * (1.0f - fv) + c1 * fv;
+ }
+ else
+ { //point sampling
+ return readTexel((int)floor(uvw.x), (int)floor(uvw.y), 0, tilingMode, tileFillColor);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Generates mip maps for an image.
+* \param
+* \return
+* \note Downsampling is done in the input color space. We use a box
+* filter for downsampling.
+*//*-------------------------------------------------------------------*/
+
+void Image::makeMipMaps()
+{
+ RI_ASSERT(m_data);
+ RI_ASSERT(m_referenceCount > 0);
+
+ if(m_mipmapsValid)
+ return;
+
+ //delete existing mipmaps
+ for(int i=0;i<m_mipmaps.size();i++)
+ {
+ if(!m_mipmaps[i]->removeReference())
+ RI_DELETE(m_mipmaps[i]);
+ else
+ {
+ RI_ASSERT(0); //there can't be any other references to the mipmap levels
+ }
+ }
+ m_mipmaps.clear();
+
+ try
+ {
+ Color::InternalFormat procFormat = m_desc.internalFormat;
+ procFormat = (Color::InternalFormat)(procFormat | Color::PREMULTIPLIED); //premultiplied
+
+ //generate mipmaps until width and height are one
+ Image* prev = this;
+ while( prev->m_width > 1 || prev->m_height > 1 )
+ {
+ int nextw = (int)ceil(prev->m_width*0.5f);
+ int nexth = (int)ceil(prev->m_height*0.5f);
+ RI_ASSERT(nextw >= 1 && nexth >= 1);
+ RI_ASSERT(nextw < prev->m_width || nexth < prev->m_height);
+
+ m_mipmaps.resize(m_mipmaps.size()+1); //throws bad_alloc
+ m_mipmaps[m_mipmaps.size()-1] = NULL;
+
+ Image* next = RI_NEW(Image, (m_desc, nextw, nexth, m_allowedQuality)); //throws bad_alloc
+ next->addReference();
+ for(int j=0;j<next->m_height;j++)
+ {
+ for(int i=0;i<next->m_width;i++)
+ {
+ RIfloat u0 = (RIfloat)i / (RIfloat)next->m_width;
+ RIfloat u1 = (RIfloat)(i+1) / (RIfloat)next->m_width;
+ RIfloat v0 = (RIfloat)j / (RIfloat)next->m_height;
+ RIfloat v1 = (RIfloat)(j+1) / (RIfloat)next->m_height;
+
+ u0 *= prev->m_width;
+ u1 *= prev->m_width;
+ v0 *= prev->m_height;
+ v1 *= prev->m_height;
+
+ int su = (int)floor(u0);
+ int eu = (int)ceil(u1);
+ int sv = (int)floor(v0);
+ int ev = (int)ceil(v1);
+
+ Color c(0,0,0,0,procFormat);
+ int samples = 0;
+ for(int y=sv;y<ev;y++)
+ {
+ for(int x=su;x<eu;x++)
+ {
+ Color p = prev->readPixel(x, y);
+ p.convert(procFormat);
+ c += p;
+ samples++;
+ }
+ }
+ c *= (1.0f/samples);
+ c.convert(m_desc.internalFormat);
+ next->writePixel(i,j,c);
+ }
+ }
+ m_mipmaps[m_mipmaps.size()-1] = next;
+ prev = next;
+ }
+ RI_ASSERT(prev->m_width == 1 && prev->m_height == 1);
+ m_mipmapsValid = true;
+ }
+ catch(std::bad_alloc)
+ {
+ //delete existing mipmaps
+ for(int i=0;i<m_mipmaps.size();i++)
+ {
+ if(m_mipmaps[i])
+ {
+ if(!m_mipmaps[i]->removeReference())
+ RI_DELETE(m_mipmaps[i]);
+ else
+ {
+ RI_ASSERT(0); //there can't be any other references to the mipmap levels
+ }
+ }
+ }
+ m_mipmaps.clear();
+ m_mipmapsValid = false;
+ throw;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Applies color matrix filter.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::colorMatrix(const Image& src, const RIfloat* matrix, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
+{
+ RI_ASSERT(src.m_data); //source exists
+ RI_ASSERT(m_data); //destination exists
+ RI_ASSERT(matrix);
+ RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
+
+ int w = RI_INT_MIN(m_width, src.m_width);
+ int h = RI_INT_MIN(m_height, src.m_height);
+ RI_ASSERT(w > 0 && h > 0);
+
+ Color::InternalFormat srcFormat = src.m_desc.internalFormat;
+ Color::InternalFormat procFormat = (Color::InternalFormat)(srcFormat & ~Color::LUMINANCE); //process in RGB, not luminance
+ if(filterFormatLinear)
+ procFormat = (Color::InternalFormat)(procFormat & ~Color::NONLINEAR);
+ else
+ procFormat = (Color::InternalFormat)(procFormat | Color::NONLINEAR);
+
+ if(filterFormatPremultiplied)
+ procFormat = (Color::InternalFormat)(procFormat | Color::PREMULTIPLIED);
+ else
+ procFormat = (Color::InternalFormat)(procFormat & ~Color::PREMULTIPLIED);
+
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color s = src.readPixel(i,j); //convert to RGBA [0,1]
+ s.convert(procFormat);
+
+ Color d(0,0,0,0,procFormat);
+ d.r = matrix[0+4*0] * s.r + matrix[0+4*1] * s.g + matrix[0+4*2] * s.b + matrix[0+4*3] * s.a + matrix[0+4*4];
+ d.g = matrix[1+4*0] * s.r + matrix[1+4*1] * s.g + matrix[1+4*2] * s.b + matrix[1+4*3] * s.a + matrix[1+4*4];
+ d.b = matrix[2+4*0] * s.r + matrix[2+4*1] * s.g + matrix[2+4*2] * s.b + matrix[2+4*3] * s.a + matrix[2+4*4];
+ d.a = matrix[3+4*0] * s.r + matrix[3+4*1] * s.g + matrix[3+4*2] * s.b + matrix[3+4*3] * s.a + matrix[3+4*4];
+
+ writeFilteredPixel(i, j, d, channelMask);
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Reads a pixel from image with tiling mode applied.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static Color readTiledPixel(int x, int y, int w, int h, VGTilingMode tilingMode, const Array<Color>& image, const Color& edge)
+{
+ Color s;
+ if(x < 0 || x >= w || y < 0 || y >= h)
+ { //apply tiling mode
+ switch(tilingMode)
+ {
+ case VG_TILE_FILL:
+ s = edge;
+ break;
+ case VG_TILE_PAD:
+ x = RI_INT_MIN(RI_INT_MAX(x, 0), w-1);
+ y = RI_INT_MIN(RI_INT_MAX(y, 0), h-1);
+ RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
+ s = image[y*w+x];
+ break;
+ case VG_TILE_REPEAT:
+ x = RI_INT_MOD(x, w);
+ y = RI_INT_MOD(y, h);
+ RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
+ s = image[y*w+x];
+ break;
+ default:
+ RI_ASSERT(tilingMode == VG_TILE_REFLECT);
+ x = RI_INT_MOD(x, w*2);
+ y = RI_INT_MOD(y, h*2);
+ if(x >= w) x = w*2-1-x;
+ if(y >= h) y = h*2-1-y;
+ RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
+ s = image[y*w+x];
+ break;
+ }
+ }
+ else
+ {
+ RI_ASSERT(x >= 0 && x < w && y >= 0 && y < h);
+ s = image[y*w+x];
+ }
+ return s;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns processing format for filtering.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static Color::InternalFormat getProcessingFormat(Color::InternalFormat srcFormat, bool filterFormatLinear, bool filterFormatPremultiplied)
+{
+ Color::InternalFormat procFormat = (Color::InternalFormat)(srcFormat & ~Color::LUMINANCE); //process in RGB, not luminance
+ if(filterFormatLinear)
+ procFormat = (Color::InternalFormat)(procFormat & ~Color::NONLINEAR);
+ else
+ procFormat = (Color::InternalFormat)(procFormat | Color::NONLINEAR);
+
+ if(filterFormatPremultiplied)
+ procFormat = (Color::InternalFormat)(procFormat | Color::PREMULTIPLIED);
+ else
+ procFormat = (Color::InternalFormat)(procFormat & ~Color::PREMULTIPLIED);
+ return procFormat;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Applies convolution filter.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::convolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernel, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
+{
+ RI_ASSERT(src.m_data); //source exists
+ RI_ASSERT(m_data); //destination exists
+ RI_ASSERT(kernel && kernelWidth > 0 && kernelHeight > 0);
+ RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
+
+ //the area to be written is an intersection of source and destination image areas.
+ //lower-left corners of the images are aligned.
+ int w = RI_INT_MIN(m_width, src.m_width);
+ int h = RI_INT_MIN(m_height, src.m_height);
+ RI_ASSERT(w > 0 && h > 0);
+
+ Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
+
+ Color edge = edgeFillColor;
+ edge.clamp();
+ edge.convert(procFormat);
+
+ Array<Color> tmp;
+ tmp.resize(src.m_width*src.m_height); //throws bad_alloc
+
+ //copy source region to tmp and do conversion
+ for(int j=0;j<src.m_height;j++)
+ {
+ for(int i=0;i<src.m_width;i++)
+ {
+ Color s = src.readPixel(i, j);
+ s.convert(procFormat);
+ tmp[j*src.m_width+i] = s;
+ }
+ }
+
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color sum(0,0,0,0,procFormat);
+
+ for(int kj=0;kj<kernelHeight;kj++)
+ {
+ for(int ki=0;ki<kernelWidth;ki++)
+ {
+ int x = i+ki-shiftX;
+ int y = j+kj-shiftY;
+ Color s = readTiledPixel(x, y, src.m_width, src.m_height, tilingMode, tmp, edge);
+
+ int kx = kernelWidth-ki-1;
+ int ky = kernelHeight-kj-1;
+ RI_ASSERT(kx >= 0 && kx < kernelWidth && ky >= 0 && ky < kernelHeight);
+
+ sum += (RIfloat)kernel[kx*kernelHeight+ky] * s;
+ }
+ }
+
+ sum *= scale;
+ sum.r += bias;
+ sum.g += bias;
+ sum.b += bias;
+ sum.a += bias;
+
+ writeFilteredPixel(i, j, sum, channelMask);
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Applies separable convolution filter.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::separableConvolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernelX, const RIint16* kernelY, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
+{
+ RI_ASSERT(src.m_data); //source exists
+ RI_ASSERT(m_data); //destination exists
+ RI_ASSERT(kernelX && kernelY && kernelWidth > 0 && kernelHeight > 0);
+ RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
+
+ //the area to be written is an intersection of source and destination image areas.
+ //lower-left corners of the images are aligned.
+ int w = RI_INT_MIN(m_width, src.m_width);
+ int h = RI_INT_MIN(m_height, src.m_height);
+ RI_ASSERT(w > 0 && h > 0);
+
+ Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
+
+ Color edge = edgeFillColor;
+ edge.clamp();
+ edge.convert(procFormat);
+
+ Array<Color> tmp;
+ tmp.resize(src.m_width*src.m_height); //throws bad_alloc
+
+ //copy source region to tmp and do conversion
+ for(int j=0;j<src.m_height;j++)
+ {
+ for(int i=0;i<src.m_width;i++)
+ {
+ Color s = src.readPixel(i, j);
+ s.convert(procFormat);
+ tmp[j*src.m_width+i] = s;
+ }
+ }
+
+ Array<Color> tmp2;
+ tmp2.resize(w*src.m_height); //throws bad_alloc
+ for(int j=0;j<src.m_height;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color sum(0,0,0,0,procFormat);
+ for(int ki=0;ki<kernelWidth;ki++)
+ {
+ int x = i+ki-shiftX;
+ Color s = readTiledPixel(x, j, src.m_width, src.m_height, tilingMode, tmp, edge);
+
+ int kx = kernelWidth-ki-1;
+ RI_ASSERT(kx >= 0 && kx < kernelWidth);
+
+ sum += (RIfloat)kernelX[kx] * s;
+ }
+ tmp2[j*w+i] = sum;
+ }
+ }
+
+ if(tilingMode == VG_TILE_FILL)
+ { //convolve the edge color
+ Color sum(0,0,0,0,procFormat);
+ for(int ki=0;ki<kernelWidth;ki++)
+ {
+ sum += (RIfloat)kernelX[ki] * edge;
+ }
+ edge = sum;
+ }
+
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color sum(0,0,0,0,procFormat);
+ for(int kj=0;kj<kernelHeight;kj++)
+ {
+ int y = j+kj-shiftY;
+ Color s = readTiledPixel(i, y, w, src.m_height, tilingMode, tmp2, edge);
+
+ int ky = kernelHeight-kj-1;
+ RI_ASSERT(ky >= 0 && ky < kernelHeight);
+
+ sum += (RIfloat)kernelY[ky] * s;
+ }
+
+ sum *= scale;
+ sum.r += bias;
+ sum.g += bias;
+ sum.b += bias;
+ sum.a += bias;
+
+ writeFilteredPixel(i, j, sum, channelMask);
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Applies Gaussian blur filter.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::gaussianBlur(const Image& src, RIfloat stdDeviationX, RIfloat stdDeviationY, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
+{
+ RI_ASSERT(src.m_data); //source exists
+ RI_ASSERT(m_data); //destination exists
+ RI_ASSERT(stdDeviationX > 0.0f && stdDeviationY > 0.0f);
+ RI_ASSERT(stdDeviationX <= RI_MAX_GAUSSIAN_STD_DEVIATION && stdDeviationY <= RI_MAX_GAUSSIAN_STD_DEVIATION);
+ RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
+
+ //the area to be written is an intersection of source and destination image areas.
+ //lower-left corners of the images are aligned.
+ int w = RI_INT_MIN(m_width, src.m_width);
+ int h = RI_INT_MIN(m_height, src.m_height);
+ RI_ASSERT(w > 0 && h > 0);
+
+ Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
+
+ Color edge = edgeFillColor;
+ edge.clamp();
+ edge.convert(procFormat);
+
+ Array<Color> tmp;
+ tmp.resize(src.m_width*src.m_height); //throws bad_alloc
+
+ //copy source region to tmp and do conversion
+ for(int j=0;j<src.m_height;j++)
+ {
+ for(int i=0;i<src.m_width;i++)
+ {
+ Color s = src.readPixel(i, j);
+ s.convert(procFormat);
+ tmp[j*src.m_width+i] = s;
+ }
+ }
+
+ RIfloat expScaleX = -1.0f / (2.0f*stdDeviationX*stdDeviationX);
+ RIfloat expScaleY = -1.0f / (2.0f*stdDeviationY*stdDeviationY);
+
+ int kernelWidth = (int)(stdDeviationX * 4.0f + 1.0f);
+ int kernelHeight = (int)(stdDeviationY * 4.0f + 1.0f);
+
+ //make a separable kernel
+ Array<RIfloat> kernelX;
+ kernelX.resize(kernelWidth*2+1);
+ int shiftX = kernelWidth;
+ RIfloat scaleX = 0.0f;
+ for(int i=0;i<kernelX.size();i++)
+ {
+ int x = i-shiftX;
+ kernelX[i] = (RIfloat)exp((RIfloat)x*(RIfloat)x * expScaleX);
+ scaleX += kernelX[i];
+ }
+ scaleX = 1.0f / scaleX; //NOTE: using the mathematical definition of the scaling term doesn't work since we cut the filter support early for performance
+
+ Array<RIfloat> kernelY;
+ kernelY.resize(kernelHeight*2+1);
+ int shiftY = kernelHeight;
+ RIfloat scaleY = 0.0f;
+ for(int i=0;i<kernelY.size();i++)
+ {
+ int y = i-shiftY;
+ kernelY[i] = (RIfloat)exp((RIfloat)y*(RIfloat)y * expScaleY);
+ scaleY += kernelY[i];
+ }
+ scaleY = 1.0f / scaleY; //NOTE: using the mathematical definition of the scaling term doesn't work since we cut the filter support early for performance
+
+ Array<Color> tmp2;
+ tmp2.resize(w*src.m_height); //throws bad_alloc
+ //horizontal pass
+ for(int j=0;j<src.m_height;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color sum(0,0,0,0,procFormat);
+ for(int ki=0;ki<kernelX.size();ki++)
+ {
+ int x = i+ki-shiftX;
+ sum += kernelX[ki] * readTiledPixel(x, j, src.m_width, src.m_height, tilingMode, tmp, edge);
+ }
+ tmp2[j*w+i] = sum * scaleX;
+ }
+ }
+ //vertical pass
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color sum(0,0,0,0,procFormat);
+ for(int kj=0;kj<kernelY.size();kj++)
+ {
+ int y = j+kj-shiftY;
+ sum += kernelY[kj] * readTiledPixel(i, y, w, src.m_height, tilingMode, tmp2, edge);
+ }
+ writeFilteredPixel(i, j, sum * scaleY, channelMask);
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns lookup table format for lookup filters.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static Color::InternalFormat getLUTFormat(bool outputLinear, bool outputPremultiplied)
+{
+ Color::InternalFormat lutFormat = Color::lRGBA;
+ if(outputLinear && outputPremultiplied)
+ lutFormat = Color::lRGBA_PRE;
+ else if(!outputLinear && !outputPremultiplied)
+ lutFormat = Color::sRGBA;
+ else if(!outputLinear && outputPremultiplied)
+ lutFormat = Color::sRGBA_PRE;
+ return lutFormat;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Applies multi-channel lookup table filter.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::lookup(const Image& src, const RIuint8 * redLUT, const RIuint8 * greenLUT, const RIuint8 * blueLUT, const RIuint8 * alphaLUT, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
+{
+ RI_ASSERT(src.m_data); //source exists
+ RI_ASSERT(m_data); //destination exists
+ RI_ASSERT(redLUT && greenLUT && blueLUT && alphaLUT);
+ RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
+
+ //the area to be written is an intersection of source and destination image areas.
+ //lower-left corners of the images are aligned.
+ int w = RI_INT_MIN(m_width, src.m_width);
+ int h = RI_INT_MIN(m_height, src.m_height);
+ RI_ASSERT(w > 0 && h > 0);
+
+ Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
+ Color::InternalFormat lutFormat = getLUTFormat(outputLinear, outputPremultiplied);
+
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color s = src.readPixel(i,j); //convert to RGBA [0,1]
+ s.convert(procFormat);
+
+ Color d(0,0,0,0,lutFormat);
+ d.r = intToColor( redLUT[colorToInt(s.r, 255)], 255);
+ d.g = intToColor(greenLUT[colorToInt(s.g, 255)], 255);
+ d.b = intToColor( blueLUT[colorToInt(s.b, 255)], 255);
+ d.a = intToColor(alphaLUT[colorToInt(s.a, 255)], 255);
+
+ writeFilteredPixel(i, j, d, channelMask);
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Applies single channel lookup table filter.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Image::lookupSingle(const Image& src, const RIuint32 * lookupTable, VGImageChannel sourceChannel, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask)
+{
+ RI_ASSERT(src.m_data); //source exists
+ RI_ASSERT(m_data); //destination exists
+ RI_ASSERT(lookupTable);
+ RI_ASSERT(m_referenceCount > 0 && src.m_referenceCount > 0);
+
+ //the area to be written is an intersection of source and destination image areas.
+ //lower-left corners of the images are aligned.
+ int w = RI_INT_MIN(m_width, src.m_width);
+ int h = RI_INT_MIN(m_height, src.m_height);
+ RI_ASSERT(w > 0 && h > 0);
+
+ if(src.m_desc.isLuminance())
+ sourceChannel = VG_RED;
+ else if(src.m_desc.redBits + src.m_desc.greenBits + src.m_desc.blueBits == 0)
+ {
+ RI_ASSERT(src.m_desc.alphaBits);
+ sourceChannel = VG_ALPHA;
+ }
+
+ Color::InternalFormat procFormat = getProcessingFormat(src.m_desc.internalFormat, filterFormatLinear, filterFormatPremultiplied);
+ Color::InternalFormat lutFormat = getLUTFormat(outputLinear, outputPremultiplied);
+
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ Color s = src.readPixel(i,j); //convert to RGBA [0,1]
+ s.convert(procFormat);
+ int e;
+ switch(sourceChannel)
+ {
+ case VG_RED:
+ e = colorToInt(s.r, 255);
+ break;
+ case VG_GREEN:
+ e = colorToInt(s.g, 255);
+ break;
+ case VG_BLUE:
+ e = colorToInt(s.b, 255);
+ break;
+ default:
+ RI_ASSERT(sourceChannel == VG_ALPHA);
+ e = colorToInt(s.a, 255);
+ break;
+ }
+
+ RIuint32 l = ((const RIuint32*)lookupTable)[e];
+ Color d(0,0,0,0,lutFormat);
+ d.r = intToColor((l>>24), 255);
+ d.g = intToColor((l>>16), 255);
+ d.b = intToColor((l>> 8), 255);
+ d.a = intToColor((l ), 255);
+
+ writeFilteredPixel(i, j, d, channelMask);
+ }
+ }
+}
+
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Surface::Surface(const Color::Descriptor& desc, int width, int height, int numSamples) :
+ m_width(width),
+ m_height(height),
+ m_numSamples(numSamples),
+ m_referenceCount(0),
+ m_image(NULL)
+{
+ RI_ASSERT(width > 0 && height > 0 && numSamples > 0 && numSamples <= 32);
+ m_image = RI_NEW(Image, (desc, width*numSamples, height, 0)); //throws bad_alloc
+ m_image->addReference();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Surface::Surface(Image* image) :
+ m_width(0),
+ m_height(0),
+ m_numSamples(1),
+ m_referenceCount(0),
+ m_image(image)
+{
+ RI_ASSERT(image);
+ m_width = image->getWidth();
+ m_height = image->getHeight();
+ m_image->addReference();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Surface::Surface(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data) :
+ m_width(width),
+ m_height(height),
+ m_numSamples(1),
+ m_referenceCount(0),
+ m_image(NULL)
+{
+ RI_ASSERT(width > 0 && height > 0);
+ m_image = RI_NEW(Image, (desc, width, height, stride, data)); //throws bad_alloc
+ m_image->addReference();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Surface::~Surface()
+{
+ RI_ASSERT(m_referenceCount == 0);
+ if(!m_image->removeReference())
+ RI_DELETE(m_image);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Surface::clear(const Color& clearColor, int x, int y, int w, int h)
+{
+ Rectangle rect;
+ rect.x = 0;
+ rect.y = 0;
+ rect.width = getWidth();
+ rect.height = getHeight();
+ Array<Rectangle> scissors;
+ scissors.push_back(rect);
+ clear(clearColor, x, y, w, h, scissors);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Surface::clear(const Color& clearColor, int x, int y, int w, int h, const Array<Rectangle>& scissors)
+{
+ RI_ASSERT(w > 0 && h > 0);
+
+ //intersect clear region with image bounds
+ Rectangle r(0,0,getWidth(),getHeight());
+ r.intersect(Rectangle(x,y,w,h));
+ if(!r.width || !r.height)
+ return; //intersection is empty or one of the rectangles is invalid
+
+ Array<ScissorEdge> scissorEdges;
+ for(int i=0;i<scissors.size();i++)
+ {
+ if(scissors[i].width > 0 && scissors[i].height > 0)
+ {
+ ScissorEdge e;
+ e.miny = scissors[i].y;
+ e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
+
+ e.x = scissors[i].x;
+ e.direction = 1;
+ scissorEdges.push_back(e); //throws bad_alloc
+ e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
+ e.direction = -1;
+ scissorEdges.push_back(e); //throws bad_alloc
+ }
+ }
+ if(!scissorEdges.size())
+ return; //there are no scissor rectangles => nothing is visible
+
+ //sort scissor edges by edge x
+ scissorEdges.sort();
+
+ //clear the image
+ Color col = clearColor;
+ col.clamp();
+ col.convert(m_image->getDescriptor().internalFormat);
+
+ Array<ScissorEdge> scissorAet;
+ for(int j=r.y;j<r.y + r.height;j++)
+ {
+ //gather scissor edges intersecting this scanline
+ scissorAet.clear();
+ for(int e=0;e<scissorEdges.size();e++)
+ {
+ const ScissorEdge& se = scissorEdges[e];
+ if(j >= se.miny && j < se.maxy)
+ scissorAet.push_back(scissorEdges[e]); //throws bad_alloc
+ }
+ if(!scissorAet.size())
+ continue; //scissoring is on, but there are no scissor rectangles on this scanline
+
+ //clear a scanline
+ int scissorWinding = 0;
+ int scissorIndex = 0;
+ for(int i=r.x;i<r.x + r.width;i++)
+ {
+ while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= i)
+ scissorWinding += scissorAet[scissorIndex++].direction;
+ RI_ASSERT(scissorWinding >= 0);
+
+ if(scissorWinding)
+ {
+ for(int s=0;s<m_numSamples;s++)
+ writeSample(i, j, s, col);
+ }
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Surface::blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h)
+{
+ Rectangle rect;
+ rect.x = 0;
+ rect.y = 0;
+ rect.width = getWidth();
+ rect.height = getHeight();
+ Array<Rectangle> scissors;
+ scissors.push_back(rect);
+ blit(src, sx, sy, dx, dy, w, h, scissors);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note no overlap is possible. Single sample to single or multisample (replicate)
+*//*-------------------------------------------------------------------*/
+
+void Surface::blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors)
+{
+ //img=>fb: vgSetPixels
+ //user=>fb: vgWritePixels
+ computeBlitRegion(sx, sy, dx, dy, w, h, src.getWidth(), src.getHeight(), getWidth(), getHeight());
+ if(w <= 0 || h <= 0)
+ return; //zero area
+
+ Array<ScissorEdge> scissorEdges;
+ for(int i=0;i<scissors.size();i++)
+ {
+ if(scissors[i].width > 0 && scissors[i].height > 0)
+ {
+ ScissorEdge e;
+ e.miny = scissors[i].y;
+ e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
+
+ e.x = scissors[i].x;
+ e.direction = 1;
+ scissorEdges.push_back(e); //throws bad_alloc
+ e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
+ e.direction = -1;
+ scissorEdges.push_back(e); //throws bad_alloc
+ }
+ }
+ if(!scissorEdges.size())
+ return; //there are no scissor rectangles => nothing is visible
+
+ //sort scissor edges by edge x
+ scissorEdges.sort();
+
+ Array<ScissorEdge> scissorAet;
+ for(int j=0;j<h;j++)
+ {
+ //gather scissor edges intersecting this scanline
+ scissorAet.clear();
+ for(int e=0;e<scissorEdges.size();e++)
+ {
+ const ScissorEdge& se = scissorEdges[e];
+ if(dy + j >= se.miny && dy + j < se.maxy)
+ scissorAet.push_back(scissorEdges[e]); //throws bad_alloc
+ }
+ if(!scissorAet.size())
+ continue; //scissoring is on, but there are no scissor rectangles on this scanline
+
+ //blit a scanline
+ int scissorWinding = 0;
+ int scissorIndex = 0;
+ for(int i=0;i<w;i++)
+ {
+ while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= dx + i)
+ scissorWinding += scissorAet[scissorIndex++].direction;
+ RI_ASSERT(scissorWinding >= 0);
+
+ if(scissorWinding)
+ {
+ Color c = src.readPixel(sx + i, sy + j);
+ c.convert(getDescriptor().internalFormat);
+ for(int s=0;s<m_numSamples;s++)
+ writeSample(dx + i, dy + j, s, c);
+ }
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Surface::blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h)
+{
+ Rectangle rect;
+ rect.x = 0;
+ rect.y = 0;
+ rect.width = getWidth();
+ rect.height = getHeight();
+ Array<Rectangle> scissors;
+ scissors.push_back(rect);
+ blit(src, sx, sy, dx, dy, w, h, scissors);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Surface::blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors)
+{
+ RI_ASSERT(m_numSamples == src->m_numSamples);
+
+ //fb=>fb: vgCopyPixels
+ computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), getWidth(), getHeight());
+ if(w <= 0 || h <= 0)
+ return; //zero area
+
+ Array<ScissorEdge> scissorEdges;
+ for(int i=0;i<scissors.size();i++)
+ {
+ if(scissors[i].width > 0 && scissors[i].height > 0)
+ {
+ ScissorEdge e;
+ e.miny = scissors[i].y;
+ e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
+
+ e.x = scissors[i].x;
+ e.direction = 1;
+ scissorEdges.push_back(e); //throws bad_alloc
+ e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
+ e.direction = -1;
+ scissorEdges.push_back(e); //throws bad_alloc
+ }
+ }
+ if(!scissorEdges.size())
+ return; //there are no scissor rectangles => nothing is visible
+
+ //sort scissor edges by edge x
+ scissorEdges.sort();
+
+ Array<Color> tmp;
+ tmp.resize(w*m_numSamples*h); //throws bad_alloc
+
+ //copy source region to tmp
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ int numSamples = m_numSamples;
+ for(int s=0;s<numSamples;s++)
+ {
+ Color c = src->m_image->readPixel((sx + i)*m_numSamples+s, sy + j);
+ c.convert(m_image->getDescriptor().internalFormat);
+ tmp[(j*w+i)*m_numSamples+s] = c;
+ }
+ }
+ }
+
+ Array<ScissorEdge> scissorAet;
+ for(int j=0;j<h;j++)
+ {
+ //gather scissor edges intersecting this scanline
+ scissorAet.clear();
+ for(int e=0;e<scissorEdges.size();e++)
+ {
+ const ScissorEdge& se = scissorEdges[e];
+ if(dy + j >= se.miny && dy + j < se.maxy)
+ scissorAet.push_back(scissorEdges[e]); //throws bad_alloc
+ }
+ if(!scissorAet.size())
+ continue; //scissoring is on, but there are no scissor rectangles on this scanline
+
+ //blit a scanline
+ int scissorWinding = 0;
+ int scissorIndex = 0;
+ for(int i=0;i<w;i++)
+ {
+ while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= dx + i)
+ scissorWinding += scissorAet[scissorIndex++].direction;
+ RI_ASSERT(scissorWinding >= 0);
+
+ if(scissorWinding)
+ {
+ int numSamples = m_numSamples;
+ for(int s=0;s<numSamples;s++)
+ {
+ m_image->writePixel((dx + i)*m_numSamples+s, dy + j, tmp[(j*w+i)*m_numSamples+s]);
+ }
+ }
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Surface::mask(const Image* src, VGMaskOperation operation, int x, int y, int w, int h)
+{
+ RI_ASSERT(w > 0 && h > 0);
+
+ if(operation == VG_CLEAR_MASK || operation == VG_FILL_MASK)
+ {
+ //intersect clear region with image bounds
+ Rectangle r(0,0,getWidth(),getHeight());
+ r.intersect(Rectangle(x,y,w,h));
+ if(!r.width || !r.height)
+ return; //intersection is empty or one of the rectangles is invalid
+
+ if(m_numSamples == 1)
+ {
+ RIfloat m = 0.0f;
+ if(operation == VG_FILL_MASK)
+ m = 1.0f;
+ for(int j=r.y;j<r.y + r.height;j++)
+ {
+ for(int i=r.x;i<r.x + r.width;i++)
+ {
+ writeMaskCoverage(i, j, m);
+ }
+ }
+ }
+ else
+ {
+ unsigned int m = 0;
+ if(operation == VG_FILL_MASK)
+ m = (1<<m_numSamples)-1;
+ for(int j=r.y;j<r.y + r.height;j++)
+ {
+ for(int i=r.x;i<r.x + r.width;i++)
+ {
+ writeMaskMSAA(i, j, m);
+ }
+ }
+ }
+ }
+ else
+ {
+ RI_ASSERT(src);
+
+ int sx = 0, sy = 0, dx = x, dy = y;
+ computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), getWidth(), getHeight());
+ if(w <= 0 || h <= 0)
+ return; //zero area
+
+ if(m_numSamples == 1)
+ {
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ RIfloat amask = src->readMaskPixel(sx + i, sy + j);
+ if(operation == VG_SET_MASK)
+ writeMaskCoverage(dx + i, dy + j, amask);
+ else
+ {
+ RIfloat aprev = readMaskCoverage(dx + i, dy + j);
+ RIfloat anew = 0.0f;
+ switch(operation)
+ {
+ case VG_UNION_MASK: anew = 1.0f - (1.0f - amask)*(1.0f - aprev); break;
+ case VG_INTERSECT_MASK: anew = amask * aprev; break;
+ default: anew = aprev * (1.0f - amask); RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
+ }
+ writeMaskCoverage(dx + i, dy + j, anew);
+ }
+ }
+ }
+ }
+ else
+ {
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ RIfloat fmask = src->readMaskPixel(sx + i, sy + j);
+ //TODO implement dithering?
+ unsigned int amask = fmask > 0.5f ? (1<<m_numSamples)-1 : 0;
+ if(operation == VG_SET_MASK)
+ writeMaskMSAA(dx + i, dy + j, amask);
+ else
+ {
+ unsigned int aprev = readMaskMSAA(dx + i, dy + j);
+ unsigned int anew = 0;
+ switch(operation)
+ {
+ case VG_UNION_MASK: anew = amask | aprev; break;
+ case VG_INTERSECT_MASK: anew = amask & aprev; break;
+ default: anew = ~amask & aprev; RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
+ }
+ writeMaskMSAA(dx + i, dy + j, anew);
+ }
+ }
+ }
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Surface::mask(const Surface* src, VGMaskOperation operation, int x, int y, int w, int h)
+{
+ RI_ASSERT(w > 0 && h > 0);
+
+ if(operation == VG_CLEAR_MASK || operation == VG_FILL_MASK)
+ {
+ //intersect clear region with image bounds
+ Rectangle r(0,0,getWidth(),getHeight());
+ r.intersect(Rectangle(x,y,w,h));
+ if(!r.width || !r.height)
+ return; //intersection is empty or one of the rectangles is invalid
+
+ if(m_numSamples == 1)
+ {
+ RIfloat m = 0.0f;
+ if(operation == VG_FILL_MASK)
+ m = 1.0f;
+ for(int j=r.y;j<r.y + r.height;j++)
+ {
+ for(int i=r.x;i<r.x + r.width;i++)
+ {
+ writeMaskCoverage(i, j, m);
+ }
+ }
+ }
+ else
+ {
+ unsigned int m = 0;
+ if(operation == VG_FILL_MASK)
+ m = (1<<m_numSamples)-1;
+ for(int j=r.y;j<r.y + r.height;j++)
+ {
+ for(int i=r.x;i<r.x + r.width;i++)
+ {
+ writeMaskMSAA(i, j, m);
+ }
+ }
+ }
+ }
+ else
+ {
+ RI_ASSERT(src);
+ RI_ASSERT(m_numSamples == src->m_numSamples);
+
+ int sx = 0, sy = 0, dx = x, dy = y;
+ computeBlitRegion(sx, sy, dx, dy, w, h, src->getWidth(), src->getHeight(), getWidth(), getHeight());
+ if(w <= 0 || h <= 0)
+ return; //zero area
+
+ if(m_numSamples == 1)
+ {
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ RIfloat amask = src->readMaskCoverage(sx + i, sy + j);
+ if(operation == VG_SET_MASK)
+ writeMaskCoverage(dx + i, dy + j, amask);
+ else
+ {
+ RIfloat aprev = readMaskCoverage(dx + i, dy + j);
+ RIfloat anew = 0.0f;
+ switch(operation)
+ {
+ case VG_UNION_MASK: anew = 1.0f - (1.0f - amask)*(1.0f - aprev); break;
+ case VG_INTERSECT_MASK: anew = amask * aprev; break;
+ default: anew = aprev * (1.0f - amask); RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
+ }
+ writeMaskCoverage(dx + i, dy + j, anew);
+ }
+ }
+ }
+ }
+ else
+ {
+ for(int j=0;j<h;j++)
+ {
+ for(int i=0;i<w;i++)
+ {
+ unsigned int amask = src->readMaskMSAA(sx + i, sy + j);
+ if(operation == VG_SET_MASK)
+ writeMaskMSAA(dx + i, dy + j, amask);
+ else
+ {
+ unsigned int aprev = readMaskMSAA(dx + i, dy + j);
+ unsigned int anew = 0;
+ switch(operation)
+ {
+ case VG_UNION_MASK: anew = amask | aprev; break;
+ case VG_INTERSECT_MASK: anew = amask & aprev; break;
+ default: anew = ~amask & aprev; RI_ASSERT(operation == VG_SUBTRACT_MASK); break;
+ }
+ writeMaskMSAA(dx + i, dy + j, anew);
+ }
+ }
+ }
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+RIfloat Surface::readMaskCoverage(int x, int y) const
+{
+ RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
+ RI_ASSERT(m_numSamples == 1);
+ return m_image->readMaskPixel(x, y);
+}
+
+void Surface::writeMaskCoverage(int x, int y, RIfloat m)
+{
+ RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
+ RI_ASSERT(m_numSamples == 1);
+ m_image->writeMaskPixel(x, y, m); //TODO support other than alpha formats but don't write to color channels?
+}
+
+unsigned int Surface::readMaskMSAA(int x, int y) const
+{
+ RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
+ RI_ASSERT(m_numSamples > 1);
+ unsigned int m = 0;
+ for(int i=0;i<m_numSamples;i++)
+ {
+ if(m_image->readMaskPixel(x*m_numSamples+i, y) > 0.5f) //TODO is this the right formula for converting alpha to bit mask? does it matter?
+ m |= 1<<i;
+ }
+ return m;
+}
+
+void Surface::writeMaskMSAA(int x, int y, unsigned int m)
+{
+ RI_ASSERT(x >= 0 && x < m_width && y >= 0 && y < m_height);
+ RI_ASSERT(m_numSamples > 1);
+ for(int i=0;i<m_numSamples;i++)
+ {
+ RIfloat a = 0.0f;
+ if(m & (1<<i))
+ a = 1.0f;
+ m_image->writeMaskPixel(x*m_numSamples+i, y, a); //TODO support other than alpha formats but don't write to color channels?
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Color Surface::FSAAResolve(int x, int y) const
+{
+ if(m_numSamples == 1)
+ return readSample(x, y, 0);
+
+ Color::InternalFormat aaFormat = getDescriptor().isLuminance() ? Color::lLA_PRE : Color::lRGBA_PRE; //antialias in linear color space
+ Color r(0.0f, 0.0f, 0.0f, 0.0f, aaFormat);
+ for(int i=0;i<m_numSamples;i++)
+ {
+ Color d = readSample(x, y, i);
+ d.convert(aaFormat);
+ r += d;
+ }
+ r *= 1.0f/m_numSamples;
+ return r;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Drawable::Drawable(const Color::Descriptor& desc, int width, int height, int numSamples, int maskBits) :
+ m_referenceCount(0),
+ m_color(NULL),
+ m_mask(NULL)
+{
+ RI_ASSERT(width > 0 && height > 0 && numSamples > 0 && numSamples <= 32);
+ RI_ASSERT(maskBits == 0 || maskBits == 1 || maskBits == 4 || maskBits == 8);
+ m_color = RI_NEW(Surface, (desc, width, height, numSamples)); //throws bad_alloc
+ m_color->addReference();
+ if(maskBits)
+ {
+ VGImageFormat mf = VG_A_1;
+ if(maskBits == 4)
+ mf = VG_A_4;
+ else if(maskBits == 8)
+ mf = VG_A_8;
+ m_mask = RI_NEW(Surface, (Color::formatToDescriptor(mf), width, height, numSamples));
+ m_mask->addReference();
+ m_mask->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, width, height);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Drawable::Drawable(Image* image, int maskBits) :
+ m_referenceCount(0),
+ m_color(NULL),
+ m_mask(NULL)
+{
+ RI_ASSERT(maskBits == 0 || maskBits == 1 || maskBits == 4 || maskBits == 8);
+ RI_ASSERT(image);
+ m_color = RI_NEW(Surface, (image));
+ m_color->addReference();
+ if(maskBits)
+ {
+ VGImageFormat mf = VG_A_1;
+ if(maskBits == 4)
+ mf = VG_A_4;
+ else if(maskBits == 8)
+ mf = VG_A_8;
+ m_mask = RI_NEW(Surface, (Color::formatToDescriptor(mf), image->getWidth(), image->getHeight(), 1));
+ m_mask->addReference();
+ m_mask->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, image->getWidth(), image->getHeight());
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Drawable::Drawable(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data, int maskBits) :
+ m_referenceCount(0),
+ m_color(NULL),
+ m_mask(NULL)
+{
+ RI_ASSERT(width > 0 && height > 0);
+ RI_ASSERT(maskBits == 0 || maskBits == 1 || maskBits == 4 || maskBits == 8);
+ m_color = RI_NEW(Surface, (desc, width, height, stride, data)); //throws bad_alloc
+ m_color->addReference();
+ if(maskBits)
+ {
+ VGImageFormat mf = VG_A_1;
+ if(maskBits == 4)
+ mf = VG_A_4;
+ else if(maskBits == 8)
+ mf = VG_A_8;
+ m_mask = RI_NEW(Surface, (Color::formatToDescriptor(mf), width, height, 1));
+ m_mask->addReference();
+ m_mask->clear(Color(1,1,1,1,Color::sRGBA), 0, 0, width, height);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Drawable::~Drawable()
+{
+ RI_ASSERT(m_referenceCount == 0);
+ if(!m_color->removeReference())
+ RI_DELETE(m_color);
+ if(m_mask)
+ if(!m_mask->removeReference())
+ RI_DELETE(m_mask);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Drawable::resize(int newWidth, int newHeight)
+{
+ Surface* oldcolor = m_color;
+ Surface* oldmask = m_mask;
+ int oldWidth = m_color->getWidth();
+ int oldHeight = m_color->getHeight();
+
+ //TODO check that image is not a proxy
+ m_color = RI_NEW(Surface, (m_color->getDescriptor(), newWidth, newHeight, m_color->getNumSamples()));
+ m_color->addReference();
+ if(m_mask)
+ {
+ m_mask = RI_NEW(Surface, (m_mask->getDescriptor(), newWidth, newHeight, m_mask->getNumSamples()));
+ m_mask->addReference();
+ }
+
+ int wmin = RI_INT_MIN(newWidth,oldWidth);
+ int hmin = RI_INT_MIN(newHeight,oldHeight);
+ m_color->clear(Color(0.0f, 0.0f, 0.0f, 0.0f, getDescriptor().internalFormat), 0, 0, m_color->getWidth(), m_color->getHeight());
+ m_color->blit(oldcolor, 0, 0, 0, 0, wmin, hmin);
+ if(m_mask)
+ {
+ m_mask->clear(Color(1.0f, 1.0f, 1.0f, 1.0f, getDescriptor().internalFormat), 0, 0, m_mask->getWidth(), m_mask->getHeight());
+ m_mask->blit(oldmask, 0, 0, 0, 0, wmin, hmin);
+ }
+
+ if(!oldcolor->removeReference())
+ RI_DELETE(oldcolor);
+ if(oldmask)
+ if(!oldmask->removeReference())
+ RI_DELETE(oldmask);
+}
+
+//==============================================================================================
+
+} //namespace OpenVGRI
+
+//==============================================================================================
diff --git a/ri/src/riImage.h b/ri/src/riImage.h
new file mode 100644
index 0000000..e930cdf
--- /dev/null
+++ b/ri/src/riImage.h
@@ -0,0 +1,379 @@
+#ifndef __RIIMAGE_H
+#define __RIIMAGE_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Color and Image classes.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#ifndef OPENVG_H
+#include "openvg.h"
+#endif
+
+#ifndef __RIMATH_H
+#include "riMath.h"
+#endif
+
+#ifndef __RIARRAY_H
+#include "riArray.h"
+#endif
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief A class representing rectangles.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class Rectangle
+{
+public:
+ Rectangle() : x(0), y(0), width(0), height(0) {}
+ Rectangle(int rx, int ry, int rw, int rh) : x(rx), y(ry), width(rw), height(rh) {}
+ void intersect(const Rectangle& r)
+ {
+ if(width >= 0 && r.width >= 0 && height >= 0 && r.height >= 0)
+ {
+ int x1 = RI_INT_MIN(RI_INT_ADDSATURATE(x, width), RI_INT_ADDSATURATE(r.x, r.width));
+ x = RI_INT_MAX(x, r.x);
+ width = RI_INT_MAX(x1 - x, 0);
+
+ int y1 = RI_INT_MIN(RI_INT_ADDSATURATE(y, height), RI_INT_ADDSATURATE(r.y, r.height));
+ y = RI_INT_MAX(y, r.y);
+ height = RI_INT_MAX(y1 - y, 0);
+ }
+ else
+ {
+ x = 0;
+ y = 0;
+ width = 0;
+ height = 0;
+ }
+ }
+
+ int x;
+ int y;
+ int width;
+ int height;
+};
+
+/*-------------------------------------------------------------------*//*!
+* \brief A class representing color for processing and converting it
+* to and from various surface formats.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class Color
+{
+public:
+ enum InternalFormat
+ {
+ lRGBA = 0,
+ sRGBA = 1,
+ lRGBA_PRE = 2,
+ sRGBA_PRE = 3,
+ lLA = 4,
+ sLA = 5,
+ lLA_PRE = 6,
+ sLA_PRE = 7
+ };
+ enum FormatBits
+ {
+ NONLINEAR = (1<<0),
+ PREMULTIPLIED = (1<<1),
+ LUMINANCE = (1<<2)
+ };
+ class Descriptor
+ {
+ public:
+ bool isNonlinear() const { return (internalFormat & NONLINEAR) ? true : false; }
+ bool isPremultiplied() const { return (internalFormat & PREMULTIPLIED) ? true : false; }
+ bool isLuminance() const { return (internalFormat & LUMINANCE) ? true : false; }
+ bool isAlphaOnly() const { return (alphaBits && (redBits+greenBits+blueBits+luminanceBits) == 0) ? true : false; }
+
+ int redBits;
+ int redShift;
+ int greenBits;
+ int greenShift;
+ int blueBits;
+ int blueShift;
+ int alphaBits;
+ int alphaShift;
+ int luminanceBits;
+ int luminanceShift;
+ VGImageFormat format;
+ InternalFormat internalFormat;
+ int bitsPerPixel;
+ };
+
+ RI_INLINE Color() : r(0.0f), g(0.0f), b(0.0f), a(0.0f), m_format(lRGBA) {}
+ RI_INLINE Color(RIfloat cl, RIfloat ca, InternalFormat cs) : r(cl), g(cl), b(cl), a(ca), m_format(cs) { RI_ASSERT(cs == lLA || cs == sLA || cs == lLA_PRE || cs == sLA_PRE); }
+ RI_INLINE Color(RIfloat cr, RIfloat cg, RIfloat cb, RIfloat ca, InternalFormat cs) : r(cr), g(cg), b(cb), a(ca), m_format(cs) { RI_ASSERT(cs == lRGBA || cs == sRGBA || cs == lRGBA_PRE || cs == sRGBA_PRE || cs == lLA || cs == sLA || cs == lLA_PRE || cs == sLA_PRE); }
+ RI_INLINE Color(const Color& c) : r(c.r), g(c.g), b(c.b), a(c.a), m_format(c.m_format) {}
+ RI_INLINE Color& operator=(const Color&c) { r = c.r; g = c.g; b = c.b; a = c.a; m_format = c.m_format; return *this; }
+ RI_INLINE void operator*=(RIfloat f) { r *= f; g *= f; b *= f; a*= f; }
+ RI_INLINE void operator+=(const Color& c1) { RI_ASSERT(m_format == c1.getInternalFormat()); r += c1.r; g += c1.g; b += c1.b; a += c1.a; }
+ RI_INLINE void operator-=(const Color& c1) { RI_ASSERT(m_format == c1.getInternalFormat()); r -= c1.r; g -= c1.g; b -= c1.b; a -= c1.a; }
+
+ void set(RIfloat cl, RIfloat ca, InternalFormat cs) { RI_ASSERT(cs == lLA || cs == sLA || cs == lLA_PRE || cs == sLA_PRE); r = cl; g = cl; b = cl; a = ca; m_format = cs; }
+ void set(RIfloat cr, RIfloat cg, RIfloat cb, RIfloat ca, InternalFormat cs) { RI_ASSERT(cs == lRGBA || cs == sRGBA || cs == lRGBA_PRE || cs == sRGBA_PRE); r = cr; g = cg; b = cb; a = ca; m_format = cs; }
+ void unpack(unsigned int inputData, const Descriptor& inputDesc);
+ unsigned int pack(const Descriptor& outputDesc) const;
+ RI_INLINE InternalFormat getInternalFormat() const { return m_format; }
+
+ //clamps nonpremultiplied colors and alpha to [0,1] range, and premultiplied alpha to [0,1], colors to [0,a]
+ void clamp() { a = RI_CLAMP(a,0.0f,1.0f); RIfloat u = (m_format & PREMULTIPLIED) ? a : (RIfloat)1.0f; r = RI_CLAMP(r,0.0f,u); g = RI_CLAMP(g,0.0f,u); b = RI_CLAMP(b,0.0f,u); }
+ void convert(InternalFormat outputFormat);
+ void premultiply() { if(!(m_format & PREMULTIPLIED)) { r *= a; g *= a; b *= a; m_format = (InternalFormat)(m_format | PREMULTIPLIED); } }
+ void unpremultiply() { if(m_format & PREMULTIPLIED) { RIfloat ooa = (a != 0.0f) ? 1.0f/a : (RIfloat)0.0f; r *= ooa; g *= ooa; b *= ooa; m_format = (InternalFormat)(m_format & ~PREMULTIPLIED); } }
+ void luminanceToRGB() { if(m_format & LUMINANCE) { RI_ASSERT(r == g && g == b); m_format = (InternalFormat)(m_format & ~LUMINANCE); } }
+
+ bool isNonlinear() const { return (m_format & NONLINEAR) ? true : false; }
+ bool isPremultiplied() const { return (m_format & PREMULTIPLIED) ? true : false; }
+ bool isLuminance() const { return (m_format & LUMINANCE) ? true : false; }
+
+ RI_INLINE void assertConsistency() const;
+
+ static Descriptor formatToDescriptor(VGImageFormat format);
+ static bool isValidDescriptor(const Descriptor& desc);
+
+ RIfloat r;
+ RIfloat g;
+ RIfloat b;
+ RIfloat a;
+private:
+ InternalFormat m_format;
+};
+
+RI_INLINE Color operator*(const Color& c, RIfloat f) { return Color(c.r*f, c.g*f, c.b*f, c.a*f, c.getInternalFormat()); }
+RI_INLINE Color operator*(RIfloat f, const Color& c) { return Color(c.r*f, c.g*f, c.b*f, c.a*f, c.getInternalFormat()); }
+RI_INLINE Color operator+(const Color& c0, const Color& c1) { RI_ASSERT(c0.getInternalFormat() == c1.getInternalFormat()); return Color(c0.r+c1.r, c0.g+c1.g, c0.b+c1.b, c0.a+c1.a, c0.getInternalFormat()); }
+RI_INLINE Color operator-(const Color& c0, const Color& c1) { RI_ASSERT(c0.getInternalFormat() == c1.getInternalFormat()); return Color(c0.r-c1.r, c0.g-c1.g, c0.b-c1.b, c0.a-c1.a, c0.getInternalFormat()); }
+RI_INLINE void Color::assertConsistency() const
+{
+ RI_ASSERT(r >= 0.0f && r <= 1.0f);
+ RI_ASSERT(g >= 0.0f && g <= 1.0f);
+ RI_ASSERT(b >= 0.0f && b <= 1.0f);
+ RI_ASSERT(a >= 0.0f && a <= 1.0f);
+ RI_ASSERT(!isPremultiplied() || (r <= a && g <= a && b <= a)); //premultiplied colors must have color channels less than or equal to alpha
+ RI_ASSERT((isLuminance() && r == g && r == b) || !isLuminance()); //if luminance, r=g=b
+}
+
+//==============================================================================================
+
+/*-------------------------------------------------------------------*//*!
+* \brief Storage and operations for VGImage.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class Surface;
+class Image
+{
+public:
+ Image(const Color::Descriptor& desc, int width, int height, VGbitfield allowedQuality); //throws bad_alloc
+ //use data from a memory buffer. NOTE: data is not copied, so it is user's responsibility to make sure the data remains valid while the Image is in use.
+ Image(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data); //throws bad_alloc
+ //child image constructor
+ Image(Image* parent, int x, int y, int width, int height); //throws bad_alloc
+ ~Image();
+
+ const Color::Descriptor& getDescriptor() const { return m_desc; }
+ int getWidth() const { return m_width; }
+ int getHeight() const { return m_height; }
+ int getStride() const { return m_stride; }
+ Image* getParent() const { return m_parent; }
+ VGbitfield getAllowedQuality() const { return m_allowedQuality; }
+ void addInUse() { m_inUse++; }
+ void removeInUse() { RI_ASSERT(m_inUse > 0); m_inUse--; }
+ int isInUse() const { return m_inUse; }
+ RIuint8* getData() const { return m_data; }
+ void addReference() { m_referenceCount++; }
+ int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
+ bool overlaps(const Image* src) const;
+
+ void clear(const Color& clearColor, int x, int y, int w, int h);
+ void blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, bool dither); //throws bad_alloc
+ void blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h); //throws bad_alloc
+
+ Color readPixel(int x, int y) const;
+ void writePixel(int x, int y, const Color& c);
+ void writeFilteredPixel(int x, int y, const Color& c, VGbitfield channelMask);
+
+ RIfloat readMaskPixel(int x, int y) const; //can read any image format
+ void writeMaskPixel(int x, int y, RIfloat m); //can write only to VG_A_x
+
+ Color resample(RIfloat x, RIfloat y, const Matrix3x3& surfaceToImage, VGImageQuality quality, VGTilingMode tilingMode, const Color& tileFillColor); //throws bad_alloc
+ void makeMipMaps(); //throws bad_alloc
+
+ void colorMatrix(const Image& src, const RIfloat* matrix, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
+ void convolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernel, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
+ void separableConvolve(const Image& src, int kernelWidth, int kernelHeight, int shiftX, int shiftY, const RIint16* kernelX, const RIint16* kernelY, RIfloat scale, RIfloat bias, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
+ void gaussianBlur(const Image& src, RIfloat stdDeviationX, RIfloat stdDeviationY, VGTilingMode tilingMode, const Color& edgeFillColor, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
+ void lookup(const Image& src, const RIuint8 * redLUT, const RIuint8 * greenLUT, const RIuint8 * blueLUT, const RIuint8 * alphaLUT, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
+ void lookupSingle(const Image& src, const RIuint32 * lookupTable, VGImageChannel sourceChannel, bool outputLinear, bool outputPremultiplied, bool filterFormatLinear, bool filterFormatPremultiplied, VGbitfield channelMask);
+private:
+ Image(const Image&); //!< Not allowed.
+ void operator=(const Image&); //!< Not allowed.
+
+ Color readTexel(int u, int v, int level, VGTilingMode tilingMode, const Color& tileFillColor) const;
+
+ Color::Descriptor m_desc;
+ int m_width;
+ int m_height;
+ VGbitfield m_allowedQuality;
+ int m_inUse;
+ int m_stride;
+ RIuint8* m_data;
+ int m_referenceCount;
+ bool m_ownsData;
+ Image* m_parent;
+ int m_storageOffsetX;
+ int m_storageOffsetY;
+
+ bool m_mipmapsValid;
+ Array<Image*> m_mipmaps;
+};
+
+/*-------------------------------------------------------------------*//*!
+* \brief Surface class abstracting multisampled rendering surface.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class Surface
+{
+public:
+ Surface(const Color::Descriptor& desc, int width, int height, int numSamples); //throws bad_alloc
+ Surface(Image* image); //throws bad_alloc
+ Surface(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data); //throws bad_alloc
+ ~Surface();
+
+ RI_INLINE const Color::Descriptor& getDescriptor() const { return m_image->getDescriptor(); }
+ RI_INLINE int getWidth() const { return m_width; }
+ RI_INLINE int getHeight() const { return m_height; }
+ RI_INLINE int getNumSamples() const { return m_numSamples; }
+ RI_INLINE void addReference() { m_referenceCount++; }
+ RI_INLINE int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
+ RI_INLINE int isInUse() const { return m_image->isInUse(); }
+ RI_INLINE bool isInUse(Image* image) const { return image == m_image ? true : false; }
+
+ void clear(const Color& clearColor, int x, int y, int w, int h);
+ void clear(const Color& clearColor, int x, int y, int w, int h, const Array<Rectangle>& scissors);
+ void blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h); //throws bad_alloc
+ void blit(const Image& src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors); //throws bad_alloc
+ void blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h); //throws bad_alloc
+ void blit(const Surface* src, int sx, int sy, int dx, int dy, int w, int h, const Array<Rectangle>& scissors); //throws bad_alloc
+ void mask(const Image* src, VGMaskOperation operation, int x, int y, int w, int h);
+ void mask(const Surface* src, VGMaskOperation operation, int x, int y, int w, int h);
+
+ RI_INLINE Color readSample(int x, int y, int sample) const { return m_image->readPixel(x*m_numSamples+sample, y); }
+ RI_INLINE void writeSample(int x, int y, int sample, const Color& c) { m_image->writePixel(x*m_numSamples+sample, y, c); }
+
+ RIfloat readMaskCoverage(int x, int y) const;
+ void writeMaskCoverage(int x, int y, RIfloat m);
+ unsigned int readMaskMSAA(int x, int y) const;
+ void writeMaskMSAA(int x, int y, unsigned int m);
+
+ Color FSAAResolve(int x, int y) const; //for fb=>img: vgGetPixels, vgReadPixels
+private:
+ Surface(const Surface&); //!< Not allowed.
+ void operator=(const Surface&); //!< Not allowed.
+
+ struct ScissorEdge
+ {
+ ScissorEdge() : x(0), miny(0), maxy(0), direction(0) {}
+ bool operator<(const ScissorEdge& e) const { return x < e.x; }
+ int x;
+ int miny;
+ int maxy;
+ int direction; //1 start, -1 end
+ };
+
+ int m_width;
+ int m_height;
+ int m_numSamples;
+ int m_referenceCount;
+ Image* m_image;
+};
+
+/*-------------------------------------------------------------------*//*!
+* \brief Drawable class for encapsulating color and mask buffers.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class Drawable
+{
+public:
+ Drawable(const Color::Descriptor& desc, int width, int height, int numSamples, int maskBits); //throws bad_alloc
+ Drawable(Image* image, int maskBits); //throws bad_alloc
+ Drawable(const Color::Descriptor& desc, int width, int height, int stride, RIuint8* data, int maskBits); //throws bad_alloc
+ ~Drawable();
+
+ RI_INLINE const Color::Descriptor& getDescriptor() const { return m_color->getDescriptor(); }
+ RI_INLINE int getNumMaskBits() const { if(!m_mask) return 0; return m_mask->getDescriptor().alphaBits; }
+ RI_INLINE int getWidth() const { return m_color->getWidth(); }
+ RI_INLINE int getHeight() const { return m_color->getHeight(); }
+ RI_INLINE int getNumSamples() const { return m_color->getNumSamples(); }
+ RI_INLINE void addReference() { m_referenceCount++; }
+ RI_INLINE int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
+ RI_INLINE int isInUse() const { return m_color->isInUse() || (m_mask && m_mask->isInUse()); }
+ RI_INLINE bool isInUse(Image* image) const { return m_color->isInUse(image) || (m_mask && m_mask->isInUse(image)); }
+ RI_INLINE Surface* getColorBuffer() const { return m_color; }
+ RI_INLINE Surface* getMaskBuffer() const { return m_mask; }
+
+ void resize(int newWidth, int newHeight); //throws bad_alloc
+private:
+ Drawable(const Drawable&); //!< Not allowed.
+ void operator=(const Drawable&); //!< Not allowed.
+
+ int m_referenceCount;
+ Surface* m_color;
+ Surface* m_mask;
+};
+
+//==============================================================================================
+
+} //namespace OpenVGRI
+
+//==============================================================================================
+
+#endif /* __RIIMAGE_H */
diff --git a/ri/src/riMath.cpp b/ri/src/riMath.cpp
new file mode 100644
index 0000000..409a083
--- /dev/null
+++ b/ri/src/riMath.cpp
@@ -0,0 +1,75 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Implementation of non-inline matrix functions.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "riDefs.h"
+#include "riMath.h"
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief Inverts a 3x3 matrix. Returns false if the matrix is singular.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool Matrix3x3::invert()
+{
+ bool affine = isAffine();
+ RIfloat det00 = matrix[1][1]*matrix[2][2] - matrix[2][1]*matrix[1][2];
+ RIfloat det01 = matrix[2][0]*matrix[1][2] - matrix[1][0]*matrix[2][2];
+ RIfloat det02 = matrix[1][0]*matrix[2][1] - matrix[2][0]*matrix[1][1];
+
+ RIfloat d = matrix[0][0]*det00 + matrix[0][1]*det01 + matrix[0][2]*det02;
+ if( d == 0.0f ) return false; //singular, leave the matrix unmodified and return false
+ d = 1.0f / d;
+
+ Matrix3x3 t;
+ t[0][0] = d * det00;
+ t[1][0] = d * det01;
+ t[2][0] = d * det02;
+ t[0][1] = d * (matrix[2][1]*matrix[0][2] - matrix[0][1]*matrix[2][2]);
+ t[1][1] = d * (matrix[0][0]*matrix[2][2] - matrix[2][0]*matrix[0][2]);
+ t[2][1] = d * (matrix[2][0]*matrix[0][1] - matrix[0][0]*matrix[2][1]);
+ t[0][2] = d * (matrix[0][1]*matrix[1][2] - matrix[1][1]*matrix[0][2]);
+ t[1][2] = d * (matrix[1][0]*matrix[0][2] - matrix[0][0]*matrix[1][2]);
+ t[2][2] = d * (matrix[0][0]*matrix[1][1] - matrix[1][0]*matrix[0][1]);
+ if(affine)
+ t[2].set(0,0,1); //affine matrix stays affine
+ *this = t;
+ return true;
+}
+
+//==============================================================================================
+
+} //namespace OpenVGRI
diff --git a/ri/src/riMath.h b/ri/src/riMath.h
new file mode 100644
index 0000000..0b2ab10
--- /dev/null
+++ b/ri/src/riMath.h
@@ -0,0 +1,382 @@
+#ifndef __RIMATH_H
+#define __RIMATH_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Math functions, Vector and Matrix classes.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#ifndef __RIDEFS_H
+#include "riDefs.h"
+#endif
+
+#include <math.h>
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+RI_INLINE int RI_ISNAN(float a)
+{
+ RIfloatInt p;
+ p.f = a;
+ unsigned int exponent = (p.i>>23) & 0xff;
+ unsigned int mantissa = p.i & 0x7fffff;
+ if(exponent == 255 && mantissa)
+ return 1;
+ return 0;
+}
+
+#if (RI_MANTISSA_BITS > 23)
+#error RI_MANTISSA_BITS is greater than 23
+#elif (RI_EXPONENT_BITS > 8)
+#error RI_EXPONENT_BITS is greater than 8
+#elif (RI_MANTISSA_BITS != 23) || (RI_EXPONENT_BITS != 8)
+
+class RIfloat
+{
+public:
+ RIfloat() : v(0.0f) { removeBits(); }
+ RIfloat(float a) : v(a) { removeBits(); }
+ RIfloat(double a) : v((float)a) { removeBits(); }
+ RIfloat(int a) : v((float)a) { removeBits(); }
+ RIfloat(unsigned int a) : v((float)a) { removeBits(); }
+ RIfloat& operator=(const RIfloat &a) { v = a.v; removeBits(); return *this; }
+ RIfloat& operator+=(const RIfloat &a){ v += a.v; removeBits(); return *this; }
+ RIfloat& operator-=(const RIfloat &a){ v -= a.v; removeBits(); return *this; }
+ RIfloat& operator*=(const RIfloat &a){ v *= a.v; removeBits(); return *this; }
+ RIfloat& operator/=(const RIfloat &a){ v /= a.v; removeBits(); return *this; }
+ RIfloat operator-() const { return -v; }
+ operator float() const { return v; }
+ operator double() const { return (double)v; }
+ operator int() const { return (int)v; }
+
+ friend RIfloat operator+(const RIfloat &a, const RIfloat &b);
+ friend RIfloat operator+(float a, const RIfloat &b);
+ friend RIfloat operator+(const RIfloat &a, float b);
+ friend RIfloat operator-(const RIfloat &a, const RIfloat &b);
+ friend RIfloat operator-(float a, const RIfloat &b);
+ friend RIfloat operator-(const RIfloat &a, float b);
+ friend RIfloat operator*(const RIfloat &a, const RIfloat &b);
+ friend RIfloat operator*(float a, const RIfloat &b);
+ friend RIfloat operator*(const RIfloat &a, float b);
+ friend RIfloat operator/(const RIfloat &a, const RIfloat &b);
+ friend RIfloat operator/(float a, const RIfloat &b);
+ friend RIfloat operator/(const RIfloat &a, float b);
+
+ friend bool operator<(const RIfloat &a, const RIfloat &b);
+ friend bool operator<(float a, const RIfloat &b);
+ friend bool operator<(const RIfloat &a, float b);
+ friend bool operator>(const RIfloat &a, const RIfloat &b);
+ friend bool operator>(float a, const RIfloat &b);
+ friend bool operator>(const RIfloat &a, float b);
+ friend bool operator<=(const RIfloat &a, const RIfloat &b);
+ friend bool operator<=(float a, const RIfloat &b);
+ friend bool operator<=(const RIfloat &a, float b);
+ friend bool operator>=(const RIfloat &a, const RIfloat &b);
+ friend bool operator>=(float a, const RIfloat &b);
+ friend bool operator>=(const RIfloat &a, float b);
+ friend bool operator==(const RIfloat &a, const RIfloat &b);
+ friend bool operator==(float a, const RIfloat &b);
+ friend bool operator==(const RIfloat &a, float b);
+ friend bool operator!=(const RIfloat &a, const RIfloat &b);
+ friend bool operator!=(float a, const RIfloat &b);
+ friend bool operator!=(const RIfloat &a, float b);
+private:
+ void removeBits()
+ {
+ RIfloatInt p;
+ p.f = v;
+ unsigned int exponent = (p.i>>23) & 0xff;
+ if(exponent == 0 || exponent == 255)
+ return; //zero, denormal, infinite, or NaN
+
+ p.i &= ~((1<<(23-RI_MANTISSA_BITS))-1);
+
+#if (RI_EXPONENT_BITS != 8)
+ if (exponent > 127 + (1 << (RI_EXPONENT_BITS-1)))
+ exponent = 127 + (1 << (RI_EXPONENT_BITS-1));
+
+ if (exponent < 127 + 1 - (1 << (RI_EXPONENT_BITS-1)))
+ exponent = 127 + 1 - (1 << (RI_EXPONENT_BITS-1));
+
+ p.i &= ~(0xff<<23);
+ p.i |= exponent<<23;
+#endif
+ v = p.f;
+ }
+
+ float v;
+};
+
+RI_INLINE RIfloat operator+(const RIfloat &a, const RIfloat &b) { return RIfloat(a.v+b.v); }
+RI_INLINE RIfloat operator+(float a, const RIfloat &b) { return RIfloat(a+b.v); }
+RI_INLINE RIfloat operator+(const RIfloat &a, float b) { return RIfloat(a.v+b); }
+RI_INLINE RIfloat operator-(const RIfloat &a, const RIfloat &b) { return RIfloat(a.v-b.v); }
+RI_INLINE RIfloat operator-(float a, const RIfloat &b) { return RIfloat(a-b.v); }
+RI_INLINE RIfloat operator-(const RIfloat &a, float b) { return RIfloat(a.v-b); }
+RI_INLINE RIfloat operator*(const RIfloat &a, const RIfloat &b) { return RIfloat(a.v*b.v); }
+RI_INLINE RIfloat operator*(float a, const RIfloat &b) { return RIfloat(a*b.v); }
+RI_INLINE RIfloat operator*(const RIfloat &a, float b) { return RIfloat(a.v*b); }
+RI_INLINE RIfloat operator/(const RIfloat &a, const RIfloat &b) { return RIfloat(a.v/b.v); }
+RI_INLINE RIfloat operator/(float a, const RIfloat &b) { return RIfloat(a/b.v); }
+RI_INLINE RIfloat operator/(const RIfloat &a, float b) { return RIfloat(a.v/b); }
+
+RI_INLINE bool operator<(const RIfloat &a, const RIfloat &b) { return a.v < b.v ? true : false; }
+RI_INLINE bool operator<(float a, const RIfloat &b) { return a < b.v ? true : false; }
+RI_INLINE bool operator<(const RIfloat &a, float b) { return a.v < b ? true : false; }
+RI_INLINE bool operator>(const RIfloat &a, const RIfloat &b) { return a.v > b.v ? true : false; }
+RI_INLINE bool operator>(float a, const RIfloat &b) { return a > b.v ? true : false; }
+RI_INLINE bool operator>(const RIfloat &a, float b) { return a.v > b ? true : false; }
+RI_INLINE bool operator<=(const RIfloat &a, const RIfloat &b) { return a.v <= b.v ? true : false; }
+RI_INLINE bool operator<=(float a, const RIfloat &b) { return a <= b.v ? true : false; }
+RI_INLINE bool operator<=(const RIfloat &a, float b) { return a.v <= b ? true : false; }
+RI_INLINE bool operator>=(const RIfloat &a, const RIfloat &b) { return a.v >= b.v ? true : false; }
+RI_INLINE bool operator>=(float a, const RIfloat &b) { return a >= b.v ? true : false; }
+RI_INLINE bool operator>=(const RIfloat &a, float b) { return a.v >= b ? true : false; }
+RI_INLINE bool operator==(const RIfloat &a, const RIfloat &b) { return a.v == b.v ? true : false; }
+RI_INLINE bool operator==(float a, const RIfloat &b) { return a == b.v ? true : false; }
+RI_INLINE bool operator==(const RIfloat &a, float b) { return a.v == b ? true : false; }
+RI_INLINE bool operator!=(const RIfloat &a, const RIfloat &b) { return a.v != b.v ? true : false; }
+RI_INLINE bool operator!=(float a, const RIfloat &b) { return a != b.v ? true : false; }
+RI_INLINE bool operator!=(const RIfloat &a, float b) { return a.v != b ? true : false; }
+
+#else
+typedef float RIfloat;
+#endif
+
+#define PI 3.141592654f
+
+RI_INLINE RIfloat RI_MAX(RIfloat a, RIfloat b) { return (a > b) ? a : b; }
+RI_INLINE RIfloat RI_MIN(RIfloat a, RIfloat b) { return (a < b) ? a : b; }
+RI_INLINE RIfloat RI_CLAMP(RIfloat a, RIfloat l, RIfloat h) { if(RI_ISNAN(a)) return l; RI_ASSERT(l <= h); return (a < l) ? l : (a > h) ? h : a; }
+RI_INLINE void RI_SWAP(RIfloat &a, RIfloat &b) { RIfloat tmp = a; a = b; b = tmp; }
+RI_INLINE RIfloat RI_ABS(RIfloat a) { return (a < 0.0f) ? -a : a; }
+RI_INLINE RIfloat RI_SQR(RIfloat a) { return a * a; }
+RI_INLINE RIfloat RI_DEG_TO_RAD(RIfloat a) { return a * PI / 180.0f; }
+RI_INLINE RIfloat RI_RAD_TO_DEG(RIfloat a) { return a * 180.0f/ PI; }
+RI_INLINE RIfloat RI_MOD(RIfloat a, RIfloat b) { if(RI_ISNAN(a) || RI_ISNAN(b)) return 0.0f; RI_ASSERT(b >= 0.0f); if(b == 0.0f) return 0.0f; RIfloat f = (RIfloat)fmod(a, b); if(f < 0.0f) f += b; RI_ASSERT(f >= 0.0f && f <= b); return f; }
+
+RI_INLINE int RI_INT_MAX(int a, int b) { return (a > b) ? a : b; }
+RI_INLINE int RI_INT_MIN(int a, int b) { return (a < b) ? a : b; }
+RI_INLINE void RI_INT_SWAP(int &a, int &b) { int tmp = a; a = b; b = tmp; }
+RI_INLINE int RI_INT_MOD(int a, int b) { RI_ASSERT(b >= 0); if(!b) return 0; int i = a % b; if(i < 0) i += b; RI_ASSERT(i >= 0 && i < b); return i; }
+RI_INLINE int RI_INT_ADDSATURATE(int a, int b) { RI_ASSERT(b >= 0); int r = a + b; return (r >= a) ? r : RI_INT32_MAX; }
+
+class Matrix3x3;
+class Vector2;
+class Vector3;
+
+//==============================================================================================
+
+//MatrixRxC, R = number of rows, C = number of columns
+//indexing: matrix[row][column]
+//Matrix3x3 inline functions cannot be inside the class because Vector3 is not defined yet when Matrix3x3 is defined
+
+class Matrix3x3
+{
+public:
+ RI_INLINE Matrix3x3 (); //initialized to identity
+ RI_INLINE Matrix3x3 ( const Matrix3x3& m );
+ RI_INLINE Matrix3x3 ( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 );
+ RI_INLINE ~Matrix3x3 ();
+ RI_INLINE Matrix3x3& operator= ( const Matrix3x3& m );
+ RI_INLINE Vector3& operator[] ( int i ); //returns a row vector
+ RI_INLINE const Vector3& operator[] ( int i ) const;
+ RI_INLINE void set ( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 );
+ RI_INLINE const Vector3 getRow ( int i ) const;
+ RI_INLINE const Vector3 getColumn ( int i ) const;
+ RI_INLINE void setRow ( int i, const Vector3& v );
+ RI_INLINE void setColumn ( int i, const Vector3& v );
+ RI_INLINE void operator*= ( const Matrix3x3& m );
+ RI_INLINE void operator*= ( RIfloat f );
+ RI_INLINE void operator+= ( const Matrix3x3& m );
+ RI_INLINE void operator-= ( const Matrix3x3& m );
+ RI_INLINE const Matrix3x3 operator- () const;
+ RI_INLINE void identity ();
+ RI_INLINE void transpose ();
+ bool invert (); //if the matrix is singular, returns false and leaves it unmodified
+ RI_INLINE RIfloat det () const;
+ RI_INLINE bool isAffine () const;
+
+private:
+ RIfloat matrix[3][3];
+};
+
+//==============================================================================================
+
+class Vector2
+{
+public:
+ RI_INLINE Vector2 () : x(0.0f), y(0.0f) {}
+ RI_INLINE Vector2 ( const Vector2& v ) : x(v.x), y(v.y) {}
+ RI_INLINE Vector2 ( RIfloat fx, RIfloat fy ) : x(fx), y(fy) {}
+ RI_INLINE ~Vector2 () {}
+ RI_INLINE Vector2& operator= ( const Vector2& v ) { x = v.x; y = v.y; return *this; }
+ RI_INLINE RIfloat& operator[] ( int i ) { RI_ASSERT(i>=0&&i<2); return (&x)[i]; }
+ RI_INLINE const RIfloat& operator[] ( int i ) const { RI_ASSERT(i>=0&&i<2); return (&x)[i]; }
+ RI_INLINE void set ( RIfloat fx, RIfloat fy ) { x = fx; y = fy; }
+ RI_INLINE void operator*= ( RIfloat f ) { x *= f; y *= f; }
+ RI_INLINE void operator+= ( const Vector2& v ) { x += v.x; y += v.y; }
+ RI_INLINE void operator-= ( const Vector2& v ) { x -= v.x; y -= v.y; }
+ RI_INLINE const Vector2 operator- () const { return Vector2(-x,-y); }
+ //if the vector is zero, returns false and leaves it unmodified
+ RI_INLINE bool normalize () { double l = (double)x*(double)x+(double)y*(double)y; if( l == 0.0 ) return false; l = 1.0 / sqrt(l); x = (RIfloat)((double)x * l); y = (RIfloat)((double)y * l); return true; }
+ RI_INLINE RIfloat length () const { return (RIfloat)sqrt((double)x*(double)x+(double)y*(double)y); }
+ RI_INLINE void scale ( const Vector2& v ) { x *= v.x; y *= v.y; } //component-wise scale
+ RI_INLINE void negate () { x = -x; y = -y; }
+
+ RIfloat x,y;
+};
+
+//==============================================================================================
+
+class Vector3
+{
+public:
+ RI_INLINE Vector3 () : x(0.0f), y(0.0f), z(0.0f) {}
+ RI_INLINE Vector3 ( const Vector3& v ) : x(v.x), y(v.y), z(v.z) {}
+ RI_INLINE Vector3 ( RIfloat fx, RIfloat fy, RIfloat fz ) : x(fx), y(fy), z(fz) {}
+ RI_INLINE ~Vector3 () {}
+ RI_INLINE Vector3& operator= ( const Vector3& v ) { x = v.x; y = v.y; z = v.z; return *this; }
+ RI_INLINE RIfloat& operator[] ( int i ) { RI_ASSERT(i>=0&&i<3); return (&x)[i]; }
+ RI_INLINE const RIfloat& operator[] ( int i ) const { RI_ASSERT(i>=0&&i<3); return (&x)[i]; }
+ RI_INLINE void set ( RIfloat fx, RIfloat fy, RIfloat fz ){ x = fx; y = fy; z = fz; }
+ RI_INLINE void operator*= ( RIfloat f ) { x *= f; y *= f; z *= f; }
+ RI_INLINE void operator+= ( const Vector3& v ) { x += v.x; y += v.y; z += v.z; }
+ RI_INLINE void operator-= ( const Vector3& v ) { x -= v.x; y -= v.y; z -= v.z; }
+ RI_INLINE const Vector3 operator- () const { return Vector3(-x,-y,-z); }
+ //if the vector is zero, returns false and leaves it unmodified
+ RI_INLINE bool normalize () { double l = (double)x*(double)x+(double)y*(double)y+(double)z*(double)z; if( l == 0.0 ) return false; l = 1.0 / sqrt(l); x = (RIfloat)((double)x * l); y = (RIfloat)((double)y * l); z = (RIfloat)((double)z * l); return true; }
+ RI_INLINE RIfloat length () const { return (RIfloat)sqrt((double)x*(double)x+(double)y*(double)y+(double)z*(double)z); }
+ RI_INLINE void scale ( const Vector3& v ) { x *= v.x; y *= v.y; z *= v.z; } //component-wise scale
+ RI_INLINE void negate () { x = -x; y = -y; z = -z; }
+
+ RIfloat x,y,z;
+};
+
+//==============================================================================================
+
+//Vector2 global functions
+RI_INLINE bool operator== ( const Vector2& v1, const Vector2& v2 ) { return (v1.x == v2.x) && (v1.y == v2.y); }
+RI_INLINE bool operator!= ( const Vector2& v1, const Vector2& v2 ) { return (v1.x != v2.x) || (v1.y != v2.y); }
+RI_INLINE bool isEqual ( const Vector2& v1, const Vector2& v2, RIfloat epsilon ) { return RI_SQR(v2.x-v1.x) + RI_SQR(v2.y-v1.y) <= epsilon*epsilon; }
+RI_INLINE bool isZero ( const Vector2& v ) { return (v.x == 0.0f) && (v.y == 0.0f); }
+RI_INLINE const Vector2 operator* ( RIfloat f, const Vector2& v ) { return Vector2(v.x*f,v.y*f); }
+RI_INLINE const Vector2 operator* ( const Vector2& v, RIfloat f ) { return Vector2(v.x*f,v.y*f); }
+RI_INLINE const Vector2 operator+ ( const Vector2& v1, const Vector2& v2 ) { return Vector2(v1.x+v2.x, v1.y+v2.y); }
+RI_INLINE const Vector2 operator- ( const Vector2& v1, const Vector2& v2 ) { return Vector2(v1.x-v2.x, v1.y-v2.y); }
+RI_INLINE RIfloat dot ( const Vector2& v1, const Vector2& v2 ) { return v1.x*v2.x+v1.y*v2.y; }
+//if v is a zero vector, returns a zero vector
+RI_INLINE const Vector2 normalize ( const Vector2& v ) { double l = (double)v.x*(double)v.x+(double)v.y*(double)v.y; if( l != 0.0 ) l = 1.0 / sqrt(l); return Vector2((RIfloat)((double)v.x * l), (RIfloat)((double)v.y * l)); }
+//if onThis is a zero vector, returns a zero vector
+RI_INLINE const Vector2 project ( const Vector2& v, const Vector2& onThis ) { RIfloat l = dot(onThis,onThis); if( l != 0.0f ) l = dot(v, onThis)/l; return onThis * l; }
+RI_INLINE const Vector2 lerp ( const Vector2& v1, const Vector2& v2, RIfloat ratio ) { return v1 + ratio * (v2 - v1); }
+RI_INLINE const Vector2 scale ( const Vector2& v1, const Vector2& v2 ) { return Vector2(v1.x*v2.x, v1.y*v2.y); }
+//matrix * column vector. The input vector2 is implicitly expanded to (x,y,1)
+RI_INLINE const Vector2 affineTransform( const Matrix3x3& m, const Vector2& v ) { RI_ASSERT(m.isAffine()); return Vector2(v.x * m[0][0] + v.y * m[0][1] + m[0][2], v.x * m[1][0] + v.y * m[1][1] + m[1][2]); }
+//matrix * column vector. The input vector2 is implicitly expanded to (x,y,0)
+RI_INLINE const Vector2 affineTangentTransform(const Matrix3x3& m, const Vector2& v) { RI_ASSERT(m.isAffine()); return Vector2(v.x * m[0][0] + v.y * m[0][1], v.x * m[1][0] + v.y * m[1][1]); }
+RI_INLINE const Vector2 perpendicularCW(const Vector2& v) { return Vector2(v.y, -v.x); }
+RI_INLINE const Vector2 perpendicularCCW(const Vector2& v) { return Vector2(-v.y, v.x); }
+RI_INLINE const Vector2 perpendicular(const Vector2& v, bool cw) { if(cw) return Vector2(v.y, -v.x); return Vector2(-v.y, v.x); }
+
+//==============================================================================================
+
+//Vector3 global functions
+RI_INLINE bool operator== ( const Vector3& v1, const Vector3& v2 ) { return (v1.x == v2.x) && (v1.y == v2.y) && (v1.z == v2.z); }
+RI_INLINE bool operator!= ( const Vector3& v1, const Vector3& v2 ) { return (v1.x != v2.x) || (v1.y != v2.y) || (v1.z != v2.z); }
+RI_INLINE bool isEqual ( const Vector3& v1, const Vector3& v2, RIfloat epsilon ) { return RI_SQR(v2.x-v1.x) + RI_SQR(v2.y-v1.y) + RI_SQR(v2.z-v1.z) <= epsilon*epsilon; }
+RI_INLINE const Vector3 operator* ( RIfloat f, const Vector3& v ) { return Vector3(v.x*f,v.y*f,v.z*f); }
+RI_INLINE const Vector3 operator* ( const Vector3& v, RIfloat f ) { return Vector3(v.x*f,v.y*f,v.z*f); }
+RI_INLINE const Vector3 operator+ ( const Vector3& v1, const Vector3& v2 ) { return Vector3(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z); }
+RI_INLINE const Vector3 operator- ( const Vector3& v1, const Vector3& v2 ) { return Vector3(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z); }
+RI_INLINE RIfloat dot ( const Vector3& v1, const Vector3& v2 ) { return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z; }
+RI_INLINE const Vector3 cross ( const Vector3& v1, const Vector3& v2 ) { return Vector3( v1.y*v2.z-v1.z*v2.y, v1.z*v2.x-v1.x*v2.z, v1.x*v2.y-v1.y*v2.x ); }
+//if v is a zero vector, returns a zero vector
+RI_INLINE const Vector3 normalize ( const Vector3& v ) { double l = (double)v.x*(double)v.x+(double)v.y*(double)v.y+(double)v.z*(double)v.z; if( l != 0.0 ) l = 1.0 / sqrt(l); return Vector3((RIfloat)((double)v.x * l), (RIfloat)((double)v.y * l), (RIfloat)((double)v.z * l)); }
+RI_INLINE const Vector3 lerp ( const Vector3& v1, const Vector3& v2, RIfloat ratio ) { return v1 + ratio * (v2 - v1); }
+RI_INLINE const Vector3 scale ( const Vector3& v1, const Vector3& v2 ) { return Vector3(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z); }
+
+//==============================================================================================
+
+//matrix * column vector
+RI_INLINE const Vector3 operator* ( const Matrix3x3& m, const Vector3& v) { return Vector3( v.x*m[0][0]+v.y*m[0][1]+v.z*m[0][2], v.x*m[1][0]+v.y*m[1][1]+v.z*m[1][2], v.x*m[2][0]+v.y*m[2][1]+v.z*m[2][2] ); }
+
+//==============================================================================================
+
+//Matrix3x3 global functions
+RI_INLINE bool operator== ( const Matrix3x3& m1, const Matrix3x3& m2 ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) if( m1[i][j] != m2[i][j] ) return false; return true; }
+RI_INLINE bool operator!= ( const Matrix3x3& m1, const Matrix3x3& m2 ) { return !(m1 == m2); }
+RI_INLINE const Matrix3x3 operator* ( const Matrix3x3& m1, const Matrix3x3& m2 ) { Matrix3x3 t; for(int i=0;i<3;i++) for(int j=0;j<3;j++) t[i][j] = m1[i][0] * m2[0][j] + m1[i][1] * m2[1][j] + m1[i][2] * m2[2][j]; return t; }
+RI_INLINE const Matrix3x3 operator* ( RIfloat f, const Matrix3x3& m ) { Matrix3x3 t(m); t *= f; return t; }
+RI_INLINE const Matrix3x3 operator* ( const Matrix3x3& m, RIfloat f ) { Matrix3x3 t(m); t *= f; return t; }
+RI_INLINE const Matrix3x3 operator+ ( const Matrix3x3& m1, const Matrix3x3& m2 ) { Matrix3x3 t(m1); t += m2; return t; }
+RI_INLINE const Matrix3x3 operator- ( const Matrix3x3& m1, const Matrix3x3& m2 ) { Matrix3x3 t(m1); t -= m2; return t; }
+RI_INLINE const Matrix3x3 transpose ( const Matrix3x3& m ) { Matrix3x3 t(m); t.transpose(); return t; }
+// if the matrix is singular, returns it unmodified
+RI_INLINE const Matrix3x3 invert ( const Matrix3x3& m ) { Matrix3x3 t(m); t.invert(); return t; }
+
+//==============================================================================================
+
+//Matrix3x3 inline functions (cannot be inside the class because Vector3 is not defined yet when Matrix3x3 is defined)
+RI_INLINE Matrix3x3::Matrix3x3 () { identity(); }
+RI_INLINE Matrix3x3::Matrix3x3 ( const Matrix3x3& m ) { *this = m; }
+RI_INLINE Matrix3x3::Matrix3x3 ( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 ) { set(m00,m01,m02,m10,m11,m12,m20,m21,m22); }
+RI_INLINE Matrix3x3::~Matrix3x3 () {}
+RI_INLINE Matrix3x3& Matrix3x3::operator= ( const Matrix3x3& m ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] = m.matrix[i][j]; return *this; }
+RI_INLINE Vector3& Matrix3x3::operator[] ( int i ) { RI_ASSERT(i>=0&&i<3); return (Vector3&)matrix[i][0]; }
+RI_INLINE const Vector3& Matrix3x3::operator[] ( int i ) const { RI_ASSERT(i>=0&&i<3); return (const Vector3&)matrix[i][0]; }
+RI_INLINE void Matrix3x3::set ( RIfloat m00, RIfloat m01, RIfloat m02, RIfloat m10, RIfloat m11, RIfloat m12, RIfloat m20, RIfloat m21, RIfloat m22 ) { matrix[0][0] = m00; matrix[0][1] = m01; matrix[0][2] = m02; matrix[1][0] = m10; matrix[1][1] = m11; matrix[1][2] = m12; matrix[2][0] = m20; matrix[2][1] = m21; matrix[2][2] = m22; }
+RI_INLINE const Vector3 Matrix3x3::getRow ( int i ) const { RI_ASSERT(i>=0&&i<3); return Vector3(matrix[i][0], matrix[i][1], matrix[i][2]); }
+RI_INLINE const Vector3 Matrix3x3::getColumn ( int i ) const { RI_ASSERT(i>=0&&i<3); return Vector3(matrix[0][i], matrix[1][i], matrix[2][i]); }
+RI_INLINE void Matrix3x3::setRow ( int i, const Vector3& v ) { RI_ASSERT(i>=0&&i<3); matrix[i][0] = v.x; matrix[i][1] = v.y; matrix[i][2] = v.z; }
+RI_INLINE void Matrix3x3::setColumn ( int i, const Vector3& v ) { RI_ASSERT(i>=0&&i<3); matrix[0][i] = v.x; matrix[1][i] = v.y; matrix[2][i] = v.z; }
+RI_INLINE void Matrix3x3::operator*= ( const Matrix3x3& m ) { *this = *this * m; }
+RI_INLINE void Matrix3x3::operator*= ( RIfloat f ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] *= f; }
+RI_INLINE void Matrix3x3::operator+= ( const Matrix3x3& m ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] += m.matrix[i][j]; }
+RI_INLINE void Matrix3x3::operator-= ( const Matrix3x3& m ) { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] -= m.matrix[i][j]; }
+RI_INLINE const Matrix3x3 Matrix3x3::operator- () const { return Matrix3x3( -matrix[0][0],-matrix[0][1],-matrix[0][2], -matrix[1][0],-matrix[1][1],-matrix[1][2], -matrix[2][0],-matrix[2][1],-matrix[2][2]); }
+RI_INLINE void Matrix3x3::identity () { for(int i=0;i<3;i++) for(int j=0;j<3;j++) matrix[i][j] = (i == j) ? 1.0f : 0.0f; }
+RI_INLINE void Matrix3x3::transpose () { RI_SWAP(matrix[1][0], matrix[0][1]); RI_SWAP(matrix[2][0], matrix[0][2]); RI_SWAP(matrix[2][1], matrix[1][2]); }
+RI_INLINE RIfloat Matrix3x3::det () const { return matrix[0][0] * (matrix[1][1]*matrix[2][2] - matrix[2][1]*matrix[1][2]) + matrix[0][1] * (matrix[2][0]*matrix[1][2] - matrix[1][0]*matrix[2][2]) + matrix[0][2] * (matrix[1][0]*matrix[2][1] - matrix[2][0]*matrix[1][1]); }
+RI_INLINE bool Matrix3x3::isAffine () const { if(matrix[2][0] == 0.0f && matrix[2][1] == 0.0f && matrix[2][2] == 1.0f) return true; return false; }
+
+//==============================================================================================
+
+} //namespace OpenVGRI
+
+#endif /* __RIMATH_H */
diff --git a/ri/src/riMiniEGL.cpp b/ri/src/riMiniEGL.cpp
new file mode 100644
index 0000000..56927af
--- /dev/null
+++ b/ri/src/riMiniEGL.cpp
@@ -0,0 +1,2132 @@
+/*------------------------------------------------------------------------
+ *
+ * EGL 1.3
+ * -------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Simple implementation of EGL 1.3
+ * \note caveats:
+ - always renders into the backbuffer and blits it to window (no single buffered rendering)
+ - no native Windows or Mac OS X pixmap support
+ - no power management events
+ - no support for swap interval
+ * \todo what happens in egl functions when eglTerminate has been called but the context and surface are still in use?
+ * \todo OSDeinitMutex should be called in case getEGL fails.
+ *//*-------------------------------------------------------------------*/
+
+#include <EGL/egl.h>
+#include "openvg.h"
+#include "riArray.h"
+#include "riMath.h"
+#include "riContext.h"
+#include "riImage.h"
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+void* OSGetCurrentThreadID(void);
+void OSAcquireMutex(void);
+void OSReleaseMutex(void);
+void OSDeinitMutex(void);
+
+EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id);
+void* OSCreateWindowContext(EGLNativeWindowType window);
+void OSDestroyWindowContext(void* context);
+bool OSIsWindow(const void* context);
+void OSGetWindowSize(const void* context, int& width, int& height);
+void OSBlitToWindow(void* context, const Drawable* drawable);
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class RIEGLConfig
+{
+public:
+ RIEGLConfig() : m_desc(Color::formatToDescriptor(VG_sRGBA_8888)), m_configID(0) {}
+ ~RIEGLConfig() {}
+ void set(int r, int g, int b, int a, int l, int bpp, int samples, int maskBits, int ID)
+ {
+ m_desc.redBits = r;
+ m_desc.greenBits = g;
+ m_desc.blueBits = b;
+ m_desc.alphaBits = a;
+ m_desc.luminanceBits = l;
+ m_desc.alphaShift = 0;
+ m_desc.luminanceShift = 0;
+ m_desc.blueShift = b ? a : 0;
+ m_desc.greenShift = g ? a + b : 0;
+ m_desc.redShift = r ? a + b + g : 0;
+ m_desc.format = (VGImageFormat)-1;
+ m_desc.internalFormat = l ? Color::sLA : Color::sRGBA;
+ m_desc.bitsPerPixel = bpp;
+ RI_ASSERT(Color::isValidDescriptor(m_desc));
+ m_samples = samples;
+ m_maskBits = maskBits;
+ m_configID = ID;
+ m_config = (EGLConfig)ID;
+ }
+
+ Color::Descriptor configToDescriptor(bool sRGB, bool premultiplied) const
+ {
+ Color::Descriptor desc = m_desc;
+ unsigned int f = m_desc.luminanceBits ? Color::LUMINANCE : 0;
+ f |= sRGB ? Color::NONLINEAR : 0;
+ f |= premultiplied ? Color::PREMULTIPLIED : 0;
+ desc.internalFormat = (Color::InternalFormat)f;
+ return desc;
+ }
+
+ //EGL RED SIZE bits of Red in the color buffer
+ //EGL GREEN SIZE bits of Green in the color buffer
+ //EGL BLUE SIZE bits of Blue in the color buffer
+ //EGL ALPHA SIZE bits of Alpha in the color buffer
+ //EGL LUMINANCE SIZE bits of Luminance in the color buffer
+ Color::Descriptor m_desc;
+ int m_samples;
+ int m_maskBits;
+ EGLint m_configID; //EGL CONFIG ID unique EGLConfig identifier
+ EGLConfig m_config;
+ //EGL BUFFER SIZE depth of the color buffer (sum of channel bits)
+ //EGL ALPHA MASK SIZE number alpha mask bits (always 8)
+ //EGL BIND TO TEXTURE RGB boolean True if bindable to RGB textures. (always EGL_FALSE)
+ //EGL BIND TO TEXTURE RGBA boolean True if bindable to RGBA textures. (always EGL_FALSE)
+ //EGL COLOR BUFFER TYPE enum color buffer type (EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER)
+ //EGL CONFIG CAVEAT enum any caveats for the configuration (always EGL_NONE)
+ //EGL DEPTH SIZE integer bits of Z in the depth buffer (always 0)
+ //EGL LEVEL integer frame buffer level (always 0)
+ //EGL MAX PBUFFER WIDTH integer maximum width of pbuffer (always INT_MAX)
+ //EGL MAX PBUFFER HEIGHT integer maximum height of pbuffer (always INT_MAX)
+ //EGL MAX PBUFFER PIXELS integer maximum size of pbuffer (always INT_MAX)
+ //EGL MAX SWAP INTERVAL integer maximum swap interval (always 1)
+ //EGL MIN SWAP INTERVAL integer minimum swap interval (always 1)
+ //EGL NATIVE RENDERABLE boolean EGL TRUE if native rendering APIs can render to surface (always EGL_FALSE)
+ //EGL NATIVE VISUAL ID integer handle of corresponding native visual (always 0)
+ //EGL NATIVE VISUAL TYPE integer native visual type of the associated visual (always EGL_NONE)
+ //EGL RENDERABLE TYPE bitmask which client rendering APIs are supported. (always EGL_OPENVG_BIT)
+ //EGL SAMPLE BUFFERS integer number of multisample buffers (always 0)
+ //EGL SAMPLES integer number of samples per pixel (always 0)
+ //EGL STENCIL SIZE integer bits of Stencil in the stencil buffer (always 0)
+ //EGL SURFACE TYPE bitmask which types of EGL surfaces are supported. (always EGL WINDOW BIT | EGL PIXMAP BIT | EGL PBUFFER BIT)
+ //EGL TRANSPARENT TYPE enum type of transparency supported (always EGL_NONE)
+ //EGL TRANSPARENT RED VALUE integer transparent red value (undefined)
+ //EGL TRANSPARENT GREEN VALUE integer transparent green value (undefined)
+ //EGL TRANSPARENT BLUE VALUE integer transparent blue value (undefined)
+};
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class RIEGLContext
+{
+public:
+ RIEGLContext(OpenVGRI::VGContext* vgctx, const EGLConfig config);
+ ~RIEGLContext();
+ void addReference() { m_referenceCount++; }
+ int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
+
+ VGContext* getVGContext() const { return m_vgContext; }
+ const EGLConfig getConfig() const { return m_config; }
+private:
+ RIEGLContext(const RIEGLContext&);
+ RIEGLContext& operator=(const RIEGLContext&);
+ VGContext* m_vgContext;
+ const EGLConfig m_config;
+ int m_referenceCount;
+};
+
+RIEGLContext::RIEGLContext(OpenVGRI::VGContext* vgctx, const EGLConfig config) :
+ m_vgContext(vgctx),
+ m_config(config),
+ m_referenceCount(0)
+{
+}
+RIEGLContext::~RIEGLContext()
+{
+ RI_ASSERT(m_referenceCount == 0);
+ RI_DELETE(m_vgContext);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class RIEGLSurface
+{
+public:
+ RIEGLSurface(void* OSWindowContext, const EGLConfig config, Drawable* drawable, bool largestPbuffer, int renderBuffer);
+ ~RIEGLSurface();
+ void addReference() { m_referenceCount++; }
+ int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
+
+ void* getOSWindowContext() const { return m_OSWindowContext; }
+ const EGLConfig getConfig() const { return m_config; }
+ Drawable* getDrawable() const { return m_drawable; }
+ bool isLargestPbuffer() const { return m_largestPbuffer; }
+ int getRenderBuffer() const { return m_renderBuffer; }
+
+private:
+ RIEGLSurface(const RIEGLSurface&);
+ RIEGLSurface& operator=(const RIEGLSurface&);
+ void* m_OSWindowContext;
+ const EGLConfig m_config;
+ Drawable* m_drawable;
+ bool m_largestPbuffer;
+ int m_renderBuffer; //EGL_BACK_BUFFER or EGL_SINGLE_BUFFER
+ int m_referenceCount;
+};
+
+RIEGLSurface::RIEGLSurface(void* OSWindowContext, const EGLConfig config, Drawable* drawable, bool largestPbuffer, int renderBuffer) :
+ m_OSWindowContext(OSWindowContext),
+ m_config(config),
+ m_drawable(drawable),
+ m_largestPbuffer(largestPbuffer),
+ m_renderBuffer(renderBuffer),
+ m_referenceCount(0)
+{
+ RI_ASSERT(m_renderBuffer == EGL_BACK_BUFFER); //only back buffer rendering is supported
+ m_drawable->addReference();
+}
+
+RIEGLSurface::~RIEGLSurface()
+{
+ RI_ASSERT(m_referenceCount == 0);
+ OSDestroyWindowContext(m_OSWindowContext);
+ if(m_drawable)
+ {
+ if(!m_drawable->removeReference())
+ RI_DELETE(m_drawable);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+#define EGL_NUMCONFIGS 60
+
+class RIEGLDisplay
+{
+public:
+ RIEGLDisplay(EGLDisplay id);
+ ~RIEGLDisplay();
+
+ int getNumConfigs() const { return EGL_NUMCONFIGS; }
+ const RIEGLConfig& getConfig(int i) const { RI_ASSERT(i >= 0 && i < EGL_NUMCONFIGS); return m_configs[i]; }
+ const RIEGLConfig& getConfig(const EGLConfig config) const { for(int i=0;i<EGL_NUMCONFIGS;i++) { if(m_configs[i].m_config == config) return m_configs[i]; } RI_ASSERT(0); return m_configs[0]; }
+
+ const EGLDisplay getID() const { return m_id; }
+
+ void addContext(RIEGLContext* ctx) { RI_ASSERT(ctx); m_contexts.push_back(ctx); } //throws bad_alloc
+ void removeContext(RIEGLContext* ctx) { RI_ASSERT(ctx); bool res = m_contexts.remove(ctx); RI_ASSERT(res); RI_UNREF(res); }
+
+ void addSurface(RIEGLSurface* srf) { RI_ASSERT(srf); m_surfaces.push_back(srf); } //throws bad_alloc
+ void removeSurface(RIEGLSurface* srf) { RI_ASSERT(srf); bool res = m_surfaces.remove(srf); RI_ASSERT(res); RI_UNREF(res); }
+
+ EGLBoolean contextExists(const EGLContext ctx) const;
+ EGLBoolean surfaceExists(const EGLSurface srf) const;
+ EGLBoolean configExists(const EGLConfig cfg) const;
+
+private:
+ RIEGLDisplay(const RIEGLDisplay& t);
+ RIEGLDisplay& operator=(const RIEGLDisplay&t);
+
+ EGLDisplay m_id;
+
+ Array<RIEGLContext*> m_contexts;
+ Array<RIEGLSurface*> m_surfaces;
+
+ RIEGLConfig m_configs[EGL_NUMCONFIGS];
+};
+
+RIEGLDisplay::RIEGLDisplay(EGLDisplay id) :
+ m_id(id),
+ m_contexts(),
+ m_surfaces()
+{
+ RI_ASSERT(EGL_NUMCONFIGS == 60);
+
+ //sorted by RGB/LUMINANCE (exact), larger total number of color bits (at least), buffer size (at least), config ID (exact)
+ //NOTE: 16 bit configs need to be sorted on the fly if the request ignores some channels
+ //NOTE: config IDs start from 1
+ // R B G A L bpp samples maskBits ID
+ m_configs[0].set(8, 8, 8, 8, 0, 32, 1, 8, 1); //EGL_RGB_BUFFER, buffer size = 32
+ m_configs[1].set(8, 8, 8, 0, 0, 32, 1, 8, 2); //EGL_RGB_BUFFER, buffer size = 24
+ m_configs[2].set(5, 5, 5, 1, 0, 16, 1, 4, 3); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[3].set(5, 6, 5, 0, 0, 16, 1, 4, 4); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[4].set(4, 4, 4, 4, 0, 16, 1, 4, 5); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[5].set(0, 0, 0, 8, 0, 8, 1, 8, 6); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[6].set(0, 0, 0, 4, 0, 4, 1, 4, 7); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[7].set(0, 0, 0, 1, 0, 1, 1, 1, 8); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[8].set(0, 0, 0, 0, 8, 8, 1, 8, 9); //EGL_LUMINANCE_BUFFER, buffer size = 8
+ m_configs[9].set(0, 0, 0, 0, 1, 1, 1, 1, 10); //EGL_LUMINANCE_BUFFER, buffer size = 1
+
+ m_configs[10].set(8, 8, 8, 8, 0, 32, 4, 1, 11); //EGL_RGB_BUFFER, buffer size = 32
+ m_configs[11].set(8, 8, 8, 0, 0, 32, 4, 1, 12); //EGL_RGB_BUFFER, buffer size = 24
+ m_configs[12].set(5, 5, 5, 1, 0, 16, 4, 1, 13); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[13].set(5, 6, 5, 0, 0, 16, 4, 1, 14); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[14].set(4, 4, 4, 4, 0, 16, 4, 1, 15); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[15].set(0, 0, 0, 8, 0, 8, 4, 1, 16); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[16].set(0, 0, 0, 4, 0, 4, 4, 1, 17); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[17].set(0, 0, 0, 1, 0, 1, 4, 1, 18); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[18].set(0, 0, 0, 0, 8, 8, 4, 1, 19); //EGL_LUMINANCE_BUFFER, buffer size = 8
+ m_configs[19].set(0, 0, 0, 0, 1, 1, 4, 1, 20); //EGL_LUMINANCE_BUFFER, buffer size = 1
+
+ m_configs[20].set(8, 8, 8, 8, 0, 32, 32, 1, 21); //EGL_RGB_BUFFER, buffer size = 32
+ m_configs[21].set(8, 8, 8, 0, 0, 32, 32, 1, 22); //EGL_RGB_BUFFER, buffer size = 24
+ m_configs[22].set(5, 5, 5, 1, 0, 16, 32, 1, 23); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[23].set(5, 6, 5, 0, 0, 16, 32, 1, 24); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[24].set(4, 4, 4, 4, 0, 16, 32, 1, 25); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[25].set(0, 0, 0, 8, 0, 8, 32, 1, 26); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[26].set(0, 0, 0, 4, 0, 4, 32, 1, 27); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[27].set(0, 0, 0, 1, 0, 1, 32, 1, 28); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[28].set(0, 0, 0, 0, 8, 8, 32, 1, 29); //EGL_LUMINANCE_BUFFER, buffer size = 8
+ m_configs[29].set(0, 0, 0, 0, 1, 1, 32, 1, 30); //EGL_LUMINANCE_BUFFER, buffer size = 1
+
+ //configs without mask
+ m_configs[30].set(8, 8, 8, 8, 0, 32, 1, 0, 31); //EGL_RGB_BUFFER, buffer size = 32
+ m_configs[31].set(8, 8, 8, 0, 0, 32, 1, 0, 32); //EGL_RGB_BUFFER, buffer size = 24
+ m_configs[32].set(5, 5, 5, 1, 0, 16, 1, 0, 33); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[33].set(5, 6, 5, 0, 0, 16, 1, 0, 34); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[34].set(4, 4, 4, 4, 0, 16, 1, 0, 35); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[35].set(0, 0, 0, 8, 0, 8, 1, 0, 36); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[36].set(0, 0, 0, 4, 0, 4, 1, 0, 37); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[37].set(0, 0, 0, 1, 0, 1, 1, 0, 38); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[38].set(0, 0, 0, 0, 8, 8, 1, 0, 39); //EGL_LUMINANCE_BUFFER, buffer size = 8
+ m_configs[39].set(0, 0, 0, 0, 1, 1, 1, 0, 40); //EGL_LUMINANCE_BUFFER, buffer size = 1
+
+ m_configs[40].set(8, 8, 8, 8, 0, 32, 4, 0, 41); //EGL_RGB_BUFFER, buffer size = 32
+ m_configs[41].set(8, 8, 8, 0, 0, 32, 4, 0, 42); //EGL_RGB_BUFFER, buffer size = 24
+ m_configs[42].set(5, 5, 5, 1, 0, 16, 4, 0, 43); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[43].set(5, 6, 5, 0, 0, 16, 4, 0, 44); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[44].set(4, 4, 4, 4, 0, 16, 4, 0, 45); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[45].set(0, 0, 0, 8, 0, 8, 4, 0, 46); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[46].set(0, 0, 0, 4, 0, 4, 4, 0, 47); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[47].set(0, 0, 0, 1, 0, 1, 4, 0, 48); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[48].set(0, 0, 0, 0, 8, 8, 4, 0, 49); //EGL_LUMINANCE_BUFFER, buffer size = 8
+ m_configs[49].set(0, 0, 0, 0, 1, 1, 4, 0, 50); //EGL_LUMINANCE_BUFFER, buffer size = 1
+
+ m_configs[50].set(8, 8, 8, 8, 0, 32, 32, 0, 51); //EGL_RGB_BUFFER, buffer size = 32
+ m_configs[51].set(8, 8, 8, 0, 0, 32, 32, 0, 52); //EGL_RGB_BUFFER, buffer size = 24
+ m_configs[52].set(5, 5, 5, 1, 0, 16, 32, 0, 53); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[53].set(5, 6, 5, 0, 0, 16, 32, 0, 54); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[54].set(4, 4, 4, 4, 0, 16, 32, 0, 55); //EGL_RGB_BUFFER, buffer size = 16
+ m_configs[55].set(0, 0, 0, 8, 0, 8, 32, 0, 56); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[56].set(0, 0, 0, 4, 0, 4, 32, 0, 57); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[57].set(0, 0, 0, 1, 0, 1, 32, 0, 58); //EGL_RGB_BUFFER, buffer size = 8
+ m_configs[58].set(0, 0, 0, 0, 8, 8, 32, 0, 59); //EGL_LUMINANCE_BUFFER, buffer size = 8
+ m_configs[59].set(0, 0, 0, 0, 1, 1, 32, 0, 60); //EGL_LUMINANCE_BUFFER, buffer size = 1
+/*
+attrib default criteria order priority
+--------------------------------------------------------------
+EGL_COLOR_BUFFER_TYPE EGL_RGB_BUFFER Exact None 2
+EGL_RED_SIZE 0 AtLeast Special 3
+EGL_GREEN_SIZE 0 AtLeast Special 3
+EGL_BLUE_SIZE 0 AtLeast Special 3
+EGL_LUMINANCE_SIZE 0 AtLeast Special 3
+EGL_ALPHA_SIZE 0 AtLeast Special 3
+EGL_BUFFER_SIZE 0 AtLeast Smaller 4
+EGL_CONFIG_ID EGL_DONT_CARE Exact Smaller 11
+*/
+}
+
+RIEGLDisplay::~RIEGLDisplay()
+{
+ //mark everything for deletion, but don't delete the current context and surface
+ for(int i=0;i<m_contexts.size();i++)
+ {
+ if(!m_contexts[i]->removeReference())
+ RI_DELETE(m_contexts[i]);
+ }
+ m_contexts.clear(); //remove all contexts from the list (makes further references to the current contexts invalid)
+
+ for(int i=0;i<m_surfaces.size();i++)
+ {
+ if(!m_surfaces[i]->removeReference())
+ RI_DELETE(m_surfaces[i]);
+ }
+ m_surfaces.clear(); //remove all surfaces from the list (makes further references to the current surfaces invalid)
+}
+
+EGLBoolean RIEGLDisplay::contextExists(const EGLContext ctx) const
+{
+ for(int i=0;i<m_contexts.size();i++)
+ {
+ if(m_contexts[i] == ctx)
+ return EGL_TRUE;
+ }
+ return EGL_FALSE;
+}
+
+EGLBoolean RIEGLDisplay::surfaceExists(const EGLSurface surf) const
+{
+ for(int i=0;i<m_surfaces.size();i++)
+ {
+ if(m_surfaces[i] == surf)
+ return EGL_TRUE;
+ }
+ return EGL_FALSE;
+}
+
+EGLBoolean RIEGLDisplay::configExists(const EGLConfig config) const
+{
+ for(int i=0;i<EGL_NUMCONFIGS;i++)
+ {
+ if(m_configs[i].m_config == config)
+ return EGL_TRUE;
+ }
+ return EGL_FALSE;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class RIEGLThread
+{
+public:
+ RIEGLThread(void* currentThreadID);
+ ~RIEGLThread();
+
+ void* getThreadID() const { return m_threadID; }
+
+ void makeCurrent(RIEGLContext* c, RIEGLSurface* s) { m_context = c; m_surface = s; }
+ RIEGLContext* getCurrentContext() const { return m_context; }
+ RIEGLSurface* getCurrentSurface() const { return m_surface; }
+
+ void setError(EGLint error) { m_error = error; }
+ EGLint getError() const { return m_error; }
+
+ void bindAPI(EGLint api) { m_boundAPI = api; }
+ EGLint getBoundAPI() const { return m_boundAPI; }
+
+private:
+ RIEGLThread(const RIEGLThread&);
+ RIEGLThread operator=(const RIEGLThread&);
+
+ RIEGLContext* m_context;
+ RIEGLSurface* m_surface;
+ EGLint m_error;
+ void* m_threadID;
+ EGLint m_boundAPI;
+};
+
+RIEGLThread::RIEGLThread(void* currentThreadID) :
+ m_context(NULL),
+ m_surface(NULL),
+ m_error(EGL_SUCCESS),
+ m_threadID(currentThreadID),
+ m_boundAPI(EGL_NONE)
+{
+}
+
+RIEGLThread::~RIEGLThread()
+{
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class EGL
+{
+public:
+ EGL();
+ ~EGL();
+
+ void addReference() { m_referenceCount++; }
+ int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
+
+ void addDisplay(RIEGLDisplay* display) { RI_ASSERT(display); m_displays.push_back(display); } //throws bad alloc
+ void removeDisplay(RIEGLDisplay* display) { RI_ASSERT(display); bool res = m_displays.remove(display); RI_ASSERT(res); RI_UNREF(res); }
+ RIEGLDisplay* getDisplay(const EGLDisplay displayID) const;
+ const EGLDisplay findDisplay(const EGLContext ctx) const;
+
+ void addCurrentThread(RIEGLThread* thread) { RI_ASSERT(thread); m_currentThreads.push_back(thread); } //throws bad alloc
+ void removeCurrentThread(RIEGLThread* thread) { RI_ASSERT(thread); bool res = m_currentThreads.remove(thread); RI_ASSERT(res); RI_UNREF(res); }
+ RIEGLThread* getCurrentThread() const;
+
+ RIEGLThread* getThread();
+ void destroyThread();
+
+ bool isInUse(const void* image) const;
+
+private:
+ EGL(const EGL&); // Not allowed.
+ const EGL& operator=(const EGL&); // Not allowed.
+
+ Array<RIEGLThread*> m_threads; //threads that have called EGL
+ Array<RIEGLThread*> m_currentThreads; //threads that have a bound context
+ Array<RIEGLDisplay*> m_displays;
+
+ int m_referenceCount;
+};
+
+EGL::EGL() :
+ m_displays(),
+ m_threads(),
+ m_currentThreads(),
+ m_referenceCount(0)
+{
+}
+EGL::~EGL()
+{
+ for(int i=0;i<m_displays.size();i++)
+ {
+ RI_DELETE(m_displays[i]);
+ }
+ for(int i=0;i<m_threads.size();i++)
+ {
+ RI_DELETE(m_threads[i]);
+ }
+ //currentThreads contain just pointers to threads we just deleted
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static EGL* g_egl = NULL; //never use this directly
+static EGL* getEGL()
+{
+ if(!g_egl)
+ {
+ try
+ {
+ g_egl = RI_NEW(EGL, ()); //throws bad_alloc
+ g_egl->addReference();
+ }
+ catch(std::bad_alloc)
+ {
+ g_egl = NULL;
+ }
+ }
+ return g_egl;
+}
+static void releaseEGL()
+{
+ if(g_egl)
+ {
+ if(!g_egl->removeReference())
+ {
+ RI_DELETE(g_egl);
+ g_egl = NULL;
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Given a display ID, return the corresponding object, or NULL
+* if the ID hasn't been initialized.
+* \param
+* \return
+* \note if egl has been initialized for this display, the display ID can
+* be found from egl->m_displays
+*//*-------------------------------------------------------------------*/
+
+RIEGLDisplay* EGL::getDisplay(EGLDisplay displayID) const
+{
+ for(int i=0;i<m_displays.size();i++)
+ {
+ if(displayID == m_displays[i]->getID())
+ return m_displays[i];
+ }
+ return NULL; //error: the display hasn't been eglInitialized
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief return EGLDisplay for the current context
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+const EGLDisplay EGL::findDisplay(EGLContext ctx) const
+{
+ for(int i=0;i<m_displays.size();i++)
+ {
+ if(m_displays[i]->contextExists(ctx))
+ return m_displays[i]->getID();
+ }
+ return EGL_NO_DISPLAY;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief return an EGL thread struct for the thread made current, or
+* NULL if there's no current context.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+RIEGLThread* EGL::getCurrentThread() const
+{
+ void* currentThreadID = OSGetCurrentThreadID();
+ for(int i=0;i<m_currentThreads.size();i++)
+ {
+ if(currentThreadID == m_currentThreads[i]->getThreadID())
+ return m_currentThreads[i];
+ }
+ return NULL; //thread is not current
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief return an EGL thread struct corresponding to current OS thread.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+RIEGLThread* EGL::getThread()
+{
+ void* currentThreadID = OSGetCurrentThreadID();
+ for(int i=0;i<m_threads.size();i++)
+ {
+ if(currentThreadID == m_threads[i]->getThreadID())
+ return m_threads[i];
+ }
+
+ //EGL doesn't have a struct for the thread yet, add it to EGL's list
+ RIEGLThread* newThread = NULL;
+ try
+ {
+ newThread = RI_NEW(RIEGLThread, (OSGetCurrentThreadID())); //throws bad_alloc
+ m_threads.push_back(newThread); //throws bad_alloc
+ return newThread;
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(newThread);
+ return NULL;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief destroy an EGL thread struct
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void EGL::destroyThread()
+{
+ void* currentThreadID = OSGetCurrentThreadID();
+ for(int i=0;i<m_threads.size();i++)
+ {
+ if(currentThreadID == m_threads[i]->getThreadID())
+ {
+ RIEGLThread* thread = m_threads[i];
+ bool res = m_threads.remove(thread);
+ RI_ASSERT(res);
+ RI_UNREF(res);
+ RI_DELETE(thread);
+ break;
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool EGL::isInUse(const void* image) const
+{
+ for(int i=0;i<m_currentThreads.size();i++)
+ {
+ RIEGLSurface* s = m_currentThreads[i]->getCurrentSurface();
+ if(s && s->getDrawable() && s->getDrawable()->isInUse((Image*)image))
+ return true;
+ }
+ return false;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+#define EGL_GET_DISPLAY(DISPLAY, RETVAL) \
+ OSAcquireMutex(); \
+ EGL* egl = getEGL(); \
+ if(!egl) \
+ { \
+ OSReleaseMutex(); \
+ return RETVAL; \
+ } \
+ RIEGLDisplay* display = egl->getDisplay(DISPLAY); \
+
+#define EGL_GET_EGL(RETVAL) \
+ OSAcquireMutex(); \
+ EGL* egl = getEGL(); \
+ if(!egl) \
+ { \
+ OSReleaseMutex(); \
+ return RETVAL; \
+ } \
+
+#define EGL_IF_ERROR(COND, ERRORCODE, RETVAL) \
+ if(COND) { eglSetError(egl, ERRORCODE); OSReleaseMutex(); return RETVAL; } \
+
+#define EGL_RETURN(ERRORCODE, RETVAL) \
+ { \
+ eglSetError(egl, ERRORCODE); \
+ OSReleaseMutex(); \
+ return RETVAL; \
+ }
+
+// Note: egl error handling model differs from OpenVG. The latest error is stored instead of the oldest one.
+static void eglSetError(EGL* egl, EGLint error)
+{
+ RIEGLThread* thread = egl->getThread();
+ if(thread)
+ thread->setError(error);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns the OpenVG context current to the calling thread.
+* \param
+* \return
+* \note This function is always called from a mutexed API function
+*//*-------------------------------------------------------------------*/
+
+void* eglvgGetCurrentVGContext(void)
+{
+ EGL* egl = getEGL();
+ if(egl)
+ {
+ RIEGLThread* thread = egl->getCurrentThread();
+ if(thread)
+ {
+ RI_ASSERT(thread->getCurrentContext() && thread->getCurrentSurface());
+ return thread->getCurrentContext()->getVGContext();
+ }
+ }
+ return NULL; //not initialized or made current
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Check if the image is current in any of the displays
+* \param
+* \return
+* \note This function is always called from a mutexed API function
+*//*-------------------------------------------------------------------*/
+
+bool eglvgIsInUse(void* image)
+{
+ EGL* egl = getEGL();
+ if(egl)
+ {
+ return egl->isInUse(image);
+ }
+ return false;
+}
+
+//==============================================================================================
+
+} //namespace OpenVGRI
+
+using namespace OpenVGRI;
+
+
+
+
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLint eglGetError()
+{
+ OSAcquireMutex();
+ EGLint ret = EGL_SUCCESS;
+ EGL* egl = getEGL();
+ if(egl)
+ {
+ RIEGLThread* thread = egl->getThread();
+ if(thread)
+ ret = thread->getError(); //initialized, return error code
+ }
+ else ret = EGL_NOT_INITIALIZED;
+ OSReleaseMutex();
+ return ret;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id)
+{
+ return OSGetDisplay(display_id);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(display, EGL_SUCCESS, EGL_TRUE); //already initialized
+
+ //create the current display
+ //if a context and a surface are bound by the time of eglTerminate, they remain bound until eglMakeCurrent is called
+ RIEGLDisplay* newDisplay = NULL;
+ try
+ {
+ newDisplay = RI_NEW(RIEGLDisplay, (dpy)); //throws bad_alloc
+ egl->addDisplay(newDisplay); //throws bad_alloc
+ display = newDisplay;
+ RI_ASSERT(display);
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(newDisplay);
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
+ }
+
+ if(major) *major = 1;
+ if(minor) *minor = 2;
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglTerminate(EGLDisplay dpy)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_SUCCESS, EGL_TRUE);
+ egl->removeDisplay(display);
+ RI_DELETE(display);
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+const char *eglQueryString(EGLDisplay dpy, EGLint name)
+{
+ EGL_GET_DISPLAY(dpy, NULL);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, NULL);
+
+ static const char apis[] = "OpenVG";
+ static const char extensions[] = "";
+ static const char vendor[] = "Khronos Group";
+ static const char version[] = "1.3";
+
+ const char* ret = NULL;
+ switch(name)
+ {
+ case EGL_CLIENT_APIS:
+ ret = apis;
+ break;
+
+ case EGL_EXTENSIONS:
+ ret = extensions;
+ break;
+
+ case EGL_VENDOR:
+ ret = vendor;
+ break;
+
+ case EGL_VERSION:
+ ret = version;
+ break;
+
+ default:
+ EGL_RETURN(EGL_BAD_PARAMETER, NULL);
+ }
+ EGL_RETURN(EGL_SUCCESS, ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!num_config, EGL_BAD_PARAMETER, EGL_FALSE);
+ if(!configs)
+ {
+ *num_config = display->getNumConfigs();
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+ }
+ *num_config = RI_INT_MIN(config_size, display->getNumConfigs());
+ for(int i=0;i<*num_config;i++)
+ configs[i] = display->getConfig(i).m_config;
+
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static bool smaller(EGLint c, EGLint filter)
+{
+ return (filter != EGL_DONT_CARE) && (c < filter);
+}
+
+EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!num_config, EGL_BAD_PARAMETER, EGL_FALSE);
+
+ if(!configs)
+ {
+ *num_config = display->getNumConfigs();
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+ }
+ *num_config = 0;
+ if(!config_size)
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+
+ int bufferSize = 0;
+ int redSize = 0;
+ int greenSize = 0;
+ int blueSize = 0;
+ int luminanceSize = 0;
+ int alphaSize = 0;
+ int colorBufferType = EGL_RGB_BUFFER;
+ int configID = EGL_DONT_CARE;
+ int sampleBuffers = 0;
+ int samples = 0;
+ if(attrib_list)
+ {
+ for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
+ {
+ switch(attrib_list[i])
+ {
+ case EGL_BUFFER_SIZE: //depth of the color buffer
+ bufferSize = attrib_list[i+1];
+ break;
+ case EGL_RED_SIZE: //bits of Red in the color buffer
+ redSize = attrib_list[i+1];
+ break;
+ case EGL_GREEN_SIZE: //bits of Green in the color buffer
+ greenSize = attrib_list[i+1];
+ break;
+ case EGL_BLUE_SIZE: //bits of Blue in the color buffer
+ blueSize = attrib_list[i+1];
+ break;
+ case EGL_LUMINANCE_SIZE: //bits of Luminance in the color buffer
+ luminanceSize = attrib_list[i+1];
+ break;
+ case EGL_ALPHA_SIZE: //bits of Alpha in the color buffer
+ alphaSize = attrib_list[i+1];
+ break;
+ case EGL_ALPHA_MASK_SIZE: //bits of Alpha in the alpha mask buffer
+ if(attrib_list[i+1] > 8)
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE); //not supported
+ break;
+ case EGL_COLOR_BUFFER_TYPE: //enum color buffer type (EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER)
+ EGL_IF_ERROR(attrib_list[i+1] != EGL_RGB_BUFFER && attrib_list[i+1] != EGL_LUMINANCE_BUFFER && attrib_list[i+1] != EGL_DONT_CARE, EGL_BAD_ATTRIBUTE, EGL_FALSE);
+ colorBufferType = attrib_list[i+1];
+ break;
+ case EGL_CONFIG_ID: //unique EGLConfig identifier
+ configID = attrib_list[i+1];
+ break;
+
+ case EGL_SAMPLE_BUFFERS: //integer number of multisample buffers
+ sampleBuffers = attrib_list[i+1];
+ break;
+ case EGL_SAMPLES: //integer number of samples per pixel
+ samples = attrib_list[i+1];
+ break;
+
+ case EGL_BIND_TO_TEXTURE_RGB: //boolean True if bindable to RGB textures. (always EGL_FALSE)
+ case EGL_BIND_TO_TEXTURE_RGBA: //boolean True if bindable to RGBA textures. (always EGL_FALSE)
+ case EGL_DEPTH_SIZE: //integer bits of Z in the depth buffer (always 0)
+ case EGL_LEVEL: //integer frame buffer level (always 0)
+ case EGL_NATIVE_RENDERABLE: //boolean EGL TRUE if native rendering APIs can render to surface (always EGL_FALSE)
+ case EGL_STENCIL_SIZE: //integer bits of Stencil in the stencil buffer (always 0)
+ if(attrib_list[i+1])
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE); //not supported
+ break;
+
+ case EGL_CONFIG_CAVEAT: //enum any caveats for the configuration (always EGL_NONE)
+ case EGL_NATIVE_VISUAL_TYPE: //integer native visual type of the associated visual (always EGL_NONE)
+ if(attrib_list[i+1] != EGL_NONE)
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE); //not supported
+ break;
+
+ case EGL_MAX_SWAP_INTERVAL: //integer maximum swap interval (always 1)
+ case EGL_MIN_SWAP_INTERVAL: //integer minimum swap interval (always 1)
+ if(attrib_list[i+1] != 1)
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE); //not supported
+ break;
+
+ case EGL_RENDERABLE_TYPE: //bitmask which client rendering APIs are supported. (always EGL_OPENVG_BIT)
+ if(!(attrib_list[i+1] & EGL_OPENVG_BIT))
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE); //not supported
+ break;
+
+ case EGL_SURFACE_TYPE: //bitmask which types of EGL surfaces are supported. (always EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | EGL_VG_COLORSPACE_LINEAR_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT)
+ break; //all types are always supported
+
+ case EGL_TRANSPARENT_TYPE: //enum type of transparency supported (always EGL_NONE)
+ case EGL_NATIVE_VISUAL_ID: //integer handle of corresponding native visual (always 0)
+ case EGL_MAX_PBUFFER_WIDTH: //integer maximum width of pbuffer (always INT_MAX)
+ case EGL_MAX_PBUFFER_HEIGHT: //integer maximum height of pbuffer (always INT_MAX)
+ case EGL_MAX_PBUFFER_PIXELS: //integer maximum size of pbuffer (always INT_MAX)
+ case EGL_TRANSPARENT_RED_VALUE: //integer transparent red value (undefined)
+ case EGL_TRANSPARENT_GREEN_VALUE: //integer transparent green value (undefined)
+ case EGL_TRANSPARENT_BLUE_VALUE: //integer transparent blue value (undefined)
+ break; //ignored
+
+ default:
+ EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE); //unknown attribute
+ }
+ }
+ }
+
+ if(configID && configID != EGL_DONT_CARE)
+ { //if CONFIG_ID is defined, ignore the rest of the attribs
+ for(int i=0;i<EGL_NUMCONFIGS;i++)
+ {
+ if(display->getConfig(i).m_configID == configID)
+ {
+ *num_config = 1;
+ *configs = display->getConfig(i).m_config;
+ }
+ }
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+ }
+
+ //go through all configs, add passed configs to return list
+ //TODO take alpha mask size into account
+ EGLConfig found[EGL_NUMCONFIGS];
+ int keys[EGL_NUMCONFIGS];
+ int numFound = 0;
+ for(int i=0;i<display->getNumConfigs();i++)
+ {
+ const RIEGLConfig& c = display->getConfig(i);
+
+ int colorBits = c.m_desc.redBits + c.m_desc.greenBits + c.m_desc.blueBits;
+ int luminanceBits = c.m_desc.luminanceBits;
+ int configBufferSize;
+ if(colorBits)
+ {
+ RI_ASSERT(!luminanceBits);
+ colorBits += c.m_desc.alphaBits;
+ configBufferSize = colorBits;
+ }
+ else if(luminanceBits)
+ {
+ luminanceBits += c.m_desc.alphaBits;
+ configBufferSize = luminanceBits;
+ }
+ else
+ { //alpha only surface
+ colorBits = c.m_desc.alphaBits;
+ luminanceBits = c.m_desc.alphaBits;
+ configBufferSize = colorBits;
+ }
+
+ if (smaller(configBufferSize, bufferSize))
+ continue;
+
+ int configSampleBuffers = c.m_samples == 1 ? 0 : 1;
+ if (smaller(configSampleBuffers, sampleBuffers))
+ continue;
+ if (smaller(c.m_samples, samples))
+ continue;
+
+ if (smaller(c.m_desc.redBits, redSize)
+ || smaller(c.m_desc.greenBits, greenSize)
+ || smaller(c.m_desc.blueBits, blueSize)
+ || smaller(c.m_desc.alphaBits, alphaSize) )
+ continue;
+
+ if (smaller(c.m_desc.luminanceBits, luminanceSize))
+ continue;
+
+ if ((colorBufferType == EGL_RGB_BUFFER && !colorBits) ||
+ (colorBufferType == EGL_LUMINANCE_BUFFER && !luminanceBits))
+ continue;
+
+ int sortKey = c.m_configID; //sort from smaller to larger
+ int sortBits = 0;
+ if(redSize != 0 && redSize != EGL_DONT_CARE)
+ sortBits += c.m_desc.redBits;
+ if(greenSize != 0 && greenSize != EGL_DONT_CARE)
+ sortBits += c.m_desc.greenBits;
+ if(blueSize != 0 && blueSize != EGL_DONT_CARE)
+ sortBits += c.m_desc.blueBits;
+ if(alphaSize != 0 && alphaSize != EGL_DONT_CARE)
+ sortBits += c.m_desc.alphaBits;
+ if(luminanceSize != 0 && luminanceSize != EGL_DONT_CARE)
+ sortBits += c.m_desc.luminanceBits;
+ RI_ASSERT(c.m_configID <= EGL_NUMCONFIGS); //if there are more configs, increase the shift value
+ RI_ASSERT(sortBits <= 32);
+ sortKey += (32-sortBits) << 4; //sort from larger to smaller
+
+ found[numFound] = c.m_config;
+ keys[numFound++] = sortKey;
+ }
+ if(!numFound)
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+
+ //sort return list into increasing order
+ for(int e=0;e<numFound-1;e++)
+ {
+ for(int f=e+1;f<numFound;f++)
+ {
+ if(keys[e] > keys[f])
+ {
+ EGLConfig tmp = found[e];
+ found[e] = found[f];
+ found[f] = tmp;
+ RI_INT_SWAP(keys[e], keys[f]);
+ }
+ }
+ }
+
+ //write configs into return array
+ numFound = RI_INT_MIN(numFound, config_size);
+ for(int i=0;i<numFound;i++)
+ {
+ configs[i] = found[i];
+ }
+ *num_config = numFound;
+
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_FALSE);
+ const RIEGLConfig& c = display->getConfig(config);
+ switch(attribute)
+ {
+ case EGL_BUFFER_SIZE:
+ *value = RI_INT_MAX(c.m_desc.redBits + c.m_desc.greenBits + c.m_desc.blueBits + c.m_desc.alphaBits, c.m_desc.luminanceBits + c.m_desc.alphaBits);
+ break;
+
+ case EGL_RED_SIZE:
+ *value = c.m_desc.redBits;
+ break;
+
+ case EGL_GREEN_SIZE:
+ *value = c.m_desc.greenBits;
+ break;
+
+ case EGL_BLUE_SIZE:
+ *value = c.m_desc.blueBits;
+ break;
+
+ case EGL_LUMINANCE_SIZE:
+ *value = c.m_desc.luminanceBits;
+ break;
+
+ case EGL_ALPHA_SIZE:
+ *value = c.m_desc.alphaBits;
+ break;
+
+ case EGL_ALPHA_MASK_SIZE:
+ *value = c.m_maskBits;
+ break;
+
+ case EGL_BIND_TO_TEXTURE_RGB:
+ case EGL_BIND_TO_TEXTURE_RGBA:
+ *value = EGL_FALSE;
+ break;
+
+ case EGL_COLOR_BUFFER_TYPE:
+ if(c.m_desc.redBits)
+ *value = EGL_RGB_BUFFER;
+ else
+ *value = EGL_LUMINANCE_BUFFER;
+ break;
+
+ case EGL_CONFIG_CAVEAT:
+ *value = EGL_NONE;
+ break;
+
+ case EGL_CONFIG_ID:
+ *value = c.m_configID;
+ break;
+
+ case EGL_DEPTH_SIZE:
+ *value = 0;
+ break;
+
+ case EGL_LEVEL:
+ *value = 0;
+ break;
+
+ case EGL_MAX_PBUFFER_WIDTH:
+ case EGL_MAX_PBUFFER_HEIGHT:
+ *value = 16384; //NOTE arbitrary maximum
+ break;
+
+ case EGL_MAX_PBUFFER_PIXELS:
+ *value = 16384*16384; //NOTE arbitrary maximum
+ break;
+
+ case EGL_MAX_SWAP_INTERVAL:
+ case EGL_MIN_SWAP_INTERVAL:
+ *value = 1;
+ break;
+
+ case EGL_NATIVE_RENDERABLE:
+ *value = EGL_FALSE;
+ break;
+
+ case EGL_NATIVE_VISUAL_ID:
+ *value = 0;
+ break;
+
+ case EGL_NATIVE_VISUAL_TYPE:
+ *value = EGL_NONE;
+ break;
+
+ case EGL_RENDERABLE_TYPE:
+ *value = EGL_OPENVG_BIT;
+ break;
+
+ case EGL_SAMPLE_BUFFERS:
+ *value = c.m_samples > 1 ? 1 : 0;
+ break;
+
+ case EGL_SAMPLES:
+ *value = c.m_samples > 1 ? c.m_samples : 0;
+ break;
+
+ case EGL_STENCIL_SIZE:
+ *value = 0;
+ break;
+
+ case EGL_SURFACE_TYPE:
+ *value = EGL_WINDOW_BIT | EGL_PIXMAP_BIT | EGL_PBUFFER_BIT | EGL_VG_COLORSPACE_LINEAR_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT;
+ break;
+
+ case EGL_TRANSPARENT_TYPE:
+ *value = EGL_NONE;
+ break;
+
+ case EGL_TRANSPARENT_RED_VALUE:
+ case EGL_TRANSPARENT_GREEN_VALUE:
+ case EGL_TRANSPARENT_BLUE_VALUE:
+ *value = 0;
+ break;
+
+ case EGL_CONFORMANT:
+ *value = EGL_OPENVG_BIT; //TODO return proper value
+ break;
+
+ default:
+ EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE);
+ }
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
+{
+ EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
+ EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
+
+ int renderBuffer = EGL_BACK_BUFFER;
+ int colorSpace = EGL_VG_COLORSPACE_sRGB;
+ int alphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
+ if(attrib_list)
+ {
+ for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
+ {
+ switch(attrib_list[i])
+ {
+ case EGL_RENDER_BUFFER:
+ renderBuffer = attrib_list[i+1];
+ break;
+
+ case EGL_VG_COLORSPACE:
+ colorSpace = attrib_list[i+1];
+ break;
+
+ case EGL_VG_ALPHA_FORMAT:
+ alphaFormat = attrib_list[i+1];
+ break;
+
+ default:
+ EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
+ }
+ }
+ }
+ //we ignore the renderBuffer parameter since we can only render to double buffered surfaces
+
+ //TODO If the attributes of win do not correspond to config, then an EGL BAD MATCH error is generated.
+ //TODO If there is already an EGLConfig associated with win (as a result of a previous eglCreateWindowSurface call), then an EGL BAD ALLOC error is generated
+
+ void* wc = NULL;
+ Drawable* d = NULL;
+ RIEGLSurface* s = NULL;
+ try
+ {
+ wc = OSCreateWindowContext(win);
+ RI_ASSERT(wc);
+ //TODO what should happen if window width or height is zero?
+ int windowWidth = 0, windowHeight = 0;
+ OSGetWindowSize(wc, windowWidth, windowHeight);
+ bool isWindow = OSIsWindow(wc);
+ if(windowWidth <= 0 || windowHeight <= 0 || !isWindow)
+ {
+ OSDestroyWindowContext(wc);
+ EGL_IF_ERROR(!isWindow, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
+ EGL_IF_ERROR(windowWidth <= 0 || windowHeight <= 0, EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE);
+ }
+ d = RI_NEW(Drawable, (display->getConfig(config).configToDescriptor((colorSpace == EGL_VG_COLORSPACE_LINEAR) ? false : true, (alphaFormat == EGL_VG_ALPHA_FORMAT_PRE) ? true : false), windowWidth, windowHeight, display->getConfig(config).m_samples, display->getConfig(config).m_maskBits)); //throws bad_alloc
+ RI_ASSERT(d);
+ s = RI_NEW(RIEGLSurface,(wc, config, d, false, renderBuffer)); //throws bad_alloc
+ RI_ASSERT(s);
+ s->addReference();
+ display->addSurface(s); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ OSDestroyWindowContext(wc);
+ RI_DELETE(d);
+ RI_DELETE(s);
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
+ }
+ EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
+{
+ EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
+ EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
+
+ int width = 0, height = 0;
+ bool largestPbuffer = false;
+ int colorSpace = EGL_VG_COLORSPACE_sRGB;
+ int alphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
+ if(attrib_list)
+ {
+ for(int i=0;attrib_list[i] != EGL_NONE;i+=2)
+ {
+ switch(attrib_list[i])
+ {
+ case EGL_WIDTH:
+ width = attrib_list[i+1];
+ break;
+
+ case EGL_HEIGHT:
+ height = attrib_list[i+1];
+ break;
+
+ case EGL_LARGEST_PBUFFER:
+ largestPbuffer = attrib_list[i+1] ? true : false;
+ break;
+
+ case EGL_VG_COLORSPACE:
+ colorSpace = attrib_list[i+1];
+ break;
+
+ case EGL_VG_ALPHA_FORMAT:
+ alphaFormat = attrib_list[i+1];
+ break;
+
+ case EGL_TEXTURE_FORMAT: //config doesn't support OpenGL ES
+ case EGL_TEXTURE_TARGET: //config doesn't support OpenGL ES
+ case EGL_MIPMAP_TEXTURE: //config doesn't support OpenGL ES
+ default:
+ EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
+ break;
+ }
+ }
+ }
+ EGL_IF_ERROR(width <= 0 || height <= 0, EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE);
+
+ Drawable* d = NULL;
+ RIEGLSurface* s = NULL;
+ try
+ {
+ d = RI_NEW(Drawable, (display->getConfig(config).configToDescriptor((colorSpace == EGL_VG_COLORSPACE_LINEAR) ? false : true, (alphaFormat == EGL_VG_ALPHA_FORMAT_PRE) ? true : false), width, height, display->getConfig(config).m_samples, display->getConfig(config).m_maskBits)); //throws bad_alloc
+ RI_ASSERT(d);
+ s = RI_NEW(RIEGLSurface,(NULL, config, d, largestPbuffer, EGL_BACK_BUFFER)); //throws bad_alloc
+ RI_ASSERT(s);
+ s->addReference();
+ display->addSurface(s); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(d);
+ RI_DELETE(s);
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
+ }
+ EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
+{
+ EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
+ EGL_IF_ERROR(buftype != EGL_OPENVG_IMAGE, EGL_BAD_PARAMETER, EGL_NO_SURFACE);
+ EGL_IF_ERROR(!buffer, EGL_BAD_PARAMETER, EGL_NO_SURFACE); //TODO should also check if buffer really is a valid VGImage object (needs VG context for that)
+ Image* image = (Image*)buffer;
+ EGL_IF_ERROR(image->isInUse(), EGL_BAD_ACCESS, EGL_NO_SURFACE); //buffer is in use by OpenVG
+ EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
+ EGL_IF_ERROR(attrib_list && attrib_list[0] != EGL_NONE, EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); //there are no valid attribs for OpenVG
+ const Color::Descriptor& bc = ((Image*)buffer)->getDescriptor();
+ const Color::Descriptor& cc = display->getConfig(config).m_desc;
+ EGL_IF_ERROR(bc.redBits != cc.redBits || bc.greenBits != cc.greenBits || bc.blueBits != cc.blueBits ||
+ bc.alphaBits != cc.alphaBits || bc.luminanceBits != cc.luminanceBits, EGL_BAD_MATCH, EGL_NO_SURFACE);
+
+ //TODO If buffer is already bound to another pbuffer, an EGL BAD ACCESS error is generated.
+
+ Drawable* d = NULL;
+ RIEGLSurface* s = NULL;
+ try
+ {
+ d = RI_NEW(Drawable, (image, display->getConfig(config).m_maskBits));
+ RI_ASSERT(d);
+ s = RI_NEW(RIEGLSurface,(NULL, config, d, false, EGL_BACK_BUFFER)); //throws bad_alloc
+ RI_ASSERT(s);
+ s->addReference();
+ display->addSurface(s); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(d);
+ RI_DELETE(s);
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
+ }
+ EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLSurface eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list)
+{
+ EGL_GET_DISPLAY(dpy, EGL_NO_SURFACE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_SURFACE);
+ EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_SURFACE);
+ EGL_IF_ERROR(!pixmap || !isValidImageFormat(pixmap->format) || !pixmap->data || pixmap->width <= 0 || pixmap->height <= 0, EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE);
+ RI_UNREF(attrib_list);
+ EGL_IF_ERROR(display->getConfig(config).m_samples != 1, EGL_BAD_MATCH, EGL_NO_SURFACE);
+
+ //TODO If there is already an EGLSurface associated with pixmap (as a result of a previous eglCreatePixmapSurface call), then a EGL BAD ALLOC error is generated.
+
+ Drawable* d = NULL;
+ RIEGLSurface* s = NULL;
+ try
+ {
+ d = RI_NEW(Drawable, (Color::formatToDescriptor((VGImageFormat)pixmap->format), pixmap->width, pixmap->height, pixmap->stride, (RIuint8*)pixmap->data, display->getConfig(config).m_maskBits)); //throws bad_alloc
+ RI_ASSERT(d);
+ s = RI_NEW(RIEGLSurface,(NULL, config, d, false, EGL_BACK_BUFFER)); //throws bad_alloc
+ RI_ASSERT(s);
+ s->addReference();
+ display->addSurface(s); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(d);
+ RI_DELETE(s);
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_SURFACE);
+ }
+ EGL_RETURN(EGL_SUCCESS, (EGLSurface)s);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
+
+ display->removeSurface((RIEGLSurface*)surface);
+ if(!((RIEGLSurface*)surface)->removeReference())
+ RI_DELETE((RIEGLSurface*)surface);
+
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
+ RI_UNREF(attribute);
+ RI_UNREF(value);
+ //do nothing
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
+ //TODO give an error if value is NULL?
+
+ RIEGLSurface* s = (RIEGLSurface*)surface;
+ switch(attribute)
+ {
+ case EGL_VG_ALPHA_FORMAT:
+ *value = (s->getDrawable()->getDescriptor().isPremultiplied()) ? EGL_VG_ALPHA_FORMAT_PRE : EGL_VG_ALPHA_FORMAT_NONPRE;
+ break;
+
+ case EGL_VG_COLORSPACE:
+ *value = (s->getDrawable()->getDescriptor().isNonlinear()) ? EGL_VG_COLORSPACE_sRGB : EGL_VG_COLORSPACE_LINEAR;
+ break;
+
+ case EGL_CONFIG_ID:
+ *value = display->getConfig(s->getConfig()).m_configID;
+ break;
+
+ case EGL_HEIGHT:
+ *value = s->getDrawable()->getHeight();
+ break;
+
+ case EGL_HORIZONTAL_RESOLUTION:
+ *value = EGL_UNKNOWN; //TODO Horizontal dot pitch
+ break;
+
+ case EGL_LARGEST_PBUFFER:
+ if(!s->getOSWindowContext())
+ *value = s->isLargestPbuffer() ? EGL_TRUE : EGL_FALSE;
+ break;
+
+ case EGL_MIPMAP_TEXTURE:
+ if(!s->getOSWindowContext())
+ *value = EGL_FALSE;
+ break;
+
+ case EGL_MIPMAP_LEVEL:
+ if(!s->getOSWindowContext())
+ *value = 0;
+ break;
+
+ case EGL_PIXEL_ASPECT_RATIO:
+ *value = EGL_UNKNOWN; //TODO Display aspect ratio
+ break;
+
+ case EGL_RENDER_BUFFER:
+ *value = s->getRenderBuffer();
+ break;
+
+ case EGL_SWAP_BEHAVIOR:
+ *value = EGL_BUFFER_PRESERVED;
+ break;
+
+ case EGL_TEXTURE_FORMAT:
+ if(!s->getOSWindowContext())
+ *value = EGL_NO_TEXTURE;
+ break;
+
+ case EGL_TEXTURE_TARGET:
+ if(!s->getOSWindowContext())
+ *value = EGL_NO_TEXTURE;
+ break;
+
+ case EGL_VERTICAL_RESOLUTION:
+ *value = EGL_UNKNOWN; //TODO Vertical dot pitch
+ break;
+
+ case EGL_WIDTH:
+ *value = s->getDrawable()->getWidth();
+ break;
+
+ default:
+ EGL_RETURN(EGL_BAD_ATTRIBUTE, EGL_FALSE);
+ }
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
+{
+ EGL_GET_DISPLAY(dpy, EGL_NO_CONTEXT);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_NO_CONTEXT);
+ EGL_IF_ERROR(!display->configExists(config), EGL_BAD_CONFIG, EGL_NO_CONTEXT);
+ RI_UNREF(attrib_list);
+
+ RIEGLThread* thread = egl->getThread();
+ if(!thread)
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
+
+ //creation of OpenGL ES contexts is not allowed in this implementation
+ if(thread->getBoundAPI() != EGL_OPENVG_API)
+ EGL_RETURN(EGL_BAD_MATCH, EGL_NO_CONTEXT);
+
+ OpenVGRI::VGContext* vgctx = NULL;
+ RIEGLContext* c = NULL;
+ try
+ {
+ vgctx = RI_NEW(OpenVGRI::VGContext, (share_context ? ((RIEGLContext*)share_context)->getVGContext() : NULL)); //throws bad_alloc
+ c = RI_NEW(RIEGLContext, (vgctx, config)); //throws bad_alloc
+ c->addReference();
+ display->addContext(c); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ RI_DELETE(vgctx);
+ RI_DELETE(c);
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
+ }
+
+ EGL_RETURN(EGL_SUCCESS, (EGLContext)c);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
+
+ RIEGLContext* context = (RIEGLContext*)ctx;
+ display->removeContext(context);
+ if(!context->removeReference() )
+ RI_DELETE(context);
+
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(ctx != EGL_NO_CONTEXT && !display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
+ EGL_IF_ERROR(draw != EGL_NO_SURFACE && !display->surfaceExists(draw), EGL_BAD_SURFACE, EGL_FALSE);
+ EGL_IF_ERROR(read != EGL_NO_SURFACE && !display->surfaceExists(read), EGL_BAD_SURFACE, EGL_FALSE);
+ EGL_IF_ERROR(draw != read, EGL_BAD_MATCH, EGL_FALSE); //TODO what's the proper error code?
+ EGL_IF_ERROR((draw != EGL_NO_SURFACE && ctx == EGL_NO_CONTEXT) || (draw == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT), EGL_BAD_MATCH, EGL_FALSE);
+
+ RIEGLSurface* s = NULL;
+ RIEGLContext* c = NULL;
+ if(draw != EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT)
+ {
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+
+ s = (RIEGLSurface*)draw;
+ c = (RIEGLContext*)ctx;
+
+ //If either draw or read are pbuffers created with eglCreatePbufferFromClientBuffer, and the underlying bound client API buffers
+ //are in use by the client API that created them, an EGL BAD ACCESS error is generated.
+ EGL_IF_ERROR(s->getDrawable()->isInUse(), EGL_BAD_ACCESS, EGL_FALSE);
+
+
+ //TODO properly check compatibility of surface and context:
+ //-both have RGB or LUMINANCE configs
+ //-buffer bit depths match
+ //-configs support OpenVG
+ //-both have the same display
+ EGL_IF_ERROR(s->getConfig() != c->getConfig(), EGL_BAD_MATCH, EGL_FALSE);
+ //TODO check if context or surfaces are already bound to another thread
+
+ //If a native window underlying either draw or read is no longer valid, an EGL BAD NATIVE WINDOW error is generated.
+ EGL_IF_ERROR(s->getOSWindowContext() && !OSIsWindow(s->getOSWindowContext()), EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
+
+ //TODO If the previous context of the calling display has unflushed commands, and the previous surface is no longer valid, an EGL BAD CURRENT SURFACE error is generated. (can this happen?)
+ //TODO If the ancillary buffers for draw and read cannot be allocated, an EGL BAD ALLOC error is generated. (mask buffer?)
+ }
+
+ //check if the thread is current
+ RIEGLThread* thread = egl->getCurrentThread();
+ if(thread)
+ { //thread is current, release the old bindinds and remove the thread from the current thread list
+ RIEGLContext* pc = thread->getCurrentContext();
+ RIEGLSurface* ps = thread->getCurrentSurface();
+ if(pc)
+ {
+ vgFlush();
+ pc->getVGContext()->setDefaultDrawable(NULL);
+ if(!pc->removeReference())
+ RI_DELETE(pc);
+ }
+ if(ps)
+ {
+ if(!ps->removeReference())
+ RI_DELETE(ps);
+ }
+
+ egl->removeCurrentThread(thread);
+ }
+
+ if( c && s )
+ {
+ //bind context and surface to the current display
+ RIEGLThread* newThread = egl->getThread();
+ if(!newThread)
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
+ newThread->makeCurrent(c, s);
+ c->getVGContext()->setDefaultDrawable(s->getDrawable());
+
+ try
+ {
+ egl->addCurrentThread(newThread); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
+ }
+
+ c->addReference();
+ s->addReference();
+ }
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLContext eglGetCurrentContext()
+{
+ EGL_GET_EGL(EGL_NO_CONTEXT);
+ EGLContext ret = EGL_NO_CONTEXT;
+ RIEGLThread* thread = egl->getCurrentThread();
+ if(thread && thread->getBoundAPI() == EGL_OPENVG_API)
+ {
+ ret = thread->getCurrentContext();
+ RI_ASSERT(ret);
+ }
+ EGL_RETURN(EGL_SUCCESS, ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLSurface eglGetCurrentSurface(EGLint readdraw)
+{
+ EGL_GET_EGL(EGL_NO_SURFACE);
+ EGL_IF_ERROR(readdraw != EGL_READ && readdraw != EGL_DRAW, EGL_BAD_PARAMETER, EGL_NO_SURFACE);
+ EGLContext ret = EGL_NO_SURFACE;
+ RIEGLThread* thread = egl->getCurrentThread();
+ if(thread && thread->getBoundAPI() == EGL_OPENVG_API)
+ {
+ ret = thread->getCurrentSurface();
+ RI_ASSERT(ret);
+ }
+ EGL_RETURN(EGL_SUCCESS, ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns the current display
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLDisplay eglGetCurrentDisplay(void)
+{
+ EGL_GET_EGL(EGL_NO_DISPLAY);
+
+ RIEGLThread* thread = egl->getCurrentThread();
+ if(!thread || thread->getBoundAPI() != EGL_OPENVG_API)
+ EGL_RETURN(EGL_SUCCESS, EGL_NO_DISPLAY);
+
+ RIEGLContext* ctx = thread->getCurrentContext();
+ RI_ASSERT(ctx);
+ EGLDisplay ret = egl->findDisplay(ctx);
+ EGL_RETURN(EGL_SUCCESS, ret);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglQueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!display->contextExists(ctx), EGL_BAD_CONTEXT, EGL_FALSE);
+ EGL_IF_ERROR(attribute != EGL_CONFIG_ID && attribute != EGL_CONTEXT_CLIENT_TYPE, EGL_BAD_ATTRIBUTE, EGL_FALSE);
+ if(attribute == EGL_CONFIG_ID)
+ *value = display->getConfig(((RIEGLContext*)ctx)->getConfig()).m_configID;
+ if(attribute == EGL_CONTEXT_CLIENT_TYPE)
+ *value = EGL_OPENVG_API;
+ // \todo [kalle 05/Jul/05] Handling of EGL_RENDER_BUFFER attribute is missing.
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglBindAPI(EGLenum api)
+{
+ EGL_GET_EGL(EGL_FALSE);
+ EGL_IF_ERROR(api != EGL_OPENVG_API && api != EGL_OPENGL_ES_API, EGL_BAD_PARAMETER, EGL_FALSE);
+ RIEGLThread* thread = egl->getThread();
+ if(thread)
+ thread->bindAPI(api);
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLenum eglQueryAPI(void)
+{
+ EGL_GET_EGL(EGL_NONE);
+ RIEGLThread* thread = egl->getThread();
+ if(thread)
+ EGL_RETURN(EGL_SUCCESS, thread->getBoundAPI());
+ EGL_RETURN(EGL_SUCCESS, EGL_NONE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglWaitClient()
+{
+ EGL_GET_EGL(EGL_FALSE);
+ RIEGLThread* thread = egl->getCurrentThread();
+ if(thread && thread->getBoundAPI() == EGL_OPENVG_API)
+ vgFinish();
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Waits for OpenGL ES
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglWaitGL(void)
+{
+ return EGL_TRUE;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note We don't support native rendering
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglWaitNative(EGLint engine)
+{
+ RI_UNREF(engine);
+ return EGL_TRUE;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
+
+ RIEGLSurface* s = (RIEGLSurface*)surface;
+
+ RIEGLThread* currentThread = egl->getCurrentThread();
+ EGL_IF_ERROR(!currentThread || currentThread->getCurrentSurface() != s, EGL_BAD_SURFACE, EGL_FALSE);
+ EGL_IF_ERROR(!OSIsWindow(s->getOSWindowContext()), EGL_BAD_NATIVE_WINDOW, EGL_FALSE);
+
+ vgFlush();
+
+ if(!s->getOSWindowContext())
+ { //do nothing for other than window surfaces (NOTE: single-buffered window surfaces should return immediately as well)
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+ }
+
+ int windowWidth = 0, windowHeight = 0;
+ OSGetWindowSize(s->getOSWindowContext(), windowWidth, windowHeight);
+
+ if(windowWidth != s->getDrawable()->getWidth() || windowHeight != s->getDrawable()->getHeight())
+ { //resize the back buffer
+ RIEGLContext* c = currentThread->getCurrentContext();
+ RI_ASSERT(c);
+ try
+ {
+ s->getDrawable()->resize(windowWidth, windowHeight); //throws bad_alloc
+ }
+ catch(std::bad_alloc)
+ {
+ c->getVGContext()->setDefaultDrawable(NULL);
+ EGL_RETURN(EGL_BAD_ALLOC, EGL_FALSE);
+ }
+ }
+
+ OSBlitToWindow(s->getOSWindowContext(), s->getDrawable());
+
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ EGL_IF_ERROR(!display->surfaceExists(surface), EGL_BAD_SURFACE, EGL_FALSE);
+ EGL_IF_ERROR(!target || !isValidImageFormat(target->format) || !target->data || target->width <= 0 || target->height <= 0, EGL_BAD_NATIVE_PIXMAP, EGL_FALSE);
+ try
+ {
+ Image output(Color::formatToDescriptor((VGImageFormat)target->format), target->width, target->height, target->stride, (RIuint8*)target->data);
+ output.addReference();
+ output.blit(((RIEGLSurface*)surface)->getDrawable()->getColorBuffer(), 0, 0, 0, 0, target->width, target->height); //throws bad_alloc
+ output.removeReference();
+ }
+ catch(std::bad_alloc)
+ {
+ }
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note We support only swap interval one
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval)
+{
+ EGL_GET_DISPLAY(dpy, EGL_FALSE);
+ EGL_IF_ERROR(!display, EGL_NOT_INITIALIZED, EGL_FALSE);
+ RI_UNREF(interval);
+ EGL_RETURN(EGL_SUCCESS, EGL_TRUE);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+typedef void RI_Proc();
+
+void (*eglGetProcAddress(const char *procname))()
+{
+ if(!procname)
+ return NULL;
+ return NULL;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+EGLBoolean eglReleaseThread(void)
+{
+ EGL_GET_EGL(EGL_FALSE);
+
+ //check if the thread is current
+ RIEGLThread* thread = egl->getCurrentThread();
+ if(thread)
+ { //thread is current, release the old bindings and remove the thread from the current thread list
+ RIEGLContext* pc = thread->getCurrentContext();
+ RIEGLSurface* ps = thread->getCurrentSurface();
+ if(pc)
+ {
+ vgFlush();
+ pc->getVGContext()->setDefaultDrawable(NULL);
+ if(!pc->removeReference())
+ RI_DELETE(pc);
+ }
+ if(ps)
+ {
+ if(!ps->removeReference())
+ RI_DELETE(ps);
+ }
+
+ egl->removeCurrentThread(thread);
+ }
+
+ //destroy EGL's thread struct
+ egl->destroyThread();
+
+ //destroy the EGL instance
+ releaseEGL();
+
+ OSReleaseMutex();
+ OSDeinitMutex();
+
+ return EGL_SUCCESS;
+}
+
+#undef EGL_NUMCONFIGS
diff --git a/ri/src/riPath.cpp b/ri/src/riPath.cpp
new file mode 100644
index 0000000..bf018f5
--- /dev/null
+++ b/ri/src/riPath.cpp
@@ -0,0 +1,2579 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Implementation of Path functions.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "riPath.h"
+
+//==============================================================================================
+
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+RIfloat inputFloat(VGfloat f); //defined in riApi.cpp
+
+/*-------------------------------------------------------------------*//*!
+* \brief Form a reliable normalized average of the two unit input vectors.
+* The average always lies to the given direction from the first
+* vector.
+* \param u0, u1 Unit input vectors.
+* \param cw True if the average should be clockwise from u0, false if
+* counterclockwise.
+* \return Average of the two input vectors.
+* \note
+*//*-------------------------------------------------------------------*/
+
+static const Vector2 unitAverage(const Vector2& u0, const Vector2& u1, bool cw)
+{
+ Vector2 u = 0.5f * (u0 + u1);
+ Vector2 n0 = perpendicularCCW(u0);
+
+ if( dot(u, u) > 0.25f )
+ { //the average is long enough and thus reliable
+ if( dot(n0, u1) < 0.0f )
+ u = -u; //choose the larger angle
+ }
+ else
+ { // the average is too short, use the average of the normals to the vectors instead
+ Vector2 n1 = perpendicularCW(u1);
+ u = 0.5f * (n0 + n1);
+ }
+ if( cw )
+ u = -u;
+
+ return normalize(u);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Form a reliable normalized average of the two unit input vectors.
+* The average lies on the side where the angle between the input
+* vectors is less than 180 degrees.
+* \param u0, u1 Unit input vectors.
+* \return Average of the two input vectors.
+* \note
+*//*-------------------------------------------------------------------*/
+
+static const Vector2 unitAverage(const Vector2& u0, const Vector2& u1)
+{
+ Vector2 u = 0.5f * (u0 + u1);
+
+ if( dot(u, u) < 0.25f )
+ { // the average is unreliable, use the average of the normals to the vectors instead
+ Vector2 n0 = perpendicularCCW(u0);
+ Vector2 n1 = perpendicularCW(u1);
+ u = 0.5f * (n0 + n1);
+ if( dot(n1, u0) < 0.0f )
+ u = -u;
+ }
+
+ return normalize(u);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Interpolate the given unit tangent vectors to the given
+* direction on a unit circle.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static const Vector2 circularLerp(const Vector2& t0, const Vector2& t1, RIfloat ratio, bool cw)
+{
+ Vector2 u0 = t0, u1 = t1;
+ RIfloat l0 = 0.0f, l1 = 1.0f;
+ for(int i=0;i<18;i++)
+ {
+ Vector2 n = unitAverage(u0, u1, cw);
+ RIfloat l = 0.5f * (l0 + l1);
+ if( ratio < l )
+ {
+ u1 = n;
+ l1 = l;
+ }
+ else
+ {
+ u0 = n;
+ l0 = l;
+ }
+ }
+ return u0;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Interpolate the given unit tangent vectors on a unit circle.
+* Smaller angle between the vectors is used.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static const Vector2 circularLerp(const Vector2& t0, const Vector2& t1, RIfloat ratio)
+{
+ Vector2 u0 = t0, u1 = t1;
+ RIfloat l0 = 0.0f, l1 = 1.0f;
+ for(int i=0;i<18;i++)
+ {
+ Vector2 n = unitAverage(u0, u1);
+ RIfloat l = 0.5f * (l0 + l1);
+ if( ratio < l )
+ {
+ u1 = n;
+ l1 = l;
+ }
+ else
+ {
+ u0 = n;
+ l0 = l;
+ }
+ }
+ return u0;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Path constructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Path::Path(VGint format, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int segmentCapacityHint, int coordCapacityHint, VGbitfield caps) :
+ m_format(format),
+ m_datatype(datatype),
+ m_scale(scale),
+ m_bias(bias),
+ m_capabilities(caps),
+ m_referenceCount(0),
+ m_segments(),
+ m_data(),
+ m_vertices(),
+ m_segmentToVertex(),
+ m_userMinx(0.0f),
+ m_userMiny(0.0f),
+ m_userMaxx(0.0f),
+ m_userMaxy(0.0f)
+{
+ RI_ASSERT(format == VG_PATH_FORMAT_STANDARD);
+ RI_ASSERT(datatype >= VG_PATH_DATATYPE_S_8 && datatype <= VG_PATH_DATATYPE_F);
+ if(segmentCapacityHint > 0)
+ m_segments.reserve(RI_INT_MIN(segmentCapacityHint, 65536));
+ if(coordCapacityHint > 0)
+ m_data.reserve(RI_INT_MIN(coordCapacityHint, 65536) * getBytesPerCoordinate(datatype));
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Path destructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Path::~Path()
+{
+ RI_ASSERT(m_referenceCount == 0);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Reads a coordinate and applies scale and bias.
+* \param
+* \return
+*//*-------------------------------------------------------------------*/
+
+RIfloat Path::getCoordinate(int i) const
+{
+ RI_ASSERT(i >= 0 && i < m_data.size() / getBytesPerCoordinate(m_datatype));
+ RI_ASSERT(m_scale != 0.0f);
+
+ const RIuint8* ptr = &m_data[0];
+ switch(m_datatype)
+ {
+ case VG_PATH_DATATYPE_S_8:
+ return (RIfloat)(((const RIint8*)ptr)[i]) * m_scale + m_bias;
+
+ case VG_PATH_DATATYPE_S_16:
+ return (RIfloat)(((const RIint16*)ptr)[i]) * m_scale + m_bias;
+
+ case VG_PATH_DATATYPE_S_32:
+ return (RIfloat)(((const RIint32*)ptr)[i]) * m_scale + m_bias;
+
+ default:
+ RI_ASSERT(m_datatype == VG_PATH_DATATYPE_F);
+ return (RIfloat)(((const RIfloat32*)ptr)[i]) * m_scale + m_bias;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Writes a coordinate, subtracting bias and dividing out scale.
+* \param
+* \return
+* \note If the coordinates do not fit into path datatype range, they
+* will overflow silently.
+*//*-------------------------------------------------------------------*/
+
+void Path::setCoordinate(Array<RIuint8>& data, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int i, RIfloat c)
+{
+ RI_ASSERT(i >= 0 && i < data.size()/getBytesPerCoordinate(datatype));
+ RI_ASSERT(scale != 0.0f);
+
+ c -= bias;
+ c /= scale;
+
+ RIuint8* ptr = &data[0];
+ switch(datatype)
+ {
+ case VG_PATH_DATATYPE_S_8:
+ ((RIint8*)ptr)[i] = (RIint8)floor(c + 0.5f); //add 0.5 for correct rounding
+ break;
+
+ case VG_PATH_DATATYPE_S_16:
+ ((RIint16*)ptr)[i] = (RIint16)floor(c + 0.5f); //add 0.5 for correct rounding
+ break;
+
+ case VG_PATH_DATATYPE_S_32:
+ ((RIint32*)ptr)[i] = (RIint32)floor(c + 0.5f); //add 0.5 for correct rounding
+ break;
+
+ default:
+ RI_ASSERT(datatype == VG_PATH_DATATYPE_F);
+ ((RIfloat32*)ptr)[i] = (RIfloat32)c;
+ break;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Given a datatype, returns the number of bytes per coordinate.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+int Path::getBytesPerCoordinate(VGPathDatatype datatype)
+{
+ if(datatype == VG_PATH_DATATYPE_S_8)
+ return 1;
+ if(datatype == VG_PATH_DATATYPE_S_16)
+ return 2;
+ RI_ASSERT(datatype == VG_PATH_DATATYPE_S_32 || datatype == VG_PATH_DATATYPE_F);
+ return 4;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Given a path segment type, returns the number of coordinates
+* it uses.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+int Path::segmentToNumCoordinates(VGPathSegment segment)
+{
+ RI_ASSERT(((int)segment >> 1) >= 0 && ((int)segment >> 1) <= 12);
+ static const int coords[13] = {0,2,2,1,1,4,6,2,4,5,5,5,5};
+ return coords[(int)segment >> 1];
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Computes the number of coordinates a segment sequence uses.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+int Path::countNumCoordinates(const RIuint8* segments, int numSegments)
+{
+ RI_ASSERT(segments);
+ RI_ASSERT(numSegments >= 0);
+
+ int coordinates = 0;
+ for(int i=0;i<numSegments;i++)
+ coordinates += segmentToNumCoordinates(getPathSegment(segments[i]));
+ return coordinates;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Clears path segments and data, and resets capabilities.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Path::clear(VGbitfield capabilities)
+{
+ m_segments.clear();
+ m_data.clear();
+ m_capabilities = capabilities;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Appends user segments and data.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+void Path::appendData(const RIuint8* segments, int numSegments, const RIuint8* data)
+{
+ RI_ASSERT(numSegments > 0);
+ RI_ASSERT(segments && data);
+ RI_ASSERT(m_referenceCount > 0);
+
+ //allocate new arrays
+ int oldSegmentsSize = m_segments.size();
+ int newSegmentsSize = oldSegmentsSize + numSegments;
+ Array<RIuint8> newSegments;
+ newSegments.resize(newSegmentsSize); //throws bad_alloc
+
+ int newCoords = countNumCoordinates(segments, numSegments);
+ int bytesPerCoordinate = getBytesPerCoordinate(m_datatype);
+ int newDataSize = m_data.size() + newCoords * bytesPerCoordinate;
+ Array<RIuint8> newData;
+ newData.resize(newDataSize); //throws bad_alloc
+ //if we get here, the memory allocations have succeeded
+
+ //copy old segments and append new ones
+ if(m_segments.size())
+ memcpy(&newSegments[0], &m_segments[0], m_segments.size());
+ memcpy(&newSegments[0] + m_segments.size(), segments, numSegments);
+
+ //copy old data and append new ones
+ if(newData.size())
+ {
+ if(m_data.size())
+ memcpy(&newData[0], &m_data[0], m_data.size());
+ if(m_datatype == VG_PATH_DATATYPE_F)
+ {
+ RIfloat32* d = (RIfloat32*)(&newData[0] + m_data.size());
+ const RIfloat32* s = (const RIfloat32*)data;
+ for(int i=0;i<newCoords;i++)
+ *d++ = (RIfloat32)inputFloat(*s++);
+ }
+ else
+ {
+ memcpy(&newData[0] + m_data.size(), data, newCoords * bytesPerCoordinate);
+ }
+ }
+
+ RI_ASSERT(newData.size() == countNumCoordinates(&newSegments[0],newSegments.size()) * getBytesPerCoordinate(m_datatype));
+
+ //replace old arrays
+ m_segments.swap(newSegments);
+ m_data.swap(newData);
+
+ int c = 0;
+ for(int i=0;i<m_segments.size();i++)
+ {
+ VGPathSegment segment = getPathSegment(m_segments[i]);
+ int coords = segmentToNumCoordinates(segment);
+ c += coords;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Appends a path.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+void Path::append(const Path* srcPath)
+{
+ RI_ASSERT(srcPath);
+ RI_ASSERT(m_referenceCount > 0 && srcPath->m_referenceCount > 0);
+
+ if(srcPath->m_segments.size())
+ {
+ //allocate new arrays
+ int newSegmentsSize = m_segments.size() + srcPath->m_segments.size();
+ Array<RIuint8> newSegments;
+ newSegments.resize(newSegmentsSize); //throws bad_alloc
+
+ int newDataSize = m_data.size() + srcPath->getNumCoordinates() * getBytesPerCoordinate(m_datatype);
+ Array<RIuint8> newData;
+ newData.resize(newDataSize); //throws bad_alloc
+ //if we get here, the memory allocations have succeeded
+
+ //copy old segments and append new ones
+ if(m_segments.size())
+ memcpy(&newSegments[0], &m_segments[0], m_segments.size());
+ if(srcPath->m_segments.size())
+ memcpy(&newSegments[0] + m_segments.size(), &srcPath->m_segments[0], srcPath->m_segments.size());
+
+ //copy old data and append new ones
+ if(m_data.size())
+ memcpy(&newData[0], &m_data[0], m_data.size());
+ for(int i=0;i<srcPath->getNumCoordinates();i++)
+ setCoordinate(newData, m_datatype, m_scale, m_bias, i + getNumCoordinates(), srcPath->getCoordinate(i));
+
+ RI_ASSERT(newData.size() == countNumCoordinates(&newSegments[0],newSegments.size()) * getBytesPerCoordinate(m_datatype));
+
+ //replace old arrays
+ m_segments.swap(newSegments);
+ m_data.swap(newData);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Modifies existing coordinate data.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Path::modifyCoords(int startIndex, int numSegments, const RIuint8* data)
+{
+ RI_ASSERT(numSegments > 0);
+ RI_ASSERT(startIndex >= 0 && startIndex + numSegments <= m_segments.size());
+ RI_ASSERT(data);
+ RI_ASSERT(m_referenceCount > 0);
+
+ int startCoord = countNumCoordinates(&m_segments[0], startIndex);
+ int numCoords = countNumCoordinates(&m_segments[startIndex], numSegments);
+ if(!numCoords)
+ return;
+ int bytesPerCoordinate = getBytesPerCoordinate(m_datatype);
+ RIuint8* dst = &m_data[startCoord * bytesPerCoordinate];
+ if(m_datatype == VG_PATH_DATATYPE_F)
+ {
+ RIfloat32* d = (RIfloat32*)dst;
+ const RIfloat32* s = (const RIfloat32*)data;
+ for(int i=0;i<numCoords;i++)
+ *d++ = (RIfloat32)inputFloat(*s++);
+ }
+ else
+ {
+ memcpy(dst, data, numCoords*bytesPerCoordinate);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Appends a transformed copy of the source path.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+void Path::transform(const Path* srcPath, const Matrix3x3& matrix)
+{
+ RI_ASSERT(srcPath);
+ RI_ASSERT(m_referenceCount > 0 && srcPath->m_referenceCount > 0);
+ RI_ASSERT(matrix.isAffine());
+
+ if(!srcPath->m_segments.size())
+ return;
+
+ //count the number of resulting coordinates
+ int numSrcCoords = 0;
+ int numDstCoords = 0;
+ for(int i=0;i<srcPath->m_segments.size();i++)
+ {
+ VGPathSegment segment = getPathSegment(srcPath->m_segments[i]);
+ int coords = segmentToNumCoordinates(segment);
+ numSrcCoords += coords;
+ if(segment == VG_HLINE_TO || segment == VG_VLINE_TO)
+ coords = 2; //convert hline and vline to lines
+ numDstCoords += coords;
+ }
+
+ //allocate new arrays
+ Array<RIuint8> newSegments;
+ newSegments.resize(m_segments.size() + srcPath->m_segments.size()); //throws bad_alloc
+ Array<RIuint8> newData;
+ newData.resize(m_data.size() + numDstCoords * getBytesPerCoordinate(m_datatype)); //throws bad_alloc
+ //if we get here, the memory allocations have succeeded
+
+ //copy old segments
+ if(m_segments.size())
+ memcpy(&newSegments[0], &m_segments[0], m_segments.size());
+
+ //copy old data
+ if(m_data.size())
+ memcpy(&newData[0], &m_data[0], m_data.size());
+
+ int srcCoord = 0;
+ int dstCoord = getNumCoordinates();
+ Vector2 s(0,0); //the beginning of the current subpath
+ Vector2 o(0,0); //the last point of the previous segment
+ for(int i=0;i<srcPath->m_segments.size();i++)
+ {
+ VGPathSegment segment = getPathSegment(srcPath->m_segments[i]);
+ VGPathAbsRel absRel = getPathAbsRel(srcPath->m_segments[i]);
+ int coords = segmentToNumCoordinates(segment);
+
+ switch(segment)
+ {
+ case VG_CLOSE_PATH:
+ {
+ RI_ASSERT(coords == 0);
+ o = s;
+ break;
+ }
+
+ case VG_MOVE_TO:
+ {
+ RI_ASSERT(coords == 2);
+ Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ Vector2 tc;
+
+ if (absRel == VG_ABSOLUTE)
+ tc = affineTransform(matrix, c);
+ else
+ {
+ tc = affineTangentTransform(matrix, c);
+ c += o;
+ }
+
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ s = c;
+ o = c;
+ break;
+ }
+
+ case VG_LINE_TO:
+ {
+ RI_ASSERT(coords == 2);
+ Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ Vector2 tc;
+
+ if (absRel == VG_ABSOLUTE)
+ tc = affineTransform(matrix, c);
+ else
+ {
+ tc = affineTangentTransform(matrix, c);
+ c += o;
+ }
+
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ o = c;
+ break;
+ }
+
+ case VG_HLINE_TO:
+ {
+ RI_ASSERT(coords == 1);
+ Vector2 c(srcPath->getCoordinate(srcCoord+0), 0);
+ Vector2 tc;
+
+ if (absRel == VG_ABSOLUTE)
+ {
+ c.y = o.y;
+ tc = affineTransform(matrix, c);
+ }
+ else
+ {
+ tc = affineTangentTransform(matrix, c);
+ c += o;
+ }
+
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ o = c;
+ segment = VG_LINE_TO;
+ break;
+ }
+
+ case VG_VLINE_TO:
+ {
+ RI_ASSERT(coords == 1);
+ Vector2 c(0, srcPath->getCoordinate(srcCoord+0));
+ Vector2 tc;
+
+ if (absRel == VG_ABSOLUTE)
+ {
+ c.x = o.x;
+ tc = affineTransform(matrix, c);
+ }
+ else
+ {
+ tc = affineTangentTransform(matrix, c);
+ c += o;
+ }
+
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ o = c;
+ segment = VG_LINE_TO;
+ break;
+ }
+
+ case VG_QUAD_TO:
+ {
+ RI_ASSERT(coords == 4);
+ Vector2 c0(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ Vector2 c1(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
+ Vector2 tc0, tc1;
+
+ if (absRel == VG_ABSOLUTE)
+ {
+ tc0 = affineTransform(matrix, c0);
+ tc1 = affineTransform(matrix, c1);
+ }
+ else
+ {
+ tc0 = affineTangentTransform(matrix, c0);
+ tc1 = affineTangentTransform(matrix, c1);
+ c1 += o;
+ }
+
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
+ o = c1;
+ break;
+ }
+
+ case VG_CUBIC_TO:
+ {
+ RI_ASSERT(coords == 6);
+ Vector2 c0(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ Vector2 c1(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
+ Vector2 c2(srcPath->getCoordinate(srcCoord+4), srcPath->getCoordinate(srcCoord+5));
+ Vector2 tc0, tc1, tc2;
+
+ if (absRel == VG_ABSOLUTE)
+ {
+ tc0 = affineTransform(matrix, c0);
+ tc1 = affineTransform(matrix, c1);
+ tc2 = affineTransform(matrix, c2);
+ }
+ else
+ {
+ tc0 = affineTangentTransform(matrix, c0);
+ tc1 = affineTangentTransform(matrix, c1);
+ tc2 = affineTangentTransform(matrix, c2);
+ c2 += o;
+ }
+
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc0.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.y);
+ o = c2;
+ break;
+ }
+
+ case VG_SQUAD_TO:
+ {
+ RI_ASSERT(coords == 2);
+ Vector2 c1(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ Vector2 tc1;
+
+ if (absRel == VG_ABSOLUTE)
+ tc1 = affineTransform(matrix, c1);
+ else
+ {
+ tc1 = affineTangentTransform(matrix, c1);
+ c1 += o;
+ }
+
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
+ o = c1;
+ break;
+ }
+
+ case VG_SCUBIC_TO:
+ {
+ RI_ASSERT(coords == 4);
+ Vector2 c1(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ Vector2 c2(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
+ Vector2 tc1, tc2;
+
+ if (absRel == VG_ABSOLUTE)
+ {
+ tc1 = affineTransform(matrix, c1);
+ tc2 = affineTransform(matrix, c2);
+ }
+ else
+ {
+ tc1 = affineTangentTransform(matrix, c1);
+ tc2 = affineTangentTransform(matrix, c2);
+ c2 += o;
+ }
+
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc1.y);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc2.y);
+ o = c2;
+ break;
+ }
+
+ default:
+ {
+ RI_ASSERT(segment == VG_SCCWARC_TO || segment == VG_SCWARC_TO ||
+ segment == VG_LCCWARC_TO || segment == VG_LCWARC_TO);
+ RI_ASSERT(coords == 5);
+ RIfloat rh = srcPath->getCoordinate(srcCoord+0);
+ RIfloat rv = srcPath->getCoordinate(srcCoord+1);
+ RIfloat rot = srcPath->getCoordinate(srcCoord+2);
+ Vector2 c(srcPath->getCoordinate(srcCoord+3), srcPath->getCoordinate(srcCoord+4));
+
+ rot = RI_DEG_TO_RAD(rot);
+ Matrix3x3 u((RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv, 0,
+ (RIfloat)sin(rot)*rh, (RIfloat)cos(rot)*rv, 0,
+ 0, 0, 1);
+ u = matrix * u;
+ u[2].set(0,0,1); //force affinity
+ //u maps from the unit circle to transformed ellipse
+
+ //compute new rh, rv and rot
+ Vector2 p(u[0][0], u[1][0]);
+ Vector2 q(u[1][1], -u[0][1]);
+ bool swapped = false;
+ if(dot(p,p) < dot(q,q))
+ {
+ RI_SWAP(p.x,q.x);
+ RI_SWAP(p.y,q.y);
+ swapped = true;
+ }
+ Vector2 h = (p+q) * 0.5f;
+ Vector2 hp = (p-q) * 0.5f;
+ RIfloat hlen = h.length();
+ RIfloat hplen = hp.length();
+ rh = hlen + hplen;
+ rv = hlen - hplen;
+ h = hplen * h + hlen * hp;
+ hlen = dot(h,h);
+ if(hlen == 0.0f)
+ rot = 0.0f;
+ else
+ {
+ h.normalize();
+ rot = (RIfloat)acos(h.x);
+ if(h.y < 0.0f)
+ rot = 2.0f*PI - rot;
+ }
+ if(swapped)
+ rot += PI*0.5f;
+
+ Vector2 tc;
+ if (absRel == VG_ABSOLUTE)
+ tc = affineTransform(matrix, c);
+ else
+ {
+ tc = affineTangentTransform(matrix, c);
+ c += o;
+ }
+
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, rh);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, rv);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, RI_RAD_TO_DEG(rot));
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.x);
+ setCoordinate(newData, m_datatype, m_scale, m_bias, dstCoord++, tc.y);
+ o = c;
+
+ //flip winding if the determinant is negative
+ if (matrix.det() < 0)
+ {
+ switch (segment)
+ {
+ case VG_SCCWARC_TO: segment = VG_SCWARC_TO; break;
+ case VG_SCWARC_TO: segment = VG_SCCWARC_TO; break;
+ case VG_LCCWARC_TO: segment = VG_LCWARC_TO; break;
+ case VG_LCWARC_TO: segment = VG_LCCWARC_TO; break;
+ default: break;
+ }
+ }
+ break;
+ }
+ }
+
+ newSegments[m_segments.size() + i] = (RIuint8)(segment | absRel);
+ srcCoord += coords;
+ }
+ RI_ASSERT(srcCoord == numSrcCoords);
+ RI_ASSERT(dstCoord == getNumCoordinates() + numDstCoords);
+
+ RI_ASSERT(newData.size() == countNumCoordinates(&newSegments[0],newSegments.size()) * getBytesPerCoordinate(m_datatype));
+
+ //replace old arrays
+ m_segments.swap(newSegments);
+ m_data.swap(newData);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Normalizes a path for interpolation.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Path::normalizeForInterpolation(const Path* srcPath)
+{
+ RI_ASSERT(srcPath);
+ RI_ASSERT(srcPath != this);
+ RI_ASSERT(srcPath->m_referenceCount > 0);
+
+ //count the number of resulting coordinates
+ int numSrcCoords = 0;
+ int numDstCoords = 0;
+ for(int i=0;i<srcPath->m_segments.size();i++)
+ {
+ VGPathSegment segment = getPathSegment(srcPath->m_segments[i]);
+ int coords = segmentToNumCoordinates(segment);
+ numSrcCoords += coords;
+ switch(segment)
+ {
+ case VG_CLOSE_PATH:
+ case VG_MOVE_TO:
+ case VG_LINE_TO:
+ break;
+
+ case VG_HLINE_TO:
+ case VG_VLINE_TO:
+ coords = 2;
+ break;
+
+ case VG_QUAD_TO:
+ case VG_CUBIC_TO:
+ case VG_SQUAD_TO:
+ case VG_SCUBIC_TO:
+ coords = 6;
+ break;
+
+ default:
+ RI_ASSERT(segment == VG_SCCWARC_TO || segment == VG_SCWARC_TO ||
+ segment == VG_LCCWARC_TO || segment == VG_LCWARC_TO);
+ break;
+ }
+ numDstCoords += coords;
+ }
+
+ m_segments.resize(srcPath->m_segments.size()); //throws bad_alloc
+ m_data.resize(numDstCoords * getBytesPerCoordinate(VG_PATH_DATATYPE_F)); //throws bad_alloc
+
+ int srcCoord = 0;
+ int dstCoord = 0;
+ Vector2 s(0,0); //the beginning of the current subpath
+ Vector2 o(0,0); //the last point of the previous segment
+
+ // the last internal control point of the previous segment, if the
+ //segment was a (regular or smooth) quadratic or cubic
+ //Bezier, or else the last point of the previous segment
+ Vector2 p(0,0);
+ for(int i=0;i<srcPath->m_segments.size();i++)
+ {
+ VGPathSegment segment = getPathSegment(srcPath->m_segments[i]);
+ VGPathAbsRel absRel = getPathAbsRel(srcPath->m_segments[i]);
+ int coords = segmentToNumCoordinates(segment);
+
+ switch(segment)
+ {
+ case VG_CLOSE_PATH:
+ {
+ RI_ASSERT(coords == 0);
+ p = s;
+ o = s;
+ break;
+ }
+
+ case VG_MOVE_TO:
+ {
+ RI_ASSERT(coords == 2);
+ Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ if(absRel == VG_RELATIVE)
+ c += o;
+ setCoordinate(dstCoord++, c.x);
+ setCoordinate(dstCoord++, c.y);
+ s = c;
+ p = c;
+ o = c;
+ break;
+ }
+
+ case VG_LINE_TO:
+ {
+ RI_ASSERT(coords == 2);
+ Vector2 c(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ if(absRel == VG_RELATIVE)
+ c += o;
+ setCoordinate(dstCoord++, c.x);
+ setCoordinate(dstCoord++, c.y);
+ p = c;
+ o = c;
+ break;
+ }
+
+ case VG_HLINE_TO:
+ {
+ RI_ASSERT(coords == 1);
+ Vector2 c(srcPath->getCoordinate(srcCoord+0), o.y);
+ if(absRel == VG_RELATIVE)
+ c.x += o.x;
+ setCoordinate(dstCoord++, c.x);
+ setCoordinate(dstCoord++, c.y);
+ p = c;
+ o = c;
+ segment = VG_LINE_TO;
+ break;
+ }
+
+ case VG_VLINE_TO:
+ {
+ RI_ASSERT(coords == 1);
+ Vector2 c(o.x, srcPath->getCoordinate(srcCoord+0));
+ if(absRel == VG_RELATIVE)
+ c.y += o.y;
+ setCoordinate(dstCoord++, c.x);
+ setCoordinate(dstCoord++, c.y);
+ p = c;
+ o = c;
+ segment = VG_LINE_TO;
+ break;
+ }
+
+ case VG_QUAD_TO:
+ {
+ RI_ASSERT(coords == 4);
+ Vector2 c0(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ Vector2 c1(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
+ if(absRel == VG_RELATIVE)
+ {
+ c0 += o;
+ c1 += o;
+ }
+ Vector2 d0 = (1.0f/3.0f) * (o + 2.0f * c0);
+ Vector2 d1 = (1.0f/3.0f) * (c1 + 2.0f * c0);
+ setCoordinate(dstCoord++, d0.x);
+ setCoordinate(dstCoord++, d0.y);
+ setCoordinate(dstCoord++, d1.x);
+ setCoordinate(dstCoord++, d1.y);
+ setCoordinate(dstCoord++, c1.x);
+ setCoordinate(dstCoord++, c1.y);
+ p = c0;
+ o = c1;
+ segment = VG_CUBIC_TO;
+ break;
+ }
+
+ case VG_CUBIC_TO:
+ {
+ RI_ASSERT(coords == 6);
+ Vector2 c0(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ Vector2 c1(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
+ Vector2 c2(srcPath->getCoordinate(srcCoord+4), srcPath->getCoordinate(srcCoord+5));
+ if(absRel == VG_RELATIVE)
+ {
+ c0 += o;
+ c1 += o;
+ c2 += o;
+ }
+ setCoordinate(dstCoord++, c0.x);
+ setCoordinate(dstCoord++, c0.y);
+ setCoordinate(dstCoord++, c1.x);
+ setCoordinate(dstCoord++, c1.y);
+ setCoordinate(dstCoord++, c2.x);
+ setCoordinate(dstCoord++, c2.y);
+ p = c1;
+ o = c2;
+ break;
+ }
+
+ case VG_SQUAD_TO:
+ {
+ RI_ASSERT(coords == 2);
+ Vector2 c0 = 2.0f * o - p;
+ Vector2 c1(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ if(absRel == VG_RELATIVE)
+ c1 += o;
+ Vector2 d0 = (1.0f/3.0f) * (o + 2.0f * c0);
+ Vector2 d1 = (1.0f/3.0f) * (c1 + 2.0f * c0);
+ setCoordinate(dstCoord++, d0.x);
+ setCoordinate(dstCoord++, d0.y);
+ setCoordinate(dstCoord++, d1.x);
+ setCoordinate(dstCoord++, d1.y);
+ setCoordinate(dstCoord++, c1.x);
+ setCoordinate(dstCoord++, c1.y);
+ p = c0;
+ o = c1;
+ segment = VG_CUBIC_TO;
+ break;
+ }
+
+ case VG_SCUBIC_TO:
+ {
+ RI_ASSERT(coords == 4);
+ Vector2 c0 = 2.0f * o - p;
+ Vector2 c1(srcPath->getCoordinate(srcCoord+0), srcPath->getCoordinate(srcCoord+1));
+ Vector2 c2(srcPath->getCoordinate(srcCoord+2), srcPath->getCoordinate(srcCoord+3));
+ if(absRel == VG_RELATIVE)
+ {
+ c1 += o;
+ c2 += o;
+ }
+ setCoordinate(dstCoord++, c0.x);
+ setCoordinate(dstCoord++, c0.y);
+ setCoordinate(dstCoord++, c1.x);
+ setCoordinate(dstCoord++, c1.y);
+ setCoordinate(dstCoord++, c2.x);
+ setCoordinate(dstCoord++, c2.y);
+ p = c1;
+ o = c2;
+ segment = VG_CUBIC_TO;
+ break;
+ }
+
+ default:
+ {
+ RI_ASSERT(segment == VG_SCCWARC_TO || segment == VG_SCWARC_TO ||
+ segment == VG_LCCWARC_TO || segment == VG_LCWARC_TO);
+ RI_ASSERT(coords == 5);
+ RIfloat rh = srcPath->getCoordinate(srcCoord+0);
+ RIfloat rv = srcPath->getCoordinate(srcCoord+1);
+ RIfloat rot = srcPath->getCoordinate(srcCoord+2);
+ Vector2 c(srcPath->getCoordinate(srcCoord+3), srcPath->getCoordinate(srcCoord+4));
+ if(absRel == VG_RELATIVE)
+ c += o;
+ setCoordinate(dstCoord++, rh);
+ setCoordinate(dstCoord++, rv);
+ setCoordinate(dstCoord++, rot);
+ setCoordinate(dstCoord++, c.x);
+ setCoordinate(dstCoord++, c.y);
+ p = c;
+ o = c;
+ break;
+ }
+ }
+
+ m_segments[i] = (RIuint8)(segment | VG_ABSOLUTE);
+ srcCoord += coords;
+ }
+ RI_ASSERT(srcCoord == numSrcCoords);
+ RI_ASSERT(dstCoord == numDstCoords);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Appends a linearly interpolated copy of the two source paths.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+bool Path::interpolate(const Path* startPath, const Path* endPath, RIfloat amount)
+{
+ RI_ASSERT(startPath && endPath);
+ RI_ASSERT(m_referenceCount > 0 && startPath->m_referenceCount > 0 && endPath->m_referenceCount > 0);
+
+ if(!startPath->m_segments.size() || startPath->m_segments.size() != endPath->m_segments.size())
+ return false; //start and end paths are incompatible or zero length
+
+ Path start(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, 0);
+ start.normalizeForInterpolation(startPath); //throws bad_alloc
+
+ Path end(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, 0);
+ end.normalizeForInterpolation(endPath); //throws bad_alloc
+
+ //check that start and end paths are compatible
+ if(start.m_data.size() != end.m_data.size() || start.m_segments.size() != end.m_segments.size())
+ return false; //start and end paths are incompatible
+
+ //allocate new arrays
+ Array<RIuint8> newSegments;
+ newSegments.resize(m_segments.size() + start.m_segments.size()); //throws bad_alloc
+ Array<RIuint8> newData;
+ newData.resize(m_data.size() + start.m_data.size() * getBytesPerCoordinate(m_datatype) / getBytesPerCoordinate(start.m_datatype)); //throws bad_alloc
+ //if we get here, the memory allocations have succeeded
+
+ //copy old segments
+ if(m_segments.size())
+ memcpy(&newSegments[0], &m_segments[0], m_segments.size());
+
+ //copy old data
+ if(m_data.size())
+ memcpy(&newData[0], &m_data[0], m_data.size());
+
+ //copy segments
+ for(int i=0;i<start.m_segments.size();i++)
+ {
+ VGPathSegment s = getPathSegment(start.m_segments[i]);
+ VGPathSegment e = getPathSegment(end.m_segments[i]);
+
+ if(s == VG_SCCWARC_TO || s == VG_SCWARC_TO || s == VG_LCCWARC_TO || s == VG_LCWARC_TO)
+ {
+ if(e != VG_SCCWARC_TO && e != VG_SCWARC_TO && e != VG_LCCWARC_TO && e != VG_LCWARC_TO)
+ return false; //start and end paths are incompatible
+ if(amount < 0.5f)
+ newSegments[m_segments.size() + i] = start.m_segments[i];
+ else
+ newSegments[m_segments.size() + i] = end.m_segments[i];
+ }
+ else
+ {
+ if(s != e)
+ return false; //start and end paths are incompatible
+ newSegments[m_segments.size() + i] = start.m_segments[i];
+ }
+ }
+
+ //interpolate data
+ int oldNumCoords = getNumCoordinates();
+ for(int i=0;i<start.getNumCoordinates();i++)
+ setCoordinate(newData, m_datatype, m_scale, m_bias, oldNumCoords + i, start.getCoordinate(i) * (1.0f - amount) + end.getCoordinate(i) * amount);
+
+ RI_ASSERT(newData.size() == countNumCoordinates(&newSegments[0],newSegments.size()) * getBytesPerCoordinate(m_datatype));
+
+ //replace old arrays
+ m_segments.swap(newSegments);
+ m_data.swap(newData);
+
+ return true;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a path for filling and appends resulting edges
+* to a rasterizer.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+void Path::fill(const Matrix3x3& pathToSurface, Rasterizer& rasterizer)
+{
+ RI_ASSERT(m_referenceCount > 0);
+ RI_ASSERT(pathToSurface.isAffine());
+
+ tessellate(pathToSurface, 0.0f); //throws bad_alloc
+
+ try
+ {
+ Vector2 p0(0,0), p1(0,0);
+ for(int i=0;i<m_vertices.size();i++)
+ {
+ p1 = affineTransform(pathToSurface, m_vertices[i].userPosition);
+
+ if(!(m_vertices[i].flags & START_SEGMENT))
+ { //in the middle of a segment
+ rasterizer.addEdge(p0, p1); //throws bad_alloc
+ }
+
+ p0 = p1;
+ }
+ }
+ catch(std::bad_alloc)
+ {
+ rasterizer.clear(); //remove the unfinished path
+ throw;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Smoothly interpolates between two StrokeVertices. Positions
+* are interpolated linearly, while tangents are interpolated
+* on a unit circle. Stroking is implemented so that overlapping
+* geometry doesnt cancel itself when filled with nonzero rule.
+* The resulting polygons are closed.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Path::interpolateStroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth) const
+{
+ Vector2 pccw = affineTransform(pathToSurface, v0.ccw);
+ Vector2 pcw = affineTransform(pathToSurface, v0.cw);
+ Vector2 p = affineTransform(pathToSurface, v0.p);
+ Vector2 endccw = affineTransform(pathToSurface, v1.ccw);
+ Vector2 endcw = affineTransform(pathToSurface, v1.cw);
+ Vector2 endp = affineTransform(pathToSurface, v1.p);
+
+ const RIfloat tessellationAngle = 5.0f;
+
+ RIfloat angle = RI_RAD_TO_DEG((RIfloat)acos(RI_CLAMP(dot(v0.t, v1.t), -1.0f, 1.0f))) / tessellationAngle;
+ int samples = RI_INT_MAX((int)ceil(angle), 1);
+
+ for(int j=0;j<samples-1;j++)
+ {
+ RIfloat t = (RIfloat)(j+1) / (RIfloat)samples;
+ Vector2 position = v0.p * (1.0f - t) + v1.p * t;
+ Vector2 tangent = circularLerp(v0.t, v1.t, t);
+ Vector2 normal = normalize(perpendicularCCW(tangent)) * strokeWidth * 0.5f;
+
+ Vector2 nccw = affineTransform(pathToSurface, position + normal);
+ Vector2 ncw = affineTransform(pathToSurface, position - normal);
+ Vector2 n = affineTransform(pathToSurface, position);
+
+ rasterizer.clear();
+ rasterizer.addEdge(p, pccw); //throws bad_alloc
+ rasterizer.addEdge(pccw, nccw); //throws bad_alloc
+ rasterizer.addEdge(nccw, n); //throws bad_alloc
+ rasterizer.addEdge(n, ncw); //throws bad_alloc
+ rasterizer.addEdge(ncw, pcw); //throws bad_alloc
+ rasterizer.addEdge(pcw, p); //throws bad_alloc
+ rasterizer.fill();
+
+ pccw = nccw;
+ pcw = ncw;
+ p = n;
+ }
+
+ //connect the last segment to the end coordinates
+ rasterizer.clear();
+ rasterizer.addEdge(p, pccw); //throws bad_alloc
+ rasterizer.addEdge(pccw, endccw); //throws bad_alloc
+ rasterizer.addEdge(endccw, endp); //throws bad_alloc
+ rasterizer.addEdge(endp, endcw); //throws bad_alloc
+ rasterizer.addEdge(endcw, pcw); //throws bad_alloc
+ rasterizer.addEdge(pcw, p); //throws bad_alloc
+ rasterizer.fill();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Generate edges for stroke caps. Resulting polygons are closed.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Path::doCap(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v, RIfloat strokeWidth, VGCapStyle capStyle) const
+{
+ Vector2 ccwt = affineTransform(pathToSurface, v.ccw);
+ Vector2 cwt = affineTransform(pathToSurface, v.cw);
+ Vector2 p = affineTransform(pathToSurface, v.p);
+
+ rasterizer.clear();
+ switch(capStyle)
+ {
+ case VG_CAP_BUTT:
+ break;
+
+ case VG_CAP_ROUND:
+ {
+ const RIfloat tessellationAngle = 5.0f;
+
+ RIfloat angle = 180.0f / tessellationAngle;
+
+ int samples = (int)ceil(angle);
+ RIfloat step = 1.0f / samples;
+ RIfloat t = step;
+ Vector2 u0 = normalize(v.ccw - v.p);
+ Vector2 u1 = normalize(v.cw - v.p);
+ Vector2 prev = ccwt;
+ rasterizer.addEdge(p, ccwt); //throws bad_alloc
+ for(int j=1;j<samples;j++)
+ {
+ Vector2 next = v.p + circularLerp(u0, u1, t, true) * strokeWidth * 0.5f;
+ next = affineTransform(pathToSurface, next);
+
+ rasterizer.addEdge(prev, next); //throws bad_alloc
+ prev = next;
+ t += step;
+ }
+ rasterizer.addEdge(prev, cwt); //throws bad_alloc
+ rasterizer.addEdge(cwt, p); //throws bad_alloc
+ break;
+ }
+
+ default:
+ {
+ RI_ASSERT(capStyle == VG_CAP_SQUARE);
+ Vector2 t = v.t;
+ t.normalize();
+ Vector2 ccws = affineTransform(pathToSurface, v.ccw + t * strokeWidth * 0.5f);
+ Vector2 cws = affineTransform(pathToSurface, v.cw + t * strokeWidth * 0.5f);
+ rasterizer.addEdge(p, ccwt); //throws bad_alloc
+ rasterizer.addEdge(ccwt, ccws); //throws bad_alloc
+ rasterizer.addEdge(ccws, cws); //throws bad_alloc
+ rasterizer.addEdge(cws, cwt); //throws bad_alloc
+ rasterizer.addEdge(cwt, p); //throws bad_alloc
+ break;
+ }
+ }
+ rasterizer.fill();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Generate edges for stroke joins. Resulting polygons are closed.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Path::doJoin(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth, VGJoinStyle joinStyle, RIfloat miterLimit) const
+{
+ Vector2 ccw0t = affineTransform(pathToSurface, v0.ccw);
+ Vector2 cw0t = affineTransform(pathToSurface, v0.cw);
+ Vector2 m0t = affineTransform(pathToSurface, v0.p);
+ Vector2 ccw1t = affineTransform(pathToSurface, v1.ccw);
+ Vector2 cw1t = affineTransform(pathToSurface, v1.cw);
+ Vector2 m1t = affineTransform(pathToSurface, v1.p);
+
+ Vector2 tccw = v1.ccw - v0.ccw;
+ Vector2 s, e, m, st, et;
+ bool cw;
+
+ rasterizer.clear();
+
+ if( dot(tccw, v0.t) > 0.0f )
+ { //draw ccw miter (draw from point 0 to 1)
+ s = ccw0t;
+ e = ccw1t;
+ st = v0.t;
+ et = v1.t;
+ m = v0.ccw;
+ cw = false;
+ rasterizer.addEdge(m0t, ccw0t); //throws bad_alloc
+ rasterizer.addEdge(ccw1t, m1t); //throws bad_alloc
+ rasterizer.addEdge(m1t, m0t); //throws bad_alloc
+ }
+ else
+ { //draw cw miter (draw from point 1 to 0)
+ s = cw1t;
+ e = cw0t;
+ st = v1.t;
+ et = v0.t;
+ m = v0.cw;
+ cw = true;
+ rasterizer.addEdge(cw0t, m0t); //throws bad_alloc
+ rasterizer.addEdge(m1t, cw1t); //throws bad_alloc
+ rasterizer.addEdge(m0t, m1t); //throws bad_alloc
+ }
+
+ switch(joinStyle)
+ {
+ case VG_JOIN_MITER:
+ {
+ RIfloat theta = (RIfloat)acos(RI_CLAMP(dot(v0.t, -v1.t), -1.0f, 1.0f));
+ RIfloat miterLengthPerStrokeWidth = 1.0f / (RIfloat)sin(theta*0.5f);
+ if( miterLengthPerStrokeWidth < miterLimit )
+ { //miter
+ RIfloat l = (RIfloat)cos(theta*0.5f) * miterLengthPerStrokeWidth * (strokeWidth * 0.5f);
+ l = RI_MIN(l, RI_FLOAT_MAX); //force finite
+ Vector2 c = m + v0.t * l;
+ c = affineTransform(pathToSurface, c);
+ rasterizer.addEdge(s, c); //throws bad_alloc
+ rasterizer.addEdge(c, e); //throws bad_alloc
+ }
+ else
+ { //bevel
+ rasterizer.addEdge(s, e); //throws bad_alloc
+ }
+ break;
+ }
+
+ case VG_JOIN_ROUND:
+ {
+ const RIfloat tessellationAngle = 5.0f;
+
+ Vector2 prev = s;
+ RIfloat angle = RI_RAD_TO_DEG((RIfloat)acos(RI_CLAMP(dot(st, et), -1.0f, 1.0f))) / tessellationAngle;
+ int samples = (int)ceil(angle);
+ if( samples )
+ {
+ RIfloat step = 1.0f / samples;
+ RIfloat t = step;
+ for(int j=1;j<samples;j++)
+ {
+ Vector2 position = v0.p * (1.0f - t) + v1.p * t;
+ Vector2 tangent = circularLerp(st, et, t, true);
+
+ Vector2 next = position + normalize(perpendicular(tangent, cw)) * strokeWidth * 0.5f;
+ next = affineTransform(pathToSurface, next);
+
+ rasterizer.addEdge(prev, next); //throws bad_alloc
+ prev = next;
+ t += step;
+ }
+ }
+ rasterizer.addEdge(prev, e); //throws bad_alloc
+ break;
+ }
+
+ default:
+ RI_ASSERT(joinStyle == VG_JOIN_BEVEL);
+ if(!cw)
+ rasterizer.addEdge(ccw0t, ccw1t); //throws bad_alloc
+ else
+ rasterizer.addEdge(cw1t, cw0t); //throws bad_alloc
+ break;
+ }
+ rasterizer.fill();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellate a path, apply stroking, dashing, caps and joins, and
+* append resulting edges to a rasterizer.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+void Path::stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const Array<RIfloat>& dashPattern, RIfloat dashPhase, bool dashPhaseReset, RIfloat strokeWidth, VGCapStyle capStyle, VGJoinStyle joinStyle, RIfloat miterLimit)
+{
+ RI_ASSERT(pathToSurface.isAffine());
+ RI_ASSERT(m_referenceCount > 0);
+ RI_ASSERT(strokeWidth >= 0.0f);
+ RI_ASSERT(miterLimit >= 1.0f);
+
+ tessellate(pathToSurface, strokeWidth); //throws bad_alloc
+
+ if(!m_vertices.size())
+ return;
+
+ bool dashing = true;
+ int dashPatternSize = dashPattern.size();
+ if( dashPattern.size() & 1 )
+ dashPatternSize--; //odd number of dash pattern entries, discard the last one
+ RIfloat dashPatternLength = 0.0f;
+ for(int i=0;i<dashPatternSize;i++)
+ dashPatternLength += RI_MAX(dashPattern[i], 0.0f);
+ if(!dashPatternSize || dashPatternLength == 0.0f )
+ dashing = false;
+ dashPatternLength = RI_MIN(dashPatternLength, RI_FLOAT_MAX);
+
+ //walk along the path
+ //stop at the next event which is either:
+ //-path vertex
+ //-dash stop
+ //for robustness, decisions based on geometry are done only once.
+ //inDash keeps track whether the last point was in dash or not
+
+ //loop vertex events
+ try
+ {
+ RIfloat nextDash = 0.0f;
+ int d = 0;
+ bool inDash = true;
+ StrokeVertex v0, v1, vs;
+ for(int i=0;i<m_vertices.size();i++)
+ {
+ //read the next vertex
+ Vertex& v = m_vertices[i];
+ v1.p = v.userPosition;
+ v1.t = v.userTangent;
+ RI_ASSERT(!isZero(v1.t)); //don't allow zero tangents
+ v1.ccw = v1.p + normalize(perpendicularCCW(v1.t)) * strokeWidth * 0.5f;
+ v1.cw = v1.p + normalize(perpendicularCW(v1.t)) * strokeWidth * 0.5f;
+ v1.pathLength = v.pathLength;
+ v1.flags = v.flags;
+ v1.inDash = dashing ? inDash : true; //NOTE: for other than START_SEGMENT vertices inDash will be updated after dashing
+
+ //process the vertex event
+ if(v.flags & START_SEGMENT)
+ {
+ if(v.flags & START_SUBPATH)
+ {
+ if( dashing )
+ { //initialize dashing by finding which dash or gap the first point of the path lies in
+ if(dashPhaseReset || i == 0)
+ {
+ d = 0;
+ inDash = true;
+ nextDash = v1.pathLength - RI_MOD(dashPhase, dashPatternLength);
+ for(;;)
+ {
+ RIfloat prevDash = nextDash;
+ nextDash = prevDash + RI_MAX(dashPattern[d], 0.0f);
+ if(nextDash >= v1.pathLength)
+ break;
+
+ if( d & 1 )
+ inDash = true;
+ else
+ inDash = false;
+ d = (d+1) % dashPatternSize;
+ }
+ v1.inDash = inDash;
+ //the first point of the path lies between prevDash and nextDash
+ //d in the index of the next dash stop
+ //inDash is true if the first point is in a dash
+ }
+ }
+ vs = v1; //save the subpath start point
+ }
+ else
+ {
+ if( v.flags & IMPLICIT_CLOSE_SUBPATH )
+ { //do caps for the start and end of the current subpath
+ if( v0.inDash )
+ doCap(pathToSurface, rasterizer, v0, strokeWidth, capStyle); //end cap //throws bad_alloc
+ if( vs.inDash )
+ {
+ StrokeVertex vi = vs;
+ vi.t = -vi.t;
+ RI_SWAP(vi.ccw.x, vi.cw.x);
+ RI_SWAP(vi.ccw.y, vi.cw.y);
+ doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle); //start cap //throws bad_alloc
+ }
+ }
+ else
+ { //join two segments
+ RI_ASSERT(v0.inDash == v1.inDash);
+ if( v0.inDash )
+ doJoin(pathToSurface, rasterizer, v0, v1, strokeWidth, joinStyle, miterLimit); //throws bad_alloc
+ }
+ }
+ }
+ else
+ { //in the middle of a segment
+ if( !(v.flags & IMPLICIT_CLOSE_SUBPATH) )
+ { //normal segment, do stroking
+ if( dashing )
+ {
+ StrokeVertex prevDashVertex = v0; //dashing of the segment starts from the previous vertex
+
+ if(nextDash + 10000.0f * dashPatternLength < v1.pathLength)
+ throw std::bad_alloc(); //too many dashes, throw bad_alloc
+
+ //loop dash events until the next vertex event
+ //zero length dashes are handled as a special case since if they hit the vertex,
+ //we want to include their starting point to this segment already in order to generate a join
+ int numDashStops = 0;
+ while(nextDash < v1.pathLength || (nextDash <= v1.pathLength && dashPattern[(d+1) % dashPatternSize] == 0.0f))
+ {
+ RIfloat edgeLength = v1.pathLength - v0.pathLength;
+ RIfloat ratio = 0.0f;
+ if(edgeLength > 0.0f)
+ ratio = (nextDash - v0.pathLength) / edgeLength;
+ StrokeVertex nextDashVertex;
+ nextDashVertex.p = v0.p * (1.0f - ratio) + v1.p * ratio;
+ nextDashVertex.t = circularLerp(v0.t, v1.t, ratio);
+ nextDashVertex.ccw = nextDashVertex.p + normalize(perpendicularCCW(nextDashVertex.t)) * strokeWidth * 0.5f;
+ nextDashVertex.cw = nextDashVertex.p + normalize(perpendicularCW(nextDashVertex.t)) * strokeWidth * 0.5f;
+
+ if( inDash )
+ { //stroke from prevDashVertex -> nextDashVertex
+ if( numDashStops )
+ { //prevDashVertex is not the start vertex of the segment, cap it (start vertex has already been joined or capped)
+ StrokeVertex vi = prevDashVertex;
+ vi.t = -vi.t;
+ RI_SWAP(vi.ccw.x, vi.cw.x);
+ RI_SWAP(vi.ccw.y, vi.cw.y);
+ doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle); //throws bad_alloc
+ }
+ interpolateStroke(pathToSurface, rasterizer, prevDashVertex, nextDashVertex, strokeWidth); //throws bad_alloc
+ doCap(pathToSurface, rasterizer, nextDashVertex, strokeWidth, capStyle); //end cap //throws bad_alloc
+ }
+ prevDashVertex = nextDashVertex;
+
+ if( d & 1 )
+ { //dash starts
+ RI_ASSERT(!inDash);
+ inDash = true;
+ }
+ else
+ { //dash ends
+ RI_ASSERT(inDash);
+ inDash = false;
+ }
+ d = (d+1) % dashPatternSize;
+ nextDash += RI_MAX(dashPattern[d], 0.0f);
+ numDashStops++;
+ }
+
+ if( inDash )
+ { //stroke prevDashVertex -> v1
+ if( numDashStops )
+ { //prevDashVertex is not the start vertex of the segment, cap it (start vertex has already been joined or capped)
+ StrokeVertex vi = prevDashVertex;
+ vi.t = -vi.t;
+ RI_SWAP(vi.ccw.x, vi.cw.x);
+ RI_SWAP(vi.ccw.y, vi.cw.y);
+ doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle); //throws bad_alloc
+ }
+ interpolateStroke(pathToSurface, rasterizer, prevDashVertex, v1, strokeWidth); //throws bad_alloc
+ //no cap, leave path open
+ }
+
+ v1.inDash = inDash; //update inDash status of the segment end point
+ }
+ else //no dashing, just interpolate segment end points
+ interpolateStroke(pathToSurface, rasterizer, v0, v1, strokeWidth); //throws bad_alloc
+ }
+ }
+
+ if((v.flags & END_SEGMENT) && (v.flags & CLOSE_SUBPATH))
+ { //join start and end of the current subpath
+ if( v1.inDash && vs.inDash )
+ doJoin(pathToSurface, rasterizer, v1, vs, strokeWidth, joinStyle, miterLimit); //throws bad_alloc
+ else
+ { //both start and end are not in dash, cap them
+ if( v1.inDash )
+ doCap(pathToSurface, rasterizer, v1, strokeWidth, capStyle); //end cap //throws bad_alloc
+ if( vs.inDash )
+ {
+ StrokeVertex vi = vs;
+ vi.t = -vi.t;
+ RI_SWAP(vi.ccw.x, vi.cw.x);
+ RI_SWAP(vi.ccw.y, vi.cw.y);
+ doCap(pathToSurface, rasterizer, vi, strokeWidth, capStyle); //start cap //throws bad_alloc
+ }
+ }
+ }
+
+ v0 = v1;
+ }
+ }
+ catch(std::bad_alloc)
+ {
+ rasterizer.clear(); //remove the unfinished path
+ throw;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a path, and returns a position and a tangent on the path
+* given a distance along the path.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+void Path::getPointAlong(int startIndex, int numSegments, RIfloat distance, Vector2& p, Vector2& t)
+{
+ RI_ASSERT(m_referenceCount > 0);
+ RI_ASSERT(startIndex >= 0 && startIndex + numSegments <= m_segments.size() && numSegments > 0);
+
+ Matrix3x3 identity;
+ identity.identity();
+ tessellate(identity, 0.0f); //throws bad_alloc
+
+ RI_ASSERT(startIndex >= 0 && startIndex < m_segmentToVertex.size());
+ RI_ASSERT(startIndex + numSegments >= 0 && startIndex + numSegments <= m_segmentToVertex.size());
+
+ // ignore move segments at the start of the path
+ while (numSegments && (m_segments[startIndex] & ~VG_RELATIVE) == VG_MOVE_TO)
+ {
+ startIndex++;
+ numSegments--;
+ }
+
+ // ignore move segments at the end of the path
+ while (numSegments && (m_segments[startIndex + numSegments - 1] & ~VG_RELATIVE) == VG_MOVE_TO)
+ numSegments--;
+
+ // empty path?
+ if (!m_vertices.size() || !numSegments)
+ {
+ p.set(0,0);
+ t.set(1,0);
+ return;
+ }
+
+ int startVertex = m_segmentToVertex[startIndex].start;
+ int endVertex = m_segmentToVertex[startIndex + numSegments - 1].end;
+
+ if(startVertex == -1)
+ startVertex = 0;
+
+ // zero length?
+ if (startVertex >= endVertex)
+ {
+ p = m_vertices[startVertex].userPosition;
+ t.set(1,0);
+ return;
+ }
+
+ RI_ASSERT(startVertex >= 0 && startVertex < m_vertices.size());
+ RI_ASSERT(endVertex >= 0 && endVertex < m_vertices.size());
+
+ distance += m_vertices[startVertex].pathLength; //map distance to the range of the whole path
+
+ if(distance <= m_vertices[startVertex].pathLength)
+ { //return the first point of the path
+ p = m_vertices[startVertex].userPosition;
+ t = m_vertices[startVertex].userTangent;
+ return;
+ }
+
+ if(distance >= m_vertices[endVertex].pathLength)
+ { //return the last point of the path
+ p = m_vertices[endVertex].userPosition;
+ t = m_vertices[endVertex].userTangent;
+ return;
+ }
+
+ //search for the segment containing the distance
+ for(int s=startIndex;s<startIndex+numSegments;s++)
+ {
+ int start = m_segmentToVertex[s].start;
+ int end = m_segmentToVertex[s].end;
+ if(start < 0)
+ start = 0;
+ if(end < 0)
+ end = 0;
+ RI_ASSERT(start >= 0 && start < m_vertices.size());
+ RI_ASSERT(end >= 0 && end < m_vertices.size());
+
+ if(distance >= m_vertices[start].pathLength && distance < m_vertices[end].pathLength)
+ { //segment contains the queried distance
+ for(int i=start;i<end;i++)
+ {
+ const Vertex& v0 = m_vertices[i];
+ const Vertex& v1 = m_vertices[i+1];
+ if(distance >= v0.pathLength && distance < v1.pathLength)
+ { //segment found, interpolate linearly between its end points
+ RIfloat edgeLength = v1.pathLength - v0.pathLength;
+ RI_ASSERT(edgeLength > 0.0f);
+ RIfloat r = (distance - v0.pathLength) / edgeLength;
+ p = (1.0f - r) * v0.userPosition + r * v1.userPosition;
+ t = (1.0f - r) * v0.userTangent + r * v1.userTangent;
+ return;
+ }
+ }
+ }
+ }
+
+ RI_ASSERT(0); //point not found (should never get here)
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a path, and computes its length.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+RIfloat Path::getPathLength(int startIndex, int numSegments)
+{
+ RI_ASSERT(m_referenceCount > 0);
+ RI_ASSERT(startIndex >= 0 && startIndex + numSegments <= m_segments.size() && numSegments > 0);
+
+ Matrix3x3 identity;
+ identity.identity();
+ tessellate(identity, 0.0f); //throws bad_alloc
+
+ RI_ASSERT(startIndex >= 0 && startIndex < m_segmentToVertex.size());
+ RI_ASSERT(startIndex + numSegments >= 0 && startIndex + numSegments <= m_segmentToVertex.size());
+
+ int startVertex = m_segmentToVertex[startIndex].start;
+ int endVertex = m_segmentToVertex[startIndex + numSegments - 1].end;
+
+ if(!m_vertices.size())
+ return 0.0f;
+
+ RIfloat startPathLength = 0.0f;
+ if(startVertex >= 0)
+ {
+ RI_ASSERT(startVertex >= 0 && startVertex < m_vertices.size());
+ startPathLength = m_vertices[startVertex].pathLength;
+ }
+ RIfloat endPathLength = 0.0f;
+ if(endVertex >= 0)
+ {
+ RI_ASSERT(endVertex >= 0 && endVertex < m_vertices.size());
+ endPathLength = m_vertices[endVertex].pathLength;
+ }
+
+ return endPathLength - startPathLength;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a path, and computes its bounding box in user space.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+void Path::getPathBounds(RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy)
+{
+ RI_ASSERT(m_referenceCount > 0);
+
+ Matrix3x3 identity;
+ identity.identity();
+ tessellate(identity, 0.0f); //throws bad_alloc
+
+ if(m_vertices.size())
+ {
+ minx = m_userMinx;
+ miny = m_userMiny;
+ maxx = m_userMaxx;
+ maxy = m_userMaxy;
+ }
+ else
+ {
+ minx = miny = 0;
+ maxx = maxy = -1;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a path, and computes its bounding box in surface space.
+* \param
+* \return
+* \note if runs out of memory, throws bad_alloc and leaves the path as it was
+*//*-------------------------------------------------------------------*/
+
+void Path::getPathTransformedBounds(const Matrix3x3& pathToSurface, RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy)
+{
+ RI_ASSERT(m_referenceCount > 0);
+ RI_ASSERT(pathToSurface.isAffine());
+
+ Matrix3x3 identity;
+ identity.identity();
+ tessellate(identity, 0.0f); //throws bad_alloc
+
+ if(m_vertices.size())
+ {
+ Vector3 p0(m_userMinx, m_userMiny, 1.0f);
+ Vector3 p1(m_userMinx, m_userMaxy, 1.0f);
+ Vector3 p2(m_userMaxx, m_userMaxy, 1.0f);
+ Vector3 p3(m_userMaxx, m_userMiny, 1.0f);
+ p0 = pathToSurface * p0;
+ p1 = pathToSurface * p1;
+ p2 = pathToSurface * p2;
+ p3 = pathToSurface * p3;
+
+ minx = RI_MIN(RI_MIN(RI_MIN(p0.x, p1.x), p2.x), p3.x);
+ miny = RI_MIN(RI_MIN(RI_MIN(p0.y, p1.y), p2.y), p3.y);
+ maxx = RI_MAX(RI_MAX(RI_MAX(p0.x, p1.x), p2.x), p3.x);
+ maxy = RI_MAX(RI_MAX(RI_MAX(p0.y, p1.y), p2.y), p3.y);
+ }
+ else
+ {
+ minx = miny = 0;
+ maxx = maxy = -1;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Adds a vertex to a tessellated path.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Path::addVertex(const Vector2& p, const Vector2& t, RIfloat pathLength, unsigned int flags)
+{
+ RI_ASSERT(!isZero(t));
+
+ Vertex v;
+ v.pathLength = pathLength;
+ v.userPosition = p;
+ v.userTangent = t;
+ v.flags = flags;
+ m_vertices.push_back(v); //throws bad_alloc
+ m_numTessVertices++;
+
+ m_userMinx = RI_MIN(m_userMinx, v.userPosition.x);
+ m_userMiny = RI_MIN(m_userMiny, v.userPosition.y);
+ m_userMaxx = RI_MAX(m_userMaxx, v.userPosition.x);
+ m_userMaxy = RI_MAX(m_userMaxy, v.userPosition.y);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Adds an edge to a tessellated path.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Path::addEdge(const Vector2& p0, const Vector2& p1, const Vector2& t0, const Vector2& t1, unsigned int startFlags, unsigned int endFlags)
+{
+ Vertex v;
+ RIfloat pathLength = 0.0f;
+
+ RI_ASSERT(!isZero(t0) && !isZero(t1));
+
+ //segment midpoints are shared between edges
+ if(!m_numTessVertices)
+ {
+ if(m_vertices.size() > 0)
+ pathLength = m_vertices[m_vertices.size()-1].pathLength;
+
+ addVertex(p0, t0, pathLength, startFlags); //throws bad_alloc
+ }
+
+ //other than implicit close paths (caused by a MOVE_TO) add to path length
+ if( !(endFlags & IMPLICIT_CLOSE_SUBPATH) )
+ {
+ //NOTE: with extremely large coordinates the floating point path length is infinite
+ RIfloat l = (p1 - p0).length();
+ pathLength = m_vertices[m_vertices.size()-1].pathLength + l;
+ pathLength = RI_MIN(pathLength, RI_FLOAT_MAX);
+ }
+
+ addVertex(p1, t1, pathLength, endFlags); //throws bad_alloc
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a close-path segment.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Path::addEndPath(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry, unsigned int flags)
+{
+ RI_UNREF(pathToSurface);
+ m_numTessVertices = 0;
+ if(!subpathHasGeometry)
+ { //single vertex
+ Vector2 t(1.0f,0.0f);
+ addEdge(p0, p1, t, t, START_SEGMENT | START_SUBPATH, END_SEGMENT | END_SUBPATH); //throws bad_alloc
+ m_numTessVertices = 0;
+ addEdge(p0, p1, -t, -t, IMPLICIT_CLOSE_SUBPATH | START_SEGMENT, IMPLICIT_CLOSE_SUBPATH | END_SEGMENT); //throws bad_alloc
+ return;
+ }
+ //the subpath contains segment commands that have generated geometry
+
+ //add a close path segment to the start point of the subpath
+ RI_ASSERT(m_vertices.size() > 0);
+ m_vertices[m_vertices.size()-1].flags |= END_SUBPATH;
+
+ Vector2 t = normalize(p1 - p0);
+ if(isZero(t))
+ t = m_vertices[m_vertices.size()-1].userTangent; //if the segment is zero-length, use the tangent of the last segment end point so that proper join will be generated
+ RI_ASSERT(!isZero(t));
+
+ addEdge(p0, p1, t, t, flags | START_SEGMENT, flags | END_SEGMENT); //throws bad_alloc
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a line-to segment.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool Path::addLineTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry)
+{
+ RI_UNREF(pathToSurface);
+ if(p0 == p1)
+ return false; //discard zero-length segments
+
+ //compute end point tangents
+ Vector2 t = normalize(p1 - p0);
+ RI_ASSERT(!isZero(t));
+
+ m_numTessVertices = 0;
+ unsigned int startFlags = START_SEGMENT;
+ if(!subpathHasGeometry)
+ startFlags |= START_SUBPATH;
+ addEdge(p0, p1, t, t, startFlags, END_SEGMENT); //throws bad_alloc
+ return true;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a quad-to segment.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool Path::addQuadTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, bool subpathHasGeometry, float strokeWidth)
+{
+ RI_UNREF(pathToSurface);
+ RI_UNREF(strokeWidth);
+ if(p0 == p1 && p0 == p2)
+ {
+ RI_ASSERT(p1 == p2);
+ return false; //discard zero-length segments
+ }
+
+ //compute end point tangents
+
+ Vector2 incomingTangent = normalize(p1 - p0);
+ Vector2 outgoingTangent = normalize(p2 - p1);
+ if(p0 == p1)
+ incomingTangent = normalize(p2 - p0);
+ if(p1 == p2)
+ outgoingTangent = normalize(p2 - p0);
+ RI_ASSERT(!isZero(incomingTangent) && !isZero(outgoingTangent));
+
+ m_numTessVertices = 0;
+ unsigned int startFlags = START_SEGMENT;
+ if(!subpathHasGeometry)
+ startFlags |= START_SUBPATH;
+
+ const int segments = RI_NUM_TESSELLATED_SEGMENTS;
+ Vector2 pp = p0;
+ Vector2 tp = incomingTangent;
+ unsigned int prevFlags = startFlags;
+ for(int i=1;i<segments;i++)
+ {
+ RIfloat t = (RIfloat)i / (RIfloat)segments;
+ RIfloat u = 1.0f-t;
+ Vector2 pn = u*u * p0 + 2.0f*t*u * p1 + t*t * p2;
+ Vector2 tn = (-1.0f+t) * p0 + (1.0f-2.0f*t) * p1 + t * p2;
+ tn = normalize(tn);
+ if(isZero(tn))
+ tn = tp;
+
+ addEdge(pp, pn, tp, tn, prevFlags, 0); //throws bad_alloc
+
+ pp = pn;
+ tp = tn;
+ prevFlags = 0;
+ }
+ addEdge(pp, p2, tp, outgoingTangent, prevFlags, END_SEGMENT); //throws bad_alloc
+ return true;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a cubic-to segment.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool Path::addCubicTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& p3, bool subpathHasGeometry, float strokeWidth)
+{
+ RI_UNREF(pathToSurface);
+ RI_UNREF(strokeWidth);
+
+ if(p0 == p1 && p0 == p2 && p0 == p3)
+ {
+ RI_ASSERT(p1 == p2 && p1 == p3 && p2 == p3);
+ return false; //discard zero-length segments
+ }
+
+ //compute end point tangents
+ Vector2 incomingTangent = normalize(p1 - p0);
+ Vector2 outgoingTangent = normalize(p3 - p2);
+ if(p0 == p1)
+ {
+ incomingTangent = normalize(p2 - p0);
+ if(p1 == p2)
+ incomingTangent = normalize(p3 - p0);
+ }
+ if(p2 == p3)
+ {
+ outgoingTangent = normalize(p3 - p1);
+ if(p1 == p2)
+ outgoingTangent = normalize(p3 - p0);
+ }
+ RI_ASSERT(!isZero(incomingTangent) && !isZero(outgoingTangent));
+
+ m_numTessVertices = 0;
+ unsigned int startFlags = START_SEGMENT;
+ if(!subpathHasGeometry)
+ startFlags |= START_SUBPATH;
+
+ const int segments = RI_NUM_TESSELLATED_SEGMENTS;
+ Vector2 pp = p0;
+ Vector2 tp = incomingTangent;
+ unsigned int prevFlags = startFlags;
+ for(int i=1;i<segments;i++)
+ {
+ RIfloat t = (RIfloat)i / (RIfloat)segments;
+ Vector2 pn = (1.0f - 3.0f*t + 3.0f*t*t - t*t*t) * p0 + (3.0f*t - 6.0f*t*t + 3.0f*t*t*t) * p1 + (3.0f*t*t - 3.0f*t*t*t) * p2 + t*t*t * p3;
+ Vector2 tn = (-3.0f + 6.0f*t - 3.0f*t*t) * p0 + (3.0f - 12.0f*t + 9.0f*t*t) * p1 + (6.0f*t - 9.0f*t*t) * p2 + 3.0f*t*t * p3;
+
+ tn = normalize(tn);
+ if(isZero(tn))
+ tn = tp;
+
+ addEdge(pp, pn, tp, tn, prevFlags, 0); //throws bad_alloc
+
+ pp = pn;
+ tp = tn;
+ prevFlags = 0;
+ }
+ addEdge(pp, p3, tp, outgoingTangent, prevFlags, END_SEGMENT); //throws bad_alloc
+ return true;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Finds an ellipse center and transformation from the unit circle to
+* that ellipse.
+* \param rh Length of the horizontal axis
+* rv Length of the vertical axis
+* rot Rotation angle
+* p0,p1 User space end points of the arc
+* c0,c1 (Return value) Unit circle space center points of the two ellipses
+* u0,u1 (Return value) Unit circle space end points of the arc
+* unitCircleToEllipse (Return value) A matrix mapping from unit circle space to user space
+* \return true if ellipse exists, false if doesn't
+* \note
+*//*-------------------------------------------------------------------*/
+
+static bool findEllipses(RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p0, const Vector2& p1, VGPathSegment segment, Vector2& c0, Vector2& c1, Vector2& u0, Vector2& u1, Matrix3x3& unitCircleToEllipse, bool& cw)
+{
+ rh = RI_ABS(rh);
+ rv = RI_ABS(rv);
+ if(rh == 0.0f || rv == 0.0f || p0 == p1)
+ return false; //degenerate ellipse
+
+ rot = RI_DEG_TO_RAD(rot);
+ unitCircleToEllipse.set((RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv, 0,
+ (RIfloat)sin(rot)*rh, (RIfloat)cos(rot)*rv, 0,
+ 0, 0, 1);
+ Matrix3x3 ellipseToUnitCircle = invert(unitCircleToEllipse);
+ //force affinity
+ ellipseToUnitCircle[2][0] = 0.0f;
+ ellipseToUnitCircle[2][1] = 0.0f;
+ ellipseToUnitCircle[2][2] = 1.0f;
+
+ // Transform p0 and p1 into unit space
+ u0 = affineTransform(ellipseToUnitCircle, p0);
+ u1 = affineTransform(ellipseToUnitCircle, p1);
+
+ Vector2 m = 0.5f * (u0 + u1);
+ Vector2 d = u0 - u1;
+
+ RIfloat lsq = (RIfloat)dot(d,d);
+ if(lsq <= 0.0f)
+ return false; //the points are coincident
+
+ RIfloat disc = (1.0f / lsq) - 0.25f;
+ if(disc < 0.0f)
+ { //the points are too far apart for a solution to exist, scale the axes so that there is a solution
+ RIfloat l = (RIfloat)sqrt(lsq);
+ rh *= 0.5f * l;
+ rv *= 0.5f * l;
+
+ //redo the computation with scaled axes
+ unitCircleToEllipse.set((RIfloat)cos(rot)*rh, -(RIfloat)sin(rot)*rv, 0,
+ (RIfloat)sin(rot)*rh, (RIfloat)cos(rot)*rv, 0,
+ 0, 0, 1);
+ ellipseToUnitCircle = invert(unitCircleToEllipse);
+ //force affinity
+ ellipseToUnitCircle[2][0] = 0.0f;
+ ellipseToUnitCircle[2][1] = 0.0f;
+ ellipseToUnitCircle[2][2] = 1.0f;
+
+ // Transform p0 and p1 into unit space
+ u0 = affineTransform(ellipseToUnitCircle, p0);
+ u1 = affineTransform(ellipseToUnitCircle, p1);
+
+ // Solve for intersecting unit circles
+ d = u0 - u1;
+ m = 0.5f * (u0 + u1);
+
+ lsq = dot(d,d);
+ if(lsq <= 0.0f)
+ return false; //the points are coincident
+
+ disc = RI_MAX(0.0f, 1.0f / lsq - 0.25f);
+ }
+
+ if(u0 == u1)
+ return false;
+
+ Vector2 sd = d * (RIfloat)sqrt(disc);
+ Vector2 sp = perpendicularCW(sd);
+ c0 = m + sp;
+ c1 = m - sp;
+
+ //choose the center point and direction
+ Vector2 cp = c0;
+ if(segment == VG_SCWARC_TO || segment == VG_LCCWARC_TO)
+ cp = c1;
+ cw = false;
+ if(segment == VG_SCWARC_TO || segment == VG_LCWARC_TO)
+ cw = true;
+
+ //move the unit circle origin to the chosen center point
+ u0 -= cp;
+ u1 -= cp;
+
+ if(u0 == u1 || isZero(u0) || isZero(u1))
+ return false;
+
+ //transform back to the original coordinate space
+ cp = affineTransform(unitCircleToEllipse, cp);
+ unitCircleToEllipse[0][2] = cp.x;
+ unitCircleToEllipse[1][2] = cp.y;
+ return true;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates an arc-to segment.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+bool Path::addArcTo(const Matrix3x3& pathToSurface, const Vector2& p0, RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p1, const Vector2& p1r, VGPathSegment segment, bool subpathHasGeometry, float strokeWidth)
+{
+ RI_UNREF(pathToSurface);
+ RI_UNREF(strokeWidth);
+ if(p0 == p1)
+ return false; //discard zero-length segments
+
+ Vector2 c0, c1, u0, u1;
+ Matrix3x3 unitCircleToEllipse;
+ bool cw;
+
+ m_numTessVertices = 0;
+ unsigned int startFlags = START_SEGMENT;
+ if(!subpathHasGeometry)
+ startFlags |= START_SUBPATH;
+
+ if(!findEllipses(rh, rv, rot, Vector2(), p1r, segment, c0, c1, u0, u1, unitCircleToEllipse, cw))
+ { //ellipses don't exist, add line instead
+ Vector2 t = normalize(p1r);
+ RI_ASSERT(!isZero(t));
+ addEdge(p0, p1, t, t, startFlags, END_SEGMENT); //throws bad_alloc
+ return true;
+ }
+
+ //compute end point tangents
+ Vector2 incomingTangent = perpendicular(u0, cw);
+ incomingTangent = affineTangentTransform(unitCircleToEllipse, incomingTangent);
+ incomingTangent = normalize(incomingTangent);
+ Vector2 outgoingTangent = perpendicular(u1, cw);
+ outgoingTangent = affineTangentTransform(unitCircleToEllipse, outgoingTangent);
+ outgoingTangent = normalize(outgoingTangent);
+ RI_ASSERT(!isZero(incomingTangent) && !isZero(outgoingTangent));
+
+ const int segments = RI_NUM_TESSELLATED_SEGMENTS;
+ Vector2 pp = p0;
+ Vector2 tp = incomingTangent;
+ unsigned int prevFlags = startFlags;
+ for(int i=1;i<segments;i++)
+ {
+ RIfloat t = (RIfloat)i / (RIfloat)segments;
+ Vector2 pn = circularLerp(u0, u1, t, cw);
+ Vector2 tn = perpendicular(pn, cw);
+ tn = affineTangentTransform(unitCircleToEllipse, tn);
+ pn = affineTransform(unitCircleToEllipse, pn) + p0;
+ tn = normalize(tn);
+ if(isZero(tn))
+ tn = tp;
+
+ addEdge(pp, pn, tp, tn, prevFlags, 0); //throws bad_alloc
+
+ pp = pn;
+ tp = tn;
+ prevFlags = 0;
+ }
+ addEdge(pp, p1, tp, outgoingTangent, prevFlags, END_SEGMENT); //throws bad_alloc
+ return true;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Tessellates a path.
+* \param
+* \return
+* \note tessellation output format: A list of vertices describing the
+* path tessellated into line segments and relevant aspects of the
+* input data. Each path segment has a start vertex, a number of
+* internal vertices (possibly zero), and an end vertex. The start
+* and end of segments and subpaths have been flagged, as well as
+* implicit and explicit close subpath segments.
+*//*-------------------------------------------------------------------*/
+
+void Path::tessellate(const Matrix3x3& pathToSurface, float strokeWidth)
+{
+ m_vertices.clear();
+
+ m_userMinx = RI_FLOAT_MAX;
+ m_userMiny = RI_FLOAT_MAX;
+ m_userMaxx = -RI_FLOAT_MAX;
+ m_userMaxy = -RI_FLOAT_MAX;
+
+ try
+ {
+ m_segmentToVertex.resize(m_segments.size());
+
+ int coordIndex = 0;
+ Vector2 s(0,0); //the beginning of the current subpath
+ Vector2 o(0,0); //the last point of the previous segment
+ Vector2 p(0,0); //the last internal control point of the previous segment, if the segment was a (regular or smooth) quadratic or cubic Bezier, or else the last point of the previous segment
+
+ //tessellate the path segments
+ coordIndex = 0;
+ s.set(0,0);
+ o.set(0,0);
+ p.set(0,0);
+ bool subpathHasGeometry = false;
+ VGPathSegment prevSegment = VG_MOVE_TO;
+ for(int i=0;i<m_segments.size();i++)
+ {
+ VGPathSegment segment = getPathSegment(m_segments[i]);
+ VGPathAbsRel absRel = getPathAbsRel(m_segments[i]);
+ int coords = segmentToNumCoordinates(segment);
+ m_segmentToVertex[i].start = m_vertices.size();
+
+ switch(segment)
+ {
+ case VG_CLOSE_PATH:
+ {
+ RI_ASSERT(coords == 0);
+ addEndPath(pathToSurface, o, s, subpathHasGeometry, CLOSE_SUBPATH);
+ p = s;
+ o = s;
+ subpathHasGeometry = false;
+ break;
+ }
+
+ case VG_MOVE_TO:
+ {
+ RI_ASSERT(coords == 2);
+ Vector2 c(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
+ if(absRel == VG_RELATIVE)
+ c += o;
+ if(prevSegment != VG_MOVE_TO && prevSegment != VG_CLOSE_PATH)
+ addEndPath(pathToSurface, o, s, subpathHasGeometry, IMPLICIT_CLOSE_SUBPATH);
+ s = c;
+ p = c;
+ o = c;
+ subpathHasGeometry = false;
+ break;
+ }
+
+ case VG_LINE_TO:
+ {
+ RI_ASSERT(coords == 2);
+ Vector2 c(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
+ if(absRel == VG_RELATIVE)
+ c += o;
+ if(addLineTo(pathToSurface, o, c, subpathHasGeometry))
+ subpathHasGeometry = true;
+ p = c;
+ o = c;
+ break;
+ }
+
+ case VG_HLINE_TO:
+ {
+ RI_ASSERT(coords == 1);
+ Vector2 c(getCoordinate(coordIndex+0), o.y);
+ if(absRel == VG_RELATIVE)
+ c.x += o.x;
+ if(addLineTo(pathToSurface, o, c, subpathHasGeometry))
+ subpathHasGeometry = true;
+ p = c;
+ o = c;
+ break;
+ }
+
+ case VG_VLINE_TO:
+ {
+ RI_ASSERT(coords == 1);
+ Vector2 c(o.x, getCoordinate(coordIndex+0));
+ if(absRel == VG_RELATIVE)
+ c.y += o.y;
+ if(addLineTo(pathToSurface, o, c, subpathHasGeometry))
+ subpathHasGeometry = true;
+ p = c;
+ o = c;
+ break;
+ }
+
+ case VG_QUAD_TO:
+ {
+ RI_ASSERT(coords == 4);
+ Vector2 c0(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
+ Vector2 c1(getCoordinate(coordIndex+2), getCoordinate(coordIndex+3));
+ if(absRel == VG_RELATIVE)
+ {
+ c0 += o;
+ c1 += o;
+ }
+ if(addQuadTo(pathToSurface, o, c0, c1, subpathHasGeometry, strokeWidth))
+ subpathHasGeometry = true;
+ p = c0;
+ o = c1;
+ break;
+ }
+
+ case VG_SQUAD_TO:
+ {
+ RI_ASSERT(coords == 2);
+ Vector2 c0 = 2.0f * o - p;
+ Vector2 c1(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
+ if(absRel == VG_RELATIVE)
+ c1 += o;
+ if(addQuadTo(pathToSurface, o, c0, c1, subpathHasGeometry, strokeWidth))
+ subpathHasGeometry = true;
+ p = c0;
+ o = c1;
+ break;
+ }
+
+ case VG_CUBIC_TO:
+ {
+ RI_ASSERT(coords == 6);
+ Vector2 c0(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
+ Vector2 c1(getCoordinate(coordIndex+2), getCoordinate(coordIndex+3));
+ Vector2 c2(getCoordinate(coordIndex+4), getCoordinate(coordIndex+5));
+ if(absRel == VG_RELATIVE)
+ {
+ c0 += o;
+ c1 += o;
+ c2 += o;
+ }
+ if(addCubicTo(pathToSurface, o, c0, c1, c2, subpathHasGeometry, strokeWidth))
+ subpathHasGeometry = true;
+ p = c1;
+ o = c2;
+ break;
+ }
+
+ case VG_SCUBIC_TO:
+ {
+ RI_ASSERT(coords == 4);
+ Vector2 c0 = 2.0f * o - p;
+ Vector2 c1(getCoordinate(coordIndex+0), getCoordinate(coordIndex+1));
+ Vector2 c2(getCoordinate(coordIndex+2), getCoordinate(coordIndex+3));
+ if(absRel == VG_RELATIVE)
+ {
+ c1 += o;
+ c2 += o;
+ }
+ if(addCubicTo(pathToSurface, o, c0, c1, c2, subpathHasGeometry, strokeWidth))
+ subpathHasGeometry = true;
+ p = c1;
+ o = c2;
+ break;
+ }
+
+ default:
+ {
+ RI_ASSERT(segment == VG_SCCWARC_TO || segment == VG_SCWARC_TO ||
+ segment == VG_LCCWARC_TO || segment == VG_LCWARC_TO);
+ RI_ASSERT(coords == 5);
+ RIfloat rh = getCoordinate(coordIndex+0);
+ RIfloat rv = getCoordinate(coordIndex+1);
+ RIfloat rot = getCoordinate(coordIndex+2);
+ Vector2 c(getCoordinate(coordIndex+3), getCoordinate(coordIndex+4));
+
+ Vector2 cr = c;
+ if(absRel == VG_ABSOLUTE)
+ cr -= o;
+ else
+ c += o;
+
+ if(addArcTo(pathToSurface, o, rh, rv, rot, c, cr, segment, subpathHasGeometry, strokeWidth))
+ subpathHasGeometry = true;
+ p = c;
+ o = c;
+ break;
+ }
+ }
+
+ if(m_vertices.size() > m_segmentToVertex[i].start)
+ { //segment produced vertices
+ m_segmentToVertex[i].end = m_vertices.size() - 1;
+ }
+ else
+ { //segment didn't produce vertices (zero-length segment). Ignore it.
+ m_segmentToVertex[i].start = m_segmentToVertex[i].end = m_vertices.size()-1;
+ }
+ prevSegment = segment;
+ coordIndex += coords;
+ }
+
+ //add an implicit MOVE_TO to the end to close the last subpath.
+ //if the subpath contained only zero-length segments, this produces the necessary geometry to get it stroked
+ // and included in path bounds. The geometry won't be included in the pointAlongPath query.
+ if(prevSegment != VG_MOVE_TO && prevSegment != VG_CLOSE_PATH)
+ addEndPath(pathToSurface, o, s, subpathHasGeometry, IMPLICIT_CLOSE_SUBPATH);
+
+ //check that the flags are correct
+#ifdef RI_DEBUG
+ int prev = -1;
+ bool subpathStarted = false;
+ bool segmentStarted = false;
+ for(int i=0;i<m_vertices.size();i++)
+ {
+ Vertex& v = m_vertices[i];
+
+ if(v.flags & START_SUBPATH)
+ {
+ RI_ASSERT(!subpathStarted);
+ RI_ASSERT(v.flags & START_SEGMENT);
+ RI_ASSERT(!(v.flags & END_SUBPATH));
+ RI_ASSERT(!(v.flags & END_SEGMENT));
+ RI_ASSERT(!(v.flags & CLOSE_SUBPATH));
+ RI_ASSERT(!(v.flags & IMPLICIT_CLOSE_SUBPATH));
+ subpathStarted = true;
+ }
+
+ if(v.flags & START_SEGMENT)
+ {
+ RI_ASSERT(subpathStarted || (v.flags & CLOSE_SUBPATH) || (v.flags & IMPLICIT_CLOSE_SUBPATH));
+ RI_ASSERT(!segmentStarted);
+ RI_ASSERT(!(v.flags & END_SUBPATH));
+ RI_ASSERT(!(v.flags & END_SEGMENT));
+ segmentStarted = true;
+ }
+
+ if( v.flags & CLOSE_SUBPATH )
+ {
+ RI_ASSERT(segmentStarted);
+ RI_ASSERT(!subpathStarted);
+ RI_ASSERT((v.flags & START_SEGMENT) || (v.flags & END_SEGMENT));
+ RI_ASSERT(!(v.flags & IMPLICIT_CLOSE_SUBPATH));
+ RI_ASSERT(!(v.flags & START_SUBPATH));
+ RI_ASSERT(!(v.flags & END_SUBPATH));
+ }
+ if( v.flags & IMPLICIT_CLOSE_SUBPATH )
+ {
+ RI_ASSERT(segmentStarted);
+ RI_ASSERT(!subpathStarted);
+ RI_ASSERT((v.flags & START_SEGMENT) || (v.flags & END_SEGMENT));
+ RI_ASSERT(!(v.flags & CLOSE_SUBPATH));
+ RI_ASSERT(!(v.flags & START_SUBPATH));
+ RI_ASSERT(!(v.flags & END_SUBPATH));
+ }
+
+ if( prev >= 0 )
+ {
+ RI_ASSERT(segmentStarted);
+ RI_ASSERT(subpathStarted || ((m_vertices[prev].flags & CLOSE_SUBPATH) && (m_vertices[i].flags & CLOSE_SUBPATH)) ||
+ ((m_vertices[prev].flags & IMPLICIT_CLOSE_SUBPATH) && (m_vertices[i].flags & IMPLICIT_CLOSE_SUBPATH)));
+ }
+
+ prev = i;
+ if(v.flags & END_SEGMENT)
+ {
+ RI_ASSERT(subpathStarted || (v.flags & CLOSE_SUBPATH) || (v.flags & IMPLICIT_CLOSE_SUBPATH));
+ RI_ASSERT(segmentStarted);
+ RI_ASSERT(!(v.flags & START_SUBPATH));
+ RI_ASSERT(!(v.flags & START_SEGMENT));
+ segmentStarted = false;
+ prev = -1;
+ }
+
+ if(v.flags & END_SUBPATH)
+ {
+ RI_ASSERT(subpathStarted);
+ RI_ASSERT(v.flags & END_SEGMENT);
+ RI_ASSERT(!(v.flags & START_SUBPATH));
+ RI_ASSERT(!(v.flags & START_SEGMENT));
+ RI_ASSERT(!(v.flags & CLOSE_SUBPATH));
+ RI_ASSERT(!(v.flags & IMPLICIT_CLOSE_SUBPATH));
+ subpathStarted = false;
+ }
+ }
+#endif //RI_DEBUG
+ }
+ catch(std::bad_alloc)
+ {
+ m_vertices.clear();
+ throw;
+ }
+}
+
+//==============================================================================================
+
+} //namespace OpenVGRI
+
+//==============================================================================================
diff --git a/ri/src/riPath.h b/ri/src/riPath.h
new file mode 100644
index 0000000..34ef5c4
--- /dev/null
+++ b/ri/src/riPath.h
@@ -0,0 +1,188 @@
+#ifndef __RIPATH_H
+#define __RIPATH_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Path class.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#ifndef _OPENVG_H
+#include "openvg.h"
+#endif
+
+#ifndef __RIMATH_H
+#include "riMath.h"
+#endif
+
+#ifndef __RIARRAY_H
+#include "riArray.h"
+#endif
+
+#ifndef __RIRASTERIZER_H
+#include "riRasterizer.h"
+#endif
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief Storage and operations for VGPath.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class Path
+{
+public:
+ Path(VGint format, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int segmentCapacityHint, int coordCapacityHint, VGbitfield caps); //throws bad_alloc
+ ~Path();
+
+ VGint getFormat() const { return m_format; }
+ VGPathDatatype getDatatype() const { return m_datatype; }
+ RIfloat getScale() const { return m_scale; }
+ RIfloat getBias() const { return m_bias; }
+ VGbitfield getCapabilities() const { return m_capabilities; }
+ void setCapabilities(VGbitfield caps) { m_capabilities = caps; }
+ int getNumSegments() const { return m_segments.size(); }
+ int getNumCoordinates() const { return m_data.size() / getBytesPerCoordinate(m_datatype); }
+ void addReference() { m_referenceCount++; }
+ int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
+
+ void clear(VGbitfield capabilities);
+ void appendData(const RIuint8* segments, int numSegments, const RIuint8* data); //throws bad_alloc
+ void append(const Path* srcPath); //throws bad_alloc
+ void modifyCoords(int startIndex, int numSegments, const RIuint8* data);
+ void transform(const Path* srcPath, const Matrix3x3& matrix); //throws bad_alloc
+ //returns true if interpolation succeeds, false if start and end paths are not compatible
+ bool interpolate(const Path* startPath, const Path* endPath, RIfloat amount); //throws bad_alloc
+ void fill(const Matrix3x3& pathToSurface, Rasterizer& rasterizer); //throws bad_alloc
+ void stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const Array<RIfloat>& dashPattern, RIfloat dashPhase, bool dashPhaseReset, RIfloat strokeWidth, VGCapStyle capStyle, VGJoinStyle joinStyle, RIfloat miterLimit); //throws bad_alloc
+
+ void getPointAlong(int startIndex, int numSegments, RIfloat distance, Vector2& p, Vector2& t); //throws bad_alloc
+ RIfloat getPathLength(int startIndex, int numSegments); //throws bad_alloc
+ void getPathBounds(RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy); //throws bad_alloc
+ void getPathTransformedBounds(const Matrix3x3& pathToSurface, RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy); //throws bad_alloc
+
+private:
+ enum VertexFlags
+ {
+ START_SUBPATH = (1<<0),
+ END_SUBPATH = (1<<1),
+ START_SEGMENT = (1<<2),
+ END_SEGMENT = (1<<3),
+ CLOSE_SUBPATH = (1<<4),
+ IMPLICIT_CLOSE_SUBPATH = (1<<5)
+ };
+ struct Vertex
+ {
+ Vertex() : userPosition(), userTangent(), pathLength(0.0f), flags(0) {}
+ Vector2 userPosition;
+ Vector2 userTangent;
+ RIfloat pathLength;
+ unsigned int flags;
+ };
+ struct StrokeVertex
+ {
+ StrokeVertex() : p(), t(), ccw(), cw(), pathLength(0.0f), flags(0), inDash(false) {}
+ Vector2 p;
+ Vector2 t;
+ Vector2 ccw;
+ Vector2 cw;
+ RIfloat pathLength;
+ unsigned int flags;
+ bool inDash;
+ };
+
+ Path(const Path&); //!< Not allowed.
+ const Path& operator=(const Path&); //!< Not allowed.
+
+ static VGPathSegment getPathSegment(RIuint8 data) { return (VGPathSegment)(data & 0x1e); }
+ static VGPathAbsRel getPathAbsRel(RIuint8 data) { return (VGPathAbsRel)(data & 0x1); }
+ static int segmentToNumCoordinates(VGPathSegment segment);
+ static int countNumCoordinates(const RIuint8* segments, int numSegments);
+ static int getBytesPerCoordinate(VGPathDatatype datatype);
+
+ static void setCoordinate(Array<RIuint8>& data, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int i, RIfloat c);
+
+ RIfloat getCoordinate(int i) const;
+ void setCoordinate(int i, RIfloat c) { setCoordinate(m_data, m_datatype, m_scale, m_bias, i, c); }
+
+ void addVertex(const Vector2& p, const Vector2& t, RIfloat pathLength, unsigned int flags); //throws bad_alloc
+ void addEdge(const Vector2& p0, const Vector2& p1, const Vector2& t0, const Vector2& t1, unsigned int startFlags, unsigned int endFlags); //throws bad_alloc
+
+ void addEndPath(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry, unsigned int flags); //throws bad_alloc
+ bool addLineTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry); //throws bad_alloc
+ bool addQuadTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, bool subpathHasGeometry, float strokeWidth); //throws bad_alloc
+ bool addCubicTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& p3, bool subpathHasGeometry, float strokeWidth); //throws bad_alloc
+ bool addArcTo(const Matrix3x3& pathToSurface, const Vector2& p0, RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p1, const Vector2& p1r, VGPathSegment segment, bool subpathHasGeometry, float strokeWidth); //throws bad_alloc
+
+ void tessellate(const Matrix3x3& pathToSurface, float strokeWidth); //throws bad_alloc
+
+ void normalizeForInterpolation(const Path* srcPath); //throws bad_alloc
+
+ void interpolateStroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth) const; //throws bad_alloc
+ void doCap(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v, RIfloat strokeWidth, VGCapStyle capStyle) const; //throws bad_alloc
+ void doJoin(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth, VGJoinStyle joinStyle, RIfloat miterLimit) const; //throws bad_alloc
+
+ //input data
+ VGint m_format;
+ VGPathDatatype m_datatype;
+ RIfloat m_scale;
+ RIfloat m_bias;
+ VGbitfield m_capabilities;
+ int m_referenceCount;
+ Array<RIuint8> m_segments;
+ Array<RIuint8> m_data;
+
+ //data produced by tessellation
+ struct VertexIndex
+ {
+ int start;
+ int end;
+ };
+ Array<Vertex> m_vertices;
+ int m_numTessVertices;
+ Array<VertexIndex> m_segmentToVertex;
+ RIfloat m_userMinx;
+ RIfloat m_userMiny;
+ RIfloat m_userMaxx;
+ RIfloat m_userMaxy;
+};
+
+//==============================================================================================
+
+} //namespace OpenVGRI
+
+//==============================================================================================
+
+#endif /* __RIPATH_H */
diff --git a/ri/src/riPixelPipe.cpp b/ri/src/riPixelPipe.cpp
new file mode 100644
index 0000000..479e8d8
--- /dev/null
+++ b/ri/src/riPixelPipe.cpp
@@ -0,0 +1,894 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Implementation of Paint and pixel pipe functionality.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "riPixelPipe.h"
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief Paint constructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Paint::Paint() :
+ m_paintType(VG_PAINT_TYPE_COLOR),
+ m_paintColor(0,0,0,1,Color::sRGBA_PRE),
+ m_inputPaintColor(0,0,0,1,Color::sRGBA),
+ m_colorRampSpreadMode(VG_COLOR_RAMP_SPREAD_PAD),
+ m_colorRampStops(),
+ m_inputColorRampStops(),
+ m_colorRampPremultiplied(VG_TRUE),
+ m_inputLinearGradientPoint0(0,0),
+ m_linearGradientPoint0(0,0),
+ m_inputLinearGradientPoint1(1,0),
+ m_linearGradientPoint1(1,0),
+ m_inputRadialGradientCenter(0,0),
+ m_radialGradientCenter(0,0),
+ m_inputRadialGradientFocalPoint(0,0),
+ m_radialGradientFocalPoint(0,0),
+ m_inputRadialGradientRadius(1.0f),
+ m_radialGradientRadius(1.0f),
+ m_patternTilingMode(VG_TILE_FILL),
+ m_pattern(NULL),
+ m_referenceCount(0)
+{
+ Paint::GradientStop gs;
+ gs.offset = 0.0f;
+ gs.color.set(0,0,0,1,Color::sRGBA);
+ m_colorRampStops.push_back(gs); //throws bad_alloc
+ gs.offset = 1.0f;
+ gs.color.set(1,1,1,1,Color::sRGBA);
+ m_colorRampStops.push_back(gs); //throws bad_alloc
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Paint destructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Paint::~Paint()
+{
+ RI_ASSERT(m_referenceCount == 0);
+ if(m_pattern)
+ {
+ m_pattern->removeInUse();
+ if(!m_pattern->removeReference())
+ RI_DELETE(m_pattern);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief PixelPipe constructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+PixelPipe::PixelPipe() :
+ m_drawable(NULL),
+ m_image(NULL),
+ m_paint(NULL),
+ m_defaultPaint(),
+ m_blendMode(VG_BLEND_SRC_OVER),
+ m_imageMode(VG_DRAW_IMAGE_NORMAL),
+ m_imageQuality(VG_IMAGE_QUALITY_FASTER),
+ m_tileFillColor(0,0,0,0,Color::sRGBA),
+ m_colorTransform(false),
+ m_colorTransformValues(),
+ m_surfaceToPaintMatrix(),
+ m_surfaceToImageMatrix()
+{
+ for(int i=0;i<8;i++)
+ m_colorTransformValues[i] = (i < 4) ? 1.0f : 0.0f;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief PixelPipe destructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+PixelPipe::~PixelPipe()
+{
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets the rendering surface.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setDrawable(Drawable* drawable)
+{
+ RI_ASSERT(drawable);
+ m_drawable = drawable;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets the blend mode.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setBlendMode(VGBlendMode blendMode)
+{
+ RI_ASSERT(blendMode >= VG_BLEND_SRC && blendMode <= VG_BLEND_ADDITIVE);
+ m_blendMode = blendMode;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets the mask image. NULL disables masking.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setMask(bool masking)
+{
+ m_masking = masking;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets the image to be drawn. NULL disables image drawing.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setImage(Image* image, VGImageMode imageMode)
+{
+ RI_ASSERT(imageMode == VG_DRAW_IMAGE_NORMAL || imageMode == VG_DRAW_IMAGE_MULTIPLY || imageMode == VG_DRAW_IMAGE_STENCIL);
+ m_image = image;
+ m_imageMode = imageMode;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets the surface-to-paint matrix.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setSurfaceToPaintMatrix(const Matrix3x3& surfaceToPaintMatrix)
+{
+ m_surfaceToPaintMatrix = surfaceToPaintMatrix;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets the surface-to-image matrix.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setSurfaceToImageMatrix(const Matrix3x3& surfaceToImageMatrix)
+{
+ m_surfaceToImageMatrix = surfaceToImageMatrix;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets image quality.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setImageQuality(VGImageQuality imageQuality)
+{
+ RI_ASSERT(imageQuality == VG_IMAGE_QUALITY_NONANTIALIASED || imageQuality == VG_IMAGE_QUALITY_FASTER || imageQuality == VG_IMAGE_QUALITY_BETTER);
+ m_imageQuality = imageQuality;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets fill color for VG_TILE_FILL tiling mode (pattern only).
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setTileFillColor(const Color& c)
+{
+ m_tileFillColor = c;
+ m_tileFillColor.clamp();
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets paint.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setPaint(const Paint* paint)
+{
+ m_paint = paint;
+ if(!m_paint)
+ m_paint = &m_defaultPaint;
+ if(m_paint->m_pattern)
+ m_tileFillColor.convert(m_paint->m_pattern->getDescriptor().internalFormat);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Color transform.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::setColorTransform(bool enable, RIfloat values[8])
+{
+ m_colorTransform = enable;
+ for(int i=0;i<4;i++)
+ {
+ m_colorTransformValues[i] = RI_CLAMP(values[i], -127.0f, 127.0f);
+ m_colorTransformValues[i+4] = RI_CLAMP(values[i+4], -1.0f, 1.0f);
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Computes the linear gradient function at (x,y).
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::linearGradient(RIfloat& g, RIfloat& rho, RIfloat x, RIfloat y) const
+{
+ RI_ASSERT(m_paint);
+ Vector2 u = m_paint->m_linearGradientPoint1 - m_paint->m_linearGradientPoint0;
+ RIfloat usq = dot(u,u);
+ if( usq <= 0.0f )
+ { //points are equal, gradient is always 1.0f
+ g = 1.0f;
+ rho = 0.0f;
+ return;
+ }
+ RIfloat oou = 1.0f / usq;
+
+ Vector2 p(x, y);
+ p = affineTransform(m_surfaceToPaintMatrix, p);
+ p -= m_paint->m_linearGradientPoint0;
+ RI_ASSERT(usq >= 0.0f);
+ g = dot(p, u) * oou;
+ RIfloat dgdx = oou * u.x * m_surfaceToPaintMatrix[0][0] + oou * u.y * m_surfaceToPaintMatrix[1][0];
+ RIfloat dgdy = oou * u.x * m_surfaceToPaintMatrix[0][1] + oou * u.y * m_surfaceToPaintMatrix[1][1];
+ rho = (RIfloat)sqrt(dgdx*dgdx + dgdy*dgdy);
+ RI_ASSERT(rho >= 0.0f);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Computes the radial gradient function at (x,y).
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::radialGradient(RIfloat &g, RIfloat &rho, RIfloat x, RIfloat y) const
+{
+ RI_ASSERT(m_paint);
+ if( m_paint->m_radialGradientRadius <= 0.0f )
+ {
+ g = 1.0f;
+ rho = 0.0f;
+ return;
+ }
+
+ RIfloat r = m_paint->m_radialGradientRadius;
+ Vector2 c = m_paint->m_radialGradientCenter;
+ Vector2 f = m_paint->m_radialGradientFocalPoint;
+ Vector2 gx(m_surfaceToPaintMatrix[0][0], m_surfaceToPaintMatrix[1][0]);
+ Vector2 gy(m_surfaceToPaintMatrix[0][1], m_surfaceToPaintMatrix[1][1]);
+
+ Vector2 fp = f - c;
+
+ //clamp the focal point inside the gradient circle
+ RIfloat fpLen = fp.length();
+ if( fpLen > 0.999f * r )
+ fp *= 0.999f * r / fpLen;
+
+ RIfloat D = -1.0f / (dot(fp,fp) - r*r);
+ Vector2 p(x, y);
+ p = affineTransform(m_surfaceToPaintMatrix, p) - c;
+ Vector2 d = p - fp;
+ RIfloat s = (RIfloat)sqrt(r*r*dot(d,d) - RI_SQR(p.x*fp.y - p.y*fp.x));
+ g = (dot(fp,d) + s) * D;
+ if(RI_ISNAN(g))
+ g = 0.0f;
+ RIfloat dgdx = D*dot(fp,gx) + (r*r*dot(d,gx) - (gx.x*fp.y - gx.y*fp.x)*(p.x*fp.y - p.y*fp.x)) * (D / s);
+ RIfloat dgdy = D*dot(fp,gy) + (r*r*dot(d,gy) - (gy.x*fp.y - gy.y*fp.x)*(p.x*fp.y - p.y*fp.x)) * (D / s);
+ rho = (RIfloat)sqrt(dgdx*dgdx + dgdy*dgdy);
+ if(RI_ISNAN(rho))
+ rho = 0.0f;
+ RI_ASSERT(rho >= 0.0f);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns the average color within an offset range in the color ramp.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static Color readStopColor(const Array<Paint::GradientStop>& colorRampStops, int i, VGboolean colorRampPremultiplied)
+{
+ RI_ASSERT(i >= 0 && i < colorRampStops.size());
+ Color c = colorRampStops[i].color;
+ RI_ASSERT(c.getInternalFormat() == Color::sRGBA);
+ if(colorRampPremultiplied)
+ c.premultiply();
+ return c;
+}
+
+Color PixelPipe::integrateColorRamp(RIfloat gmin, RIfloat gmax) const
+{
+ RI_ASSERT(gmin <= gmax);
+ RI_ASSERT(gmin >= 0.0f && gmin <= 1.0f);
+ RI_ASSERT(gmax >= 0.0f && gmax <= 1.0f);
+ RI_ASSERT(m_paint->m_colorRampStops.size() >= 2); //there are at least two stops
+
+ Color c(0,0,0,0,m_paint->m_colorRampPremultiplied ? Color::sRGBA_PRE : Color::sRGBA);
+ if(gmin == 1.0f || gmax == 0.0f)
+ return c;
+
+ int i=0;
+ for(;i<m_paint->m_colorRampStops.size()-1;i++)
+ {
+ if(gmin >= m_paint->m_colorRampStops[i].offset && gmin < m_paint->m_colorRampStops[i+1].offset)
+ {
+ RIfloat s = m_paint->m_colorRampStops[i].offset;
+ RIfloat e = m_paint->m_colorRampStops[i+1].offset;
+ RI_ASSERT(s < e);
+ RIfloat g = (gmin - s) / (e - s);
+
+ Color sc = readStopColor(m_paint->m_colorRampStops, i, m_paint->m_colorRampPremultiplied);
+ Color ec = readStopColor(m_paint->m_colorRampStops, i+1, m_paint->m_colorRampPremultiplied);
+ Color rc = (1.0f-g) * sc + g * ec;
+
+ //subtract the average color from the start of the stop to gmin
+ c -= 0.5f*(gmin - s)*(sc + rc);
+ break;
+ }
+ }
+
+ for(;i<m_paint->m_colorRampStops.size()-1;i++)
+ {
+ RIfloat s = m_paint->m_colorRampStops[i].offset;
+ RIfloat e = m_paint->m_colorRampStops[i+1].offset;
+ RI_ASSERT(s <= e);
+
+ Color sc = readStopColor(m_paint->m_colorRampStops, i, m_paint->m_colorRampPremultiplied);
+ Color ec = readStopColor(m_paint->m_colorRampStops, i+1, m_paint->m_colorRampPremultiplied);
+
+ //average of the stop
+ c += 0.5f*(e-s)*(sc + ec);
+
+ if(gmax >= m_paint->m_colorRampStops[i].offset && gmax < m_paint->m_colorRampStops[i+1].offset)
+ {
+ RIfloat g = (gmax - s) / (e - s);
+ Color rc = (1.0f-g) * sc + g * ec;
+
+ //subtract the average color from gmax to the end of the stop
+ c -= 0.5f*(e - gmax)*(rc + ec);
+ break;
+ }
+ }
+ return c;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Maps a gradient function value to a color.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Color PixelPipe::colorRamp(RIfloat gradient, RIfloat rho) const
+{
+ RI_ASSERT(m_paint);
+ RI_ASSERT(rho >= 0.0f);
+
+ Color c(0,0,0,0,m_paint->m_colorRampPremultiplied ? Color::sRGBA_PRE : Color::sRGBA);
+ Color avg;
+
+ if(rho == 0.0f)
+ { //filter size is zero or gradient is degenerate
+ switch(m_paint->m_colorRampSpreadMode)
+ {
+ case VG_COLOR_RAMP_SPREAD_PAD:
+ gradient = RI_CLAMP(gradient, 0.0f, 1.0f);
+ break;
+ case VG_COLOR_RAMP_SPREAD_REFLECT:
+ {
+ RIfloat g = RI_MOD(gradient, 2.0f);
+ gradient = (g < 1.0f) ? g : 2.0f - g;
+ break;
+ }
+ default:
+ RI_ASSERT(m_paint->m_colorRampSpreadMode == VG_COLOR_RAMP_SPREAD_REPEAT);
+ gradient = gradient - (RIfloat)floor(gradient);
+ break;
+ }
+ RI_ASSERT(gradient >= 0.0f && gradient <= 1.0f);
+
+ for(int i=0;i<m_paint->m_colorRampStops.size()-1;i++)
+ {
+ if(gradient >= m_paint->m_colorRampStops[i].offset && gradient < m_paint->m_colorRampStops[i+1].offset)
+ {
+ RIfloat s = m_paint->m_colorRampStops[i].offset;
+ RIfloat e = m_paint->m_colorRampStops[i+1].offset;
+ RI_ASSERT(s < e);
+ RIfloat g = RI_CLAMP((gradient - s) / (e - s), 0.0f, 1.0f); //clamp needed due to numerical inaccuracies
+
+ Color sc = readStopColor(m_paint->m_colorRampStops, i, m_paint->m_colorRampPremultiplied);
+ Color ec = readStopColor(m_paint->m_colorRampStops, i+1, m_paint->m_colorRampPremultiplied);
+ return (1.0f-g) * sc + g * ec; //return interpolated value
+ }
+ }
+ return readStopColor(m_paint->m_colorRampStops, m_paint->m_colorRampStops.size()-1, m_paint->m_colorRampPremultiplied);
+ }
+
+ RIfloat gmin = gradient - rho*0.5f; //filter starting from the gradient point (if starts earlier, radial gradient center will be an average of the first and the last stop, which doesn't look good)
+ RIfloat gmax = gradient + rho*0.5f;
+
+ switch(m_paint->m_colorRampSpreadMode)
+ {
+ case VG_COLOR_RAMP_SPREAD_PAD:
+ {
+ if(gmin < 0.0f)
+ c += (RI_MIN(gmax, 0.0f) - gmin) * readStopColor(m_paint->m_colorRampStops, 0, m_paint->m_colorRampPremultiplied);
+ if(gmax > 1.0f)
+ c += (gmax - RI_MAX(gmin, 1.0f)) * readStopColor(m_paint->m_colorRampStops, m_paint->m_colorRampStops.size()-1, m_paint->m_colorRampPremultiplied);
+ gmin = RI_CLAMP(gmin, 0.0f, 1.0f);
+ gmax = RI_CLAMP(gmax, 0.0f, 1.0f);
+ c += integrateColorRamp(gmin, gmax);
+ c *= 1.0f/rho;
+ c.clamp(); //clamp needed due to numerical inaccuracies
+ return c;
+ }
+
+ case VG_COLOR_RAMP_SPREAD_REFLECT:
+ {
+ avg = integrateColorRamp(0.0f, 1.0f);
+ RIfloat gmini = (RIfloat)floor(gmin);
+ RIfloat gmaxi = (RIfloat)floor(gmax);
+ c = (gmaxi + 1.0f - gmini) * avg; //full ramps
+
+ //subtract beginning
+ if(((int)gmini) & 1)
+ c -= integrateColorRamp(RI_CLAMP(1.0f - (gmin - gmini), 0.0f, 1.0f), 1.0f);
+ else
+ c -= integrateColorRamp(0.0f, RI_CLAMP(gmin - gmini, 0.0f, 1.0f));
+
+ //subtract end
+ if(((int)gmaxi) & 1)
+ c -= integrateColorRamp(0.0f, RI_CLAMP(1.0f - (gmax - gmaxi), 0.0f, 1.0f));
+ else
+ c -= integrateColorRamp(RI_CLAMP(gmax - gmaxi, 0.0f, 1.0f), 1.0f);
+ break;
+ }
+
+ default:
+ {
+ RI_ASSERT(m_paint->m_colorRampSpreadMode == VG_COLOR_RAMP_SPREAD_REPEAT);
+ avg = integrateColorRamp(0.0f, 1.0f);
+ RIfloat gmini = (RIfloat)floor(gmin);
+ RIfloat gmaxi = (RIfloat)floor(gmax);
+ c = (gmaxi + 1.0f - gmini) * avg; //full ramps
+ c -= integrateColorRamp(0.0f, RI_CLAMP(gmin - gmini, 0.0f, 1.0f)); //subtract beginning
+ c -= integrateColorRamp(RI_CLAMP(gmax - gmaxi, 0.0f, 1.0f), 1.0f); //subtract end
+ break;
+ }
+ }
+
+ //divide color by the length of the range
+ c *= 1.0f / rho;
+ c.clamp(); //clamp needed due to numerical inaccuracies
+
+ //hide aliasing by fading to the average color
+ const RIfloat fadeStart = 0.5f;
+ const RIfloat fadeMultiplier = 2.0f; //the larger, the earlier fade to average is done
+
+ if(rho < fadeStart)
+ return c;
+
+ RIfloat ratio = RI_MIN((rho - fadeStart) * fadeMultiplier, 1.0f);
+ return ratio * avg + (1.0f - ratio) * c;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Computes blend.
+* \param
+* \return
+* \note premultiplied blending formulas
+ //src
+ a = asrc
+ r = rsrc
+ //src over
+ a = asrc + adst * (1-asrc)
+ r = rsrc + rdst * (1-asrc)
+ //dst over
+ a = asrc * (1-adst) + adst
+ r = rsrc * (1-adst) + adst
+ //src in
+ a = asrc * adst
+ r = rsrc * adst
+ //dst in
+ a = adst * asrc
+ r = rdst * asrc
+ //multiply
+ a = asrc + adst * (1-asrc)
+ r = rsrc * (1-adst) + rdst * (1-asrc) + rsrc * rdst
+ //screen
+ a = asrc + adst * (1-asrc)
+ r = rsrc + rdst - rsrc * rdst
+ //darken
+ a = asrc + adst * (1-asrc)
+ r = MIN(rsrc + rdst * (1-asrc), rdst + rsrc * (1-adst))
+ //lighten
+ a = asrc + adst * (1-asrc)
+ r = MAX(rsrc + rdst * (1-asrc), rdst + rsrc * (1-adst))
+ //additive
+ a = MIN(asrc+adst,1)
+ r = rsrc + rdst
+*//*-------------------------------------------------------------------*/
+
+Color PixelPipe::blend(const Color& s, RIfloat ar, RIfloat ag, RIfloat ab, const Color& d, VGBlendMode blendMode) const
+{
+ //apply blending in the premultiplied format
+ Color r(0,0,0,0,d.getInternalFormat());
+ RI_ASSERT(s.a >= 0.0f && s.a <= 1.0f);
+ RI_ASSERT(s.r >= 0.0f && s.r <= s.a && s.r <= ar);
+ RI_ASSERT(s.g >= 0.0f && s.g <= s.a && s.g <= ag);
+ RI_ASSERT(s.b >= 0.0f && s.b <= s.a && s.b <= ab);
+ RI_ASSERT(d.a >= 0.0f && d.a <= 1.0f);
+ RI_ASSERT(d.r >= 0.0f && d.r <= d.a);
+ RI_ASSERT(d.g >= 0.0f && d.g <= d.a);
+ RI_ASSERT(d.b >= 0.0f && d.b <= d.a);
+ switch(blendMode)
+ {
+ case VG_BLEND_SRC:
+ r = s;
+ break;
+
+ case VG_BLEND_SRC_OVER:
+ r.r = s.r + d.r * (1.0f - ar);
+ r.g = s.g + d.g * (1.0f - ag);
+ r.b = s.b + d.b * (1.0f - ab);
+ r.a = s.a + d.a * (1.0f - s.a);
+ break;
+
+ case VG_BLEND_DST_OVER:
+ r.r = s.r * (1.0f - d.a) + d.r;
+ r.g = s.g * (1.0f - d.a) + d.g;
+ r.b = s.b * (1.0f - d.a) + d.b;
+ r.a = s.a * (1.0f - d.a) + d.a;
+ break;
+
+ case VG_BLEND_SRC_IN:
+ r.r = s.r * d.a;
+ r.g = s.g * d.a;
+ r.b = s.b * d.a;
+ r.a = s.a * d.a;
+ break;
+
+ case VG_BLEND_DST_IN:
+ r.r = d.r * ar;
+ r.g = d.g * ag;
+ r.b = d.b * ab;
+ r.a = d.a * s.a;
+ break;
+
+ case VG_BLEND_MULTIPLY:
+ r.r = s.r * (1.0f - d.a + d.r) + d.r * (1.0f - ar);
+ r.g = s.g * (1.0f - d.a + d.g) + d.g * (1.0f - ag);
+ r.b = s.b * (1.0f - d.a + d.b) + d.b * (1.0f - ab);
+ r.a = s.a + d.a * (1.0f - s.a);
+ break;
+
+ case VG_BLEND_SCREEN:
+ r.r = s.r + d.r * (1.0f - s.r);
+ r.g = s.g + d.g * (1.0f - s.g);
+ r.b = s.b + d.b * (1.0f - s.b);
+ r.a = s.a + d.a * (1.0f - s.a);
+ break;
+
+ case VG_BLEND_DARKEN:
+ r.r = RI_MIN(s.r + d.r * (1.0f - ar), d.r + s.r * (1.0f - d.a));
+ r.g = RI_MIN(s.g + d.g * (1.0f - ag), d.g + s.g * (1.0f - d.a));
+ r.b = RI_MIN(s.b + d.b * (1.0f - ab), d.b + s.b * (1.0f - d.a));
+ r.a = s.a + d.a * (1.0f - s.a);
+ break;
+
+ case VG_BLEND_LIGHTEN:
+ r.r = RI_MAX(s.r + d.r * (1.0f - ar), d.r + s.r * (1.0f - d.a));
+ r.g = RI_MAX(s.g + d.g * (1.0f - ag), d.g + s.g * (1.0f - d.a));
+ r.b = RI_MAX(s.b + d.b * (1.0f - ab), d.b + s.b * (1.0f - d.a));
+ //although the statement below is equivalent to r.a = s.a + d.a * (1.0f - s.a)
+ //in practice there can be a very slight difference because
+ //of the max operation in the blending formula that may cause color to exceed alpha.
+ //Because of this, we compute the result both ways and return the maximum.
+ r.a = RI_MAX(s.a + d.a * (1.0f - s.a), d.a + s.a * (1.0f - d.a));
+ break;
+
+ default:
+ RI_ASSERT(blendMode == VG_BLEND_ADDITIVE);
+ r.r = RI_MIN(s.r + d.r, 1.0f);
+ r.g = RI_MIN(s.g + d.g, 1.0f);
+ r.b = RI_MIN(s.b + d.b, 1.0f);
+ r.a = RI_MIN(s.a + d.a, 1.0f);
+ break;
+ }
+ return r;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Applies color transform.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::colorTransform(Color& c) const
+{
+ if(m_colorTransform)
+ {
+ c.unpremultiply();
+ c.luminanceToRGB();
+ c.r = c.r * m_colorTransformValues[0] + m_colorTransformValues[4];
+ c.g = c.g * m_colorTransformValues[1] + m_colorTransformValues[5];
+ c.b = c.b * m_colorTransformValues[2] + m_colorTransformValues[6];
+ c.a = c.a * m_colorTransformValues[3] + m_colorTransformValues[7];
+ c.clamp();
+ c.premultiply();
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Applies paint, image drawing, masking and blending at pixel (x,y).
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void PixelPipe::pixelPipe(int x, int y, RIfloat coverage, unsigned int sampleMask) const
+{
+ RI_ASSERT(m_drawable);
+ RI_ASSERT(sampleMask);
+ RI_ASSERT(coverage > 0.0f);
+ Color::InternalFormat dstFormat = (Color::InternalFormat)(m_drawable->getDescriptor().internalFormat | Color::PREMULTIPLIED);
+
+ //evaluate paint
+ RI_ASSERT(m_paint);
+ Color s;
+ switch(m_paint->m_paintType)
+ {
+ case VG_PAINT_TYPE_COLOR:
+ s = m_paint->m_paintColor;
+ break;
+
+ case VG_PAINT_TYPE_LINEAR_GRADIENT:
+ {
+ RIfloat g, rho;
+ linearGradient(g, rho, x+0.5f, y+0.5f);
+ s = colorRamp(g, rho);
+ RI_ASSERT((s.getInternalFormat() == Color::sRGBA && !m_paint->m_colorRampPremultiplied) || (s.getInternalFormat() == Color::sRGBA_PRE && m_paint->m_colorRampPremultiplied));
+ s.premultiply();
+ break;
+ }
+
+ case VG_PAINT_TYPE_RADIAL_GRADIENT:
+ {
+ RIfloat g, rho;
+ radialGradient(g, rho, x+0.5f, y+0.5f);
+ s = colorRamp(g, rho);
+ RI_ASSERT((s.getInternalFormat() == Color::sRGBA && !m_paint->m_colorRampPremultiplied) || (s.getInternalFormat() == Color::sRGBA_PRE && m_paint->m_colorRampPremultiplied));
+ s.premultiply();
+ break;
+ }
+
+ default:
+ RI_ASSERT(m_paint->m_paintType == VG_PAINT_TYPE_PATTERN);
+ if(m_paint->m_pattern)
+ s = m_paint->m_pattern->resample(x+0.5f, y+0.5f, m_surfaceToPaintMatrix, m_imageQuality, m_paint->m_patternTilingMode, m_tileFillColor);
+ else
+ s = m_paint->m_paintColor;
+ break;
+ }
+ s.assertConsistency();
+
+ //apply image (vgDrawImage only)
+ //1. paint: convert paint to dst space
+ //2. image: convert image to dst space
+ //3. paint MULTIPLY image: convert paint to image number of channels, multiply with image, and convert to dst
+ //4. paint STENCIL image: convert paint to dst, convert image to dst number of channels, multiply
+
+ //color transform:
+ //paint => transform paint color
+ //image normal => transform image color
+ //image multiply => transform paint*image color
+ //image stencil => transform paint color
+
+ RIfloat ar = 0.0f, ag = 0.0f, ab = 0.0f;
+ if(m_image)
+ {
+ Color im = m_image->resample(x+0.5f, y+0.5f, m_surfaceToImageMatrix, m_imageQuality, VG_TILE_PAD, Color(0,0,0,0,m_image->getDescriptor().internalFormat));
+ im.assertConsistency();
+
+ switch(m_imageMode)
+ {
+ case VG_DRAW_IMAGE_NORMAL:
+ s = im;
+ colorTransform(s);
+ ar = s.a;
+ ag = s.a;
+ ab = s.a;
+ s.convert(dstFormat); //convert image color to destination color space
+ break;
+ case VG_DRAW_IMAGE_MULTIPLY:
+ //the result will be in image color space, except when paint is RGB and image is L the result will be RGB.
+ //paint == RGB && image == RGB: RGB*RGB
+ //paint == RGB && image == L : RGB*LLL
+ //paint == L && image == RGB: LLL*RGB
+ //paint == L && image == L : L*L
+ RI_ASSERT(m_surfaceToPaintMatrix.isAffine());
+ if(!s.isLuminance() && im.isLuminance())
+ im.convert((Color::InternalFormat)(im.getInternalFormat() & ~Color::LUMINANCE));
+ im.r *= s.r;
+ im.g *= s.g;
+ im.b *= s.b;
+ im.a *= s.a;
+ s = im; //use image color space
+ colorTransform(s);
+ ar = s.a;
+ ag = s.a;
+ ab = s.a;
+ s.convert(dstFormat); //convert resulting color to destination color space
+ break;
+ default:
+ //the result will be in paint color space.
+ //dst == RGB && image == RGB: RGB*RGB
+ //dst == RGB && image == L : RGB*LLL
+ //dst == L && image == RGB: L*(0.2126 R + 0.7152 G + 0.0722 B)
+ //dst == L && image == L : L*L
+ RI_ASSERT(m_imageMode == VG_DRAW_IMAGE_STENCIL);
+ if(dstFormat & Color::LUMINANCE && !im.isLuminance())
+ {
+ im.r = im.g = im.b = RI_MIN(0.2126f*im.r + 0.7152f*im.g + 0.0722f*im.b, im.a);
+ }
+ RI_ASSERT(m_surfaceToPaintMatrix.isAffine());
+ //s and im are both in premultiplied format. Each image channel acts as an alpha channel.
+ colorTransform(s);
+ s.convert(dstFormat); //convert paint color to destination space already here, since convert cannot deal with per channel alphas used in this mode.
+ //compute per channel alphas
+ ar = s.a * im.r;
+ ag = s.a * im.g;
+ ab = s.a * im.b;
+ //premultiply each channel by per channel alphas from the image
+ s.r *= im.r;
+ s.g *= im.g;
+ s.b *= im.b;
+ s.a *= im.a;
+ //in nonpremultiplied form the result is
+ // s.rgb = paint.a * paint.rgb * image.a * image.rgb
+ // s.a = paint.a * image.a
+ // argb = paint.a * image.a * image.rgb
+ break;
+ }
+ }
+ else
+ { //paint only
+ colorTransform(s);
+ ar = s.a;
+ ag = s.a;
+ ab = s.a;
+ s.convert(dstFormat); //convert paint color to destination color space
+ }
+ RI_ASSERT(s.getInternalFormat() == Color::lRGBA_PRE || s.getInternalFormat() == Color::sRGBA_PRE || s.getInternalFormat() == Color::lLA_PRE || s.getInternalFormat() == Color::sLA_PRE);
+ s.assertConsistency();
+
+ Surface* colorBuffer = m_drawable->getColorBuffer();
+ Surface* maskBuffer = m_drawable->getMaskBuffer();
+ RI_ASSERT(colorBuffer);
+
+ if(m_drawable->getNumSamples() == 1)
+ { //coverage-based antialiasing
+ RIfloat cov = coverage;
+ if(m_masking && maskBuffer)
+ {
+ cov *= maskBuffer->readMaskCoverage(x, y);
+ if(cov == 0.0f)
+ return;
+ }
+
+ //read destination color
+ Color d = colorBuffer->readSample(x, y, 0);
+ d.premultiply();
+ RI_ASSERT(dstFormat == Color::lRGBA_PRE || dstFormat == Color::sRGBA_PRE || dstFormat == Color::lLA_PRE || dstFormat == Color::sLA_PRE);
+
+ //blend
+ Color r = blend(s, ar, ag, ab, d, m_blendMode);
+
+ //apply antialiasing in linear color space
+ Color::InternalFormat aaFormat = (dstFormat & Color::LUMINANCE) ? Color::lLA_PRE : Color::lRGBA_PRE;
+ r.convert(aaFormat);
+ d.convert(aaFormat);
+ r = r * cov + d * (1.0f - cov);
+
+ //write result to the destination surface
+ r.convert(colorBuffer->getDescriptor().internalFormat);
+ colorBuffer->writeSample(x, y, 0, r);
+ }
+ else
+ { //multisampling FSAA
+ if(m_masking && maskBuffer)
+ {
+ sampleMask &= maskBuffer->readMaskMSAA(x, y);
+ if(!sampleMask)
+ return;
+ }
+
+ {
+ for(int i=0;i<m_drawable->getNumSamples();i++)
+ {
+ if(sampleMask & (1<<i)) //1-bit coverage
+ {
+ //read destination color
+ Color d = colorBuffer->readSample(x, y, i);
+
+ d.premultiply();
+ RI_ASSERT(dstFormat == Color::lRGBA_PRE || dstFormat == Color::sRGBA_PRE || dstFormat == Color::lLA_PRE || dstFormat == Color::sLA_PRE);
+
+ //blend
+ Color r = blend(s, ar, ag, ab, d, m_blendMode);
+
+ //write result to the destination surface
+ r.convert(colorBuffer->getDescriptor().internalFormat);
+ colorBuffer->writeSample(x, y, i, r);
+ }
+ }
+ }
+ }
+}
+
+//=======================================================================
+
+} //namespace OpenVGRI
diff --git a/ri/src/riPixelPipe.h b/ri/src/riPixelPipe.h
new file mode 100644
index 0000000..1d49b9c
--- /dev/null
+++ b/ri/src/riPixelPipe.h
@@ -0,0 +1,155 @@
+#ifndef __RIPIXELPIPE_H
+#define __RIPIXELPIPE_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Paint and PixelPipe classes.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#ifndef __RIMATH_H
+#include "riMath.h"
+#endif
+
+#ifndef __RIIMAGE_H
+#include "riImage.h"
+#endif
+
+//=======================================================================
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief Storage and operations for VGPaint.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class Paint
+{
+public:
+ Paint();
+ ~Paint();
+ void addReference() { m_referenceCount++; }
+ int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
+
+ struct GradientStop
+ {
+ GradientStop() : offset(0.0f), color(0.0f, 0.0f, 0.0f, 0.0f, Color::sRGBA) {}
+ RIfloat offset;
+ Color color;
+ };
+
+ VGPaintType m_paintType;
+ Color m_paintColor;
+ Color m_inputPaintColor;
+ VGColorRampSpreadMode m_colorRampSpreadMode;
+ Array<GradientStop> m_colorRampStops;
+ Array<GradientStop> m_inputColorRampStops;
+ VGboolean m_colorRampPremultiplied;
+ Vector2 m_inputLinearGradientPoint0;
+ Vector2 m_inputLinearGradientPoint1;
+ Vector2 m_inputRadialGradientCenter;
+ Vector2 m_inputRadialGradientFocalPoint;
+ RIfloat m_inputRadialGradientRadius;
+ Vector2 m_linearGradientPoint0;
+ Vector2 m_linearGradientPoint1;
+ Vector2 m_radialGradientCenter;
+ Vector2 m_radialGradientFocalPoint;
+ RIfloat m_radialGradientRadius;
+ VGTilingMode m_patternTilingMode;
+ Image* m_pattern;
+private:
+ Paint(const Paint&); //!< Not allowed.
+ const Paint& operator=(const Paint&); //!< Not allowed.
+
+ int m_referenceCount;
+};
+
+/*-------------------------------------------------------------------*//*!
+* \brief Encapsulates all information needed for painting a pixel.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class PixelPipe
+{
+public:
+ PixelPipe(); //throws bad_alloc
+ ~PixelPipe();
+
+ void pixelPipe(int x, int y, RIfloat coverage, unsigned int sampleMask) const; //rasterizer calls this function for each pixel
+
+ void setDrawable(Drawable* drawable);
+ void setBlendMode(VGBlendMode blendMode);
+ void setMask(bool masking);
+ void setImage(Image* image, VGImageMode imageMode); //image = NULL disables drawImage functionality
+ void setSurfaceToPaintMatrix(const Matrix3x3& surfaceToPaintMatrix);
+ void setSurfaceToImageMatrix(const Matrix3x3& surfaceToImageMatrix);
+ void setImageQuality(VGImageQuality imageQuality);
+ void setTileFillColor(const Color& c);
+ void setPaint(const Paint* paint);
+ void setColorTransform(bool enable, RIfloat values[8]);
+
+private:
+ void linearGradient(RIfloat& g, RIfloat& rho, RIfloat x, RIfloat y) const;
+ void radialGradient(RIfloat& g, RIfloat& rho, RIfloat x, RIfloat y) const;
+ Color integrateColorRamp(RIfloat gmin, RIfloat gmax) const;
+ Color colorRamp(RIfloat gradient, RIfloat rho) const;
+ Color blend(const Color& s, RIfloat ar, RIfloat ag, RIfloat ab, const Color& d, VGBlendMode blendMode) const;
+ void colorTransform(Color& c) const;
+
+ PixelPipe(const PixelPipe&); //!< Not allowed.
+ const PixelPipe& operator=(const PixelPipe&); //!< Not allowed.
+
+ Drawable* m_drawable;
+ bool m_masking;
+ Image* m_image;
+ const Paint* m_paint;
+ Paint m_defaultPaint;
+ VGBlendMode m_blendMode;
+ VGImageMode m_imageMode;
+ VGImageQuality m_imageQuality;
+ Color m_tileFillColor;
+ bool m_colorTransform;
+ RIfloat m_colorTransformValues[8];
+ Matrix3x3 m_surfaceToPaintMatrix;
+ Matrix3x3 m_surfaceToImageMatrix;
+};
+
+//=======================================================================
+
+} //namespace OpenVGRI
+
+//=======================================================================
+
+#endif /* __RIPIXELPIPE_H */
diff --git a/ri/src/riRasterizer.cpp b/ri/src/riRasterizer.cpp
new file mode 100644
index 0000000..9d75e21
--- /dev/null
+++ b/ri/src/riRasterizer.cpp
@@ -0,0 +1,499 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Implementation of polygon rasterizer.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include "riRasterizer.h"
+
+//==============================================================================================
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief Rasterizer constructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Rasterizer::Rasterizer() :
+ m_edges(),
+ m_scissorEdges(),
+ m_scissor(false),
+ m_samples(),
+ m_numSamples(0),
+ m_numFSAASamples(0),
+ m_sumWeights(0.0f),
+ m_sampleRadius(0.0f),
+ m_vpx(0),
+ m_vpy(0),
+ m_vpwidth(0),
+ m_vpheight(0),
+ m_fillRule(VG_EVEN_ODD),
+ m_pixelPipe(NULL),
+ m_covBuffer(NULL)
+{}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Rasterizer destructor.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+Rasterizer::~Rasterizer()
+{
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Removes all appended edges.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Rasterizer::clear()
+{
+ m_edges.clear();
+ m_edgeMin.set(RI_FLOAT_MAX, RI_FLOAT_MAX);
+ m_edgeMax.set(-RI_FLOAT_MAX, -RI_FLOAT_MAX);
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Appends an edge to the rasterizer.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Rasterizer::addBBox(const Vector2& v)
+{
+ if(v.x < m_edgeMin.x) m_edgeMin.x = v.x;
+ if(v.y < m_edgeMin.y) m_edgeMin.y = v.y;
+ if(v.x > m_edgeMax.x) m_edgeMax.x = v.x;
+ if(v.y > m_edgeMax.y) m_edgeMax.y = v.y;
+}
+
+void Rasterizer::addEdge(const Vector2& v0, const Vector2& v1)
+{
+ if( m_edges.size() >= RI_MAX_EDGES )
+ throw std::bad_alloc(); //throw an out of memory error if there are too many edges
+
+ if(v0.y == v1.y)
+ return; //skip horizontal edges (they don't affect rasterization since we scan horizontally)
+
+ Edge e;
+ if(v0.y < v1.y)
+ { //edge is going upward
+ e.v0 = v0;
+ e.v1 = v1;
+ e.direction = 1;
+ }
+ else
+ { //edge is going downward
+ e.v0 = v1;
+ e.v1 = v0;
+ e.direction = -1;
+ }
+
+ addBBox(v0);
+ addBBox(v1);
+
+ m_edges.push_back(e); //throws bad_alloc
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Set up rasterizer
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Rasterizer::setup(int vpx, int vpy, int vpwidth, int vpheight, VGFillRule fillRule, const PixelPipe* pixelPipe, unsigned int* covBuffer)
+{
+ RI_ASSERT(vpwidth >= 0 && vpheight >= 0);
+ RI_ASSERT(vpx + vpwidth >= vpx && vpy + vpheight >= vpy);
+ RI_ASSERT(fillRule == VG_EVEN_ODD || fillRule == VG_NON_ZERO);
+ RI_ASSERT(pixelPipe || covBuffer);
+ m_vpx = vpx;
+ m_vpy = vpy;
+ m_vpwidth = vpwidth;
+ m_vpheight = vpheight;
+ m_fillRule = fillRule;
+ m_pixelPipe = pixelPipe;
+ m_covBuffer = covBuffer;
+ m_covMinx = vpx+vpwidth;
+ m_covMiny = vpy+vpheight;
+ m_covMaxx = vpx;
+ m_covMaxy = vpy;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Sets scissor rectangles.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Rasterizer::setScissor(const Array<Rectangle>& scissors)
+{
+ m_scissor = true;
+ try
+ {
+ m_scissorEdges.clear();
+ for(int i=0;i<scissors.size();i++)
+ {
+ if(scissors[i].width > 0 && scissors[i].height > 0)
+ {
+ ScissorEdge e;
+ e.miny = scissors[i].y;
+ e.maxy = RI_INT_ADDSATURATE(scissors[i].y, scissors[i].height);
+
+ e.x = scissors[i].x;
+ e.direction = 1;
+ m_scissorEdges.push_back(e); //throws bad_alloc
+ e.x = RI_INT_ADDSATURATE(scissors[i].x, scissors[i].width);
+ e.direction = -1;
+ m_scissorEdges.push_back(e); //throws bad_alloc
+ }
+ }
+ }
+ catch(std::bad_alloc)
+ {
+ m_scissorEdges.clear();
+ throw;
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Returns a radical inverse of a given integer for Hammersley
+* point set.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static double radicalInverseBase2(unsigned int i)
+{
+ if( i == 0 )
+ return 0.0;
+ double p = 0.0;
+ double f = 0.5;
+ double ff = f;
+ for(unsigned int j=0;j<32;j++)
+ {
+ if( i & (1<<j) )
+ p += f;
+ f *= ff;
+ }
+ return p;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Calls PixelPipe::pixelPipe for each pixel with coverage greater
+* than zero.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+int Rasterizer::setupSamplingPattern(VGRenderingQuality renderingQuality, int numFSAASamples)
+{
+ RI_ASSERT(renderingQuality == VG_RENDERING_QUALITY_NONANTIALIASED ||
+ renderingQuality == VG_RENDERING_QUALITY_FASTER ||
+ renderingQuality == VG_RENDERING_QUALITY_BETTER);
+ RI_ASSERT(numFSAASamples > 0 && numFSAASamples <= RI_MAX_SAMPLES);
+
+ //make a sampling pattern
+ m_sumWeights = 0.0f;
+ m_sampleRadius = 0.0f; //max offset of the sampling points from a pixel center
+ m_numFSAASamples = numFSAASamples;
+ if(numFSAASamples == 1)
+ {
+ if(renderingQuality == VG_RENDERING_QUALITY_NONANTIALIASED)
+ {
+ m_numSamples = 1;
+ m_samples[0].x = 0.0f;
+ m_samples[0].y = 0.0f;
+ m_samples[0].weight = 1.0f;
+ m_sampleRadius = 0.0f;
+ m_sumWeights = 1.0f;
+ }
+ else if(renderingQuality == VG_RENDERING_QUALITY_FASTER)
+ { //box filter of diameter 1.0f, 8-queen sampling pattern
+ m_numSamples = 8;
+ m_samples[0].x = 3;
+ m_samples[1].x = 7;
+ m_samples[2].x = 0;
+ m_samples[3].x = 2;
+ m_samples[4].x = 5;
+ m_samples[5].x = 1;
+ m_samples[6].x = 6;
+ m_samples[7].x = 4;
+ for(int i=0;i<m_numSamples;i++)
+ {
+ m_samples[i].x = (m_samples[i].x + 0.5f) / (RScalar)m_numSamples - 0.5f;
+ m_samples[i].y = ((RScalar)i + 0.5f) / (RScalar)m_numSamples - 0.5f;
+ m_samples[i].weight = 1.0f / (RScalar)m_numSamples;
+ m_sumWeights += m_samples[i].weight;
+ }
+ m_sampleRadius = 0.5f;
+ }
+ else
+ {
+ RI_ASSERT(renderingQuality == VG_RENDERING_QUALITY_BETTER);
+ m_numSamples = RI_MAX_SAMPLES;
+ m_sampleRadius = 0.75f;
+ for(int i=0;i<m_numSamples;i++)
+ { //Gaussian filter, implemented using Hammersley point set for sample point locations
+ RScalar x = (RScalar)radicalInverseBase2(i);
+ RScalar y = ((RScalar)i + 0.5f) / (RScalar)m_numSamples;
+ RI_ASSERT(x >= 0.0f && x < 1.0f);
+ RI_ASSERT(y >= 0.0f && y < 1.0f);
+
+ //map unit square to unit circle
+ RScalar r = (RScalar)sqrt(x) * m_sampleRadius;
+ x = r * (RScalar)sin(y*2.0f*PI);
+ y = r * (RScalar)cos(y*2.0f*PI);
+ m_samples[i].weight = (RScalar)exp(-0.5f * RI_SQR(r/m_sampleRadius));
+
+ RI_ASSERT(x >= -1.5f && x <= 1.5f && y >= -1.5f && y <= 1.5f); //the specification restricts the filter radius to be less than or equal to 1.5
+
+ m_samples[i].x = x;
+ m_samples[i].y = y;
+ m_sumWeights += m_samples[i].weight;
+ }
+ }
+ }
+ else
+ { //box filter
+ m_numSamples = numFSAASamples;
+ RI_ASSERT(numFSAASamples >= 1 && numFSAASamples <= 32); //sample mask is a 32-bit uint => can't support more than 32 samples
+ //use Hammersley point set as a sampling pattern
+ for(int i=0;i<m_numSamples;i++)
+ {
+ m_samples[i].x = (RScalar)radicalInverseBase2(i) + 1.0f / (RScalar)(m_numSamples<<1) - 0.5f;
+ m_samples[i].y = ((RScalar)i + 0.5f) / (RScalar)m_numSamples - 0.5f;
+ m_samples[i].weight = 1.0f;
+ RI_ASSERT(m_samples[i].x > -0.5f && m_samples[i].x < 0.5f);
+ RI_ASSERT(m_samples[i].y > -0.5f && m_samples[i].y < 0.5f);
+ }
+ m_sumWeights = (RScalar)m_numSamples;
+ m_sampleRadius = 0.5f;
+ }
+ return m_numSamples;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief Calls PixelPipe::pixelPipe for each pixel with coverage greater
+* than zero.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+void Rasterizer::fill()
+{
+ if(m_scissor && !m_scissorEdges.size())
+ return; //scissoring is on, but there are no scissor rectangles => nothing is visible
+
+ //proceed scanline by scanline
+ //keep track of edges that can intersect the pixel filters of the current scanline (Active Edge Table)
+ //until all pixels of the scanline have been processed
+ // for all sampling points of the current pixel
+ // determine the winding number using edge functions
+ // add filter weight to coverage
+ // divide coverage by the number of samples
+ // determine a run of pixels with constant coverage
+ // call fill callback for each pixel of the run
+
+ int fillRuleMask = 1;
+ if(m_fillRule == VG_NON_ZERO)
+ fillRuleMask = -1;
+
+ int bbminx = (int)floor(m_edgeMin.x);
+ int bbminy = (int)floor(m_edgeMin.y);
+ int bbmaxx = (int)floor(m_edgeMax.x)+1;
+ int bbmaxy = (int)floor(m_edgeMax.y)+1;
+ int sx = RI_INT_MAX(m_vpx, bbminx);
+ int ex = RI_INT_MIN(m_vpx+m_vpwidth, bbmaxx);
+ int sy = RI_INT_MAX(m_vpy, bbminy);
+ int ey = RI_INT_MIN(m_vpy+m_vpheight, bbmaxy);
+ if(sx < m_covMinx) m_covMinx = sx;
+ if(sy < m_covMiny) m_covMiny = sy;
+ if(ex > m_covMaxx) m_covMaxx = ex;
+ if(ey > m_covMaxy) m_covMaxy = ey;
+
+ //fill the screen
+ Array<ActiveEdge> aet;
+ Array<ScissorEdge> scissorAet;
+ for(int j=sy;j<ey;j++)
+ {
+ //gather scissor edges intersecting this scanline
+ scissorAet.clear();
+ if( m_scissor )
+ {
+ for(int e=0;e<m_scissorEdges.size();e++)
+ {
+ const ScissorEdge& se = m_scissorEdges[e];
+ if(j >= se.miny && j < se.maxy)
+ scissorAet.push_back(m_scissorEdges[e]); //throws bad_alloc
+ }
+ if(!scissorAet.size())
+ continue; //scissoring is on, but there are no scissor rectangles on this scanline
+ }
+
+ //simple AET: scan through all the edges and pick the ones intersecting this scanline
+ aet.clear();
+ for(int e=0;e<m_edges.size();e++)
+ {
+ RScalar cminy = (RScalar)j - m_sampleRadius + 0.5f;
+ RScalar cmaxy = (RScalar)j + m_sampleRadius + 0.5f;
+ const Edge& ed = m_edges[e];
+ RI_ASSERT(ed.v0.y <= ed.v1.y); //horizontal edges should have been dropped already
+
+ ActiveEdge ae;
+ ae.v0 = ed.v0;
+ ae.v1 = ed.v1;
+ ae.direction = ed.direction;
+
+ if(cmaxy >= ae.v0.y && cminy < ae.v1.y)
+ {
+ ae.n.set(ae.v0.y - ae.v1.y, ae.v1.x - ae.v0.x); //edge normal
+ ae.cnst = ae.v0.x * ae.n.x + ae.v0.y * ae.n.y; //distance of v0 from the origin along the edge normal
+
+ //compute edge min and max x-coordinates for this scanline
+ Vector2 vd(ae.v1.x - ae.v0.x, ae.v1.y - ae.v0.y);
+ RScalar wl = 1.0f / vd.y;
+ RScalar sx = ae.v0.x + vd.x * (cminy - ae.v0.y) * wl;
+ RScalar ex = ae.v0.x + vd.x * (cmaxy - ae.v0.y) * wl;
+ RScalar bminx = RI_MIN(ae.v0.x, ae.v1.x);
+ RScalar bmaxx = RI_MAX(ae.v0.x, ae.v1.x);
+ sx = RI_CLAMP(sx, bminx, bmaxx);
+ ex = RI_CLAMP(ex, bminx, bmaxx);
+ ae.minx = RI_MIN(sx,ex);
+ ae.maxx = RI_MAX(sx,ex);
+ aet.push_back(ae); //throws bad_alloc
+ }
+ }
+ if(!aet.size())
+ continue; //no edges on the whole scanline, skip it
+
+ //sort AET by edge minx
+ aet.sort();
+
+ //sort scissor AET by edge x
+ scissorAet.sort();
+
+ //fill the scanline
+ int scissorWinding = m_scissor ? 0 : 1; //if scissoring is off, winding is always 1
+ int scissorIndex = 0;
+ int aes = 0;
+ int aen = 0;
+ for(int i=sx;i<ex;)
+ {
+ Vector2 pc(i + 0.5f, j + 0.5f); //pixel center
+
+ //find edges that intersect or are to the left of the pixel antialiasing filter
+ while(aes < aet.size() && pc.x + m_sampleRadius >= aet[aes].minx)
+ aes++;
+ //edges [0,aes[ may have an effect on winding, and need to be evaluated while sampling
+
+ //compute coverage
+ RScalar coverage = 0.0f;
+ unsigned int sampleMask = 0;
+ for(int s=0;s<m_numSamples;s++)
+ {
+ Vector2 sp = pc; //sampling point
+ sp.x += m_samples[s].x;
+ sp.y += m_samples[s].y;
+
+ //compute winding number by evaluating the edge functions of edges to the left of the sampling point
+ int winding = 0;
+ for(int e=0;e<aes;e++)
+ {
+ if(sp.y >= aet[e].v0.y && sp.y < aet[e].v1.y)
+ { //evaluate edge function to determine on which side of the edge the sampling point lies
+ RScalar side = sp.x * aet[e].n.x + sp.y * aet[e].n.y - aet[e].cnst;
+ if(side <= 0.0f) //implicit tie breaking: a sampling point on an opening edge is in, on a closing edge it's out
+ {
+ winding += aet[e].direction;
+ }
+ }
+ }
+ if(winding & fillRuleMask)
+ {
+ coverage += m_samples[s].weight;
+ sampleMask |= (unsigned int)(1<<s);
+ }
+ }
+
+ //constant coverage optimization:
+ //scan AET from left to right and skip all the edges that are completely to the left of the pixel filter.
+ //since AET is sorted by minx, the edge we stop at is the leftmost of the edges we haven't passed yet.
+ //if that edge is to the right of this pixel, coverage is constant between this pixel and the start of the edge.
+ while(aen < aet.size() && aet[aen].maxx < pc.x - m_sampleRadius - 0.01f) //0.01 is a safety region to prevent too aggressive optimization due to numerical inaccuracy
+ aen++;
+
+ int endSpan = m_vpx + m_vpwidth; //endSpan is the first pixel NOT part of the span
+ if(aen < aet.size())
+ endSpan = RI_INT_MAX(i+1, RI_INT_MIN(endSpan, (int)ceil(aet[aen].minx - m_sampleRadius - 0.5f)));
+
+ coverage /= m_sumWeights;
+ RI_ASSERT(coverage >= 0.0f && coverage <= 1.0f);
+
+ //fill a run of pixels with constant coverage
+ if(sampleMask)
+ {
+ for(;i<endSpan;i++)
+ {
+ //update scissor winding number
+ while(scissorIndex < scissorAet.size() && scissorAet[scissorIndex].x <= i)
+ scissorWinding += scissorAet[scissorIndex++].direction;
+ RI_ASSERT(scissorWinding >= 0);
+
+ if(scissorWinding)
+ {
+ if(m_covBuffer)
+ m_covBuffer[j*m_vpwidth+i] |= (RIuint32)sampleMask;
+ else
+ m_pixelPipe->pixelPipe(i, j, coverage, sampleMask);
+ }
+ }
+ }
+ i = endSpan;
+ }
+ }
+}
+
+//=======================================================================
+
+} //namespace OpenVGRI
diff --git a/ri/src/riRasterizer.h b/ri/src/riRasterizer.h
new file mode 100644
index 0000000..37b5cfc
--- /dev/null
+++ b/ri/src/riRasterizer.h
@@ -0,0 +1,173 @@
+#ifndef __RIRASTERIZER_H
+#define __RIRASTERIZER_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.1 Reference Implementation
+ * -----------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Rasterizer class.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#ifndef __RIMATH_H
+#include "riMath.h"
+#endif
+
+#ifndef __RIARRAY_H
+#include "riArray.h"
+#endif
+
+#ifndef __RIPIXELPIPE_H
+#include "riPixelPipe.h"
+#endif
+
+//=======================================================================
+
+namespace OpenVGRI
+{
+
+/*-------------------------------------------------------------------*//*!
+* \brief Scalar and vector data types used by the rasterizer.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+typedef RIfloat RScalar; //change this if you want to have different precision for rasterizer scalars and RIfloat
+
+struct RVector2
+{
+ RI_INLINE RVector2() { }
+ RI_INLINE RVector2(const Vector2& v) { x = v.x; y = v.y; }
+ RI_INLINE RVector2(RIfloat vx, RIfloat vy) { x = vx; y = vy; }
+ RI_INLINE void set(RIfloat vx, RIfloat vy) { x = vx; y = vy; }
+ RScalar x;
+ RScalar y;
+};
+
+/*-------------------------------------------------------------------*//*!
+* \brief Converts a set of edges to coverage values for each pixel and
+* calls PixelPipe::pixelPipe for painting a pixel.
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+class Rasterizer
+{
+public:
+ Rasterizer(); //throws bad_alloc
+ ~Rasterizer();
+
+ void setup(int vpx, int vpy, int vpwidth, int vpheight, VGFillRule fillRule, const PixelPipe* pixelPipe, RIuint32* covBuffer);
+ void setScissor(const Array<Rectangle>& scissors); //throws bad_alloc
+
+ void clear();
+ void addEdge(const Vector2& v0, const Vector2& v1); //throws bad_alloc
+
+ int setupSamplingPattern(VGRenderingQuality renderingQuality, int numFSAASamples);
+ void fill(); //throws bad_alloc
+
+ void getBBox(int& sx, int& sy, int& ex, int& ey) const { sx = m_covMinx; sy = m_covMiny; ex = m_covMaxx; ey = m_covMaxy; }
+private:
+ Rasterizer(const Rasterizer&); //!< Not allowed.
+ const Rasterizer& operator=(const Rasterizer&); //!< Not allowed.
+
+ struct ScissorEdge
+ {
+ ScissorEdge() : x(0), miny(0), maxy(0), direction(0) {}
+ bool operator<(const ScissorEdge& e) const { return x < e.x; }
+ int x;
+ int miny;
+ int maxy;
+ int direction; //1 start, -1 end
+ };
+
+ struct Edge
+ {
+ Edge() : v0(), v1(), direction(1) {}
+ bool operator<(const Edge& e) const { return v0.y < e.v0.y; }
+ RVector2 v0;
+ RVector2 v1;
+ int direction;
+ };
+
+ struct ActiveEdge
+ {
+ ActiveEdge() : v0(), v1(), direction(0), minx(0.0f), maxx(0.0f), n(), cnst(0.0f) {}
+ bool operator<(const ActiveEdge& e) const { return minx < e.minx; }
+ RVector2 v0;
+ RVector2 v1;
+ int direction; //-1 down, 1 up
+ RScalar minx; //for the current scanline
+ RScalar maxx; //for the current scanline
+ RVector2 n;
+ RScalar cnst;
+ };
+
+ struct Sample
+ {
+ Sample() : x(0.0f), y(0.0f), weight(0.0f) {}
+ RScalar x;
+ RScalar y;
+ RScalar weight;
+ };
+
+ void addBBox(const Vector2& v);
+
+ Array<Edge> m_edges;
+ Array<ScissorEdge> m_scissorEdges;
+ bool m_scissor;
+
+ Sample m_samples[RI_MAX_SAMPLES];
+ int m_numSamples;
+ int m_numFSAASamples;
+ RScalar m_sumWeights;
+ RScalar m_sampleRadius;
+
+ Vector2 m_edgeMin;
+ Vector2 m_edgeMax;
+ int m_covMinx;
+ int m_covMiny;
+ int m_covMaxx;
+ int m_covMaxy;
+ int m_vpx;
+ int m_vpy;
+ int m_vpwidth;
+ int m_vpheight;
+ VGFillRule m_fillRule;
+ const PixelPipe* m_pixelPipe;
+ RIuint32* m_covBuffer;
+};
+
+//=======================================================================
+
+} //namespace OpenVGRI
+
+//=======================================================================
+
+#endif /* __RIRASTERIZER_H */
diff --git a/ri/src/riVGU.cpp b/ri/src/riVGU.cpp
new file mode 100644
index 0000000..b435b14
--- /dev/null
+++ b/ri/src/riVGU.cpp
@@ -0,0 +1,469 @@
+/*------------------------------------------------------------------------
+ *
+ * VGU library for OpenVG 1.1 Reference Implementation
+ * ---------------------------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Implementation of the VGU utility library for OpenVG
+ *//*-------------------------------------------------------------------*/
+
+#include "vgu.h"
+#include "openvg.h"
+#include "riMath.h"
+
+using namespace OpenVGRI;
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+static void append(VGPath path, int numSegments, const VGubyte* segments, int numCoordinates, const VGfloat* coordinates)
+{
+ RI_ASSERT(numCoordinates <= 26);
+
+ VGPathDatatype datatype = (VGPathDatatype)vgGetParameteri(path, VG_PATH_DATATYPE);
+ VGfloat scale = vgGetParameterf(path, VG_PATH_SCALE);
+ VGfloat bias = vgGetParameterf(path, VG_PATH_BIAS);
+
+ switch(datatype)
+ {
+ case VG_PATH_DATATYPE_S_8:
+ {
+ RIint8 data[26];
+ for(int i=0;i<numCoordinates;i++)
+ data[i] = (RIint8)floor((coordinates[i] - bias) / scale + 0.5f); //add 0.5 for correct rounding
+ vgAppendPathData(path, numSegments, segments, data);
+ break;
+ }
+
+ case VG_PATH_DATATYPE_S_16:
+ {
+ RIint16 data[26];
+ for(int i=0;i<numCoordinates;i++)
+ data[i] = (RIint16)floor((coordinates[i] - bias) / scale + 0.5f); //add 0.5 for correct rounding
+ vgAppendPathData(path, numSegments, segments, data);
+ break;
+ }
+
+ case VG_PATH_DATATYPE_S_32:
+ {
+ RIint32 data[26];
+ for(int i=0;i<numCoordinates;i++)
+ data[i] = (RIint32)floor((coordinates[i] - bias) / scale + 0.5f); //add 0.5 for correct rounding
+ vgAppendPathData(path, numSegments, segments, data);
+ break;
+ }
+
+ default:
+ {
+ RI_ASSERT(datatype == VG_PATH_DATATYPE_F);
+ RIfloat32 data[26];
+ for(int i=0;i<numCoordinates;i++)
+ data[i] = (RIfloat32)((coordinates[i] - bias) / scale);
+ vgAppendPathData(path, numSegments, segments, data);
+ break;
+ }
+ }
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGUErrorCode RI_APIENTRY vguLine(VGPath path, VGfloat x0, VGfloat y0, VGfloat x1, VGfloat y1)
+{
+ VGErrorCode error = vgGetError(); //clear the error state
+ static const VGubyte segments[2] = {VG_MOVE_TO | VG_ABSOLUTE, VG_LINE_TO | VG_ABSOLUTE};
+ const VGfloat data[4] = {x0, y0, x1, y1};
+ append(path, 2, segments, 4, data);
+
+ error = vgGetError();
+ if(error == VG_BAD_HANDLE_ERROR)
+ return VGU_BAD_HANDLE_ERROR;
+ else if(error == VG_PATH_CAPABILITY_ERROR)
+ return VGU_PATH_CAPABILITY_ERROR;
+ return VGU_NO_ERROR;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGUErrorCode RI_APIENTRY vguPolygon(VGPath path, const VGfloat * points, VGint count, VGboolean closed)
+{
+ VGErrorCode error = vgGetError(); //clear the error state
+ if(!points || (((RIuintptr)points) & 3) || count <= 0)
+ return VGU_ILLEGAL_ARGUMENT_ERROR;
+
+ VGubyte segments[1] = {VG_MOVE_TO | VG_ABSOLUTE};
+ VGfloat data[2];
+ for(int i=0;i<count;i++)
+ {
+ data[0] = points[i*2+0];
+ data[1] = points[i*2+1];
+ append(path, 1, segments, 2, data);
+ segments[0] = VG_LINE_TO | VG_ABSOLUTE;
+ }
+ if(closed)
+ {
+ segments[0] = VG_CLOSE_PATH;
+ append(path, 1, segments, 0, data);
+ }
+
+ error = vgGetError();
+ if(error == VG_BAD_HANDLE_ERROR)
+ return VGU_BAD_HANDLE_ERROR;
+ else if(error == VG_PATH_CAPABILITY_ERROR)
+ return VGU_PATH_CAPABILITY_ERROR;
+ return VGU_NO_ERROR;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGUErrorCode RI_APIENTRY vguRect(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height)
+{
+ VGErrorCode error = vgGetError(); //clear the error state
+ if(width <= 0 || height <= 0)
+ return VGU_ILLEGAL_ARGUMENT_ERROR;
+
+ static const VGubyte segments[5] = {VG_MOVE_TO | VG_ABSOLUTE,
+ VG_HLINE_TO | VG_ABSOLUTE,
+ VG_VLINE_TO | VG_ABSOLUTE,
+ VG_HLINE_TO | VG_ABSOLUTE,
+ VG_CLOSE_PATH};
+ const VGfloat data[5] = {x, y, x + width, y + height, x};
+ append(path, 5, segments, 5, data);
+
+ error = vgGetError();
+ if(error == VG_BAD_HANDLE_ERROR)
+ return VGU_BAD_HANDLE_ERROR;
+ else if(error == VG_PATH_CAPABILITY_ERROR)
+ return VGU_PATH_CAPABILITY_ERROR;
+ return VGU_NO_ERROR;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGUErrorCode RI_APIENTRY vguRoundRect(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height, VGfloat arcWidth, VGfloat arcHeight)
+{
+ VGErrorCode error = vgGetError(); //clear the error state
+ if(width <= 0 || height <= 0)
+ return VGU_ILLEGAL_ARGUMENT_ERROR;
+
+ arcWidth = RI_CLAMP(arcWidth, 0.0f, width);
+ arcHeight = RI_CLAMP(arcHeight, 0.0f, height);
+
+ static const VGubyte segments[10] = {VG_MOVE_TO | VG_ABSOLUTE,
+ VG_HLINE_TO | VG_ABSOLUTE,
+ VG_SCCWARC_TO | VG_ABSOLUTE,
+ VG_VLINE_TO | VG_ABSOLUTE,
+ VG_SCCWARC_TO | VG_ABSOLUTE,
+ VG_HLINE_TO | VG_ABSOLUTE,
+ VG_SCCWARC_TO | VG_ABSOLUTE,
+ VG_VLINE_TO | VG_ABSOLUTE,
+ VG_SCCWARC_TO | VG_ABSOLUTE,
+ VG_CLOSE_PATH};
+ const VGfloat data[26] = {x + arcWidth/2, y,
+ x + width - arcWidth/2,
+ arcWidth/2, arcHeight/2, 0, x + width, y + arcHeight/2,
+ y + height - arcHeight/2,
+ arcWidth/2, arcHeight/2, 0, x + width - arcWidth/2, y + height,
+ x + arcWidth/2,
+ arcWidth/2, arcHeight/2, 0, x, y + height - arcHeight/2,
+ y + arcHeight/2,
+ arcWidth/2, arcHeight/2, 0, x + arcWidth/2, y};
+ append(path, 10, segments, 26, data);
+
+ error = vgGetError();
+ if(error == VG_BAD_HANDLE_ERROR)
+ return VGU_BAD_HANDLE_ERROR;
+ else if(error == VG_PATH_CAPABILITY_ERROR)
+ return VGU_PATH_CAPABILITY_ERROR;
+ return VGU_NO_ERROR;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGUErrorCode RI_APIENTRY vguEllipse(VGPath path, VGfloat cx, VGfloat cy, VGfloat width, VGfloat height)
+{
+ VGErrorCode error = vgGetError(); //clear the error state
+ if(width <= 0 || height <= 0)
+ return VGU_ILLEGAL_ARGUMENT_ERROR;
+
+ static const VGubyte segments[4] = {VG_MOVE_TO | VG_ABSOLUTE,
+ VG_SCCWARC_TO | VG_ABSOLUTE,
+ VG_SCCWARC_TO | VG_ABSOLUTE,
+ VG_CLOSE_PATH};
+ const VGfloat data[12] = {cx + width/2, cy,
+ width/2, height/2, 0, cx - width/2, cy,
+ width/2, height/2, 0, cx + width/2, cy};
+ append(path, 4, segments, 12, data);
+
+ error = vgGetError();
+ if(error == VG_BAD_HANDLE_ERROR)
+ return VGU_BAD_HANDLE_ERROR;
+ else if(error == VG_PATH_CAPABILITY_ERROR)
+ return VGU_PATH_CAPABILITY_ERROR;
+ return VGU_NO_ERROR;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGUErrorCode RI_APIENTRY vguArc(VGPath path, VGfloat x, VGfloat y, VGfloat width, VGfloat height, VGfloat startAngle, VGfloat angleExtent, VGUArcType arcType)
+{
+ VGErrorCode error = vgGetError(); //clear the error state
+ if((arcType != VGU_ARC_OPEN && arcType != VGU_ARC_CHORD && arcType != VGU_ARC_PIE) || width <= 0.0f || height <= 0.0f)
+ return VGU_ILLEGAL_ARGUMENT_ERROR;
+
+ startAngle = RI_DEG_TO_RAD(startAngle);
+ angleExtent = RI_DEG_TO_RAD(angleExtent);
+
+ VGfloat w = width/2.0f;
+ VGfloat h = height/2.0f;
+
+ VGubyte segments[1];
+ VGfloat data[5];
+
+ segments[0] = VG_MOVE_TO | VG_ABSOLUTE;
+ data[0] = x + w * (VGfloat)cos(startAngle);
+ data[1] = y + h * (VGfloat)sin(startAngle);
+ append(path, 1, segments, 2, data);
+
+ data[0] = w;
+ data[1] = h;
+ data[2] = 0.0f;
+ VGfloat endAngle = startAngle + angleExtent;
+ if(angleExtent >= 0.0f)
+ {
+ segments[0] = VG_SCCWARC_TO | VG_ABSOLUTE;
+ for(VGfloat a = startAngle + PI;a < endAngle; a += PI)
+ {
+ data[3] = x + w * (VGfloat)cos(a);
+ data[4] = y + h * (VGfloat)sin(a);
+ append(path, 1, segments, 5, data);
+ }
+ }
+ else
+ {
+ segments[0] = VG_SCWARC_TO | VG_ABSOLUTE;
+ for(VGfloat a = startAngle - PI;a > endAngle; a -= PI)
+ {
+ data[3] = x + w * (VGfloat)cos(a);
+ data[4] = y + h * (VGfloat)sin(a);
+ append(path, 1, segments, 5, data);
+ }
+ }
+ data[3] = x + w * (VGfloat)cos(endAngle);
+ data[4] = y + h * (VGfloat)sin(endAngle);
+ append(path, 1, segments, 5, data);
+
+ if(arcType == VGU_ARC_CHORD)
+ {
+ segments[0] = VG_CLOSE_PATH;
+ append(path, 1, segments, 0, data);
+ }
+ else if(arcType == VGU_ARC_PIE)
+ {
+ segments[0] = VG_LINE_TO | VG_ABSOLUTE;
+ data[0] = x;
+ data[1] = y;
+ append(path, 1, segments, 2, data);
+ segments[0] = VG_CLOSE_PATH;
+ append(path, 1, segments, 0, data);
+ }
+
+ error = vgGetError();
+ if(error == VG_BAD_HANDLE_ERROR)
+ return VGU_BAD_HANDLE_ERROR;
+ else if(error == VG_PATH_CAPABILITY_ERROR)
+ return VGU_PATH_CAPABILITY_ERROR;
+ return VGU_NO_ERROR;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGUErrorCode RI_APIENTRY vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix)
+{
+ if(!matrix || ((RIuintptr)matrix) & 3)
+ return VGU_ILLEGAL_ARGUMENT_ERROR;
+
+ VGfloat mat[9];
+ VGUErrorCode ret = vguComputeWarpSquareToQuad(sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3, mat);
+ if(ret == VGU_BAD_WARP_ERROR)
+ return VGU_BAD_WARP_ERROR;
+ Matrix3x3 m(mat[0], mat[3], mat[6],
+ mat[1], mat[4], mat[7],
+ mat[2], mat[5], mat[8]);
+ bool nonsingular = m.invert();
+ if(!nonsingular)
+ return VGU_BAD_WARP_ERROR;
+ matrix[0] = m[0][0];
+ matrix[1] = m[1][0];
+ matrix[2] = m[2][0];
+ matrix[3] = m[0][1];
+ matrix[4] = m[1][1];
+ matrix[5] = m[2][1];
+ matrix[6] = m[0][2];
+ matrix[7] = m[1][2];
+ matrix[8] = m[2][2];
+ return VGU_NO_ERROR;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGUErrorCode RI_APIENTRY vguComputeWarpSquareToQuad(VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat * matrix)
+{
+ if(!matrix || ((RIuintptr)matrix) & 3)
+ return VGU_ILLEGAL_ARGUMENT_ERROR;
+
+ //from Heckbert:Fundamentals of Texture Mapping and Image Warping
+ //Note that his mapping of vertices is different from OpenVG's
+ //(0,0) => (dx0,dy0)
+ //(1,0) => (dx1,dy1)
+ //(0,1) => (dx2,dy2)
+ //(1,1) => (dx3,dy3)
+
+ VGfloat diffx1 = dx1 - dx3;
+ VGfloat diffy1 = dy1 - dy3;
+ VGfloat diffx2 = dx2 - dx3;
+ VGfloat diffy2 = dy2 - dy3;
+
+ VGfloat det = diffx1*diffy2 - diffx2*diffy1;
+ if(det == 0.0f)
+ return VGU_BAD_WARP_ERROR;
+
+ VGfloat sumx = dx0 - dx1 + dx3 - dx2;
+ VGfloat sumy = dy0 - dy1 + dy3 - dy2;
+
+ if(sumx == 0.0f && sumy == 0.0f)
+ { //affine mapping
+ matrix[0] = dx1 - dx0;
+ matrix[1] = dy1 - dy0;
+ matrix[2] = 0.0f;
+ matrix[3] = dx3 - dx1;
+ matrix[4] = dy3 - dy1;
+ matrix[5] = 0.0f;
+ matrix[6] = dx0;
+ matrix[7] = dy0;
+ matrix[8] = 1.0f;
+ return VGU_NO_ERROR;
+ }
+
+ VGfloat oodet = 1.0f / det;
+ VGfloat g = (sumx*diffy2 - diffx2*sumy) * oodet;
+ VGfloat h = (diffx1*sumy - sumx*diffy1) * oodet;
+
+ matrix[0] = dx1-dx0+g*dx1;
+ matrix[1] = dy1-dy0+g*dy1;
+ matrix[2] = g;
+ matrix[3] = dx2-dx0+h*dx2;
+ matrix[4] = dy2-dy0+h*dy2;
+ matrix[5] = h;
+ matrix[6] = dx0;
+ matrix[7] = dy0;
+ matrix[8] = 1.0f;
+ return VGU_NO_ERROR;
+}
+
+/*-------------------------------------------------------------------*//*!
+* \brief
+* \param
+* \return
+* \note
+*//*-------------------------------------------------------------------*/
+
+VGUErrorCode RI_APIENTRY vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0, VGfloat dx1, VGfloat dy1, VGfloat dx2, VGfloat dy2, VGfloat dx3, VGfloat dy3, VGfloat sx0, VGfloat sy0, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, VGfloat sx3, VGfloat sy3, VGfloat * matrix)
+{
+ if(!matrix || ((RIuintptr)matrix) & 3)
+ return VGU_ILLEGAL_ARGUMENT_ERROR;
+
+ VGfloat qtos[9];
+ VGUErrorCode ret1 = vguComputeWarpQuadToSquare(sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3, qtos);
+ if(ret1 == VGU_BAD_WARP_ERROR)
+ return VGU_BAD_WARP_ERROR;
+
+ VGfloat stoq[9];
+ VGUErrorCode ret2 = vguComputeWarpSquareToQuad(dx0, dy0, dx1, dy1, dx2, dy2, dx3, dy3, stoq);
+ if(ret2 == VGU_BAD_WARP_ERROR)
+ return VGU_BAD_WARP_ERROR;
+
+ Matrix3x3 m1(qtos[0], qtos[3], qtos[6],
+ qtos[1], qtos[4], qtos[7],
+ qtos[2], qtos[5], qtos[8]);
+ Matrix3x3 m2(stoq[0], stoq[3], stoq[6],
+ stoq[1], stoq[4], stoq[7],
+ stoq[2], stoq[5], stoq[8]);
+ Matrix3x3 r = m2 * m1;
+
+ matrix[0] = r[0][0];
+ matrix[1] = r[1][0];
+ matrix[2] = r[2][0];
+ matrix[3] = r[0][1];
+ matrix[4] = r[1][1];
+ matrix[5] = r[2][1];
+ matrix[6] = r[0][2];
+ matrix[7] = r[1][2];
+ matrix[8] = r[2][2];
+ return VGU_NO_ERROR;
+}
diff --git a/ri/src/win32/riEGLOS.cpp b/ri/src/win32/riEGLOS.cpp
new file mode 100644
index 0000000..3135a09
--- /dev/null
+++ b/ri/src/win32/riEGLOS.cpp
@@ -0,0 +1,379 @@
+/*------------------------------------------------------------------------
+ *
+ * EGL 1.3
+ * -------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Simple implementation of EGL 1.3
+ * \note caveats:
+ - always renders into the backbuffer and blits it to window (no single buffered rendering)
+ - no native Windows or Mac OS X pixmap support
+ - no power management events
+ - no support for swap interval
+ * \todo what happens in egl functions when eglTerminate has been called but the context and surface are still in use?
+ * \todo OSDeinitMutex should be called in case getEGL fails.
+ * \todo clarify getThread and getCurrentThread distinction.
+ *//*-------------------------------------------------------------------*/
+
+#include "egl.h"
+#include "openvg.h"
+#include "riArray.h"
+#include "riMath.h"
+#include "riContext.h"
+#include "riImage.h"
+
+namespace OpenVGRI
+{
+
+#include <windows.h>
+
+void* OSGetCurrentThreadID(void)
+{
+ return (void*)GetCurrentThreadId(); //TODO this is not safe
+}
+
+static HANDLE mutex = NULL;
+static int mutexRefCount = 0;
+//acquired mutex cannot be deinited.
+void OSDeinitMutex(void)
+{
+ RI_ASSERT(mutex);
+ RI_ASSERT(mutexRefCount == 0);
+ BOOL ret = CloseHandle(mutex);
+ RI_ASSERT(ret);
+ RI_UNREF(ret);
+}
+void OSAcquireMutex(void)
+{
+ if(!mutex)
+ {
+ mutex = CreateMutex(NULL, FALSE, NULL); //initially not locked
+ mutexRefCount = 0;
+ }
+ RI_ASSERT(mutex);
+ DWORD ret = WaitForSingleObject(mutex, INFINITE);
+ RI_ASSERT(ret != WAIT_FAILED);
+ RI_UNREF(ret);
+ mutexRefCount++;
+}
+void OSReleaseMutex(void)
+{
+ RI_ASSERT(mutex);
+ mutexRefCount--;
+ RI_ASSERT(mutexRefCount >= 0);
+ BOOL ret = ReleaseMutex(mutex);
+ RI_ASSERT(ret);
+ RI_UNREF(ret);
+}
+
+static bool isBigEndian()
+{
+ static const RIuint32 v = 0x12345678u;
+ const RIuint8* p = (const RIuint8*)&v;
+ RI_ASSERT (*p == (RIuint8)0x12u || *p == (RIuint8)0x78u);
+ return (*p == (RIuint8)(0x12)) ? true : false;
+}
+
+
+#ifdef RI_USE_GLUT
+# include <GL/gl.h>
+# define GLUT_DISABLE_ATEXIT_HACK
+# include "glut.h"
+
+struct OSWindowContext
+{
+ int window;
+ unsigned int* tmp;
+ int tmpWidth;
+ int tmpHeight;
+};
+
+void* OSCreateWindowContext(EGLNativeWindowType window)
+{
+ try
+ {
+ OSWindowContext* ctx = RI_NEW(OSWindowContext, ());
+ ctx->window = (int)window;
+ ctx->tmp = NULL;
+ ctx->tmpWidth = 0;
+ ctx->tmpHeight = 0;
+ return ctx;
+ }
+ catch(std::bad_alloc)
+ {
+ return NULL;
+ }
+}
+
+void OSDestroyWindowContext(void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ RI_DELETE_ARRAY(ctx->tmp);
+ RI_DELETE(ctx);
+ }
+}
+
+bool OSIsWindow(const void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ //TODO implement
+ return true;
+ }
+ return false;
+}
+
+void OSGetWindowSize(const void* context, int& width, int& height)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ int currWin = glutGetWindow();
+ glutSetWindow(ctx->window);
+ width = glutGet(GLUT_WINDOW_WIDTH);
+ height = glutGet(GLUT_WINDOW_HEIGHT);
+ glutSetWindow(currWin);
+ }
+ else
+ {
+ width = 0;
+ height = 0;
+ }
+}
+
+void OSBlitToWindow(void* context, const Drawable* drawable)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ int w = drawable->getWidth();
+ int h = drawable->getHeight();
+
+ int currWin = glutGetWindow();
+ glutSetWindow(ctx->window);
+
+ if(!ctx->tmp || ctx->tmpWidth != w || ctx->tmpHeight != h)
+ {
+ RI_DELETE_ARRAY(ctx->tmp);
+ ctx->tmp = NULL;
+ try
+ {
+ ctx->tmp = RI_NEW_ARRAY(unsigned int, w*h); //throws bad_alloc
+ ctx->tmpWidth = w;
+ ctx->tmpHeight = h;
+ }
+ catch(std::bad_alloc)
+ {
+ //do nothing
+ }
+ }
+
+ if(ctx->tmp)
+ {
+ glViewport(0, 0, w, h);
+ glDisable(GL_DEPTH_TEST);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ //NOTE: we assume here that the display is always in sRGB color space
+ VGImageFormat f = VG_sXBGR_8888;
+ if(isBigEndian())
+ f = VG_sRGBX_8888;
+ vgReadPixels(ctx->tmp, w*sizeof(unsigned int), f, 0, 0, w, h);
+ glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, ctx->tmp);
+ }
+
+ glutSwapBuffers(); //shows the OpenGL frame buffer
+ glutSetWindow(currWin); //restore the current window
+ }
+}
+
+EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id)
+{
+ return (EGLDisplay)display_id; //just casting to (EGLDisplay) should be enough to make a unique identifier out of this
+}
+
+#else
+//Windows native
+#define _WIN32_WINNT 0x0400
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+struct OSWindowContext
+{
+ HWND window;
+ HDC bufDC;
+ HBITMAP bufDIB;
+ unsigned int* tmp;
+ int tmpWidth;
+ int tmpHeight;
+};
+
+void* OSCreateWindowContext(EGLNativeWindowType window)
+{
+ OSWindowContext* ctx = NULL;
+ try
+ {
+ ctx = RI_NEW(OSWindowContext, ());
+ }
+ catch(std::bad_alloc)
+ {
+ return NULL;
+ }
+
+ ctx->window = (HWND)window;
+ HDC winDC = GetDC(ctx->window);
+ ctx->bufDC = CreateCompatibleDC(winDC);
+ ReleaseDC(ctx->window, winDC);
+ if(!ctx->bufDC)
+ {
+ RI_DELETE(ctx);
+ return NULL;
+ }
+
+ ctx->bufDIB = NULL;
+ ctx->tmp = NULL;
+ ctx->tmpWidth = 0;
+ ctx->tmpHeight = 0;
+ return ctx;
+}
+
+void OSDestroyWindowContext(void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ if(ctx->bufDC)
+ {
+ SelectObject(ctx->bufDC, NULL);
+ DeleteDC(ctx->bufDC);
+ }
+ if(ctx->bufDIB)
+ DeleteObject(ctx->bufDIB);
+ RI_DELETE(ctx);
+ }
+}
+
+bool OSIsWindow(const void* context)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ if(IsWindow(ctx->window))
+ return true;
+ }
+ return false;
+}
+
+void OSGetWindowSize(const void* context, int& width, int& height)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ RECT rect;
+ GetClientRect(ctx->window, &rect);
+ width = rect.right - rect.left;
+ height = rect.bottom - rect.top;
+ }
+ else
+ {
+ width = 0;
+ height = 0;
+ }
+}
+
+void OSBlitToWindow(void* context, const Drawable* drawable)
+{
+ OSWindowContext* ctx = (OSWindowContext*)context;
+ if(ctx)
+ {
+ int w = drawable->getWidth();
+ int h = drawable->getHeight();
+
+ if(!ctx->tmp || !ctx->bufDIB || ctx->tmpWidth != w || ctx->tmpHeight != h)
+ {
+ if(ctx->bufDIB)
+ DeleteObject(ctx->bufDIB);
+ ctx->tmp = NULL;
+ ctx->bufDIB = NULL;
+
+ ctx->tmpWidth = w;
+ ctx->tmpHeight = h;
+
+ struct
+ {
+ BITMAPINFOHEADER header;
+ DWORD rMask;
+ DWORD gMask;
+ DWORD bMask;
+ } bmi;
+ bmi.header.biSize = sizeof(BITMAPINFOHEADER);
+ bmi.header.biWidth = w;
+ bmi.header.biHeight = h;
+ bmi.header.biPlanes = 1;
+ bmi.header.biBitCount = (WORD)32;
+ bmi.header.biCompression = BI_BITFIELDS;
+ bmi.rMask = 0x000000ff;
+ bmi.gMask = 0x0000ff00;
+ bmi.bMask = 0x00ff0000;
+ ctx->bufDIB = CreateDIBSection(ctx->bufDC, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, (void**)&ctx->tmp, NULL, 0);
+ if(!ctx->bufDIB)
+ {
+ ctx->tmp = NULL;
+ return;
+ }
+ }
+
+ if(ctx->tmp)
+ {
+ //NOTE: we assume here that the display is always in sRGB color space
+ GdiFlush();
+ VGImageFormat f = VG_sXBGR_8888;
+ if(isBigEndian())
+ f = VG_sRGBX_8888;
+ vgReadPixels(ctx->tmp, w*sizeof(unsigned int), f, 0, 0, w, h);
+
+ SelectObject(ctx->bufDC, ctx->bufDIB);
+ HDC winDC = GetDC(ctx->window);
+ BitBlt(winDC, 0, 0, w, h, ctx->bufDC, 0, 0, SRCCOPY);
+ ReleaseDC(ctx->window, winDC);
+ SelectObject(ctx->bufDC, NULL);
+ }
+ }
+}
+
+EGLDisplay OSGetDisplay(EGLNativeDisplayType display_id)
+{
+ RI_UNREF(display_id);
+ return (EGLDisplay)1; //support only a single display
+}
+
+#endif
+
+} //namespace OpenVGRI
diff --git a/samples/samples.dsp b/samples/samples.dsp
new file mode 100644
index 0000000..4b8792c
--- /dev/null
+++ b/samples/samples.dsp
@@ -0,0 +1,98 @@
+# Microsoft Developer Studio Project File - Name="samples" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=samples - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "samples.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "samples.mak" CFG="samples - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "samples - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "samples - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName "samples"
+# PROP Scc_LocalPath "."
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "samples - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../ri/include" /I "../lib" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x40b /d "NDEBUG"
+# ADD RSC /l 0x40b /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"../bin/win32/tiger.exe" /libpath:"../lib"
+
+!ELSEIF "$(CFG)" == "samples - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "samples___Win32_Debug"
+# PROP BASE Intermediate_Dir "samples___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "samples___Win32_Debug"
+# PROP Intermediate_Dir "samples___Win32_Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../ri/include" /I "../lib" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x40b /d "_DEBUG"
+# ADD RSC /l 0x40b /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/win32/tiger-dbg.exe" /pdbtype:sept /libpath:"../lib"
+
+!ENDIF
+
+# Begin Target
+
+# Name "samples - Win32 Release"
+# Name "samples - Win32 Debug"
+# Begin Source File
+
+SOURCE=.\tiger\main.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\tiger\tiger.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\tiger\tiger.h
+# End Source File
+# End Target
+# End Project
diff --git a/samples/samples.dsw b/samples/samples.dsw
new file mode 100644
index 0000000..fd68ef7
--- /dev/null
+++ b/samples/samples.dsw
@@ -0,0 +1,44 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "openvg_ri"=..\ri\openvg_ri.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "samples"=.\samples.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name openvg_ri
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/samples/tiger/main.c b/samples/tiger/main.c
new file mode 100644
index 0000000..4f5dd8b
--- /dev/null
+++ b/samples/tiger/main.c
@@ -0,0 +1,471 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.0.1 Reference Implementation sample code
+ * -------------------------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Tiger sample application. Resizing the application window
+ * rerenders the tiger in the new resolution. Pressing 1,2,3
+ * or 4 sets pixel zoom factor, mouse moves inside the zoomed
+ * image (mouse move works on OpenGL >= 1.2).
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#define UNREF(X) ((void)(X))
+
+#ifdef HG_FLAT_INCLUDES
+# include "openvg.h"
+# include "vgu.h"
+# include "egl.h"
+#else
+# include "VG/openvg.h"
+# include "VG/vgu.h"
+# include "EGL/egl.h"
+#endif
+
+#include "tiger.h"
+
+/*--------------------------------------------------------------*/
+
+const float aspectRatio = 612.0f / 792.0f;
+int renderWidth = 0;
+int renderHeight = 0;
+EGLDisplay egldisplay;
+EGLConfig eglconfig;
+EGLSurface eglsurface;
+EGLContext eglcontext;
+
+/*--------------------------------------------------------------*/
+
+typedef struct
+{
+ VGFillRule m_fillRule;
+ VGPaintMode m_paintMode;
+ VGCapStyle m_capStyle;
+ VGJoinStyle m_joinStyle;
+ float m_miterLimit;
+ float m_strokeWidth;
+ VGPaint m_fillPaint;
+ VGPaint m_strokePaint;
+ VGPath m_path;
+} PathData;
+
+typedef struct
+{
+ PathData* m_paths;
+ int m_numPaths;
+} PS;
+
+PS* PS_construct(const char* commands, int commandCount, const float* points, int pointCount)
+{
+ PS* ps = (PS*)malloc(sizeof(PS));
+ int p = 0;
+ int c = 0;
+ int i = 0;
+ int paths = 0;
+ int maxElements = 0;
+ unsigned char* cmd;
+ UNREF(pointCount);
+
+ while(c < commandCount)
+ {
+ int elements, e;
+ c += 4;
+ p += 8;
+ elements = (int)points[p++];
+ assert(elements > 0);
+ if(elements > maxElements)
+ maxElements = elements;
+ for(e=0;e<elements;e++)
+ {
+ switch(commands[c])
+ {
+ case 'M': p += 2; break;
+ case 'L': p += 2; break;
+ case 'C': p += 6; break;
+ case 'E': break;
+ default:
+ assert(0); //unknown command
+ }
+ c++;
+ }
+ paths++;
+ }
+
+ ps->m_numPaths = paths;
+ ps->m_paths = (PathData*)malloc(paths * sizeof(PathData));
+ cmd = (unsigned char*)malloc(maxElements);
+
+ i = 0;
+ p = 0;
+ c = 0;
+ while(c < commandCount)
+ {
+ int elements, startp, e;
+ float color[4];
+
+ //fill type
+ int paintMode = 0;
+ ps->m_paths[i].m_fillRule = VG_NON_ZERO;
+ switch( commands[c] )
+ {
+ case 'N':
+ break;
+ case 'F':
+ ps->m_paths[i].m_fillRule = VG_NON_ZERO;
+ paintMode |= VG_FILL_PATH;
+ break;
+ case 'E':
+ ps->m_paths[i].m_fillRule = VG_EVEN_ODD;
+ paintMode |= VG_FILL_PATH;
+ break;
+ default:
+ assert(0); //unknown command
+ }
+ c++;
+
+ //stroke
+ switch( commands[c] )
+ {
+ case 'N':
+ break;
+ case 'S':
+ paintMode |= VG_STROKE_PATH;
+ break;
+ default:
+ assert(0); //unknown command
+ }
+ ps->m_paths[i].m_paintMode = (VGPaintMode)paintMode;
+ c++;
+
+ //line cap
+ switch( commands[c] )
+ {
+ case 'B':
+ ps->m_paths[i].m_capStyle = VG_CAP_BUTT;
+ break;
+ case 'R':
+ ps->m_paths[i].m_capStyle = VG_CAP_ROUND;
+ break;
+ case 'S':
+ ps->m_paths[i].m_capStyle = VG_CAP_SQUARE;
+ break;
+ default:
+ assert(0); //unknown command
+ }
+ c++;
+
+ //line join
+ switch( commands[c] )
+ {
+ case 'M':
+ ps->m_paths[i].m_joinStyle = VG_JOIN_MITER;
+ break;
+ case 'R':
+ ps->m_paths[i].m_joinStyle = VG_JOIN_ROUND;
+ break;
+ case 'B':
+ ps->m_paths[i].m_joinStyle = VG_JOIN_BEVEL;
+ break;
+ default:
+ assert(0); //unknown command
+ }
+ c++;
+
+ //the rest of stroke attributes
+ ps->m_paths[i].m_miterLimit = points[p++];
+ ps->m_paths[i].m_strokeWidth = points[p++];
+
+ //paints
+ color[0] = points[p++];
+ color[1] = points[p++];
+ color[2] = points[p++];
+ color[3] = 1.0f;
+ ps->m_paths[i].m_strokePaint = vgCreatePaint();
+ vgSetParameteri(ps->m_paths[i].m_strokePaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
+ vgSetParameterfv(ps->m_paths[i].m_strokePaint, VG_PAINT_COLOR, 4, color);
+
+ color[0] = points[p++];
+ color[1] = points[p++];
+ color[2] = points[p++];
+ color[3] = 1.0f;
+ ps->m_paths[i].m_fillPaint = vgCreatePaint();
+ vgSetParameteri(ps->m_paths[i].m_fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
+ vgSetParameterfv(ps->m_paths[i].m_fillPaint, VG_PAINT_COLOR, 4, color);
+
+ //read number of elements
+
+ elements = (int)points[p++];
+ assert(elements > 0);
+ startp = p;
+ for(e=0;e<elements;e++)
+ {
+ switch( commands[c] )
+ {
+ case 'M':
+ cmd[e] = VG_MOVE_TO | VG_ABSOLUTE;
+ p += 2;
+ break;
+ case 'L':
+ cmd[e] = VG_LINE_TO | VG_ABSOLUTE;
+ p += 2;
+ break;
+ case 'C':
+ cmd[e] = VG_CUBIC_TO | VG_ABSOLUTE;
+ p += 6;
+ break;
+ case 'E':
+ cmd[e] = VG_CLOSE_PATH;
+ break;
+ default:
+ assert(0); //unknown command
+ }
+ c++;
+ }
+
+ ps->m_paths[i].m_path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, (unsigned int)VG_PATH_CAPABILITY_ALL);
+ vgAppendPathData(ps->m_paths[i].m_path, elements, cmd, points + startp);
+ i++;
+ }
+ free(cmd);
+ return ps;
+}
+
+void PS_destruct(PS* ps)
+{
+ int i;
+ assert(ps);
+ for(i=0;i<ps->m_numPaths;i++)
+ {
+ vgDestroyPaint(ps->m_paths[i].m_fillPaint);
+ vgDestroyPaint(ps->m_paths[i].m_strokePaint);
+ vgDestroyPath(ps->m_paths[i].m_path);
+ }
+ free(ps->m_paths);
+ free(ps);
+}
+
+void PS_render(PS* ps)
+{
+ int i;
+ assert(ps);
+ vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
+
+ for(i=0;i<ps->m_numPaths;i++)
+ {
+ vgSeti(VG_FILL_RULE, ps->m_paths[i].m_fillRule);
+ vgSetPaint(ps->m_paths[i].m_fillPaint, VG_FILL_PATH);
+
+ if(ps->m_paths[i].m_paintMode & VG_STROKE_PATH)
+ {
+ vgSetf(VG_STROKE_LINE_WIDTH, ps->m_paths[i].m_strokeWidth);
+ vgSeti(VG_STROKE_CAP_STYLE, ps->m_paths[i].m_capStyle);
+ vgSeti(VG_STROKE_JOIN_STYLE, ps->m_paths[i].m_joinStyle);
+ vgSetf(VG_STROKE_MITER_LIMIT, ps->m_paths[i].m_miterLimit);
+ vgSetPaint(ps->m_paths[i].m_strokePaint, VG_STROKE_PATH);
+ }
+
+ vgDrawPath(ps->m_paths[i].m_path, ps->m_paths[i].m_paintMode);
+ }
+ assert(vgGetError() == VG_NO_ERROR);
+}
+
+PS* tiger = NULL;
+
+/*--------------------------------------------------------------*/
+
+void render(int w, int h)
+{
+ if(renderWidth != w || renderHeight != h)
+ {
+ float clearColor[4] = {1,1,1,1};
+ float scale = w / (tigerMaxX - tigerMinX);
+
+ eglSwapBuffers(egldisplay, eglsurface); //force EGL to recognize resize
+
+ vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
+ vgClear(0, 0, w, h);
+
+ vgLoadIdentity();
+ vgScale(scale, scale);
+ vgTranslate(-tigerMinX, -tigerMinY + 0.5f * (h / scale - (tigerMaxY - tigerMinY)));
+
+ PS_render(tiger);
+ assert(vgGetError() == VG_NO_ERROR);
+
+ renderWidth = w;
+ renderHeight = h;
+ }
+
+ eglSwapBuffers(egldisplay, eglsurface);
+ assert(eglGetError() == EGL_SUCCESS);
+}
+
+/*--------------------------------------------------------------*/
+
+void init(NativeWindowType window)
+{
+ static const EGLint s_configAttribs[] =
+ {
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_LUMINANCE_SIZE, EGL_DONT_CARE, //EGL_DONT_CARE
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_SAMPLES, 1,
+ EGL_NONE
+ };
+ EGLint numconfigs;
+
+ egldisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ eglInitialize(egldisplay, NULL, NULL);
+ assert(eglGetError() == EGL_SUCCESS);
+ eglBindAPI(EGL_OPENVG_API);
+
+ eglChooseConfig(egldisplay, s_configAttribs, &eglconfig, 1, &numconfigs);
+ assert(eglGetError() == EGL_SUCCESS);
+ assert(numconfigs == 1);
+
+ eglsurface = eglCreateWindowSurface(egldisplay, eglconfig, window, NULL);
+ assert(eglGetError() == EGL_SUCCESS);
+ eglcontext = eglCreateContext(egldisplay, eglconfig, NULL, NULL);
+ assert(eglGetError() == EGL_SUCCESS);
+ eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext);
+ assert(eglGetError() == EGL_SUCCESS);
+
+ tiger = PS_construct(tigerCommands, tigerCommandCount, tigerPoints, tigerPointCount);
+}
+
+/*--------------------------------------------------------------*/
+
+void deinit(void)
+{
+ PS_destruct(tiger);
+ eglMakeCurrent(egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ assert(eglGetError() == EGL_SUCCESS);
+ eglTerminate(egldisplay);
+ assert(eglGetError() == EGL_SUCCESS);
+ eglReleaseThread();
+}
+
+/*--------------------------------------------------------------*/
+
+#ifdef WIN32
+#pragma warning(disable:4115) /* named type definition in parentheses (this comes from a visual studio include file) */
+#include <windows.h>
+
+static LONG WINAPI windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
+ {
+ case WM_CLOSE:
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ return 0;
+ case WM_PAINT:
+ {
+ RECT rect;
+ InvalidateRect(hWnd, NULL, 0);
+ GetClientRect(hWnd, &rect);
+ render(rect.right - rect.left, rect.bottom - rect.top);
+ return 0;
+ }
+ default:
+ break;
+ }
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
+/*--------------------------------------------------------------*/
+
+int main(void)
+{
+ HWND window;
+ {
+ WNDCLASS wndclass;
+ wndclass.style = 0;
+ wndclass.lpfnWndProc = windowProc;
+ wndclass.cbClsExtra = 0;
+ wndclass.cbWndExtra = 0;
+ wndclass.hInstance = (HINSTANCE)GetModuleHandle(NULL);
+ wndclass.hIcon = LoadIcon(wndclass.hInstance, MAKEINTRESOURCE(101));
+ wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wndclass.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
+ wndclass.lpszMenuName = NULL;
+ wndclass.lpszClassName = "MainWndClass";
+ if (!wndclass.hIcon)
+ wndclass.hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
+ RegisterClass(&wndclass);
+ }
+
+ window = CreateWindow(
+ "MainWndClass",
+ "OpenVG Tiger sample (rendering, please wait)",
+ WS_OVERLAPPEDWINDOW,
+ 200, 200, 400, (int)(400.0f / aspectRatio),
+ NULL,
+ NULL,
+ (HINSTANCE)GetModuleHandle(NULL),
+ NULL);
+ if (!window)
+ return -1;
+
+ init((NativeWindowType)window);
+
+ {
+ MSG msg;
+ ShowWindow(window, SW_SHOW);
+ while (GetMessage(&msg, NULL, 0, 0))
+ {
+ DispatchMessage(&msg);
+ if (msg.message == WM_QUIT)
+ break;
+ }
+ }
+
+ deinit();
+
+ DestroyWindow(window);
+ return 0;
+}
+
+/*--------------------------------------------------------------*/
+
+#elif defined __APPLE__
+
+/*--------------------------------------------------------------*/
+
+#include <OpenGL/gl.h>
+
+//TODO
+
+#endif
+
diff --git a/samples/tiger/tiger.c b/samples/tiger/tiger.c
new file mode 100644
index 0000000..99b27e4
--- /dev/null
+++ b/samples/tiger/tiger.c
@@ -0,0 +1,1952 @@
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.0.1 Reference Implementation sample code
+ * -------------------------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Path and paint data for Tiger image.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+const int tigerCommandCount = 4151;
+const char tigerCommands[4151] = {
+'F', 'N', 'B', 'M', 'M', 'L', 'L', 'L', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S',
+'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M',
+'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C',
+'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C',
+'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F',
+'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M',
+'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E',
+'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S',
+'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M',
+'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C',
+'L', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'L', 'C', 'C', 'L', 'C', 'C', 'C', 'C',
+'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'N', 'S', 'B',
+'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'L', 'C', 'L', 'C', 'C', 'C', 'C', 'C',
+'L', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'L', 'L', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C',
+'L', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'N', 'S', 'B',
+'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'E', 'F',
+'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C',
+'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C',
+'L', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C',
+'C', 'C', 'C', 'L', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'E', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'F',
+'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C',
+'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'L', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'L', 'C', 'C',
+'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F',
+'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R',
+'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C',
+'C', 'C', 'L', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C',
+'L', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'L', 'C', 'C', 'C',
+'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M',
+'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'N',
+'S', 'B', 'M', 'M', 'C', 'C', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M',
+'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C',
+'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E',
+'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N',
+'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C',
+'C', 'C', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C',
+'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'N', 'S',
+'B', 'M', 'M', 'C', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C',
+'C', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N',
+'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N',
+'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C',
+'C', 'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C',
+'E', 'N', 'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N',
+'S', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B',
+'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'B', 'M', 'M',
+'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'L', 'C', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C',
+'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F',
+'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F',
+'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C',
+'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C',
+'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C',
+'C', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C',
+'C', 'L', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'C', 'C',
+'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'C', 'C', 'C',
+'C', 'L', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'C', 'C', 'C', 'C',
+'L', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C',
+'C', 'C', 'L', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M',
+'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'L', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C',
+'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'L',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'F', 'N', 'R',
+'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'L', 'L', 'C', 'E', 'F', 'N', 'R',
+'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M',
+'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'L', 'L', 'L', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'L', 'L', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F',
+'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'L', 'L', 'C', 'C', 'C', 'C', 'C',
+'C', 'L', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'L', 'L', 'L', 'N', 'S', 'R', 'M', 'M', 'C', 'C',
+'N', 'S', 'R', 'M', 'M', 'C', 'C', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'N', 'S', 'R', 'M', 'M',
+'C', 'C', 'C', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M',
+'M', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'E', 'F', 'N',
+'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F',
+'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'L',
+'L', 'C', 'C', 'C', 'C', 'L', 'L', 'C', 'C', 'C', 'C', 'C', 'C', 'L', 'C', 'F', 'N', 'B', 'M', 'M',
+'C', 'L', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'C', 'L', 'C', 'C', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C',
+'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F',
+'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C',
+'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M',
+'L', 'L', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B',
+'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C',
+'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N',
+'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R',
+'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M',
+'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C',
+'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E',
+'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N',
+'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C',
+'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N',
+'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C',
+'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N',
+'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N',
+'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R',
+'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M',
+'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C',
+'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E',
+'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N',
+'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M',
+'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C',
+'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C',
+'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N',
+'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R',
+'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M',
+'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C',
+'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E',
+'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N',
+'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M',
+'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C',
+'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C',
+'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N',
+'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R',
+'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M',
+'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C',
+'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'N', 'S', 'R', 'M', 'M', 'C', 'C', 'C', 'E',
+'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M',
+'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L',
+'F', 'N', 'B', 'M', 'M', 'C', 'C', 'L', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R',
+'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N',
+'R', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'C', 'C', 'C',
+'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C',
+'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M',
+'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M',
+'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C',
+'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C',
+'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C',
+'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C',
+'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F', 'N', 'R', 'M', 'M', 'C', 'C', 'C', 'E', 'F',
+'N', 'R', 'M', 'M', 'L', 'C', 'L', 'N', 'S', 'R', 'M', 'M', 'L', 'N', 'S', 'R', 'M', 'M', 'C', 'N',
+'S', 'R', 'M', 'M', 'C', 'N', 'S', 'R', 'M', 'M', 'C'};
+
+const float tigerMinX = 0.0f;
+const float tigerMaxX = 612.0f;
+const float tigerMinY = 0.0f;
+const float tigerMaxY = 792.0f;
+
+const int tigerPointCount = 17005;
+const float tigerPoints[17005] = {
+10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 5, 0,
+792, 0, 0, 612, 0, 612, 792, 10, 0, 1,
+1, 1, 1, 1, 1, 5, 85.25f, 487.75f, 85.25f, 487.75f,
+85.5742f, 485.199f, 84.25f, 484.746f, 83.7617f, 485.242f, 65.6641f, 538.125f, 43.2461f, 535.746f,
+43.2422f, 535.746f, 62.6445f, 543.746f, 85.25f, 487.75f, 10, 0.1892f, 0, 0,
+0, 0, 0, 0, 5, 85.25f, 487.75f, 85.25f, 487.75f, 85.5742f,
+485.199f, 84.25f, 484.746f, 83.7617f, 485.242f, 65.6641f, 538.125f, 43.2461f, 535.746f, 43.2422f,
+535.746f, 62.6445f, 543.746f, 85.25f, 487.75f, 10, 0, 1, 1, 1,
+1, 1, 1, 5, 89.2461f, 490.75f, 89.2461f, 490.75f, 88.7422f, 488.613f,
+88.2461f, 488.746f, 87.0508f, 489.27f, 88.0234f, 545.156f, 66.2461f, 550.746f, 66.2461f, 550.742f,
+87.0977f, 551.469f, 89.2461f, 490.75f, 10, 0.1892f, 0, 0, 0, 0,
+0, 0, 5, 89.2461f, 490.75f, 89.2461f, 490.75f, 88.7422f, 488.613f, 88.2461f,
+488.746f, 87.0508f, 489.27f, 88.0234f, 545.156f, 66.2461f, 550.746f, 66.2461f, 550.742f, 87.0977f,
+551.469f, 89.2461f, 490.75f, 10, 0, 1, 1, 1, 1, 1,
+1, 5, 119.25f, 443.75f, 119.25f, 443.75f, 121.387f, 442.992f, 121.246f, 442.746f,
+120.352f, 441.504f, 66.2578f, 455.586f, 56.25f, 435.75f, 56.25f, 435.75f, 59.9062f, 456.168f,
+119.25f, 443.75f, 10, 0.1892f, 0, 0, 0, 0, 0, 0,
+5, 119.25f, 443.75f, 119.25f, 443.75f, 121.387f, 442.992f, 121.246f, 442.746f, 120.352f,
+441.504f, 66.2578f, 455.586f, 56.25f, 435.75f, 56.25f, 435.75f, 59.9062f, 456.168f, 119.25f,
+443.75f, 10, 0, 1, 1, 1, 1, 1, 1, 5,
+116.246f, 432.75f, 116.246f, 432.75f, 118.539f, 432.383f, 118.25f, 431.746f, 118.023f, 430.641f,
+62.25f, 426.965f, 58.25f, 404.75f, 58.25f, 404.75f, 56.0391f, 425.516f, 116.246f, 432.75f,
+10, 0.1892f, 0, 0, 0, 0, 0, 0, 5, 116.246f,
+432.75f, 116.246f, 432.75f, 118.539f, 432.383f, 118.25f, 431.746f, 118.023f, 430.641f, 62.25f,
+426.965f, 58.25f, 404.75f, 58.25f, 404.75f, 56.0391f, 425.516f, 116.246f, 432.75f, 10,
+0, 1, 1, 1, 1, 1, 1, 5, 112.25f, 438.746f,
+112.25f, 438.742f, 113.82f, 438.164f, 113.25f, 437.75f, 113.059f, 436.52f, 57.3437f, 441.016f,
+50.2461f, 419.75f, 50.2461f, 419.75f, 50.9883f, 440.492f, 112.25f, 438.746f, 10, 0.1892f,
+0, 0, 0, 0, 0, 0, 5, 112.25f, 438.746f, 112.25f,
+438.742f, 113.82f, 438.164f, 113.25f, 437.75f, 113.059f, 436.52f, 57.3437f, 441.016f, 50.2461f,
+419.75f, 50.2461f, 419.75f, 50.9883f, 440.492f, 112.25f, 438.746f, 10, 0, 1,
+1, 1, 1, 1, 1, 5, 100.246f, 458.746f, 100.246f, 458.746f,
+101.527f, 457.406f, 101.25f, 456.746f, 100.121f, 456.262f, 52.0039f, 484.699f, 36.25f, 467.746f,
+36.25f, 467.746f, 46.0586f, 487.012f, 100.246f, 458.746f, 10, 0.1892f, 0, 0,
+0, 0, 0, 0, 5, 100.246f, 458.746f, 100.246f, 458.746f, 101.527f,
+457.406f, 101.25f, 456.746f, 100.121f, 456.262f, 52.0039f, 484.699f, 36.25f, 467.746f, 36.25f,
+467.746f, 46.0586f, 487.012f, 100.246f, 458.746f, 10, 0, 1, 1, 1,
+1, 1, 1, 5, 92.2461f, 454.75f, 92.2422f, 454.75f, 93.3906f, 452.969f,
+93.2461f, 452.75f, 92.125f, 451.672f, 41.0976f, 474.484f, 27.25f, 456.746f, 27.25f, 456.746f,
+34.9258f, 476.105f, 92.2461f, 454.75f, 10, 0.1892f, 0, 0, 0, 0,
+0, 0, 5, 92.2461f, 454.75f, 92.2422f, 454.75f, 93.3906f, 452.969f, 93.2461f,
+452.75f, 92.125f, 451.672f, 41.0976f, 474.484f, 27.25f, 456.746f, 27.25f, 456.746f, 34.9258f,
+476.105f, 92.2461f, 454.75f, 10, 0, 1, 1, 1, 1, 1,
+1, 5, 89.2461f, 449.746f, 89.2461f, 449.742f, 90.6992f, 448.723f, 90.25f, 447.746f,
+89.6211f, 447.262f, 35.9609f, 462.906f, 25.25f, 442.746f, 25.25f, 442.742f, 29.625f, 463.676f,
+89.2461f, 449.746f, 10, 0.1892f, 0, 0, 0, 0, 0, 0,
+5, 89.2461f, 449.746f, 89.2461f, 449.742f, 90.6992f, 448.723f, 90.25f, 447.746f, 89.6211f,
+447.262f, 35.9609f, 462.906f, 25.25f, 442.746f, 25.25f, 442.742f, 29.625f, 463.676f, 89.2461f,
+449.746f, 10, 0, 1, 1, 1, 1, 1, 1, 5,
+100.246f, 448.75f, 100.246f, 448.75f, 101.969f, 447.469f, 101.25f, 446.75f, 100.43f, 446.512f,
+56.3516f, 480.887f, 39.2461f, 466.746f, 39.2461f, 466.742f, 50.75f, 483.941f, 100.246f, 448.75f,
+10, 0.1892f, 0, 0, 0, 0, 0, 0, 5, 100.246f,
+448.75f, 100.246f, 448.75f, 101.969f, 447.469f, 101.25f, 446.75f, 100.43f, 446.512f, 56.3516f,
+480.887f, 39.2461f, 466.746f, 39.2461f, 466.742f, 50.75f, 483.941f, 100.246f, 448.75f, 10,
+0, 1, 1, 1, 1, 1, 1, 5, 79.25f, 480.746f,
+79.25f, 480.746f, 79.6367f, 479.02f, 79.25f, 478.746f, 77.8789f, 478.578f, 46.418f, 524.777f,
+25.25f, 516.75f, 25.25f, 516.75f, 42.0195f, 529.398f, 79.25f, 480.746f, 10, 0.1892f,
+0, 0, 0, 0, 0, 0, 5, 79.25f, 480.746f, 79.25f,
+480.746f, 79.6367f, 479.02f, 79.25f, 478.746f, 77.8789f, 478.578f, 46.418f, 524.777f, 25.25f,
+516.75f, 25.25f, 516.75f, 42.0195f, 529.398f, 79.25f, 480.746f, 10, 0, 1,
+1, 1, 1, 1, 1, 5, 79.25f, 473.746f, 79.25f, 473.742f,
+80.8164f, 471.527f, 80.25f, 470.75f, 79.1914f, 470.723f, 38.5078f, 509.051f, 19.25f, 496.75f,
+19.25f, 496.75f, 33.2148f, 512.609f, 79.25f, 473.746f, 10, 0.1892f, 0, 0,
+0, 0, 0, 0, 5, 79.25f, 473.746f, 79.25f, 473.742f, 80.8164f,
+471.527f, 80.25f, 470.75f, 79.1914f, 470.723f, 38.5078f, 509.051f, 19.25f, 496.75f, 19.25f,
+496.75f, 33.2148f, 512.609f, 79.25f, 473.746f, 10, 0, 1, 1, 1,
+1, 1, 1, 5, 79.25f, 468.75f, 79.25f, 468.75f, 80.8516f, 466.828f,
+80.25f, 466.746f, 79.3086f, 465.875f, 35.2305f, 500.246f, 17.25f, 485.75f, 17.25f, 485.75f,
+29.6289f, 503.301f, 79.25f, 468.75f, 10, 0.1892f, 0, 0, 0, 0,
+0, 0, 5, 79.25f, 468.75f, 79.25f, 468.75f, 80.8516f, 466.828f, 80.25f,
+466.746f, 79.3086f, 465.875f, 35.2305f, 500.246f, 17.25f, 485.75f, 17.25f, 485.75f, 29.6289f,
+503.301f, 79.25f, 468.75f, 10, 0, 1, 1, 1, 1, 1,
+1, 88, 77.2461f, 466.746f, 77.7383f, 459.973f, 78.8242f, 452.746f, 80.25f, 449.746f,
+80.25f, 449.742f, 76.7773f, 435.676f, 86.25f, 420.746f, 86.25f, 420.742f, 86.0195f, 413.238f,
+88.2461f, 409.746f, 88.2461f, 409.742f, 92.1797f, 400.477f, 97.25f, 399.75f, 101.73f, 398.887f,
+111.324f, 395.508f, 122.246f, 393.75f, 122.246f, 393.75f, 141.02f, 378.477f, 137.246f, 364.75f,
+137.242f, 364.75f, 137.059f, 346.355f, 133.246f, 344.75f, 133.246f, 344.75f, 145.859f, 356.918f,
+135.25f, 338.75f, 130.25f, 317.746f, 130.25f, 317.742f, 158.617f, 341.516f, 141.25f, 321.746f,
+130.25f, 292.75f, 130.25f, 292.75f, 152.02f, 312.918f, 144.246f, 303.75f, 140.25f, 293.746f,
+140.25f, 293.746f, 188.098f, 323.918f, 154.246f, 291.746f, 154.242f, 291.746f, 163.02f, 295.316f,
+168.25f, 291.746f, 168.25f, 291.746f, 175.34f, 293.559f, 174.25f, 291.746f, 174.25f, 291.746f,
+151.578f, 280.355f, 147.25f, 259.746f, 147.25f, 259.746f, 156.859f, 271.117f, 153.246f, 258.746f,
+154.246f, 246.746f, 154.242f, 246.746f, 158.18f, 270.238f, 157.25f, 228.746f, 157.25f, 228.742f,
+178.859f, 248.676f, 166.246f, 225.746f, 166.246f, 207.75f, 166.246f, 207.75f, 182.816f, 225.355f,
+176.246f, 211.75f, 176.246f, 211.75f, 186.777f, 220.957f, 182.25f, 203.746f, 182.25f, 203.746f,
+181.5f, 192.797f, 186.25f, 204.746f, 186.25f, 204.746f, 203.938f, 238.777f, 197.25f, 209.75f,
+197.25f, 209.75f, 196.457f, 188.836f, 201.246f, 204.746f, 201.246f, 204.746f, 202.18f, 193.676f,
+212.246f, 185.75f, 212.246f, 185.75f, 210.977f, 241.637f, 225.25f, 201.746f, 229.25f, 183.746f,
+229.25f, 183.742f, 232.539f, 194.117f, 232.246f, 199.75f, 232.246f, 199.75f, 248.379f, 217.879f,
+241.25f, 190.746f, 241.25f, 190.746f, 257.617f, 216.117f, 254.246f, 201.746f, 254.246f, 201.746f,
+245.738f, 183.996f, 247.246f, 178.75f, 247.242f, 178.75f, 265.977f, 216.996f, 267.246f, 218.75f,
+267.246f, 218.75f, 265.098f, 172.117f, 277.246f, 211.75f, 277.246f, 211.75f, 283.137f, 198.516f,
+280.246f, 193.746f, 280.242f, 193.746f, 288.859f, 202.477f, 288.246f, 205.746f, 288.246f, 205.742f,
+293.039f, 215.016f, 296.25f, 199.75f, 296.25f, 199.75f, 298.098f, 189.719f, 300.246f, 192.746f,
+300.246f, 192.746f, 304.258f, 166.836f, 305.25f, 191.746f, 305.25f, 191.746f, 307.34f, 206.879f,
+299.246f, 219.75f, 299.246f, 219.75f, 300.297f, 223.156f, 297.246f, 227.746f, 297.246f, 227.742f,
+312.18f, 203.797f, 304.25f, 235.746f, 304.25f, 235.746f, 316.578f, 226.676f, 318.25f, 226.746f,
+318.25f, 226.746f, 302.937f, 252.195f, 312.246f, 246.746f, 312.242f, 246.746f, 306.898f, 258.355f,
+326.25f, 244.75f, 326.25f, 244.75f, 309.098f, 262.758f, 328.25f, 251.75f, 328.25f, 251.75f,
+337.258f, 245.156f, 329.25f, 255.75f, 329.25f, 255.75f, 313.059f, 273.758f, 337.25f, 253.75f,
+337.25f, 253.75f, 350.02f, 235.918f, 351.25f, 232.75f, 351.25f, 232.75f, 339.898f, 264.957f,
+335.246f, 267.75f, 335.242f, 267.75f, 344.301f, 308.078f, 389.246f, 290.75f, 389.246f, 290.75f,
+397.098f, 271.996f, 402.246f, 291.746f, 402.242f, 291.746f, 416.02f, 299.277f, 428.25f, 268.75f,
+428.25f, 268.75f, 432.738f, 283.879f, 432.246f, 286.746f, 432.246f, 286.742f, 439.34f, 285.637f,
+438.25f, 286.746f, 438.25f, 286.742f, 452.98f, 282.117f, 454.246f, 282.746f, 454.246f, 282.746f,
+461.777f, 275.516f, 462.246f, 279.75f, 462.242f, 279.75f, 472.34f, 276.398f, 470.25f, 280.746f,
+470.25f, 280.746f, 479.82f, 263.195f, 480.246f, 258.746f, 483.25f, 274.75f, 485.25f, 271.746f,
+485.25f, 271.746f, 486.859f, 279.918f, 486.25f, 280.746f, 485.098f, 282.559f, 507.98f, 273.758f,
+513.246f, 250.746f, 515.246f, 241.75f, 515.242f, 241.75f, 522.059f, 257.918f, 520.246f, 262.75f,
+520.246f, 262.75f, 526.02f, 261.438f, 526.246f, 256.746f, 526.242f, 256.746f, 530.859f, 282.117f,
+525.25f, 288.746f, 525.25f, 288.742f, 530.418f, 289.598f, 531.246f, 285.75f, 531.246f, 293.746f,
+531.246f, 293.746f, 539.66f, 292.676f, 539.246f, 295.746f, 539.242f, 295.742f, 544.5f, 299.719f,
+546.246f, 294.75f, 546.242f, 294.75f, 533.059f, 333.156f, 553.246f, 311.75f, 553.246f, 311.75f,
+561.219f, 300.156f, 557.246f, 320.75f, 553.301f, 341.516f, 548.898f, 343.277f, 554.25f, 343.746f,
+554.25f, 343.742f, 555.059f, 347.676f, 553.246f, 349.75f, 550.66f, 351.195f, 554.25f, 349.75f,
+554.25f, 349.75f, 554.25f, 349.75f, 559.461f, 345.035f, 553.246f, 368.746f, 553.246f, 368.746f,
+560.777f, 367.477f, 547.25f, 399.75f, 547.25f, 399.75f, 550.66f, 402.238f, 546.246f, 411.746f,
+546.242f, 411.742f, 555.059f, 406.637f, 558.25f, 408.75f, 558.25f, 408.75f, 557.699f, 410.156f,
+554.25f, 414.746f, 554.25f, 414.746f, 530.418f, 474.84f, 553.246f, 450.75f, 553.246f, 450.75f,
+565.895f, 435.73f, 559.246f, 460.746f, 559.242f, 460.742f, 548.832f, 487.223f, 549.25f, 491.746f,
+77.2461f, 466.746f, 10, 1.1f, 0, 0, 0, 0, 0, 0,
+88, 77.2461f, 466.746f, 77.7383f, 459.973f, 78.8242f, 452.746f, 80.25f, 449.746f, 80.25f,
+449.742f, 76.7773f, 435.676f, 86.25f, 420.746f, 86.25f, 420.742f, 86.0195f, 413.238f, 88.2461f,
+409.746f, 88.2461f, 409.742f, 92.1797f, 400.477f, 97.25f, 399.75f, 101.73f, 398.887f, 111.324f,
+395.508f, 122.246f, 393.75f, 122.246f, 393.75f, 141.02f, 378.477f, 137.246f, 364.75f, 137.242f,
+364.75f, 137.059f, 346.355f, 133.246f, 344.75f, 133.246f, 344.75f, 145.859f, 356.918f, 135.25f,
+338.75f, 130.25f, 317.746f, 130.25f, 317.742f, 158.617f, 341.516f, 141.25f, 321.746f, 130.25f,
+292.75f, 130.25f, 292.75f, 152.02f, 312.918f, 144.246f, 303.75f, 140.25f, 293.746f, 140.25f,
+293.746f, 188.098f, 323.918f, 154.246f, 291.746f, 154.242f, 291.746f, 163.02f, 295.316f, 168.25f,
+291.746f, 168.25f, 291.746f, 175.34f, 293.559f, 174.25f, 291.746f, 174.25f, 291.746f, 151.578f,
+280.355f, 147.25f, 259.746f, 147.25f, 259.746f, 156.859f, 271.117f, 153.246f, 258.746f, 154.246f,
+246.746f, 154.242f, 246.746f, 158.18f, 270.238f, 157.25f, 228.746f, 157.25f, 228.742f, 178.859f,
+248.676f, 166.246f, 225.746f, 166.246f, 207.75f, 166.246f, 207.75f, 182.816f, 225.355f, 176.246f,
+211.75f, 176.246f, 211.75f, 186.777f, 220.957f, 182.25f, 203.746f, 182.25f, 203.746f, 181.5f,
+192.797f, 186.25f, 204.746f, 186.25f, 204.746f, 203.938f, 238.777f, 197.25f, 209.75f, 197.25f,
+209.75f, 196.457f, 188.836f, 201.246f, 204.746f, 201.246f, 204.746f, 202.18f, 193.676f, 212.246f,
+185.75f, 212.246f, 185.75f, 210.977f, 241.637f, 225.25f, 201.746f, 229.25f, 183.746f, 229.25f,
+183.742f, 232.539f, 194.117f, 232.246f, 199.75f, 232.246f, 199.75f, 248.379f, 217.879f, 241.25f,
+190.746f, 241.25f, 190.746f, 257.617f, 216.117f, 254.246f, 201.746f, 254.246f, 201.746f, 245.738f,
+183.996f, 247.246f, 178.75f, 247.242f, 178.75f, 265.977f, 216.996f, 267.246f, 218.75f, 267.246f,
+218.75f, 265.098f, 172.117f, 277.246f, 211.75f, 277.246f, 211.75f, 283.137f, 198.516f, 280.246f,
+193.746f, 280.242f, 193.746f, 288.859f, 202.477f, 288.246f, 205.746f, 288.246f, 205.742f, 293.039f,
+215.016f, 296.25f, 199.75f, 296.25f, 199.75f, 298.098f, 189.719f, 300.246f, 192.746f, 300.246f,
+192.746f, 304.258f, 166.836f, 305.25f, 191.746f, 305.25f, 191.746f, 307.34f, 206.879f, 299.246f,
+219.75f, 299.246f, 219.75f, 300.297f, 223.156f, 297.246f, 227.746f, 297.246f, 227.742f, 312.18f,
+203.797f, 304.25f, 235.746f, 304.25f, 235.746f, 316.578f, 226.676f, 318.25f, 226.746f, 318.25f,
+226.746f, 302.937f, 252.195f, 312.246f, 246.746f, 312.242f, 246.746f, 306.898f, 258.355f, 326.25f,
+244.75f, 326.25f, 244.75f, 309.098f, 262.758f, 328.25f, 251.75f, 328.25f, 251.75f, 337.258f,
+245.156f, 329.25f, 255.75f, 329.25f, 255.75f, 313.059f, 273.758f, 337.25f, 253.75f, 337.25f,
+253.75f, 350.02f, 235.918f, 351.25f, 232.75f, 351.25f, 232.75f, 339.898f, 264.957f, 335.246f,
+267.75f, 335.242f, 267.75f, 344.301f, 308.078f, 389.246f, 290.75f, 389.246f, 290.75f, 397.098f,
+271.996f, 402.246f, 291.746f, 402.242f, 291.746f, 416.02f, 299.277f, 428.25f, 268.75f, 428.25f,
+268.75f, 432.738f, 283.879f, 432.246f, 286.746f, 432.246f, 286.742f, 439.34f, 285.637f, 438.25f,
+286.746f, 438.25f, 286.742f, 452.98f, 282.117f, 454.246f, 282.746f, 454.246f, 282.746f, 461.777f,
+275.516f, 462.246f, 279.75f, 462.242f, 279.75f, 472.34f, 276.398f, 470.25f, 280.746f, 470.25f,
+280.746f, 479.82f, 263.195f, 480.246f, 258.746f, 483.25f, 274.75f, 485.25f, 271.746f, 485.25f,
+271.746f, 486.859f, 279.918f, 486.25f, 280.746f, 485.098f, 282.559f, 507.98f, 273.758f, 513.246f,
+250.746f, 515.246f, 241.75f, 515.242f, 241.75f, 522.059f, 257.918f, 520.246f, 262.75f, 520.246f,
+262.75f, 526.02f, 261.438f, 526.246f, 256.746f, 526.242f, 256.746f, 530.859f, 282.117f, 525.25f,
+288.746f, 525.25f, 288.742f, 530.418f, 289.598f, 531.246f, 285.75f, 531.246f, 293.746f, 531.246f,
+293.746f, 539.66f, 292.676f, 539.246f, 295.746f, 539.242f, 295.742f, 544.5f, 299.719f, 546.246f,
+294.75f, 546.242f, 294.75f, 533.059f, 333.156f, 553.246f, 311.75f, 553.246f, 311.75f, 561.219f,
+300.156f, 557.246f, 320.75f, 553.301f, 341.516f, 548.898f, 343.277f, 554.25f, 343.746f, 554.25f,
+343.742f, 555.059f, 347.676f, 553.246f, 349.75f, 550.66f, 351.195f, 554.25f, 349.75f, 554.25f,
+349.75f, 554.25f, 349.75f, 559.461f, 345.035f, 553.246f, 368.746f, 553.246f, 368.746f, 560.777f,
+367.477f, 547.25f, 399.75f, 547.25f, 399.75f, 550.66f, 402.238f, 546.246f, 411.746f, 546.242f,
+411.742f, 555.059f, 406.637f, 558.25f, 408.75f, 558.25f, 408.75f, 557.699f, 410.156f, 554.25f,
+414.746f, 554.25f, 414.746f, 530.418f, 474.84f, 553.246f, 450.75f, 553.246f, 450.75f, 565.895f,
+435.73f, 559.246f, 460.746f, 559.242f, 460.742f, 548.832f, 487.223f, 549.25f, 491.746f, 77.2461f,
+466.746f, 10, 0, 0.8f, 0.45f, 0.15f, 0.8f, 0.45f, 0.15f, 44,
+549.25f, 491.746f, 550.379f, 491.531f, 552.805f, 490.293f, 554.25f, 488.746f, 554.25f, 488.742f,
+561.66f, 476.598f, 556.25f, 496.75f, 556.25f, 496.75f, 545.82f, 528.52f, 555.246f, 515.746f,
+555.246f, 515.742f, 562.098f, 508.277f, 558.25f, 522.746f, 554.328f, 541.309f, 551.25f, 548.746f,
+551.25f, 548.746f, 551.25f, 548.746f, 564.301f, 543.039f, 535.246f, 586.75f, 544.246f, 582.75f,
+544.246f, 582.75f, 522.938f, 626.199f, 499.25f, 631.746f, 490.25f, 638.746f, 490.25f, 638.742f,
+532.621f, 680.316f, 518.25f, 720.75f, 518.25f, 720.75f, 511.059f, 726.52f, 500.246f, 716.75f,
+500.246f, 716.75f, 493.461f, 711.117f, 487.246f, 712.75f, 487.246f, 712.75f, 452.98f, 711.559f,
+451.25f, 711.746f, 448.578f, 711.559f, 410.301f, 752.477f, 338.25f, 732.746f, 338.25f, 732.742f,
+332.418f, 730.918f, 327.25f, 731.75f, 327.25f, 731.75f, 307.34f, 749.84f, 253.246f, 724.746f,
+253.246f, 724.746f, 242.656f, 722.559f, 241.25f, 722.746f, 239.137f, 722.559f, 236.059f, 722.559f,
+227.25f, 715.746f, 218.457f, 708.477f, 218.02f, 707.598f, 216.25f, 705.75f, 216.25f, 705.75f,
+197.777f, 693.52f, 192.25f, 692.75f, 192.25f, 692.75f, 179.738f, 685.598f, 175.25f, 674.75f,
+171.246f, 673.746f, 171.246f, 673.742f, 169.18f, 665.359f, 168.25f, 663.75f, 168.25f, 663.75f,
+163.457f, 660.078f, 162.25f, 653.746f, 162.25f, 653.742f, 152.898f, 647.316f, 153.246f, 642.746f,
+153.242f, 642.742f, 151.578f, 636.758f, 150.246f, 631.746f, 150.246f, 631.742f, 142.777f, 626.199f,
+143.246f, 622.75f, 143.242f, 622.75f, 135.297f, 607.719f, 136.25f, 599.75f, 136.25f, 599.75f,
+129.578f, 600.68f, 126.246f, 597.75f, 126.242f, 597.75f, 125.617f, 592.758f, 124.25f, 592.746f,
+124.25f, 592.746f, 120.777f, 591, 123.25f, 586.75f, 123.25f, 586.75f, 121.656f, 583.52f,
+121.246f, 581.746f, 121.246f, 581.746f, 122.098f, 578.68f, 117.25f, 572.746f, 117.25f, 572.742f,
+110.219f, 551.84f, 112.25f, 545.75f, 112.25f, 545.75f, 112.859f, 540.84f, 110.246f, 538.75f,
+110.246f, 538.75f, 105.816f, 539.52f, 115.246f, 526.746f, 115.242f, 526.742f, 115.938f, 525,
+112.25f, 522.746f, 112.25f, 522.746f, 93.5f, 518.398f, 91.25f, 500.746f, 91.25f, 500.746f,
+75.8984f, 484.078f, 76.2461f, 478.746f, 75.8984f, 475.824f, 76.1953f, 472.359f, 77.2461f, 467.746f,
+77.2461f, 467.746f, 76.3398f, 458.117f, 106.25f, 456.746f, 137.059f, 456.355f, 549.25f, 491.746f,
+549.25f, 491.746f, 10, 1.1f, 0, 0, 0, 0, 0, 0,
+44, 549.25f, 491.746f, 550.379f, 491.531f, 552.805f, 490.293f, 554.25f, 488.746f, 554.25f,
+488.742f, 561.66f, 476.598f, 556.25f, 496.75f, 556.25f, 496.75f, 545.82f, 528.52f, 555.246f,
+515.746f, 555.246f, 515.742f, 562.098f, 508.277f, 558.25f, 522.746f, 554.328f, 541.309f, 551.25f,
+548.746f, 551.25f, 548.746f, 551.25f, 548.746f, 564.301f, 543.039f, 535.246f, 586.75f, 544.246f,
+582.75f, 544.246f, 582.75f, 522.938f, 626.199f, 499.25f, 631.746f, 490.25f, 638.746f, 490.25f,
+638.742f, 532.621f, 680.316f, 518.25f, 720.75f, 518.25f, 720.75f, 511.059f, 726.52f, 500.246f,
+716.75f, 500.246f, 716.75f, 493.461f, 711.117f, 487.246f, 712.75f, 487.246f, 712.75f, 452.98f,
+711.559f, 451.25f, 711.746f, 448.578f, 711.559f, 410.301f, 752.477f, 338.25f, 732.746f, 338.25f,
+732.742f, 332.418f, 730.918f, 327.25f, 731.75f, 327.25f, 731.75f, 307.34f, 749.84f, 253.246f,
+724.746f, 253.246f, 724.746f, 242.656f, 722.559f, 241.25f, 722.746f, 239.137f, 722.559f, 236.059f,
+722.559f, 227.25f, 715.746f, 218.457f, 708.477f, 218.02f, 707.598f, 216.25f, 705.75f, 216.25f,
+705.75f, 197.777f, 693.52f, 192.25f, 692.75f, 192.25f, 692.75f, 179.738f, 685.598f, 175.25f,
+674.75f, 171.246f, 673.746f, 171.246f, 673.742f, 169.18f, 665.359f, 168.25f, 663.75f, 168.25f,
+663.75f, 163.457f, 660.078f, 162.25f, 653.746f, 162.25f, 653.742f, 152.898f, 647.316f, 153.246f,
+642.746f, 153.242f, 642.742f, 151.578f, 636.758f, 150.246f, 631.746f, 150.246f, 631.742f, 142.777f,
+626.199f, 143.246f, 622.75f, 143.242f, 622.75f, 135.297f, 607.719f, 136.25f, 599.75f, 136.25f,
+599.75f, 129.578f, 600.68f, 126.246f, 597.75f, 126.242f, 597.75f, 125.617f, 592.758f, 124.25f,
+592.746f, 124.25f, 592.746f, 120.777f, 591, 123.25f, 586.75f, 123.25f, 586.75f, 121.656f,
+583.52f, 121.246f, 581.746f, 121.246f, 581.746f, 122.098f, 578.68f, 117.25f, 572.746f, 117.25f,
+572.742f, 110.219f, 551.84f, 112.25f, 545.75f, 112.25f, 545.75f, 112.859f, 540.84f, 110.246f,
+538.75f, 110.246f, 538.75f, 105.816f, 539.52f, 115.246f, 526.746f, 115.242f, 526.742f, 115.938f,
+525, 112.25f, 522.746f, 112.25f, 522.746f, 93.5f, 518.398f, 91.25f, 500.746f, 91.25f,
+500.746f, 75.8984f, 484.078f, 76.2461f, 478.746f, 75.8984f, 475.824f, 76.1953f, 472.359f, 77.2461f,
+467.746f, 77.2461f, 467.746f, 76.3398f, 458.117f, 106.25f, 456.746f, 137.059f, 456.355f, 549.25f,
+491.746f, 549.25f, 491.746f, 10, 0, 0.8f, 0.45f, 0.15f, 0.8f, 0.45f,
+0.15f, 18, 93.2461f, 466.746f, 65.3398f, 510.477f, 81.2461f, 448.75f, 81.2461f, 448.75f,
+90.8594f, 410.598f, 233.246f, 451.746f, 233.246f, 451.746f, 233.246f, 451.742f, 419.098f, 485.398f,
+431.246f, 489.746f, 443.738f, 494.199f, 548.246f, 486.746f, 548.246f, 486.746f, 542.246f, 505.75f,
+471.02f, 556.68f, 449.898f, 531.156f, 435.246f, 535.746f, 419.98f, 539.957f, 422.621f, 529.398f,
+419.246f, 528.746f, 415.578f, 527.637f, 372.461f, 554.918f, 365.246f, 553.75f, 358.379f, 553.156f,
+330.504f, 579.285f, 347.25f, 544.746f, 364.539f, 506.957f, 282.699f, 501.238f, 264.246f, 513.746f,
+245.738f, 525.879f, 272.25f, 493.746f, 272.25f, 493.746f, 292.379f, 471.316f, 254.246f, 489.746f,
+254.246f, 489.746f, 216.699f, 503.879f, 190.297f, 475.719f, 187.246f, 474.75f, 183.258f, 473.957f,
+177.977f, 470.438f, 177.246f, 477.746f, 176.219f, 484.52f, 167.957f, 502.891f, 133.246f, 473.746f,
+111.098f, 455.695f, 96.25f, 479.75f, 96.25f, 479.75f, 93.2461f, 466.746f, 10, 0,
+0.91f, 0.5f, 0.228f, 0.91f, 0.5f, 0.228f, 19, 367.246f, 551.75f, 359.82f,
+551.238f, 331.914f, 577.352f, 348.25f, 542.75f, 366.641f, 503.719f, 284.141f, 499.316f, 265.246f,
+511.746f, 247.18f, 523.957f, 273.25f, 491.746f, 273.25f, 491.746f, 293.82f, 469.398f, 256.246f,
+487.75f, 256.246f, 487.75f, 218.137f, 501.957f, 191.738f, 473.797f, 188.246f, 472.75f, 184.699f,
+472.039f, 179.418f, 468.516f, 178.246f, 475.746f, 177.656f, 482.598f, 169.543f, 500.785f, 134.25f,
+471.746f, 111.18f, 452.957f, 96.25f, 476.75f, 96.25f, 476.75f, 93.2461f, 465.75f, 65.3164f,
+509.219f, 82.2461f, 444.746f, 82.2461f, 444.746f, 91.5781f, 407.238f, 235.246f, 449.746f, 235.246f,
+449.746f, 235.242f, 449.742f, 420.539f, 483.477f, 433.246f, 487.75f, 445.18f, 492.277f, 549.25f,
+485.75f, 549.25f, 485.75f, 543.25f, 504.746f, 471.578f, 555.398f, 451.34f, 529.238f, 436.25f,
+533.746f, 421.418f, 538.039f, 424.059f, 527.477f, 420.246f, 526.746f, 417.02f, 525.719f, 373.898f,
+552.996f, 367.246f, 551.75f, 10, 0, 0.919f, 0.55f, 0.305f, 0.919f, 0.55f,
+0.305f, 19, 368.246f, 549.75f, 361.258f, 549.316f, 334.051f, 575.75f, 350.25f, 540.75f,
+367.641f, 500.695f, 285.578f, 497.398f, 267.246f, 509.75f, 248.617f, 522.035f, 275.246f, 489.746f,
+275.246f, 489.746f, 295.258f, 467.477f, 257.246f, 485.75f, 257.246f, 485.75f, 219.578f, 500.035f,
+193.18f, 471.875f, 189.246f, 470.75f, 186.137f, 470.117f, 180.859f, 466.598f, 180.246f, 473.746f,
+179.098f, 480.676f, 171.125f, 498.68f, 136.25f, 469.746f, 111.258f, 450.215f, 97.25f, 472.75f,
+97.25f, 472.75f, 93.2461f, 463.75f, 66.6172f, 506.637f, 82.2461f, 441.75f, 82.2461f, 441.75f,
+92.2969f, 403.879f, 236.25f, 447.746f, 236.25f, 447.746f, 236.25f, 447.746f, 421.98f, 481.559f,
+434.246f, 485.75f, 446.617f, 490.355f, 549.25f, 483.75f, 549.25f, 483.75f, 543.25f, 502.746f,
+472.141f, 554.117f, 452.777f, 527.316f, 438.25f, 531.75f, 422.859f, 536.117f, 425.5f, 525.559f,
+422.246f, 524.746f, 418.457f, 523.797f, 375.34f, 551.078f, 368.246f, 549.75f, 10, 0,
+0.928f, 0.6f, 0.382f, 0.928f, 0.6f, 0.382f, 19, 369.25f, 548.746f, 362.699f,
+547.398f, 335.496f, 573.832f, 351.25f, 538.75f, 369.738f, 497.285f, 286.43f, 495.867f, 268.246f,
+507.75f, 250.059f, 520.117f, 276.246f, 487.75f, 276.246f, 487.75f, 296.699f, 465.559f, 259.25f,
+483.75f, 259.25f, 483.75f, 221.02f, 498.117f, 194.617f, 469.957f, 191.246f, 468.75f, 187.578f,
+468.199f, 182.301f, 464.676f, 181.25f, 471.746f, 180.539f, 478.758f, 172.711f, 496.574f, 137.246f,
+467.746f, 111.336f, 447.477f, 97.25f, 469.746f, 97.25f, 469.746f, 93.2461f, 461.75f, 68.7969f,
+502.516f, 83.2461f, 438.746f, 83.2461f, 438.746f, 93.0195f, 400.516f, 237.25f, 445.746f, 237.25f,
+445.746f, 237.25f, 445.746f, 423.418f, 479.637f, 435.246f, 483.75f, 448.059f, 488.438f, 550.246f,
+481.75f, 550.246f, 481.75f, 544.246f, 501.75f, 472.699f, 552.84f, 454.219f, 525.398f, 439.25f,
+529.75f, 424.301f, 534.199f, 426.938f, 523.637f, 423.246f, 522.746f, 419.898f, 521.879f, 376.777f,
+549.156f, 369.25f, 548.746f, 10, 0, 0.937f, 0.65f, 0.46f, 0.937f, 0.65f,
+0.46f, 19, 371.25f, 546.746f, 364.141f, 545.477f, 337.492f, 572.156f, 352.25f, 536.75f,
+371.18f, 493.559f, 288.457f, 493.559f, 270.25f, 505.75f, 251.5f, 518.195f, 278.246f, 485.75f,
+278.246f, 485.75f, 298.141f, 463.637f, 260.25f, 481.75f, 260.25f, 481.75f, 222.457f, 496.195f,
+196.059f, 468.035f, 192.25f, 466.746f, 189.02f, 466.277f, 183.738f, 462.758f, 183.25f, 469.746f,
+181.98f, 476.836f, 174.297f, 494.473f, 139.246f, 466.746f, 111.418f, 444.738f, 97.25f, 466.746f,
+97.25f, 466.746f, 93.2461f, 460.746f, 70.9766f, 498.617f, 84.25f, 434.746f, 84.25f, 434.746f,
+93.7383f, 397.156f, 239.25f, 444.746f, 239.25f, 444.746f, 239.25f, 444.742f, 424.859f, 477.715f,
+437.25f, 481.75f, 449.5f, 486.516f, 550.246f, 479.75f, 550.246f, 479.75f, 544.246f, 500.746f,
+473.262f, 551.559f, 455.66f, 523.477f, 440.25f, 527.75f, 425.738f, 532.277f, 428.379f, 521.715f,
+425.25f, 520.75f, 421.34f, 519.957f, 378.219f, 547.238f, 371.25f, 546.746f, 10, 0,
+0.946f, 0.7f, 0.537f, 0.946f, 0.7f, 0.537f, 19, 372.25f, 544.746f, 365.578f,
+543.559f, 337.02f, 569.352f, 354.246f, 534.75f, 375.258f, 492.078f, 289.898f, 491.637f, 271.25f,
+503.75f, 252.938f, 516.277f, 279.246f, 483.75f, 279.246f, 483.75f, 299.578f, 461.719f, 261.25f,
+479.75f, 261.25f, 479.75f, 223.898f, 494.277f, 197.5f, 466.117f, 194.25f, 464.746f, 190.457f,
+464.355f, 185.18f, 460.836f, 184.25f, 467.746f, 183.418f, 474.918f, 175.879f, 492.367f, 140.25f,
+464.746f, 111.5f, 441.996f, 98.2461f, 462.746f, 98.2461f, 462.746f, 92.2461f, 458.746f, 72.9375f,
+495.156f, 85.25f, 431.746f, 85.25f, 431.746f, 94.457f, 393.797f, 240.25f, 442.746f, 240.25f,
+442.746f, 240.25f, 442.742f, 426.301f, 475.797f, 438.25f, 479.75f, 450.941f, 484.598f, 551.25f,
+477.746f, 551.25f, 477.746f, 545.25f, 498.75f, 473.82f, 550.277f, 457.102f, 521.559f, 442.246f,
+525.75f, 427.18f, 530.355f, 429.82f, 519.797f, 426.25f, 518.75f, 422.781f, 518.039f, 379.66f,
+545.316f, 372.25f, 544.746f, 10, 0, 0.955f, 0.75f, 0.614f, 0.955f, 0.75f,
+0.614f, 19, 374.25f, 542.75f, 367.02f, 541.637f, 338.043f, 567.223f, 355.246f, 532.746f,
+378.02f, 488.836f, 291.34f, 489.715f, 273.25f, 501.75f, 254.379f, 514.355f, 281.25f, 481.75f,
+281.25f, 481.75f, 301.02f, 459.797f, 263.25f, 478.746f, 263.25f, 478.746f, 225.34f, 492.355f,
+198.938f, 464.195f, 195.25f, 463.75f, 191.898f, 462.438f, 186.617f, 458.918f, 185.25f, 465.75f,
+184.859f, 472.996f, 177.465f, 490.262f, 141.25f, 462.746f, 111.578f, 439.258f, 98.2461f, 459.75f,
+98.2461f, 459.75f, 92.2461f, 456.746f, 75.1172f, 490.156f, 85.25f, 428.75f, 85.25f, 428.75f,
+95.1797f, 390.438f, 242.246f, 440.746f, 242.246f, 440.746f, 242.246f, 440.742f, 427.738f, 473.875f,
+440.25f, 478.746f, 452.379f, 482.676f, 551.25f, 475.746f, 551.25f, 475.746f, 545.25f, 497.746f,
+474.379f, 548.996f, 458.539f, 519.637f, 443.246f, 523.75f, 428.621f, 528.438f, 431.258f, 517.875f,
+427.25f, 516.75f, 424.219f, 516.117f, 381.102f, 543.398f, 374.25f, 542.75f, 10, 0,
+0.964f, 0.8f, 0.691f, 0.964f, 0.8f, 0.691f, 19, 375.246f, 540.75f, 368.461f,
+539.719f, 338.273f, 564.66f, 357.246f, 530.746f, 381.219f, 487.355f, 292.777f, 487.797f, 274.25f,
+499.746f, 255.82f, 512.438f, 282.25f, 479.75f, 282.25f, 479.75f, 302.457f, 457.879f, 264.246f,
+476.75f, 264.246f, 476.75f, 226.777f, 490.438f, 200.379f, 462.277f, 197.25f, 461.75f, 193.34f,
+460.516f, 188.059f, 456.996f, 187.246f, 463.75f, 186.297f, 471.078f, 179.047f, 488.156f, 143.246f,
+460.746f, 111.656f, 436.516f, 99.2461f, 456.746f, 99.2461f, 456.746f, 92.2461f, 454.75f, 76.8555f,
+486.477f, 86.25f, 424.75f, 86.25f, 424.75f, 95.8984f, 387.074f, 243.246f, 438.746f, 243.246f,
+438.746f, 243.246f, 438.742f, 429.18f, 471.957f, 441.246f, 476.75f, 453.82f, 480.758f, 552.25f,
+474.75f, 552.25f, 474.75f, 546.246f, 496.75f, 474.941f, 547.719f, 459.98f, 517.719f, 445.246f,
+521.746f, 430.059f, 526.516f, 432.699f, 515.957f, 429.25f, 514.75f, 425.66f, 514.195f, 382.539f,
+541.477f, 375.246f, 540.75f, 10, 0, 0.973f, 0.85f, 0.769f, 0.973f, 0.85f,
+0.769f, 19, 377.246f, 538.75f, 369.898f, 537.797f, 339.715f, 562.738f, 358.25f, 528.746f,
+382.66f, 485.437f, 294.219f, 485.875f, 275.246f, 497.746f, 257.258f, 510.516f, 283.25f, 477.746f,
+283.25f, 477.746f, 303.898f, 455.957f, 266.246f, 474.75f, 266.246f, 474.75f, 228.219f, 488.516f,
+201.816f, 460.355f, 198.246f, 459.75f, 194.777f, 458.598f, 189.5f, 455.078f, 188.246f, 461.75f,
+187.738f, 469.156f, 180.633f, 486.051f, 144.246f, 458.746f, 111.738f, 433.777f, 99.2461f, 452.75f,
+99.2461f, 452.75f, 92.2461f, 453.746f, 77.7188f, 482.578f, 87.2461f, 421.75f, 87.2461f, 421.75f,
+96.6172f, 383.715f, 245.246f, 436.746f, 245.246f, 436.746f, 245.246f, 436.746f, 430.621f, 470.035f,
+443.246f, 474.75f, 455.258f, 478.836f, 552.25f, 472.75f, 552.25f, 472.75f, 547.25f, 495.746f,
+475.5f, 546.438f, 461.418f, 515.797f, 446.246f, 519.746f, 431.5f, 524.598f, 434.141f, 514.035f,
+430.246f, 512.75f, 427.098f, 512.277f, 383.98f, 539.555f, 377.246f, 538.75f, 10, 0,
+0.982f, 0.9f, 0.846f, 0.982f, 0.9f, 0.846f, 19, 378.246f, 536.75f, 371.34f,
+535.879f, 341.578f, 561.055f, 360.25f, 526.746f, 384.098f, 482.195f, 295.66f, 483.957f, 277.246f,
+496.75f, 258.699f, 508.598f, 285.25f, 475.746f, 285.25f, 475.746f, 305.34f, 454.035f, 267.246f,
+472.75f, 267.246f, 472.75f, 229.66f, 486.598f, 203.258f, 458.438f, 199.246f, 457.75f, 196.219f,
+456.676f, 190.937f, 453.156f, 190.246f, 459.75f, 189.18f, 467.238f, 182.219f, 483.949f, 146.25f,
+456.746f, 111.82f, 431.035f, 99.2461f, 449.746f, 99.2461f, 449.746f, 92.2461f, 451.746f, 78.3594f,
+478.238f, 87.2461f, 417.75f, 87.2461f, 417.75f, 97.3399f, 380.355f, 246.246f, 434.746f, 246.246f,
+434.746f, 246.242f, 434.746f, 432.059f, 468.117f, 444.246f, 472.75f, 456.699f, 476.918f, 553.246f,
+470.75f, 553.246f, 470.75f, 547.25f, 493.746f, 476.059f, 545.156f, 462.859f, 513.879f, 448.25f,
+518.75f, 432.938f, 522.676f, 435.578f, 512.117f, 432.246f, 510.746f, 428.539f, 510.355f, 385.418f,
+537.637f, 378.246f, 536.75f, 10, 0, 0.991f, 0.95f, 0.923f, 0.991f, 0.95f,
+0.923f, 19, 380.25f, 534.75f, 372.777f, 533.957f, 344.207f, 559.746f, 361.25f, 524.746f,
+384.66f, 478.078f, 297.098f, 482.035f, 278.246f, 494.75f, 260.141f, 506.676f, 286.246f, 473.746f,
+286.246f, 473.746f, 306.777f, 452.117f, 269.246f, 470.75f, 269.246f, 470.75f, 231.098f, 484.676f,
+204.699f, 456.516f, 201.246f, 455.746f, 197.66f, 454.758f, 192.379f, 451.238f, 191.246f, 458.746f,
+190.621f, 465.316f, 183.801f, 481.844f, 147.25f, 454.75f, 111.898f, 428.297f, 100.246f, 446.75f,
+100.246f, 446.75f, 92.2461f, 449.746f, 78.5586f, 475.656f, 88.2461f, 414.746f, 88.2461f, 414.746f,
+98.0586f, 376.996f, 248.25f, 432.75f, 248.25f, 432.75f, 248.25f, 432.75f, 433.5f, 466.195f,
+446.246f, 470.75f, 458.141f, 474.996f, 553.246f, 468.75f, 553.246f, 468.75f, 548.246f, 492.75f,
+476.621f, 543.879f, 464.301f, 511.957f, 449.25f, 516.75f, 434.379f, 520.758f, 437.02f, 510.195f,
+433.246f, 509.75f, 429.98f, 508.438f, 386.859f, 535.719f, 380.25f, 534.75f, 10, 0,
+1, 1, 1, 1, 1, 1, 18, 92.2461f, 448.75f, 78.5391f,
+472.637f, 89.2461f, 411.746f, 89.2461f, 411.746f, 98.7773f, 373.637f, 249.25f, 430.75f, 249.25f,
+430.75f, 249.25f, 430.75f, 434.938f, 464.277f, 447.25f, 468.75f, 459.578f, 473.078f, 553.246f,
+466.746f, 553.246f, 466.746f, 548.246f, 491.746f, 477.18f, 542.598f, 465.738f, 510.039f, 451.25f,
+514.75f, 435.82f, 518.84f, 438.461f, 508.277f, 435.246f, 507.75f, 431.418f, 506.52f, 388.301f,
+533.797f, 381.25f, 532.746f, 374.219f, 532.039f, 346.477f, 558.227f, 363.25f, 522.746f, 387.23f,
+470.762f, 295.941f, 481.848f, 280.246f, 492.75f, 261.578f, 504.758f, 288.246f, 471.746f, 288.246f,
+471.746f, 308.219f, 450.195f, 270.25f, 468.75f, 270.25f, 468.75f, 232.539f, 482.758f, 206.137f,
+454.598f, 202.246f, 453.746f, 199.098f, 452.836f, 193.816f, 449.316f, 193.25f, 456.746f, 192.059f,
+463.398f, 185.387f, 479.738f, 149.246f, 452.75f, 111.977f, 425.559f, 100.246f, 442.746f, 100.246f,
+442.746f, 92.2461f, 448.75f, 10, 0, 0, 0, 0, 0, 0,
+0, 7, 138.246f, 415.75f, 138.246f, 415.75f, 130.457f, 402.676f, 153.246f, 387.746f,
+153.242f, 387.742f, 154.879f, 386.617f, 135.25f, 390.746f, 135.25f, 390.746f, 128.258f, 393.438f,
+126.246f, 404.75f, 126.242f, 404.75f, 121.219f, 409.719f, 116.246f, 415.75f, 110.656f, 422.035f,
+138.246f, 415.75f, 138.246f, 415.75f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 8, 292.25f, 467.746f, 292.25f, 467.746f, 311.848f, 438.297f, 311.246f,
+432.75f, 309.758f, 421.598f, 309.539f, 411.035f, 313.246f, 406.75f, 316.578f, 402.238f, 326.25f,
+365.746f, 326.25f, 365.746f, 326.25f, 365.742f, 325.82f, 364.398f, 339.25f, 405.746f, 339.25f,
+405.742f, 352.219f, 423.797f, 330.25f, 443.75f, 330.25f, 443.75f, 291.5f, 475.719f, 292.25f,
+467.746f, 10, 0, 0, 0, 0, 0, 0, 0, 15,
+160.246f, 385.746f, 160.246f, 385.742f, 172.699f, 378.035f, 157.25f, 343.746f, 164.246f, 346.746f,
+164.242f, 346.746f, 163.02f, 334.035f, 159.246f, 331.75f, 167.25f, 334.75f, 167.25f, 334.75f,
+172.699f, 326.117f, 168.25f, 320.75f, 168.25f, 320.75f, 186.777f, 312.035f, 186.25f, 304.746f,
+186.25f, 304.746f, 192.938f, 313.797f, 188.246f, 320.75f, 184.137f, 327.879f, 176.219f, 323.477f,
+177.246f, 343.746f, 167.25f, 339.746f, 167.25f, 339.742f, 173.578f, 349.879f, 173.25f, 356.75f,
+165.246f, 354.746f, 165.242f, 354.742f, 181.793f, 383.512f, 170.246f, 384.75f, 163.457f, 385.957f,
+160.246f, 385.746f, 160.246f, 385.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 5, 196.25f, 367.75f, 196.25f, 367.75f, 199.098f, 372.316f, 196.25f,
+371.75f, 192.938f, 370.559f, 158.617f, 354.277f, 152.25f, 343.746f, 152.25f, 343.742f, 189.859f,
+370.559f, 196.25f, 367.75f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f,
+0.8f, 5, 207.25f, 358.75f, 207.25f, 358.75f, 210.539f, 363.516f, 207.25f, 362.75f,
+204.379f, 361.758f, 170.059f, 345.477f, 163.25f, 334.75f, 163.25f, 334.75f, 201.297f, 361.758f,
+207.25f, 358.75f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f,
+5, 222.246f, 375.75f, 222.246f, 375.75f, 225.059f, 380.238f, 222.246f, 379.746f, 218.898f,
+378.477f, 184.578f, 362.195f, 178.246f, 351.75f, 178.246f, 351.75f, 215.816f, 378.477f, 222.246f,
+375.75f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 5,
+196.25f, 327.75f, 196.25f, 327.75f, 196.457f, 334.035f, 193.25f, 332.746f, 190.297f, 332.277f,
+150.699f, 312.918f, 144.246f, 302.746f, 144.246f, 302.746f, 190.297f, 330.516f, 196.25f, 327.75f,
+10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 5, 198.246f,
+339.746f, 198.246f, 339.742f, 199.098f, 344.598f, 196.25f, 343.746f, 193.816f, 343.719f, 164.777f,
+330.957f, 158.25f, 320.75f, 158.25f, 320.75f, 190.738f, 344.156f, 198.246f, 339.746f, 10,
+0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 24, 182.25f, 286.746f,
+171.246f, 278.75f, 171.246f, 278.75f, 182.379f, 286.957f, 186.25f, 285.75f, 186.25f, 285.75f,
+178.859f, 273.316f, 178.246f, 267.75f, 178.246f, 267.75f, 189.418f, 281.676f, 195.25f, 280.746f,
+195.25f, 280.746f, 203.938f, 280.797f, 204.25f, 268.75f, 204.25f, 268.75f, 210.098f, 280.355f,
+213.246f, 279.75f, 213.242f, 279.75f, 214.938f, 272.879f, 213.246f, 265.75f, 213.242f, 265.75f,
+218.02f, 273.758f, 222.246f, 271.746f, 222.246f, 271.746f, 229.457f, 274.195f, 228.25f, 261.746f,
+228.25f, 261.742f, 228.578f, 249.996f, 227.25f, 246.746f, 227.25f, 246.746f, 233.859f, 275.957f,
+236.25f, 276.75f, 236.25f, 276.75f, 245.297f, 277.719f, 250.25f, 267.75f, 250.25f, 267.75f,
+246.18f, 276.398f, 251.25f, 273.746f, 251.25f, 273.742f, 263.34f, 272.438f, 267.246f, 264.746f,
+267.246f, 264.742f, 259.379f, 278.156f, 265.246f, 274.75f, 265.246f, 274.75f, 273.02f, 274.637f,
+274.25f, 267.75f, 274.25f, 267.75f, 283.578f, 244.277f, 286.246f, 242.75f, 286.246f, 242.75f,
+277.418f, 266.277f, 279.246f, 266.746f, 279.242f, 266.742f, 276.977f, 279.477f, 282.25f, 262.75f,
+282.25f, 262.75f, 279.18f, 278.598f, 285.25f, 277.746f, 291.5f, 276.836f, 296.34f, 265.836f,
+305.25f, 268.75f, 305.25f, 268.75f, 316.141f, 262.316f, 318.25f, 338.75f, 182.25f, 286.746f,
+10, 0, 0, 0, 0, 0, 0, 0, 15, 187.246f,
+388.75f, 187.246f, 388.75f, 203.5f, 395.637f, 247.246f, 388.75f, 247.242f, 388.75f, 255.418f,
+388.598f, 263.25f, 398.746f, 270.379f, 407.957f, 299.859f, 415.879f, 307.25f, 413.75f, 317.25f,
+406.75f, 318.25f, 405.746f, 318.25f, 405.742f, 331.98f, 393.879f, 332.246f, 385.746f, 332.859f,
+377.156f, 316.578f, 324.355f, 306.25f, 306.746f, 295.457f, 289.156f, 284.898f, 275.516f, 264.246f,
+277.746f, 264.246f, 277.742f, 240.898f, 282.559f, 212.246f, 277.746f, 212.246f, 277.742f, 180.617f,
+279.918f, 177.246f, 288.746f, 174.457f, 297.516f, 190.246f, 313.746f, 190.246f, 313.746f, 190.246f,
+313.746f, 194.699f, 323.477f, 193.25f, 339.746f, 192.059f, 355.156f, 192.5f, 385.957f, 187.246f,
+388.75f, 10, 0, 0.9f, 0.4f, 0.55f, 0.9f, 0.4f, 0.55f, 8,
+211.246f, 386.75f, 220.656f, 366.598f, 188.246f, 294.75f, 188.246f, 294.75f, 185.898f, 293.117f,
+202.023f, 286.469f, 213.246f, 288.746f, 225.219f, 292.059f, 269.246f, 287.75f, 269.246f, 287.75f,
+295.457f, 304.559f, 309.246f, 353.75f, 309.246f, 353.75f, 309.246f, 353.75f, 320.98f, 379.797f,
+301.246f, 383.746f, 282.258f, 386.836f, 211.246f, 386.75f, 211.246f, 386.75f, 10, 0,
+0.7f, 0.2f, 0.35f, 0.7f, 0.2f, 0.35f, 6, 209.246f, 352.746f, 212.844f,
+366.922f, 214.586f, 379.902f, 211.246f, 386.75f, 211.246f, 386.75f, 280.059f, 379.797f, 292.25f,
+402.75f, 297.043f, 411.34f, 313.277f, 377.598f, 313.246f, 366.75f, 313.242f, 366.75f, 243.539f,
+351.195f, 227.25f, 363.746f, 209.246f, 352.746f, 10, 0, 0.65f, 0.15f, 0.3f,
+0.65f, 0.15f, 0.3f, 13, 214.25f, 334.75f, 214.25f, 334.75f, 216.258f, 326.996f,
+213.246f, 322.75f, 213.242f, 322.75f, 211.859f, 321.719f, 210.246f, 321.746f, 210.246f, 321.742f,
+211.859f, 317.316f, 218.25f, 315.746f, 218.25f, 315.746f, 220.656f, 310.719f, 223.246f, 310.746f,
+225.938f, 309.836f, 231.219f, 303.676f, 235.246f, 304.746f, 240.02f, 306.316f, 252.25f, 310.746f,
+252.25f, 310.746f, 252.25f, 310.742f, 258.5f, 314.238f, 268.246f, 310.746f, 268.242f, 310.742f,
+270.789f, 311.16f, 271.25f, 315.746f, 271.809f, 320.727f, 275.219f, 324.797f, 277.246f, 326.746f,
+279.617f, 329.195f, 290.18f, 343.277f, 289.246f, 343.746f, 287.539f, 344.156f, 214.25f, 334.75f,
+214.25f, 334.75f, 10, 0, 1, 0.45f, 0.5f, 1, 0.45f, 0.5f,
+12, 209.246f, 387.746f, 209.246f, 387.742f, 206.137f, 363.516f, 209.246f, 354.746f, 213.18f,
+345.035f, 212.297f, 342.836f, 211.246f, 338.75f, 210.539f, 334.035f, 215.379f, 323.035f, 221.246f,
+316.75f, 234.246f, 314.75f, 234.246f, 314.75f, 251.457f, 318.637f, 261.25f, 315.746f, 261.25f,
+315.746f, 271.473f, 314.078f, 275.246f, 330.746f, 275.246f, 330.742f, 280.5f, 337.559f, 288.246f,
+340.75f, 296.34f, 343.719f, 304.258f, 389.477f, 300.246f, 398.746f, 295.457f, 407.078f, 279.617f,
+411.918f, 262.25f, 394.746f, 244.418f, 377.598f, 242.219f, 396.078f, 209.246f, 387.746f, 10,
+1.1f, 0, 0, 0, 0, 0, 0, 12, 209.246f, 387.746f,
+209.246f, 387.742f, 206.137f, 363.516f, 209.246f, 354.746f, 213.18f, 345.035f, 212.297f, 342.836f,
+211.246f, 338.75f, 210.539f, 334.035f, 215.379f, 323.035f, 221.246f, 316.75f, 234.246f, 314.75f,
+234.246f, 314.75f, 251.457f, 318.637f, 261.25f, 315.746f, 261.25f, 315.746f, 271.473f, 314.078f,
+275.246f, 330.746f, 275.246f, 330.742f, 280.5f, 337.559f, 288.246f, 340.75f, 296.34f, 343.719f,
+304.258f, 389.477f, 300.246f, 398.746f, 295.457f, 407.078f, 279.617f, 411.918f, 262.25f, 394.746f,
+244.418f, 377.598f, 242.219f, 396.078f, 209.246f, 387.746f, 10, 0, 1, 1,
+0.8f, 1, 1, 0.8f, 7, 211.246f, 305.75f, 211.246f, 305.75f, 210.098f,
+308.078f, 205.25f, 308.746f, 205.25f, 308.742f, 180.617f, 312.477f, 171.246f, 325.75f, 171.246f,
+325.75f, 163.898f, 332.277f, 168.25f, 319.746f, 168.25f, 319.742f, 180.18f, 297.078f, 187.246f,
+293.746f, 187.246f, 293.746f, 205.699f, 289.598f, 211.246f, 305.75f, 10, 0.55f, 0,
+0, 0, 0, 0, 0, 7, 211.246f, 305.75f, 211.246f, 305.75f,
+210.098f, 308.078f, 205.25f, 308.746f, 205.25f, 308.742f, 180.617f, 312.477f, 171.246f, 325.75f,
+171.246f, 325.75f, 163.898f, 332.277f, 168.25f, 319.746f, 168.25f, 319.742f, 180.18f, 297.078f,
+187.246f, 293.746f, 187.246f, 293.746f, 205.699f, 289.598f, 211.246f, 305.75f, 10, 0,
+0.8f, 0.25f, 0.3f, 0.8f, 0.25f, 0.3f, 9, 299.246f, 375.75f, 299.641f,
+384.941f, 301.789f, 394.418f, 300.246f, 398.746f, 292.766f, 412.461f, 274.098f, 406.535f, 262.25f,
+394.746f, 244.418f, 377.598f, 242.219f, 396.078f, 209.246f, 387.746f, 209.246f, 387.742f, 207.297f,
+372.797f, 208.25f, 361.746f, 208.25f, 361.742f, 249.258f, 374.516f, 250.25f, 368.746f, 250.25f,
+368.746f, 251.898f, 371.879f, 262.25f, 371.75f, 272.137f, 371.879f, 297.152f, 373.168f, 299.246f,
+375.75f, 10, 2.2f, 0.65f, 0.1f, 0.15f, 0.65f, 0.1f, 0.15f, 3,
+251.25f, 387.746f, 251.25f, 387.742f, 256.738f, 381.996f, 253.246f, 371.75f, 253.246f, 371.75f,
+236.938f, 353.836f, 239.25f, 338.75f, 10, 0, 1, 1, 0.8f, 1,
+1, 0.8f, 5, 198.246f, 293.746f, 198.246f, 293.746f, 193.816f, 308.078f, 203.25f,
+300.75f, 203.25f, 300.75f, 208.777f, 298.398f, 207.25f, 296.75f, 206.137f, 294.879f, 199.977f,
+290.477f, 198.246f, 293.746f, 10, 0.55f, 0, 0, 0, 0, 0,
+0, 5, 198.246f, 293.746f, 198.246f, 293.746f, 193.816f, 308.078f, 203.25f, 300.75f,
+203.25f, 300.75f, 208.777f, 298.398f, 207.25f, 296.75f, 206.137f, 294.879f, 199.977f, 290.477f,
+198.246f, 293.746f, 10, 0, 1, 1, 0.8f, 1, 1, 0.8f,
+5, 204.25f, 292.75f, 204.25f, 292.75f, 200.328f, 303.941f, 208.25f, 297.746f, 208.25f,
+297.742f, 212.937f, 295.266f, 211.246f, 294.75f, 206.227f, 293.383f, 211.242f, 290.566f, 204.25f,
+292.75f, 10, 0.55f, 0, 0, 0, 0, 0, 0, 5,
+204.25f, 292.75f, 204.25f, 292.75f, 200.328f, 303.941f, 208.25f, 297.746f, 208.25f, 297.742f,
+212.937f, 295.266f, 211.246f, 294.75f, 206.227f, 293.383f, 211.242f, 290.566f, 204.25f, 292.75f,
+10, 0, 1, 1, 0.8f, 1, 1, 0.8f, 5, 209.246f,
+292.75f, 209.246f, 292.75f, 205.609f, 303.941f, 213.246f, 297.746f, 213.242f, 297.742f, 218.168f,
+295.414f, 216.25f, 294.75f, 212.824f, 293.383f, 216.523f, 290.566f, 209.246f, 292.75f, 10,
+0.55f, 0, 0, 0, 0, 0, 0, 5, 209.246f, 292.75f,
+209.246f, 292.75f, 205.609f, 303.941f, 213.246f, 297.746f, 213.242f, 297.742f, 218.168f, 295.414f,
+216.25f, 294.75f, 212.824f, 293.383f, 216.523f, 290.566f, 209.246f, 292.75f, 10, 0,
+1, 1, 0.8f, 1, 1, 0.8f, 5, 216.25f, 292.75f, 216.25f,
+292.75f, 212.871f, 303.723f, 220.246f, 297.746f, 220.246f, 297.742f, 225.434f, 295.172f, 224.246f,
+294.75f, 220.527f, 293.383f, 223.781f, 290.344f, 216.25f, 292.75f, 10, 0.55f, 0,
+0, 0, 0, 0, 0, 5, 216.25f, 292.75f, 216.25f, 292.75f,
+212.871f, 303.723f, 220.246f, 297.746f, 220.246f, 297.742f, 225.434f, 295.172f, 224.246f, 294.75f,
+220.527f, 293.383f, 223.781f, 290.344f, 216.25f, 292.75f, 10, 0, 1, 1,
+0.8f, 1, 1, 0.8f, 5, 224.246f, 292.75f, 224.242f, 292.75f, 220,
+303.809f, 227.25f, 297.746f, 227.25f, 297.742f, 231.969f, 296.066f, 231.246f, 294.75f, 229.855f,
+293.25f, 230.91f, 290.434f, 224.246f, 292.75f, 10, 0.55f, 0, 0, 0,
+0, 0, 0, 5, 224.246f, 292.75f, 224.242f, 292.75f, 220, 303.809f,
+227.25f, 297.746f, 227.25f, 297.742f, 231.969f, 296.066f, 231.246f, 294.75f, 229.855f, 293.25f,
+230.91f, 290.434f, 224.246f, 292.75f, 10, 0, 1, 1, 0.8f, 1,
+1, 0.8f, 5, 231.246f, 291.746f, 231.246f, 291.746f, 225.938f, 305.438f, 236.25f,
+298.75f, 236.25f, 298.75f, 241.34f, 296.195f, 240.25f, 294.75f, 238.699f, 292.676f, 240.02f,
+289.156f, 231.246f, 291.746f, 10, 0.55f, 0, 0, 0, 0, 0,
+0, 5, 231.246f, 291.746f, 231.246f, 291.746f, 225.938f, 305.438f, 236.25f, 298.75f,
+236.25f, 298.75f, 241.34f, 296.195f, 240.25f, 294.75f, 238.699f, 292.676f, 240.02f, 289.156f,
+231.246f, 291.746f, 10, 2.2f, 0.65f, 0.15f, 0.3f, 0.65f, 0.15f, 0.3f,
+4, 200.246f, 310.746f, 200.246f, 310.742f, 214.5f, 313.797f, 221.246f, 310.746f, 221.246f,
+310.742f, 227.699f, 308.957f, 229.25f, 309.75f, 230.34f, 309.836f, 234.246f, 310.746f, 234.246f,
+310.746f, 10, 2.2f, 0.65f, 0.15f, 0.3f, 0.65f, 0.15f, 0.3f, 4,
+237.25f, 300.75f, 237.25f, 300.75f, 250.578f, 315.996f, 264.246f, 310.746f, 271.496f, 308.328f,
+270.379f, 312.035f, 271.25f, 314.75f, 272.137f, 318.195f, 272.359f, 322.816f, 278.246f, 325.75f,
+10, 0, 1, 1, 0.8f, 1, 1, 0.8f, 7, 256.246f,
+318.75f, 256.246f, 318.75f, 251.898f, 330.516f, 249.25f, 316.75f, 245.738f, 302.355f, 242.219f,
+298.398f, 240.25f, 295.746f, 240.25f, 295.742f, 240.457f, 289.598f, 249.25f, 289.75f, 249.25f,
+289.75f, 261.578f, 290.477f, 262.25f, 293.746f, 262.457f, 296.637f, 260.699f, 309.398f, 256.246f,
+318.75f, 10, 0.55f, 0, 0, 0, 0, 0, 0, 7,
+256.246f, 318.75f, 256.246f, 318.75f, 251.898f, 330.516f, 249.25f, 316.75f, 245.738f, 302.355f,
+242.219f, 298.398f, 240.25f, 295.746f, 240.25f, 295.742f, 240.457f, 289.598f, 249.25f, 289.75f,
+249.25f, 289.75f, 261.578f, 290.477f, 262.25f, 293.746f, 262.457f, 296.637f, 260.699f, 309.398f,
+256.246f, 318.75f, 10, 2.2f, 0.65f, 0.15f, 0.3f, 0.65f, 0.15f, 0.3f,
+2, 271.25f, 310.746f, 271.25f, 310.742f, 275.656f, 313.355f, 278.246f, 311.75f, 10,
+2.2f, 0.65f, 0.15f, 0.3f, 0.65f, 0.15f, 0.3f, 2, 279.246f, 328.746f,
+279.242f, 328.742f, 282.039f, 334.148f, 287.246f, 334.75f, 10, 0, 0.7f, 0.7f,
+0.7f, 0.7f, 0.7f, 0.7f, 6, 191.246f, 288.746f, 191.242f, 288.742f, 211.418f,
+284.758f, 216.25f, 286.746f, 216.25f, 286.742f, 225.938f, 286.516f, 216.25f, 284.746f, 216.25f,
+284.742f, 202.617f, 284.316f, 194.25f, 285.75f, 194.25f, 285.75f, 181.059f, 291.797f, 191.246f,
+288.746f, 10, 0, 1, 1, 0.8f, 1, 1, 0.8f, 7,
+207.25f, 390.746f, 207.25f, 390.746f, 226.379f, 390.797f, 228.25f, 389.75f, 228.25f, 389.75f,
+236.5f, 356.035f, 232.246f, 347.75f, 232.246f, 347.75f, 231.219f, 344.598f, 228.25f, 350.746f,
+228.25f, 350.742f, 207.898f, 386.836f, 204.25f, 388.75f, 200.859f, 391.238f, 205.699f, 390.797f,
+207.25f, 390.746f, 10, 0.55f, 0, 0, 0, 0, 0, 0,
+7, 207.25f, 390.746f, 207.25f, 390.746f, 226.379f, 390.797f, 228.25f, 389.75f, 228.25f,
+389.75f, 236.5f, 356.035f, 232.246f, 347.75f, 232.246f, 347.75f, 231.219f, 344.598f, 228.25f,
+350.746f, 228.25f, 350.742f, 207.898f, 386.836f, 204.25f, 388.75f, 200.859f, 391.238f, 205.699f,
+390.797f, 207.25f, 390.746f, 10, 0, 1, 1, 0.8f, 1, 1,
+0.8f, 7, 122.246f, 393.75f, 122.246f, 393.75f, 132, 391.898f, 146.25f, 388.75f,
+146.25f, 388.75f, 151.137f, 364.398f, 154.246f, 358.75f, 158.18f, 353.836f, 154.219f, 353.836f,
+150.246f, 356.75f, 146.297f, 359.996f, 130.02f, 375.398f, 128.25f, 379.746f, 125.617f, 385.078f,
+122.246f, 393.75f, 122.246f, 393.75f, 10, 0.55f, 0, 0, 0, 0,
+0, 0, 7, 122.246f, 393.75f, 122.246f, 393.75f, 132, 391.898f, 146.25f,
+388.75f, 146.25f, 388.75f, 151.137f, 364.398f, 154.246f, 358.75f, 158.18f, 353.836f, 154.219f,
+353.836f, 150.246f, 356.75f, 146.297f, 359.996f, 130.02f, 375.398f, 128.25f, 379.746f, 125.617f,
+385.078f, 122.246f, 393.75f, 122.246f, 393.75f, 10, 0, 1, 1, 0.8f,
+1, 1, 0.8f, 6, 146.25f, 388.75f, 146.25f, 388.75f, 152.637f, 387.094f,
+153.246f, 384.75f, 154.855f, 382.223f, 152.25f, 378.75f, 152.25f, 378.75f, 152.25f, 378.75f,
+151.324f, 374.961f, 150.246f, 377.75f, 148.68f, 379.719f, 145.52f, 388.145f, 146.25f, 388.75f,
+10, 0.55f, 0, 0, 0, 0, 0, 0, 6, 146.25f,
+388.75f, 146.25f, 388.75f, 152.637f, 387.094f, 153.246f, 384.75f, 154.855f, 382.223f, 152.25f,
+378.75f, 152.25f, 378.75f, 152.25f, 378.75f, 151.324f, 374.961f, 150.246f, 377.75f, 148.68f,
+379.719f, 145.52f, 388.145f, 146.25f, 388.75f, 10, 0, 0, 0, 0,
+0, 0, 0, 10, 146.25f, 388.75f, 146.25f, 388.75f, 150.258f, 383.316f,
+154.246f, 383.746f, 158.18f, 383.316f, 158.598f, 383.77f, 161.246f, 382.75f, 166.758f, 381.996f,
+166.316f, 384.195f, 173.25f, 382.75f, 176.48f, 382.348f, 179.297f, 383.316f, 182.25f, 381.746f,
+185.457f, 380.676f, 188.977f, 381.559f, 190.246f, 383.746f, 191.617f, 385.957f, 197.25f, 390.746f,
+197.25f, 390.746f, 197.25f, 390.746f, 182.816f, 388.598f, 179.246f, 387.746f, 179.246f, 387.742f,
+155.098f, 386.398f, 146.25f, 388.75f, 10, 0, 1, 1, 0.8f, 1,
+1, 0.8f, 6, 195.25f, 388.75f, 195.25f, 388.75f, 188.262f, 384.969f, 188.246f,
+382.75f, 187.383f, 379.688f, 193.25f, 375.75f, 193.25f, 375.75f, 193.25f, 375.75f, 196.625f,
+370.559f, 197.25f, 372.746f, 197.941f, 375.836f, 196.238f, 388.379f, 195.25f, 388.75f, 10,
+0.55f, 0, 0, 0, 0, 0, 0, 6, 195.25f, 388.75f,
+195.25f, 388.75f, 188.262f, 384.969f, 188.246f, 382.75f, 187.383f, 379.688f, 193.25f, 375.75f,
+193.25f, 375.75f, 193.25f, 375.75f, 196.625f, 370.559f, 197.25f, 372.746f, 197.941f, 375.836f,
+196.238f, 388.379f, 195.25f, 388.75f, 10, 0, 1, 1, 0.8f, 1,
+1, 0.8f, 5, 154.246f, 382.75f, 154.242f, 382.75f, 161.832f, 370.5f, 162.25f,
+382.75f, 162.25f, 382.75f, 162.684f, 384.215f, 160.246f, 383.746f, 154.066f, 384.324f, 155.738f,
+388.836f, 154.246f, 382.75f, 10, 0.55f, 0, 0, 0, 0, 0,
+0, 5, 154.246f, 382.75f, 154.242f, 382.75f, 161.832f, 370.5f, 162.25f, 382.75f,
+162.25f, 382.75f, 162.684f, 384.215f, 160.246f, 383.746f, 154.066f, 384.324f, 155.738f, 388.836f,
+154.246f, 382.75f, 10, 0, 1, 1, 0.8f, 1, 1, 0.8f,
+5, 162.25f, 382.75f, 162.25f, 382.75f, 170.734f, 370.227f, 170.246f, 382.75f, 170.242f,
+382.75f, 170.043f, 383, 168.25f, 382.75f, 162.891f, 383.625f, 163.27f, 388.594f, 162.25f,
+382.75f, 10, 0.55f, 0, 0, 0, 0, 0, 0, 5,
+162.25f, 382.75f, 162.25f, 382.75f, 170.734f, 370.227f, 170.246f, 382.75f, 170.242f, 382.75f,
+170.043f, 383, 168.25f, 382.75f, 162.891f, 383.625f, 163.27f, 388.594f, 162.25f, 382.75f,
+10, 0, 1, 1, 0.8f, 1, 1, 0.8f, 5, 170.246f,
+382.75f, 170.242f, 382.75f, 178.711f, 370.832f, 178.246f, 381.746f, 178.246f, 381.746f, 178.105f,
+382.82f, 176.246f, 382.75f, 172.004f, 383.93f, 171.773f, 387.504f, 170.246f, 382.75f, 10,
+0.55f, 0, 0, 0, 0, 0, 0, 5, 170.246f, 382.75f,
+170.242f, 382.75f, 178.711f, 370.832f, 178.246f, 381.746f, 178.246f, 381.746f, 178.105f, 382.82f,
+176.246f, 382.75f, 172.004f, 383.93f, 171.773f, 387.504f, 170.246f, 382.75f, 10, 0,
+1, 1, 0.8f, 1, 1, 0.8f, 5, 177.246f, 382.75f, 177.246f,
+382.75f, 186.207f, 369.719f, 186.25f, 380.75f, 186.25f, 380.75f, 188.398f, 381.992f, 186.25f,
+381.746f, 180.078f, 383.051f, 180.957f, 387.953f, 177.246f, 382.75f, 10, 0.55f, 0,
+0, 0, 0, 0, 0, 5, 177.246f, 382.75f, 177.246f, 382.75f,
+186.207f, 369.719f, 186.25f, 380.75f, 186.25f, 380.75f, 188.398f, 381.992f, 186.25f, 381.746f,
+180.078f, 383.051f, 180.957f, 387.953f, 177.246f, 382.75f, 10, 0, 0.9f, 0.9f,
+0.7f, 0.9f, 0.9f, 0.7f, 6, 137.246f, 378.75f, 129.25f, 379.746f, 126.441f,
+385.738f, 124.25f, 392.746f, 124.25f, 392.746f, 124.25f, 392.746f, 131.117f, 391.402f, 145.25f,
+388.75f, 145.25f, 388.75f, 145.832f, 384.672f, 147.25f, 378.75f, 137.246f, 378.75f, 10,
+0, 0.9f, 0.9f, 0.7f, 0.9f, 0.9f, 0.7f, 7, 209.246f, 383.746f,
+207.469f, 386.437f, 206.02f, 388.371f, 205.25f, 388.75f, 201.992f, 390.891f, 206.547f, 390.477f,
+208.25f, 390.746f, 208.25f, 390.746f, 226.02f, 390.477f, 228.25f, 389.75f, 228.25f, 389.75f,
+228.668f, 387.18f, 229.25f, 383.746f, 229.25f, 383.742f, 218.32f, 385.66f, 209.246f, 383.746f,
+10, 0, 0.8f, 0.45f, 0.15f, 0.8f, 0.45f, 0.15f, 10, 268.246f,
+535.746f, 298.758f, 531.289f, 326.832f, 570.492f, 329.25f, 580.75f, 330.703f, 591.789f, 319.25f,
+604.75f, 319.25f, 604.75f, 321.023f, 608.246f, 315.699f, 623.734f, 310.246f, 633.75f, 304.082f,
+644.063f, 286.594f, 642.992f, 267.246f, 643.75f, 249.875f, 645.031f, 229.547f, 619.379f, 228.25f,
+617.75f, 226.641f, 615.508f, 233.418f, 573.398f, 235.246f, 566.75f, 236.32f, 560.813f, 233.246f,
+531.75f, 233.246f, 531.75f, 271.082f, 541.781f, 237.773f, 540, 268.246f, 535.746f, 10,
+0, 0.92f, 0.56f, 0.32f, 0.92f, 0.56f, 0.32f, 10, 229.25f, 616.746f,
+227.469f, 614.828f, 234.121f, 573.484f, 235.246f, 567.75f, 236.973f, 561.129f, 234.246f, 532.746f,
+234.246f, 532.746f, 270.063f, 542.387f, 238.398f, 540.695f, 268.246f, 536.75f, 298.273f, 532.141f,
+325.836f, 570.633f, 327.25f, 580.75f, 329.637f, 591.543f, 318.25f, 604.75f, 318.25f, 604.75f,
+320.133f, 607.699f, 314.906f, 622.906f, 309.246f, 632.75f, 303.504f, 642.867f, 286.332f, 641.813f,
+267.246f, 642.746f, 250.277f, 643.816f, 230.32f, 618.629f, 229.25f, 616.746f, 10, 0,
+0.94f, 0.67f, 0.49f, 0.94f, 0.67f, 0.49f, 10, 229.25f, 615.75f, 228.297f,
+614.152f, 234.824f, 573.574f, 236.25f, 567.75f, 237.625f, 561.445f, 235.246f, 533.746f, 235.246f,
+533.746f, 269.371f, 543.539f, 239.023f, 541.391f, 268.246f, 536.75f, 297.793f, 532.996f, 324.844f,
+570.773f, 326.25f, 580.75f, 328.574f, 591.297f, 318.25f, 603.746f, 318.25f, 603.746f, 319.246f,
+607.156f, 314.113f, 622.078f, 308.246f, 631.746f, 302.922f, 641.668f, 286.066f, 640.637f, 267.246f,
+641.75f, 250.684f, 642.602f, 231.094f, 617.883f, 229.25f, 615.75f, 10, 0, 0.96f,
+0.78f, 0.66f, 0.96f, 0.78f, 0.66f, 10, 230.25f, 615.75f, 229.125f, 613.473f,
+235.531f, 573.66f, 237.25f, 567.75f, 238.277f, 561.762f, 235.246f, 534.75f, 235.246f, 534.75f,
+267.91f, 544.25f, 239.648f, 542.086f, 268.246f, 537.746f, 297.309f, 533.852f, 323.848f, 570.914f,
+325.25f, 580.75f, 327.508f, 591.051f, 317.25f, 603.746f, 317.25f, 603.746f, 318.355f, 606.609f,
+313.324f, 621.254f, 308.246f, 630.75f, 302.34f, 640.473f, 285.805f, 639.457f, 267.246f, 640.746f,
+251.09f, 641.387f, 231.871f, 617.133f, 230.25f, 615.75f, 10, 0, 0.98f, 0.89f,
+0.83f, 0.98f, 0.89f, 0.83f, 10, 231.246f, 614.746f, 229.949f, 612.797f, 236.234f,
+573.75f, 237.25f, 567.75f, 238.926f, 562.082f, 236.25f, 534.75f, 236.25f, 534.75f, 266.891f,
+544.965f, 240.273f, 542.781f, 268.246f, 538.75f, 296.824f, 534.703f, 322.855f, 571.055f, 324.246f,
+580.75f, 326.445f, 590.805f, 316.25f, 602.75f, 316.25f, 602.75f, 317.469f, 606.063f, 312.531f,
+620.426f, 307.25f, 629.746f, 301.762f, 639.273f, 285.543f, 638.281f, 267.246f, 639.75f, 251.492f,
+640.172f, 232.645f, 616.387f, 231.246f, 614.746f, 10, 0, 1, 1, 1,
+1, 1, 1, 10, 268.246f, 539.746f, 296.34f, 535.559f, 321.859f, 571.199f,
+323.246f, 580.75f, 325.379f, 590.559f, 315.25f, 602.75f, 315.25f, 602.75f, 316.578f, 605.52f,
+311.738f, 619.598f, 306.25f, 628.75f, 301.18f, 638.078f, 285.277f, 637.102f, 267.246f, 637.75f,
+251.898f, 638.957f, 233.418f, 615.637f, 232.246f, 613.75f, 230.777f, 612.117f, 236.938f, 573.84f,
+238.25f, 567.75f, 239.578f, 562.398f, 237.25f, 535.746f, 237.25f, 535.746f, 264.988f, 545.457f,
+240.898f, 543.477f, 268.246f, 539.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 6, 319.25f, 576.746f, 319.25f, 576.742f, 289.078f, 568.559f, 276.246f,
+570.746f, 276.246f, 570.746f, 258.937f, 577.578f, 249.25f, 553.75f, 249.25f, 553.75f, 245.297f,
+545.68f, 243.246f, 543.746f, 240.898f, 541.277f, 319.25f, 576.746f, 319.25f, 576.746f, 10,
+0, 0, 0, 0, 0, 0, 0, 11, 324.246f, 579.746f,
+324.242f, 579.746f, 291.937f, 565.918f, 281.25f, 566.75f, 281.25f, 566.75f, 262.898f, 571.418f,
+253.246f, 555.75f, 253.246f, 555.75f, 244.418f, 545.238f, 241.25f, 543.746f, 241.25f, 543.742f,
+240.457f, 541.719f, 247.246f, 545.75f, 259.25f, 540.75f, 259.25f, 540.75f, 275.219f, 529.84f,
+286.246f, 547.75f, 286.246f, 547.75f, 290.18f, 559.758f, 290.246f, 561.746f, 290.18f, 564.156f,
+313.5f, 570.316f, 315.25f, 570.746f, 317.02f, 571.199f, 324.277f, 575.816f, 324.246f, 579.746f,
+10, 0, 0.6f, 0.8f, 0.2f, 0.6f, 0.8f, 0.2f, 6, 271.25f,
+539.746f, 264.141f, 539.832f, 254.93f, 544.086f, 255.246f, 550.746f, 254.93f, 557.832f, 264.141f,
+564.723f, 271.25f, 564.75f, 279.258f, 564.723f, 285.387f, 559.152f, 285.25f, 552.746f, 285.387f,
+545.402f, 279.258f, 539.832f, 271.25f, 539.746f, 10, 0, 0.4f, 0.6f, 0,
+0.4f, 0.6f, 0, 6, 267.246f, 557.746f, 262.383f, 557.391f, 256.785f, 555.738f,
+257.246f, 555.75f, 258.559f, 561.055f, 265.555f, 564.723f, 271.25f, 564.75f, 276.422f, 564.723f,
+280.59f, 562.547f, 283.25f, 558.75f, 283.25f, 558.75f, 277.203f, 559.598f, 267.246f, 557.746f,
+10, 0, 1, 1, 1, 1, 1, 1, 4, 281.25f,
+558.75f, 281.25f, 558.75f, 276.098f, 561.957f, 276.246f, 559.746f, 276.246f, 559.746f, 280.059f,
+554.699f, 281.25f, 558.75f, 10, 0, 0, 0, 0, 0, 0,
+0, 6, 270.25f, 549.75f, 267.187f, 549.5f, 264.961f, 551.727f, 265.246f, 554.746f,
+264.961f, 557.227f, 267.187f, 559.457f, 270.25f, 559.746f, 272.687f, 559.457f, 274.918f, 557.227f,
+275.246f, 554.746f, 274.918f, 551.727f, 272.687f, 549.5f, 270.25f, 549.75f, 10, 0,
+0.8f, 0.45f, 0.15f, 0.8f, 0.45f, 0.15f, 15, 155.246f, 563.746f, 155.246f,
+563.742f, 152.02f, 587.477f, 154.246f, 592.746f, 154.242f, 592.746f, 166.539f, 603.316f, 166.246f,
+607.746f, 166.246f, 607.742f, 165.656f, 627.078f, 164.246f, 627.746f, 163.02f, 628.84f, 154.656f,
+635.438f, 148.246f, 628.75f, 148.242f, 628.75f, 136.617f, 608.598f, 137.246f, 601.746f, 137.246f,
+599.75f, 137.242f, 599.75f, 129.137f, 599.797f, 127.246f, 597.75f, 127.246f, 597.75f, 126.059f,
+591.879f, 124.25f, 591.75f, 124.25f, 591.75f, 121.656f, 588.797f, 124.25f, 585.746f, 124.25f,
+585.742f, 121.656f, 583.078f, 122.246f, 578.75f, 130.25f, 574.746f, 130.25f, 574.742f, 132.656f,
+558.438f, 144.246f, 552.746f, 149.859f, 550.156f, 153.34f, 557.559f, 155.246f, 563.746f, 10,
+0, 1, 1, 1, 1, 1, 1, 15, 154.246f, 565.746f,
+154.242f, 565.742f, 151.27f, 587.172f, 153.246f, 591.75f, 153.242f, 591.75f, 164.34f, 601.426f,
+164.246f, 604.75f, 164.242f, 604.75f, 163.547f, 622.809f, 162.25f, 623.746f, 161.172f, 624.395f,
+153.645f, 630.336f, 147.25f, 623.746f, 147.25f, 623.746f, 137.41f, 606.18f, 138.246f, 599.75f,
+138.246f, 597.75f, 138.246f, 597.75f, 130.68f, 598.258f, 129.25f, 596.746f, 129.25f, 596.742f,
+127.906f, 591.129f, 126.246f, 590.746f, 126.242f, 590.746f, 123.945f, 588.359f, 126.246f, 585.746f,
+126.242f, 585.742f, 123.945f, 583.211f, 124.25f, 579.746f, 132.246f, 575.75f, 132.246f, 575.75f,
+133.848f, 561.035f, 144.246f, 555.75f, 149.324f, 553.582f, 152.457f, 560.242f, 154.246f, 565.746f,
+10, 0, 0.925f, 0.588f, 0.363f, 0.925f, 0.588f, 0.363f, 15, 164.246f,
+626.75f, 162.645f, 627.816f, 154.406f, 634.16f, 148.246f, 627.746f, 148.242f, 627.742f, 136.816f,
+607.992f, 137.246f, 600.75f, 137.246f, 598.746f, 137.242f, 598.742f, 129.523f, 599.414f, 128.25f,
+597.75f, 128.25f, 597.75f, 126.52f, 591.691f, 125.25f, 591.75f, 125.25f, 591.75f, 122.23f,
+588.688f, 124.25f, 585.746f, 124.25f, 585.742f, 122.23f, 583.109f, 122.246f, 578.75f, 131.246f,
+574.746f, 131.242f, 574.742f, 132.953f, 559.086f, 144.246f, 553.75f, 149.723f, 551.012f, 153.117f,
+558.23f, 155.246f, 564.75f, 155.246f, 564.75f, 151.832f, 587.402f, 154.246f, 591.75f, 154.242f,
+591.75f, 165.988f, 602.844f, 165.246f, 606.75f, 165.242f, 606.75f, 165.129f, 626.012f, 164.246f,
+626.75f, 10, 0, 0.95f, 0.725f, 0.575f, 0.95f, 0.725f, 0.575f, 15,
+163.25f, 625.746f, 162.27f, 626.793f, 154.152f, 632.887f, 148.246f, 625.746f, 148.242f, 625.746f,
+137.016f, 607.387f, 138.246f, 600.75f, 138.246f, 598.746f, 138.246f, 598.742f, 129.906f, 599.027f,
+128.25f, 596.746f, 128.25f, 596.742f, 126.98f, 591.504f, 125.25f, 590.746f, 125.25f, 590.746f,
+122.801f, 588.578f, 125.25f, 585.746f, 125.25f, 585.742f, 122.801f, 583.145f, 123.25f, 578.75f,
+131.246f, 574.746f, 131.242f, 574.742f, 133.254f, 559.734f, 144.246f, 554.746f, 149.59f, 551.867f,
+152.898f, 558.898f, 155.246f, 564.75f, 155.246f, 564.75f, 151.645f, 587.324f, 154.246f, 591.75f,
+154.242f, 591.75f, 165.438f, 602.371f, 165.246f, 605.746f, 165.242f, 605.742f, 164.602f, 624.945f,
+163.25f, 625.746f, 10, 0, 0.975f, 0.863f, 0.788f, 0.975f, 0.863f, 0.788f,
+15, 163.25f, 624.75f, 161.895f, 625.77f, 153.898f, 631.609f, 148.246f, 624.75f, 148.242f,
+624.75f, 137.211f, 606.781f, 138.246f, 600.75f, 138.246f, 597.75f, 138.246f, 597.75f, 130.293f,
+598.645f, 128.25f, 596.746f, 128.25f, 596.742f, 127.445f, 591.316f, 126.246f, 590.746f, 126.242f,
+590.746f, 123.375f, 588.469f, 125.25f, 585.746f, 125.25f, 585.742f, 123.375f, 583.176f, 124.25f,
+578.75f, 131.246f, 574.746f, 131.242f, 574.742f, 133.551f, 560.387f, 144.246f, 554.746f, 149.457f,
+552.727f, 152.68f, 559.57f, 154.246f, 565.746f, 154.242f, 565.742f, 151.457f, 587.246f, 154.246f,
+591.75f, 154.242f, 591.75f, 164.887f, 601.898f, 164.246f, 605.746f, 164.242f, 605.742f, 164.074f,
+623.879f, 163.25f, 624.75f, 10, 0, 1, 1, 1, 1, 1,
+1, 15, 154.246f, 566.75f, 154.242f, 566.75f, 151.27f, 587.172f, 153.246f, 591.75f,
+153.242f, 591.75f, 164.34f, 601.426f, 164.246f, 604.75f, 164.242f, 604.75f, 163.547f, 622.809f,
+162.25f, 623.746f, 161.523f, 624.746f, 153.645f, 630.336f, 147.25f, 623.746f, 147.25f, 623.746f,
+137.41f, 606.18f, 138.246f, 599.75f, 138.246f, 597.75f, 138.246f, 597.75f, 130.68f, 598.258f,
+129.25f, 596.746f, 129.25f, 596.742f, 127.906f, 591.129f, 126.246f, 590.746f, 126.242f, 590.746f,
+123.945f, 588.359f, 126.246f, 585.746f, 126.242f, 585.742f, 123.945f, 583.211f, 124.25f, 579.746f,
+132.246f, 575.75f, 132.246f, 575.75f, 133.848f, 561.035f, 144.246f, 555.75f, 149.324f, 553.582f,
+152.457f, 560.352f, 154.246f, 566.75f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 5, 151.25f, 572.746f, 151.25f, 572.742f, 127.27f, 584.398f, 126.246f,
+585.746f, 126.242f, 585.742f, 136.289f, 576.258f, 137.246f, 576.746f, 138.047f, 576.258f, 151.25f,
+572.746f, 151.25f, 572.746f, 10, 0, 0, 0, 0, 0, 0,
+0, 5, 132.246f, 579.746f, 132.246f, 579.746f, 152.457f, 576.039f, 152.25f, 570.746f,
+152.457f, 567.996f, 152.191f, 553.234f, 146.25f, 554.746f, 137.059f, 557.559f, 141.02f, 573.398f,
+132.246f, 579.746f, 10, 0, 0.6f, 0.8f, 0.2f, 0.6f, 0.8f, 0.2f,
+5, 141.25f, 575.75f, 141.25f, 575.75f, 151.332f, 574.195f, 152.25f, 570.746f, 153.117f,
+569.438f, 153.848f, 560.301f, 148.246f, 558.75f, 142.832f, 558.098f, 140.379f, 569.34f, 141.25f,
+575.75f, 10, 0, 0, 0, 0, 0, 0, 0, 44,
+236.25f, 528.746f, 235.504f, 530.93f, 236.949f, 530.785f, 239.25f, 531.75f, 241.117f, 532.039f,
+254.539f, 536.219f, 255.246f, 538.75f, 256.297f, 541.938f, 271.25f, 536.75f, 271.25f, 536.75f,
+272.797f, 536.219f, 277.246f, 533.746f, 277.246f, 533.746f, 282.918f, 532.039f, 290.246f, 531.75f,
+290.246f, 531.75f, 292.816f, 530.5f, 296.25f, 527.75f, 296.25f, 527.75f, 312.617f, 516.199f,
+326.25f, 523.75f, 326.25f, 523.75f, 348.258f, 531.379f, 341.25f, 550.746f, 341.25f, 550.746f,
+338.359f, 560.199f, 342.246f, 563.746f, 342.246f, 563.746f, 342.098f, 568.117f, 350.25f, 560.75f,
+350.25f, 560.75f, 352.879f, 556.457f, 354.246f, 550.746f, 354.246f, 550.746f, 362.559f, 538.637f,
+359.25f, 557.746f, 359.25f, 557.746f, 359.039f, 559.316f, 355.961f, 563.277f, 356.246f, 564.75f,
+355.961f, 565.918f, 354.246f, 569.75f, 354.246f, 569.75f, 350.68f, 573.398f, 353.246f, 580.75f,
+353.246f, 580.75f, 355.301f, 596.277f, 353.246f, 594.746f, 353.246f, 594.746f, 351.559f, 596.277f,
+341.25f, 585.746f, 341.25f, 585.746f, 339.02f, 581.539f, 332.246f, 579.746f, 332.246f, 579.746f,
+329.34f, 577.797f, 325.25f, 579.746f, 325.25f, 579.746f, 322.738f, 579.777f, 316.25f, 571.75f,
+316.25f, 571.75f, 319.66f, 572.297f, 322.301f, 567.457f, 325.25f, 566.75f, 327.578f, 567.02f,
+329.559f, 569.879f, 331.246f, 570.746f, 333.078f, 571.199f, 336.25f, 564.75f, 336.25f, 564.75f,
+336.598f, 561.957f, 330.25f, 556.75f, 330.25f, 556.75f, 330, 551.617f, 328.25f, 553.75f,
+328.25f, 553.75f, 324.938f, 554.039f, 323.621f, 549.859f, 322.246f, 544.746f, 321.418f, 539.738f,
+317.25f, 539.746f, 317.25f, 539.746f, 315.039f, 531.156f, 313.246f, 534.75f, 313.246f, 534.75f,
+313.5f, 540.617f, 307.25f, 533.746f, 307.25f, 533.746f, 305.578f, 532.039f, 300.246f, 534.75f,
+300.246f, 534.75f, 293.039f, 536.656f, 295.25f, 538.75f, 295.25f, 538.75f, 297.656f, 541.277f,
+310.246f, 538.75f, 310.246f, 538.75f, 312.398f, 540.617f, 303.25f, 544.746f, 303.25f, 544.746f,
+302.937f, 547, 304.25f, 551.75f, 304.25f, 551.75f, 305.359f, 555.359f, 313.246f, 561.746f,
+313.246f, 561.746f, 323.18f, 562.84f, 320.246f, 564.75f, 320.246f, 564.75f, 313.277f, 570.316f,
+307.25f, 561.746f, 307.25f, 561.746f, 304.477f, 555.137f, 285.25f, 538.75f, 285.25f, 538.75f,
+280.059f, 534.898f, 282.918f, 542.379f, 278.246f, 538.75f, 274.117f, 534.898f, 251.25f, 544.746f,
+251.25f, 544.746f, 238.738f, 546.109f, 235.734f, 528.793f, 232.246f, 531.75f, 232.246f, 531.75f,
+237.813f, 522.855f, 236.25f, 528.746f, 10, 0, 0, 0, 0, 0,
+0, 0, 12, 450.25f, 711.746f, 450.25f, 711.746f, 422.18f, 703.199f, 419.246f,
+682.746f, 419.246f, 682.742f, 416.461f, 657.438f, 439.25f, 637.75f, 439.25f, 637.75f, 439.34f,
+631.039f, 441.246f, 627.746f, 441.246f, 627.742f, 439.777f, 622.238f, 460.246f, 630.75f, 490.25f,
+639.75f, 490.25f, 639.75f, 497.418f, 642.477f, 503.25f, 651.746f, 508.859f, 661.84f, 525.578f,
+682.52f, 521.25f, 709.75f, 521.25f, 709.75f, 522.938f, 722.559f, 516.25f, 722.746f, 516.25f,
+722.746f, 507.098f, 724.758f, 499.25f, 716.75f, 499.25f, 716.75f, 491.699f, 712.879f, 489.246f,
+713.746f, 450.25f, 711.746f, 10, 0, 0, 0, 0, 0, 0,
+0, 8, 510.25f, 712.75f, 510.25f, 712.75f, 512.73f, 722.91f, 507.25f, 717.746f,
+507.25f, 717.742f, 499.664f, 711.293f, 491.246f, 711.746f, 491.242f, 711.746f, 475.465f, 708.875f,
+470.25f, 694.75f, 470.25f, 694.75f, 466.266f, 664.828f, 475.25f, 658.746f, 475.25f, 658.746f,
+480.305f, 650.309f, 488.25f, 657.75f, 495.793f, 664.828f, 512.844f, 698.082f, 510.25f, 712.75f,
+10, 0, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 8, 510.25f,
+712.75f, 510.25f, 712.75f, 512.309f, 722.313f, 507.25f, 716.75f, 507.25f, 716.75f, 499.48f,
+710.906f, 491.246f, 710.746f, 491.242f, 710.742f, 475.719f, 708.531f, 471.246f, 694.75f, 471.242f,
+694.75f, 466.691f, 665.289f, 475.25f, 658.746f, 475.25f, 658.746f, 480.469f, 651.031f, 488.25f,
+657.75f, 495.68f, 665.289f, 512.387f, 697.961f, 510.25f, 712.75f, 10, 0, 0.4f,
+0.4f, 0.4f, 0.4f, 0.4f, 0.4f, 8, 509.246f, 712.75f, 509.246f, 712.75f,
+511.887f, 721.715f, 507.25f, 716.75f, 507.25f, 716.75f, 499.293f, 710.52f, 491.246f, 710.746f,
+491.242f, 710.742f, 475.973f, 708.188f, 471.246f, 693.746f, 471.242f, 693.742f, 467.113f, 665.746f,
+475.25f, 659.75f, 475.25f, 659.75f, 480.637f, 651.754f, 488.25f, 658.746f, 495.563f, 665.746f,
+511.93f, 697.84f, 509.246f, 712.75f, 10, 0, 0.6f, 0.6f, 0.6f, 0.6f,
+0.6f, 0.6f, 8, 509.246f, 711.746f, 509.246f, 711.746f, 511.465f, 721.113f, 506.246f,
+715.746f, 506.242f, 715.742f, 499.109f, 710.133f, 491.246f, 709.75f, 491.242f, 709.75f, 476.23f,
+707.844f, 471.246f, 693.746f, 471.242f, 693.742f, 467.535f, 666.203f, 476.246f, 660.746f, 476.246f,
+660.742f, 480.805f, 652.477f, 488.25f, 659.75f, 495.449f, 666.203f, 511.477f, 697.719f, 509.246f,
+711.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 8,
+509.246f, 711.746f, 509.246f, 711.746f, 511.043f, 720.516f, 506.246f, 715.746f, 506.242f, 715.742f,
+498.926f, 709.746f, 491.246f, 709.75f, 491.242f, 709.75f, 476.484f, 707.5f, 472.25f, 693.746f,
+472.25f, 693.742f, 467.957f, 666.66f, 476.246f, 660.746f, 476.246f, 660.742f, 480.973f, 653.195f,
+488.25f, 659.75f, 495.332f, 666.66f, 511.02f, 697.598f, 509.246f, 711.746f, 10, 0,
+1, 1, 1, 1, 1, 1, 8, 508.25f, 710.746f, 508.25f,
+710.742f, 510.621f, 719.918f, 506.246f, 714.75f, 506.242f, 714.75f, 498.738f, 709.359f, 491.246f,
+709.75f, 491.242f, 709.75f, 476.738f, 707.156f, 472.25f, 693.746f, 472.25f, 693.742f, 468.379f,
+667.117f, 476.246f, 661.75f, 476.246f, 661.75f, 481.141f, 653.918f, 488.25f, 660.746f, 495.219f,
+667.117f, 510.563f, 697.477f, 508.25f, 710.746f, 10, 0, 0.6f, 0.15f, 0,
+0.6f, 0.15f, 0, 24, 275.246f, 487.75f, 275.246f, 487.75f, 253.219f, 508.719f,
+244.246f, 509.75f, 244.246f, 509.75f, 206.578f, 514, 190.246f, 493.746f, 190.246f, 493.742f,
+209.656f, 516.637f, 240.25f, 510.746f, 240.25f, 510.742f, 216.258f, 515.316f, 202.246f, 511.746f,
+202.242f, 511.746f, 184.137f, 511.797f, 173.25f, 496.75f, 170.246f, 490.75f, 170.242f, 490.75f,
+174.898f, 507.398f, 195.25f, 513.746f, 195.25f, 513.746f, 220.219f, 519.277f, 232.246f, 513.746f,
+232.246f, 513.746f, 208.34f, 521.477f, 197.25f, 519.746f, 197.25f, 519.742f, 163.898f, 521.918f,
+150.246f, 492.75f, 150.246f, 492.75f, 154.219f, 508.719f, 170.246f, 516.75f, 170.242f, 516.75f,
+185.457f, 526.316f, 208.25f, 522.746f, 208.25f, 522.746f, 223.738f, 519.719f, 229.25f, 516.75f,
+235.18f, 514.438f, 233.859f, 517.52f, 224.246f, 522.746f, 224.242f, 522.746f, 218.457f, 533.797f,
+203.25f, 533.746f, 203.25f, 533.746f, 155.977f, 529.398f, 144.246f, 515.746f, 144.246f, 515.742f,
+159.5f, 528.52f, 171.246f, 531.75f, 171.246f, 531.75f, 195.578f, 540.398f, 205.25f, 539.746f,
+205.25f, 539.742f, 232.098f, 538.418f, 240.25f, 542.75f, 240.25f, 542.75f, 228.137f, 537.316f,
+231.246f, 533.746f, 235.18f, 530.277f, 242.656f, 521.918f, 242.246f, 520.75f, 242.656f, 519.277f,
+269.277f, 494.969f, 273.25f, 489.746f, 275.246f, 487.75f, 10, 0, 0.8f, 0.8f,
+0.8f, 0.8f, 0.8f, 0.8f, 5, 428.25f, 273.746f, 428.25f, 273.742f, 410.848f,
+314.348f, 397.246f, 324.746f, 397.246f, 324.746f, 425.699f, 307.199f, 429.25f, 287.75f, 429.25f,
+287.75f, 429.547f, 276.398f, 428.25f, 273.746f, 10, 0, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 0.8f, 7, 479.25f, 265.75f, 479.25f, 265.75f, 450.449f, 326.449f,
+430.246f, 352.746f, 430.246f, 352.742f, 477.949f, 311.598f, 483.25f, 282.746f, 484.246f, 276.75f,
+480.246f, 278.75f, 480.242f, 278.75f, 480.148f, 269.25f, 479.25f, 265.75f, 10, 0,
+0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 5, 542.246f, 319.746f, 542.246f,
+319.742f, 473, 384.75f, 471.246f, 387.746f, 471.242f, 387.742f, 537.898f, 314.898f, 541.25f,
+306.746f, 541.25f, 306.742f, 539, 316.547f, 542.246f, 319.746f, 10, 0, 0.8f,
+0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 6, 334.246f, 271.746f, 334.246f, 271.746f,
+355.848f, 328.648f, 377.246f, 303.75f, 377.246f, 303.75f, 393.25f, 292.898f, 392.25f, 289.75f,
+392.25f, 289.75f, 388.297f, 296.75f, 368.246f, 295.746f, 368.242f, 295.742f, 347.598f, 299.5f,
+334.246f, 271.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f,
+5, 544.246f, 411.746f, 544.246f, 411.742f, 494.449f, 443.047f, 486.25f, 444.746f, 473.211f,
+447.297f, 540.648f, 412.797f, 546.246f, 400.75f, 546.242f, 400.75f, 548.348f, 404, 544.246f,
+411.746f, 10, 0, 0, 0, 0, 0, 0, 0, 63,
+378.246f, 294.75f, 378.246f, 294.75f, 400.621f, 296.637f, 408.246f, 303.75f, 413.246f, 299.746f,
+432.246f, 342.75f, 436.25f, 336.75f, 436.25f, 336.75f, 452.098f, 352.957f, 451.25f, 361.746f,
+450.34f, 370.559f, 465.246f, 354.746f, 465.246f, 354.746f, 465.246f, 354.742f, 464.418f, 367.918f,
+472.25f, 360.75f, 472.25f, 360.75f, 469.699f, 377.598f, 479.25f, 368.746f, 479.25f, 368.746f,
+467.348f, 401.969f, 492.25f, 373.75f, 498.301f, 366.598f, 493.246f, 373.75f, 493.246f, 373.75f,
+493.242f, 373.75f, 464.859f, 426.879f, 488.25f, 410.75f, 488.25f, 410.75f, 490.82f, 436.117f,
+489.246f, 440.746f, 488.18f, 445.797f, 485.98f, 470.438f, 480.246f, 475.746f, 475.418f, 481.879f,
+481.141f, 483.637f, 487.246f, 477.746f, 487.246f, 477.742f, 474.98f, 504.316f, 489.246f, 490.75f,
+489.246f, 490.75f, 485.539f, 507.84f, 480.246f, 510.746f, 480.242f, 510.742f, 474.539f, 529.84f,
+491.246f, 517.746f, 491.242f, 517.742f, 486.418f, 531.598f, 483.25f, 534.75f, 483.25f, 534.75f,
+470.141f, 565.477f, 478.246f, 559.746f, 483.25f, 555.75f, 483.25f, 555.75f, 475.418f, 571.637f,
+482.246f, 566.75f, 489.5f, 561.957f, 489.246f, 562.75f, 489.246f, 562.75f, 489.246f, 562.75f,
+466.18f, 598.918f, 488.25f, 579.746f, 488.25f, 579.746f, 479.645f, 594.867f, 476.246f, 602.75f,
+476.246f, 602.75f, 455.18f, 624.879f, 471.246f, 617.75f, 476.246f, 615.75f, 476.246f, 615.75f,
+466.621f, 627.078f, 458.246f, 628.75f, 449.02f, 630.598f, 460.461f, 637.637f, 467.246f, 635.75f,
+474.539f, 633.238f, 491.246f, 624.75f, 491.246f, 624.75f, 491.242f, 624.75f, 505.777f, 604.199f,
+510.25f, 603.746f, 510.25f, 603.746f, 488.18f, 612.117f, 495.246f, 603.746f, 495.242f, 603.746f,
+510.621f, 587.918f, 502.246f, 588.75f, 502.242f, 588.75f, 496.098f, 580.438f, 501.25f, 570.746f,
+501.25f, 570.746f, 481.074f, 590.988f, 497.25f, 562.75f, 505.25f, 544.746f, 505.25f, 544.746f,
+478.059f, 572.078f, 490.25f, 547.75f, 490.25f, 547.75f, 509.301f, 521.918f, 511.246f, 521.746f,
+513.699f, 521.039f, 518.25f, 511.746f, 518.25f, 511.746f, 513.246f, 513.746f, 519.25f, 503.75f,
+519.25f, 503.75f, 507.098f, 517.078f, 513.246f, 502.746f, 520.246f, 486.746f, 520.246f, 486.742f,
+497.418f, 510.918f, 512.25f, 478.746f, 512.25f, 478.746f, 494.34f, 484.078f, 504.246f, 464.746f,
+504.242f, 464.742f, 502.258f, 447.559f, 502.246f, 441.75f, 503.141f, 436.117f, 504.461f, 404.879f,
+499.25f, 395.75f, 494.777f, 387.277f, 506.219f, 366.156f, 508.25f, 361.746f, 510.621f, 357.355f,
+514.578f, 345.477f, 505.25f, 355.75f, 495.219f, 365.719f, 500.059f, 359.559f, 502.246f, 349.75f,
+504.461f, 340.195f, 511.059f, 323.035f, 510.25f, 316.75f, 510.25f, 316.75f, 508.859f, 315.559f,
+505.25f, 319.746f, 505.25f, 319.742f, 489.059f, 344.598f, 491.246f, 328.746f, 491.242f, 328.742f,
+489.5f, 319.957f, 486.25f, 310.746f, 486.25f, 310.742f, 482.461f, 298.398f, 482.246f, 307.75f,
+482.242f, 307.75f, 478.938f, 326.559f, 476.246f, 317.746f, 472.777f, 309.836f, 468.82f, 303.238f,
+465.246f, 300.75f, 462.66f, 297.957f, 456.938f, 323.035f, 455.25f, 311.75f, 455.25f, 311.75f,
+442.418f, 325.238f, 437.25f, 306.746f, 424.246f, 288.746f, 424.242f, 288.742f, 423.938f, 302.797f,
+422.246f, 295.746f, 422.246f, 295.742f, 389.621f, 289.598f, 378.246f, 294.75f, 10, 0,
+0, 0, 0, 0, 0, 0, 34, 340.25f, 686.746f, 340.25f,
+686.742f, 327.578f, 695.719f, 323.246f, 695.746f, 318.777f, 694.84f, 353.539f, 704.957f, 399.246f,
+674.75f, 399.246f, 674.75f, 404.141f, 671.52f, 408.246f, 671.746f, 408.246f, 671.742f, 411.621f,
+669.316f, 408.246f, 665.75f, 408.246f, 665.75f, 398.859f, 654.797f, 411.246f, 642.746f, 411.246f,
+642.742f, 431.418f, 635, 425.25f, 644.75f, 425.25f, 644.75f, 437.141f, 640.277f, 440.25f,
+635.75f, 442.418f, 631.477f, 441.246f, 635.75f, 441.246f, 635.75f, 441.246f, 635.75f, 434.059f,
+643.797f, 427.25f, 649.746f, 427.25f, 649.742f, 421.738f, 651.719f, 418.25f, 660.746f, 415.578f,
+670.199f, 412.938f, 681.199f, 418.25f, 684.746f, 418.25f, 684.742f, 413.379f, 679.879f, 414.25f,
+684.746f, 415.141f, 688.68f, 419.098f, 692.637f, 421.246f, 692.75f, 422.621f, 693.52f, 440.66f,
+710.898f, 448.25f, 711.746f, 448.25f, 711.746f, 438.02f, 709.797f, 434.246f, 710.746f, 431.418f,
+712, 402.16f, 724.539f, 395.25f, 725.75f, 395.25f, 725.75f, 377.078f, 733.117f, 390.246f,
+730.746f, 390.242f, 730.742f, 429.66f, 726.738f, 449.25f, 711.746f, 449.25f, 711.746f, 441.758f,
+721.457f, 421.246f, 728.746f, 421.246f, 728.742f, 397.098f, 743.02f, 358.25f, 737.746f, 358.25f,
+737.742f, 338.801f, 734, 330.25f, 731.75f, 330.25f, 731.75f, 327.359f, 732.68f, 326.25f,
+732.746f, 326.039f, 733.559f, 313.059f, 743.457f, 282.25f, 735.746f, 282.25f, 735.746f, 264,
+730.699f, 254.246f, 725.75f, 254.246f, 725.75f, 237.816f, 724.098f, 234.246f, 720.75f, 234.246f,
+720.75f, 213.398f, 704.52f, 211.246f, 703.75f, 209, 702.758f, 196.457f, 694.398f, 195.25f,
+693.746f, 195.25f, 693.742f, 222.637f, 701.219f, 225.25f, 703.75f, 227.918f, 706.5f, 247.059f,
+709.359f, 249.25f, 707.75f, 252.34f, 706.277f, 261.578f, 706.938f, 251.25f, 706.746f, 251.25f,
+706.742f, 334.18f, 690, 335.246f, 687.75f, 335.938f, 685.598f, 340.25f, 686.746f, 340.25f,
+686.746f, 10, 0, 0.8f, 0.45f, 0.15f, 0.8f, 0.45f, 0.15f, 13,
+419.246f, 696.75f, 419.246f, 696.75f, 407.66f, 705.18f, 405.25f, 704.746f, 403.258f, 705.18f,
+389.621f, 716.398f, 385.25f, 715.746f, 380.379f, 715.52f, 366.961f, 726.52f, 337.25f, 717.746f,
+337.25f, 717.742f, 336.16f, 719.699f, 340.25f, 720.75f, 340.25f, 720.75f, 347.16f, 723,
+347.25f, 723.75f, 347.25f, 723.75f, 369.82f, 728.277f, 377.246f, 724.746f, 377.246f, 724.746f,
+387.859f, 721.457f, 394.25f, 714.75f, 394.25f, 714.75f, 407, 711.117f, 410.246f, 711.746f,
+410.246f, 711.746f, 420.199f, 709.797f, 420.246f, 707.75f, 420.246f, 707.75f, 427.02f, 704.52f,
+425.25f, 701.75f, 425.25f, 701.75f, 425.48f, 699.898f, 419.246f, 696.75f, 10, 0,
+0.8f, 0.45f, 0.15f, 0.8f, 0.45f, 0.15f, 38, 405.25f, 699.746f, 406.047f,
+698.664f, 407.168f, 698.555f, 408.246f, 697.746f, 408.094f, 697.32f, 407.773f, 696.961f, 407.25f,
+696.75f, 406.281f, 696.504f, 405.121f, 697.133f, 404.25f, 696.75f, 403.422f, 696.258f, 402.715f,
+696.457f, 402.246f, 696.75f, 400.313f, 697.105f, 398.301f, 697.137f, 396.25f, 696.75f, 394.254f,
+697.621f, 391.66f, 696.977f, 389.246f, 697.746f, 389.309f, 698.109f, 389.063f, 697.727f, 389.246f,
+697.746f, 385.629f, 699.016f, 381.512f, 698.707f, 379.246f, 700.746f, 376.168f, 701.672f, 373.574f,
+702.18f, 371.25f, 702.746f, 368.906f, 703.488f, 367.355f, 704.574f, 365.246f, 705.75f, 364.059f,
+706.27f, 362.457f, 706.844f, 361.25f, 707.75f, 358.719f, 707.75f, 356.703f, 707.625f, 354.246f,
+707.75f, 354.52f, 708.227f, 354.309f, 707.848f, 354.246f, 707.75f, 353.863f, 707.996f, 353.543f,
+708.637f, 353.246f, 708.746f, 351.508f, 708.004f, 349.871f, 709.074f, 348.25f, 708.746f, 346.742f,
+710.043f, 344.844f, 709.773f, 343.246f, 710.746f, 339.883f, 711.195f, 336.414f, 709.797f, 333.246f,
+710.746f, 337.602f, 712.926f, 342.758f, 711.57f, 347.25f, 713.746f, 349.789f, 715.148f, 352.715f,
+713.938f, 355.246f, 714.75f, 356.078f, 714.934f, 356.84f, 715.152f, 357.246f, 714.75f, 357.426f,
+714.566f, 357.625f, 714.828f, 357.246f, 714.75f, 360.387f, 713.527f, 362.934f, 712.125f, 365.246f,
+710.746f, 366.039f, 710.793f, 366.621f, 711.047f, 367.246f, 710.746f, 368.57f, 709.488f, 370.711f,
+709.602f, 372.25f, 708.746f, 374.105f, 708.809f, 376.078f, 708.391f, 378.246f, 708.746f, 378.066f,
+709.109f, 378.324f, 708.734f, 378.246f, 708.746f, 379.602f, 709.582f, 380.875f, 709.281f, 382.25f,
+708.746f, 382.227f, 708.82f, 382.957f, 708.551f, 383.25f, 708.746f, 384.531f, 708.164f, 385.473f,
+707.637f, 387.246f, 707.75f, 386.895f, 707.414f, 387.098f, 707.789f, 387.246f, 707.75f, 388.41f,
+707.277f, 389.559f, 707.34f, 390.246f, 705.75f, 390.426f, 706.207f, 390.609f, 706.469f, 390.246f,
+706.746f, 391.828f, 706.066f, 392.543f, 705.238f, 394.25f, 704.746f, 394.289f, 704.855f, 394.961f,
+704.168f, 395.25f, 703.75f, 398.227f, 703.168f, 400.254f, 701.488f, 402.246f, 700.746f, 403.5f,
+700.16f, 404.465f, 699.902f, 405.25f, 699.746f, 10, 0, 0.8f, 0.45f, 0.15f,
+0.8f, 0.45f, 0.15f, 23, 321.246f, 714.75f, 318.094f, 716.91f, 315.488f, 718.125f,
+313.246f, 719.746f, 312.605f, 720.234f, 312.207f, 720.051f, 312.246f, 719.746f, 310.879f, 720.852f,
+309.902f, 721.492f, 309.246f, 722.746f, 308.227f, 722.68f, 307.324f, 722.664f, 307.25f, 722.746f,
+303.969f, 724.371f, 301.074f, 724.984f, 298.246f, 726.746f, 299.066f, 727, 300.301f, 726.73f,
+301.246f, 727.75f, 301.172f, 727.309f, 301.434f, 726.996f, 302.246f, 726.746f, 303.668f, 728.203f,
+305.703f, 728.371f, 307.25f, 728.746f, 309.422f, 728.172f, 311.313f, 727.836f, 313.246f, 727.75f,
+313.605f, 727.484f, 313.824f, 726.91f, 314.25f, 726.746f, 316.629f, 726.074f, 319.258f, 726.648f,
+321.246f, 725.75f, 323.336f, 725.035f, 325.066f, 724.133f, 326.25f, 722.746f, 326.703f, 722.441f,
+326.348f, 722.113f, 326.25f, 721.746f, 326.465f, 722.02f, 326.766f, 721.793f, 327.25f, 721.746f,
+326.98f, 721.184f, 326.98f, 720.852f, 327.25f, 720.75f, 326.766f, 720.246f, 326.457f, 720.133f,
+326.25f, 719.746f, 324.5f, 719.871f, 326.449f, 721.387f, 325.25f, 720.75f, 324.277f, 720,
+325.098f, 718.453f, 324.246f, 716.75f, 323.973f, 717.27f, 323.719f, 717.512f, 324.246f, 717.746f,
+324.098f, 717.363f, 323.434f, 717.043f, 323.246f, 716.75f, 322.824f, 715.898f, 321.836f, 714.344f,
+321.246f, 714.75f, 10, 0, 0.8f, 0.45f, 0.15f, 0.8f, 0.45f, 0.15f,
+25, 285.25f, 706.746f, 281.645f, 707.801f, 278.293f, 707.676f, 275.246f, 708.746f, 274.898f,
+709.109f, 274.656f, 708.727f, 274.25f, 708.746f, 273.082f, 709.41f, 272.07f, 710.473f, 271.25f,
+711.746f, 269.883f, 712.602f, 268.059f, 712.176f, 266.246f, 712.75f, 266.301f, 712.848f, 266.078f,
+713.41f, 266.246f, 713.746f, 264.406f, 713.625f, 263.387f, 714.672f, 262.25f, 715.746f, 264.809f,
+716.172f, 267.461f, 716.137f, 270.25f, 716.75f, 270.293f, 716.582f, 270.453f, 716.227f, 270.25f,
+715.746f, 270.746f, 716.227f, 270.891f, 716.469f, 271.25f, 716.75f, 271.254f, 716.309f, 271.586f,
+715.953f, 272.25f, 715.746f, 272.469f, 716.824f, 273.082f, 716.617f, 273.25f, 716.75f, 273.836f,
+716.563f, 273.973f, 716.227f, 274.25f, 715.746f, 274.27f, 716.227f, 274.41f, 716.57f, 274.25f,
+716.75f, 274.707f, 716.57f, 274.852f, 716.227f, 275.246f, 715.746f, 275.148f, 716.227f, 275.289f,
+716.469f, 275.246f, 716.75f, 276.199f, 715.758f, 277.172f, 716.367f, 278.246f, 715.746f, 279.219f,
+715.922f, 279.512f, 714.656f, 280.246f, 714.75f, 285.879f, 712.895f, 290.43f, 710.535f, 295.25f,
+707.75f, 295.566f, 708.078f, 295.801f, 707.805f, 295.25f, 707.75f, 295.973f, 707.379f, 296.316f,
+707.477f, 296.25f, 707.75f, 297.688f, 706.523f, 298.832f, 705.922f, 299.246f, 704.746f, 299.84f,
+704.34f, 299.477f, 703.895f, 299.246f, 703.75f, 294.348f, 705.047f, 289.941f, 705.715f, 285.25f,
+706.746f, 10, 0, 0.8f, 0.45f, 0.15f, 0.8f, 0.45f, 0.15f, 10,
+270.25f, 658.746f, 268.117f, 659.637f, 267.477f, 661.871f, 266.246f, 663.75f, 266, 664.215f,
+266.301f, 664.563f, 266.246f, 664.746f, 267.266f, 664.832f, 267.863f, 664.309f, 268.246f, 663.75f,
+270.234f, 663.137f, 271.922f, 661.77f, 274.25f, 661.75f, 276.309f, 659.16f, 280.992f, 658.738f,
+281.25f, 654.75f, 281, 654.074f, 279.43f, 655.082f, 279.246f, 653.746f, 276.262f, 655.242f,
+273.633f, 655.129f, 271.25f, 656.746f, 270.336f, 657.16f, 270.699f, 657.66f, 270.25f, 658.746f,
+10, 0, 0.8f, 0.45f, 0.15f, 0.8f, 0.45f, 0.15f, 6, 239.25f,
+715.746f, 239.727f, 716.129f, 247.461f, 715.871f, 247.246f, 715.746f, 247.391f, 715.406f, 238.891f,
+714.254f, 238.25f, 714.75f, 238.309f, 714.523f, 230.047f, 711.852f, 230.25f, 711.746f, 230.191f,
+712.148f, 239.285f, 716.129f, 239.25f, 715.746f, 10, 0, 0, 0, 0,
+0, 0, 0, 80, 256.246f, 705.75f, 256.246f, 705.75f, 240.238f, 703.418f,
+235.246f, 701.75f, 230.559f, 700.777f, 210.098f, 692.418f, 207.25f, 689.746f, 207.25f, 689.746f,
+192.059f, 684.277f, 173.25f, 662.746f, 173.25f, 662.742f, 181.719f, 666.02f, 184.25f, 668.75f,
+184.25f, 668.75f, 199.098f, 682.957f, 199.246f, 679.75f, 199.246f, 679.75f, 212.297f, 689.559f,
+211.246f, 686.746f, 211.246f, 686.742f, 238.477f, 699.457f, 236.25f, 695.746f, 236.25f, 695.742f,
+260.039f, 701, 259.25f, 698.75f, 259.25f, 698.75f, 279.617f, 693.957f, 276.246f, 693.746f,
+276.246f, 693.742f, 270.156f, 692.418f, 277.246f, 688.746f, 277.246f, 688.742f, 273.457f, 683.617f,
+267.246f, 687.75f, 261.578f, 692.418f, 264.879f, 690, 259.25f, 688.746f, 259.25f, 688.742f,
+256.52f, 688.02f, 251.25f, 692.75f, 251.25f, 692.75f, 245.297f, 697.477f, 235.246f, 693.746f,
+235.242f, 693.742f, 201.957f, 679.656f, 200.246f, 678.746f, 200.246f, 678.746f, 195.797f, 675.918f,
+193.25f, 671.746f, 193.25f, 671.742f, 186.777f, 667.117f, 183.25f, 665.75f, 183.25f, 665.75f,
+169.398f, 652.816f, 168.25f, 651.746f, 168.25f, 651.742f, 164.34f, 645.559f, 163.25f, 644.75f,
+163.25f, 644.75f, 170.5f, 649.297f, 172.25f, 651.746f, 172.25f, 651.742f, 188.098f, 662.5f,
+194.25f, 663.75f, 194.25f, 663.75f, 198.879f, 666.68f, 200.246f, 667.746f, 200.246f, 667.746f,
+215.598f, 678.34f, 220.246f, 678.746f, 220.246f, 678.746f, 230.34f, 672.617f, 233.246f, 680.746f,
+233.246f, 680.746f, 239.359f, 682.297f, 245.246f, 680.746f, 245.246f, 680.746f, 249.039f, 683.84f,
+248.25f, 686.746f, 248.25f, 686.742f, 249.918f, 688.238f, 251.25f, 683.75f, 251.25f, 683.75f,
+254.758f, 680.098f, 260.25f, 682.746f, 260.25f, 682.742f, 264.437f, 682.52f, 262.25f, 679.75f,
+262.25f, 679.75f, 257.398f, 675.699f, 244.246f, 675.746f, 244.246f, 675.742f, 230.777f, 674.816f,
+212.246f, 666.75f, 212.246f, 666.75f, 179.957f, 655.02f, 170.246f, 643.75f, 170.242f, 643.75f,
+162.797f, 633.898f, 157.25f, 632.75f, 157.25f, 632.75f, 150.477f, 631.699f, 144.246f, 623.746f,
+144.246f, 623.746f, 154.656f, 629.938f, 164.246f, 629.746f, 164.242f, 629.742f, 168.957f, 632.578f,
+165.246f, 628.75f, 165.242f, 628.75f, 160.816f, 620.258f, 162.25f, 614.746f, 162.25f, 614.746f,
+161.918f, 608.598f, 161.246f, 606.75f, 161.246f, 606.75f, 152.457f, 592.758f, 152.25f, 589.75f,
+152.457f, 587.477f, 153.777f, 576.699f, 154.246f, 575.75f, 154.656f, 575.379f, 153.117f, 577.797f,
+157.25f, 574.746f, 161.477f, 572.52f, 164.559f, 570.758f, 165.246f, 567.75f, 166.316f, 564.598f,
+163.238f, 573.617f, 163.25f, 575.75f, 162.797f, 577.578f, 158.18f, 585.5f, 159.246f, 587.746f,
+159.242f, 587.742f, 160.156f, 587.039f, 161.246f, 585.746f, 161.246f, 585.742f, 160.379f, 586.156f,
+161.246f, 589.75f, 161.246f, 589.75f, 161.918f, 595.84f, 163.25f, 599.75f, 165, 602.879f,
+167.199f, 607.059f, 167.25f, 607.746f, 168.078f, 608.816f, 168.078f, 615.199f, 169.25f, 612.746f,
+173.25f, 609.746f, 173.25f, 609.742f, 170.277f, 612.34f, 172.25f, 614.746f, 172.25f, 614.746f,
+171.598f, 620.918f, 173.25f, 623.746f, 173.25f, 623.746f, 181.277f, 633.02f, 183.25f, 633.75f,
+184.797f, 635.219f, 183.25f, 634.746f, 183.25f, 634.746f, 183.25f, 634.746f, 189.859f, 639.398f,
+183.25f, 637.75f, 183.25f, 637.75f, 179.078f, 635.879f, 176.246f, 635.75f, 176.246f, 635.75f,
+167.418f, 633.68f, 172.25f, 638.746f, 176.219f, 642.918f, 187.219f, 648.859f, 191.246f, 648.75f,
+192.25f, 646.75f, 204.25f, 649.746f, 203.25f, 648.75f, 203.25f, 648.75f, 203.059f, 648.859f,
+207.25f, 649.746f, 212.297f, 649.738f, 218.68f, 648.199f, 220.246f, 649.746f, 221.758f, 652.156f,
+225.5f, 653.258f, 225.25f, 651.746f, 224.617f, 650.18f, 224.246f, 647.746f, 224.246f, 647.746f,
+224.242f, 647.746f, 229.898f, 654.359f, 229.25f, 651.746f, 228.578f, 649.52f, 219.559f, 643.797f,
+218.25f, 636.746f, 229.25f, 645.746f, 233.246f, 649.746f, 233.246f, 649.742f, 237.379f, 646.879f,
+237.25f, 648.75f, 237.816f, 650.398f, 242.879f, 656.777f, 244.246f, 656.746f, 245.52f, 656.34f,
+247.719f, 659.418f, 247.246f, 656.746f, 247.277f, 653.699f, 255.246f, 647.746f, 255.246f, 647.746f,
+255.246f, 647.746f, 259.156f, 649.738f, 260.25f, 647.746f, 262.238f, 646.656f, 267.246f, 669.746f,
+267.246f, 669.746f, 294.25f, 681.75f, 342.246f, 685.75f, 323.246f, 692.75f, 256.246f, 705.75f,
+10, 2.2f, 0.3f, 0, 0, 0.3f, 0, 0, 3, 276.246f,
+486.746f, 276.246f, 486.742f, 260.039f, 504.977f, 251.25f, 507.75f, 251.25f, 507.75f, 236.059f,
+515.316f, 209.246f, 506.746f, 10, 2.2f, 0.3f, 0, 0, 0.3f, 0,
+0, 3, 247.246f, 509.75f, 247.242f, 509.75f, 219.559f, 518.18f, 202.246f, 513.746f,
+202.242f, 513.746f, 182.379f, 511.359f, 173.25f, 495.746f, 10, 2.2f, 0.3f, 0,
+0, 0.3f, 0, 0, 4, 243.246f, 510.746f, 243.246f, 510.742f, 224.617f,
+518.617f, 208.25f, 520.75f, 208.25f, 520.75f, 190.078f, 523.898f, 172.25f, 515.746f, 172.25f,
+515.742f, 158.398f, 509.379f, 152.25f, 497.746f, 10, 2.2f, 0.3f, 0, 0,
+0.3f, 0, 0, 4, 244.246f, 510.746f, 244.246f, 510.742f, 227.477f, 522.359f,
+226.25f, 523.75f, 226.25f, 523.75f, 218.68f, 536, 204.25f, 536.75f, 204.25f, 536.75f,
+180.84f, 535.559f, 162.25f, 526.746f, 10, 0, 0, 0, 0, 0,
+0, 0, 169, 243.246f, 519.746f, 244.68f, 518.543f, 274.25f, 486.746f, 274.25f,
+486.746f, 313.059f, 446.457f, 282.25f, 483.75f, 282.25f, 483.75f, 273.898f, 489.359f, 264.246f,
+509.75f, 264.246f, 509.75f, 262.457f, 513.117f, 279.246f, 501.75f, 279.246f, 501.75f, 283.578f,
+501.238f, 298.246f, 479.75f, 298.246f, 479.75f, 291.059f, 482.758f, 296.25f, 474.75f, 296.25f,
+474.75f, 299.418f, 472.637f, 322.246f, 455.746f, 322.246f, 455.746f, 325.82f, 451.078f, 330.25f,
+449.746f, 330.25f, 449.746f, 345.621f, 455.035f, 338.25f, 440.746f, 338.25f, 440.746f, 341.219f,
+433.035f, 347.25f, 445.746f, 347.25f, 445.746f, 359.699f, 464.277f, 341.25f, 461.75f, 341.25f,
+461.75f, 308.656f, 458.559f, 301.246f, 475.746f, 301.246f, 475.746f, 298.539f, 478.797f, 308.246f,
+475.746f, 308.246f, 475.746f, 317.461f, 473.957f, 300.246f, 489.746f, 300.246f, 489.746f, 302.937f,
+489.797f, 313.246f, 482.746f, 313.246f, 482.746f, 324.5f, 472.199f, 326.25f, 474.75f, 326.25f,
+474.75f, 346.5f, 484.078f, 358.25f, 475.746f, 358.25f, 475.746f, 360.141f, 473.957f, 353.98f,
+466.477f, 355.246f, 460.746f, 357.5f, 455.035f, 363.25f, 441.75f, 363.25f, 441.75f, 360.141f,
+439.637f, 360.25f, 427.746f, 360.25f, 427.746f, 379.059f, 402.238f, 368.246f, 404.75f, 368.246f,
+404.75f, 351.34f, 404.879f, 367.246f, 396.746f, 367.246f, 396.746f, 371.141f, 394.316f, 381.25f,
+386.75f, 381.25f, 386.75f, 377.738f, 387.719f, 376.246f, 381.746f, 376.246f, 381.746f, 381.258f,
+377.598f, 378.246f, 372.746f, 378.246f, 372.746f, 371.578f, 370.996f, 370.25f, 366.75f, 370.25f,
+366.75f, 377.738f, 357.797f, 366.246f, 357.746f, 366.246f, 357.746f, 370.699f, 352.516f, 365.246f,
+339.746f, 365.246f, 339.746f, 360.141f, 339.316f, 353.246f, 332.746f, 353.246f, 332.746f, 355.738f,
+327.879f, 344.246f, 321.746f, 344.246f, 321.746f, 335.059f, 319.957f, 338.25f, 312.75f, 338.25f,
+312.75f, 329.34f, 305.879f, 326.25f, 288.746f, 326.25f, 288.746f, 325.82f, 276.836f, 323.18f,
+273.316f, 329.25f, 275.746f, 334.621f, 277.719f, 333.246f, 291.746f, 333.246f, 291.746f, 328.461f,
+308.516f, 375.246f, 325.75f, 375.246f, 325.75f, 379.938f, 327.879f, 381.25f, 333.75f, 381.25f,
+333.75f, 383.02f, 333.156f, 392.25f, 324.746f, 392.25f, 324.746f, 401.059f, 312.477f, 401.246f,
+322.75f, 401.246f, 322.75f, 402.82f, 326.559f, 401.246f, 332.746f, 401.246f, 332.746f, 407.66f,
+356.918f, 392.25f, 363.746f, 392.25f, 363.746f, 381.258f, 400.918f, 396.25f, 391.75f, 396.25f,
+391.75f, 399.738f, 385.516f, 411.246f, 379.746f, 411.246f, 379.746f, 415.25f, 382.75f, 413.82f,
+387.719f, 423.246f, 394.746f, 423.246f, 394.746f, 426.141f, 387.277f, 432.246f, 395.75f, 432.246f,
+395.75f, 436.699f, 422.918f, 450.25f, 406.75f, 450.25f, 406.75f, 454.738f, 405.758f, 456.246f,
+412.746f, 456.246f, 412.746f, 460.02f, 424.676f, 456.246f, 439.75f, 456.246f, 439.75f, 460.02f,
+440.078f, 470.25f, 433.746f, 470.25f, 433.746f, 473.66f, 437.438f, 463.539f, 455.918f, 468.25f,
+453.746f, 472.34f, 450.637f, 477.25f, 448.75f, 477.25f, 448.75f, 478.059f, 451.078f, 467.246f,
+464.746f, 467.246f, 464.746f, 462.219f, 467.797f, 456.246f, 489.746f, 456.246f, 489.746f, 464.418f,
+486.277f, 453.25f, 502.746f, 453.25f, 502.746f, 453.418f, 506.52f, 460.246f, 518.75f, 460.246f,
+518.75f, 459.141f, 526.316f, 460.246f, 525.75f, 460.246f, 525.75f, 463.098f, 524.559f, 471.898f,
+522.797f, 464.25f, 529.75f, 456.938f, 536.879f, 465.246f, 541.746f, 465.246f, 541.746f, 470.141f,
+545.238f, 455.25f, 544.746f, 455.25f, 544.746f, 449.461f, 549.637f, 450.25f, 553.75f, 450.25f,
+553.75f, 458.699f, 551.84f, 442.859f, 567.68f, 440.25f, 571.75f, 437.578f, 575.598f, 448.25f,
+581.746f, 448.25f, 581.746f, 462.66f, 585.277f, 450.25f, 588.75f, 450.25f, 588.75f, 428.34f,
+588.359f, 440.25f, 599.75f, 440.25f, 599.75f, 446.82f, 599.797f, 445.246f, 602.75f, 445.246f,
+602.75f, 439.34f, 603.758f, 429.25f, 610.75f, 429.25f, 610.75f, 424.379f, 614.758f, 428.25f,
+613.75f, 428.25f, 613.75f, 446.82f, 612.559f, 415.25f, 624.75f, 415.25f, 624.75f, 423.938f,
+624.879f, 404.25f, 636.746f, 404.25f, 636.746f, 401.938f, 638.078f, 398.246f, 646.75f, 398.246f,
+646.75f, 391.82f, 652.156f, 386.246f, 659.75f, 386.246f, 659.75f, 386.098f, 664.477f, 381.25f,
+669.746f, 381.25f, 669.746f, 368.059f, 684.719f, 362.25f, 684.746f, 362.25f, 684.746f, 345.621f,
+688.238f, 340.25f, 687.75f, 340.25f, 687.75f, 282.25f, 682.746f, 252.777f, 668.438f, 261.25f,
+645.746f, 261.25f, 645.746f, 268.398f, 636.098f, 278.246f, 640.746f, 278.246f, 640.746f, 283.578f,
+647.098f, 296.25f, 644.75f, 296.25f, 644.75f, 318.777f, 641.156f, 316.25f, 644.75f, 316.25f,
+644.75f, 313.277f, 650.18f, 295.457f, 657, 295.25f, 657.75f, 295.02f, 658.316f, 285.25f,
+661.75f, 285.25f, 661.75f, 282.039f, 663.379f, 277.246f, 673.746f, 277.246f, 673.746f, 273.68f,
+677.238f, 291.246f, 670.75f, 291.246f, 670.75f, 289.738f, 669.758f, 298.246f, 665.75f, 298.246f,
+665.75f, 317.02f, 666.457f, 328.25f, 654.75f, 328.25f, 654.75f, 340.559f, 636.316f, 341.25f,
+645.746f, 341.25f, 645.746f, 343.859f, 655.68f, 331.246f, 678.746f, 331.246f, 678.746f, 331.32f,
+681.199f, 340.25f, 673.746f, 340.25f, 673.746f, 341.879f, 676.137f, 343.246f, 669.746f, 343.246f,
+669.746f, 342.98f, 667.117f, 347.25f, 658.746f, 347.25f, 658.746f, 350.238f, 644.02f, 354.246f,
+651.746f, 354.246f, 651.746f, 359.25f, 641.75f, 360.801f, 638.957f, 354.246f, 630.75f, 354.246f,
+630.75f, 353.98f, 627.52f, 354.859f, 627.738f, 348.25f, 619.75f, 342.539f, 611.02f, 346.246f,
+605.746f, 346.246f, 605.746f, 344.738f, 598.918f, 354.246f, 599.75f, 354.246f, 599.75f, 357.277f,
+596.938f, 361.25f, 596.746f, 361.25f, 596.746f, 363, 594.738f, 365.246f, 595.75f, 365.246f,
+595.75f, 367.398f, 599.578f, 374.25f, 597.75f, 374.25f, 597.75f, 375.758f, 600.02f, 385.25f,
+600.75f, 385.25f, 600.75f, 385.879f, 603.316f, 386.32f, 605.078f, 390.246f, 605.746f, 393.801f,
+606.398f, 366.246f, 653.746f, 366.246f, 653.746f, 373.777f, 654.578f, 365.246f, 667.746f, 365.246f,
+667.746f, 362.34f, 675.477f, 374.879f, 659.418f, 377.246f, 657.75f, 379.719f, 656.34f, 380.82f,
+653.918f, 379.246f, 653.746f, 377.301f, 654.359f, 375.32f, 651.938f, 377.246f, 651.746f, 378.398f,
+651.5f, 392.699f, 635, 396.25f, 623.746f, 400.18f, 612.559f, 406.777f, 608.156f, 413.246f,
+601.746f, 420.418f, 594.957f, 419.246f, 568.746f, 419.246f, 568.746f, 419.098f, 558.656f, 425.25f,
+546.746f, 425.25f, 546.746f, 427.898f, 542.816f, 423.246f, 522.746f, 423.246f, 522.746f, 421.078f,
+520.379f, 422.246f, 519.746f, 422.246f, 519.746f, 423.719f, 518.18f, 431.246f, 503.75f, 431.246f,
+503.75f, 429.219f, 503.879f, 433.246f, 499.746f, 433.246f, 499.746f, 438.898f, 493.316f, 432.246f,
+496.75f, 432.246f, 496.75f, 425.258f, 498.379f, 433.246f, 487.75f, 433.246f, 487.75f, 434.277f,
+485.617f, 424.246f, 490.75f, 424.246f, 490.75f, 414.258f, 491.34f, 427.25f, 483.75f, 427.25f,
+483.75f, 436.48f, 475.5f, 424.246f, 480.746f, 424.246f, 480.746f, 418.879f, 482.316f, 422.246f,
+474.75f, 422.246f, 474.75f, 425.918f, 473.078f, 445.246f, 465.75f, 445.246f, 465.75f, 445.277f,
+461.195f, 442.246f, 455.746f, 442.246f, 455.746f, 442.418f, 451.297f, 440.25f, 447.746f, 440.25f,
+447.746f, 438.68f, 438.535f, 438.25f, 437.75f, 438.25f, 437.75f, 433.398f, 437.438f, 425.25f,
+422.746f, 425.25f, 422.746f, 423.277f, 419.398f, 412.246f, 405.746f, 412.246f, 405.746f, 409.859f,
+398.496f, 390.246f, 406.75f, 390.246f, 406.75f, 382.801f, 402.676f, 385.25f, 406.75f, 385.25f,
+406.75f, 384.559f, 408.836f, 390.246f, 415.75f, 390.246f, 415.75f, 397.539f, 418.297f, 394.25f,
+429.746f, 394.25f, 429.746f, 399.078f, 431.719f, 386.758f, 434.797f, 387.246f, 435.75f, 387.199f,
+437.438f, 393.25f, 438.746f, 393.25f, 438.746f, 402.379f, 441.176f, 397.246f, 443.75f, 397.246f,
+443.75f, 396.879f, 448.219f, 400.246f, 454.75f, 400.246f, 454.75f, 412.938f, 455.258f, 400.246f,
+472.75f, 400.246f, 472.75f, 388.301f, 481.438f, 387.246f, 487.75f, 387.246f, 487.75f, 401.059f,
+496.84f, 392.039f, 510.477f, 392.25f, 514.75f, 392.48f, 518.398f, 394.25f, 541.746f, 394.25f,
+541.746f, 391.598f, 548.977f, 388.246f, 563.746f, 388.246f, 563.746f, 390.719f, 569.656f, 399.246f,
+583.746f, 399.246f, 583.746f, 401.938f, 588.137f, 411.621f, 593.418f, 409.246f, 596.746f, 406.777f,
+600.02f, 398.246f, 597.75f, 398.246f, 597.75f, 389.621f, 599.578f, 390.246f, 593.75f, 390.246f,
+593.75f, 388.52f, 592.758f, 387.246f, 587.746f, 387.246f, 587.746f, 386.848f, 578.531f, 377.246f,
+571.75f, 377.246f, 571.75f, 364.758f, 564.816f, 375.246f, 560.75f, 375.246f, 560.75f, 381.48f,
+553.156f, 370.25f, 552.746f, 370.25f, 552.746f, 358.598f, 554.918f, 367.246f, 543.746f, 367.246f,
+543.746f, 379.5f, 529.617f, 376.246f, 526.746f, 376.246f, 526.746f, 364.98f, 525.438f, 379.246f,
+515.746f, 379.246f, 515.746f, 379.242f, 515.742f, 377.961f, 517.52f, 378.246f, 515.746f, 378.398f,
+513.559f, 381.699f, 508.938f, 382.25f, 506.746f, 383.461f, 504.539f, 379.246f, 504.746f, 379.246f,
+504.746f, 379.719f, 493.758f, 363.25f, 498.75f, 363.25f, 498.75f, 363.25f, 498.75f, 362.777f,
+498.379f, 361.25f, 497.746f, 359.258f, 497.938f, 346.938f, 498.816f, 340.25f, 500.746f, 334.18f,
+503.656f, 326.25f, 503.75f, 326.25f, 503.75f, 326.25f, 503.75f, 322.301f, 501.68f, 314.25f,
+501.75f, 305.578f, 502.117f, 297.246f, 498.75f, 297.246f, 498.75f, 291.937f, 499.477f, 301.398f,
+504.316f, 301.246f, 503.75f, 301.84f, 503.879f, 308, 510.039f, 299.246f, 509.75f, 275.223f,
+507.578f, 263.25f, 518.75f, 263.25f, 518.75f, 261.137f, 520.379f, 258.246f, 523.75f, 258.246f,
+523.75f, 247.277f, 525.656f, 260.25f, 509.75f, 260.25f, 509.75f, 261.137f, 508.277f, 259.25f,
+506.746f, 259.25f, 506.746f, 258.719f, 508.938f, 250.25f, 514.75f, 250.25f, 514.75f, 247.047f,
+515.949f, 245.547f, 517.414f, 243.246f, 519.746f, 10, 0, 0.3f, 0, 0,
+0.3f, 0, 0, 7, 216.25f, 532.746f, 216.25f, 532.742f, 229.457f, 526.758f,
+232.246f, 523.75f, 235.18f, 520.598f, 250.25f, 507.75f, 250.25f, 507.75f, 250.25f, 507.75f,
+244.637f, 510.258f, 242.246f, 511.746f, 238.918f, 514.219f, 227.25f, 522.746f, 227.25f, 522.746f,
+227.25f, 522.746f, 222.859f, 529.84f, 216.25f, 532.746f, 10, 0, 0.6f, 0.8f,
+0.2f, 0.6f, 0.8f, 0.2f, 6, 153.246f, 566.75f, 153.258f, 567.398f, 152.684f,
+570.379f, 152.25f, 570.746f, 151.332f, 573.977f, 141.25f, 575.75f, 141.25f, 575.75f, 141.207f,
+574.098f, 141.148f, 572.34f, 141.25f, 570.746f, 141.25f, 570.746f, 146.621f, 564.469f, 153.246f,
+566.75f, 10, 0, 0.4f, 0.6f, 0, 0.4f, 0.6f, 0, 6,
+153.246f, 567.75f, 152.395f, 567.281f, 152.871f, 570.461f, 152.25f, 570.746f, 151.555f, 573.977f,
+141.25f, 575.75f, 141.25f, 575.75f, 141.207f, 574.207f, 141.148f, 572.449f, 141.25f, 570.746f,
+141.25f, 570.746f, 145.961f, 565.02f, 153.246f, 567.75f, 10, 0, 0, 0,
+0, 0, 0, 0, 6, 148.246f, 567.75f, 147.371f, 567.297f, 146.812f,
+568.551f, 147.25f, 569.75f, 146.812f, 571.645f, 147.371f, 572.898f, 148.246f, 572.746f, 148.746f,
+572.898f, 149.305f, 571.645f, 149.246f, 569.75f, 149.305f, 568.551f, 148.746f, 567.297f, 148.246f,
+567.75f, 10, 0, 0, 0, 0, 0, 0, 0, 17,
+98.2461f, 459.75f, 98.2422f, 459.75f, 91.7383f, 448.438f, 119.25f, 454.75f, 119.25f, 454.75f,
+134.418f, 456.355f, 137.246f, 458.746f, 138.379f, 458.117f, 147.582f, 454.891f, 150.246f, 453.746f,
+158.18f, 452.398f, 167.25f, 463.75f, 167.25f, 463.75f, 167.25f, 463.75f, 172.477f, 474.949f,
+175.25f, 474.75f, 178.637f, 474.949f, 175.25f, 472.75f, 175.25f, 472.75f, 175.25f, 472.75f,
+167.859f, 462.078f, 168.25f, 460.746f, 168.25f, 460.742f, 162.578f, 438.316f, 145.25f, 437.75f,
+145.25f, 437.75f, 127.215f, 436.391f, 128.25f, 429.746f, 128.25f, 429.742f, 138.379f, 432.598f,
+141.25f, 429.746f, 141.25f, 429.742f, 152.898f, 430.398f, 144.246f, 423.746f, 136.25f, 410.75f,
+136.25f, 410.75f, 136.773f, 406.289f, 125.25f, 409.746f, 114.84f, 413.898f, 103.25f, 427.746f,
+103.25f, 427.746f, 103.25f, 427.742f, 85.9648f, 444.094f, 98.2461f, 459.75f, 10, 0,
+0.9f, 0.6f, 0.6f, 0.9f, 0.6f, 0.6f, 14, 96.25f, 454.75f, 96.25f,
+454.75f, 94.3789f, 444.477f, 135.25f, 455.746f, 135.25f, 455.742f, 139.699f, 455.918f, 142.246f,
+454.75f, 144.977f, 454.156f, 158.18f, 451.078f, 160.246f, 452.75f, 160.246f, 452.75f, 152.457f,
+437.438f, 139.246f, 438.746f, 139.246f, 438.742f, 125.18f, 437.438f, 125.25f, 431.746f, 125.25f,
+431.742f, 130.02f, 424.238f, 135.25f, 421.75f, 135.25f, 421.75f, 138.379f, 418.957f, 138.246f,
+415.75f, 137.5f, 411.918f, 134.418f, 410.156f, 132.246f, 409.746f, 130.02f, 408.398f, 126.5f,
+411.918f, 124.25f, 411.746f, 122.977f, 411.918f, 113.738f, 418.957f, 109.246f, 423.746f, 104.059f,
+429.516f, 94.8164f, 442.719f, 95.25f, 445.746f, 95.6992f, 448.879f, 96.25f, 454.75f, 96.25f,
+454.75f, 10, 0, 0.7f, 0.4f, 0.4f, 0.7f, 0.4f, 0.4f, 13,
+100.246f, 435.75f, 102.957f, 431.496f, 106.477f, 426.879f, 109.246f, 423.746f, 113.738f, 418.957f,
+122.977f, 411.918f, 124.25f, 411.746f, 126.5f, 411.918f, 130.02f, 408.398f, 132.246f, 409.746f,
+134.418f, 410.156f, 137.5f, 411.918f, 138.246f, 415.75f, 138.379f, 418.957f, 135.25f, 421.75f,
+135.25f, 421.75f, 131.926f, 423.285f, 128.91f, 427.125f, 127.246f, 429.746f, 127.246f, 429.742f,
+127.379f, 426.879f, 121.246f, 427.746f, 115.938f, 428.637f, 110.219f, 431.719f, 108.25f, 434.746f,
+106.699f, 438.758f, 104.059f, 441.398f, 106.25f, 437.75f, 107.578f, 433.477f, 110.219f, 429.516f,
+112.25f, 428.75f, 113.738f, 428.637f, 113.297f, 427.316f, 110.246f, 427.746f, 108.02f, 428.195f,
+104.938f, 428.637f, 100.246f, 434.746f, 10, 0, 0.6f, 0.15f, 0, 0.6f,
+0.15f, 0, 20, 97.25f, 458.746f, 97.25f, 458.746f, 99.2187f, 473.957f, 100.246f,
+478.746f, 100.246f, 478.746f, 99.6563f, 485.84f, 102.25f, 490.75f, 104.938f, 495.078f, 107.137f,
+501.898f, 110.246f, 507.75f, 113.738f, 513.777f, 113.957f, 518.18f, 118.25f, 519.746f, 122.758f,
+521.699f, 129.359f, 531.156f, 132.246f, 532.746f, 135.52f, 533.359f, 135.25f, 532.746f, 135.25f,
+532.746f, 135.25f, 532.742f, 142.777f, 548.758f, 157.25f, 544.746f, 157.25f, 544.746f, 139.918f,
+547.438f, 157.25f, 557.746f, 157.25f, 557.746f, 152.02f, 556.566f, 155.246f, 564.75f, 158.07f,
+569.402f, 157.52f, 561.957f, 145.25f, 548.746f, 145.25f, 548.746f, 139.918f, 539.52f, 134.25f,
+535.746f, 128.477f, 532.918f, 115.277f, 525.219f, 114.25f, 520.75f, 112.637f, 516.859f, 109.117f,
+510.477f, 107.25f, 508.746f, 104.719f, 506.957f, 101.637f, 502.34f, 101.25f, 498.75f, 101.25f,
+498.75f, 99.8789f, 494.199f, 98.2461f, 492.75f, 96.7969f, 491.559f, 96.5781f, 488.039f, 96.25f,
+485.75f, 96.5781f, 483.637f, 94.3789f, 480.559f, 94.2461f, 477.746f, 94.2461f, 477.742f, 95.4766f,
+457.016f, 95.25f, 454.75f, 97.25f, 458.746f, 10, 0, 1, 1, 1,
+1, 1, 1, 6, 88.2461f, 453.746f, 88.2461f, 453.742f, 85.5781f, 455.477f,
+80.25f, 448.75f, 80.25f, 448.75f, 88.7695f, 412.578f, 89.2461f, 410.75f, 89.2461f, 410.75f,
+89.9766f, 413.348f, 88.2461f, 421.75f, 87.1172f, 429.188f, 86.25f, 442.746f, 86.25f, 442.746f,
+88.2461f, 453.746f, 10, 0, 0.6f, 0.15f, 0, 0.6f, 0.15f, 0,
+13, 111.246f, 520.75f, 111.246f, 520.75f, 92.1797f, 517.078f, 92.2461f, 484.746f, 91.25f,
+457.75f, 91.25f, 457.75f, 90.418f, 485.84f, 89.2461f, 487.75f, 87.7773f, 489.359f, 92.1797f,
+501.68f, 88.2461f, 494.75f, 88.2461f, 494.75f, 73.2578f, 479.68f, 82.2461f, 456.746f, 82.2422f,
+456.746f, 83.707f, 452.727f, 80.25f, 457.75f, 80.25f, 457.75f, 75.3477f, 471.648f, 76.2461f,
+478.746f, 76.2422f, 478.746f, 76.7773f, 481.109f, 79.25f, 483.75f, 79.25f, 483.75f, 88.3281f,
+497.059f, 91.25f, 499.746f, 91.25f, 499.742f, 93.2773f, 515.43f, 110.246f, 520.75f, 110.246f,
+520.75f, 116.488f, 523.68f, 111.246f, 520.75f, 10, 0, 0, 0, 0,
+0, 0, 0, 28, 265.246f, 593.75f, 265.605f, 593.809f, 265.594f, 594.875f,
+266.246f, 594.746f, 267.496f, 595.441f, 267.676f, 596.617f, 268.246f, 597.75f, 269.207f, 598.93f,
+269.418f, 600.617f, 270.25f, 602.75f, 270.359f, 603.027f, 270.387f, 604.078f, 270.25f, 604.75f,
+268.754f, 607.531f, 267.98f, 610.227f, 266.246f, 612.746f, 266.098f, 613.391f, 265.812f, 614.262f,
+265.246f, 614.746f, 265.082f, 616.441f, 263.699f, 617.535f, 263.25f, 618.746f, 262.434f, 619.469f,
+263.012f, 620.488f, 262.25f, 620.746f, 261.238f, 620.695f, 259.645f, 621.332f, 259.25f, 619.75f,
+258.742f, 617.359f, 259.852f, 614.586f, 261.25f, 611.75f, 260.059f, 611.137f, 260.426f, 610.125f,
+260.25f, 609.746f, 261.375f, 605.313f, 260.055f, 601.625f, 259.25f, 597.75f, 259.191f, 597.691f,
+259.57f, 597.473f, 259.25f, 597.75f, 258.195f, 594.449f, 256.598f, 591.762f, 254.246f, 588.75f,
+253.762f, 588.051f, 252.805f, 587.043f, 252.25f, 585.746f, 251.852f, 585.008f, 251.402f, 583.945f,
+251.25f, 582.75f, 247.898f, 579.801f, 245.426f, 575.57f, 242.246f, 571.75f, 242.043f, 570.594f,
+242.363f, 569.262f, 243.246f, 568.746f, 243.863f, 568.527f, 244.918f, 569.656f, 245.246f, 570.746f,
+245.859f, 571.352f, 246.25f, 572.066f, 247.246f, 572.746f, 246.937f, 572.969f, 246.738f, 573.43f,
+247.246f, 573.75f, 249.785f, 576.145f, 251.621f, 579.375f, 254.246f, 581.746f, 256.465f, 582.34f,
+258.152f, 583.438f, 260.25f, 584.75f, 260.414f, 584.75f, 260.992f, 584.477f, 261.25f, 584.75f,
+263.238f, 585.984f, 263.238f, 588.223f, 263.25f, 590.746f, 263.41f, 591.297f, 263.625f, 592.746f,
+265.246f, 593.75f, 10, 0, 0, 0, 0, 0, 0, 0,
+19, 255.246f, 598.746f, 255.289f, 598.414f, 255.117f, 598.879f, 255.246f, 598.746f, 255.418f,
+599.477f, 255.859f, 599.68f, 256.246f, 599.75f, 256.16f, 600.277f, 255.98f, 600.695f, 256.246f,
+600.75f, 258.695f, 603.543f, 258.977f, 606.867f, 258.246f, 609.746f, 258.965f, 610.82f, 259.031f,
+612.207f, 258.246f, 612.746f, 257.625f, 615.012f, 257.414f, 617.129f, 256.246f, 618.746f, 255.457f,
+620.223f, 253.723f, 621.59f, 252.25f, 619.75f, 251.75f, 619.719f, 251.398f, 618.852f, 251.25f,
+617.75f, 251.773f, 617.887f, 252.09f, 617.727f, 252.25f, 617.75f, 251.941f, 617.281f, 251.34f,
+617.035f, 251.25f, 616.746f, 251.301f, 615.09f, 250.25f, 613.43f, 251.25f, 611.75f, 251.793f,
+610.176f, 252.695f, 608.133f, 253.246f, 605.746f, 252.082f, 603.852f, 253.219f, 601.156f, 251.25f,
+598.746f, 251.141f, 598.93f, 251.148f, 598.508f, 251.25f, 598.746f, 251.605f, 597.75f, 252.051f,
+597.305f, 252.25f, 596.746f, 252.809f, 596.848f, 253.191f, 596.848f, 253.246f, 596.746f, 254.047f,
+597.383f, 254.484f, 597.918f, 255.246f, 598.746f, 10, 0, 0, 0, 0,
+0, 0, 0, 21, 324.246f, 609.746f, 325.773f, 607.703f, 326.094f, 604.629f,
+324.246f, 602.75f, 324.445f, 599.457f, 328.129f, 601.637f, 330.25f, 601.746f, 330.32f, 602.645f,
+330.57f, 603.023f, 331.246f, 602.75f, 332.043f, 603.047f, 332.789f, 604.18f, 334.246f, 603.746f,
+334.438f, 605.691f, 336.238f, 606.465f, 337.25f, 607.746f, 338.844f, 612.047f, 338.195f, 616.746f,
+335.246f, 620.746f, 335.129f, 620.598f, 335.371f, 621.164f, 335.246f, 621.75f, 334.402f, 623.996f,
+332.125f, 624.34f, 330.25f, 624.75f, 328.703f, 629.359f, 327.977f, 633.793f, 326.25f, 637.75f,
+324.266f, 638.133f, 323.496f, 640.047f, 322.246f, 640.746f, 320.559f, 641.629f, 319.934f, 639.891f,
+320.246f, 638.746f, 319.988f, 638.516f, 320.484f, 638.27f, 320.246f, 637.75f, 320.215f, 637.688f,
+319.926f, 637.566f, 320.246f, 637.75f, 319.93f, 637.27f, 320.172f, 637.125f, 320.246f, 636.746f,
+319.309f, 636.074f, 317.742f, 635.551f, 317.25f, 634.746f, 316.371f, 630.211f, 319.199f, 626.773f,
+321.246f, 623.746f, 321.684f, 622.004f, 320.875f, 620.605f, 320.246f, 619.75f, 319.559f, 618.512f,
+319.676f, 617.273f, 320.246f, 616.746f, 320.809f, 613.766f, 322.559f, 611.855f, 324.246f, 609.746f,
+10, 0, 0, 0, 0, 0, 0, 0, 73, 283.25f,
+589.75f, 281.734f, 587.41f, 277.98f, 584.586f, 281.25f, 582.75f, 281.402f, 582.324f, 281.809f,
+582.32f, 282.25f, 582.75f, 284.223f, 584.188f, 286.426f, 585.18f, 289.246f, 585.746f, 289.242f,
+585.852f, 289.543f, 585.34f, 290.246f, 585.746f, 291.727f, 586.289f, 293.938f, 586.227f, 295.25f,
+587.746f, 299.383f, 587.453f, 303.305f, 588.68f, 307.25f, 589.75f, 308.309f, 590.609f, 309.707f,
+591.227f, 311.246f, 591.75f, 312.543f, 592.41f, 313.867f, 593.434f, 315.25f, 594.746f, 315.234f,
+594.836f, 315.625f, 594.738f, 316.25f, 594.746f, 315.875f, 595.688f, 316.934f, 595.828f, 317.25f,
+596.746f, 317.305f, 596.766f, 317.141f, 597.203f, 317.25f, 597.75f, 319.641f, 599.105f, 320.652f,
+601.328f, 319.25f, 603.746f, 319.051f, 604.578f, 318.777f, 605.258f, 318.25f, 605.746f, 316.961f,
+606.781f, 315.75f, 605.844f, 314.25f, 605.746f, 314.422f, 605.488f, 313.621f, 605.676f, 313.246f,
+605.746f, 312.25f, 604.977f, 310.785f, 605.621f, 310.246f, 604.75f, 308.344f, 604.371f, 306.977f,
+604.188f, 305.25f, 603.746f, 305.07f, 603.684f, 304.215f, 603.789f, 304.25f, 602.75f, 303.891f,
+603.246f, 303.727f, 603.504f, 303.25f, 603.746f, 301.512f, 603.043f, 300.125f, 602.809f, 298.246f,
+600.75f, 298.582f, 600.801f, 298.098f, 600.996f, 298.246f, 600.75f, 296.867f, 599.961f, 296.422f,
+598.602f, 295.25f, 597.75f, 294.992f, 597.727f, 294.602f, 597.914f, 294.25f, 597.75f, 293.68f,
+597.297f, 293.277f, 596.59f, 292.25f, 595.75f, 292.207f, 595.848f, 291.766f, 596.207f, 292.25f,
+596.746f, 292.07f, 598.629f, 292.789f, 600.594f, 292.25f, 602.75f, 294.441f, 605.43f, 297.211f,
+607.574f, 299.246f, 610.75f, 299.215f, 612.961f, 299.977f, 615.32f, 300.246f, 617.75f, 299.84f,
+617.816f, 299.523f, 618.625f, 299.246f, 618.746f, 299.043f, 619.945f, 300.039f, 621.117f, 299.246f,
+621.75f, 297.566f, 623.238f, 296.145f, 622.273f, 295.25f, 620.746f, 293.215f, 620.27f, 290.945f,
+619.508f, 289.246f, 620.746f, 288.102f, 621.73f, 287.465f, 622.727f, 286.246f, 623.746f, 285.504f,
+625.32f, 285.871f, 626.898f, 286.246f, 628.75f, 285.953f, 628.762f, 285.609f, 628.91f, 285.25f,
+628.75f, 285.609f, 629.207f, 285.852f, 629.352f, 286.246f, 629.746f, 285.223f, 630.188f, 284.918f,
+631.352f, 284.25f, 631.746f, 284.133f, 632.898f, 283.391f, 633.871f, 282.25f, 633.75f, 280.238f,
+634.965f, 278.395f, 632.859f, 276.246f, 632.75f, 275.746f, 632.758f, 275.23f, 633.902f, 274.25f,
+634.746f, 274.043f, 634.496f, 273.27f, 634.531f, 273.25f, 633.75f, 272.113f, 633.688f, 271.465f,
+633.559f, 270.25f, 633.75f, 268.852f, 632.855f, 267.449f, 631.652f, 266.246f, 630.75f, 264.188f,
+629.77f, 263.137f, 628.188f, 262.25f, 626.75f, 260.914f, 625.469f, 260.762f, 622.813f, 262.25f,
+622.75f, 264.352f, 621.547f, 265.785f, 624.523f, 268.246f, 623.746f, 268.293f, 624.105f, 268.52f,
+623.766f, 268.246f, 623.746f, 268.824f, 623.219f, 269.066f, 623.469f, 269.246f, 623.746f, 270.223f,
+622.656f, 271.504f, 622.285f, 272.25f, 621.75f, 273.602f, 620.332f, 275.523f, 620.793f, 276.246f,
+619.75f, 278.32f, 618.043f, 277.707f, 615.094f, 280.246f, 613.75f, 279.195f, 612.215f, 278.527f,
+610.809f, 278.246f, 608.75f, 277.848f, 607.914f, 278.941f, 606.598f, 280.246f, 606.75f, 281.656f,
+606.801f, 281.945f, 607.633f, 282.25f, 608.75f, 282.773f, 608.523f, 283.289f, 608.199f, 283.25f,
+607.746f, 282.738f, 605.336f, 281.609f, 603.141f, 281.25f, 600.75f, 281.043f, 600.121f, 280.707f,
+599.898f, 280.246f, 599.75f, 279.762f, 595.453f, 275.305f, 592.82f, 272.25f, 589.75f, 272.063f,
+588.785f, 272.059f, 587.414f, 272.25f, 586.75f, 274.051f, 585.445f, 276.207f, 587.145f, 278.246f,
+587.746f, 278.313f, 589.023f, 279.258f, 590.063f, 280.246f, 589.75f, 281.004f, 589.988f, 281.262f,
+590.586f, 281.25f, 590.746f, 282, 590.879f, 282.555f, 590.633f, 283.25f, 590.746f, 284.77f,
+592.164f, 286.32f, 593.383f, 288.246f, 594.746f, 288.441f, 594.832f, 288.82f, 594.66f, 289.246f,
+594.746f, 289.414f, 594.957f, 289.621f, 595.383f, 290.246f, 595.75f, 290.359f, 595.805f, 290.625f,
+595.484f, 291.246f, 594.746f, 290.129f, 594.793f, 290.125f, 593.742f, 289.246f, 593.75f, 288.629f,
+593.223f, 288.012f, 592.66f, 287.246f, 591.75f, 286.949f, 591.957f, 286.227f, 592.23f, 286.246f,
+591.75f, 285.453f, 590.902f, 284.152f, 590.418f, 283.25f, 589.75f, 10, 0, 0,
+0, 0, 0, 0, 0, 30, 222.246f, 643.75f, 222.246f, 643.75f,
+212.258f, 646.957f, 200.246f, 618.746f, 200.246f, 618.742f, 197.34f, 613, 194.25f, 610.75f,
+192.059f, 608.598f, 179.738f, 604.637f, 177.246f, 599.75f, 166.246f, 582.75f, 166.246f, 582.75f,
+182.379f, 600.238f, 186.25f, 602.75f, 186.25f, 602.75f, 194.699f, 612.117f, 191.246f, 604.75f,
+191.242f, 604.75f, 175.777f, 592.758f, 177.246f, 582.75f, 177.246f, 582.75f, 170.938f, 566.797f,
+170.246f, 564.75f, 170.242f, 564.75f, 187.656f, 599.797f, 190.246f, 600.75f, 192.938f, 602.438f,
+194.258f, 602.438f, 193.25f, 598.746f, 191.617f, 594.52f, 191.18f, 576.477f, 188.246f, 574.746f,
+188.246f, 574.742f, 196.898f, 596.719f, 196.25f, 599.75f, 196.25f, 599.75f, 199.539f, 604.199f,
+202.246f, 598.746f, 201.246f, 580.75f, 205.25f, 567.75f, 205.25f, 567.75f, 203.059f, 580,
+205.25f, 596.746f, 205.25f, 596.742f, 202.617f, 608.598f, 207.25f, 602.75f, 211.418f, 596.277f,
+221.977f, 589.68f, 222.246f, 584.75f, 222.246f, 584.75f, 216.258f, 603.758f, 206.25f, 608.75f,
+201.246f, 602.75f, 200.246f, 604.75f, 200.246f, 604.75f, 196.457f, 605.52f, 201.246f, 612.746f,
+206.137f, 620.477f, 205.25f, 621.75f, 205.25f, 621.75f, 205.25f, 621.75f, 212.738f, 613.438f,
+214.25f, 613.75f, 214.25f, 613.75f, 229.02f, 621.797f, 230.25f, 594.746f, 230.25f, 594.742f,
+237.816f, 610.797f, 227.25f, 618.746f, 227.25f, 618.742f, 211.418f, 620.477f, 212.246f, 625.746f,
+220.246f, 639.75f, 224.617f, 645.559f, 223.246f, 642.746f, 223.246f, 642.746f, 10, 0,
+0, 0, 0, 0, 0, 0, 6, 200.246f, 625.746f, 200.246f,
+625.746f, 186.34f, 625.758f, 183.25f, 619.75f, 175.25f, 609.746f, 175.25f, 609.742f, 193.816f,
+620.477f, 198.246f, 621.75f, 202.617f, 623.117f, 200.246f, 625.746f, 200.246f, 625.746f, 10,
+0, 0, 0, 0, 0, 0, 0, 7, 156.25f, 618.746f,
+156.25f, 618.742f, 154.219f, 617.398f, 154.246f, 614.746f, 153.34f, 611.238f, 150.699f, 610.797f,
+151.25f, 607.746f, 152.457f, 604.637f, 154.656f, 602, 154.246f, 606.75f, 154.656f, 610.797f,
+156.418f, 613, 157.25f, 614.746f, 158.18f, 615.637f, 159.938f, 620.477f, 156.25f, 618.746f,
+10, 0, 0, 0, 0, 0, 0, 0, 10, 146.25f,
+551.75f, 146.25f, 551.75f, 137.5f, 555.797f, 134.25f, 559.746f, 130.457f, 563.719f, 130.957f,
+558.035f, 125.25f, 558.75f, 119.187f, 558.922f, 120.246f, 576.746f, 120.246f, 576.746f, 116.246f,
+567.75f, 116.246f, 567.75f, 114.617f, 552.277f, 123.25f, 554.746f, 127.715f, 556.207f, 129.137f,
+554.477f, 127.246f, 553.75f, 125.617f, 552.719f, 133.539f, 552.277f, 130.25f, 550.746f, 127.379f,
+548.758f, 143.219f, 554.477f, 140.25f, 542.75f, 146.25f, 551.75f, 10, 0, 0,
+0, 0, 0, 0, 0, 8, 133.246f, 535.746f, 133.246f, 535.746f,
+115.938f, 530.719f, 112.25f, 541.746f, 112.25f, 541.742f, 106.699f, 538.637f, 109.246f, 535.746f,
+111.539f, 532.039f, 113.25f, 531.75f, 113.25f, 531.75f, 113.25f, 531.75f, 118.797f, 530.277f,
+118.25f, 529.75f, 117.477f, 528.52f, 115.246f, 524.746f, 115.246f, 524.746f, 115.242f, 524.746f,
+126.059f, 531.379f, 133.246f, 535.746f, 10, 0, 1, 1, 1, 1,
+1, 1, 24, 384.25f, 449.746f, 383.648f, 447.191f, 381.813f, 446.309f, 379.246f,
+445.746f, 377.609f, 446.629f, 374.754f, 450.047f, 372.25f, 447.746f, 372.156f, 448.305f, 371.301f,
+448.371f, 371.25f, 448.75f, 370.41f, 450.086f, 370.711f, 451.238f, 370.25f, 451.746f, 369.734f,
+453.516f, 368.953f, 455.016f, 369.25f, 456.746f, 371.145f, 457.359f, 371.801f, 459.457f, 371.25f,
+461.75f, 371.203f, 461.68f, 370.73f, 461.895f, 371.25f, 462.746f, 371.156f, 462.633f, 371.504f,
+462.883f, 372.25f, 462.746f, 371.652f, 463.031f, 371.492f, 462.773f, 371.25f, 462.746f, 370.699f,
+462.91f, 370.836f, 463.613f, 371.25f, 463.75f, 371.621f, 465.957f, 373.836f, 466.25f, 375.246f,
+464.746f, 375.602f, 465.559f, 376.16f, 465.348f, 376.246f, 465.75f, 376.586f, 466.016f, 377.031f,
+466.594f, 377.246f, 466.746f, 377.82f, 468.266f, 379.613f, 467.047f, 380.25f, 467.746f, 381.672f,
+468.629f, 382.844f, 469.398f, 384.25f, 468.75f, 386.02f, 467.621f, 387.898f, 466.285f, 389.246f,
+464.746f, 389.848f, 463.453f, 390.113f, 462.047f, 390.246f, 460.746f, 390.008f, 460.281f, 388.488f,
+460.668f, 388.246f, 459.75f, 387.402f, 457.723f, 389.414f, 457.152f, 390.246f, 455.746f, 390.465f,
+455.297f, 390.176f, 454.961f, 390.246f, 454.75f, 389.375f, 454.711f, 388.516f, 454.922f, 388.246f,
+454.75f, 389.734f, 450.91f, 386.703f, 450.164f, 384.25f, 449.746f, 10, 0, 1,
+1, 1, 1, 1, 1, 11, 373.25f, 427.746f, 373.551f, 429.891f,
+371.789f, 431.82f, 373.25f, 433.746f, 373.27f, 433.551f, 373.41f, 433.305f, 373.25f, 433.746f,
+373.707f, 433.305f, 373.852f, 433.551f, 374.25f, 433.746f, 375.645f, 431.258f, 379.66f, 430.238f,
+379.246f, 426.75f, 379.48f, 426.617f, 378.285f, 425.605f, 379.246f, 424.75f, 377.285f, 423.414f,
+377.223f, 420.809f, 376.246f, 418.746f, 374.836f, 419.051f, 373.504f, 419.449f, 372.25f, 419.75f,
+372.625f, 421.691f, 372.496f, 423.543f, 373.25f, 424.75f, 373.879f, 425.766f, 373.563f, 426.949f,
+373.25f, 427.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f,
+15, 190.246f, 437.75f, 190.246f, 437.75f, 172.195f, 426.727f, 187.246f, 443.75f, 197.34f,
+454.156f, 208.25f, 460.746f, 208.25f, 460.746f, 208.25f, 460.742f, 219.777f, 465.156f, 223.246f,
+466.746f, 227.699f, 467.797f, 244.418f, 473.52f, 248.25f, 473.746f, 251.457f, 474.398f, 262.02f,
+478.797f, 269.246f, 474.75f, 276.977f, 470, 286.246f, 464.746f, 286.246f, 464.746f, 286.246f,
+464.742f, 267.738f, 474.398f, 264.246f, 471.746f, 259.816f, 469.117f, 251.898f, 469.559f, 245.246f,
+465.75f, 245.246f, 465.75f, 229.02f, 461.195f, 225.25f, 458.746f, 221.977f, 456.797f, 210.539f,
+444.035f, 209.246f, 444.746f, 207.02f, 445.797f, 209.219f, 446.238f, 210.246f, 449.746f, 211.859f,
+452.398f, 209.656f, 454.156f, 201.246f, 446.75f, 192.059f, 440.078f, 190.246f, 437.75f, 190.246f,
+437.75f, 10, 0, 0, 0, 0, 0, 0, 0, 11,
+199.246f, 444.746f, 199.246f, 444.742f, 200.434f, 458.785f, 210.246f, 456.746f, 210.246f, 456.746f,
+218.809f, 461.539f, 222.246f, 463.75f, 222.246f, 463.75f, 230.758f, 465.578f, 232.246f, 466.746f,
+252.523f, 475.824f, 268.715f, 470.855f, 269.246f, 471.746f, 269.918f, 473.316f, 291.504f, 465.488f,
+295.25f, 460.746f, 295.906f, 460.508f, 284.219f, 467.152f, 273.25f, 468.75f, 264.453f, 471.008f,
+240.691f, 468.961f, 228.25f, 462.746f, 225.422f, 461.211f, 215.582f, 454.848f, 213.246f, 454.75f,
+210.016f, 455.094f, 199.246f, 444.746f, 199.246f, 444.746f, 10, 0, 0.8f, 0.8f,
+0.8f, 0.8f, 0.8f, 0.8f, 11, 194.25f, 416.746f, 194.25f, 416.742f, 177.977f,
+418.957f, 196.25f, 420.746f, 196.25f, 420.742f, 216.258f, 422.918f, 220.246f, 428.75f, 220.246f,
+428.75f, 235.617f, 438.758f, 238.25f, 438.746f, 241.777f, 439.637f, 274.777f, 447.559f, 275.246f,
+449.746f, 275.656f, 452.836f, 281.816f, 452.836f, 283.25f, 451.746f, 285.34f, 451.078f, 284.457f,
+449.758f, 281.25f, 448.75f, 278.297f, 447.996f, 243.977f, 429.957f, 237.25f, 428.75f, 229.898f,
+427.316f, 217.137f, 418.957f, 212.246f, 417.75f, 206.578f, 416.316f, 194.25f, 416.746f, 194.25f,
+416.746f, 10, 0, 0, 0, 0, 0, 0, 0, 11,
+216.25f, 424.75f, 216.25f, 424.75f, 206.73f, 425.367f, 216.25f, 426.75f, 216.25f, 426.75f,
+225.887f, 430.035f, 228.25f, 432.75f, 228.25f, 432.75f, 235.801f, 438.145f, 237.25f, 438.746f,
+238.957f, 438.594f, 254.313f, 442.652f, 254.246f, 443.75f, 254.762f, 445.355f, 292.234f, 459.191f,
+297.246f, 455.746f, 300.301f, 453.371f, 289.406f, 455.219f, 279.246f, 450.75f, 277.32f, 449.684f,
+240.082f, 433.637f, 236.25f, 432.75f, 232.871f, 432.285f, 226.34f, 428.008f, 223.246f, 427.746f,
+220.934f, 426.656f, 216.25f, 424.75f, 216.25f, 424.75f, 10, 0, 0, 0,
+0, 0, 0, 0, 4, 207.25f, 421.75f, 207.25f, 421.75f, 213.18f,
+422.477f, 212.246f, 420.746f, 210.539f, 418.957f, 208.25f, 419.75f, 208.25f, 419.75f, 207.25f,
+421.75f, 10, 0, 0, 0, 0, 0, 0, 0, 4,
+199.246f, 420.746f, 199.246f, 420.742f, 205.258f, 420.719f, 204.25f, 418.746f, 202.617f, 417.195f,
+200.246f, 417.75f, 200.246f, 417.75f, 199.246f, 420.746f, 10, 0, 0, 0,
+0, 0, 0, 0, 4, 188.246f, 418.746f, 188.246f, 418.742f, 193.816f,
+418.957f, 192.25f, 416.746f, 191.18f, 415.438f, 188.246f, 416.746f, 188.246f, 416.746f, 188.246f,
+418.746f, 10, 0, 0, 0, 0, 0, 0, 0, 4,
+179.246f, 417.75f, 179.246f, 417.75f, 185.457f, 418.078f, 184.25f, 416.746f, 182.816f, 414.559f,
+180.246f, 415.75f, 180.246f, 415.75f, 179.246f, 417.75f, 10, 0, 0, 0,
+0, 0, 0, 0, 4, 222.246f, 460.746f, 222.246f, 460.742f, 226.816f,
+461.195f, 225.25f, 459.75f, 224.18f, 457.676f, 220.246f, 457.75f, 220.246f, 457.75f, 222.246f,
+460.746f, 10, 0, 0, 0, 0, 0, 0, 0, 4,
+211.246f, 454.75f, 211.246f, 454.75f, 218.133f, 457.391f, 215.25f, 453.746f, 214.059f, 451.957f,
+211.246f, 452.75f, 211.246f, 452.75f, 211.246f, 454.75f, 10, 0, 0, 0,
+0, 0, 0, 0, 4, 198.246f, 449.746f, 198.246f, 449.742f, 204.379f,
+450.195f, 203.25f, 448.75f, 201.738f, 446.676f, 199.246f, 447.746f, 199.246f, 447.746f, 198.246f,
+449.746f, 10, 0, 0, 0, 0, 0, 0, 0, 4,
+190.246f, 442.746f, 190.246f, 442.742f, 196.02f, 443.598f, 194.25f, 441.75f, 193.379f, 440.078f,
+190.246f, 440.746f, 190.246f, 440.746f, 190.246f, 442.746f, 10, 0, 0, 0,
+0, 0, 0, 0, 4, 183.25f, 437.75f, 183.25f, 437.75f, 188.539f,
+438.316f, 187.246f, 436.746f, 185.898f, 434.797f, 183.25f, 435.75f, 183.25f, 435.75f, 183.25f,
+437.75f, 10, 0, 0, 0, 0, 0, 0, 0, 4,
+226.25f, 430.75f, 226.25f, 430.75f, 233.422f, 431.426f, 231.246f, 428.75f, 229.906f, 426.742f,
+226.25f, 427.746f, 226.25f, 427.746f, 226.25f, 430.75f, 10, 0, 0, 0,
+0, 0, 0, 0, 4, 237.25f, 435.75f, 237.25f, 435.75f, 244.863f,
+436.707f, 243.246f, 434.746f, 241.348f, 432.02f, 238.25f, 432.75f, 238.25f, 432.75f, 237.25f,
+435.75f, 10, 0, 0, 0, 0, 0, 0, 0, 4,
+249.25f, 440.746f, 249.25f, 440.742f, 256.742f, 441.547f, 255.246f, 438.746f, 253.227f, 436.859f,
+249.25f, 437.75f, 249.25f, 437.75f, 249.25f, 440.746f, 10, 0, 0, 0,
+0, 0, 0, 0, 4, 260.25f, 445.746f, 260.25f, 445.746f, 268.18f,
+446.824f, 266.246f, 444.746f, 264.668f, 442.141f, 261.25f, 443.75f, 261.25f, 443.75f, 260.25f,
+445.746f, 10, 0, 0, 0, 0, 0, 0, 0, 4,
+230.25f, 465.75f, 230.25f, 465.75f, 237.82f, 466.625f, 236.25f, 464.746f, 234.309f, 461.941f,
+230.25f, 461.75f, 230.25f, 461.75f, 230.25f, 465.75f, 10, 0, 0, 0,
+0, 0, 0, 0, 4, 241.25f, 469.746f, 241.25f, 469.746f, 248.82f,
+470.145f, 247.246f, 467.746f, 245.309f, 465.461f, 240.25f, 465.75f, 240.25f, 465.75f, 241.25f,
+469.746f, 10, 0, 0, 0, 0, 0, 0, 0, 4,
+216.25f, 425.746f, 216.25f, 425.746f, 221.977f, 425.996f, 220.246f, 423.746f, 219.34f, 422.477f,
+216.25f, 423.746f, 216.25f, 423.746f, 216.25f, 425.746f, 10, 0, 0.6f, 0.15f,
+0, 0.6f, 0.15f, 0, 5, 135.25f, 534.75f, 135.25f, 534.75f, 130.898f,
+525, 130.25f, 521.746f, 130.25f, 521.742f, 131.34f, 531.156f, 132.246f, 533.746f, 133.977f,
+535.559f, 135.25f, 534.75f, 135.25f, 534.75f, 10, 0, 0.6f, 0.15f, 0,
+0.6f, 0.15f, 0, 5, 115.246f, 519.746f, 115.242f, 519.742f, 111.977f, 503.438f,
+112.25f, 500.746f, 112.25f, 500.746f, 111.098f, 513.117f, 111.246f, 514.75f, 111.977f, 515.758f,
+115.246f, 519.746f, 115.246f, 519.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 6, 138.246f, 601.746f, 138.246f, 597.75f, 135.25f, 597.75f, 135.25f,
+597.75f, 151.359f, 583.738f, 152.25f, 575.75f, 152.25f, 575.75f, 152.898f, 584.398f, 138.246f,
+601.746f, 10, 0, 0, 0, 0, 0, 0, 0, 28,
+143.246f, 599.75f, 142.285f, 600.402f, 142.527f, 601.223f, 142.246f, 601.746f, 141.188f, 602.078f,
+143.508f, 602.141f, 143.246f, 602.75f, 142.836f, 604.254f, 143.039f, 604.277f, 143.246f, 605.746f,
+142.844f, 606.34f, 143.488f, 608.031f, 144.246f, 608.75f, 145.504f, 610.332f, 144.047f, 613.559f,
+146.25f, 615.75f, 146.188f, 615.582f, 146.598f, 616.191f, 147.25f, 616.746f, 147.637f, 617.711f,
+148.941f, 618.246f, 150.246f, 618.746f, 150.336f, 619.461f, 150.113f, 620.371f, 150.246f, 620.746f,
+151.523f, 620.141f, 152.891f, 620.285f, 153.246f, 619.75f, 152.715f, 617.027f, 151.254f, 615.137f,
+150.246f, 613.75f, 150.344f, 612.527f, 149.84f, 611.828f, 149.246f, 610.75f, 148.059f, 608.336f,
+148.266f, 605.207f, 148.246f, 601.746f, 148.07f, 601.992f, 147.73f, 601.906f, 147.25f, 601.746f,
+148.129f, 599.277f, 148.77f, 596.859f, 149.246f, 594.746f, 150.141f, 593.387f, 150.66f, 592.402f,
+151.25f, 591.75f, 150.945f, 590.625f, 151.059f, 589.711f, 150.246f, 588.75f, 152.848f, 585.754f,
+151.41f, 582.84f, 152.25f, 578.75f, 152.922f, 578.27f, 154.785f, 576.164f, 154.246f, 576.746f,
+151.512f, 577.297f, 151.387f, 577.734f, 151.25f, 578.75f, 151.031f, 579.25f, 150.668f, 580.762f,
+150.246f, 581.746f, 150.336f, 581.605f, 150.148f, 583.68f, 150.246f, 583.746f, 148.398f, 586.434f,
+149.895f, 586.238f, 148.246f, 588.75f, 146.816f, 589.582f, 145.754f, 590.797f, 144.246f, 591.75f,
+144.301f, 592.297f, 145.559f, 593.094f, 145.25f, 593.75f, 144.156f, 594.746f, 142.887f, 595.59f,
+143.246f, 596.746f, 143.43f, 597.992f, 143.578f, 599.156f, 143.246f, 599.75f, 10, 0,
+0, 0, 0, 0, 0, 0, 11, 139.246f, 597.75f, 139.246f,
+597.75f, 139.258f, 590.559f, 142.246f, 588.75f, 144.539f, 587.039f, 143.219f, 587.918f, 139.246f,
+588.75f, 136.18f, 590.559f, 137.246f, 591.75f, 137.246f, 591.75f, 137.242f, 591.75f, 134.418f,
+591, 137.246f, 588.75f, 139.699f, 586.598f, 143.656f, 583.957f, 142.246f, 583.746f, 140.137f,
+583.957f, 131.777f, 588.359f, 132.246f, 591.75f, 131.777f, 594.52f, 130.25f, 598.746f, 130.25f,
+598.746f, 130.25f, 598.742f, 131.887f, 599.906f, 137.246f, 599.75f, 137.242f, 599.75f, 138.707f,
+599.027f, 139.246f, 597.75f, 10, 0, 1, 1, 1, 1, 1,
+1, 5, 138.246f, 577.75f, 138.246f, 577.75f, 128.566f, 580.648f, 108.25f, 576.746f,
+108.25f, 576.742f, 118.172f, 579.203f, 139.246f, 576.746f, 150.148f, 575.324f, 138.246f, 577.75f,
+138.246f, 577.75f, 10, 0.11f, 0, 0, 0, 0, 0, 0,
+5, 138.246f, 577.75f, 138.246f, 577.75f, 128.566f, 580.648f, 108.25f, 576.746f, 108.25f,
+576.742f, 118.172f, 579.203f, 139.246f, 576.746f, 150.148f, 575.324f, 138.246f, 577.75f, 138.246f,
+577.75f, 10, 0, 1, 1, 1, 1, 1, 1, 5,
+140.25f, 577.75f, 140.25f, 577.75f, 131.176f, 581.527f, 110.246f, 579.746f, 110.246f, 579.746f,
+120.695f, 580.984f, 141.25f, 576.746f, 152.215f, 574.355f, 140.25f, 577.75f, 140.25f, 577.75f,
+10, 0.11f, 0, 0, 0, 0, 0, 0, 5, 140.25f,
+577.75f, 140.25f, 577.75f, 131.176f, 581.527f, 110.246f, 579.746f, 110.246f, 579.746f, 120.695f,
+580.984f, 141.25f, 576.746f, 152.215f, 574.355f, 140.25f, 577.75f, 140.25f, 577.75f, 10,
+0, 1, 1, 1, 1, 1, 1, 5, 142.246f, 577.75f,
+142.242f, 577.75f, 133.453f, 582.086f, 113.25f, 581.746f, 113.25f, 581.746f, 122.965f, 582.328f,
+143.246f, 576.746f, 153.902f, 573.371f, 142.246f, 577.75f, 142.246f, 577.75f, 10, 0.11f,
+0, 0, 0, 0, 0, 0, 5, 142.246f, 577.75f, 142.242f,
+577.75f, 133.453f, 582.086f, 113.25f, 581.746f, 113.25f, 581.746f, 122.965f, 582.328f, 143.246f,
+576.746f, 153.902f, 573.371f, 142.246f, 577.75f, 142.246f, 577.75f, 10, 0, 1,
+1, 1, 1, 1, 1, 5, 143.246f, 577.75f, 143.242f, 577.75f,
+136.102f, 582.047f, 117.25f, 583.746f, 117.25f, 583.742f, 126.715f, 583.066f, 144.246f, 576.746f,
+153.77f, 572.66f, 143.246f, 577.75f, 143.246f, 577.75f, 10, 0.11f, 0, 0,
+0, 0, 0, 0, 5, 143.246f, 577.75f, 143.242f, 577.75f, 136.102f,
+582.047f, 117.25f, 583.746f, 117.25f, 583.742f, 126.715f, 583.066f, 144.246f, 576.746f, 153.77f,
+572.66f, 143.246f, 577.75f, 143.246f, 577.75f, 10, 0, 1, 1, 1,
+1, 1, 1, 5, 270.25f, 565.746f, 270.25f, 565.742f, 269.398f, 565.031f,
+269.246f, 566.75f, 269.871f, 567.629f, 300.898f, 582.117f, 305.25f, 581.746f, 305.25f, 581.746f,
+271.602f, 567.316f, 270.25f, 565.746f, 10, 0.11f, 0, 0, 0, 0,
+0, 0, 5, 270.25f, 565.746f, 270.25f, 565.742f, 269.398f, 565.031f, 269.246f,
+566.75f, 269.871f, 567.629f, 300.898f, 582.117f, 305.25f, 581.746f, 305.25f, 581.746f, 271.602f,
+567.316f, 270.25f, 565.746f, 10, 0, 1, 1, 1, 1, 1,
+1, 5, 266.246f, 564.75f, 266.246f, 564.75f, 265.727f, 564.25f, 266.246f, 565.746f,
+265.992f, 566.879f, 295.785f, 583.758f, 300.246f, 583.746f, 300.246f, 583.742f, 267.742f, 566.699f,
+266.246f, 564.75f, 10, 0.11f, 0, 0, 0, 0, 0, 0,
+5, 266.246f, 564.75f, 266.246f, 564.75f, 265.727f, 564.25f, 266.246f, 565.746f, 265.992f,
+566.879f, 295.785f, 583.758f, 300.246f, 583.746f, 300.246f, 583.742f, 267.742f, 566.699f, 266.246f,
+564.75f, 10, 0, 1, 1, 1, 1, 1, 1, 5,
+263.25f, 563.746f, 263.25f, 563.742f, 262.164f, 562.676f, 262.25f, 563.746f, 262.254f, 565.316f,
+284.055f, 582.363f, 295.25f, 584.75f, 295.25f, 584.75f, 275.016f, 575.484f, 263.25f, 563.746f,
+10, 0.11f, 0, 0, 0, 0, 0, 0, 5, 263.25f,
+563.746f, 263.25f, 563.742f, 262.164f, 562.676f, 262.25f, 563.746f, 262.254f, 565.316f, 284.055f,
+582.363f, 295.25f, 584.75f, 295.25f, 584.75f, 275.016f, 575.484f, 263.25f, 563.746f, 10,
+0, 1, 1, 1, 1, 1, 1, 5, 260.25f, 561.746f,
+260.25f, 561.742f, 259.09f, 560.711f, 259.25f, 561.746f, 259.176f, 563.086f, 278.793f, 578.43f,
+288.246f, 580.75f, 288.246f, 580.75f, 270.656f, 572.238f, 260.25f, 561.746f, 10, 0.11f,
+0, 0, 0, 0, 0, 0, 5, 260.25f, 561.746f, 260.25f,
+561.742f, 259.09f, 560.711f, 259.25f, 561.746f, 259.176f, 563.086f, 278.793f, 578.43f, 288.246f,
+580.75f, 288.246f, 580.75f, 270.656f, 572.238f, 260.25f, 561.746f, 10, 0, 0.8f,
+0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 11, 225.25f, 398.746f, 225.25f, 398.742f,
+208.34f, 401.355f, 227.25f, 402.75f, 227.25f, 402.75f, 246.617f, 405.316f, 251.25f, 410.75f,
+251.25f, 410.75f, 265.977f, 421.156f, 269.246f, 421.75f, 272.137f, 422.035f, 290.18f, 425.996f,
+290.246f, 428.75f, 291.059f, 431.277f, 297.656f, 433.918f, 299.246f, 432.75f, 301.18f, 432.156f,
+301.18f, 422.035f, 298.246f, 420.746f, 295.02f, 420.277f, 274.34f, 412.355f, 267.246f, 410.75f,
+260.258f, 409.719f, 247.5f, 401.355f, 242.246f, 399.75f, 236.938f, 398.719f, 225.25f, 398.746f,
+225.25f, 398.746f, 10, 0, 0, 0, 0, 0, 0, 0,
+11, 305.25f, 439.75f, 305.25f, 439.75f, 302.059f, 438.098f, 300.246f, 434.746f, 300.246f,
+434.746f, 293.699f, 423.578f, 278.246f, 419.75f, 278.246f, 419.75f, 252.777f, 410.156f, 244.246f,
+407.746f, 244.246f, 407.742f, 229.457f, 402.457f, 221.246f, 403.746f, 221.246f, 403.746f, 213.617f,
+403.117f, 220.246f, 401.746f, 220.246f, 401.746f, 242.656f, 403.559f, 246.246f, 405.746f, 246.242f,
+405.742f, 263.559f, 411.258f, 267.246f, 413.75f, 270.156f, 416.977f, 290.18f, 422.477f, 292.25f,
+424.75f, 295.02f, 426.879f, 305.797f, 436.117f, 305.25f, 439.75f, 10, 0, 0,
+0, 0, 0, 0, 0, 4, 241.25f, 404.75f, 241.25f, 404.75f,
+246.52f, 405.445f, 245.246f, 403.746f, 243.984f, 402.035f, 241.25f, 402.75f, 241.25f, 402.75f,
+241.25f, 404.75f, 10, 0, 0, 0, 0, 0, 0, 0,
+4, 233.246f, 403.746f, 233.246f, 403.746f, 238.598f, 403.957f, 237.25f, 402.75f, 236.063f,
+400.547f, 233.246f, 401.746f, 233.246f, 401.746f, 233.246f, 403.746f, 10, 0, 0,
+0, 0, 0, 0, 0, 4, 221.246f, 402.75f, 221.246f, 402.75f,
+227.125f, 402.586f, 226.25f, 400.75f, 224.59f, 399.176f, 222.246f, 399.75f, 222.246f, 399.75f,
+221.246f, 402.75f, 10, 0, 0, 0, 0, 0, 0, 0,
+4, 213.246f, 401.746f, 213.242f, 401.746f, 218.73f, 401.984f, 217.25f, 400.75f, 216.191f,
+398.578f, 213.246f, 399.75f, 213.246f, 399.75f, 213.246f, 401.746f, 10, 0, 0,
+0, 0, 0, 0, 0, 4, 259.25f, 413.75f, 259.25f, 413.75f,
+266.609f, 413.664f, 265.246f, 411.746f, 263.234f, 409.129f, 259.25f, 410.75f, 259.25f, 410.75f,
+259.25f, 413.75f, 10, 0, 0, 0, 0, 0, 0, 0,
+4, 270.25f, 417.75f, 270.25f, 417.75f, 276.855f, 421.832f, 276.246f, 416.746f, 275.973f,
+413.453f, 271.25f, 415.75f, 271.25f, 415.75f, 270.25f, 417.75f, 10, 0, 0,
+0, 0, 0, 0, 0, 4, 280.246f, 421.75f, 280.242f, 421.75f,
+288.223f, 425.367f, 286.246f, 419.75f, 285.457f, 416.664f, 281.25f, 418.746f, 281.25f, 418.746f,
+280.246f, 421.75f, 10, 0, 0, 0, 0, 0, 0, 0,
+4, 291.246f, 426.75f, 291.242f, 426.75f, 295.605f, 431.996f, 297.246f, 424.75f, 297.227f,
+421.875f, 291.246f, 423.746f, 291.246f, 423.746f, 291.246f, 426.75f, 10, 0, 0,
+0, 0, 0, 0, 0, 4, 249.25f, 408.75f, 249.25f, 408.75f,
+255.266f, 408.652f, 254.246f, 406.75f, 252.73f, 405.242f, 250.25f, 405.746f, 250.25f, 405.746f,
+249.25f, 408.75f, 10, 0, 1, 1, 1, 1, 1, 1,
+5, 288.246f, 541.746f, 288.246f, 541.742f, 287.875f, 541.203f, 288.246f, 542.75f, 287.875f,
+543.559f, 307.109f, 558.148f, 317.25f, 559.746f, 317.25f, 559.746f, 299.125f, 552.27f, 288.246f,
+541.746f, 10, 0.11f, 0, 0, 0, 0, 0, 0, 5,
+288.246f, 541.746f, 288.246f, 541.742f, 287.875f, 541.203f, 288.246f, 542.75f, 287.875f, 543.559f,
+307.109f, 558.148f, 317.25f, 559.746f, 317.25f, 559.746f, 299.125f, 552.27f, 288.246f, 541.746f,
+10, 0, 0, 0, 0, 0, 0, 0, 10, 292.25f,
+471.746f, 292.25f, 471.742f, 316.141f, 447.117f, 326.25f, 442.746f, 326.25f, 442.742f, 336.379f,
+430.836f, 332.246f, 401.746f, 332.246f, 401.746f, 328.461f, 393.879f, 325.25f, 416.746f, 325.25f,
+416.742f, 328.461f, 444.477f, 316.25f, 426.75f, 316.25f, 426.75f, 306.898f, 437.766f, 314.25f,
+437.75f, 314.25f, 437.75f, 317.461f, 435.238f, 318.25f, 436.746f, 318.34f, 438.758f, 309.539f,
+453.719f, 290.246f, 469.746f, 271.699f, 485.398f, 292.25f, 471.746f, 292.25f, 471.746f, 10,
+0, 1, 1, 1, 1, 1, 1, 5, 227.25f, 428.75f,
+227.25f, 428.75f, 227.477f, 431.059f, 229.25f, 429.746f, 231.438f, 429.297f, 335.059f, 422.477f,
+370.25f, 395.75f, 370.25f, 395.75f, 320.098f, 421.598f, 227.25f, 428.75f, 10, 0.11f,
+0, 0, 0, 0, 0, 0, 5, 227.25f, 428.75f, 227.25f,
+428.75f, 227.477f, 431.059f, 229.25f, 429.746f, 231.438f, 429.297f, 335.059f, 422.477f, 370.25f,
+395.75f, 370.25f, 395.75f, 320.098f, 421.598f, 227.25f, 428.75f, 10, 0, 1,
+1, 1, 1, 1, 1, 5, 239.25f, 433.746f, 239.25f, 433.742f,
+238.918f, 435.898f, 241.25f, 434.746f, 242.879f, 434.137f, 393.141f, 435.238f, 419.246f, 399.75f,
+419.246f, 399.75f, 394.898f, 427.316f, 239.25f, 433.746f, 10, 0.11f, 0, 0,
+0, 0, 0, 0, 5, 239.25f, 433.746f, 239.25f, 433.742f, 238.918f,
+435.898f, 241.25f, 434.746f, 242.879f, 434.137f, 393.141f, 435.238f, 419.246f, 399.75f, 419.246f,
+399.75f, 394.898f, 427.316f, 239.25f, 433.746f, 10, 0, 1, 1, 1,
+1, 1, 1, 5, 252.25f, 438.746f, 252.25f, 438.742f, 251.68f, 440.297f,
+253.246f, 439.75f, 255.637f, 438.535f, 446.379f, 452.836f, 472.25f, 416.746f, 472.25f, 416.742f,
+461.777f, 445.355f, 252.25f, 438.746f, 10, 0.11f, 0, 0, 0, 0,
+0, 0, 5, 252.25f, 438.746f, 252.25f, 438.742f, 251.68f, 440.297f, 253.246f,
+439.75f, 255.637f, 438.535f, 446.379f, 452.836f, 472.25f, 416.746f, 472.25f, 416.742f, 461.777f,
+445.355f, 252.25f, 438.746f, 10, 0, 1, 1, 1, 1, 1,
+1, 5, 263.25f, 443.75f, 263.25f, 443.75f, 262.68f, 445.578f, 264.246f, 444.746f,
+266.637f, 443.816f, 401.059f, 486.277f, 427.25f, 450.75f, 427.25f, 450.75f, 412.277f, 477.699f,
+263.25f, 443.75f, 10, 0.11f, 0, 0, 0, 0, 0, 0,
+5, 263.25f, 443.75f, 263.25f, 443.75f, 262.68f, 445.578f, 264.246f, 444.746f, 266.637f,
+443.816f, 401.059f, 486.277f, 427.25f, 450.75f, 427.25f, 450.75f, 412.277f, 477.699f, 263.25f,
+443.75f, 10, 0, 1, 1, 1, 1, 1, 1, 5,
+199.246f, 418.746f, 199.246f, 418.742f, 198.879f, 420.496f, 201.246f, 419.75f, 202.84f, 418.738f,
+222.418f, 416.316f, 224.246f, 373.75f, 224.242f, 373.75f, 216.699f, 419.836f, 199.246f, 418.746f,
+10, 0.11f, 0, 0, 0, 0, 0, 0, 5, 199.246f,
+418.746f, 199.246f, 418.742f, 198.879f, 420.496f, 201.246f, 419.75f, 202.84f, 418.738f, 222.418f,
+416.316f, 224.246f, 373.75f, 224.242f, 373.75f, 216.699f, 419.836f, 199.246f, 418.746f, 10,
+0, 1, 1, 1, 1, 1, 1, 5, 189.246f, 416.746f,
+189.246f, 416.742f, 189.199f, 418.738f, 191.246f, 417.75f, 193.156f, 416.977f, 208.777f, 422.035f,
+205.25f, 379.746f, 205.25f, 379.746f, 207.02f, 418.078f, 189.246f, 416.746f, 10, 0.11f,
+0, 0, 0, 0, 0, 0, 5, 189.246f, 416.746f, 189.246f,
+416.742f, 189.199f, 418.738f, 191.246f, 417.75f, 193.156f, 416.977f, 208.777f, 422.035f, 205.25f,
+379.746f, 205.25f, 379.746f, 207.02f, 418.078f, 189.246f, 416.746f, 10, 0, 1,
+1, 1, 1, 1, 1, 5, 180.246f, 416.746f, 180.242f, 416.742f,
+180.398f, 418.297f, 182.25f, 417.75f, 184.359f, 416.535f, 201.297f, 415.879f, 187.246f, 390.746f,
+187.246f, 390.746f, 198.219f, 417.637f, 180.246f, 416.746f, 10, 0.11f, 0, 0,
+0, 0, 0, 0, 5, 180.246f, 416.746f, 180.242f, 416.742f, 180.398f,
+418.297f, 182.25f, 417.75f, 184.359f, 416.535f, 201.297f, 415.879f, 187.246f, 390.746f, 187.246f,
+390.746f, 198.219f, 417.637f, 180.246f, 416.746f, 10, 0, 1, 1, 1,
+1, 1, 1, 5, 232.246f, 464.746f, 232.246f, 464.742f, 232.187f, 462.887f,
+234.246f, 463.75f, 251.566f, 478.113f, 287.254f, 542.906f, 348.25f, 548.746f, 348.25f, 548.746f,
+306.367f, 562.426f, 232.246f, 464.746f, 10, 0.11f, 0, 0, 0, 0,
+0, 0, 5, 232.246f, 464.746f, 232.246f, 464.742f, 232.187f, 462.887f, 234.246f,
+463.75f, 251.566f, 478.113f, 287.254f, 542.906f, 348.25f, 548.746f, 348.25f, 548.746f, 306.367f,
+562.426f, 232.246f, 464.746f, 10, 0, 1, 1, 1, 1, 1,
+1, 5, 245.246f, 466.746f, 245.246f, 466.742f, 243.496f, 468.379f, 245.246f, 468.75f,
+247.605f, 469.754f, 371.293f, 549.508f, 414.25f, 540.75f, 414.25f, 540.75f, 384.688f, 549.004f,
+245.246f, 466.746f, 10, 0.11f, 0, 0, 0, 0, 0, 0,
+5, 245.246f, 466.746f, 245.246f, 466.742f, 243.496f, 468.379f, 245.246f, 468.75f, 247.605f,
+469.754f, 371.293f, 549.508f, 414.25f, 540.75f, 414.25f, 540.75f, 384.688f, 549.004f, 245.246f,
+466.746f, 10, 0, 1, 1, 1, 1, 1, 1, 5,
+222.246f, 460.746f, 222.246f, 460.742f, 221.512f, 458.594f, 223.246f, 459.75f, 233.266f, 465.301f,
+237.242f, 528.234f, 285.25f, 529.75f, 285.25f, 529.75f, 249.523f, 545.801f, 222.246f, 460.746f,
+10, 0.11f, 0, 0, 0, 0, 0, 0, 5, 222.246f,
+460.746f, 222.246f, 460.742f, 221.512f, 458.594f, 223.246f, 459.75f, 233.266f, 465.301f, 237.242f,
+528.234f, 285.25f, 529.75f, 285.25f, 529.75f, 249.523f, 545.801f, 222.246f, 460.746f, 10,
+0, 1, 1, 1, 1, 1, 1, 5, 200.246f, 447.746f,
+200.246f, 447.746f, 198.973f, 446.812f, 201.246f, 446.75f, 212.391f, 448.555f, 235.937f, 493.953f,
+285.25f, 488.746f, 285.25f, 488.742f, 249.656f, 504.148f, 200.246f, 447.746f, 10, 0.11f,
+0, 0, 0, 0, 0, 0, 5, 200.246f, 447.746f, 200.246f,
+447.746f, 198.973f, 446.812f, 201.246f, 446.75f, 212.391f, 448.555f, 235.937f, 493.953f, 285.25f,
+488.746f, 285.25f, 488.742f, 249.656f, 504.148f, 200.246f, 447.746f, 10, 0, 1,
+1, 1, 1, 1, 1, 5, 212.246f, 454.75f, 212.246f, 454.75f,
+211.625f, 453.348f, 213.246f, 453.746f, 224.461f, 457.637f, 238.852f, 506.711f, 288.246f, 510.746f,
+288.246f, 510.742f, 250.363f, 519.348f, 212.246f, 454.75f, 10, 0.11f, 0, 0,
+0, 0, 0, 0, 5, 212.246f, 454.75f, 212.246f, 454.75f, 211.625f,
+453.348f, 213.246f, 453.746f, 224.461f, 457.637f, 238.852f, 506.711f, 288.246f, 510.746f, 288.246f,
+510.742f, 250.363f, 519.348f, 212.246f, 454.75f, 10, 0, 1, 1, 1,
+1, 1, 1, 5, 192.25f, 442.746f, 192.25f, 442.742f, 191.453f, 441.449f,
+193.25f, 441.75f, 202.32f, 442.863f, 221.395f, 479.633f, 261.25f, 474.75f, 261.25f, 474.75f,
+232.508f, 487.891f, 192.25f, 442.746f, 10, 0.11f, 0, 0, 0, 0,
+0, 0, 5, 192.25f, 442.746f, 192.25f, 442.742f, 191.453f, 441.449f, 193.25f,
+441.75f, 202.32f, 442.863f, 221.395f, 479.633f, 261.25f, 474.75f, 261.25f, 474.75f, 232.508f,
+487.891f, 192.25f, 442.746f, 10, 0, 1, 1, 1, 1, 1,
+1, 5, 184.25f, 435.75f, 184.25f, 435.75f, 182.949f, 434.945f, 184.25f, 434.746f,
+189.281f, 435.414f, 222.984f, 471.801f, 243.246f, 454.75f, 243.246f, 454.75f, 230.082f, 475.344f,
+184.25f, 435.75f, 10, 0.11f, 0, 0, 0, 0, 0, 0,
+5, 184.25f, 435.75f, 184.25f, 435.75f, 182.949f, 434.945f, 184.25f, 434.746f, 189.281f,
+435.414f, 222.984f, 471.801f, 243.246f, 454.75f, 243.246f, 454.75f, 230.082f, 475.344f, 184.25f,
+435.75f, 10, 0, 1, 1, 1, 1, 1, 1, 5,
+260.25f, 470.75f, 260.25f, 470.75f, 259.219f, 472.699f, 261.25f, 472.75f, 263.469f, 473.547f,
+396.242f, 537.031f, 438.25f, 522.746f, 438.25f, 522.746f, 409.465f, 534.84f, 260.25f, 470.75f,
+10, 0.11f, 0, 0, 0, 0, 0, 0, 5, 260.25f,
+470.75f, 260.25f, 470.75f, 259.219f, 472.699f, 261.25f, 472.75f, 263.469f, 473.547f, 396.242f,
+537.031f, 438.25f, 522.746f, 438.25f, 522.746f, 409.465f, 534.84f, 260.25f, 470.75f, 10,
+0, 1, 1, 1, 1, 1, 1, 5, 223.246f, 400.75f,
+223.246f, 400.75f, 223.52f, 402.457f, 225.25f, 401.746f, 227.477f, 400.695f, 244.418f, 400.035f,
+231.246f, 375.75f, 231.246f, 375.75f, 241.34f, 401.797f, 223.246f, 400.75f, 10, 0.11f,
+0, 0, 0, 0, 0, 0, 5, 223.246f, 400.75f, 223.246f,
+400.75f, 223.52f, 402.457f, 225.25f, 401.746f, 227.477f, 400.695f, 244.418f, 400.035f, 231.246f,
+375.75f, 231.246f, 375.75f, 241.34f, 401.797f, 223.246f, 400.75f, 10, 0, 1,
+1, 1, 1, 1, 1, 5, 235.246f, 401.746f, 235.242f, 401.746f,
+234.957f, 404.219f, 237.25f, 403.746f, 238.918f, 402.457f, 258.5f, 400.035f, 260.25f, 357.746f,
+260.25f, 357.746f, 252.777f, 403.559f, 235.246f, 401.746f, 10, 0.11f, 0, 0,
+0, 0, 0, 0, 5, 235.246f, 401.746f, 235.242f, 401.746f, 234.957f,
+404.219f, 237.25f, 403.746f, 238.918f, 402.457f, 258.5f, 400.035f, 260.25f, 357.746f, 260.25f,
+357.746f, 252.777f, 403.559f, 235.246f, 401.746f, 10, 0, 1, 1, 1,
+1, 1, 1, 5, 242.246f, 403.746f, 242.246f, 403.746f, 242.437f, 405.977f,
+244.246f, 404.75f, 246.398f, 404.219f, 273.457f, 400.477f, 299.246f, 364.75f, 299.246f, 364.75f,
+260.258f, 405.316f, 242.246f, 403.746f, 10, 0.11f, 0, 0, 0, 0,
+0, 0, 5, 242.246f, 403.746f, 242.246f, 403.746f, 242.437f, 405.977f, 244.246f,
+404.75f, 246.398f, 404.219f, 273.457f, 400.477f, 299.246f, 364.75f, 299.246f, 364.75f, 260.258f,
+405.316f, 242.246f, 403.746f, 10, 0, 1, 1, 1, 1, 1,
+1, 5, 251.25f, 405.746f, 251.25f, 405.742f, 250.566f, 408.164f, 252.25f, 407.746f,
+254.723f, 406.945f, 277.199f, 409.031f, 319.25f, 371.75f, 319.25f, 371.75f, 268.316f, 409.875f,
+251.25f, 405.746f, 10, 0.11f, 0, 0, 0, 0, 0, 0,
+5, 251.25f, 405.746f, 251.25f, 405.742f, 250.566f, 408.164f, 252.25f, 407.746f, 254.723f,
+406.945f, 277.199f, 409.031f, 319.25f, 371.75f, 319.25f, 371.75f, 268.316f, 409.875f, 251.25f,
+405.746f, 10, 0, 1, 1, 1, 1, 1, 1, 5,
+262.25f, 410.75f, 262.25f, 410.75f, 262.004f, 413.004f, 264.246f, 412.746f, 266.164f, 411.785f,
+304.48f, 406.832f, 361.25f, 368.746f, 361.25f, 368.746f, 279.754f, 414.715f, 262.25f, 410.75f,
+10, 0.11f, 0, 0, 0, 0, 0, 0, 5, 262.25f,
+410.75f, 262.25f, 410.75f, 262.004f, 413.004f, 264.246f, 412.746f, 266.164f, 411.785f, 304.48f,
+406.832f, 361.25f, 368.746f, 361.25f, 368.746f, 279.754f, 414.715f, 262.25f, 410.75f, 10,
+0, 1, 1, 1, 1, 1, 1, 5, 218.25f, 423.746f,
+218.25f, 423.746f, 217.797f, 425.777f, 220.246f, 424.75f, 221.758f, 424.016f, 280.5f, 421.156f,
+314.25f, 391.75f, 314.25f, 391.75f, 275.547f, 418.93f, 218.25f, 423.746f, 10, 0.11f,
+0, 0, 0, 0, 0, 0, 5, 218.25f, 423.746f, 218.25f,
+423.746f, 217.797f, 425.777f, 220.246f, 424.75f, 221.758f, 424.016f, 280.5f, 421.156f, 314.25f,
+391.75f, 314.25f, 391.75f, 275.547f, 418.93f, 218.25f, 423.746f, 10, 0, 1,
+1, 1, 1, 1, 1, 5, 207.25f, 419.75f, 207.25f, 419.75f,
+206.797f, 421.379f, 209.246f, 420.746f, 210.758f, 419.617f, 237.816f, 415.879f, 264.246f, 379.746f,
+264.246f, 379.746f, 224.617f, 420.719f, 207.25f, 419.75f, 10, 0.11f, 0, 0,
+0, 0, 0, 0, 5, 207.25f, 419.75f, 207.25f, 419.75f, 206.797f,
+421.379f, 209.246f, 420.746f, 210.758f, 419.617f, 237.816f, 415.879f, 264.246f, 379.746f, 264.246f,
+379.746f, 224.617f, 420.719f, 207.25f, 419.75f, 10, 0, 1, 1, 1,
+1, 1, 1, 5, 274.25f, 415.75f, 274.25f, 415.75f, 273.828f, 418.031f,
+276.246f, 417.75f, 278.066f, 417.125f, 316.645f, 414.992f, 376.246f, 380.75f, 376.246f, 380.75f,
+290.746f, 418.625f, 274.25f, 415.75f, 10, 0.11f, 0, 0, 0, 0,
+0, 0, 5, 274.25f, 415.75f, 274.25f, 415.75f, 273.828f, 418.031f, 276.246f,
+417.75f, 278.066f, 417.125f, 316.645f, 414.992f, 376.246f, 380.75f, 376.246f, 380.75f, 290.746f,
+418.625f, 274.25f, 415.75f, 10, 0, 1, 1, 1, 1, 1,
+1, 5, 283.25f, 418.746f, 283.25f, 418.742f, 283.07f, 420.672f, 285.25f, 419.75f,
+287.309f, 419.762f, 325.883f, 417.633f, 385.25f, 383.746f, 385.25f, 383.742f, 300.648f, 421.703f,
+283.25f, 418.746f, 10, 0.11f, 0, 0, 0, 0, 0, 0,
+5, 283.25f, 418.746f, 283.25f, 418.742f, 283.07f, 420.672f, 285.25f, 419.75f, 287.309f,
+419.762f, 325.883f, 417.633f, 385.25f, 383.746f, 385.25f, 383.742f, 300.648f, 421.703f, 283.25f,
+418.746f, 10, 0, 1, 1, 1, 1, 1, 1, 5,
+294.25f, 424.75f, 294.25f, 424.75f, 293.629f, 426.172f, 296.25f, 425.746f, 297.867f, 425.262f,
+345.242f, 420.492f, 444.246f, 382.75f, 444.246f, 382.75f, 311.207f, 427.203f, 294.25f, 424.75f,
+10, 0.11f, 0, 0, 0, 0, 0, 0, 5, 294.25f,
+424.75f, 294.25f, 424.75f, 293.629f, 426.172f, 296.25f, 425.746f, 297.867f, 425.262f, 345.242f,
+420.492f, 444.246f, 382.75f, 444.246f, 382.75f, 311.207f, 427.203f, 294.25f, 424.75f, 10,
+0, 0, 0, 0, 0, 0, 0, 4, 172.25f, 416.746f,
+172.25f, 416.742f, 177.539f, 417.195f, 176.246f, 415.75f, 174.898f, 413.676f, 172.25f, 414.746f,
+172.25f, 414.746f, 172.25f, 416.746f, 10, 0, 0, 0, 0, 0,
+0, 0, 4, 205.25f, 401.746f, 205.25f, 401.746f, 211.418f, 401.797f, 210.246f,
+399.75f, 208.777f, 398.277f, 206.25f, 398.746f, 206.25f, 398.746f, 205.25f, 401.746f, 10,
+0, 0, 0, 0, 0, 0, 0, 4, 196.25f, 401.746f,
+196.25f, 401.746f, 201.738f, 402.238f, 200.246f, 400.75f, 199.098f, 398.719f, 196.25f, 399.75f,
+196.25f, 399.75f, 196.25f, 401.746f, 10, 0, 0, 0, 0, 0,
+0, 0, 4, 91.25f, 414.746f, 91.25f, 414.746f, 96.6602f, 413.344f, 95.25f,
+411.746f, 93.0156f, 410.879f, 91.25f, 412.746f, 91.25f, 412.746f, 91.25f, 414.746f, 10,
+0, 0, 0, 0, 0, 0, 0, 4, 93.2461f, 425.746f,
+93.2422f, 425.746f, 98.8633f, 423.902f, 97.25f, 422.746f, 95.2148f, 421.441f, 93.2461f, 422.746f,
+93.2461f, 422.746f, 93.2461f, 425.746f, 10, 0, 0, 0, 0, 0,
+0, 0, 4, 85.25f, 429.746f, 85.25f, 429.742f, 90.9414f, 428.742f, 89.2461f,
+427.746f, 87.2969f, 426.281f, 85.25f, 427.746f, 85.25f, 427.746f, 85.25f, 429.746f, 10,
+0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 5, 173.25f, 347.75f,
+173.25f, 347.75f, 171.379f, 347.676f, 167.25f, 345.75f, 164.777f, 345.477f, 152.457f, 341.516f,
+146.25f, 330.746f, 146.25f, 330.742f, 159.938f, 341.078f, 173.25f, 347.75f, 10, 0,
+0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 9, 269.246f, 245.746f, 269.781f,
+245.484f, 269.84f, 245.02f, 270.25f, 244.75f, 270.887f, 244.957f, 272.242f, 244.625f, 272.25f,
+245.746f, 271.172f, 250.063f, 270.211f, 255.492f, 265.246f, 257.746f, 264.961f, 257.789f, 263.375f,
+257.332f, 263.25f, 256.746f, 263.156f, 254.684f, 263.027f, 253.203f, 263.25f, 251.75f, 263.695f,
+250.027f, 266.07f, 250.016f, 267.246f, 251.75f, 268.109f, 249.699f, 268.582f, 247.672f, 269.246f,
+245.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 9,
+257.246f, 240.75f, 258.262f, 239.004f, 258.121f, 236.961f, 259.25f, 236.746f, 260.492f, 236.016f,
+262.527f, 237.09f, 262.25f, 238.746f, 261.188f, 240.539f, 260.758f, 243, 259.25f, 244.75f,
+259.012f, 245.281f, 259.277f, 245.867f, 259.25f, 245.746f, 258.445f, 247.57f, 257.188f, 248.379f,
+255.246f, 247.746f, 254.41f, 245.594f, 255.676f, 243.25f, 257.246f, 241.75f, 257.5f, 241.203f,
+257.316f, 240.793f, 257.246f, 240.75f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 11, 214.25f, 246.746f, 213.758f, 246.684f, 213.719f, 247.191f, 214.25f,
+247.746f, 214.484f, 248.68f, 215.355f, 249.914f, 215.25f, 250.746f, 214.602f, 252.203f, 213.375f,
+252, 212.246f, 251.75f, 211.41f, 250.281f, 211.355f, 248.273f, 210.246f, 246.746f, 210.379f,
+246.355f, 210.438f, 245.723f, 210.246f, 245.746f, 209.43f, 244.832f, 208.945f, 243.152f, 209.246f,
+242.75f, 209.109f, 242.18f, 208.91f, 231.281f, 209.246f, 231.75f, 209.836f, 232.379f, 213.188f,
+243.086f, 213.246f, 243.75f, 213.328f, 244.871f, 214.133f, 245.383f, 214.25f, 246.746f, 10,
+0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 7, 185.25f, 253.75f,
+188.574f, 256.488f, 191.641f, 259.746f, 191.246f, 263.75f, 191.027f, 264.902f, 189.074f, 264.32f,
+189.246f, 263.75f, 187.988f, 259.402f, 185.746f, 256.477f, 183.25f, 253.75f, 180.504f, 251.594f,
+178.457f, 244.617f, 178.246f, 243.75f, 182.266f, 249.84f, 184.746f, 252.859f, 185.25f, 253.75f,
+10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 10, 170.246f,
+260.746f, 171.32f, 260.707f, 170.988f, 261.246f, 171.246f, 261.746f, 172.273f, 263.215f, 173.707f,
+264.586f, 173.25f, 266.746f, 173.73f, 266.805f, 173.313f, 267.145f, 173.25f, 266.746f, 172.641f,
+266.695f, 172.262f, 266.551f, 172.25f, 266.746f, 169.91f, 263.715f, 168.371f, 260.777f, 167.25f,
+257.746f, 166.582f, 257.289f, 165.324f, 252.352f, 165.246f, 251.75f, 165.934f, 252.133f, 167.824f,
+256.734f, 168.25f, 256.746f, 169.445f, 257.613f, 169.457f, 259.391f, 170.246f, 260.746f, 10,
+0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 6, 189.246f, 238.746f,
+189.641f, 239.758f, 191.371f, 241.078f, 191.246f, 241.75f, 191.117f, 243.078f, 191.633f, 244.664f,
+190.246f, 243.75f, 189.246f, 242.867f, 185.453f, 241.383f, 185.25f, 234.746f, 185.129f, 234.363f,
+188.398f, 237.328f, 189.246f, 238.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 19, 205.25f, 257.746f, 205.477f, 258.434f, 206.258f, 257.91f, 207.25f,
+257.746f, 207.473f, 258.609f, 208.148f, 259.223f, 208.25f, 259.746f, 209.535f, 262.301f, 211.48f,
+264.305f, 211.246f, 266.746f, 209.996f, 268.484f, 209.25f, 266.238f, 208.25f, 264.746f, 207.102f,
+266.988f, 206.004f, 264.926f, 204.25f, 264.746f, 204.496f, 264.324f, 204.262f, 264.707f, 204.25f,
+264.746f, 202.887f, 264.195f, 202.137f, 263.004f, 201.246f, 261.746f, 200.852f, 261.996f, 200.406f,
+262.195f, 200.246f, 261.746f, 199.527f, 261.383f, 198.457f, 261.027f, 198.246f, 260.746f, 196.93f,
+257.297f, 193.473f, 254.992f, 191.246f, 246.746f, 191.816f, 245.695f, 196.359f, 254.004f, 197.25f,
+254.75f, 197.816f, 256.086f, 197.945f, 252.945f, 199.246f, 253.75f, 199.406f, 253.707f, 199.609f,
+253.445f, 200.246f, 253.75f, 199.973f, 253.605f, 200.211f, 253.855f, 200.246f, 253.75f, 200.637f,
+254.176f, 200.492f, 254.789f, 200.246f, 254.75f, 202.074f, 256.039f, 201.98f, 257.215f, 203.25f,
+258.746f, 203.344f, 257.711f, 204.508f, 258.5f, 205.25f, 257.746f, 10, 0, 0.8f,
+0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 6, 271.25f, 197.75f, 271.25f, 197.75f,
+278.957f, 220.297f, 274.25f, 232.75f, 274.25f, 232.75f, 286.656f, 208.855f, 281.25f, 196.75f,
+281.25f, 196.75f, 281.156f, 207.977f, 277.246f, 213.746f, 277.246f, 213.746f, 272.359f, 199.398f,
+271.25f, 197.75f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f,
+5, 254.246f, 200.75f, 254.246f, 200.75f, 260.477f, 210.398f, 251.25f, 230.75f, 251.25f,
+230.75f, 250.797f, 208.195f, 243.246f, 195.746f, 243.246f, 195.742f, 258.937f, 218.316f, 254.246f,
+200.75f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 5,
+243.246f, 202.746f, 243.246f, 202.746f, 243.316f, 224.918f, 244.246f, 227.746f, 244.246f, 227.742f,
+239.578f, 209.957f, 228.25f, 199.75f, 228.25f, 199.75f, 244.199f, 212.598f, 243.246f, 202.746f,
+10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 5, 233.246f,
+237.746f, 233.246f, 237.746f, 239.578f, 223.156f, 228.25f, 202.746f, 228.25f, 202.746f, 235.617f,
+216.336f, 230.25f, 223.746f, 230.25f, 223.746f, 233.199f, 227.777f, 233.246f, 237.746f, 10,
+0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 8, 212.246f, 203.746f,
+212.246f, 203.746f, 210.758f, 220.516f, 212.246f, 222.75f, 212.246f, 222.75f, 212.957f, 229.977f,
+212.246f, 230.75f, 212.246f, 230.75f, 216.918f, 237.898f, 217.25f, 229.75f, 217.25f, 229.75f,
+218.68f, 221.176f, 222.246f, 215.746f, 222.246f, 215.746f, 225.719f, 210.176f, 225.25f, 202.746f,
+225.25f, 202.746f, 214.5f, 236.355f, 212.246f, 203.746f, 10, 0, 0.8f, 0.8f,
+0.8f, 0.8f, 0.8f, 0.8f, 5, 208.25f, 233.75f, 208.25f, 233.75f, 200.637f,
+221.836f, 198.246f, 200.75f, 198.246f, 200.75f, 197.117f, 207.758f, 201.246f, 223.746f, 201.246f,
+223.746f, 205.918f, 240.535f, 208.25f, 233.75f, 10, 0, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 0.8f, 6, 184.25f, 211.75f, 184.25f, 211.75f, 189.418f, 217.879f,
+191.246f, 223.746f, 191.242f, 223.746f, 194.918f, 240.758f, 188.246f, 231.75f, 188.246f, 231.75f,
+188.098f, 222.496f, 179.246f, 214.746f, 179.246f, 214.746f, 184.359f, 216.996f, 184.25f, 211.75f,
+10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 6, 177.246f,
+217.746f, 177.246f, 217.742f, 181.277f, 236.578f, 182.25f, 237.746f, 182.25f, 237.746f, 184.137f,
+241.195f, 181.25f, 237.746f, 181.25f, 237.746f, 171.379f, 216.559f, 167.25f, 209.75f, 167.25f,
+209.75f, 175.777f, 219.418f, 177.246f, 217.746f, 10, 0, 0.8f, 0.8f, 0.8f,
+0.8f, 0.8f, 0.8f, 4, 171.246f, 235.746f, 171.246f, 235.746f, 183.918f, 260.336f,
+160.246f, 231.75f, 160.246f, 231.75f, 172.039f, 242.738f, 171.246f, 235.746f, 10, 0,
+0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 6, 154.246f, 251.75f, 154.242f,
+251.75f, 159.5f, 272.438f, 162.25f, 271.746f, 162.25f, 271.746f, 171.379f, 282.117f, 164.246f,
+270.75f, 164.242f, 270.75f, 157.52f, 259.898f, 158.25f, 248.746f, 158.25f, 248.746f, 157.52f,
+259.676f, 154.246f, 251.75f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f,
+0.8f, 5, 517.246f, 264.746f, 517.242f, 264.742f, 504.348f, 275.297f, 501.25f, 278.75f,
+501.25f, 278.75f, 516.449f, 258.797f, 516.25f, 250.746f, 516.25f, 250.742f, 519.199f, 259.348f,
+517.246f, 264.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f,
+5, 523.25f, 288.746f, 523.25f, 288.742f, 500.5f, 305, 496.25f, 312.75f, 496.25f,
+312.75f, 525.797f, 280.797f, 526.246f, 275.746f, 526.242f, 275.742f, 526.348f, 285.75f, 523.25f,
+288.746f, 10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 5,
+542.246f, 457.75f, 542.246f, 457.75f, 529.098f, 466.699f, 527.25f, 464.746f, 527.25f, 464.742f,
+539, 457.348f, 542.246f, 447.746f, 542.246f, 447.746f, 540.098f, 457.898f, 542.246f, 457.75f,
+10, 0, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 4, 551.25f,
+369.75f, 532.25f, 382.75f, 532.25f, 382.75f, 553.297f, 363.848f, 554.25f, 359.746f, 551.25f,
+369.75f, 10, 1.1f, 0, 0, 0, 0, 0, 0, 2,
+122.246f, 393.75f, 146.25f, 388.75f, 10, 1.1f, 0, 0, 0, 0,
+0, 0, 2, 177.246f, 215.746f, 177.246f, 215.746f, 176.547f, 219.75f, 166.246f,
+207.75f, 10, 1.1f, 0, 0, 0, 0, 0, 0, 2,
+183.25f, 210.75f, 183.25f, 210.75f, 185.348f, 217.547f, 178.246f, 212.746f, 10, 1.1f,
+0, 0, 0, 0, 0, 0, 2, 242.246f, 200.75f, 242.246f,
+200.75f, 244.199f, 213.148f, 231.246f, 198.75f};
+
diff --git a/samples/tiger/tiger.h b/samples/tiger/tiger.h
new file mode 100644
index 0000000..ffbf6ac
--- /dev/null
+++ b/samples/tiger/tiger.h
@@ -0,0 +1,45 @@
+#ifndef __TIGER_H
+#define __TIGER_H
+
+/*------------------------------------------------------------------------
+ *
+ * OpenVG 1.0.1 Reference Implementation sample code
+ * -------------------------------------------------
+ *
+ * Copyright (c) 2007 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and /or associated documentation files
+ * (the "Materials "), to deal in the Materials without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Materials,
+ * and to permit persons to whom the Materials are furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
+ * THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//**
+ * \file
+ * \brief Header for including the Tiger image data.
+ * \note
+ *//*-------------------------------------------------------------------*/
+
+extern const int tigerCommandCount;
+extern const char tigerCommands[];
+extern const float tigerMinX;
+extern const float tigerMaxX;
+extern const float tigerMinY;
+extern const float tigerMaxY;
+extern const int tigerPointCount;
+extern const float tigerPoints[];
+
+#endif /* __TIGER_H */