void Image::load() { flags |= USED; if (tex != 0 || image != NULL) return; if (flags & FILE) { ((FileImage*)this)->load_file(); return; } open_image_file(); image_file.set_item(handle, AssetFile::IMAGE_DATA); FileStream stream(image_file); hotspot_x = stream.read_int16(); hotspot_y = stream.read_int16(); action_x = stream.read_int16(); action_y = stream.read_int16(); int size = stream.read_uint32(); int w, h, channels; image = load_image(image_file, size, &w, &h, &channels); width = w; height = h; if (image == NULL) { std::cout << "Could not load image " << handle << std::endl; std::cout << stbi_failure_reason() << std::endl; return; } }
void Media::init() { ChowdrenAudio::open_audio(); double start_time = platform_get_time(); AssetFile fp; fp.open(); #ifdef CHOWDREN_IS_WIIU // experimental code to load faster unsigned int start = AssetFile::get_offset(0, AssetFile::SOUND_DATA); unsigned int size = AssetFile::get_size(AssetFile::SOUND_DATA); startup_data = new unsigned char[size]; startup_size = size; fp.seek(start); fp.read(startup_data, size); for (int i = 0; i < SOUND_COUNT; i++) { add_cache(i); } delete[] startup_data; #else for (int i = 0; i < SOUND_COUNT; i++) { fp.set_item(i, AssetFile::SOUND_DATA); add_cache(i, fp); } #endif std::cout << "Sound bank took " << (platform_get_time() - start_time) << std::endl; }
bool load_fonts(FontList & fonts) { AssetFile fp; fp.open(); FileStream stream(fp); for (int i = 0; i < FONT_COUNT; i++) { fp.set_item(i, AssetFile::FONT_DATA); unsigned int count = stream.read_uint32(); for (unsigned int i = 0; i < count; i++) { FTTextureFont * font = new FTTextureFont(stream); fonts.push_back(font); } } return fonts.size() > 0; }
void Image::load() { flags |= USED; if (tex != 0 || image != NULL) return; if (flags & FILE) { ((FileImage*)this)->load_file(); return; } unsigned int size, out_size; unsigned char * buf; int ret; if (startup_data) { unsigned int start = AssetFile::get_offset(0, AssetFile::IMAGE_DATA); unsigned int self = AssetFile::get_offset(handle, AssetFile::IMAGE_DATA); unsigned int offset = self - start; ArrayStream stream((char*)startup_data, startup_size); stream.seek(offset); load_image_info(*this, stream, size, out_size); buf = &startup_data[stream.pos]; ret = stbi_zlib_decode_buffer((char*)image, out_size, (const char*)buf, size); } else { open_image_file(); image_file.set_item(handle, AssetFile::IMAGE_DATA); FileStream stream(image_file); load_image_info(*this, stream, size, out_size); buf = new unsigned char[size]; image_file.read(buf, size); ret = stbi_zlib_decode_buffer((char*)image, out_size, (const char*)buf, size); delete[] buf; } if (ret < 0) { std::cout << "Could not load image " << handle << std::endl; std::cout << stbi_failure_reason() << std::endl; stbi_image_free(image); image = NULL; } }