View previous topic :: View next topic |
Author |
Message |
JNewt
Joined: 05 Jun 2008 Posts: 69
|
Posted: Wed Oct 22, 2008 9:45 am Post subject: LodePNG bug + fix |
|
|
The Problem: The lodepng decode function was loading greyscale images fine for me, but only returning about a quarter of RGBA images. I've traced the issue back to this line in Common.d:
Code: | 312 uint bytesPerPixel(ref PngImage image)
313 {
314 return image.bitDepth / 8;
315 } |
I believe it should read like this:
Code: | uint bytesPerPixel(ref PngImage image)
{
return image.bpp / image.bitDepth;
} |
Fixing this on my local copy and building/installing resolved all my image loading problems, and I thought that it should be reported and fixed. |
|
Back to top |
|
|
Kosmonaut
Joined: 22 Jun 2008 Posts: 10
|
Posted: Thu Oct 23, 2008 6:28 pm Post subject: |
|
|
This doesn't work for all the images. Remember that
It was just lucky that it worked. Anyways there's something not working with LodePng, I doesn't work anymore for me either. |
|
Back to top |
|
|
Kosmonaut
Joined: 22 Jun 2008 Posts: 10
|
Posted: Fri Oct 24, 2008 12:51 am Post subject: |
|
|
DISREGARD THAT... I SUCK... at graphics programming.
The bytesPerPixel method is called when the image is reconstruted, specifically:
Code: |
// lodepng.Decode.d : 150
...
return decompressor.reconstructImage()[0..info.image.width * bytesPerPixel(info.image) * info.image.height];
...
|
The problem is that the bytesPerPixel method returns the bytes per channel (bitDepth = bits per channel), not the bytes per pixel. I think the solution could be:
Code: |
uint bytesPerPixel(ref PngImage image)
{
return image.bpp / 8;
}
|
And now you have the bytes per pixel |
|
Back to top |
|
|
JNewt
Joined: 05 Jun 2008 Posts: 69
|
Posted: Tue Oct 28, 2008 4:56 pm Post subject: |
|
|
As it is possible (albeit unusual) for images to have 16 bit color channels (2 ubytes/channel), I believe my proposed revision is the proper one. The one you've proposed will only work with images with 1 ubyte per channel. |
|
Back to top |
|
|
Lutger
Joined: 25 May 2006 Posts: 91
|
Posted: Sun Nov 02, 2008 6:53 am Post subject: |
|
|
My apology for this bug, I have updated lodepng with a fix. Thanks for bringing it up, nice to know people are actually using it
Kosmonaut had the proper fix, quite the mistake I made.
It also works for 16 bit images, see Decode line 212:
bpp = numChannels(colorType) * bitDepth
thus with 16 bit RGBA bpp will be 4 * 16 == 64 bits and bytesPerPixel will return 64 / 8 == 8 bytes.
I hope to have a bit more time soon to work a bit on lodepng. Please do post here or email me if you find any more problems. |
|
Back to top |
|
|
|