On Mon, Dec 3, 2012 at 12:24 PM, Chris Barker - NOAA Federal
<chris.bar...@noaa.gov> wrote:

>>>> but some of that complexity could be reduced by using Numpy arrays in place

>> It would at least make this a more fair comparison to have the Cython
>> code as Cythonic as possible.  However, I couldn't find any ways around
>> using these particular APIs -- other than the Numpy stuff which probably
>> does have a more elegant solution in the form of Cython arrays and
>> memory views.

OK -- so I poked at it, and this is my (very untested) version of
write_png (I left out the py3 stuff, though it does look like it may
be required for file handling...

Letting Cython unpack the numpy array is the real win. Maybe having it
this simple won't work for MPL, but this is what my code tends to look
like.


def write_png(cnp.ndarray[cnp.uint32, ndim=2, mode="c" ] buff not None,
              file_obj,
              double dpi=0.0):

    cdef png_uint_32 width  = buff.size[0]
    cdef png_uint_32 height = buff.size[1]

    if PyFile_CheckExact(file_obj):
        cdef FILE *fp = fdopen(file_obj.fileno(), "w")
        fp = PyFile_AsFile(file_obj)
        write_png_c(buff[0,0], width, height, fp,
                    NULL, NULL, NULL, dpi)
        return
    else:
        raise TypeError("write_png only works with real PyFileObject")


NOTE: that could be:

cnp.ndarray[cnp.uint8, ndim=3, mode="c" ]

I'm not sure how MPL stores image buffers.

or you could accept any object, then call:

np.view()

-Chris



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to