From 60b06ee98e21b3d75c1f791cc81d2094562a0894 Mon Sep 17 00:00:00 2001 From: Benlitz Date: Sun, 16 Jun 2013 16:42:13 +0000 Subject: [PATCH] added BytesPerPixel() method to PixelFormat structure --- src/lol/gpu/texture.h | 16 ++++++++++++++++ src/tileset.cpp | 15 +-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/lol/gpu/texture.h b/src/lol/gpu/texture.h index 6173ca6b..83e8106b 100644 --- a/src/lol/gpu/texture.h +++ b/src/lol/gpu/texture.h @@ -36,6 +36,22 @@ struct PixelFormat inline PixelFormat() : m_value(Unknown) {} inline PixelFormat(Value v) : m_value(v) {} inline operator Value() { return m_value; } + + inline uint8_t BytesPerPixel() + { + switch (m_value) + { + case Y_8: + return 1; + case RGB_8: + return 3; + case RGBA_8: + case ARGB_8: + case ABGR_8: + default: + return 4; + } + } }; class Texture diff --git a/src/tileset.cpp b/src/tileset.cpp index 3423ed04..f7535f65 100644 --- a/src/tileset.cpp +++ b/src/tileset.cpp @@ -139,21 +139,8 @@ void TileSet::TickDraw(float seconds) } else if (m_data->m_image) { - int planes; PixelFormat format = m_data->m_image->GetFormat(); - - switch (format) - { - case PixelFormat::RGB_8: - planes = 3; - break; - case PixelFormat::RGBA_8: - case PixelFormat::ARGB_8: - case PixelFormat::ABGR_8: - default: - planes = 4; - break; - } + int planes = format.BytesPerPixel(); int w = m_data->m_texture_size.x; int h = m_data->m_texture_size.y;