encode method
Encode an image
to an image format.
If singleFrame
is true, only the one Image will be encoded;
otherwise if image has animation, all frames of the image
will be
encoded if the encoder supports animation.
Implementation
@override
Uint8List encode(Image image, {bool singleFrame = false}) {
final output = OutputBuffer();
var format = this.format;
Uint8List pvrtc;
switch (format) {
case PvrFormat.auto:
if (image.numChannels == 3) {
pvrtc = encodeRgb4bpp(image);
format = PvrFormat.rgb4;
} else {
pvrtc = encodeRgba4bpp(image);
format = PvrFormat.rgba4;
}
break;
case PvrFormat.rgb2:
//pvrtc = encodeRgb2bpp(bitmap);
pvrtc = encodeRgb4bpp(image);
break;
case PvrFormat.rgba2:
//pvrtc = encodeRgba2bpp(bitmap);
pvrtc = encodeRgba4bpp(image);
break;
case PvrFormat.rgb4:
pvrtc = encodeRgb4bpp(image);
break;
case PvrFormat.rgba4:
pvrtc = encodeRgba4bpp(image);
break;
}
const version = 55727696;
const flags = 0;
final pixelFormat = format.index - 1;
const channelOrder = 0;
const colorSpace = 0;
const channelType = 0;
final height = image.height;
final width = image.width;
const depth = 1;
const numSurfaces = 1;
const numFaces = 1;
const mipmapCount = 1;
const metaDataSize = 0;
output
..writeUint32(version)
..writeUint32(flags)
..writeUint32(pixelFormat)
..writeUint32(channelOrder)
..writeUint32(colorSpace)
..writeUint32(channelType)
..writeUint32(height)
..writeUint32(width)
..writeUint32(depth)
..writeUint32(numSurfaces)
..writeUint32(numFaces)
..writeUint32(mipmapCount)
..writeUint32(metaDataSize)
..writeBytes(pvrtc);
return output.getBytes();
}