X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FImage.cc;h=158135287b7f727822e03b3ad5ad2e2144e0c641;hp=c5566d54e33f8bc0812a4328a5ad939d28ee78fe;hb=321f005b45580b8c2c14ddc577fb6ca7780a68c5;hpb=837bae9f2bf7b25e1d3d2625eeaf39c1d2f48827 diff --git a/src/Moof/Image.cc b/src/Moof/Image.cc index c5566d5..1581352 100644 --- a/src/Moof/Image.cc +++ b/src/Moof/Image.cc @@ -17,7 +17,7 @@ #include #include -#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"); }