FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/src/_backend_gdk.c at master · feisuo/matplotlib · GitHub
feisuo
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
src
/
_backend_gdk.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (65 loc) · 2.28 KB
Breadcrumbs
matplotlib
/
src
/
_backend_gdk.c
Copy path
File metadata and controls
81 lines (65 loc) · 2.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* -*- mode: C; c-basic-offset: 4 -*-
* C extensions for backend_gdk
*/
#include
"Python.h"
#include
"numpy/arrayobject.h"
#include
<pygtk/pygtk.h>
// support numpy 1.6 - this macro was renamed and deprecated at once in 1.7
#ifndef
NPY_ARRAY_WRITEABLE
#define
NPY_ARRAY_WRITEABLE
NPY_WRITEABLE
#endif
static
PyTypeObject
*
_PyGdkPixbuf_Type
;
#define
PyGdkPixbuf_Type
(*_PyGdkPixbuf_Type)
static
PyObject
*
pixbuf_get_pixels_array
(
PyObject
*
self
,
PyObject
*
args
)
{
/* 1) read in Python pixbuf, get the underlying gdk_pixbuf */
PyGObject
*
py_pixbuf
;
GdkPixbuf
*
gdk_pixbuf
;
PyArrayObject
*
array
;
npy_intp
dims
[
3
]
=
{
0
,
0
,
3
};
npy_intp
strides
[
3
];
if
(!
PyArg_ParseTuple
(
args
,
"O!:pixbuf_get_pixels_array"
,
&
PyGdkPixbuf_Type
,
&
py_pixbuf
))
return
NULL
;
gdk_pixbuf
=
GDK_PIXBUF
(
py_pixbuf
->
obj
);
/* 2) same as pygtk/gtk/gdk.c _wrap_gdk_pixbuf_get_pixels_array()
* with 'self' changed to py_pixbuf
*/
dims
[
0
]
=
gdk_pixbuf_get_height
(
gdk_pixbuf
);
dims
[
1
]
=
gdk_pixbuf_get_width
(
gdk_pixbuf
);
if
(
gdk_pixbuf_get_has_alpha
(
gdk_pixbuf
))
dims
[
2
]
=
4
;
strides
[
0
]
=
gdk_pixbuf_get_rowstride
(
gdk_pixbuf
);
strides
[
1
]
=
dims
[
2
];
strides
[
2
]
=
1
;
array
=
(
PyArrayObject
*
)
PyArray_New
(
&
PyArray_Type
,
3
,
dims
,
NPY_UBYTE
,
strides
,
(
void
*
)
gdk_pixbuf_get_pixels
(
gdk_pixbuf
),
1
,
NPY_ARRAY_WRITEABLE
,
NULL
);
if
(
array
==
NULL
)
return
NULL
;
/* the array holds a ref to the pixbuf pixels through this wrapper*/
Py_INCREF
(
py_pixbuf
);
#if
NPY_API_VERSION
>=
0x00000007
if
(
PyArray_SetBaseObject
(
array
, (
PyObject
*
)
py_pixbuf
)
==
-1
) {
Py_DECREF
(
py_pixbuf
);
Py_DECREF
(
array
);
return
NULL
;
}
#else
PyArray_BASE
(
array
)
=
(
PyObject
*
)
py_pixbuf
;
#endif
return
PyArray_Return
(
array
);
}
static
PyMethodDef
_backend_gdk_functions
[]
=
{
{
"pixbuf_get_pixels_array"
, (
PyCFunction
)
pixbuf_get_pixels_array
,
METH_VARARGS
},
{
NULL
,
NULL
,
0
}
};
PyMODINIT_FUNC
init_backend_gdk
(
void
)
{
PyObject
*
mod
;
mod
=
Py_InitModule
(
"matplotlib.backends._backend_gdk"
,
_backend_gdk_functions
);
import_array
();
init_pygtk
();
mod
=
PyImport_ImportModule
(
"gtk.gdk"
);
_PyGdkPixbuf_Type
=
(
PyTypeObject
*
)
PyObject_GetAttrString
(
mod
,
"Pixbuf"
);
}
Back
|
FazBrowse Home
|
New Git URL