You're welcome. The code was ripped out of a fax file manager project I wrote a while back. It doesn't make much sense without reading a copy of the TIFF specification, but in a nutshell the code traverses a chain of image directories (basically a linked list) using the while loop. Each image directory contains meta data and pointers for one image, so counting the directories gives you the number of images in the file. Each directory is also parsed for the pointer to the next image directory in the chain. Since TIFF files can be big or little endian, this is detected after the first read so the binary data can be properly unpacked.
Note that the count too high detection is to prevent the possibility of a corrupt file causing an endless loop. It was arbitrarily set to 100, but a TIFF file can have any number of images, so set it to something sensible for your application.