////////////////////////////////////////// //// //// GW_PlatformSDL_Image //// ////////////////////////////////////////// GW_PlatformSDL_Image::GW_PlatformSDL_Image(SDL_Renderer *renderer, const string &filename, GW_Platform_RGB *tcolor) { SDL_Surface* _surface; #ifndef GW_USE_ZDATA _surface = SDL_LoadBMP( filename.c_str() ); #else SDL_RWops *l = SDL_RWFromZZIP( filename.c_str(), "rb" ); if (l) _surface = SDL_LoadBMP_RW( l, 1 ); else _surface = NULL; //SDL_FreeRW(l); #endif if (!_surface) throw GW_Exception(string("Unable to load image "+filename+": "+string(SDL_GetError()))); if (tcolor) SDL_SetColorKey(_surface, SDL_TRUE, SDL_MapRGB(_surface->format, tcolor->r, tcolor->g, tcolor->b)); texture_ = SDL_CreateTextureFromSurface(renderer, _surface); if (!texture_) throw GW_Exception(string("Unable to load image "+filename+": "+string(SDL_GetError()))); SDL_QueryTexture(texture_, NULL, NULL, &w_, &h_); // Cleanup ... SDL_FreeSurface(_surface); #ifdef GW_DEBUG GWDBG_FVOUTPUT("\tGW_PlatformSDL_Image(file %s, texture %p, width %i, height %i)\n", filename.c_str(), texture_, w_, h_); #endif }
AudioSample* AudioSampleSet::LoadSample(const string& identifier, const string& relativePath) { SDL_RWops* rw = SDL_RWFromZZIP((relativePath + identifier).c_str(), "r"); Mix_Chunk* chunk = Mix_LoadWAV_RW(rw, 0); SDL_FreeRW(rw); if(!chunk) throw string("Unable to open audio file: " + relativePath + identifier); AudioSample* newSample = new AudioSample(identifier, chunk); sampleSet.push_back(newSample); return newSample; }
void Texture::Load() { std::string tmp = ASSETS_TEXTURE; tmp.append(texname.c_str()); SDL_RWops* rw = SDL_RWFromZZIP(tmp.c_str(), "r"); surface = NULL; if(NULL == (surface = IMG_Load_RW(rw, 0))) { logger.Log(LOG_WARN, "Missing Texture: %s", tmp.c_str()); tmp = ASSETS_TEXTURE; tmp.append("misc/unknown.png"); if(NULL == (surface = IMG_Load_RW(SDL_RWFromZZIP(tmp.c_str(), "r"), 0))) throw TextureNotFoundException() << "Unable to load fallback image: " << tmp; // FIXME: compile the fallback image into the executable. } SDL_FreeRW(rw); texdata.nOfColors = surface->format->BytesPerPixel; if(4 == texdata.nOfColors) // alpha channel { if(0x000000ff == surface->format->Rmask) texdata.format = GL_RGBA; else texdata.format = GL_BGRA; } else if(3 == texdata.nOfColors) // no alpha channel { if(0x000000ff == surface->format->Rmask) texdata.format = GL_RGB; else texdata.format = GL_BGR; } else throw InvalidTextureException() << "Given texture is not Truecolor."; if(!texdata.dimension.width) texdata.dimension.width = surface->w; if(!texdata.dimension.height) texdata.dimension.height = surface->h; texdata.pixels = (Uint32*)surface->pixels; }
int main (int argc, char** argv) { static const char usage[] = " zzcat <file>... \n" " - prints the file to stdout. the file can be a normal file\n" " or an inflated part of a zip-archive \n" ; int argn; if (argc <= 1) { printf (usage); exit (0); } for (argn=1; argn < argc; argn++) { SDL_RWops* rwops; rwops = SDL_RWFromZZIP (argv[argn], "rb"); if (! rwops) { perror (argv[argn]); continue; }else{ char buf[17]; int n; /* read chunks of 16 bytes into buf and print them to stdout */ while (0 < (n = SDL_RWread(rwops, buf, 16, 1))) { buf[n] = '\0'; # ifdef STDOUT_FILENO write (STDOUT_FILENO, buf, n); # else fwrite (buf, 1, n, stdout); # endif } if (n == -1) perror (argv[argn]); SDL_RWclose (rwops); } } return 0; }
// Open data file bool FileSpecifier::Open(OpenedFile &OFile, bool Writable) { OFile.Close(); SDL_RWops *f; #ifdef __MACOS__ if (!Writable) f = OFile.f = open_fork_from_existing_path(GetPath(), false); else #endif { #ifdef HAVE_ZZIP if (!Writable) { f = OFile.f = SDL_RWFromZZIP(unix_path_separators(GetPath()).c_str(), "rb"); } else #endif f = OFile.f = SDL_RWFromFile(GetPath(), Writable ? "wb+" : "rb"); } err = f ? 0 : errno; if (f == NULL) { set_game_error(systemError, err); return false; } if (Writable) return true; // Transparently handle AppleSingle and MacBinary files on reading int32 offset, data_length, rsrc_length; if (is_applesingle(f, false, offset, data_length)) { OFile.is_forked = true; OFile.fork_offset = offset; OFile.fork_length = data_length; SDL_RWseek(f, offset, SEEK_SET); return true; } else if (is_macbinary(f, data_length, rsrc_length)) { OFile.is_forked = true; OFile.fork_offset = 128; OFile.fork_length = data_length; SDL_RWseek(f, 128, SEEK_SET); return true; } SDL_RWseek(f, 0, SEEK_SET); return true; }
void ZipResourceManager::populate() { zzip_error_t zzipError; ZZIP_DIR* zzipDir = zzip_dir_open(resourcePath.c_str(), &zzipError); checkZzipError(zzipError); ZZIP_DIRENT zzipEntry; while (zzip_dir_read(zzipDir, &zzipEntry)) { int compressedSize = zzipEntry.d_csize; int uncompressedSize = zzipEntry.st_size; std::string name = std::string(zzipEntry.d_name); files[name] = SDL_RWFromZZIP((resourcePath + "/" + name).c_str(), "rb"); } zzip_dir_close(zzipDir); }
SDL_Surface *BKLoadSurface(const char *filename) { SDL_Surface *tempSurfaceP = NULL; SDL_RWops *ops; #ifdef HAVE_SDL_ZZIP ops = SDL_RWFromZZIP(filename, "rb"); #else ops = SDL_RWFromFile(filename, "rb"); #endif if (ops != NULL) { if ( strstr(filename, ".tga") ) { tempSurfaceP = BKLoadTGA_RW(ops, 0); if (!tempSurfaceP) fprintf(stderr, "SDLLoadTGA %s\n", SDL_GetError()); } #ifdef HAVE_SDL_IMAGE else { tempSurfaceP = IMG_Load_RW(ops,0); if (!tempSurfaceP) fprintf(stderr, "IMG_Load %s\n", SDL_GetError()); } #else else if ( strstr(filename, ".bmp") ) { tempSurfaceP = SDL_LoadBMP_RW(ops,0); if (!tempSurfaceP) fprintf(stderr, "SDL_LoadBMP %s\n", SDL_GetError()); } else { SDL_SetError("Unknown file type"); } #endif // HAVE_SDL_IMAGE /* if (tempSurfaceP) fprintf(stderr, "loaded \"%s\" %dx%dx%d%s%s\n", filename, tempSurfaceP->w, tempSurfaceP->h, tempSurfaceP->format->BitsPerPixel, (tempSurfaceP->flags & SDL_SRCCOLORKEY) ? " colorkey" : "", (tempSurfaceP->flags & SDL_SRCALPHA) ? " alpha" : ""); */ SDL_FreeRW(ops); }
////////////////////////////////////////// //// //// GW_PlatformSDL_Sound //// ////////////////////////////////////////// GW_PlatformSDL_Sound::GW_PlatformSDL_Sound(const string &filename) { #ifndef GW_NO_SDL_MIXER #ifndef GW_USE_ZDATA sample_ = Mix_LoadWAV( filename.c_str() ); #else SDL_RWops *l = SDL_RWFromZZIP( filename.c_str(), "rb" ); if (l) sample_ = Mix_LoadWAV_RW( l, 1 ); else sample_=NULL; //SDL_FreeRW(l); #endif if (!sample_) throw GW_Exception(string("Unable to load sound sample "+filename+": "+string(Mix_GetError()))); #endif }