Skip to content

Commit

Permalink
Refactor|libgui|Image: Use GLPixelFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 29, 2013
1 parent 4696bf0 commit af04668
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 35 deletions.
16 changes: 4 additions & 12 deletions doomsday/libgui/include/de/gui/image.h
Expand Up @@ -27,6 +27,7 @@
#include <de/ISerializable>

#include "libgui.h"
#include "../GLPixelFormat"

namespace de {

Expand Down Expand Up @@ -66,15 +67,6 @@ class LIBGUI_PUBLIC Image : public ISerializable
typedef Vector2ui Size;
typedef Vector4ub Color;

/// GL format + type for glTex(Sub)Image.
struct GLFormat {
duint format;
duint type;
duint rowAlignment;

GLFormat(duint f, duint t = 0, duint ra = 0) : format(f), type(t), rowAlignment(ra) {}
};

public:
Image();
Image(Image const &other);
Expand Down Expand Up @@ -143,7 +135,7 @@ class LIBGUI_PUBLIC Image : public ISerializable
*/
QImage toQImage() const;

GLFormat glFormat() const;
GLPixelFormat glFormat() const;

// Drawing/editing methods.
Image subImage(Rectanglei const &subArea) const;
Expand All @@ -157,8 +149,8 @@ class LIBGUI_PUBLIC Image : public ISerializable
void operator << (Reader &from);

public:
static GLFormat glFormat(Format imageFormat);
static GLFormat glFormat(QImage::Format qtImageFormat);
static GLPixelFormat glFormat(Format imageFormat);
static GLPixelFormat glFormat(QImage::Format qtImageFormat);

static Image solidColor(Color const &color, Size const &size);

Expand Down
46 changes: 23 additions & 23 deletions doomsday/libgui/src/image.cpp
Expand Up @@ -274,7 +274,7 @@ QImage Image::toQImage() const
return img;
}

Image::GLFormat Image::glFormat() const
GLPixelFormat Image::glFormat() const
{
if(d->format == UseQImageFormat)
{
Expand Down Expand Up @@ -371,82 +371,82 @@ void Image::operator << (Reader &from)
}
}

Image::GLFormat Image::glFormat(Format imageFormat)
GLPixelFormat Image::glFormat(Format imageFormat)
{
DENG2_ASSERT(imageFormat >= Luminance_8 && imageFormat <= RGBx_8888);

switch(imageFormat)
{
case Luminance_8:
return GLFormat(GL_LUMINANCE, GL_UNSIGNED_BYTE, 1);
return GLPixelFormat(GL_LUMINANCE, GL_UNSIGNED_BYTE, 1);

case LuminanceAlpha_88:
return GLFormat(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2);
return GLPixelFormat(GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2);

case Alpha_8:
return GLFormat(GL_ALPHA, GL_UNSIGNED_BYTE, 1);
return GLPixelFormat(GL_ALPHA, GL_UNSIGNED_BYTE, 1);

case RGB_555:
return GLFormat(GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, 2);
return GLPixelFormat(GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, 2);

case RGB_565:
return GLFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2);
return GLPixelFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2);

case RGB_444:
return GLFormat(GL_RGB, GL_UNSIGNED_SHORT_4_4_4_4, 2);
return GLPixelFormat(GL_RGB, GL_UNSIGNED_SHORT_4_4_4_4, 2);

case RGB_888:
return GLFormat(GL_RGB, GL_UNSIGNED_BYTE, 1);
return GLPixelFormat(GL_RGB, GL_UNSIGNED_BYTE, 1);

case RGBA_4444:
return GLFormat(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 2);
return GLPixelFormat(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 2);

case RGBA_5551:
return GLFormat(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 2);
return GLPixelFormat(GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 2);

case RGBA_8888:
return GLFormat(GL_RGBA, GL_UNSIGNED_BYTE, 4);
return GLPixelFormat(GL_RGBA, GL_UNSIGNED_BYTE, 4);

default:
case RGBx_8888:
return GLFormat(GL_RGBA, GL_UNSIGNED_BYTE, 4);
return GLPixelFormat(GL_RGBA, GL_UNSIGNED_BYTE, 4);
}
}

Image::GLFormat Image::glFormat(QImage::Format format)
GLPixelFormat Image::glFormat(QImage::Format format)
{
switch(format)
{
case QImage::Format_Indexed8:
return GLFormat(GL_LUMINANCE, GL_UNSIGNED_BYTE, 1);
return GLPixelFormat(GL_LUMINANCE, GL_UNSIGNED_BYTE, 1);

case QImage::Format_RGB444:
return GLFormat(GL_RGB, GL_UNSIGNED_SHORT_4_4_4_4, 2);
return GLPixelFormat(GL_RGB, GL_UNSIGNED_SHORT_4_4_4_4, 2);

case QImage::Format_ARGB4444_Premultiplied:
return GLFormat(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 2);
return GLPixelFormat(GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 2);

case QImage::Format_RGB555:
return GLFormat(GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, 2);
return GLPixelFormat(GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, 2);

case QImage::Format_RGB16:
return GLFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2);
return GLPixelFormat(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2);

case QImage::Format_RGB888:
return GLFormat(GL_RGB, GL_UNSIGNED_BYTE, 1);
return GLPixelFormat(GL_RGB, GL_UNSIGNED_BYTE, 1);

case QImage::Format_RGB32:
/// @todo Is GL_BGR in any GL standard spec? Check for EXT_bgra.
return GLFormat(GL_BGR, GL_UNSIGNED_BYTE, 4);
return GLPixelFormat(GL_BGR, GL_UNSIGNED_BYTE, 4);

case QImage::Format_ARGB32:
/// @todo Is GL_BGRA in any GL standard spec? Check for EXT_bgra.
return GLFormat(GL_BGRA, GL_UNSIGNED_BYTE, 4);
return GLPixelFormat(GL_BGRA, GL_UNSIGNED_BYTE, 4);

default:
break;
}
return GLFormat(GL_RGBA, GL_UNSIGNED_BYTE, 4);
return GLPixelFormat(GL_RGBA, GL_UNSIGNED_BYTE, 4);
}

Image Image::solidColor(Color const &color, Size const &size)
Expand Down

0 comments on commit af04668

Please sign in to comment.