Sprite resizing - .png format images

Discuss anything ZDoom-related that doesn't fall into one of the other categories.

Sprite resizing - .png format images

Postby ReX » Fri Feb 22, 2008 2:11 pm

I am trying to create sprites from a model. I have taken screenshots of a model using a model viewer, which gives the pictures in .tga format, but result in massive file sizes (2.5 MB each). I can convert them to .png format with negligible loss in resolution & color depth, and each picture becomes about 30 - 50K in file size, but the dimensions are quite large. This is not an issue, as I can scale them down in-game in GZDooM. However, if I try to reduce the file size further by resizing each .png image, it messes up the transparency. This is because it is sampling the colors using the recommended algorithm (Lanczos), and it is creating approximations of the transparency color (in this case, RGB = 68 130, 132) around the object in the picture. In other words, even though the main picture will have a transparency, there will be a bluish edge around the sprite. I suspect that the problem will occur no matter what algorithm is used.

So here's my question: Is there a relatively easy way to resize a .png format image without creating these approximations of the transparency color? This would require the program to scale the image down without resampling the colors.
User avatar
ReX
Title? I don't need no steenkin' title!
 
Joined: 05 Aug 2003
Location: Quatto's Palace

Re: Sprite resizing - .png format images

Postby Enjay » Fri Feb 22, 2008 2:25 pm

I'm sure someone once posted a much better way to do it than this (so hold fire for other input) but, with Paint Shop Pro at least, you can specify "pixel resize" which doesn't average out the pixels as it resizes the image. This has an advantage and (sometimes) a disadvantage. The advantage is that the edge is always clean and does not show the pixel smoothing effect. The disadvantage is that the same effect is also applied to the rest of the image so you don't get the averaging/smoothing effect anywhere else either. Like I said, that may or may not be a problem and I've often found that it's fine and that GZdoom does a nice job of smoothing things out anyway.

I'm sure most other graphics tools will have something similar. Some of them will default to the averaging effect for true colour images and "pixel resize" for 256 colour images. So you might want to try reducing the colour depth before resizing to see if that works and looks OK or not.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
Joined: 15 Jul 2003
Location: Scotland

Re: Sprite resizing - .png format images

Postby ReX » Fri Feb 22, 2008 3:08 pm

I am using XnView, a free graphics editing program. Unfortunately, it does not have a pixel resize option.

[EDIT: I do, however, have Wally, which allows a "high quality resize". I reduced the dimensions by 75%, the file size dropped from 55K to 8K, and there were no color approximations. All is well with the world.]
User avatar
ReX
Title? I don't need no steenkin' title!
 
Joined: 05 Aug 2003
Location: Quatto's Palace

Re: Sprite resizing - .png format images

Postby bagheadspidey » Fri Feb 22, 2008 3:32 pm

ReX, here's what you can do about those edges - get rid of that background color before resizing. Meaning, make all those pixels transparent. Then, instead of semi-blue semi-transparent pixels around the edges, you will just have nice anti-aliased semi-transparent pixels when you resize (if using a method like Lanczos).

I believe png alpha channels (partial transparency) are properly supported in the newest gzdooms, but not totally sure...

Anyway, since I assume you have a lot of these images to deal with, if you like I can make you a "custom edition" of this tool for batch resizing those pngs. Should take less than 10 minutes to get ready from this point, so it's really not a big deal - if you want it, just let me know.
User avatar
bagheadspidey
 
Joined: 20 Oct 2007

Re: Sprite resizing - .png format images

Postby Enjay » Fri Feb 22, 2008 3:40 pm

I thought about suggesting that but it requires leaving the images in "true colour" format (as far as I know) and so the file size will not be as small: which is ReX's goal.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
Joined: 15 Jul 2003
Location: Scotland

Re: Sprite resizing - .png format images

Postby bagheadspidey » Fri Feb 22, 2008 4:02 pm

Oh yeah, we never got imagemagick save true color on windows did we =/ Well, paletted sprites at half the size should still be a lot smaller than the original true color sprites... Of course they would use their own palette, not the doom palette. Not that that is a problem.

The only change to that tool that would really be needed would be making it read pngs, which would take like 5 seconds.

Anyway, the general principle still applies - get rid of that color before you resize. I don't think PNG knows what a transparency color is (like GIF does) or at least it isn't widely used... PNG supports 24 bit alpha channel in 24 bit (true color) mode, and 8-bit alpha channel in indexed mode. So, in other words those "transparent" pixels always have RGB values as well, so unless they are totally transparent that resizing algorithm is going to blend the color with the one next to it.
User avatar
bagheadspidey
 
Joined: 20 Oct 2007

Re: Sprite resizing - .png format images

Postby Enjay » Fri Feb 22, 2008 4:26 pm

Here's a side question - How on earth do I make an alpha chanel? I mean, if I want to make a sprite with varying transluceny by using the alpha chanel, what do I do?
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
Joined: 15 Jul 2003
Location: Scotland

Re: Sprite resizing - .png format images

Postby bagheadspidey » Fri Feb 22, 2008 4:44 pm

Enjay wrote:I want to make a sprite with varying transluceny by using the alpha chanel, what do I do?


Ok, first of all no image editor I can think of can do this properly in indexed mode (ie when working with a paletted image). Formats like PNG support 8 bit RGBA, but PS, PSP, GIMP, etc don't work like that. You have to be working in true color mode; convert the image to true color (called RGB in gimp).

[PS, PSP, GIMP, etc] have a concept of a background layer. They are treated weirdly. Look in layers dialog, duplicate that background layer and delete the original. Now you can start using alpha transparency...

Select-by-color, select "transparent" color, hit delete (try ctrl-x if that didnt work)
Get out the erase tool*, try it out. It should seem kind of "pressure sensitive".
Make a new layer, get out brush tool, pick fuzzy-edged brush, draw on transparent area.
etc...

When you are done if you must have paletted PNG, you can use a utility like pngquant (or imagemagick) to convert 24 bit rgba png to 8 bit indexed rgba png.

edit - in reply to enjay's next comment to keep this from going too far off topic ;) - * erase tool works very similarly in all three programs. Here's another description. You can't draw transparency "subtractively" any other way that I know of, it just draws transparency over whatever's there with the brush, pencil, etc tools. Gotta use E.
Last edited by bagheadspidey on Fri Feb 22, 2008 5:08 pm, edited 1 time in total.
User avatar
bagheadspidey
 
Joined: 20 Oct 2007

Re: Sprite resizing - .png format images

Postby Enjay » Fri Feb 22, 2008 4:57 pm

OK, I get it (I think). I'd tried something similar before but I simply can't (and still can't) figure out how to get the tools in PSP to draw with the transparent colour. I just managed in PS though so I guess I'll just have to familiarise myself a bit more with that prog. Probably no bad thing. Mind you, if you know how to select transparency as the "colour" to draw with in PSP 7.04 that would be very useful too.

Oh, and I am happy enough to work with true colour pngs if they do a particular job best. I just normally work with paletised ones for ease (in certain situations) and file size.
User avatar
Enjay
Everyone is a moon, and has a dark side which he never shows to anybody. Twain
 
Joined: 15 Jul 2003
Location: Scotland

Re: Sprite resizing - .png format images

Postby bagheadspidey » Fri Feb 22, 2008 9:19 pm

I think this is somewhat on topic as it concerns png filesize ;)

I just did a little test of a utility called pngcrush...
Spoiler: stuff


The 24 bit images compress a lot better than the 8 bit ones, and can be smaller than 8 bit images (like in this case) when you compress them. Of course, the original bitmap was a 256 color image to begin with - you might not get as good results if you were using more colors in your source image... but then again, you might. Whenever I get that batch tool to save true color pngs under windows I will definitely be adding pngcrush to it, so the output files will be as small as possible =)

edit - just noticed the "Wally" cross post, glad you found a solution.
User avatar
bagheadspidey
 
Joined: 20 Oct 2007

Re: Sprite resizing - .png format images

Postby ReX » Sat Feb 23, 2008 11:09 am

Thanks for the suggestions, Spidey & Enjay.

After my last post I took a break and went back into Wally to resize the remainder of my sprite frames. I had only resized one image when I made that post, and when I got gack to my resizing task I ran into an unexpected problem - Wally did not give me the option of reducing my second image. Thankfully I figured out the solution. It turns out that Wally cannot shrink an image if the canvas size dimensions are not in multiples of 16. [The first image must have had the right dimensions, which is why it worked fine.] Fortunately, there's a handy tool right in Wally to increase the canvas size dimensions to the nearest multiple of 16. After that the shrink works just fine, but you still need to crop the dark edge created by Wally when expanding the canvas, and you need to enable transparency again.

Although it works, the down side is that each image has to be manipulated individually using my method and tools (XnView + Wally). It is a mind-numbingly tedious process (not to mention the same tedium when manually applying x- and y-offsets to the sprite in XWE), and I will try out pngcrush when I have a chance.

The good news is that I now have a hi-res set of sprite frames for an enemy in my project. You shall all bow before its awesome awsomeness (or is it awsometude?) :twisted:
User avatar
ReX
Title? I don't need no steenkin' title!
 
Joined: 05 Aug 2003
Location: Quatto's Palace


Return to General

Who is online

Users browsing this forum: No registered users and 3 guests