Converted ImagePacker from Java to Scala just for fun...