Mailing Lists: Apple Mailing Lists

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

Re: A Tail of Two Bitmaps



Okay :)  Here's the gory details.

If alphaInfo is kCGImageAlphaPremultipliedFirst and I try to draw the resulting image into a rectangle that is smaller than the image, I get junk.
If alphaInfo is kCGImageAlphaNoneSkipLast, I can draw into a smaller rectangle without problem.


Both versions spit out the same values to the log window.

Mark

---

csRenderBitmap::csRenderBitmap( csCount width, csCount height )
{
		this->fImage		= null;
		this->fWidth		= width;
		this->fHeight		= height;
		
		CGColorSpaceRef			colorSpace = null;
		
		try
			{
					colorSpace = CGColorSpaceCreateDeviceRGB();
					ThrowIfNullPointer( colorSpace );

					size_t bitsPerComponent		= csRenderBitmap::kBitsPerComponent;
					//size_t bitsPerPixel = csRenderBitmap::kBitsPerPixel;
					csCount bytesPerRow = this->_calculateBytesPerRow();
					CGImageAlphaInfo alphaInfo = kCGImageAlphaPremultipliedFirst;
					//   kCGImageAlphaNoneSkipLast


//::fprintf( csLog::Out(),
// "csRenderBitmap::csRenderBitmap:\n"
// " width = %d\n"
// " height = %d\n"
// " bitsPerComponent = %d\n"
// " bitsPerPixel = %d\n"
// " bytesPerRow = %d\n"
// " alphaInfo = %d\n",
// this->fWidth, this->fHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, alphaInfo
// );


this->fImageData.allocate( bytesPerRow * this->fHeight );
// uses malloc to allocate the block


CGContextRef context = ::CGBitmapContextCreate( this->fImageData.pointer(), this->fWidth, this->fHeight, bitsPerComponent,
bytesPerRow, colorSpace, alphaInfo );
//kCGImageAlphaNoneSkipLast kCGImageAlphaPremultipliedLast kCGImageAlphaPremultipliedFirst
ThrowIfNullPointer( context );

this->setContext( context, true );
}
catch( const csException& ex )
{
this->setContext( null, false ); // just to be sure.
this->fWidth = this->fHeight = 0;
}

::CGColorSpaceRelease( colorSpace );
}



CGImageRef csRenderBitmap::createImage()
{
if( null == this->getContext() )
return null;

if( null != this->fImage )
return this->fImage;

CGDataProviderRef provider = null;

try
{
provider = ::CGDataProviderCreateWithData( null, this->fImageData.pointer(), this->fImageData.size(), null );
ThrowIfNullPointer( provider );

size_t width = ::CGBitmapContextGetWidth( this->getContext() );
size_t height = ::CGBitmapContextGetHeight( this->getContext() );
size_t bitsPerComponent = ::CGBitmapContextGetBitsPerComponent( this->getContext() );
size_t bitsPerPixel = ::CGBitmapContextGetBitsPerPixel( this->getContext() );
size_t bytesPerRow = ::CGBitmapContextGetBytesPerRow( this->getContext() );
CGImageAlphaInfo alphaInfo = ::CGBitmapContextGetAlphaInfo( this->getContext() );

//::fprintf( csLog::Out(),
// "csRenderBitmap::createImage:\n"
// " width = %d\n"
// " height = %d\n"
// " bitsPerComponent = %d\n"
// " bitsPerPixel = %d\n"
// " bytesPerRow = %d\n"
// " alphaInfo = %d\n",
// width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, alphaInfo
// );

this->fImage = ::CGImageCreate( width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, ::CGBitmapContextGetColorSpace( this->getContext() ),
alphaInfo, provider, null, true, kCGRenderingIntentDefault );

}
catch( const csException& ex )
{
this->_resetImage();
}

::CGDataProviderRelease( provider );

return this->fImage;

}


_______________________________________________
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
References: 
 >A Tail of Two Bitmaps (From: Mark Morrill <email@hidden>)
 >Re: A Tail of Two Bitmaps (From: Scott Thompson <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.