first commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/// Clockwise degrees that turn a camera buffer upright on screen.
|
||||
///
|
||||
/// Same compensation ML Kit uses for the Android camera plugin:
|
||||
/// back camera `(sensor - device) mod 360`, front camera `(sensor + device) mod 360`.
|
||||
int uprightClockwiseDegrees({
|
||||
required int sensorOrientation,
|
||||
required int deviceDegrees,
|
||||
required bool frontCamera,
|
||||
}) {
|
||||
if (frontCamera) {
|
||||
return (sensorOrientation + deviceDegrees) % 360;
|
||||
}
|
||||
return (sensorOrientation - deviceDegrees + 360) % 360;
|
||||
}
|
||||
|
||||
/// Maps a pixel of the upright image back to the raw camera buffer.
|
||||
(int x, int y) rawPixelFromUpright({
|
||||
required int ux,
|
||||
required int uy,
|
||||
required int rawWidth,
|
||||
required int rawHeight,
|
||||
required int clockwiseDegrees,
|
||||
}) {
|
||||
switch (clockwiseDegrees) {
|
||||
case 0:
|
||||
return (ux, uy);
|
||||
case 90:
|
||||
// destX = rawHeight - 1 - ry, destY = rx
|
||||
return (uy, rawHeight - 1 - ux);
|
||||
case 180:
|
||||
return (rawWidth - 1 - ux, rawHeight - 1 - uy);
|
||||
case 270:
|
||||
// destX = ry, destY = rawWidth - 1 - rx
|
||||
return (rawWidth - 1 - uy, ux);
|
||||
default:
|
||||
throw ArgumentError(
|
||||
'Поворот должен быть 0, 90, 180 или 270, получено $clockwiseDegrees',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
(int width, int height) uprightSize({
|
||||
required int rawWidth,
|
||||
required int rawHeight,
|
||||
required int clockwiseDegrees,
|
||||
}) {
|
||||
switch (clockwiseDegrees) {
|
||||
case 0:
|
||||
case 180:
|
||||
return (rawWidth, rawHeight);
|
||||
case 90:
|
||||
case 270:
|
||||
return (rawHeight, rawWidth);
|
||||
default:
|
||||
throw ArgumentError(
|
||||
'Поворот должен быть 0, 90, 180 или 270, получено $clockwiseDegrees',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user