char *txtpal = new char[strlen(palname) + 10]; strcpy(txtpal, palname); strcat(txtpal, ".txt"); cout << "Creating text (Gimp) palette '" << txtpal << "'" << endl; ofstream pout(txtpal); pout << "Palette from Exult's Ipack" << endl; int i; for (i = palsize - 1; i > 0; i--) if (palette[3*i] != 0 || palette[3*i+1] != 0 || palette[3*i+2] != 0) break; int last_color = i; for (i = 0; i <= last_color; i++) { int r = palette[3*i], g = palette[3*i + 1], b = palette[3*i + 2]; pout << setw(3) << r << ' ' << setw(3) << g << ' ' << setw(3) << b << endl; } pout.close(); delete txtpal;
void Write_palette	(	char *palname, 	unsigned char *palette, 	// 3 bytes for each color.	int palsize			// # entries.	)	{	unsigned char palbuf[3*256];	// We always write 256 colors.	memset(&palbuf[0], 0, sizeof(palbuf));	if (palsize > 256)		// Shouldn't happen.		palsize = 256;					// Convert 0-255 to 0-63 for Exult.	for (int i = 0; i < 3*palsize; i++)		palbuf[i] = palette[i]/4;	ofstream out;	U7open(out, palname);		// May throw exception.	Flex_writer writer(out, "Exult palette by Ipack", 1);	out.write(&palbuf[0], sizeof(palbuf));	writer.mark_section_done();	if (!writer.close())		throw file_write_exception(palname);	}