diff --git a/.github/workflows/bleeding-edge.yml b/.github/workflows/bleeding-edge.yml
index def91f6b7..4c801c754 100644
--- a/.github/workflows/bleeding-edge.yml
+++ b/.github/workflows/bleeding-edge.yml
@@ -34,8 +34,6 @@ jobs:
if: matrix.toolkit != 'wx' && matrix.toolkit != 'null'
- name: Install dependencies for Linux
run: |
- # needed for GL
- sudo apt-get install libglu1-mesa-dev
# needed for Celiagg
sudo apt-get install libfreetype-dev libharfbuzz-dev
# needed for Cairo
@@ -49,7 +47,7 @@ jobs:
run: |
python -m pip install --upgrade pip wheel
- name: Install local packages
- run: pip install ".[cairo,gl,layout,pdf,svg,test,${{ matrix.toolkit }}]"
+ run: pip install ".[cairo,layout,pdf,svg,test,${{ matrix.toolkit }}]"
- name: Install source dependencies
run: |
python -m pip install git+https://github.com/enthought/traits.git
diff --git a/.github/workflows/test-with-edm.yml b/.github/workflows/test-with-edm.yml
index d9bc87da3..c180e64c1 100644
--- a/.github/workflows/test-with-edm.yml
+++ b/.github/workflows/test-with-edm.yml
@@ -23,8 +23,6 @@ jobs:
- name: Install Qt dependencies
uses: ./.github/actions/install-qt-support
if: matrix.toolkit != 'wx'
- - name: Install GL dependencies for Linux
- run: sudo apt-get install libglu1-mesa-dev
- name: Cache EDM packages
uses: actions/cache@v2
with:
diff --git a/.github/workflows/test-with-pip.yml b/.github/workflows/test-with-pip.yml
index a343b8cb7..13c39354b 100644
--- a/.github/workflows/test-with-pip.yml
+++ b/.github/workflows/test-with-pip.yml
@@ -40,8 +40,6 @@ jobs:
if: matrix.toolkit != 'wx' && matrix.toolkit != 'null'
- name: Install dependencies for Linux
run: |
- # needed for GL
- sudo apt-get install libglu1-mesa-dev
# needed for Celiagg
sudo apt-get install libfreetype-dev libharfbuzz-dev
# needed for Cairo
@@ -55,7 +53,7 @@ jobs:
run: |
python -m pip install --upgrade pip wheel
- name: Install local packages
- run: pip install ".[cairo,gl,layout,pdf,svg,test,${{ matrix.toolkit }}]"
+ run: pip install ".[cairo,layout,pdf,svg,test,${{ matrix.toolkit }}]"
- name: Install celiagg manually
# This is needed until new release of celiagg
# - numpy is needed for install in current released version
diff --git a/.gitignore b/.gitignore
index 1ccf897c2..e5e0ddf9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,8 +26,6 @@ kiva/agg/src/gtk1/plat_support_wrap.cpp
kiva/agg/src/osx/plat_support_wrap.cpp
kiva/agg/src/win32/plat_support_wrap.cpp
kiva/agg/src/x11/plat_support_wrap.cpp
-kiva/gl/gl.py
-kiva/gl/gl_wrap.cpp
kiva/quartz/ABCGI.c
kiva/quartz/CTFont.c
diff --git a/README.rst b/README.rst
index 7744a2b94..f908207e3 100644
--- a/README.rst
+++ b/README.rst
@@ -71,7 +71,6 @@ the Enable/Kiva project:
- `SWIG `_
- `fonttools `_
- (on Linux) X11-devel (development tools for X11)
-- (on Linux) libglu1-mesa-dev (OpenGL utility library for development)
- (on Mac OS X) `Cython `_
Enable/Kiva also have the following requirements:
@@ -89,8 +88,6 @@ Enable/Kiva also have the following requirements:
- `apptools `_
- (Qt backend) `PySide `_ or `PyQt4 `_
- (WX backend) `WxPython `_
-- (GL backend) `pyglet `_
-- (GL backend) `pygarrayimage `_
- (SVG backend) `PyParsing `_
- (PDF backend) `ReportLab Toolkit `_
- (Cairo backend) `PyCairo `_
diff --git a/ci/edmtool.py b/ci/edmtool.py
index ceff9c4d3..edfb2920d 100644
--- a/ci/edmtool.py
+++ b/ci/edmtool.py
@@ -287,7 +287,6 @@ def docs(runtime, toolkit, environment):
"kiva/qpainter.py",
"kiva/svg.py",
"kiva/agg",
- "kiva/gl",
"kiva/quartz",
"*/tests",
])
diff --git a/ci/requirements_3.8.txt b/ci/requirements_3.8.txt
index bde71b04e..2a49d052f 100644
--- a/ci/requirements_3.8.txt
+++ b/ci/requirements_3.8.txt
@@ -1,4 +1,2 @@
-pygarrayimage
-pyglet<2.0
pypdf2<3.0
reportlab
diff --git a/docs/source/enable/overview.rst b/docs/source/enable/overview.rst
index 21e78d139..f9960ce2c 100644
--- a/docs/source/enable/overview.rst
+++ b/docs/source/enable/overview.rst
@@ -260,8 +260,7 @@ Backbuffer
A backbuffer provides the ability to render into an offscreen buffer, which is
blitted on every draw, until it is invalidated. Various traits such as
:attr:`use_backbuffer` and :attr:`backbuffer_padding` control the behavior of
-the backbuffer. A backbuffer is used for non-OpenGL backends, such as `agg`
-and on OS X. If :attr:`use_backbuffer` is False, a backbuffer is never used,
+the backbuffer. If :attr:`use_backbuffer` is False, a backbuffer is never used,
even if a backbuffer is referenced by a component.
Users typically subclass Chaco :class:`PlotComponent`, but may need features
diff --git a/docs/source/kiva/overview.rst b/docs/source/kiva/overview.rst
index f285a72a0..1e4220b8e 100644
--- a/docs/source/kiva/overview.rst
+++ b/docs/source/kiva/overview.rst
@@ -8,10 +8,9 @@ Kiva is a 2D vector drawing interface providing functionality similar to
`Quartz `_,
`Cairo `_, the
`Qt QPainter interface `_,
-the 2D drawing routines of `OpenGL `_ , the HTML5
-Canvas element and many other similar 2D vector drawing APIs. Rather than
-re-implementing everything, Kiva is a Python interface layer that sits on top
-of many different back-ends, some of which are in fact provided by some of
+the HTML5 Canvas element and many other similar 2D vector drawing APIs. Rather
+than re-implementing everything, Kiva is a Python interface layer that sits on
+top of many different back-ends, some of which are in fact provided by some of
these libraries. Which back-ends are available depends on the platform, GUI
toolkit, and capabilities of the system. For example the Quartz backend is only
available on Mac OS systems, while the QPainter backend is available if PyQt
@@ -410,9 +409,6 @@ celiagg
kiva/enable. It is planned that this will become the default image backend
in a future release.
-gl
- OpenGL drawing. This backend is quite limited compared to others.
-
qpainter
Qt ``QPainter`` drawing. This is only availble with the Qt toolkit.
diff --git a/enable/__init__.py b/enable/__init__.py
index 0722a979b..07c6e49e0 100644
--- a/enable/__init__.py
+++ b/enable/__init__.py
@@ -23,9 +23,7 @@
# Dependencies for documentation
"docs": ["enthought-sphinx-theme", "sphinx", "sphinx-copybutton"],
# Dependencies for running enable/kiva's examples
- "examples": ["chaco", "mayavi", "scipy", "kiwisolver", "pyglet"],
- # Dependencies for GL backend support
- "gl": ["pygarrayimage", "pyglet<2.0"],
+ "examples": ["chaco", "mayavi", "scipy", "kiwisolver"],
# Dependencies for constrained layout
"layout": ["kiwisolver"],
# Dependencies for PDF backend
diff --git a/enable/component.py b/enable/component.py
index 768789e5c..d1826a8c2 100644
--- a/enable/component.py
+++ b/enable/component.py
@@ -729,11 +729,7 @@ def _draw(self, gc, view_bounds=None, mode="default"):
self.drawn_outer_position = list(self.outer_position[:])
self.drawn_outer_bounds = list(self.outer_bounds[:])
- # OpenGL-based graphics-contexts have a `gl_init()` method. We
- # test for this to avoid having to import the OpenGL
- # GraphicsContext just to do an isinstance() check.
- is_gl = hasattr(gc, "gl_init")
- if self.use_backbuffer and (not is_gl):
+ if self.use_backbuffer:
if self.backbuffer_padding:
x, y = self.outer_position
width, height = self.outer_bounds
diff --git a/enable/gcbench/bench.py b/enable/gcbench/bench.py
index a31025cb5..b628335ba 100644
--- a/enable/gcbench/bench.py
+++ b/enable/gcbench/bench.py
@@ -25,7 +25,6 @@
"blend2d": "enable.null.blend2d",
"cairo": "enable.null.cairo",
"celiagg": "enable.null.celiagg",
- "opengl": "enable.gcbench.opengl",
"qpainter": "enable.null.qpainter",
"quartz": "enable.null.quartz",
},
diff --git a/enable/gcbench/opengl.py b/enable/gcbench/opengl.py
deleted file mode 100644
index db0dc2a3d..000000000
--- a/enable/gcbench/opengl.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# (C) Copyright 2005-2022 Enthought, Inc., Austin, TX
-# All rights reserved.
-#
-# This software is provided without warranty under the terms of the BSD
-# license included in LICENSE.txt and may be redistributed only under
-# the conditions described in the aforementioned license. The license
-# is also available online at http://www.enthought.com/licenses/BSD.txt
-#
-# Thanks for using Enthought open source!
-import pyglet
-from pyglet.image.codecs.png import PNGImageEncoder
-
-import kiva.gl as gl_backend
-
-# Pass it along
-CompiledPath = gl_backend.CompiledPath
-
-
-class GraphicsContext(gl_backend.GraphicsContext):
- """ This is a wrapper of the GL GraphicsContext which works in headless
- mode.
- """
- def __init__(self, size, *args, **kw):
- width, height = size
- self.__window = pyglet.window.Window(width=width, height=height)
- super().__init__((width, height), base_pixel_scale=1.0)
- self.gl_init()
-
- def clear(self, *args):
- self.__window.clear()
-
- def save(self, filename, *args, **kw):
- buffer = pyglet.image.get_buffer_manager()
- with open(filename, mode="wb") as fp:
- buffer.get_color_buffer().save(
- filename,
- file=fp,
- encoder=PNGImageEncoder(),
- )
diff --git a/enable/gl_graphics_context.py b/enable/gl_graphics_context.py
deleted file mode 100644
index e0f79241c..000000000
--- a/enable/gl_graphics_context.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# (C) Copyright 2005-2022 Enthought, Inc., Austin, TX
-# All rights reserved.
-#
-# This software is provided without warranty under the terms of the BSD
-# license included in LICENSE.txt and may be redistributed only under
-# the conditions described in the aforementioned license. The license
-# is also available online at http://www.enthought.com/licenses/BSD.txt
-#
-# Thanks for using Enthought open source!
-from kiva.gl import GraphicsContext
-from .graphics_context import GraphicsContextEnable
-
-
-class GLGraphicsContextEnable(GraphicsContextEnable, GraphicsContext):
- """ This class just binds the GraphicsContextEnable to a Kiva
- GL graphics context.
- """
-
- pass
diff --git a/enable/qt4/gl.py b/enable/qt4/gl.py
deleted file mode 100644
index 71c4032db..000000000
--- a/enable/qt4/gl.py
+++ /dev/null
@@ -1,60 +0,0 @@
-# (C) Copyright 2005-2022 Enthought, Inc., Austin, TX
-# All rights reserved.
-#
-# This software is provided without warranty under the terms of the BSD
-# license included in LICENSE.txt and may be redistributed only under
-# the conditions described in the aforementioned license. The license
-# is also available online at http://www.enthought.com/licenses/BSD.txt
-#
-# Thanks for using Enthought open source!
-from enable.qt4.base_window import BaseGLWindow
-from enable.qt4.scrollbar import NativeScrollBar
-from kiva.gl import CompiledPath, FakePygletContext, GraphicsContext
-
-
-class Window(BaseGLWindow):
- def _create_gc(self, size, pix_format=None):
- """ Create a GraphicsContext instance.
- """
- gc = GraphicsContext(
- (size[0] + 1, size[1] + 1),
- base_pixel_scale=self.base_pixel_scale,
- )
- self._fake_pyglet_context = FakePygletContext()
- gc.gl_init()
- gc.translate_ctm(0.5, 0.5)
- return gc
-
- def _init_gc(self):
- """ Gives the GC a chance to initialize itself before components
- perform layout and draw.
-
- This is called every time through the paint loop.
- """
- self.control.makeCurrent()
- self._fake_pyglet_context.set_current()
- super()._init_gc()
-
- def _paint(self, event=None):
- """ Paint the contents of the window.
- """
- if self.control is None:
- return
-
- size = self._get_control_size()
- self._size = tuple(size)
- self._gc = self._create_gc(size)
- self._init_gc()
- if hasattr(self.component, "do_layout"):
- self.component.do_layout()
- self._gc.clear(self.bgcolor_)
- self.component.draw(self._gc, view_bounds=(0, 0, size[0], size[1]))
- self._update_region = []
-
-
-def font_metrics_provider():
- from kiva.api import Font
-
- gc = GraphicsContext((1, 1))
- gc.set_font(Font())
- return gc
diff --git a/enable/wx/gl.py b/enable/wx/gl.py
deleted file mode 100644
index 91ad66bf4..000000000
--- a/enable/wx/gl.py
+++ /dev/null
@@ -1,90 +0,0 @@
-# (C) Copyright 2005-2022 Enthought, Inc., Austin, TX
-# All rights reserved.
-#
-# This software is provided without warranty under the terms of the BSD
-# license included in LICENSE.txt and may be redistributed only under
-# the conditions described in the aforementioned license. The license
-# is also available online at http://www.enthought.com/licenses/BSD.txt
-#
-# Thanks for using Enthought open source!
-import wx
-
-import pyglet
-
-pyglet.options["shadow_window"] = False
-from wx.glcanvas import GLCanvas
-
-from traits.api import Instance
-from kiva.gl import CompiledPath, FakePygletContext, GraphicsContext
-
-from .base_window import BaseWindow
-from .scrollbar import NativeScrollBar
-
-
-class Window(BaseWindow):
-
- control = Instance(GLCanvas)
-
- def __init__(self, *args, **kw):
- super().__init__(*args, **kw)
-
- # If we are using the GL backend, we will need to have a pyglet
- # GL context
- self._pyglet_gl_context = None
-
- self._gc = None
-
- def _create_control(self, parent, wid, pos=wx.DefaultPosition,
- size=wx.DefaultSize):
- return GLCanvas(
- parent, wid, pos, size, style=wx.CLIP_CHILDREN | wx.WANTS_CHARS
- )
-
- def _create_gc(self, size, pix_format=None):
- """ Create a GraphicsContext instance.
- """
- gc = GraphicsContext(
- (size[0] + 1, size[1] + 1),
- base_pixel_scale=self.base_pixel_scale,
- )
- if self._pyglet_gl_context is None:
- self._pyglet_gl_context = FakePygletContext()
- gc.gl_init()
- gc.translate_ctm(0.5, 0.5)
- return gc
-
- def _init_gc(self):
- """ Gives the GC a chance to initialize itself before components
- perform layout and draw. This is called every time through the paint
- loop.
- """
- dc = wx.PaintDC(self.control)
- self._pyglet_gl_context.set_current()
- self.control.SetCurrent()
- super()._init_gc()
-
- def _paint(self, event=None):
- """ Paint the contents of the window.
- """
- if self.control is None:
- event.Skip()
- return
-
- size = self._get_control_size()
- self._size = tuple(size)
- self._gc = self._create_gc(size)
- self._init_gc()
- if hasattr(self.component, "do_layout"):
- self.component.do_layout()
- self._gc.clear(self.bgcolor_)
- self.component.draw(self._gc, view_bounds=(0, 0, size[0], size[1]))
- self._update_region = []
- self.control.SwapBuffers()
-
-
-def font_metrics_provider():
- from kiva.api import Font
-
- gc = GraphicsContext((1, 1))
- gc.set_font(Font())
- return gc
diff --git a/kiva/basecore2d.py b/kiva/basecore2d.py
index 1de3ed4a6..9181f1c77 100644
--- a/kiva/basecore2d.py
+++ b/kiva/basecore2d.py
@@ -22,9 +22,8 @@
treat any alpha value greater than 0 as fully opaque.
transform
currently a 3x3 array. This is not the
- most convenient in some backends. Mac and OpenGL
- use a 1-D 6 element array. We need to either make
- transform a class or always use accessor functions
+ most convenient in some backends. Quartz uses a 1-D 6 element array.
+ We need to either make transform a class or always use accessor functions
to access its values. Currently, I do the latter.
"""
@@ -134,8 +133,7 @@ def __init__(self, *args, **kwargs):
# We're currently maintaining a couple of copies of the ctm around.
# The state.ctm is used mainly for user querying, etc. We also have
# something called the device_ctm which is actually used in the
- # drawing of objects. In some implementation (OpenGL), the
- # device_ctm is actually maintained in hardware.
+ # drawing of objects.
# --------------------------------------------------------------------
self.device_prepare_device_ctm()
@@ -1204,9 +1202,8 @@ def device_prepare_device_ctm(self):
def device_transform_device_ctm(self, func, args):
""" Default implementation for handling scaling matrices.
- Many implementations will just use this function. Others, like
- OpenGL, can benefit from overriding the method and using
- hardware acceleration.
+ Many implementations will just use this function. Others can
+ benefit from overriding the method and using hardware acceleration.
"""
if func == SCALE_CTM:
self.device_ctm = affine.scale(self.device_ctm, args[0], args[1])
@@ -1227,7 +1224,7 @@ def device_draw_rect(self, x, y, sx, sy, mode):
self._new_subpath()
# When rectangles are rotated, they have to be drawn as a polygon
# on most devices. We'll need to specialize this on API's that
- # can handle rotated rects such as Quartz and OpenGL(?).
+ # can handle rotated rects such as Quartz.
# All transformations are done in the call to lines().
pts = array(
((x, y), (x, y + sy), (x + sx, y + sy), (x + sx, y), (x, y))
diff --git a/kiva/constants.py b/kiva/constants.py
index 7d8dc4bbb..3b9588bf1 100644
--- a/kiva/constants.py
+++ b/kiva/constants.py
@@ -115,8 +115,6 @@
# -----------------------------------------------------------------------------
# Subpath CTM Constants
#
-# These are added so its possible for OpenGL to do the matrix transformations
-# on the data (its much faster than doing it with Numeric).
# -----------------------------------------------------------------------------
SCALE_CTM = 5
diff --git a/kiva/examples/kiva/pyglet_gl.py b/kiva/examples/kiva/pyglet_gl.py
deleted file mode 100644
index 3fad3cd10..000000000
--- a/kiva/examples/kiva/pyglet_gl.py
+++ /dev/null
@@ -1,64 +0,0 @@
-# (C) Copyright 2005-2022 Enthought, Inc., Austin, TX
-# All rights reserved.
-#
-# This software is provided without warranty under the terms of the BSD
-# license included in LICENSE.txt and may be redistributed only under
-# the conditions described in the aforementioned license. The license
-# is also available online at http://www.enthought.com/licenses/BSD.txt
-#
-# Thanks for using Enthought open source!
-from numpy import array
-from pyglet.window import key, Window
-
-from kiva.api import STROKE
-
-try:
- from kiva.gl import GraphicsContext
-except ImportError as e:
- raise Exception(e)
-
-
-class TestWindow(Window):
- """ Press Q or Escape to exit
- """
-
- def __init__(self, *args, **kw):
- Window.__init__(self, *args, **kw)
- self.init_window()
-
- def init_window(self):
- self.gc = GraphicsContext(size=(self.width, self.height))
- self.gc.gl_init()
-
- def on_key_press(self, symbol, modifiers):
- if symbol in (key.ESCAPE, key.Q):
- self.has_exit = True
-
- def draw(self):
- gc = self.gc
- with gc:
- gc.clear((0, 1, 0, 1))
- gc.set_stroke_color((1, 1, 1, 1))
- gc.set_line_width(2)
- pts = array([[50, 50], [50, 100], [100, 100], [100, 50]])
- gc.begin_path()
- gc.lines(pts)
- gc.close_path()
- gc.draw_path(STROKE)
- gc.flush()
-
-
-def main():
- win = TestWindow(width=640, height=480)
- exit = False
- while not exit:
- win.switch_to()
- win.dispatch_events()
- win.clear()
- win.draw()
- win.flip()
- exit = win.has_exit
-
-
-if __name__ == "__main__":
- main()
diff --git a/kiva/gl/LICENSES/LICENSE_Agg b/kiva/gl/LICENSES/LICENSE_Agg
deleted file mode 100644
index f17681401..000000000
--- a/kiva/gl/LICENSES/LICENSE_Agg
+++ /dev/null
@@ -1,65 +0,0 @@
-The Anti-Grain Geometry Project
-A high quality rendering engine for C++
-http://antigrain.com
-
-Anti-Grain Geometry has dual licensing model. The Modified BSD
-License was first added in version v2.4 just for convenience.
-It is a simple, permissive non-copyleft free software license,
-compatible with the GNU GPL. It's well proven and recognizable.
-See http://www.fsf.org/licensing/licenses/index_html#ModifiedBSD
-for details.
-
-Note that the Modified BSD license DOES NOT restrict your rights
-if you choose the Anti-Grain Geometry Public License.
-
-
-
-
-Anti-Grain Geometry Public License
-====================================================
-
-Anti-Grain Geometry - Version 2.4
-Copyright (C) 2002-2005 Maxim Shemanarev (McSeem)
-
-Permission to copy, use, modify, sell and distribute this software
-is granted provided this copyright notice appears in all copies.
-This software is provided "as is" without express or implied
-warranty, and with no claim as to its suitability for any purpose.
-
-
-
-
-
-Modified BSD License
-====================================================
-Anti-Grain Geometry - Version 2.4
-Copyright (C) 2002-2005 Maxim Shemanarev (McSeem)
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-
- 3. The name of the author may not be used to endorse or promote
- products derived from this software without specific prior
- written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
-IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
diff --git a/kiva/gl/LICENSES/LICENSE_Matplotlib b/kiva/gl/LICENSES/LICENSE_Matplotlib
deleted file mode 100644
index ec51537db..000000000
--- a/kiva/gl/LICENSES/LICENSE_Matplotlib
+++ /dev/null
@@ -1,99 +0,0 @@
-License agreement for matplotlib versions 1.3.0 and later
-=========================================================
-
-1. This LICENSE AGREEMENT is between the Matplotlib Development Team
-("MDT"), and the Individual or Organization ("Licensee") accessing and
-otherwise using matplotlib software in source or binary form and its
-associated documentation.
-
-2. Subject to the terms and conditions of this License Agreement, MDT
-hereby grants Licensee a nonexclusive, royalty-free, world-wide license
-to reproduce, analyze, test, perform and/or display publicly, prepare
-derivative works, distribute, and otherwise use matplotlib
-alone or in any derivative version, provided, however, that MDT's
-License Agreement and MDT's notice of copyright, i.e., "Copyright (c)
-2012- Matplotlib Development Team; All Rights Reserved" are retained in
-matplotlib alone or in any derivative version prepared by
-Licensee.
-
-3. In the event Licensee prepares a derivative work that is based on or
-incorporates matplotlib or any part thereof, and wants to
-make the derivative work available to others as provided herein, then
-Licensee hereby agrees to include in any such work a brief summary of
-the changes made to matplotlib .
-
-4. MDT is making matplotlib available to Licensee on an "AS
-IS" basis. MDT MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
-IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, MDT MAKES NO AND
-DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
-FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB
-WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
-
-5. MDT SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
- FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
-LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
-MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
-THE POSSIBILITY THEREOF.
-
-6. This License Agreement will automatically terminate upon a material
-breach of its terms and conditions.
-
-7. Nothing in this License Agreement shall be deemed to create any
-relationship of agency, partnership, or joint venture between MDT and
-Licensee. This License Agreement does not grant permission to use MDT
-trademarks or trade name in a trademark sense to endorse or promote
-products or services of Licensee, or any third party.
-
-8. By copying, installing or otherwise using matplotlib ,
-Licensee agrees to be bound by the terms and conditions of this License
-Agreement.
-
-License agreement for matplotlib versions prior to 1.3.0
-========================================================
-
-1. This LICENSE AGREEMENT is between John D. Hunter ("JDH"), and the
-Individual or Organization ("Licensee") accessing and otherwise using
-matplotlib software in source or binary form and its associated
-documentation.
-
-2. Subject to the terms and conditions of this License Agreement, JDH
-hereby grants Licensee a nonexclusive, royalty-free, world-wide license
-to reproduce, analyze, test, perform and/or display publicly, prepare
-derivative works, distribute, and otherwise use matplotlib
-alone or in any derivative version, provided, however, that JDH's
-License Agreement and JDH's notice of copyright, i.e., "Copyright (c)
-2002-2011 John D. Hunter; All Rights Reserved" are retained in
-matplotlib alone or in any derivative version prepared by
-Licensee.
-
-3. In the event Licensee prepares a derivative work that is based on or
-incorporates matplotlib or any part thereof, and wants to
-make the derivative work available to others as provided herein, then
-Licensee hereby agrees to include in any such work a brief summary of
-the changes made to matplotlib.
-
-4. JDH is making matplotlib available to Licensee on an "AS
-IS" basis. JDH MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
-IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, JDH MAKES NO AND
-DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
-FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB
-WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
-
-5. JDH SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
- FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
-LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
-MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
-THE POSSIBILITY THEREOF.
-
-6. This License Agreement will automatically terminate upon a material
-breach of its terms and conditions.
-
-7. Nothing in this License Agreement shall be deemed to create any
-relationship of agency, partnership, or joint venture between JDH and
-Licensee. This License Agreement does not grant permission to use JDH
-trademarks or trade name in a trademark sense to endorse or promote
-products or services of Licensee, or any third party.
-
-8. By copying, installing or otherwise using matplotlib,
-Licensee agrees to be bound by the terms and conditions of this License
-Agreement.
\ No newline at end of file
diff --git a/kiva/gl/__init__.py b/kiva/gl/__init__.py
deleted file mode 100644
index 985e52ee4..000000000
--- a/kiva/gl/__init__.py
+++ /dev/null
@@ -1,584 +0,0 @@
-# (C) Copyright 2005-2022 Enthought, Inc., Austin, TX
-# All rights reserved.
-#
-# This software is provided without warranty under the terms of the BSD
-# license included in LICENSE.txt and may be redistributed only under
-# the conditions described in the aforementioned license. The license
-# is also available online at http://www.enthought.com/licenses/BSD.txt
-#
-# Thanks for using Enthought open source!
-import ctypes
-import logging
-from math import floor
-import sys
-
-from numpy import array, ndarray
-
-# Local kiva imports
-from kiva.affine import affine_from_values, transform_points
-from kiva.constants import BOLD, bold_styles, italic_styles
-from kiva.fonttools import Font
-from kiva.gl.gl import CompiledPath, GraphicsContextGL, KivaGLFontType
-
-
-logger = logging.getLogger(__name__)
-
-
-def image_as_array(img):
- """ Adapt an image object into a numpy array.
-
- Typically, this is used to adapt an agg GraphicsContextArray which has been
- used for image storage in Kiva applications.
- """
- from PIL import Image
-
- if hasattr(img, "bmp_array"):
- # Yup, a GraphicsContextArray.
- img = Image.fromarray(img.bmp_array)
- elif isinstance(img, ndarray):
- img = Image.fromarray(img)
- elif isinstance(img, Image.Image):
- pass
- else:
- msg = "can't convert %r into a numpy array" % (img,)
- raise NotImplementedError(msg)
-
- # Ensure RGB or RGBA formats
- if not img.mode.startswith("RGB"):
- img = img.convert("RGB")
- return array(img)
-
-
-def get_dpi():
- """ Returns the appropriate DPI setting for the system"""
- pass
-
-
-class MRU(dict):
- def __init__(self, *args, **kw):
- # An ordering of keys in self; the last item was the most recently used
- self.__order__ = []
- self.__maxlength__ = 30
- dict.__init__(self, *args, **kw)
-
- def __getitem__(self, key):
- val = dict.__getitem__(self, key)
- # If we get here, then key was found in our dict
- self.__touch__(key)
- return val
-
- def __setitem__(self, key, value):
- dict.__setitem__(self, key, value)
- self.__touch__(key)
-
- def __delitem__(self, key):
- dict.__delitem__(self, key)
- if key in self.__order__:
- self.__order__.remove(key)
-
- def __touch__(self, key):
- """ Puts **key** as the most recently used item """
- if len(self.__order__) == 0:
- self.__order__.append(key)
- if (len(self.__order__) == self.__maxlength__ and
- key not in self.__order__):
- # The MRU is full, so pop the oldest element
- del self[self.__order__[0]]
- if key != self.__order__[-1]:
- try:
- ndx = self.__order__.index(key)
- self.__order__[ndx:-1] = self.__order__[ndx + 1:]
- self.__order__[-1] = key
- except ValueError:
- # new key that's not already in the cache
- if len(self.__order__) == self.__maxlength__:
- self.__order__ = self.__order__[1:] + [key]
- else:
- self.__order__.append(key)
-
-
-# Pyglet and pyglet-related imports
-# Before we import anything else from pyglet, we need to set the shadow_window
-# option to False, so that it does not conflict with WX, in case someone is
-# trying to use the kiva GL GraphicsContext from within WX.
-# This is necessary as of pyglet 1.1.
-try:
- import pyglet
-
- pyglet.options["shadow_window"] = False
-
- from pyglet.text import Label
- from pyglet.font import load as load_font
- from pyglet.font.base import Font as PygletFont
- from pyglet import gl
- from pygarrayimage.arrayimage import ArrayInterfaceImage
-
- class _ObjectSpace(object):
- """ Object space mocker
-
- Source: https://github.com/ColinDuquesnoy/QPygletWidget
- """
-
- def __init__(self):
- # Textures and buffers scheduled for deletion the next time this
- # object space is active.
- self._doomed_textures = []
- self._doomed_buffers = []
-
- class FakePygletContext(object):
- """ pyglet.gl.Context mocker.
-
- This is used to make pyglet believe that a valid context has already
- been setup. (Qt takes care of creating the open gl context)
-
- _Most of the methods are empty, there is just the minimum required to
- make it look like a duck..._
-
- Source: https://github.com/ColinDuquesnoy/QPygletWidget
- """
-
- # define the same class attribute as pyglet.gl.Context
- CONTEXT_SHARE_NONE = None
- CONTEXT_SHARE_EXISTING = 1
- _gl_begin = False
- _info = None
- _workaround_checks = [
- (
- "_workaround_unpack_row_length",
- lambda info: info.get_renderer() == "GDI Generic",
- ),
- (
- "_workaround_vbo",
- lambda info: info.get_renderer().startswith("ATI Radeon X"),
- ),
- (
- "_workaround_vbo_finish",
- lambda info: (
- "ATI" in info.get_renderer()
- and info.have_version(1, 5)
- and sys.platform == "darwin"
- ),
- ),
- ]
-
- def __init__(self, context_share=None):
- """ Setup workaround attr and object spaces
- (again to mock what is done in pyglet context)
- """
- self.object_space = _ObjectSpace()
- for attr, check in self._workaround_checks:
- setattr(self, attr, None)
-
- def __repr__(self):
- return "%s()" % self.__class__.__name__
-
- def set_current(self):
- gl.current_context = self
-
- def destroy(self):
- pass
-
- def delete_texture(self, texture_id):
- pass
-
- def delete_buffer(self, buffer_id):
- pass
-
- class ArrayImage(ArrayInterfaceImage):
- """ pyglet ImageData made from numpy arrays.
-
- Customized from pygarrayimage's ArrayInterfaceImage to override the
- texture creation.
- """
-
- def create_texture(self, cls, rectangle=False, force_rectangle=False):
- """ Create a texture containing this image.
-
- If the image's dimensions are not powers of 2, a TextureRegion of
- a larger Texture will be returned that matches the dimensions of
- this image.
-
- :Parameters:
- `cls` : class (subclass of Texture)
- Class to construct.
- `rectangle` : bool
- ``True`` if a rectangle can be created; see
- `AbstractImage.get_texture`.
-
- :rtype: cls or cls.region_class
- """
-
- _is_pow2 = (lambda v: (v & (v - 1)) == 0)
-
- target = gl.GL_TEXTURE_2D
- if (rectangle
- and not (_is_pow2(self.width) and _is_pow2(self.height))):
- if gl.gl_info.have_extension("GL_ARB_texture_rectangle"):
- target = gl.GL_TEXTURE_RECTANGLE_ARB
- elif gl.gl_info.have_extension("GL_NV_texture_rectangle"):
- target = gl.GL_TEXTURE_RECTANGLE_NV
-
- texture = cls.create_for_size(target, self.width, self.height)
- subimage = False
- if texture.width != self.width or texture.height != self.height:
- texture = texture.get_region(0, 0, self.width, self.height)
- subimage = True
-
- internalformat = self._get_internalformat(self.format)
-
- gl.glBindTexture(texture.target, texture.id)
- gl.glTexParameteri(
- texture.target, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE
- )
- gl.glTexParameteri(
- texture.target, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE
- )
- gl.glTexParameteri(
- texture.target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR
- )
- gl.glTexParameteri(
- texture.target, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR
- )
-
- if subimage:
- width = texture.owner.width
- height = texture.owner.height
- blank = (ctypes.c_ubyte * (width * height * 4))()
- gl.glTexImage2D(
- texture.target,
- texture.level,
- internalformat,
- width,
- height,
- 1,
- gl.GL_RGBA,
- gl.GL_UNSIGNED_BYTE,
- blank,
- )
- internalformat = None
-
- self.blit_to_texture(
- texture.target, texture.level, 0, 0, 0, internalformat
- )
-
- return texture
-
- def blit_to_texture(self, target, level, x, y, z, internalformat=None):
- """Draw this image to to the currently bound texture at `target`.
-
- If `internalformat` is specified, glTexImage is used to initialise
- the texture; otherwise, glTexSubImage is used to update a region.
- """
-
- data_format = self.format
- data_pitch = abs(self._current_pitch)
-
- # Determine pixel format from format string
- matrix = None
- format, type = self._get_gl_format_and_type(data_format)
- if format is None:
- if (len(data_format) in (3, 4)
- and gl.gl_info.have_extension("GL_ARB_imaging")):
-
- # Construct a color matrix to convert to GL_RGBA
- def component_column(component):
- try:
- pos = "RGBA".index(component)
- return [0] * pos + [1] + [0] * (3 - pos)
- except ValueError:
- return [0, 0, 0, 0]
-
- # pad to avoid index exceptions
- lookup_format = data_format + "XXX"
- matrix = (
- component_column(lookup_format[0])
- + component_column(lookup_format[1])
- + component_column(lookup_format[2])
- + component_column(lookup_format[3])
- )
- format = {3: gl.GL_RGB, 4: gl.GL_RGBA}.get(
- len(data_format)
- )
- type = gl.GL_UNSIGNED_BYTE
-
- gl.glMatrixMode(gl.GL_COLOR)
- gl.glPushMatrix()
- gl.glLoadMatrixf((gl.GLfloat * 16)(*matrix))
- else:
- # Need to convert data to a standard form
- data_format = {1: "L", 2: "LA", 3: "RGB", 4: "RGBA"}.get(
- len(data_format)
- )
- format, type = self._get_gl_format_and_type(data_format)
-
- # Workaround: don't use GL_UNPACK_ROW_LENGTH
- if gl.current_context._workaround_unpack_row_length:
- data_pitch = self.width * len(data_format)
-
- # Get data in required format (hopefully will be the same format
- # it's already in, unless that's an obscure format, upside-down or
- # the driver is old).
- data = self._convert(data_format, data_pitch)
-
- if data_pitch & 0x1:
- alignment = 1
- elif data_pitch & 0x2:
- alignment = 2
- else:
- alignment = 4
- row_length = data_pitch / len(data_format)
- gl.glPushClientAttrib(gl.GL_CLIENT_PIXEL_STORE_BIT)
- gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, alignment)
- gl.glPixelStorei(gl.GL_UNPACK_ROW_LENGTH, row_length)
- self._apply_region_unpack()
- gl.glTexParameteri(
- target, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE
- )
- gl.glTexParameteri(
- target, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE
- )
- gl.glTexParameteri(target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
- gl.glTexParameteri(target, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
-
- if target == gl.GL_TEXTURE_3D:
- assert not internalformat
- gl.glTexSubImage3D(
- target,
- level,
- x,
- y,
- z,
- self.width,
- self.height,
- 1,
- format,
- type,
- data,
- )
- elif internalformat:
- gl.glTexImage2D(
- target,
- level,
- internalformat,
- self.width,
- self.height,
- 0,
- format,
- type,
- data,
- )
- else:
- gl.glTexSubImage2D(
- target,
- level,
- x,
- y,
- self.width,
- self.height,
- format,
- type,
- data,
- )
- gl.glPopClientAttrib()
-
- if matrix:
- gl.glPopMatrix()
- gl.glMatrixMode(gl.GL_MODELVIEW)
-
- # Use a singleton for the font cache
- GlobalFontCache = MRU()
-
- def GetFont(font):
- """ Returns a Pylget Font object for the given Agg or Kiva font """
- if isinstance(font, PygletFont):
- pyglet_font = font
- else:
- # KivaGLFontType
- key = (font.name, font.size, font.family, font.style)
- if key not in GlobalFontCache:
- if isinstance(font, KivaGLFontType):
- kiva_gl_font = font
- font = Font(
- face_name=kiva_gl_font.name,
- size=kiva_gl_font.size,
- family=kiva_gl_font.family,
- style=kiva_gl_font.style,
- )
- bold = font.is_bold()
- italic = font.style in italic_styles
- pyglet_font = load_font(
- font.findfontname(), font.size, bold, italic
- )
- GlobalFontCache[key] = pyglet_font
- else:
- pyglet_font = GlobalFontCache[key]
- return pyglet_font
-
- # Because Pyglet 1.1 uses persistent Label objects to efficiently lay
- # out and render text, we cache these globally to minimize the creation
- # time. An MRU is not really the right structure to use here, though.
- # (We typically expect that the same numbers of labels will be rendered.)
- GlobalTextCache = MRU()
- GlobalTextCache.__maxlength__ = 100
-
- def GetLabel(text, pyglet_font):
- """ Returns a Pyglet Label object for the given text and font """
- key = (text, pyglet_font)
- if key not in GlobalTextCache:
- # Use anchor_y="bottom" because by default, pyglet sets the
- # baseline to the y coordinate given. Unfortunately, it doesn't
- # expose a per-Text descent (only a per-Font descent), so it's
- # impossible to know how to offset the y value properly for a
- # given string.
- label = Label(
- text,
- font_name=pyglet_font.name,
- font_size=pyglet_font.size,
- anchor_y="bottom",
- )
- GlobalTextCache[key] = label
- else:
- label = GlobalTextCache[key]
- return label
-
-
-except ImportError as exc:
- # Pyglet is not available, so we forgo some features
- logger.exception(
- "Error importing Pyglet, some features not available in gl backend"
- )
- ArrayImage = None
- GetFont = None
- GetLabel = None
- gl = None
-
-
-class GraphicsContext(GraphicsContextGL):
- def __init__(self, size, *args, **kw):
- # Ignore the pix_format argument for now
- kw.pop("pix_format", None)
- base_scale = kw.pop("base_pixel_scale", 1)
- GraphicsContextGL.__init__(self, size[0], size[1], *args, **kw)
- self.corner_pixel_origin = True
-
- # For HiDPI support
- self.scale_ctm(base_scale, base_scale)
-
- self._font_stack = []
- self._current_font = None
- self._text_pos = (0, 0)
-
- def save_state(self):
- super().save_state()
- self._font_stack.append(self._current_font)
-
- def restore_state(self):
- super().restore_state()
- self._current_font = self._font_stack.pop()
-
- def set_font(self, font):
- self._current_font = font
-
- def get_text_extent(self, text):
- if self._current_font is None:
- return (0, 0, 0, 0)
-
- pyglet_font = GetFont(self._current_font)
- label = GetLabel(text, pyglet_font)
- return (0, 0, label.content_width, label.content_height)
-
- def set_text_position(self, x, y):
- self._text_pos = (x, y)
-
- def show_text(self, text, point=None):
- if point is None:
- point = self._text_pos
- return self.show_text_at_point(text, *point)
-
- def show_text_at_point(self, text, x, y):
- if self._current_font is None:
- return
-
- pyglet_font = GetFont(self._current_font)
- label = GetLabel(text, pyglet_font)
-
- xform = self.get_ctm()
- x0 = xform[4]
- y0 = xform[5]
-
- # The GL backend places the center of a pixel at (0.5, 0.5); however,
- # for show_text_at_point, we don't actually want to render the text
- # offset by half a pixel. There is probably a better, more uniform way
- # to handle this across all of Kiva, because this is probably a common
- # issue that will arise, but for now, we just round the position down.
- x = floor(x + x0)
- y = floor(y + y0)
-
- label.x = x
- label.y = y
- c = self.get_fill_color()
- label.color = (
- int(c[0] * 255),
- int(c[1] * 255),
- int(c[2] * 255),
- int(c[3] * 255),
- )
- label.draw()
- return True
-
- def linear_gradient(self, x1, y1, x2, y2, stops, spread_method,
- units="userSpaceOnUse"):
- """ Not implemented.
- """
- pass
-
- def radial_gradient(self, cx, cy, r, fx, fy, stops, spread_method,
- units="userSpaceOnUse"):
- """ Not implemented.
- """
- pass
-
- def draw_image(self, img, rect=None, force_copy=False):
- """ Renders a GraphicsContextArray into this GC """
- xform = self.get_ctm()
-
- image = image_as_array(img)
- shape = image.shape
- if shape[2] == 4:
- fmt = "RGBA"
- else:
- fmt = "RGB"
- aii = ArrayImage(image, format=fmt)
- texture = aii.texture
-
- # The texture coords consists of (u,v,r) for each corner of the
- # texture rectangle. The coordinates are stored in the order
- # bottom left, bottom right, top right, top left.
- x, y, w, h = rect
- texture.width = w
- texture.height = h
- t = texture.tex_coords
- points = array([[x, y + h], [x + w, y + h], [x + w, y], [x, y]])
- p = transform_points(affine_from_values(*xform), points)
- a = (gl.GLfloat*32)(
- t[0], t[1], t[2], 1.,
- p[0, 0], p[0, 1], 0, 1.,
- t[3], t[4], t[5], 1.,
- p[1, 0], p[1, 1], 0, 1.,
- t[6], t[7], t[8], 1.,
- p[2, 0], p[2, 1], 0, 1.,
- t[9], t[10], t[11], 1.,
- p[3, 0], p[3, 1], 0, 1.,
- )
- gl.glPushAttrib(gl.GL_ENABLE_BIT)
- gl.glEnable(texture.target)
- gl.glBindTexture(texture.target, texture.id)
- gl.glPushClientAttrib(gl.GL_CLIENT_VERTEX_ARRAY_BIT)
- gl.glInterleavedArrays(gl.GL_T4F_V4F, 0, a)
- gl.glDrawArrays(gl.GL_QUADS, 0, 4)
- gl.glPopClientAttrib()
- gl.glPopAttrib()
-
-
-def font_metrics_provider():
- return GraphicsContext((1, 1))
diff --git a/kiva/gl/gl.i b/kiva/gl/gl.i
deleted file mode 100644
index cba55880b..000000000
--- a/kiva/gl/gl.i
+++ /dev/null
@@ -1,21 +0,0 @@
-/* -*- c++ -*- */
-// (C) Copyright 2005-2022 Enthought, Inc., Austin, TX
-// All rights reserved.
-//
-// This software is provided without warranty under the terms of the BSD
-// license included in LICENSE.txt and may be redistributed only under
-// the conditions described in the aforementioned license. The license
-// is also available online at http://www.enthought.com/licenses/BSD.txt
-//
-// Thanks for using Enthought open source!
-
-%module gl
-
-%feature("compactdefaultargs");
-
-%include "constants.i"
-%include "rgba.i"
-%include "affine_matrix.i"
-%include "compiled_path.i"
-%include "font_type.i"
-%include "graphics_context.i"
diff --git a/kiva/gl/src/agg/agg_array.h b/kiva/gl/src/agg/agg_array.h
deleted file mode 100644
index 485347c56..000000000
--- a/kiva/gl/src/agg/agg_array.h
+++ /dev/null
@@ -1,1119 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-#ifndef AGG_ARRAY_INCLUDED
-#define AGG_ARRAY_INCLUDED
-
-#include
-#include
-#include "agg_basics.h"
-
-namespace kiva_gl_agg
-{
-
- //-------------------------------------------------------pod_array_adaptor
- template class pod_array_adaptor
- {
- public:
- typedef T value_type;
- pod_array_adaptor(T* array, unsigned size) :
- m_array(array), m_size(size) {}
-
- unsigned size() const { return m_size; }
- const T& operator [] (unsigned i) const { return m_array[i]; }
- T& operator [] (unsigned i) { return m_array[i]; }
- const T& at(unsigned i) const { return m_array[i]; }
- T& at(unsigned i) { return m_array[i]; }
- T value_at(unsigned i) const { return m_array[i]; }
-
- private:
- T* m_array;
- unsigned m_size;
- };
-
-
- //---------------------------------------------------------pod_auto_array
- template class pod_auto_array
- {
- public:
- typedef T value_type;
- typedef pod_auto_array self_type;
-
- pod_auto_array() {}
- explicit pod_auto_array(const T* c)
- {
- memcpy(m_array, c, sizeof(T) * Size);
- }
-
- const self_type& operator = (const T* c)
- {
- memcpy(m_array, c, sizeof(T) * Size);
- return *this;
- }
-
- static unsigned size() { return Size; }
- const T& operator [] (unsigned i) const { return m_array[i]; }
- T& operator [] (unsigned i) { return m_array[i]; }
- const T& at(unsigned i) const { return m_array[i]; }
- T& at(unsigned i) { return m_array[i]; }
- T value_at(unsigned i) const { return m_array[i]; }
-
- private:
- T m_array[Size];
- };
-
-
- //--------------------------------------------------------pod_auto_vector
- template class pod_auto_vector
- {
- public:
- typedef T value_type;
- typedef pod_auto_vector self_type;
-
- pod_auto_vector() : m_size(0) {}
-
- void remove_all() { m_size = 0; }
- void clear() { m_size = 0; }
- void add(const T& v) { m_array[m_size++] = v; }
- void push_back(const T& v) { m_array[m_size++] = v; }
- void inc_size(unsigned size) { m_size += size; }
-
- unsigned size() const { return m_size; }
- const T& operator [] (unsigned i) const { return m_array[i]; }
- T& operator [] (unsigned i) { return m_array[i]; }
- const T& at(unsigned i) const { return m_array[i]; }
- T& at(unsigned i) { return m_array[i]; }
- T value_at(unsigned i) const { return m_array[i]; }
-
- private:
- T m_array[Size];
- unsigned m_size;
- };
-
-
- //---------------------------------------------------------------pod_array
- template class pod_array
- {
- public:
- typedef T value_type;
- typedef pod_array self_type;
-
- ~pod_array() { pod_allocator::deallocate(m_array, m_size); }
- pod_array() : m_array(0), m_size(0) {}
-
- pod_array(unsigned size) :
- m_array(pod_allocator::allocate(size)),
- m_size(size)
- {}
-
- pod_array(const self_type& v) :
- m_array(pod_allocator::allocate(v.m_size)),
- m_size(v.m_size)
- {
- memcpy(m_array, v.m_array, sizeof(T) * m_size);
- }
-
- void resize(unsigned size)
- {
- if(size != m_size)
- {
- pod_allocator::deallocate(m_array, m_size);
- m_array = pod_allocator::allocate(m_size = size);
- }
- }
- const self_type& operator = (const self_type& v)
- {
- resize(v.size());
- memcpy(m_array, v.m_array, sizeof(T) * m_size);
- return *this;
- }
-
- unsigned size() const { return m_size; }
- const T& operator [] (unsigned i) const { return m_array[i]; }
- T& operator [] (unsigned i) { return m_array[i]; }
- const T& at(unsigned i) const { return m_array[i]; }
- T& at(unsigned i) { return m_array[i]; }
- T value_at(unsigned i) const { return m_array[i]; }
-
- const T* data() const { return m_array; }
- T* data() { return m_array; }
- private:
- T* m_array;
- unsigned m_size;
- };
-
-
-
- //--------------------------------------------------------------pod_vector
- // A simple class template to store Plain Old Data, a vector
- // of a fixed size. The data is continous in memory
- //------------------------------------------------------------------------
- template class pod_vector
- {
- public:
- typedef T value_type;
-
- ~pod_vector() { pod_allocator::deallocate(m_array, m_capacity); }
- pod_vector() : m_size(0), m_capacity(0), m_array(0) {}
- pod_vector(unsigned cap, unsigned extra_tail=0);
-
- // Copying
- pod_vector(const pod_vector&);
- const pod_vector& operator = (const pod_vector&);
-
- // Set new capacity. All data is lost, size is set to zero.
- void capacity(unsigned cap, unsigned extra_tail=0);
- unsigned capacity() const { return m_capacity; }
-
- // Allocate n elements. All data is lost,
- // but elements can be accessed in range 0...size-1.
- void allocate(unsigned size, unsigned extra_tail=0);
-
- // Resize keeping the content.
- void resize(unsigned new_size);
-
- void zero()
- {
- memset(m_array, 0, sizeof(T) * m_size);
- }
-
- void add(const T& v) { m_array[m_size++] = v; }
- void push_back(const T& v) { m_array[m_size++] = v; }
- void insert_at(unsigned pos, const T& val);
- void inc_size(unsigned size) { m_size += size; }
- unsigned size() const { return m_size; }
- unsigned byte_size() const { return m_size * sizeof(T); }
- void serialize(int8u* ptr) const;
- void deserialize(const int8u* data, unsigned byte_size);
- const T& operator [] (unsigned i) const { return m_array[i]; }
- T& operator [] (unsigned i) { return m_array[i]; }
- const T& at(unsigned i) const { return m_array[i]; }
- T& at(unsigned i) { return m_array[i]; }
- T value_at(unsigned i) const { return m_array[i]; }
-
- const T* data() const { return m_array; }
- T* data() { return m_array; }
-
- void remove_all() { m_size = 0; }
- void clear() { m_size = 0; }
- void cut_at(unsigned num) { if(num < m_size) m_size = num; }
-
- private:
- unsigned m_size;
- unsigned m_capacity;
- T* m_array;
- };
-
- //------------------------------------------------------------------------
- template
- void pod_vector::capacity(unsigned cap, unsigned extra_tail)
- {
- m_size = 0;
- if(cap > m_capacity)
- {
- pod_allocator::deallocate(m_array, m_capacity);
- m_capacity = cap + extra_tail;
- m_array = m_capacity ? pod_allocator::allocate(m_capacity) : 0;
- }
- }
-
- //------------------------------------------------------------------------
- template
- void pod_vector::allocate(unsigned size, unsigned extra_tail)
- {
- capacity(size, extra_tail);
- m_size = size;
- }
-
-
- //------------------------------------------------------------------------
- template
- void pod_vector::resize(unsigned new_size)
- {
- if(new_size > m_size)
- {
- if(new_size > m_capacity)
- {
- T* data = pod_allocator::allocate(new_size);
- memcpy(data, m_array, m_size * sizeof(T));
- pod_allocator::deallocate(m_array, m_capacity);
- m_array = data;
- }
- }
- else
- {
- m_size = new_size;
- }
- }
-
- //------------------------------------------------------------------------
- template pod_vector::pod_vector(unsigned cap, unsigned extra_tail) :
- m_size(0),
- m_capacity(cap + extra_tail),
- m_array(pod_allocator::allocate(m_capacity)) {}
-
- //------------------------------------------------------------------------
- template pod_vector::pod_vector(const pod_vector& v) :
- m_size(v.m_size),
- m_capacity(v.m_capacity),
- m_array(v.m_capacity ? pod_allocator::allocate(v.m_capacity) : 0)
- {
- memcpy(m_array, v.m_array, sizeof(T) * v.m_size);
- }
-
- //------------------------------------------------------------------------
- template const pod_vector&
- pod_vector::operator = (const pod_vector&v)
- {
- allocate(v.m_size);
- if(v.m_size) memcpy(m_array, v.m_array, sizeof(T) * v.m_size);
- return *this;
- }
-
- //------------------------------------------------------------------------
- template void pod_vector::serialize(int8u* ptr) const
- {
- if(m_size) memcpy(ptr, m_array, m_size * sizeof(T));
- }
-
- //------------------------------------------------------------------------
- template
- void pod_vector::deserialize(const int8u* data, unsigned byte_size)
- {
- byte_size /= sizeof(T);
- allocate(byte_size);
- if(byte_size) memcpy(m_array, data, byte_size * sizeof(T));
- }
-
- //------------------------------------------------------------------------
- template
- void pod_vector::insert_at(unsigned pos, const T& val)
- {
- if(pos >= m_size)
- {
- m_array[m_size] = val;
- }
- else
- {
- memmove(m_array + pos + 1, m_array + pos, (m_size - pos) * sizeof(T));
- m_array[pos] = val;
- }
- ++m_size;
- }
-
- //---------------------------------------------------------------pod_bvector
- // A simple class template to store Plain Old Data, similar to std::deque
- // It doesn't reallocate memory but instead, uses blocks of data of size
- // of (1 << S), that is, power of two. The data is NOT contiguous in memory,
- // so the only valid access method is operator [] or curr(), prev(), next()
- //
- // There reallocs occure only when the pool of pointers to blocks needs
- // to be extended (it happens very rarely). You can control the value
- // of increment to reallocate the pointer buffer. See the second constructor.
- // By default, the incremeent value equals (1 << S), i.e., the block size.
- //------------------------------------------------------------------------
- template class pod_bvector
- {
- public:
- enum block_scale_e
- {
- block_shift = S,
- block_size = 1 << block_shift,
- block_mask = block_size - 1
- };
-
- typedef T value_type;
-
- ~pod_bvector();
- pod_bvector();
- pod_bvector(unsigned block_ptr_inc);
-
- // Copying
- pod_bvector(const pod_bvector& v);
- const pod_bvector& operator = (const pod_bvector& v);
-
- void remove_all() { m_size = 0; }
- void clear() { m_size = 0; }
- void free_all() { free_tail(0); }
- void free_tail(unsigned size);
- void add(const T& val);
- void push_back(const T& val) { add(val); }
- void modify_last(const T& val);
- void remove_last();
-
- int allocate_continuous_block(unsigned num_elements);
-
- void add_array(const T* ptr, unsigned num_elem)
- {
- while(num_elem--)
- {
- add(*ptr++);
- }
- }
-
- template void add_data(DataAccessor& data)
- {
- while(data.size())
- {
- add(*data);
- ++data;
- }
- }
-
- void cut_at(unsigned size)
- {
- if(size < m_size) m_size = size;
- }
-
- unsigned size() const { return m_size; }
-
- const T& operator [] (unsigned i) const
- {
- return m_blocks[i >> block_shift][i & block_mask];
- }
-
- T& operator [] (unsigned i)
- {
- return m_blocks[i >> block_shift][i & block_mask];
- }
-
- const T& at(unsigned i) const
- {
- return m_blocks[i >> block_shift][i & block_mask];
- }
-
- T& at(unsigned i)
- {
- return m_blocks[i >> block_shift][i & block_mask];
- }
-
- T value_at(unsigned i) const
- {
- return m_blocks[i >> block_shift][i & block_mask];
- }
-
- const T& curr(unsigned idx) const
- {
- return (*this)[idx];
- }
-
- T& curr(unsigned idx)
- {
- return (*this)[idx];
- }
-
- const T& prev(unsigned idx) const
- {
- return (*this)[(idx + m_size - 1) % m_size];
- }
-
- T& prev(unsigned idx)
- {
- return (*this)[(idx + m_size - 1) % m_size];
- }
-
- const T& next(unsigned idx) const
- {
- return (*this)[(idx + 1) % m_size];
- }
-
- T& next(unsigned idx)
- {
- return (*this)[(idx + 1) % m_size];
- }
-
- const T& last() const
- {
- return (*this)[m_size - 1];
- }
-
- T& last()
- {
- return (*this)[m_size - 1];
- }
-
- unsigned byte_size() const;
- void serialize(int8u* ptr) const;
- void deserialize(const int8u* data, unsigned byte_size);
- void deserialize(unsigned start, const T& empty_val,
- const int8u* data, unsigned byte_size);
-
- template
- void deserialize(ByteAccessor data)
- {
- remove_all();
- unsigned elem_size = data.size() / sizeof(T);
-
- for(unsigned i = 0; i < elem_size; ++i)
- {
- int8u* ptr = (int8u*)data_ptr();
- for(unsigned j = 0; j < sizeof(T); ++j)
- {
- *ptr++ = *data;
- ++data;
- }
- ++m_size;
- }
- }
-
- template
- void deserialize(unsigned start, const T& empty_val, ByteAccessor data)
- {
- while(m_size < start)
- {
- add(empty_val);
- }
-
- unsigned elem_size = data.size() / sizeof(T);
- for(unsigned i = 0; i < elem_size; ++i)
- {
- int8u* ptr;
- if(start + i < m_size)
- {
- ptr = (int8u*)(&((*this)[start + i]));
- }
- else
- {
- ptr = (int8u*)data_ptr();
- ++m_size;
- }
- for(unsigned j = 0; j < sizeof(T); ++j)
- {
- *ptr++ = *data;
- ++data;
- }
- }
- }
-
- const T* block(unsigned nb) const { return m_blocks[nb]; }
-
- private:
- void allocate_block(unsigned nb);
- T* data_ptr();
-
- unsigned m_size;
- unsigned m_num_blocks;
- unsigned m_max_blocks;
- T** m_blocks;
- unsigned m_block_ptr_inc;
- };
-
-
- //------------------------------------------------------------------------
- template pod_bvector::~pod_bvector()
- {
- if(m_num_blocks)
- {
- T** blk = m_blocks + m_num_blocks - 1;
- while(m_num_blocks--)
- {
- pod_allocator::deallocate(*blk, block_size);
- --blk;
- }
- }
- pod_allocator::deallocate(m_blocks, m_max_blocks);
- }
-
-
- //------------------------------------------------------------------------
- template
- void pod_bvector::free_tail(unsigned size)
- {
- if(size < m_size)
- {
- unsigned nb = (size + block_mask) >> block_shift;
- while(m_num_blocks > nb)
- {
- pod_allocator::deallocate(m_blocks[--m_num_blocks], block_size);
- }
- if(m_num_blocks == 0)
- {
- pod_allocator::deallocate(m_blocks, m_max_blocks);
- m_blocks = 0;
- m_max_blocks = 0;
- }
- m_size = size;
- }
- }
-
-
- //------------------------------------------------------------------------
- template pod_bvector::pod_bvector() :
- m_size(0),
- m_num_blocks(0),
- m_max_blocks(0),
- m_blocks(0),
- m_block_ptr_inc(block_size)
- {
- }
-
-
- //------------------------------------------------------------------------
- template
- pod_bvector::pod_bvector(unsigned block_ptr_inc) :
- m_size(0),
- m_num_blocks(0),
- m_max_blocks(0),
- m_blocks(0),
- m_block_ptr_inc(block_ptr_inc)
- {
- }
-
-
- //------------------------------------------------------------------------
- template
- pod_bvector::pod_bvector(const pod_bvector& v) :
- m_size(v.m_size),
- m_num_blocks(v.m_num_blocks),
- m_max_blocks(v.m_max_blocks),
- m_blocks(v.m_max_blocks ?
- pod_allocator::allocate(v.m_max_blocks) :
- 0),
- m_block_ptr_inc(v.m_block_ptr_inc)
- {
- unsigned i;
- for(i = 0; i < v.m_num_blocks; ++i)
- {
- m_blocks[i] = pod_allocator::allocate(block_size);
- memcpy(m_blocks[i], v.m_blocks[i], block_size * sizeof(T));
- }
- }
-
-
- //------------------------------------------------------------------------
- template
- const pod_bvector&
- pod_bvector::operator = (const pod_bvector& v)
- {
- unsigned i;
- for(i = m_num_blocks; i < v.m_num_blocks; ++i)
- {
- allocate_block(i);
- }
- for(i = 0; i < v.m_num_blocks; ++i)
- {
- memcpy(m_blocks[i], v.m_blocks[i], block_size * sizeof(T));
- }
- m_size = v.m_size;
- return *this;
- }
-
-
- //------------------------------------------------------------------------
- template
- void pod_bvector::allocate_block(unsigned nb)
- {
- if(nb >= m_max_blocks)
- {
- T** new_blocks = pod_allocator::allocate(m_max_blocks + m_block_ptr_inc);
-
- if(m_blocks)
- {
- memcpy(new_blocks,
- m_blocks,
- m_num_blocks * sizeof(T*));
-
- pod_allocator::deallocate(m_blocks, m_max_blocks);
- }
- m_blocks = new_blocks;
- m_max_blocks += m_block_ptr_inc;
- }
- m_blocks[nb] = pod_allocator::allocate(block_size);
- m_num_blocks++;
- }
-
-
-
- //------------------------------------------------------------------------
- template
- inline T* pod_bvector::data_ptr()
- {
- unsigned nb = m_size >> block_shift;
- if(nb >= m_num_blocks)
- {
- allocate_block(nb);
- }
- return m_blocks[nb] + (m_size & block_mask);
- }
-
-
-
- //------------------------------------------------------------------------
- template
- inline void pod_bvector::add(const T& val)
- {
- *data_ptr() = val;
- ++m_size;
- }
-
-
- //------------------------------------------------------------------------
- template
- inline void pod_bvector::remove_last()
- {
- if(m_size) --m_size;
- }
-
-
- //------------------------------------------------------------------------
- template
- void pod_bvector::modify_last(const T& val)
- {
- remove_last();
- add(val);
- }
-
-
- //------------------------------------------------------------------------
- template
- int pod_bvector::allocate_continuous_block(unsigned num_elements)
- {
- if(num_elements < block_size)
- {
- data_ptr(); // Allocate initial block if necessary
- unsigned rest = block_size - (m_size & block_mask);
- unsigned index;
- if(num_elements <= rest)
- {
- // The rest of the block is good, we can use it
- //-----------------
- index = m_size;
- m_size += num_elements;
- return index;
- }
-
- // New block
- //---------------
- m_size += rest;
- data_ptr();
- index = m_size;
- m_size += num_elements;
- return index;
- }
- return -1; // Impossible to allocate
- }
-
-
- //------------------------------------------------------------------------
- template
- unsigned pod_bvector::byte_size() const
- {
- return m_size * sizeof(T);
- }
-
-
- //------------------------------------------------------------------------
- template
- void pod_bvector::serialize(int8u* ptr) const
- {
- unsigned i;
- for(i = 0; i < m_size; i++)
- {
- memcpy(ptr, &(*this)[i], sizeof(T));
- ptr += sizeof(T);
- }
- }
-
- //------------------------------------------------------------------------
- template
- void pod_bvector::deserialize(const int8u* data, unsigned byte_size)
- {
- remove_all();
- byte_size /= sizeof(T);
- for(unsigned i = 0; i < byte_size; ++i)
- {
- T* ptr = data_ptr();
- memcpy(ptr, data, sizeof(T));
- ++m_size;
- data += sizeof(T);
- }
- }
-
-
- // Replace or add a number of elements starting from "start" position
- //------------------------------------------------------------------------
- template
- void pod_bvector::deserialize(unsigned start, const T& empty_val,
- const int8u* data, unsigned byte_size)
- {
- while(m_size < start)
- {
- add(empty_val);
- }
-
- byte_size /= sizeof(T);
- for(unsigned i = 0; i < byte_size; ++i)
- {
- if(start + i < m_size)
- {
- memcpy(&((*this)[start + i]), data, sizeof(T));
- }
- else
- {
- T* ptr = data_ptr();
- memcpy(ptr, data, sizeof(T));
- ++m_size;
- }
- data += sizeof(T);
- }
- }
-
-
- //---------------------------------------------------------block_allocator
- // Allocator for arbitrary POD data. Most usable in different cache
- // systems for efficient memory allocations.
- // Memory is allocated with blocks of fixed size ("block_size" in
- // the constructor). If required size exceeds the block size the allocator
- // creates a new block of the required size. However, the most efficient
- // use is when the average reqired size is much less than the block size.
- //------------------------------------------------------------------------
- class block_allocator
- {
- struct block_type
- {
- int8u* data;
- unsigned size;
- };
-
- public:
- void remove_all()
- {
- if(m_num_blocks)
- {
- block_type* blk = m_blocks + m_num_blocks - 1;
- while(m_num_blocks--)
- {
- pod_allocator::deallocate(blk->data, blk->size);
- --blk;
- }
- pod_allocator::deallocate(m_blocks, m_max_blocks);
- }
- m_num_blocks = 0;
- m_max_blocks = 0;
- m_blocks = 0;
- m_buf_ptr = 0;
- m_rest = 0;
- }
-
- ~block_allocator()
- {
- remove_all();
- }
-
- block_allocator(unsigned block_size, unsigned block_ptr_inc=256-8) :
- m_block_size(block_size),
- m_block_ptr_inc(block_ptr_inc),
- m_num_blocks(0),
- m_max_blocks(0),
- m_blocks(0),
- m_buf_ptr(0),
- m_rest(0)
- {
- }
-
-
- int8u* allocate(unsigned size, unsigned alignment=1)
- {
- if(size == 0) return 0;
- if(size <= m_rest)
- {
- int8u* ptr = m_buf_ptr;
- if(alignment > 1)
- {
- unsigned align =
- (alignment - unsigned((size_t)ptr) % alignment) % alignment;
-
- size += align;
- ptr += align;
- if(size <= m_rest)
- {
- m_rest -= size;
- m_buf_ptr += size;
- return ptr;
- }
- allocate_block(size);
- return allocate(size - align, alignment);
- }
- m_rest -= size;
- m_buf_ptr += size;
- return ptr;
- }
- allocate_block(size + alignment - 1);
- return allocate(size, alignment);
- }
-
-
- private:
- void allocate_block(unsigned size)
- {
- if(size < m_block_size) size = m_block_size;
- if(m_num_blocks >= m_max_blocks)
- {
- block_type* new_blocks =
- pod_allocator::allocate(m_max_blocks + m_block_ptr_inc);
-
- if(m_blocks)
- {
- memcpy(new_blocks,
- m_blocks,
- m_num_blocks * sizeof(block_type));
- pod_allocator::deallocate(m_blocks, m_max_blocks);
- }
- m_blocks = new_blocks;
- m_max_blocks += m_block_ptr_inc;
- }
-
- m_blocks[m_num_blocks].size = size;
- m_blocks[m_num_blocks].data =
- m_buf_ptr =
- pod_allocator::allocate(size);
-
- m_num_blocks++;
- m_rest = size;
- }
-
- unsigned m_block_size;
- unsigned m_block_ptr_inc;
- unsigned m_num_blocks;
- unsigned m_max_blocks;
- block_type* m_blocks;
- int8u* m_buf_ptr;
- unsigned m_rest;
- };
-
-
-
-
-
-
-
-
- //------------------------------------------------------------------------
- enum quick_sort_threshold_e
- {
- quick_sort_threshold = 9
- };
-
-
- //-----------------------------------------------------------swap_elements
- template inline void swap_elements(T& a, T& b)
- {
- T temp = a;
- a = b;
- b = temp;
- }
-
-
- //--------------------------------------------------------------quick_sort
- template
- void quick_sort(Array& arr, Less less)
- {
- if(arr.size() < 2) return;
-
- typename Array::value_type* e1;
- typename Array::value_type* e2;
-
- int stack[80];
- int* top = stack;
- int limit = arr.size();
- int base = 0;
-
- for(;;)
- {
- int len = limit - base;
-
- int i;
- int j;
- int pivot;
-
- if(len > quick_sort_threshold)
- {
- // we use base + len/2 as the pivot
- pivot = base + len / 2;
- swap_elements(arr[base], arr[pivot]);
-
- i = base + 1;
- j = limit - 1;
-
- // now ensure that *i <= *base <= *j
- e1 = &(arr[j]);
- e2 = &(arr[i]);
- if(less(*e1, *e2)) swap_elements(*e1, *e2);
-
- e1 = &(arr[base]);
- e2 = &(arr[i]);
- if(less(*e1, *e2)) swap_elements(*e1, *e2);
-
- e1 = &(arr[j]);
- e2 = &(arr[base]);
- if(less(*e1, *e2)) swap_elements(*e1, *e2);
-
- for(;;)
- {
- do i++; while( less(arr[i], arr[base]) );
- do j--; while( less(arr[base], arr[j]) );
-
- if( i > j )
- {
- break;
- }
-
- swap_elements(arr[i], arr[j]);
- }
-
- swap_elements(arr[base], arr[j]);
-
- // now, push the largest sub-array
- if(j - base > limit - i)
- {
- top[0] = base;
- top[1] = j;
- base = i;
- }
- else
- {
- top[0] = i;
- top[1] = limit;
- limit = j;
- }
- top += 2;
- }
- else
- {
- // the sub-array is small, perform insertion sort
- j = base;
- i = j + 1;
-
- for(; i < limit; j = i, i++)
- {
- for(; less(*(e1 = &(arr[j + 1])), *(e2 = &(arr[j]))); j--)
- {
- swap_elements(*e1, *e2);
- if(j == base)
- {
- break;
- }
- }
- }
- if(top > stack)
- {
- top -= 2;
- base = top[0];
- limit = top[1];
- }
- else
- {
- break;
- }
- }
- }
- }
-
-
-
-
- //------------------------------------------------------remove_duplicates
- // Remove duplicates from a sorted array. It doesn't cut the
- // tail of the array, it just returns the number of remaining elements.
- //-----------------------------------------------------------------------
- template
- unsigned remove_duplicates(Array& arr, Equal equal)
- {
- if(arr.size() < 2) return arr.size();
-
- unsigned i, j;
- for(i = 1, j = 1; i < arr.size(); i++)
- {
- typename Array::value_type& e = arr[i];
- if(!equal(e, arr[i - 1]))
- {
- arr[j++] = e;
- }
- }
- return j;
- }
-
- //--------------------------------------------------------invert_container
- template void invert_container(Array& arr)
- {
- int i = 0;
- int j = arr.size() - 1;
- while(i < j)
- {
- swap_elements(arr[i++], arr[j--]);
- }
- }
-
- //------------------------------------------------------binary_search_pos
- template
- unsigned binary_search_pos(const Array& arr, const Value& val, Less less)
- {
- if(arr.size() == 0) return 0;
-
- unsigned beg = 0;
- unsigned end = arr.size() - 1;
-
- if(less(val, arr[0])) return 0;
- if(less(arr[end], val)) return end + 1;
-
- while(end - beg > 1)
- {
- unsigned mid = (end + beg) >> 1;
- if(less(val, arr[mid])) end = mid;
- else beg = mid;
- }
-
- //if(beg <= 0 && less(val, arr[0])) return 0;
- //if(end >= arr.size() - 1 && less(arr[end], val)) ++end;
-
- return end;
- }
-
- //----------------------------------------------------------range_adaptor
- template class range_adaptor
- {
- public:
- typedef typename Array::value_type value_type;
-
- range_adaptor(Array& array, unsigned start, unsigned size) :
- m_array(array), m_start(start), m_size(size)
- {}
-
- unsigned size() const { return m_size; }
- const value_type& operator [] (unsigned i) const { return m_array[m_start + i]; }
- value_type& operator [] (unsigned i) { return m_array[m_start + i]; }
- const value_type& at(unsigned i) const { return m_array[m_start + i]; }
- value_type& at(unsigned i) { return m_array[m_start + i]; }
- value_type value_at(unsigned i) const { return m_array[m_start + i]; }
-
- private:
- Array& m_array;
- unsigned m_start;
- unsigned m_size;
- };
-
- //---------------------------------------------------------------int_less
- inline bool int_less(int a, int b) { return a < b; }
-
- //------------------------------------------------------------int_greater
- inline bool int_greater(int a, int b) { return a > b; }
-
- //----------------------------------------------------------unsigned_less
- inline bool unsigned_less(unsigned a, unsigned b) { return a < b; }
-
- //-------------------------------------------------------unsigned_greater
- inline bool unsigned_greater(unsigned a, unsigned b) { return a > b; }
-}
-
-#endif
diff --git a/kiva/gl/src/agg/agg_basics.h b/kiva/gl/src/agg/agg_basics.h
deleted file mode 100644
index 88930fd47..000000000
--- a/kiva/gl/src/agg/agg_basics.h
+++ /dev/null
@@ -1,560 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-
-#ifndef AGG_BASICS_INCLUDED
-#define AGG_BASICS_INCLUDED
-
-#include
-#include "agg_config.h"
-
-//---------------------------------------------------------AGG_CUSTOM_ALLOCATOR
-#ifdef AGG_CUSTOM_ALLOCATOR
-#include "agg_allocator.h"
-#else
-namespace kiva_gl_agg
-{
- // The policy of all AGG containers and memory allocation strategy
- // in general is that no allocated data requires explicit construction.
- // It means that the allocator can be really simple; you can even
- // replace new/delete to malloc/free. The constructors and destructors
- // won't be called in this case, however everything will remain working.
- // The second argument of deallocate() is the size of the allocated
- // block. You can use this information if you wish.
- //------------------------------------------------------------pod_allocator
- template struct pod_allocator
- {
- static T* allocate(unsigned num) { return new T [num]; }
- static void deallocate(T* ptr, unsigned) { delete [] ptr; }
- };
-
- // Single object allocator. It's also can be replaced with your custom
- // allocator. The difference is that it can only allocate a single
- // object and the constructor and destructor must be called.
- // In AGG there is no need to allocate an array of objects with
- // calling their constructors (only single ones). So that, if you
- // replace these new/delete to malloc/free make sure that the in-place
- // new is called and take care of calling the destructor too.
- //------------------------------------------------------------obj_allocator
- template struct obj_allocator
- {
- static T* allocate() { return new T; }
- static void deallocate(T* ptr) { delete ptr; }
- };
-}
-#endif
-
-
-//-------------------------------------------------------- Default basic types
-//
-// If the compiler has different capacity of the basic types you can redefine
-// them via the compiler command line or by generating agg_config.h that is
-// empty by default.
-//
-#ifndef AGG_INT8
-#define AGG_INT8 signed char
-#endif
-
-#ifndef AGG_INT8U
-#define AGG_INT8U unsigned char
-#endif
-
-#ifndef AGG_INT16
-#define AGG_INT16 short
-#endif
-
-#ifndef AGG_INT16U
-#define AGG_INT16U unsigned short
-#endif
-
-#ifndef AGG_INT32
-#define AGG_INT32 int
-#endif
-
-#ifndef AGG_INT32U
-#define AGG_INT32U unsigned
-#endif
-
-#ifndef AGG_INT64
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-#define AGG_INT64 signed __int64
-#else
-#define AGG_INT64 signed long long
-#endif
-#endif
-
-#ifndef AGG_INT64U
-#if defined(_MSC_VER) || defined(__BORLANDC__)
-#define AGG_INT64U unsigned __int64
-#else
-#define AGG_INT64U unsigned long long
-#endif
-#endif
-
-//------------------------------------------------ Some fixes for MS Visual C++
-#if defined(_MSC_VER)
-#pragma warning(disable:4786) // Identifier was truncated...
-#endif
-
-#if defined(_MSC_VER)
-#define AGG_INLINE __forceinline
-#else
-#define AGG_INLINE inline
-#endif
-
-namespace kiva_gl_agg
-{
- //-------------------------------------------------------------------------
- typedef AGG_INT8 int8; //----int8
- typedef AGG_INT8U int8u; //----int8u
- typedef AGG_INT16 int16; //----int16
- typedef AGG_INT16U int16u; //----int16u
- typedef AGG_INT32 int32; //----int32
- typedef AGG_INT32U int32u; //----int32u
- typedef AGG_INT64 int64; //----int64
- typedef AGG_INT64U int64u; //----int64u
-
-#if defined(AGG_FISTP)
-#pragma warning(push)
-#pragma warning(disable : 4035) //Disable warning "no return value"
- AGG_INLINE int iround(double v) //-------iround
- {
- int t;
- __asm fld qword ptr [v]
- __asm fistp dword ptr [t]
- __asm mov eax, dword ptr [t]
- }
- AGG_INLINE unsigned uround(double v) //-------uround
- {
- unsigned t;
- __asm fld qword ptr [v]
- __asm fistp dword ptr [t]
- __asm mov eax, dword ptr [t]
- }
-#pragma warning(pop)
- AGG_INLINE int ifloor(double v)
- {
- return int(floor(v));
- }
- AGG_INLINE unsigned ufloor(double v) //-------ufloor
- {
- return unsigned(floor(v));
- }
- AGG_INLINE int iceil(double v)
- {
- return int(ceil(v));
- }
- AGG_INLINE unsigned uceil(double v) //--------uceil
- {
- return unsigned(ceil(v));
- }
-#elif defined(AGG_QIFIST)
- AGG_INLINE int iround(double v)
- {
- return int(v);
- }
- AGG_INLINE int uround(double v)
- {
- return unsigned(v);
- }
- AGG_INLINE int ifloor(double v)
- {
- return int(floor(v));
- }
- AGG_INLINE unsigned ufloor(double v)
- {
- return unsigned(floor(v));
- }
- AGG_INLINE int iceil(double v)
- {
- return int(ceil(v));
- }
- AGG_INLINE unsigned uceil(double v)
- {
- return unsigned(ceil(v));
- }
-#else
- AGG_INLINE int iround(double v)
- {
- return int((v < 0.0) ? v - 0.5 : v + 0.5);
- }
- AGG_INLINE int uround(double v)
- {
- return unsigned(v + 0.5);
- }
- AGG_INLINE int ifloor(double v)
- {
- int i = int(v);
- return i - (i > v);
- }
- AGG_INLINE unsigned ufloor(double v)
- {
- return unsigned(v);
- }
- AGG_INLINE int iceil(double v)
- {
- return int(ceil(v));
- }
- AGG_INLINE unsigned uceil(double v)
- {
- return unsigned(ceil(v));
- }
-#endif
-
- //---------------------------------------------------------------saturation
- template struct saturation
- {
- AGG_INLINE static int iround(double v)
- {
- if(v < double(-Limit)) return -Limit;
- if(v > double( Limit)) return Limit;
- return kiva_gl_agg::iround(v);
- }
- };
-
- //------------------------------------------------------------------mul_one
- template struct mul_one
- {
- AGG_INLINE static unsigned mul(unsigned a, unsigned b)
- {
- register unsigned q = a * b + (1 << (Shift-1));
- return (q + (q >> Shift)) >> Shift;
- }
- };
-
- //-------------------------------------------------------------------------
- typedef unsigned char cover_type; //----cover_type
- enum cover_scale_e
- {
- cover_shift = 8, //----cover_shift
- cover_size = 1 << cover_shift, //----cover_size
- cover_mask = cover_size - 1, //----cover_mask
- cover_none = 0, //----cover_none
- cover_full = cover_mask //----cover_full
- };
-
- //----------------------------------------------------poly_subpixel_scale_e
- // These constants determine the subpixel accuracy, to be more precise,
- // the number of bits of the fractional part of the coordinates.
- // The possible coordinate capacity in bits can be calculated by formula:
- // sizeof(int) * 8 - poly_subpixel_shift, i.e, for 32-bit integers and
- // 8-bits fractional part the capacity is 24 bits.
- enum poly_subpixel_scale_e
- {
- poly_subpixel_shift = 8, //----poly_subpixel_shift
- poly_subpixel_scale = 1< struct rect_base
- {
- typedef T value_type;
- typedef rect_base self_type;
- T x1, y1, x2, y2;
-
- rect_base() {}
- rect_base(T x1_, T y1_, T x2_, T y2_) :
- x1(x1_), y1(y1_), x2(x2_), y2(y2_) {}
-
- void init(T x1_, T y1_, T x2_, T y2_)
- {
- x1 = x1_; y1 = y1_; x2 = x2_; y2 = y2_;
- }
-
- const self_type& normalize()
- {
- T t;
- if(x1 > x2) { t = x1; x1 = x2; x2 = t; }
- if(y1 > y2) { t = y1; y1 = y2; y2 = t; }
- return *this;
- }
-
- bool clip(const self_type& r)
- {
- if(x2 > r.x2) x2 = r.x2;
- if(y2 > r.y2) y2 = r.y2;
- if(x1 < r.x1) x1 = r.x1;
- if(y1 < r.y1) y1 = r.y1;
- return x1 <= x2 && y1 <= y2;
- }
-
- bool is_valid() const
- {
- return x1 <= x2 && y1 <= y2;
- }
-
- bool hit_test(T x, T y) const
- {
- return (x >= x1 && x <= x2 && y >= y1 && y <= y2);
- }
-
- bool overlaps(const self_type& r) const
- {
- return !(r.x1 > x2 || r.x2 < x1
- || r.y1 > y2 || r.y2 < y1);
- }
- };
-
- //-----------------------------------------------------intersect_rectangles
- template
- inline Rect intersect_rectangles(const Rect& r1, const Rect& r2)
- {
- Rect r = r1;
-
- // First process x2,y2 because the other order
- // results in Internal Compiler Error under
- // Microsoft Visual C++ .NET 2003 69462-335-0000007-18038 in
- // case of "Maximize Speed" optimization option.
- //-----------------
- if(r.x2 > r2.x2) r.x2 = r2.x2;
- if(r.y2 > r2.y2) r.y2 = r2.y2;
- if(r.x1 < r2.x1) r.x1 = r2.x1;
- if(r.y1 < r2.y1) r.y1 = r2.y1;
- return r;
- }
-
-
- //---------------------------------------------------------unite_rectangles
- template
- inline Rect unite_rectangles(const Rect& r1, const Rect& r2)
- {
- Rect r = r1;
- if(r.x2 < r2.x2) r.x2 = r2.x2;
- if(r.y2 < r2.y2) r.y2 = r2.y2;
- if(r.x1 > r2.x1) r.x1 = r2.x1;
- if(r.y1 > r2.y1) r.y1 = r2.y1;
- return r;
- }
-
- typedef rect_base rect_i; //----rect_i
- typedef rect_base rect_f; //----rect_f
- typedef rect_base rect_d; //----rect_d
-
- //---------------------------------------------------------path_commands_e
- enum path_commands_e
- {
- path_cmd_stop = 0, //----path_cmd_stop
- path_cmd_move_to = 1, //----path_cmd_move_to
- path_cmd_line_to = 2, //----path_cmd_line_to
- path_cmd_curve3 = 3, //----path_cmd_curve3
- path_cmd_curve4 = 4, //----path_cmd_curve4
- path_cmd_curveN = 5, //----path_cmd_curveN
- path_cmd_catrom = 6, //----path_cmd_catrom
- path_cmd_ubspline = 7, //----path_cmd_ubspline
- path_cmd_end_poly = 0x0F, //----path_cmd_end_poly
- path_cmd_mask = 0x0F //----path_cmd_mask
- };
-
- //------------------------------------------------------------path_flags_e
- enum path_flags_e
- {
- path_flags_none = 0, //----path_flags_none
- path_flags_ccw = 0x10, //----path_flags_ccw
- path_flags_cw = 0x20, //----path_flags_cw
- path_flags_close = 0x40, //----path_flags_close
- path_flags_mask = 0xF0 //----path_flags_mask
- };
-
- //---------------------------------------------------------------is_vertex
- inline bool is_vertex(unsigned c)
- {
- return c >= path_cmd_move_to && c < path_cmd_end_poly;
- }
-
- //--------------------------------------------------------------is_drawing
- inline bool is_drawing(unsigned c)
- {
- return c >= path_cmd_line_to && c < path_cmd_end_poly;
- }
-
- //-----------------------------------------------------------------is_stop
- inline bool is_stop(unsigned c)
- {
- return c == path_cmd_stop;
- }
-
- //--------------------------------------------------------------is_move_to
- inline bool is_move_to(unsigned c)
- {
- return c == path_cmd_move_to;
- }
-
- //--------------------------------------------------------------is_line_to
- inline bool is_line_to(unsigned c)
- {
- return c == path_cmd_line_to;
- }
-
- //----------------------------------------------------------------is_curve
- inline bool is_curve(unsigned c)
- {
- return c == path_cmd_curve3 || c == path_cmd_curve4;
- }
-
- //---------------------------------------------------------------is_curve3
- inline bool is_curve3(unsigned c)
- {
- return c == path_cmd_curve3;
- }
-
- //---------------------------------------------------------------is_curve4
- inline bool is_curve4(unsigned c)
- {
- return c == path_cmd_curve4;
- }
-
- //-------------------------------------------------------------is_end_poly
- inline bool is_end_poly(unsigned c)
- {
- return (c & path_cmd_mask) == path_cmd_end_poly;
- }
-
- //----------------------------------------------------------------is_close
- inline bool is_close(unsigned c)
- {
- return (c & ~(path_flags_cw | path_flags_ccw)) ==
- (path_cmd_end_poly | path_flags_close);
- }
-
- //------------------------------------------------------------is_next_poly
- inline bool is_next_poly(unsigned c)
- {
- return is_stop(c) || is_move_to(c) || is_end_poly(c);
- }
-
- //-------------------------------------------------------------------is_cw
- inline bool is_cw(unsigned c)
- {
- return (c & path_flags_cw) != 0;
- }
-
- //------------------------------------------------------------------is_ccw
- inline bool is_ccw(unsigned c)
- {
- return (c & path_flags_ccw) != 0;
- }
-
- //-------------------------------------------------------------is_oriented
- inline bool is_oriented(unsigned c)
- {
- return (c & (path_flags_cw | path_flags_ccw)) != 0;
- }
-
- //---------------------------------------------------------------is_closed
- inline bool is_closed(unsigned c)
- {
- return (c & path_flags_close) != 0;
- }
-
- //----------------------------------------------------------get_close_flag
- inline unsigned get_close_flag(unsigned c)
- {
- return c & path_flags_close;
- }
-
- //-------------------------------------------------------clear_orientation
- inline unsigned clear_orientation(unsigned c)
- {
- return c & ~(path_flags_cw | path_flags_ccw);
- }
-
- //---------------------------------------------------------get_orientation
- inline unsigned get_orientation(unsigned c)
- {
- return c & (path_flags_cw | path_flags_ccw);
- }
-
- //---------------------------------------------------------set_orientation
- inline unsigned set_orientation(unsigned c, unsigned o)
- {
- return clear_orientation(c) | o;
- }
-
- //--------------------------------------------------------------point_base
- template struct point_base
- {
- typedef T value_type;
- T x,y;
- point_base() {}
- point_base(T x_, T y_) : x(x_), y(y_) {}
- };
- typedef point_base point_i; //-----point_i
- typedef point_base point_f; //-----point_f
- typedef point_base point_d; //-----point_d
-
- //-------------------------------------------------------------vertex_base
- template struct vertex_base
- {
- typedef T value_type;
- T x,y;
- unsigned cmd;
- vertex_base() {}
- vertex_base(T x_, T y_, unsigned cmd_) : x(x_), y(y_), cmd(cmd_) {}
- };
- typedef vertex_base vertex_i; //-----vertex_i
- typedef vertex_base vertex_f; //-----vertex_f
- typedef vertex_base vertex_d; //-----vertex_d
-
- //----------------------------------------------------------------row_info
- template struct row_info
- {
- int x1, x2;
- T* ptr;
- row_info() {}
- row_info(int x1_, int x2_, T* ptr_) : x1(x1_), x2(x2_), ptr(ptr_) {}
- };
-
- //----------------------------------------------------------const_row_info
- template struct const_row_info
- {
- int x1, x2;
- const T* ptr;
- const_row_info() {}
- const_row_info(int x1_, int x2_, const T* ptr_) :
- x1(x1_), x2(x2_), ptr(ptr_) {}
- };
-
- //------------------------------------------------------------is_equal_eps
- template inline bool is_equal_eps(T v1, T v2, T epsilon)
- {
- return fabs(v1 - v2) <= double(epsilon);
- }
-}
-
-
-#endif
-
diff --git a/kiva/gl/src/agg/agg_bezier_arc.cpp b/kiva/gl/src/agg/agg_bezier_arc.cpp
deleted file mode 100644
index c499c23a8..000000000
--- a/kiva/gl/src/agg/agg_bezier_arc.cpp
+++ /dev/null
@@ -1,255 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-//
-// Arc generator. Produces at most 4 consecutive cubic bezier curves, i.e.,
-// 4, 7, 10, or 13 vertices.
-//
-//----------------------------------------------------------------------------
-
-#include
-#include "agg_bezier_arc.h"
-
-namespace kiva_gl_agg
-{
-
- // This epsilon is used to prevent us from adding degenerate curves
- // (converging to a single point).
- // The value isn't very critical. Function arc_to_bezier() has a limit
- // of the sweep_angle. If fabs(sweep_angle) exceeds pi/2 the curve
- // becomes inaccurate. But slight exceeding is quite appropriate.
- //-------------------------------------------------bezier_arc_angle_epsilon
- const double bezier_arc_angle_epsilon = 0.01;
-
- //------------------------------------------------------------arc_to_bezier
- void arc_to_bezier(double cx, double cy, double rx, double ry,
- double start_angle, double sweep_angle,
- double* curve)
- {
- double x0 = cos(sweep_angle / 2.0);
- double y0 = sin(sweep_angle / 2.0);
- double tx = (1.0 - x0) * 4.0 / 3.0;
- double ty = y0 - tx * x0 / y0;
- double px[4];
- double py[4];
- px[0] = x0;
- py[0] = -y0;
- px[1] = x0 + tx;
- py[1] = -ty;
- px[2] = x0 + tx;
- py[2] = ty;
- px[3] = x0;
- py[3] = y0;
-
- double sn = sin(start_angle + sweep_angle / 2.0);
- double cs = cos(start_angle + sweep_angle / 2.0);
-
- unsigned i;
- for(i = 0; i < 4; i++)
- {
- curve[i * 2] = cx + rx * (px[i] * cs - py[i] * sn);
- curve[i * 2 + 1] = cy + ry * (px[i] * sn + py[i] * cs);
- }
- }
-
-
-
- //------------------------------------------------------------------------
- void bezier_arc::init(double x, double y,
- double rx, double ry,
- double start_angle,
- double sweep_angle)
- {
- start_angle = fmod(start_angle, 2.0 * pi);
- if(sweep_angle >= 2.0 * pi) sweep_angle = 2.0 * pi;
- if(sweep_angle <= -2.0 * pi) sweep_angle = -2.0 * pi;
-
- if(fabs(sweep_angle) < 1e-10)
- {
- m_num_vertices = 4;
- m_cmd = path_cmd_line_to;
- m_vertices[0] = x + rx * cos(start_angle);
- m_vertices[1] = y + ry * sin(start_angle);
- m_vertices[2] = x + rx * cos(start_angle + sweep_angle);
- m_vertices[3] = y + ry * sin(start_angle + sweep_angle);
- return;
- }
-
- double total_sweep = 0.0;
- double local_sweep = 0.0;
- double prev_sweep;
- m_num_vertices = 2;
- m_cmd = path_cmd_curve4;
- bool done = false;
- do
- {
- if(sweep_angle < 0.0)
- {
- prev_sweep = total_sweep;
- local_sweep = -pi * 0.5;
- total_sweep -= pi * 0.5;
- if(total_sweep <= sweep_angle + bezier_arc_angle_epsilon)
- {
- local_sweep = sweep_angle - prev_sweep;
- done = true;
- }
- }
- else
- {
- prev_sweep = total_sweep;
- local_sweep = pi * 0.5;
- total_sweep += pi * 0.5;
- if(total_sweep >= sweep_angle - bezier_arc_angle_epsilon)
- {
- local_sweep = sweep_angle - prev_sweep;
- done = true;
- }
- }
-
- arc_to_bezier(x, y, rx, ry,
- start_angle,
- local_sweep,
- m_vertices + m_num_vertices - 2);
-
- m_num_vertices += 6;
- start_angle += local_sweep;
- }
- while(!done && m_num_vertices < 26);
- }
-
-
-
-
- //--------------------------------------------------------------------
- void bezier_arc_svg::init(double x0, double y0,
- double rx, double ry,
- double angle,
- bool large_arc_flag,
- bool sweep_flag,
- double x2, double y2)
- {
- m_radii_ok = true;
-
- if(rx < 0.0) rx = -rx;
- if(ry < 0.0) ry = -rx;
-
- // Calculate the middle point between
- // the current and the final points
- //------------------------
- double dx2 = (x0 - x2) / 2.0;
- double dy2 = (y0 - y2) / 2.0;
-
- double cos_a = cos(angle);
- double sin_a = sin(angle);
-
- // Calculate (x1, y1)
- //------------------------
- double x1 = cos_a * dx2 + sin_a * dy2;
- double y1 = -sin_a * dx2 + cos_a * dy2;
-
- // Ensure radii are large enough
- //------------------------
- double prx = rx * rx;
- double pry = ry * ry;
- double px1 = x1 * x1;
- double py1 = y1 * y1;
-
- // Check that radii are large enough
- //------------------------
- double radii_check = px1/prx + py1/pry;
- if(radii_check > 1.0)
- {
- rx = sqrt(radii_check) * rx;
- ry = sqrt(radii_check) * ry;
- prx = rx * rx;
- pry = ry * ry;
- if(radii_check > 10.0) m_radii_ok = false;
- }
-
- // Calculate (cx1, cy1)
- //------------------------
- double sign = (large_arc_flag == sweep_flag) ? -1.0 : 1.0;
- double sq = (prx*pry - prx*py1 - pry*px1) / (prx*py1 + pry*px1);
- double coef = sign * sqrt((sq < 0) ? 0 : sq);
- double cx1 = coef * ((rx * y1) / ry);
- double cy1 = coef * -((ry * x1) / rx);
-
- //
- // Calculate (cx, cy) from (cx1, cy1)
- //------------------------
- double sx2 = (x0 + x2) / 2.0;
- double sy2 = (y0 + y2) / 2.0;
- double cx = sx2 + (cos_a * cx1 - sin_a * cy1);
- double cy = sy2 + (sin_a * cx1 + cos_a * cy1);
-
- // Calculate the start_angle (angle1) and the sweep_angle (dangle)
- //------------------------
- double ux = (x1 - cx1) / rx;
- double uy = (y1 - cy1) / ry;
- double vx = (-x1 - cx1) / rx;
- double vy = (-y1 - cy1) / ry;
- double p, n;
-
- // Calculate the angle start
- //------------------------
- n = sqrt(ux*ux + uy*uy);
- p = ux; // (1 * ux) + (0 * uy)
- sign = (uy < 0) ? -1.0 : 1.0;
- double v = p / n;
- if(v < -1.0) v = -1.0;
- if(v > 1.0) v = 1.0;
- double start_angle = sign * acos(v);
-
- // Calculate the sweep angle
- //------------------------
- n = sqrt((ux*ux + uy*uy) * (vx*vx + vy*vy));
- p = ux * vx + uy * vy;
- sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0;
- v = p / n;
- if(v < -1.0) v = -1.0;
- if(v > 1.0) v = 1.0;
- double sweep_angle = sign * acos(v);
- if(!sweep_flag && sweep_angle > 0)
- {
- sweep_angle -= pi * 2.0;
- }
- else
- if (sweep_flag && sweep_angle < 0)
- {
- sweep_angle += pi * 2.0;
- }
-
- // We can now build and transform the resulting arc
- //------------------------
- m_arc.init(0.0, 0.0, rx, ry, start_angle, sweep_angle);
- trans_affine mtx = trans_affine_rotation(angle);
- mtx *= trans_affine_translation(cx, cy);
-
- for(unsigned i = 2; i < m_arc.num_vertices()-2; i += 2)
- {
- mtx.transform(m_arc.vertices() + i, m_arc.vertices() + i + 1);
- }
-
- // We must make sure that the starting and ending points
- // exactly coincide with the initial (x0,y0) and (x2,y2)
- m_arc.vertices()[0] = x0;
- m_arc.vertices()[1] = y0;
- if(m_arc.num_vertices() > 2)
- {
- m_arc.vertices()[m_arc.num_vertices() - 2] = x2;
- m_arc.vertices()[m_arc.num_vertices() - 1] = y2;
- }
- }
-
-}
diff --git a/kiva/gl/src/agg/agg_bezier_arc.h b/kiva/gl/src/agg/agg_bezier_arc.h
deleted file mode 100644
index 85fba1c0e..000000000
--- a/kiva/gl/src/agg/agg_bezier_arc.h
+++ /dev/null
@@ -1,154 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-//
-// Arc generator. Produces at most 4 consecutive cubic bezier curves, i.e.,
-// 4, 7, 10, or 13 vertices.
-//
-//----------------------------------------------------------------------------
-
-#ifndef AGG_BEZIER_ARC_INCLUDED
-#define AGG_BEZIER_ARC_INCLUDED
-
-#include "agg_conv_transform.h"
-
-namespace kiva_gl_agg
-{
-
- //-----------------------------------------------------------------------
- void arc_to_bezier(double cx, double cy, double rx, double ry,
- double start_angle, double sweep_angle,
- double* curve);
-
- //==============================================================bezier_arc
- //
- // See implemantaion agg_bezier_arc.cpp
- //
- class bezier_arc
- {
- public:
- //--------------------------------------------------------------------
- bezier_arc() : m_vertex(26), m_num_vertices(0), m_cmd(path_cmd_line_to) {}
- bezier_arc(double x, double y,
- double rx, double ry,
- double start_angle,
- double sweep_angle)
- {
- init(x, y, rx, ry, start_angle, sweep_angle);
- }
-
- //--------------------------------------------------------------------
- void init(double x, double y,
- double rx, double ry,
- double start_angle,
- double sweep_angle);
-
- //--------------------------------------------------------------------
- void rewind(unsigned)
- {
- m_vertex = 0;
- }
-
- //--------------------------------------------------------------------
- unsigned vertex(double* x, double* y)
- {
- if(m_vertex >= m_num_vertices) return path_cmd_stop;
- *x = m_vertices[m_vertex];
- *y = m_vertices[m_vertex + 1];
- m_vertex += 2;
- return (m_vertex == 2) ? path_cmd_move_to : m_cmd;
- }
-
- // Supplemantary functions. num_vertices() actually returns doubled
- // number of vertices. That is, for 1 vertex it returns 2.
- //--------------------------------------------------------------------
- unsigned num_vertices() const { return m_num_vertices; }
- const double* vertices() const { return m_vertices; }
- double* vertices() { return m_vertices; }
-
- private:
- unsigned m_vertex;
- unsigned m_num_vertices;
- double m_vertices[26];
- unsigned m_cmd;
- };
-
-
-
- //==========================================================bezier_arc_svg
- // Compute an SVG-style bezier arc.
- //
- // Computes an elliptical arc from (x1, y1) to (x2, y2). The size and
- // orientation of the ellipse are defined by two radii (rx, ry)
- // and an x-axis-rotation, which indicates how the ellipse as a whole
- // is rotated relative to the current coordinate system. The center
- // (cx, cy) of the ellipse is calculated automatically to satisfy the
- // constraints imposed by the other parameters.
- // large-arc-flag and sweep-flag contribute to the automatic calculations
- // and help determine how the arc is drawn.
- class bezier_arc_svg
- {
- public:
- //--------------------------------------------------------------------
- bezier_arc_svg() : m_arc(), m_radii_ok(false) {}
-
- bezier_arc_svg(double x1, double y1,
- double rx, double ry,
- double angle,
- bool large_arc_flag,
- bool sweep_flag,
- double x2, double y2) :
- m_arc(), m_radii_ok(false)
- {
- init(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2);
- }
-
- //--------------------------------------------------------------------
- void init(double x1, double y1,
- double rx, double ry,
- double angle,
- bool large_arc_flag,
- bool sweep_flag,
- double x2, double y2);
-
- //--------------------------------------------------------------------
- bool radii_ok() const { return m_radii_ok; }
-
- //--------------------------------------------------------------------
- void rewind(unsigned)
- {
- m_arc.rewind(0);
- }
-
- //--------------------------------------------------------------------
- unsigned vertex(double* x, double* y)
- {
- return m_arc.vertex(x, y);
- }
-
- // Supplemantary functions. num_vertices() actually returns doubled
- // number of vertices. That is, for 1 vertex it returns 2.
- //--------------------------------------------------------------------
- unsigned num_vertices() const { return m_arc.num_vertices(); }
- const double* vertices() const { return m_arc.vertices(); }
- double* vertices() { return m_arc.vertices(); }
-
- private:
- bezier_arc m_arc;
- bool m_radii_ok;
- };
-
-}
-
-#endif
diff --git a/kiva/gl/src/agg/agg_color_rgba.h b/kiva/gl/src/agg/agg_color_rgba.h
deleted file mode 100644
index f2987884a..000000000
--- a/kiva/gl/src/agg/agg_color_rgba.h
+++ /dev/null
@@ -1,1351 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-//
-// Adaptation for high precision colors has been sponsored by
-// Liberty Technology Systems, Inc., visit http://lib-sys.com
-//
-// Liberty Technology Systems, Inc. is the provider of
-// PostScript and PDF technology for software developers.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-
-#ifndef AGG_COLOR_RGBA_INCLUDED
-#define AGG_COLOR_RGBA_INCLUDED
-
-#include
-#include "agg_basics.h"
-#include "agg_gamma_lut.h"
-
-namespace kiva_gl_agg
-{
- // Supported component orders for RGB and RGBA pixel formats
- //=======================================================================
- struct order_rgb { enum rgb_e { R=0, G=1, B=2, N=3 }; };
- struct order_bgr { enum bgr_e { B=0, G=1, R=2, N=3 }; };
- struct order_rgba { enum rgba_e { R=0, G=1, B=2, A=3, N=4 }; };
- struct order_argb { enum argb_e { A=0, R=1, G=2, B=3, N=4 }; };
- struct order_abgr { enum abgr_e { A=0, B=1, G=2, R=3, N=4 }; };
- struct order_bgra { enum bgra_e { B=0, G=1, R=2, A=3, N=4 }; };
-
- // Colorspace tag types.
- struct linear {};
- struct sRGB {};
-
- //====================================================================rgba
- struct rgba
- {
- typedef double value_type;
-
- double r;
- double g;
- double b;
- double a;
-
- //--------------------------------------------------------------------
- rgba() {}
-
- //--------------------------------------------------------------------
- rgba(double r_, double g_, double b_, double a_=1.0) :
- r(r_), g(g_), b(b_), a(a_) {}
-
- //--------------------------------------------------------------------
- rgba(const rgba& c, double a_) : r(c.r), g(c.g), b(c.b), a(a_) {}
-
- //--------------------------------------------------------------------
- rgba& clear()
- {
- r = g = b = a = 0;
- return *this;
- }
-
- //--------------------------------------------------------------------
- rgba& transparent()
- {
- a = 0;
- return *this;
- }
-
- //--------------------------------------------------------------------
- rgba& opacity(double a_)
- {
- if (a_ < 0) a = 0;
- else if (a_ > 1) a = 1;
- else a = a_;
- return *this;
- }
-
- //--------------------------------------------------------------------
- double opacity() const
- {
- return a;
- }
-
- //--------------------------------------------------------------------
- rgba& premultiply()
- {
- r *= a;
- g *= a;
- b *= a;
- return *this;
- }
-
- //--------------------------------------------------------------------
- rgba& premultiply(double a_)
- {
- if (a <= 0 || a_ <= 0)
- {
- r = g = b = a = 0;
- }
- else
- {
- a_ /= a;
- r *= a_;
- g *= a_;
- b *= a_;
- a = a_;
- }
- return *this;
- }
-
- //--------------------------------------------------------------------
- rgba& demultiply()
- {
- if (a == 0)
- {
- r = g = b = 0;
- }
- else
- {
- double a_ = 1.0 / a;
- r *= a_;
- g *= a_;
- b *= a_;
- }
- return *this;
- }
-
-
- //--------------------------------------------------------------------
- rgba gradient(rgba c, double k) const
- {
- rgba ret;
- ret.r = r + (c.r - r) * k;
- ret.g = g + (c.g - g) * k;
- ret.b = b + (c.b - b) * k;
- ret.a = a + (c.a - a) * k;
- return ret;
- }
-
- rgba& operator+=(const rgba& c)
- {
- r += c.r;
- g += c.g;
- b += c.b;
- a += c.a;
- return *this;
- }
-
- rgba& operator*=(double k)
- {
- r *= k;
- g *= k;
- b *= k;
- a *= k;
- return *this;
- }
-
- //--------------------------------------------------------------------
- static rgba no_color() { return rgba(0,0,0,0); }
-
- //--------------------------------------------------------------------
- static rgba from_wavelength(double wl, double gamma = 1.0);
-
- //--------------------------------------------------------------------
- explicit rgba(double wavelen, double gamma=1.0)
- {
- *this = from_wavelength(wavelen, gamma);
- }
-
- };
-
- inline rgba operator+(const rgba& a, const rgba& b)
- {
- return rgba(a) += b;
- }
-
- inline rgba operator*(const rgba& a, double b)
- {
- return rgba(a) *= b;
- }
-
- //------------------------------------------------------------------------
- inline rgba rgba::from_wavelength(double wl, double gamma)
- {
- rgba t(0.0, 0.0, 0.0);
-
- if (wl >= 380.0 && wl <= 440.0)
- {
- t.r = -1.0 * (wl - 440.0) / (440.0 - 380.0);
- t.b = 1.0;
- }
- else if (wl >= 440.0 && wl <= 490.0)
- {
- t.g = (wl - 440.0) / (490.0 - 440.0);
- t.b = 1.0;
- }
- else if (wl >= 490.0 && wl <= 510.0)
- {
- t.g = 1.0;
- t.b = -1.0 * (wl - 510.0) / (510.0 - 490.0);
- }
- else if (wl >= 510.0 && wl <= 580.0)
- {
- t.r = (wl - 510.0) / (580.0 - 510.0);
- t.g = 1.0;
- }
- else if (wl >= 580.0 && wl <= 645.0)
- {
- t.r = 1.0;
- t.g = -1.0 * (wl - 645.0) / (645.0 - 580.0);
- }
- else if (wl >= 645.0 && wl <= 780.0)
- {
- t.r = 1.0;
- }
-
- double s = 1.0;
- if (wl > 700.0) s = 0.3 + 0.7 * (780.0 - wl) / (780.0 - 700.0);
- else if (wl < 420.0) s = 0.3 + 0.7 * (wl - 380.0) / (420.0 - 380.0);
-
- t.r = pow(t.r * s, gamma);
- t.g = pow(t.g * s, gamma);
- t.b = pow(t.b * s, gamma);
- return t;
- }
-
- inline rgba rgba_pre(double r, double g, double b, double a)
- {
- return rgba(r, g, b, a).premultiply();
- }
-
-
- //===================================================================rgba8
- template
- struct rgba8T
- {
- typedef int8u value_type;
- typedef int32u calc_type;
- typedef int32 long_type;
- enum base_scale_e
- {
- base_shift = 8,
- base_scale = 1 << base_shift,
- base_mask = base_scale - 1,
- base_MSB = 1 << (base_shift - 1)
- };
- typedef rgba8T self_type;
-
-
- value_type r;
- value_type g;
- value_type b;
- value_type a;
-
- static void convert(rgba8T& dst, const rgba8T& src)
- {
- dst.r = sRGB_conv::rgb_from_sRGB(src.r);
- dst.g = sRGB_conv::rgb_from_sRGB(src.g);
- dst.b = sRGB_conv::rgb_from_sRGB(src.b);
- dst.a = src.a;
- }
-
- static void convert(rgba8T& dst, const rgba8T& src)
- {
- dst.r = sRGB_conv::rgb_to_sRGB(src.r);
- dst.g = sRGB_conv::rgb_to_sRGB(src.g);
- dst.b = sRGB_conv::rgb_to_sRGB(src.b);
- dst.a = src.a;
- }
-
- static void convert(rgba8T& dst, const rgba& src)
- {
- dst.r = value_type(uround(src.r * base_mask));
- dst.g = value_type(uround(src.g * base_mask));
- dst.b = value_type(uround(src.b * base_mask));
- dst.a = value_type(uround(src.a * base_mask));
- }
-
- static void convert(rgba8T& dst, const rgba& src)
- {
- // Use the "float" table.
- dst.r = sRGB_conv::rgb_to_sRGB(float(src.r));
- dst.g = sRGB_conv::rgb_to_sRGB(float(src.g));
- dst.b = sRGB_conv::rgb_to_sRGB(float(src.b));
- dst.a = sRGB_conv::alpha_to_sRGB(float(src.a));
- }
-
- static void convert(rgba& dst, const rgba8T& src)
- {
- dst.r = src.r / 255.0;
- dst.g = src.g / 255.0;
- dst.b = src.b / 255.0;
- dst.a = src.a / 255.0;
- }
-
- static void convert(rgba& dst, const rgba8T& src)
- {
- // Use the "float" table.
- dst.r = sRGB_conv::rgb_from_sRGB(src.r);
- dst.g = sRGB_conv::rgb_from_sRGB(src.g);
- dst.b = sRGB_conv::rgb_from_sRGB(src.b);
- dst.a = sRGB_conv::alpha_from_sRGB(src.a);
- }
-
- //--------------------------------------------------------------------
- rgba8T() {}
-
- //--------------------------------------------------------------------
- rgba8T(unsigned r_, unsigned g_, unsigned b_, unsigned a_ = base_mask) :
- r(value_type(r_)),
- g(value_type(g_)),
- b(value_type(b_)),
- a(value_type(a_)) {}
-
- //--------------------------------------------------------------------
- rgba8T(const rgba& c)
- {
- convert(*this, c);
- }
-
- //--------------------------------------------------------------------
- rgba8T(const self_type& c, unsigned a_) :
- r(c.r), g(c.g), b(c.b), a(value_type(a_)) {}
-
- //--------------------------------------------------------------------
- template
- rgba8T(const rgba8T& c)
- {
- convert(*this, c);
- }
-
- //--------------------------------------------------------------------
- operator rgba() const
- {
- rgba c;
- convert(c, *this);
- return c;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE double to_double(value_type a)
- {
- return double(a) / base_mask;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type from_double(double a)
- {
- return value_type(uround(a * base_mask));
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type empty_value()
- {
- return 0;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type full_value()
- {
- return base_mask;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE bool is_transparent() const
- {
- return a == 0;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE bool is_opaque() const
- {
- return a == base_mask;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type invert(value_type x)
- {
- return base_mask - x;
- }
-
- //--------------------------------------------------------------------
- // Fixed-point multiply, exact over int8u.
- static AGG_INLINE value_type multiply(value_type a, value_type b)
- {
- calc_type t = a * b + base_MSB;
- return value_type(((t >> base_shift) + t) >> base_shift);
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type demultiply(value_type a, value_type b)
- {
- if (a * b == 0)
- {
- return 0;
- }
- else if (a >= b)
- {
- return base_mask;
- }
- else return value_type((a * base_mask + (b >> 1)) / b);
- }
-
- //--------------------------------------------------------------------
- template
- static AGG_INLINE T downscale(T a)
- {
- return a >> base_shift;
- }
-
- //--------------------------------------------------------------------
- template
- static AGG_INLINE T downshift(T a, unsigned n)
- {
- return a >> n;
- }
-
- //--------------------------------------------------------------------
- // Fixed-point multiply, exact over int8u.
- // Specifically for multiplying a color component by a cover.
- static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
- {
- return multiply(a, b);
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE cover_type scale_cover(cover_type a, value_type b)
- {
- return multiply(b, a);
- }
-
- //--------------------------------------------------------------------
- // Interpolate p to q by a, assuming q is premultiplied by a.
- static AGG_INLINE value_type prelerp(value_type p, value_type q, value_type a)
- {
- return p + q - multiply(p, a);
- }
-
- //--------------------------------------------------------------------
- // Interpolate p to q by a.
- static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
- {
- int t = (q - p) * a + base_MSB - (p > q);
- return value_type(p + (((t >> base_shift) + t) >> base_shift));
- }
-
- //--------------------------------------------------------------------
- self_type& clear()
- {
- r = g = b = a = 0;
- return *this;
- }
-
- //--------------------------------------------------------------------
- self_type& transparent()
- {
- a = 0;
- return *this;
- }
-
- //--------------------------------------------------------------------
- self_type& opacity(double a_)
- {
- if (a_ < 0) a = 0;
- else if (a_ > 1) a = 1;
- else a = (value_type)uround(a_ * double(base_mask));
- return *this;
- }
-
- //--------------------------------------------------------------------
- double opacity() const
- {
- return double(a) / double(base_mask);
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& premultiply()
- {
- if (a != base_mask)
- {
- if (a == 0)
- {
- r = g = b = 0;
- }
- else
- {
- r = multiply(r, a);
- g = multiply(g, a);
- b = multiply(b, a);
- }
- }
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& premultiply(unsigned a_)
- {
- if (a != base_mask || a_ < base_mask)
- {
- if (a == 0 || a_ == 0)
- {
- r = g = b = a = 0;
- }
- else
- {
- calc_type r_ = (calc_type(r) * a_) / a;
- calc_type g_ = (calc_type(g) * a_) / a;
- calc_type b_ = (calc_type(b) * a_) / a;
- r = value_type((r_ > a_) ? a_ : r_);
- g = value_type((g_ > a_) ? a_ : g_);
- b = value_type((b_ > a_) ? a_ : b_);
- a = value_type(a_);
- }
- }
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& demultiply()
- {
- if (a < base_mask)
- {
- if (a == 0)
- {
- r = g = b = 0;
- }
- else
- {
- calc_type r_ = (calc_type(r) * base_mask) / a;
- calc_type g_ = (calc_type(g) * base_mask) / a;
- calc_type b_ = (calc_type(b) * base_mask) / a;
- r = value_type((r_ > calc_type(base_mask)) ? calc_type(base_mask) : r_);
- g = value_type((g_ > calc_type(base_mask)) ? calc_type(base_mask) : g_);
- b = value_type((b_ > calc_type(base_mask)) ? calc_type(base_mask) : b_);
- }
- }
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type gradient(const self_type& c, double k) const
- {
- self_type ret;
- calc_type ik = uround(k * base_mask);
- ret.r = lerp(r, c.r, ik);
- ret.g = lerp(g, c.g, ik);
- ret.b = lerp(b, c.b, ik);
- ret.a = lerp(a, c.a, ik);
- return ret;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE void add(const self_type& c, unsigned cover)
- {
- calc_type cr, cg, cb, ca;
- if (cover == cover_mask)
- {
- if (c.a == base_mask)
- {
- *this = c;
- return;
- }
- else
- {
- cr = r + c.r;
- cg = g + c.g;
- cb = b + c.b;
- ca = a + c.a;
- }
- }
- else
- {
- cr = r + mult_cover(c.r, cover);
- cg = g + mult_cover(c.g, cover);
- cb = b + mult_cover(c.b, cover);
- ca = a + mult_cover(c.a, cover);
- }
- r = (value_type)((cr > calc_type(base_mask)) ? calc_type(base_mask) : cr);
- g = (value_type)((cg > calc_type(base_mask)) ? calc_type(base_mask) : cg);
- b = (value_type)((cb > calc_type(base_mask)) ? calc_type(base_mask) : cb);
- a = (value_type)((ca > calc_type(base_mask)) ? calc_type(base_mask) : ca);
- }
-
- //--------------------------------------------------------------------
- template
- AGG_INLINE void apply_gamma_dir(const GammaLUT& gamma)
- {
- r = gamma.dir(r);
- g = gamma.dir(g);
- b = gamma.dir(b);
- }
-
- //--------------------------------------------------------------------
- template
- AGG_INLINE void apply_gamma_inv(const GammaLUT& gamma)
- {
- r = gamma.inv(r);
- g = gamma.inv(g);
- b = gamma.inv(b);
- }
-
- //--------------------------------------------------------------------
- static self_type no_color() { return self_type(0,0,0,0); }
-
- //--------------------------------------------------------------------
- static self_type from_wavelength(double wl, double gamma = 1.0)
- {
- return self_type(rgba::from_wavelength(wl, gamma));
- }
- };
-
- typedef rgba8T rgba8;
- typedef rgba8T srgba8;
-
-
- //-------------------------------------------------------------rgb8_packed
- inline rgba8 rgb8_packed(unsigned v)
- {
- return rgba8((v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF);
- }
-
- //-------------------------------------------------------------bgr8_packed
- inline rgba8 bgr8_packed(unsigned v)
- {
- return rgba8(v & 0xFF, (v >> 8) & 0xFF, (v >> 16) & 0xFF);
- }
-
- //------------------------------------------------------------argb8_packed
- inline rgba8 argb8_packed(unsigned v)
- {
- return rgba8((v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF, v >> 24);
- }
-
- //---------------------------------------------------------rgba8_gamma_dir
- template
- rgba8 rgba8_gamma_dir(rgba8 c, const GammaLUT& gamma)
- {
- return rgba8(gamma.dir(c.r), gamma.dir(c.g), gamma.dir(c.b), c.a);
- }
-
- //---------------------------------------------------------rgba8_gamma_inv
- template
- rgba8 rgba8_gamma_inv(rgba8 c, const GammaLUT& gamma)
- {
- return rgba8(gamma.inv(c.r), gamma.inv(c.g), gamma.inv(c.b), c.a);
- }
-
-
-
- //==================================================================rgba16
- struct rgba16
- {
- typedef int16u value_type;
- typedef int32u calc_type;
- typedef int64 long_type;
- enum base_scale_e
- {
- base_shift = 16,
- base_scale = 1 << base_shift,
- base_mask = base_scale - 1,
- base_MSB = 1 << (base_shift - 1)
- };
- typedef rgba16 self_type;
-
- value_type r;
- value_type g;
- value_type b;
- value_type a;
-
- //--------------------------------------------------------------------
- rgba16() {}
-
- //--------------------------------------------------------------------
- rgba16(unsigned r_, unsigned g_, unsigned b_, unsigned a_=base_mask) :
- r(value_type(r_)),
- g(value_type(g_)),
- b(value_type(b_)),
- a(value_type(a_)) {}
-
- //--------------------------------------------------------------------
- rgba16(const self_type& c, unsigned a_) :
- r(c.r), g(c.g), b(c.b), a(value_type(a_)) {}
-
- //--------------------------------------------------------------------
- rgba16(const rgba& c) :
- r((value_type)uround(c.r * double(base_mask))),
- g((value_type)uround(c.g * double(base_mask))),
- b((value_type)uround(c.b * double(base_mask))),
- a((value_type)uround(c.a * double(base_mask))) {}
-
- //--------------------------------------------------------------------
- rgba16(const rgba8& c) :
- r(value_type((value_type(c.r) << 8) | c.r)),
- g(value_type((value_type(c.g) << 8) | c.g)),
- b(value_type((value_type(c.b) << 8) | c.b)),
- a(value_type((value_type(c.a) << 8) | c.a)) {}
-
- //--------------------------------------------------------------------
- rgba16(const srgba8& c) :
- r(sRGB_conv::rgb_from_sRGB(c.r)),
- g(sRGB_conv::rgb_from_sRGB(c.g)),
- b(sRGB_conv::rgb_from_sRGB(c.b)),
- a(sRGB_conv::alpha_from_sRGB(c.a)) {}
-
- //--------------------------------------------------------------------
- operator rgba() const
- {
- return rgba(
- r / 65535.0,
- g / 65535.0,
- b / 65535.0,
- a / 65535.0);
- }
-
- //--------------------------------------------------------------------
- operator rgba8() const
- {
- return rgba8(r >> 8, g >> 8, b >> 8, a >> 8);
- }
-
- //--------------------------------------------------------------------
- operator srgba8() const
- {
- // Return (non-premultiplied) sRGB values.
- return srgba8(
- sRGB_conv::rgb_to_sRGB(r),
- sRGB_conv::rgb_to_sRGB(g),
- sRGB_conv::rgb_to_sRGB(b),
- sRGB_conv::alpha_to_sRGB(a));
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE double to_double(value_type a)
- {
- return double(a) / base_mask;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type from_double(double a)
- {
- return value_type(uround(a * base_mask));
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type empty_value()
- {
- return 0;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type full_value()
- {
- return base_mask;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE bool is_transparent() const
- {
- return a == 0;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE bool is_opaque() const
- {
- return a == base_mask;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type invert(value_type x)
- {
- return base_mask - x;
- }
-
- //--------------------------------------------------------------------
- // Fixed-point multiply, exact over int16u.
- static AGG_INLINE value_type multiply(value_type a, value_type b)
- {
- calc_type t = a * b + base_MSB;
- return value_type(((t >> base_shift) + t) >> base_shift);
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type demultiply(value_type a, value_type b)
- {
- if (a * b == 0)
- {
- return 0;
- }
- else if (a >= b)
- {
- return base_mask;
- }
- else return value_type((a * base_mask + (b >> 1)) / b);
- }
-
- //--------------------------------------------------------------------
- template
- static AGG_INLINE T downscale(T a)
- {
- return a >> base_shift;
- }
-
- //--------------------------------------------------------------------
- template
- static AGG_INLINE T downshift(T a, unsigned n)
- {
- return a >> n;
- }
-
- //--------------------------------------------------------------------
- // Fixed-point multiply, almost exact over int16u.
- // Specifically for multiplying a color component by a cover.
- static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
- {
- return multiply(a, (b << 8) | b);
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE cover_type scale_cover(cover_type a, value_type b)
- {
- return multiply((a << 8) | a, b) >> 8;
- }
-
- //--------------------------------------------------------------------
- // Interpolate p to q by a, assuming q is premultiplied by a.
- static AGG_INLINE value_type prelerp(value_type p, value_type q, value_type a)
- {
- return p + q - multiply(p, a);
- }
-
- //--------------------------------------------------------------------
- // Interpolate p to q by a.
- static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
- {
- int t = (q - p) * a + base_MSB - (p > q);
- return value_type(p + (((t >> base_shift) + t) >> base_shift));
- }
-
- //--------------------------------------------------------------------
- self_type& clear()
- {
- r = g = b = a = 0;
- return *this;
- }
-
- //--------------------------------------------------------------------
- self_type& transparent()
- {
- a = 0;
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& opacity(double a_)
- {
- if (a_ < 0) a = 0;
- if (a_ > 1) a = 1;
- a = value_type(uround(a_ * double(base_mask)));
- return *this;
- }
-
- //--------------------------------------------------------------------
- double opacity() const
- {
- return double(a) / double(base_mask);
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& premultiply()
- {
- if (a != base_mask)
- {
- if (a == 0)
- {
- r = g = b = 0;
- }
- else
- {
- r = multiply(r, a);
- g = multiply(g, a);
- b = multiply(b, a);
- }
- }
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& premultiply(unsigned a_)
- {
- if (a < base_mask || a_ < base_mask)
- {
- if (a == 0 || a_ == 0)
- {
- r = g = b = a = 0;
- }
- else
- {
- calc_type r_ = (calc_type(r) * a_) / a;
- calc_type g_ = (calc_type(g) * a_) / a;
- calc_type b_ = (calc_type(b) * a_) / a;
- r = value_type((r_ > a_) ? a_ : r_);
- g = value_type((g_ > a_) ? a_ : g_);
- b = value_type((b_ > a_) ? a_ : b_);
- a = value_type(a_);
- }
- }
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& demultiply()
- {
- if (a < base_mask)
- {
- if (a == 0)
- {
- r = g = b = 0;
- }
- else
- {
- calc_type r_ = (calc_type(r) * base_mask) / a;
- calc_type g_ = (calc_type(g) * base_mask) / a;
- calc_type b_ = (calc_type(b) * base_mask) / a;
- r = value_type((r_ > calc_type(base_mask)) ? calc_type(base_mask) : r_);
- g = value_type((g_ > calc_type(base_mask)) ? calc_type(base_mask) : g_);
- b = value_type((b_ > calc_type(base_mask)) ? calc_type(base_mask) : b_);
- }
- }
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type gradient(const self_type& c, double k) const
- {
- self_type ret;
- calc_type ik = uround(k * base_mask);
- ret.r = lerp(r, c.r, ik);
- ret.g = lerp(g, c.g, ik);
- ret.b = lerp(b, c.b, ik);
- ret.a = lerp(a, c.a, ik);
- return ret;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE void add(const self_type& c, unsigned cover)
- {
- calc_type cr, cg, cb, ca;
- if (cover == cover_mask)
- {
- if (c.a == base_mask)
- {
- *this = c;
- return;
- }
- else
- {
- cr = r + c.r;
- cg = g + c.g;
- cb = b + c.b;
- ca = a + c.a;
- }
- }
- else
- {
- cr = r + mult_cover(c.r, cover);
- cg = g + mult_cover(c.g, cover);
- cb = b + mult_cover(c.b, cover);
- ca = a + mult_cover(c.a, cover);
- }
- r = (value_type)((cr > calc_type(base_mask)) ? calc_type(base_mask) : cr);
- g = (value_type)((cg > calc_type(base_mask)) ? calc_type(base_mask) : cg);
- b = (value_type)((cb > calc_type(base_mask)) ? calc_type(base_mask) : cb);
- a = (value_type)((ca > calc_type(base_mask)) ? calc_type(base_mask) : ca);
- }
-
- //--------------------------------------------------------------------
- template
- AGG_INLINE void apply_gamma_dir(const GammaLUT& gamma)
- {
- r = gamma.dir(r);
- g = gamma.dir(g);
- b = gamma.dir(b);
- }
-
- //--------------------------------------------------------------------
- template
- AGG_INLINE void apply_gamma_inv(const GammaLUT& gamma)
- {
- r = gamma.inv(r);
- g = gamma.inv(g);
- b = gamma.inv(b);
- }
-
- //--------------------------------------------------------------------
- static self_type no_color() { return self_type(0,0,0,0); }
-
- //--------------------------------------------------------------------
- static self_type from_wavelength(double wl, double gamma = 1.0)
- {
- return self_type(rgba::from_wavelength(wl, gamma));
- }
- };
-
-
- //------------------------------------------------------rgba16_gamma_dir
- template
- rgba16 rgba16_gamma_dir(rgba16 c, const GammaLUT& gamma)
- {
- return rgba16(gamma.dir(c.r), gamma.dir(c.g), gamma.dir(c.b), c.a);
- }
-
- //------------------------------------------------------rgba16_gamma_inv
- template
- rgba16 rgba16_gamma_inv(rgba16 c, const GammaLUT& gamma)
- {
- return rgba16(gamma.inv(c.r), gamma.inv(c.g), gamma.inv(c.b), c.a);
- }
-
- //====================================================================rgba32
- struct rgba32
- {
- typedef float value_type;
- typedef double calc_type;
- typedef double long_type;
- typedef rgba32 self_type;
-
- value_type r;
- value_type g;
- value_type b;
- value_type a;
-
- //--------------------------------------------------------------------
- rgba32() {}
-
- //--------------------------------------------------------------------
- rgba32(value_type r_, value_type g_, value_type b_, value_type a_= 1) :
- r(r_), g(g_), b(b_), a(a_) {}
-
- //--------------------------------------------------------------------
- rgba32(const self_type& c, float a_) :
- r(c.r), g(c.g), b(c.b), a(a_) {}
-
- //--------------------------------------------------------------------
- rgba32(const rgba& c) :
- r(value_type(c.r)), g(value_type(c.g)), b(value_type(c.b)), a(value_type(c.a)) {}
-
- //--------------------------------------------------------------------
- rgba32(const rgba8& c) :
- r(value_type(c.r / 255.0)),
- g(value_type(c.g / 255.0)),
- b(value_type(c.b / 255.0)),
- a(value_type(c.a / 255.0)) {}
-
- //--------------------------------------------------------------------
- rgba32(const srgba8& c) :
- r(sRGB_conv::rgb_from_sRGB(c.r)),
- g(sRGB_conv::rgb_from_sRGB(c.g)),
- b(sRGB_conv::rgb_from_sRGB(c.b)),
- a(sRGB_conv::alpha_from_sRGB(c.a)) {}
-
- //--------------------------------------------------------------------
- rgba32(const rgba16& c) :
- r(value_type(c.r / 65535.0)),
- g(value_type(c.g / 65535.0)),
- b(value_type(c.b / 65535.0)),
- a(value_type(c.a / 65535.0)) {}
-
- //--------------------------------------------------------------------
- operator rgba() const
- {
- return rgba(r, g, b, a);
- }
-
- //--------------------------------------------------------------------
- operator rgba8() const
- {
- return rgba8(
- uround(r * 255.0),
- uround(g * 255.0),
- uround(b * 255.0),
- uround(a * 255.0));
- }
-
- //--------------------------------------------------------------------
- operator srgba8() const
- {
- return srgba8(
- sRGB_conv::rgb_to_sRGB(r),
- sRGB_conv::rgb_to_sRGB(g),
- sRGB_conv::rgb_to_sRGB(b),
- sRGB_conv::alpha_to_sRGB(a));
- }
-
- //--------------------------------------------------------------------
- operator rgba16() const
- {
- return rgba8(
- uround(r * 65535.0),
- uround(g * 65535.0),
- uround(b * 65535.0),
- uround(a * 65535.0));
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE double to_double(value_type a)
- {
- return a;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type from_double(double a)
- {
- return value_type(a);
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type empty_value()
- {
- return 0;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type full_value()
- {
- return 1;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE bool is_transparent() const
- {
- return a <= 0;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE bool is_opaque() const
- {
- return a >= 1;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type invert(value_type x)
- {
- return 1 - x;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type multiply(value_type a, value_type b)
- {
- return value_type(a * b);
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type demultiply(value_type a, value_type b)
- {
- return (b == 0) ? 0 : value_type(a / b);
- }
-
- //--------------------------------------------------------------------
- template
- static AGG_INLINE T downscale(T a)
- {
- return a;
- }
-
- //--------------------------------------------------------------------
- template
- static AGG_INLINE T downshift(T a, unsigned n)
- {
- return n > 0 ? a / (1 << n) : a;
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE value_type mult_cover(value_type a, cover_type b)
- {
- return value_type(a * b / cover_mask);
- }
-
- //--------------------------------------------------------------------
- static AGG_INLINE cover_type scale_cover(cover_type a, value_type b)
- {
- return cover_type(uround(a * b));
- }
-
- //--------------------------------------------------------------------
- // Interpolate p to q by a, assuming q is premultiplied by a.
- static AGG_INLINE value_type prelerp(value_type p, value_type q, value_type a)
- {
- return (1 - a) * p + q; // more accurate than "p + q - p * a"
- }
-
- //--------------------------------------------------------------------
- // Interpolate p to q by a.
- static AGG_INLINE value_type lerp(value_type p, value_type q, value_type a)
- {
- // The form "p + a * (q - p)" avoids a multiplication, but may produce an
- // inaccurate result. For example, "p + (q - p)" may not be exactly equal
- // to q. Therefore, stick to the basic expression, which at least produces
- // the correct result at either extreme.
- return (1 - a) * p + a * q;
- }
-
- //--------------------------------------------------------------------
- self_type& clear()
- {
- r = g = b = a = 0;
- return *this;
- }
-
- //--------------------------------------------------------------------
- self_type& transparent()
- {
- a = 0;
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& opacity(double a_)
- {
- if (a_ < 0) a = 0;
- else if (a_ > 1) a = 1;
- else a = value_type(a_);
- return *this;
- }
-
- //--------------------------------------------------------------------
- double opacity() const
- {
- return a;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& premultiply()
- {
- if (a < 1)
- {
- if (a <= 0)
- {
- r = g = b = 0;
- }
- else
- {
- r *= a;
- g *= a;
- b *= a;
- }
- }
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type& demultiply()
- {
- if (a < 1)
- {
- if (a <= 0)
- {
- r = g = b = 0;
- }
- else
- {
- r /= a;
- g /= a;
- b /= a;
- }
- }
- return *this;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE self_type gradient(const self_type& c, double k) const
- {
- self_type ret;
- ret.r = value_type(r + (c.r - r) * k);
- ret.g = value_type(g + (c.g - g) * k);
- ret.b = value_type(b + (c.b - b) * k);
- ret.a = value_type(a + (c.a - a) * k);
- return ret;
- }
-
- //--------------------------------------------------------------------
- AGG_INLINE void add(const self_type& c, unsigned cover)
- {
- if (cover == cover_mask)
- {
- if (c.is_opaque())
- {
- *this = c;
- return;
- }
- else
- {
- r += c.r;
- g += c.g;
- b += c.b;
- a += c.a;
- }
- }
- else
- {
- r += mult_cover(c.r, cover);
- g += mult_cover(c.g, cover);
- b += mult_cover(c.b, cover);
- a += mult_cover(c.a, cover);
- }
- if (a > 1) a = 1;
- if (r > a) r = a;
- if (g > a) g = a;
- if (b > a) b = a;
- }
-
- //--------------------------------------------------------------------
- template
- AGG_INLINE void apply_gamma_dir(const GammaLUT& gamma)
- {
- r = gamma.dir(r);
- g = gamma.dir(g);
- b = gamma.dir(b);
- }
-
- //--------------------------------------------------------------------
- template
- AGG_INLINE void apply_gamma_inv(const GammaLUT& gamma)
- {
- r = gamma.inv(r);
- g = gamma.inv(g);
- b = gamma.inv(b);
- }
-
- //--------------------------------------------------------------------
- static self_type no_color() { return self_type(0,0,0,0); }
-
- //--------------------------------------------------------------------
- static self_type from_wavelength(double wl, double gamma = 1)
- {
- return self_type(rgba::from_wavelength(wl, gamma));
- }
- };
-}
-
-#endif
diff --git a/kiva/gl/src/agg/agg_config.h b/kiva/gl/src/agg/agg_config.h
deleted file mode 100644
index 40205e827..000000000
--- a/kiva/gl/src/agg/agg_config.h
+++ /dev/null
@@ -1,44 +0,0 @@
-#ifndef AGG_CONFIG_INCLUDED
-#define AGG_CONFIG_INCLUDED
-
-// This file can be used to redefine certain data types.
-
-//---------------------------------------
-// 1. Default basic types such as:
-//
-// AGG_INT8
-// AGG_INT8U
-// AGG_INT16
-// AGG_INT16U
-// AGG_INT32
-// AGG_INT32U
-// AGG_INT64
-// AGG_INT64U
-//
-// Just replace this file with new defines if necessary.
-// For example, if your compiler doesn't have a 64 bit integer type
-// you can still use AGG if you define the follows:
-//
-// #define AGG_INT64 int
-// #define AGG_INT64U unsigned
-//
-// It will result in overflow in 16 bit-per-component image/pattern resampling
-// but it won't result any crash and the rest of the library will remain
-// fully functional.
-
-
-//---------------------------------------
-// 2. Default rendering_buffer type. Can be:
-//
-// Provides faster access for massive pixel operations,
-// such as blur, image filtering:
-// #define AGG_RENDERING_BUFFER row_ptr_cache
-//
-// Provides cheaper creation and destruction (no mem allocs):
-// #define AGG_RENDERING_BUFFER row_accessor
-//
-// You can still use both of them simultaneously in your applications
-// This #define is used only for default rendering_buffer type,
-// in short hand typedefs like pixfmt_rgba32.
-
-#endif
diff --git a/kiva/gl/src/agg/agg_conv_transform.h b/kiva/gl/src/agg/agg_conv_transform.h
deleted file mode 100644
index b3fda33f3..000000000
--- a/kiva/gl/src/agg/agg_conv_transform.h
+++ /dev/null
@@ -1,67 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-//
-// class conv_transform
-//
-//----------------------------------------------------------------------------
-#ifndef AGG_CONV_TRANSFORM_INCLUDED
-#define AGG_CONV_TRANSFORM_INCLUDED
-
-#include "agg_basics.h"
-#include "agg_trans_affine.h"
-
-namespace kiva_gl_agg
-{
-
- //----------------------------------------------------------conv_transform
- template class conv_transform
- {
- public:
- conv_transform(VertexSource& source, Transformer& tr) :
- m_source(&source), m_trans(&tr) {}
- void attach(VertexSource& source) { m_source = &source; }
-
- void rewind(unsigned path_id)
- {
- m_source->rewind(path_id);
- }
-
- unsigned vertex(double* x, double* y)
- {
- unsigned cmd = m_source->vertex(x, y);
- if(is_vertex(cmd))
- {
- m_trans->transform(x, y);
- }
- return cmd;
- }
-
- void transformer(Transformer& tr)
- {
- m_trans = &tr;
- }
-
- private:
- conv_transform(const conv_transform&);
- const conv_transform&
- operator = (const conv_transform&);
-
- VertexSource* m_source;
- Transformer* m_trans;
- };
-
-}
-
-#endif
diff --git a/kiva/gl/src/agg/agg_gamma_functions.h b/kiva/gl/src/agg/agg_gamma_functions.h
deleted file mode 100644
index 36676e00f..000000000
--- a/kiva/gl/src/agg/agg_gamma_functions.h
+++ /dev/null
@@ -1,128 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-
-#ifndef AGG_GAMMA_FUNCTIONS_INCLUDED
-#define AGG_GAMMA_FUNCTIONS_INCLUDED
-
-#include
-#include "agg_basics.h"
-
-namespace kiva_gl_agg
-{
- //===============================================================gamma_none
- struct gamma_none
- {
- double operator()(double x) const { return x; }
- };
-
- //==============================================================gamma_power
- class gamma_power
- {
- public:
- gamma_power() : m_gamma(1.0) {}
- gamma_power(double g) : m_gamma(g) {}
-
- void gamma(double g) { m_gamma = g; }
- double gamma() const { return m_gamma; }
-
- double operator() (double x) const
- {
- return pow(x, m_gamma);
- }
-
- private:
- double m_gamma;
- };
-
-
- //==========================================================gamma_threshold
- class gamma_threshold
- {
- public:
- gamma_threshold() : m_threshold(0.5) {}
- gamma_threshold(double t) : m_threshold(t) {}
-
- void threshold(double t) { m_threshold = t; }
- double threshold() const { return m_threshold; }
-
- double operator() (double x) const
- {
- return (x < m_threshold) ? 0.0 : 1.0;
- }
-
- private:
- double m_threshold;
- };
-
-
- //============================================================gamma_linear
- class gamma_linear
- {
- public:
- gamma_linear() : m_start(0.0), m_end(1.0) {}
- gamma_linear(double s, double e) : m_start(s), m_end(e) {}
-
- void set(double s, double e) { m_start = s; m_end = e; }
- void start(double s) { m_start = s; }
- void end(double e) { m_end = e; }
- double start() const { return m_start; }
- double end() const { return m_end; }
-
- double operator() (double x) const
- {
- if(x < m_start) return 0.0;
- if(x > m_end) return 1.0;
- return (x - m_start) / (m_end - m_start);
- }
-
- private:
- double m_start;
- double m_end;
- };
-
-
- //==========================================================gamma_multiply
- class gamma_multiply
- {
- public:
- gamma_multiply() : m_mul(1.0) {}
- gamma_multiply(double v) : m_mul(v) {}
-
- void value(double v) { m_mul = v; }
- double value() const { return m_mul; }
-
- double operator() (double x) const
- {
- double y = x * m_mul;
- if(y > 1.0) y = 1.0;
- return y;
- }
-
- private:
- double m_mul;
- };
-
- inline double sRGB_to_linear(double x)
- {
- return (x <= 0.04045) ? (x / 12.92) : pow((x + 0.055) / (1.055), 2.4);
- }
-
- inline double linear_to_sRGB(double x)
- {
- return (x <= 0.0031308) ? (x * 12.92) : (1.055 * pow(x, 1 / 2.4) - 0.055);
- }
-}
-
-#endif
diff --git a/kiva/gl/src/agg/agg_gamma_lut.h b/kiva/gl/src/agg/agg_gamma_lut.h
deleted file mode 100644
index 25570fef2..000000000
--- a/kiva/gl/src/agg/agg_gamma_lut.h
+++ /dev/null
@@ -1,305 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-
-#ifndef AGG_GAMMA_LUT_INCLUDED
-#define AGG_GAMMA_LUT_INCLUDED
-
-#include
-#include "agg_basics.h"
-#include "agg_gamma_functions.h"
-
-namespace kiva_gl_agg
-{
- template class gamma_lut
- {
- public:
- typedef gamma_lut self_type;
-
- enum gamma_scale_e
- {
- gamma_shift = GammaShift,
- gamma_size = 1 << gamma_shift,
- gamma_mask = gamma_size - 1
- };
-
- enum hi_res_scale_e
- {
- hi_res_shift = HiResShift,
- hi_res_size = 1 << hi_res_shift,
- hi_res_mask = hi_res_size - 1
- };
-
- ~gamma_lut()
- {
- pod_allocator::deallocate(m_inv_gamma, hi_res_size);
- pod_allocator::deallocate(m_dir_gamma, gamma_size);
- }
-
- gamma_lut() :
- m_gamma(1.0),
- m_dir_gamma(pod_allocator::allocate(gamma_size)),
- m_inv_gamma(pod_allocator::allocate(hi_res_size))
- {
- unsigned i;
- for(i = 0; i < gamma_size; i++)
- {
- m_dir_gamma[i] = HiResT(i << (hi_res_shift - gamma_shift));
- }
-
- for(i = 0; i < hi_res_size; i++)
- {
- m_inv_gamma[i] = LoResT(i >> (hi_res_shift - gamma_shift));
- }
- }
-
- gamma_lut(double g) :
- m_gamma(1.0),
- m_dir_gamma(pod_allocator::allocate(gamma_size)),
- m_inv_gamma(pod_allocator::allocate(hi_res_size))
- {
- gamma(g);
- }
-
- void gamma(double g)
- {
- m_gamma = g;
-
- unsigned i;
- for(i = 0; i < gamma_size; i++)
- {
- m_dir_gamma[i] = (HiResT)
- uround(pow(i / double(gamma_mask), m_gamma) * double(hi_res_mask));
- }
-
- double inv_g = 1.0 / g;
- for(i = 0; i < hi_res_size; i++)
- {
- m_inv_gamma[i] = (LoResT)
- uround(pow(i / double(hi_res_mask), inv_g) * double(gamma_mask));
- }
- }
-
- double gamma() const
- {
- return m_gamma;
- }
-
- HiResT dir(LoResT v) const
- {
- return m_dir_gamma[unsigned(v)];
- }
-
- LoResT inv(HiResT v) const
- {
- return m_inv_gamma[unsigned(v)];
- }
-
- private:
- gamma_lut(const self_type&);
- const self_type& operator = (const self_type&);
-
- double m_gamma;
- HiResT* m_dir_gamma;
- LoResT* m_inv_gamma;
- };
-
- //
- // sRGB support classes
- //
-
- // Optimized sRGB lookup table. The direct conversion (sRGB to linear)
- // is a straightforward lookup. The inverse conversion (linear to sRGB)
- // is implemented using binary search.
- template
- class sRGB_lut_base
- {
- public:
- LinearType dir(int8u v) const
- {
- return m_dir_table[v];
- }
-
- int8u inv(LinearType v) const
- {
- // Unrolled binary search.
- int8u x = 0;
- if (v > m_inv_table[128]) x = 128;
- if (v > m_inv_table[x + 64]) x += 64;
- if (v > m_inv_table[x + 32]) x += 32;
- if (v > m_inv_table[x + 16]) x += 16;
- if (v > m_inv_table[x + 8]) x += 8;
- if (v > m_inv_table[x + 4]) x += 4;
- if (v > m_inv_table[x + 2]) x += 2;
- if (v > m_inv_table[x + 1]) x += 1;
- return x;
- }
-
- protected:
- LinearType m_dir_table[256];
- LinearType m_inv_table[256];
-
- // Only derived classes may instantiate.
- sRGB_lut_base()
- {
- }
- };
-
- // sRGB_lut - implements sRGB conversion for the various types.
- // Base template is undefined, specializations are provided below.
- template
- class sRGB_lut;
-
- template<>
- class sRGB_lut : public sRGB_lut_base
- {
- public:
- sRGB_lut()
- {
- // Generate lookup tables.
- m_dir_table[0] = 0;
- m_inv_table[0] = 0;
- for (unsigned i = 1; i <= 255; ++i)
- {
- // Floating-point RGB is in range [0,1].
- m_dir_table[i] = float(sRGB_to_linear(i / 255.0));
- m_inv_table[i] = float(sRGB_to_linear((i - 0.5) / 255.0));
- }
- }
- };
-
- template<>
- class sRGB_lut : public sRGB_lut_base
- {
- public:
- sRGB_lut()
- {
- // Generate lookup tables.
- m_dir_table[0] = 0;
- m_inv_table[0] = 0;
- for (unsigned i = 1; i <= 255; ++i)
- {
- // 16-bit RGB is in range [0,65535].
- m_dir_table[i] = uround(65535.0 * sRGB_to_linear(i / 255.0));
- m_inv_table[i] = uround(65535.0 * sRGB_to_linear((i - 0.5) / 255.0));
- }
- }
- };
-
- template<>
- class sRGB_lut : public sRGB_lut_base
- {
- public:
- sRGB_lut()
- {
- // Generate lookup tables.
- m_dir_table[0] = 0;
- m_inv_table[0] = 0;
- for (unsigned i = 1; i <= 255; ++i)
- {
- // 8-bit RGB is handled with simple bidirectional lookup tables.
- m_dir_table[i] = uround(255.0 * sRGB_to_linear(i / 255.0));
- m_inv_table[i] = uround(255.0 * linear_to_sRGB(i / 255.0));
- }
- }
-
- int8u inv(int8u v) const
- {
- // In this case, the inverse transform is a simple lookup.
- return m_inv_table[v];
- }
- };
-
- // Common base class for sRGB_conv objects. Defines an internal
- // sRGB_lut object so that users don't have to.
- template
- class sRGB_conv_base
- {
- public:
- static T rgb_from_sRGB(int8u x)
- {
- return lut.dir(x);
- }
-
- static int8u rgb_to_sRGB(T x)
- {
- return lut.inv(x);
- }
-
- private:
- static sRGB_lut lut;
- };
-
- // Definition of sRGB_conv_base::lut. Due to the fact that this a template,
- // we don't need to place the definition in a cpp file. Hurrah.
- template
- sRGB_lut sRGB_conv_base::lut;
-
- // Wrapper for sRGB-linear conversion.
- // Base template is undefined, specializations are provided below.
- template
- class sRGB_conv;
-
- template<>
- class sRGB_conv : public sRGB_conv_base
- {
- public:
- static float alpha_from_sRGB(int8u x)
- {
- return float(x / 255.0);
- }
-
- static int8u alpha_to_sRGB(float x)
- {
- if (x <= 0) return 0;
- else if (x >= 1) return 255;
- else return int8u(0.5 + x * 255);
- }
- };
-
- template<>
- class sRGB_conv : public sRGB_conv_base
- {
- public:
- static int16u alpha_from_sRGB(int8u x)
- {
- return (x << 8) | x;
- }
-
- static int8u alpha_to_sRGB(int16u x)
- {
- return x >> 8;
- }
- };
-
- template<>
- class sRGB_conv : public sRGB_conv_base
- {
- public:
- static int8u alpha_from_sRGB(int8u x)
- {
- return x;
- }
-
- static int8u alpha_to_sRGB(int8u x)
- {
- return x;
- }
- };
-}
-
-#endif
diff --git a/kiva/gl/src/agg/agg_math.h b/kiva/gl/src/agg/agg_math.h
deleted file mode 100644
index 6336c6f9a..000000000
--- a/kiva/gl/src/agg/agg_math.h
+++ /dev/null
@@ -1,437 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-// Bessel function (besj) was adapted for use in AGG library by Andy Wilk
-// Contact: castor.vulgaris@gmail.com
-//----------------------------------------------------------------------------
-
-#ifndef AGG_MATH_INCLUDED
-#define AGG_MATH_INCLUDED
-
-#include
-#include "agg_basics.h"
-
-namespace kiva_gl_agg
-{
-
- //------------------------------------------------------vertex_dist_epsilon
- // Coinciding points maximal distance (Epsilon)
- const double vertex_dist_epsilon = 1e-14;
-
- //-----------------------------------------------------intersection_epsilon
- // See calc_intersection
- const double intersection_epsilon = 1.0e-30;
-
- //------------------------------------------------------------cross_product
- AGG_INLINE double cross_product(double x1, double y1,
- double x2, double y2,
- double x, double y)
- {
- return (x - x2) * (y2 - y1) - (y - y2) * (x2 - x1);
- }
-
- //--------------------------------------------------------point_in_triangle
- AGG_INLINE bool point_in_triangle(double x1, double y1,
- double x2, double y2,
- double x3, double y3,
- double x, double y)
- {
- bool cp1 = cross_product(x1, y1, x2, y2, x, y) < 0.0;
- bool cp2 = cross_product(x2, y2, x3, y3, x, y) < 0.0;
- bool cp3 = cross_product(x3, y3, x1, y1, x, y) < 0.0;
- return cp1 == cp2 && cp2 == cp3 && cp3 == cp1;
- }
-
- //-----------------------------------------------------------calc_distance
- AGG_INLINE double calc_distance(double x1, double y1, double x2, double y2)
- {
- double dx = x2-x1;
- double dy = y2-y1;
- return sqrt(dx * dx + dy * dy);
- }
-
- //--------------------------------------------------------calc_sq_distance
- AGG_INLINE double calc_sq_distance(double x1, double y1, double x2, double y2)
- {
- double dx = x2-x1;
- double dy = y2-y1;
- return dx * dx + dy * dy;
- }
-
- //------------------------------------------------calc_line_point_distance
- AGG_INLINE double calc_line_point_distance(double x1, double y1,
- double x2, double y2,
- double x, double y)
- {
- double dx = x2-x1;
- double dy = y2-y1;
- double d = sqrt(dx * dx + dy * dy);
- if(d < vertex_dist_epsilon)
- {
- return calc_distance(x1, y1, x, y);
- }
- return ((x - x2) * dy - (y - y2) * dx) / d;
- }
-
- //-------------------------------------------------------calc_line_point_u
- AGG_INLINE double calc_segment_point_u(double x1, double y1,
- double x2, double y2,
- double x, double y)
- {
- double dx = x2 - x1;
- double dy = y2 - y1;
-
- if(dx == 0 && dy == 0)
- {
- return 0;
- }
-
- double pdx = x - x1;
- double pdy = y - y1;
-
- return (pdx * dx + pdy * dy) / (dx * dx + dy * dy);
- }
-
- //---------------------------------------------calc_line_point_sq_distance
- AGG_INLINE double calc_segment_point_sq_distance(double x1, double y1,
- double x2, double y2,
- double x, double y,
- double u)
- {
- if(u <= 0)
- {
- return calc_sq_distance(x, y, x1, y1);
- }
- else
- if(u >= 1)
- {
- return calc_sq_distance(x, y, x2, y2);
- }
- return calc_sq_distance(x, y, x1 + u * (x2 - x1), y1 + u * (y2 - y1));
- }
-
- //---------------------------------------------calc_line_point_sq_distance
- AGG_INLINE double calc_segment_point_sq_distance(double x1, double y1,
- double x2, double y2,
- double x, double y)
- {
- return
- calc_segment_point_sq_distance(
- x1, y1, x2, y2, x, y,
- calc_segment_point_u(x1, y1, x2, y2, x, y));
- }
-
- //-------------------------------------------------------calc_intersection
- AGG_INLINE bool calc_intersection(double ax, double ay, double bx, double by,
- double cx, double cy, double dx, double dy,
- double* x, double* y)
- {
- double num = (ay-cy) * (dx-cx) - (ax-cx) * (dy-cy);
- double den = (bx-ax) * (dy-cy) - (by-ay) * (dx-cx);
- if(fabs(den) < intersection_epsilon) return false;
- double r = num / den;
- *x = ax + r * (bx-ax);
- *y = ay + r * (by-ay);
- return true;
- }
-
- //-----------------------------------------------------intersection_exists
- AGG_INLINE bool intersection_exists(double x1, double y1, double x2, double y2,
- double x3, double y3, double x4, double y4)
- {
- // It's less expensive but you can't control the
- // boundary conditions: Less or LessEqual
- double dx1 = x2 - x1;
- double dy1 = y2 - y1;
- double dx2 = x4 - x3;
- double dy2 = y4 - y3;
- return ((x3 - x2) * dy1 - (y3 - y2) * dx1 < 0.0) !=
- ((x4 - x2) * dy1 - (y4 - y2) * dx1 < 0.0) &&
- ((x1 - x4) * dy2 - (y1 - y4) * dx2 < 0.0) !=
- ((x2 - x4) * dy2 - (y2 - y4) * dx2 < 0.0);
-
- // It's is more expensive but more flexible
- // in terms of boundary conditions.
- //--------------------
- //double den = (x2-x1) * (y4-y3) - (y2-y1) * (x4-x3);
- //if(fabs(den) < intersection_epsilon) return false;
- //double nom1 = (x4-x3) * (y1-y3) - (y4-y3) * (x1-x3);
- //double nom2 = (x2-x1) * (y1-y3) - (y2-y1) * (x1-x3);
- //double ua = nom1 / den;
- //double ub = nom2 / den;
- //return ua >= 0.0 && ua <= 1.0 && ub >= 0.0 && ub <= 1.0;
- }
-
- //--------------------------------------------------------calc_orthogonal
- AGG_INLINE void calc_orthogonal(double thickness,
- double x1, double y1,
- double x2, double y2,
- double* x, double* y)
- {
- double dx = x2 - x1;
- double dy = y2 - y1;
- double d = sqrt(dx*dx + dy*dy);
- *x = thickness * dy / d;
- *y = -thickness * dx / d;
- }
-
- //--------------------------------------------------------dilate_triangle
- AGG_INLINE void dilate_triangle(double x1, double y1,
- double x2, double y2,
- double x3, double y3,
- double *x, double* y,
- double d)
- {
- double dx1=0.0;
- double dy1=0.0;
- double dx2=0.0;
- double dy2=0.0;
- double dx3=0.0;
- double dy3=0.0;
- double loc = cross_product(x1, y1, x2, y2, x3, y3);
- if(fabs(loc) > intersection_epsilon)
- {
- if(cross_product(x1, y1, x2, y2, x3, y3) > 0.0)
- {
- d = -d;
- }
- calc_orthogonal(d, x1, y1, x2, y2, &dx1, &dy1);
- calc_orthogonal(d, x2, y2, x3, y3, &dx2, &dy2);
- calc_orthogonal(d, x3, y3, x1, y1, &dx3, &dy3);
- }
- *x++ = x1 + dx1; *y++ = y1 + dy1;
- *x++ = x2 + dx1; *y++ = y2 + dy1;
- *x++ = x2 + dx2; *y++ = y2 + dy2;
- *x++ = x3 + dx2; *y++ = y3 + dy2;
- *x++ = x3 + dx3; *y++ = y3 + dy3;
- *x++ = x1 + dx3; *y++ = y1 + dy3;
- }
-
- //------------------------------------------------------calc_triangle_area
- AGG_INLINE double calc_triangle_area(double x1, double y1,
- double x2, double y2,
- double x3, double y3)
- {
- return (x1*y2 - x2*y1 + x2*y3 - x3*y2 + x3*y1 - x1*y3) * 0.5;
- }
-
- //-------------------------------------------------------calc_polygon_area
- template double calc_polygon_area(const Storage& st)
- {
- unsigned i;
- double sum = 0.0;
- double x = st[0].x;
- double y = st[0].y;
- double xs = x;
- double ys = y;
-
- for(i = 1; i < st.size(); i++)
- {
- const typename Storage::value_type& v = st[i];
- sum += x * v.y - y * v.x;
- x = v.x;
- y = v.y;
- }
- return (sum + x * ys - y * xs) * 0.5;
- }
-
- //------------------------------------------------------------------------
- // Tables for fast sqrt
- extern int16u g_sqrt_table[1024];
- extern int8 g_elder_bit_table[256];
-
-
- //---------------------------------------------------------------fast_sqrt
- //Fast integer Sqrt - really fast: no cycles, divisions or multiplications
- #if defined(_MSC_VER)
- #pragma warning(push)
- #pragma warning(disable : 4035) //Disable warning "no return value"
- #endif
- AGG_INLINE unsigned fast_sqrt(unsigned val)
- {
- #if defined(_M_IX86) && defined(_MSC_VER) && !defined(AGG_NO_ASM)
- //For Ix86 family processors this assembler code is used.
- //The key command here is bsr - determination the number of the most
- //significant bit of the value. For other processors
- //(and maybe compilers) the pure C "#else" section is used.
- __asm
- {
- mov ebx, val
- mov edx, 11
- bsr ecx, ebx
- sub ecx, 9
- jle less_than_9_bits
- shr ecx, 1
- adc ecx, 0
- sub edx, ecx
- shl ecx, 1
- shr ebx, cl
- less_than_9_bits:
- xor eax, eax
- mov ax, g_sqrt_table[ebx*2]
- mov ecx, edx
- shr eax, cl
- }
- #else
-
- //This code is actually pure C and portable to most
- //arcitectures including 64bit ones.
- unsigned t = val;
- int bit=0;
- unsigned shift = 11;
-
- //The following piece of code is just an emulation of the
- //Ix86 assembler command "bsr" (see above). However on old
- //Intels (like Intel MMX 233MHz) this code is about twice
- //faster (sic!) then just one "bsr". On PIII and PIV the
- //bsr is optimized quite well.
- bit = t >> 24;
- if(bit)
- {
- bit = g_elder_bit_table[bit] + 24;
- }
- else
- {
- bit = (t >> 16) & 0xFF;
- if(bit)
- {
- bit = g_elder_bit_table[bit] + 16;
- }
- else
- {
- bit = (t >> 8) & 0xFF;
- if(bit)
- {
- bit = g_elder_bit_table[bit] + 8;
- }
- else
- {
- bit = g_elder_bit_table[t];
- }
- }
- }
-
- //This code calculates the sqrt.
- bit -= 9;
- if(bit > 0)
- {
- bit = (bit >> 1) + (bit & 1);
- shift -= bit;
- val >>= (bit << 1);
- }
- return g_sqrt_table[val] >> shift;
- #endif
- }
- #if defined(_MSC_VER)
- #pragma warning(pop)
- #endif
-
-
-
-
- //--------------------------------------------------------------------besj
- // Function BESJ calculates Bessel function of first kind of order n
- // Arguments:
- // n - an integer (>=0), the order
- // x - value at which the Bessel function is required
- //--------------------
- // C++ Mathematical Library
- // Convereted from equivalent FORTRAN library
- // Converetd by Gareth Walker for use by course 392 computational project
- // All functions tested and yield the same results as the corresponding
- // FORTRAN versions.
- //
- // If you have any problems using these functions please report them to
- // M.Muldoon@UMIST.ac.uk
- //
- // Documentation available on the web
- // http://www.ma.umist.ac.uk/mrm/Teaching/392/libs/392.html
- // Version 1.0 8/98
- // 29 October, 1999
- //--------------------
- // Adapted for use in AGG library by Andy Wilk (castor.vulgaris@gmail.com)
- //------------------------------------------------------------------------
- inline double besj(double x, int n)
- {
- if(n < 0)
- {
- return 0;
- }
- double d = 1E-6;
- double b = 0;
- if(fabs(x) <= d)
- {
- if(n != 0) return 0;
- return 1;
- }
- double b1 = 0; // b1 is the value from the previous iteration
- // Set up a starting order for recurrence
- int m1 = (int)fabs(x) + 6;
- if(fabs(x) > 5)
- {
- m1 = (int)(fabs(1.4 * x + 60 / x));
- }
- int m2 = (int)(n + 2 + fabs(x) / 4);
- if (m1 > m2)
- {
- m2 = m1;
- }
-
- // Apply recurrence down from curent max order
- for(;;)
- {
- double c3 = 0;
- double c2 = 1E-30;
- double c4 = 0;
- int m8 = 1;
- if (m2 / 2 * 2 == m2)
- {
- m8 = -1;
- }
- int imax = m2 - 2;
- for (int i = 1; i <= imax; i++)
- {
- double c6 = 2 * (m2 - i) * c2 / x - c3;
- c3 = c2;
- c2 = c6;
- if(m2 - i - 1 == n)
- {
- b = c6;
- }
- m8 = -1 * m8;
- if (m8 > 0)
- {
- c4 = c4 + 2 * c6;
- }
- }
- double c6 = 2 * c2 / x - c3;
- if(n == 0)
- {
- b = c6;
- }
- c4 += c6;
- b /= c4;
- if(fabs(b - b1) < d)
- {
- return b;
- }
- b1 = b;
- m2 += 3;
- }
- }
-
-}
-
-
-#endif
diff --git a/kiva/gl/src/agg/agg_path_storage.h b/kiva/gl/src/agg/agg_path_storage.h
deleted file mode 100644
index f908c1626..000000000
--- a/kiva/gl/src/agg/agg_path_storage.h
+++ /dev/null
@@ -1,1539 +0,0 @@
-//----------------------------------------------------------------------------
-// Anti-Grain Geometry - Version 2.4
-// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//
-//----------------------------------------------------------------------------
-// Contact: mcseem@antigrain.com
-// mcseemagg@yahoo.com
-// http://www.antigrain.com
-//----------------------------------------------------------------------------
-
-#ifndef AGG_PATH_STORAGE_INCLUDED
-#define AGG_PATH_STORAGE_INCLUDED
-
-#include
-#include
-#include "agg_math.h"
-#include "agg_array.h"
-#include "agg_bezier_arc.h"
-
-namespace kiva_gl_agg
-{
-
- //----------------------------------------------------vertex_block_storage
- template
- class vertex_block_storage
- {
- public:
- // Allocation parameters
- enum block_scale_e
- {
- block_shift = BlockShift,
- block_size = 1 << block_shift,
- block_mask = block_size - 1,
- block_pool = BlockPool
- };
-
- typedef T value_type;
- typedef vertex_block_storage self_type;
-
- ~vertex_block_storage();
- vertex_block_storage();
- vertex_block_storage(const self_type& v);
- const self_type& operator = (const self_type& ps);
-
- void remove_all();
- void free_all();
-
- void add_vertex(double x, double y, unsigned cmd);
- void modify_vertex(unsigned idx, double x, double y);
- void modify_vertex(unsigned idx, double x, double y, unsigned cmd);
- void modify_command(unsigned idx, unsigned cmd);
- void swap_vertices(unsigned v1, unsigned v2);
-
- unsigned last_command() const;
- unsigned last_vertex(double* x, double* y) const;
- unsigned prev_vertex(double* x, double* y) const;
-
- double last_x() const;
- double last_y() const;
-
- unsigned total_vertices() const;
- unsigned vertex(unsigned idx, double* x, double* y) const;
- unsigned command(unsigned idx) const;
-
- private:
- void allocate_block(unsigned nb);
- int8u* storage_ptrs(T** xy_ptr);
-
- private:
- unsigned m_total_vertices;
- unsigned m_total_blocks;
- unsigned m_max_blocks;
- T** m_coord_blocks;
- int8u** m_cmd_blocks;
- };
-
-
- //------------------------------------------------------------------------
- template
- void vertex_block_storage::free_all()
- {
- if(m_total_blocks)
- {
- T** coord_blk = m_coord_blocks + m_total_blocks - 1;
- while(m_total_blocks--)
- {
- pod_allocator::deallocate(
- *coord_blk,
- block_size * 2 +
- block_size / (sizeof(T) / sizeof(unsigned char)));
- --coord_blk;
- }
- pod_allocator::deallocate(m_coord_blocks, m_max_blocks * 2);
- m_total_blocks = 0;
- m_max_blocks = 0;
- m_coord_blocks = 0;
- m_cmd_blocks = 0;
- m_total_vertices = 0;
- }
- }
-
- //------------------------------------------------------------------------
- template
- vertex_block_storage::~vertex_block_storage()
- {
- free_all();
- }
-
- //------------------------------------------------------------------------
- template
- vertex_block_storage::vertex_block_storage() :
- m_total_vertices(0),
- m_total_blocks(0),
- m_max_blocks(0),
- m_coord_blocks(0),
- m_cmd_blocks(0)
- {
- }
-
- //------------------------------------------------------------------------
- template
- vertex_block_storage::vertex_block_storage(const vertex_block_storage& v) :
- m_total_vertices(0),
- m_total_blocks(0),
- m_max_blocks(0),
- m_coord_blocks(0),
- m_cmd_blocks(0)
- {
- *this = v;
- }
-
- //------------------------------------------------------------------------
- template
- const vertex_block_storage&
- vertex_block_storage