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