11#define PY_SSIZE_T_CLEAN
51 pyrna_WindowManager_clipboard_doc,
52 "Clipboard text storage.\n"
61 if (text !=
nullptr) {
69 PyObject *value_coerce =
nullptr;
71 if (text ==
nullptr) {
75 Py_XDECREF(value_coerce);
87 pyrna_draw_cursor_add_doc,
88 ".. classmethod:: draw_cursor_add(callback, args, space_type, region_type)\n"
90 " Add a new draw cursor handler to this space type.\n"
91 " It will be called every time the cursor for the specified region in the space "
92 "type will be drawn.\n"
93 " Note: All arguments are positional only for now.\n"
96 " A function that will be called when the cursor is drawn.\n"
97 " It gets the specified arguments as input with the mouse position "
98 "(``tuple[int, int]``) as last argument.\n"
99 " :type callback: Callable[..., Any]\n"
100 " :param args: Arguments that will be passed to the callback.\n"
101 " :type args: tuple[Any, ...]\n"
102 " :param space_type: The space type the callback draws in; for example ``VIEW_3D``. "
103 "(:class:`bpy.types.Space.type`)\n"
104 " :type space_type: str\n"
105 " :param region_type: The region type the callback draws in; usually ``WINDOW``. "
106 "(:class:`bpy.types.Region.type`)\n"
107 " :type region_type: str\n"
108 " :return: Handler that can be removed later on.\n"
109 " :rtype: object\n");
112 pyrna_draw_cursor_remove_doc,
113 ".. classmethod:: draw_cursor_remove(handler)\n"
115 " Remove a draw cursor handler that was added previously.\n"
117 " :param handler: The draw cursor handler that should be removed.\n"
118 " :type handler: object\n");
123 METH_VARARGS | METH_CLASS,
124 pyrna_draw_cursor_add_doc,
128 "draw_cursor_remove",
130 METH_VARARGS | METH_CLASS,
131 pyrna_draw_cursor_remove_doc,
138 pyrna_WindowManager_clipboard_doc,
150 bpy_rna_window_screenshot_doc,
151 ".. method:: screenshot(*, region=None, use_alpha=False)\n"
153 " Capture the windows pixel data.\n"
155 " :param region: The region to capture, or ``None`` to capture all.\n"
156 " Each int pair represents a pixel coordinate "
157 "(the end value is not inclusive, matching Python slicing): "
158 "((min_x, min_y), (max_x, max_y))\n"
159 " :type region: tuple[tuple[int, int], tuple[int, int]] | None\n"
160 " :param use_alpha: When false the alpha channel is fully opaque. "
161 "Otherwise alpha values from the window's frame-buffer are returned as-is.\n"
162 " :type use_alpha: bool\n"
163 " :return: A read-only :class:`memoryview` of shape ``(height, width, 4)`` "
164 "and format ``'B'``, viewing the captured RGBA pixels (rows ordered from bottom to top).\n"
165 " :rtype: memoryview\n");
171 std::optional<rcti> region;
172 bool use_alpha =
false;
174 static const char *_keywords[] = {
"region",
"use_alpha",
nullptr};
175 static _PyArg_Parser _parser = {
183 if (!_PyArg_ParseTupleAndKeywordsFast(
190 PyErr_SetString(PyExc_RuntimeError,
"Window.screenshot() is not available in background mode");
196 int dumprect_size[2];
198 if (dumprect ==
nullptr) {
199 PyErr_SetString(PyExc_RuntimeError,
"Failed to read window pixels");
208 .xmin =
max_ii(0, region->xmin),
209 .xmax =
min_ii(dumprect_size[0], region->xmax),
210 .ymin =
max_ii(0, region->ymin),
211 .ymax =
min_ii(dumprect_size[1], region->ymax),
217 if (crop_size.x > 0 && crop_size.y > 0) {
218 const size_t row_bytes = size_t(crop_size.x) * 4;
219 const size_t src_stride = size_t(dumprect_size[0]) * 4;
222 for (
int y = 0;
y < crop_size.y;
y++) {
223 const uint8_t *src = dumprect + (size_t(safe.
ymin +
y) * src_stride) +
224 (
size_t(safe.
xmin) * 4);
225 memcpy(cropped +
size_t(
y) * row_bytes, src, row_bytes);
227 MEM_delete(dumprect);
229 dumprect_size[0] = crop_size.x;
230 dumprect_size[1] = crop_size.y;
237 MEM_delete(dumprect);
239 dumprect_size[0] = 0;
240 dumprect_size[1] = 0;
246 const size_t total_bytes = size_t(dumprect_size[0]) * dumprect_size[1] * 4;
247 for (
size_t i = 3; i < total_bytes; i += 4) {
252 Py_ssize_t shape[3] = {dumprect_size[1], dumprect_size[0], 4};
253 Py_ssize_t strides[3] = {Py_ssize_t(dumprect_size[0]) * 4, 4, 1};
255 memset(&info, 0,
sizeof(info));
257 info.len = shape[0] * shape[1] * shape[2];
260 info.format =
const_cast<char *
>(
"B");
263 info.strides = strides;
269# pragma clang diagnostic push
270# pragma clang diagnostic ignored "-Wcast-function-type"
272# pragma GCC diagnostic push
273# pragma GCC diagnostic ignored "-Wcast-function-type"
280 METH_VARARGS | METH_KEYWORDS,
281 bpy_rna_window_screenshot_doc,
286# pragma clang diagnostic pop
288# pragma GCC diagnostic pop
Read Blender memory allocation and freeing.
static PyObject * bpy_rna_window_screenshot(PyObject *self, PyObject *args, PyObject *kwds)
PyGetSetDef BPY_rna_windowmanager_clipboard_getset_def
PyMethodDef BPY_rna_window_screenshot_method_def
int PyC_ParseBool(PyObject *o, void *p)
PyObject * PyC_MemoryView_FromBufferOwned(const Py_buffer *info)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
PyMethodDef BPY_rna_windowmanager_draw_cursor_remove_method_def
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
uint8_t * WM_window_pixels_read(bContext *C, wmWindow *win, int r_size[2])
MINLINE int max_ii(int a, int b)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
static PyObject * pyrna_WindowManager_clipboard_get(PyObject *, void *)
PyMethodDef BPY_rna_windowmanager_draw_cursor_add_method_def
VecBase< int32_t, 2 > int2
struct bContext * BPY_context_get()
PyObject * pyrna_callback_classmethod_add(PyObject *, PyObject *args)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
PyObject * pyrna_callback_classmethod_remove(PyObject *, PyObject *args)
const char * PyC_UnicodeAsBytes(PyObject *py_str, PyObject **r_coerce)
char * WM_clipboard_text_get(bool selection, bool ensure_utf8, int *r_len)
static int pyrna_WindowManager_clipboard_set(PyObject *, PyObject *value, void *)
void WM_clipboard_text_set(const char *buf, bool selection)
int PyC_ParseOptionalRectI(PyObject *o, void *p)
PyObject * PyC_UnicodeFromBytesAndSize(const char *str, Py_ssize_t size)
MINLINE int min_ii(int a, int b)
header-only compatibility defines.
PyObject_HEAD std::optional< PointerRNA > ptr