Skip to content

Commit

Permalink
Update useSkiaFrameProcessor.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jul 12, 2024
1 parent dc9595b commit 5fe86c1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions package/src/skia/useSkiaFrameProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,27 @@ function getDegrees(orientation: Orientation): number {
case 'portrait':
return 0
case 'landscape-left':
return 270
return 90
case 'portrait-upside-down':
return 180
case 'landscape-right':
return 90
return 270
}
}

function getOrientation(degrees: number): Orientation {
'worklet'
const clamped = degrees % 360
const clamped = (degrees + 360) % 360
if (clamped >= 315 || clamped <= 45) return 'portrait'
else if (clamped >= 45 || clamped <= 135) return 'landscape-left'
else if (clamped >= 135 || clamped <= 225) return 'portrait-upside-down'
else if (clamped >= 225 || clamped <= 315) return 'landscape-right'
else if (clamped >= 45 && clamped <= 135) return 'landscape-left'
else if (clamped >= 135 && clamped <= 225) return 'portrait-upside-down'
else if (clamped >= 225 && clamped <= 315) return 'landscape-right'
else throw new Error(`Invalid degrees! ${degrees}`)
}

function rotateBy(a: Orientation, b: Orientation): Orientation {
function relativeTo(a: Orientation, b: Orientation): Orientation {
'worklet'
return getOrientation(getDegrees(a) + getDegrees(b))
return getOrientation(getDegrees(a) - getDegrees(b))
}

/**
Expand All @@ -88,8 +88,7 @@ function withRotatedFrame(frame: Frame, canvas: SkCanvas, previewOrientation: Or

try {
// 2. properly rotate canvas so Frame is rendered up-right.
const orientation = rotateBy(frame.orientation, previewOrientation)
console.log(frame.orientation, previewOrientation, orientation)
const orientation = relativeTo(frame.orientation, previewOrientation)
switch (orientation) {
case 'portrait':
// do nothing
Expand Down

0 comments on commit 5fe86c1

Please sign in to comment.