ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm thinking about a program I want to write which will need to read image files of major formats into an array of pixels, as well as info like geometry, bit depth, and gamma value. It needs to preserve as much of the bit depth as is present in the image (e.g. for a 16-bit per color image, I'd need at least 16 bits per pixel). If the format is a lossless one, of course I need perfect pixels.
All the libraries I see out there so far as way overly complex. For specific libraries for specific formats, I would need to add their complexity together if I am to use them. I also looked for something generic. The one I found (MagickWand) was also way overly complex.
I'm looking for something simple. Does it exist? Before I have to dive into the complex mess, I want to exhaust the search for simpler solutions to avoid gumming up my code with a lot of library overhead calls.
Sure, a little bit of overhead is needed in my case. I need to find out the geometry and the bit/byte depth so I can set up an array of pixels. if there are gamma variations, I need to know that, too. Then I just want to read the whole thing in. If it can covert to linear, that's a plus. I'd be happy with it providing 32 bits per color per pixel if it can convert to that.
Any good choices out there? Or do I have to dive into the complex mess (looks so far like MagickWand is it).
The following formats (all variations of these that commonly exist) would be a minimum: bmp, gif, jpeg, png, pnm/ppm, tiff
Take a look at libimlib2. It looks very versatile yet lightweight. I successfully run example code from the documentation distributed with the library. The feh image viewer uses this library, so using it you can easily test whether required file formats are supported or not.
There is another possibility, opencv, but I don't seem to be able to run example program on ubuntu and it is probably an overkill for your purposes anyway. My previous experience with python-opencv was very positive though.
It looks like Imlib (package libimlib2 on Ubuntu) has dependencies on X libraries. There's a requirement I had not thought of. Since my anticipated program needs to run in a server context, this could create some problems. It appears Imlib is intended as a tool for X Windows applications displaying imagery.
I see it does have a bunch of files in the Ubuntu package of type .so that are in a subdirectory called "loaders". It seems there may be some minimally implemented source I could borrow and make a smaller library from, or just toss into my own program. I'll have to check up on the source.
Moreover, I found the following lines in Imlib2.h (from -dev package):
Code:
# ifndef X_DISPLAY_MISSING
# include <X11/Xlib.h>
# endif
So, my conclusion is that Imlib2 may be used without any X libraries installed. To do that you'll need to install libimlib2 on the server, get Imlib2.h header file and use it as follows:
Code:
#define X_DISPLAY_MISSING
#include "Imlib2.h"
You will probably also need to manually create a symbolic link, e.g.
Code:
ln -s /usr/lib/libImlib2.so.1 libImlib2.so
(either in current directory or in /usr/lib)
I have successfully done this on my X-less laptop attached to my 3D printer (a kind of server). At least test program, which converts between different image formats, works.
I suppose there is a way to compile Imlib2 with X_DISPLAY_MISSING defined and install resulting library on a server, but you'll need to install lots of other libraries anyway, so this is actually even harder way to setup the library.
FreeImage is a framework built upon those "specific libraries for specific formats" and provides a unified interface for image manipulations.
Give it a try.
server-46-67/root/x0 /root 2# apt-get install libimlib2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libgif4 libid3tag0 libx11-6 libxau6 libxcb1 libxdmcp6 libxext6
The following NEW packages will be installed:
libgif4 libid3tag0 libimlib2 libx11-6 libxau6 libxcb1 libxdmcp6 libxext6
0 upgraded, 8 newly installed, 0 to remove and 18 not upgraded.
Need to get 892 kB/1,140 kB of archives.
After this operation, 2,827 kB of additional disk space will be used.
Do you want to continue [Y/n]?
I suppose maybe it might need X libs for some image formats. But I really rather have something that focuses on image processing, instead of treating it as an accessory for an X application.
FreeImage is a framework built upon those "specific libraries for specific formats" and provides a unified interface for image manipulations.
Give it a try.
This looks like what I might need. I will check it out.
Code:
server-46-67/root/x0 /root 12# apt-get install libfreeimage3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libilmbase6 liblcms1 libmng1 libopenexr6 libopenjpeg2 libraw5
Suggested packages:
liblcms-utils
The following NEW packages will be installed:
libfreeimage3 libilmbase6 liblcms1 libmng1 libopenexr6 libopenjpeg2 libraw5
0 upgraded, 7 newly installed, 0 to remove and 18 not upgraded.
Need to get 1,911 kB of archives.
After this operation, 5,906 kB of additional disk space will be used.
Do you want to continue [Y/n]?
Seems to not depend on too much, at least for Ubuntu. I will have to check it on Slackware later.
Seems to not depend on too much, at least for Ubuntu. I will have to check it on Slackware later.
The source archive of FreeImage contains the sources of the other image libs (libpng, libOpenEXR etc.) so it's self-contained.
You can find a SlackBuild for it on SBo. BTW, I'm the current maintainer of the script
It looks like FreeImage won't bring in all the bits for 16 bits per color images (what I get when I convert my camera raw images that have 14 bits per color over to PNG). It intentionally divides the 16-bit values by 256. It doesn't say why it divides, but we know that means all you get at most is 8 bits per color. While the images will end up being displayed at 8 bits per color, more bits are needed to avoid quantizing artifacts in the calculations I'll be doing, which involve removing the gamma correction, doing maths on linear values, then re-correcting for the gamma effect (because even new displays expect gamma corrected values by emulating the gamma error of old analog phosphor CRT displays).
FYI, this program idea I have is not limited to operating on my own camera images. That's why I need multi-format import capability (though I doubt GIF would be expected to be imported with any decent quality, since true-color-GIF never caught on, and wasn't very efficient).
I just found on "teh interwebz" a 48bpp TIFF image to perform some tests (for anyone else interested, you can find it on this page).
Although I think FreeImage should handle that color depth, you could also try using OpenImageIO. It has good documentation (even in PDF format) available.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.