diff --git a/build/lol-build b/build/lol-build index bd92cf7a..878a9c39 100755 --- a/build/lol-build +++ b/build/lol-build @@ -80,6 +80,7 @@ configure() BUILDFLAGS= fi PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PWD/contrib/gtkglarea-2.0.1/lib/pkgconfig" + LDFLAGS="$LDFLAGS -L$PWD/contrib/gdiplus/lib" LDFLAGS="$LDFLAGS -L$PWD/contrib/glew-1.7.0/lib/i686-w64-mingw32" LDFLAGS="$LDFLAGS -L$PWD/contrib/sdl-1.2.14/lib/i686-w64-mingw32" LDFLAGS="$LDFLAGS -L$PWD/contrib/sdl-image-1.2.10/lib/i686-w64-mingw32" @@ -121,6 +122,7 @@ configure() PATH="$PATH" ./configure CXX=ppu-lv2-g++ CC=ppu-lv2-gcc ac_cv_exeext=.elf --host=none ;; windows-i386|windows-amd64) + CPPFLAGS="$CPPFLAGS -I$PWD/contrib/gdiplus/include" CPPFLAGS="$CPPFLAGS -I$PWD/contrib/sdl-1.2.14/include" CPPFLAGS="$CPPFLAGS -I$PWD/contrib/sdl-image-1.2.10/include" CPPFLAGS="$CPPFLAGS -I$PWD/contrib/sdl-mixer-1.2.11/include" diff --git a/configure.ac b/configure.ac index 85d61ee9..9cbe9330 100644 --- a/configure.ac +++ b/configure.ac @@ -263,6 +263,24 @@ fi AM_CONDITIONAL(USE_LIBPNG, test "${ac_cv_my_have_libpng}" != "no") +dnl Use Windows GDI+? +ac_cv_my_have_gdiplus="no" +AC_LANG_PUSH(C++) +AC_CHECK_HEADERS(Gdiplus.h, + [ac_cv_my_have_gdiplus="yes" + LOL_LIBS="${LOL_LIBS} -lgdiplus"], + [ac_cv_my_have_gdiplus="no"], + [#include + using std::min; + using std::max; + #include ]) +AC_LANG_POP(C++) +if test "${ac_cv_my_have_gdiplus}" != "no"; then + AC_DEFINE(USE_GDIPLUS, 1, Define to 1 to use GDI+) +fi +AM_CONDITIONAL(USE_GDIPLUS, test "${ac_cv_my_have_gdiplus}" = "yes") + + dnl Use libcaca? (required for font generation) ac_cv_my_have_caca="no" PKG_CHECK_MODULES(CACA, caca >= 0.99.beta17, [ac_cv_my_have_caca="yes"], [:]) diff --git a/src/Makefile.am b/src/Makefile.am index 886558d2..5ba2725b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,6 +27,7 @@ liblol_a_SOURCES = \ \ image/image.cpp image/image.h image/image-private.h \ image/codec/android-image.cpp \ + image/codec/gdiplus-image.cpp \ image/codec/ios-image.cpp \ image/codec/sdl-image.cpp \ image/codec/ps3-image.cpp \ diff --git a/src/image/codec/gdiplus-image.cpp b/src/image/codec/gdiplus-image.cpp new file mode 100644 index 00000000..4b23d78e --- /dev/null +++ b/src/image/codec/gdiplus-image.cpp @@ -0,0 +1,117 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#if defined USE_GDIPLUS + +#include + +#include + +using namespace std; + +#include +#include + +#include "core.h" +#include "../../image/image-private.h" + +namespace lol +{ + +/* + * Image implementation class + */ + +DECLARE_IMAGE_LOADER(GdiPlusImageData, 100) +{ +public: + virtual bool Open(char const *); + virtual bool Close(); + + virtual void *GetData() const; + +private: + Gdiplus::Bitmap *bitmap; + Gdiplus::BitmapData bdata; +}; + +/* + * Public Image class + */ + +bool GdiPlusImageData::Open(char const *path) +{ + size_t len; + len = mbstowcs(NULL, path, 0); + wchar_t *wpath = new wchar_t[len + 1]; + if (mbstowcs(wpath, path, len + 1) == (size_t)-1) + { +#if !LOL_RELEASE + Log::Error("invalid image name %s\n", path); +#endif + delete[] wpath; + return false; + } + + ULONG_PTR token; + Gdiplus::GdiplusStartupInput input; + Gdiplus::GdiplusStartup(&token, &input, NULL); + + for (wchar_t const *wname = wpath; *wname; wname++) + if ((bitmap = Gdiplus::Bitmap::FromFile(wname, 0))) + break; + + delete[] wpath; + if (!bitmap) + { +#if !LOL_RELEASE + Log::Error("could not load %s\n", path); +#endif + return false; + } + + size = ivec2(bitmap->GetWidth(), bitmap->GetHeight()); + format = Image::FORMAT_RGBA; + + Gdiplus::Rect rect(0, 0, size.x, size.y); + if(bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead, + PixelFormat32bppARGB, &bdata) != Gdiplus::Ok) + { +#if !LOL_RELEASE + Log::Error("could not lock bits in %s\n", path); +#endif + delete bitmap; + return false; + } + + return true; +} + +bool GdiPlusImageData::Close() +{ + bitmap->UnlockBits(&bdata); + delete bitmap; + + return true; +} + +void * GdiPlusImageData::GetData() const +{ + return bdata.Scan0; +} + +} /* namespace lol */ + +#endif /* defined USE_GDIPLUS */ + diff --git a/src/image/image.cpp b/src/image/image.cpp index 07845463..e95b2073 100644 --- a/src/image/image.cpp +++ b/src/image/image.cpp @@ -28,6 +28,9 @@ bool ImageLoader::RegisterAllLoaders() REGISTER_IMAGE_LOADER(AndroidImageData) #endif REGISTER_IMAGE_LOADER(DummyImageData) +#if defined USE_GDIPLUS + REGISTER_IMAGE_LOADER(GdiPlusImageData) +#endif #if defined __APPLE__ && defined __MACH__ && defined __arm__ REGISTER_IMAGE_LOADER(IosImageData) #endif