Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

fix: Fluid keeps a dark cover's colors, and the lyrics blur is not gray (#124)

My-Name-Is-Jeff4f42820b7f3c
diff --git a/harness/player/main.m b/harness/player/main.m
index 3fd3ade1..1658443a 100644
--- a/harness/player/main.m
+++ b/harness/player/main.m
@@ -912,7 +912,9 @@ static BOOL fieldCovered(void) {
after(5, ^{
UIView *motion = motionView();
CALayer *foot = [motion valueForKey:@"_foot"], *clip = [motion valueForKey:@"_clip"];
- UIVisualEffectView *seam = [motion valueForKey:@"_seamBlur"], *lyrics = [motion valueForKey:@"_lyricsBlur"];
+ UIVisualEffectView *seam = [motion valueForKey:@"_seamBlur"];
+ // The lyrics' blur is a filter on the clip, there only while the lyrics are up.
+ BOOL lyricsBlurred = ((UIView *)[motion valueForKey:@"_picture"]).layer.filters.count > 0;
[self expect:motion != nil && self->_covers.layer.mask != nil step:@"the player opened"
detail:[NSString stringWithFormat:@"clip %@ the field, cover %@", motion ? @"on" : @"not on", self->_covers.layer.mask ? @"hidden" : @"shown"]];
CGFloat seamAt = round(clip.frame.size.height * 0.9);
@@ -929,9 +931,9 @@ static BOOL fieldCovered(void) {
detail:[NSString stringWithFormat:@"poster %@ at %@, video %@, fade %@, field %@, %@", still.contents ? @"in" : @"missing",
NSStringFromCGRect(still.frame), NSStringFromCGRect(clip.frame), still.mask ? @"on the poster" : @"missing",
SGRPlayerField().motionHeld ? @"held" : @"moving", fieldCovered() ? @"its Fluid copies hidden" : @"its Fluid copies drawn"]];
- [self expect:seam.effect && !lyrics.effect step:@"the blur from the seam"
+ [self expect:seam.effect && !lyricsBlurred step:@"the blur from the seam"
detail:[NSString stringWithFormat:@"seam blur %@, from %@ of the height, lyrics blur %@", seam.effect ? @"on" : @"off",
- [[seam.maskView.layer.sublayers.firstObject valueForKey:@"locations"] componentsJoinedByString:@" to "], lyrics.effect ? @"on" : @"off"]];
+ [[seam.maskView.layer.sublayers.firstObject valueForKey:@"locations"] componentsJoinedByString:@" to "], lyricsBlurred ? @"on" : @"off"]];
// Dimmed by its brightness: HARNESS_DIM is what the clip in HARNESS_CANVAS_FILE should get (0.54 for white,
// 0.10 for black); the rule itself is checked at its ends.
CALayer *dim = [motion valueForKey:@"_dim"];
@@ -947,7 +949,7 @@ static BOOL fieldCovered(void) {
});
after(7, ^{ SGRPlayerToggleLyrics(); });
after(8.5, ^{
- UIVisualEffectView *lyrics = [motionView() valueForKey:@"_lyricsBlur"];
+ BOOL lyricsBlurred = ((UIView *)[motionView() valueForKey:@"_picture"]).layer.filters.count > 0;
UIView *thumb = nil;
for (UIView *view in self->_host.subviews) {
if ([NSStringFromClass(view.class) isEqualToString:@"SGRPlayerLyricsOverlay"]) thumb = [view valueForKey:@"thumb"];
@@ -956,9 +958,9 @@ static BOOL fieldCovered(void) {
float dim = ((CALayer *)[motionView() valueForKey:@"_dim"]).opacity;
[self expect:fabsf(dim - self->_dimAlone - 0.15f) < 0.01f step:@"the dim under the lyrics"
detail:[NSString stringWithFormat:@"%.2f, %.2f without them", dim, self->_dimAlone]];
- [self expect:SGRPlayerLyricsOpen() && lyrics.effect && away step:@"the lyrics"
+ [self expect:SGRPlayerLyricsOpen() && lyricsBlurred && away step:@"the lyrics"
detail:[NSString stringWithFormat:@"lyrics %@, clip blurred %@, thumbnail %@ at alpha %.2f", SGRPlayerLyricsOpen() ? @"up" : @"down",
- lyrics.effect ? @"yes" : @"no", thumb && !CGAffineTransformIsIdentity(thumb.transform) ? @"in its corner" : @"at the cover", thumb.alpha]];
+ lyricsBlurred ? @"yes" : @"no", thumb && !CGAffineTransformIsIdentity(thumb.transform) ? @"in its corner" : @"at the cover", thumb.alpha]];
NSLog(@"[harness] motion: screenshot the lyrics now");
});
after(10, ^{ SGRPlayerToggleLyrics(); });
diff --git a/tweak/Sources/Redesigned/Kit/SGRFluid.m b/tweak/Sources/Redesigned/Kit/SGRFluid.m
index 0ed70239..8040fdec 100644
--- a/tweak/Sources/Redesigned/Kit/SGRFluid.m
+++ b/tweak/Sources/Redesigned/Kit/SGRFluid.m
@@ -13,12 +13,15 @@ static const struct { CGFloat side, x, y; CFTimeInterval turn; } kCopy[] = {
};
enum { kCopies = sizeof(kCopy) / sizeof(kCopy[0]) };
// The blurred cover is small: it is drawn several times the screen's size, so detail is lost anyway. The Blur
-// setting is its radius in steps of 1.25 px, so the standard 8 is 10 px, a twelfth of the side.
-static const CGFloat kBlurSide = 128, kBlurPerStep = 1.25, kBrightness = -0.08;
+// setting is its radius in steps of 1.25 px, so the standard 8 is 10 px, a twelfth of the side. No brightness
+// offset: Core Image works in linear light, where even -0.08 turned every channel under about 30% to black
+// (issue #100), leaving dark covers black and the rest a single saturated channel. The ceiling below darkens.
+static const CGFloat kBlurSide = 128, kBlurPerStep = 1.25;
// The upper three copies' opacity at full Warp.
static const float kOverOpacity = 0.7;
-// The shade over the bottom of the visible rect, where the controls are.
-static const CGFloat kShadeFrom = 0.45, kShadeAlpha = 0.55;
+// The shade over the bottom of the visible rect, where the controls are. Light: the ceiling already keeps the
+// text's contrast, and 0.55 left the lower half of a dark cover black (issue #100).
+static const CGFloat kShadeFrom = 0.45, kShadeAlpha = 0.3;
NSNotificationName const SGRFluidSettingsDidChangeNotification = @"spotifyglass.redesign.fluidSettingsDidChange";
@@ -60,7 +63,7 @@ static UIImage *blurred(UIImage *image, BOOL contrast, CGFloat radius, CGFloat s
CGRect extent = input.extent;
CIImage *output = [[[input imageByClampingToExtent]
imageByApplyingFilter:@"CIGaussianBlur" withInputParameters:@{kCIInputRadiusKey: @(radius)}]
- imageByApplyingFilter:@"CIColorControls" withInputParameters:@{kCIInputSaturationKey: @(saturation), kCIInputBrightnessKey: @(kBrightness)}];
+ imageByApplyingFilter:@"CIColorControls" withInputParameters:@{kCIInputSaturationKey: @(saturation)}];
static CIContext *context;
static dispatch_once_t once;
dispatch_once(&once, ^{ context = [CIContext contextWithOptions:nil]; });
@@ -68,7 +71,9 @@ static UIImage *blurred(UIImage *image, BOOL contrast, CGFloat radius, CGFloat s
if (!cg) return nil;
// Each blurred pixel is capped at a linear luminance (0.04 with Increase Contrast) that keeps the player's
// white text at about 8.8:1 and its 65% white at about 4.7:1 on the brightest; an average alone would leave
- // a bright patch of a cover behind the text. The Brightness gain comes first, so the ceiling still caps it.
+ // a bright patch of a cover behind the text. The Brightness gain scales the capped pixel, so below 100 it
+ // darkens every cover alike (applied before the cap, a bright cover stayed at the ceiling whatever the
+ // setting); above 100 it lifts the darker pixels, and the ceiling still holds the bright ones.
size_t width = CGImageGetWidth(cg), height = CGImageGetHeight(cg);
CGColorSpaceRef space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
CGContextRef bitmap = CGBitmapContextCreate(NULL, width, height, 8, width * 4, space,
@@ -84,10 +89,10 @@ static UIImage *blurred(UIImage *image, BOOL contrast, CGFloat radius, CGFloat s
CGFloat rgb[3];
for (int c = 0; c < 3; c++) {
CGFloat v = p[c] / 255.0;
- rgb[c] = gain * (v <= 0.04045 ? v / 12.92 : pow((v + 0.055) / 1.055, 2.4));
+ rgb[c] = v <= 0.04045 ? v / 12.92 : pow((v + 0.055) / 1.055, 2.4);
}
CGFloat light = 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
- CGFloat cap = light > ceiling ? ceiling / light : 1;
+ CGFloat cap = MIN(gain * (light > ceiling ? ceiling / light : 1), ceiling / light);
for (int c = 0; c < 3; c++) {
CGFloat v = MIN(1, rgb[c] * cap);
p[c] = floor(255 * (v <= 0.0031308 ? v * 12.92 : 1.055 * pow(v, 1 / 2.4) - 0.055));
diff --git a/tweak/Sources/Redesigned/Player/PlayerMotion.x b/tweak/Sources/Redesigned/Player/PlayerMotion.x
index 77528e22..649bf529 100644
--- a/tweak/Sources/Redesigned/Player/PlayerMotion.x
+++ b/tweak/Sources/Redesigned/Player/PlayerMotion.x
@@ -61,6 +61,14 @@ static const NSTimeInterval kHandOver = 0.4;
static const CGFloat kDimLeast = 0.10, kDimMost = 0.80, kDimLyrics = 0.15;
// The frames measured for the dim besides the poster, in seconds into the clip (one past its end is skipped).
static const double kMeasuredAt[] = {1, 2};
+// Behind the lyrics the clip itself is blurred, a plain Gaussian blur with no material's gray tint over it
+// (issue #101), so it keeps its colors as the Fluid field does; the dim keeps the text's contrast.
+static NSString *const kLyricsBlurPath = @"filters.gaussianBlur.inputRadius";
+static const CGFloat kLyricsBlurRadius = 30;
+
+@interface CAFilter : NSObject
++ (instancetype)filterWithType:(NSString *)type;
+@end
CGFloat SGRPlayerClipDim(CGFloat luminance, BOOL contrast, BOOL lyrics) {
// White is 1, so (1 + 0.05) / (L + 0.05) >= ratio puts the clip's luminance at `most` or under.
@@ -148,7 +156,8 @@ static UIColor *footColor(CGImageRef poster) {
CALayer *_dim; // black over the clip and its foot, as dark as the clip is bright
NSMutableData *_luminances; // of the frames measured so far
BOOL _lyricsUp;
- UIVisualEffectView *_seamBlur, *_lyricsBlur;
+ NSUInteger _blurTurn; // counts the lyrics' turns, so a fade cut short leaves the filter to the turn after it
+ UIVisualEffectView *_seamBlur;
CGFloat _aspect;
BOOL _timing; // the give-up's count is running
}
@@ -194,9 +203,6 @@ static UIBlurEffect *blurEffect(void) {
[mask.layer addSublayer:_seamMask];
_seamBlur.maskView = mask;
[self addSubview:_seamBlur];
- _lyricsBlur = [[UIVisualEffectView alloc] initWithEffect:nil];
- _lyricsBlur.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
- [self addSubview:_lyricsBlur];
NSNotificationCenter *center = NSNotificationCenter.defaultCenter;
for (NSNotificationName name in @[UIApplicationDidBecomeActiveNotification, UIApplicationWillResignActiveNotification,
@@ -204,6 +210,7 @@ static UIBlurEffect *blurEffect(void) {
[center addObserver:self selector:@selector(updateMotionSoon) name:name object:nil];
}
[center addObserver:self selector:@selector(updateDim) name:UIAccessibilityDarkerSystemColorsStatusDidChangeNotification object:nil];
+ [center addObserver:self selector:@selector(updateDim) name:UIAccessibilityReduceTransparencyStatusDidChangeNotification object:nil];
SGRObservePlayerTransition(self, ^(id owner) { [owner updateMotion]; }, ^(id owner) { [owner updateMotion]; });
SGAddPlayerStateObserver(self);
return self;
@@ -234,7 +241,6 @@ static UIBlurEffect *blurEffect(void) {
_picture.frame = bounds;
_seamBlur.frame = bounds;
_seamBlur.maskView.frame = bounds;
- _lyricsBlur.frame = bounds;
[CATransaction begin];
[CATransaction setDisableActions:YES];
_still.frame = CGRectMake(0, 0, width, height);
@@ -291,7 +297,9 @@ static UIBlurEffect *blurEffect(void) {
}
- (void)updateDim {
- CGFloat dim = SGRPlayerClipDim(brightEnd(_luminances), UIAccessibilityDarkerSystemColorsEnabled(), _lyricsUp);
+ // Reduce Transparency puts the lyrics on black, as the material it replaced went opaque there.
+ CGFloat dim = _lyricsUp && SGRReduceTransparency() ? 1
+ : SGRPlayerClipDim(brightEnd(_luminances), UIAccessibilityDarkerSystemColorsEnabled(), _lyricsUp);
_dim.opacity = (float)dim;
}
@@ -312,26 +320,61 @@ static UIBlurEffect *blurEffect(void) {
}
}
-// The clip and both blurs fade out; `done` runs once they have.
+// The clip and the seam's blur fade out; `done` runs once they have.
- (void)disappear:(void (^)(void))done {
SGRAnimate(SGRMotionFade, ^{
self->_picture.alpha = 0;
self->_seamBlur.effect = nil;
- self->_lyricsBlur.effect = nil;
}, ^(BOOL finished) { done(); });
}
-// The lyrics' blur, and their share of the dim, which a layer's own animation carries over the same fade.
+// The lyrics' blur, and their share of the dim, which a layer's own animation carries over the same fade. The
+// filter is on the clip only while the lyrics are up, so a closed lyrics page costs no blur pass a frame.
- (void)setBlurred:(BOOL)blurred animated:(BOOL)animated {
+ // Asked again on every footer layout pass: the same state again would restart the fade.
+ if (blurred == _lyricsUp) return;
_lyricsUp = blurred;
- void (^apply)(void) = ^{ self->_lyricsBlur.effect = blurred ? blurEffect() : nil; };
+ NSUInteger turn = ++_blurTurn;
+ CALayer *layer = _picture.layer;
+ if (blurred && !layer.filters && !SGRReduceTransparency()) {
+ CAFilter *blur = [NSClassFromString(@"CAFilter") filterWithType:@"gaussianBlur"];
+ [blur setValue:@0 forKey:@"inputRadius"];
+ // The clip's edges blur against themselves, not against the clear around it.
+ [blur setValue:@YES forKey:@"inputNormalizeEdges"];
+ if (blur) {
+ layer.filters = @[blur];
+ // The clip changes every video frame, so the blur runs every frame either way: rendered at one pixel a
+ // point it blurs a ninth of a 3x screen's pixels, as cheap as the material's quarter-scale backdrop
+ // was. Nothing sharp is left to lose.
+ layer.rasterizationScale = 1;
+ layer.shouldRasterize = YES;
+ }
+ }
+ id shown = [layer.presentationLayer valueForKeyPath:kLyricsBlurPath];
+ CGFloat from = [shown isKindOfClass:NSNumber.class] ? [shown doubleValue] : 0, to = blurred ? kLyricsBlurRadius : 0;
[CATransaction begin];
[CATransaction setDisableActions:!animated];
[CATransaction setAnimationDuration:SGRCrossfade];
[self updateDim];
+ if (layer.filters) {
+ __weak SGRPlayerMotionView *weakSelf = self;
+ [CATransaction setCompletionBlock:^{
+ SGRPlayerMotionView *view = weakSelf;
+ if (!view || view->_blurTurn != turn || view->_lyricsUp) return;
+ view->_picture.layer.filters = nil;
+ view->_picture.layer.shouldRasterize = NO;
+ }];
+ [layer setValue:@(to) forKeyPath:kLyricsBlurPath];
+ if (animated) {
+ CABasicAnimation *ease = [CABasicAnimation animationWithKeyPath:kLyricsBlurPath];
+ ease.fromValue = @(from);
+ ease.toValue = @(to);
+ ease.duration = SGRCrossfade;
+ ease.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ [layer addAnimation:ease forKey:@"lyricsBlur"];
+ }
+ }
[CATransaction commit];
- if (animated) SGRAnimate(SGRMotionFade, apply, nil);
- else apply();
}
// The power state is reported off the main thread.