Thread: Image Formats (In Memory) And Poppler

  1. #1
    Registered User TangoOversway's Avatar
    Join Date
    Mar 2013
    Posts
    20

    Image Formats (In Memory) And Poppler

    I know this is a newbie question and I don't mind doing more research, but I'd like to know what to work with. Right now I feel I could go in a dozen directions and I want to narrow that down so I don't spend days looking at information that won't help me.

    I'm new to C++ and before now the only graphics programming I've done was to load in an image to display in a Java panel.

    I have been using Poppler to do some simple work with PDFs. I'd like to be able to use it to display PDFs as well. While there is a Qt wrapper for Poppler, I can't use it for a number of reasons. (For starters, the wrapper is for Qt 4 and Qt is now at version 5, but there's more reasons.)

    However, I can use Poppler to render an image of a PDF. From there, I can access the image in memory or write it out in a number of specified formats, like jpg or png. (The reference for this image class is here: https://oinksoft.com/doc/poppler/cpp..._1_1image.html).

    I know, to do this, I'll have to learn more about graphics programming and image handling, but I don't want start tracking down graphics libraries and reading up on ones that are totally unrelated to anything I might need, since that might take days until I find the format I need.

    I notice there is information in the documentation of the image class to indicate what kind of format the data must be in for an image. Is there enough there to know if this is a typical way image data is stored in memory in C++? Is this format compatible with any other library or GUI toolkit? Is there any way of knowing how easy it would be to take the date from this image and convert it into something useable by another library?

    And, in a much broader and more useful sense for me, as I try to learn this: Are there standard ways most C or C++ programmers would store image data within memory? I know there will always be exceptions, but is there any "normal" way to store image data while the image is in memory?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Do you have to use Qt5?

    The "normal" way is uncompressed RGB values, row by row, pixel by pixel, going left to right, top to bottom. This is the most suitable for fast blitting to the screen or accessing parts for mutation. Sometimes bottom to top is used for historical reasons - in particular, some image formats expect this layout (BMP for example).

    Of course, if you have a LOT of images, you might want to keep some of them compressed and only keep uncompressed versions of those that are needed right now. Web browsers for example do this.

    In your particular situation, I would a) see if the Qt poppler support isn't available for Qt5 too (possibly in an unreleased version in the repository). It pretty much has to be, because KDE5 is in the works, and it uses poppler for its PDF viewer. And if that fails, b) don't write out the image, just copy the data directly from the poppler image to a Qt image buffer (QImage class). Actually, do that even if you want to write out the image - QImage has a nice save() method.

    Actually, it appears that poppler image can have different formats. You probably don't need to understand them, just find the equivalency between the image::format_enum constants and the QImage::Format constants. I suggest format_mono == Format_Mono, format_rgb24 == Format_RGB888, format_argb32 == Format_ARGB32. (Wow, that was complicated. )
    Last edited by CornedBee; 04-10-2013 at 05:47 AM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User TangoOversway's Avatar
    Join Date
    Mar 2013
    Posts
    20
    I've (tried to) talk to the Poppler people on IRC. They're not exactly tolerant of newbies still figuring things out. But one issue with Qt is that there isn't a Qt 5 wrapper for Poppler yet. Also, I downloaded Qt Creator and that installs, but it puts all the Qt libs in the Qt directory tree it creates in my home directory, and not in /usr/local/lib or /usr/lib. I've tried downloading just the libraries and installing them with the usual ./configure && make && make install (there's a few options to include there, too), but it won't get past the make command. I've asked for help on the Qt forums, but my post has been there a week with no answers. (Also, it seems very few there use OS X and, as a group, they seem to think it's an unknown from some comments I've read.) I subscribe to the Poppler mailing list and haven't seen any indication that they have the wrapper upgraded yet.

    My thought, and I didn't want to get into all the details in my question (since I know I can get long winded), is that if the Poppler image is in a compatible format (or easily and quickly converted to one), that I could convert a PDF page to the image, then display the image. I figure that's what the wrapper does anyway. So I was hoping to do just what you suggested - find a library (which could be Qt or even Wx) where I could just copy the data or point to it and use that for the image to display.

    You're probably right on target with the comparison between Poppler's formats and Qt's, but I wasn't sure whether Poppler was using their formats, or another library and converting and didn't want to spend a week tracking down different graphics libraries to find out just which one they used.

    I'm working on an e-reader. I used to run a business based on my software (in Perl and Java), where I had to learn fast and learn what I needed and move on (which is why I didn't learn C++ back then), but that allowed me to retire and now I write. I, and some writer friends, don't like sending our material over email for sharing, so I'm writing an e-reader where the PDFs we create are encrypted except when in memory. In it I decrypt the PDF as I load it, then I'd render the current page, and the next and previous 2-3 pages at a time, so it's limited memory use, but allows the user to page through without waiting for rendering. The Qt wrapper would have been nice to use, but without it, I'm learning more!


    Thank you!

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Try macports or homebrew or something like that for Macs, they often have -dev packages as well.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User TangoOversway's Avatar
    Join Date
    Mar 2013
    Posts
    20
    I was using macports for a while, but it turned into a nightmare. Updates would help one program and crash the other and I never could count on programs to work after updates. I'm not trying to slam the system or programmers - that's a LOT of material to maintain and it's a great piece of work, but sometimes something would break. I like macports, but it was just hard to keep up with. Thanks for the suggestion, though!

    I figure if I can use Poppler and get the image from there, I can add the Qt library directories in my home directory to the build path in Eclipse. I can still use them together, they just won't interact. It's not much more code anyway, since I'm buffering 2-3 pages before and after the current one and it also won't be an issue later, when Qt goes from 5 to 6 and Poppler needs a new wrapper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-13-2013, 08:31 PM
  2. Compilable image formats
    By parad0x13 in forum C++ Programming
    Replies: 23
    Last Post: 03-10-2009, 08:20 PM
  3. Custom image file formats..
    By IKG in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2007, 08:56 PM
  4. Can't allocate enough memory for image data
    By slowcoder in forum C Programming
    Replies: 5
    Last Post: 08-06-2006, 05:13 AM
  5. Loading an image into memory using OpenGL
    By Kaelin in forum C++ Programming
    Replies: 3
    Last Post: 02-08-2005, 12:03 PM

Tags for this Thread