Maybe think about storing the data in a single string
and working it with vec. Vec can be sexy
fast on certain tasks. OTOH, Perl isn't your friend when
it comes to too much bit-twiddling. You likely should take
the other's advice and look at Image::Magick
or PDL. You'll be happier in the end if you can
job image creation out to C routines.