#ifndef __ALE_SCREEN_HPP__
#define __ALE_SCREEN_HPP__
#include <cassert>
#include <cstddef>
#include <cstring>
#include <memory>
#include <vector>
namespace ale {
using pixel_t = unsigned char;
class ALEScreen {
public:
ALEScreen(int h, int w);
ALEScreen(const ALEScreen& rhs);
ALEScreen& operator=(const ALEScreen& rhs);
pixel_t get(int r, int c) const;
pixel_t* pixel(int r, int c);
pixel_t* getRow(int r) const;
pixel_t* getArray() const { return const_cast<pixel_t*>(&m_pixels[0]); }
size_t height() const { return m_rows; }
size_t width() const { return m_columns; }
size_t arraySize() const { return m_rows * m_columns * sizeof(pixel_t); }
bool equals(const ALEScreen& rhs) const;
protected:
int m_rows;
int m_columns;
std::vector<pixel_t> m_pixels;
};
inline ALEScreen::ALEScreen(int h, int w)
: m_rows(h), m_columns(w),
m_pixels(m_rows * m_columns) {}
inline ALEScreen::ALEScreen(const ALEScreen& rhs)
: m_rows(rhs.m_rows), m_columns(rhs.m_columns), m_pixels(rhs.m_pixels) {}
inline ALEScreen& ALEScreen::operator=(const ALEScreen& rhs) {
m_rows = rhs.m_rows;
m_columns = rhs.m_columns;
m_pixels = rhs.m_pixels;
return *this;
}
inline bool ALEScreen::equals(const ALEScreen& rhs) const {
return (m_rows == rhs.m_rows && m_columns == rhs.m_columns &&
(memcmp(&m_pixels[0], &rhs.m_pixels[0], arraySize()) == 0));
}
inline pixel_t ALEScreen::get(int r, int c) const {
assert(r >= 0 && r < m_rows && c >= 0 && c < m_columns);
return m_pixels[r * m_columns + c];
}
inline pixel_t* ALEScreen::pixel(int r, int c) {
assert(r >= 0 && r < m_rows && c >= 0 && c < m_columns);
return &m_pixels[r * m_columns + c];
}
inline pixel_t* ALEScreen::getRow(int r) const {
assert(r >= 0 && r < m_rows);
return const_cast<pixel_t*>(&m_pixels[r * m_columns]);
}
}
#endif