Browse Source

image: add a GDI+ loader.

legacy
Sam Hocevar sam 13 years ago
parent
commit
fbdec834dd
5 changed files with 141 additions and 0 deletions
  1. +2
    -0
      build/lol-build
  2. +18
    -0
      configure.ac
  3. +1
    -0
      src/Makefile.am
  4. +117
    -0
      src/image/codec/gdiplus-image.cpp
  5. +3
    -0
      src/image/image.cpp

+ 2
- 0
build/lol-build View File

@@ -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"


+ 18
- 0
configure.ac View File

@@ -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 <algorithm>
using std::min;
using std::max;
#include <windows.h>])
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"], [:])


+ 1
- 0
src/Makefile.am View File

@@ -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 \


+ 117
- 0
src/image/codec/gdiplus-image.cpp View File

@@ -0,0 +1,117 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// 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 <cmath>

#include <algorithm>

using namespace std;

#include <windows.h>
#include <Gdiplus.h>

#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 */


+ 3
- 0
src/image/image.cpp View File

@@ -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


Loading…
Cancel
Save