Question: Let us take the first one as an example. We read in a 1 2 - byte TIFF tag and find that its identifier field
Let us take the first one as an example. We read in a byte TIFF tag and find that its identifier
field is xF Its data type field will be which means that the data is encoded in an ASCII
string. The number of data items field will tell us how many bytes our string has.
The final field in the tag can contain the value of the data itself if it fits in bytes, or it can
contain an offset to the data elsewhere in the file. Since an arbitrary string cannot fit in bytes,
in our case this value is an offset. Its an offset from the beginning of the TIFF header, which
occurred at byte of the file. So we seek to offset in the file and read each letter from
that position in the file, until we have read them all well encounter a NUL terminator at the
end
At this point, weve read the manufacturer string. We must seek back to the location in the file
where we were reading tags and continue on to the next one.
To make this concrete, say we encounter our Manufacturer String tag while reading bytes
of our file. The tag would be:
xF
The tells us how many bytes the string will be including the NUL terminator The tells us
to seek to bytes from the start of the file the bytes is the offset of the TIFF header
from the start of the file
When we seek to offset we read in Canon the manufacturer of the camera.
We must now seek back to offset so that we can read the next tag in this section.
If we encounter the x identifier, there is an additional Exif block elsewhere in the file. We
can stop reading at this point even if we havent read all count tags because the TIFF format
states that all identifiers must be in sorted order.
We will seek to the offset specified in this Exif sub block tag, again bytes. There, well repeat
the above process one more time to get more specific information about the picture.
First, read in a new count as an unsigned short. Next, loop, reading more byte TIFF tags from
the file.
This time, well be concerned with the following fields:
Tag identifier Data Type Description
xAbit integer Width in pixels
xAbit integer Height in pixels
xbit integer ISO speed
xa fraction of bit unsigned integers Exposure speed
xd fraction of bit unsigned integers Fstop
xA fraction of bit unsigned integers Lens focal length
xASCII String Date taken
The good news is that type means that the value is directly encoded in the last bytes of our
tag and no seeking needs to be done.
Type requires us to behave like we did with the string, but rather than reading several single
byte characters, we will read unsigned ints. Display the ratio of the two numbers as shown in
the example below.
What To Do
For your project you will make a utility that can print the contents of an existing tag, if there.
Make a program called exifview and make it so that it runs with the following command line:
exifview FILENAME
It should print the contents of the EXIF tag to the console if present, or give a message if not
present or readable by our program.
Output
$ exifview imgjpg
Manufacturer: Canon
Model: Canon EOS REBEL SL
Exposure Time: second
Fstop: f
ISO: ISO
Date Taken: ::::
Focal Length: mm
Width: pixels
Height: pixels
Hints and Requirements
We need to treat these files as binary files rather than text files. Make sure to open the
file correctly, and to use fread for IO
You must use a structure to represent a JPEGTIFFEXIF header and another struct to
represent a TIFF tag. Do NOT use a bunch of disjoint variables. Do your fread with the
whole structure at once. That is read an entire tag in one file operation.
If the header field does not contain the Exif string in the right place, print an error
message that the tag was not found. If the TIFF header contains MM instead of II print
an error message that we do not support the endianness.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
