コード例 #1
0
ファイル: wavfile.c プロジェクト: xmoeproject/X-moe
static void waveFormatCopy( WAVEFORMAT* wav, char *ptr ) {
	wav->dwSize           = LittleEndian_getDW( ptr,  0 );
	wav->wFormatTag       = LittleEndian_getW(  ptr,  4 );
	wav->wChannels        = LittleEndian_getW(  ptr,  6 );
	wav->dwSamplesPerSec  = LittleEndian_getDW( ptr,  8 );
	wav->dwAvgBytesPerSec = LittleEndian_getDW( ptr, 12 );
	wav->wBlockAlign      = LittleEndian_getW(  ptr, 16 );
	wav->wBitsPerSample   = LittleEndian_getW(  ptr, 18 );
}
コード例 #2
0
ファイル: cursor.c プロジェクト: avan06/ONScripter-CN
static int read_direntries(BYTE* data) {
	BYTE *p = data;
	
	/* read Width, in pixels */
	cursordirentry.bWidth = *data;
	data++;
	
	/* read Height, in pixels */
	cursordirentry.bHeight = *data;
	data++;
	
	/* and validate data */
	NOTICE("Cursor:  bWidth==%d  bHeight==%d\n",
	       (int)cursordirentry.bWidth,
	       (int)cursordirentry.bHeight);
	
	if (cursordirentry.bWidth == 0 || cursordirentry.bHeight == 0) {
		return -1;
	}
	
	/* Bits per pixel, not used, 0 */
	cursordirentry.dwBytesInRes = LittleEndian_getW(data, 0);
	data += 2;
        
	cursordirentry.wxHotspot = LittleEndian_getW(data, 0);
	data += 2;
	
	cursordirentry.wyHotspot = LittleEndian_getW(data, 0);
	data += 2;
	
	/* size of image data, in bytes */
	cursordirentry.dwBytesInRes = LittleEndian_getDW(data, 0);
	data += 4;
	
	/* size of image data, in bytes */
	cursordirentry.dwImageOffset = LittleEndian_getDW(data, 0);
	data += 4;
	
	if (cursordirentry.dwImageOffset == 0) {
		return 0;
	}
	
	NOTICE("Cursor:  x==%d  y==%d\n",
	       (int)cursordirentry.wxHotspot,
	       (int)cursordirentry.wyHotspot);
	
	
	NOTICE("Width: %d\n", (int)(cursordirentry.bWidth));
	NOTICE("Height: %d\n", (int)(cursordirentry.bHeight));
	NOTICE("Bit Count (unused): %d\n", (int)(cursordirentry.dwBytesInRes));
	NOTICE("Total bytes: %ld\n", (long)(cursordirentry.dwBytesInRes));
	
	return (int)(data - p);
}
コード例 #3
0
ファイル: bmp.c プロジェクト: avan06/ONScripter-CN
/*
 * Check data is 8bit bmp format cg or not
 *   data: raw data (pointer to data top)
 *   return: TRUE if data is bmp
*/
boolean bmp256_checkfmt(BYTE *data) {
	int w, h, bpp;
	if (data[0] != 'B' || data[1] != 'M') return FALSE;
	
	w = LittleEndian_getDW(data, 18);
	h = LittleEndian_getDW(data, 22);
	bpp = LittleEndian_getW(data, 28);
	
	if (bpp != 8) return FALSE;
	if (w < 0 || h < 0) return FALSE;
	
	return TRUE;
}
コード例 #4
0
ファイル: dri.c プロジェクト: avan06/ONScripter-CN
/*
 * Get data 
 *   d : drifile object
 *   no: drifile no ( >= 0 )
 *   return: dridata obhect
 */
dridata *dri_getdata(drifiles *d, int no) {
	BYTE *data;
	dridata *dfile;
	int disk, ptr, dataptr, dataptr2, size;
	
	/* check no is lager than files which contains */
	if (no > d->maxfile) return NULL;
	
	/* check disk & ptr are negative, if negative, file does not exist */
	disk = d->map_disk[no];
	ptr  = d->map_ptr[no];
	if (disk < 0 || ptr < 0) return NULL;
	
	/* no file registered */
	if (d->fileptr[disk] == NULL) return NULL;
	
	/* get pointer in file and size */
	dataptr = *(d->fileptr[disk] + ptr);
	dataptr2 = *(d->fileptr[disk] + ptr + 1);
	if (dataptr == 0 || dataptr2 == 0) return NULL;
	
	/* get data top */
	if (d->mmapped) {
		data = d->mmapadr[disk] + dataptr;
	} else {
		int readsize = dataptr2 - dataptr;
		FILE *fp;
		data = g_new(char, readsize);
		fp = fopen(d->fnames[disk], "r");
		fseek(fp, dataptr, SEEK_SET);
		fread(data, 1, readsize, fp);
		fclose(fp);
	}
	
	/* get real data and size */
	ptr  = LittleEndian_getDW(data, 0);
	size = LittleEndian_getDW(data, 4);
	
	dfile = g_new0(dridata, 1);
	dfile->data_raw = data;    /* dri data header  */
	dfile->data = data + ptr;  /* real data */
	dfile->size = size;
	dfile->a = d; /* archive file */
	return dfile;
}
コード例 #5
0
ファイル: wavfile.c プロジェクト: xmoeproject/X-moe
WAVFILE * WavGetInfo(char *data) {
	int e;					/* Saved errno value */
	int channels;				/* Channels recorded in this wav file */
	u_long samplerate;			/* Sampling rate */
	int sample_bits;			/* data bit size (8/12/16) */
	u_long samples;				/* The number of samples in this file */
	u_long datastart;			/* The offset to the wav data */
	WAVFILE *wfile = (WAVFILE *)malloc(sizeof (WAVFILE));
	memset(wfile->other_data, 0, sizeof(wfile->other_data));

	if ( wfile == NULL ) {
		fprintf(stderr, "WavGetInfo(): Allocating WAVFILE structure\n");
		return NULL;
	}
	
	if ( (e = WaveHeaderCheck(data,
				  &channels,&samplerate,
				  &sample_bits,&samples,&datastart) != 0 )) {
		fprintf(stderr,"WavGetInfo(): Reading WAV header\n");
		goto errxit;
	}
	
	/*
	 * Copy WAV data over to WAVFILE struct:
	 */
	if ( channels == 2 )
		wfile->wavinfo.Channels = Stereo;
	else	wfile->wavinfo.Channels = Mono;


	wfile->wavinfo.SamplingRate = (UInt32) samplerate;
	wfile->wavinfo.Samples = (UInt32) samples;
	wfile->wavinfo.DataBits = (UInt16) sample_bits;
	wfile->wavinfo.DataStart = (UInt32) datastart;

	wfile->wavinfo.DataBytes_o = wfile->wavinfo.DataBytes = LittleEndian_getDW((char *)(datastart - 4),0);
	wfile->data = (char *) datastart;
	
	/*
	 * Open succeeded:
	 */
	return wfile;				/* Return open descriptor */

	/*
	 * Return error after failed open:
	 */
errxit:	e = errno;				/* Save errno */
	free(wfile);				/* Dispose of WAVFILE struct */
	errno = e;				/* Restore error number */
	return NULL;				/* Return error indication */
}
コード例 #6
0
ファイル: bmp.c プロジェクト: avan06/ONScripter-CN
/*
 * Get information from cg header
 *   b: raw data (pointer to header)
 *   return: acquired bmp information object
*/
static bmp_header *extract_header(BYTE *b) {
	bmp_header *bmp = g_new(bmp_header, 1);
	
	bmp->bmpSize    = LittleEndian_getDW(b, 2);
	/*data[4]-data[7]reserv*/
	bmp->bmpDp = LittleEndian_getDW(b, 10);
	bmp->bmpXW = LittleEndian_getDW(b, 18);
 	bmp->bmpYW = LittleEndian_getDW(b, 22);
	bmp->bmpBpp = LittleEndian_getW(b, 28);
	bmp->bmpCp  = LittleEndian_getDW(b, 30);
	bmp->bmpImgSize  = LittleEndian_getDW(b, 34);
	bmp->bmpPp  = (bmp->bmpBpp==24 ? 0 :
		       14 + LittleEndian_getDW(b, 14));
	bmp->bmpTp = LittleEndian_getDW(b, 14) == 12 ? BMP_OS2 : BMP_WIN;
	
	return bmp;
}
コード例 #7
0
ファイル: wavfile.c プロジェクト: xmoeproject/X-moe
static int  WaveHeaderCheck  (char *wave_buf,int* channels, u_long* samplerate, int* samplebits, u_long* samples,u_long* datastart)
{	
	static  WAVEFORMAT  waveformat ;
	char*   ptr ;
	u_long  databytes ;

	if (findchunk (wave_buf, "RIFF", BUFFERSIZE) != wave_buf) {
		fprintf(stderr, "Bad format: Cannot find RIFF file marker");
		return  WR_BADRIFF ;
	}

	if (! findchunk (wave_buf, "WAVE", BUFFERSIZE)) {
		fprintf(stderr, "Bad format: Cannot find WAVE file marker");
		return  WR_BADWAVE ;
	}

	ptr = findchunk (wave_buf, "fmt ", BUFFERSIZE) ;

	if (! ptr) {
		fprintf(stderr, "Bad format: Cannot find 'fmt' file marker");
		return  WR_BADFORMAT ;
	}

	ptr += 4 ;	/* Move past "fmt ".*/
	waveFormatCopy( &waveformat, ptr );
	
	if (waveformat.dwSize != (sizeof (WAVEFORMAT) - sizeof (u_long))) {
		fprintf(stderr, "Bad format: Bad fmt size");
		/* return  WR_BADFORMATSIZE ; */
	}

	if (waveformat.wFormatTag != PCM_WAVE_FORMAT) {
		fprintf(stderr, "Only supports PCM wave format");
		return  WR_NOTPCMFORMAT ;
	}

	ptr = findchunk (wave_buf, "data", BUFFERSIZE) ;

	if (! ptr) {
		fprintf(stderr,"Bad format: unable to find 'data' file marker");
		return  WR_NODATACHUNK ;
	}

	ptr += 4 ;	/* Move past "data".*/
	databytes = LittleEndian_getDW(ptr, 0);
	
	/* Everything is now cool, so fill in output data.*/

	*channels   = waveformat.wChannels;
	*samplerate = waveformat.dwSamplesPerSec ;
	*samplebits = waveformat.wBitsPerSample ;
	*samples    = databytes / waveformat.wBlockAlign ;
	
	*datastart  = (u_long)(ptr) + 4;

	if (waveformat.dwSamplesPerSec != waveformat.dwAvgBytesPerSec / waveformat.wBlockAlign) {
		fprintf(stderr, "Bad file format");
		return  WR_BADFORMATDATA ;
	}

	if (waveformat.dwSamplesPerSec != waveformat.dwAvgBytesPerSec / waveformat.wChannels / ((waveformat.wBitsPerSample == 16) ? 2 : 1)) {
		fprintf(stderr, "Bad file format");
		return  WR_BADFORMATDATA ;
	}

	return  0 ;
} ; /* WaveHeaderCheck*/
コード例 #8
0
ファイル: cursor.c プロジェクト: avan06/ONScripter-CN
static int read_bitmapinfo(BYTE* data) {
	BYTE* p = data;
	
#define ih cursorImage.icHeader
	/* read bitmap info an perform some primitive sanity checks */

	/* sizeof(TBitmapInfoHeader) */
	ih.biSize = LittleEndian_getDW(data, 0);
	data += 4;
	
	/* width of bitmap */
	ih.biWidth = LittleEndian_getDW(data, 0);
	data += 4;
	
	/* height of bitmap, see notes (icon.h) */
	ih.biHeight=LittleEndian_getDW(data,0);
	data += 4;
	
	NOTICE("Cursor:  biWidth==%d  biHeight==%d\n", (int)ih.biWidth, (int)ih.biHeight);

	if (ih.biWidth == 0 || ih.biHeight == 0) {
		return 0;
	}
	
	/* planes, always 1 */
	ih.biPlanes = LittleEndian_getW(data, 0);
	data += 2;
	
	/* number of color bits (2,4,8) */
	ih.biBitCount = LittleEndian_getW(data, 0);
	if (ih.biBitCount != 1) {
		WARNING("Cursor: %d not supported color bit\n", ih.biBitCount);
		return 0;
	}
	data += 2;

	/* compression used, 0 */
	ih.biCompression = LittleEndian_getDW(data, 0);
	data += 4;
	
	if (ih.biCompression != 0) {
		WARNING("Cursor:  invalid compression value of %d\n", (int)ih.biCompression);
		return 0;
	}
	
	/* size of the pixel data, see icon.h */
	ih.biSizeImage = LittleEndian_getDW(data, 0);
	data += 4;
	
	NOTICE("Cursor:  biSizeImage==%d\n", (int)ih.biSizeImage);
	
	ih.biXPelsPerMeter = LittleEndian_getDW(data, 0);
	data += 4;

	/* not used, 0 */
	ih.biYPelsPerMeter = LittleEndian_getDW(data, 0);
	data += 4;
	
	/* # of colors used, set to 0 */
	ih.biClrUsed = LittleEndian_getDW(data, 0);
	data += 4;
	
	/* important colors, set to 0 */
	ih.biClrImportant = LittleEndian_getDW(data, 0);
	data += 4;
	
#undef ih
	
	return (int)(data - p);
}