benkasminbullock / image-png-libpng

Perl interface to libpng
https://metacpan.org/release/Image-PNG-Libpng
0 stars 2 forks source link

Alien build? #27

Closed PhilterPaper closed 9 months ago

PhilterPaper commented 4 years ago

Would anyone be interested in providing an Alien::PNG build process? If I understand things, it is up to a system owner to provide a suitable libpng.a in the right place. If the Perl system doesn't provide it, and they can't, or it's beyond their abilities, they're out of luck as far as providing PNG image services go. Anyway, there is a Perl system called "Alien" that looks for a library (such as libpng.a) and reports where it is, and if there isn't one, will download and build from official sources. If someone is looking for a "fun" little (?) Alien project to while away the lockdown, this could be quite useful to the community.

Something else I need for my project is a way to separate the A channel (transparency) from RGBA and GA images. That is, RGBA -> RGB + A, and GA -> G + A. Right now I'm using pure Perl code, which is incredibly slow. A entries are packed, and each could be 1 to 16 bits wide. Worst case, I could write my own C module to include with my Perl modules, to perform these functions, but it would be nice if this were integrated into the wrapper, either as a standalone function, or a flag to work on the image being returned. Any takers? If not, I might be able to provide patches to the wrapper, if the owner would be willing to consider putting them in. Note that this is separate from providing the libpng.a file (Alien::PNG).

benkasminbullock commented 4 years ago

Something else I need for my project is a way to separate the A channel (transparency) from RGBA and GA images. That is, RGBA -> RGB + A, and GA -> G + A. Right now I'm using pure Perl code, which is incredibly slow. A entries are packed, and each could be 1 to 16 bits wide. Worst case, I could write my own C module to include with my Perl modules, to perform these functions, but it would be nice if this were integrated into the wrapper, either as a standalone function, or a flag to work on the image being returned. Any takers? If not, I might be able to provide patches to the wrapper, if the owner would be willing to consider putting them in. Note that this is separate from providing the libpng.a file (Alien::PNG).

Are you using Image::PNG::Libpng to do this at the moment? Can you post the Perl code you are using?

benkasminbullock commented 4 years ago

Would anyone be interested in providing an Alien::PNG build process? If I understand things, it is up to a system owner to provide a suitable libpng.a in the right place. If the Perl system doesn't provide it, and they can't, or it's beyond their abilities, they're out of luck as far as providing PNG image services go. Anyway, there is a Perl system called "Alien" that looks for a library (such as libpng.a) and reports where it is, and if there isn't one, will download and build from official sources. If someone is looking for a "fun" little (?) Alien project to while away the lockdown, this could be quite useful to the community.

I don't have plans to do this at the moment but feel free to send a push request.

PhilterPaper commented 4 years ago

I was just told there is an Alien::PNG already, but I don't know if it builds the right libpng.a for use with Image::PNG::Libpng. If it does, perhaps you could update the build process for Image::PNG::Libpng to not just assume libpng.a exists, but use Alien::PNG to find where it is OR build it from official sources. Hopefully most of the work (of building it) has been done for you already.

benkasminbullock commented 4 years ago

I was just told there is an Alien::PNG already, but I don't know if it builds the right libpng.a for use with Image::PNG::Libpng.

Usually we would be using the shared object version of the libpng. Image::PNG::Libpng does not require a certain version of libpng.

Hopefully most of the work (of building it) has been done for you already.

Can I ask why you have not tried it yourself?

PhilterPaper commented 4 years ago

Are you using Image::PNG::Libpng to do this at the moment? Can you post the Perl code you are using?

Yes, it's in use with PDF::Builder. The code is https://github.com/PhilterPaper/Perl-PDF-Builder/blob/master/lib/PDF/Builder/Resource/XObject/Image/TIFF_GT.pm . I think that's the only code directly calling Image::PNG::Libpng.

Can I ask why you have not tried it yourself?

I'm just starting to look at Alien and its usage, and I'm hoping that someone out there has some real experience with it, before I start putting out a package where I don't quite know what I'm doing!

benkasminbullock commented 4 years ago

This Perl module doesn't have any other watchers besides me, so if you post issues here, the only person who will see them will be me. Sorry but I don't have any experience with Alien::PNG so it's up to you to work that out. Failing that you could try the usual forums like Perlmonks and Stackoverflow. Good luck with it.

benkasminbullock commented 4 years ago

Yes, it's in use with PDF::Builder. The code is https://github.com/PhilterPaper/Perl-PDF-Builder/blob/master/lib/PDF/Builder/Resource/XObject/Image/TIFF_GT.pm . I think that's the only code directly calling Image::PNG::Libpng.

Thanks, I'll have a look at that later on and see if there is anything that occurs to me.

benkasminbullock commented 4 years ago

The link seems to be this one:

https://github.com/PhilterPaper/Perl-PDF-Builder/blob/master/lib/PDF/Builder/Resource/XObject/Image/PNG_IPL.pm

benkasminbullock commented 4 years ago

Is this the code you were writing about?

https://github.com/PhilterPaper/Perl-PDF-Builder/blob/master/lib/PDF/Builder/Resource/XObject/Image/PNG_IPL.pm#L455-L464

PhilterPaper commented 4 years ago

Ah yes, PNG_IPL is the one in question, and the lines concerning vec() usage are the guilty ones. Sorry about that, Chief! I'm also trying to get the TIFF support (Graphics::TIFF) updated in the same way, and suffered a senior moment. :-(

If you can see an obviously faster way to do it besides vec(), I'm all ears. I tried a few other ways (substr, etc.) that either were even slower, or got messed up with the binary data.

benkasminbullock commented 4 years ago

OK, I didn't even know there was a "vec" function within Perl until today. I will try and look at this code in its entirety to see if there are better ways to do these things within libpng.

benkasminbullock commented 4 years ago

I don't see a function to do this in libpng, so I think what I'll do is implement something in C. I'm going to close this issue and open another one.

https://github.com/benkasminbullock/image-png-libpng/issues/29

benkasminbullock commented 4 years ago

I'll reopen this issue since you don't seem satisfied. This discussion is for the Alien::PNG and the other one is for the alpha separation discussion.

benkasminbullock commented 3 years ago

I tried Alien::PNG before and thought it wasn't suitable for use since it prompted the user. I've just tried it again and found that the prompt seems to be gone, so I'll try again on including this in the build script for Image::PNG::Libpng.

benkasminbullock commented 9 months ago

This issue is now rather stale, I'll close it again.