Exemple #1
0
void tga::print_header(FILE* fp, const dimension& dim, const ColorTable& ct)
{
	const char BITS_PER_COLOR = 24;
	const char BIT_PER_PIXEL = 8; // GIMP does not allow 16

	// 0-0: no image id field
	// 1-1: color map? yes
	// 2-2: image type: color mapped
	fwrite("\x00\x01\x01", 1, 3, fp);

	// color map:
	// 0-1: index of first entry (=0)
	// 2-3: number of entries
	// 4-4: bpp to describe each color
	fwrite("\x00\x00", 1, 2, fp);
	const short number_of_colors = ct.num_colors();
	fwrite(&number_of_colors, 1, 2, fp);
	fwrite(&BITS_PER_COLOR, 1, 1, fp);

	// 0-1: x-origin (=0)
	// 2-3: y-origin (=0)
	fwrite("\x00\x00\x00\x00", 1, 4, fp);

	const short width = dim.width() - 2;
	fwrite(&width, 2, 1,  fp);
	const short height = dim.height() - 2;
	fwrite(&height, 2, 1, fp);

	// 0: pixel depth (=BPP)
	// 1: bits 3-0: attributes per pixel (=alpha?) =0
	// 1: bits 4-5: left-right => set bit 4
	// 1: bits 6-7: reserved to be 0
	fwrite(&BIT_PER_PIXEL, 1, 1, fp);
	fwrite("\x20", 1, 1, fp);

}