png_struct *png;
png_info *info, *end;
pngBuffer_t pb;
- int bitDepth, colorType, channels;
+ int bitDepth, colorType;
png_uint_32 w, h, i;
byte **rowPointers;
png_get_IHDR( png, info,
&w, &h, &bitDepth, &colorType, NULL, NULL, NULL );
- /* read number of channels */
- channels = png_get_channels( png, info );
-
/* the following will probably bork on certain types of png images, but hey... */
/* force indexed/gray/trans chunk to rgb */
char name[ 1024 ];
int size;
byte *buffer = NULL;
+ qboolean alphaHack = qfalse;
/* init */
{
if( LoadJPGBuff( buffer, size, &image->pixels, &image->width, &image->height ) == -1 && image->pixels != NULL )
Sys_Printf( "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels );
+ alphaHack = qtrue;
}
else
{
/* set count */
image->refCount = 1;
numImages++;
+
+ if(alphaHack)
+ {
+ StripExtension( name );
+ strcat( name, "_alpha.jpg" );
+ size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
+ if( size > 0 )
+ {
+ unsigned char *pixels;
+ int width, height;
+ if( LoadJPGBuff( buffer, size, &pixels, &width, &height ) == -1 && pixels != NULL )
+ Sys_Printf( "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels );
+ if(pixels && width == image->width && height == image->height)
+ {
+ int i;
+ for(i = 0; i < width*height; ++i)
+ image->pixels[4*i+3] = pixels[4*i+2]; // copy alpha from blue channel
+ }
+ free(pixels);
+ free(buffer);
+ }
+ }
/* return the image */
return image;