how good is SavePixmapPNG?

BlitzMax Forums/BlitzMax Programming/how good is SavePixmapPNG?

Jesse(Posted 2010) [#1]
I was doing some testing to create a single file with compressed PNG files but the results I got were not what I expected.
My tests included loading a file into a bank to view the size, converting the bank file into an image, extracting the pixmap, compressing the pixmap file back into a PNG and storing the file in a bank.

the problem I am running into is that the newly created PNG is twice as large as the original.
this is the code:
Local bank:TBank = TBank.Load("tileset.png")
Print  bank.size()
Local bank2:TBank = TBank.Create(0)
Local stream:TStream = TBankStream.Create(bank2)
If stream = Null End
Local im:TImage = LoadImage(bank)
Local pixmap:TPixmap = LockImage(im)
SavePixmapPNG( pixmap,stream,9)
Print bank2.size()
Local image:TImage = LoadImage(bank2) 
Graphics 800,600
DrawImage image,0,0
Flip()
WaitKey()


Im I doing something wrong? or is the PNG module a little bit outdated and not as efficient as the current PNG algorithm? the original file algorithm is from the Paint.Net program.

If that is the case, this is going to be useless to me for what I am doing.


xlsior(Posted 2010) [#2]
There are different sub-types of PNG compression, depending on the encoder and its settings.

Even though PNG is a lossless format, the resulting file size can differ based on whether an image is stored in interlaced mode, whether or not it DEFLATEs, whether or not any predictive filters are applied first, whether or not the Alpha channel is included, etc.

Some of those compression methods are more space-efficient, but are much more CPU intensive and will take longer to complete.

If your savepng files end up larger than the original, then it appears that the blitzmax implementation may favor speed over size... It doesn't appear that you can tweak any of the specific features for the output file.


Jesse(Posted 2010) [#3]
Thanks xlsior. I just thought the compression settings would take care of that. Anyway, I already figured out a way to get around it.