ForkandBeard / Alferd-Spritesheet-Unpacker

A spritesheet unpacker/ ripper for Windows
http://www.alferdspritesheetunpacker.forkandbeard.co.uk
MIT License
268 stars 59 forks source link

Optimized RemoveTransparencyFromImage function for better performance. #17

Closed NEstelami closed 7 years ago

NEstelami commented 7 years ago

In the original code, the dictionary transparentPixelsByCoord used a Point as a key. For whatever reason, this causes a significant overhead whenever transparentPixelsByCoord.Add is called. With a large image that has many transparent pixels, the function can take tens of seconds to process. I changed the key type for this dictionary to uint, and created two functions to convert a Point into a uint and back. The x coordinate is stored in the upper region of the int and the y coordinate in the lower. The only limitation with this is that an image can not be bigger than 65535x65535, though I would imagine that in most instances such large images would not be used. However, if bigger resolutions are needed, a ulong can be used instead of an int.