migrated giflib to C++ idioms to improve memory allocation performance and prevent leaks during progressive loads