don't click here

Sprite Rotation Utility

Discussion in 'Engineering & Reverse Engineering' started by Xenowhirl, Jan 17, 2007.

Thread Status:
Not open for further replies.
  1. Xenowhirl

    Xenowhirl

    Tech Member
    175
    0
    0
    Making rotated versions of sprites is usually a pain in the ass, because most programs that rotate a sprite will antialias it (which blurs it and messes with the colors) and ones that don't antialias it tend to do a poor job of preserving features of the original image. It usually takes a lot of manual touch-up work to make the rotated sprite look good. (If you didn't know already, the walking and running frames in Sonic 1, 2, and 3 all need 45 degree rotated equivalents, and I believe those were custom-drawn by the artists at Sega for lack of any good way of generating them)

    So I wrote a little utility to avoid those problems: It can rotate sprites at arbitrary angles without antialiasing and (IMHO) without making them look demented. I call it rotsprite because I suck at inventing names and don't care. It attempts to preserve lines and (to some extent) curves in the original image, it never mixes colors together, and it considers multiple rotation offsets to minimize error. It can optionally scale up or down while rotating.

    It isn't perfect; it minimizes error by a very simple method, but won't try to intelligently recognize and eliminate oddities like a human could. Other, simpler methods may do better for certain parts of the image, but rotsprite output should require much less touch-up work overall. It works best on small images, so the quality of rotation can suffer if you place many sprites in an image and rotate the whole image instead of rotating them separately. Dithering (fine-grained checkerboard patterns) can confuse it because it tries to rotate the pattern itself without considering it a single color, so if you need to rotate something dithered I suggest replacing the dithered parts with solid blended colors before rotation, and replacing those colors with the dithering pattern after rotation.

    The program asks for input when you open it, should be self-explanitory. To use it as a commandline utility, here are the flags:
    rotsprite -in "input.png" -out "output.bmp" -angle 22.5 -endangle 180 -scale 1.0 -endscale 1.0 -frames 8

    Now for some sample output:
    Creating angled frames for an animation without them:
    [​IMG]

    Comparing automatically rotated sprites with Sega's actual final rotated sprites:
    [​IMG]

    More comparison between regular aliased rotation and this program's output:
    [​IMG]

    Fun with upscaling and rotation:
    [​IMG]

    Making a silly animation (64 rotation angles):
    [​IMG]

    If you missed the download link here it is again: http://www.fileden.com/files/2006/12/3/457443/rotsprite.zip
     
  2. Chimpo

    Chimpo

    Happiest Retro Poster Member
    9,415
    2,267
    93
    Los Angeles, 2029
    Banana
    Why didn't you make this before I did my sprites :'(

    Awesome tool though, will make rotation touch ups quick and easy, especially considering how annoying it is when you have to do it for every single frame.
     
  3. Orengefox

    Orengefox

    Snooping as usual... Researcher
    462
    21
    18
    Right in front of my computer.
    Some artwork, a ZZT game, and a hack.
    Egad, that is freakin sweet. I know you were talking about this a couple of days ago as far as rotating sprites and if there were programs out there that could possibly do the job well; but to make a program that specializes in rotating sprites with very little trouble, that was very unexpected. Excellent job of making this nifty program and thanks ^_-
     
  4. Yuski

    Yuski

    Dragons, dragons everywhere! Oldbie
    368
    12
    18
    I officially love you. =P
     
  5. JcFerggy

    JcFerggy

    Do you want to taco 'bout it? Member
    1,396
    103
    43
    This program will help me alot and has re-motivated me to work on my hack again, Thanks!
     
  6. Ultima

    Ultima

    Games Publisher Tech Member
    2,398
    1
    18
    London, England
    Publishing mobile games!
    Fucking nice, dude ;P
     
  7. StephenUK

    StephenUK

    Liquor in the front, poker in the rear Tech Member
    1,678
    0
    16
    Manchester, UK
    Quackshot Disassembly
    I think I'll start working on my hack again and put the sprites in now. Manual rotation was the main thing putting me off from doing it, but this is perfect. Keep it up.
     
  8. jman2050

    jman2050

    Teh Sonik Haker Tech Member
    634
    4
    18
    Holy crap, a rotation program that *works*. I honestly had a bit of trouble telling the difference between rotsprite's output and Sonic's official rotated sprites (the differences are there, but they can easily be touched up). Nifty program.
     
  9. Techokami

    Techokami

    For use only on NTSC Genesis systems Researcher
    1,374
    86
    28
    HoleNet!
    Sonic Worlds Next
    Man, this will be useful in many applications, not just ROM hacking :D
     
  10. Dark Sonic

    Dark Sonic

    Member
    14,631
    1,617
    93
    Working on my art!
    This will come in handy for many people, my self included. Perhaps now I will be arsed enough to change Sonic's sprites in the game. But still, fine job on this and your sprite editor. You continue to amaze all of us with your awesomeness.
     
  11. NickW

    NickW

    Member
    This would definitely come in handy for some people, not me for right now, but still useful none the less.
     
  12. superstarCSB

    superstarCSB

    snootch Member
    621
    0
    16
    Lawrence, Kansas
    I probably should get back to work on my site someday...
    This looks like a nifty little program. I too, seemed to become frustrated in doing sprite edits when I had to try and redraw the sprite at different angles. Hopefully this will motivate me to actually put something out.
     
  13. Kampfer

    Kampfer

    Member
    1,609
    5
    18
    Nice job.

    Its neat stuff like this that makes me wish I had time to re-learn how to hack things. I remeber it was a bitch to try and get my Metal Sonic Sprites to look half way decent for slopes.
     
  14. Xenowhirl

    Xenowhirl

    Tech Member
    175
    0
    0
    I'm glad people are finding this useful and motivating; hopefully someone will put this to better use than I can.

    BTW, even though the main feature is rotation, the scaling is decent compared to point sampling. It's handy if you have some sprites you want to use but they're the wrong size for the game:

    [​IMG]

    The angled ones were made by scaling and rotating at the same time. It looks worse if you rotate and scale separately, so... don't do that. For comparison, here's what normal point sampling/rotation gives:

    [​IMG]
     
  15. Eli White

    Eli White

    Member
    60
    0
    0
    While it's not perfect, it's damn good. Thanks!


    Edit: oops, wrong account. :P
     
  16. Ultima

    Ultima

    Games Publisher Tech Member
    2,398
    1
    18
    London, England
    Publishing mobile games!
    How fast is the algorithm you use for this?
     
  17. Xenowhirl

    Xenowhirl

    Tech Member
    175
    0
    0
    The algorithm is dead simple, so I'll just describe it and you can decide: First it scales the image to 8x size, using a "pixel guessing" algorithm to add detail. Then it scales the image to 1/8 size and also rotates it using standard aliased rotation and scaling. That's basically it. To get a big speed increase for a small penalty in quality, you could use 4x instead of 8x and skip some other optional steps I did, but I wanted high quality above all else.

    Here's the more detailed version: First it scales the image to double size using something similar to Scale2x, but checking if pixels are more similar to each other instead of if they're equal, which makes the result less blocky and ultimately leads to smoother output. The important thing is that the scaling algorithm works by choosing a pixel instead of by blending pixels. It does that 3 times to achieve an 8x scale, determined empirically to be a good place to stop. Then (optional step) it tries to find the best rotation offsets by looping through a small grid of offsets between 0 and 7 pixels in x and y, and for each one looping through the 8x image at the rotation angle with step size 8 pixels, and adding the squared distance of the difference in color components between each point and its immediate (1 pixel) neighbors in the 8x image, which will be 0 except on the boundaries between 8x pixels. Then it simply performs standard nearest-neighbor scaling+rotation, starting at the offsets that gave minimal sum of squared differences, and using 1/8 scale to return the image to normal size while rotating it. Finally (optional step), it tries to fix any overlooked single-pixel details by checking for any pixels in the output image that have 3 or 4 identical neighbors equal to them and unequal to the color at the corresponding place in the source image, and replacing those pixels with the one from the source image.

    You might say I'm cheating by not vectorizing the graphics into lines and curves and rotating those, but I say this method is an approximation of that and works better in practice. When the original image has little detail at the angle it's being sampled, aliased rotation makes too many arbitrary decisions, but the smoothing of a pixel-choosing enlargement algorithm is sufficient to resolve most of the ambiguity.
     
  18. stormislandgal

    stormislandgal

    It's not a phase! Tech Member
    4,534
    10
    18
    Married life <3
    Yes. Now I can finally get back to work on my Tails' sprites. =P
     
  19. ICEknight

    ICEknight

    Researcher Researcher
    Those look like Paint Shop Pro's rotations, but without the background colors interfering. Quite nice.
     
Thread Status:
Not open for further replies.