|
From: <md...@us...> - 2010-06-24 13:06:10
|
Revision: 8460
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8460&view=rev
Author: mdboom
Date: 2010-06-24 13:06:03 +0000 (Thu, 24 Jun 2010)
Log Message:
-----------
Standardizing formatting of C/C++ code.
Modified Paths:
--------------
trunk/matplotlib/src/_backend_agg.cpp
trunk/matplotlib/src/_backend_agg.h
trunk/matplotlib/src/_gtkagg.cpp
trunk/matplotlib/src/_image.cpp
trunk/matplotlib/src/_image.h
trunk/matplotlib/src/_path.cpp
trunk/matplotlib/src/_png.cpp
trunk/matplotlib/src/_tkagg.cpp
trunk/matplotlib/src/_ttconv.cpp
trunk/matplotlib/src/_windowing.cpp
trunk/matplotlib/src/_wxagg.cpp
trunk/matplotlib/src/agg_py_path_iterator.h
trunk/matplotlib/src/ft2font.cpp
trunk/matplotlib/src/ft2font.h
trunk/matplotlib/src/mplutils.cpp
trunk/matplotlib/src/mplutils.h
trunk/matplotlib/src/path_cleanup.cpp
trunk/matplotlib/src/path_converters.h
Modified: trunk/matplotlib/src/_backend_agg.cpp
===================================================================
--- trunk/matplotlib/src/_backend_agg.cpp 2010-06-23 14:44:32 UTC (rev 8459)
+++ trunk/matplotlib/src/_backend_agg.cpp 2010-06-24 13:06:03 UTC (rev 8460)
@@ -54,57 +54,82 @@
/*
Convert dashes from the Python representation as nested sequences to
the C++ representation as a std::vector<std::pair<double, double> >
- (GCAgg::dash_t)
-*/
-void convert_dashes(const Py::Tuple& dashes, double dpi, GCAgg::dash_t& dashes_out,
- double& dashOffset_out) {
- if (dashes.length()!=2)
- throw Py::ValueError(Printf("Dash descriptor must be a length 2 tuple; found %d", dashes.length()).str());
+ (GCAgg::dash_t) */
+void
+convert_dashes(const Py::Tuple& dashes, double dpi,
+ GCAgg::dash_t& dashes_out, double& dashOffset_out)
+{
+ if (dashes.length() != 2)
+ {
+ throw Py::ValueError(
+ Printf("Dash descriptor must be a length 2 tuple; found %d",
+ dashes.length()).str()
+ );
+ }
- dashes_out.clear();
- dashOffset_out = 0.0;
- if (dashes[0].ptr() == Py_None)
- return;
+ dashes_out.clear();
+ dashOffset_out = 0.0;
+ if (dashes[0].ptr() == Py_None)
+ {
+ return;
+ }
- dashOffset_out = double(Py::Float(dashes[0])) * dpi/72.0;
+ dashOffset_out = double(Py::Float(dashes[0])) * dpi / 72.0;
- Py::SeqBase<Py::Object> dashSeq = dashes[1];
+ Py::SeqBase<Py::Object> dashSeq = dashes[1];
- size_t Ndash = dashSeq.length();
- if (Ndash % 2 != 0)
- throw Py::ValueError(Printf("Dash sequence must be an even length sequence; found %d", Ndash).str());
+ size_t Ndash = dashSeq.length();
+ if (Ndash % 2 != 0)
+ {
+ throw Py::ValueError(
+ Printf("Dash sequence must be an even length sequence; found %d", Ndash).str()
+ );
+ }
- dashes_out.clear();
- dashes_out.reserve(Ndash / 2);
+ dashes_out.clear();
+ dashes_out.reserve(Ndash / 2);
- double val0, val1;
- for (size_t i = 0; i < Ndash; i += 2) {
- val0 = double(Py::Float(dashSeq[i])) * dpi/72.0;
- val1 = double(Py::Float(dashSeq[i+1])) * dpi/72.0;
- dashes_out.push_back(std::make_pair(val0, val1));
- }
+ double val0, val1;
+ for (size_t i = 0; i < Ndash; i += 2)
+ {
+ val0 = double(Py::Float(dashSeq[i])) * dpi / 72.0;
+ val1 = double(Py::Float(dashSeq[i+1])) * dpi / 72.0;
+ dashes_out.push_back(std::make_pair(val0, val1));
+ }
}
-Py::Object BufferRegion::to_string(const Py::Tuple &args) {
- // owned=true to prevent memory leak
- return Py::String(PyString_FromStringAndSize((const char*)data, height*stride), true);
+
+Py::Object
+BufferRegion::to_string(const Py::Tuple &args)
+{
+ // owned=true to prevent memory leak
+ return Py::String(PyString_FromStringAndSize((const char*)data, height*stride), true);
}
-Py::Object BufferRegion::set_x(const Py::Tuple &args) {
+
+Py::Object
+BufferRegion::set_x(const Py::Tuple &args)
+{
args.verify_length(1);
- size_t x = Py::Int( args[0] );
+ size_t x = Py::Int(args[0]);
rect.x1 = x;
return Py::Object();
}
-Py::Object BufferRegion::set_y(const Py::Tuple &args) {
+
+Py::Object
+BufferRegion::set_y(const Py::Tuple &args)
+{
args.verify_length(1);
- size_t y = Py::Int( args[0] );
+ size_t y = Py::Int(args[0]);
rect.y1 = y;
return Py::Object();
}
-Py::Object BufferRegion::get_extents(const Py::Tuple &args) {
+
+Py::Object
+BufferRegion::get_extents(const Py::Tuple &args)
+{
args.verify_length(0);
Py::Tuple extents(4);
@@ -116,562 +141,673 @@
return extents;
}
-Py::Object BufferRegion::to_string_argb(const Py::Tuple &args) {
- // owned=true to prevent memory leak
- Py_ssize_t length;
- unsigned char* pix;
- unsigned char* begin;
- unsigned char* end;
- unsigned char tmp;
- size_t i, j;
- PyObject* str = PyString_FromStringAndSize((const char*)data, height*stride);
- if (PyString_AsStringAndSize(str, (char**)&begin, &length)) {
- throw Py::TypeError("Could not create memory for blit");
- }
+Py::Object
+BufferRegion::to_string_argb(const Py::Tuple &args)
+{
+ // owned=true to prevent memory leak
+ Py_ssize_t length;
+ unsigned char* pix;
+ unsigned char* begin;
+ unsigned char* end;
+ unsigned char tmp;
+ size_t i, j;
- pix = begin;
- end = begin + (height * stride);
- for (i = 0; i < (size_t)height; ++i) {
- pix = begin + i * stride;
- for (j = 0; j < (size_t)width; ++j) {
- // Convert rgba to argb
- tmp = pix[2];
- pix[2] = pix[0];
- pix[0] = tmp;
- pix += 4;
+ PyObject* str = PyString_FromStringAndSize(
+ (const char*)data, height * stride);
+ if (PyString_AsStringAndSize(str, (char**)&begin, &length))
+ {
+ throw Py::TypeError("Could not create memory for blit");
}
- }
- return Py::String(str, true);
+ pix = begin;
+ end = begin + (height * stride);
+ for (i = 0; i < (size_t)height; ++i)
+ {
+ pix = begin + i * stride;
+ for (j = 0; j < (size_t)width; ++j)
+ {
+ // Convert rgba to argb
+ tmp = pix[2];
+ pix[2] = pix[0];
+ pix[0] = tmp;
+ pix += 4;
+ }
+ }
+
+ return Py::String(str, true);
}
+
GCAgg::GCAgg(const Py::Object &gc, double dpi) :
- dpi(dpi), isaa(true), dashOffset(0.0)
+ dpi(dpi), isaa(true), dashOffset(0.0)
{
- _VERBOSE("GCAgg::GCAgg");
- linewidth = points_to_pixels ( gc.getAttr("_linewidth") ) ;
- alpha = Py::Float( gc.getAttr("_alpha") );
- color = get_color(gc);
- _set_antialiased(gc);
- _set_linecap(gc);
- _set_joinstyle(gc);
- _set_dashes(gc);
- _set_clip_rectangle(gc);
- _set_clip_path(gc);
- _set_snap(gc);
- _set_hatch_path(gc);
+ _VERBOSE("GCAgg::GCAgg");
+ linewidth = points_to_pixels(gc.getAttr("_linewidth")) ;
+ alpha = Py::Float(gc.getAttr("_alpha"));
+ color = get_color(gc);
+ _set_antialiased(gc);
+ _set_linecap(gc);
+ _set_joinstyle(gc);
+ _set_dashes(gc);
+ _set_clip_rectangle(gc);
+ _set_clip_path(gc);
+ _set_snap(gc);
+ _set_hatch_path(gc);
}
+
void
-GCAgg::_set_antialiased(const Py::Object& gc) {
- _VERBOSE("GCAgg::antialiased");
- isaa = Py::Int( gc.getAttr( "_antialiased") );
+GCAgg::_set_antialiased(const Py::Object& gc)
+{
+ _VERBOSE("GCAgg::antialiased");
+ isaa = Py::Int(gc.getAttr("_antialiased"));
}
+
agg::rgba
-GCAgg::get_color(const Py::Object& gc) {
- _VERBOSE("GCAgg::get_color");
- Py::Tuple rgb = Py::Tuple( gc.getAttr("_rgb") );
+GCAgg::get_color(const Py::Object& gc)
+{
+ _VERBOSE("GCAgg::get_color");
+ Py::Tuple rgb = Py::Tuple(gc.getAttr("_rgb"));
- double alpha = Py::Float( gc.getAttr("_alpha") );
+ double alpha = Py::Float(gc.getAttr("_alpha"));
- double r = Py::Float(rgb[0]);
- double g = Py::Float(rgb[1]);
- double b = Py::Float(rgb[2]);
- return agg::rgba(r, g, b, alpha);
+ double r = Py::Float(rgb[0]);
+ double g = Py::Float(rgb[1]);
+ double b = Py::Float(rgb[2]);
+ return agg::rgba(r, g, b, alpha);
}
+
double
-GCAgg::points_to_pixels( const Py::Object& points) {
- _VERBOSE("GCAgg::points_to_pixels");
- double p = Py::Float( points ) ;
- return p * dpi/72.0;
+GCAgg::points_to_pixels(const Py::Object& points)
+{
+ _VERBOSE("GCAgg::points_to_pixels");
+ double p = Py::Float(points) ;
+ return p * dpi / 72.0;
}
+
void
-GCAgg::_set_linecap(const Py::Object& gc) {
- _VERBOSE("GCAgg::_set_linecap");
+GCAgg::_set_linecap(const Py::Object& gc)
+{
+ _VERBOSE("GCAgg::_set_linecap");
- std::string capstyle = Py::String( gc.getAttr( "_capstyle" ) );
+ std::string capstyle = Py::String(gc.getAttr("_capstyle"));
- if (capstyle=="butt")
- cap = agg::butt_cap;
- else if (capstyle=="round")
- cap = agg::round_cap;
- else if(capstyle=="projecting")
- cap = agg::square_cap;
- else
- throw Py::ValueError(Printf("GC _capstyle attribute must be one of butt, round, projecting; found %s", capstyle.c_str()).str());
+ if (capstyle == "butt")
+ {
+ cap = agg::butt_cap;
+ }
+ else if (capstyle == "round")
+ {
+ cap = agg::round_cap;
+ }
+ else if (capstyle == "projecting")
+ {
+ cap = agg::square_cap;
+ }
+ else
+ {
+ throw Py::ValueError(Printf("GC _capstyle attribute must be one of butt, round, projecting; found %s", capstyle.c_str()).str());
+ }
}
+
void
-GCAgg::_set_joinstyle(const Py::Object& gc) {
- _VERBOSE("GCAgg::_set_joinstyle");
+GCAgg::_set_joinstyle(const Py::Object& gc)
+{
+ _VERBOSE("GCAgg::_set_joinstyle");
- std::string joinstyle = Py::String( gc.getAttr("_joinstyle") );
+ std::string joinstyle = Py::String(gc.getAttr("_joinstyle"));
- if (joinstyle == "miter")
- join = agg::miter_join_revert;
- else if (joinstyle == "round")
- join = agg::round_join;
- else if (joinstyle == "bevel")
- join = agg::bevel_join;
- else
- throw Py::ValueError(Printf("GC _joinstyle attribute must be one of butt, round, projecting; found %s", joinstyle.c_str()).str());
+ if (joinstyle == "miter")
+ {
+ join = agg::miter_join_revert;
+ }
+ else if (joinstyle == "round")
+ {
+ join = agg::round_join;
+ }
+ else if (joinstyle == "bevel")
+ {
+ join = agg::bevel_join;
+ }
+ else
+ {
+ throw Py::ValueError(Printf("GC _joinstyle attribute must be one of butt, round, projecting; found %s", joinstyle.c_str()).str());
+ }
}
+
void
-GCAgg::_set_dashes(const Py::Object& gc) {
- //return the dashOffset, dashes sequence tuple.
- _VERBOSE("GCAgg::_set_dashes");
+GCAgg::_set_dashes(const Py::Object& gc)
+{
+ //return the dashOffset, dashes sequence tuple.
+ _VERBOSE("GCAgg::_set_dashes");
- Py::Object dash_obj( gc.getAttr( "_dashes" ) );
- if (dash_obj.ptr() == Py_None) {
- dashes.clear();
- return;
- }
+ Py::Object dash_obj(gc.getAttr("_dashes"));
+ if (dash_obj.ptr() == Py_None)
+ {
+ dashes.clear();
+ return;
+ }
- convert_dashes(dash_obj, dpi, dashes, dashOffset);
+ convert_dashes(dash_obj, dpi, dashes, dashOffset);
}
+
void
-GCAgg::_set_clip_rectangle( const Py::Object& gc) {
- //set the clip rectangle from the gc
+GCAgg::_set_clip_rectangle(const Py::Object& gc)
+{
+ //set the clip rectangle from the gc
- _VERBOSE("GCAgg::_set_clip_rectangle");
+ _VERBOSE("GCAgg::_set_clip_rectangle");
- Py::Object o ( gc.getAttr( "_cliprect" ) );
- cliprect = o;
+ Py::Object o(gc.getAttr("_cliprect"));
+ cliprect = o;
}
+
void
-GCAgg::_set_clip_path( const Py::Object& gc) {
- //set the clip path from the gc
+GCAgg::_set_clip_path(const Py::Object& gc)
+{
+ //set the clip path from the gc
- _VERBOSE("GCAgg::_set_clip_path");
+ _VERBOSE("GCAgg::_set_clip_path");
- Py::Object method_obj = gc.getAttr("get_clip_path");
- Py::Callable method(method_obj);
- Py::Tuple path_and_transform = method.apply(Py::Tuple());
- if (path_and_transform[0].ptr() != Py_None) {
- clippath = path_and_transform[0];
- clippath_trans = py_to_agg_transformation_matrix(path_and_transform[1].ptr());
- }
+ Py::Object method_obj = gc.getAttr("get_clip_path");
+ Py::Callable method(method_obj);
+ Py::Tuple path_and_transform = method.apply(Py::Tuple());
+ if (path_and_transform[0].ptr() != Py_None)
+ {
+ clippath = path_and_transform[0];
+ clippath_trans = py_to_agg_transformation_matrix(path_and_transform[1].ptr());
+ }
}
+
void
-GCAgg::_set_snap( const Py::Object& gc) {
- //set the snap setting
+GCAgg::_set_snap(const Py::Object& gc)
+{
+ //set the snap setting
- _VERBOSE("GCAgg::_set_snap");
+ _VERBOSE("GCAgg::_set_snap");
- Py::Object method_obj = gc.getAttr("get_snap");
- Py::Callable method(method_obj);
- Py::Object py_snap = method.apply(Py::Tuple());
- if (py_snap.isNone()) {
- snap_mode = SNAP_AUTO;
- } else if (py_snap.isTrue()) {
- snap_mode = SNAP_TRUE;
- } else {
- snap_mode = SNAP_FALSE;
- }
+ Py::Object method_obj = gc.getAttr("get_snap");
+ Py::Callable method(method_obj);
+ Py::Object py_snap = method.apply(Py::Tuple());
+ if (py_snap.isNone())
+ {
+ snap_mode = SNAP_AUTO;
+ }
+ else if (py_snap.isTrue())
+ {
+ snap_mode = SNAP_TRUE;
+ }
+ else
+ {
+ snap_mode = SNAP_FALSE;
+ }
}
+
void
-GCAgg::_set_hatch_path( const Py::Object& gc) {
- _VERBOSE("GCAgg::_set_hatch_path");
+GCAgg::_set_hatch_path(const Py::Object& gc)
+{
+ _VERBOSE("GCAgg::_set_hatch_path");
- Py::Object method_obj = gc.getAttr("get_hatch_path");
- Py::Callable method(method_obj);
- hatchpath = method.apply(Py::Tuple());
+ Py::Object method_obj = gc.getAttr("get_hatch_path");
+ Py::Callable method(method_obj);
+ hatchpath = method.apply(Py::Tuple());
}
+
const size_t
RendererAgg::PIXELS_PER_INCH(96);
+
RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi,
int debug) :
- width(width),
- height(height),
- dpi(dpi),
- NUMBYTES(width*height*4),
- pixBuffer(NULL),
- renderingBuffer(),
- alphaBuffer(NULL),
- alphaMaskRenderingBuffer(),
- alphaMask(alphaMaskRenderingBuffer),
- pixfmtAlphaMask(alphaMaskRenderingBuffer),
- rendererBaseAlphaMask(),
- rendererAlphaMask(),
- scanlineAlphaMask(),
- slineP8(),
- slineBin(),
- pixFmt(),
- rendererBase(),
- rendererAA(),
- rendererBin(),
- theRasterizer(),
- debug(debug)
+ width(width),
+ height(height),
+ dpi(dpi),
+ NUMBYTES(width*height*4),
+ pixBuffer(NULL),
+ renderingBuffer(),
+ alphaBuffer(NULL),
+ alphaMaskRenderingBuffer(),
+ alphaMask(alphaMaskRenderingBuffer),
+ pixfmtAlphaMask(alphaMaskRenderingBuffer),
+ rendererBaseAlphaMask(),
+ rendererAlphaMask(),
+ scanlineAlphaMask(),
+ slineP8(),
+ slineBin(),
+ pixFmt(),
+ rendererBase(),
+ rendererAA(),
+ rendererBin(),
+ theRasterizer(),
+ debug(debug)
{
- _VERBOSE("RendererAgg::RendererAgg");
- unsigned stride(width*4);
+ _VERBOSE("RendererAgg::RendererAgg");
+ unsigned stride(width*4);
- pixBuffer = new agg::int8u[NUMBYTES];
- renderingBuffer.attach(pixBuffer, width, height, stride);
- pixFmt.attach(renderingBuffer);
- rendererBase.attach(pixFmt);
- rendererBase.clear(agg::rgba(1, 1, 1, 0));
- rendererAA.attach(rendererBase);
- rendererBin.attach(rendererBase);
- hatchRenderingBuffer.attach(hatchBuffer, HATCH_SIZE, HATCH_SIZE, HATCH_SIZE*4);
+ pixBuffer = new agg::int8u[NUMBYTES];
+ renderingBuffer.attach(pixBuffer, width, height, stride);
+ pixFmt.attach(renderingBuffer);
+ rendererBase.attach(pixFmt);
+ rendererBase.clear(agg::rgba(1, 1, 1, 0));
+ rendererAA.attach(rendererBase);
+ rendererBin.attach(rendererBase);
+ hatchRenderingBuffer.attach(hatchBuffer, HATCH_SIZE, HATCH_SIZE,
+ HATCH_SIZE*4);
}
-void RendererAgg::create_alpha_buffers() {
- if (!alphaBuffer) {
- unsigned stride(width*4);
- alphaBuffer = new agg::int8u[NUMBYTES];
- alphaMaskRenderingBuffer.attach(alphaBuffer, width, height, stride);
- rendererBaseAlphaMask.attach(pixfmtAlphaMask);
- rendererAlphaMask.attach(rendererBaseAlphaMask);
- }
+
+void
+RendererAgg::create_alpha_buffers()
+{
+ if (!alphaBuffer)
+ {
+ unsigned stride(width*4);
+ alphaBuffer = new agg::int8u[NUMBYTES];
+ alphaMaskRenderingBuffer.attach(alphaBuffer, width, height, stride);
+ rendererBaseAlphaMask.attach(pixfmtAlphaMask);
+ rendererAlphaMask.attach(rendererBaseAlphaMask);
+ }
}
+
template<class R>
void
-RendererAgg::set_clipbox(const Py::Object& cliprect, R& rasterizer) {
- //set the clip rectangle from the gc
+RendererAgg::set_clipbox(const Py::Object& cliprect, R& rasterizer)
+{
+ //set the clip rectangle from the gc
- _VERBOSE("RendererAgg::set_clipbox");
+ _VERBOSE("RendererAgg::set_clipbox");
- double l, b, r, t;
- if (py_convert_bbox(cliprect.ptr(), l, b, r, t)) {
- rasterizer.clip_box(int(mpl_round(l)), height - int(mpl_round(b)),
- int(mpl_round(r)), height - int(mpl_round(t)));
- }
+ double l, b, r, t;
+ if (py_convert_bbox(cliprect.ptr(), l, b, r, t))
+ {
+ rasterizer.clip_box(int(mpl_round(l)), height - int(mpl_round(b)),
+ int(mpl_round(r)), height - int(mpl_round(t)));
+ }
- _VERBOSE("RendererAgg::set_clipbox done");
+ _VERBOSE("RendererAgg::set_clipbox done");
}
+
std::pair<bool, agg::rgba>
-RendererAgg::_get_rgba_face(const Py::Object& rgbFace, double alpha) {
- _VERBOSE("RendererAgg::_get_rgba_face");
- std::pair<bool, agg::rgba> face;
+RendererAgg::_get_rgba_face(const Py::Object& rgbFace, double alpha)
+{
+ _VERBOSE("RendererAgg::_get_rgba_face");
+ std::pair<bool, agg::rgba> face;
- if (rgbFace.ptr() == Py_None) {
- face.first = false;
- }
- else {
- face.first = true;
- Py::Tuple rgb = Py::Tuple(rgbFace);
- face.second = rgb_to_color(rgb, alpha);
- }
- return face;
+ if (rgbFace.ptr() == Py_None)
+ {
+ face.first = false;
+ }
+ else
+ {
+ face.first = true;
+ Py::Tuple rgb = Py::Tuple(rgbFace);
+ face.second = rgb_to_color(rgb, alpha);
+ }
+ return face;
}
+
Py::Object
-RendererAgg::copy_from_bbox(const Py::Tuple& args) {
- //copy region in bbox to buffer and return swig/agg buffer object
- args.verify_length(1);
+RendererAgg::copy_from_bbox(const Py::Tuple& args)
+{
+ //copy region in bbox to buffer and return swig/agg buffer object
+ args.verify_length(1);
- Py::Object box_obj = args[0];
- double l, b, r, t;
- if (!py_convert_bbox(box_obj.ptr(), l, b, r, t))
- throw Py::TypeError("Invalid bbox provided to copy_from_bbox");
+ Py::Object box_obj = args[0];
+ double l, b, r, t;
+ if (!py_convert_bbox(box_obj.ptr(), l, b, r, t))
+ {
+ throw Py::TypeError("Invalid bbox provided to copy_from_bbox");
+ }
- // std::cout << l << " " << b << " " << r << " " << t << " " << (height - (int)b) << " " << height - (int)t << std::endl;
- agg::rect_i rect((int)l, height - (int)t, (int)r, height - (int)b);
+ agg::rect_i rect((int)l, height - (int)t, (int)r, height - (int)b);
- BufferRegion* reg = NULL;
- try {
- reg = new BufferRegion(rect, true);
- } catch (...) {
- throw Py::MemoryError("RendererAgg::copy_from_bbox could not allocate memory for buffer");
- }
+ BufferRegion* reg = NULL;
+ try
+ {
+ reg = new BufferRegion(rect, true);
+ }
+ catch (...)
+ {
+ throw Py::MemoryError(
+ "RendererAgg::copy_from_bbox could not allocate memory for buffer");
+ }
- if (!reg) {
- throw Py::MemoryError("RendererAgg::copy_from_bbox could not allocate memory for buffer");
- }
+ if (!reg)
+ {
+ throw Py::MemoryError(
+ "RendererAgg::copy_from_bbox could not allocate memory for buffer");
+ }
- try {
- agg::rendering_buffer rbuf;
- rbuf.attach(reg->data, reg->width, reg->height, reg->stride);
+ try
+ {
+ agg::rendering_buffer rbuf;
+ rbuf.attach(reg->data, reg->width, reg->height, reg->stride);
- pixfmt pf(rbuf);
- renderer_base rb(pf);
- rb.copy_from(renderingBuffer, &rect, -rect.x1, -rect.y1);
- } catch (...) {
- delete reg;
- throw Py::RuntimeError("An unknown error occurred in copy_from_bbox");
- }
- return Py::asObject(reg);
+ pixfmt pf(rbuf);
+ renderer_base rb(pf);
+ rb.copy_from(renderingBuffer, &rect, -rect.x1, -rect.y1);
+ }
+ catch (...)
+ {
+ delete reg;
+ throw Py::RuntimeError("An unknown error occurred in copy_from_bbox");
+ }
+ return Py::asObject(reg);
}
+
Py::Object
-RendererAgg::restore_region(const Py::Tuple& args) {
- //copy BufferRegion to buffer
- args.verify_length(1);
- BufferRegion* region = static_cast<BufferRegion*>(args[0].ptr());
+RendererAgg::restore_region(const Py::Tuple& args)
+{
+ //copy BufferRegion to buffer
+ args.verify_length(1);
+ BufferRegion* region = static_cast<BufferRegion*>(args[0].ptr());
- if (region->data==NULL)
- throw Py::ValueError("Cannot restore_region from NULL data");
- //return Py::Object();
+ if (region->data == NULL)
+ {
+ throw Py::ValueError("Cannot restore_region from NULL data");
+ }
- //std::cout << "restoring " << region->width << " " << region->height << " " << region->stride << " " << region->rect.x1 << " " << region->rect.y1 << std::endl;
+ agg::rendering_buffer rbuf;
+ rbuf.attach(region->data,
+ region->width,
+ region->height,
+ region->stride);
- agg::rendering_buffer rbuf;
- rbuf.attach(region->data,
- region->width,
- region->height,
- region->stride);
+ rendererBase.copy_from(rbuf, 0, region->rect.x1, region->rect.y1);
- rendererBase.copy_from(rbuf, 0, region->rect.x1, region->rect.y1);
-
- return Py::Object();
+ return Py::Object();
}
+
// Restore the part of the saved region with offsets
Py::Object
-RendererAgg::restore_region2(const Py::Tuple& args) {
- //copy BufferRegion to buffer
- args.verify_length(7);
+RendererAgg::restore_region2(const Py::Tuple& args)
+{
+ //copy BufferRegion to buffer
+ args.verify_length(7);
+ int x(0), y(0), xx1(0), yy1(0), xx2(0), yy2(0);
+ try
+ {
+ xx1 = Py::Int(args[1]);
+ yy1 = Py::Int(args[2]);
+ xx2 = Py::Int(args[3]);
+ yy2 = Py::Int(args[4]);
+ x = Py::Int(args[5]);
+ y = Py::Int(args[6]);
+ }
+ catch (Py::TypeError)
+ {
+ throw Py::TypeError("Invalid input arguments to draw_text_image");
+ }
- int x(0),y(0), xx1(0),yy1(0), xx2(0), yy2(0);
- try {
- xx1 = Py::Int( args[1] );
- yy1 = Py::Int( args[2] );
- xx2 = Py::Int( args[3] );
- yy2 = Py::Int( args[4] );
- x = Py::Int( args[5] );
- y = Py::Int( args[6] );
- }
- catch (Py::TypeError) {
- throw Py::TypeError("Invalid input arguments to draw_text_image");
- }
+ BufferRegion* region = static_cast<BufferRegion*>(args[0].ptr());
+ if (region->data == NULL)
+ {
+ throw Py::ValueError("Cannot restore_region from NULL data");
+ }
- BufferRegion* region = static_cast<BufferRegion*>(args[0].ptr());
+ agg::rect_i rect(xx1 - region->rect.x1, (yy1 - region->rect.y1),
+ xx2 - region->rect.x1, (yy2 - region->rect.y1));
- if (region->data==NULL)
- throw Py::ValueError("Cannot restore_region from NULL data");
+ agg::rendering_buffer rbuf;
+ rbuf.attach(region->data,
+ region->width,
+ region->height,
+ region->stride);
- agg::rect_i rect(xx1-region->rect.x1, (yy1-region->rect.y1),
- xx2-region->rect.x1, (yy2-region->rect.y1));
+ rendererBase.copy_from(rbuf, &rect, x, y);
-
- agg::rendering_buffer rbuf;
- rbuf.attach(region->data,
- region->width,
- region->height,
- region->stride);
-
- rendererBase.copy_from(rbuf, &rect, x, y);
-
- return Py::Object();
+ return Py::Object();
}
-bool RendererAgg::render_clippath(const Py::Object& clippath, const agg::trans_affine& clippath_trans) {
- typedef agg::conv_transform<PathIterator> transformed_path_t;
- typedef agg::conv_curve<transformed_path_t> curve_t;
+bool
+RendererAgg::render_clippath(const Py::Object& clippath,
+ const agg::trans_affine& clippath_trans)
+{
+ typedef agg::conv_transform<PathIterator> transformed_path_t;
+ typedef agg::conv_curve<transformed_path_t> curve_t;
- bool has_clippath = (clippath.ptr() != Py_None);
+ bool has_clippath = (clippath.ptr() != Py_None);
- if (has_clippath &&
- (clippath.ptr() != lastclippath.ptr() ||
- clippath_trans != lastclippath_transform)) {
- create_alpha_buffers();
- agg::trans_affine trans(clippath_trans);
- trans *= agg::trans_affine_scaling(1.0, -1.0);
- trans *= agg::trans_affine_translation(0.0, (double)height);
+ if (has_clippath &&
+ (clippath.ptr() != lastclippath.ptr() ||
+ clippath_trans != lastclippath_transform))
+ {
+ create_alpha_buffers();
+ agg::trans_affine trans(clippath_trans);
+ trans *= agg::trans_affine_scaling(1.0, -1.0);
+ trans *= agg::trans_affine_translation(0.0, (double)height);
- PathIterator clippath_iter(clippath);
- rendererBaseAlphaMask.clear(agg::gray8(0, 0));
- transformed_path_t transformed_clippath(clippath_iter, trans);
- agg::conv_curve<transformed_path_t> curved_clippath(transformed_clippath);
- theRasterizer.add_path(curved_clippath);
- rendererAlphaMask.color(agg::gray8(255, 255));
- agg::render_scanlines(theRasterizer, scanlineAlphaMask, rendererAlphaMask);
- lastclippath = clippath;
- lastclippath_transform = clippath_trans;
- }
+ PathIterator clippath_iter(clippath);
+ rendererBaseAlphaMask.clear(agg::gray8(0, 0));
+ transformed_path_t transformed_clippath(clippath_iter, trans);
+ agg::conv_curve<transformed_path_t> curved_clippath(transformed_clippath);
+ theRasterizer.add_path(curved_clippath);
+ rendererAlphaMask.color(agg::gray8(255, 255));
+ agg::render_scanlines(theRasterizer, scanlineAlphaMask, rendererAlphaMask);
+ lastclippath = clippath;
+ lastclippath_transform = clippath_trans;
+ }
- return has_clippath;
+ return has_clippath;
}
#define MARKER_CACHE_SIZE 512
+
Py::Object
-RendererAgg::draw_markers(const Py::Tuple& args) {
- typedef agg::conv_transform<PathIterator> transformed_path_t;
- typedef PathSnapper<transformed_path_t> snap_t;
- typedef agg::conv_curve<snap_t> curve_t;
- typedef agg::conv_stroke<curve_t> stroke_t;
- typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
- typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
- typedef agg::renderer_scanline_aa_solid<amask_ren_type> amask_aa_renderer_type;
- typedef agg::renderer_scanline_bin_solid<amask_ren_type> amask_bin_renderer_type;
- args.verify_length(5, 6);
+RendererAgg::draw_markers(const Py::Tuple& args)
+{
+ typedef agg::conv_transform<PathIterator> transformed_path_t;
+ typedef PathSnapper<transformed_path_t> snap_t;
+ typedef agg::conv_curve<snap_t> curve_t;
+ typedef agg::conv_stroke<curve_t> stroke_t;
+ typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
+ typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
+ typedef agg::renderer_scanline_aa_solid<amask_ren_type> amask_aa_renderer_type;
+ typedef agg::renderer_scanline_bin_solid<amask_ren_type> amask_bin_renderer_type;
+ args.verify_length(5, 6);
- Py::Object gc_obj = args[0];
- Py::Object marker_path_obj = args[1];
- agg::trans_affine marker_trans = py_to_agg_transformation_matrix(args[2].ptr());
- Py::Object path_obj = args[3];
- agg::trans_affine trans = py_to_agg_transformation_matrix(args[4].ptr());
- Py::Object face_obj;
- if (args.size() == 6)
- face_obj = args[5];
+ Py::Object gc_obj = args[0];
+ Py::Object marker_path_obj = args[1];
+ agg::trans_affine marker_trans = py_to_agg_transformation_matrix(args[2].ptr());
+ Py::Object path_obj = args[3];
+ agg::trans_affine trans = py_to_agg_transformation_matrix(args[4].ptr());
+ Py::Object face_obj;
+ if (args.size() == 6)
+ {
+ face_obj = args[5];
+ }
- GCAgg gc(gc_obj, dpi);
+ GCAgg gc(gc_obj, dpi);
- // Deal with the difference in y-axis direction
- marker_trans *= agg::trans_affine_scaling(1.0, -1.0);
- trans *= agg::trans_affine_scaling(1.0, -1.0);
- trans *= agg::trans_affine_translation(0.0, (double)height);
+ // Deal with the difference in y-axis direction
+ marker_trans *= agg::trans_affine_scaling(1.0, -1.0);
+ trans *= agg::trans_affine_scaling(1.0, -1.0);
+ trans *= agg::trans_affine_translation(0.0, (double)height);
- PathIterator marker_path(marker_path_obj);
- transformed_path_t marker_path_transformed(marker_path, marker_trans);
- snap_t marker_path_snapped(marker_path_transformed,
- gc.snap_mode,
- marker_path.total_vertices(),
- gc.linewidth);
- curve_t marker_path_curve(marker_path_snapped);
+ PathIterator marker_path(marker_path_obj);
+ transformed_path_t marker_path_transformed(marker_path, marker_trans);
+ snap_t marker_path_snapped(marker_path_transformed,
+ gc.snap_mode,
+ marker_path.total_vertices(),
+ gc.linewidth);
+ curve_t marker_path_curve(marker_path_snapped);
- PathIterator path(path_obj);
- transformed_path_t path_transformed(path, trans);
- snap_t path_snapped(path_transformed,
- gc.snap_mode,
- path.total_vertices(),
- 1.0);
- curve_t path_curve(path_snapped);
- path_curve.rewind(0);
+ PathIterator path(path_obj);
+ transformed_path_t path_transformed(path, trans);
+ snap_t path_snapped(path_transformed,
+ gc.snap_mode,
+ path.total_vertices(),
+ 1.0);
+ curve_t path_curve(path_snapped);
+ path_curve.rewind(0);
- facepair_t face = _get_rgba_face(face_obj, gc.alpha);
+ facepair_t face = _get_rgba_face(face_obj, gc.alpha);
- //maxim's suggestions for cached scanlines
- agg::scanline_storage_aa8 scanlines;
- theRasterizer.reset();
- theRasterizer.reset_clipping();
- rendererBase.reset_clipping(true);
+ //maxim's suggestions for cached scanlines
+ agg::scanline_storage_aa8 scanlines;
+ theRasterizer.reset();
+ theRasterizer.reset_clipping();
+ rendererBase.reset_clipping(true);
- agg::int8u staticFillCache[MARKER_CACHE_SIZE];
- agg::int8u staticStrokeCache[MARKER_CACHE_SIZE];
- agg::int8u* fillCache = staticFillCache;
- agg::int8u* strokeCache = staticStrokeCache;
+ agg::int8u staticFillCache[MARKER_CACHE_SIZE];
+ agg::int8u staticStrokeCache[MARKER_CACHE_SIZE];
+ agg::int8u* fillCache = staticFillCache;
+ agg::int8u* strokeCache = staticStrokeCache;
- try {
- unsigned fillSize = 0;
- if (face.first) {
- theRasterizer.add_path(marker_path_curve);
- agg::render_scanlines(theRasterizer, slineP8, scanlines);
- fillSize = scanlines.byte_size();
- if (fillSize >= MARKER_CACHE_SIZE)
- fillCache = new agg::int8u[fillSize];
- scanlines.serialize(fillCache);
- }
+ try
+ {
+ unsigned fillSize = 0;
+ if (face.first)
+ {
+ theRasterizer.add_path(marker_path_curve);
+ agg::render_scanlines(theRasterizer, slineP8, scanlines);
+ fillSize = scanlines.byte_size();
+ if (fillSize >= MARKER_CACHE_SIZE)
+ {
+ fillCache = new agg::int8u[fillSize];
+ }
+ scanlines.serialize(fillCache);
+ }
- stroke_t stroke(marker_path_curve);
- stroke.width(gc.linewidth);
- stroke.line_cap(gc.cap);
- stroke.line_join(gc.join);
- theRasterizer.reset();
- theRasterizer.add_path(stroke);
- agg::render_scanlines(theRasterizer, slineP8, scanlines);
- unsigned strokeSize = scanlines.byte_size();
- if (strokeSize >= MARKER_CACHE_SIZE)
- strokeCache = new agg::int8u[strokeSize];
- scanlines.serialize(strokeCache);
+ stroke_t stroke(marker_path_curve);
+ stroke.width(gc.linewidth);
+ stroke.line_cap(gc.cap);
+ stroke.line_join(gc.join);
+ theRasterizer.reset();
+ theRasterizer.add_path(stroke);
+ agg::render_scanlines(theRasterizer, slineP8, scanlines);
+ unsigned strokeSize = scanlines.byte_size();
+ if (strokeSize >= MARKER_CACHE_SIZE)
+ {
+ strokeCache = new agg::int8u[strokeSize];
+ }
+ scanlines.serialize(strokeCache);
- theRasterizer.reset_clipping();
- rendererBase.reset_clipping(true);
- set_clipbox(gc.cliprect, rendererBase);
- bool has_clippath = render_clippath(gc.clippath, gc.clippath_trans);
+ theRasterizer.reset_clipping();
+ rendererBase.reset_clipping(true);
+ set_clipbox(gc.cliprect, rendererBase);
+ bool has_clippath = render_clippath(gc.clippath, gc.clippath_trans);
- double x, y;
+ double x, y;
- agg::serialized_scanlines_adaptor_aa8 sa;
- agg::serialized_scanlines_adaptor_aa8::embedded_scanline sl;
+ agg::serialized_scanlines_adaptor_aa8 sa;
+ agg::serialized_scanlines_adaptor_aa8::embedded_scanline sl;
- agg::rect_d clipping_rect(
- -(scanlines.min_x() + 1.0),
- -(scanlines.min_y() + 1.0),
- width + scanlines.max_x() + 1.0,
- height + scanlines.max_y() + 1.0);
+ agg::rect_d clipping_rect(
+ -(scanlines.min_x() + 1.0),
+ -(scanlines.min_y() + 1.0),
+ width + scanlines.max_x() + 1.0,
+ height + scanlines.max_y() + 1.0);
- if (has_clippath) {
- while (path_curve.vertex(&x, &y) != agg::path_cmd_stop) {
- if (MPL_notisfinite64(x) || MPL_notisfinite64(y)) {
- continue;
- }
+ if (has_clippath)
+ {
+ while (path_curve.vertex(&x, &y) != agg::path_cmd_stop)
+ {
+ if (MPL_notisfinite64(x) || MPL_notisfinite64(y))
+ {
+ continue;
+ }
- x = (double)(int)x; y = (double)(int)y;
+ x = (double)(int)x;
+ y = (double)(int)y;
- // Cull points outside the boundary of the image. Values
- // that are too large may overflow and create segfaults.
- // because they can create segfaults of they overflow; eg
- // http://sourceforge.net/tracker/?func=detail&aid=2865490&group_id=80706&atid=560720
- if (!clipping_rect.hit_test(x, y)) {
- continue;
- }
+ // Cull points outside the boundary of the image.
+ // Values that are too large may overflow and create
+ // segfaults.
+ // http://sourceforge.net/tracker/?func=detail&aid=2865490&group_id=80706&atid=560720
+ if (!clipping_rect.hit_test(x, y))
+ {
+ continue;
+ }
- pixfmt_amask_type pfa(pixFmt, alphaMask);
- amask_ren_type r(pfa);
- amask_aa_renderer_type ren(r);
+ pixfmt_amask_type pfa(pixFmt, alphaMask);
+ amask_ren_type r(pfa);
+ amask_aa_renderer_type ren(r);
- if (face.first) {
- ren.color(face.second);
- sa.init(fillCache, fillSize, x, y);
- agg::render_scanlines(sa, sl, ren);
+ if (face.first)
+ {
+ ren.color(face.second);
+ sa.init(fillCache, fillSize, x, y);
+ agg::render_scanlines(sa, sl, ren);
+ }
+ ren.color(gc.color);
+ sa.init(strokeCache, strokeSize, x, y);
+ agg::render_scanlines(sa, sl, ren);
+ }
}
- ren.color(gc.color);
- sa.init(strokeCache, strokeSize, x, y);
- agg::render_scanlines(sa, sl, ren);
- }
- } else {
- while (path_curve.vertex(&x, &y) != agg::path_cmd_stop) {
- if (MPL_notisfinite64(x) || MPL_notisfinite64(y)) {
- continue;
- }
+ else
+ {
+ while (path_curve.vertex(&x, &y) != agg::path_cmd_stop)
+ {
+ if (MPL_notisfinite64(x) || MPL_notisfinite64(y))
+ {
+ continue;
+ }
- x = (double)(int)x; y = (double)(int)y;
+ x = (double)(int)x;
+ y = (double)(int)y;
- // Cull points outside the boundary of the image. Values
- // that are too large may overflow and create segfaults.
- // because they can create segfaults of they overflow; eg
- // http://sourceforge.net/tracker/?func=detail&aid=2865490&group_id=80706&atid=560720
- if (!clipping_rect.hit_test(x, y)) {
- continue;
- }
+ // Cull points outside the boundary of the image.
+ // Values that are too large may overflow and create
+ // segfaults.
+ // http://sourceforge.net/tracker/?func=detail&aid=2865490&group_id=80706&atid=560720
+ if (!clipping_rect.hit_test(x, y))
+ {
+ continue;
+ }
- if (face.first) {
- rendererAA.color(face.second);
- sa.init(fillCache, fillSize, x, y);
- agg::render_scanlines(sa, sl, rendererAA);
+ if (face.first)
+ {
+ rendererAA.color(face.second);
+ sa.init(fillCache, fillSize, x, y);
+ agg::render_scanlines(sa, sl, rendererAA);
+ }
+
+ rendererAA.color(gc.color);
+ sa.init(strokeCache, strokeSize, x, y);
+ agg::render_scanlines(sa, sl, rendererAA);
+ }
}
+ }
+ catch (...)
+ {
+ if (fillCache != staticFillCache)
+ delete[] fillCache;
+ if (strokeCache != staticStrokeCache)
+ delete[] strokeCache;
+ throw;
+ }
- rendererAA.color(gc.color);
- sa.init(strokeCache, strokeSize, x, y);
- agg::render_scanlines(sa, sl, rendererAA);
- }
- }
- } catch(...) {
if (fillCache != staticFillCache)
- delete[] fillCache;
+ delete[] fillCache;
if (strokeCache != staticStrokeCache)
- delete[] strokeCache;
- throw;
- }
+ delete[] strokeCache;
- if (fillCache != staticFillCache)
- delete[] fillCache;
- if (strokeCache != staticStrokeCache)
- delete[] strokeCache;
-
- return Py::Object();
+ return Py::Object();
}
+
/**
* This is a custom span generator that converts spans in the
* 8-bit inverted greyscale font buffer to rgba that agg can use.
@@ -680,1380 +816,1626 @@
class font_to_rgba
{
public:
- typedef ChildGenerator child_type;
- typedef agg::rgba8 color_type;
- typedef typename child_type::color_type child_color_type;
- typedef agg::span_allocator<child_color_type> span_alloc_type;
+ typedef ChildGenerator child_type;
+ typedef agg::rgba8 color_type;
+ typedef typename child_type::color_type child_color_type;
+ typedef agg::span_allocator<child_color_type> span_alloc_type;
private:
- child_type* _gen;
- color_type _color;
- span_alloc_type _allocator;
+ child_type* _gen;
+ color_type _color;
+ span_alloc_type _allocator;
public:
- font_to_rgba(child_type* gen, color_type color) :
- _gen(gen),
- _color(color) {
- }
+ font_to_rgba(child_type* gen, color_type color) :
+ _gen(gen),
+ _color(color)
+ {
- inline void generate(color_type* output_span, int x, int y, unsigned len)
- {
- _allocator.allocate(len);
- child_color_type* input_span = _allocator.span();
- _gen->generate(input_span, x, y, len);
+ }
- do {
- *output_span = _color;
- output_span->a = ((unsigned int)_color.a * (unsigned int)input_span->v) >> 8;
- ++output_span;
- ++input_span;
- } while (--len);
- }
+ inline void
+ generate(color_type* output_span, int x, int y, unsigned len)
+ {
+ _allocator.allocate(len);
+ child_color_type* input_span = _allocator.span();
+ _gen->generate(input_span, x, y, len);
- void prepare()
- {
- _gen->prepare();
- }
+ do
+ {
+ *output_span = _color;
+ output_span->a = ((unsigned int)_color.a *
+ (unsigned int)input_span->v) >> 8;
+ ++output_span;
+ ++input_span;
+ }
+ while (--len);
+ }
+ void
+ prepare()
+ {
+ _gen->prepare();
+ }
};
+
// MGDTODO: Support clip paths
Py::Object
-RendererAgg::draw_text_image(const Py::Tuple& args) {
- _VERBOSE("RendererAgg::draw_text");
+RendererAgg::draw_text_image(const Py::Tuple& args)
+{
+ _VERBOSE("RendererAgg::draw_text");
- typedef agg::span_allocator<agg::gray8> gray_span_alloc_type;
- typedef agg::span_allocator<agg::rgba8> color_span_alloc_type;
- typedef agg::span_interpolator_linear<> interpolator_type;
- typedef agg::image_accessor_clip<agg::pixfmt_gray8> image_accessor_type;
- //typedef agg::span_image_filter_gray_2x2<image_accessor_type, interpolator_type>
- // image_span_gen_type;
- typedef agg::span_image_filter_gray<image_accessor_type, interpolator_type>
- image_span_gen_type;
+ typedef agg::span_allocator<agg::gray8> gray_span_alloc_type;
+ typedef agg::span_allocator<agg::rgba8> color_span_alloc_type;
+ typedef agg::span_interpolator_linear<> interpolator_type;
+ typedef agg::image_accessor_clip<agg::pixfmt_gray8> image_accessor_type;
+ typedef agg::span_image_filter_gray<image_accessor_type,
+ interpolator_type> image_span_gen_type;
+ typedef font_to_rgba<image_span_gen_type> span_gen_type;
+ typedef agg::renderer_scanline_aa<renderer_base, color_span_alloc_type,
+ span_gen_type> renderer_type;
- typedef font_to_rgba<image_span_gen_type> span_gen_type;
- typedef agg::renderer_scanline_aa<renderer_base, color_span_alloc_type, span_gen_type>
- renderer_type;
+ args.verify_length(5);
- args.verify_length(5);
+ const unsigned char* buffer = NULL;
+ int width, height;
+ Py::Object image_obj = args[0];
+ PyArrayObject* image_array = NULL;
- const unsigned char* buffer = NULL;
- int width, height;
- Py::Object image_obj = args[0];
- PyArrayObject* image_array = NULL;
- if (PyArray_Check(image_obj.ptr())) {
- image_array = (PyArrayObject*)PyArray_FromObject(image_obj.ptr(), PyArray_UBYTE, 2, 2);
- if (!image_array)
- throw Py::ValueError("First argument to draw_text_image must be a FT2Font.Image object or a Nx2 uint8 numpy array.");
- buffer = (unsigned char *)PyArray_DATA(image_array);
- width = PyArray_DIM(image_array, 1);
- height = PyArray_DIM(image_array, 0);
- } else {
- FT2Image *image = static_cast<FT2Image*>(args[0].ptr());
- if (!image->get_buffer())
- throw Py::ValueError("First argument to draw_text_image must be a FT2Font.Image object or a Nx2 uint8 numpy array.");
- buffer = image->get_buffer();
- width = image->get_width();
- height = image->get_height();
- }
+ if (PyArray_Check(image_obj.ptr()))
+ {
+ image_array = (PyArrayObject*)PyArray_FromObject(image_obj.ptr(), PyArray_UBYTE, 2, 2);
+ if (!image_array)
+ {
+ throw Py::ValueError(
+ "First argument to draw_text_image must be a FT2Font.Image object or a Nx2 uint8 numpy array.");
+ }
+ buffer = (unsigned char *)PyArray_DATA(image_array);
+ width = PyArray_DIM(image_array, 1);
+ height = PyArray_DIM(image_array, 0);
+ }
+ else
+ {
+ FT2Image *image = static_cast<FT2Image*>(args[0].ptr());
+ if (!image->get_buffer())
+ {
+ throw Py::ValueError(
+ "First argument to draw_text_image must be a FT2Font.Image object or a Nx2 uint8 numpy array.");
+ }
+ buffer = image->get_buffer();
+ width = image->get_width();
+ height = image->get_height();
+ }
- int x(0),y(0);
- try {
- x = Py::Int( args[1] );
- y = Py::Int( args[2] );
- }
- catch (Py::TypeError) {
- Py_XDECREF(image_array);
- throw Py::TypeError("Invalid input arguments to draw_text_image");
- }
+ int x(0), y(0);
+ try
+ {
+ x = Py::Int(args[1]);
+ y = Py::Int(args[2]);
+ }
+ catch (Py::TypeError)
+ {
+ Py_XDECREF(image_array);
+ throw Py::TypeError("Invalid input arguments to draw_text_image");
+ }
- double angle = Py::Float( args[3] );
+ double angle = Py::Float(args[3]);
- GCAgg gc(args[4], dpi);
+ GCAgg gc(args[4], dpi);
- theRasterizer.reset_clipping();
- rendererBase.reset_clipping(true);
- set_clipbox(gc.cliprect, theRasterizer);
+ theRasterizer.reset_clipping();
+ rendererBase.reset_clipping(true);
+ set_clipbox(gc.cliprect, theRasterizer);
- agg::rendering_buffer srcbuf((agg::int8u*)buffer, width, height, width);
- agg::pixfmt_gray8 pixf_img(srcbuf);
+ agg::rendering_buffer srcbuf((agg::int8u*)buffer, width, height, width);
+ agg::pixfmt_gray8 pixf_img(srcbuf);
- agg::trans_affine mtx;
- mtx *= agg::trans_affine_translation(0, -height);
- mtx *= agg::trans_affine_rotation(-angle * agg::pi / 180.0);
- mtx *= agg::trans_affine_translation(x, y);
+ agg::trans_affine mtx;
+ mtx *= agg::trans_affine_translation(0, -height);
+ mtx *= agg::trans_affine_rotation(-angle * agg::pi / 180.0);
+ mtx *= agg::trans_affine_translation(x, y);
- agg::path_storage rect;
- rect.move_to(0, 0);
- rect.line_to(width, 0);
- rect.line_to(width, height);
- rect.line_to(0, height);
- rect.line_to(0, 0);
- agg::conv_transform<agg::path_storage> rect2(rect, mtx);
+ agg::path_storage rect;
+ rect.move_to(0, 0);
+ rect.line_to(width, 0);
+ rect.line_to(width, height);
+ rect.line_to(0, height);
+ rect.line_to(0, 0);
+ agg::conv_transform<agg::path_storage> rect2(rect, mtx);
- agg::trans_affine inv_mtx(mtx);
- inv_mtx.invert();
+ agg::trans_affine inv_mtx(mtx);
+ inv_mtx.invert();
- agg::image_filter_lut filter;
- filter.calculate(agg::image_filter_spline36());
- interpolator_type interpolator(inv_mtx);
- color_span_alloc_type sa;
- image_accessor_type ia(pixf_img, 0);
- image_span_gen_type image_span_generator(ia, interpolator, filter);
- span_gen_type output_span_generator(&image_span_generator, gc.color);
- renderer_type ri(rendererBase, sa, output_span_generator);
+ agg::image_filter_lut filter;
+ filter.calculate(agg::image_filter_spline36());
+ interpolator_type interpolator(inv_mtx);
+ color_span_alloc_type sa;
+ image_accessor_type ia(pixf_img, 0);
+ image_span_gen_type image_span_generator(ia, interpolator, filter);
+ span_gen_type output_span_generator(&image_span_generator, gc.color);
+ renderer_type ri(rendererBase, sa, output_span_generator);
- theRasterizer.add_path(rect2);
- agg::render_scanlines(theRasterizer, slineP8, ri);
+ theRasterizer.add_path(rect2);
+ agg::render_scanlines(theRasterizer, slineP8, ri);
- Py_XDECREF(image_array);
+ Py_XDECREF(image_array);
- return Py::Object();
+ return Py::Object();
}
Py::Object
-RendererAgg::draw_image(const Py::Tuple& args) {
- _VERBOSE("RendererAgg::draw_image");
+RendererAgg::draw_image(const Py::Tuple& args)
+{
+ _VERBOSE("RendererAgg::draw_image");
- args.verify_length(4, 7); // 7 if affine matrix if given
+ args.verify_length(4, 7); // 7 if affine matrix if given
- GCAgg gc(args[0], dpi);
- Image *image = static_cast<Image*>(args[3].ptr());
- bool has_clippath = false;
- agg::trans_affine affine_trans;
- bool has_affine = false;
- double x, y, w, h;
+ GCAgg gc(args[0], dpi);
+ Image *image = static_cast<Image*>(args[3].ptr());
+ bool has_clippath = false;
+ agg::trans_affine affine_trans;
+ bool has_affine = false;
+ double x, y, w, h;
-
- if (args.size() == 7) {
- has_affine = true;
- x = Py::Float(args[1]);
- y = Py::Float(args[2]);
- w = Py::Float(args[4]);
- h = Py::Float(args[5]);
- affine_trans = py_to_agg_transformation_matrix(args[6].ptr());
- } else {
- x = mpl_round(Py::Float(args[1]));
- y = mpl_round(Py::Float(args[2]));
- w = h = 0; /* w and h not used in this case, but assign to prevent
+ if (args.size() == 7)
+ {
+ has_affine = true;
+ x = Py::Float(args[1]);
+ y = Py::Float(args[2]);
+ w = Py::Float(args[4]);
+ h = Py::Float(args[5]);
+ affine_trans = py_to_agg_transformation_matrix(args[6].ptr());
+ }
+ else
+ {
+ x = mpl_round(Py::Float(args[1]));
+ y = mpl_round(Py::Float(args[2]));
+ w = h = 0; /* w and h not used in this case, but assign to prevent
warnings from the compiler */
- }
+ }
+ theRasterizer.reset_clipping();
+ rendererBase.reset_clipping(true);
+ set_clipbox(gc.cliprect, theRasterizer);
+ has_clippath = render_clippath(gc.clippath, gc.clippath_trans);
- theRasterizer.reset_clipping();
- rendererBase.reset_clipping(true);
- set_clipbox(gc.cliprect, theRasterizer);
- has_clippath = render_clippath(gc.clippath, gc.clippath_trans);
+ Py::Tuple empty;
+ image->flipud_out(empty);
+ pixfmt pixf(*(image->rbufOut));
- Py::Tuple empty;
- image->flipud_out(empty);
- pixfmt pixf(*(image->rbufOut));
+ if (has_affine | has_clippath)
+ {
+ agg::trans_affine mtx;
+ agg::path_storage rect;
- if (has_affine | has_clippath) {
- agg::trans_affine mtx;
- agg::path_storage rect;
+ if (has_affine)
+ {
+ mtx *= agg::trans_affine_scaling(1, -1);
+ mtx *= agg::trans_affine_translation(0, image->rowsOut);
+ mtx *= agg::trans_affine_scaling(w / (image->colsOut),
+ h / (image->rowsOut));
+ mtx *= agg::trans_affine_translation(x, y);
+ mtx *= affine_trans;
+ mtx *= agg::trans_affine_scaling(1.0, -1.0);
+ mtx *= agg::trans_affine_translation(0.0, (double) height);
+ }
+ else
+ {
+ mtx *= agg::trans_affine_translation(
+ (int)x,
+ (int)(height - (y + image->rowsOut)));
+ }
- if (has_affine) {
- mtx *= agg::trans_affine_scaling(1, -1);
- mtx *= agg::trans_affine_translation(0, image->rowsOut);
- mtx *= agg::trans_affine_scaling(w/(image->colsOut), h/(image->rowsOut));
- mtx *= agg::trans_affine_translation(x, y);
- mtx *= affine_trans;
- mtx *= agg::trans_affine_scaling(1.0, -1.0);
- mtx *= agg::trans_affine_translation(0.0, (double) height);
- } else {
- mtx *= agg::trans_affine_translation((int)x, (int)(height-(y+image->rowsOut)));
- }
+ rect.move_to(0, 0);
+ rect.line_to(image->colsOut, 0);
+ rect.line_to(image->colsOut, image->rowsOut);
+ rect.line_to(0, image->rowsOut);
+ rect.line_to(0, 0);
- rect.move_to(0, 0);
- rect.line_to(image->colsOut, 0);
- rect.line_to(image->colsOut, image->rowsOut);
- rect.line_to(0, image->rowsOut);
- rect.line_to(0, 0);
+ agg::conv_transform<agg::path_storage> rect2(rect, mtx);
- agg::conv_transform<agg::path_storage> rect2(rect, mtx);
+ agg::trans_affine inv_mtx(mtx);
+ inv_mtx.invert();
- agg::trans_affine inv_mtx(mtx);
- inv_mtx.invert();
+ typedef agg::span_allocator<agg::rgba8> color_span_alloc_type;
+ typedef agg::image_accessor_clip<agg::pixfmt_rgba32>
+ image_accessor_type;
+ typedef agg::span_interpolator_linear<> interpolator_type;
+ typedef agg::span_image_filter_rgba_nn<image_accessor_type,
+ interpolator_type> image_span_gen_type;
+ color_span_alloc_type sa;
+ image_accessor_type ia(pixf, agg::rgba8(0, 0, 0, 0));
+ interpolator_type interpolator(inv_mtx);
+ image_span_gen_type image_span_generator(ia, interpolator);
- typedef agg::span_allocator<agg::rgba8> color_span_alloc_type;
- typedef agg::image_accessor_clip<agg::pixfmt_rgba32> image_accessor_type;
- typedef agg::span_interpolator_linear<> interpolator_type;
- typedef agg::span_image_filter_rgba_nn<image_accessor_type, interpolator_type> image_span_gen_type;
+ if (has_clippath)
+ {
+ typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type>
+ pixfmt_amask_type;
+ typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
+ typedef agg::renderer_scanline_aa<amask_ren_type,
+ color_span_alloc_type,
+ image_span_gen_type>
+ renderer_type_alpha;
+ pixfmt_amask_type pfa(pixFmt, alphaMask);
+ amask_ren_type r(pfa);
+ renderer_type_alpha ri(r, sa, image_span_generator);
- color_span_alloc_type sa;
- image_accessor_type ia(pixf, agg::rgba8(0, 0, 0, 0));
- interpolator_type interpolator(inv_mtx);
- image_span_gen_type image_span_generator(ia, interpolator);
+ theRasterizer.add_path(rect2);
+ agg::render_scanlines(theRasterizer, slineP8, ri);
+ }
+ else
+ {
+ typedef agg::renderer_base<pixfmt> ren_type;
+ typedef agg::renderer_scanline_aa<ren_type,
+ color_span_alloc_type,
+ image_span_gen_type>
+ renderer_type;
+ ren_type r(pixFmt);
+ renderer_type ri(r, sa, image_span_generator);
- if (has_clippath) {
- typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
- typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
- typedef agg::renderer_scanline_aa<amask_ren_type, color_span_alloc_type, image_span_gen_type> renderer_type_alpha;
+ theRasterizer.add_path(rect2);
+ agg::render_scanlines(theRasterizer, slineP8, ri);
+ }
- pixfmt_amask_type pfa(pixFmt, alphaMask);
- amask_ren_type r(pfa);
- renderer_type_alpha ri(r, sa, image_span_generator);
-
- theRasterizer.add_path(rect2);
- agg::render_scanlines(theRasterizer, slineP8, ri);
- } else {
- typedef agg::renderer_base<pixfmt> ren_type;
- typedef agg::renderer_scanline_aa<ren_type, color_span_alloc_type, image_span_gen_type> renderer_type;
- ren_type r(pixFmt);
- renderer_type ri(r, sa, image_span_generator);
-
- theRasterizer.add_path(rect2);
- agg::render_scanlines(theRasterizer, slineP8, ri);
}
+ else
+ {
+ set_clipbox(gc.cliprect, rendererBase);
+ rendererBase.blend_from(pixf, 0, (int)x, (int)(height - (y + image->rowsOut)));
+ }
- } else {
- set_clipbox(gc.cliprect, rendererBase);
- rendererBase.blend_from(pixf, 0, (int)x, (int)(height-(y+image->rowsOut)));
- }
+ image->flipud_out(empty);
- image->flipud_out(empty);
-
- return Py::Object();
+ return Py::Object();
}
-
-
template<class path_t>
void RendererAgg::_draw_path(path_t& path, bool has_clippath,
- const facepair_t& face, const GCAgg& gc) {
- typedef agg::conv_stroke<path_t> stroke_t;
- typedef agg::conv_dash<path_t> dash_t;
- typedef agg::conv_stroke<dash_t> stroke_dash_t;
- typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
- typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
- typedef agg::renderer_scanline_aa_solid<amask_ren_type> amask_aa_renderer_type;
- typedef agg::renderer_scanline_bin_solid<amask_ren_type> amask_bin_renderer_type;
+ const facepair_t& face, const GCAgg& gc)
+{
+ typedef agg::conv_stroke<path_t> stroke_t;
+ typedef agg::conv_dash<path_t> dash_t;
+ typedef agg::conv_stroke<dash_t> stroke_dash_t;
+ typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
+ typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
+ typedef agg::renderer_scanline_aa_solid<amask_ren_type> amask_aa_renderer_type;
+ typedef agg::renderer_scanline_bin_solid<amask_ren_type> amask_bin_renderer_type;
- // Render face
- if (face.first) {
- theRasterizer.add_path(path);
+ // Render face
+ if (face.first)
+ {
+ theRasterizer.add_path(path);
- if (gc.isaa) {
- if (has_clippath) {
- pixfmt_amask_type pfa(pixFmt, alphaMask);
- amask_ren_type r(pfa);
- amask_aa_renderer_type ren(r);
- ren.color(face.second);
- agg::render_scanlines(theRasterizer, slineP8, ren);
- } else {
- rendererAA.color(face.second);
- agg::render_scanlines(theRasterizer, slineP8, rendererAA);
- }
- } else {
- if (has_clippath) {
- pixfmt_amask_type pfa(pixFmt, alphaMask);
- amask_ren_type r(pfa);
- amask_bin_renderer_type ren(r);
- ren.color(face.second);
- agg::render_scanlines(theRasterizer, slineP8, ren);
- } else {
- rendererBin.color(face.second);
- agg::render_scanlines(theRasterizer, slineP8, rendererBin);
- }
+ if (gc.isaa)
+ {
+ if (has_clippath)
+ {
+ pixfmt_amask_type pfa(pixFmt, alphaMask);
+ amask_ren_type r(pfa);
+ amask_aa_renderer_type ren(r);
+ ren.color(face.second);
+ agg::render_scanlines(theRasterizer, slineP8, ren);
+ }
+ else
+ {
+ rendererAA.color(face.second);
+ agg::render_scanlines(theRasterizer, slineP8, rendererAA);
+ }
+ }
+ else
+ {
+ if (has_clippath)
+ {
+ pixfmt_amask_type pfa(pixFmt, alphaMask);
+ amask_ren_type r(pfa);
+ amask_bin_renderer_type ren(r);
+ ren.color(face.second);
+ agg::render_scanlines(theRasterizer, slineP8, ren);
+ }
+ else
+ {
+ rendererBin.color(face.second);
+ agg::render_scanlines(theRasterizer, slineP8, rendererBin);
+ }
+ }
}
- }
- // Render hatch
- if (!gc.hatchpath.isNone()) {
- // Reset any clipping that may be in effect, since we'll be
- // drawing the hatch in a scratch buffer at origin (0, 0)
- theRasterizer.reset_clipping();
- rendererBase.reset_clipping(true);
+ // Render hatch
+ if (!gc.hatchpath.isNone())
+ {
+ // Reset any clipping that may be in effect, since we'll be
+ // drawing the hatch in a scratch buffer at origin (0, 0)
+ theRasterizer.reset_clipping();
+ rendererBase.reset_clipping(true);
- // Create and transform the path
- typedef agg::conv_transform<PathIterator> hatch_p...
[truncated message content] |