Browse files

Fixed: crashes when imageWidth is divisible by tileWidth without rema…

…inder
  • Loading branch information...
1 parent 3e58e58 commit 3e3a7e7d2bf5e811010f7ba12793744048088748 @psineur psineur committed Apr 25, 2011
Showing with 16 additions and 1 deletion.
  1. +3 −0 NSBitmapImageRep-Tile.h
  2. +11 −0 NSBitmapImageRep-Tile.m
  3. +2 −1 TileOperation.m
View
3 NSBitmapImageRep-Tile.h
@@ -11,4 +11,7 @@
@interface NSBitmapImageRep(Tile)
-(NSImage *)subImageWithTileWidth:(CGFloat)tileWidth tileHeight:(CGFloat)tileHeight column:(NSUInteger)column row:(NSUInteger)row;
+-(NSUInteger)columnsWithTileWidth:(CGFloat)tileWidth;
+-(NSUInteger)rowsWithTileHeight:(CGFloat)tileHeight;
+
@end
View
11 NSBitmapImageRep-Tile.m
@@ -85,4 +85,15 @@ -(NSImage *)subImageWithTileWidth:(CGFloat)tileWidth tileHeight:(CGFloat)tileHei
}
+-(NSUInteger)columnsWithTileWidth:(CGFloat)tileWidth
+{
+ CGFloat columns = [self size].width / tileWidth;
+ return (NSUInteger) ceilf(columns);
+}
+-(NSUInteger)rowsWithTileHeight:(CGFloat)tileHeight
+{
+ CGFloat rows = [self size].height / tileHeight;
+ return (NSUInteger) ceilf(rows);
+}
+
@end
View
3 TileOperation.m
@@ -67,7 +67,8 @@ - (void)main
break;
}
- for (int column = 0; column < [imageRep pixelsWide] / tileWidth + 1; column++)
+ int tileColCount = [imageRep columnsWithTileWidth:tileWidth];
+ for (int column = 0; column < tileColCount; column++)
{
NSImage *subImage = [imageRep subImageWithTileWidth:(float)tileWidth tileHeight:(float)tileHeight column:column row:row];

0 comments on commit 3e3a7e7

Please sign in to comment.