Orientation tag in Exif Jpeg header - C++/Qt code

Getting the orientation of photo in Jpeg format is essential part of most photo viewing programs. This information is contained in one part of Jpeg files - Exif section. The full specification of Exif is complicated and permits many variants. Photo cameras from different vendors and different photo processing programs handle this part in a variety of ways that makes very difficult to implement a parser of Exif part.

In connection with my recent project to create automatic photo collage program I evaluated most well known open source programs for parsing and manipulation of Exif data. They all are complex and don't suit my need to have simple-in-one-file function to get the orientation tag. One of the simple implementations is of Jhead. I extracted from code only the part that gets Orientation. Following code is written in C++/Qt and uses QByteArray. Returned code is the code is -1, 0, 1, ..., 8. Where 1,..,8 is orientation code on success.

exif.cpp exif.h main.cpp

Notes:

Enjoy happy programming.