1. pygame
  2. Untitled project
  3. pygame

Commits

pygame  committed cebda43

cleanedup surfarray alpha

  • Participants
  • Parent commits 37e90d2
  • Branches default

Comments (0)

Files changed (7)

File docs/index.html

View file
  • Ignore whitespace
 	<a href=index.html>Help Contents</a> &nbsp;||
 	<br>&nbsp;<br>
 
-|| <a href=ref/CD.html>CD</a> || 
-<a href=ref/Channel.html>Channel</a> || 
-<a href=ref/Font.html>Font</a> || 
-<a href=ref/Joystick.html>Joystick</a> || 
-<a href=ref/Rect.html>Rect</a> || 
-<a href=ref/Sound.html>Sound</a> || 
-<a href=ref/Surface.html>Surface</a> ||<br>
-|| <a href=ref/pygame.html>pygame</a> || 
-<a href=ref/pygame_UserRect.html>UserRect</a> || 
-<a href=ref/pygame_cdrom.html>cdrom</a> || 
-<a href=ref/pygame_constants.html>constants</a> || 
-<a href=ref/pygame_cursors.html>cursors</a> || 
-<a href=ref/pygame_display.html>display</a> || 
-<a href=ref/pygame_draw.html>draw</a> ||<br>
-|| <a href=ref/pygame_event.html>event</a> || 
-<a href=ref/pygame_font.html>font</a> || 
-<a href=ref/pygame_image.html>image</a> || 
-<a href=ref/pygame_joystick.html>joystick</a> || 
-<a href=ref/pygame_key.html>key</a> || 
-<a href=ref/pygame_mixer.html>mixer</a> || 
-<a href=ref/pygame_mixer_music.html>mixer_music</a> ||<br>
-|| <a href=ref/pygame_mouse.html>mouse</a> || 
-<a href=ref/pygame_surfarray.html>surfarray</a> || 
-<a href=ref/pygame_time.html>time</a> || 
-<a href=ref/pygame_version.html>version</a> ||<br>
+|| <a href=ref/Surface.html>Surface</a> || 
+<a href=ref/pygame.html>pygame</a> ||<br>
 
 
 </td></tr></table>

File docs/ref/CD.html

View file
  • Ignore whitespace
 	<br>&nbsp;<br>
 
 || <a href=CD.html>CD</a> || 
-<a href=Channel.html>Channel</a> || 
-<a href=Font.html>Font</a> || 
-<a href=Joystick.html>Joystick</a> || 
-<a href=Rect.html>Rect</a> || 
-<a href=Sound.html>Sound</a> || 
-<a href=Surface.html>Surface</a> ||<br>
-|| <a href=pygame.html>pygame</a> || 
-<a href=pygame_UserRect.html>UserRect</a> || 
-<a href=pygame_cdrom.html>cdrom</a> || 
-<a href=pygame_constants.html>constants</a> || 
-<a href=pygame_cursors.html>cursors</a> || 
-<a href=pygame_display.html>display</a> || 
-<a href=pygame_draw.html>draw</a> ||<br>
-|| <a href=pygame_event.html>event</a> || 
-<a href=pygame_font.html>font</a> || 
-<a href=pygame_image.html>image</a> || 
-<a href=pygame_joystick.html>joystick</a> || 
-<a href=pygame_key.html>key</a> || 
-<a href=pygame_mixer.html>mixer</a> || 
-<a href=pygame_mixer_music.html>mixer_music</a> ||<br>
-|| <a href=pygame_mouse.html>mouse</a> || 
-<a href=pygame_surfarray.html>surfarray</a> || 
-<a href=pygame_time.html>time</a> || 
-<a href=pygame_version.html>version</a> ||<br>
+<a href=pygame_cdrom.html>cdrom</a> ||<br>
 
 
 </td></tr></table>
 <br>
 <h2 align=center>CD</h2>
 The CD object represents a CDROM drive and allows you to
-access the CD inside that drive. All functions (except get_name() and get_id())
+access the CD inside that drive. All functions (except <a href=#get_name>get_name()</a> and <a href=#get_id>get_id()</a>)
 require the CD object to be initialized. This is done with the
 CD.init() function.
 <br>&nbsp;<br>
 CD.quit() -> None
 </tt></font><ul>
 After you are completely finished with a cdrom device, you
-can use this <a href=pygame.html#quit>quit()</a> function to free access to the drive.
+can use this <a href=pygame_cdrom.html#quit>quit()</a> function to free access to the drive.
 This will be cleaned up automatically when the cdrom module is.
 uninitialized. It is safe to call this function on an uninitialized CD.
 </ul><br>&nbsp;<br>

File docs/ref/Surface.html

View file
  • Ignore whitespace
 	<a href=../index.html>Help Contents</a> &nbsp;||
 	<br>&nbsp;<br>
 
-|| <a href=CD.html>CD</a> || 
-<a href=Channel.html>Channel</a> || 
-<a href=Font.html>Font</a> || 
-<a href=Joystick.html>Joystick</a> || 
-<a href=Rect.html>Rect</a> || 
-<a href=Sound.html>Sound</a> || 
-<a href=Surface.html>Surface</a> ||<br>
-|| <a href=pygame.html>pygame</a> || 
-<a href=pygame_UserRect.html>UserRect</a> || 
-<a href=pygame_cdrom.html>cdrom</a> || 
-<a href=pygame_constants.html>constants</a> || 
-<a href=pygame_cursors.html>cursors</a> || 
-<a href=pygame_display.html>display</a> || 
-<a href=pygame_draw.html>draw</a> ||<br>
-|| <a href=pygame_event.html>event</a> || 
-<a href=pygame_font.html>font</a> || 
-<a href=pygame_image.html>image</a> || 
-<a href=pygame_joystick.html>joystick</a> || 
-<a href=pygame_key.html>key</a> || 
-<a href=pygame_mixer.html>mixer</a> || 
-<a href=pygame_mixer_music.html>mixer_music</a> ||<br>
-|| <a href=pygame_mouse.html>mouse</a> || 
-<a href=pygame_surfarray.html>surfarray</a> || 
-<a href=pygame_time.html>time</a> || 
-<a href=pygame_version.html>version</a> ||<br>
+|| <a href=Surface.html>Surface</a> || 
+<a href=pygame.html>pygame</a> ||<br>
 
 
 </td></tr></table>
 <br>&nbsp;<br>
 There is support for pixel access for the Surfaces. Pixel access
 on hardware surfaces is slow and not recommended. Pixels can be
-accessed using the get_at() and set_at() functions. These methods
+accessed using the <a href=#get_at>get_at()</a> and <a href=#set_at>set_at()</a> functions. These methods
 are fine for simple access, but will be considerably slow when
 doing of pixel work with them. If you plan on doing a lot of
 pixel level work, it is recommended to use the pygame.surfarray
 module, which can treat the surfaces like large multidimensional
 arrays (and it's quite quick). Some surfaces need to be locked
 before they can be used. Surfaces with flags like HWSURFACE and
-RLEACCEL generally require calls to lock() and unlock()
-surrounding pixel access. It is safe to lock() and unlock()
+RLEACCEL generally require calls to <a href=#lock>lock()</a> and <a href=#unlock>unlock()</a>
+surrounding pixel access. It is safe to <a href=#lock>lock()</a> and <a href=#unlock>unlock()</a>
 surfaces that do not require locking. Nonetheless, you can check
-to see if a Surface really needs to be locked with the mustlock()
+to see if a Surface really needs to be locked with the <a href=#mustlock>mustlock()</a>
 function.<p>&nbsp;</p>Here is the quick breakdown of how packed pixels work (don't worry if
 you don't quite understand this, it is only here for informational
 purposes, it is not needed). Each colorplane mask can be used to
 masks can be used to convert back and forth between each
 colorplane and the actual color for that plane. Here are the
 final formulas used be map and unmap (not exactly, heh).
-PACKED_COLOR = RED>>losses[0]<<shifts[0] |
-      GREEN>>losses[1]<<shifts[1] | BLUE>>losses[2]<<shifts[2]
-RED = PACKED_COLOR & masks[0] >> shifts[0] << losses[0]
-GREEN = PACKED_COLOR & masks[1] >> shifts[1] << losses[1]
-BLUE = PACKED_COLOR & masks[2] >> shifts[2] << losses[2]
+PACKED_COLOR = RED&gt;&gt;losses[0]&lt;&lt;shifts[0] |
+      GREEN&gt;&gt;losses[1]&lt;&lt;shifts[1] | BLUE&gt;&gt;losses[2]&lt;&lt;shifts[2]
+RED = PACKED_COLOR & masks[0] &gt;&gt; shifts[0] &lt;&lt; losses[0]
+GREEN = PACKED_COLOR & masks[1] &gt;&gt; shifts[1] &lt;&lt; losses[1]
+BLUE = PACKED_COLOR & masks[2] &gt;&gt; shifts[2] &lt;&lt; losses[2]
 There is also an alpha channel for some Surfaces. The alpha
 channel works this same exact way, and the map_rgba() and
 unmap_rgba() functions can be used to do the conversion for you.

File docs/ref/pygame.html

View file
  • Ignore whitespace
 	<a href=../index.html>Help Contents</a> &nbsp;||
 	<br>&nbsp;<br>
 
-|| <a href=CD.html>CD</a> || 
-<a href=Channel.html>Channel</a> || 
-<a href=Font.html>Font</a> || 
-<a href=Joystick.html>Joystick</a> || 
-<a href=Rect.html>Rect</a> || 
-<a href=Sound.html>Sound</a> || 
-<a href=Surface.html>Surface</a> ||<br>
-|| <a href=pygame.html>pygame</a> || 
-<a href=pygame_UserRect.html>UserRect</a> || 
-<a href=pygame_cdrom.html>cdrom</a> || 
-<a href=pygame_constants.html>constants</a> || 
-<a href=pygame_cursors.html>cursors</a> || 
-<a href=pygame_display.html>display</a> || 
-<a href=pygame_draw.html>draw</a> ||<br>
-|| <a href=pygame_event.html>event</a> || 
-<a href=pygame_font.html>font</a> || 
-<a href=pygame_image.html>image</a> || 
-<a href=pygame_joystick.html>joystick</a> || 
-<a href=pygame_key.html>key</a> || 
-<a href=pygame_mixer.html>mixer</a> || 
-<a href=pygame_mixer_music.html>mixer_music</a> ||<br>
-|| <a href=pygame_mouse.html>mouse</a> || 
-<a href=pygame_surfarray.html>surfarray</a> || 
-<a href=pygame_time.html>time</a> || 
-<a href=pygame_version.html>version</a> ||<br>
+|| <a href=Surface.html>Surface</a> || 
+<a href=pygame.html>pygame</a> ||<br>
 
 
 </td></tr></table>
 <br>
 <h2 align=center>pygame</h2>
-Contains the core routines that are used by the rest of the
-pygame modules. It's routines are merged directly into the pygame
-namespace. This mainly includes the auto-initialization init() and
-quit() routines.
-<br>&nbsp;<br>
-There is a small module named 'locals' that also gets merged into
-this namespace. This contains all the constants needed by pygame.
-Object constructors also get placed into this namespace, you can
-call functions like rect() and surface() to create objects of
-that type. As a convenience, you can import the members of
-pygame.locals directly into your module's namespace with 'from
-pygame.locals import *'. Most of the pygame examples do this if
-you'd like to take a look.
+{module}
 
 <hr>
 
 <table>
-<tr><td><a href=#Rect>Rect</a></td><td> -
-create a new rectangle</td></tr>
-
-
 <tr><td><a href=#Surface>Surface</a></td><td> -
 create a new Surface</td></tr>
 
 
-<tr><td><a href=#get_error>get_error</a></td><td> -
-get current error message</td></tr>
-
-
-<tr><td><a href=#get_grab>get_grab</a></td><td> -
-query the state of input grabbing</td></tr>
-
-
-<tr><td><a href=#init>init</a></td><td> -
-autoinitialize all imported pygame modules</td></tr>
-
-
-<tr><td><a href=#quit>quit</a></td><td> -
-uninitialize all pygame modules</td></tr>
-
-
-<tr><td><a href=#register_quit>register_quit</a></td><td> -
-routine to call when pyGame quits</td></tr>
-
-
 </table>
 
 <hr>
 
-<a name=Rect><font size=+2><b>Rect
-</b></font><br><font size=+1><tt>
-pygame.Rect(rectstyle) -> Rect
-</tt></font><ul>
-Creates a new rectangle object. The given
-rectstyle represents one of the various ways of
-representing rectangle data. This is usually a
-sequence of x and y position for the topleft
-corner, and the width and height.
-</ul><br>&nbsp;<br>
-
 <a name=Surface><font size=+2><b>Surface
 </b></font><br><font size=+1><tt>
 pygame.Surface(size, [flags, [depth|Surface, [masks]]]) -> Surface
 for the flag.
 </ul><br>&nbsp;<br>
 
-<a name=get_error><font size=+2><b>get_error
-</b></font><br><font size=+1><tt>
-pygame.get_error() -> errorstring
-</tt></font><ul>
-SDL maintains an internal current error message. This message is
-usually given to you when an SDL related exception occurs, but
-sometimes you may want to call this directly yourself.
-</ul><br>&nbsp;<br>
-
-<a name=get_grab><font size=+2><b>get_grab
-</b></font><br><font size=+1><tt>
-pygame.get_grab() -> bool
-</tt></font><ul>
-Returns true if the input is currently grabbed to your
-application.
-</ul><br>&nbsp;<br>
-
-<a name=init><font size=+2><b>init
-</b></font><br><font size=+1><tt>
-pygame.init() -> passed, failed
-</tt></font><ul>
-Initialize all imported pygame modules. Including pygame modules
-that are not part of the base modules (like font and image).
-<br>&nbsp;<br>
-It does not raise exceptions, but instead silently counts which
-modules have failed to init. The return argument contains a count
-of the number of modules initialized, and the number of modules
-that failed to initialize.
-<br>&nbsp;<br>
-You can always initialize the modules you want by hand. The
-modules that need it have an <u>init()</u> and <a href=#quit>quit()</a> routine built in,
-which you can call directly. They also have a <a href=pygame_cdrom.html#get_init>get_init()</a> routine
-which you can use to doublecheck the initialization. Note that
-the manual <u>init()</u> routines will raise an exception on error. Be
-aware that most platforms require the display module to be
-initialized before others. This <u>init()</u> will handle that for you,
-but if you initialize by hand, be aware of this constraint.
-<br>&nbsp;<br>
-As with the manual <u>init()</u> routines. It is safe to call this
-init() as often as you like. If you have imported pygame modules
-since the.
-</ul><br>&nbsp;<br>
-
-<a name=quit><font size=+2><b>quit
-</b></font><br><font size=+1><tt>
-pygame.quit() -> none
-</tt></font><ul>
-Uninitialize all pygame modules that have been initialized. Even
-if you initialized the module by hand, this <u>quit()</u> will
-uninitialize it for you.
-<br>&nbsp;<br>
-All the pygame modules are uninitialized automatically when your
-program exits, so you will usually not need this routine. If you
-program plans to keep running after it is done with pygame, then
-would be a good time to make this call.
-</ul><br>&nbsp;<br>
-
-<a name=register_quit><font size=+2><b>register_quit
-</b></font><br><font size=+1><tt>
-pygame.register_quit(callback) -> None
-</tt></font><ul>
-The given callback routine will be called when. pygame is
-quitting. Quit callbacks are served on a 'last in, first out'
-basis. Also be aware that your callback may be called more than
-once.
-</ul><br>&nbsp;<br>
-
 
 <hr>
 

File docs/ref/pygame_cdrom.html

View file
  • Ignore whitespace
 	<br>&nbsp;<br>
 
 || <a href=CD.html>CD</a> || 
-<a href=Channel.html>Channel</a> || 
-<a href=Font.html>Font</a> || 
-<a href=Joystick.html>Joystick</a> || 
-<a href=Rect.html>Rect</a> || 
-<a href=Sound.html>Sound</a> || 
-<a href=Surface.html>Surface</a> ||<br>
-|| <a href=pygame.html>pygame</a> || 
-<a href=pygame_UserRect.html>UserRect</a> || 
-<a href=pygame_cdrom.html>cdrom</a> || 
-<a href=pygame_constants.html>constants</a> || 
-<a href=pygame_cursors.html>cursors</a> || 
-<a href=pygame_display.html>display</a> || 
-<a href=pygame_draw.html>draw</a> ||<br>
-|| <a href=pygame_event.html>event</a> || 
-<a href=pygame_font.html>font</a> || 
-<a href=pygame_image.html>image</a> || 
-<a href=pygame_joystick.html>joystick</a> || 
-<a href=pygame_key.html>key</a> || 
-<a href=pygame_mixer.html>mixer</a> || 
-<a href=pygame_mixer_music.html>mixer_music</a> ||<br>
-|| <a href=pygame_mouse.html>mouse</a> || 
-<a href=pygame_surfarray.html>surfarray</a> || 
-<a href=pygame_time.html>time</a> || 
-<a href=pygame_version.html>version</a> ||<br>
+<a href=pygame_cdrom.html>cdrom</a> ||<br>
 
 
 </td></tr></table>
 <h2 align=center>pygame.cdrom</h2>
 The cdrom module provides a few functions to initialize
 the CDROM subsystem and to manage the CD objects. The CD
-objects are created with the pygame.cdrom.CD() function.
+objects are created with the <a href=#CD>pygame.cdrom.CD()</a> function.
 This function needs a cdrom device number to work on. All
 cdrom drives on the system are enumerated for use as a CD
 object. To access most of the CD functions, you'll need to
 same CDROM device, the state and values for those CD objects
 will be shared.
 <br>&nbsp;<br>
-You can call the CD.get_name() and CD.get_id() functions
+You can call the <a href=CD.html#get_name>CD.get_name()</a> and <a href=CD.html#get_id>CD.get_id()</a> functions
 without initializing the CD object.
 <br>&nbsp;<br>
 Be sure to understand there is a difference between the cdrom module

File docs/util/makedocs.py

View file
  • Ignore whitespace
- 
 """take all the PyGame source and create html documentation"""
-#needs to eventually handle python source too.
 
 import fnmatch, glob, os
 
 
 DOCPATTERN = '*static char*doc_*=*'
-SOURCES = ['../../src/*.c']
+
+SOURCES = ['../../src/surface*.c']
 IGNORE_SOURCES = ['rwobject.c']
+PYTHONSRC = []#['cursors', 'version', 'UserRect']
+
 OUTPUTDIR = '../ref/'
-PYTHONSRC = ['cursors', 'version', 'UserRect']
 PAGETEMPLATE = open('pagelate.html').readlines()
 DOCTEMPLATE = open('doclate.html').readlines()
 LISTTEMPLATE = open('listlate.html').readlines()
             return d
 
 
+def htmlize(doc, obj, func):
+    for i in range(len(doc)):
+        line = doc[i]
+        line = line.replace('<<', '&lt;&lt;').replace('>>', '&gt;&gt;')
+        pos = 0
+        while 1:
+            pos = line.find('(', pos+1)
+            if pos == -1: break
+            if line[pos-1].isspace(): continue
+            start = line.rfind(' ', 0, pos)
+            if start == -1: continue
+            lookname = line[start+1:pos]
+            match = lookupdoc(func, lookname, obj['category'])
+            if not match: continue
+            end = line.find(')', pos)+1
+            if match['fullname'] == obj['fullname']:
+                link = '<u>%s</u>' % line[start+1:end]
+            else:
+                if match['category'] == obj['category']:
+                    dest = '#%s' % (match['name'])
+                else:
+                    dest = '%s.html#%s' % (match['category'], match['name'])
+                link = '<a href=%s>%s</a>' % (dest, line[start+1:end])
+            line = line[:start+1] + link + line[end:]
+            pos += len(link) - (pos-start)
+        doc[i] = line
+
 
 def buildlinks(alldocs):
     mod, ext, func = alldocs
     for obj in func:
         doc = obj['docs']
-        for i in range(len(doc)):
-            line = doc[i]
-            pos = 0
-            while 1:
-                pos = line.find('(', pos+1)
-                if pos == -1: break
-                if line[pos-1].isspace(): continue
-                start = line.rfind(' ', 0, pos)
-                if start == -1: continue
-                lookname = line[start+1:pos]
-                match = lookupdoc(func, lookname, obj['category'])
-                if not match: continue
-                end = line.find(')', pos)+1
-                if match['fullname'] == obj['fullname']:
-                    link = '<u>%s</u>' % line[start+1:end]
-                else:
-                    if match['category'] == obj['category']:
-                        dest = '#%s' % (match['name'])
-                    else:
-                        dest = '%s.html#%s' % (match['category'], match['name'])
-                    link = '<a href=%s>%s</a>' % (dest, line[start+1:end])
-                line = line[:start+1] + link + line[end:]
-                pos += len(link) - (pos-start)
-            doc[i] = line
-
+        htmlize(doc, obj, func)
+    for k,i in mod.items():
+        doc = [i]
+        obj = {'category': k, 'fullname':''}
+        htmlize(doc, obj, func)
+        mod[k] = doc[0]
+    for k,i in ext.items():
+        doc = [i]
+        obj = {'category': k, 'fullname':''}
+        htmlize(doc, obj, func)
+        ext[k] = doc[0]
 
 
 def categorize(allfuncs):

File src/surfarray.c

View file
  • Ignore whitespace
 	dim[0] = surf->w;
 	dim[1] = surf->h;
 
-	if(surf->format->BytesPerPixel <= 1 || surf->format->BytesPerPixel > 4)
+	if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4)
 		return RAISE(PyExc_ValueError, "unsupport bit depth for alpha array");
 
 	array = PyArray_FromDims(2, dim, PyArray_UBYTE);
 	Ashift = surf->format->Ashift;
 	Aloss = surf->format->Aloss;
 
-	if(!Amask) /*no pixel alpha*/
+	if(!Amask || surf->format->BytesPerPixel==1) /*no pixel alpha*/
 	{
 		memset(((PyArrayObject*)array)->data, 255, surf->w * surf->h);
 		return array;
 	if(!array) return NULL;
 
 	colorkey = surf->format->colorkey;
-
 	if(!(surf->flags & SDL_SRCCOLORKEY)) /*no pixel alpha*/
 	{
 		memset(((PyArrayObject*)array)->data, 255, surf->w * surf->h);
 			return RAISE(PyExc_SDLError, SDL_GetError());
 		didlock = 1;
 	}
-
 	switch(surf->format->BytesPerPixel)
 	{
 	case 1:
 		for(loopy = 0; loopy < surf->h; ++loopy)
 		{
 			Uint8* pix = (Uint8*)(((char*)surf->pixels)+loopy*surf->pitch);
-			Uint8* end = (Uint8*)(((char*)pix)+surf->w*2);
+			Uint8* end = (Uint8*)(((char*)pix)+surf->w);
 			data = ((Uint8*)((PyArrayObject*)array)->data) + stridey*loopy;
 			while(pix < end)
 			{
 				color = *pix++;
-				*data = (color == colorkey) * 255;
+				*data = (color != colorkey) * 255;
 				data += stridex;
 			}
 		}break;
 			while(pix < end)
 			{
 				color = *pix++;
-				*data = (color == colorkey) * 255;
+				*data = (color != colorkey) * 255;
 				data += stridex;
 			}
 		}break;
 #else
 				color = pix[2] + (pix[1]<<8) + (pix[0]<<16);
 #endif
-				*data = (color == colorkey) * 255;
+				*data = (color != colorkey) * 255;
 				pix += 3;
 				data += stridex;
 			}
 			while(pix < end)
 			{
 				color = *pix++;
-				*data = (color == colorkey) * 255;
+				*data = (color != colorkey) * 255;
 				data += stridex;
 			}
 		}break;