Search code examples
pythonc++jpegfile-header

Read bunch of JPGs from container


I have a container file which consists of a header (plain text data) and a bunch of JPGs, divided by few tenth of zeroes.

I currently have some code in Python, which do the following:

  • skip zero and header on needed;
  • seeks SOI (0xFF, 0xD8) marker;
  • seeks EOI (0xFF, 0xD9) marker;
  • using feed, from Pillow library, function to read image itself and save to write it to file;
  • repeat until all images saved.

I want to rewrite it in C++, but stuck with reading JPG, I want complete analogue of feed function: C++ library that can read JPG between start and stop from fstream or FILE *.

Is there something like this in boost::GIL? Or any other suggestion.


Solution

  • I myself would use Qt library, specifically QImageReader/QImageWritter. They can read from (and write to) QFile, which can be used to search (and eventually manipulate) the file before image reading.

    Qt gives massive support to construct GUI as well. So you could easily display e.g. image preview to the user, while allowing him to type in file or even path name or easily select them via file browser widget.

    If you plan more high-level work in C++, Qt is my recommended first vote general purpose library. Plenty of opportunities once you make Qt linking (which can be little tricky in non-linux-distro environments, but is doable in day(s) anyways). Qt learning base looks huge at first, but the documentation is great and the curve can be pretty steep.