浏览代码

Add the Image class for better abstraction.

legacy
Sam Hocevar sam 13 年前
父节点
当前提交
edd75a3c89
共有 10 个文件被更改,包括 176 次插入1 次删除
  1. +1
    -1
      src/Makefile.am
  2. +1
    -0
      src/core.h
  3. +99
    -0
      src/image.cpp
  4. +51
    -0
      src/image.h
  5. +2
    -0
      win32/deushax.vcxproj
  6. +6
    -0
      win32/deushax.vcxproj.filters
  7. +2
    -0
      win32/editor.vcxproj
  8. +6
    -0
      win32/editor.vcxproj.filters
  9. +2
    -0
      win32/monsterz.vcxproj
  10. +6
    -0
      win32/monsterz.vcxproj.filters

+ 1
- 1
src/Makefile.am 查看文件

@@ -9,7 +9,7 @@ liblol_a_SOURCES = \
timer.cpp timer.h bitfield.h profiler.cpp profiler.h input.h input.cpp \
world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \
text.cpp text.h emitter.cpp emitter.h numeric.h hash.cpp hash.h \
worldentity.cpp worldentity.h shader.cpp shader.h \
worldentity.cpp worldentity.h shader.cpp shader.h image.cpp image.h \
\
sdlapp.cpp sdlapp.h sdlinput.cpp sdlinput.h \
\


+ 1
- 0
src/core.h 查看文件

@@ -44,6 +44,7 @@
#include "map.h"
#include "layer.h"
#include "shader.h"
#include "image.h"

// Managers
#include "ticker.h"


+ 99
- 0
src/image.cpp 查看文件

@@ -0,0 +1,99 @@
//
// 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

#include <cmath>
#include <cstdio>

#if defined USE_SDL
# include <SDL.h>
# include <SDL_image.h>
#endif

#include "core.h"
#include "lolgl.h"

namespace lol
{

/*
* Image implementation class
*/

class ImageData
{
friend class Image;

private:
vec2i size;
Image::format_t format;

#if defined USE_SDL
SDL_Surface *img;
#endif
};

/*
* Public Image class
*/

Image::Image(char const *path)
: data(new ImageData())
{
#if defined USE_SDL
for (char const *name = path; *name; name++)
if ((data->img = IMG_Load(name)))
break;

if (!data->img)
{
#if !LOL_RELEASE
fprintf(stderr, "ERROR: could not load %s\n", path);
#endif
SDL_Quit();
exit(1);
}

data->size = vec2i(data->img->w, data->img->h);
data->format = data->img->format->Amask ? FORMAT_RGBA : FORMAT_RGB;
#else
data->size = 0;
data->format = FORMAT_UNKNOWN;
#endif
}

vec2i Image::GetSize() const
{
return data->size;
}

Image::format_t Image::GetFormat() const
{
return data->format;
}

void * Image::GetData() const
{
return data->img->pixels;
}

Image::~Image()
{
#if defined USE_LOL
SDL_FreeSurface(data->img);
#endif
delete data;
}

} /* namespace lol */


+ 51
- 0
src/image.h 查看文件

@@ -0,0 +1,51 @@
//
// 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.
//

//
// The Image class
// ---------------
//

#if !defined __DH_IMAGE_H__
#define __DH_IMAGE_H__

#include "matrix.h"

namespace lol
{

class ImageData;

class Image
{
public:
Image(char const *path);
~Image();

typedef enum
{
FORMAT_RGBA = 0,
FORMAT_RGB,
FORMAT_UNKNOWN,
}
format_t;

vec2i GetSize() const;
format_t GetFormat() const;
void *GetData() const;

private:
ImageData *data;
};

} /* namespace lol */

#endif // __DH_IMAGE_H__


+ 2
- 0
win32/deushax.vcxproj 查看文件

@@ -26,6 +26,7 @@
<ClInclude Include="..\src\font.h" />
<ClInclude Include="..\src\forge.h" />
<ClInclude Include="..\src\hash.h" />
<ClInclude Include="..\src\image.h" />
<ClInclude Include="..\src\input.h" />
<ClInclude Include="..\src\layer.h" />
<ClInclude Include="..\src\lolgl.h" />
@@ -63,6 +64,7 @@
<ClCompile Include="..\src\font.cpp" />
<ClCompile Include="..\src\forge.cpp" />
<ClCompile Include="..\src\hash.cpp" />
<ClCompile Include="..\src\image.cpp" />
<ClCompile Include="..\src\input.cpp" />
<ClCompile Include="..\src\layer.cpp" />
<ClCompile Include="..\src\map.cpp" />


+ 6
- 0
win32/deushax.vcxproj.filters 查看文件

@@ -42,6 +42,9 @@
<ClInclude Include="..\src\hash.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\image.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\input.h">
<Filter>lolengine</Filter>
</ClInclude>
@@ -142,6 +145,9 @@
<ClCompile Include="..\src\hash.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\image.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\input.cpp">
<Filter>lolengine</Filter>
</ClCompile>


+ 2
- 0
win32/editor.vcxproj 查看文件

@@ -26,6 +26,7 @@
<ClInclude Include="..\src\font.h" />
<ClInclude Include="..\src\forge.h" />
<ClInclude Include="..\src\hash.h" />
<ClInclude Include="..\src\image.h" />
<ClInclude Include="..\src\input.h" />
<ClInclude Include="..\src\layer.h" />
<ClInclude Include="..\src\lolgl.h" />
@@ -63,6 +64,7 @@
<ClCompile Include="..\src\font.cpp" />
<ClCompile Include="..\src\forge.cpp" />
<ClCompile Include="..\src\hash.cpp" />
<ClCompile Include="..\src\image.cpp" />
<ClCompile Include="..\src\input.cpp" />
<ClCompile Include="..\src\layer.cpp" />
<ClCompile Include="..\src\map.cpp" />


+ 6
- 0
win32/editor.vcxproj.filters 查看文件

@@ -42,6 +42,9 @@
<ClInclude Include="..\src\hash.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\image.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\input.h">
<Filter>lolengine</Filter>
</ClInclude>
@@ -142,6 +145,9 @@
<ClCompile Include="..\src\hash.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\image.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\input.cpp">
<Filter>lolengine</Filter>
</ClCompile>


+ 2
- 0
win32/monsterz.vcxproj 查看文件

@@ -31,6 +31,7 @@
<ClInclude Include="..\src\font.h" />
<ClInclude Include="..\src\forge.h" />
<ClInclude Include="..\src\hash.h" />
<ClInclude Include="..\src\image.h" />
<ClInclude Include="..\src\input.h" />
<ClInclude Include="..\src\layer.h" />
<ClInclude Include="..\src\lolgl.h" />
@@ -72,6 +73,7 @@
<ClCompile Include="..\src\font.cpp" />
<ClCompile Include="..\src\forge.cpp" />
<ClCompile Include="..\src\hash.cpp" />
<ClCompile Include="..\src\image.cpp" />
<ClCompile Include="..\src\input.cpp" />
<ClCompile Include="..\src\layer.cpp" />
<ClCompile Include="..\src\map.cpp" />


+ 6
- 0
win32/monsterz.vcxproj.filters 查看文件

@@ -42,6 +42,9 @@
<ClInclude Include="..\src\hash.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\image.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\input.h">
<Filter>lolengine</Filter>
</ClInclude>
@@ -147,6 +150,9 @@
<ClCompile Include="..\src\hash.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\image.cpp">
<Filter>lolengine</Filter>
</ClCompile>
<ClCompile Include="..\src\input.cpp">
<Filter>lolengine</Filter>
</ClCompile>


正在加载...
取消
保存