diff --git a/demos/tutorial/11_fractal.cpp b/demos/tutorial/11_fractal.cpp index 2e4a6bdc..a766ed99 100644 --- a/demos/tutorial/11_fractal.cpp +++ b/demos/tutorial/11_fractal.cpp @@ -457,7 +457,7 @@ public: /* Create a texture of half the width and twice the height * so that we can upload four different subimages each frame. */ m_texture = new Texture(ivec2(m_size.x / 2, m_size.y * 2), - PixelFormat::ABGR_8); + PixelFormat::RGBA_8); /* Ensure the texture data is complete at least once, otherwise * uploading subimages will not work. */ diff --git a/src/Makefile.am b/src/Makefile.am index a5ed73cb..f5bc3b15 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -50,7 +50,7 @@ liblolcore_headers = \ lol/sys/timer.h \ \ lol/image/all.h \ - lol/image/color.h lol/image/image.h \ + lol/image/pixel.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 \ @@ -110,7 +110,7 @@ liblolcore_sources = \ sys/init.cpp sys/timer.cpp sys/file.cpp \ sys/thread.cpp sys/threadbase.h \ \ - image/image.cpp image/image-private.h image/kernel.cpp image/pixels.cpp \ + image/image.cpp image/image-private.h image/kernel.cpp image/pixel.cpp \ image/crop.cpp image/resample.cpp image/noise.cpp \ image/codec/gdiplus-image.cpp image/codec/imlib2-image.cpp \ image/codec/sdl-image.cpp image/codec/ios-image.cpp \ diff --git a/src/core.h b/src/core.h index fd8cbed2..84b29958 100644 --- a/src/core.h +++ b/src/core.h @@ -159,8 +159,8 @@ static inline int isnan(float f) #include #include #include -#include #include +#include #include #include "utils.h" diff --git a/src/gpu/texture.cpp b/src/gpu/texture.cpp index 1498e5a3..08307126 100644 --- a/src/gpu/texture.cpp +++ b/src/gpu/texture.cpp @@ -92,21 +92,17 @@ Texture::Texture(ivec2 size, PixelFormat format) /* FIXME: this is all mixed up for the RGBA/ARGB combinations */ # if defined USE_D3D9 - { D3DFMT_L8, 1 }, /* Y8 */ + { D3DFMT_L8, 1 }, /* Y_8 */ { D3DFMT_R8G8B8, 3 }, /* RGB_8 */ { D3DFMT_A8R8G8B8, 4 }, /* RGBA_8 */ - { D3DFMT_A8R8G8B8, 4 }, /* ARGB_8 */ - { D3DFMT_UNKNOWN, 0 }, /* ABGR_8 */ { D3DFMT_UNKNOWN, 0 }, /* Y_F32 */ { D3DFMT_UNKNOWN, 0 }, /* RGB_F32 */ { D3DFMT_UNKNOWN, 0 }, /* RGBA_F32 */ # else { D3DFMT_LIN_L8, 1 }, { D3DFMT_UNKNOWN, 0 }, - { D3DFMT_UNKNOWN, 0 }, /* By default the X360 will swizzle the texture. Ask for linear. */ { D3DFMT_LIN_A8R8G8B8, 4 }, - { D3DFMT_UNKNOWN, 0 }, { D3DFMT_UNKNOWN, 0 }, /* Y_F32 */ { D3DFMT_UNKNOWN, 0 }, /* RGB_F32 */ { D3DFMT_UNKNOWN, 0 }, /* RGBA_F32 */ @@ -142,23 +138,17 @@ Texture::Texture(ivec2 size, PixelFormat format) { GL_LUMINANCE8, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 }, { 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 }, #elif defined __native_client__ || defined HAVE_GLES_2X { GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1 }, { 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 }, #else { GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1 }, /* A8 */ { 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 */ #endif { 0, 0, 0, 0 }, /* Y_F32 */ { 0, 0, 0, 0 }, /* RGB_F32 */ diff --git a/src/image/analysis/histogram.cpp b/src/image/analysis/histogram.cpp deleted file mode 100644 index 2435b3b2..00000000 --- a/src/image/analysis/histogram.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * libpipi Pathetic image processing interface library - * Copyright (c) 2004-2008 Sam Hocevar - * 2008 Jean-Yves Lamoureux -#include -#include - -#include "pipi.h" -#include "pipi-internals.h" - - -pipi_histogram_t* pipi_new_histogram(void) -{ - return malloc(sizeof(pipi_histogram_t)); -} - - -int pipi_get_image_histogram(pipi_image_t *img, pipi_histogram_t*h, int flags) -{ - pipi_pixels_t *p; - uint8_t *data; - float n; - unsigned int max; - int i; - - if(!h) return -1; - - p = pipi_get_pixels(img, PIPI_PIXELS_RGBA_U8); - data = (uint8_t *)p->pixels; - memset(h->a, 0, 256*(sizeof(unsigned int))); - memset(h->r, 0, 256*(sizeof(unsigned int))); - memset(h->g, 0, 256*(sizeof(unsigned int))); - memset(h->b, 0, 256*(sizeof(unsigned int))); - memset(h->y, 0, 256*(sizeof(unsigned int))); - - - for(i=0; i< img->w*img->h*4; i+=4) - { - if(flags&PIPI_COLOR_A) - h->a[data[i+3]]++; - if(flags&PIPI_COLOR_R) - h->r[data[i+2]]++; - if(flags&PIPI_COLOR_G) - h->g[data[i+1]]++; - if(flags&PIPI_COLOR_B) - h->b[data[i]]++; - if(flags&PIPI_COLOR_Y) - { - uint32_t val = 0.; - val += 0.299 * data[i]; - val += 0.587 * data[i+1]; - val += 0.114 * data[i+2]; - - h->y[val>255?255:val]++; - } - } - - /* Normalize dataset */ - if(flags&PIPI_COLOR_R) - { - max = 0; - for(i=0; i<256; i++) - if(h->r[i] > max) max = h->r[i]; - n = 255.0f / max; - for(i=0; i<256; i++) - h->r[i]*=n; - } - if(flags&PIPI_COLOR_G) - { - max = 0; - for(i=0; i<256; i++) - if(h->g[i] > max) max = h->g[i]; - n = 255.0f / max; - for(i=0; i<256; i++) - h->g[i]*=n; - } - if(flags&PIPI_COLOR_B) - { - max = 0; - for(i=0; i<256; i++) - if(h->b[i] > max) max = h->b[i]; - n = 255.0f / max; - for(i=0; i<256; i++) - h->b[i]*=n; - } - if(flags&PIPI_COLOR_A) - { - max = 0; - for(i=0; i<256; i++) - if(h->a[i] > max) max = h->a[i]; - n = 255.0f / max; - for(i=0; i<256; i++) - h->a[i]*=n; - } - if(flags&PIPI_COLOR_Y) - { - max = 0; - for(i=0; i<256; i++) - if(h->y[i] > max) max = h->y[i]; - n = 255.0f / max; - for(i=0; i<256; i++) - h->y[i]*=n; - } - - pipi_release_pixels(img, p); - - return 0; -} - -int pipi_render_histogram(pipi_image_t *img, pipi_histogram_t*h, int flags) -{ - int x; - - if(!img || !h) return -1; - - for(x=0; x<256; x++) - { - if(flags&PIPI_COLOR_R) - pipi_draw_line(img, - x, 255, - x, 255 - h->r[x], - 0x00FF0000, - 0); - if(flags&PIPI_COLOR_G) - pipi_draw_line(img, - x, 255, - x, 255 - h->g[x], - 0x0000FF00, - 0); - if(flags&PIPI_COLOR_B) - pipi_draw_line(img, - x, 255, - x, 255 - h->b[x], - 0x000000FF, - 0); - if(flags&PIPI_COLOR_A) - pipi_draw_line(img, - x, 255, - x, 255 - h->a[x], - 0x00000FFF, - 0); - if(flags&PIPI_COLOR_Y) - pipi_draw_line(img, - x, 255, - x, 255 - h->y[x], - 0x00FFFFFF, - 0); - } - - return 0; -} - - -int pipi_free_histogram(pipi_histogram_t* h) -{ - if(h) free(h); - else return -1; - - return 0; -} diff --git a/src/image/pixels.cpp b/src/image/pixel.cpp similarity index 96% rename from src/image/pixels.cpp rename to src/image/pixel.cpp index ce62bab1..a7295894 100644 --- a/src/image/pixels.cpp +++ b/src/image/pixel.cpp @@ -68,8 +68,12 @@ void Image::SetFormat(PixelFormat fmt) if (m_data->m_pixels[(int)fmt] == nullptr) { PixelDataBase *data = nullptr; +#pragma GCC diagnostic push +#pragma GCC diagnostic error "-Wswitch" switch (fmt) { + case PixelFormat::Unknown: + break; case PixelFormat::Y_8: data = new PixelData(size); break; case PixelFormat::RGB_8: @@ -82,9 +86,9 @@ void Image::SetFormat(PixelFormat fmt) data = new PixelData(size); break; case PixelFormat::RGBA_F32: data = new PixelData(size); break; - default: - ASSERT(false, "invalid pixel type %d", (int)fmt); } +#pragma GCC diagnostic pop + ASSERT(data, "invalid pixel type %d", (int)fmt); m_data->m_pixels[(int)fmt] = data; } diff --git a/src/lol/gpu/texture.h b/src/lol/gpu/texture.h index 5d04d194..50340563 100644 --- a/src/lol/gpu/texture.h +++ b/src/lol/gpu/texture.h @@ -19,43 +19,6 @@ namespace lol { -enum class PixelFormat -{ - /* XXX: make sure to update texture.cpp when this changes */ - Unknown = 0, - Y_8, - RGB_8, - RGBA_8, - ARGB_8, - ABGR_8, - Y_F32, - RGB_F32, - RGBA_F32, -}; - -static inline uint8_t BytesPerPixel(PixelFormat format) -{ - switch (format) - { - case PixelFormat::Y_8: - return 1; - case PixelFormat::RGB_8: - return 3; - case PixelFormat::RGBA_8: - case PixelFormat::ARGB_8: - case PixelFormat::ABGR_8: - return 4; - case PixelFormat::Y_F32: - return 4; - case PixelFormat::RGB_F32: - return 12; - case PixelFormat::RGBA_F32: - return 16; - default: - return 1; - } -}; - struct TextureMagFilter { enum Value diff --git a/src/lol/image/all.h b/src/lol/image/all.h index b0b08ec4..bc60f234 100644 --- a/src/lol/image/all.h +++ b/src/lol/image/all.h @@ -11,6 +11,7 @@ #if !defined __LOL_IMAGE_ALL_H__ #define __LOL_IMAGE_ALL_H__ +#include #include #include diff --git a/src/lol/image/image.h b/src/lol/image/image.h index 612e3ea1..f63c63ee 100644 --- a/src/lol/image/image.h +++ b/src/lol/image/image.h @@ -21,14 +21,6 @@ namespace lol { -template struct PixelType { typedef void type; }; -template<> struct PixelType { typedef uint8_t type; }; -template<> struct PixelType { typedef u8vec3 type; }; -template<> struct PixelType { typedef u8vec4 type; }; -template<> struct PixelType { typedef float type; }; -template<> struct PixelType { typedef vec3 type; }; -template<> struct PixelType { typedef vec4 type; }; - enum class WrapMode : uint8_t { Clamp, diff --git a/src/lol/image/pixel.h b/src/lol/image/pixel.h new file mode 100644 index 00000000..e9ea1a21 --- /dev/null +++ b/src/lol/image/pixel.h @@ -0,0 +1,73 @@ +// +// Lol Engine +// +// Copyright: (c) 2004-2014 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://www.wtfpl.net/ for more details. +// + +// +// The Pixel-related classes +// ------------------------- +// + +#if !defined __LOL_IMAGE_PIXEL_H__ +#define __LOL_IMAGE_PIXEL_H__ + +namespace lol +{ + +/* The pixel formats we know about */ +enum class PixelFormat +{ + /* XXX: make sure to update image.cpp and texture.cpp when this changes */ + Unknown, + Y_8, + RGB_8, + RGBA_8, + Y_F32, + RGB_F32, + RGBA_F32, +}; + +/* Associated storage types for each pixel format */ +template struct PixelType { typedef void type; }; +template<> struct PixelType { typedef uint8_t type; }; +template<> struct PixelType { typedef u8vec3 type; }; +template<> struct PixelType { typedef u8vec4 type; }; +template<> struct PixelType { typedef float type; }; +template<> struct PixelType { typedef vec3 type; }; +template<> struct PixelType { typedef vec4 type; }; + +/* Number of bytes used by each pixel format */ +static inline uint8_t BytesPerPixel(PixelFormat format) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic error "-Wswitch" + switch (format) + { + case PixelFormat::Unknown: + break; + case PixelFormat::Y_8: + return 1; + case PixelFormat::RGB_8: + return 3; + case PixelFormat::RGBA_8: + return 4; + case PixelFormat::Y_F32: + return 4; + case PixelFormat::RGB_F32: + return 12; + case PixelFormat::RGBA_F32: + return 16; + } + return 0; +#pragma GCC diagnostic pop +}; + +} /* namespace lol */ + +#endif // __LOL_IMAGE_PIXEL_H__ + diff --git a/src/lolcore.vcxproj b/src/lolcore.vcxproj index de94f1cd..708d85d0 100644 --- a/src/lolcore.vcxproj +++ b/src/lolcore.vcxproj @@ -164,7 +164,7 @@ - + @@ -313,6 +313,7 @@ + diff --git a/src/lolcore.vcxproj.filters b/src/lolcore.vcxproj.filters index a1da3dde..83511936 100644 --- a/src/lolcore.vcxproj.filters +++ b/src/lolcore.vcxproj.filters @@ -400,7 +400,7 @@ image - + image @@ -699,6 +699,9 @@ lol\image + + lol\image + input