예제 #1
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 );
}
예제 #2
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 );
}
예제 #3
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;
}
예제 #4
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);
  }
}
예제 #5
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 ) );
}
예제 #6
0
void PicoFreeFileFunc( void* file ){
	vfsFreeFile( file );
}
예제 #7
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);
}
예제 #8
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);
}
예제 #9
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);
}