Article Preview
Buy Now
| Print: | |
| PDF: |
Beyond the Limits
Unroll the loops
Optimizing your code
Issue: 2.3 (December/January 2003)
Article Description: No description available.
Article Length (in bytes): 7,134
Starting Page Number: 46
RBD Number: 2323
Resource File(s):
2323.sit Updated: Thursday, December 18, 2003 at 10:00 AM
Related Link(s): None
Known Limitations: None
Excerpt of article text...
In one of my previous columns, Stego Part II, I mentionned a way of doing some things faster, especially by using MemoryBlocks instead of strings. Following this, there were requests for an article on optimization. I won't be able to cover everything in the space alloted here, but I'll give you a couple of improvements you can use in your code. We'll see how to improve square-angle image rotation with a few tricks that'll speed things up to nine times faster!
Image Rotation: 90 degrees that seem to take forever
We've all dealt with image rotation, at least at square angle: +/- 90 degrees, 180 degrees, horizontal or vertical mirror. This is not extremely difficult to achieve, but doing it fast is trickier. Let's see first a "standard" 90 degree rotation routine:
x=pix.width
y=pix.height
q=newPicture(y,x,32)
p=newPicture(x,y,32)
x=x-1
y=y-1
p.graphics.drawPicture pix,0,0
srf=p.rgbSurface
srf2=q.rgbSurface
for i=0 to x
for j=0 to y
srf2.pixel(j,i)=srf.pixel(i,y-j)
...End of Excerpt. Please purchase the magazine to read the full article.
Article copyrighted by REALbasic Developer magazine. All rights reserved.
|










