1 // Scintilla source code edit control
3 ** Define a classes to hold image data in the X Pixmap (XPM) and RGBA formats.
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.
14 * Hold a pixmap in XPM format.
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;
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;
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;
41 static std::vector
<const char *>LinesFormFromTextForm(const char *textForm
);
45 * A translucent image stored as a sequence of RGBA bytes.
51 std::vector
<unsigned char> pixelBytes
;
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;
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
);
71 * A collection of RGBAImage pixmaps indexed by integer id.
74 typedef std::map
<int, std::unique_ptr
<RGBAImage
>> ImageMap
;
76 mutable int height
; ///< Memorize largest height of the set.
77 mutable int width
; ///< Memorize largest width of the set.
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;
86 /// Remove all images.
89 void Add(int ident
, RGBAImage
*image
);
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.