in reply to BMP file manipulation

It seems to me llike you're reinventing an operation called "BitBlt" (short for "Bit BLock Transfer"). There's a few Win32 API calls that exist for it, you might want to check them out, if this is for Windows.

If it's for another platform, I wouldn't necessarily stick to the BMP format. For example, I'm quite sure the image manipulation modules on CPAN (GD, Image::Magick, Imager) support a form of raw pixel data manipulation, perhaps even BitBlt.