not entirely sure, but an idea or two:
I am writing a python module for the following utility:
SeExpr/src/demos/imageSynth/imageSynth.cpp at main · wdas/SeExpr · GitHub
For pixel data I am generating a list like this:
PyList_Append(list, Py_BuildValue("i", (unsigned
char)clamp(result[1]*256.)));
PyList_Append(list, Py_BuildValue("i", (unsigned
char)clamp(result[1]*256.)));
PyList_Append(list, Py_BuildValue("i", (unsigned
char)clamp(result[2]*256.)));
PyList_Append(list, Py_BuildValue("i", 255));
why use a list? -- as you know, you'll need to use a binary
compatible implimentation later, so I"d put those either in a
array.array object from the C++ (I'm pretty sure the C api is
documented), or even a string (or bytes object), or, in fact, you
could create an object that support the buffer protocol.
but none of that is probably the source of your problem.
mlist = seexpr("noise(10*$u,10*$v)", width, height)
bytes = array.array('B', mlist)
rgbBmp = wx.BitmapFromBuffer(width, height, bytes)
do you have the data in the right order for an image? i.e. row-major
vs. column major? I'd experiment with that. IIRC, numpy natively
stores the data in a different order (height, width) vs. (width,
height) -- and numpy natively uses C order -- which you may be using
also. I"d look into that.
I also see that your C++ code is appending result[1] twice, then
result[2]. if you car converting from greyscale to RGB, wouldn't you
want to write each value three times?
It looks like you are trying te reduce dependencies, but PIL might be
helpful here -- it can work natively with greyscale.
I would also appreciate if some one point me out how to write python's array
of "B" type in 'C' for above situation.
I've never done it, but it should be pretty straightforward form teh
API -- or, as I mentioned above, use a bytes object.
I don't want to use numpy's array
for extra dependency.
but it would be easier....
another option is Cython -- it makes it much easier to do this sort of
thing -- it support bytes objects, numpy arrays (I know, you dont want
to use them...), and I think array.array support was just added to the
development version.
HTH,
-Chris
···
On Mon, May 21, 2012 at 12:34 AM, King <animator333@gmail.com> wrote:
--
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.Barker@noaa.gov