Annotation of nono/lib/bitmap.h, revision 1.1.1.3

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: 
1.1.1.3 ! root       24:        bool Create(int width_, int height_, int depth_);
1.1       root       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_);
1.1.1.2   root       71:        void Create(const void *buf_, int width_, int height_);
1.1       root       72: 
                     73:        // カラーコード cc で全体を塗りつぶす
                     74:        void Fill(int cc);
                     75: 
                     76:        uint8 *GetRowPtr(int y) const {
1.1.1.2   root       77:                assertmsg(y < height, "y=%d height=%d", y, height);
1.1       root       78:                return &buf[y * stride];
                     79:        }
                     80:        uint8 *GetPtr(int x, int y) const {
1.1.1.2   root       81:                assertmsg(x < width, "x=%d width=%d", x, width);
                     82:                assertmsg(y < height, "y=%d height=%d", y, height);
                     83:                return &buf[y * stride + x];
                     84:        }
                     85: };
1.1       root       86: 
                     87: // 24bpp ビットマップ
                     88: class BitmapRGB : public BitmapBase
                     89: {
                     90:        using inherited = BitmapBase;
                     91:  public:
                     92:        BitmapRGB();
                     93:        BitmapRGB(int width_, int height_);
                     94:        BitmapRGB(const void *buf_, int width_, int height_);
                     95:        ~BitmapRGB() override;
                     96: 
                     97:        void Create(int width_, int height_);
                     98: 
                     99:        // 色 c で全体を塗りつぶす
                    100:        void Fill(Color c);
                    101: 
                    102:        void DrawLine(Color c, int x1, int y1, int x2, int y2);
                    103:        void DrawLineH(Color c, int x1, int y1, int x2);
                    104:        void DrawLineV(Color c, int x1, int y1, int y2);
                    105: 
                    106:        void FillRect(Color c, const Rect& rect);
                    107:        void FillRect(Color c, int dx, int dy, int dw, int dh);
                    108: 
                    109:        void DrawRect(Color c, const Rect& rect);
                    110:        void DrawRect(Color c, int dx, int dy, int dw, int dh);
                    111: 
                    112:        void DrawBitmap(int dx, int dy, const BitmapI1& src, const Color *palette);
1.1.1.2   root      113:        void DrawBitmap(int dx, int dy, const BitmapI8& src, const Color *palette);
1.1       root      114:        void DrawBitmap(int dx, int dy, const BitmapI8& src, const Color *palette,
                    115:                const Rect& sr);
                    116:        void DrawBitmap(int dx, int dy, const BitmapRGB& src);
                    117:        void DrawScaleUp(int dx, int dy, int scale, const BitmapI1& src,
                    118:                const Color *palette);
1.1.1.2   root      119:        void DrawScale(const Rect& dr, const BitmapI8& src, const Color *palette,
                    120:                int sxN, int sxD, int sxS, int syN, int syD, int syS);
1.1       root      121: 
                    122:        void StretchDraw(Rect dr, const BitmapRGB& src);
                    123: 
                    124:        uint8 *GetRowPtr(int y) const {
1.1.1.2   root      125:                assertmsg(y < height, "y=%d height=%d", y, height);
1.1       root      126:                return &buf[y * stride];
                    127:        }
                    128:        uint8 *GetPtr(int x, int y) const {
1.1.1.2   root      129:                assertmsg(x < width, "x=%d width=%d", x, width);
                    130:                assertmsg(y < height, "y=%d height=%d", y, height);
1.1       root      131:                return &buf[y * stride + x * 3];
                    132:        }
                    133: 
                    134:  private:
                    135:        Color Mean(const RectD& sr) const;
                    136: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.