'Extract uncompressed TIFF thumbnail.
Take advantage of the pre-existing layout in the thumbnail IFD as
much as possible'

def extract_tiff_thumbnail(self, thumb_ifd):

    thumb = self.tags.get('Thumbnail    Compression')
    if ((not thumb) or (thumb.printable != 'Uncompressed    TIFF')):
        return
    entries = self.s2n(thumb_ifd, 2)
    if (self.endian == 'M'):
        tiff = 'MM\x00*\x00\x00\x00\x08'
    else:
        tiff = 'II*\x00\x08\x00\x00\x00'
    self.file.seek((self.offset + thumb_ifd))
    tiff += (self.file.read(((entries * 12) + 2)) + '\x00\x00\x00\x00')
    for i in range(entries):
        entry = ((thumb_ifd + 2) + (12 * i))
        tag = self.s2n(entry, 2)
        field_type = self.s2n((entry + 2), 2)
        type_length = FIELD_TYPES[field_type][0]
        count = self.s2n((entry + 4), 4)
        old_offset = self.s2n((entry + 8), 4)
        ptr = ((i * 12) + 18)
        if (tag == 273):
            strip_off = ptr
            strip_len = (count * type_length)
        if ((count * type_length) > 4):
            newoff = len(tiff)
            tiff = ((tiff[:ptr] + self.n2s(newoff, 4)) + tiff[(ptr + 4):])
            if (tag == 273):
                strip_off = newoff
                strip_len = 4
            self.file.seek((self.offset + old_offset))
            tiff += self.file.read((count * type_length))
    old_offsets = self.tags['Thumbnail    StripOffsets'].values
    old_counts = self.tags['Thumbnail    StripByteCounts'].values
    for i in range(len(old_offsets)):
        offset = self.n2s(len(tiff), strip_len)
        tiff = ((tiff[:strip_off] + offset) + tiff[(strip_off + strip_len):])
        strip_off += strip_len
        self.file.seek((self.offset + old_offsets[i]))
        tiff += self.file.read(old_counts[i])
    self.tags['TIFFThumbnail'] = tiff
