|
|
1.1 ! root 1: // ! 2: // nono ! 3: // Copyright (C) 2021 nono project ! 4: // Licensed under nono-license.txt ! 5: // ! 6: ! 7: // ! 8: // ビットマップ ! 9: // ! 10: ! 11: #pragma once ! 12: ! 13: #include "header.h" ! 14: #include "color.h" ! 15: #include "rect.h" ! 16: ! 17: // ビットマップ (基本クラス) ! 18: class BitmapBase ! 19: { ! 20: protected: ! 21: BitmapBase(); ! 22: BitmapBase(int width_, int height_, int depth_); ! 23: ! 24: void Create(int width_, int height_, int depth_); ! 25: public: ! 26: virtual ~BitmapBase(); ! 27: ! 28: int GetWidth() const { return width; } ! 29: int GetHeight() const { return height; } ! 30: int GetStride() const { return stride; } ! 31: ! 32: uint8 *GetBuf() { return buf; } ! 33: const uint8 *GetBuf() const { return buf; } ! 34: ! 35: protected: ! 36: int width {}; ! 37: int height {}; ! 38: int stride {}; ! 39: ! 40: uint8 *buf {}; ! 41: std::unique_ptr<uint8[]> owned_buf {}; ! 42: }; ! 43: ! 44: // 1bpp ビットマップ ! 45: class BitmapI1 : public BitmapBase ! 46: { ! 47: using inherited = BitmapBase; ! 48: public: ! 49: BitmapI1(); ! 50: BitmapI1(int width_, int height_); ! 51: BitmapI1(const void *buf_, int width_, int height_); ! 52: ~BitmapI1() override; ! 53: ! 54: void Create(int width_, int height_); ! 55: ! 56: // カラーコード cc で全体を塗りつぶす ! 57: void Fill(int cc); ! 58: }; ! 59: ! 60: // 8bpp ビットマップ ! 61: class BitmapI8 : public BitmapBase ! 62: { ! 63: using inherited = BitmapBase; ! 64: public: ! 65: BitmapI8(); ! 66: BitmapI8(int width_, int height_); ! 67: BitmapI8(const void *buf_, int width_, int height_); ! 68: ~BitmapI8() override; ! 69: ! 70: void Create(int width_, int height_); ! 71: ! 72: // カラーコード cc で全体を塗りつぶす ! 73: void Fill(int cc); ! 74: ! 75: uint8 *GetRowPtr(int y) const { ! 76: assert(y < height); ! 77: return &buf[y * stride]; ! 78: } ! 79: uint8 *GetPtr(int x, int y) const { ! 80: assert(x < width); ! 81: assert(y < height); ! 82: return &buf[y * stride + x]; } ! 83: }; ! 84: ! 85: // 24bpp ビットマップ ! 86: class BitmapRGB : public BitmapBase ! 87: { ! 88: using inherited = BitmapBase; ! 89: public: ! 90: BitmapRGB(); ! 91: BitmapRGB(int width_, int height_); ! 92: BitmapRGB(const void *buf_, int width_, int height_); ! 93: ~BitmapRGB() override; ! 94: ! 95: void Create(int width_, int height_); ! 96: ! 97: // 色 c で全体を塗りつぶす ! 98: void Fill(Color c); ! 99: ! 100: void DrawLine(Color c, int x1, int y1, int x2, int y2); ! 101: void DrawLineH(Color c, int x1, int y1, int x2); ! 102: void DrawLineV(Color c, int x1, int y1, int y2); ! 103: ! 104: void FillRect(Color c, const Rect& rect); ! 105: void FillRect(Color c, int dx, int dy, int dw, int dh); ! 106: ! 107: void DrawRect(Color c, const Rect& rect); ! 108: void DrawRect(Color c, int dx, int dy, int dw, int dh); ! 109: ! 110: void DrawBitmap(int dx, int dy, const BitmapI1& src, const Color *palette); ! 111: void DrawBitmap(int dx, int dy, const BitmapI8& src, const Color *palette, ! 112: const Rect& sr); ! 113: void DrawBitmap(int dx, int dy, const BitmapRGB& src); ! 114: void DrawScaleUp(int dx, int dy, int scale, const BitmapI1& src, ! 115: const Color *palette); ! 116: ! 117: void StretchDraw(Rect dr, const BitmapRGB& src); ! 118: ! 119: uint8 *GetRowPtr(int y) const { ! 120: assert(y < height); ! 121: return &buf[y * stride]; ! 122: } ! 123: uint8 *GetPtr(int x, int y) const { ! 124: assert(x < width); ! 125: assert(y < height); ! 126: return &buf[y * stride + x * 3]; ! 127: } ! 128: ! 129: private: ! 130: Color Mean(const RectD& sr) const; ! 131: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.