コード例 #1
0
ファイル: agg_bmp.cpp プロジェクト: enthought/enable
  PyObject* pixel_map::convert_to_rgbarray() const {
    unsigned w = width();
    unsigned h = height();
    pix_format_e format = get_pix_format();
    rgba8 c;
    unsigned i,j;
    npy_intp dims[3];
    PyObject* arr = NULL;
    char* data = NULL;
    dims[0] = w;
    dims[1] = h;
    dims[2] = 3;
    import_array();
    arr = PyArray_SimpleNew(3,dims,PyArray_BYTE);
    if (arr==NULL)
      return NULL;
    data = ((PyArrayObject *)arr)->data;

    switch (format) {
    case pix_format_bgra32:
      {
	pixfmt_bgra32 r((rendering_buffer&)m_rbuf_window);

	for (j=0;j<h;++j)
	  for (i=0;i<w;++i)
	    {
	      c = r.pixel(i,h-j-1);
	      *(data++) = (char)c.r;
	      *(data++) = (char)c.g;
	      *(data++) = (char)c.b;
	    }
      }
      break;
    case pix_format_rgb24:
      {
	pixfmt_rgb24 r((rendering_buffer&)m_rbuf_window);

	for (j=0;j<h;++j)
	{
	  memcpy(data, r.row_ptr(h-j-1), w*3);
	  data += w*3;
	}
      }
      break;
    default:
      fprintf(stderr,"pix_format %d not handled!\n",format);
    }
    return arr;
  }
コード例 #2
0
ファイル: agg_bmp.cpp プロジェクト: pib/enable
    // Convert to a Python string containing 32 bit ARGB values.
    PyObject* pixel_map::convert_to_argb32string() const
    {
	    unsigned w = width();
	    unsigned h = height();

	    PyObject *str = PyString_FromStringAndSize(NULL, w * h * 4);

	    if (str == NULL)
	      return NULL;

	    unsigned *data = (unsigned *)PyString_AS_STRING(str);

	    pix_format_e format = get_pix_format();

	    switch (format)
	    {
	    case pix_format_bgra32:
	      {
	        pixfmt_bgra32 r((rendering_buffer &)m_rbuf_window);

	        for (unsigned j = 0; j < h; ++j)
	          for (unsigned i = 0; i < w; ++i)
	          {
	            rgba8 c = r.pixel(i, h - j - 1);

	            *data++ = (((unsigned char)c.a) << 24) |
	                      (((unsigned char)c.r) << 16) |
	                      (((unsigned char)c.g) << 8) |
	                      ((unsigned char)c.b);
	          }
	      }
	      break;

	    default:
	      Py_DECREF(str);
	      PyErr_Format(PyExc_ValueError, "pix_format %d not handled", format);
	      return NULL;
	    }

	    return str;
  }
コード例 #3
0
ファイル: agg_bmp.cpp プロジェクト: enthought/enable
  wxImage* pixel_map::convert_to_wximage() const {
    unsigned w = width();
    unsigned h = height();
#ifdef WX_RELEASE_2_5
    wxImage* image = new wxImage(w, h, false);
#else
    wxImage* image = new wxImage(w, h);
#endif
    unsigned char* data = image->GetData();
    pix_format_e format = get_pix_format();
    rgba8 c;
    unsigned i,j;
    switch (format) {
    case pix_format_bgra32:
#ifdef WX_RELEASE_2_5
      image->SetAlpha();
      printf("image->HasAlpha()=%d\n",image->HasAlpha());
#endif
      {
	pixel_formats_rgba32<order_bgra32> r((rendering_buffer&)m_rbuf_window);

	for (j=0;j<h;++j)
	  for (i=0;i<w;++i)
	    {
	      c = r.pixel(i,h-j-1);
	      *(data++) = (unsigned char)c.r;
	      *(data++) = (unsigned char)c.g;
	      *(data++) = (unsigned char)c.b;
#ifdef WX_RELEASE_2_5
	      image->SetAlpha((int)i,(int)j,(unsigned char)c.a);
#endif
	    }
      }
      break;
    default:
      fprintf(stderr,"pix_format %d not handled!\n",format);
    }
    return image;
  }