@@ -259,28 +259,14 @@ extension AbstractPlayer{
259
259
filters. append ( value)
260
260
}
261
261
262
- /// Combines all currently applied filters with brightness and contrast adjustments.
263
- /// Brightness and contrast are applied as additional filters on top of the existing filters in the stack.
264
- /// - Returns: An array of CIFilter objects that include the existing filters and the brightness/contrast adjustments.
265
- private var combineFilters : [ CIFilter ] {
266
- var allFilters = filters
267
- if let filter = CIFilter ( name: " CIColorControls " , parameters: [ kCIInputBrightnessKey: brightness] ) {
268
- allFilters. append ( filter)
269
- }
270
- if let filter = CIFilter ( name: " CIColorControls " , parameters: [ kCIInputContrastKey: contrast] ) {
271
- allFilters. append ( filter)
272
- }
273
- return allFilters
274
- }
275
-
276
262
/// Applies the current set of filters to the video using an AVVideoComposition.
277
263
/// This method combines the existing filters and brightness/contrast adjustments, creates a new video composition,
278
264
/// and assigns it to the current AVPlayerItem. The video is paused during this process to ensure smooth application.
279
265
/// This method is not supported on Vision OS.
280
266
func applyVideoComposition( ) {
281
267
guard let player = player, let currentItem = player. currentItem else { return }
282
268
283
- let allFilters = combineFilters
269
+ let allFilters = combineFilters ( filters , brightness , contrast )
284
270
#if !os(visionOS)
285
271
// Might be heavy operation need to explore
286
272
let videoComposition = AVVideoComposition ( asset: currentItem. asset, applyingCIFiltersWithHandler: { request in
@@ -305,7 +291,14 @@ extension AbstractPlayer{
305
291
#endif
306
292
}
307
293
308
- /// Removes all filters from the video playback.
294
+ /// Removes all applied CIFilters from the video playback.
295
+ ///
296
+ /// This function clears the array of filters and optionally re-applies the video composition
297
+ /// to ensure the changes take effect immediately.
298
+ ///
299
+ /// - Parameters:
300
+ /// - apply: A Boolean value indicating whether to immediately apply the video composition after removing the filters.
301
+ /// Defaults to `true`.
309
302
func removeAllFilters( apply : Bool = true ) {
310
303
311
304
guard !filters. isEmpty else { return }
0 commit comments