#include <cstdio> // FILE
#include <cstring> // strncmp
+#include <boost/algorithm/string.hpp>
+
#include <SDL/SDL.h>
#include <png.h>
#include "Core.hh"
#include "Error.hh"
#include "Image.hh"
-#include "Library.hh"
#include "Log.hh"
+#include "Manager.hh"
namespace Mf {
-class Image::Impl : public Library<Impl>
+class Image::Impl : public Manager<Impl>
{
public:
- explicit Impl(const std::string& name, bool flipped = false) :
- Library<Impl>(name),
+ explicit Impl() :
mContext(0),
- mPixels(0)
- {
- init(getName(), flipped);
- }
+ mPixels(0) {}
~Impl()
{
}
- SDL_Surface* mContext;
- char* mPixels;
-
- unsigned mDepth;
- GLuint mColorMode;
-
- std::string mComment;
-
-
-private:
-
- Backend mBackend;
-
- bool init(const std::string& filePath, bool flipped)
+ bool init(const std::string& name, bool flipped = false)
{
- logInfo("opening image file...");
- FILE* fp = fopen(filePath.c_str(), "rb");
+ std::string path = Image::getPath(name);
+
+ logInfo << "opening image file " << path << std::endl;
+ FILE* fp = fopen(path.c_str(), "rb");
if (!fp) return false;
png_byte signature[8];
break;
case PNG_COLOR_TYPE_GRAY:
- if (bpp < 8) png_set_gray_1_2_4_to_8(pngObj);
+ if (bpp < 8) png_set_expand(pngObj);
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
logInfo << "num texts: " << numTexts << std::endl;
for (int i = 0; i < numTexts; ++i)
{
- if (strncmp(texts[i].key, "Comment", 7) == 0)
+ if (strncmp(texts[i].key, "TextureInfo", 11) == 0)
{
mComment = texts[i].text;
break;
return mContext;
}
+
+
+ SDL_Surface* mContext;
+ char* mPixels;
+
+ unsigned mDepth;
+ GLuint mColorMode;
+
+ std::string mComment;
+
+private:
+
+ Backend mBackend;
};
return mImpl->mContext->pitch;
}
-GLuint Image::getColorMode() const
+GLuint Image::getMode() const
{
return mImpl->mColorMode;
}
}
-
std::string Image::getPath(const std::string& name)
{
- std::string path = Resource::getPath("images/" + name + ".png");
- return path;
+ if (boost::find_last(name, ".png"))
+ {
+ return Resource::getPath(name);
+ }
+ else
+ {
+ std::string path("images/");
+ path += name;
+ path += ".png";
+ return Resource::getPath(path);
+ }
}