Пример #1
0
Py::Object
FuncXY::set_funcy(const Py::Tuple & args) {
  _VERBOSE("FuncXY::set_funcy");
  args.verify_length(1);
  
  if (!Func::check(args[0])) 
    throw Py::TypeError("set_funcy(func) expected a Func instance");
  
  _funcy = static_cast<Func*>(args[0].ptr());
  Py_INCREF(_funcy);
  return Py::Object();
}
Пример #2
0
Py::Object
Image::get_size(const Py::Tuple& args) {
  _VERBOSE("Image::get_size");
  
  args.verify_length(0);
  
  Py::Tuple ret(2);
  ret[0] = Py::Int((long)rowsIn);
  ret[1] = Py::Int((long)colsIn);
  return ret;
  
}
Пример #3
0
Py::Object 
Bbox::overlaps(const Py::Tuple &args) {
  _VERBOSE("Bbox::overlaps");
  args.verify_length(1);

  if (! check(args[0]))
    throw Py::TypeError("Expected a bbox");

  int x = Py::Int( overlapsx(args) );
  int y = Py::Int( overlapsy(args) );
  return Py::Int(x&&y);
}
Пример #4
0
Py::Object
Image::buffer_rgba(const Py::Tuple& args) {
  //"Return the image object as rgba";

  _VERBOSE("RendererAgg::buffer_rgba");

  args.verify_length(0);
  int row_len = colsOut * 4;
  PyObject* o = Py_BuildValue("lls#", rowsOut, colsOut,
			      rbufOut, row_len * rowsOut);
  return Py::asObject(o);
}
Пример #5
0
Py::Object
Image::reset_matrix(const Py::Tuple& args) {
  _VERBOSE("Image::reset_matrix");
  
  args.verify_length(0);
  srcMatrix.reset();
  imageMatrix.reset();
  
  return Py::Object();
  
  
}
Пример #6
0
Py::Object _path_module::convert_path_to_polygons(const Py::Tuple& args)
{
    typedef agg::conv_transform<PathIterator> transformed_path_t;
    typedef SimplifyPath<transformed_path_t> simplify_t;
    typedef agg::conv_curve<simplify_t> curve_t;

    typedef std::vector<double> vertices_t;

    args.verify_length(4);

    PathIterator path(args[0]);
    agg::trans_affine trans = py_to_agg_transformation_matrix(args[1], false);
    double width = Py::Float(args[2]);
    double height = Py::Float(args[3]);

    bool simplify = path.should_simplify() && width != 0.0 && height != 0.0;

    transformed_path_t tpath(path, trans);
    simplify_t simplified(tpath, false, simplify, width, height);
    curve_t curve(simplified);

    Py::List polygons;
    vertices_t polygon;
    double x, y;
    unsigned code;

    polygon.reserve(path.total_vertices() * 2);

    while ((code = curve.vertex(&x, &y)) != agg::path_cmd_stop)
    {
	if ((code & agg::path_cmd_end_poly) == agg::path_cmd_end_poly) {
	    if (polygon.size() >= 2)
	    {
		polygon.push_back(polygon[0]);
		polygon.push_back(polygon[1]);
		_add_polygon(polygons, polygon);
	    }
	    polygon.clear();
	} else {
	    if (code == agg::path_cmd_move_to) {
		_add_polygon(polygons, polygon);
		polygon.clear();
	    }
	    polygon.push_back(x);
	    polygon.push_back(y);
	}
    }

    _add_polygon(polygons, polygon);

    return polygons;
}
Пример #7
0
Py::Object
RendererAgg::draw_rectangle(const Py::Tuple & args) {
  _VERBOSE("RendererAgg::draw_rectangle");
  args.verify_length(6);
  theRasterizer->reset_clipping();
  Py::Object gcEdge( args[0] );
  Py::Object rgbFaceMaybeNone( args[1] );
  
  double l = Py::Float( args[2] ); 
  double b = Py::Float( args[3] ); 
  double w = Py::Float( args[4] ); 
  double h = Py::Float( args[5] ); 
  
  set_clip_rectangle(gcEdge);
  
  double lw = points_to_pixels ( gcEdge.getAttr("_linewidth") ) ;
  
  agg::path_storage path;
  
  b = height - (b+h);
  path.move_to(l, b+h);
  path.line_to(l+w, b+h);
  path.line_to(l+w, b);
  path.line_to(l, b);
  path.close_polygon();
  
  agg::rgba edgecolor = get_color(gcEdge);
  
  
  if (rgbFaceMaybeNone.ptr() != Py_None) {
    //fill the face
    Py::SeqBase<Py::Object> rgbFace = rgbFaceMaybeNone;
    agg::rgba facecolor = rgb_to_color(rgbFace, edgecolor.a);
    
    rendererAA->color(facecolor);
    theRasterizer->add_path(path);    
    agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA);
    
    
  }
  
  //now fill the edge
  agg::conv_stroke<agg::path_storage> stroke(path);
  stroke.width(lw);
  rendererAA->color(edgecolor);
  //self->theRasterizer->gamma(agg::gamma_power(gamma));
  theRasterizer->add_path(stroke);
  agg::render_scanlines(*theRasterizer, *slineP8, *rendererAA);
  
  return Py::Object();
  
}
Пример #8
0
Py::Object
FT2Font::get_glyph(const Py::Tuple & args){
  _VERBOSE("FT2Font::get_glyph");
  
  args.verify_length(1);
  int num = Py::Int(args[0]);
  
  if ( (size_t)num >= gms.size()) 
    throw Py::ValueError("Glyph index out of range");
  
  //todo: refcount?
  return Py::asObject(gms[num]);
}
Пример #9
0
Py::Object
Image::apply_rotation(const Py::Tuple& args) {
  _VERBOSE("Image::apply_rotation");
  
  args.verify_length(1);  
  double r = Py::Float(args[0]);
  
  
  agg::trans_affine M = agg::trans_affine_rotation( r * agg::pi / 180.0);	      
  srcMatrix *= M;
  imageMatrix *= M;
  return Py::Object();  
}
Пример #10
0
Py::Object
Image::get_matrix(const Py::Tuple& args) {
  _VERBOSE("Image::get_matrix");

  args.verify_length(0);

  double m[6];
  srcMatrix.store_to(m);
  Py::Tuple ret(6);
  for(int i=0;i<6;i++)
    ret[i] = Py::Float(m[i]);
  return ret;
}
Пример #11
0
Py::Object
FT2Font::get_glyph_name(const Py::Tuple & args) {
  _VERBOSE("FT2Font::get_glyph_name");
  args.verify_length(1);

  if (!FT_HAS_GLYPH_NAMES(face))
    throw Py::RuntimeError("Face has no glyph names");

  char buffer[128];
  if (FT_Get_Glyph_Name(face, (FT_UInt) Py::Int(args[0]), buffer, 128))
    Py::RuntimeError("Could not get glyph names.");
  return Py::String(buffer);
}
Пример #12
0
Py::Object _path_module::point_in_path(const Py::Tuple& args)
{
    args.verify_length(4);

    double x = Py::Float(args[0]);
    double y = Py::Float(args[1]);
    PathIterator path(args[2]);
    agg::trans_affine trans = py_to_agg_transformation_matrix(args[3], false);

    if (::point_in_path(x, y, path, trans))
        return Py::Int(1);
    return Py::Int(0);
}
Пример #13
0
Py::Object
FT2Font::image_as_str(const Py::Tuple & args) {
  _VERBOSE("FT2Font::image_as_str");
  args.verify_length(0);
  
  return Py::asObject(
		    Py_BuildValue("lls#", 
				  image.width, 
				  image.height, 
				  image.buffer, 
				  image.width*image.height)
		    );
}
Пример #14
0
Py::Object 
Affine::as_vec6(const Py::Tuple &args) {
  _VERBOSE("Affine::as_vec6");
  //return the affine as length 6 list
  args.verify_length(0);
  Py::List ret(6);
  ret[0] = Py::Object(_a);
  ret[1] = Py::Object(_b);
  ret[2] = Py::Object(_c);
  ret[3] = Py::Object(_d);
  ret[4] = Py::Object(_tx);
  ret[5] = Py::Object(_ty);
  return ret;
}
Пример #15
0
Py::Object
Affine::deepcopy(const Py::Tuple &args) {
  _VERBOSE("Affine::deepcopy");
  args.verify_length(0);
  try {
    eval_scalars();
  }
  catch(...) {
    throw Py::ValueError("Domain error on Affine deepcopy");
  }

  return Py::asObject( new Affine( new Value(_aval),new Value(_bval), new Value(_cval),
                                   new Value(_dval),new Value(_txval),new Value(_tyval) ));
}
Пример #16
0
Py::Object
Image::as_rgba_str(const Py::Tuple& args, const Py::Dict& kwargs) {
  _VERBOSE("Image::as_rgba_str");

  args.verify_length(0);

  std::pair<agg::int8u*,bool> bufpair = _get_output_buffer();

  Py::Object ret =  Py::asObject(Py_BuildValue("lls#", rowsOut, colsOut,
					       bufpair.first, colsOut*rowsOut*4));

  if (bufpair.second) delete [] bufpair.first;
  return ret;
}
Пример #17
0
Py::Object 
_transforms_module::new_funcxy (const Py::Tuple &args)
{
  _VERBOSE("_transforms_module::new_funcxy ");
  args.verify_length(2);
  if (!Func::check(args[0]))
    throw Py::TypeError("FuncXY(funcx, funcy) expected a Func instance for funcx)");
  if (!Func::check(args[1]))
    throw Py::TypeError("FuncXY(funcx, funcy) expected a Func instance for funcy)");
  Func* funcx  = static_cast<Func*>(args[0].ptr());
  Func* funcy  = static_cast<Func*>(args[1].ptr());

  return Py::asObject(new FuncXY(funcx, funcy));
}   
Пример #18
0
Py::Object
_path_module::path_in_path(const Py::Tuple& args)
{
    args.verify_length(4);

    PathIterator a(args[0]);
    agg::trans_affine atrans = py_to_agg_transformation_matrix(
        args[1].ptr(), false);
    PathIterator b(args[2]);
    agg::trans_affine btrans = py_to_agg_transformation_matrix(
        args[3].ptr(), false);

    return Py::Int(::path_in_path(a, atrans, b, btrans));
}
Пример #19
0
Py::Object 
RendererAgg::write_rgba(const Py::Tuple& args) {
  _VERBOSE("RendererAgg::write_rgba");
  
  args.verify_length(1);  
  std::string fname = Py::String( args[0]);
  
  std::ofstream of2( fname.c_str(), std::ios::binary|std::ios::out);
  for (size_t i=0; i<NUMBYTES; ++i) {
    of2.write((char*)&(pixBuffer[i]), sizeof(char));
  }
  return Py::Object();
  
}
Пример #20
0
Py::Object CyPy_Task::irrelevant(const Py::Tuple& args)
{
    m_value->irrelevant();
    if (args.size() > 0) {
        args.verify_length(1);
        Atlas::Objects::Operation::Error e;
        Atlas::Objects::Entity::Anonymous arg;
        arg->setAttr("message", verifyString(args.front()));
        e->modifyArgs().push_back(arg);
        e->setTo(m_value->m_usageInstance.actor->getId());
        return CyPy_Operation::wrap(e);
    }
    return Py::None();
}
Пример #21
0
Py::Object 
Bbox::update(const Py::Tuple &args) {
  _VERBOSE("Bbox::update");
  args.verify_length(2);

  Py::SeqBase<Py::Object> xys = args[0];

  //don't use current bounds when updating box if ignore==1
  int ignore = Py::Int(args[1]);  
  size_t Nx = xys.length();
  if (Nx==0) return Py::Object();

  double minx = _ll->xval();
  double maxx = _ur->xval();
  double miny = _ll->yval();
  double maxy = _ur->yval();

  Py::Tuple tup;
  if (ignore) {
    tup = xys[0];
    double x = Py::Float(tup[0]);
    double y = Py::Float(tup[1]);

    minx=x;
    maxx=x;
    miny=y;
    maxy=y;
  }


  for (size_t i=0; i<Nx; ++i) {
    tup = xys[i];
    double x = Py::Float(tup[0]);
    double y = Py::Float(tup[1]);

    if (x<minx) minx=x;
    if (x>maxx) maxx=x;
    if (y<miny) miny=y;
    if (y>maxy) maxy=y;

  } 


  _ll->x_api()->set_api(minx);
  _ll->y_api()->set_api(miny);
  _ur->x_api()->set_api(maxx);
  _ur->y_api()->set_api(maxy);
  return Py::Object();
}
Пример #22
0
Py::Object
FT2Font::draw_glyphs_to_bitmap(const Py::Tuple & args) {
  _VERBOSE("FT2Font::draw_glyphs_to_bitmap");
  args.verify_length(0);
  
  FT_BBox string_bbox = compute_string_bbox();
  
  image.width   = (string_bbox.xMax-string_bbox.xMin) / 64+2;
  image.height  = (string_bbox.yMax-string_bbox.yMin) / 64+2;
  
  image.offsetx = (int)(string_bbox.xMin/64.0);
  if (angle==0)  
    image.offsety = -image.height;
  else
    image.offsety = (int)(-string_bbox.yMax/64.0);
  
  size_t numBytes = image.width*image.height;
  delete [] image.buffer;
  image.buffer = new unsigned char [numBytes];
  for (size_t n=0; n<numBytes; n++) 
    image.buffer[n] = 0;
  
  for ( size_t n = 0; n < glyphs.size(); n++ )
    {
      FT_BBox bbox;
      
      FT_Glyph_Get_CBox(glyphs[n], ft_glyph_bbox_pixels, &bbox);
      
      error = FT_Glyph_To_Bitmap(&glyphs[n],
				 ft_render_mode_normal,
				 0,
				 //&pos[n],
				 1  //destroy image; 
				 );
      if (error)
	throw Py::RuntimeError("Could not convert glyph to bitmap");
      
      FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n];
      /* now, draw to our target surface (convert position) */
      
      //bitmap left and top in pixel, string bbox in subpixel
      
      draw_bitmap( &bitmap->bitmap, 
		   bitmap->left-string_bbox.xMin/64,
		   string_bbox.yMax/64-bitmap->top+1
		   );
    }
  return Py::Object();
}
Пример #23
0
Py::Object TriContourGenerator::create_contour(const Py::Tuple &args)
{
    _VERBOSE("TriContourGenerator::create_contour");
    args.verify_length(1);

    double level = (Py::Float)args[0];

    clear_visited_flags(false);
    Contour contour;

    find_boundary_lines(contour, level);
    find_interior_lines(contour, level, false, false);

    return contour_to_segs(contour);
}
Пример #24
0
Py::Object
FT2Font::set_size(const Py::Tuple & args) {
  _VERBOSE("FT2Font::set_size");
  args.verify_length(2);
  
  double ptsize = Py::Float(args[0]);
  double dpi = Py::Float(args[1]);

  int error = FT_Set_Char_Size( face, (long)(ptsize * 64), 0, 
				(unsigned int)dpi, 
				(unsigned int)dpi );
  if (error) 
    throw Py::RuntimeError("Could not set the fontsize");  
  return Py::Object();
}
Пример #25
0
Py::Object 
RendererAgg::draw_image(const Py::Tuple& args) {
  _VERBOSE("RendererAgg::draw_image");
  args.verify_length(4);
  
  int x = Py::Int(args[0]);
  int y = Py::Int(args[1]);
  Image *image = static_cast<Image*>(args[2].ptr());
  std::string origin = Py::String(args[3]);
  
  if (origin!="lower" && origin!="upper")
    throw Py::ValueError("origin must be upper|lower");
  
  bool isUpper = origin=="upper";
  //std::cout << "agg says isupper " << origin << " " << isUpper << std::endl;

  
  //todo: handle x and y
  //agg::rect r(0, 0, image->colsOut, image->rowsOut);
  //rendererBase->copy_from(*image->rbufOut, &r, x, y);
  size_t ind=0;
  size_t thisx, thisy;
  size_t oy = isUpper ? y : height-y;
  //if (isUpper) oy -= image->rowsOut;  //start at top
  //std::cout << "params " << height << " " << y << " " << oy << " " << image->rowsOut << std::endl;
  for (size_t j=0; j<image->rowsOut; j++) {
    for (size_t i=0; i<image->colsOut; i++) {
      thisx = i+x; 
      thisy =  isUpper ?  oy+j : oy-j; 

      if (thisx<0 || thisx>=width || thisy<0 || thisy>=height) {
	ind += 4;
	continue;
      }
	
      pixfmt::color_type p;
      p.r = *(image->bufferOut+ind++);
      p.g = *(image->bufferOut+ind++);
      p.b = *(image->bufferOut+ind++);
      p.a = *(image->bufferOut+ind++);

      pixFmt->blend_pixel(thisx, thisy, p, p.a);
    }
  }

  return Py::Object();
  
}
Пример #26
0
Py::Object 
_transforms_module::new_bbox (const Py::Tuple &args)
{
  _VERBOSE("_transforms_module::new_bbox ");
  
  args.verify_length(2);
  
  if (!Point::check(args[0])) 
    throw Py::TypeError("Point(p1,p2) expected a Point for p1");
  if (!Point::check(args[1])) 
    throw Py::TypeError("Point(p1,p2) expected a Point for p2");
  
  Point* ll = static_cast<Point*>(args[0].ptr());
  Point* ur = static_cast<Point*>(args[1].ptr());
  return Py::asObject(new Bbox(ll, ur) );  
}
Пример #27
0
Py::Object
FT2Font::get_charmap(const Py::Tuple & args) {
  _VERBOSE("FT2Font::get_charmap");
  args.verify_length(0);
  
  FT_UInt index;
  Py::Dict charmap;
  
  FT_ULong code = FT_Get_First_Char(face, &index);
  while (code != 0) {
    //charmap[Py::Long((long) code)] = Py::Int((int) index);
    charmap[Py::Int((int) index)] = Py::Long((long) code);
    code = FT_Get_Next_Char(face, code, &index);
  }
  return charmap;
}
Пример #28
0
Py::Object _path_module::clip_path_to_rect(const Py::Tuple &args)
{
    args.verify_length(3);

    PathIterator path(args[0]);
    Py::Object bbox_obj = args[1];
    bool inside = Py::Int(args[2]);

    double x0, y0, x1, y1;
    if (!py_convert_bbox(bbox_obj.ptr(), x0, y0, x1, y1))
        throw Py::TypeError("Argument 2 to clip_to_rect must be a Bbox object.");

    std::vector<Polygon> results;

    ::clip_to_rect(path, x0, y0, x1, y1, inside, results);

    npy_intp dims[2];
    dims[1] = 2;
    PyObject* py_results = PyList_New(results.size());
    if (!py_results)
        throw Py::RuntimeError("Error creating results list");
    try
    {
        for (std::vector<Polygon>::const_iterator p = results.begin(); p != results.end(); ++p)
        {
            size_t size = p->size();
            dims[0] = p->size();
            PyArrayObject* pyarray = (PyArrayObject*)PyArray_SimpleNew(2, dims, PyArray_DOUBLE);
            for (size_t i = 0; i < size; ++i)
            {
                ((double *)pyarray->data)[2*i]	 = (*p)[i].x;
                ((double *)pyarray->data)[2*i+1] = (*p)[i].y;
            }
            if (PyList_SetItem(py_results, p - results.begin(), (PyObject *)pyarray) != -1)
            {
                throw Py::RuntimeError("Error creating results list");
            }
        }
    }
    catch (...)
    {
        Py_XDECREF(py_results);
        throw;
    }

    return Py::Object(py_results, true);
}
Пример #29
0
Py::Object _path_module::count_bboxes_overlapping_bbox(const Py::Tuple& args)
{
    args.verify_length(2);

    Py::Object		    bbox   = args[0];
    Py::SeqBase<Py::Object> bboxes = args[1];

    double ax0, ay0, ax1, ay1;
    double bx0, by0, bx1, by1;
    long count = 0;

    if (py_convert_bbox(bbox.ptr(), ax0, ay0, ax1, ay1))
    {
        if (ax1 < ax0)
            std::swap(ax0, ax1);
        if (ay1 < ay0)
            std::swap(ay0, ay1);

        size_t num_bboxes = bboxes.size();
        for (size_t i = 0; i < num_bboxes; ++i)
        {
            Py::Object bbox_b = bboxes[i];
            if (py_convert_bbox(bbox_b.ptr(), bx0, by0, bx1, by1))
            {
                if (bx1 < bx0)
                    std::swap(bx0, bx1);
                if (by1 < by0)
                    std::swap(by0, by1);
                if (!((bx1 <= ax0) ||
                      (by1 <= ay0) ||
                      (bx0 >= ax1) ||
                      (by0 >= ay1)))
                    ++count;
            }
            else
            {
                throw Py::ValueError("Non-bbox object in bboxes list");
            }
        }
    }
    else
    {
        throw Py::ValueError("First argument to count_bboxes_overlapping_bbox must be a Bbox object.");
    }

    return Py::Int(count);
}
Пример #30
0
Py::Object 
_transforms_module::new_interval (const Py::Tuple &args)
{
  _VERBOSE("_transforms_module::new_interval ");
  
  args.verify_length(2);
  
  if (!LazyValue::check(args[0])) 
    throw Py::TypeError("Interval(val1, val2) expected a LazyValue for val1");
  if (!LazyValue::check(args[1])) 
    throw Py::TypeError("Interval(val1, val2) expected a LazyValue for val2");
  
  
  LazyValue* v1 = static_cast<LazyValue*>(args[0].ptr());
  LazyValue* v2 = static_cast<LazyValue*>(args[1].ptr());
  return Py::asObject(new Interval(v1, v2) );  
}