Generated by Cython 0.29
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-2018 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, language_level=3
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) nogil
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/py3cairo.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_u_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_u_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_u_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_u_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_u_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_u_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_u_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)(void*)(PyCFunctionWithKeywords)__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_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_7); __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_PyUnicode_FormatSafe(__pyx_kp_u_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 = PyTuple_New(10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = 127; __Pyx_INCREF(__pyx_kp_u_pixel_buffer_is_too_small_for); __pyx_t_2 += 30; __Pyx_GIVEREF(__pyx_kp_u_pixel_buffer_is_too_small_for); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_pixel_buffer_is_too_small_for); __pyx_t_4 = __Pyx_PyUnicode_From_int(__pyx_v_width, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_n_u_x); __pyx_t_2 += 1; __Pyx_GIVEREF(__pyx_n_u_x); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_n_u_x); __pyx_t_4 = __Pyx_PyUnicode_From_int(__pyx_v_height, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u_with_stride); __pyx_t_2 += 13; __Pyx_GIVEREF(__pyx_kp_u_with_stride); PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_with_stride); __pyx_t_4 = __Pyx_PyUnicode_From_int(__pyx_v_stride, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u_only); __pyx_t_2 += 7; __Pyx_GIVEREF(__pyx_kp_u_only); PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_kp_u_only); __pyx_t_4 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_v_cbuf_len, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 7, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u_bytes_expected); __pyx_t_2 += 17; __Pyx_GIVEREF(__pyx_kp_u_bytes_expected); PyTuple_SET_ITEM(__pyx_t_1, 8, __pyx_kp_u_bytes_expected); __pyx_t_4 = __Pyx_PyUnicode_From_int((__pyx_v_height * __pyx_v_stride), 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 9, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 10, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 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_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_cairo); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 94, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ImageSurface); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 94, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_5 = PyObject_IsInstance(__pyx_v_image_surface, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 94, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_6 = ((!(__pyx_t_5 != 0)) != 0); if (unlikely(__pyx_t_6)) { /* … */ }
+095: raise TypeError("object %r is not a %r" % (image_surface, cairo.ImageSurface))
__pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = 127; __Pyx_INCREF(__pyx_kp_u_object); __pyx_t_2 += 7; __Pyx_GIVEREF(__pyx_kp_u_object); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_object); __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_image_surface), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3; __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u_is_not_a); __pyx_t_2 += 10; __Pyx_GIVEREF(__pyx_kp_u_is_not_a); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_is_not_a); __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_cairo); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ImageSurface); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_t_7), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_3; __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 4, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 95, __pyx_L1_error)
+096: cdef cairo_surface_t * surface = (<PycairoImageSurface *> image_surface).surface
__pyx_t_8 = ((PycairoImageSurface *)__pyx_v_image_surface)->surface; __pyx_v_surface = __pyx_t_8;
+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_5 = ((__pyx_v_iwidth >= __pyx_v_width) != 0); if (__pyx_t_5) { } else { __pyx_t_6 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } __pyx_t_5 = ((__pyx_v_iheight >= __pyx_v_height) != 0); __pyx_t_6 = __pyx_t_5; __pyx_L4_bool_binop_done:; if (unlikely(!__pyx_t_6)) { __pyx_t_1 = PyTuple_New(8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = 0; __pyx_t_3 = 127; __Pyx_INCREF(__pyx_kp_u_invalid_image_surface_expected_a); __pyx_t_2 += 41; __Pyx_GIVEREF(__pyx_kp_u_invalid_image_surface_expected_a); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_invalid_image_surface_expected_a); __pyx_t_4 = __Pyx_PyUnicode_From_int(__pyx_v_width, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_n_u_x); __pyx_t_2 += 1; __Pyx_GIVEREF(__pyx_n_u_x); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_n_u_x); __pyx_t_4 = __Pyx_PyUnicode_From_int(__pyx_v_height, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u_but_got); __pyx_t_2 += 9; __Pyx_GIVEREF(__pyx_kp_u_but_got); PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u_but_got); __pyx_t_4 = __Pyx_PyUnicode_From_int(__pyx_v_iwidth, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_n_u_x); __pyx_t_2 += 1; __Pyx_GIVEREF(__pyx_n_u_x); PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_n_u_x); __pyx_t_4 = __Pyx_PyUnicode_From_int(__pyx_v_iheight, 0, ' ', 'd'); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 7, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 8, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 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_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = 0; __pyx_t_3 = 127; __Pyx_INCREF(__pyx_kp_u_invalid_image_stride_expected_at); __pyx_t_2 += 40; __Pyx_GIVEREF(__pyx_kp_u_invalid_image_stride_expected_at); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_invalid_image_stride_expected_at); __pyx_t_1 = __Pyx_PyUnicode_From_long((__pyx_v_iwidth * 4), 0, ' ', 'd'); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); __pyx_t_1 = 0; __Pyx_INCREF(__pyx_kp_u_but_got); __pyx_t_2 += 9; __Pyx_GIVEREF(__pyx_kp_u_but_got); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_but_got); __pyx_t_1 = __Pyx_PyUnicode_From_int(__pyx_v_istride, 0, ' ', 'd'); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_4, 4, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; PyErr_SetObject(PyExc_AssertionError, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 105, __pyx_L1_error) } } #endif
106: #log("set_image_surface_data%s pixel buffer=%#x, surface=%#x, data=%#x, stride=%i, width=%i, height=%i", (image_surface, rgb_format, pixel_data, width, height, stride), <uintptr_t> cbuf, <uintptr_t> surface, <uintptr_t> data, istride, iwidth, iheight)
107: cdef int x, y
108: cdef int srci, dsti
109: cdef uintptr_t src, dst
110: #just deal with the formats we care about:
+111: if format==CAIRO_FORMAT_RGB24:
switch (__pyx_v_format) { case CAIRO_FORMAT_RGB24: /* … */ break; case CAIRO_FORMAT_ARGB32:
112: #cairo's RGB24 format is actually stored as BGR on little endian
+113: if rgb_format=="BGR":
__pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_v_rgb_format, __pyx_n_u_BGR, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 113, __pyx_L1_error) if (__pyx_t_6) { /* … */ goto __pyx_L6; }
+114: with nogil:
{ #ifdef WITH_THREAD PyThreadState *_save; Py_UNBLOCK_THREADS __Pyx_FastGIL_Remember(); #endif /*try:*/ { /* … */ /*finally:*/ { /*normal exit:*/{ #ifdef WITH_THREAD __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif goto __pyx_L9; } __pyx_L9:; } }
+115: for y in range(height):
__pyx_t_9 = __pyx_v_height; __pyx_t_10 = __pyx_t_9; for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { __pyx_v_y = __pyx_t_11;
+116: for x in range(width):
__pyx_t_12 = __pyx_v_width; __pyx_t_13 = __pyx_t_12; for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { __pyx_v_x = __pyx_t_14;
+117: srci = x*3 + y*stride
__pyx_v_srci = ((__pyx_v_x * 3) + (__pyx_v_y * __pyx_v_stride));
+118: dsti = x*4 + y*istride
__pyx_v_dsti = ((__pyx_v_x * 4) + (__pyx_v_y * __pyx_v_istride));
+119: data[dsti + 0] = cbuf[srci + 0] #B
(__pyx_v_data[(__pyx_v_dsti + 0)]) = (__pyx_v_cbuf[(__pyx_v_srci + 0)]);
+120: data[dsti + 1] = cbuf[srci + 1] #G
(__pyx_v_data[(__pyx_v_dsti + 1)]) = (__pyx_v_cbuf[(__pyx_v_srci + 1)]);
+121: data[dsti + 2] = cbuf[srci + 2] #R
(__pyx_v_data[(__pyx_v_dsti + 2)]) = (__pyx_v_cbuf[(__pyx_v_srci + 2)]);
+122: data[dsti + 3] = 255 #X
(__pyx_v_data[(__pyx_v_dsti + 3)]) = 0xFF; } } }
+123: elif rgb_format=="RGB":
__pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_v_rgb_format, __pyx_n_u_RGB, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 123, __pyx_L1_error) if (likely(__pyx_t_6)) { /* … */ goto __pyx_L6; }
+124: with nogil:
{ #ifdef WITH_THREAD PyThreadState *_save; Py_UNBLOCK_THREADS __Pyx_FastGIL_Remember(); #endif /*try:*/ { /* … */ /*finally:*/ { /*normal exit:*/{ #ifdef WITH_THREAD __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif goto __pyx_L16; } __pyx_L16:; } }
+125: for y in range(height):
__pyx_t_9 = __pyx_v_height; __pyx_t_10 = __pyx_t_9; for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { __pyx_v_y = __pyx_t_11;
+126: for x in range(width):
__pyx_t_12 = __pyx_v_width; __pyx_t_13 = __pyx_t_12; for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { __pyx_v_x = __pyx_t_14;
+127: srci = x*3 + y*stride
__pyx_v_srci = ((__pyx_v_x * 3) + (__pyx_v_y * __pyx_v_stride));
+128: dsti = x*4 + y*istride
__pyx_v_dsti = ((__pyx_v_x * 4) + (__pyx_v_y * __pyx_v_istride));
+129: data[dsti + 0] = cbuf[srci + 2] #B
(__pyx_v_data[(__pyx_v_dsti + 0)]) = (__pyx_v_cbuf[(__pyx_v_srci + 2)]);
+130: data[dsti + 1] = cbuf[srci + 1] #G
(__pyx_v_data[(__pyx_v_dsti + 1)]) = (__pyx_v_cbuf[(__pyx_v_srci + 1)]);
+131: data[dsti + 2] = cbuf[srci + 0] #R
(__pyx_v_data[(__pyx_v_dsti + 2)]) = (__pyx_v_cbuf[(__pyx_v_srci + 0)]);
+132: data[dsti + 3] = 255 #X
(__pyx_v_data[(__pyx_v_dsti + 3)]) = 0xFF; } } }
133: else:
+134: raise ValueError("unhandled RGB format '%s'" % rgb_format)
/*else*/ { __pyx_t_1 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_unhandled_RGB_format_s, __pyx_v_rgb_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 134, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __PYX_ERR(0, 134, __pyx_L1_error) } __pyx_L6:;
+135: elif format==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_5 = (__Pyx_PyUnicode_Equals(__pyx_t_4, __pyx_n_u_RGBA, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 136, __pyx_L1_error) if (!__pyx_t_5) { } else { __pyx_t_6 = __pyx_t_5; goto __pyx_L22_bool_binop_done; } __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_t_4, __pyx_n_u_RGBX, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 136, __pyx_L1_error) __pyx_t_6 = __pyx_t_5; __pyx_L22_bool_binop_done:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_5 = (__pyx_t_6 != 0); if (__pyx_t_5) { /* … */ goto __pyx_L21; }
+137: with nogil:
{ #ifdef WITH_THREAD PyThreadState *_save; Py_UNBLOCK_THREADS __Pyx_FastGIL_Remember(); #endif /*try:*/ { /* … */ /*finally:*/ { /*normal exit:*/{ #ifdef WITH_THREAD __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif goto __pyx_L26; } __pyx_L26:; } }
+138: for y in range(height):
__pyx_t_9 = __pyx_v_height; __pyx_t_10 = __pyx_t_9; for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { __pyx_v_y = __pyx_t_11;
+139: for x in range(width):
__pyx_t_12 = __pyx_v_width; __pyx_t_13 = __pyx_t_12; for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { __pyx_v_x = __pyx_t_14;
+140: 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))]);
+141: 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))]);
+142: 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))]);
+143: 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))]); } } }
+144: elif rgb_format in ("BGRA", "BGRX"):
__Pyx_INCREF(__pyx_v_rgb_format); __pyx_t_4 = __pyx_v_rgb_format; __pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_t_4, __pyx_n_u_BGRA, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 144, __pyx_L1_error) if (!__pyx_t_6) { } else { __pyx_t_5 = __pyx_t_6; goto __pyx_L31_bool_binop_done; } __pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_t_4, __pyx_n_u_BGRX, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 144, __pyx_L1_error) __pyx_t_5 = __pyx_t_6; __pyx_L31_bool_binop_done:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_6 = (__pyx_t_5 != 0); if (likely(__pyx_t_6)) { /* … */ goto __pyx_L21; }
+145: with nogil:
{ #ifdef WITH_THREAD PyThreadState *_save; Py_UNBLOCK_THREADS __Pyx_FastGIL_Remember(); #endif /*try:*/ { /* … */ /*finally:*/ { /*normal exit:*/{ #ifdef WITH_THREAD __Pyx_FastGIL_Forget(); Py_BLOCK_THREADS #endif goto __pyx_L35; } __pyx_L35:; } }
+146: if stride==istride:
__pyx_t_6 = ((__pyx_v_stride == __pyx_v_istride) != 0); if (__pyx_t_6) { /* … */ goto __pyx_L36; }
+147: memcpy(<void*> data, <void*> cbuf, stride*height)
(void)(memcpy(((void *)__pyx_v_data), ((void *)__pyx_v_cbuf), (__pyx_v_stride * __pyx_v_height)));
148: else:
+149: for y in range(height):
/*else*/ { __pyx_t_9 = __pyx_v_height; __pyx_t_10 = __pyx_t_9; for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { __pyx_v_y = __pyx_t_11;
+150: src = (<uintptr_t> cbuf) + y*stride
__pyx_v_src = (((uintptr_t)__pyx_v_cbuf) + (__pyx_v_y * __pyx_v_stride));
+151: dst = (<uintptr_t> data) + y*istride
__pyx_v_dst = (((uintptr_t)__pyx_v_data) + (__pyx_v_y * __pyx_v_istride));
+152: memcpy(<void*> dst, <void*> src, istride)
(void)(memcpy(((void *)__pyx_v_dst), ((void *)__pyx_v_src), __pyx_v_istride)); } } __pyx_L36:; }
153: else:
+154: raise ValueError("unhandled RGB format '%s'" % rgb_format)
/*else*/ { __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_unhandled_RGB_format_s, __pyx_v_rgb_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 154, __pyx_L1_error) } __pyx_L21:;
155: else:
+156: raise ValueError("unhandled cairo format '%s'" % format)
__pyx_t_1 = __Pyx_PyInt_From_cairo_format_t(__pyx_v_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_unhandled_cairo_format_s, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 156, __pyx_L1_error) break; }
+157: cairo_surface_mark_dirty(surface)
cairo_surface_mark_dirty(__pyx_v_surface);
158:
159:
160: cdef Pycairo_CAPI_t * Pycairo_CAPI
+161: 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));