forked from unixpickle/Giraffe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIImagePixelSource.m
55 lines (45 loc) · 1.2 KB
/
UIImagePixelSource.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// UIImagePixelSource.m
// Giraffe
//
// Created by Alex Nichol on 11/5/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
#import "UIImagePixelSource.h"
@implementation UIImagePixelSource
- (id)initWithImage:(UIImage *)anImage {
if ((self = [super init])) {
imageRep = [[ANImageBitmapRep alloc] initWithImage:anImage];
}
return self;
}
+ (UIImagePixelSource *)pixelSourceWithImage:(UIImage *)anImage {
#if __has_feature(objc_arc)
return [[UIImagePixelSource alloc] initWithImage:anImage];
#else
return [[[UIImagePixelSource alloc] initWithImage:anImage] autorelease];
#endif
}
- (NSUInteger)pixelsWide {
return [imageRep bitmapSize].x;
}
- (NSUInteger)pixelsHigh {
return [imageRep bitmapSize].y;
}
- (void)getPixel:(NSUInteger *)pixel atX:(NSInteger)x y:(NSInteger)y {
BMPixel bpixel = [imageRep getPixelAtPoint:BMPointMake(x, y)];
pixel[0] = (NSUInteger)round(bpixel.red * 255.0);
pixel[1] = (NSUInteger)round(bpixel.green * 255.0);
pixel[2] = (NSUInteger)round(bpixel.blue * 255.0);
pixel[3] = (NSUInteger)round(bpixel.alpha * 255.0);
}
- (BOOL)hasTransparency {
return YES;
}
#if !__has_feature(objc_arc)
- (void)dealloc {
[imageRep release];
[super dealloc];
}
#endif
@end