1 #pragma once 2 3 #ifndef WIN32_BITMAP_H_ 4 #define WIN32_BITMAP_H_ 5 6 #include <cstddef> 7 #include <memory> 8 #include <stdexcept> 9 10 struct BitmapDataError : public std::runtime_error { 11 using std::runtime_error::runtime_error; 12 }; 13 14 class WindowsBitmap { 15 class impl; 16 17 struct read_tag {}; 18 struct write_tag {}; 19 public: 20 static const read_tag READ_TAG; 21 static const write_tag WRITE_TAG; 22 private: 23 std::unique_ptr<impl> m_impl; 24 get_impl()25 impl *get_impl() noexcept { return m_impl.get(); } get_impl()26 const impl *get_impl() const noexcept { return m_impl.get(); } 27 public: 28 WindowsBitmap(WindowsBitmap &&other) noexcept; 29 30 WindowsBitmap(const char *path, read_tag); 31 32 WindowsBitmap(const char *path, write_tag); 33 34 WindowsBitmap(const char *path, int width, int height, int bit_count); 35 36 ~WindowsBitmap(); 37 38 WindowsBitmap &operator=(WindowsBitmap &&other) noexcept; 39 40 ptrdiff_t stride() const noexcept; 41 42 int width() const noexcept; 43 44 int height() const noexcept; 45 46 int bit_count() const noexcept; 47 48 const unsigned char *read_ptr() const noexcept; 49 50 unsigned char *write_ptr() noexcept; 51 52 void flush(); 53 54 void close(); 55 }; 56 57 #endif // WIN32_BITMAP_H_ 58