コード例 #1
0
ファイル: palette.c プロジェクト: gameplayer22/d2x-1
void gr_use_palette_table( char * filename )
{
	CFILE *fp;
	int i,fsize;

	fp = cfopen( filename, "rb" );
	if ( fp==NULL)
		Error("Can't open palette file <%s>",filename);

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

	// This is the TRANSPARENCY COLOR
	for (i=0; i<GR_FADE_LEVELS; i++ )	{
		gr_fade_table[i*256+255] = 255;
	}

	Num_computed_colors = 0;	//	Flush palette cache.
#if defined(POLY_ACC)
    pa_update_clut(gr_palette, 0, 256, 0);
#endif
}
コード例 #2
0
ファイル: pcxutils.cpp プロジェクト: lubomyr/freespace2
// reads header information from the PCX file into the bitmap pointer
int pcx_read_header(char *real_filename, int *w, int *h, ubyte *pal )
{
	PCXHeader header;
	CFILE * PCXfile;
	char filename[MAX_FILENAME_LEN];
		
	strcpy( filename, real_filename );
	char *p = strchr( filename, '.' );
	if ( p ) *p = 0;
	strcat( filename, ".pcx" );

	PCXfile = cfopen( filename , "rb" );
	if ( !PCXfile )
		return PCX_ERROR_OPENING;

	// read 128 char PCX header
	if (cfread( &header, sizeof(PCXHeader), 1, PCXfile )!=1)	{
		cfclose( PCXfile );
		return PCX_ERROR_NO_HEADER;
	}
        header.Xmin = INTEL_SHORT( header.Xmin );
        header.Ymin = INTEL_SHORT( header.Ymin );
        header.Xmax = INTEL_SHORT( header.Xmax );
        header.Ymax = INTEL_SHORT( header.Ymax );
        header.Hdpi = INTEL_SHORT( header.Hdpi );
        header.Vdpi = INTEL_SHORT( header.Vdpi );
        for ( int i=0; i<16; i++ ){
            for ( int j=0; j<3; j++){
                header.ColorMap[i][j] = INTEL_INT( header.ColorMap[i][j] );
            }
        }
        header.BytesPerLine = INTEL_SHORT( header.BytesPerLine );
        for ( int i=0; i<60; i++ ){
            header.filler[i] = INTEL_INT( header.filler[i] );
        }

	// Is it a 256 color PCX file?
	if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5))	{
		cfclose( PCXfile );
		return PCX_ERROR_WRONG_VERSION;
	}

	if (w) *w = header.Xmax - header.Xmin + 1;
	if (h) *h = header.Ymax - header.Ymin + 1;
	
	if ( pal ) {
		cfseek( PCXfile, -768, CF_SEEK_END );
		cfread( pal, 3, 256, PCXfile );
	}

	cfclose(PCXfile);
	return PCX_ERROR_NONE;
}
コード例 #3
0
ファイル: palette.c プロジェクト: btb/d2x
void gr_use_palette_table( char * filename )
{
	CFILE *fp;
	int i,fsize;
#ifdef SWAP_0_255
	ubyte c;
#endif

	fp = cfopen( filename, "rb" );

	// the following is a hack to enable the loading of d2 levels
	// even if only the d2 mac shareware datafiles are present.
	// However, if the pig file is present but the palette file isn't,
	// the textures in the level will look wierd...
	if ( fp==NULL)
		fp = cfopen( DEFAULT_LEVEL_PALETTE, "rb" );
	if ( fp==NULL)
		Error("Can open neither palette file <%s> "
		      "nor default palette file <"
		      DEFAULT_LEVEL_PALETTE
		      ">.\n",
		      filename);

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

	// This is the TRANSPARENCY COLOR
	for (i=0; i<GR_FADE_LEVELS; i++ )	{
		gr_fade_table[i*256+255] = 255;
	}

	Num_computed_colors = 0;	//	Flush palette cache.
// swap colors 0 and 255 of the palette along with fade table entries

#ifdef SWAP_0_255
	for (i = 0; i < 3; i++) {
		c = gr_palette[i];
		gr_palette[i] = gr_palette[765+i];
		gr_palette[765+i] = c;
	}

	for (i = 0; i < GR_FADE_LEVELS * 256; i++) {
		if (gr_fade_table[i] == 0)
			gr_fade_table[i] = 255;
	}
	for (i=0; i<GR_FADE_LEVELS; i++)
		gr_fade_table[i*256] = TRANSPARENCY_COLOR;
#endif
}
コード例 #4
0
unsigned int apng_ani::_read_chunk(_chunk_s& chunk)
{
	_offset = cftell(_cfp);
	if (cfread(&chunk.data[0], 4, 1, _cfp) == 1) {
		chunk.size = png_get_uint_32(&chunk.data[0]) + 12;
		// reduce the amount of vector resizing
		if (chunk.size > _max_chunk_size) {
			_max_chunk_size = chunk.size;
			chunk.data.resize(chunk.size);
		}
		if (cfread(&chunk.data[4], chunk.size-4, 1, _cfp) == 1) {
			return *(uint*)(&chunk.data[4]);
		}
	}
	return 0;
}
コード例 #5
0
/*
 * reads n polymodel structs from a CFILE
 */
extern int polymodel_read_n(polymodel *pm, int n, CFILE *fp)
{
	int i, j;

	for (i = 0; i < n; i++) {
		pm[i].n_models = cfile_read_int(fp);
		pm[i].model_data_size = cfile_read_int(fp);
		pm[i].model_data = (ubyte *) (size_t)cfile_read_int(fp);
		for (j = 0; j < MAX_SUBMODELS; j++)
			pm[i].submodel_ptrs[j] = cfile_read_int(fp);
		for (j = 0; j < MAX_SUBMODELS; j++)
			cfile_read_vector(&(pm[i].submodel_offsets[j]), fp);
		for (j = 0; j < MAX_SUBMODELS; j++)
			cfile_read_vector(&(pm[i].submodel_norms[j]), fp);
		for (j = 0; j < MAX_SUBMODELS; j++)
			cfile_read_vector(&(pm[i].submodel_pnts[j]), fp);
		for (j = 0; j < MAX_SUBMODELS; j++)
			pm[i].submodel_rads[j] = cfile_read_fix(fp);
		cfread(pm[i].submodel_parents, MAX_SUBMODELS, 1, fp);
		for (j = 0; j < MAX_SUBMODELS; j++)
			cfile_read_vector(&(pm[i].submodel_mins[j]), fp);
		for (j = 0; j < MAX_SUBMODELS; j++)
			cfile_read_vector(&(pm[i].submodel_maxs[j]), fp);
		cfile_read_vector(&(pm[i].mins), fp);
		cfile_read_vector(&(pm[i].maxs), fp);
		pm[i].rad = cfile_read_fix(fp);
		pm[i].n_textures = cfile_read_byte(fp);
		pm[i].first_texture = cfile_read_short(fp);
		pm[i].simpler_model = cfile_read_byte(fp);
	}
	return i;
}
コード例 #6
0
ファイル: piggy.c プロジェクト: devint1/Descent-Mobile
void piggy_read_sounds()
{
	ubyte * ptr;
	int i, sbytes;

	ptr = SoundBits;
	sbytes = 0;

	for (i=0; i<Num_sound_files; i++ )	{
		digi_sound *snd = &GameSounds[i];

		if ( SoundOffset[i] > 0 )	{
			if ( piggy_is_needed(i) )	{
				cfseek( Piggy_fp, SoundOffset[i], SEEK_SET );

				// Read in the sound data!!!
				snd->data = ptr;
				ptr += snd->length;
				sbytes += snd->length;
				cfread( snd->data, snd->length, 1, Piggy_fp );
			}
		}
	}

	mprintf(( 0, "\nActual Sound usage: %d KB\n", sbytes/1024 ));

}
コード例 #7
0
unsigned char anim_instance_get_byte(anim_instance *ai, int offset)
{
	int absolute_offset;
	anim *parent;
	
	Assert(ai);
	Assert(ai->parent->cfile_ptr);
	Assert(ai->parent->flags & ANF_STREAMED);

	parent = ai->parent;
	absolute_offset = ai->file_offset + offset;

	// maybe in cache?
	int cache_offset;
	cache_offset = absolute_offset - parent->cache_file_offset;
	if ( (cache_offset >= 0) && (cache_offset < ANI_STREAM_CACHE_SIZE) ) {
		return parent->cache[cache_offset];
	} else {
		// fill cache
		cfseek(parent->cfile_ptr, absolute_offset, CF_SEEK_SET);
		cfread(parent->cache, ANI_STREAM_CACHE_SIZE, 1, parent->cfile_ptr);
		parent->cache_file_offset = absolute_offset;
		return parent->cache[0];
	}
}
コード例 #8
0
ファイル: palman.cpp プロジェクト: svn2github/FS2Open_Trunk
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);
}
コード例 #9
0
ファイル: polyobj.c プロジェクト: gameplayer22/d2x-1
/*
 * reads a polymodel structure from a CFILE
 */
extern void polymodel_read(polymodel *pm, CFILE *fp)
{
	int i;

	pm->n_models = cfile_read_int(fp);
	pm->model_data_size = cfile_read_int(fp);
	pm->model_data = (ubyte *) cfile_read_int(fp);
	for (i = 0; i < MAX_SUBMODELS; i++)
		pm->submodel_ptrs[i] = cfile_read_int(fp);
	for (i = 0; i < MAX_SUBMODELS; i++)
		cfile_read_vector(&(pm->submodel_offsets[i]), fp);
	for (i = 0; i < MAX_SUBMODELS; i++)
		cfile_read_vector(&(pm->submodel_norms[i]), fp);
	for (i = 0; i < MAX_SUBMODELS; i++)
		cfile_read_vector(&(pm->submodel_pnts[i]), fp);
	for (i = 0; i < MAX_SUBMODELS; i++)
		pm->submodel_rads[i] = cfile_read_fix(fp);
	cfread(pm->submodel_parents, MAX_SUBMODELS, 1, fp);
	for (i = 0; i < MAX_SUBMODELS; i++)
		cfile_read_vector(&(pm->submodel_mins[i]), fp);
	for (i = 0; i < MAX_SUBMODELS; i++)
		cfile_read_vector(&(pm->submodel_maxs[i]), fp);
	cfile_read_vector(&(pm->mins), fp);
	cfile_read_vector(&(pm->maxs), fp);
	pm->rad = cfile_read_fix(fp);
	pm->n_textures = cfile_read_byte(fp);
	pm->first_texture = cfile_read_short(fp);
	pm->simpler_model = cfile_read_byte(fp);
}
コード例 #10
0
ファイル: bitfile.c プロジェクト: Sjord/checkmate
int bitfile_readbits(BITFILE * b, size_t length) {
	int result;
	int left;
	char ch;
	unsigned int mask;

	result = 0;
	do {
		if (b->bitoffset == 0) {
			cfread(& (b->currentchar), 1, b->fp);
		}
		mask = (1 << length) - 1;
		left = BYTEBITS - b->bitoffset - length;
		if (left > 0) {
			// 'left' bits remain in this byte
			ch = b->currentchar >> left;
			b->bitoffset = (b->bitoffset + length) % BYTEBITS;
			length = 0;
		} else {
			// abs(left) bits are in the next byte
			left = abs(left);
			ch = b->currentchar << left;
			b->bitoffset = (b->bitoffset + length - left) % BYTEBITS;
			length = left;
		}
		result |= ch & mask;
	} while (length);
コード例 #11
0
void pilotfile_convert::plr_import_hud()
{
	int idx;
	conv_color c;

	plr->hud_show_flags = cfread_int(cfp);
	plr->hud_show_flags2 = cfread_int(cfp);

	plr->hud_popup_flags = cfread_int(cfp);
	plr->hud_popup_flags2 = cfread_int(cfp);

	plr->hud_num_lines = cfread_ubyte(cfp);
	plr->hud_rp_flags = cfread_int(cfp);
	plr->hud_rp_dist = cfread_int(cfp);

	for (idx = 0; idx < 39; idx++) {
		cfread(&c, sizeof(conv_color), 1, cfp);

		if ( (c.alphacolor != -1) || (c.is_alphacolor != 1) ) {
			throw "Data check failure in hud!";
		}

		plr->hud_colors[idx][0] = c.red;
		plr->hud_colors[idx][1] = c.green;
		plr->hud_colors[idx][2] = c.blue;
		plr->hud_colors[idx][3] = c.alpha;
	}
}
コード例 #12
0
boolean jpeg_cf_fill_input_buffer(j_decompress_ptr cinfo)
{
	cfile_src_ptr src = (cfile_src_ptr)cinfo->src;
	size_t nbytes;

	nbytes = cfread(src->buffer, 1, INPUT_BUF_SIZE, src->infile);

	if (nbytes <= 0)
	{
		if (src->start_of_file)
		{	// Treat empty input file as fatal error
			Jpeg_Set_Error(JPEG_ERROR_READING);
		}

		// Insert a fake EOI marker
		src->buffer[0] = (JOCTET)0xFF;
		src->buffer[1] = (JOCTET)JPEG_EOI;
		nbytes = 2;

		return FALSE;
	}

	src->pub.next_input_byte = src->buffer;
	src->pub.bytes_in_buffer = nbytes;
	src->start_of_file = FALSE;

	return TRUE;
}
コード例 #13
0
ファイル: cfile.c プロジェクト: gameplayer22/d2x-1
byte cfile_read_byte(CFILE *file)
{
	byte b;

	if (cfread( &b, sizeof(b), 1, file) != 1)
		Error( "Error reading byte in cfile_read_byte()" );

	return b;
}
コード例 #14
0
ファイル: GAMEMINE.C プロジェクト: NonCreature0714/descent2
static byte read_byte(CFILE *file)
{
	byte b;

	if (cfread( &b, sizeof(b), 1, file) != 1)
		Error( "Error reading byte in gamesave.c" );

	return b;
}
コード例 #15
0
ファイル: GAMEMINE.C プロジェクト: NonCreature0714/descent2
static fix read_fix(CFILE *file)
{
	fix f;

	if (cfread( &f, sizeof(f), 1, file) != 1)
		Error( "Error reading fix in gamesave.c" );

	f = (fix)INTEL_INT((int)f);
	return f;
}
コード例 #16
0
ファイル: cfile.c プロジェクト: gameplayer22/d2x-1
fixang cfile_read_fixang(CFILE *file)
{
	fixang f;

	if (cfread(&f, 2, 1, file) != 1)
		Error("Error reading fixang in cfile_read_fixang()");

	f = (fixang) INTEL_SHORT((int) f);
	return f;
}
コード例 #17
0
ファイル: cfile.c プロジェクト: gameplayer22/d2x-1
fix cfile_read_fix(CFILE *file)
{
	fix f;

	if (cfread( &f, sizeof(f), 1, file) != 1)
		Error( "Error reading fix in cfile_read_fix()" );

	f = (fix)INTEL_INT((int)f);
	return f;
}
コード例 #18
0
ファイル: cfile.c プロジェクト: gameplayer22/d2x-1
short cfile_read_short(CFILE *file)
{
	int16_t s;

	if (cfread( &s, sizeof(s), 1, file) != 1)
		Error( "Error reading short in cfile_read_short()" );

	s = INTEL_SHORT(s);
	return s;
}
コード例 #19
0
ファイル: cfile.c プロジェクト: gameplayer22/d2x-1
int cfile_read_int(CFILE *file)
{
	int32_t i;

	if (cfread( &i, sizeof(i), 1, file) != 1)
		Error( "Error reading int in cfile_read_int()" );

	i = INTEL_INT(i);
	return i;
}
コード例 #20
0
ファイル: GAMEMINE.C プロジェクト: NonCreature0714/descent2
static short read_short(CFILE *file)
{
	short s;

	if (cfread( &s, sizeof(s), 1, file) != 1)
		Error( "Error reading short in gamesave.c" );

	s = INTEL_SHORT(s);
	return s;
}
コード例 #21
0
ファイル: palette.c プロジェクト: arbruijn/d1xnacl
void gr_use_palette_table( char * filename )
{
	CFILE *fp;
	int i,fsize;

	fp = cfopen( filename, "rb" );
	if ( fp==NULL)
		Error("Can't open palette file <%s>",filename);

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

	// This is the TRANSPARENCY COLOR
	for (i=0; i<GR_FADE_LEVELS; i++ )	{
		gr_fade_table[i*256+255] = 255;
	}
}
コード例 #22
0
void fiction_viewer_load(const char *filename, const char *font_filename, const char *voice_filename)
{
	int file_length;
	Assertion(filename, "Invalid fictionviewer filename pointer given!");
	Assertion(font_filename, "Invalid fictionviewer font filename pointer given!");
	Assertion(voice_filename, "Invalid fictionviewer voice filename pointer given!");

	// just to be sure
	if (Fiction_viewer_text != NULL)
	{
		Int3();
		fiction_viewer_reset();
	}

	// save our filenames
	strcpy_s(Fiction_viewer_filename, filename);
	strcpy_s(Fiction_viewer_font_filename, font_filename);
	strcpy_s(Fiction_viewer_voice_filename, voice_filename);

	// see if we have a matching font
	Fiction_viewer_fontnum = gr_get_fontnum(Fiction_viewer_font_filename);
	if (Fiction_viewer_fontnum < 0 && !Fred_running)
		strcpy_s(Fiction_viewer_font_filename, "");

	Fiction_viewer_voice = audiostream_open(Fiction_viewer_voice_filename, ASF_VOICE);
	if (Fiction_viewer_voice < 0 && !Fred_running)
		strcpy_s(Fiction_viewer_voice_filename, "");

	if (!strlen(filename))
		return;

	// load up the text
	CFILE *fp = cfopen(filename, "rb", CFILE_NORMAL, CF_TYPE_FICTION);
	if (fp == NULL)
	{
		Warning(LOCATION, "Unable to load fiction file '%s'.", filename);
		return;
	}

	// we don't need to copy the text in Fred
	if (!Fred_running)
	{
		// allocate space
		file_length = cfilelength(fp);
		Fiction_viewer_text = (char *) vm_malloc(file_length + 1);
		Fiction_viewer_text[file_length] = '\0';

		// copy all the text
		cfread(Fiction_viewer_text, file_length, 1, fp);
	}

	// we're done, close it out
	cfclose(fp);
}
コード例 #23
0
/*
 * routine which allocates, reads, and inits a polymodel's model_data
 */
void polygon_model_data_read(polymodel *pm, CFILE *fp)
{
	pm->model_data = d_malloc(pm->model_data_size);
	Assert(pm->model_data != NULL);
	cfread(pm->model_data, sizeof(ubyte), pm->model_data_size, fp );
#ifdef WORDS_NEED_ALIGNMENT
	align_polygon_model_data(pm);
#endif
#ifdef WORDS_BIGENDIAN
	swap_polygon_model_data(pm->model_data);
#endif
}
コード例 #24
0
ファイル: cfilelist.cpp プロジェクト: lubomyr/freespace2
// cfread() reads from a file and decompresses it
//
// returns:   returns the number of full elements read
//            
//
int cfread_compressed(void *buf, int elsize, int nelem, CFILE *cfile)
{
	char *out = (char *)buf;
	
	while(1)	{

		byte count;

		if ( cfread( &count, 1, 1, cfile ) != 1 )	{
			break;
		}

		int run_span = count & 0x80;
		count &= (~0x80);
		count++;

		if ( count > 0 )	{
			if ( run_span )	{
				// RLE'd data
				byte c;
				if ( cfread( &c, 1, 1, cfile ) != 1 )	{
					break;
				}
				memset( out, c, count );
			} else {
				if ( cfread( out, 1, count, cfile ) != count )	{
					break;
				}
			}
			out += count;
			if ( out >= (char *)buf + (elsize*nelem))	{
				break;
			}
		} else {
			break;
		}
	}

	return (out - (char *)buf)/elsize;
}
コード例 #25
0
//copy/pasted from libpng
void png_scp_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
	png_size_t check;

	if (png_ptr == NULL)
		return;
	/* fread() returns 0 on error, so it is OK to store this in a png_size_t
	* instead of an int, which is what fread() actually returns.
	*/
	check = (png_size_t)cfread(data, (png_size_t)1, length, png_file);
	if (check != length)
		png_error(png_ptr, "Read Error");
}
コード例 #26
0
// reads header information from the PCX file into the bitmap pointer
int pcx_read_header(char *real_filename, int *w, int *h, ubyte *pal )
{
	PCXHeader header;
	CFILE * PCXfile;
	char filename[MAX_FILENAME_LEN];
		
	strcpy( filename, real_filename );
	char *p = strchr( filename, '.' );
	if ( p ) *p = 0;
	strcat( filename, ".pcx" );

	PCXfile = cfopen( filename , "rb" );
	if ( !PCXfile )
		return PCX_ERROR_OPENING;

	// read 128 char PCX header
	if (cfread( &header, sizeof(PCXHeader), 1, PCXfile )!=1)	{
		cfclose( PCXfile );
		return PCX_ERROR_NO_HEADER;
	}

	// Is it a 256 color PCX file?
	if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5))	{
		cfclose( PCXfile );
		return PCX_ERROR_WRONG_VERSION;
	}

	if (w) *w = header.Xmax - header.Xmin + 1;
	if (h) *h = header.Ymax - header.Ymin + 1;
	
	if ( pal ) {
		cfseek( PCXfile, -768, CF_SEEK_END );
		cfread( pal, 3, 256, PCXfile );
	}

	cfclose(PCXfile);
	return PCX_ERROR_NONE;
}
コード例 #27
0
ファイル: palette.c プロジェクト: osgcc/descent-mac
void gr_use_palette_table( char * filename )
{
	CFILE *fp;
	int i,j;
	ubyte c;

	fp = cfopen( filename, "rb" );
	if ( fp==NULL)
		Error("Can't open palette file <%s> which is not in the current dir.",filename);

	cfread( gr_palette, 256*3, 1, fp );
	cfread( gr_fade_table, 256*34, 1, fp );
	cfclose(fp);

	// This is the TRANSPARENCY COLOR
	for (i=0; i<GR_FADE_LEVELS; i++ )	{
		gr_fade_table[i*256+255] = 255;
	}
	
// swap colors 0 and 255 of the palette along with fade table entries

#ifdef SWAP_0_255
	for (i = 0; i < 3; i++) {
		c = gr_palette[i];
		gr_palette[i] = gr_palette[765+i];
		gr_palette[765+i] = c;
	}

	for (i = 0; i < GR_FADE_LEVELS * 256; i++) {
		if (gr_fade_table[i] == 0)
			gr_fade_table[i] = 255;
	}
	for (i=0; i<GR_FADE_LEVELS; i++)
		gr_fade_table[i*256] = TRANSPARENCY_COLOR;
#endif
}
コード例 #28
0
/*
 * @brief copy/pasted from libpng
 */
static void png_scp_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
	png_size_t check;

	if (png_ptr == NULL)
		return;

	png_read_status* status = reinterpret_cast<png_read_status*>(png_get_io_ptr(png_ptr));

	/* fread() returns 0 on error, so it is OK to store this in a png_size_t
	* instead of an int, which is what fread() actually returns.
	*/
	check = (png_size_t)cfread(data, (png_size_t)1, (int)length, status->cfp);
	if (check != length)
		png_error(png_ptr, "Read Error");
}
コード例 #29
0
ファイル: hmiplay.c プロジェクト: gameplayer22/d2x-1
int do_ipc(int qid, struct msgbuf *buf, int flags)
{
	int ipc_read;
	CFILE *fptr;
	int l=0;
	
	ipc_read = msgrcv(qid,buf,16,0,flags | MSG_NOERROR);
	
	switch (ipc_read)
	{
	 case -1:
		if (errno == ENOMSG)
		  break;
		perror("IPC trouble");
		break;
	 case 0:
		break;
	 default:
		printf ("do_ipc %s\n", buf->mtext);//##########3
		switch (buf->mtext[0])
		{
		 case 'v':
			volume=(double) ((double) buf->mtext[0]/127.0);
			break;
		 case 'p':
			fptr=cfopen((buf->mtext+1),"rb");		
			if(fptr != NULL)
			{
				l = cfilelength(fptr);
				data=realloc(data,(size_t) l);
				cfread(data, l, 1, fptr);
				cfclose(fptr);
				printf ("good. fpr=%p l=%i data=%p\n", fptr, l, data);//##########3
			}
			stop = 0;
			break;
		 case 's':
			stop = 2;
			break;
		 case 'q':
//			SDL_KillThread(player_thread);
			break;  
		}
	}
	
	return ipc_read;
}
コード例 #30
0
ファイル: loadfile.c プロジェクト: arbruijn/d1xnacl
const char *loadfile(const char *url, int *size) {
  CFILE *f;
  char *buf;
  long fsize;

  if (!(f = cfopen((char *)url, "rb")))
    return NULL;
  fsize = cfilelength(f);
  if (fsize != (int)fsize)
    return NULL;
  if (!(buf = (char *)malloc(fsize)))
    return NULL;
  cfread(buf, fsize, 1, f);
  cfclose(f);
  *size = fsize;
  return buf;
}