Fix vertical offset in ScreenCaptureKit crops
The captured CGImage has a top-left origin, while the crop rect was
computed in SCDisplay space (bottom-left). Flip Y within the display's
bounds when converting to pixel coordinates so the crop lands exactly
where the user selected.
💘 Generated with Crush
Assisted-by: Crush:deepseek-v4-flash-0731
This commit is contained in:
@@ -118,18 +118,18 @@ final class ScreenCapture {
|
|||||||
|
|
||||||
@available(macOS 14.0, *)
|
@available(macOS 14.0, *)
|
||||||
private func crop(_ image: CGImage, to cgRect: CGRect, display: SCDisplay) -> CGImage? {
|
private func crop(_ image: CGImage, to cgRect: CGRect, display: SCDisplay) -> CGImage? {
|
||||||
// cgRect is already in SCDisplay space (Y flipped relative to AppKit).
|
// cgRect is in SCDisplay space (bottom-left origin, Y flipped vs AppKit).
|
||||||
// Derive the pixel scale from the image we actually got, relative to
|
// The captured image has a TOP-LEFT origin. So within the display,
|
||||||
// the display's point frame.
|
// we must flip Y: pixelY = displayHeight - (cgY - displayMinY) - cgHeight.
|
||||||
let scaleX = CGFloat(image.width) / display.frame.width
|
let scaleX = CGFloat(image.width) / display.frame.width
|
||||||
let scaleY = CGFloat(image.height) / display.frame.height
|
let scaleY = CGFloat(image.height) / display.frame.height
|
||||||
guard scaleX > 0, scaleY > 0 else { return nil }
|
guard scaleX > 0, scaleY > 0 else { return nil }
|
||||||
// pxRect is in image pixel space with a TOP-LEFT origin (SCDisplay space).
|
let localMinX = cgRect.minX - display.frame.minX
|
||||||
// CGImage.cropping(to:) expects the same top-left rect, so no Y flip
|
let localMaxY = cgRect.maxY - display.frame.minY
|
||||||
// is needed here — this preserves the previous CGContext behavior.
|
let flippedY = display.frame.height - localMaxY
|
||||||
let pxRect = CGRect(
|
let pxRect = CGRect(
|
||||||
x: (cgRect.minX - display.frame.minX) * scaleX,
|
x: localMinX * scaleX,
|
||||||
y: (cgRect.minY - display.frame.minY) * scaleY,
|
y: flippedY * scaleY,
|
||||||
width: cgRect.width * scaleX,
|
width: cgRect.width * scaleX,
|
||||||
height: cgRect.height * scaleY
|
height: cgRect.height * scaleY
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-2
@@ -108,9 +108,9 @@ cat > "$APP/Contents/Info.plist" <<'PLIST'
|
|||||||
<key>CFBundleIconFile</key>
|
<key>CFBundleIconFile</key>
|
||||||
<string>Icon</string>
|
<string>Icon</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.3.1</string>
|
<string>1.3.2</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>31</string>
|
<string>32</string>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
|
|||||||
Reference in New Issue
Block a user