]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Image.cc
new win32 deps script; using pkgconfig for openal
[chaz/yoink] / src / Moof / Image.cc
index c5566d54e33f8bc0812a4328a5ad939d28ee78fe..158135287b7f727822e03b3ad5ad2e2144e0c641 100644 (file)
@@ -17,7 +17,7 @@
 #include <png.h>
 #include <SDL/SDL.h>
 
-#include "Core.hh"
+#include "Backend.hh"
 #include "Error.hh"
 #include "Image.hh"
 #include "Log.hh"
@@ -70,13 +70,12 @@ public:
        }
 
 
-       bool init(const std::string& name, bool flipped = false)
+       void init(const std::string& name, bool flipped = false)
        {
-               std::string path = Image::getPath(name);
+               std::string path(name);
 
-               logInfo << "opening image file " << path << std::endl;
-               FILE* fp = fopen(path.c_str(), "rb");
-               if (!fp) return false;
+               FILE* fp = Image::openFile(path);
+               if (!fp) return;
 
                png_byte        signature[8];
                size_t          bytesRead;
@@ -97,14 +96,10 @@ public:
                png_textp       texts = 0;
                int                     numTexts;
 
-               logInfo("checking signature...");
                bytesRead = fread(signature, 1, sizeof(signature), fp);
-               logInfo << "reading " << bytesRead << " bytes of signature"
-                               << std::endl;
                if (bytesRead < sizeof(signature) ||
                        png_sig_cmp(signature, 0, sizeof(signature)) != 0) goto cleanup;
 
-               logInfo("creating png structures...");
                pngObj = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
                if (!pngObj)     goto cleanup;
 
@@ -114,7 +109,6 @@ public:
                pngInfoEnd = png_create_info_struct(pngObj);
                if (!pngInfoEnd) goto cleanup;
 
-               logInfo("setting up long jump...");
                if (setjmp(png_jmpbuf(pngObj))) goto cleanup;
 
                png_init_io(pngObj, fp);
@@ -122,7 +116,6 @@ public:
                png_read_info(pngObj, pngInfo);
 
                bpp = png_get_bit_depth(pngObj, pngInfo);
-               logInfo << "texture bpp: " << bpp << std::endl;
                colors = png_get_color_type(pngObj, pngInfo);
                switch (colors)
                {
@@ -147,13 +140,11 @@ public:
                channels = png_get_channels(pngObj, pngInfo);
                mDepth = bpp * channels;
 
-               logInfo << "texture channels: " << channels << std::endl;
                if (channels == 3) mColorMode = GL_RGB;
                else               mColorMode = GL_RGBA;
                
                // read comments
                png_get_text(pngObj, pngInfo, &texts, &numTexts);
-               logInfo << "num texts: " << numTexts << std::endl;
                for (int i = 0; i < numTexts; ++i)
                {
                        if (strncmp(texts[i].key, "TextureInfo", 11) == 0)
@@ -211,14 +202,11 @@ public:
 
        cleanup:
 
-               logInfo("cleaning up...");
                delete[] rows;
                png_destroy_read_struct(pngObj     ? &pngObj     : 0,
                                                                pngInfo    ? &pngInfo    : 0,
                                                                pngInfoEnd ? &pngInfoEnd : 0);
                fclose(fp);
-
-               return mContext;
        }
 
 
@@ -300,19 +288,14 @@ void Image::setAsIcon() const
 }
 
 
-std::string Image::getPath(const std::string& name)
+bool Image::getPath(std::string& name)
 {
-       if (boost::find_last(name, ".png"))
-       {
-               return Resource::getPath(name);
-       }
-       else
-       {
-               std::string path("images/");
-               path += name;
-               path += ".png";
-               return Resource::getPath(path);
-       }
+       return Resource::getPath(name, "images/", "png");
+}
+
+FILE* Image::openFile(std::string& name)
+{
+       return Resource::openFile(name, "images/", "png");
 }
 
 
This page took 0.020471 seconds and 4 git commands to generate.