Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9a807e8a0 | ||
|
|
7bc93c2014 | ||
|
|
374af50acc |
@@ -86,8 +86,12 @@ final class ScreenCapture {
|
|||||||
|
|
||||||
@available(macOS 14.0, *)
|
@available(macOS 14.0, *)
|
||||||
private func crop(_ image: CGImage, to rect: NSRect, display: SCDisplay) -> CGImage? {
|
private func crop(_ image: CGImage, to rect: NSRect, display: SCDisplay) -> CGImage? {
|
||||||
let scaleX = CGFloat(display.width) / display.frame.width
|
// The captured image may be at any scale (retina 2x, secondary display
|
||||||
let scaleY = CGFloat(display.height) / display.frame.height
|
// 1x, or trimmed by ScreenCaptureKit). Derive the pixel scale from the
|
||||||
|
// image we actually got, relative to the display's point frame.
|
||||||
|
let scaleX = CGFloat(image.width) / display.frame.width
|
||||||
|
let scaleY = CGFloat(image.height) / display.frame.height
|
||||||
|
guard scaleX > 0, scaleY > 0 else { return nil }
|
||||||
let cgRect = CGRect(
|
let cgRect = CGRect(
|
||||||
x: rect.minX,
|
x: rect.minX,
|
||||||
y: rect.minY,
|
y: rect.minY,
|
||||||
@@ -100,14 +104,18 @@ final class ScreenCapture {
|
|||||||
width: cgRect.width * scaleX,
|
width: cgRect.width * scaleX,
|
||||||
height: cgRect.height * scaleY
|
height: cgRect.height * scaleY
|
||||||
)
|
)
|
||||||
|
// Guard against negative offsets when the selection reaches beyond the
|
||||||
|
// display's frame (e.g. secondary monitor coordinate quirks).
|
||||||
|
let safeRect = pxRect.intersection(CGRect(x: 0, y: 0, width: CGFloat(image.width), height: CGFloat(image.height)))
|
||||||
|
guard safeRect.width >= 1, safeRect.height >= 1 else { return nil }
|
||||||
guard let cropCtx = CGContext(
|
guard let cropCtx = CGContext(
|
||||||
data: nil, width: Int(pxRect.width), height: Int(pxRect.height),
|
data: nil, width: Int(safeRect.width), height: Int(safeRect.height),
|
||||||
bitsPerComponent: 8, bytesPerRow: 0,
|
bitsPerComponent: 8, bytesPerRow: 0,
|
||||||
space: CGColorSpaceCreateDeviceRGB(),
|
space: CGColorSpaceCreateDeviceRGB(),
|
||||||
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
|
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
|
||||||
) else { return nil }
|
) else { return nil }
|
||||||
cropCtx.interpolationQuality = .high
|
cropCtx.interpolationQuality = .high
|
||||||
cropCtx.draw(image, in: CGRect(x: -pxRect.minX, y: -pxRect.minY, width: CGFloat(image.width), height: CGFloat(image.height)))
|
cropCtx.draw(image, in: CGRect(x: -safeRect.minX, y: -safeRect.minY, width: CGFloat(image.width), height: CGFloat(image.height)))
|
||||||
return cropCtx.makeImage()
|
return cropCtx.makeImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +141,8 @@ final class ScreenCapture {
|
|||||||
let excluded = content.windows.filter { excludedSet.contains($0.windowID) }
|
let excluded = content.windows.filter { excludedSet.contains($0.windowID) }
|
||||||
let filter = SCContentFilter(display: display, excludingWindows: excluded)
|
let filter = SCContentFilter(display: display, excludingWindows: excluded)
|
||||||
let config = SCStreamConfiguration()
|
let config = SCStreamConfiguration()
|
||||||
|
// display.width/height are pixels; request the display's full
|
||||||
|
// native resolution so ScreenCaptureKit gives us every pixel.
|
||||||
config.width = Int(display.width)
|
config.width = Int(display.width)
|
||||||
config.height = Int(display.height)
|
config.height = Int(display.height)
|
||||||
config.showsCursor = true
|
config.showsCursor = true
|
||||||
|
|||||||
@@ -193,10 +193,14 @@ struct ResultView: View {
|
|||||||
.padding(.top, 10)
|
.padding(.top, 10)
|
||||||
|
|
||||||
if model.mode == .screenshot {
|
if model.mode == .screenshot {
|
||||||
|
GeometryReader { geo in
|
||||||
|
let imageWidth = CGFloat(model.image.width)
|
||||||
Image(nsImage: NSImage(cgImage: model.image, size: .zero))
|
Image(nsImage: NSImage(cgImage: model.image, size: .zero))
|
||||||
.resizable()
|
.resizable()
|
||||||
.interpolation(.none)
|
// Downscale with smoothing (AA); upscale keeps pixels crisp.
|
||||||
|
.interpolation(imageWidth >= geo.size.width ? .high : .none)
|
||||||
.aspectRatio(contentMode: .fit)
|
.aspectRatio(contentMode: .fit)
|
||||||
|
}
|
||||||
.border(Color.secondary.opacity(0.4))
|
.border(Color.secondary.opacity(0.4))
|
||||||
.padding(.horizontal, 12)
|
.padding(.horizontal, 12)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+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.1.1</string>
|
<string>1.1.4</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>11</string>
|
<string>14</string>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
|
|||||||
Reference in New Issue
Block a user