Anonymous avatar Anonymous committed f53b1e6

math.Vector operations require vector arguments and operators to havethe same dimensions now.
base.Surface adds abstract get_at() and set_at() methods formanipulating pixels at certain positions.
Fixed a memory leak in PyFreeTypeFont_New().

Comments (0)

Files changed (15)

 * add pgcompat.h to *mod.h internal headers.
 * >8 bpp surfaces with palettes - it is supported (although it might be
   pointless) by SDL and so should we.
-* add OpenMP support where useful (looped operations, etc.)
+* math module changes in rev. 2777
 
 * freetype: render to buffer buffer support (like new bytearray, but
   write to a buffer instead)
    has)?
 
 * openal: check integrity and references for sources, buffers and listeners.
-* openal: check for locking issues on closing a CaptureDevice.
 
 Things to ADD:
 ==============
 * add movie module
 * subsurfaces via surface[x:y,a:b]? Brought up by ctgPi via IRC
 * Add prebuilt package for Win32 VC++ builds.
+* add OpenMP support where useful (looped operations, etc.)
 
 Things to FIX:
 ==============
 * :ref:`search`
 
 Last generated on: |today|
-
       <call>copy () -> Surface</call>
       <desc>Creates a copy of this Surface.</desc>
     </method>
+    <method name="get_at">
+      <call>get_at (x, y) -> Color
+      get_at (point) -> Color
+      </call>
+      <desc>
+        Gets the Surface pixel value at the specified point.
+      </desc>
+    </method>
     <attr name="height">
       <desc>Gets the height of the Surface.</desc>
     </attr>
     <attr name="pixels">
       <desc>Gets a buffer with the pixels of the Surface.</desc>
     </attr>
+    <method name="set_at">
+      <call>set_at (x, y, color) -> None
+      set_at (point, color) -> None
+      </call>
+      <desc>
+        Sets the Surface pixel value at the specified point.
+      </desc>
+    </method>
     <attr name="size">
       <desc>Gets the width and height of the Surface.</desc>
     </attr>

doc/src/examples.rst

 :mod:`pygame2.examples` -- examples for Pygame2
 ===============================================
 
-Examples package for Pygame2.
+.. module:: pygame2.examples
+   :synopsis: Examples package for Pygame2.
 
 This package contains code snippets demonstrating the aspects of the
 various Pygame2 modules. Each example is a module of its own and can be

doc/src/openalbase.xml

   <desc>
     Basic Pygame2 OpenAL wrapper module.
 
-
-
-
     Identifiers for the property get and set methods:
     
     +------+------------------------------------------------------------+
       for playback, recording and manipulation.
       
       The Buffers object provides methods and properties to manipulate
-      certain aspects of the buffered data.
+      certain aspects of the buffered data and can be queued to multiple
+      sources within the same context.
 
       Buffers instances cannot be created directly, but are bound to a
       :class:`Device`. To create a Buffers instance for the currently
     <method name="buffer_data">
       <call>buffer_data (bufnum, format, data, samplerate)</call>
       <desc>
-        Buffers a chunk of *data* into one of the created buffers. 
+        Buffers a chunk of *data* into one of the created buffers.
+
+        
       </desc>
       <example></example>
     </method>
     <attr name="buffers">
-      <desc>The buffer identifiers used inb the Buffers instance.</desc>
+      <desc>The buffer identifiers used in the Buffers instance.</desc>
       <example></example>
     </attr>
     <attr name="count">

doc/tutorial/index.rst

 framework. It features efficient high- and low-level structures and an
 excellent object-oriented programming layout.
 
+The following tutorial will guide you through your first applications
+written with Pygame2 and introduces certain parts of the Pygame2
+packages to you. It will most likely *not* cover each single part of
+Pygame2, but instead show you the most noteworthy features.
+
 .. toctree::
+  :maxdepth: 2
 
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
+Last generated on: |today|
+

src/base/pgbase.h

     PyObject* (*get_size)(PyObject *self, void *closure);
     PyObject* (*get_pixels)(PyObject *self, void *closure);
     PyObject* (*blit)(PyObject *self, PyObject *args, PyObject *kwds); 
+    PyObject* (*set_at)(PyObject *self, PyObject *args); 
+    PyObject* (*get_at)(PyObject *self, PyObject *args); 
     PyObject* (*copy)(PyObject *self); 
 } PySurface;
 #define PYGAME_SURFACE_FIRSTSLOT                                        \
     PyObject* (*get_name)(PyObject *self, void *closure);
     PyObject* (*get_style)(PyObject *self, void *closure);
     int       (*set_style)(PyObject *self, PyObject *attr, void *closure);
-    
-
     PyObject* (*get_size)(PyObject *self, PyObject *args, PyObject *kwds);
     PyObject* (*render)(PyObject *self, PyObject *args, PyObject *kwds);
     PyObject* (*copy)(PyObject *self);

src/base/surface.c

 static PyObject* _surface_getsize (PyObject *self, void *closure);
 static PyObject* _surface_getpixels (PyObject *self, void *closure);
 
+static PyObject* _surface_setat (PyObject* self, PyObject *args);
+static PyObject* _surface_getat (PyObject* self, PyObject *args);
 static PyObject* _surface_blit (PyObject* self, PyObject *args, PyObject *kwds);
 static PyObject* _surface_copy (PyObject* self);
 
 static PyObject* _def_get_height (PyObject *self, void *closure);
 static PyObject* _def_get_size (PyObject *self, void *closure);
 static PyObject* _def_get_pixels (PyObject *self, void *closure);
+static PyObject* _def_set_at (PyObject* self, PyObject *args);
+static PyObject* _def_get_at (PyObject* self, PyObject *args);
 static PyObject* _def_blit (PyObject *self, PyObject *args, PyObject *kwds); 
 static PyObject* _def_copy (PyObject *self); 
 
     { "blit", (PyCFunction) _surface_blit, METH_VARARGS | METH_KEYWORDS,
       DOC_BASE_SURFACE_BLIT },
     { "copy", (PyCFunction) _surface_copy, METH_NOARGS, DOC_BASE_SURFACE_COPY },
+    { "get_at", _surface_getat, METH_VARARGS, DOC_BASE_SURFACE_GET_AT },
+    { "set_at", _surface_setat, METH_VARARGS, DOC_BASE_SURFACE_SET_AT },
     { NULL, NULL, 0, NULL }
 };
 
     sf->get_size = _def_get_size;
     sf->blit = _def_blit;
     sf->copy = _def_copy;
+    sf->set_at = _def_set_at;
+    sf->get_at = _def_get_at;
 
     return (PyObject*) sf;
 }
 }
 
 static PyObject*
+_surface_setat (PyObject* self, PyObject *args)
+{
+    if (((PySurface*)self)->set_at && ((PySurface*)self)->set_at != _def_set_at)
+        return ((PySurface*)self)->set_at (self, args);
+    PyErr_SetString (PyExc_NotImplementedError,
+        "set_at method not implemented");
+    return NULL;
+}
+
+static PyObject*
+_surface_getat (PyObject* self, PyObject *args)
+{
+    if (((PySurface*)self)->get_at && ((PySurface*)self)->get_at != _def_get_at)
+        return ((PySurface*)self)->get_at (self, args);
+    PyErr_SetString (PyExc_NotImplementedError,
+        "get_at method not implemented");
+    return NULL;
+}
+
+
+static PyObject*
 _def_get_width (PyObject *self, void *closure)
 {
     return PyObject_GetAttrString (self, "width");
     return PyObject_CallMethod (self, "copy", NULL, NULL);
 }
 
+static PyObject*
+_def_set_at (PyObject* self, PyObject *args)
+{
+    PyObject *retval, *method;
+    
+    method = PyObject_GetAttrString (self, "set_at");
+    if (!method)
+        return NULL;
+    retval = PyObject_Call (method, args, NULL);
+    Py_DECREF (method);
+    return retval;
+}
+
+static PyObject*
+_def_get_at (PyObject* self, PyObject *args)
+{
+    PyObject *retval, *method;
+    
+    method = PyObject_GetAttrString (self, "get_at");
+    if (!method)
+        return NULL;
+    retval = PyObject_Call (method, args, NULL);
+    Py_DECREF (method);
+    return retval;
+}
+
 /* C API */
 PyObject*
 PySurface_New (void)

src/freetype/ft_font.c

 #include "ft_mod.h"
 #include "freetypebase_doc.h"
 
-
-/*
- * Auxiliar defines
- */
-#define PGFT_CHECK_BOOL(_pyobj, _var)               \
-    if (_pyobj)                                     \
-    {                                               \
-        if (!PyBool_Check(_pyobj))                  \
-        {                                           \
-            PyErr_SetString(PyExc_TypeError,        \
-                #_var " must be a boolean value");  \
-            return NULL;                            \
-        }                                           \
-                                                    \
-        _var = PyObject_IsTrue(_pyobj);             \
-    }
-
 /*
  * Constructor/init/destructor
  */
 static PyObject* _ftfont_getmetrics(PyObject *self, PyObject* args, PyObject *kwds);
 static PyObject* _ftfont_render(PyObject *self, PyObject* args, PyObject *kwds);
 static PyObject* _ftfont_render_raw(PyObject *self, PyObject* args, PyObject *kwds);
-
-/* static PyObject* _ftfont_copy(PyObject *self); */
+/*static PyObject* _ftfont_copy (PyObject *self);*/
 
 /*
  * Getters/setters
  */
 static PyMethodDef _ftfont_methods[] = 
 {
-    {
-        "get_size", 
-        (PyCFunction) _ftfont_getsize,
-        METH_VARARGS | METH_KEYWORDS,
-        DOC_BASE_FONT_GET_SIZE 
-    },
-    {
-        "get_metrics", 
-        (PyCFunction) _ftfont_getmetrics,
-        METH_VARARGS | METH_KEYWORDS,
-        DOC_BASE_FONT_GET_METRICS 
-    },
-    { 
-        "render", 
-        (PyCFunction)_ftfont_render, 
-        METH_VARARGS | METH_KEYWORDS,
-        DOC_BASE_FONT_RENDER 
-    },
-    { 
-        "render_raw", 
-        (PyCFunction)_ftfont_render_raw, 
-        METH_VARARGS | METH_KEYWORDS,
-        DOC_BASE_FONT_RENDER_RAW
-    },
+    { "get_size", (PyCFunction) _ftfont_getsize, METH_VARARGS | METH_KEYWORDS,
+      DOC_BASE_FONT_GET_SIZE },
+    { "get_metrics", (PyCFunction) _ftfont_getmetrics,
+      METH_VARARGS | METH_KEYWORDS, DOC_BASE_FONT_GET_METRICS },
+    { "render",  (PyCFunction)_ftfont_render, METH_VARARGS | METH_KEYWORDS,
+      DOC_BASE_FONT_RENDER },
+    { "render_raw", (PyCFunction)_ftfont_render_raw,
+      METH_VARARGS | METH_KEYWORDS, DOC_BASE_FONT_RENDER_RAW },
     { NULL, NULL, 0, NULL }
 };
 
  */
 static PyGetSetDef _ftfont_getsets[] = 
 {
-    { 
-        "style",    
-        _ftfont_getstyle,   
-        _ftfont_setstyle, 
-        DOC_BASE_FONT_STYLE,    
-        NULL 
-    },
-    { 
-        "height",
-        _ftfont_getheight,  
-        NULL,
-        DOC_BASE_FONT_HEIGHT,   
-        NULL
-    },
-    { 
-        "name", 
-        _ftfont_getname, 
-        NULL,
-        DOC_BASE_FONT_NAME, 
-        NULL 
-    },
-    {
-        "fixed_width",
-        _ftfont_getfixedwidth,
-        NULL,
-        DOC_BASE_FONT_FIXED_WIDTH,
-        NULL
-    },
-    {
-        "antialiased",
-        _ftfont_getantialias,
-        _ftfont_setantialias,
-        DOC_BASE_FONT_ANTIALIASED,
-        NULL
-    },
-    {
-        "vertical",
-        _ftfont_getvertical,
-        _ftfont_setvertical,
-        DOC_BASE_FONT_VERTICAL,
-        NULL
-    },
-    {
-        "italic",
-        _ftfont_getstyle_flag,
-        _ftfont_setstyle_flag,
-        DOC_BASE_FONT_ITALIC, 
-        (void *)FT_STYLE_ITALIC
-    },
-    {
-        "bold",
-        _ftfont_getstyle_flag,
-        _ftfont_setstyle_flag,
-        DOC_BASE_FONT_BOLD, 
-        (void *)FT_STYLE_BOLD
-    },
-    {
-        "underline",
-        _ftfont_getstyle_flag,
-        _ftfont_setstyle_flag,
-        DOC_BASE_FONT_UNDERLINE, 
-        (void *)FT_STYLE_UNDERLINE
-    },
+    { "style",  _ftfont_getstyle, _ftfont_setstyle,  DOC_BASE_FONT_STYLE,
+      NULL },
+    { "height", _ftfont_getheight, NULL, DOC_BASE_FONT_HEIGHT, NULL },
+    { "name", _ftfont_getname, NULL, DOC_BASE_FONT_NAME, NULL },
+    { "fixed_width", _ftfont_getfixedwidth, NULL, DOC_BASE_FONT_FIXED_WIDTH,
+      NULL },
+    { "antialiased", _ftfont_getantialias, _ftfont_setantialias,
+      DOC_BASE_FONT_ANTIALIASED, NULL },
+    { "vertical", _ftfont_getvertical, _ftfont_setvertical,
+      DOC_BASE_FONT_VERTICAL, NULL },
+    { "italic", _ftfont_getstyle_flag, _ftfont_setstyle_flag,
+      DOC_BASE_FONT_ITALIC, (void *)FT_STYLE_ITALIC },
+    { "bold", _ftfont_getstyle_flag, _ftfont_setstyle_flag,
+      DOC_BASE_FONT_BOLD, (void *)FT_STYLE_BOLD },
+    { "underline", _ftfont_getstyle_flag, _ftfont_setstyle_flag,
+      DOC_BASE_FONT_UNDERLINE,  (void *)FT_STYLE_UNDERLINE },
     { NULL, NULL, NULL, NULL, NULL }
 };
 
     font->pyfont.set_style = _ftfont_setstyle;
     font->pyfont.get_size = _ftfont_getsize;
     font->pyfont.render = _ftfont_render;
+    /*font->pyfont.copy = _ftfont_copy;*/
     /* TODO: font->pyfont.copy  */
 
     return (PyObject*)font;
 PyFreeTypeFont_New(const char *filename, int face_index)
 {
     PyFreeTypeFont *font;
-
+    
     FreeTypeInstance *ft;
     ASSERT_GRAB_FREETYPE(ft, NULL);
-
+    
     if (!filename)
+    {
+        PyErr_SetString (PyExc_ValueError, "filename must not be NULL");
         return NULL;
+    }
 
     font = (PyFreeTypeFont *)PyFreeTypeFont_Type.tp_new(
             &PyFreeTypeFont_Type, NULL, NULL);
     if (PGFT_TryLoadFont_Filename(ft, font, filename, face_index) != 0)
     {
         PyErr_SetString(PyExc_PyGameError, PGFT_GetError(ft));
+        Py_XDECREF (font);
         return NULL;
     }
 
     return (PyObject*) font;
 }
-
+    
 void
 ftfont_export_capi(void **capi)
 {

src/freetype/ft_wrap.c

 }
 
 int
-PGFT_TryLoadFont_Filename(FreeTypeInstance *ft, 
-    PyFreeTypeFont *font, 
-    const char *filename, 
-    int face_index)
+PGFT_TryLoadFont_Filename (FreeTypeInstance *ft,  PyFreeTypeFont *font, 
+    const char *filename,  int face_index)
 {
     char *filename_alloc;
     size_t file_len;

src/math/vector.c

     (unaryfunc)0,                     /* nb_hex;       __hex__ */
 #endif
     (binaryfunc) _vector_inplace_add, /* nb_inplace_add;       __iadd__ */
-    (binaryfunc) _vector_inplace_sub, /* nb_inplace_subtract;  __isub__ */
+   (binaryfunc) _vector_inplace_sub, /* nb_inplace_subtract;  __isub__ */
     (binaryfunc) _vector_inplace_mul, /* nb_inplace_multiply;  __imul__ */
 #ifndef IS_PYTHON_3
     (binaryfunc) _vector_inplace_div, /* nb_inplace_divide;    __idiv__ */
     ncoords = VectorCoordsFromObj (n, &ndim);
     if (!ncoords)
         return NULL;
-    if (ndim < dim)
+    if (ndim != dim)
     {
         PyErr_SetString (PyExc_ValueError,
             "normal must have same dimension as vector");
     othercoords = VectorCoordsFromObj (args, &otherdim);
     if (!othercoords)
         return NULL;
-    if (otherdim < self->dim)
+    if (otherdim != self->dim)
     {
         PyErr_SetString (PyExc_ValueError,
-            "must have same at least the same dimension as vector");
+            "must have same the same dimension as vector");
         PyMem_Free (othercoords);
         return NULL;
     }
     othercoords = VectorCoordsFromObj (args, &otherdim);
     if (!othercoords)
         return NULL;
-    if (otherdim < self->dim)
+    if (otherdim != self->dim)
     {
         PyErr_SetString (PyExc_ValueError,
-            "must have same at least the same dimension as vector");
+            "must have same the same dimension as vector");
         PyMem_Free (othercoords);
         return NULL;
     }
     if (coords)
     {
         op |= OP_ARG_VECTOR;
-        /* right-hand vector must have less dimensions than left-hand. */
-        if (otherdim > dim)
+        /* right-hand vector must have the same dimensions than left-hand. */
+        if (otherdim != dim)
         {
             PyErr_SetString (PyExc_TypeError,
-                "right op must not have more dimensions than left op");
+                "right op must have the same dimensions as left op");
             PyMem_Free (coords);
             return NULL;
         }

src/math/vector2.c

     othercoords = VectorCoordsFromObj (args, &otherdim);
     if (!othercoords)
         return NULL;
+    if (otherdim != v->dim)
+    {
+        PyErr_SetString (PyExc_TypeError,
+            "vectors must have the same dimensions");
+        PyMem_Free (othercoords);
+        return NULL;
+    }
+
     retval = v->coords[0] * othercoords[1] - v->coords[1] * othercoords[0];
     PyMem_Free (othercoords);
     return PyFloat_FromDouble (retval);
     othercoords = VectorCoordsFromObj (args, &otherdim);
     if (!othercoords)
         return NULL;
+    if (otherdim != v->dim)
+    {
+        PyErr_SetString (PyExc_TypeError,
+            "vectors must have the same dimensions");
+        PyMem_Free (othercoords);
+        return NULL;
+    }
     angle = atan2 (othercoords[1], othercoords[0]) -
         atan2 (v->coords[1], v->coords[0]);
     PyMem_Free (othercoords);

src/math/vector3.c

     axiscoords = VectorCoordsFromObj (axis, &axisdim);
     if (!axiscoords)
         return NULL;
-    if (axisdim < v->dim)
+    if (axisdim != v->dim)
     {
         PyErr_SetString (PyExc_ValueError,
-            "axis must have at least three dimensions");
+            "axis must have the same dimensions as the vector");
         PyMem_Free (axiscoords);
         return NULL;
     }
     axiscoords = VectorCoordsFromObj (axis, &axisdim);
     if (!axiscoords)
         return NULL;
-    if (axisdim < v->dim)
+    if (axisdim != v->dim)
     {
         PyErr_SetString (PyExc_ValueError,
-            "axis must have at least three dimensions");
+            "axis must have the same dimensions as the vector");
         PyMem_Free (axiscoords);
         return NULL;
     }
     othercoords = VectorCoordsFromObj (args, &otherdim);
     if (!othercoords)
         return NULL;
-    if (otherdim < v->dim)
+    if (otherdim != v->dim)
     {
         PyErr_SetString (PyExc_ValueError,
-            "other must have at least three dimensions");
+            "other must have the same dimensions as the vector");
         PyMem_Free (othercoords);
         return NULL;
     }
     othercoords = VectorCoordsFromObj (args, &otherdim);
     if (!othercoords)
         return NULL;
-    if (otherdim < v->dim)
+    if (otherdim != v->dim)
     {
         PyErr_SetString (PyExc_ValueError,
-            "other must have at least three dimensions");
+            "other must have the same dimensions as the vector");
         PyMem_Free (othercoords);
         return NULL;
     }

src/openal/constantsmod.c

     
     DEC_CONST(AL_BYTE_RW_OFFSETS_EXT);
     DEC_CONST(AL_SAMPLE_RW_OFFSETS_EXT);
-    DEC_CONST(AL_SEC_RW_OFFSETS_EXT);
-    
     DEC_CONST(AL_SAMPLE_SOURCE_EXT);
     DEC_CONST(AL_SAMPLE_SINK_EXT);
     DEC_CONST(AL_READ_ONLY_EXT);

src/sdl/surface.c

     surface->pysurface.get_pixels = _surface_getpixels;
     surface->pysurface.blit = _surface_blit;
     surface->pysurface.copy = _surface_copy;
+    surface->pysurface.get_at = _surface_getat;
+    surface->pysurface.set_at = _surface_setat;
 
     return (PyObject*) surface;
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.