Browse Source

image: remove the Image::Format enum and use PixelFormat instead.

legacy
Sam Hocevar sam 12 years ago
parent
commit
c46b3fbfec
16 changed files with 61 additions and 74 deletions
  1. +2
    -2
      src/Makefile.am
  2. +1
    -2
      src/core.h
  3. +12
    -15
      src/gpu/texture.cpp
  4. +5
    -5
      src/image/codec/android-image.cpp
  5. +2
    -2
      src/image/codec/dummy-image.cpp
  6. +5
    -5
      src/image/codec/gdiplus-image.cpp
  7. +2
    -2
      src/image/codec/ios-image.cpp
  8. +2
    -2
      src/image/codec/ps3-image.cpp
  9. +4
    -3
      src/image/codec/sdl-image.cpp
  10. +2
    -4
      src/image/image-private.h
  11. +8
    -8
      src/image/image.cpp
  12. +1
    -0
      src/lol/gpu/texture.h
  13. +1
    -0
      src/lol/image/all.h
  14. +7
    -17
      src/lol/image/image.h
  15. +1
    -1
      src/lolcore.vcxproj
  16. +6
    -6
      src/tileset.cpp

+ 2
- 2
src/Makefile.am View File

@@ -45,7 +45,7 @@ liblolcore_headers = \
lol/sys/timer.h \ lol/sys/timer.h \
\ \
lol/image/all.h \ lol/image/all.h \
lol/image/color.h \
lol/image/color.h lol/image/image.h \
\ \
lol/gpu/all.h \ lol/gpu/all.h \
lol/gpu/shader.h lol/gpu/indexbuffer.h lol/gpu/vertexbuffer.h \ lol/gpu/shader.h lol/gpu/indexbuffer.h lol/gpu/vertexbuffer.h \
@@ -98,7 +98,7 @@ liblolcore_sources = \
sys/init.cpp sys/timer.cpp sys/file.cpp \ sys/init.cpp sys/timer.cpp sys/file.cpp \
sys/threadbase.h \ sys/threadbase.h \
\ \
image/image.cpp image/image.h image/image-private.h \
image/image.cpp image/image-private.h \
image/codec/gdiplus-image.cpp \ image/codec/gdiplus-image.cpp \
image/codec/ios-image.cpp \ image/codec/ios-image.cpp \
image/codec/dummy-image.cpp \ image/codec/dummy-image.cpp \


+ 1
- 2
src/core.h View File

@@ -94,8 +94,8 @@ static inline int isnan(float f)
#include <lol/base/all.h> #include <lol/base/all.h>
#include <lol/math/all.h> #include <lol/math/all.h>
#include <lol/sys/all.h> #include <lol/sys/all.h>
#include <lol/image/all.h>
#include <lol/gpu/all.h> #include <lol/gpu/all.h>
#include <lol/image/all.h>
#include <lol/debug/all.h> #include <lol/debug/all.h>


#include "numeric.h" #include "numeric.h"
@@ -130,7 +130,6 @@ static inline int isnan(float f)
#include "map.h" #include "map.h"
#include "layer.h" #include "layer.h"
#include "mesh/mesh.h" #include "mesh/mesh.h"
#include "image/image.h"
#include "application/application.h" #include "application/application.h"
#include "easymesh/csgbsp.h" #include "easymesh/csgbsp.h"
#include "easymesh/easymesh.h" #include "easymesh/easymesh.h"


+ 12
- 15
src/gpu/texture.cpp View File

@@ -82,26 +82,19 @@ Texture::Texture(ivec2 size, PixelFormat format)
/* Unknown */ /* Unknown */
{ D3DFMT_UNKNOWN, 0 }, { D3DFMT_UNKNOWN, 0 },


/* R8G8B8 */
/* FIXME: this is all mixed up for the RGBA/ARGB combinations */
# if defined USE_D3D9 # if defined USE_D3D9
{ D3DFMT_R8G8B8, 3 },
{ D3DFMT_R8G8B8, 3 }, /* RGB_8 */
{ D3DFMT_UNKNOWN, 0 }, /* RGBA_8 */
{ D3DFMT_A8R8G8B8, 4 }, /* ARGB_8 */
{ D3DFMT_UNKNOWN, 0 }, /* ABGR_8 */
{ D3DFMT_L8, 1 }, /* Y8 */
# else # else
{ D3DFMT_UNKNOWN, 0 }, { D3DFMT_UNKNOWN, 0 },
# endif

/* A8R8G8B8 */
# if defined USE_D3D9
{ D3DFMT_A8R8G8B8, 4 },
# else
{ D3DFMT_UNKNOWN, 0 },
/* By default the X360 will swizzle the texture. Ask for linear. */ /* By default the X360 will swizzle the texture. Ask for linear. */
{ D3DFMT_LIN_A8R8G8B8, 4 }, { D3DFMT_LIN_A8R8G8B8, 4 },
# endif

/* Y8 */
# if defined USE_D3D9
{ D3DFMT_L8, 1 },
# else
/* By default the X360 will swizzle the texture. Ask for linear. */
{ D3DFMT_UNKNOWN, 0 },
{ D3DFMT_LIN_L8, 1 }, { D3DFMT_LIN_L8, 1 },
# endif # endif
}; };
@@ -128,14 +121,17 @@ Texture::Texture(ivec2 size, PixelFormat format)
{ {
{ 0, 0, 0, 0 }, /* Unknown */ { 0, 0, 0, 0 }, /* Unknown */


/* FIXME: this is all mixed up for the RGBA/ARGB combinations */
#if __CELLOS_LV2__ #if __CELLOS_LV2__
{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, 3 }, { GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, 3 },
{ GL_ARGB_SCE, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, 4 }, { GL_ARGB_SCE, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, 4 },
{ GL_ARGB_SCE, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, 4 },
{ GL_ARGB_SCE, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, 4 }, { GL_ARGB_SCE, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, 4 },
{ GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 }, { GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 },
#elif defined __native_client__ || defined HAVE_GLES_2X #elif defined __native_client__ || defined HAVE_GLES_2X
{ GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, 3 }, { GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, 3 },
{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 4 }, { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 4 },
{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 4 },
/* FIXME: if GL_RGBA is not available, we should advertise /* FIXME: if GL_RGBA is not available, we should advertise
* this format as "not available" on this platform. */ * this format as "not available" on this platform. */
{ GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 4 }, { GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 4 },
@@ -144,6 +140,7 @@ Texture::Texture(ivec2 size, PixelFormat format)
{ GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, 3 }, /* RGB_8 */ { GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, 3 }, /* RGB_8 */
/* Seems efficient for little endian textures */ /* Seems efficient for little endian textures */
{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 4 }, /* ARGB_8 */ { GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 4 }, /* ARGB_8 */
{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 4 }, /* ARGB_8 */
{ GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 4 }, /* ABGR_8 */ { GL_RGBA8, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 4 }, /* ABGR_8 */
{ GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1 }, /* A8 */ { GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1 }, /* A8 */
#endif #endif


+ 5
- 5
src/image/codec/android-image.cpp View File

@@ -83,24 +83,24 @@ bool AndroidImageData::Open(char const *path)


/* Get image dimensions */ /* Get image dimensions */
mid = env->GetMethodID(cls, "getWidth", "(Landroid/graphics/Bitmap;)I"); mid = env->GetMethodID(cls, "getWidth", "(Landroid/graphics/Bitmap;)I");
size.x = env->CallIntMethod(g_activity, mid, bmp);
m_size.x = env->CallIntMethod(g_activity, mid, bmp);
mid = env->GetMethodID(cls, "getHeight", "(Landroid/graphics/Bitmap;)I"); mid = env->GetMethodID(cls, "getHeight", "(Landroid/graphics/Bitmap;)I");
size.y = env->CallIntMethod(g_activity, mid, bmp);
m_size.y = env->CallIntMethod(g_activity, mid, bmp);


/* Get pixels */ /* Get pixels */
array = env->NewIntArray(size.x * size.y);
array = env->NewIntArray(m_size.x * m_size.y);
env->NewGlobalRef(array); env->NewGlobalRef(array);
mid = env->GetMethodID(cls, "getPixels", "(Landroid/graphics/Bitmap;[I)V"); mid = env->GetMethodID(cls, "getPixels", "(Landroid/graphics/Bitmap;[I)V");
env->CallVoidMethod(g_activity, mid, bmp, array); env->CallVoidMethod(g_activity, mid, bmp, array);


pixels = env->GetIntArrayElements(array, 0); pixels = env->GetIntArrayElements(array, 0);
for (int n = 0; n < size.x * size.y; n++)
for (int n = 0; n < m_size.x * m_size.y; n++)
{ {
uint32_t u = pixels[n]; uint32_t u = pixels[n];
u = (u & 0xff00ff00) | ((u & 0xff0000) >> 16) | ((u & 0xff) << 16); u = (u & 0xff00ff00) | ((u & 0xff0000) >> 16) | ((u & 0xff) << 16);
pixels[n] = u; pixels[n] = u;
} }
format = Image::FORMAT_RGBA;
m_format = PixelFormat::RGBA_8;


return true; return true;
} }


+ 2
- 2
src/image/codec/dummy-image.cpp View File

@@ -44,8 +44,8 @@ bool DummyImageData::Open(char const *path)
{ {
UNUSED(path); UNUSED(path);


size = ivec2(256);
format = Image::FORMAT_RGBA;
m_size = ivec2(256);
m_format = PixelFormat::RGBA_8;
pixels = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*pixels)); pixels = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*pixels));
uint8_t *parser = pixels; uint8_t *parser = pixels;
for (int j = 0; j < 256; j++) for (int j = 0; j < 256; j++)


+ 5
- 5
src/image/codec/gdiplus-image.cpp View File

@@ -109,10 +109,10 @@ bool GdiPlusImageData::Open(char const *path)
return false; return false;
} }


size = ivec2(m_bitmap->GetWidth(), m_bitmap->GetHeight());
format = Image::FORMAT_RGBA;
m_size = ivec2(m_bitmap->GetWidth(), m_bitmap->GetHeight());
m_format = PixelFormat::RGBA_8;


Gdiplus::Rect rect(0, 0, size.x, size.y);
Gdiplus::Rect rect(0, 0, m_size.x, m_size.y);
if(m_bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead, if(m_bitmap->LockBits(&rect, Gdiplus::ImageLockModeRead,
PixelFormat32bppARGB, &m_bdata) != Gdiplus::Ok) PixelFormat32bppARGB, &m_bdata) != Gdiplus::Ok)
{ {
@@ -127,8 +127,8 @@ bool GdiPlusImageData::Open(char const *path)
* know about ARGB, only RGBA. So we swap bytes. We could also fix * know about ARGB, only RGBA. So we swap bytes. We could also fix
* this in the shader. */ * this in the shader. */
uint8_t *p = static_cast<uint8_t *>(m_bdata.Scan0); uint8_t *p = static_cast<uint8_t *>(m_bdata.Scan0);
for (int y = 0; y < size.y; y++)
for (int x = 0; x < size.x; x++)
for (int y = 0; y < m_size.y; y++)
for (int x = 0; x < m_size.x; x++)
{ {
uint8_t tmp = p[2]; uint8_t tmp = p[2];
p[2] = p[0]; p[2] = p[0];


+ 2
- 2
src/image/codec/ios-image.cpp View File

@@ -64,8 +64,8 @@ bool IosImageData::Open(char const *path)


int w = CGImageGetWidth(image.CGImage); int w = CGImageGetWidth(image.CGImage);
int h = CGImageGetHeight(image.CGImage); int h = CGImageGetHeight(image.CGImage);
size = ivec2(w, h);
format = Image::FORMAT_RGBA;
m_size = ivec2(w, h);
m_format = PixelFormat::RGBA_8;


CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB(); CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB();
pixels = (uint8_t *)malloc(w * h * 4); pixels = (uint8_t *)malloc(w * h * 4);


+ 2
- 2
src/image/codec/ps3-image.cpp View File

@@ -137,8 +137,8 @@ bool Ps3ImageData::Open(char const *path)
} }


/* Decode image */ /* Decode image */
size = ivec2(info.imageWidth, info.imageHeight);
format = Image::FORMAT_RGBA;
m_size = ivec2(info.imageWidth, info.imageHeight);
m_format = PixelFormat::RGBA_8;
pixels = (uint8_t *)malloc(info.imageWidth * 4 * info.imageHeight); pixels = (uint8_t *)malloc(info.imageWidth * 4 * info.imageHeight);
CellPngDecDataCtrlParam data_ctrl_param; CellPngDecDataCtrlParam data_ctrl_param;
data_ctrl_param.outputBytesPerLine = info.imageWidth * 4; data_ctrl_param.outputBytesPerLine = info.imageWidth * 4;


+ 4
- 3
src/image/codec/sdl-image.cpp View File

@@ -73,17 +73,18 @@ bool SdlImageData::Open(char const *path)
return false; return false;
} }


size = ivec2(m_img->w, m_img->h);
m_size = ivec2(m_img->w, m_img->h);


if (m_img->format->BytesPerPixel != 4) if (m_img->format->BytesPerPixel != 4)
{ {
SDL_Surface *tmp = Create32BppSurface(size);
SDL_Surface *tmp = Create32BppSurface(m_size);
SDL_BlitSurface(m_img, nullptr, tmp, nullptr); SDL_BlitSurface(m_img, nullptr, tmp, nullptr);
SDL_FreeSurface(m_img); SDL_FreeSurface(m_img);
m_img = tmp; m_img = tmp;
} }


format = m_img->format->Amask ? Image::FORMAT_RGBA : Image::FORMAT_RGB;
m_format = m_img->format->Amask ? PixelFormat::RGBA_8
: PixelFormat::RGB_8;


return true; return true;
} }


+ 2
- 4
src/image/image-private.h View File

@@ -16,8 +16,6 @@
#if !defined __LOL_IMAGE_PRIVATE_H__ #if !defined __LOL_IMAGE_PRIVATE_H__
#define __LOL_IMAGE_PRIVATE_H__ #define __LOL_IMAGE_PRIVATE_H__


#include "image.h"

namespace lol namespace lol
{ {


@@ -81,8 +79,8 @@ public:
virtual void *GetData() const = 0; virtual void *GetData() const = 0;


protected: protected:
ivec2 size;
Image::format_t format;
ivec2 m_size;
PixelFormat m_format;
}; };


#define REGISTER_IMAGE_LOADER(name) \ #define REGISTER_IMAGE_LOADER(name) \


+ 8
- 8
src/image/image.cpp View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or // 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 // modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See // Public License, Version 2, as published by Sam Hocevar. See
@@ -58,28 +58,28 @@ Image::Image(char const *path)
static bool init = RegisterAllLoaders(); static bool init = RegisterAllLoaders();
UNUSED(init); UNUSED(init);


data = ImageLoader::Load(path);
m_data = ImageLoader::Load(path);
} }


ivec2 Image::GetSize() const ivec2 Image::GetSize() const
{ {
return data->size;
return m_data->m_size;
} }


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


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


Image::~Image() Image::~Image()
{ {
data->Close();
delete data;
m_data->Close();
delete m_data;
} }


} /* namespace lol */ } /* namespace lol */


+ 1
- 0
src/lol/gpu/texture.h View File

@@ -26,6 +26,7 @@ struct PixelFormat
{ {
Unknown = 0, Unknown = 0,
RGB_8, RGB_8,
RGBA_8,
ARGB_8, ARGB_8,
ABGR_8, ABGR_8,
Y_8, Y_8,


+ 1
- 0
src/lol/image/all.h View File

@@ -12,6 +12,7 @@
#define __LOL_IMAGE_ALL_H__ #define __LOL_IMAGE_ALL_H__


#include <lol/image/color.h> #include <lol/image/color.h>
#include <lol/image/image.h>


#endif // __LOL_IMAGE_ALL_H__ #endif // __LOL_IMAGE_ALL_H__



src/image/image.h → src/lol/image/image.h View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or // 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 // modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See // Public License, Version 2, as published by Sam Hocevar. See
@@ -13,39 +13,29 @@
// --------------- // ---------------
// //


#if !defined __LOL_IMAGE_H__
#define __LOL_IMAGE_H__
#if !defined __LOL_IMAGE_IMAGE_H__
#define __LOL_IMAGE_IMAGE_H__


#include "lol/math/vector.h"
#include <lol/math/vector.h>


namespace lol namespace lol
{ {


class ImageData;

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


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

ivec2 GetSize() const; ivec2 GetSize() const;
format_t GetFormat() const;
PixelFormat GetFormat() const;
void *GetData() const; void *GetData() const;


private: private:
ImageData *data;
class ImageData *m_data;
}; };


} /* namespace lol */ } /* namespace lol */


#endif // __LOL_IMAGE_H__
#endif // __LOL_IMAGE_IMAGE_H__



+ 1
- 1
src/lolcore.vcxproj View File

@@ -188,7 +188,6 @@
<ClInclude Include="gpu\lolfx-compiler.h" /> <ClInclude Include="gpu\lolfx-compiler.h" />
<ClInclude Include="gradient.h" /> <ClInclude Include="gradient.h" />
<ClInclude Include="image\image-private.h" /> <ClInclude Include="image\image-private.h" />
<ClInclude Include="image\image.h" />
<ClInclude Include="input\input.h" /> <ClInclude Include="input\input.h" />
<ClInclude Include="input\keyboard.h" /> <ClInclude Include="input\keyboard.h" />
<ClInclude Include="input\stick.h" /> <ClInclude Include="input\stick.h" />
@@ -215,6 +214,7 @@
<ClInclude Include="lol\gpu\vertexbuffer.h" /> <ClInclude Include="lol\gpu\vertexbuffer.h" />
<ClInclude Include="lol\image\all.h" /> <ClInclude Include="lol\image\all.h" />
<ClInclude Include="lol\image\color.h" /> <ClInclude Include="lol\image\color.h" />
<ClInclude Include="lol\image\image.h" />
<ClInclude Include="lol\math\all.h" /> <ClInclude Include="lol\math\all.h" />
<ClInclude Include="lol\math\functions.h" /> <ClInclude Include="lol\math\functions.h" />
<ClInclude Include="lol\math\geometry.h" /> <ClInclude Include="lol\math\geometry.h" />


+ 6
- 6
src/tileset.cpp View File

@@ -115,17 +115,17 @@ void TileSet::TickDraw(float seconds)
else if (data->img) else if (data->img)
{ {
int planes; int planes;
PixelFormat format = PixelFormat::Unknown;
PixelFormat format = data->img->GetFormat();


switch (data->img->GetFormat())
switch (format)
{ {
case Image::FORMAT_RGB:
format = PixelFormat::RGB_8;
case PixelFormat::RGB_8:
planes = 3; planes = 3;
break; break;
case Image::FORMAT_RGBA:
case PixelFormat::RGBA_8:
case PixelFormat::ARGB_8:
case PixelFormat::ABGR_8:
default: default:
format = PixelFormat::ARGB_8;
planes = 4; planes = 4;
break; break;
} }


Loading…
Cancel
Save