Generated by Cython 0.27

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_2 = __Pyx_Import(__pyx_n_s_cairo, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cairo, __pyx_t_2) < 0) __PYX_ERR(0, 29, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 030: from xpra.buffers.membuf cimport object_as_buffer
 031: 
 032: 
 033: cdef extern from "Python.h":
 034:     ctypedef struct PyObject:
 035:         pass
 036:     void * PyCapsule_Import(const char *name, int no_block)
 037:     object PyBuffer_FromMemory(void *ptr, Py_ssize_t size)
 038:     int PyObject_AsReadBuffer(object obj, void ** buffer, Py_ssize_t * buffer_len) except -1
 039: 
 040: cdef extern from "cairo/cairo.h":
 041:     ctypedef struct cairo_surface_t:
 042:         pass
 043: 
 044:     #typedef enum _cairo_format {
 045:     ctypedef enum cairo_format_t:
 046:         CAIRO_FORMAT_INVALID
 047:         CAIRO_FORMAT_ARGB32
 048:         CAIRO_FORMAT_RGB24
 049:         CAIRO_FORMAT_A8
 050:         CAIRO_FORMAT_A1
 051:         CAIRO_FORMAT_RGB16_565
 052:         CAIRO_FORMAT_RGB30
 053: 
 054:     unsigned char * cairo_image_surface_get_data(cairo_surface_t *surface)
 055:     cairo_format_t cairo_image_surface_get_format(cairo_surface_t *surface)
 056: 
 057:     int cairo_image_surface_get_width (cairo_surface_t *surface)
 058:     int cairo_image_surface_get_height (cairo_surface_t *surface)
 059:     int cairo_image_surface_get_stride (cairo_surface_t *surface)
 060: 
 061: 
 062: cdef extern from "pycairo/pycairo.h":
 063:     ctypedef struct Pycairo_CAPI_t:
 064:         pass
 065:     ctypedef struct PycairoSurface:
 066:         #PyObject_HEAD
 067:         cairo_surface_t *surface
 068:         #PyObject *base; /* base object used to create surface, or NULL */
 069:     ctypedef PycairoSurface PycairoImageSurface
 070: 
 071: CAIRO_FORMAT = {
+072:         CAIRO_FORMAT_INVALID    : "Invalid",
  __pyx_t_2 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_INVALID); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_Invalid) < 0) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+073:         CAIRO_FORMAT_ARGB32     : "ARGB32",
  __pyx_t_3 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_ARGB32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 73, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_ARGB32) < 0) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+074:         CAIRO_FORMAT_RGB24      : "RGB24",
  __pyx_t_3 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_RGB24); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 74, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_RGB24) < 0) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+075:         CAIRO_FORMAT_A8         : "A8",
  __pyx_t_3 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_A8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 75, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_A8) < 0) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+076:         CAIRO_FORMAT_A1         : "A1",
  __pyx_t_3 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_A1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_A1) < 0) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+077:         CAIRO_FORMAT_RGB16_565  : "RGB16_565",
  __pyx_t_3 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_RGB16_565); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 77, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_RGB16_565) < 0) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+078:         CAIRO_FORMAT_RGB30      : "RGB30",
  __pyx_t_3 = __Pyx_PyInt_From_cairo_format_t(CAIRO_FORMAT_RGB30); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_2, __pyx_t_3, __pyx_n_s_RGB30) < 0) __PYX_ERR(0, 72, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_CAIRO_FORMAT, __pyx_t_2) < 0) __PYX_ERR(0, 71, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 079:         }
 080: 
+081: 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] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_image_surface)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rgb_format)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 1); __PYX_ERR(0, 81, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pixel_data)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 2); __PYX_ERR(0, 81, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_width)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 3); __PYX_ERR(0, 81, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_height)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 4); __PYX_ERR(0, 81, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_stride)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("set_image_surface_data", 1, 6, 6, 5); __PYX_ERR(0, 81, __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, 81, __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, 81, __pyx_L3_error)
    __pyx_v_height = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_height == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 81, __pyx_L3_error)
    __pyx_v_stride = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_stride == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 81, __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, 81, __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;
  PyObject *__pyx_v_srci = 0;
  PyObject *__pyx_v_dsti = 0;
  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_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_XDECREF(__pyx_v_srci);
  __Pyx_XDECREF(__pyx_v_dsti);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple_ = PyTuple_Pack(18, __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); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 81, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);
/* … */
  __pyx_t_2 = 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_2)) __PYX_ERR(0, 81, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_set_image_surface_data, __pyx_t_2) < 0) __PYX_ERR(0, 81, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 082:     #convert pixel_data to a C buffer:
+083:     cdef const unsigned char * cbuf = <unsigned char *> 0
  __pyx_v_cbuf = ((unsigned char *)0);
+084:     cdef Py_ssize_t cbuf_len = 0
  __pyx_v_cbuf_len = 0;
+085:     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, 85, __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, 85, __pyx_L1_error)
    }
  }
  #endif
+086:     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, 86, __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, 86, __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, 86, __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, 86, __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, 86, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyTuple_New(5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 86, __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, 86, __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, 86, __pyx_L1_error)
    }
  }
  #endif
 087:     #convert cairo.ImageSurface python object to a cairo_surface_t
+088:     if not isinstance(image_surface, cairo.ImageSurface):
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_cairo); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 88, __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, 88, __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 == -1)) __PYX_ERR(0, 88, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_8 = ((!(__pyx_t_7 != 0)) != 0);
  if (__pyx_t_8) {
/* … */
  }
+089:         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, 89, __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, 89, __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, 89, __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, 89, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 89, __pyx_L1_error)
+090:     cdef cairo_surface_t * surface = (<PycairoImageSurface *> image_surface).surface
  __pyx_t_9 = ((PycairoImageSurface *)__pyx_v_image_surface)->surface;
  __pyx_v_surface = __pyx_t_9;
+091:     cdef unsigned char * data = cairo_image_surface_get_data(surface)
  __pyx_v_data = cairo_image_surface_get_data(__pyx_v_surface);
 092:     #get surface attributes:
+093:     cdef cairo_format_t format = cairo_image_surface_get_format(surface)
  __pyx_v_format = cairo_image_surface_get_format(__pyx_v_surface);
+094:     cdef int istride    = cairo_image_surface_get_stride(surface)
  __pyx_v_istride = cairo_image_surface_get_stride(__pyx_v_surface);
+095:     cdef int iwidth     = cairo_image_surface_get_width(surface)
  __pyx_v_iwidth = cairo_image_surface_get_width(__pyx_v_surface);
+096:     cdef int iheight    = cairo_image_surface_get_height(surface)
  __pyx_v_iheight = cairo_image_surface_get_height(__pyx_v_surface);
+097:     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_5 = __Pyx_PyInt_From_int(__pyx_v_width); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_height); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_iwidth); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 97, __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, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6);
      __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_5 = 0;
      __pyx_t_6 = 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, 97, __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, 97, __pyx_L1_error)
    }
  }
  #endif
+098:     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, 98, __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, 98, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 98, __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, 98, __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, 98, __pyx_L1_error)
    }
  }
  #endif
 099:     cdef int x,y
 100:     cdef srci, dsti
 101:     #just deal with the formats we care about:
+102:     if format==CAIRO_FORMAT_RGB24 and rgb_format=="RGB":
  __pyx_t_7 = ((__pyx_v_format == CAIRO_FORMAT_RGB24) != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_8 = __pyx_t_7;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_rgb_format, __pyx_n_s_RGB, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 102, __pyx_L1_error)
  __pyx_t_8 = __pyx_t_7;
  __pyx_L7_bool_binop_done:;
  if (__pyx_t_8) {
/* … */
  }
 103:         #cairo's RGB24 format is actually stored as BGR!
+104:         for y in range(height):
    __pyx_t_10 = __pyx_v_height;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
      __pyx_v_y = __pyx_t_11;
+105:             for x in range(width):
      __pyx_t_12 = __pyx_v_width;
      for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
        __pyx_v_x = __pyx_t_13;
+106:                 srci = x*4 + y*istride
        __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_x * 4) + (__pyx_v_y * __pyx_v_istride))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_XDECREF_SET(__pyx_v_srci, __pyx_t_2);
        __pyx_t_2 = 0;
+107:                 dsti = x*3 + y*stride
        __pyx_t_2 = __Pyx_PyInt_From_long(((__pyx_v_x * 3) + (__pyx_v_y * __pyx_v_stride))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 107, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_XDECREF_SET(__pyx_v_dsti, __pyx_t_2);
        __pyx_t_2 = 0;
+108:                 data[srci + 0] = cbuf[dsti + 2]     #B
        __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_dsti, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_14 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_14 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 108, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_srci, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 108, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 108, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        (__pyx_v_data[__pyx_t_15]) = (__pyx_v_cbuf[__pyx_t_14]);
+109:                 data[srci + 1] = cbuf[dsti + 1]     #G
        __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_dsti, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 109, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_14 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_14 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 109, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_srci, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 109, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 109, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        (__pyx_v_data[__pyx_t_15]) = (__pyx_v_cbuf[__pyx_t_14]);
+110:                 data[srci + 2] = cbuf[dsti + 0]     #R
        __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_dsti, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 110, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_14 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_14 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 110, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_srci, __pyx_int_2, 2, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 110, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_15 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_15 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 110, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        (__pyx_v_data[__pyx_t_15]) = (__pyx_v_cbuf[__pyx_t_14]);
+111:                 data[srci + 3] = 255                #X
        __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_v_srci, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 111, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_14 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_14 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 111, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        (__pyx_v_data[__pyx_t_14]) = 0xFF;
      }
    }
+112:         return
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
 113:     #note: this one is currently unused because it doesn't work
 114:     #and I don't know why
 115:     #(we just disable 'rgb32' for gtk3... and fallback to png)
+116:     elif format==CAIRO_FORMAT_ARGB32 and rgb_format=="RGBA":
  __pyx_t_7 = ((__pyx_v_format == CAIRO_FORMAT_ARGB32) != 0);
  if (__pyx_t_7) {
  } else {
    __pyx_t_8 = __pyx_t_7;
    goto __pyx_L13_bool_binop_done;
  }
  __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_rgb_format, __pyx_n_s_RGBA, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 116, __pyx_L1_error)
  __pyx_t_8 = __pyx_t_7;
  __pyx_L13_bool_binop_done:;
  if (__pyx_t_8) {
/* … */
  }
+117:         for x in range(width):
    __pyx_t_10 = __pyx_v_width;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
      __pyx_v_x = __pyx_t_11;
+118:             for y in range(height):
      __pyx_t_12 = __pyx_v_height;
      for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
        __pyx_v_y = __pyx_t_13;
+119:                 data[x*4 + 0 + y*istride] = cbuf[x*4 + 3 + y*stride]    #A
        (__pyx_v_data[(((__pyx_v_x * 4) + 0) + (__pyx_v_y * __pyx_v_istride))]) = (__pyx_v_cbuf[(((__pyx_v_x * 4) + 3) + (__pyx_v_y * __pyx_v_stride))]);
+120:                 data[x*4 + 1 + y*istride] = cbuf[x*4 + 0 + y*stride]    #R
        (__pyx_v_data[(((__pyx_v_x * 4) + 1) + (__pyx_v_y * __pyx_v_istride))]) = (__pyx_v_cbuf[(((__pyx_v_x * 4) + 0) + (__pyx_v_y * __pyx_v_stride))]);
+121:                 data[x*4 + 2 + y*istride] = cbuf[x*4 + 1 + y*stride]    #G
        (__pyx_v_data[(((__pyx_v_x * 4) + 2) + (__pyx_v_y * __pyx_v_istride))]) = (__pyx_v_cbuf[(((__pyx_v_x * 4) + 1) + (__pyx_v_y * __pyx_v_stride))]);
+122:                 data[x*4 + 3 + y*istride] = cbuf[x*4 + 2 + y*stride]    #B
        (__pyx_v_data[(((__pyx_v_x * 4) + 3) + (__pyx_v_y * __pyx_v_istride))]) = (__pyx_v_cbuf[(((__pyx_v_x * 4) + 2) + (__pyx_v_y * __pyx_v_stride))]);
      }
    }
+123:         return
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
+124:     print("ERROR: cairo workaround not implemented for %s / %s" % (rgb_format, CAIRO_FORMAT.get(format, "unknown")))
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_CAIRO_FORMAT); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_From_cairo_format_t(__pyx_v_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = NULL;
  __pyx_t_10 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_10 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_4, __pyx_n_s_unknown};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_t_4, __pyx_n_s_unknown};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 124, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_10, __pyx_t_4);
    __Pyx_INCREF(__pyx_n_s_unknown);
    __Pyx_GIVEREF(__pyx_n_s_unknown);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_10, __pyx_n_s_unknown);
    __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_rgb_format);
  __Pyx_GIVEREF(__pyx_v_rgb_format);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_rgb_format);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_ERROR_cairo_workaround_not_imple, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__Pyx_PrintOne(0, __pyx_t_2) < 0) __PYX_ERR(0, 124, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 125: 
 126: cdef Pycairo_CAPI_t * Pycairo_CAPI
+127: 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));