void Texture::load(std::string filename) { uint8 *data; file_t fd = fs_open(filename.c_str(), O_RDONLY); data = new uint8[fs_total(fd)]; fs_read(fd, data, fs_total(fd)); fs_close(fd); memcpy(&header, data, sizeof(HeaderStruct)); assert_msg(Texture::formatTag.compare(header.formatTag) == 0, "Wrong texture format OR version"); /* Read texture */ uint16 *tdata = new uint16[header.byteCount]; memcpy(tdata, &data[0x18], header.byteCount); int pvrfmt = -1; if(header.format == KOS_IMG_FMT_ARGB1555) pvrfmt = PVR_TXRFMT_ARGB1555; else if(header.format == KOS_IMG_FMT_ARGB4444) pvrfmt = PVR_TXRFMT_ARGB4444; assert_msg(pvrfmt != -1, "Cannot determine PVR texture format"); sys->debugLog(" -> size %lu*%lu, KOS format %lu, pvr format %i, byteCount %08lx\n", header.width, header.height, header.format, pvrfmt, header.byteCount); texture = plx_txr_canvas(header.width, header.height, pvrfmt); pvr_txr_load_ex(tdata, texture->ptr, texture->w, texture->h, PVR_TXRLOAD_16BPP); delete[] tdata; delete[] data; }
Texture::Texture(int w, int h, int fmt) { m_txr = plx_txr_canvas(w, h, fmt); if (m_txr == NULL) { dbglog(DBG_WARNING, "Texture::loadFromFile: Can't allocate %dx%dcanvas texture\n", w, h); assert( false ); } }
void Font::load(std::string filename) { uint8 *data; file_t fd = fs_open(filename.c_str(), O_RDONLY); data = new uint8[fs_total(fd)]; fs_read(fd, data, fs_total(fd)); fs_close(fd); uint32 rofs; memcpy(&header, data, sizeof(HeaderStruct)); assert_msg(Font::formatTag.compare(header.formatTag) == 0, "Wrong font format OR version"); /* Read characters */ rofs = header.characterDataOffset; memcpy(&characterList.characterCount, &data[rofs], 4); rofs += 4; characterList.characters = new CharacterDataStruct[characterList.characterCount]; memcpy(characterList.characters, &data[rofs], (sizeof(CharacterDataStruct) * characterList.characterCount)); /* Read font texture */ rofs = header.fontTextureOffset; int w = 0, h = 0, fmt = 0, byte_count = 0; memcpy(&w, &data[rofs], 4); memcpy(&h, &data[rofs + 0x4], 4); memcpy(&fmt, &data[rofs + 0x8], 4); memcpy(&byte_count, &data[rofs + 0xC], 4); uint32 *tdata = new uint32[byte_count]; memcpy(tdata, &data[rofs + 0x10], byte_count); texture = plx_txr_canvas(w, h, PVR_TXRFMT_ARGB4444); pvr_txr_load_ex(tdata, texture->ptr, texture->w, texture->h, PVR_TXRLOAD_16BPP); delete[] tdata; delete[] data; }