| @@ -45,7 +45,7 @@ liblolcore_headers = \ | |||
| lol/sys/timer.h \ | |||
| \ | |||
| lol/image/all.h \ | |||
| lol/image/color.h \ | |||
| lol/image/color.h lol/image/image.h \ | |||
| \ | |||
| lol/gpu/all.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/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/ios-image.cpp \ | |||
| image/codec/dummy-image.cpp \ | |||
| @@ -94,8 +94,8 @@ static inline int isnan(float f) | |||
| #include <lol/base/all.h> | |||
| #include <lol/math/all.h> | |||
| #include <lol/sys/all.h> | |||
| #include <lol/image/all.h> | |||
| #include <lol/gpu/all.h> | |||
| #include <lol/image/all.h> | |||
| #include <lol/debug/all.h> | |||
| #include "numeric.h" | |||
| @@ -130,7 +130,6 @@ static inline int isnan(float f) | |||
| #include "map.h" | |||
| #include "layer.h" | |||
| #include "mesh/mesh.h" | |||
| #include "image/image.h" | |||
| #include "application/application.h" | |||
| #include "easymesh/csgbsp.h" | |||
| #include "easymesh/easymesh.h" | |||
| @@ -82,26 +82,19 @@ Texture::Texture(ivec2 size, PixelFormat format) | |||
| /* Unknown */ | |||
| { D3DFMT_UNKNOWN, 0 }, | |||
| /* R8G8B8 */ | |||
| /* FIXME: this is all mixed up for the RGBA/ARGB combinations */ | |||
| # 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 | |||
| { 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. */ | |||
| { 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 }, | |||
| # endif | |||
| }; | |||
| @@ -128,14 +121,17 @@ Texture::Texture(ivec2 size, PixelFormat format) | |||
| { | |||
| { 0, 0, 0, 0 }, /* Unknown */ | |||
| /* FIXME: this is all mixed up for the RGBA/ARGB combinations */ | |||
| #if __CELLOS_LV2__ | |||
| { 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_BGRA, GL_UNSIGNED_INT_8_8_8_8, 4 }, | |||
| { GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 }, | |||
| #elif defined __native_client__ || defined HAVE_GLES_2X | |||
| { GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, 3 }, | |||
| { 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 | |||
| * this format as "not available" on this platform. */ | |||
| { 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 */ | |||
| /* 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_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 4 }, /* ABGR_8 */ | |||
| { GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1 }, /* A8 */ | |||
| #endif | |||
| @@ -83,24 +83,24 @@ bool AndroidImageData::Open(char const *path) | |||
| /* Get image dimensions */ | |||
| 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"); | |||
| size.y = env->CallIntMethod(g_activity, mid, bmp); | |||
| m_size.y = env->CallIntMethod(g_activity, mid, bmp); | |||
| /* Get pixels */ | |||
| array = env->NewIntArray(size.x * size.y); | |||
| array = env->NewIntArray(m_size.x * m_size.y); | |||
| env->NewGlobalRef(array); | |||
| mid = env->GetMethodID(cls, "getPixels", "(Landroid/graphics/Bitmap;[I)V"); | |||
| env->CallVoidMethod(g_activity, mid, bmp, array); | |||
| 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]; | |||
| u = (u & 0xff00ff00) | ((u & 0xff0000) >> 16) | ((u & 0xff) << 16); | |||
| pixels[n] = u; | |||
| } | |||
| format = Image::FORMAT_RGBA; | |||
| m_format = PixelFormat::RGBA_8; | |||
| return true; | |||
| } | |||
| @@ -44,8 +44,8 @@ bool DummyImageData::Open(char const *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)); | |||
| uint8_t *parser = pixels; | |||
| for (int j = 0; j < 256; j++) | |||
| @@ -109,10 +109,10 @@ bool GdiPlusImageData::Open(char const *path) | |||
| 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, | |||
| 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 | |||
| * this in the shader. */ | |||
| 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]; | |||
| p[2] = p[0]; | |||
| @@ -64,8 +64,8 @@ bool IosImageData::Open(char const *path) | |||
| int w = CGImageGetWidth(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(); | |||
| pixels = (uint8_t *)malloc(w * h * 4); | |||
| @@ -137,8 +137,8 @@ bool Ps3ImageData::Open(char const *path) | |||
| } | |||
| /* 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); | |||
| CellPngDecDataCtrlParam data_ctrl_param; | |||
| data_ctrl_param.outputBytesPerLine = info.imageWidth * 4; | |||
| @@ -73,17 +73,18 @@ bool SdlImageData::Open(char const *path) | |||
| 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) | |||
| { | |||
| SDL_Surface *tmp = Create32BppSurface(size); | |||
| SDL_Surface *tmp = Create32BppSurface(m_size); | |||
| SDL_BlitSurface(m_img, nullptr, tmp, nullptr); | |||
| SDL_FreeSurface(m_img); | |||
| 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; | |||
| } | |||
| @@ -16,8 +16,6 @@ | |||
| #if !defined __LOL_IMAGE_PRIVATE_H__ | |||
| #define __LOL_IMAGE_PRIVATE_H__ | |||
| #include "image.h" | |||
| namespace lol | |||
| { | |||
| @@ -81,8 +79,8 @@ public: | |||
| virtual void *GetData() const = 0; | |||
| protected: | |||
| ivec2 size; | |||
| Image::format_t format; | |||
| ivec2 m_size; | |||
| PixelFormat m_format; | |||
| }; | |||
| #define REGISTER_IMAGE_LOADER(name) \ | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // 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 | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| @@ -58,28 +58,28 @@ Image::Image(char const *path) | |||
| static bool init = RegisterAllLoaders(); | |||
| UNUSED(init); | |||
| data = ImageLoader::Load(path); | |||
| m_data = ImageLoader::Load(path); | |||
| } | |||
| 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 | |||
| { | |||
| return data->GetData(); | |||
| return m_data->GetData(); | |||
| } | |||
| Image::~Image() | |||
| { | |||
| data->Close(); | |||
| delete data; | |||
| m_data->Close(); | |||
| delete m_data; | |||
| } | |||
| } /* namespace lol */ | |||
| @@ -26,6 +26,7 @@ struct PixelFormat | |||
| { | |||
| Unknown = 0, | |||
| RGB_8, | |||
| RGBA_8, | |||
| ARGB_8, | |||
| ABGR_8, | |||
| Y_8, | |||
| @@ -12,6 +12,7 @@ | |||
| #define __LOL_IMAGE_ALL_H__ | |||
| #include <lol/image/color.h> | |||
| #include <lol/image/image.h> | |||
| #endif // __LOL_IMAGE_ALL_H__ | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // 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 | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // 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 | |||
| { | |||
| class ImageData; | |||
| class Image | |||
| { | |||
| public: | |||
| Image(char const *path); | |||
| ~Image(); | |||
| typedef enum | |||
| { | |||
| FORMAT_RGBA = 0, | |||
| FORMAT_RGB, | |||
| FORMAT_UNKNOWN, | |||
| } | |||
| format_t; | |||
| ivec2 GetSize() const; | |||
| format_t GetFormat() const; | |||
| PixelFormat GetFormat() const; | |||
| void *GetData() const; | |||
| private: | |||
| ImageData *data; | |||
| class ImageData *m_data; | |||
| }; | |||
| } /* namespace lol */ | |||
| #endif // __LOL_IMAGE_H__ | |||
| #endif // __LOL_IMAGE_IMAGE_H__ | |||
| @@ -188,7 +188,6 @@ | |||
| <ClInclude Include="gpu\lolfx-compiler.h" /> | |||
| <ClInclude Include="gradient.h" /> | |||
| <ClInclude Include="image\image-private.h" /> | |||
| <ClInclude Include="image\image.h" /> | |||
| <ClInclude Include="input\input.h" /> | |||
| <ClInclude Include="input\keyboard.h" /> | |||
| <ClInclude Include="input\stick.h" /> | |||
| @@ -215,6 +214,7 @@ | |||
| <ClInclude Include="lol\gpu\vertexbuffer.h" /> | |||
| <ClInclude Include="lol\image\all.h" /> | |||
| <ClInclude Include="lol\image\color.h" /> | |||
| <ClInclude Include="lol\image\image.h" /> | |||
| <ClInclude Include="lol\math\all.h" /> | |||
| <ClInclude Include="lol\math\functions.h" /> | |||
| <ClInclude Include="lol\math\geometry.h" /> | |||
| @@ -115,17 +115,17 @@ void TileSet::TickDraw(float seconds) | |||
| else if (data->img) | |||
| { | |||
| 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; | |||
| break; | |||
| case Image::FORMAT_RGBA: | |||
| case PixelFormat::RGBA_8: | |||
| case PixelFormat::ARGB_8: | |||
| case PixelFormat::ABGR_8: | |||
| default: | |||
| format = PixelFormat::ARGB_8; | |||
| planes = 4; | |||
| break; | |||
| } | |||