static ECursor * ECursorRealize(ECursor * ec) { Pixmap pmap, mask; int xh, yh; unsigned int w, h, ww, hh; char *img, msk[FILEPATH_LEN_MAX]; if (ec->file) { img = ThemeFileFind(ec->file, FILE_TYPE_CURSOR); _EFREE(ec->file); /* Ok or not - we never need file again */ if (!img) goto done; Esnprintf(msk, sizeof(msk), "%s.mask", img); pmap = 0; mask = 0; xh = 0; yh = 0; XReadBitmapFile(disp, WinGetXwin(VROOT), msk, &w, &h, &mask, &xh, &yh); XReadBitmapFile(disp, WinGetXwin(VROOT), img, &w, &h, &pmap, &xh, &yh); XQueryBestCursor(disp, WinGetXwin(VROOT), w, h, &ww, &hh); if ((w <= ww) && (h <= hh) && (pmap)) { if (xh < 0 || xh >= (int)w) xh = (int)w / 2; if (yh < 0 || yh >= (int)h) yh = (int)h / 2; ec->cursor = ECreatePixmapCursor(pmap, mask, w, h, xh, yh, ec->fg, ec->bg); } if (ec->cursor == NoXID) { Eprintf("*** Failed to create cursor \"%s\" from %s,%s\n", ec->name, img, msk); } if (pmap) EFreePixmap(pmap); if (mask) EFreePixmap(mask); Efree(img); } else { ec->cursor = (ec->native_id == 999) ? None : XCreateFontCursor(disp, ec->native_id); } done: if (ec->cursor == NoXID) { ECursorDestroy(ec); ec = NULL; } return ec; }
int SoundSampleGetData(const char *file, SoundSampleData * ssd) { AFfilehandle in_file; int in_format, in_width, bytes_per_frame, frame_count; int frames_read; in_file = afOpenFile(file, "r", NULL); if (!in_file) return -1; frame_count = afGetFrameCount(in_file, AF_DEFAULT_TRACK); ssd->channels = afGetChannels(in_file, AF_DEFAULT_TRACK); ssd->rate = (unsigned int)(afGetRate(in_file, AF_DEFAULT_TRACK) + .5); afGetSampleFormat(in_file, AF_DEFAULT_TRACK, &in_format, &in_width); ssd->bit_per_sample = in_width; #ifdef WORDS_BIGENDIAN afSetVirtualByteOrder(in_file, AF_DEFAULT_TRACK, AF_BYTEORDER_BIGENDIAN); #else afSetVirtualByteOrder(in_file, AF_DEFAULT_TRACK, AF_BYTEORDER_LITTLEENDIAN); #endif if (EDebug(EDBUG_TYPE_SOUND)) Eprintf("SoundSampleGetData chan=%d width=%d rate=%d\n", ssd->channels, ssd->bit_per_sample, ssd->rate); bytes_per_frame = (ssd->bit_per_sample * ssd->channels) / 8; ssd->size = frame_count * bytes_per_frame; ssd->data = EMALLOC(unsigned char, ssd->size); frames_read = afReadFrames(in_file, AF_DEFAULT_TRACK, ssd->data, frame_count); afCloseFile(in_file); if (frames_read <= 0) { ssd->size = 0; _EFREE(ssd->data); return -1; } return 0; }