forked from getsentry/sentry-cocoa
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: Use average color for redact masking (getsentry#3877)
Use the text color or the average color of the image as the redaction mask. Co-authored-by: Philipp Hofmann <[email protected]>
- Loading branch information
1 parent
f9a829d
commit b2da4f4
Showing
18 changed files
with
658 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Sources/Swift/Integrations/SessionReplay/SentryReplayVideoMaker.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#if canImport(UIKit) | ||
import Foundation | ||
import UIKit | ||
|
||
@objc | ||
protocol SentryReplayVideoMaker: NSObjectProtocol { | ||
func addFrameAsync(image: UIImage) | ||
func releaseFramesUntil(_ date: Date) | ||
func createVideoWith(duration: TimeInterval, beginning: Date, outputFileURL: URL, completion: @escaping (SentryVideoInfo?, Error?) -> Void) throws | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#if canImport(UIKit) && !SENTRY_NO_UIKIT | ||
#if os(iOS) || os(tvOS) | ||
import Foundation | ||
import UIKit | ||
|
||
typealias ScreenshotCallback = (UIImage) -> Void | ||
|
||
@objc | ||
protocol SentryViewScreenshotProvider: NSObjectProtocol { | ||
func image(view: UIView, options: SentryRedactOptions, onComplete: @escaping ScreenshotCallback) | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#if canImport(UIKit) && !SENTRY_NO_UIKIT | ||
#if os(iOS) || os(tvOS) | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
final class UIImageHelper { | ||
private init() { } | ||
|
||
static func averageColor(of image: UIImage, at region: CGRect) -> UIColor { | ||
let scaledRegion = region.applying(CGAffineTransform(scaleX: image.scale, y: image.scale)) | ||
guard let croppedImage = image.cgImage?.cropping(to: scaledRegion), let colorSpace = croppedImage.colorSpace else { | ||
return .black | ||
} | ||
|
||
let bitmapInfo: UInt32 = CGBitmapInfo.byteOrder32Little.rawValue | CGImageAlphaInfo.premultipliedFirst.rawValue | ||
|
||
guard let context = CGContext(data: nil, width: 1, height: 1, bitsPerComponent: 8, bytesPerRow: 4, space: colorSpace, bitmapInfo: bitmapInfo) else { return .black } | ||
context.interpolationQuality = .high | ||
context.draw(croppedImage, in: CGRect(x: 0, y: 0, width: 1, height: 1)) | ||
guard let pixelBuffer = context.data else { return .black } | ||
|
||
let data = pixelBuffer.bindMemory(to: UInt8.self, capacity: 4) | ||
|
||
let blue = CGFloat(data[0]) / 255.0 | ||
let green = CGFloat(data[1]) / 255.0 | ||
let red = CGFloat(data[2]) / 255.0 | ||
let alpha = CGFloat(data[3]) / 255.0 | ||
|
||
return UIColor(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
|
||
} | ||
|
||
#endif | ||
#endif |
Oops, something went wrong.