Get access to libjpeg & libpng


#1

Juce has libjpeg and libpng, however ther are just included in one .cpp file. There doesn’t seem to be an easy way for me to get access to them from my code if I need some of their functions. Any easy way to do this?


#2

I am not sure, if I understand your question correctly.

a) you don’t access code inside a source file. The linker as last step is responsible, to put together all executable code into the binary

b) to read Image files, there is the ImageFileFormat. You can use this to load by hand. Use the static method to get the ImageFileFormat: ImageFileFormat::findImageFormatForStream (InputStream &input)

c) The easiest way is to use ImageCache::getFromFile()

The ImageCache keeps a reference to the ImageData, so it doesn’t need reloading. But that also means, if you modify the Image, all further accessing from ImageCache returns the modified version. Use Image::duplicateIfShared() to avoid that.

HTH


#3

I’m trying to access the metadata in jpeg and png images. Juce doesn’t provide functions for that, I wrote my own functions, and every time I update juce I re-add my functions to PNGLoader.cpp and JPEGLoader.cpp. This is a pain, I want to move them to my own submodule, but for that, I need access to libpng/libjpeg.

I started with libpng, to see if I could include “juce_graphics/image_formats/pnglib/png.h” in my code, but all the config for the png library is in PNG_Loader.cpp. I could copy/paste all that config into my code as well, but then if PNGLoader.cpp changes and I don’t notice, the structs could become different and it will break silently. The other option is I could also include the libpng .c files from my code as well, then there would be too versions of libbpng getting compiled (in different namespaces). Probably fine and I only need a few functions so it wouldn’t be to big a deal.

My question was, is there a preferred way to do what I’m trying to do? Or is this unsupported.


#4

Why not make a pull request with the meta-data getters, sounds useful!


#5

Indeed, seems useful!

juce::ImagePixelData supplies a NamedValueSet member called userData. Image::getProperties() allows you to retrieve and edit that set of info.

Seems like you could try to just fill that value set out with the appropriate metadata?


#6

Yeah, having ways to access the (possibly arbitrary) metadata stored in images would be awesome, even more so if it were possible to WRITE that metadata to PNG after it has been altered.
(I’m thinking about adding coordinate markers for e.g. the centre of a knob in all of its frames, etc.)


#7

I got reading metadata working, I’m including a 2nd copy of libpng / libjpeg, kind of a hack, but at least it won’t break if juce is configured to use external libjpeg/libpng. It shouldn’t make the binary too much bigger. I’ll look to see if writing metadata is easy – no promises.

image


Scale 9 Images