dispatchFull method
Implementation
@override
Uint8List dispatchFull(Uint8List data, int width, int height) {
int cropTop = 0, cropLeft = 0, cropRight = 0, cropBottom = 0;
final minSize = 10;
// 垂直裁剪
for (int i = 0; i < height - minSize; i++) {
if (checkLine(data.getRange(i * width, (i + 1) * width).toList())) {
cropTop++;
} else {
break;
}
}
for (int i = height - 1; i > cropTop + minSize; i--) {
if (checkLine(data.getRange(i * width, (i + 1) * width).toList())) {
cropBottom++;
} else {
break;
}
}
final newHeight = height - cropBottom - cropTop;
// 横向裁剪
for (int i = 0; i < width - minSize; i++) {
if (checkLine(
List.generate(newHeight, (l) => data[(l + cropTop) * width + i]),
)) {
cropLeft++;
} else {
break;
}
}
for (int i = width - 1; i > cropLeft + minSize; i--) {
if (checkLine(
List.generate(newHeight, (l) => data[(l + cropTop) * width + i]),
)) {
cropRight++;
} else {
break;
}
}
if (cropTop > 0 || cropLeft > 0 || cropRight > 0 || cropBottom > 0) {
_cropRect =
Rect(cropLeft, cropTop, width - cropRight, height - cropBottom);
final newWidth = _cropRect!.width;
final newHeight = _cropRect!.height;
// math.max(math.min(newWidth, newHeight) * 0.1, 10).round();
final padding = 0;
final newData = Uint8List(
(newWidth + padding * 2) * (newHeight + padding * 2),
);
//newData.fillRange(0, newData.length, wrapper);
for (int i = 0; i < newHeight; i++) {
final start = (i + cropTop) * width + cropLeft;
List.copyRange(
newData,
(i + padding) * newWidth + padding,
data,
start,
start + newWidth,
);
}
lastColor = null;
return newData;
}
return data;
}