-
Notifications
You must be signed in to change notification settings - Fork 0
/
XeeBitmapRawImage.m
68 lines (53 loc) · 1.17 KB
/
XeeBitmapRawImage.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
56
57
58
59
60
61
62
63
64
65
66
67
68
#import "XeeBitmapRawImage.h"
@implementation XeeBitmapRawImage
-(id)initWithHandle:(CSHandle *)fh width:(int)w height:(int)h
{
return [self initWithHandle:fh width:w height:h bytesPerRow:(w+7)/8];
}
-(id)initWithHandle:(CSHandle *)fh width:(int)w height:(int)h bytesPerRow:(int)bpr
{
if(self=[super initWithHandle:fh])
{
width=w;
height=h;
bytesperfilerow=bpr;
zero=255;
one=0;
buffer=NULL;
}
return self;
}
-(void)dealloc
{
free(buffer);
[super dealloc];
}
-(void)setZeroPoint:(float)low onePoint:(float)high
{
zero=low*255;
one=high*255;
}
-(void)load
{
if(!handle) XeeImageLoaderDone(NO);
XeeImageLoaderHeaderDone();
if(![self allocWithType:XeeBitmapTypeLuma8 width:width height:height]) XeeImageLoaderDone(NO);
buffer=malloc(bytesperfilerow);
if(!buffer) XeeImageLoaderDone(NO);
for(int row=0;row<height;row++)
{
[handle readBytes:bytesperfilerow toBuffer:buffer];
uint8_t *rowptr=XeeImageDataRow(self,row);
for(int x=0;x<width;x++)
{
if(buffer[x>>3]&(0x80>>(x&7))) *rowptr++=one;
else *rowptr++=zero;
}
[self setCompletedRowCount:row+1];
XeeImageLoaderYield();
}
free(buffer);
buffer=NULL;
XeeImageLoaderDone(YES);
}
@end