How to hand-create a PhImage_t ?

I want to do something that was not immediately obvious to me
with a PhImage_t object.

As an alternative to a problem posted recently (see “PtDBContainer
question/problem” or “Memory context drawing”), I tried to
do the double buffering myself.

I guaranteed that all images were the same size. I’ll worry about
the palette colors later. I would think something below would work,
but I had trouble with things crashing, probably due to my attempt
to create a PhImage_t incorrectly.

a) create a PhImage_t with enough memory for the proper image size
b) copy in my base image to the image pointer (with memory allocated
in step a).
c) copy in all pixels that are not my transparent color from image 2.
d) copy in all non-transparent pixels from image 3.
e) set my label widget to display the new image
f) repeat the process for the next animation from step b.

Any tips on creating the first image? Any flags to watch out for?
Anyone done something similar? An example would be great.

Thanks in advance,