summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-10 05:36:32 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-10 05:36:32 +0100
commit305aa25aaea63a1516094992d48f800a58a7715b (patch)
treee1dc8d952587d4d13bec65f3d935e87cc3fb247e
parentdf799e6d7b917aea1f84a89a8ea72bc31879d5fb (diff)
downloadserenity-305aa25aaea63a1516094992d48f800a58a7715b.zip
Let's have an RGBA32 typedef for raw pixel data.
-rw-r--r--Widgets/Color.h6
-rw-r--r--Widgets/FrameBuffer.cpp4
-rw-r--r--Widgets/FrameBuffer.h3
-rw-r--r--Widgets/GraphicsBitmap.cpp18
-rw-r--r--Widgets/GraphicsBitmap.h9
-rw-r--r--Widgets/Painter.cpp8
-rw-r--r--Widgets/RootWidget.cpp2
7 files changed, 27 insertions, 23 deletions
diff --git a/Widgets/Color.h b/Widgets/Color.h
index 28abafc2e8..9e2e5ca389 100644
--- a/Widgets/Color.h
+++ b/Widgets/Color.h
@@ -2,6 +2,8 @@
#include <AK/Types.h>
+typedef dword RGBA32;
+
class Color {
public:
enum NamedColor {
@@ -19,8 +21,8 @@ public:
Color(NamedColor);
Color(byte r, byte g, byte b);
- dword value() const { return m_value; }
+ RGBA32 value() const { return m_value; }
private:
- dword m_value { 0 };
+ RGBA32 m_value { 0 };
};
diff --git a/Widgets/FrameBuffer.cpp b/Widgets/FrameBuffer.cpp
index 2cfae7ac19..4454dc972e 100644
--- a/Widgets/FrameBuffer.cpp
+++ b/Widgets/FrameBuffer.cpp
@@ -63,10 +63,10 @@ void FrameBuffer::initializeSDL()
}
#endif
-dword* FrameBuffer::scanline(int y)
+RGBA32* FrameBuffer::scanline(int y)
{
#ifdef USE_SDL
- return (dword*)(((byte*)m_surface->pixels) + (y * m_surface->pitch));
+ return reinterpret_cast<RGBA32*>(((byte*)m_surface->pixels) + (y * m_surface->pitch));
#endif
}
diff --git a/Widgets/FrameBuffer.h b/Widgets/FrameBuffer.h
index 7fd85346a8..03da7eab91 100644
--- a/Widgets/FrameBuffer.h
+++ b/Widgets/FrameBuffer.h
@@ -1,6 +1,7 @@
#pragma once
#include "AbstractScreen.h"
+#include "Color.h"
#ifdef USE_SDL
#include <SDL.h>
@@ -21,7 +22,7 @@ public:
static FrameBuffer& the();
- dword* scanline(int y);
+ RGBA32* scanline(int y);
void blit(const Point&, GraphicsBitmap&);
void flush();
diff --git a/Widgets/GraphicsBitmap.cpp b/Widgets/GraphicsBitmap.cpp
index 83fd7543e9..abf8fe941f 100644
--- a/Widgets/GraphicsBitmap.cpp
+++ b/Widgets/GraphicsBitmap.cpp
@@ -6,7 +6,7 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::create(const Size& size)
return adopt(*new GraphicsBitmap(size));
}
-RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, byte* data)
+RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, RGBA32* data)
{
return adopt(*new GraphicsBitmap(size, data));
}
@@ -14,16 +14,16 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, byte*
GraphicsBitmap::GraphicsBitmap(const Size& size)
: m_size(size)
{
- m_data = (byte*)kmalloc(size.width() * size.height() * 4);
- memset(m_data, 0, size.width() * size.height() * 4);
+ m_data = static_cast<RGBA32*>(kmalloc(size.width() * size.height() * sizeof(RGBA32)));
+ memset(m_data, 0, size.width() * size.height() * sizeof(RGBA32));
m_owned = true;
}
-GraphicsBitmap::GraphicsBitmap(const Size& size, byte* data)
+GraphicsBitmap::GraphicsBitmap(const Size& size, RGBA32* data)
: m_size(size)
+ , m_data(data)
+ , m_owned(false)
{
- m_data = data;
- m_owned = false;
}
GraphicsBitmap::~GraphicsBitmap()
@@ -33,9 +33,9 @@ GraphicsBitmap::~GraphicsBitmap()
m_data = nullptr;
}
-dword* GraphicsBitmap::scanline(int y)
+RGBA32* GraphicsBitmap::scanline(int y)
{
- unsigned pitch = m_size.width() * 4;
- return (dword*)(((byte*)m_data) + (y * pitch));
+ unsigned pitch = m_size.width() * sizeof(RGBA32);
+ return reinterpret_cast<RGBA32*>((((byte*)m_data) + (y * pitch)));
}
diff --git a/Widgets/GraphicsBitmap.h b/Widgets/GraphicsBitmap.h
index bf09c65623..4eb8aded17 100644
--- a/Widgets/GraphicsBitmap.h
+++ b/Widgets/GraphicsBitmap.h
@@ -1,5 +1,6 @@
#pragma once
+#include "Color.h"
#include "Size.h"
#include <AK/Retainable.h>
#include <AK/RetainPtr.h>
@@ -7,10 +8,10 @@
class GraphicsBitmap : public Retainable<GraphicsBitmap> {
public:
static RetainPtr<GraphicsBitmap> create(const Size&);
- static RetainPtr<GraphicsBitmap> create_wrapper(const Size&, byte*);
+ static RetainPtr<GraphicsBitmap> create_wrapper(const Size&, RGBA32*);
~GraphicsBitmap();
- dword* scanline(int y);
+ RGBA32* scanline(int y);
Size size() const { return m_size; }
int width() const { return m_size.width(); }
@@ -18,9 +19,9 @@ public:
private:
explicit GraphicsBitmap(const Size&);
- GraphicsBitmap(const Size&, byte*);
+ GraphicsBitmap(const Size&, RGBA32*);
Size m_size;
- byte* m_data { nullptr };
+ RGBA32* m_data { nullptr };
bool m_owned { false };
};
diff --git a/Widgets/Painter.cpp b/Widgets/Painter.cpp
index e202165b4e..6a26703ffe 100644
--- a/Widgets/Painter.cpp
+++ b/Widgets/Painter.cpp
@@ -28,7 +28,7 @@ void Painter::fillRect(const Rect& rect, Color color)
r.moveBy(m_translation);
for (int y = max(r.top(), m_clipRect.top()); y < min(r.bottom(), m_clipRect.bottom()); ++y) {
- dword* bits = m_target->scanline(y);
+ auto* bits = m_target->scanline(y);
for (int x = max(r.left(), m_clipRect.left()); x < min(r.right(), m_clipRect.right()); ++x) {
bits[x] = color.value();
}
@@ -41,7 +41,7 @@ void Painter::drawRect(const Rect& rect, Color color)
r.moveBy(m_translation);
for (int y = max(r.top(), m_clipRect.top()); y < min(r.bottom(), m_clipRect.bottom()); ++y) {
- dword* bits = m_target->scanline(y);
+ auto* bits = m_target->scanline(y);
if (y == r.top() || y == (r.bottom() - 1)) {
for (int x = max(r.left(), m_clipRect.left()); x < min(r.right(), m_clipRect.right()); ++x) {
bits[x] = color.value();
@@ -61,7 +61,7 @@ void Painter::xorRect(const Rect& rect, Color color)
r.moveBy(m_translation);
for (int y = max(r.top(), m_clipRect.top()); y < min(r.bottom(), m_clipRect.bottom()); ++y) {
- dword* bits = m_target->scanline(y);
+ auto* bits = m_target->scanline(y);
if (y == r.top() || y == (r.bottom() - 1)) {
for (int x = max(r.left(), m_clipRect.left()); x < min(r.right(), m_clipRect.right()); ++x) {
bits[x] ^= color.value();
@@ -83,7 +83,7 @@ void Painter::drawBitmap(const Point& p, const CBitmap& bitmap, Color color)
int y = point.y() + row;
if (y < m_clipRect.top() || y >= m_clipRect.bottom())
break;
- dword* bits = m_target->scanline(y);
+ auto* bits = m_target->scanline(y);
for (unsigned j = 0; j < bitmap.width(); ++j) {
int x = point.x() + j;
if (x < m_clipRect.left() || x >= m_clipRect.right())
diff --git a/Widgets/RootWidget.cpp b/Widgets/RootWidget.cpp
index df0d4b34f8..644a051fb3 100644
--- a/Widgets/RootWidget.cpp
+++ b/Widgets/RootWidget.cpp
@@ -9,7 +9,7 @@
RootWidget::RootWidget()
{
setWindowRelativeRect(FrameBuffer::the().rect());
- m_backing = GraphicsBitmap::create_wrapper(size(), (byte*)FrameBuffer::the().scanline(0));
+ m_backing = GraphicsBitmap::create_wrapper(size(), FrameBuffer::the().scanline(0));
}
RootWidget::~RootWidget()