Ejemplo n.º 1
0
Image* LoadMDLImageBuff( byte* buffer ){
	if ( !LoadPalette() ) {
		return 0;
	}

	if ( !ident_equal( buffer, MDL_IDENT ) ) {
		globalErrorStream() << "LoadMDLImage: data has wrong ident\n";
		return 0;
	}

	PointerInputStream inputStream( buffer );
	inputStream.seek( 4 + 4 + 12 + 12 + 4 + 12 );
	//int numskins =
	istream_read_int32_le( inputStream );
	int skinwidth = istream_read_int32_le( inputStream );
	int skinheight = istream_read_int32_le( inputStream );
	inputStream.seek( 4 + 4 + 4 + 4 + 4 + 4 );

	switch ( istream_read_int32_le( inputStream ) )
	{
	case MDL_SKIN_SINGLE:
		break;
	case MDL_SKIN_GROUP:
		int numskins = istream_read_int32_le( inputStream );
		inputStream.seek( numskins * 4 );
		break;
	}

	RGBAImage* image = new RGBAImage( skinwidth, skinheight );
	unsigned char* pRGBA = image->getRGBAPixels();

	for ( int i = 0; i < ( skinheight ); i++ )
	{
		for ( int j = 0; j < ( skinwidth ); j++ )
		{
			byte index = istream_read_byte( inputStream );
			*pRGBA++ = mdl_palette[index * 3 + 0];
			*pRGBA++ = mdl_palette[index * 3 + 1];
			*pRGBA++ = mdl_palette[index * 3 + 2];
			*pRGBA++ = 255;
		}
	}

	return image;
}
Ejemplo n.º 2
0
inline void targa_header_read_istream(TargaHeader& targa_header, PointerInputStream& istream)
{
  targa_header.id_length = istream_read_byte(istream);
  targa_header.colormap_type = istream_read_byte(istream);
  targa_header.image_type = istream_read_byte(istream);

  targa_header.colormap_index = istream_read_int16_le(istream);
  targa_header.colormap_length = istream_read_int16_le(istream);
  targa_header.colormap_size = istream_read_byte(istream);
  targa_header.x_origin = istream_read_int16_le(istream);
  targa_header.y_origin = istream_read_int16_le(istream);
  targa_header.width = istream_read_int16_le(istream);
  targa_header.height = istream_read_int16_le(istream);
  targa_header.pixel_size = istream_read_byte(istream);
  targa_header.attributes = istream_read_byte(istream);

  if (targa_header.id_length != 0)
    istream.seek(targa_header.id_length);	// skip TARGA image comment
}
Ejemplo n.º 3
0
void LoadPCXBuff(byte* buffer, std::size_t len, byte **pic, byte **palette, int *width, int *height )
{
  *pic = 0;

  pcx_t	pcx;
  int		x, y, lsize;
  byte	*out, *pix;

  /* parse the PCX file */

  PointerInputStream inputStream(buffer);

  pcx.manufacturer = istream_read_byte(inputStream);
  pcx.version = istream_read_byte(inputStream);
  pcx.encoding = istream_read_byte(inputStream);
  pcx.bits_per_pixel = istream_read_byte(inputStream);
  pcx.xmin = istream_read_int16_le(inputStream);
  pcx.ymin = istream_read_int16_le(inputStream);
  pcx.xmax = istream_read_int16_le(inputStream);
  pcx.ymax = istream_read_int16_le(inputStream);
  pcx.hres = istream_read_int16_le(inputStream);
  pcx.vres = istream_read_int16_le(inputStream);
  inputStream.read(pcx.palette, 48);
  pcx.reserved = istream_read_byte(inputStream);
  pcx.color_planes = istream_read_byte(inputStream);
  pcx.bytes_per_line = istream_read_int16_le(inputStream);
  pcx.palette_type = istream_read_int16_le(inputStream);
  inputStream.read(pcx.filler, 58);


  if (pcx.manufacturer != 0x0a
    || pcx.version != 5
    || pcx.encoding != 1
    || pcx.bits_per_pixel != 8)
    return;

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

  if (!pic)
    return;

  out = (byte *)malloc ( (pcx.ymax+1) * (pcx.xmax+1) );

  *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 */
      PCXRLEPacket packet;
      ByteStream_readPCXRLEPacket(inputStream, packet);

      while(packet.length-- > 0)
      {
        pix[ x++ ] = packet.data;
      }
    }

    /* RR2DO2: discard any other data */
    PCXRLEPacket packet;
    while( x < lsize )
    {
      ByteStream_readPCXRLEPacket(inputStream, packet);
      x++;
    }
    while( packet.length-- > 0 )
    {
      x++;
    }
  }

  /* validity check */
  if( std::size_t(inputStream.get() - buffer) > len)
  {
    *pic = 0;
  }

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