-
Notifications
You must be signed in to change notification settings - Fork 0
/
maccgimageinterpolatetest.m
144 lines (118 loc) · 3.59 KB
/
maccgimageinterpolatetest.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// 24 june 2016
// based on code from 22 june 2016
#import <Cocoa/Cocoa.h>
NSLayoutConstraint *mkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRelation relation, id view2, NSLayoutAttribute attr2, CGFloat multiplier, CGFloat c)
{
return [NSLayoutConstraint constraintWithItem:view1
attribute:attr1
relatedBy:relation
toItem:view2
attribute:attr2
multiplier:multiplier
constant:c];
}
@interface drawingView : NSView
@end
CGImageRef should, shouldNot;
#define filename "16x16test_24june2016.png"
void loadImages(void)
{
CGDataProviderRef dp;
dp = CGDataProviderCreateWithFilename(filename);
should = CGImageCreateWithPNGDataProvider(dp, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(dp);
dp = CGDataProviderCreateWithFilename(filename);
shouldNot = CGImageCreateWithPNGDataProvider(dp, NULL, false, kCGRenderingIntentDefault);
CGDataProviderRelease(dp);
}
void drawQuadrant(CGContextRef c, NSString *label, CGImageRef image, CGInterpolationQuality interpolation, double x, double y)
{
CGContextSaveGState(c);
CGContextSetInterpolationQuality(c, interpolation);
[label drawAtPoint:NSMakePoint(x, y + 256 + 5)
withAttributes:nil];
CGContextDrawImage(c,
CGRectMake(x, y + (256 - 16), 16, 16),
image);
CGContextDrawImage(c,
CGRectMake(x + 16 + 5, y, 256, 256),
image);
CGContextRestoreGState(c);
}
@implementation drawingView
- (id)initWithFrame:(NSRect)r
{
self = [super initWithFrame:r];
if (self)
loadImages();
return self;
}
- (void)drawRect:(NSRect)r
{
CGContextRef c;
c = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
#define quadHeight (20 + 5 + 256)
drawQuadrant(c, @"Should, None",
should, kCGInterpolationNone,
5, 5 + quadHeight + 5);
drawQuadrant(c, @"Should, Medium",
should, kCGInterpolationMedium,
5 + quadHeight + 5, 5 + quadHeight + 5);
drawQuadrant(c, @"Should Not, None",
shouldNot, kCGInterpolationNone,
5, 5);
drawQuadrant(c, @"Should Not, Medium",
shouldNot, kCGInterpolationMedium,
5 + quadHeight + 5, 5);
}
@end
@interface appDelegate : NSObject<NSApplicationDelegate>
@end
@implementation appDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)note
{
NSWindow *w;
NSView *contentView;
drawingView *dv;
w = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0,
20 + 5 + quadHeight + 5 + quadHeight + 5 + 20,
20 + 5 + quadHeight + 5 + quadHeight + 5 + 20)
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
backing:NSBackingStoreBuffered
defer:YES];
contentView = [w contentView];
dv = [[drawingView alloc] initWithFrame:NSZeroRect];
[dv setTranslatesAutoresizingMaskIntoConstraints:NO];
[contentView addSubview:dv];
[contentView addConstraint:mkConstraint(contentView, NSLayoutAttributeLeading,
NSLayoutRelationEqual,
dv, NSLayoutAttributeLeading,
1, -20)];
[contentView addConstraint:mkConstraint(contentView, NSLayoutAttributeTop,
NSLayoutRelationEqual,
dv, NSLayoutAttributeTop,
1, -20)];
[contentView addConstraint:mkConstraint(contentView, NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
dv, NSLayoutAttributeTrailing,
1, 20)];
[contentView addConstraint:mkConstraint(contentView, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
dv, NSLayoutAttributeBottom,
1, 20)];
[w makeKeyAndOrderFront:nil];
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app
{
return YES;
}
@end
int main(void)
{
NSApplication *app;
app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
[app setDelegate:[appDelegate new]];
[app run];
return 0;
}