Example #1
0
void palette_load_table( char * filename )
{
	int i;
	int w, h;
	int pcx_error;

	strcpy( palette_base_filename, filename );
	char * p = strchr(palette_base_filename,'.');
	if ( p )	{
		*p = 0;
	}

	pcx_error = pcx_read_header(palette_base_filename, NULL, &w, &h, NULL, palette_org );
	if ( pcx_error != PCX_ERROR_NONE )	{
		// Read the old .256 file
		CFILE *fp;
		int fsize;
		fp = cfopen( palette_base_filename, "rb" );
		if ( fp==NULL)
			Error( LOCATION, "Can't open palette file <%s>",palette_base_filename);

		fsize	= cfilelength( fp );
		Assert( fsize == 9472 );
		cfread( palette_org, 256*3, 1, fp );
		cfclose(fp);

		for (i=0; i<768; i++ )	{	
			palette_org[i] = ubyte((palette_org[i]*255)/63);
		}
	}

	palette_base_loaded = 1;

	gr_set_palette(palette_base_filename, palette_org);
}
Example #2
0
// initialize nebula stuff - call from game_post_level_init(), so the mission has been loaded
void neb2_post_level_init()
{
	int idx;

	// standalone servers can bail here
	if (Game_mode & GM_STANDALONE_SERVER) {
		return;
	}

	// Skip actual rendering if we're in FRED.
	if(Fred_running)
	{
		Neb2_render_mode = NEB2_RENDER_NONE;
		return;
	}

	// if the mission is not a fullneb mission, skip
	if ( !((The_mission.flags[Mission::Mission_Flags::Fullneb]) || Nebula_sexp_used) ) {
		Neb2_render_mode = NEB2_RENDER_NONE;
		Neb2_awacs = -1.0f;
		return;
	}

	// Set a default colour just in case something goes wrong
	Neb2_fog_color_r =  30;
	Neb2_fog_color_g =  52;
	Neb2_fog_color_b = 157;

	// OK, lets try something a bit more interesting
	if (strlen(Neb2_texture_name)) {
		Neb2_htl_fog_data = new ubyte[768];

		if ((Neb2_htl_fog_data != NULL) && (pcx_read_header(Neb2_texture_name, NULL, NULL, NULL, NULL, Neb2_htl_fog_data) == PCX_ERROR_NONE)) {
			// based on the palette, get an average color value (this doesn't really account for actual pixel usage though)
			ushort r = 0, g = 0, b = 0, pcount = 0;
			for (idx = 0; idx < 768; idx += 3) {
				if (Neb2_htl_fog_data[idx] || Neb2_htl_fog_data[idx+1] || Neb2_htl_fog_data[idx+2]) {
					r = r + Neb2_htl_fog_data[idx];
					g = g + Neb2_htl_fog_data[idx+1];
					b = b + Neb2_htl_fog_data[idx+2];
					pcount++;
				}
			}

			if (pcount > 0) {
				Neb2_fog_color_r = (ubyte)(r / pcount);
				Neb2_fog_color_g = (ubyte)(g / pcount);
				Neb2_fog_color_b = (ubyte)(b / pcount);
			} else {
				// it's just black
				Neb2_fog_color_r = Neb2_fog_color_g = Neb2_fog_color_b = 0;
			}

			// done, now free up the palette data
			if ( Neb2_htl_fog_data != NULL ) {
				delete[] Neb2_htl_fog_data;
				Neb2_htl_fog_data = NULL;
			}
		}
	}

	Neb2_render_mode = NEB2_RENDER_HTL;

	// load in all nebula bitmaps
	for (idx=0; idx<Neb2_poof_count; idx++) {
		if (Neb2_poofs[idx] < 0) {
			Neb2_poofs[idx] = bm_load(Neb2_poof_filenames[idx]);
		}
	}

	pneb_tried = 0;
	pneb_tossed_alpha = 0;
	pneb_tossed_dot = 0;
	neb_tried = 0;
	neb_tossed_alpha = 0;
	neb_tossed_dot = 0;
	neb_tossed_count = 0;

	// setup proper fogging values
	Neb_backg_fog_near = NEB_BACKG_FOG_NEAR_D3D;
	Neb_backg_fog_far = NEB_BACKG_FOG_FAR_D3D;

	// regen the nebula
	neb2_eye_changed();

	// if we are going to use fullneb, but aren't fullneb yet, then be sure to reset our mode
	if ( !(The_mission.flags[Mission::Mission_Flags::Fullneb]) ) {
		Neb2_render_mode = NEB2_RENDER_NONE;
		Neb2_awacs = -1.0f;
	}
}
Example #3
0
// bitmap functions
int gr_stub_bm_load(ubyte type, int n, char *filename, CFILE *img_cfp, int *w, int *h, int *bpp, ubyte *c_type, int *mm_lvl, int *size)
{
	int dds_ct;

	if (type == BM_TYPE_DDS) {
		int dds_error = dds_read_header( filename, img_cfp, w, h, bpp, &dds_ct, mm_lvl, size );
		if (dds_error != DDS_ERROR_NONE) {
			mprintf(("DDS ERROR: Couldn't open '%s' -- %s\n", filename, dds_error_string(dds_error)));
			return -1;
		}

		switch (dds_ct) {
			case DDS_DXT1:
				*c_type = BM_TYPE_DXT1;
				break;

			case DDS_DXT3:
				*c_type = BM_TYPE_DXT3;
				break;

			case DDS_DXT5:
				*c_type = BM_TYPE_DXT5;
				break;

			case DDS_UNCOMPRESSED:
				*c_type = BM_TYPE_DDS;
				break;

			case DDS_CUBEMAP_DXT1:
				*c_type = BM_TYPE_CUBEMAP_DXT1;
				break;

			case DDS_CUBEMAP_DXT3:
				*c_type = BM_TYPE_CUBEMAP_DXT3;
				break;

			case DDS_CUBEMAP_DXT5:
				*c_type = BM_TYPE_CUBEMAP_DXT5;
				break;

			case DDS_CUBEMAP_UNCOMPRESSED:
				*c_type = BM_TYPE_CUBEMAP_DDS;
				break;

			default:
				Error(LOCATION, "bad DDS file compression.  Not using DXT1,3,5 %s", filename);
				return -1;
		}
	}
	// if its a tga file
	else if (type == BM_TYPE_TGA) {
		int tga_error = targa_read_header( filename, img_cfp, w, h, bpp, NULL );
		if ( tga_error != TARGA_ERROR_NONE )	{
			mprintf(( "tga: Couldn't open '%s'\n", filename ));
			return -1;
		}
	}
	// if its a jpg file
	else if (type == BM_TYPE_JPG) {
		int jpg_error=jpeg_read_header( filename, img_cfp, w, h, bpp, NULL );
		if ( jpg_error != JPEG_ERROR_NONE ) {
			mprintf(( "jpg: Couldn't open '%s'\n", filename ));
			return -1;
		}
	}
	// if its a pcx file
	else if (type == BM_TYPE_PCX) {
		int pcx_error = pcx_read_header( filename, img_cfp, w, h, bpp, NULL );
		if ( pcx_error != PCX_ERROR_NONE )	{
			mprintf(( "pcx: Couldn't open '%s'\n", filename ));
			return -1;
		}
	} else {
		Assert( 0 );

		return -1;
	}

	return 0;
}
Example #4
0
int convert_frames_to_anim(char *filename)
{
	int first_frame, frame, pos, width, height, xparent_pal_index, r = -1;
	char ani_filename[255], name[255], temp[8];	
	int rc;
	FILE *fp;

	Assert(strlen(filename) < 254);
	strcpy(name, filename);
	strcpy(ani_filename, filename);
	strcpy(ani_filename + strlen(ani_filename) - 8, ".ani");
	pos = strlen(name) - 8;
	frame = first_frame = atoi(&name[pos]);
	force_key_frame -= frame;

	// first file
	fp = fopen(name, "rb");
	if(fp != NULL){
		do {
			fclose(fp);
			frame++;
			sprintf(temp, "%04.4d", frame);
			strncpy(&name[pos], temp, 4);	

			// next file
			fp = fopen(name, "rb");
		} while(fp != NULL);	
	}

	rc = pcx_read_header(filename, &width, &height, NULL);
	if (rc != PCX_ERROR_NONE) {
		fprintf(stdout, "An error reading the PCX file %s.  It may not exist.\n", filename);
		return -1;
	}

	cur_frame = (ubyte *) malloc(width * height);
	last_frame = (ubyte *) malloc(width * height);

	rc = pcx_read_bitmap_8bpp(filename, cur_frame, Anim.palette);
	if (rc != PCX_ERROR_NONE) {
		fprintf(stdout, "An error reading the PCX file %s.  It may not exist.\n", filename);
		return -1;
	}

	if (Use_custom_xparent_color) {
		// Need to look at pixel in top-left 
		xparent_pal_index = ((ubyte *) cur_frame)[0];
		Xparent_color.r = Anim.palette[xparent_pal_index * 3];
		Xparent_color.g = Anim.palette[xparent_pal_index * 3 + 1];
		Xparent_color.b = Anim.palette[xparent_pal_index * 3 + 2];

	} else {
		Xparent_color.r = 0;
		Xparent_color.g = 255;
		Xparent_color.b = 0;
	}

	if (anim_save_init(ani_filename, width, height, frame - first_frame))
		goto done;

	while (first_frame < frame) {
		sprintf(temp, "%04.4d", first_frame);
		strncpy(&name[pos], temp, 4);
		rc = pcx_read_bitmap_8bpp(name, cur_frame, Anim.palette);
		if (rc != PCX_ERROR_NONE)
			goto done;

		if (anim_save_frame())
			goto done;

		first_frame++;
	}

	if (save_anim_header())
		goto done;

	r = 0;

done:
	fclose(anim_fp);
	free(cur_frame);
	free(last_frame);
	fprintf(stdout, "\n");
	fflush(stdout);
	return r;
}