- The bulk of the main function
in my image analysis solution
deals with locating the names of all files
in the current directory twice.
The code starts by opening the current directory.
All directory entries are read
with sub-directories and dotfiles skipped.
When a real file is found, it's displayed as a source.
The read_jpeg function is then called,
which returns zero for a successful read,
or some other value otherwise.
Upon finding a real jpeg file,
the directory is searched again.
Once more directories and dotfiles are skipped.
The current file name is also skipped,
so there's no need to compare a file with itself.
Beyond that, every other file is opened
and compared with the original.
If the compare function returns the value one,
then the current file is flagged as a match.
The cycle then repeats
for every other file in the current directory.
The else condition handles non-jpeg files.
Because I wrote my own error handler,
the error value return from the read jpeg function
let's me choose a proper message to display,
and the program keeps running.
If libjpeg's error handler were used,
the program would just abruptly halt.
Potential improvements to this code could include
specifying command-line arguments
for the variables reduction_factor,
mismatch_percentage, and variation.
That would allow for easier experimentation and fine tuning.
I could also specify a switch
that could recursively scan directories.
It might also be more efficient simply to specify
a single jpeg file as the source
and then compare all other files found,
but to me that wasn't the precise wording
for the assignment,
which is why I chose to use the round robin.