[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[PATCH] Re: [pygame] Smooth Scaling (pygame.transform.smoothscale)
- To: pygame-users@xxxxxxxx
- Subject: [PATCH] Re: [pygame] Smooth Scaling (pygame.transform.smoothscale)
- From: "René Dudfield" <renesd@xxxxxxxxx>
- Date: Mon, 18 Jun 2007 11:03:15 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sun, 17 Jun 2007 21:03:24 -0400
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=n1z1NWwcI18X751uaDB3JF4P5uMSLlDl/UczMHCbSkAfNorevSwFNZ2c+Nm96vVwMiaFrQHJVKflCd4OOBdMMnoKPpM4X2c3ZQaG7pIT5kJTG4feo6t7Q+hQQST74cEv0MpwPRo7gYAEHViNNgNjgQRTyw9k7PF7MrS73wjPuAM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=TruAqpbJa+AHv6XnrwL9ihERj6n8q4R7PmmKuhwMcmuOZXShL8EbpBmOQd+KMAM/u+hwI1x1x2WanzxFhmnhS2gNPZQA9ZxqoHoVW3yHmlvmhA4hannWrdsMkMEJNNOC7MnNHui3yAecHlwHctkdU53tGyjxeE4YU1C1Xg5FDqo=
- In-reply-to: <4675D3CB.8060601@xxxxxxxxxxxxxxxxxxxxxxx>
- References: <4675D3CB.8060601@xxxxxxxxxxxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Nice one!
This sounds like a very nice scaling function.
It'd be cool if we could include a run time way of including mmx and other cpu specific optimizations. Probably using the SDL methods would be the way to go.
I've added it to the todo list for this weeks mini sprint. http://www.pygame.org/wiki/todo So hopefully it'll get into pygame soon.
If you feel like figuring out how to use the SDL mmx detection routines to select the mmx routine at runtime, that'd be cool.
On 6/18/07, Richard Goedeken <SirRichard@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hello everyone. I just joined the list; My name is Richard Goedeken.
I'm using Pygame in a project that I've been working on for a few weeks,
and I wanted an image scaling function with higher visual quality than
the nearest-neighbor algorithm which is included with the 'scale'
function. So I wrote one; it's in the attached zip file. I hereby give
the Pygame maintainers permission to include and distribute this code
with the Pygame project under the license of their choice.
The algorithm which I've implemented is interesting. Each axis is
scaled independently, which gives it the property that scaling an image
only in the X dimension or only in the Y dimension will be about twice
as fast as scaling both. The reason that this design was chosen is
because the axes are scaled differently depending upon whether they are
being shrunk or expanded. For expansion, a bilinear filter is used
which looks nice at magnifications under 3x or so and is quick. For
shrinking the image, a novel area-averaging algorithm is used which
suppresses Moire patterns and looks good even at very small sizes.
The source code is in
transform.c. It's pretty big because I've also
included inline MMX routines for the i686 and x86_64 architectures under
Unix. The AT&T-style asm sytax won't work with the Intel or MS
compilers, but someone could translate it and add Intel-style code for
Win32. It runs a lot faster with the MMX code. I have included a test
program (scaletest.py) which can run a short benchmark series of scaling
operations. When run with a 600k pixel image, I got the following results:
Machine Algorithm Code level Shrink time Expand time
Athlon64 3800+ smoothscale C-only 36 ms 96 ms
Athlon64 3800+ smoothscale 64-bit MMX 5 ms 16 ms
Athlon64 3800+ scale C-only 2 ms 13 ms
Pentium 3-800 smoothscale C-only 64 ms 180 ms
Pentium 3-800 smoothscale 32-bit MMX 39 ms 119 ms
Pentium 3-800 scale C-only 17 ms 85 ms
I was surprised that the MMX ran so much (6x) faster than the C-code on
my 64-bit machine. But I'm happy that it actually comes close to
matching the nearest-neighbor 'scale' function. I think the P-3 may
have been hindered by relatively low memory bandwidth. With newer
32-bit architectures such as the Core 2 or Athlon I believe that the MMX
will give a bigger speed gain over the C than the P-3.
The 'config.py' file is also modified to set CFLAGS to activate the
inline assembly code. I've integrated this new function into my project
system, and it's quite a nice visual upgrade. I'm sure there are a lot
of people who could use a relatively fast smooth scaling algorithm in
the pygame software, so enjoy!
Richard