The current implementation of putpixel requires that the color passed in for P mode images be an integer.
It would be a useful and reasonable to accept an RGB(A) color, look it up in the palette (or allocate an entry if possible) and then pass that integer into the core putpixel method.