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 12-byte TIFF tag and find that its identifier
field is 0x010F. Its data type field will be 2, 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 4 bytes, or it can
contain an offset to the data elsewhere in the file. Since an arbitrary string cannot fit in 4 bytes,
in our case this value is an offset. Its an offset from the beginning of the TIFF header, which
occurred at byte 12 of the file. So we seek to 12+ 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 22-34
of our file. The tag would be:
0x010F 26158
The 6 tells us how many bytes the string will be (including the NUL terminator). The 158 tells us
to seek to 158+12 bytes from the start of the file (the 12 bytes is the offset of the TIFF header
from the start of the file).
When we seek to offset 170, we read in Canon, the manufacturer of the camera.
We must now seek back to offset 34 so that we can read the next tag in this section.
If we encounter the 0x8769 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 +12 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 12-byte TIFF tags from
the file.
4
This time, well be concerned with the following fields:
Tag identifier Data Type Description
0xA0024(32-bit integer) Width in pixels
0xA0034(32-bit integer) Height in pixels
0x88273(16-bit integer) ISO speed
0x829a 5(fraction of 232-bit unsigned integers) Exposure speed
0x829d 5(fraction of 232-bit unsigned integers) F-stop
0x920A 5(fraction of 232-bit unsigned integers) Lens focal length
0x90032(ASCII String) Date taken
The good news is that type 4 means that the value is directly encoded in the last 4 bytes of our
tag and no seeking needs to be done.
Type 5 requires us to behave like we did with the string, but rather than reading several single-
byte characters, we will read 2 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 img1.jpg
Manufacturer: Canon
Model: Canon EOS REBEL SL1
Exposure Time: 1/80 second
F-stop: f/2.8
ISO: ISO 2000
Date Taken: 2013:08:2022:23:45
Focal Length: 40 mm
Width: 512 pixels
Height: 768 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 I/O.
5
You must use a structure to represent a JPEG/TIFF/EXIF 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!