vImage Help
vImage Help
- Subject: vImage Help
- From: R T <email@hidden>
- Date: Sat, 14 Nov 2009 13:01:57 -0800 (PST)
I'm using... vImage_Error err = vImageContrastStretch_Planar8 (&src, &dest, flags );
and getting a scrambled image from the code? Each pixel returned is at the right height but offset left 3 pixels. Anyone wanting to you to look the images email me.
- (NSImage*)vImageContrastStretch:(NSImage*)anImage{
NSBitmapImageRep *anImageRep = [[NSBitmapImageRep alloc] initWithData:[anImage TIFFRepresentation]];
unsigned char *inBytes = [anImageRep bitmapData];
NSSize imageSize = [anImage size];
UInt32 imageWidth = imageSize.width;
UInt32 imageHeight = imageSize.height;
NSImage *newImage = [[[NSImage alloc] initWithSize:imageSize]autorelease];
NSBitmapImageRep *newImageRep;
UInt32 samplesPerPixel = [anImageRepsamplesPerPixel];
BOOL hasAlpha;
if (samplesPerPixel==2 || samplesPerPixel==4) { // Gray+alpha or RGBA?
hasAlpha = YES;
} else {
hasAlpha = NO;
}
NSString *colorSpaceName = nil;
if (samplesPerPixel==1 || samplesPerPixel==2) { // Gray or Gray+alpha?
colorSpaceName = NSCalibratedWhiteColorSpace;
} else if (samplesPerPixel==3 || samplesPerPixel==4) { // RGB or RGBA?
colorSpaceName = NSCalibratedRGBColorSpace;
} else {NSLog(@"I can't handle a colorspace with %d samples per pixel",samplesPerPixel);
return nil;}
newImageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:imageWidth
pixelsHigh:imageHeight
bitsPerSample:8
samplesPerPixel:samplesPerPixel
hasAlpha:hasAlpha
isPlanar:NO
colorSpaceName:colorSpaceName
bytesPerRow:0
bitsPerPixel:0] autorelease];
unsigned char *outBytes = [newImageRep bitmapData];
long numPixels = imageWidth * imageHeight;
unsigned char *workBuffer1 = malloc(numPixels*sizeof(char));
unsigned char *workBuffer2 = malloc(numPixels*sizeof(char));
if (workBuffer1==NULL || workBuffer2==NULL) {NSLog(@"Can't allocate memory for image ");
return nil;}
vImage_Flags flags = 1;
int sampleIx;
for (sampleIx=0; sampleIx<samplesPerPixel; sampleIx++) {
int ix; for (ix=0; ix<numPixels; ix++) *(workBuffer1+ix) = *(inBytes + ix*samplesPerPixel + sampleIx);
const vImage_Buffer src = { workBuffer1, imageHeight, imageWidth, imageWidth*sizeof(char) };
const vImage_Buffer dest = { workBuffer2, imageHeight, imageWidth, imageWidth*sizeof(char) };
vImage_Error err = vImageContrastStretch_Planar8 (&src, &dest, flags );
if (err!=kvImageNoError) {return nil;}
for (ix=0; ix<numPixels; ix++) *(outBytes + ix*samplesPerPixel + sampleIx) = *(workBuffer2+ix);
}
free(workBuffer1);
free(workBuffer2);
[newImage addRepresentation:newImageRep];
[anImageRep release];
return newImage;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden