illume avatar illume committed 2ad2aa1

Added Surface.set_masks and .set_shifts useful for using data in
b,g,r,a mode... and other fun hacks.

Comments (0)

Files changed (6)

docs/ref/index.html

 <li><a href="surface.html#Surface.set_at">Surface.set_at</a> - <font size=-1>set the color value for a single pixel</font></li>
 <li><a href="surface.html#Surface.set_clip">Surface.set_clip</a> - <font size=-1>set the current clipping area of the Surface</font></li>
 <li><a href="surface.html#Surface.set_colorkey">Surface.set_colorkey</a> - <font size=-1>Set the transparent colorkey</font></li>
+<li><a href="surface.html#Surface.set_masks">Surface.set_masks</a> - <font size=-1>set the bitmasks needed to convert between a color and a mapped integer</font></li>
 <li><a href="surface.html#Surface.set_palette">Surface.set_palette</a> - <font size=-1>set the color palette for an 8bit Surface</font></li>
 <li><a href="surface.html#Surface.set_palette_at">Surface.set_palette_at</a> - <font size=-1>set the color for a single index in an 8bit Surface palette</font></li>
+<li><a href="surface.html#Surface.set_shifts">Surface.set_shifts</a> - <font size=-1>sets the bit shifts needed to convert between a color and a mapped integer</font></li>
 <li><a href="surface.html#Surface.subsurface">Surface.subsurface</a> - <font size=-1>create a new surface that references its parent</font></li>
 <li><a href="surface.html#Surface.unlock">Surface.unlock</a> - <font size=-1>unlock the Surface memory from pixel access</font></li>
 <li><a href="surface.html#Surface.unmap_rgb">Surface.unmap_rgb</a> - <font size=-1>convert a mapped integer color value into a Color</font></li>

docs/ref/surface.html

   <tr><td><a href="surface.html#Surface.get_flags">Surface.get_flags</a> - <font size=-1>get the additional flags used for the Surface</font></td><td>get the additional flags used for the Surface</td></tr>
   <tr><td><a href="surface.html#Surface.get_pitch">Surface.get_pitch</a> - <font size=-1>get the number of bytes used per Surface row</font></td><td>get the number of bytes used per Surface row</td></tr>
   <tr><td><a href="surface.html#Surface.get_masks">Surface.get_masks</a> - <font size=-1>the bitmasks needed to convert between a color and a mapped integer</font></td><td>the bitmasks needed to convert between a color and a mapped integer</td></tr>
+  <tr><td><a href="surface.html#Surface.set_masks">Surface.set_masks</a> - <font size=-1>set the bitmasks needed to convert between a color and a mapped integer</font></td><td>set the bitmasks needed to convert between a color and a mapped integer</td></tr>
   <tr><td><a href="surface.html#Surface.get_shifts">Surface.get_shifts</a> - <font size=-1>the bit shifts needed to convert between a color and a mapped integer</font></td><td>the bit shifts needed to convert between a color and a mapped integer</td></tr>
+  <tr><td><a href="surface.html#Surface.set_shifts">Surface.set_shifts</a> - <font size=-1>sets the bit shifts needed to convert between a color and a mapped integer</font></td><td>sets the bit shifts needed to convert between a color and a mapped integer</td></tr>
   <tr><td><a href="surface.html#Surface.get_losses">Surface.get_losses</a> - <font size=-1>the significant bits used to convert between a color and a mapped integer</font></td><td>the significant bits used to convert between a color and a mapped integer</td></tr>
   <tr><td><a href="surface.html#Surface.get_bounding_rect">Surface.get_bounding_rect</a> - <font size=-1>find the smallest rect containing data</font></td><td>find the smallest rect containing data</td></tr>
   <tr><td><a href="surface.html#Surface.get_buffer">Surface.get_buffer</a> - <font size=-1>acquires a buffer object for the pixels of the Surface.</font></td><td>acquires a buffer object for the pixels of the Surface.</td></tr>
 <br></ul>
 
 
+<a name="Surface.set_masks">
+<big><b>Surface.set_masks</big></b><br><ul>
+  <i>set the bitmasks needed to convert between a color and a mapped integer</i><br>
+  <tt>Surface.set_masks((r,g,b,a)): return None</tt><br>
+<p>This is not needed for normal Pygame usage. New in pygame <tt>1.8.1</tt> </p>
+<!--COMMENTS:Surface.set_masks--> &nbsp;<br> 
+<br></ul>
+
+
 <a name="Surface.get_shifts">
 <big><b>Surface.get_shifts</big></b><br><ul>
   <i>the bit shifts needed to convert between a color and a mapped integer</i><br>
 <br></ul>
 
 
+<a name="Surface.set_shifts">
+<big><b>Surface.set_shifts</big></b><br><ul>
+  <i>sets the bit shifts needed to convert between a color and a mapped integer</i><br>
+  <tt>Surface.get_shifts((r,g,b,a)): return None</tt><br>
+<p>This is not needed for normal Pygame usage. New in pygame <tt>1.8.1</tt> </p>
+<!--COMMENTS:Surface.set_shifts--> &nbsp;<br> 
+<br></ul>
+
+
 <a name="Surface.get_losses">
 <big><b>Surface.get_losses</big></b><br><ul>
   <i>the significant bits used to convert between a color and a mapped integer</i><br>
 
 #define DOC_SURFACEGETMASKS "Surface.get_masks(): return (R, G, B, A)\nthe bitmasks needed to convert between a color and a mapped integer"
 
+#define DOC_SURFACESETMASKS "Surface.set_masks((r,g,b,a)): return None\nset the bitmasks needed to convert between a color and a mapped integer"
+
 #define DOC_SURFACEGETSHIFTS "Surface.get_shifts(): return (R, G, B, A)\nthe bit shifts needed to convert between a color and a mapped integer"
 
+#define DOC_SURFACESETSHIFTS "Surface.get_shifts((r,g,b,a)): return None\nsets the bit shifts needed to convert between a color and a mapped integer"
+
 #define DOC_SURFACEGETLOSSES "Surface.get_losses(): return (R, G, B, A)\nthe significant bits used to convert between a color and a mapped integer"
 
 #define DOC_SURFACEGETBOUNDINGRECT "Surface.get_bounding_rect(min_alpha = 1): return Rect\nfind the smallest rect containing data"
                                 PyObject *kwargs);
 static PyObject *surf_get_width (PyObject *self);
 static PyObject *surf_get_shifts (PyObject *self);
+static PyObject *surf_set_shifts (PyObject *self, PyObject *args);
 static PyObject *surf_get_size (PyObject *self);
 static PyObject *surf_get_losses (PyObject *self);
 static PyObject *surf_get_masks (PyObject *self);
+static PyObject *surf_set_masks (PyObject *self, PyObject *args);
 static PyObject *surf_get_offset (PyObject *self);
 static PyObject *surf_get_parent (PyObject *self);
 static PyObject *surf_subsurface (PyObject *self, PyObject *args);
       DOC_SURFACEGETMASKS },
     { "get_shifts", (PyCFunction) surf_get_shifts, METH_NOARGS,
       DOC_SURFACEGETSHIFTS },
+    { "set_masks", (PyCFunction) surf_set_masks, METH_VARARGS,
+      DOC_SURFACESETMASKS },
+    { "set_shifts", (PyCFunction) surf_set_shifts, METH_VARARGS,
+      DOC_SURFACESETSHIFTS },
+
     { "get_losses", (PyCFunction) surf_get_losses, METH_NOARGS,
       DOC_SURFACEGETLOSSES },
 
                           surf->format->Bmask, surf->format->Amask);
 }
 
+
+static PyObject*
+surf_set_masks (PyObject *self, PyObject *args)
+{
+    SDL_Surface *surf = PySurface_AsSurface (self);
+    Uint32 r, g, b, a;
+
+    if (!PyArg_ParseTuple (args, "(kkkk)", &r, &g, &b, &a))
+        return NULL;
+    if (!surf)
+        return RAISE (PyExc_SDLError, "display Surface quit");
+
+    surf->format->Rmask = r;
+	surf->format->Gmask = g;
+    surf->format->Bmask = b;
+	surf->format->Amask = a;
+
+    Py_RETURN_NONE;
+}
+
+
+
+
+
 static PyObject*
 surf_get_shifts (PyObject *self)
 {
                           surf->format->Bshift, surf->format->Ashift);
 }
 
+
+static PyObject*
+surf_set_shifts (PyObject *self, PyObject *args)
+{
+    SDL_Surface *surf = PySurface_AsSurface (self);
+    Uint32 r, g, b, a;
+
+    if (!PyArg_ParseTuple (args, "(kkkk)", &r, &g, &b, &a))
+        return NULL;
+    if (!surf)
+        return RAISE (PyExc_SDLError, "display Surface quit");
+
+    surf->format->Rshift = r;
+	surf->format->Gshift = g;
+    surf->format->Bshift = b;
+	surf->format->Ashift = a;
+
+    Py_RETURN_NONE;
+}
+
+
+
+
+
+
+
 static PyObject*
 surf_get_losses (PyObject *self)
 {
 
 
 
+set_masks
+set the bitmasks needed to convert between a color and a mapped integer
+Surface.set_masks((r,g,b,a)): return None
+
+This is not needed for normal Pygame usage.
+New in pygame 1.8.1
+<END>
+
+
+
 get_shifts
 the bit shifts needed to convert between a color and a mapped integer
 Surface.get_shifts(): return (R, G, B, A)
 
 
 
+set_shifts
+sets the bit shifts needed to convert between a color and a mapped integer
+Surface.get_shifts((r,g,b,a)): return None
+
+This is not needed for normal Pygame usage.
+New in pygame 1.8.1
+<END>
+
+
 get_losses
 the significant bits used to convert between a color and a mapped integer
 Surface.get_losses(): return (R, G, B, A)

test/surface_test.py

         self.assert_(test_not_implemented()) 
 
 
+
+    def test_set_masks(self):
+        s = pygame.Surface((32,32))
+        r,g,b,a = s.get_masks()
+        s.set_masks((b,g,r,a))
+        r2,g2,b2,a2 = s.get_masks()
+        self.assertEqual((r,g,b,a), (b2,g2,r2,a2))
+
+
+    def test_set_shifts(self):
+        s = pygame.Surface((32,32))
+        r,g,b,a = s.get_shifts()
+        s.set_shifts((b,g,r,a))
+        r2,g2,b2,a2 = s.get_shifts()
+        self.assertEqual((r,g,b,a), (b2,g2,r2,a2))
+
+
+
+
+
+
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main()
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.