Re: A Tail of Two Bitmaps
Subject : Re: A Tail of Two Bitmaps
From: Mark Morrill <email@hidden >
Date: Tue, 31 May 2005 15:42:28 -0600
Delivered-to: email@hidden
Delivered-to: email@hidden
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:mime-version:in-reply-to:references:content-type:message-id:content-transfer-encoding:from:subject:date:to:x-mailer; b=BfSnar1Vz9HP3R40Zdgmp+OSTHMH++5VPnjKw5lJJhlX61RLNEtJT7Icvigw+UgreT3aPOM+ffhnjPnJJUbY5XKiUf9OKD4/Er35PNgV3QVdnx71aibN4JUUpy0YFcXOMBlNWtAutviKrnpO6tXRNRHroZY/YkA7LTck0ExgxX0=
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
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.