2019-01-09 02:06:04 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-01-10 05:36:32 +01:00
|
|
|
#include "Color.h"
|
2019-01-24 23:40:12 +01:00
|
|
|
#include "Rect.h"
|
2019-01-09 02:06:04 +01:00
|
|
|
#include "Size.h"
|
|
|
|
|
#include <AK/Retainable.h>
|
|
|
|
|
#include <AK/RetainPtr.h>
|
2019-02-07 23:13:47 +01:00
|
|
|
#include <AK/AKString.h>
|
2019-01-14 20:00:42 +01:00
|
|
|
|
2019-01-09 02:06:04 +01:00
|
|
|
class GraphicsBitmap : public Retainable<GraphicsBitmap> {
|
|
|
|
|
public:
|
2019-02-19 01:42:53 +01:00
|
|
|
enum class Format { Invalid, RGB32, RGBA32 };
|
|
|
|
|
|
2019-02-25 12:43:52 +01:00
|
|
|
static Retained<GraphicsBitmap> create(Format, const Size&);
|
|
|
|
|
static Retained<GraphicsBitmap> create_wrapper(Format, const Size&, RGBA32*);
|
2019-02-19 01:42:53 +01:00
|
|
|
static RetainPtr<GraphicsBitmap> load_from_file(Format, const String& path, const Size&);
|
|
|
|
|
static RetainPtr<GraphicsBitmap> create_with_shared_buffer(Format, int shared_buffer_id, const Size&, RGBA32* buffer = nullptr);
|
2019-01-09 02:06:04 +01:00
|
|
|
~GraphicsBitmap();
|
|
|
|
|
|
2019-01-10 05:36:32 +01:00
|
|
|
RGBA32* scanline(int y);
|
2019-01-12 06:39:34 +01:00
|
|
|
const RGBA32* scanline(int y) const;
|
2019-01-09 02:06:04 +01:00
|
|
|
|
2019-01-24 23:40:12 +01:00
|
|
|
Rect rect() const { return { {}, m_size }; }
|
2019-01-09 02:06:04 +01:00
|
|
|
Size size() const { return m_size; }
|
|
|
|
|
int width() const { return m_size.width(); }
|
|
|
|
|
int height() const { return m_size.height(); }
|
2019-01-12 21:45:45 +01:00
|
|
|
size_t pitch() const { return m_pitch; }
|
2019-02-16 12:13:43 +01:00
|
|
|
int shared_buffer_id() const { return m_shared_buffer_id; }
|
|
|
|
|
|
2019-02-19 01:42:53 +01:00
|
|
|
bool has_alpha_channel() const { return m_format == Format::RGBA32; }
|
|
|
|
|
|
2019-01-09 02:06:04 +01:00
|
|
|
private:
|
2019-02-19 01:42:53 +01:00
|
|
|
GraphicsBitmap(Format, const Size&);
|
|
|
|
|
GraphicsBitmap(Format, const Size&, RGBA32*);
|
|
|
|
|
GraphicsBitmap(Format, int shared_buffer_id, const Size&, RGBA32*);
|
2019-01-09 02:06:04 +01:00
|
|
|
|
|
|
|
|
Size m_size;
|
2019-01-10 05:36:32 +01:00
|
|
|
RGBA32* m_data { nullptr };
|
2019-01-12 21:29:05 +01:00
|
|
|
size_t m_pitch { 0 };
|
2019-02-19 01:42:53 +01:00
|
|
|
Format m_format { Format::Invalid };
|
2019-02-07 23:13:47 +01:00
|
|
|
bool m_mmaped { false };
|
2019-02-16 12:13:43 +01:00
|
|
|
int m_shared_buffer_id { -1 };
|
2019-01-09 02:06:04 +01:00
|
|
|
};
|
2019-01-16 19:43:01 +01:00
|
|
|
|
|
|
|
|
inline RGBA32* GraphicsBitmap::scanline(int y)
|
|
|
|
|
{
|
|
|
|
|
return reinterpret_cast<RGBA32*>((((byte*)m_data) + (y * m_pitch)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline const RGBA32* GraphicsBitmap::scanline(int y) const
|
|
|
|
|
{
|
|
|
|
|
return reinterpret_cast<const RGBA32*>((((const byte*)m_data) + (y * m_pitch)));
|
|
|
|
|
}
|