pouët.net

rotating bitmap by any angle without artifacts

category: code [glöplog]
 
helps!
I'm stuck (again) trying to make a bitmap rotate without creating speckle because 2 pixels got copied to the same position.
I've seen the tutorial on codeproject but I think that's pretty slow.
any faster way?
added on the 2013-07-20 21:36:24 by zorke zorke
No, there is no faster way than this magical one at codeproject that you didn't even link to.
So, to answer your question ("any faster way?"), you should probably show us first what you got, most likely there is lots of room for improvements. Secondly, you may want to read up on interpolation, since that is basically what you want for getting rid of artefacts.
I was just looking into this some time ago.

The best solution with the least artifact that I found is RotSprite:
http://info.sonicretro.org/RotSprite

This of course requires precalculating the rotated images, but is superior to every other pixel rotation algorithm that I've ever seen, especially what comes to preserving details.
added on the 2013-07-20 22:02:20 by visy visy
The fastest way, few artifacts: Use the GPU, enable bilinear sampling.

*g*
added on the 2013-07-20 23:41:52 by Sesse Sesse
Outsource it to India.
added on the 2013-07-21 00:12:01 by trc_wm trc_wm
Quote:
I'm stuck (again) trying to make a bitmap rotate without creating speckle because 2 pixels got copied to the same position.


I guess you are doing what I did when I made my first rotozoomer. You treat each pixel of the bitmap as individual dot and transform to new position. This will produce holes indeed.

The easier (and faster) way to do it is inverse rotation, that goes for each pixel on the screen make a rotation inside bitmap array and fetch the color. This way every screen pixel will be filled with some color and no holes between. This is for fullscreen rotozoomer background, but if you want to make it as a sprite, maybe you need a simple quad textured rasterizer.

Don't remember a tutorial for rotozoomers though. I have some code around though, even in my qbasic demos.
added on the 2013-07-21 01:28:31 by Optimus Optimus
What Bugo said for inverse, which is logical.
What Sesse and Saga told about interpolation / Bilinear filtering.
What Visy said, which will be your third step.
What trc_wm said, because it'll make only one cheap step.
added on the 2013-07-21 01:34:16 by skarab skarab
i just found a very old Ansi C code of mine which does the rotation just like Bugo the Cat described. Here it is for the idea. Please note that it's 10+ years old code.

rotates picture at "pic" buffer and outputs to "bufPic" the rotated image. buffers are both 24 bit RGB buffers.

Code: void rotateImage(float angle) { float midX, midY; float deltaX, deltaY; int rotX, rotY; int i,j; midX = PIC_WIDTH / 2.0f; midY = PIC_HEIGHT / 2.0f; for(i = 0; i < PIC_WIDTH; i++) for(j = 0; j < PIC_HEIGHT; j++) { deltaX = i - midX; deltaY = j - midY; rotX = (int)(midX + deltaX * sin(angle) + deltaY * cos(angle)); rotY = (int)(midY + deltaX * cos(angle) - deltaY * sin(angle)); if(rotX >= 0 && rotX < PIC_WIDTH && rotY >= 0 && rotY < PIC_HEIGHT) { bufPic[(j * PIC_WIDTH + i) * 3] = pic[(rotX * PIC_WIDTH + rotY) * 3]; bufPic[(j * PIC_WIDTH + i) * 3 + 1] = pic[(rotX * PIC_WIDTH + rotY) * 3 + 1]; bufPic[(j * PIC_WIDTH + i) * 3 + 2] = pic[(rotX * PIC_WIDTH + rotY) * 3 + 2]; } } }
added on the 2013-07-21 01:48:59 by Skate Skate
zorke: you mean you are using nearest neighbour interpolation or is it something else?

read up on linear algebra: matrix rotation for 2d- cartesian coordinates and use that as reference for each u,v lookup-coordinate. interpolation can be integrated into your formulas
if your math is right. if its not that then artifacts may be caused by number of precision-bits that you use.
added on the 2013-07-21 03:40:05 by rudi rudi

login