예제 #1
0
파일: scriplib.c 프로젝트: clbr/netradiant
/*
==============
AddScriptToStack
==============
*/
void AddScriptToStack (const char *filename, int index)
{
  int size;

  script++;
  if (script == &scriptstack[MAX_INCLUDES])
    Error ("script file exceeded MAX_INCLUDES");
  strcpy (script->filename, ExpandPath (filename));

  size = vfsLoadFile (script->filename, (void **)&script->buffer, index);

  if (size == -1)
    Sys_Printf ("Script file %s was not found\n", script->filename);
  else
  {
    if (index > 0)
      Sys_Printf ("entering %s (%d)\n", script->filename, index+1);
    else
      Sys_Printf ("entering %s\n", script->filename);
  }

  script->line = 1;
  script->script_p = script->buffer;
  script->end_p = script->buffer + size;
}
예제 #2
0
void LoadWAL( const char *name, unsigned char **pic, int *width, int *height ) {
//    FILE      *f;
    miptex_t    *wal_header;
//    rgb_t	*palette;
    int i, num_pixels, size;
//    char	text_buf[255];
    unsigned int length;
    unsigned char   *palette_ent, *buf_temp;
    unsigned char       *buffer, *wal_file_buffer;

    // open file
    if ( ( length = vfsLoadFile( (char *) name, (void **) &wal_file_buffer, 0 ) ) == (unsigned int) -1 ) {
        Sys_Printf( "Unable to open file %s\n",name );
        return;
    }

    wal_header = (miptex_t *)wal_file_buffer;

    // make sure we have a valid bitmap file
    if ( wal_header->width & 15 ) {
        vfsFreeFile( wal_file_buffer );
        Sys_Printf( "Invalid WAL file %s: Width not multiple of 16!\n", name );
        return;
    }

    if ( wal_header->height & 15 ) {
        vfsFreeFile( wal_file_buffer );
        Sys_Printf( "Invalid WAL file %s: Height not multiple of 16!\n", name );
        return;
    }


    // Get WAL Info
    *width    = wal_header->width;      // Only interested in 1st MIP
    *height   = wal_header->height;
    num_pixels = ( *width ) * ( *height );
    size = num_pixels * 4;

    // Allocate buffer
    buf_temp = (unsigned char *)( g_malloc( size ) );
    *pic = buf_temp;

    // Image data
    buffer = wal_file_buffer + wal_header->offsets[0];


    // Load texture into buffer
    palette_ent = buffer;
    for ( i = 0; i < num_pixels; i++ )
    {
        *buf_temp++ = quake2_palette[*palette_ent][0];
        *buf_temp++ = quake2_palette[*palette_ent][1];
        *buf_temp++ = quake2_palette[*palette_ent][2];
        *buf_temp++ = 255;      // No alpha
        palette_ent++;
    }

    vfsFreeFile( wal_file_buffer );
}
예제 #3
0
파일: jpeg.cpp 프로젝트: AEonZR/GtkRadiant
void LoadJPG( const char *filename, unsigned char **pic, int *width, int *height ) {
  unsigned char *fbuffer = NULL;
  int nLen = vfsLoadFile ((char *)filename, (void **)&fbuffer, 0 );
  if (nLen == -1)
    return;

  if ( LoadJPGBuff( fbuffer, nLen, pic, width, height ) != 0 ) {
    g_FuncTable.m_pfnSysPrintf( "WARNING: JPEG library failed to load %s because %s\n", filename, *pic );
    *pic = NULL;
  }

  vfsFreeFile( fbuffer );
}
예제 #4
0
bool LoadPalette(){
	unsigned char* buffer;
	//int len =
	vfsLoadFile( "gfx/palette.lmp", (void **) &buffer );
	if ( buffer == 0 ) {
		return false;
	}

	Texture_InitPalette( buffer );

	vfsFreeFile( buffer );

	return true;
}
예제 #5
0
void WINAPI QERApp_LoadShaderFile (const char *filename)
{
  char *pBuff;
  int nSize = vfsLoadFile (filename, reinterpret_cast < void **>(&pBuff), 0);
  if (nSize > 0)
  {
    Sys_Printf ("Parsing shaderfile %s\n", filename);
    g_ScripLibTable.m_pfnStartTokenParsing (pBuff);
    while (g_ScripLibTable.m_pfnGetToken (true))
    {
      // first token should be the path + name.. (from base)
      CShader *pShader = new CShader ();
      // we want the relative filename only, it's easier for later lookup .. see QERApp_ReloadShaderFile
      char cTmp[1024];
      g_FuncTable.m_pfnQE_ConvertDOSToUnixName (cTmp, filename);
      // given the vfs, we should not store the full path
      //pShader->setShaderFileName( filename + strlen(ValueForKey(g_qeglobals.d_project_entity, "basepath")));
      pShader->setShaderFileName (filename);
      if (pShader->Parse ())
      {
	      // do we already have this shader?
	      //++timo NOTE: this may a bit slow, we may need to use a map instead of a dumb list
	      if (g_Shaders.Shader_ForName (pShader->getName ()) != NULL)
	      {
#ifdef _DEBUG
	        Sys_Printf ("WARNING: shader %s is already in memory, definition in %s ignored.\n",
		            pShader->getName (), filename);
#endif
	        delete pShader;
	      }
	      else
	      {
	        pShader->IncRef ();

	        g_Shaders.Add ((void *) pShader);
	      }
      }
      else
      {
	      Sys_Printf ("Error parsing shader %s\n", pShader->getName ());
	      delete pShader;
      }
    }
    vfsFreeFile (pBuff);
  }
  else
  {
    Sys_Printf ("Unable to read shaderfile %s\n", filename);
  }
}
예제 #6
0
/*
=============
LoadTGA
=============
*/
void LoadTGA(const char *name, byte ** pixels, int *width, int *height)
{
	byte           *buffer;
	int             nLen;

	//
	// load the file
	//
	nLen = vfsLoadFile((char *)name, (void **)&buffer, 0);
	if(nLen == -1)
	{
		Error("Couldn't read %s", name);
	}

	LoadTGABuffer(buffer, pixels, width, height);

}
예제 #7
0
void ViewShader( const char *pFile, const char *pName ){
	char* pBuff = 0;
	//int nSize =
	vfsLoadFile( pFile, reinterpret_cast<void**>( &pBuff ) );
	if ( pBuff == 0 ) {
		globalErrorStream() << "Failed to load shader file " << pFile << "\n";
		return;
	}
	// look for the shader declaration
	StringOutputStream strFind( string_length( pName ) );
	strFind << LowerCase( pName );
	StringOutputStream strLook( string_length( pBuff ) );
	strFind << LowerCase( pBuff );
	// offset used when jumping over commented out definitions
	std::size_t nOffset = 0;
	while ( true )
	{
		const char* substr = strstr( strFind.c_str() + nOffset, strFind.c_str() );
		if ( substr == 0 ) {
			break;
		}
		std::size_t nStart = substr - strLook.c_str();
		// we have found something, maybe it's a commented out shader name?
		char *strCheck = new char[string_length( strLook.c_str() ) + 1];
		strcpy( strCheck, strLook.c_str() );
		strCheck[nStart] = 0;
		char *pCheck = strrchr( strCheck, '\n' );
		// if there's a commentary sign in-between we'll continue
		if ( pCheck && strstr( pCheck, "//" ) ) {
			delete[] strCheck;
			nOffset = nStart + 1;
			continue;
		}
		delete[] strCheck;
		nOffset = nStart;
		break;
	}
	// now close the file
	vfsFreeFile( pBuff );

	DoTextEditor( pFile, static_cast<int>( nOffset ) );
}
예제 #8
0
/*
==============
LoadBMP
==============
*/
void LoadBMP(const char *filename, byte ** pic, byte ** palette, int *width, int *height)
{
	byte           *out;
	int             i;
	int             bfSize;
	int             bfOffBits;
	int             structSize;
	int             bcWidth;
	int             bcHeight;
	int             bcPlanes;
	int             bcBitCount;
	byte            bcPalette[1024];
	qboolean        flipped;
	byte           *in;
	int             len, pos = 0;

	len = vfsLoadFile(filename, (void **)&in, 0);
	if(len == -1)
	{
		Error("Couldn't read %s", filename);
	}

	i = bufLittleShort(in, len, &pos);
	if(i != 'B' + ('M' << 8))
	{
		Error("%s is not a bmp file", filename);
	}

	bfSize = bufLittleLong(in, len, &pos);
	bufLittleShort(in, len, &pos);
	bufLittleShort(in, len, &pos);
	bfOffBits = bufLittleLong(in, len, &pos);

	// the size will tell us if it is a
	// bitmapinfo or a bitmapcore
	structSize = bufLittleLong(in, len, &pos);
	if(structSize == 40)
	{
		// bitmapinfo
		bcWidth = bufLittleLong(in, len, &pos);
		bcHeight = bufLittleLong(in, len, &pos);
		bcPlanes = bufLittleShort(in, len, &pos);
		bcBitCount = bufLittleShort(in, len, &pos);

		pos += 24;

		if(palette)
		{
			memcpy(bcPalette, in + pos, 1024);
			pos += 1024;
			*palette = safe_malloc(768);

			for(i = 0; i < 256; i++)
			{
				(*palette)[i * 3 + 0] = bcPalette[i * 4 + 2];
				(*palette)[i * 3 + 1] = bcPalette[i * 4 + 1];
				(*palette)[i * 3 + 2] = bcPalette[i * 4 + 0];
			}
		}
	}
	else if(structSize == 12)
	{
		// bitmapcore
		bcWidth = bufLittleShort(in, len, &pos);
		bcHeight = bufLittleShort(in, len, &pos);
		bcPlanes = bufLittleShort(in, len, &pos);
		bcBitCount = bufLittleShort(in, len, &pos);

		if(palette)
		{
			memcpy(bcPalette, in + pos, 768);
			pos += 768;
			*palette = safe_malloc(768);

			for(i = 0; i < 256; i++)
			{
				(*palette)[i * 3 + 0] = bcPalette[i * 3 + 2];
				(*palette)[i * 3 + 1] = bcPalette[i * 3 + 1];
				(*palette)[i * 3 + 2] = bcPalette[i * 3 + 0];
			}
		}
	}
	else
	{
		Error("%s had strange struct size", filename);
	}

	if(bcPlanes != 1)
	{
		Error("%s was not a single plane image", filename);
	}

	if(bcBitCount != 8)
	{
		Error("%s was not an 8 bit image", filename);
	}

	if(bcHeight < 0)
	{
		bcHeight = -bcHeight;
		flipped = qtrue;
	}
	else
	{
		flipped = qfalse;
	}

	if(width)
		*width = bcWidth;
	if(height)
		*height = bcHeight;

	if(!pic)
	{
		free(in);
		return;
	}

	out = safe_malloc(bcWidth * bcHeight);
	*pic = out;
	pos = bfOffBits;

	if(flipped)
	{
		for(i = 0; i < bcHeight; i++)
		{
			memcpy(out + bcWidth * (bcHeight - 1 - i), in + pos, bcWidth);
			pos += bcWidth;
		}
	}
	else
	{
		memcpy(out, in + pos, bcWidth * bcHeight);
		pos += bcWidth * bcHeight;
	}

	free(in);
}
예제 #9
0
void LoadPCX(const char *filename, byte ** pic, byte ** palette, int *width, int *height)
{
	byte           *raw;
	pcx_t          *pcx;
	int             x, y, lsize;
	int             len;
	int             dataByte, runLength;
	byte           *out, *pix;


	/* load the file */
	len = vfsLoadFile(filename, (void **)&raw, 0);
	if(len == -1)
		Error("LoadPCX: Couldn't read %s", filename);


	/* parse the PCX file */
	pcx = (pcx_t *) raw;
	raw = &pcx->data;

	pcx->xmin = LittleShort(pcx->xmin);
	pcx->ymin = LittleShort(pcx->ymin);
	pcx->xmax = LittleShort(pcx->xmax);
	pcx->ymax = LittleShort(pcx->ymax);
	pcx->hres = LittleShort(pcx->hres);
	pcx->vres = LittleShort(pcx->vres);
	pcx->bytes_per_line = LittleShort(pcx->bytes_per_line);
	pcx->palette_type = LittleShort(pcx->palette_type);

	if(pcx->manufacturer != 0x0a
	   || pcx->version != 5 || pcx->encoding != 1 || pcx->bits_per_pixel != 8 || pcx->xmax >= 640 || pcx->ymax >= 480)
		Error("Bad pcx file %s", filename);

	if(palette)
	{
		*palette = safe_malloc(768);
		memcpy(*palette, (byte *) pcx + len - 768, 768);
	}

	if(width)
		*width = pcx->xmax + 1;
	if(height)
		*height = pcx->ymax + 1;

	if(!pic)
		return;

	out = safe_malloc((pcx->ymax + 1) * (pcx->xmax + 1));
	if(!out)
		Error("LoadPCX: couldn't allocate");

	*pic = out;
	pix = out;

	/* RR2DO2: pcx fix  */
	lsize = pcx->color_planes * pcx->bytes_per_line;

	/* go scanline by scanline */
	for(y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1)
	{
		/* do a scanline */
		for(x = 0; x <= pcx->xmax;)
		{
			/* RR2DO2 */
			DECODEPCX(raw, dataByte, runLength);
			while(runLength-- > 0)
				pix[x++] = dataByte;
		}

		/* RR2DO2: discard any other data */
		while(x < lsize)
		{
			DECODEPCX(raw, dataByte, runLength);
			x++;
		}
		while(runLength-- > 0)
			x++;
	}

	/* validity check */
	if(raw - (byte *) pcx > len)
		Error("PCX file %s was malformed", filename);
	free(pcx);
}
예제 #10
0
파일: image.c 프로젝트: clbr/netradiant
image_t *ImageLoad( const char *filename )
{
	int			i;
	image_t		*image;
	char		name[ 1024 ];
	int			size;
	byte		*buffer = NULL;
	qboolean	alphaHack = qfalse;

	
	/* init */
	ImageInit();
	
	/* dummy check */
	if( filename == NULL || filename[ 0 ] == '\0' )
		return NULL;
	
	/* strip file extension off name */
	strcpy( name, filename );
	StripExtension( name );
	
	/* try to find existing image */
	image = ImageFind( name );
	if( image != NULL )
	{
		image->refCount++;
		return image;
	}
	
	/* none found, so find first non-null image */
	image = NULL;
	for( i = 0; i < MAX_IMAGES; i++ )
	{
		if( images[ i ].name == NULL )
		{
			image = &images[ i ];
			break;
		}
	}
	
	/* too many images? */
	if( image == NULL )
		Error( "MAX_IMAGES (%d) exceeded, there are too many image files referenced by the map.", MAX_IMAGES );
	
	/* set it up */
	image->name = safe_malloc( strlen( name ) + 1 );
	strcpy( image->name, name );
	
	/* attempt to load tga */
	StripExtension( name );
	strcat( name, ".tga" );
	size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
	if( size > 0 )
		LoadTGABuffer( buffer, buffer + size, &image->pixels, &image->width, &image->height );
	else
	{
		/* attempt to load png */
		StripExtension( name );
		strcat( name, ".png" );
		size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
		if( size > 0 )
			LoadPNGBuffer( buffer, size, &image->pixels, &image->width, &image->height );
		else
		{
			/* attempt to load jpg */
			StripExtension( name );
			strcat( name, ".jpg" );
			size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
			if( size > 0 )
			{
				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
			{
				/* attempt to load dds */
				StripExtension( name );
				strcat( name, ".dds" );
				size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
				if( size > 0 )
				{
					LoadDDSBuffer( buffer, size, &image->pixels, &image->width, &image->height );
					
					/* debug code */
					#if 1
					{
						ddsPF_t	pf;
						DDSGetInfo( (ddsBuffer_t*) buffer, NULL, NULL, &pf );
						Sys_Printf( "pf = %d\n", pf );
						if( image->width > 0 )
						{
							StripExtension( name );
							strcat( name, "_converted.tga" );
							WriteTGA( "C:\\games\\quake3\\baseq3\\textures\\rad\\dds_converted.tga", image->pixels, image->width, image->height );
						}
					}
					#endif
				}
			}
		}
	}
	
	/* free file buffer */
	free( buffer );
	
	/* make sure everything's kosher */
	if( size <= 0 || image->width <= 0 || image->height <= 0 || image->pixels == NULL )
	{
		//%	Sys_Printf( "size = %d  width = %d  height = %d  pixels = 0x%08x (%s)\n",
		//%		size, image->width, image->height, image->pixels, name );
		free( image->name );
		image->name = NULL;
		return NULL;
	}
	
	/* set filename */
	image->filename = safe_malloc( strlen( name ) + 1 );
	strcpy( image->filename, name );
	
	/* 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;
}
예제 #11
0
void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize ){
	*bufSize = vfsLoadFile( (const char*) name, (void**) buffer, 0 );
}
예제 #12
0
static void LoadMIP (const char *name, byte ** pic, int *width, int *height)
{
  byte *buffer;
  byte *buf_p;
  unsigned int length, palettelength;
  unsigned long mipdatasize;
  int columns, rows, numPixels;
  byte *pixbuf;
  int i;
  byte *bmpRGBA;
  byte *loadedpalette;
  const byte *palette;
  LPWAD3_MIP		lpMip;

  *pic = NULL;
  loadedpalette = NULL;

  //
  // load the file
  //
  length = vfsLoadFile ((char *) name, (void **) &buffer, 0);
  if (length == (unsigned int) -1)
    return;

  lpMip = (LPWAD3_MIP)buffer;

  mipdatasize = GET_MIP_DATA_SIZE(lpMip->width,lpMip->height);

  palettelength = vfsLoadFile ("textures/palette.lmp", (void **) &loadedpalette, 0);
  if (palettelength == 768)
    palette = loadedpalette;
  else
  {
    loadedpalette = NULL;
    palette = quakepalette;
  }

  buf_p = buffer+lpMip->offsets[0];

  columns = lpMip->width;
  rows = lpMip->height;
  numPixels = columns * rows;

  if (width)
    *width = columns;
  if (height)
    *height = rows;

  //Sys_Printf("lpMip->width = %i, lpMip->height = %i, lpMip->offsets[0] = %i, lpMip->offsets[1] = %i, lpMip->offsets[2] = %i, lpMip->offsets[3] = %i, numPixels = %i\n", lpMip->width, lpMip->height, lpMip->offsets[0], lpMip->offsets[1], lpMip->offsets[2], lpMip->offsets[3], numPixels);
  //for (i = 0; i < sizeof(*lpMip); i++)
  //  Sys_Printf("%02x", (int) ((unsigned char *)lpMip)[i]);

  bmpRGBA = reinterpret_cast < unsigned char *>(g_malloc (numPixels * 4));
  *pic = bmpRGBA;
  pixbuf = bmpRGBA;

  for (i = 0; i < numPixels; i++)
  {
    int palIndex = *buf_p++;
    *pixbuf++ = palette[palIndex*3];
    *pixbuf++ = palette[palIndex*3+1];
    *pixbuf++ = palette[palIndex*3+2];
    *pixbuf++ = 0xff;
  }

  vfsFreeFile (buffer);
  if (loadedpalette != NULL)
    vfsFreeFile (loadedpalette);
}
예제 #13
0
static void LoadHLW (const char *name, byte ** pic, int *width, int *height)
{
  byte *buffer;
  byte *buf_p;
  unsigned int length;
  unsigned long mipdatasize;
  int columns, rows, numPixels;
  byte *pixbuf;
  int row, column;
  byte *bmpRGBA;
  byte *palette;
	LPWAD3_MIP		lpMip;
	unsigned char red, green, blue, alphabyte;

  *pic = NULL;

  //
  // load the file
  //
  length = vfsLoadFile ((char *) name, (void **) &buffer, 0);
  if (length == (unsigned int) -1)
    return;

  lpMip = (LPWAD3_MIP)buffer;

  mipdatasize = GET_MIP_DATA_SIZE(lpMip->width,lpMip->height);

  palette = buffer+mipdatasize+2;

  buf_p = buffer+lpMip->offsets[0];

  columns = lpMip->width;
  rows = lpMip->height;
  numPixels = columns * rows;

  if (width)
    *width = columns;
  if (height)
    *height = rows;

  bmpRGBA = reinterpret_cast < unsigned char *>(g_malloc (numPixels * 4));
  *pic = bmpRGBA;

  for (row = 0; row < rows; row++)
  {
    pixbuf = bmpRGBA + row * columns * 4;

    for (column = 0; column < columns; column++)
    {
      int palIndex;

	    palIndex = *buf_p++;

      red = *(palette+(palIndex*3));
      green = *(palette+(palIndex*3)+1);
      blue = *(palette+(palIndex*3)+2);

      // HalfLife engine makes pixels that are BLUE transparent.
      // So show them that way in the editor.
      if (blue == 0xff && red == 0x00 && green == 0x00)
      {
        alphabyte = 0x00;
        blue = 0x00; // don't set the resulting pixel to blue
      }
      else
      {
        alphabyte = 0xff;
      }

	    *pixbuf++ = red;
	    *pixbuf++ = green;
	    *pixbuf++ = blue;

	    *pixbuf++ = alphabyte;
    }
  }

  vfsFreeFile (buffer);
}
예제 #14
0
static void LoadIDSP (const char *name, byte ** pic, int *width, int *height)
{
  byte *buffer;
  byte *buf_p;
  unsigned int length;
  int columns, rows, numPixels;
  byte *pixbuf;

  int row, column;
  byte *bmpRGBA;
  byte *palette;
	unsigned char red, green, blue, alphabyte;

  dspriteheader_t *header;
 	dspritev1_t			*pinv1;
 	dspritev2_t			*pinv2;
	dspriteframetype_t	*pframetype;
	int					version;
	int					numframes;
	int					size;
  spriteframetype_t	frametype;
  dspriteframe_t *spriteframe;

  *pic = NULL;

  //
  // load the file
  //
  length = vfsLoadFile ((char *) name, (void **) &buffer, 0);
  if (length == (unsigned int) -1)
    return;

  header = (dspriteheader_t *)buffer;

  if (header->ident != IDSPRITEHEADER)
  {
    Sys_Printf ("WARNING: %s has wrong header\n");
    vfsFreeFile (buffer);
    return;
  }

  version = header->version;
  if (version != 1 && version != 2 )
  {
    Sys_Printf ("WARNING: %s has wrong version number "
				 "(%i should be 1 or 2)\n", name, version);
    vfsFreeFile (buffer);
    return;
  }

  // initialise variables depending on the sprite version.
  switch (version)
  {
    case 1:
	    pinv1 = (dspritev1_t *)(header+1);
      numframes = pinv1->numframes;
      columns = pinv1->width;
      rows = pinv1->height;
    	pframetype = (dspriteframetype_t *)(pinv1 + 1);
      break;
    case 2:
	    pinv2 = (dspritev2_t *)(header+1);
      numframes = pinv2->numframes;
      columns = pinv2->width;
      rows = pinv2->height;
      pframetype = (dspriteframetype_t *)(pinv2 + 1);
      break;
  }
  if (numframes > 1)
    Sys_Printf ("WARNING: %s has multiple frames, only the first frame will be used.\n", name);

  // palette = buffer+mipdatasize+2;
  // buf_p = buffer+lpMip->offsets[0];

  numPixels = columns * rows;

  if (width)
    *width = columns;
  if (height)
    *height = rows;

  bmpRGBA = reinterpret_cast < unsigned char *>(g_malloc (numPixels * 4));
  *pic = bmpRGBA;

#ifdef DEBUG
	frametype = spriteframetype_t(LittleLong(pframetype->type));
	if (frametype == SPR_SINGLE)
  {
    Sys_Printf("Single Frame\n");
  }
  else if (frametype == SPR_GROUP)
  {
    Sys_Printf("Group of Frames\n");
  }
  else
  {
    Sys_Printf("Bleh!\n"); // <-- we always get this, wtf!
  }
#endif

  palette = (byte *)(pframetype+1);
  spriteframe = (dspriteframe_t *)(palette + (256*3) + 4); // what are those 4 extra bytes ? what's missing ?
  buf_p = (byte *)(spriteframe + 1);

  int temp;

  temp = buf_p - buffer;

  for (row = 0; row < rows; row++)
  {
    pixbuf = bmpRGBA + row * columns * 4;

    for (column = 0; column < columns; column++)
    {
      int palIndex;

	    palIndex = *buf_p++;

      red = *(palette+(palIndex*3));
      green = *(palette+(palIndex*3)+1);
      blue = *(palette+(palIndex*3)+2);

      // HalfLife engine makes pixels that are BLUE transparent. (RGB = 0x0000FF)
      // So show them that way in the editor.
      if (blue == 0xff && red == 0x00 && green == 0x00)
      {
        alphabyte = 0xff; //FIXME: backwards? (so sprite models to render correctly)
        blue = 0x00; // don't set the resulting pixel to blue
      }
      else
      {
        alphabyte = 0x00; //FIXME: backwards? (so sprite models to render correctly)
      }

	    *pixbuf++ = red;
	    *pixbuf++ = green;
	    *pixbuf++ = blue;

	    *pixbuf++ = alphabyte;
    }
  }

  vfsFreeFile (buffer);
}
예제 #15
0
image_t        *ImageLoad(const char *filename)
{
    int             i;
    image_t        *image;
    char            name[1024];
    int             size;
    byte           *buffer = NULL;


    /* init */
    ImageInit();

    /* dummy check */
    if(filename == NULL || filename[0] == '\0')
        return NULL;

    /* strip file extension off name */
    strcpy(name, filename);
    StripExtension(name);

    /* try to find existing image */
    image = ImageFind(name);
    if(image != NULL)
    {
        image->refCount++;
        return image;
    }

    /* none found, so find first non-null image */
    image = NULL;
    for(i = 0; i < MAX_IMAGES; i++)
    {
        if(images[i].name == NULL)
        {
            image = &images[i];
            break;
        }
    }

    /* too many images? */
    if(image == NULL)
        Error("MAX_IMAGES (%d) exceeded, there are too many image files referenced by the map.", MAX_IMAGES);

    /* set it up */
    image->name = safe_malloc(strlen(name) + 1);
    strcpy(image->name, name);

#if 1
    /* attempt to load tga */
    StripExtension(name);
    strcat(name, ".tga");
    size = vfsLoadFile((const char *)name, (void **)&buffer, 0);
    if(size > 0)
        LoadTGABuffer(buffer, &image->pixels, &image->width, &image->height);
    else
    {
#if 1
        /* attempt to load png */
        StripExtension(name);
        strcat(name, ".png");
        size = vfsLoadFile((const char *)name, (void **)&buffer, 0);
        if(size > 0)
            LoadPNGBuffer(buffer, &image->pixels, &image->width, &image->height);
        else
        {
#if 1
            /* attempt to load jpg */
            StripExtension(name);
            strcat(name, ".jpg");
            size = vfsLoadFile((const char *)name, (void **)&buffer, 0);
            if(size > 0)
            {
                LoadJPGBuffer((const char *)name, buffer, size, &image->pixels, &image->width, &image->height);
                if(image->pixels == NULL)
                    Sys_Printf("WARNING: LoadJPGBuffer: '%s'\n", image->name);
            }
            else
            {
#if 1
                /* attempt to load dds */
                StripExtension(name);
                strcat(name, ".dds");
                size = vfsLoadFile((const char *)name, (void **)&buffer, 0);
                if(size > 0)
                {
                    LoadDDSBuffer(buffer, size, &image->pixels, &image->width, &image->height);

                    /* debug code */
#if 0
                    {
                        ddsPF_t         pf;

                        DDSGetInfo((ddsBuffer_t *) buffer, NULL, NULL, &pf);
                        Sys_Printf("pf = %d\n", pf);
                        if(image->width > 0)
                        {
                            StripExtension(name);
                            strcat(name, "_converted.tga");
                            WriteTGA("C:\\games\\quake3\\baseq3\\textures\\rad\\dds_converted.tga", image->pixels, image->width,
                                     image->height);
                        }
                    }
#endif							// dds debug
                }
#endif							// ignore dds
            }
#endif							// ignore jpg dds
        }
#endif							// ignore png jpg dds
    }
#endif							// ignore all images

    /* free file buffer */
    free(buffer);

    /* make sure everything's kosher */
    if(size <= 0 || image->width <= 0 || image->height <= 0 || image->pixels == NULL)
    {
        //% Sys_Printf( "size = %d  width = %d  height = %d  pixels = 0x%08x (%s)\n",
        //%     size, image->width, image->height, image->pixels, name );
        free(image->name);
        image->name = NULL;
        return NULL;
    }

    /* set filename */
    image->filename = safe_malloc(strlen(name) + 1);
    strcpy(image->filename, name);

    /* set count */
    image->refCount = 1;
    numImages++;

    /* return the image */
    return image;
}