#include <png.h>
#include <SDL/SDL.h>
-#include "Backend.hh"
-#include "Error.hh"
-#include "Image.hh"
-#include "Log.hh"
-#include "Manager.hh"
+#include "backend.hh"
+#include "image.hh"
+#include "log.hh"
+#include "manager.hh"
-namespace Mf {
+namespace moof {
-class Image::Impl : public Manager<Impl>
+class image::impl : public manager<impl>
{
public:
- explicit Impl() :
- mContext(0),
- mPixels(0) {}
+ explicit impl() :
+ context_(0),
+ pixels_(0) {}
- ~Impl()
+ ~impl()
{
- SDL_FreeSurface(mContext);
- delete[] mPixels;
+ SDL_FreeSurface(context_);
+ delete[] pixels_;
}
void flip()
{
- unsigned char* pixels = (Uint8*)(mContext->pixels);
+ unsigned char* pixels = (Uint8*)(context_->pixels);
- unsigned pitch = mContext->pitch;
+ unsigned pitch = context_->pitch;
unsigned char line[pitch];
int yBegin = 0;
- int yEnd = mContext->h - 1;
+ int yEnd = context_->h - 1;
- if (SDL_MUSTLOCK(mContext)) SDL_LockSurface(mContext);
+ if (SDL_MUSTLOCK(context_)) SDL_LockSurface(context_);
while (yBegin < yEnd)
{
memcpy(line, pixels + pitch * yBegin, pitch);
yBegin++;
yEnd--;
}
- if (SDL_MUSTLOCK(mContext)) SDL_UnlockSurface(mContext);
+ if (SDL_MUSTLOCK(context_)) SDL_UnlockSurface(context_);
}
- void setAsIcon() const
+ void set_as_icon() const
{
- SDL_WM_SetIcon(mContext, 0);
+ SDL_WM_SetIcon(context_, 0);
}
{
std::string path(name);
- FILE* fp = Image::openFile(path);
+ FILE* fp = image::open_file(path);
if (!fp) return;
png_byte signature[8];
png_bytepp rows = 0;
png_textp texts = 0;
- int numTexts;
+ int nutext_s;
bytesRead = fread(signature, 1, sizeof(signature), fp);
if (bytesRead < sizeof(signature) ||
bpp = png_get_bit_depth(pngObj, pngInfo);
channels = png_get_channels(pngObj, pngInfo);
- mDepth = bpp * channels;
+ depth_ = bpp * channels;
- if (channels == 3) mColorMode = GL_RGB;
- else mColorMode = GL_RGBA;
+ if (channels == 3) color_mode_ = GL_RGB;
+ else color_mode_ = GL_RGBA;
// read comments
- png_get_text(pngObj, pngInfo, &texts, &numTexts);
- for (int i = 0; i < numTexts; ++i)
+ png_get_text(pngObj, pngInfo, &texts, &nutext_s);
+ for (int i = 0; i < nutext_s; ++i)
{
if (strncmp(texts[i].key, "TextureInfo", 11) == 0)
{
- mComment = texts[i].text;
+ comment_ = texts[i].text;
break;
}
}
height = png_get_image_height(pngObj, pngInfo);
pitch = png_get_rowbytes(pngObj, pngInfo);
- mPixels = new char[width * pitch];
+ pixels_ = new char[width * pitch];
rows = new png_bytep[height];
if (flipped)
{
for (int i = 0; i < height; ++i)
{
- rows[height - 1 - i] = (png_bytep)(mPixels +
+ rows[height - 1 - i] = (png_bytep)(pixels_ +
i * channels * width);
}
}
{
for (int i = 0; i < height; ++i)
{
- rows[i] = (png_bytep)(mPixels + i * channels * width);
+ rows[i] = (png_bytep)(pixels_ + i * channels * width);
}
}
png_read_image(pngObj, rows);
png_read_end(pngObj, 0);
- mContext = SDL_CreateRGBSurfaceFrom
+ context_ = SDL_CreateRGBSurfaceFrom
(
- mPixels,
+ pixels_,
width,
height,
bpp * channels,
}
- SDL_Surface* mContext;
- char* mPixels;
+ SDL_Surface* context_;
+ char* pixels_;
- unsigned mDepth;
- GLuint mColorMode;
+ unsigned depth_;
+ GLuint color_mode_;
- std::string mComment;
+ std::string comment_;
private:
- Backend mBackend;
+ backend backend_;
};
-Image::Image(const std::string& name) :
+image::image(const std::string& name) :
// pass through
- mImpl(Image::Impl::getInstance(name)) {}
+ impl_(image::impl::instance(name)) {}
-bool Image::isValid() const
+bool image::is_valid() const
{
- return mImpl->mContext;
+ return impl_->context_;
}
-int Image::getWidth() const
+int image::width() const
{
- return mImpl->mContext->w;
+ return impl_->context_->w;
}
-int Image::getHeight() const
+int image::height() const
{
- return mImpl->mContext->h;
+ return impl_->context_->h;
}
-unsigned Image::getDepth() const
+unsigned image::depth() const
{
- return mImpl->mDepth;
+ return impl_->depth_;
}
-unsigned Image::getPitch() const
+unsigned image::pitch() const
{
- return mImpl->mContext->pitch;
+ return impl_->context_->pitch;
}
-GLuint Image::getMode() const
+GLuint image::mode() const
{
- return mImpl->mColorMode;
+ return impl_->color_mode_;
}
-std::string Image::getComment() const
+std::string image::comment() const
{
- return mImpl->mComment;
+ return impl_->comment_;
}
-const char* Image::getPixels() const
+const char* image::pixels() const
{
- return mImpl->mPixels;
+ return impl_->pixels_;
}
-char* Image::getPixels()
+char* image::pixels()
{
- return mImpl->mPixels;
+ return impl_->pixels_;
}
-void Image::flip()
+void image::flip()
{
// pass through
- mImpl->flip();
+ impl_->flip();
}
-void Image::setAsIcon() const
+void image::set_as_icon() const
{
// pass through
- mImpl->setAsIcon();
+ impl_->set_as_icon();
}
-bool Image::getPath(std::string& name)
+bool image::find_path(std::string& name)
{
- return Resource::getPath(name, "images/", "png");
+ return resource::find_path(name, "images/", "png");
}
-FILE* Image::openFile(std::string& name)
+FILE* image::open_file(std::string& name)
{
- return Resource::openFile(name, "images/", "png");
+ return resource::open_file(name, "images/", "png");
}
-} // namespace Mf
+} // namespace moof