python-imaging/Pillow — pull request #179 by manisandro (2013-04-07 23:03:13+00:00)
Title: Make quantization code more portable

The quantization code, as was already noticed before, was written in a way that makes it very fragile (int to void* casts, wrong assumptions on integer variables sizes). These issues caused the quantization code to work incorrectly on big endian, 64bit architectures. This (somewhat huge) patch does two things:
- Replaces all unsigned long type declarations with uint32_t. Code like

typedef union {
struct {
unsigned char r,g,b,a;
} c;
unsigned long v;
} Pixel;

assumes v to be 32bits wide, which is not the case on 64bit. The only reason this worked on 64bit little endian was because the used bits of v actually overlapped with the r,g,b,a bits.
- Removes all the void* to int casts, by using typedefs instead of void* as the type declarations of the hash table entry key and value.
- Properly forward-declares the HashTable and Heap as incomplete structs, instead of using pointer-to-void conversions. This change also exposed previous bugs where void** were used as void*.

Code compiles (without warnings) and passes tests on i686, x86_64, ppc and ppc64.