PNG Crop
Moderator: Graphics Moderators
- coyoteelabs
- Engineer
- Posts: 27
- Joined: 07 Aug 2006 09:52
- Location: Romania
PNG Crop
PNG Crop is a small program designed for the purpose of cropping PNG sprites used in OpenTTD 32bpp.
It offers 2 methods for cropping:
* automatic mode - automatically crops as much as possible from the sprite reducing it to its smallest size possible
(like Visual PNG codec crop tool). Alpha tolerance option is included.
* manual mode - manually specify cropping coordinates (top left corner and width/height)
PNG Crop can also crop the sprite masks using the same values used for the actual sprite.
If the sprites contain x_offs and y_offs, PNG Crop will adjust these values accordingly.
License: GPL v2 or later
Special thanks to Zephyris for the idea and initial testing.
Version 0.3.1 released
* fixed offset detection
It offers 2 methods for cropping:
* automatic mode - automatically crops as much as possible from the sprite reducing it to its smallest size possible
(like Visual PNG codec crop tool). Alpha tolerance option is included.
* manual mode - manually specify cropping coordinates (top left corner and width/height)
PNG Crop can also crop the sprite masks using the same values used for the actual sprite.
If the sprites contain x_offs and y_offs, PNG Crop will adjust these values accordingly.
License: GPL v2 or later
Special thanks to Zephyris for the idea and initial testing.
Version 0.3.1 released
* fixed offset detection
- Attachments
-
- pngcrop_v0.3.1.zip
- PNG Crop 0.3.1 binaries
- (261.98 KiB) Downloaded 286 times
-
- pngcrop_source_v0.3.1.zip
- Delphi 2010 GPL'd source code
- (326.83 KiB) Downloaded 262 times
Last edited by coyoteelabs on 02 Mar 2010 07:25, edited 1 time in total.
Visual PNG codec - Win32 GUI based alternative for PNG codec
PNG crop - Win32 Console based tool for PNG cropping
PNG Resize - Win32 Console based tool for PNG Resizing (z0 -> z1 / z2)
Re: PNG Crop
One minor problem, it seems v0.3 doesn't write the new offset data...
*edit* This also happens when autocrop also makes a change to the size of the sprite.
*edit* This also happens when autocrop also makes a change to the size of the sprite.
- Attachments
-
- pngcropbug.png (40.78 KiB) Viewed 6192 times
- coyoteelabs
- Engineer
- Posts: 27
- Joined: 07 Aug 2006 09:52
- Location: Romania
Re: PNG Crop
Uh, looks like the changes I made to the detection code were causing the program to think that there weren't any offsets. That's why it didn't write them.
Fixed it in 0.3.1. Redownload from 1st post.
Fixed it in 0.3.1. Redownload from 1st post.
Visual PNG codec - Win32 GUI based alternative for PNG codec
PNG crop - Win32 Console based tool for PNG cropping
PNG Resize - Win32 Console based tool for PNG Resizing (z0 -> z1 / z2)
Re: PNG Crop
Checked it on the GRVTS sprites and all seems good, it shaves a good bit of the file size!
-
- Tycoon
- Posts: 1828
- Joined: 10 Jul 2006 00:43
- Location: Spain
Re: PNG Crop
It could help to code de bridges easier and faster. Thanks.
Sorry if my english is too poor, I want learn it, but it isn't too easy.
- [list][*]Why use PNG screenshots in 8 bpp games.
[*]Caravan site New Industry. · Spain set. · Some spanish trains for locomotion[*]Favourites:GRVTS · ECS · FIRS
-
- Tycoon
- Posts: 1828
- Joined: 10 Jul 2006 00:43
- Location: Spain
Re: PNG Crop
PNG crop was very useful to code all latest sprites (papermill, oil wells, coal mines, latest Spain set sprites......) I will use it with airport sprites. But there is a problem: we need to make z1 and z2 sprites, not only z0 sprites. All the l
I suggest a program like PNG crop to make the zoom levels z1 and z2 from a sprite with only z0. My idea is that we need a program to make the z1 and z2 levels from all existing sprites. It would make easier this.
This is the correct way to scale the sprites without problems of subpixel offsets in end images:
http://www.tt-forums.net/viewtopic.php?p=872954#p872954
Maybe, this sourcecode (writen by me) could be useful. You can use it freely
I think that the image doesn't need to be scaled in horizontal and vertical directions at the same time. This would make less complex to add the additional lines needed if the offsets are not 0.
It would be nice if the program adds lines to a file called "Output.txt", adding the offsets used in each sprite, and allowing to convert it into a batch file.
I suggest a program like PNG crop to make the zoom levels z1 and z2 from a sprite with only z0. My idea is that we need a program to make the z1 and z2 levels from all existing sprites. It would make easier this.
This is the correct way to scale the sprites without problems of subpixel offsets in end images:
http://www.tt-forums.net/viewtopic.php?p=872954#p872954
Maybe, this sourcecode (writen by me) could be useful. You can use it freely
Code: Select all
This function mixes the values of two pixels. Maybe It could be optimized with operations like ">>1" and ">>9" instead of /2 and /512.
void mix_pixels(int redA, int greenA, int blueA, int alphaA, int redB, int greenB, int blueB, int alphaB, int *redF, int *greenF, int *blueF, int *alphaF){
if (alphaA == 0 & alphaB == 0){
alphaF =0;
}else{
if (alphaA == 1 & alphaB == 1){
alphaF =1;
redF = (redA + redB) /2;
greenF = (greenA + greenB) /2;
blueF = (blueA + blueB) /2;
}else{
alphaF = (alphaA + alphaB) / 512;
redF = (redA*alphaA + redB*alphaB) / 512;
greenF = (greenA*alphaA + greenB*alphaB) / 512;
blueF = (blueA*alphaA + blueB*alphaB) / 512;
}
}
It would be nice if the program adds lines to a file called "Output.txt", adding the offsets used in each sprite, and allowing to convert it into a batch file.
Sorry if my english is too poor, I want learn it, but it isn't too easy.
- [list][*]Why use PNG screenshots in 8 bpp games.
[*]Caravan site New Industry. · Spain set. · Some spanish trains for locomotion[*]Favourites:GRVTS · ECS · FIRS
Re: PNG Crop
When scaling images, this may be an interesting article to read. It turns out that combining pixels may not be as trivial as one would think.
http://www.4p8.com/eric.brasseur/gamma.html
http://www.4p8.com/eric.brasseur/gamma.html
Create your own NewGRF? Check out this tutorial!
Re: PNG Crop
Interesting article! Did some tests in PaintShop Pro 7.0, and it indeed does scaling wrong (as most other software).
But, using the simple algorithm:
- apply gamma 0.454545
- resize
- apply gamma 2.2
makes everything look good enough.
But, using the simple algorithm:
- apply gamma 0.454545
- resize
- apply gamma 2.2
makes everything look good enough.
Re: PNG Crop
Built-in support for automatic resizing be excellent...
-
- Tycoon
- Posts: 1828
- Joined: 10 Jul 2006 00:43
- Location: Spain
Re: PNG Crop
Now OpenTTD has automatic resizing, but the problem is that It's slow and It doesn't give a great quality, because It only resizes the sprites.Zephyris wrote:Built-in support for automatic resizing be excellent...
Sorry if my english is too poor, I want learn it, but it isn't too easy.
- [list][*]Why use PNG screenshots in 8 bpp games.
[*]Caravan site New Industry. · Spain set. · Some spanish trains for locomotion[*]Favourites:GRVTS · ECS · FIRS
Re: PNG Crop
I meant for png crop... lol
-
- Tycoon
- Posts: 1828
- Joined: 10 Jul 2006 00:43
- Location: Spain
Re: PNG Crop
I'm understand.Zephyris wrote:I meant for png crop... lol
Yes, It is a great idea.
Sorry if my english is too poor, I want learn it, but it isn't too easy.
- [list][*]Why use PNG screenshots in 8 bpp games.
[*]Caravan site New Industry. · Spain set. · Some spanish trains for locomotion[*]Favourites:GRVTS · ECS · FIRS
- coyoteelabs
- Engineer
- Posts: 27
- Joined: 07 Aug 2006 09:52
- Location: Romania
Re: PNG Crop
Glad you found it useful.maquinista wrote:PNG crop was very useful to code all latest sprites (papermill, oil wells, coal mines, latest Spain set sprites......) I will use it with airport sprites.
Interesting idea, I'll see if I can make one (unfortunately i am extremely busy these days so my programming time is limited )maquinista wrote:But there is a problem: we need to make z1 and z2 sprites, not only z0 sprites. All the l
I suggest a program like PNG crop to make the zoom levels z1 and z2 from a sprite with only z0. My idea is that we need a program to make the z1 and z2 levels from all existing sprites. It would make easier this.
Most likely, I'll make it as a separate app as that would require less programming time
I'll try to add the logging function this monday if time permits it.maquinista wrote: It would be nice if the program adds lines to a file called "Output.txt", adding the offsets used in each sprite, and allowing to convert it into a batch file.
Visual PNG codec - Win32 GUI based alternative for PNG codec
PNG crop - Win32 Console based tool for PNG cropping
PNG Resize - Win32 Console based tool for PNG Resizing (z0 -> z1 / z2)
- coyoteelabs
- Engineer
- Posts: 27
- Joined: 07 Aug 2006 09:52
- Location: Romania
Re: PNG Crop
As requested, here is PNG Resize
Visual PNG codec - Win32 GUI based alternative for PNG codec
PNG crop - Win32 Console based tool for PNG cropping
PNG Resize - Win32 Console based tool for PNG Resizing (z0 -> z1 / z2)
Who is online
Users browsing this forum: Google Adsense [Bot] and 82 guests