Пример #1
0
static boolean check_iconheader(BYTE *data) {
	
	/* read Reserved bit, abort if not 0 */
	cursorHeader.idReserved = LittleEndian_getW(data, 0);
	if (cursorHeader.idReserved != 0) {
		return FALSE;
	}
	
	data += 2;
	
	/* read Resource Type, 2 is for cursors, abort if different */
	cursorHeader.idType = LittleEndian_getW(data, 0);
	if (cursorHeader.idType != 2) {
		return FALSE;
	}
	
	data += 2;
	
	/* read Number of images, abort if invalid value (0) */
	cursorHeader.idCount = LittleEndian_getW(data, 0);
	
	data += 2;
	
	/* Number of images (>0) */
	if (cursorHeader.idCount == 0) {
		WARNING("Cursor: no images in file!\n");
		return FALSE;
	}
	
	if (cursorHeader.idCount > 1) {
		WARNING("Cursor:  warning:  too much images in file!\n"); 
	}
	return TRUE;
}
Пример #2
0
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 );
}
Пример #3
0
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);
}
Пример #4
0
static boolean cursor_load_anim(BYTE *data, int no) {
	BYTE *b = data;
	int riffsize;
	RIFFchunk_t c;
	
	if (!search_chunk(b, "RIFF", "ACON", &c)) {
		WARNING("Not animation icon format");
		return FALSE;
	}
	
	riffsize = c.size;
	// printf("size = %d\n", c.size);
	b = c.data;
	
	while (b < (data + riffsize)) {
		if (search_chunk(b, "LIST", "INFO", &c)) {
			NOTICE("LIST(INFO) ignore size = %d\n", c.size);
			b += c.size + 8;
		} else if (search_chunk(b, "anih", NULL, &c)) {
			BYTE *src = c.data;
			NOTICE("anih size = %d\n", c.size);
			anicurHeader.cbSizeof  = LittleEndian_getW(src, 0);
			anicurHeader.cFrames   = LittleEndian_getW(src, 4);
			anicurHeader.cSteps    = LittleEndian_getW(src, 8);
			anicurHeader.cx        = LittleEndian_getW(src, 12);
			anicurHeader.cy        = LittleEndian_getW(src, 16);
			anicurHeader.cBitCount = LittleEndian_getW(src, 20);
			anicurHeader.cPlanes   = LittleEndian_getW(src, 24);
			anicurHeader.jiffRate  = LittleEndian_getW(src, 28);
			anicurHeader.fl        = LittleEndian_getW(src, 32);
			
			anicurImage.header = &anicurHeader;
			
			b += c.size + 8;
		} else if (search_chunk(b, "rate", NULL, &c)) {
			BYTE *src = c.data;
			NOTICE("rate size = %d\n", c.size);
			if (anicurHeader.fl & 0x01) {
				int i;
				anicurHeader.rate = g_new(int, anicurHeader.cSteps);
				for (i = 0; i < anicurHeader.cSteps; i++) {
					anicurHeader.rate[i] = LittleEndian_getW(src, i*4);
					// printf("rate %d, %d\n", i, anicurHeader.rate[i]);
				}
			}
			b += c.size + 8;
		} else if (search_chunk(b, "icon", NULL, &c)) {
Пример #5
0
/*
 * 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;
}
Пример #6
0
static boolean search_chunk(BYTE *src, char *key1, char *key2, RIFFchunk_t *c) {
	if (0 == strncmp(src, key1, 4)) {
		c->size = LittleEndian_getW(src, 4);
		if (key2) {
			if (0 == strncmp(src+8, key2, 4)) {
				c->data = src + 12;
				return TRUE;
			}
			return FALSE;
		}
		c->data = src + 8;
		return TRUE;
	}
	return FALSE;
}
Пример #7
0
/*
 * 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;
}
Пример #8
0
/* 
 * Get file map
 *   d : drifile object
 *   fp: FILE object
*/
static void get_filemap(drifiles *d, FILE *fp) {
	BYTE b[6], *_b;
	int mapsize, ptrsize, i;
	
	/* read top 6bytes */
	fseek(fp, 0L, SEEK_SET);
	fread(b, 1, 6, fp);
	
	/* get ptrsize and mapsize */
	ptrsize = LittleEndian_get3B(b, 0);
	mapsize = LittleEndian_get3B(b, 3) - ptrsize;
	
	/* allocate read buffer */
	_b = g_new(char, mapsize << 8);
	
	/* read filemap */
	fseek(fp, ptrsize << 8L , SEEK_SET);
	fread(_b, 256, mapsize, fp);
	
	/* get max file number from mapdata */
	d->maxfile = (mapsize << 8) / 3;
	
	/* map of disk */
	d->map_disk = g_new(char , d->maxfile);
	/* map of data in disk */ 
	d->map_ptr  = g_new(short, d->maxfile);
	
	for (i = 0; i < d->maxfile; i++) {	
		/* map_disk[?] and map_ptr[?] are from 0 */
		*(d->map_disk + i) = _b[i * 3] - 1;
		*(d->map_ptr  + i) = LittleEndian_getW(_b, i * 3 + 1) - 1;
	}
	
	g_free(_b);
	return;
}
Пример #9
0
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);
}