-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAQTImage.m
90 lines (78 loc) · 2.13 KB
/
AQTImage.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// AQTImage.m
// AquaTerm
//
// Created by Per Persson on Tue Feb 05 2002.
// Copyright (c) 2001 AquaTerm. All rights reserved.
//
#import "AQTImage.h"
@implementation AQTImage
/*
- (id)initWithContentsOfFile:(NSString *)filename
{
if (self = [super init])
{
image = [[NSImage alloc] initWithContentsOfFile:filename];
}
return self;
}
*/
- (id)initWithBitmap:(const char *)bytes size:(NSSize)size bounds:(NSRect)bounds
{
if (self = [super init])
{
_bounds = bounds;
bitmapSize = size;
bitmap = [[NSData alloc] initWithBytes:bytes length:3*size.width*size.height]; // 3 bytes/sample
// Identity matrix
transform.m11 = 1.0;
transform.m22 = 1.0;
fitBounds = YES;
}
return self;
}
-(void)dealloc
{
[bitmap release];
[super dealloc];
}
- (void)encodeWithCoder:(NSCoder *)coder
{
AQTRect r;
AQTSize s;
[super encodeWithCoder:coder];
[coder encodeObject:bitmap];
// 64bit compatibility
s.width = bitmapSize.width; s.height = bitmapSize.height;
[coder encodeValueOfObjCType:@encode(AQTSize) at:&s];
r.origin.x = _bounds.origin.x; r.origin.y = _bounds.origin.y;
r.size.width = _bounds.size.width; r.size.height = _bounds.size.height;
[coder encodeValueOfObjCType:@encode(AQTRect) at:&r];
[coder encodeValueOfObjCType:@encode(AQTAffineTransformStruct) at:&transform];
[coder encodeValueOfObjCType:@encode(BOOL) at:&fitBounds];
}
-(id)initWithCoder:(NSCoder *)coder
{
AQTRect r;
AQTSize s;
self = [super initWithCoder:coder];
bitmap = [[coder decodeObject] retain];
[coder decodeValueOfObjCType:@encode(AQTSize) at:&s];
bitmapSize.width = s.width; bitmapSize.height = s.height;
[coder decodeValueOfObjCType:@encode(AQTRect) at:&r];
_bounds.origin.x = r.origin.x; _bounds.origin.y = r.origin.y;
_bounds.size.width = r.size.width; _bounds.size.height = r.size.height;
[coder decodeValueOfObjCType:@encode(AQTAffineTransformStruct) at:&transform];
[coder decodeValueOfObjCType:@encode(BOOL) at:&fitBounds];
return self;
}
- (NSData *)bitmap
{
return bitmap;
}
- (void)setTransform:(AQTAffineTransformStruct)newTransform
{
transform = newTransform;
fitBounds = NO;
}
@end