Skip to content

Commit

Permalink
Working.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlamarche committed Oct 8, 2010
1 parent fec8f94 commit ea8d848
Show file tree
Hide file tree
Showing 45 changed files with 3,630 additions and 482 deletions.
Binary file added .DS_Store
Binary file not shown.
55 changes: 27 additions & 28 deletions NSImage-Tile.m
Expand Up @@ -17,13 +17,11 @@ -(NSImage *)subImageWithTileWidth:(CGFloat)tileWidth tileHeight:(CGFloat)tileHei
if (row >= [self rowsWithTileHeight:tileHeight])
return nil;

NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:[self CGImageForProposedRect:NULL context:NULL hints:nil]];
NSBitmapImageRep *imageRep = [[[NSBitmapImageRep alloc] initWithCGImage:[self CGImageForProposedRect:NULL context:NULL hints:nil]] autorelease];
int width = [imageRep pixelsWide];
int height = [imageRep pixelsHigh];
int bpp = [imageRep bitsPerPixel] / 8;

int bytesPerPixel = [imageRep bitsPerPixel] / 8;


int theRow = row * tileHeight;
int theCol = column * tileWidth;

Expand All @@ -32,10 +30,11 @@ -(NSImage *)subImageWithTileWidth:(CGFloat)tileWidth tileHeight:(CGFloat)tileHei

int lastCol;
int outputWidth;
if (theCol + tileWidth > width)

if (theCol + tileWidth > width) // last column, not full size
{
lastCol = width;
outputWidth = width - theCol;
outputWidth = (width - theCol) - 1;
}
else
{
Expand All @@ -47,7 +46,7 @@ -(NSImage *)subImageWithTileWidth:(CGFloat)tileWidth tileHeight:(CGFloat)tileHei
if (theRow + tileHeight > height)
{
lastRow = height;
outputHeight = height - theRow;
outputHeight = (height - theRow) -1;
}
else
{
Expand All @@ -56,45 +55,45 @@ -(NSImage *)subImageWithTileWidth:(CGFloat)tileWidth tileHeight:(CGFloat)tileHei
}

NSImage *ret = [[NSImage alloc] initWithSize:NSMakeSize(outputWidth,outputHeight)];

NSMutableData *retData = [NSMutableData dataWithLength:bpp * tileWidth * tileHeight];


NSBitmapImageRep *retRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:outputWidth
pixelsHigh:outputHeight
bitsPerSample:[imageRep bitsPerSample]
samplesPerPixel:[imageRep samplesPerPixel]
hasAlpha:[imageRep hasAlpha]
isPlanar:[imageRep isPlanar]
colorSpaceName:[imageRep colorSpaceName]
bitmapFormat:[imageRep bitmapFormat]
bytesPerRow:[imageRep bytesPerRow]
bitsPerPixel:[imageRep bitsPerPixel]];

unsigned char *srcData = [imageRep bitmapData];
unsigned char *destData = [retData mutableBytes];
unsigned char *destData = [retRep bitmapData];


for (x = theCol; x < lastCol; x++)
{
for (y = theRow; y < lastRow; y++)
{
p1 = srcData + bpp * (y * width + x);
p2 = destData + bpp * ((y - theRow) * width + (x - theCol));
for (i = 0; i < bpp; i++)
p1 = srcData + bytesPerPixel * (y * width + x);
p2 = destData + bytesPerPixel * ((y - theRow) * width + (x - theCol));
for (i = 0; i < bytesPerPixel; i++)
p2[i] = p1[i];
}
}
NSBitmapImageRep *rep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:&destData
pixelsWide:tileWidth
pixelsHigh:tileHeight
bitsPerSample:[imageRep bitsPerSample]
samplesPerPixel:[imageRep samplesPerPixel]
hasAlpha:[imageRep hasAlpha]
isPlanar:[imageRep isPlanar]
colorSpaceName:[imageRep colorSpaceName]
bitmapFormat:[imageRep bitmapFormat]
bytesPerRow:[imageRep bytesPerRow]
bitsPerPixel:[imageRep bitsPerPixel]] autorelease];

[ret addRepresentation:rep];
[ret addRepresentation:retRep];
[retRep release];
return [ret autorelease];

}
-(NSUInteger)columnsWithTileWidth:(CGFloat)tileWidth
{
return [self size].width / tileWidth;
return [self size].width / tileWidth + 1;
}
-(NSUInteger)rowsWithTileHeight:(CGFloat)tileHeight
{
return [self size].height / tileHeight;
return [self size].height / tileHeight + 1;
}
@end
17 changes: 0 additions & 17 deletions NSInvocation-MCUtilities.h

This file was deleted.

47 changes: 0 additions & 47 deletions NSInvocation-MCUtilities.m

This file was deleted.

0 comments on commit ea8d848

Please sign in to comment.