I'm lost here. Your read loop reads raw bytes. The image is a GIF file and a single byte does not correspond to a pixel because GIF uses LZW compression, that's why instead of the image taking up 100x100 = 10000 bytes of space it only uses 437 bytes.

I feel pretty certain that this isn't the issue here and I've misunderstood the problem.