|
|
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:
1.1.1.4 ! root 21: BitmapBase(int depth_, int width_, int height_, const void *buf_);
1.1 root 22:
1.1.1.4 ! root 23: // サイズを指定してキャンバスを作成。
! 24: // buf_ は NULL ならこっちでメモリを確保。
! 25: void Create(int width_, int height_, const void *buf_);
1.1 root 26: public:
27: virtual ~BitmapBase();
28:
1.1.1.4 ! root 29: // サイズを指定してキャンバスを作成。
! 30: void Create(int width_, int height_) {
! 31: Create(width_, height_, NULL);
! 32: }
! 33:
1.1 root 34: int GetWidth() const { return width; }
35: int GetHeight() const { return height; }
36: int GetStride() const { return stride; }
37:
38: uint8 *GetBuf() { return buf; }
39: const uint8 *GetBuf() const { return buf; }
40:
1.1.1.4 ! root 41: // y 行目先頭のアドレスを返す
! 42: uint8 *GetRowPtr(int y) const {
! 43: assertmsg(y < height, "y=%d height=%d", y, height);
! 44: return &buf[y * stride];
! 45: }
! 46:
! 47: // (x, y) のアドレスを返す
! 48: virtual uint8 *GetPtr(int x, int y) const {
! 49: assertmsg(x < width, "x=%d width=%d", x, width);
! 50: assertmsg(y < height, "y=%d height=%d", y, height);
! 51: return &buf[y * stride + x * depth / 8];
! 52: }
! 53:
! 54: // 全域をコピーしてくる。
! 55: void CopyFrom(const BitmapBase *src);
! 56:
1.1 root 57: protected:
58: int width {};
59: int height {};
60: int stride {};
1.1.1.4 ! root 61: int depth {};
1.1 root 62:
63: uint8 *buf {};
64: std::unique_ptr<uint8[]> owned_buf {};
65: };
66:
67: // 1bpp ビットマップ
68: class BitmapI1 : public BitmapBase
69: {
70: using inherited = BitmapBase;
71: public:
72: BitmapI1();
73: BitmapI1(int width_, int height_);
74: BitmapI1(const void *buf_, int width_, int height_);
75: ~BitmapI1() override;
76:
1.1.1.4 ! root 77: uint8 *GetPtr(int x, int y) const override;
1.1 root 78: };
79:
80: // 8bpp ビットマップ
81: class BitmapI8 : public BitmapBase
82: {
83: using inherited = BitmapBase;
84: public:
85: BitmapI8();
86: BitmapI8(int width_, int height_);
87: BitmapI8(const void *buf_, int width_, int height_);
88: ~BitmapI8() override;
89:
90: // カラーコード cc で全体を塗りつぶす
91: void Fill(int cc);
1.1.1.2 root 92: };
1.1 root 93:
94: // 24bpp ビットマップ
95: class BitmapRGB : public BitmapBase
96: {
97: using inherited = BitmapBase;
98: public:
99: BitmapRGB();
100: BitmapRGB(int width_, int height_);
101: BitmapRGB(const void *buf_, int width_, int height_);
102: ~BitmapRGB() override;
103:
104: // 色 c で全体を塗りつぶす
1.1.1.4 ! root 105: void Fill(Color c) {
! 106: FillRect(c, Rect(0, 0, width, height));
! 107: }
! 108: void FillRect(Color c, int dx, int dy, int dw, int dh) {
! 109: FillRect(c, Rect(dx, dy, dw, dh));
! 110: }
! 111: void FillRect(Color c, const Rect& rect);
1.1 root 112:
113: void DrawLine(Color c, int x1, int y1, int x2, int y2);
114: void DrawLineH(Color c, int x1, int y1, int x2);
115: void DrawLineV(Color c, int x1, int y1, int y2);
116:
117: void DrawRect(Color c, const Rect& rect);
118: void DrawRect(Color c, int dx, int dy, int dw, int dh);
119:
120: void DrawBitmap(int dx, int dy, const BitmapI1& src, const Color *palette);
1.1.1.2 root 121: void DrawBitmap(int dx, int dy, const BitmapI8& src, const Color *palette);
1.1 root 122: void DrawBitmap(int dx, int dy, const BitmapI8& src, const Color *palette,
123: const Rect& sr);
124: void DrawBitmap(int dx, int dy, const BitmapRGB& src);
125: void DrawScaleUp(int dx, int dy, int scale, const BitmapI1& src,
126: const Color *palette);
1.1.1.2 root 127: void DrawScale(const Rect& dr, const BitmapI8& src, const Color *palette,
128: int sxN, int sxD, int sxS, int syN, int syD, int syS);
1.1 root 129:
130: void StretchDraw(Rect dr, const BitmapRGB& src);
131:
132: private:
133: Color Mean(const RectD& sr) const;
134: };
1.1.1.4 ! root 135:
! 136: // 32bpp (RGBX) ビットマップ
! 137: class BitmapRGBX : public BitmapBase
! 138: {
! 139: using inherited = BitmapBase;
! 140: public:
! 141: BitmapRGBX();
! 142: BitmapRGBX(int width_, int height_);
! 143: BitmapRGBX(const void *buf_, int width_, int height_);
! 144: ~BitmapRGBX() override;
! 145: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.