FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

LodePNG bug + fix

 
Post new topic   Reply to topic     Forum Index -> Scrapple
View previous topic :: View next topic  
Author Message
JNewt



Joined: 05 Jun 2008
Posts: 69

PostPosted: Wed Oct 22, 2008 9:45 am    Post subject: LodePNG bug + fix Reply with quote

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
View user's profile Send private message
Kosmonaut



Joined: 22 Jun 2008
Posts: 10

PostPosted: Thu Oct 23, 2008 6:28 pm    Post subject: Reply with quote

This doesn't work for all the images. Remember that
Code:
1 byte = 8 bits


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
View user's profile Send private message
Kosmonaut



Joined: 22 Jun 2008
Posts: 10

PostPosted: Fri Oct 24, 2008 12:51 am    Post subject: Reply with quote

DISREGARD THAT... I SUCK... at graphics programming. Laughing

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 Smile
Back to top
View user's profile Send private message
JNewt



Joined: 05 Jun 2008
Posts: 69

PostPosted: Tue Oct 28, 2008 4:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
Lutger



Joined: 25 May 2006
Posts: 91

PostPosted: Sun Nov 02, 2008 6:53 am    Post subject: Reply with quote

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 Wink

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Scrapple All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group