X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FMoof%2FImage.cc;h=ee44dd75dcacb319f331411df02e9c28da92407b;hb=81ff940d1bea07447f8218ab9a764fbf393431e8;hp=31d6b0287926e38e35f7fc51c58be55571cfdba5;hpb=b357615aba1dbde81e3c6999366604e6001010a7;p=chaz%2Fyoink diff --git a/src/Moof/Image.cc b/src/Moof/Image.cc index 31d6b02..ee44dd7 100644 --- a/src/Moof/Image.cc +++ b/src/Moof/Image.cc @@ -29,28 +29,28 @@ #include // FILE #include // strncmp +#include + #include #include +#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 +class Image::Impl : public Manager { public: - explicit Impl(const std::string& name, bool flipped = false) : - Library(name), + explicit Impl() : mContext(0), - mPixels(0) - { - init(getName(), flipped); - } + mPixels(0) {} ~Impl() { @@ -87,21 +87,12 @@ public: } - SDL_Surface* mContext; - char* mPixels; - - unsigned mDepth; - GLuint mColorMode; - - std::string mComment; - - -private: - - 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]; @@ -156,7 +147,7 @@ private: 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: @@ -181,7 +172,7 @@ private: 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; @@ -244,6 +235,19 @@ private: return mContext; } + + + SDL_Surface* mContext; + char* mPixels; + + unsigned mDepth; + GLuint mColorMode; + + std::string mComment; + +private: + + Backend mBackend; }; @@ -277,7 +281,7 @@ unsigned Image::getPitch() const return mImpl->mContext->pitch; } -GLuint Image::getColorMode() const +GLuint Image::getMode() const { return mImpl->mColorMode; } @@ -311,11 +315,19 @@ void Image::setAsIcon() const } - 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); + } }