PNG+Alpha
Does anyone have any C sources that could split a PNG+Alpha file into two picture handles? The first handle would have the picture and the second handle would store the alpha mask.
Thank you in advance!
Thank you in advance!
Picture handles? Do you mean OpenGL texture or really the old-school PixMapHandles? Either way, it should be simple. Just copy three bytes from the image to the "color part", then one byte to the "alpha part", and repeat.
Like Fenris, I'm not sure exactly what you need to know from your question, but here's something which might give you some pointers.... I wrote the AlphaPicture plugin for REALbasic which uses QuickTime to load any QT-compatible image, then splits it into a separate colour image and alpha channel. Of course, there are a few calls to REALbasic's plugin API which you can disregard, but most of the code is relevant if you want to use QuickTime. It should give you an idea of the general principle in any case.
The source file is nominally C++, but most of the code is plain C.
The source file is nominally C++, but most of the code is plain C.
Fenris Wrote:Picture handles? Do you mean OpenGL texture or really the old-school PixMapHandles? Either way, it should be simple. Just copy three bytes from the image to the "color part", then one byte to the "alpha part", and repeat.
The variable type is PicHandle. I am currently using two PICT files to make a map and I want to move over to PNG+Alpha.
I need to put a PNG+Alpha file into two PicHandles, one for the sprite, one for the alpha. After that, my existing code will take care of the rest.
I found some code from OneSadCookie's site. I made some changes until I got this. Works like a charm!
Code:
void NewTextureMapFromPNG ( ConstStr255Param fileName, int ID )
{
OSStatus err;
Rect rect;
GraphicsImportComponent import;
ComponentResult result;
void * data;
GWorldPtr world;
FSSpec fsSpec;
OSErr osErr;
osErr = FSMakeFSSpec ( dataFolder.vRefNum, dataFolder.parID, fileName, &fsSpec );
err = GetGraphicsImporterForFile ( &fsSpec, &import);
result = GraphicsImportGetNaturalBounds ( import, &rect );
data = malloc ( 4 * rect.bottom * rect.right );
err = QTNewGWorldFromPtr ( &world, k32ARGBPixelFormat, &rect, NULL, NULL, 0, data, 4 * rect.right );
result = GraphicsImportSetGWorld ( import, world, NULL );
result = GraphicsImportDraw ( import );
err = CloseComponent ( import );
glGenTextures ( 1, &map [ ID ] .ID );
glBindTexture ( GL_TEXTURE_2D, map [ ID ] .ID );
glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
map [ ID ] .size = rect.right;
glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA8, rect.right, rect.bottom, 0, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, data );
DisposeGWorld ( world );
}
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| png without alpha fine, png with alpha, nothing | dave05 | 6 | 5,669 |
Jun 11, 2005 10:31 AM Last Post: dave05 |
|

