ClangFormat: apply to source, most of intern

Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
This commit is contained in:
2019-04-17 06:17:24 +02:00
parent b3dabc200a
commit e12c08e8d1
4481 changed files with 1230080 additions and 1155401 deletions

View File

@@ -16,42 +16,42 @@
# ***** END GPL LICENSE BLOCK *****
set(INC
.
../../blenkernel
../../blenlib
../../gpu
../../makesdna
../../../../intern/guardedalloc
../../../../intern/glew-mx
.
../../blenkernel
../../blenlib
../../gpu
../../makesdna
../../../../intern/guardedalloc
../../../../intern/glew-mx
)
set(INC_SYS
${GLEW_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
${GLEW_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
)
set(SRC
bgl.c
blf_py_api.c
bpy_internal_import.c
bpy_threads.c
idprop_py_api.c
imbuf_py_api.c
py_capi_utils.c
bgl.c
blf_py_api.c
bpy_internal_import.c
bpy_threads.c
idprop_py_api.c
imbuf_py_api.c
py_capi_utils.c
bgl.h
blf_py_api.h
bpy_internal_import.h
idprop_py_api.h
imbuf_py_api.h
py_capi_utils.h
bgl.h
blf_py_api.h
bpy_internal_import.h
idprop_py_api.h
imbuf_py_api.h
py_capi_utils.h
# header-only
python_utildefines.h
# header-only
python_utildefines.h
)
set(LIB
${GLEW_LIBRARY}
${GLEW_LIBRARY}
)
add_definitions(${GL_DEFINITIONS})

File diff suppressed because it is too large Load Diff

View File

@@ -33,22 +33,21 @@ int BGL_typeSize(int type);
* For Python access to OpenGL functions requiring a pointer.
*/
typedef struct _Buffer {
PyObject_VAR_HEAD
PyObject *parent;
PyObject_VAR_HEAD PyObject *parent;
int type; /* GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT */
int ndimensions;
int *dimensions;
int type; /* GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT */
int ndimensions;
int *dimensions;
union {
char *asbyte;
short *asshort;
int *asint;
float *asfloat;
double *asdouble;
union {
char *asbyte;
short *asshort;
int *asint;
float *asfloat;
double *asdouble;
void *asvoid;
} buf;
void *asvoid;
} buf;
} Buffer;
/** The type object */

View File

@@ -29,486 +29,470 @@
#include "python_utildefines.h"
PyDoc_STRVAR(py_blf_position_doc,
".. function:: position(fontid, x, y, z)\n"
"\n"
" Set the position for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg x: X axis position to draw the text.\n"
" :type x: float\n"
" :arg y: Y axis position to draw the text.\n"
" :type y: float\n"
" :arg z: Z axis position to draw the text.\n"
" :type z: float\n"
);
".. function:: position(fontid, x, y, z)\n"
"\n"
" Set the position for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg x: X axis position to draw the text.\n"
" :type x: float\n"
" :arg y: Y axis position to draw the text.\n"
" :type y: float\n"
" :arg z: Z axis position to draw the text.\n"
" :type z: float\n");
static PyObject *py_blf_position(PyObject *UNUSED(self), PyObject *args)
{
int fontid;
float x, y, z;
int fontid;
float x, y, z;
if (!PyArg_ParseTuple(args, "ifff:blf.position", &fontid, &x, &y, &z)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "ifff:blf.position", &fontid, &x, &y, &z)) {
return NULL;
}
BLF_position(fontid, x, y, z);
BLF_position(fontid, x, y, z);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_size_doc,
".. function:: size(fontid, size, dpi)\n"
"\n"
" Set the size and dpi for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg size: Point size of the font.\n"
" :type size: int\n"
" :arg dpi: dots per inch value to use for drawing.\n"
" :type dpi: int\n"
);
".. function:: size(fontid, size, dpi)\n"
"\n"
" Set the size and dpi for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg size: Point size of the font.\n"
" :type size: int\n"
" :arg dpi: dots per inch value to use for drawing.\n"
" :type dpi: int\n");
static PyObject *py_blf_size(PyObject *UNUSED(self), PyObject *args)
{
int fontid, size, dpi;
int fontid, size, dpi;
if (!PyArg_ParseTuple(args, "iii:blf.size", &fontid, &size, &dpi)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "iii:blf.size", &fontid, &size, &dpi)) {
return NULL;
}
BLF_size(fontid, size, dpi);
BLF_size(fontid, size, dpi);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_aspect_doc,
".. function:: aspect(fontid, aspect)\n"
"\n"
" Set the aspect for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg aspect: The aspect ratio for text drawing to use.\n"
" :type aspect: float\n"
);
".. function:: aspect(fontid, aspect)\n"
"\n"
" Set the aspect for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg aspect: The aspect ratio for text drawing to use.\n"
" :type aspect: float\n");
static PyObject *py_blf_aspect(PyObject *UNUSED(self), PyObject *args)
{
float aspect;
int fontid;
float aspect;
int fontid;
if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect)) {
return NULL;
}
BLF_aspect(fontid, aspect, aspect, 1.0);
BLF_aspect(fontid, aspect, aspect, 1.0);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_color_doc,
".. function:: color(fontid, r, g, b, a)\n"
"\n"
" Set the color for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg r: red channel 0.0 - 1.0.\n"
" :type r: float\n"
" :arg g: green channel 0.0 - 1.0.\n"
" :type g: float\n"
" :arg b: blue channel 0.0 - 1.0.\n"
" :type b: float\n"
" :arg a: alpha channel 0.0 - 1.0.\n"
" :type a: float\n"
);
".. function:: color(fontid, r, g, b, a)\n"
"\n"
" Set the color for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg r: red channel 0.0 - 1.0.\n"
" :type r: float\n"
" :arg g: green channel 0.0 - 1.0.\n"
" :type g: float\n"
" :arg b: blue channel 0.0 - 1.0.\n"
" :type b: float\n"
" :arg a: alpha channel 0.0 - 1.0.\n"
" :type a: float\n");
static PyObject *py_blf_color(PyObject *UNUSED(self), PyObject *args)
{
int fontid;
float rgba[4];
int fontid;
float rgba[4];
if (!PyArg_ParseTuple(
args, "iffff:blf.color",
&fontid, &rgba[0], &rgba[1], &rgba[2], &rgba[3]))
{
return NULL;
}
if (!PyArg_ParseTuple(
args, "iffff:blf.color", &fontid, &rgba[0], &rgba[1], &rgba[2], &rgba[3])) {
return NULL;
}
BLF_color4fv(fontid, rgba);
BLF_color4fv(fontid, rgba);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
#if BLF_BLUR_ENABLE
PyDoc_STRVAR(py_blf_blur_doc,
".. function:: blur(fontid, radius)\n"
"\n"
" Set the blur radius for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg radius: The radius for blurring text (in pixels).\n"
" :type radius: int\n"
);
".. function:: blur(fontid, radius)\n"
"\n"
" Set the blur radius for drawing text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg radius: The radius for blurring text (in pixels).\n"
" :type radius: int\n");
static PyObject *py_blf_blur(PyObject *UNUSED(self), PyObject *args)
{
int blur, fontid;
int blur, fontid;
if (!PyArg_ParseTuple(args, "ii:blf.blur", &fontid, &blur)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "ii:blf.blur", &fontid, &blur)) {
return NULL;
}
BLF_blur(fontid, blur);
BLF_blur(fontid, blur);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
#endif
PyDoc_STRVAR(py_blf_draw_doc,
".. function:: draw(fontid, text)\n"
"\n"
" Draw text in the current context.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg text: the text to draw.\n"
" :type text: string\n"
);
".. function:: draw(fontid, text)\n"
"\n"
" Draw text in the current context.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg text: the text to draw.\n"
" :type text: string\n");
static PyObject *py_blf_draw(PyObject *UNUSED(self), PyObject *args)
{
const char *text;
int text_length;
int fontid;
const char *text;
int text_length;
int fontid;
if (!PyArg_ParseTuple(args, "is#:blf.draw", &fontid, &text, &text_length)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "is#:blf.draw", &fontid, &text, &text_length)) {
return NULL;
}
BLF_draw(fontid, text, (unsigned int)text_length);
BLF_draw(fontid, text, (unsigned int)text_length);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_dimensions_doc,
".. function:: dimensions(fontid, text)\n"
"\n"
" Return the width and height of the text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg text: the text to draw.\n"
" :type text: string\n"
" :return: the width and height of the text.\n"
" :rtype: tuple of 2 floats\n"
);
".. function:: dimensions(fontid, text)\n"
"\n"
" Return the width and height of the text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg text: the text to draw.\n"
" :type text: string\n"
" :return: the width and height of the text.\n"
" :rtype: tuple of 2 floats\n");
static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args)
{
const char *text;
float r_width, r_height;
PyObject *ret;
int fontid;
const char *text;
float r_width, r_height;
PyObject *ret;
int fontid;
if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) {
return NULL;
}
BLF_width_and_height(fontid, text, INT_MAX, &r_width, &r_height);
BLF_width_and_height(fontid, text, INT_MAX, &r_width, &r_height);
ret = PyTuple_New(2);
PyTuple_SET_ITEMS(ret,
PyFloat_FromDouble(r_width),
PyFloat_FromDouble(r_height));
return ret;
ret = PyTuple_New(2);
PyTuple_SET_ITEMS(ret, PyFloat_FromDouble(r_width), PyFloat_FromDouble(r_height));
return ret;
}
PyDoc_STRVAR(py_blf_clipping_doc,
".. function:: clipping(fontid, xmin, ymin, xmax, ymax)\n"
"\n"
" Set the clipping, enable/disable using CLIPPING.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg xmin: Clip the drawing area by these bounds.\n"
" :type xmin: float\n"
" :arg ymin: Clip the drawing area by these bounds.\n"
" :type ymin: float\n"
" :arg xmax: Clip the drawing area by these bounds.\n"
" :type xmax: float\n"
" :arg ymax: Clip the drawing area by these bounds.\n"
" :type ymax: float\n"
);
".. function:: clipping(fontid, xmin, ymin, xmax, ymax)\n"
"\n"
" Set the clipping, enable/disable using CLIPPING.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg xmin: Clip the drawing area by these bounds.\n"
" :type xmin: float\n"
" :arg ymin: Clip the drawing area by these bounds.\n"
" :type ymin: float\n"
" :arg xmax: Clip the drawing area by these bounds.\n"
" :type xmax: float\n"
" :arg ymax: Clip the drawing area by these bounds.\n"
" :type ymax: float\n");
static PyObject *py_blf_clipping(PyObject *UNUSED(self), PyObject *args)
{
float xmin, ymin, xmax, ymax;
int fontid;
float xmin, ymin, xmax, ymax;
int fontid;
if (!PyArg_ParseTuple(args, "iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "iffff:blf.clipping", &fontid, &xmin, &ymin, &xmax, &ymax)) {
return NULL;
}
BLF_clipping(fontid, xmin, ymin, xmax, ymax);
BLF_clipping(fontid, xmin, ymin, xmax, ymax);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_word_wrap_doc,
".. function:: word_wrap(fontid, wrap_width)\n"
"\n"
" Set the wrap width, enable/disable using WORD_WRAP.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg wrap_width: The width (in pixels) to wrap words at.\n"
" :type wrap_width: int\n"
);
".. function:: word_wrap(fontid, wrap_width)\n"
"\n"
" Set the wrap width, enable/disable using WORD_WRAP.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg wrap_width: The width (in pixels) to wrap words at.\n"
" :type wrap_width: int\n");
static PyObject *py_blf_word_wrap(PyObject *UNUSED(self), PyObject *args)
{
int wrap_width;
int fontid;
int wrap_width;
int fontid;
if (!PyArg_ParseTuple(args, "ii:blf.word_wrap", &fontid, &wrap_width)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "ii:blf.word_wrap", &fontid, &wrap_width)) {
return NULL;
}
BLF_wordwrap(fontid, wrap_width);
BLF_wordwrap(fontid, wrap_width);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_disable_doc,
".. function:: disable(fontid, option)\n"
"\n"
" Disable option.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
" :type option: int\n"
);
".. function:: disable(fontid, option)\n"
"\n"
" Disable option.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
" :type option: int\n");
static PyObject *py_blf_disable(PyObject *UNUSED(self), PyObject *args)
{
int option, fontid;
int option, fontid;
if (!PyArg_ParseTuple(args, "ii:blf.disable", &fontid, &option)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "ii:blf.disable", &fontid, &option)) {
return NULL;
}
BLF_disable(fontid, option);
BLF_disable(fontid, option);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_enable_doc,
".. function:: enable(fontid, option)\n"
"\n"
" Enable option.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
" :type option: int\n"
);
".. function:: enable(fontid, option)\n"
"\n"
" Enable option.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg option: One of ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT.\n"
" :type option: int\n");
static PyObject *py_blf_enable(PyObject *UNUSED(self), PyObject *args)
{
int option, fontid;
int option, fontid;
if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "ii:blf.enable", &fontid, &option)) {
return NULL;
}
BLF_enable(fontid, option);
BLF_enable(fontid, option);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_rotation_doc,
".. function:: rotation(fontid, angle)\n"
"\n"
" Set the text rotation angle, enable/disable using ROTATION.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg angle: The angle for text drawing to use.\n"
" :type angle: float\n"
);
".. function:: rotation(fontid, angle)\n"
"\n"
" Set the text rotation angle, enable/disable using ROTATION.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg angle: The angle for text drawing to use.\n"
" :type angle: float\n");
static PyObject *py_blf_rotation(PyObject *UNUSED(self), PyObject *args)
{
float angle;
int fontid;
float angle;
int fontid;
if (!PyArg_ParseTuple(args, "if:blf.rotation", &fontid, &angle)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "if:blf.rotation", &fontid, &angle)) {
return NULL;
}
BLF_rotation(fontid, angle);
BLF_rotation(fontid, angle);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_shadow_doc,
".. function:: shadow(fontid, level, r, g, b, a)\n"
"\n"
" Shadow options, enable/disable using SHADOW .\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg level: The blur level, can be 3, 5 or 0.\n"
" :type level: int\n"
" :arg r: Shadow color (red channel 0.0 - 1.0).\n"
" :type r: float\n"
" :arg g: Shadow color (green channel 0.0 - 1.0).\n"
" :type g: float\n"
" :arg b: Shadow color (blue channel 0.0 - 1.0).\n"
" :type b: float\n"
" :arg a: Shadow color (alpha channel 0.0 - 1.0).\n"
" :type a: float\n"
);
".. function:: shadow(fontid, level, r, g, b, a)\n"
"\n"
" Shadow options, enable/disable using SHADOW .\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg level: The blur level, can be 3, 5 or 0.\n"
" :type level: int\n"
" :arg r: Shadow color (red channel 0.0 - 1.0).\n"
" :type r: float\n"
" :arg g: Shadow color (green channel 0.0 - 1.0).\n"
" :type g: float\n"
" :arg b: Shadow color (blue channel 0.0 - 1.0).\n"
" :type b: float\n"
" :arg a: Shadow color (alpha channel 0.0 - 1.0).\n"
" :type a: float\n");
static PyObject *py_blf_shadow(PyObject *UNUSED(self), PyObject *args)
{
int level, fontid;
float rgba[4];
int level, fontid;
float rgba[4];
if (!PyArg_ParseTuple(
args, "iiffff:blf.shadow",
&fontid, &level, &rgba[0], &rgba[1], &rgba[2], &rgba[3]))
{
return NULL;
}
if (!PyArg_ParseTuple(
args, "iiffff:blf.shadow", &fontid, &level, &rgba[0], &rgba[1], &rgba[2], &rgba[3])) {
return NULL;
}
if (level != 0 && level != 3 && level != 5) {
PyErr_SetString(PyExc_TypeError, "blf.shadow expected arg to be in (0, 3, 5)");
return NULL;
}
if (level != 0 && level != 3 && level != 5) {
PyErr_SetString(PyExc_TypeError, "blf.shadow expected arg to be in (0, 3, 5)");
return NULL;
}
BLF_shadow(fontid, level, rgba);
BLF_shadow(fontid, level, rgba);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_shadow_offset_doc,
".. function:: shadow_offset(fontid, x, y)\n"
"\n"
" Set the offset for shadow text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default font use 0.\n"
" :type fontid: int\n"
" :arg x: Vertical shadow offset value in pixels.\n"
" :type x: float\n"
" :arg y: Horizontal shadow offset value in pixels.\n"
" :type y: float\n"
);
".. function:: shadow_offset(fontid, x, y)\n"
"\n"
" Set the offset for shadow text.\n"
"\n"
" :arg fontid: The id of the typeface as returned by :func:`blf.load`, for default "
"font use 0.\n"
" :type fontid: int\n"
" :arg x: Vertical shadow offset value in pixels.\n"
" :type x: float\n"
" :arg y: Horizontal shadow offset value in pixels.\n"
" :type y: float\n");
static PyObject *py_blf_shadow_offset(PyObject *UNUSED(self), PyObject *args)
{
int x, y, fontid;
int x, y, fontid;
if (!PyArg_ParseTuple(args, "iii:blf.shadow_offset", &fontid, &x, &y)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "iii:blf.shadow_offset", &fontid, &x, &y)) {
return NULL;
}
BLF_shadow_offset(fontid, x, y);
BLF_shadow_offset(fontid, x, y);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_blf_load_doc,
".. function:: load(filename)\n"
"\n"
" Load a new font.\n"
"\n"
" :arg filename: the filename of the font.\n"
" :type filename: string\n"
" :return: the new font's fontid or -1 if there was an error.\n"
" :rtype: integer\n"
);
".. function:: load(filename)\n"
"\n"
" Load a new font.\n"
"\n"
" :arg filename: the filename of the font.\n"
" :type filename: string\n"
" :return: the new font's fontid or -1 if there was an error.\n"
" :rtype: integer\n");
static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args)
{
const char *filename;
const char *filename;
if (!PyArg_ParseTuple(args, "s:blf.load", &filename)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "s:blf.load", &filename)) {
return NULL;
}
return PyLong_FromLong(BLF_load(filename));
return PyLong_FromLong(BLF_load(filename));
}
PyDoc_STRVAR(py_blf_unload_doc,
".. function:: unload(filename)\n"
"\n"
" Unload an existing font.\n"
"\n"
" :arg filename: the filename of the font.\n"
" :type filename: string\n"
);
".. function:: unload(filename)\n"
"\n"
" Unload an existing font.\n"
"\n"
" :arg filename: the filename of the font.\n"
" :type filename: string\n");
static PyObject *py_blf_unload(PyObject *UNUSED(self), PyObject *args)
{
const char *filename;
const char *filename;
if (!PyArg_ParseTuple(args, "s:blf.unload", &filename)) {
return NULL;
}
if (!PyArg_ParseTuple(args, "s:blf.unload", &filename)) {
return NULL;
}
BLF_unload(filename);
BLF_unload(filename);
Py_RETURN_NONE;
Py_RETURN_NONE;
}
/*----------------------------MODULE INIT-------------------------*/
static PyMethodDef BLF_methods[] = {
{"aspect", (PyCFunction) py_blf_aspect, METH_VARARGS, py_blf_aspect_doc},
{"aspect", (PyCFunction)py_blf_aspect, METH_VARARGS, py_blf_aspect_doc},
#if BLF_BLUR_ENABLE
{"blur", (PyCFunction) py_blf_blur, METH_VARARGS, py_blf_blur_doc},
{"blur", (PyCFunction)py_blf_blur, METH_VARARGS, py_blf_blur_doc},
#endif
{"clipping", (PyCFunction) py_blf_clipping, METH_VARARGS, py_blf_clipping_doc},
{"word_wrap", (PyCFunction) py_blf_word_wrap, METH_VARARGS, py_blf_word_wrap_doc},
{"disable", (PyCFunction) py_blf_disable, METH_VARARGS, py_blf_disable_doc},
{"dimensions", (PyCFunction) py_blf_dimensions, METH_VARARGS, py_blf_dimensions_doc},
{"draw", (PyCFunction) py_blf_draw, METH_VARARGS, py_blf_draw_doc},
{"enable", (PyCFunction) py_blf_enable, METH_VARARGS, py_blf_enable_doc},
{"position", (PyCFunction) py_blf_position, METH_VARARGS, py_blf_position_doc},
{"rotation", (PyCFunction) py_blf_rotation, METH_VARARGS, py_blf_rotation_doc},
{"shadow", (PyCFunction) py_blf_shadow, METH_VARARGS, py_blf_shadow_doc},
{"shadow_offset", (PyCFunction) py_blf_shadow_offset, METH_VARARGS, py_blf_shadow_offset_doc},
{"size", (PyCFunction) py_blf_size, METH_VARARGS, py_blf_size_doc},
{"color", (PyCFunction) py_blf_color, METH_VARARGS, py_blf_color_doc},
{"load", (PyCFunction) py_blf_load, METH_VARARGS, py_blf_load_doc},
{"unload", (PyCFunction) py_blf_unload, METH_VARARGS, py_blf_unload_doc},
{NULL, NULL, 0, NULL},
{"clipping", (PyCFunction)py_blf_clipping, METH_VARARGS, py_blf_clipping_doc},
{"word_wrap", (PyCFunction)py_blf_word_wrap, METH_VARARGS, py_blf_word_wrap_doc},
{"disable", (PyCFunction)py_blf_disable, METH_VARARGS, py_blf_disable_doc},
{"dimensions", (PyCFunction)py_blf_dimensions, METH_VARARGS, py_blf_dimensions_doc},
{"draw", (PyCFunction)py_blf_draw, METH_VARARGS, py_blf_draw_doc},
{"enable", (PyCFunction)py_blf_enable, METH_VARARGS, py_blf_enable_doc},
{"position", (PyCFunction)py_blf_position, METH_VARARGS, py_blf_position_doc},
{"rotation", (PyCFunction)py_blf_rotation, METH_VARARGS, py_blf_rotation_doc},
{"shadow", (PyCFunction)py_blf_shadow, METH_VARARGS, py_blf_shadow_doc},
{"shadow_offset", (PyCFunction)py_blf_shadow_offset, METH_VARARGS, py_blf_shadow_offset_doc},
{"size", (PyCFunction)py_blf_size, METH_VARARGS, py_blf_size_doc},
{"color", (PyCFunction)py_blf_color, METH_VARARGS, py_blf_color_doc},
{"load", (PyCFunction)py_blf_load, METH_VARARGS, py_blf_load_doc},
{"unload", (PyCFunction)py_blf_unload, METH_VARARGS, py_blf_unload_doc},
{NULL, NULL, 0, NULL},
};
PyDoc_STRVAR(BLF_doc,
"This module provides access to blenders text drawing functions."
);
PyDoc_STRVAR(BLF_doc, "This module provides access to blenders text drawing functions.");
static struct PyModuleDef BLF_module_def = {
PyModuleDef_HEAD_INIT,
"blf", /* m_name */
BLF_doc, /* m_doc */
0, /* m_size */
BLF_methods, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
PyModuleDef_HEAD_INIT,
"blf", /* m_name */
BLF_doc, /* m_doc */
0, /* m_size */
BLF_methods, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
PyObject *BPyInit_blf(void)
{
PyObject *submodule;
PyObject *submodule;
submodule = PyModule_Create(&BLF_module_def);
submodule = PyModule_Create(&BLF_module_def);
PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION);
PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING);
PyModule_AddIntConstant(submodule, "SHADOW", BLF_SHADOW);
PyModule_AddIntConstant(submodule, "KERNING_DEFAULT", BLF_KERNING_DEFAULT);
PyModule_AddIntConstant(submodule, "WORD_WRAP", BLF_WORD_WRAP);
PyModule_AddIntConstant(submodule, "MONOCHROME", BLF_MONOCHROME);
PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION);
PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING);
PyModule_AddIntConstant(submodule, "SHADOW", BLF_SHADOW);
PyModule_AddIntConstant(submodule, "KERNING_DEFAULT", BLF_KERNING_DEFAULT);
PyModule_AddIntConstant(submodule, "WORD_WRAP", BLF_WORD_WRAP);
PyModule_AddIntConstant(submodule, "MONOCHROME", BLF_MONOCHROME);
return submodule;
return submodule;
}

View File

@@ -23,4 +23,4 @@
PyObject *BPyInit_blf(void);
#endif /* __BLF_PY_API_H__ */
#endif /* __BLF_PY_API_H__ */

View File

@@ -24,7 +24,6 @@
* This should eventually be replaced by import hooks (pep 302).
*/
#include <Python.h>
#include <stddef.h>
@@ -39,18 +38,18 @@
#include "BKE_main.h"
/* UNUSED */
#include "BKE_text.h" /* txt_to_buf */
#include "BKE_text.h" /* txt_to_buf */
#include "py_capi_utils.h"
#include "bpy_internal_import.h" /* own include */
#include "bpy_internal_import.h" /* own include */
static Main *bpy_import_main = NULL;
static ListBase bpy_import_main_list;
static PyMethodDef bpy_import_meth;
static PyMethodDef bpy_reload_meth;
static PyObject *imp_reload_orig = NULL;
static PyObject *imp_reload_orig = NULL;
/* 'builtins' is most likely PyEval_GetBuiltins() */
@@ -68,304 +67,309 @@ static PyObject *imp_reload_orig = NULL;
*/
void bpy_import_init(PyObject *builtins)
{
PyObject *item;
PyObject *mod;
PyObject *item;
PyObject *mod;
PyDict_SetItemString(builtins, "__import__", item = PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item);
PyDict_SetItemString(builtins, "__import__", item = PyCFunction_New(&bpy_import_meth, NULL));
Py_DECREF(item);
/* move reload here
* XXX, use import hooks */
mod = PyImport_ImportModuleLevel("importlib", NULL, NULL, NULL, 0);
if (mod) {
PyObject *mod_dict = PyModule_GetDict(mod);
/* move reload here
* XXX, use import hooks */
mod = PyImport_ImportModuleLevel("importlib", NULL, NULL, NULL, 0);
if (mod) {
PyObject *mod_dict = PyModule_GetDict(mod);
/* blender owns the function */
imp_reload_orig = PyDict_GetItemString(mod_dict, "reload");
Py_INCREF(imp_reload_orig);
/* blender owns the function */
imp_reload_orig = PyDict_GetItemString(mod_dict, "reload");
Py_INCREF(imp_reload_orig);
PyDict_SetItemString(mod_dict, "reload", item = PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item);
Py_DECREF(mod);
}
else {
BLI_assert(!"unable to load 'importlib' module.");
}
PyDict_SetItemString(mod_dict, "reload", item = PyCFunction_New(&bpy_reload_meth, NULL));
Py_DECREF(item);
Py_DECREF(mod);
}
else {
BLI_assert(!"unable to load 'importlib' module.");
}
}
static void free_compiled_text(Text *text)
{
if (text->compiled) {
Py_DECREF((PyObject *)text->compiled);
}
text->compiled = NULL;
if (text->compiled) {
Py_DECREF((PyObject *)text->compiled);
}
text->compiled = NULL;
}
struct Main *bpy_import_main_get(void)
{
return bpy_import_main;
return bpy_import_main;
}
void bpy_import_main_set(struct Main *maggie)
{
bpy_import_main = maggie;
bpy_import_main = maggie;
}
/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
{
BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2);
BLI_snprintf(
fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2);
}
bool bpy_text_compile(Text *text)
{
char fn_dummy[FILE_MAX];
PyObject *fn_dummy_py;
char *buf;
char fn_dummy[FILE_MAX];
PyObject *fn_dummy_py;
char *buf;
bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);
bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);
/* if previously compiled, free the object */
free_compiled_text(text);
/* if previously compiled, free the object */
free_compiled_text(text);
fn_dummy_py = PyC_UnicodeFromByte(fn_dummy);
fn_dummy_py = PyC_UnicodeFromByte(fn_dummy);
buf = txt_to_buf(text);
text->compiled = Py_CompileStringObject(buf, fn_dummy_py, Py_file_input, NULL, -1);
MEM_freeN(buf);
buf = txt_to_buf(text);
text->compiled = Py_CompileStringObject(buf, fn_dummy_py, Py_file_input, NULL, -1);
MEM_freeN(buf);
Py_DECREF(fn_dummy_py);
Py_DECREF(fn_dummy_py);
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
PySys_SetObject("last_traceback", NULL);
free_compiled_text(text);
return false;
}
else {
return true;
}
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
PySys_SetObject("last_traceback", NULL);
free_compiled_text(text);
return false;
}
else {
return true;
}
}
PyObject *bpy_text_import(Text *text)
{
char modulename[MAX_ID_NAME + 2];
int len;
char modulename[MAX_ID_NAME + 2];
int len;
if (!text->compiled) {
if (bpy_text_compile(text) == false) {
return NULL;
}
}
if (!text->compiled) {
if (bpy_text_compile(text) == false) {
return NULL;
}
}
len = strlen(text->id.name + 2);
BLI_strncpy(modulename, text->id.name + 2, len);
modulename[len - 3] = '\0'; /* remove .py */
return PyImport_ExecCodeModule(modulename, text->compiled);
len = strlen(text->id.name + 2);
BLI_strncpy(modulename, text->id.name + 2, len);
modulename[len - 3] = '\0'; /* remove .py */
return PyImport_ExecCodeModule(modulename, text->compiled);
}
PyObject *bpy_text_import_name(const char *name, int *found)
{
Text *text;
char txtname[MAX_ID_NAME - 2];
int namelen = strlen(name);
//XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN;
Main *maggie = bpy_import_main;
Text *text;
char txtname[MAX_ID_NAME - 2];
int namelen = strlen(name);
//XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN;
Main *maggie = bpy_import_main;
*found = 0;
*found = 0;
if (!maggie) {
printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n");
return NULL;
}
if (!maggie) {
printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n");
return NULL;
}
/* we know this cant be importable, the name is too long for blender! */
if (namelen >= (MAX_ID_NAME - 2) - 3) {
return NULL;
}
/* we know this cant be importable, the name is too long for blender! */
if (namelen >= (MAX_ID_NAME - 2) - 3) {
return NULL;
}
memcpy(txtname, name, namelen);
memcpy(&txtname[namelen], ".py", 4);
memcpy(txtname, name, namelen);
memcpy(&txtname[namelen], ".py", 4);
text = BLI_findstring(&maggie->texts, txtname, offsetof(ID, name) + 2);
text = BLI_findstring(&maggie->texts, txtname, offsetof(ID, name) + 2);
if (text) {
*found = 1;
return bpy_text_import(text);
}
if (text) {
*found = 1;
return bpy_text_import(text);
}
/* If we still haven't found the module try additional modules form bpy_import_main_list */
maggie = bpy_import_main_list.first;
while (maggie && !text) {
text = BLI_findstring(&maggie->texts, txtname, offsetof(ID, name) + 2);
maggie = maggie->next;
}
/* If we still haven't found the module try additional modules form bpy_import_main_list */
maggie = bpy_import_main_list.first;
while (maggie && !text) {
text = BLI_findstring(&maggie->texts, txtname, offsetof(ID, name) + 2);
maggie = maggie->next;
}
if (!text) {
return NULL;
}
else {
*found = 1;
}
if (!text) {
return NULL;
}
else {
*found = 1;
}
return bpy_text_import(text);
return bpy_text_import(text);
}
/*
* find in-memory module and recompile
*/
PyObject *bpy_text_reimport(PyObject *module, int *found)
{
Text *text;
const char *name;
const char *filepath;
//XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN;
Main *maggie = bpy_import_main;
Text *text;
const char *name;
const char *filepath;
//XXX Main *maggie = bpy_import_main ? bpy_import_main : G_MAIN;
Main *maggie = bpy_import_main;
if (!maggie) {
printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n");
return NULL;
}
if (!maggie) {
printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n");
return NULL;
}
*found = 0;
*found = 0;
/* get name, filename from the module itself */
if ((name = PyModule_GetName(module)) == NULL) {
return NULL;
}
/* get name, filename from the module itself */
if ((name = PyModule_GetName(module)) == NULL) {
return NULL;
}
{
PyObject *module_file = PyModule_GetFilenameObject(module);
if (module_file == NULL) {
return NULL;
}
filepath = _PyUnicode_AsString(module_file);
Py_DECREF(module_file);
if (filepath == NULL) {
return NULL;
}
}
{
PyObject *module_file = PyModule_GetFilenameObject(module);
if (module_file == NULL) {
return NULL;
}
filepath = _PyUnicode_AsString(module_file);
Py_DECREF(module_file);
if (filepath == NULL) {
return NULL;
}
}
/* look up the text object */
text = BLI_findstring(&maggie->texts, BLI_path_basename(filepath), offsetof(ID, name) + 2);
/* look up the text object */
text = BLI_findstring(&maggie->texts, BLI_path_basename(filepath), offsetof(ID, name) + 2);
/* uh-oh.... didn't find it */
if (!text) {
return NULL;
}
else {
*found = 1;
}
/* uh-oh.... didn't find it */
if (!text) {
return NULL;
}
else {
*found = 1;
}
if (bpy_text_compile(text) == false) {
return NULL;
}
if (bpy_text_compile(text) == false) {
return NULL;
}
/* make into a module */
return PyImport_ExecCodeModule(name, text->compiled);
/* make into a module */
return PyImport_ExecCodeModule(name, text->compiled);
}
static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
PyObject *exception, *err, *tb;
const char *name;
int found = 0;
PyObject *globals = NULL, *locals = NULL, *fromlist = NULL;
int level = 0; /* relative imports */
PyObject *newmodule;
PyObject *exception, *err, *tb;
const char *name;
int found = 0;
PyObject *globals = NULL, *locals = NULL, *fromlist = NULL;
int level = 0; /* relative imports */
PyObject *newmodule;
static const char *_keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL};
static _PyArg_Parser _parser = {"s|OOOi:bpy_import_meth", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kw, &_parser,
&name, &globals, &locals, &fromlist, &level))
{
return NULL;
}
static const char *_keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL};
static _PyArg_Parser _parser = {"s|OOOi:bpy_import_meth", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kw, &_parser, &name, &globals, &locals, &fromlist, &level)) {
return NULL;
}
/* import existing builtin modules or modules that have been imported already */
newmodule = PyImport_ImportModuleLevel(name, globals, locals, fromlist, level);
/* import existing builtin modules or modules that have been imported already */
newmodule = PyImport_ImportModuleLevel(name, globals, locals, fromlist, level);
if (newmodule) {
return newmodule;
}
if (newmodule) {
return newmodule;
}
PyErr_Fetch(&exception, &err, &tb); /* get the python error in case we cant import as blender text either */
PyErr_Fetch(&exception,
&err,
&tb); /* get the python error in case we cant import as blender text either */
/* importing from existing modules failed, see if we have this module as blender text */
newmodule = bpy_text_import_name(name, &found);
/* importing from existing modules failed, see if we have this module as blender text */
newmodule = bpy_text_import_name(name, &found);
if (newmodule) { /* found module as blender text, ignore above exception */
PyErr_Clear();
Py_XDECREF(exception);
Py_XDECREF(err);
Py_XDECREF(tb);
/* printf("imported from text buffer...\n"); */
}
else if (found == 1) { /* blender text module failed to execute but was found, use its error message */
Py_XDECREF(exception);
Py_XDECREF(err);
Py_XDECREF(tb);
return NULL;
}
else {
/* no blender text was found that could import the module
* reuse the original error from PyImport_ImportModuleEx */
PyErr_Restore(exception, err, tb);
}
return newmodule;
if (newmodule) { /* found module as blender text, ignore above exception */
PyErr_Clear();
Py_XDECREF(exception);
Py_XDECREF(err);
Py_XDECREF(tb);
/* printf("imported from text buffer...\n"); */
}
else if (found ==
1) { /* blender text module failed to execute but was found, use its error message */
Py_XDECREF(exception);
Py_XDECREF(err);
Py_XDECREF(tb);
return NULL;
}
else {
/* no blender text was found that could import the module
* reuse the original error from PyImport_ImportModuleEx */
PyErr_Restore(exception, err, tb);
}
return newmodule;
}
/*
* our reload() module, to handle reloading in-memory scripts
*/
static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module)
{
PyObject *exception, *err, *tb;
PyObject *newmodule = NULL;
int found = 0;
PyObject *exception, *err, *tb;
PyObject *newmodule = NULL;
int found = 0;
/* try reimporting from file */
/* try reimporting from file */
/* in Py3.3 this just calls imp.reload() which we overwrite, causing recursive calls */
//newmodule = PyImport_ReloadModule(module);
/* in Py3.3 this just calls imp.reload() which we overwrite, causing recursive calls */
//newmodule = PyImport_ReloadModule(module);
newmodule = PyObject_CallFunctionObjArgs(imp_reload_orig, module, NULL);
newmodule = PyObject_CallFunctionObjArgs(imp_reload_orig, module, NULL);
if (newmodule) {
return newmodule;
}
if (newmodule) {
return newmodule;
}
/* no file, try importing from memory */
PyErr_Fetch(&exception, &err, &tb); /*restore for probable later use */
/* no file, try importing from memory */
PyErr_Fetch(&exception, &err, &tb); /*restore for probable later use */
newmodule = bpy_text_reimport(module, &found);
if (newmodule) { /* found module as blender text, ignore above exception */
PyErr_Clear();
Py_XDECREF(exception);
Py_XDECREF(err);
Py_XDECREF(tb);
/* printf("imported from text buffer...\n"); */
}
else if (found == 1) { /* blender text module failed to execute but was found, use its error message */
Py_XDECREF(exception);
Py_XDECREF(err);
Py_XDECREF(tb);
return NULL;
}
else {
/* no blender text was found that could import the module
* reuse the original error from PyImport_ImportModuleEx */
PyErr_Restore(exception, err, tb);
}
newmodule = bpy_text_reimport(module, &found);
if (newmodule) { /* found module as blender text, ignore above exception */
PyErr_Clear();
Py_XDECREF(exception);
Py_XDECREF(err);
Py_XDECREF(tb);
/* printf("imported from text buffer...\n"); */
}
else if (found ==
1) { /* blender text module failed to execute but was found, use its error message */
Py_XDECREF(exception);
Py_XDECREF(err);
Py_XDECREF(tb);
return NULL;
}
else {
/* no blender text was found that could import the module
* reuse the original error from PyImport_ImportModuleEx */
PyErr_Restore(exception, err, tb);
}
return newmodule;
return newmodule;
}
static PyMethodDef bpy_import_meth = {"bpy_import_meth", (PyCFunction)blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"};
static PyMethodDef bpy_reload_meth = {"bpy_reload_meth", (PyCFunction)blender_reload, METH_O, "blenders reload"};
static PyMethodDef bpy_import_meth = {"bpy_import_meth",
(PyCFunction)blender_import,
METH_VARARGS | METH_KEYWORDS,
"blenders import"};
static PyMethodDef bpy_reload_meth = {
"bpy_reload_meth", (PyCFunction)blender_reload, METH_O, "blenders reload"};

View File

@@ -18,7 +18,6 @@
* \ingroup pygen
*/
/* Note, the BGE needs to use this too, keep it minimal */
#ifndef __BPY_INTERNAL_IMPORT_H__
@@ -26,26 +25,26 @@
/* python redefines :/ */
#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
# undef _POSIX_C_SOURCE
#endif
#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
# undef _XOPEN_SOURCE
#endif
struct Text;
void bpy_import_init(PyObject *builtins);
bool bpy_text_compile(struct Text *text);
PyObject *bpy_text_import(struct Text *text);
PyObject *bpy_text_import_name(const char *name, int *found);
PyObject *bpy_text_reimport(PyObject *module, int *found);
/* void bpy_text_clear_modules(int clear_all);*/ /* Clear user modules */
bool bpy_text_compile(struct Text *text);
PyObject *bpy_text_import(struct Text *text);
PyObject *bpy_text_import_name(const char *name, int *found);
PyObject *bpy_text_reimport(PyObject *module, int *found);
/* void bpy_text_clear_modules(int clear_all);*/ /* Clear user modules */
void bpy_text_filename_get(char *fn, size_t fn_len, struct Text *text);
struct Main *bpy_import_main_get(void);
void bpy_import_main_set(struct Main *maggie);
#endif /* __BPY_INTERNAL_IMPORT_H__ */
#endif /* __BPY_INTERNAL_IMPORT_H__ */

View File

@@ -29,20 +29,20 @@
/* analogue of PyEval_SaveThread() */
BPy_ThreadStatePtr BPY_thread_save(void)
{
PyThreadState *tstate = PyThreadState_Swap(NULL);
/* note: tstate can be NULL when quitting Blender */
PyThreadState *tstate = PyThreadState_Swap(NULL);
/* note: tstate can be NULL when quitting Blender */
if (tstate && PyEval_ThreadsInitialized()) {
PyEval_ReleaseLock();
}
if (tstate && PyEval_ThreadsInitialized()) {
PyEval_ReleaseLock();
}
return (BPy_ThreadStatePtr)tstate;
return (BPy_ThreadStatePtr)tstate;
}
/* analogue of PyEval_RestoreThread() */
void BPY_thread_restore(BPy_ThreadStatePtr tstate)
{
if (tstate) {
PyEval_RestoreThread((PyThreadState *)tstate);
}
if (tstate) {
PyEval_RestoreThread((PyThreadState *)tstate);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,6 @@
* \ingroup pygen
*/
#ifndef __IDPROP_PY_API_H__
#define __IDPROP_PY_API_H__
@@ -30,32 +29,29 @@ extern PyTypeObject BPy_IDArray_Type;
extern PyTypeObject BPy_IDGroup_Iter_Type;
extern PyTypeObject BPy_IDGroup_Type;
#define BPy_IDArray_Check(v) (PyObject_TypeCheck(v, &BPy_IDArray_Type))
#define BPy_IDArray_CheckExact(v) (Py_TYPE(v) == &BPy_IDArray_Type)
#define BPy_IDGroup_Iter_Check(v) (PyObject_TypeCheck(v, &BPy_IDGroup_Iter_Type))
#define BPy_IDGroup_Iter_CheckExact(v) (Py_TYPE(v) == &BPy_IDGroup_Iter_Type)
#define BPy_IDGroup_Check(v) (PyObject_TypeCheck(v, &BPy_IDGroup_Type))
#define BPy_IDGroup_CheckExact(v) (Py_TYPE(v) == &BPy_IDGroup_Type)
#define BPy_IDArray_Check(v) (PyObject_TypeCheck(v, &BPy_IDArray_Type))
#define BPy_IDArray_CheckExact(v) (Py_TYPE(v) == &BPy_IDArray_Type)
#define BPy_IDGroup_Iter_Check(v) (PyObject_TypeCheck(v, &BPy_IDGroup_Iter_Type))
#define BPy_IDGroup_Iter_CheckExact(v) (Py_TYPE(v) == &BPy_IDGroup_Iter_Type)
#define BPy_IDGroup_Check(v) (PyObject_TypeCheck(v, &BPy_IDGroup_Type))
#define BPy_IDGroup_CheckExact(v) (Py_TYPE(v) == &BPy_IDGroup_Type)
typedef struct BPy_IDProperty {
PyObject_VAR_HEAD
struct ID *id; /* can be NULL */
struct IDProperty *prop; /* must be second member */
struct IDProperty *parent;
PyObject *data_wrap;
PyObject_VAR_HEAD struct ID *id; /* can be NULL */
struct IDProperty *prop; /* must be second member */
struct IDProperty *parent;
PyObject *data_wrap;
} BPy_IDProperty;
typedef struct BPy_IDArray {
PyObject_VAR_HEAD
struct ID *id; /* can be NULL */
struct IDProperty *prop; /* must be second member */
PyObject_VAR_HEAD struct ID *id; /* can be NULL */
struct IDProperty *prop; /* must be second member */
} BPy_IDArray;
typedef struct BPy_IDGroup_Iter {
PyObject_VAR_HEAD
BPy_IDProperty *group;
struct IDProperty *cur;
int mode;
PyObject_VAR_HEAD BPy_IDProperty *group;
struct IDProperty *cur;
int mode;
} BPy_IDGroup_Iter;
PyObject *BPy_Wrap_GetKeys(struct IDProperty *prop);
@@ -63,7 +59,6 @@ PyObject *BPy_Wrap_GetValues(struct ID *id, struct IDProperty *prop);
PyObject *BPy_Wrap_GetItems(struct ID *id, struct IDProperty *prop);
int BPy_Wrap_SetMapItem(struct IDProperty *prop, PyObject *key, PyObject *val);
PyObject *BPy_IDGroup_WrapData(struct ID *id, struct IDProperty *prop, struct IDProperty *parent);
bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *key, struct IDProperty *group, PyObject *ob);
@@ -71,7 +66,7 @@ void IDProp_Init_Types(void);
PyObject *BPyInit_idprop(void);
#define IDPROP_ITER_KEYS 0
#define IDPROP_ITER_ITEMS 1
#define IDPROP_ITER_KEYS 0
#define IDPROP_ITER_ITEMS 1
#endif /* __IDPROP_PY_API_H__ */

View File

@@ -29,7 +29,7 @@
#include "python_utildefines.h"
#include "imbuf_py_api.h" /* own include */
#include "imbuf_py_api.h" /* own include */
#include "../../imbuf/IMB_imbuf.h"
#include "../../imbuf/IMB_imbuf_types.h"
@@ -46,28 +46,33 @@ static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf);
* \{ */
typedef struct Py_ImBuf {
PyObject_VAR_HEAD
/* can be NULL */
ImBuf *ibuf;
PyObject_VAR_HEAD
/* can be NULL */
ImBuf *ibuf;
} Py_ImBuf;
static int py_imbuf_valid_check(Py_ImBuf *self)
{
if (LIKELY(self->ibuf)) {
return 0;
}
else {
PyErr_Format(PyExc_ReferenceError,
"ImBuf data of type %.200s has been freed",
Py_TYPE(self)->tp_name);
return -1;
}
if (LIKELY(self->ibuf)) {
return 0;
}
else {
PyErr_Format(
PyExc_ReferenceError, "ImBuf data of type %.200s has been freed", Py_TYPE(self)->tp_name);
return -1;
}
}
#define PY_IMBUF_CHECK_OBJ(obj) \
if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { return NULL; } ((void)0)
if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \
return NULL; \
} \
((void)0)
#define PY_IMBUF_CHECK_INT(obj) \
if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { return -1; } ((void)0)
if (UNLIKELY(py_imbuf_valid_check(obj) == -1)) { \
return -1; \
} \
((void)0)
/** \} */
@@ -76,77 +81,72 @@ static int py_imbuf_valid_check(Py_ImBuf *self)
* \{ */
PyDoc_STRVAR(py_imbuf_resize_doc,
".. method:: resize(size, method='FAST')\n"
"\n"
" Resize the image.\n"
"\n"
" :arg size: New size.\n"
" :type size: pair of ints\n"
" :arg method: Method of resizing (TODO)\n"
" :type method: str\n"
);
".. method:: resize(size, method='FAST')\n"
"\n"
" Resize the image.\n"
"\n"
" :arg size: New size.\n"
" :type size: pair of ints\n"
" :arg method: Method of resizing (TODO)\n"
" :type method: str\n");
static PyObject *py_imbuf_resize(Py_ImBuf *self, PyObject *args, PyObject *kw)
{
PY_IMBUF_CHECK_OBJ(self);
PY_IMBUF_CHECK_OBJ(self);
uint size[2];
char *method = NULL;
uint size[2];
char *method = NULL;
static const char *_keywords[] = {"size", "method", NULL};
static _PyArg_Parser _parser = {"(II)|s:resize", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kw, &_parser,
&size[0], &size[1],
&method))
{
return NULL;
}
IMB_scaleImBuf(self->ibuf, UNPACK2(size));
Py_RETURN_NONE;
static const char *_keywords[] = {"size", "method", NULL};
static _PyArg_Parser _parser = {"(II)|s:resize", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &size[0], &size[1], &method)) {
return NULL;
}
IMB_scaleImBuf(self->ibuf, UNPACK2(size));
Py_RETURN_NONE;
}
PyDoc_STRVAR(py_imbuf_copy_doc,
".. method:: copy()\n"
"\n"
" :return: A copy of the image.\n"
" :rtype: :class:`ImBuf`\n"
);
".. method:: copy()\n"
"\n"
" :return: A copy of the image.\n"
" :rtype: :class:`ImBuf`\n");
static PyObject *py_imbuf_copy(Py_ImBuf *self)
{
PY_IMBUF_CHECK_OBJ(self);
return Py_ImBuf_CreatePyObject(self->ibuf);
PY_IMBUF_CHECK_OBJ(self);
return Py_ImBuf_CreatePyObject(self->ibuf);
}
static PyObject *py_imbuf_deepcopy(Py_ImBuf *self, PyObject *args)
{
if (!PyC_CheckArgs_DeepCopy(args)) {
return NULL;
}
return py_imbuf_copy(self);
if (!PyC_CheckArgs_DeepCopy(args)) {
return NULL;
}
return py_imbuf_copy(self);
}
PyDoc_STRVAR(py_imbuf_free_doc,
".. method:: free()\n"
"\n"
" Clear image data immediately (causing an error on re-use).\n"
);
".. method:: free()\n"
"\n"
" Clear image data immediately (causing an error on re-use).\n");
static PyObject *py_imbuf_free(Py_ImBuf *self)
{
if (self->ibuf) {
IMB_freeImBuf(self->ibuf);
self->ibuf = NULL;
}
Py_RETURN_NONE;
if (self->ibuf) {
IMB_freeImBuf(self->ibuf);
self->ibuf = NULL;
}
Py_RETURN_NONE;
}
static struct PyMethodDef Py_ImBuf_methods[] = {
{"resize", (PyCFunction)py_imbuf_resize, METH_VARARGS | METH_KEYWORDS, (char *)py_imbuf_resize_doc},
{"free", (PyCFunction)py_imbuf_free, METH_NOARGS, (char *)py_imbuf_free_doc},
{"copy", (PyCFunction)py_imbuf_copy, METH_NOARGS, (char *)py_imbuf_copy_doc},
{"__copy__", (PyCFunction)py_imbuf_copy, METH_NOARGS, (char *)py_imbuf_copy_doc},
{"__deepcopy__", (PyCFunction)py_imbuf_deepcopy, METH_VARARGS, (char *)py_imbuf_copy_doc},
{NULL, NULL, 0, NULL},
{"resize",
(PyCFunction)py_imbuf_resize,
METH_VARARGS | METH_KEYWORDS,
(char *)py_imbuf_resize_doc},
{"free", (PyCFunction)py_imbuf_free, METH_NOARGS, (char *)py_imbuf_free_doc},
{"copy", (PyCFunction)py_imbuf_copy, METH_NOARGS, (char *)py_imbuf_copy_doc},
{"__copy__", (PyCFunction)py_imbuf_copy, METH_NOARGS, (char *)py_imbuf_copy_doc},
{"__deepcopy__", (PyCFunction)py_imbuf_deepcopy, METH_VARARGS, (char *)py_imbuf_copy_doc},
{NULL, NULL, 0, NULL},
};
/** \} */
@@ -155,50 +155,50 @@ static struct PyMethodDef Py_ImBuf_methods[] = {
/** \name Attributes
* \{ */
PyDoc_STRVAR(py_imbuf_size_doc,
"size of the image in pixels.\n\n:type: pair of ints"
);
PyDoc_STRVAR(py_imbuf_size_doc, "size of the image in pixels.\n\n:type: pair of ints");
static PyObject *py_imbuf_size_get(Py_ImBuf *self, void *UNUSED(closure))
{
PY_IMBUF_CHECK_OBJ(self);
ImBuf *ibuf = self->ibuf;
return PyC_Tuple_Pack_I32(ibuf->x, ibuf->y);
PY_IMBUF_CHECK_OBJ(self);
ImBuf *ibuf = self->ibuf;
return PyC_Tuple_Pack_I32(ibuf->x, ibuf->y);
}
PyDoc_STRVAR(py_imbuf_ppm_doc,
"pixels per meter.\n\n:type: pair of floats"
);
PyDoc_STRVAR(py_imbuf_ppm_doc, "pixels per meter.\n\n:type: pair of floats");
static PyObject *py_imbuf_ppm_get(Py_ImBuf *self, void *UNUSED(closure))
{
PY_IMBUF_CHECK_OBJ(self);
ImBuf *ibuf = self->ibuf;
return PyC_Tuple_Pack_F64(ibuf->ppm[0], ibuf->ppm[1]);
PY_IMBUF_CHECK_OBJ(self);
ImBuf *ibuf = self->ibuf;
return PyC_Tuple_Pack_F64(ibuf->ppm[0], ibuf->ppm[1]);
}
static int py_imbuf_ppm_set(Py_ImBuf *self, PyObject *value, void *UNUSED(closure))
{
PY_IMBUF_CHECK_INT(self);
double ppm[2];
PY_IMBUF_CHECK_INT(self);
double ppm[2];
if (PyC_AsArray(ppm, value, 2, &PyFloat_Type, true, "ppm") == -1) {
return -1;
}
if (PyC_AsArray(ppm, value, 2, &PyFloat_Type, true, "ppm") == -1) {
return -1;
}
if (ppm[0] <= 0.0 || ppm[1] <= 0.0) {
PyErr_SetString(PyExc_ValueError, "invalid ppm value");
return -1;
}
if (ppm[0] <= 0.0 || ppm[1] <= 0.0) {
PyErr_SetString(PyExc_ValueError, "invalid ppm value");
return -1;
}
ImBuf *ibuf = self->ibuf;
ibuf->ppm[0] = ppm[0];
ibuf->ppm[1] = ppm[1];
return 0;
ImBuf *ibuf = self->ibuf;
ibuf->ppm[0] = ppm[0];
ibuf->ppm[1] = ppm[1];
return 0;
}
static PyGetSetDef Py_ImBuf_getseters[] = {
{(char *)"size", (getter)py_imbuf_size_get, (setter)NULL, (char *)py_imbuf_size_doc, NULL},
{(char *)"ppm", (getter)py_imbuf_ppm_get, (setter)py_imbuf_ppm_set, (char *)py_imbuf_ppm_doc, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
{(char *)"size", (getter)py_imbuf_size_get, (setter)NULL, (char *)py_imbuf_size_doc, NULL},
{(char *)"ppm",
(getter)py_imbuf_ppm_get,
(setter)py_imbuf_ppm_set,
(char *)py_imbuf_ppm_doc,
NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
/** \} */
@@ -209,99 +209,97 @@ static PyGetSetDef Py_ImBuf_getseters[] = {
static void py_imbuf_dealloc(Py_ImBuf *self)
{
ImBuf *ibuf = self->ibuf;
if (ibuf != NULL) {
IMB_freeImBuf(self->ibuf);
self->ibuf = NULL;
}
PyObject_DEL(self);
ImBuf *ibuf = self->ibuf;
if (ibuf != NULL) {
IMB_freeImBuf(self->ibuf);
self->ibuf = NULL;
}
PyObject_DEL(self);
}
static PyObject *py_imbuf_repr(Py_ImBuf *self)
{
const ImBuf *ibuf = self->ibuf;
if (ibuf != NULL) {
return PyUnicode_FromFormat(
"<imbuf: address=%p, filename='%s', size=(%d, %d)>",
ibuf, ibuf->name, ibuf->x, ibuf->y);
}
else {
return PyUnicode_FromString(
"<imbuf: address=0x0>");
}
const ImBuf *ibuf = self->ibuf;
if (ibuf != NULL) {
return PyUnicode_FromFormat(
"<imbuf: address=%p, filename='%s', size=(%d, %d)>", ibuf, ibuf->name, ibuf->x, ibuf->y);
}
else {
return PyUnicode_FromString("<imbuf: address=0x0>");
}
}
static Py_hash_t py_imbuf_hash(Py_ImBuf *self)
{
return _Py_HashPointer(self->ibuf);
return _Py_HashPointer(self->ibuf);
}
PyTypeObject Py_ImBuf_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
/* For printing, in format "<module>.<name>" */
"ImBuf", /* tp_name */
sizeof(Py_ImBuf), /* int tp_basicsize; */
0, /* tp_itemsize; For allocation */
PyVarObject_HEAD_INIT(NULL, 0)
/* For printing, in format "<module>.<name>" */
"ImBuf", /* tp_name */
sizeof(Py_ImBuf), /* int tp_basicsize; */
0, /* tp_itemsize; For allocation */
/* Methods to implement standard operations */
/* Methods to implement standard operations */
(destructor)py_imbuf_dealloc, /* destructor tp_dealloc; */
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* cmpfunc tp_compare; */
(reprfunc)py_imbuf_repr, /* reprfunc tp_repr; */
(destructor)py_imbuf_dealloc, /* destructor tp_dealloc; */
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* cmpfunc tp_compare; */
(reprfunc)py_imbuf_repr, /* reprfunc tp_repr; */
/* Method suites for standard classes */
/* Method suites for standard classes */
NULL, /* PyNumberMethods *tp_as_number; */
NULL, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
NULL, /* PyNumberMethods *tp_as_number; */
NULL, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
/* More standard operations (here for binary compatibility) */
(hashfunc)py_imbuf_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
(hashfunc)py_imbuf_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
NULL, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
NULL, /* char *tp_doc; Documentation string */
/*** Assigned meaning in release 2.0 ***/
/* call function for all accessible objects */
NULL, /* traverseproc tp_traverse; */
NULL, /* char *tp_doc; Documentation string */
/*** Assigned meaning in release 2.0 ***/
/* call function for all accessible objects */
NULL, /* traverseproc tp_traverse; */
/* delete references to contained objects */
NULL, /* inquiry tp_clear; */
/* delete references to contained objects */
NULL, /* inquiry tp_clear; */
/*** Assigned meaning in release 2.1 ***/
/*** rich comparisons ***/
NULL, /* richcmpfunc tp_richcompare; */
/*** Assigned meaning in release 2.1 ***/
/*** rich comparisons ***/
NULL, /* richcmpfunc tp_richcompare; */
/*** weak reference enabler ***/
0, /* long tp_weaklistoffset; */
/*** weak reference enabler ***/
0, /* long tp_weaklistoffset; */
/*** Added in release 2.2 ***/
/* Iterators */
NULL, /* getiterfunc tp_iter; */
NULL, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
Py_ImBuf_methods, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
Py_ImBuf_getseters, /* struct PyGetSetDef *tp_getset; */
/*** Added in release 2.2 ***/
/* Iterators */
NULL, /* getiterfunc tp_iter; */
NULL, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
Py_ImBuf_methods, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
Py_ImBuf_getseters, /* struct PyGetSetDef *tp_getset; */
};
static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf)
{
Py_ImBuf *self = PyObject_New(Py_ImBuf, &Py_ImBuf_Type);
self->ibuf = ibuf;
return (PyObject *)self;
Py_ImBuf *self = PyObject_New(Py_ImBuf, &Py_ImBuf_Type);
self->ibuf = ibuf;
return (PyObject *)self;
}
/** \} */
@@ -311,118 +309,107 @@ static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf)
* \{ */
PyDoc_STRVAR(M_imbuf_new_doc,
".. function:: new(size)\n"
"\n"
" Load a new image.\n"
"\n"
" :arg size: The size of the image in pixels.\n"
" :type size: pair of ints\n"
" :return: the newly loaded image.\n"
" :rtype: :class:`ImBuf`\n"
);
".. function:: new(size)\n"
"\n"
" Load a new image.\n"
"\n"
" :arg size: The size of the image in pixels.\n"
" :type size: pair of ints\n"
" :return: the newly loaded image.\n"
" :rtype: :class:`ImBuf`\n");
static PyObject *M_imbuf_new(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
int size[2];
static const char *_keywords[] = {"size", NULL};
static _PyArg_Parser _parser = {"(ii)|i:new", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kw, &_parser,
&size[0], &size[1]))
{
return NULL;
}
int size[2];
static const char *_keywords[] = {"size", NULL};
static _PyArg_Parser _parser = {"(ii)|i:new", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &size[0], &size[1])) {
return NULL;
}
/* TODO, make options */
uchar planes = 4;
uint flags = IB_rect;
/* TODO, make options */
uchar planes = 4;
uint flags = IB_rect;
ImBuf *ibuf = IMB_allocImBuf(UNPACK2(size), planes, flags);
if (ibuf == NULL) {
PyErr_Format(PyExc_ValueError, "new: Unable to create image (%d, %d)", UNPACK2(size));
return NULL;
}
return Py_ImBuf_CreatePyObject(ibuf);
ImBuf *ibuf = IMB_allocImBuf(UNPACK2(size), planes, flags);
if (ibuf == NULL) {
PyErr_Format(PyExc_ValueError, "new: Unable to create image (%d, %d)", UNPACK2(size));
return NULL;
}
return Py_ImBuf_CreatePyObject(ibuf);
}
PyDoc_STRVAR(M_imbuf_load_doc,
".. function:: load(filename)\n"
"\n"
" Load an image from a file.\n"
"\n"
" :arg filename: the filename of the image.\n"
" :type filename: string\n"
" :return: the newly loaded image.\n"
" :rtype: :class:`ImBuf`\n"
);
".. function:: load(filename)\n"
"\n"
" Load an image from a file.\n"
"\n"
" :arg filename: the filename of the image.\n"
" :type filename: string\n"
" :return: the newly loaded image.\n"
" :rtype: :class:`ImBuf`\n");
static PyObject *M_imbuf_load(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
const char *filename;
const char *filename;
static const char *_keywords[] = {"filename", NULL};
static _PyArg_Parser _parser = {"s:load", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kw, &_parser,
&filename))
{
return NULL;
}
static const char *_keywords[] = {"filename", NULL};
static _PyArg_Parser _parser = {"s:load", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &filename)) {
return NULL;
}
const int file = BLI_open(filename, O_BINARY | O_RDONLY, 0);
if (file == -1) {
PyErr_Format(PyExc_IOError, "load: %s, failed to open file '%s'", strerror(errno));
return NULL;
}
const int file = BLI_open(filename, O_BINARY | O_RDONLY, 0);
if (file == -1) {
PyErr_Format(PyExc_IOError, "load: %s, failed to open file '%s'", strerror(errno));
return NULL;
}
ImBuf *ibuf = IMB_loadifffile(file, filename, IB_rect, NULL, filename);
ImBuf *ibuf = IMB_loadifffile(file, filename, IB_rect, NULL, filename);
close(file);
close(file);
if (ibuf == NULL) {
PyErr_Format(PyExc_ValueError, "load: Unable to recognize image format for file '%s'", filename);
return NULL;
}
if (ibuf == NULL) {
PyErr_Format(
PyExc_ValueError, "load: Unable to recognize image format for file '%s'", filename);
return NULL;
}
BLI_strncpy(ibuf->name, filename, sizeof(ibuf->name));
BLI_strncpy(ibuf->name, filename, sizeof(ibuf->name));
return Py_ImBuf_CreatePyObject(ibuf);
return Py_ImBuf_CreatePyObject(ibuf);
}
PyDoc_STRVAR(M_imbuf_write_doc,
".. function:: write(image, filename)\n"
"\n"
" Write an image.\n"
"\n"
" :arg image: the image to write.\n"
" :type image: :class:`ImBuf`\n"
" :arg filename: the filename of the image.\n"
" :type filename: string\n"
);
".. function:: write(image, filename)\n"
"\n"
" Write an image.\n"
"\n"
" :arg image: the image to write.\n"
" :type image: :class:`ImBuf`\n"
" :arg filename: the filename of the image.\n"
" :type filename: string\n");
static PyObject *M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
{
Py_ImBuf *py_imb;
const char *filename = NULL;
Py_ImBuf *py_imb;
const char *filename = NULL;
static const char *_keywords[] = {"image", "filename", NULL};
static _PyArg_Parser _parser = {"O!|s:write", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kw, &_parser,
&Py_ImBuf_Type, &py_imb,
&filename))
{
return NULL;
}
static const char *_keywords[] = {"image", "filename", NULL};
static _PyArg_Parser _parser = {"O!|s:write", _keywords, 0};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &Py_ImBuf_Type, &py_imb, &filename)) {
return NULL;
}
if (filename == NULL) {
filename = py_imb->ibuf->name;
}
if (filename == NULL) {
filename = py_imb->ibuf->name;
}
bool ok = IMB_saveiff(py_imb->ibuf, filename, IB_rect);
if (ok == false) {
PyErr_Format(PyExc_IOError, "write: Unable to write image file (%s) '%s'", strerror(errno), filename);
return NULL;
}
bool ok = IMB_saveiff(py_imb->ibuf, filename, IB_rect);
if (ok == false) {
PyErr_Format(
PyExc_IOError, "write: Unable to write image file (%s) '%s'", strerror(errno), filename);
return NULL;
}
Py_RETURN_NONE;
Py_RETURN_NONE;
}
/** \} */
@@ -432,36 +419,34 @@ static PyObject *M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject
* \{ */
static PyMethodDef IMB_methods[] = {
{"new", (PyCFunction) M_imbuf_new, METH_VARARGS | METH_KEYWORDS, M_imbuf_new_doc},
{"load", (PyCFunction) M_imbuf_load, METH_VARARGS | METH_KEYWORDS, M_imbuf_load_doc},
{"write", (PyCFunction) M_imbuf_write, METH_VARARGS | METH_KEYWORDS, M_imbuf_write_doc},
{NULL, NULL, 0, NULL},
{"new", (PyCFunction)M_imbuf_new, METH_VARARGS | METH_KEYWORDS, M_imbuf_new_doc},
{"load", (PyCFunction)M_imbuf_load, METH_VARARGS | METH_KEYWORDS, M_imbuf_load_doc},
{"write", (PyCFunction)M_imbuf_write, METH_VARARGS | METH_KEYWORDS, M_imbuf_write_doc},
{NULL, NULL, 0, NULL},
};
PyDoc_STRVAR(IMB_doc,
"This module provides access to Blender's image manipulation API."
);
PyDoc_STRVAR(IMB_doc, "This module provides access to Blender's image manipulation API.");
static struct PyModuleDef IMB_module_def = {
PyModuleDef_HEAD_INIT,
"imbuf", /* m_name */
IMB_doc, /* m_doc */
0, /* m_size */
IMB_methods, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
PyModuleDef_HEAD_INIT,
"imbuf", /* m_name */
IMB_doc, /* m_doc */
0, /* m_size */
IMB_methods, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
PyObject *BPyInit_imbuf(void)
{
PyObject *submodule;
PyObject *submodule;
submodule = PyModule_Create(&IMB_module_def);
submodule = PyModule_Create(&IMB_module_def);
PyType_Ready(&Py_ImBuf_Type);
PyType_Ready(&Py_ImBuf_Type);
return submodule;
return submodule;
}
/** \} */

View File

@@ -25,4 +25,4 @@ PyObject *BPyInit_imbuf(void);
extern PyTypeObject Py_ImBuf_Type;
#endif /* __IMBUF_PY_API_H__ */
#endif /* __IMBUF_PY_API_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -24,10 +24,10 @@
#include "BLI_sys_types.h"
#include "BLI_utildefines_variadic.h"
void PyC_ObSpit(const char *name, PyObject *var);
void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var);
void PyC_LineSpit(void);
void PyC_StackSpit(void);
void PyC_ObSpit(const char *name, PyObject *var);
void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var);
void PyC_LineSpit(void);
void PyC_StackSpit(void);
PyObject *PyC_ExceptionBuffer(void);
PyObject *PyC_ExceptionBuffer_Simple(void);
PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...);
@@ -36,40 +36,46 @@ PyObject *PyC_FrozenSetFromStrings(const char **strings);
PyObject *PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *format, ...);
PyObject *PyC_Err_SetString_Prefix(PyObject *exception_type_prefix, const char *str);
void PyC_Err_PrintWithFunc(PyObject *py_func);
void PyC_Err_PrintWithFunc(PyObject *py_func);
void PyC_FileAndNum(const char **filename, int *lineno);
void PyC_FileAndNum_Safe(const char **filename, int *lineno); /* checks python is running */
int PyC_AsArray_FAST(
void *array, PyObject *value_fast, const Py_ssize_t length,
const PyTypeObject *type, const bool is_double, const char *error_prefix);
int PyC_AsArray(
void *array, PyObject *value, const Py_ssize_t length,
const PyTypeObject *type, const bool is_double, const char *error_prefix);
void PyC_FileAndNum(const char **filename, int *lineno);
void PyC_FileAndNum_Safe(const char **filename, int *lineno); /* checks python is running */
int PyC_AsArray_FAST(void *array,
PyObject *value_fast,
const Py_ssize_t length,
const PyTypeObject *type,
const bool is_double,
const char *error_prefix);
int PyC_AsArray(void *array,
PyObject *value,
const Py_ssize_t length,
const PyTypeObject *type,
const bool is_double,
const char *error_prefix);
PyObject *PyC_Tuple_PackArray_F32(const float *array, uint len);
PyObject *PyC_Tuple_PackArray_F64(const double *array, uint len);
PyObject *PyC_Tuple_PackArray_I32(const int *array, uint len);
PyObject *PyC_Tuple_PackArray_I32FromBool(const int *array, uint len);
PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len);
PyObject *PyC_Tuple_PackArray_F32(const float *array, uint len);
PyObject *PyC_Tuple_PackArray_F64(const double *array, uint len);
PyObject *PyC_Tuple_PackArray_I32(const int *array, uint len);
PyObject *PyC_Tuple_PackArray_I32FromBool(const int *array, uint len);
PyObject *PyC_Tuple_PackArray_Bool(const bool *array, uint len);
#define PyC_Tuple_Pack_F32(...) \
PyC_Tuple_PackArray_F32(((const float []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
PyC_Tuple_PackArray_F32(((const float[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
#define PyC_Tuple_Pack_F64(...) \
PyC_Tuple_PackArray_F64(((const double []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
PyC_Tuple_PackArray_F64(((const double[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
#define PyC_Tuple_Pack_I32(...) \
PyC_Tuple_PackArray_I32(((const int []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
PyC_Tuple_PackArray_I32(((const int[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
#define PyC_Tuple_Pack_I32FromBool(...) \
PyC_Tuple_PackArray_I32FromBool(((const int []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
PyC_Tuple_PackArray_I32FromBool(((const int[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
#define PyC_Tuple_Pack_Bool(...) \
PyC_Tuple_PackArray_Bool(((const bool []){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
PyC_Tuple_PackArray_Bool(((const bool[]){__VA_ARGS__}), VA_NARGS_COUNT(__VA_ARGS__))
void PyC_Tuple_Fill(PyObject *tuple, PyObject *value);
void PyC_List_Fill(PyObject *list, PyObject *value);
void PyC_Tuple_Fill(PyObject *tuple, PyObject *value);
void PyC_List_Fill(PyObject *list, PyObject *value);
/* follow http://www.python.org/dev/peps/pep-0383/ */
PyObject *PyC_UnicodeFromByte(const char *str);
PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size);
PyObject *PyC_UnicodeFromByte(const char *str);
PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size);
const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce);
@@ -89,34 +95,49 @@ void *PyC_RNA_AsPointer(PyObject *value, const char *type_name);
/* flag / set --- interchange */
typedef struct PyC_FlagSet {
int value;
const char *identifier;
int value;
const char *identifier;
} PyC_FlagSet;
char *PyC_FlagSet_AsString(PyC_FlagSet *item);
int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *r_value);
int PyC_FlagSet_ValueFromID(PyC_FlagSet *item, const char *identifier, int *r_value, const char *error_prefix);
int PyC_FlagSet_ToBitfield(PyC_FlagSet *items, PyObject *value, int *r_value, const char *error_prefix);
char *PyC_FlagSet_AsString(PyC_FlagSet *item);
int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *r_value);
int PyC_FlagSet_ValueFromID(PyC_FlagSet *item,
const char *identifier,
int *r_value,
const char *error_prefix);
int PyC_FlagSet_ToBitfield(PyC_FlagSet *items,
PyObject *value,
int *r_value,
const char *error_prefix);
PyObject *PyC_FlagSet_FromBitfield(PyC_FlagSet *items, int flag);
bool PyC_RunString_AsNumber(const char **imports, const char *expr, const char *filename, double *r_value);
bool PyC_RunString_AsIntPtr(const char **imports, const char *expr, const char *filename, intptr_t *r_value);
bool PyC_RunString_AsString(const char **imports, const char *expr, const char *filename, char **r_value);
bool PyC_RunString_AsNumber(const char **imports,
const char *expr,
const char *filename,
double *r_value);
bool PyC_RunString_AsIntPtr(const char **imports,
const char *expr,
const char *filename,
intptr_t *r_value);
bool PyC_RunString_AsString(const char **imports,
const char *expr,
const char *filename,
char **r_value);
int PyC_ParseBool(PyObject *o, void *p);
int PyC_CheckArgs_DeepCopy(PyObject *args);
/* Integer parsing (with overflow checks), -1 on error. */
int PyC_Long_AsBool(PyObject *value);
int8_t PyC_Long_AsI8(PyObject *value);
int PyC_Long_AsBool(PyObject *value);
int8_t PyC_Long_AsI8(PyObject *value);
int16_t PyC_Long_AsI16(PyObject *value);
#if 0 /* inline */
int32_t PyC_Long_AsI32(PyObject *value);
int64_t PyC_Long_AsI64(PyObject *value);
#endif
uint8_t PyC_Long_AsU8(PyObject *value);
uint8_t PyC_Long_AsU8(PyObject *value);
uint16_t PyC_Long_AsU16(PyObject *value);
uint32_t PyC_Long_AsU32(PyObject *value);
#if 0 /* inline */
@@ -124,9 +145,18 @@ uint64_t PyC_Long_AsU64(PyObject *value);
#endif
/* inline so type signatures match as expected */
Py_LOCAL_INLINE(int32_t) PyC_Long_AsI32(PyObject *value) { return (int32_t)_PyLong_AsInt(value); }
Py_LOCAL_INLINE(int64_t) PyC_Long_AsI64(PyObject *value) { return (int64_t)PyLong_AsLongLong(value); }
Py_LOCAL_INLINE(uint64_t) PyC_Long_AsU64(PyObject *value) { return (uint64_t)PyLong_AsUnsignedLongLong(value); }
Py_LOCAL_INLINE(int32_t) PyC_Long_AsI32(PyObject *value)
{
return (int32_t)_PyLong_AsInt(value);
}
Py_LOCAL_INLINE(int64_t) PyC_Long_AsI64(PyObject *value)
{
return (int64_t)PyLong_AsLongLong(value);
}
Py_LOCAL_INLINE(uint64_t) PyC_Long_AsU64(PyObject *value)
{
return (uint64_t)PyLong_AsUnsignedLongLong(value);
}
/* utils for format string in `struct` module style syntax */
char PyC_StructFmt_type_from_str(const char *typestr);
@@ -135,4 +165,4 @@ bool PyC_StructFmt_type_is_int_any(char format);
bool PyC_StructFmt_type_is_byte(char format);
bool PyC_StructFmt_type_is_bool(char format);
#endif /* __PY_CAPI_UTILS_H__ */
#endif /* __PY_CAPI_UTILS_H__ */

View File

@@ -28,28 +28,33 @@ extern "C" {
#endif
#define PyTuple_SET_ITEMS(op_arg, ...) \
{ \
PyTupleObject *op = (PyTupleObject *)op_arg; \
PyObject **ob_items = op->ob_item; \
CHECK_TYPE_ANY(op_arg, PyObject *, PyTupleObject *); \
BLI_assert(VA_NARGS_COUNT(__VA_ARGS__) == PyTuple_GET_SIZE(op)); \
ARRAY_SET_ITEMS(ob_items, __VA_ARGS__); \
} (void)0
{ \
PyTupleObject *op = (PyTupleObject *)op_arg; \
PyObject **ob_items = op->ob_item; \
CHECK_TYPE_ANY(op_arg, PyObject *, PyTupleObject *); \
BLI_assert(VA_NARGS_COUNT(__VA_ARGS__) == PyTuple_GET_SIZE(op)); \
ARRAY_SET_ITEMS(ob_items, __VA_ARGS__); \
} \
(void)0
/* wrap Py_INCREF & return the result,
* use sparingly to avoid comma operator or temp var assignment */
Py_LOCAL_INLINE(PyObject *)Py_INCREF_RET(PyObject *op) { Py_INCREF(op); return op; }
Py_LOCAL_INLINE(PyObject *) Py_INCREF_RET(PyObject *op)
{
Py_INCREF(op);
return op;
}
/* append & transfer ownership to the list, avoids inline Py_DECREF all over (which is quite a large macro) */
Py_LOCAL_INLINE(int) PyList_APPEND(PyObject *op, PyObject *v)
{
int ret = PyList_Append(op, v);
Py_DecRef(v);
return ret;
int ret = PyList_Append(op, v);
Py_DecRef(v);
return ret;
}
#ifdef __cplusplus
}
#endif
#endif /* __PYTHON_UTILDEFINES_H__ */
#endif /* __PYTHON_UTILDEFINES_H__ */