mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
Let's have an RGBA32 typedef for raw pixel data.
This commit is contained in:
parent
df799e6d7b
commit
305aa25aae
7 changed files with 27 additions and 23 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
|
typedef dword RGBA32;
|
||||||
|
|
||||||
class Color {
|
class Color {
|
||||||
public:
|
public:
|
||||||
enum NamedColor {
|
enum NamedColor {
|
||||||
|
@ -19,8 +21,8 @@ public:
|
||||||
Color(NamedColor);
|
Color(NamedColor);
|
||||||
Color(byte r, byte g, byte b);
|
Color(byte r, byte g, byte b);
|
||||||
|
|
||||||
dword value() const { return m_value; }
|
RGBA32 value() const { return m_value; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
dword m_value { 0 };
|
RGBA32 m_value { 0 };
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,10 +63,10 @@ void FrameBuffer::initializeSDL()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dword* FrameBuffer::scanline(int y)
|
RGBA32* FrameBuffer::scanline(int y)
|
||||||
{
|
{
|
||||||
#ifdef USE_SDL
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "AbstractScreen.h"
|
#include "AbstractScreen.h"
|
||||||
|
#include "Color.h"
|
||||||
|
|
||||||
#ifdef USE_SDL
|
#ifdef USE_SDL
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
@ -21,7 +22,7 @@ public:
|
||||||
|
|
||||||
static FrameBuffer& the();
|
static FrameBuffer& the();
|
||||||
|
|
||||||
dword* scanline(int y);
|
RGBA32* scanline(int y);
|
||||||
|
|
||||||
void blit(const Point&, GraphicsBitmap&);
|
void blit(const Point&, GraphicsBitmap&);
|
||||||
void flush();
|
void flush();
|
||||||
|
|
|
@ -6,7 +6,7 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::create(const Size& size)
|
||||||
return adopt(*new GraphicsBitmap(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));
|
return adopt(*new GraphicsBitmap(size, data));
|
||||||
}
|
}
|
||||||
|
@ -14,16 +14,16 @@ RetainPtr<GraphicsBitmap> GraphicsBitmap::create_wrapper(const Size& size, byte*
|
||||||
GraphicsBitmap::GraphicsBitmap(const Size& size)
|
GraphicsBitmap::GraphicsBitmap(const Size& size)
|
||||||
: m_size(size)
|
: m_size(size)
|
||||||
{
|
{
|
||||||
m_data = (byte*)kmalloc(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() * 4);
|
memset(m_data, 0, size.width() * size.height() * sizeof(RGBA32));
|
||||||
m_owned = true;
|
m_owned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsBitmap::GraphicsBitmap(const Size& size, byte* data)
|
GraphicsBitmap::GraphicsBitmap(const Size& size, RGBA32* data)
|
||||||
: m_size(size)
|
: m_size(size)
|
||||||
|
, m_data(data)
|
||||||
|
, m_owned(false)
|
||||||
{
|
{
|
||||||
m_data = data;
|
|
||||||
m_owned = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsBitmap::~GraphicsBitmap()
|
GraphicsBitmap::~GraphicsBitmap()
|
||||||
|
@ -33,9 +33,9 @@ GraphicsBitmap::~GraphicsBitmap()
|
||||||
m_data = nullptr;
|
m_data = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
dword* GraphicsBitmap::scanline(int y)
|
RGBA32* GraphicsBitmap::scanline(int y)
|
||||||
{
|
{
|
||||||
unsigned pitch = m_size.width() * 4;
|
unsigned pitch = m_size.width() * sizeof(RGBA32);
|
||||||
return (dword*)(((byte*)m_data) + (y * pitch));
|
return reinterpret_cast<RGBA32*>((((byte*)m_data) + (y * pitch)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Color.h"
|
||||||
#include "Size.h"
|
#include "Size.h"
|
||||||
#include <AK/Retainable.h>
|
#include <AK/Retainable.h>
|
||||||
#include <AK/RetainPtr.h>
|
#include <AK/RetainPtr.h>
|
||||||
|
@ -7,10 +8,10 @@
|
||||||
class GraphicsBitmap : public Retainable<GraphicsBitmap> {
|
class GraphicsBitmap : public Retainable<GraphicsBitmap> {
|
||||||
public:
|
public:
|
||||||
static RetainPtr<GraphicsBitmap> create(const Size&);
|
static RetainPtr<GraphicsBitmap> create(const Size&);
|
||||||
static RetainPtr<GraphicsBitmap> create_wrapper(const Size&, byte*);
|
static RetainPtr<GraphicsBitmap> create_wrapper(const Size&, RGBA32*);
|
||||||
~GraphicsBitmap();
|
~GraphicsBitmap();
|
||||||
|
|
||||||
dword* scanline(int y);
|
RGBA32* scanline(int y);
|
||||||
|
|
||||||
Size size() const { return m_size; }
|
Size size() const { return m_size; }
|
||||||
int width() const { return m_size.width(); }
|
int width() const { return m_size.width(); }
|
||||||
|
@ -18,9 +19,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit GraphicsBitmap(const Size&);
|
explicit GraphicsBitmap(const Size&);
|
||||||
GraphicsBitmap(const Size&, byte*);
|
GraphicsBitmap(const Size&, RGBA32*);
|
||||||
|
|
||||||
Size m_size;
|
Size m_size;
|
||||||
byte* m_data { nullptr };
|
RGBA32* m_data { nullptr };
|
||||||
bool m_owned { false };
|
bool m_owned { false };
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,7 +28,7 @@ void Painter::fillRect(const Rect& rect, Color color)
|
||||||
r.moveBy(m_translation);
|
r.moveBy(m_translation);
|
||||||
|
|
||||||
for (int y = max(r.top(), m_clipRect.top()); y < min(r.bottom(), m_clipRect.bottom()); ++y) {
|
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) {
|
for (int x = max(r.left(), m_clipRect.left()); x < min(r.right(), m_clipRect.right()); ++x) {
|
||||||
bits[x] = color.value();
|
bits[x] = color.value();
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ void Painter::drawRect(const Rect& rect, Color color)
|
||||||
r.moveBy(m_translation);
|
r.moveBy(m_translation);
|
||||||
|
|
||||||
for (int y = max(r.top(), m_clipRect.top()); y < min(r.bottom(), m_clipRect.bottom()); ++y) {
|
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)) {
|
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) {
|
for (int x = max(r.left(), m_clipRect.left()); x < min(r.right(), m_clipRect.right()); ++x) {
|
||||||
bits[x] = color.value();
|
bits[x] = color.value();
|
||||||
|
@ -61,7 +61,7 @@ void Painter::xorRect(const Rect& rect, Color color)
|
||||||
r.moveBy(m_translation);
|
r.moveBy(m_translation);
|
||||||
|
|
||||||
for (int y = max(r.top(), m_clipRect.top()); y < min(r.bottom(), m_clipRect.bottom()); ++y) {
|
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)) {
|
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) {
|
for (int x = max(r.left(), m_clipRect.left()); x < min(r.right(), m_clipRect.right()); ++x) {
|
||||||
bits[x] ^= color.value();
|
bits[x] ^= color.value();
|
||||||
|
@ -83,7 +83,7 @@ void Painter::drawBitmap(const Point& p, const CBitmap& bitmap, Color color)
|
||||||
int y = point.y() + row;
|
int y = point.y() + row;
|
||||||
if (y < m_clipRect.top() || y >= m_clipRect.bottom())
|
if (y < m_clipRect.top() || y >= m_clipRect.bottom())
|
||||||
break;
|
break;
|
||||||
dword* bits = m_target->scanline(y);
|
auto* bits = m_target->scanline(y);
|
||||||
for (unsigned j = 0; j < bitmap.width(); ++j) {
|
for (unsigned j = 0; j < bitmap.width(); ++j) {
|
||||||
int x = point.x() + j;
|
int x = point.x() + j;
|
||||||
if (x < m_clipRect.left() || x >= m_clipRect.right())
|
if (x < m_clipRect.left() || x >= m_clipRect.right())
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
RootWidget::RootWidget()
|
RootWidget::RootWidget()
|
||||||
{
|
{
|
||||||
setWindowRelativeRect(FrameBuffer::the().rect());
|
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()
|
RootWidget::~RootWidget()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue