Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing cython produces error (methodobject.c) but pure python implementation works
    primarykey
    data
    text
    <p>I have the following class for using and manipulating images with pygame:</p> <pre><code>class Image: def __init__(self,file_path=None, width=0, height=0): try: self.image = pygame.image.load(file_path) except: raise IOError self.width = self.image.get_size()[0] self.height = self.image.get_size()[1] def copy(self): return Image(0, 0, self.file_path) def __getitem__(self, key): x, y = key internal_pxarray = pygame.PixelArray(self.image) rgb_int = internal_pxarray[x][y] rgb = self.image.unmap_rgb(rgb_int) if len(rgb) == 4: return rgb[:-1] elif len(rgb) == 3: return rgb else: return None def __setitem__(self, key, value): internal_pxarray = pygame.PixelArray(self.image) x, y = key internal_pxarray[x][y] = pygame.Color(value[0], value[1], value[2]) self.image = internal_pxarray.make_surface() </code></pre> <p>which I use like this:</p> <pre><code>image = Image('test.bmp') window.displayImage(image) for x in range(0, image.width): for y in range(0, image.height): ... image[x, y] = 250, 218, 221 </code></pre> <p>I tried to make this faster by using cython on the module containing the Image class but when I run the code now this line <code>internal_pxarray[x][y] = pygame.Color(value[0], value[1], value[2])</code> seems to cause the following error:</p> <pre><code>Traceback (most recent call last): File "../pink.py", line 13, in &lt;module&gt; image[x, y] = 250, 218, 221 File "imgproc.py", line 51, in imgproc.Image.__setitem__ (imgproc.c:2256) self.image = internal_pxarray.make_surface() SystemError: /Users/sysadmin/build/v2.7.3/Objects/methodobject.c:120: bad argument to internal function </code></pre> <p>and I can't figure out why, I've tried stepping through with pudb but everything seems fine.</p> <p>The corresponding line in the compiled *.c file is <code>__pyx_t_6 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;}</code></p> <p>Looking at <a href="https://github.com/yaogangqiang/Python-2.7.3/blob/master/Objects/methodobject.c" rel="nofollow">methodobject.c</a> it seems that this error is raised as the default (via <code>PyErr_BadInternalCall();</code> in <code>PyObject_Call</code> when the method arguments aren't valid. But my C knowledge is too limited to figure our exactly whats going on here.</p> <p>Any Ideas?</p> <p>Thanks,</p> <p>Jake</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload