Commits

Anonymous committed ef7a97c

transform.chop added

  • Participants
  • Parent commits 1fc0d7b

Comments (0)

Files changed (7)

 June 26, 2004
     Rect.fit() added
     Surface.get_rect() accepts keyword args for assignment
+    transform.chop() added, from Matthias Spiller
 
 June 25, 2004
     Font becomes new style type, inheritable, weakrefable
 <a href=ref/pygame_time.html#get_ticks>time.get_ticks</a> - milliseconds since initialization<br>
 <a href=ref/pygame_time.html#set_timer>time.set_timer</a> - control timer events<br>
 <a href=ref/pygame_time.html#wait>time.wait</a> - yielding delay for a number of milliseconds<br>
+<a href=ref/pygame_transform.html#chop>transform.chop</a> - remove a region of an surface<br>
+<a href=ref/pygame_transform.html#flip>transform.flip</a> - flips a surface on either axis<br>
 <a href=ref/pygame_transform.html#flip>transform.flip</a> - flips a surface on either axis<br>
 <a href=ref/pygame_transform.html#rotate>transform.rotate</a> - rotate a Surface<br>
+<a href=ref/pygame_transform.html#rotate>transform.rotate</a> - rotate a Surface<br>
+<a href=ref/pygame_transform.html#rotozoom>transform.rotozoom</a> - smoothly scale and/or rotate an image<br>
 <a href=ref/pygame_transform.html#rotozoom>transform.rotozoom</a> - smoothly scale and/or rotate an image<br>
 <a href=ref/pygame_transform.html#scale2x>transform.scale2x</a> - doubles the size of the image with advanced scaling<br>
+<a href=ref/pygame_transform.html#scale2x>transform.scale2x</a> - doubles the size of the image with advanced scaling<br>
+<a href=ref/pygame_transform.html#scale>transform.scale</a> - scale a Surface to an arbitrary size<br>
 <a href=ref/pygame_transform.html#scale>transform.scale</a> - scale a Surface to an arbitrary size<br>
 <!--ENDINDEX-->
 </ul>

docs/ref/pygame_transform.html

 <hr>
 
 <table>
+<tr><td><a href=#chop>chop</a></td><td> -
+remove a region of an surface</td></tr>
+
+
+<tr><td><a href=#flip>flip</a></td><td> -
+flips a surface on either axis</td></tr>
+
+
 <tr><td><a href=#flip>flip</a></td><td> -
 flips a surface on either axis</td></tr>
 
 rotate a Surface</td></tr>
 
 
+<tr><td><a href=#rotate>rotate</a></td><td> -
+rotate a Surface</td></tr>
+
+
+<tr><td><a href=#rotozoom>rotozoom</a></td><td> -
+smoothly scale and/or rotate an image</td></tr>
+
+
 <tr><td><a href=#rotozoom>rotozoom</a></td><td> -
 smoothly scale and/or rotate an image</td></tr>
 
 scale a Surface to an arbitrary size</td></tr>
 
 
+<tr><td><a href=#scale>scale</a></td><td> -
+scale a Surface to an arbitrary size</td></tr>
+
+
+<tr><td><a href=#scale2x>scale2x</a></td><td> -
+doubles the size of the image with advanced scaling</td></tr>
+
+
 <tr><td><a href=#scale2x>scale2x</a></td><td> -
 doubles the size of the image with advanced scaling</td></tr>
 
 
 <hr>
 
+<a name=chop><font size=+2><b>chop
+</b></font><br><font size=+1><tt>
+pygame.transform.chop(Surface, rectstyle) -> Surface
+</tt></font><ul>
+Removes an interior set of columns and rows from a Surface.
+All vertical and horizontal pixels surrounding the given
+rectangle area are removed. The resulting image is shrunken
+by the size of pixels removed.
+</ul><br>&nbsp;<br>
+
 <a name=flip><font size=+2><b>flip
 </b></font><br><font size=+1><tt>
 pygame.transform.flip(Surface, xaxis, yaxis) -> Surface
 exact original image.
 </ul><br>&nbsp;<br>
 
+<a name=flip><font size=+2><b>flip
+</b></font><br><font size=+1><tt>
+pygame.transform.flip(Surface, xaxis, yaxis) -> Surface
+</tt></font><ul>
+Flips the image on the x-axis or the y-axis if the argument
+for that axis is true.
+<br>&nbsp;<br>
+The flip operation is nondestructive, you may flip the image
+as many times as you like, and always be able to recreate the
+exact original image.
+</ul><br>&nbsp;<br>
+
+<a name=rotate><font size=+2><b>rotate
+</b></font><br><font size=+1><tt>
+pygame.transform.rotate(Surface, angle) -> Surface
+</tt></font><ul>
+Rotates the image counterclockwise with the given angle
+(in degrees). The angle can be any floating point value
+(negative rotation amounts will do clockwise rotations)
+<br>&nbsp;<br>
+Unless rotating by 90 degree increments, the resulting image
+size will be larger than the original. There will be newly
+uncovered areas in the image. These will filled with either
+the current colorkey for the Surface, or the topleft pixel value.
+(with the alpha channel zeroed out if available)
+<br>&nbsp;<br>
+This transformation is not filtered.
+</ul><br>&nbsp;<br>
+
 <a name=rotate><font size=+2><b>rotate
 </b></font><br><font size=+1><tt>
 pygame.transform.rotate(Surface, angle) -> Surface
 resulting image could be shifted and contain artifacts.
 </ul><br>&nbsp;<br>
 
+<a name=rotozoom><font size=+2><b>rotozoom
+</b></font><br><font size=+1><tt>
+pygame.transform.rotozoom(Surface, angle, zoom) -> Surface
+</tt></font><ul>
+The angle argument is the number of degrees to rotate
+counter-clockwise. The angle can be any floating point value.
+(negative rotation amounts will do clockwise rotations)
+<br>&nbsp;<br>
+This will smoothly rotate and scale an image in one pass.
+The resulting image will always be a 32bit version of the
+original surface. The scale is a multiplier for the image
+size, and angle is the degrees to rotate counter clockwise.
+<br>&nbsp;<br>
+It calls the SDL_rotozoom library which is compiled in.
+Note that the code in SDL_rotozoom is fairly messy and your
+resulting image could be shifted and contain artifacts.
+</ul><br>&nbsp;<br>
+
+<a name=scale><font size=+2><b>scale
+</b></font><br><font size=+1><tt>
+pygame.transform.scale(Surface, size) -> Surface
+</tt></font><ul>
+This will resize a surface to the given resolution.
+The size is simply any 2 number sequence representing
+the width and height.
+<br>&nbsp;<br>
+This transformation is not filtered.
+</ul><br>&nbsp;<br>
+
 <a name=scale><font size=+2><b>scale
 </b></font><br><font size=+1><tt>
 pygame.transform.scale(Surface, size) -> Surface
 like a regular unfiltered scale.
 </ul><br>&nbsp;<br>
 
+<a name=scale2x><font size=+2><b>scale2x
+</b></font><br><font size=+1><tt>
+pygame.transform.scale2x(Surface) -> Surface
+</tt></font><ul>
+This will return a new image that is double the size of
+the original. It uses the AdvanceMAME Scale2X algorithm
+which does a 'jaggie-less' scale of bitmap graphics.
+<br>&nbsp;<br>
+This really only has an effect on simple images with solid
+colors. On photographic and antialiased images it will look
+like a regular unfiltered scale.
+</ul><br>&nbsp;<br>
+
 
 <hr>
 </body></html>
     Dave Wallace, John Popplewell, Michael Urman,
     Andrew Straw, Michael Hudson, Ole Martin Bjoerndalen,
     Herv� Cauwelier, James Mazer, Lalo Martins,
-    Timothy Stranex, Chad Lester</li>
+    Timothy Stranex, Chad Lester, Matthias Spillers</li>
 <li>And our bug hunters above and beyond:
     Angus, Guillaume Proux, Frank Raiser,
     Austin Henry, Kaweh Kazemi, Arturo Aldama,
      Thanks to those sending in patches and fixes: Niki Spahiev, Gordon
    Tyler, Nathaniel Pryce, Dave Wallace, John Popplewell, Michael Urman,
    Andrew Straw, Michael Hudson, Ole Martin Bjoerndalen, Herv� Cauwelier,
-   James Mazer, Lalo Martins, Timothy Stranex, Chad Lester
+   James Mazer, Lalo Martins, Timothy Stranex, Chad Lester, Matthias
+   Spillers
 
      And our bug hunters above and beyond: Angus, Guillaume Proux, Frank
    Raiser, Austin Henry, Kaweh Kazemi, Arturo Aldama, Mike Mulcheck, Rene
 	{"get_size",		surf_get_size,		1, doc_surf_get_size },
 	{"get_width",		surf_get_width, 	1, doc_surf_get_width },
 	{"get_height",		surf_get_height,	1, doc_surf_get_height },
-	{"get_rect",		surf_get_rect,		METH_KEYWORDS, doc_surf_get_rect },
+	{"get_rect",		(PyCFunction)surf_get_rect, METH_KEYWORDS, doc_surf_get_rect },
 	{"get_pitch",		surf_get_pitch, 	1, doc_surf_get_pitch },
 	{"get_bitsize", 	surf_get_bitsize,	1, doc_surf_get_bitsize },
 	{"get_bytesize",	surf_get_bytesize,	1, doc_surf_get_bytesize },
 }
 
 
+static SDL_Surface* chop(SDL_Surface *src, int x, int y, int width, int height)
+{
+  SDL_Surface* dst;
+  int dstwidth,dstheight;
+  char *srcpix, *dstpix, *srcrow, *dstrow;
+  int srcstepx, srcstepy, dststepx, dststepy;
+  int loopx,loopy;
+
+  if((x+width) > src->w)
+    width=src->w-x;
+  if((y+height) > src->h)
+    height=src->h-y;
+  if(x < 0)
+    {
+      width-=(-x);
+      x=0;
+    }
+  if(y < 0)
+    {
+      height-=(-y);
+      y=0;
+    }
+
+  dstwidth=src->w-width;
+  dstheight=src->h-height;
+
+  dst=newsurf_fromsurf(src,dstwidth,dstheight);
+  if(!dst)
+    return NULL;
+  SDL_LockSurface(dst);
+  srcrow=(char*)src->pixels;
+  dstrow=(char*)dst->pixels;
+  srcstepx=dststepx=src->format->BytesPerPixel;
+  srcstepy=src->pitch;
+  dststepy=dst->pitch;
+
+  for(loopy=0; loopy < src->h; loopy++)
+    {
+      if((loopy < y) || (loopy >= (y+height)))
+	{
+	  dstpix=dstrow;
+	  srcpix=srcrow;
+	  for(loopx=0; loopx < src->w; loopx++)
+	    {
+	      if((loopx < x) || (loopx>= (x+width)))
+		{
+		  switch(src->format->BytesPerPixel)
+		    {
+		    case 1:
+		      *dstpix=*srcpix;
+		      break;
+		    case 2:
+		      *(Uint16*) dstpix=*(Uint16*) srcpix;
+		      break;
+		    case 3:
+		      dstpix[0] = srcpix[0];
+		      dstpix[1] = srcpix[1];
+		      dstpix[2] = srcpix[2];    
+		      break;
+		    case 4:
+		      *(Uint32*) dstpix=*(Uint32*) srcpix;
+		      break;
+		    }
+		  dstpix+=dststepx;
+		}
+	      srcpix+=srcstepx;
+	    }
+	  dstrow+=dststepy;
+	}
+      srcrow+=srcstepy;
+    }
+  SDL_UnlockSurface(dst);
+  return dst;
+}
+
+
+    /*DOC*/ static char doc_chop[] =
+    /*DOC*/    "pygame.transform.chop(Surface, rectstyle) -> Surface\n"
+    /*DOC*/    "remove a region of an surface\n"
+    /*DOC*/    "\n"
+    /*DOC*/    "Removes an interior set of columns and rows from a Surface.\n"
+    /*DOC*/    "All vertical and horizontal pixels surrounding the given\n"
+    /*DOC*/    "rectangle area are removed. The resulting image is shrunken\n"
+    /*DOC*/    "by the size of pixels removed.\n"
+    /*DOC*/ ;
+
+static PyObject* surf_chop(PyObject* self, PyObject* arg)
+{
+  PyObject *surfobj, *rectobj;
+  SDL_Surface* surf, *newsurf;
+  GAME_Rect* rect, temp;
+	
+  if(!PyArg_ParseTuple(arg, "O!O", &PySurface_Type, &surfobj, &rectobj))
+    return NULL;
+  if(!(rect = GameRect_FromObject(rectobj, &temp)))
+    return RAISE(PyExc_TypeError, "Rect argument is invalid");
+
+  surf=PySurface_AsSurface(surfobj);
+  newsurf=chop(surf, rect->x, rect->y, rect->w, rect->h);
+
+  return PySurface_New(newsurf);
+}
+
 
 static PyMethodDef transform_builtins[] =
 {
 	{ "rotate", surf_rotate, 1, doc_rotate },
 	{ "flip", surf_flip, 1, doc_flip },
 	{ "rotozoom", surf_rotozoom, 1, doc_rotozoom},
+	{ "chop", surf_chop, 1, doc_chop},
 	{ "scale2x", surf_scale2x, 1, doc_scale2x},
 		
 	{ NULL, NULL }