Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Wrong colors when applying CoreImage filters



Hi everyone,

My first test of CoreImage does not seem to go well. I
tried the motion blur filter using the code bellow;
the camera simulation movement seems correct however
there is an inexplicable (to me of course) shift of
colors: black and red appear blue, green becomes pink,
etc. The image is an RGB with an alpha constant
everywhere (value 255). What am I doing wrong please?

Many thanks

JJ


=================
{
	size_t imageWidth, imageHeight; // Known
	unsigned char ioData = NULL;
	
	NSBitmapFormat bitmapFormat = NSBitmapFormat(
NSAlphaFirstBitmapFormat +
NSAlphaNonpremultipliedBitmapFormat);	
	int bitsPerSample = 8;
	
	size_t samplesPerPixel = 4;
	size_t bytesPerRow = imageWidth*samplesPerPixel;
	size_t bitmapByteCount = bytesPerRow*imageHeight;
	
	ioData = new unsigned char[ bitmapByteCount];
	// set ioData here as interleaved ARGB.
	
	CGColorSpaceRef colorSpaceRef =
CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB);
	
	CIImage* inCIImage = [[CIImage alloc]
initWithBitmapData: [NSData dataWithBytesNoCopy:
ioData length: bitmapByteCount freeWhenDone: NO] 
					bytesPerRow: bytesPerRow size: CGSizeMake(
imageWidth, imageHeight) 
					format: kCIFormatARGB8 colorSpace:
colorSpaceRef];
	
	CGColorSpaceRelease( colorSpaceRef);

	CIFilter* motionBlur = [CIFilter filterWithName:
@"CIMotionBlur"];
	[motionBlur setDefaults];
	[motionBlur setValue: [NSNumber numberWithFloat:
radius] forKey: @"inputRadius"];
	[motionBlur setValue: [NSNumber numberWithFloat:
angleInRadians] forKey: @"inputAngle"];
	[filter setValue: inCIImage forKey: @"inputImage"];
	CIImage* outCIImage = [filter valueForKey:
@"outputImage"];

	// Create a bitmap rep
	
	NSBitmapImageRep* bitmapImageRep = [
[NSBitmapImageRep alloc] initWithBitmapDataPlanes:
NULL 
											pixelsWide: imageWidth pixelsHigh:
imageHeight 
											bitsPerSample: bitsPerSample
samplesPerPixel: samplesPerPixel
											hasAlpha: YES isPlanar: NO colorSpaceName:
NSDeviceRGBColorSpace
											bitmapFormat: bitmapFormat
											bytesPerRow: bytesPerRow bitsPerPixel:
(bitsPerSample*samplesPerPixel)
										];
	
	// Draw on the bitmapImageRep
	NSGraphicsContext* nsgContext = [NSGraphicsContext
graphicsContextWithBitmapImageRep: bitmapImageRep] ;
	CGContextRef cgContext = (CGContextRef)[nsgContext
graphicsPort];
	CIContext* myCIContext = [CIContext
contextWithCGContext: cgContext options: nil];
	
	[myCIContext drawImage: outCIImage atPoint:
CGPointZero fromRect: CGRectMake( 0, 0, imageWidth,
imageHeight)];
	
	unsigned char* ioData = (unsigned
char*)[bitmapImageRep bitmapData];					
	
	// When I do the drawing from ioData here I get this
strange color shift!

	[bitmapImageRep release];

	[inCIImage release];
}


Send instant messages to your online friends http://uk.messenger.yahoo.com 
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.