Skip to content

Commit

Permalink
Merge branch 'master' of github.com:steipete/PSFoundation
Browse files Browse the repository at this point in the history
  • Loading branch information
steipete committed Mar 16, 2011
2 parents 7271004 + 8e723ad commit 5474430
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Categories/PSCategories.h
Expand Up @@ -134,7 +134,6 @@
// + (UILabel *)labelWithText:(NSString *)text; // + (UILabel *)labelWithText:(NSString *)text;
#import "UILabel+PSLib.h" // own #import "UILabel+PSLib.h" // own


#import "UIImage+MTCache.h"
#import "UIScrollView+MTUIAdditions.h" #import "UIScrollView+MTUIAdditions.h"


#import "UIToolBar+PSLib.h" #import "UIToolBar+PSLib.h"
Expand Down Expand Up @@ -181,7 +180,8 @@
#import "UIImage+Cache.h" #import "UIImage+Cache.h"
#import "UIImage+Tint.h" #import "UIImage+Tint.h"
#import "UIImage+ProportionalFill.h" #import "UIImage+ProportionalFill.h"

#import "UIImage+MTCache.h"
#import "UIImage+MTTiling.h"
#import "UIImage+MTUniversalAdditions.h" #import "UIImage+MTUniversalAdditions.h"




Expand Down
20 changes: 20 additions & 0 deletions Categories/UIImage/UIImage+MTTiling.h
@@ -0,0 +1,20 @@
//
// UIImage+MTTiling.h
// PSFoundation
//
// Created by Matthias Tretter on 15.03.11.
// Copyright 2011 @myell0w. All rights reserved.
//
// Taken from:
// http://www.cimgf.com/2011/03/01/subduing-catiledlayer/

#import <Foundation/Foundation.h>


@interface UIImage (MTTiling)

- (void)saveTilesOfSize:(CGSize)size
toDirectory:(NSString*)directoryPath
usingPrefix:(NSString*)prefix;

@end
59 changes: 59 additions & 0 deletions Categories/UIImage/UIImage+MTTiling.m
@@ -0,0 +1,59 @@
//
// UIImage+MTTiling.m
// PSFoundation
//
// Created by Matthias Tretter on 15.03.11.
// Copyright 2011 Peter Steinberger. All rights reserved.
//
// Taken from:
// http://www.cimgf.com/2011/03/01/subduing-catiledlayer/

#import "UIImage+MTTiling.h"


@implementation UIImage (MTTiling)

- (void)saveTilesOfSize:(CGSize)size
toDirectory:(NSString*)directoryPath
usingPrefix:(NSString*)prefix
{
CGFloat cols = [self size].width / size.width;
CGFloat rows = [self size].height / size.height;

int fullColumns = floorf(cols);
int fullRows = floorf(rows);

CGFloat remainderWidth = [self size].width - (fullColumns * size.width);
CGFloat remainderHeight = [self size].height - (fullRows * size.height);


if (cols > fullColumns) fullColumns++;
if (rows > fullRows) fullRows++;

CGImageRef fullImage = [self CGImage];

for (int y = 0; y < fullRows; ++y) {
for (int x = 0; x < fullColumns; ++x) {
CGSize tileSize = size;
if (x + 1 == fullColumns && remainderWidth > 0) {
// Last column
tileSize.width = remainderWidth;
}
if (y + 1 == fullRows && remainderHeight > 0) {
// Last row
tileSize.height = remainderHeight;
}

CGImageRef tileImage = CGImageCreateWithImageInRect(fullImage,
(CGRect){{x*size.width, y*size.height},
tileSize});
NSData *imageData = UIImagePNGRepresentation([UIImage imageWithCGImage:tileImage]);
NSString *path = [NSString stringWithFormat:@"%@/%@%d_%d.png",
directoryPath, prefix, x, y];

[imageData writeToFile:path atomically:NO];
}
}
}

@end
8 changes: 8 additions & 0 deletions PSFoundation.xcodeproj/project.pbxproj
Expand Up @@ -54,6 +54,8 @@
39EE95C612C3B66300AD953B /* NSMutableArray+MTShuffle.m in Sources */ = {isa = PBXBuildFile; fileRef = 39EE95C412C3B66300AD953B /* NSMutableArray+MTShuffle.m */; }; 39EE95C612C3B66300AD953B /* NSMutableArray+MTShuffle.m in Sources */ = {isa = PBXBuildFile; fileRef = 39EE95C412C3B66300AD953B /* NSMutableArray+MTShuffle.m */; };
39EE95F912C3B83400AD953B /* ColorLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 39EE95F712C3B83400AD953B /* ColorLog.h */; }; 39EE95F912C3B83400AD953B /* ColorLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 39EE95F712C3B83400AD953B /* ColorLog.h */; };
39EE95FA12C3B83400AD953B /* ColorLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 39EE95F812C3B83400AD953B /* ColorLog.m */; }; 39EE95FA12C3B83400AD953B /* ColorLog.m in Sources */ = {isa = PBXBuildFile; fileRef = 39EE95F812C3B83400AD953B /* ColorLog.m */; };
39FAFC87132FA7D100F039C4 /* UIImage+MTTiling.h in Headers */ = {isa = PBXBuildFile; fileRef = 39FAFC85132FA7D100F039C4 /* UIImage+MTTiling.h */; };
39FAFC88132FA7D100F039C4 /* UIImage+MTTiling.m in Sources */ = {isa = PBXBuildFile; fileRef = 39FAFC86132FA7D100F039C4 /* UIImage+MTTiling.m */; };
780CBDA51326759100F22032 /* NSData+RSHexDump.h in Headers */ = {isa = PBXBuildFile; fileRef = 780CBDA31326759100F22032 /* NSData+RSHexDump.h */; }; 780CBDA51326759100F22032 /* NSData+RSHexDump.h in Headers */ = {isa = PBXBuildFile; fileRef = 780CBDA31326759100F22032 /* NSData+RSHexDump.h */; };
780CBDA61326759100F22032 /* NSData+RSHexDump.m in Sources */ = {isa = PBXBuildFile; fileRef = 780CBDA41326759100F22032 /* NSData+RSHexDump.m */; }; 780CBDA61326759100F22032 /* NSData+RSHexDump.m in Sources */ = {isa = PBXBuildFile; fileRef = 780CBDA41326759100F22032 /* NSData+RSHexDump.m */; };
782AC0BA1281864800806121 /* MANotificationCenterAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 782AC0B01281864800806121 /* MANotificationCenterAdditions.h */; }; 782AC0BA1281864800806121 /* MANotificationCenterAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 782AC0B01281864800806121 /* MANotificationCenterAdditions.h */; };
Expand Down Expand Up @@ -340,6 +342,8 @@
39EE95C412C3B66300AD953B /* NSMutableArray+MTShuffle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSMutableArray+MTShuffle.m"; path = "Categories/NSArray/NSMutableArray+MTShuffle.m"; sourceTree = SOURCE_ROOT; }; 39EE95C412C3B66300AD953B /* NSMutableArray+MTShuffle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSMutableArray+MTShuffle.m"; path = "Categories/NSArray/NSMutableArray+MTShuffle.m"; sourceTree = SOURCE_ROOT; };
39EE95F712C3B83400AD953B /* ColorLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ColorLog.h; path = Lumberjack/ColorLog.h; sourceTree = SOURCE_ROOT; }; 39EE95F712C3B83400AD953B /* ColorLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ColorLog.h; path = Lumberjack/ColorLog.h; sourceTree = SOURCE_ROOT; };
39EE95F812C3B83400AD953B /* ColorLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ColorLog.m; path = Lumberjack/ColorLog.m; sourceTree = SOURCE_ROOT; }; 39EE95F812C3B83400AD953B /* ColorLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ColorLog.m; path = Lumberjack/ColorLog.m; sourceTree = SOURCE_ROOT; };
39FAFC85132FA7D100F039C4 /* UIImage+MTTiling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+MTTiling.h"; sourceTree = "<group>"; };
39FAFC86132FA7D100F039C4 /* UIImage+MTTiling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+MTTiling.m"; sourceTree = "<group>"; };
780CBDA31326759100F22032 /* NSData+RSHexDump.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSData+RSHexDump.h"; path = "Categories/NSData/NSData+RSHexDump.h"; sourceTree = SOURCE_ROOT; }; 780CBDA31326759100F22032 /* NSData+RSHexDump.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSData+RSHexDump.h"; path = "Categories/NSData/NSData+RSHexDump.h"; sourceTree = SOURCE_ROOT; };
780CBDA41326759100F22032 /* NSData+RSHexDump.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSData+RSHexDump.m"; path = "Categories/NSData/NSData+RSHexDump.m"; sourceTree = SOURCE_ROOT; }; 780CBDA41326759100F22032 /* NSData+RSHexDump.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSData+RSHexDump.m"; path = "Categories/NSData/NSData+RSHexDump.m"; sourceTree = SOURCE_ROOT; };
782AC0B01281864800806121 /* MANotificationCenterAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MANotificationCenterAdditions.h; path = ZeroWeakReferences/MANotificationCenterAdditions.h; sourceTree = SOURCE_ROOT; }; 782AC0B01281864800806121 /* MANotificationCenterAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MANotificationCenterAdditions.h; path = ZeroWeakReferences/MANotificationCenterAdditions.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -1278,6 +1282,8 @@
78E531D1126E03EB00A89047 /* UIImage+Tint.m */, 78E531D1126E03EB00A89047 /* UIImage+Tint.m */,
78E531D2126E03EB00A89047 /* UIImageHelper.h */, 78E531D2126E03EB00A89047 /* UIImageHelper.h */,
78E531D3126E03EB00A89047 /* UIImageHelper.m */, 78E531D3126E03EB00A89047 /* UIImageHelper.m */,
39FAFC85132FA7D100F039C4 /* UIImage+MTTiling.h */,
39FAFC86132FA7D100F039C4 /* UIImage+MTTiling.m */,
); );
name = UIImage; name = UIImage;
path = Categories/UIImage; path = Categories/UIImage;
Expand Down Expand Up @@ -1555,6 +1561,7 @@
7882D5341323262A00BE7370 /* SMModelObject.h in Headers */, 7882D5341323262A00BE7370 /* SMModelObject.h in Headers */,
780CBDA51326759100F22032 /* NSData+RSHexDump.h in Headers */, 780CBDA51326759100F22032 /* NSData+RSHexDump.h in Headers */,
3934261A1328CCE5001427E1 /* DTCustomColoredAccessory.h in Headers */, 3934261A1328CCE5001427E1 /* DTCustomColoredAccessory.h in Headers */,
39FAFC87132FA7D100F039C4 /* UIImage+MTTiling.h in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down Expand Up @@ -1795,6 +1802,7 @@
7882D5351323262A00BE7370 /* SMModelObject.m in Sources */, 7882D5351323262A00BE7370 /* SMModelObject.m in Sources */,
780CBDA61326759100F22032 /* NSData+RSHexDump.m in Sources */, 780CBDA61326759100F22032 /* NSData+RSHexDump.m in Sources */,
3934261B1328CCE5001427E1 /* DTCustomColoredAccessory.m in Sources */, 3934261B1328CCE5001427E1 /* DTCustomColoredAccessory.m in Sources */,
39FAFC88132FA7D100F039C4 /* UIImage+MTTiling.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down

0 comments on commit 5474430

Please sign in to comment.