Ejemplo n.º 1
0
Image* LoadHLWBuff( byte* buffer ){
	byte *buf_p;
	unsigned long mipdatasize;
	int columns, rows, numPixels;
	byte *pixbuf;
	int row, column;
	byte *palette;
	LPWAD3_MIP lpMip;
	unsigned char red, green, blue, alphabyte;

	lpMip = (LPWAD3_MIP)buffer; //!\todo Make endian-safe.

	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;

	RGBAImage* image = new RGBAImage( columns, rows );

	for ( row = 0; row < rows; row++ )
	{
		pixbuf = image->getRGBAPixels() + 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;
		}
	}

	return image;
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
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);
}