void* crOpen(const char* filename) { NvFile* asset = NvFOpen(filename); if(nullptr == asset) { crDbgStr("failed to open asset '%s'!\n", filename); } return asset; }
// loads 24-bit bmp files into 32-bit RGBA texture unsigned int *LoadBMP(char const *name, int *width, int *height) { NvFile *f = NvFOpen(name); if (f == 0) { LOGW("error opening %s!\n", name); return 0; } BITMAP_HEADER head; BMPV3_INFO_HEADER info; NvFRead(&head, sizeof(BITMAP_HEADER), 1, f); NvFRead(&info, sizeof(BMPV3_INFO_HEADER), 1, f); NvFSeek(f, head.bitmapPtr, SEEK_SET); *width = info.bWidth; *height = info.bHeight; uint *imageData = new uint[info.bWidth * info.bHeight]; int scanSize = (info.bWidth * (info.bBpp >> 3) + 3) & ~0x3; uchar *rdata = new uchar[scanSize]; for (int y = info.bHeight - 1; y >= 0; y--) { NvFRead(rdata, scanSize, 1, f); // shuffle rgb int index = y * info.bWidth; for (int i = 0; i < info.bWidth; i++) { imageData[index + i] = (rdata[i * 3] << 16) | (rdata[i * 3 + 1] << 8) | rdata[i * 3 + 2] | 0xff000000; } } NvFClose(f); delete[] rdata; LOGI("loaded %ix%i input image", info.bWidth, info.bHeight); return imageData; }
// File handles // Directly maps to fopen/fclose/fchdir/etc. Look at the man pages for docs. MMFILE * MMfopen(const char * path) { std::string pathString = path; pathString += ".mp3"; return (MMFILE*) NvFOpen(pathString.c_str()); }