factor out de- and encoding of the PixelFormat structure