From 5b21732c9da377b7ce3d36db6259f5db4e5fe77c Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sun, 16 Oct 2011 07:32:56 +0000 Subject: [PATCH] Factor $getScale$() out to a separate function. --- Library.mm | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Library.mm b/Library.mm index bd88130..b4b8988 100644 --- a/Library.mm +++ b/Library.mm @@ -212,6 +212,21 @@ static NSMutableDictionary *Themed_ = [[NSMutableDictionary alloc] initWithCapac static unsigned Scale_ = 0; +static unsigned $getScale$(NSString *path) { + NSString *name(path); + + #define StripName(strip) \ + if ([name hasSuffix:@ strip]) \ + name = [name substringWithRange:NSMakeRange(0, [name length] - sizeof(strip) - 1)]; + + StripName(".png"); + StripName(".jpg"); + StripName("~iphone"); + StripName("~ipad"); + + return [name hasSuffix:@"@2x"] ? 2 : 1; +} + static NSString *$getTheme$(NSArray *files, bool rescale = false) { if (NSString *path = [Themed_ objectForKey:files]) return reinterpret_cast(path) == [NSNull null] ? nil : path; @@ -716,21 +731,9 @@ static NSURL *WallpaperURL_; } while (false) static UIImage *$getImage$(NSString *path) { - NSString *name(path); - - #define StripName(strip) \ - if ([name hasSuffix:@ strip]) \ - name = [name substringWithRange:NSMakeRange(0, [name length] - sizeof(strip) - 1)]; - - StripName(".png"); - StripName(".jpg"); - StripName("~iphone"); - StripName("~ipad"); - - unsigned scale([name hasSuffix:@"@2x"] ? 2 : 1); - UIImage *image([UIImage imageWithContentsOfFile:path]); + unsigned scale($getScale$(path)); if (scale != 1 && [image respondsToSelector:@selector(setScale)]) [image setScale:scale]; -- 2.45.2