split gif function into gif.h, refine delay calculation