forked from saggita/rhinoviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScreenBitmap.mm
47 lines (38 loc) · 895 Bytes
/
ScreenBitmap.mm
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
//
// ScreenBitmap.mm
// iRhino3D
//
// Created by Mac Rhino on 3/4/11.
// Copyright 2011 Robert McNeel & Associates. All rights reserved.
//
#import "ScreenBitmap.h"
@implementation ScreenBitmap
- (id) initWithWidth: (NSInteger) w height: (NSInteger) h
{
self = [super init];
if (self) {
width = w;
height = h;
NSInteger bufferLength = width * height * 4;
buffer = (unsigned char*) malloc (bufferLength);
}
return self;
}
- (void) dealloc
{
free(buffer);
[super dealloc];
}
- (unsigned char*) buffer
{
return buffer;
}
- (unsigned int) pixelAt: (CGPoint) pt
{
unsigned int x = pt.x * [RhinoApp screenScale];
unsigned int y = pt.y * [RhinoApp screenScale];
if (buffer && x >= 0 && x < width && y >= 0 && y < height)
return *(unsigned int*)(buffer + 4*width*(height-y) + x*4);
return 0;
}
@end