Update Scintilla to version 3.10.4
[geany-mirror.git] / scintilla / src / XPM.h
blobb7b895cdd5734c02946cae3057e743c49240f3d2
1 // Scintilla source code edit control
2 /** @file XPM.h
3 ** Define a classes to hold image data in the X Pixmap (XPM) and RGBA formats.
4 **/
5 // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 #ifndef XPM_H
9 #define XPM_H
11 namespace Scintilla {
13 /**
14 * Hold a pixmap in XPM format.
16 class XPM {
17 int height=1;
18 int width=1;
19 int nColours=1;
20 std::vector<unsigned char> pixels;
21 ColourDesired colourCodeTable[256];
22 char codeTransparent=' ';
23 ColourDesired ColourFromCode(int ch) const;
24 void FillRun(Surface *surface, int code, int startX, int y, int x) const;
25 public:
26 explicit XPM(const char *textForm);
27 explicit XPM(const char *const *linesForm);
28 XPM(const XPM &) = default;
29 XPM(XPM &&) noexcept = default;
30 XPM &operator=(const XPM &) = default;
31 XPM &operator=(XPM &&) noexcept = default;
32 ~XPM();
33 void Init(const char *textForm);
34 void Init(const char *const *linesForm);
35 /// Decompose image into runs and use FillRectangle for each run
36 void Draw(Surface *surface, const PRectangle &rc);
37 int GetHeight() const { return height; }
38 int GetWidth() const { return width; }
39 void PixelAt(int x, int y, ColourDesired &colour, bool &transparent) const;
40 private:
41 static std::vector<const char *>LinesFormFromTextForm(const char *textForm);
44 /**
45 * A translucent image stored as a sequence of RGBA bytes.
47 class RGBAImage {
48 int height;
49 int width;
50 float scale;
51 std::vector<unsigned char> pixelBytes;
52 public:
53 RGBAImage(int width_, int height_, float scale_, const unsigned char *pixels_);
54 explicit RGBAImage(const XPM &xpm);
55 RGBAImage(const RGBAImage &) = default;
56 RGBAImage(RGBAImage &&) noexcept = default;
57 RGBAImage &operator=(const RGBAImage &) = default;
58 RGBAImage &operator=(RGBAImage &&) noexcept = default;
59 virtual ~RGBAImage();
60 int GetHeight() const { return height; }
61 int GetWidth() const { return width; }
62 float GetScale() const { return scale; }
63 float GetScaledHeight() const { return height / scale; }
64 float GetScaledWidth() const { return width / scale; }
65 int CountBytes() const;
66 const unsigned char *Pixels() const;
67 void SetPixel(int x, int y, ColourDesired colour, int alpha);
70 /**
71 * A collection of RGBAImage pixmaps indexed by integer id.
73 class RGBAImageSet {
74 typedef std::map<int, std::unique_ptr<RGBAImage>> ImageMap;
75 ImageMap images;
76 mutable int height; ///< Memorize largest height of the set.
77 mutable int width; ///< Memorize largest width of the set.
78 public:
79 RGBAImageSet();
80 // Deleted so RGBAImageSet objects can not be copied.
81 RGBAImageSet(const RGBAImageSet &) = delete;
82 RGBAImageSet(RGBAImageSet &&) = delete;
83 RGBAImageSet &operator=(const RGBAImageSet &) = delete;
84 RGBAImageSet &operator=(RGBAImageSet &&) = delete;
85 ~RGBAImageSet();
86 /// Remove all images.
87 void Clear();
88 /// Add an image.
89 void Add(int ident, RGBAImage *image);
90 /// Get image by id.
91 RGBAImage *Get(int ident);
92 /// Give the largest height of the set.
93 int GetHeight() const;
94 /// Give the largest width of the set.
95 int GetWidth() const;
100 #endif