This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Doesn't work: | |
readsock = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, | |
IPPROTO_TCP, kCFSocketReadCallBack | | |
kCFSocketAcceptCallBack | kCFSocketDataCallBack | | |
kCFSocketConnectCallBack | kCFSocketWriteCallBack, | |
(CFSocketCallBack)&readSockCallBack, info); | |
// Works: | |
readsock = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, | |
IPPROTO_TCP, kCFSocketAcceptCallBack, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Send: | |
const uint8_t query = (uint8_t)USERNAME_QUERY; | |
const uint8_t length = (uint8_t)sizeof(query); | |
[stream write:&length maxLength:sizeof(uint8_t)]; | |
[stream write:&query maxLength:length]; | |
// Receive: | |
uint8_t length; | |
[inStream read:&length maxLength:sizeof(uint8_t)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint16_t pix; | |
uint16_t min = 34464; | |
uint16_t max = 0; | |
uint16_t *d = (uint16_t*) imgData; | |
for (int i = 0; i < 512 * 512; i++) { | |
pix = d[i]; | |
if (pix > max) | |
max = pix; | |
else if (pix < min) | |
min = pix; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef) data); | |
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray(); | |
CGImageRef img = CGImageCreate(width, height, bits_allocated, bits_allocated, | |
width,// * (bits_allocated / 8), | |
colorspace, | |
kCGBitmapByteOrderDefault, | |
provider, NULL, YES, | |
kCGRenderingIntentDefault | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint16_t pix = 0; | |
uint16_t min = 34464; | |
uint16_t max = 0; | |
uint16_t *d = (uint16_t*) imgData; | |
for (int i = 0; i < 512 * 512; i++) { | |
pix = d[i]; | |
if (pix > max) | |
max = pix; | |
else if (pix < min) | |
min = pix; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In the interface: | |
@interface TransferFunction : NSObject { | |
id <TransferFunctionDrawingDelegate> _delegate; | |
} | |
@property (nonatomic, weak) id <TransferFunctionDrawingDelegate> delegate; | |
// In the implementation: | |
@synthesize delegate=setDelegate; | |
- (void)setDelegate:(id <TransferFunctionDrawingDelegate>)delegate { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint16_t *remapped = (uint16_t*) malloc(width * height * sizeof(uint16_t)); | |
vImage_Buffer src = {imgData, | |
(vImagePixelCount) height, | |
(vImagePixelCount) width, | |
bytes_per_row | |
}; | |
vImage_Buffer dst = {remapped, | |
(vImagePixelCount) height, | |
(vImagePixelCount) width, | |
bytes_per_row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSMutableArray *histo = [NSMutableArray array]; | |
for (int i = 0; i < num_bins; i++) | |
[histo insertObject:[NSNumber numberWithUnsignedLong:histogram[i]] atIndex:i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint8 *fourchan = (uint8*) malloc(sizeof(uint8) * width * height * 4); | |
short cur; | |
short *subscript = (short*) imgData; | |
for (int i = 0; i < width * height; i++) { | |
cur = (subscript[i] + 1000) / (int) pow(2., sizeof(short)/2.); | |
fourchan[i*4] = (uint8) cur; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint8 *fourchan = (uint8*) malloc(sizeof(uint8) * width * height * 4); | |
short cur; | |
short *subscript = (short*) imgData; | |
for (int i = 0; i < width * height; i++) { | |
cur = subscript[i] + 1000; | |
fourchan[i*4] = cur; | |
} |