Skip to content

Instantly share code, notes, and snippets.

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;
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;
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
);
// 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 {
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
NSMutableArray *histo = [NSMutableArray array];
for (int i = 0; i < num_bins; i++)
[histo insertObject:[NSNumber numberWithUnsignedLong:histogram[i]] atIndex:i];
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;
}
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;
}
// works:
return [TransferFunctionPoint pointWithX:x
Y:intercol.w
Color:[UIColor greenColor]];
// runtime error:
return [TransferFunctionPoint pointWithX:x
Y:intercol.w
Color:[UIColor colorWithRed:1. green:1. blue:0. alpha:1.]];
+ (TransferFunctionPoint *)pointWithX:(double)_x Y:(double)_y Color:(UIColor*)_color {
TransferFunctionPoint *p = [[[self class] alloc] init];
p.x = _x;
p.y = _y;
p.color = _color;
return p;
}