Generated by Cython 0.28.5
Yellow lines hint at Python interaction.
Click on a line that starts with a "+
" to see the C code that Cython generated for it.
Raw output: cairo_workaround.c
001: # This file is part of Xpra.
002: # Copyright (C) 2014-2017 Antoine Martin <antoine@devloop.org.uk>
003: # Xpra is released under the terms of the GNU GPL v2, or, at your option, any
004: # later version. See the file COPYING for details.
005:
006: # What is this workaround you ask?
007: # Well, pycairo can't handle raw pixel data in RGB format,
008: # and that's despite the documentation saying otherwise:
009: # http://cairographics.org/pythoncairopil/
010: # Because of this glaring omission, we would have to roundtrip via PNG.
011: # This workaround populates an image surface with RGB pixels using Cython.
012: # (not the most efficient implementation, but still 10 times faster than the alternative)
013: #
014: #"cairo.ImageSurface.create_for_data" is not implemented in GTK3!
015: # http://cairographics.org/documentation/pycairo/3/reference/surfaces.html#cairo.ImageSurface.create_for_data
016: # "Not yet available in Python 3"
017: #
018: #It is available in the cffi cairo bindings, which can be used instead of pycairo
019: # but then we can't use it from the draw callbacks:
020: # https://mail.gnome.org/archives/python-hackers-list/2011-December/msg00004.html
021: # "PyGObject just lacks the glue code that allows it to pass the statically-wrapped
022: # cairo.Pattern to introspected methods"
023:
024:
025: #cython: boundscheck=False
026: from __future__ import absolute_import
027:
028:
+029: import cairo
__pyx_t_1 = __Pyx_Import(__pyx_n_s_cairo, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_cairo, __pyx_t_1) < 0) __PYX_ERR(0, 29, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
030: from xpra.buffers.membuf cimport object_as_buffer
031: from libc.stdint cimport uintptr_t
032:
033:
034: cdef extern from "Python.h":
035: ctypedef struct PyObject:
036: pass
037: void * PyCapsule_Import(const char *name, int no_block)
038: object PyBuffer_FromMemory(void *ptr, Py_ssize_t size)
039: int PyObject_AsReadBuffer(object obj, void ** buffer, Py_ssize_t * buffer_len) except -1
040:
041: cdef extern from "string.h":
042: void* memcpy(void * destination, void * source, size_t num)
043:
044: cdef extern from "cairo/cairo.h":
045: ctypedef struct cairo_surface_t:
046: pass
047:
048: #typedef enum _cairo_format {
049: ctypedef enum cairo_format_t:
050: CAIRO_FORMAT_INVALID
051: CAIRO_FORMAT_ARGB32
052: CAIRO_FORMAT_RGB24
053: CAIRO_FORMAT_A8
054: CAIRO_FORMAT_A1
055: CAIRO_FORMAT_RGB16_565
056: CAIRO_FORMAT_RGB30
057:
058: unsigned char * cairo_image_surface_get_data(cairo_surface_t *surface)
059: cairo_format_t cairo_image_surface_get_format(cairo_surface_t *surface)
060:
061: int cairo_image_surface_get_width (cairo_surface_t *surface)
062: int cairo_image_surface_get_height (cairo_surface_t *surface)
063: int cairo_image_surface_get_stride (cairo_surface_t *surface)
064:
065: void cairo_surface_flush (cairo_surface_t *surface)
066: void cairo_surface_mark_dirty (cairo_surface_t *surface)
067:
068: cdef extern from "pycairo/pycairo.h":
069: ctypedef struct Pycairo_CAPI_t:
070: pass
071: ctypedef struct PycairoSurface:
072: #PyObject_HEAD
073: cairo_surface_t *surface
074: #PyObject *base; /* base object used to create surface, or NULL */
075: ctypedef PycairoSurface PycairoImageSurface
076:
077: CAIRO_FORMAT = {
+078: CAIRO_FORMAT_INVALID : "Invalid",
__pyx_t_1 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_INVALID); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_n_s_Invalid) < 0) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+079: CAIRO_FORMAT_ARGB32 : "ARGB32",
__pyx_t_2 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_ARGB32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_n_s_ARGB32) < 0) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+080: CAIRO_FORMAT_RGB24 : "RGB24",
__pyx_t_2 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_RGB24); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 80, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_n_s_RGB24) < 0) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+081: CAIRO_FORMAT_A8 : "A8",
__pyx_t_2 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_A8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 81, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_n_s_A8) < 0) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+082: CAIRO_FORMAT_A1 : "A1",
__pyx_t_2 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_A1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_n_s_A1) < 0) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+083: CAIRO_FORMAT_RGB16_565 : "RGB16_565",
__pyx_t_2 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_RGB16_565); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 83, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_n_s_RGB16_565) < 0) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+084: CAIRO_FORMAT_RGB30 : "RGB30",
__pyx_t_2 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_RGB30); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_n_s_RGB30) < 0) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyDict_SetItem(__pyx_d, __pyx_n_s_CAIRO_FORMAT, __pyx_t_1) < 0) __PYX_ERR(0, 77, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
085: }
086:
+087: def set_image_surface_data(object image_surface, rgb_format, object pixel_data, int width, int height, int stride):
/* Python wrapper */ static PyObject *__pyx_pw_4xpra_6client_4gtk3_16cairo_workaround_1set_image_surface_data(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_4xpra_6client_4gtk3_16cairo_workaround_1set_image_surface_data = {"set_image_surface_data", (PyCFunction)__pyx_pw_4xpra_6client_4gtk3_16cairo_workaround_1set_image_surface_data, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_4xpra_6client_4gtk3_16cairo_workaround_1set_image_surface_data(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_image_surface = 0; PyObject *__pyx_v_rgb_format = 0; PyObject *__pyx_v_pixel_data = 0; int __pyx_v_width; int __pyx_v_height; int __pyx_v_stride; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("set_image_surface_data (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_image_surface,&__pyx_n_s_rgb_format,&__pyx_n_s_pixel_data,&__pyx_n_s_width,&__pyx_n_s_height,&__pyx_n_s_stride,0}; PyObject* values[6] = {0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_image_surface)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rgb_format)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 1); __PYX_ERR(0, 87, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pixel_data)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 2); __PYX_ERR(0, 87, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_width)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 3); __PYX_ERR(0, 87, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_height)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 4); __PYX_ERR(0, 87, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_stride)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 5); __PYX_ERR(0, 87, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_image_surface_data") < 0)) __PYX_ERR(0, 87, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); } __pyx_v_image_surface = values[0]; __pyx_v_rgb_format = values[1]; __pyx_v_pixel_data = values[2]; __pyx_v_width = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_width == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 87, __pyx_L3_error) __pyx_v_height = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_height == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 87, __pyx_L3_error) __pyx_v_stride = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_stride == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 87, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 87, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("xpra.client.gtk3.cairo_workaround.set_image_surface_data", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_4xpra_6client_4gtk3_16cairo_workaround_set_image_surface_data(__pyx_self, __pyx_v_image_surface, __pyx_v_rgb_format, __pyx_v_pixel_data, __pyx_v_width, __pyx_v_height, __pyx_v_stride); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_4xpra_6client_4gtk3_16cairo_workaround_set_image_surface_data(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_image_surface, PyObject *__pyx_v_rgb_format, PyObject *__pyx_v_pixel_data, int __pyx_v_width, int __pyx_v_height, int __pyx_v_stride) { unsigned char const *__pyx_v_cbuf; Py_ssize_t __pyx_v_cbuf_len; cairo_surface_t *__pyx_v_surface; unsigned char *__pyx_v_data; cairo_format_t __pyx_v_format; int __pyx_v_istride; int __pyx_v_iwidth; int __pyx_v_iheight; int __pyx_v_x; int __pyx_v_y; int __pyx_v_srci; int __pyx_v_dsti; uintptr_t __pyx_v_src; uintptr_t __pyx_v_dst; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("set_image_surface_data", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("xpra.client.gtk3.cairo_workaround.set_image_surface_data", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple_ = PyTuple_Pack(20, __pyx_n_s_image_surface, __pyx_n_s_rgb_format, __pyx_n_s_pixel_data, __pyx_n_s_width, __pyx_n_s_height, __pyx_n_s_stride, __pyx_n_s_cbuf, __pyx_n_s_cbuf_len, __pyx_n_s_surface, __pyx_n_s_data, __pyx_n_s_format, __pyx_n_s_istride, __pyx_n_s_iwidth, __pyx_n_s_iheight, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_srci, __pyx_n_s_dsti, __pyx_n_s_src, __pyx_n_s_dst); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 87, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4xpra_6client_4gtk3_16cairo_workaround_1set_image_surface_data, NULL, __pyx_n_s_xpra_client_gtk3_cairo_workaroun_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_image_surface_data, __pyx_t_1) < 0) __PYX_ERR(0, 87, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
088: #convert pixel_data to a C buffer:
+089: cdef const unsigned char * cbuf = <unsigned char *> 0
__pyx_v_cbuf = ((unsigned char *)0);
+090: cdef Py_ssize_t cbuf_len = 0
__pyx_v_cbuf_len = 0;
+091: assert object_as_buffer(pixel_data, <const void**> &cbuf, &cbuf_len)==0, "cannot convert %s to a readable buffer" % type(pixel_data)
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_f_4xpra_7buffers_6membuf_object_as_buffer(__pyx_v_pixel_data, ((void const **)(&__pyx_v_cbuf)), (&__pyx_v_cbuf_len)) == 0) != 0))) { __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_cannot_convert_s_to_a_readable_b, ((PyObject *)Py_TYPE(__pyx_v_pixel_data))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 91, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); PyErr_SetObject(PyExc_AssertionError, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 91, __pyx_L1_error) } } #endif
+092: assert cbuf_len>=height*stride, "pixel buffer is too small for %sx%s with stride=%s: only %s bytes, expected %s" % (width, height, stride, cbuf_len, height*stride)
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_v_cbuf_len >= (__pyx_v_height * __pyx_v_stride)) != 0))) { __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_width); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_height); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_stride); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_cbuf_len); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyInt_From_int((__pyx_v_height * __pyx_v_stride)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = PyTuple_New(5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 4, __pyx_t_5); __pyx_t_1 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_pixel_buffer_is_too_small_for_sx, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_5); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 92, __pyx_L1_error) } } #endif
093: #convert cairo.ImageSurface python object to a cairo_surface_t
+094: if not isinstance(image_surface, cairo.ImageSurface):
__pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_cairo); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 94, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_ImageSurface); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 94, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_7 = PyObject_IsInstance(__pyx_v_image_surface, __pyx_t_6); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 94, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_8 = ((!(__pyx_t_7 != 0)) != 0); if (unlikely(__pyx_t_8)) { /* … */ }
+095: raise TypeError("object %r is not a %r" % (image_surface, cairo.ImageSurface))
__pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_cairo); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ImageSurface); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_INCREF(__pyx_v_image_surface); __Pyx_GIVEREF(__pyx_v_image_surface); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_image_surface); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_object_r_is_not_a_r, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_6, 0, 0, 0); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __PYX_ERR(0, 95, __pyx_L1_error)
+096: cdef cairo_surface_t * surface = (<PycairoImageSurface *> image_surface).surface
__pyx_t_9 = ((PycairoImageSurface *)__pyx_v_image_surface)->surface; __pyx_v_surface = __pyx_t_9;
+097: cairo_surface_flush(surface)
cairo_surface_flush(__pyx_v_surface);
+098: cdef unsigned char * data = cairo_image_surface_get_data(surface)
__pyx_v_data = cairo_image_surface_get_data(__pyx_v_surface);
099: #get surface attributes:
+100: cdef cairo_format_t format = cairo_image_surface_get_format(surface)
__pyx_v_format = cairo_image_surface_get_format(__pyx_v_surface);
+101: cdef int istride = cairo_image_surface_get_stride(surface)
__pyx_v_istride = cairo_image_surface_get_stride(__pyx_v_surface);
+102: cdef int iwidth = cairo_image_surface_get_width(surface)
__pyx_v_iwidth = cairo_image_surface_get_width(__pyx_v_surface);
+103: cdef int iheight = cairo_image_surface_get_height(surface)
__pyx_v_iheight = cairo_image_surface_get_height(__pyx_v_surface);
+104: assert iwidth>=width and iheight>=height, "invalid image surface: expected at least %sx%s but got %sx%s" % (width, height, iwidth, iheight)
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { __pyx_t_7 = ((__pyx_v_iwidth >= __pyx_v_width) != 0); if (__pyx_t_7) { } else { __pyx_t_8 = __pyx_t_7; goto __pyx_L4_bool_binop_done; } __pyx_t_7 = ((__pyx_v_iheight >= __pyx_v_height) != 0); __pyx_t_8 = __pyx_t_7; __pyx_L4_bool_binop_done:; if (unlikely(!__pyx_t_8)) { __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_width); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_height); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_iwidth); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_iheight); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3); __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_invalid_image_surface_expected_a, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(0, 104, __pyx_L1_error) } } #endif
+105: assert istride>=iwidth*4, "invalid image stride: expected at least %s but got %s" % (iwidth*4, istride)
#ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_v_istride >= (__pyx_v_iwidth * 4)) != 0))) { __pyx_t_3 = __Pyx_PyInt_From_long((__pyx_v_iwidth * 4)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_istride); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __pyx_t_3 = 0; __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_invalid_image_stride_expected_at, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 105, __pyx_L1_error) } } #endif
106: cdef int x, y
107: cdef int srci, dsti
108: cdef uintptr_t src, dst
109: #just deal with the formats we care about:
+110: if format==CAIRO_FORMAT_RGB24:
switch (__pyx_v_format) { case CAIRO_FORMAT_RGB24: /* … */ break;
111: #cairo's RGB24 format is actually stored as BGR on little endian
+112: if rgb_format=="BGR":
__pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_rgb_format, __pyx_n_s_BGR, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 112, __pyx_L1_error) if (__pyx_t_8) { /* … */ goto __pyx_L6; }
+113: for y in range(height):
__pyx_t_10 = __pyx_v_height; __pyx_t_11 = __pyx_t_10; for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_y = __pyx_t_12;
+114: for x in range(width):
__pyx_t_13 = __pyx_v_width; __pyx_t_14 = __pyx_t_13; for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) { __pyx_v_x = __pyx_t_15;
+115: srci = x*3 + y*stride
__pyx_v_srci = ((__pyx_v_x * 3) + (__pyx_v_y * __pyx_v_stride));
+116: dsti = x*4 + y*istride
__pyx_v_dsti = ((__pyx_v_x * 4) + (__pyx_v_y * __pyx_v_istride));
+117: data[dsti + 0] = cbuf[srci + 0] #B
(__pyx_v_data[(__pyx_v_dsti + 0)]) = (__pyx_v_cbuf[(__pyx_v_srci + 0)]);
+118: data[dsti + 1] = cbuf[srci + 1] #G
(__pyx_v_data[(__pyx_v_dsti + 1)]) = (__pyx_v_cbuf[(__pyx_v_srci + 1)]);
+119: data[dsti + 2] = cbuf[srci + 2] #R
(__pyx_v_data[(__pyx_v_dsti + 2)]) = (__pyx_v_cbuf[(__pyx_v_srci + 2)]);
+120: data[dsti + 3] = 255 #X
(__pyx_v_data[(__pyx_v_dsti + 3)]) = 0xFF; } }
+121: elif rgb_format=="RGB":
__pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_rgb_format, __pyx_n_s_RGB, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 121, __pyx_L1_error) if (likely(__pyx_t_8)) { /* … */ goto __pyx_L6; }
+122: for y in range(height):
__pyx_t_10 = __pyx_v_height; __pyx_t_11 = __pyx_t_10; for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_y = __pyx_t_12;
+123: for x in range(width):
__pyx_t_13 = __pyx_v_width; __pyx_t_14 = __pyx_t_13; for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) { __pyx_v_x = __pyx_t_15;
+124: srci = x*3 + y*stride
__pyx_v_srci = ((__pyx_v_x * 3) + (__pyx_v_y * __pyx_v_stride));
+125: dsti = x*4 + y*istride
__pyx_v_dsti = ((__pyx_v_x * 4) + (__pyx_v_y * __pyx_v_istride));
+126: data[dsti + 0] = cbuf[srci + 2] #B
(__pyx_v_data[(__pyx_v_dsti + 0)]) = (__pyx_v_cbuf[(__pyx_v_srci + 2)]);
+127: data[dsti + 1] = cbuf[srci + 1] #G
(__pyx_v_data[(__pyx_v_dsti + 1)]) = (__pyx_v_cbuf[(__pyx_v_srci + 1)]);
+128: data[dsti + 2] = cbuf[srci + 0] #R
(__pyx_v_data[(__pyx_v_dsti + 2)]) = (__pyx_v_cbuf[(__pyx_v_srci + 0)]);
+129: data[dsti + 3] = 255 #X
(__pyx_v_data[(__pyx_v_dsti + 3)]) = 0xFF; } }
130: else:
+131: raise ValueError("unhandled RGB format '%s'" % rgb_format)
/*else*/ { __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_unhandled_RGB_format_s, __pyx_v_rgb_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 131, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __PYX_ERR(0, 131, __pyx_L1_error) } __pyx_L6:;
132: #note: this one is currently unused because it doesn't work
133: #and I don't know why
134: #(we just disable 'rgb32' for gtk3... and fallback to png)
+135: elif format==CAIRO_FORMAT_ARGB32:
case CAIRO_FORMAT_ARGB32: /* … */ break; default:
+136: if rgb_format in ("RGBA", "RGBX"):
__Pyx_INCREF(__pyx_v_rgb_format); __pyx_t_4 = __pyx_v_rgb_format; __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_RGBA, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 136, __pyx_L1_error) if (!__pyx_t_7) { } else { __pyx_t_8 = __pyx_t_7; goto __pyx_L16_bool_binop_done; } __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_RGBX, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 136, __pyx_L1_error) __pyx_t_8 = __pyx_t_7; __pyx_L16_bool_binop_done:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = (__pyx_t_8 != 0); if (__pyx_t_7) { /* … */ goto __pyx_L15; }
+137: for x in range(width):
__pyx_t_10 = __pyx_v_width; __pyx_t_11 = __pyx_t_10; for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_x = __pyx_t_12;
+138: for y in range(height):
__pyx_t_13 = __pyx_v_height; __pyx_t_14 = __pyx_t_13; for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) { __pyx_v_y = __pyx_t_15;
+139: data[x*4 + 0 + y*istride] = cbuf[x*4 + 2 + y*stride] #A
(__pyx_v_data[(((__pyx_v_x * 4) + 0) + (__pyx_v_y * __pyx_v_istride))]) = (__pyx_v_cbuf[(((__pyx_v_x * 4) + 2) + (__pyx_v_y * __pyx_v_stride))]);
+140: data[x*4 + 1 + y*istride] = cbuf[x*4 + 1 + y*stride] #R
(__pyx_v_data[(((__pyx_v_x * 4) + 1) + (__pyx_v_y * __pyx_v_istride))]) = (__pyx_v_cbuf[(((__pyx_v_x * 4) + 1) + (__pyx_v_y * __pyx_v_stride))]);
+141: data[x*4 + 2 + y*istride] = cbuf[x*4 + 0 + y*stride] #G
(__pyx_v_data[(((__pyx_v_x * 4) + 2) + (__pyx_v_y * __pyx_v_istride))]) = (__pyx_v_cbuf[(((__pyx_v_x * 4) + 0) + (__pyx_v_y * __pyx_v_stride))]);
+142: data[x*4 + 3 + y*istride] = cbuf[x*4 + 3 + y*stride] #B
(__pyx_v_data[(((__pyx_v_x * 4) + 3) + (__pyx_v_y * __pyx_v_istride))]) = (__pyx_v_cbuf[(((__pyx_v_x * 4) + 3) + (__pyx_v_y * __pyx_v_stride))]); } }
+143: elif rgb_format in ("BGRA", "BGRX"):
__Pyx_INCREF(__pyx_v_rgb_format); __pyx_t_4 = __pyx_v_rgb_format; __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_BGRA, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 143, __pyx_L1_error) if (!__pyx_t_8) { } else { __pyx_t_7 = __pyx_t_8; goto __pyx_L22_bool_binop_done; } __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_BGRX, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 143, __pyx_L1_error) __pyx_t_7 = __pyx_t_8; __pyx_L22_bool_binop_done:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_8 = (__pyx_t_7 != 0); if (likely(__pyx_t_8)) { /* … */ }
+144: for y in range(height):
__pyx_t_10 = __pyx_v_height; __pyx_t_11 = __pyx_t_10; for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_y = __pyx_t_12;
+145: src = (<uintptr_t> cbuf) + y*stride
__pyx_v_src = (((uintptr_t)__pyx_v_cbuf) + (__pyx_v_y * __pyx_v_stride));
+146: dst = (<uintptr_t> data) + y*istride
__pyx_v_dst = (((uintptr_t)__pyx_v_data) + (__pyx_v_y * __pyx_v_istride));
+147: memcpy(<void*> dst, <void*> src, istride)
(void)(memcpy(((void *)__pyx_v_dst), ((void *)__pyx_v_src), __pyx_v_istride)); }
+148: cairo_surface_mark_dirty(surface)
cairo_surface_mark_dirty(__pyx_v_surface);
+149: return
__Pyx_XDECREF(__pyx_r); __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0;
150: else:
+151: raise ValueError("unhandled RGB format '%s'" % rgb_format)
/*else*/ { __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_unhandled_RGB_format_s, __pyx_v_rgb_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 151, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 151, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 151, __pyx_L1_error) } __pyx_L15:;
152: else:
+153: raise ValueError("unhandled cairo format '%s'" % format)
__pyx_t_2 = __Pyx_PyInt_From_cairo_format_t(__pyx_v_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_unhandled_cairo_format_s, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 153, __pyx_L1_error) break; }
+154: cairo_surface_mark_dirty(surface)
cairo_surface_mark_dirty(__pyx_v_surface);
+155: return
__Pyx_XDECREF(__pyx_r); __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0;
156:
157: cdef Pycairo_CAPI_t * Pycairo_CAPI
+158: Pycairo_CAPI = <Pycairo_CAPI_t*> PyCapsule_Import("cairo.CAPI", 0);
__pyx_v_4xpra_6client_4gtk3_16cairo_workaround_Pycairo_CAPI = ((Pycairo_CAPI_t *)PyCapsule_Import(((char const *)"cairo.CAPI"), 0));