Merge pull request #3720 from b4n/encodings-ui-improvements
[geany-mirror.git] / scintilla / src / XPM.h
blobf2298066c5edc143d247d1c56407f902882067e3
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::Internal {
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 ColourRGBA colourCodeTable[256];
22 char codeTransparent=' ';
23 ColourRGBA ColourFromCode(int ch) const noexcept;
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 void Init(const char *textForm);
29 void Init(const char *const *linesForm);
30 /// Decompose image into runs and use FillRectangle for each run
31 void Draw(Surface *surface, const PRectangle &rc);
32 int GetHeight() const noexcept { return height; }
33 int GetWidth() const noexcept { return width; }
34 ColourRGBA PixelAt(int x, int y) const noexcept;
35 private:
36 static std::vector<const char *>LinesFormFromTextForm(const char *textForm);
39 /**
40 * A translucent image stored as a sequence of RGBA bytes.
42 class RGBAImage {
43 int height;
44 int width;
45 float scale;
46 std::vector<unsigned char> pixelBytes;
47 public:
48 static constexpr size_t bytesPerPixel = 4;
49 RGBAImage(int width_, int height_, float scale_, const unsigned char *pixels_);
50 explicit RGBAImage(const XPM &xpm);
51 int GetHeight() const noexcept { return height; }
52 int GetWidth() const noexcept { return width; }
53 float GetScale() const noexcept { return scale; }
54 float GetScaledHeight() const noexcept;
55 float GetScaledWidth() const noexcept;
56 int CountBytes() const noexcept;
57 const unsigned char *Pixels() const noexcept;
58 void SetPixel(int x, int y, ColourRGBA colour) noexcept;
59 static void BGRAFromRGBA(unsigned char *pixelsBGRA, const unsigned char *pixelsRGBA, size_t count) noexcept;
62 /**
63 * A collection of RGBAImage pixmaps indexed by integer id.
65 class RGBAImageSet {
66 typedef std::map<int, std::unique_ptr<RGBAImage>> ImageMap;
67 ImageMap images;
68 mutable int height; ///< Memorize largest height of the set.
69 mutable int width; ///< Memorize largest width of the set.
70 public:
71 RGBAImageSet();
72 /// Remove all images.
73 void Clear() noexcept;
74 /// Add an image.
75 void AddImage(int ident, std::unique_ptr<RGBAImage> image);
76 /// Get image by id.
77 RGBAImage *Get(int ident);
78 /// Give the largest height of the set.
79 int GetHeight() const noexcept;
80 /// Give the largest width of the set.
81 int GetWidth() const noexcept;
86 #endif