2020-12-31 07:32:16 -08:00
|
|
|
// Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
|
2012-09-15 17:59:15 -07:00
|
|
|
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
|
2012-09-12 04:38:30 -07:00
|
|
|
|
2012-04-01 15:06:58 -07:00
|
|
|
#include "SDLWrappers.h"
|
|
|
|
#include "FileSystem.h"
|
2019-01-02 08:59:07 -08:00
|
|
|
#include "libs.h"
|
2014-01-28 01:40:09 -08:00
|
|
|
#include "utils.h"
|
2012-04-01 15:06:58 -07:00
|
|
|
|
|
|
|
SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname, FileSystem::FileSource &source)
|
|
|
|
{
|
|
|
|
RefCountedPtr<FileSystem::FileData> filedata = FileSystem::gameDataFiles.ReadFile(fname);
|
|
|
|
if (!filedata) {
|
2014-01-28 01:40:09 -08:00
|
|
|
Output("LoadSurfaceFromFile: %s: could not read file\n", fname.c_str());
|
2012-04-01 15:06:58 -07:00
|
|
|
return SDLSurfacePtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_RWops *datastream = SDL_RWFromConstMem(filedata->GetData(), filedata->GetSize());
|
|
|
|
SDL_Surface *surface = IMG_Load_RW(datastream, 1);
|
|
|
|
if (!surface) {
|
2014-01-28 01:40:09 -08:00
|
|
|
Output("LoadSurfaceFromFile: %s: %s\n", fname.c_str(), IMG_GetError());
|
2012-04-01 15:06:58 -07:00
|
|
|
return SDLSurfacePtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
return SDLSurfacePtr::WrapNew(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname)
|
|
|
|
{
|
|
|
|
return LoadSurfaceFromFile(fname, FileSystem::gameDataFiles);
|
|
|
|
}
|