Just wondering how I can use a checksum to compare two images.
I need to make a small function that would either take in something like an SDL_Surface or an int thats bound to a texture in openGL.
So for SDL i could grab out the pixels from the structure of SDL_Surface or in openGL I could use a function to pull out the pixels of the image.
My problem is how exactly do I use a checksum with them? I can't find many sites with example code for them. The theory of them makes sense but I'm not sure how to implement one. But I'm looking to make one something in the lines of:
bool DoImagesMatch(Image& one, Image& two);
If you have that, you don't need to use a checksum. It's faster to just compare the images themselves.
Start by comparing their dimensions, then their bit depth, then their pitches, then their channel order (e.g. RGB or BGR), and so on until the only thing left is to compare their pixels.
You compare with checksums or hashes when (for whatever reason) you can't have both data sets in memory at the same time, otherwise you just compare the data itself, unless you want to avoid doing the same comparison over and over again.
Well the idea of this one is to stop x number of pictures being loaded. The example I gave up there is something in the lines of what i wanted. But say for the sake being of I need a checksum for an image. How would I go about generating one. I been surfing the web for ages but can't find much.
I did make a function that checks the width, height and pixels and it works fine. But for the sake of what I'm doing I'm required to have a checksum.
Well, I would grab SHA-1 (there's a C++ implementation around by Paul E. Jones, but I can never find it when I need it. I can post links to from in an SVN repository of mine, if you want) and pass it each of the image parameters (you'd have to cast them char pointers, and if you don't do it right you'll reduce the portability of the program), then the pixel data. Then I'd get the result and use that the next time I need to compare an image.
Hashing images loaded as data structures is not the simplest of tasks. If you can hash the original file as a single buffer it'd be a lot easier.