Factorize pixel cast and implement SOLARUS_SCREEN_DOUBLEBUF flag