toImage method
Implementation
FlipperImage toImage(img.Image source) {
final xbm = _toXbm(source);
final compressed = heatshrink.compress(xbm);
final framed = Uint8List(compressed.length + 2);
framed[0] = compressed.length & 0xFF;
framed[1] = (compressed.length >> 8) & 0xFF;
framed.setRange(2, framed.length, compressed);
final Uint8List data;
if (framed.length + 2 < xbm.length + 1) {
data = Uint8List(framed.length + 2)
..[0] = 0x01
..[1] = 0x00
..setRange(2, framed.length + 2, framed);
} else {
data = Uint8List(xbm.length + 1)
..[0] = 0x00
..setRange(1, xbm.length + 1, xbm);
}
return FlipperImage(
width: source.width,
height: source.height,
xbm: xbm,
data: data,
);
}