Ejemplo n.º 1
0
void tga_save(const char *name)
{
  FILE *fp;
  if ( tga_data == NULL )
    return;
  
  //printf("tga_save: File %s with %dx%d pixel\n", name, tga_width, tga_height);
  
  fp = fopen(name, "wb");
  if ( fp != NULL )
  {
    tga_write_byte(fp, 0);		/* no ID */
    tga_write_byte(fp, 0);		/* no color map */
    tga_write_byte(fp, 2);		/* uncompressed true color */
    tga_write_word(fp, 0);		
    tga_write_word(fp, 0);		
    tga_write_byte(fp, 0);		
    tga_write_word(fp, 0);		/* x origin */
    tga_write_word(fp, 0);		/* y origin */
    tga_write_word(fp, tga_width);		/* width */
    tga_write_word(fp, tga_height);		/* height */
    tga_write_byte(fp, 24);		/* color depth */
    tga_write_byte(fp, 0);		
    fwrite(tga_data, tga_width*tga_height*3, 1, fp);
    tga_write_word(fp, 0);
    tga_write_word(fp, 0);
    tga_write_word(fp, 0);
    tga_write_word(fp, 0);
    fwrite("TRUEVISION-XFILE.", 18, 1, fp);
    fclose(fp);
  }
}
Ejemplo n.º 2
0
void u8x8_bitmap_SaveTGA(u8x8_bitmap_t *b, const char *name)
{
  FILE *fp;
  uint16_t x, y;
  
  fp = fopen(name, "wb");
  if ( fp != NULL )
  {
    tga_write_byte(fp, 0);		/* no ID */
    tga_write_byte(fp, 0);		/* no color map */
    tga_write_byte(fp, 2);		/* uncompressed true color */
    tga_write_word(fp, 0);		
    tga_write_word(fp, 0);		
    tga_write_byte(fp, 0);		
    tga_write_word(fp, 0);		/* x origin */
    tga_write_word(fp, 0);		/* y origin */
    tga_write_word(fp, b->pixel_width);		/* width */
    tga_write_word(fp, b->pixel_height);		/* height */
    tga_write_byte(fp, 24);		/* color depth */
    tga_write_byte(fp, 0);	
    for( y = 0; y < b->pixel_height; y++ )
    {
      for( x = 0; x < b->pixel_width; x++ )
      {
	if ( u8x8_bitmap_GetPixel(b, x, b->pixel_height-y-1) == 0 )
	{
	  tga_write_byte(fp, 255);		/* R */
	  tga_write_byte(fp, 255);		/* G */
	  tga_write_byte(fp, 255);		/* B */
	}
	else
	{
	  tga_write_byte(fp, 0);		/* R */
	  tga_write_byte(fp, 0);		/* G */
	  tga_write_byte(fp, 0);		/* B */
	}
      }
    }
    tga_write_word(fp, 0);
    tga_write_word(fp, 0);
    tga_write_word(fp, 0);
    tga_write_word(fp, 0);
    fwrite("TRUEVISION-XFILE.", 18, 1, fp);
    fclose(fp);
  }
}
Ejemplo n.º 3
0
static void tga_write_word(FILE *fp, uint16_t word)
{
  tga_write_byte(fp, word&255);
  tga_write_byte(fp, word>>8);
}