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.
11 namespace Scintilla::Internal
{
14 * Hold a pixmap in XPM format.
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;
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 noexcept
{ return height
; }
38 int GetWidth() const noexcept
{ return width
; }
39 ColourRGBA
PixelAt(int x
, int y
) const noexcept
;
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 static constexpr size_t bytesPerPixel
= 4;
54 RGBAImage(int width_
, int height_
, float scale_
, const unsigned char *pixels_
);
55 explicit RGBAImage(const XPM
&xpm
);
56 RGBAImage(const RGBAImage
&) = default;
57 RGBAImage(RGBAImage
&&) noexcept
= default;
58 RGBAImage
&operator=(const RGBAImage
&) = default;
59 RGBAImage
&operator=(RGBAImage
&&) noexcept
= default;
61 int GetHeight() const noexcept
{ return height
; }
62 int GetWidth() const noexcept
{ return width
; }
63 float GetScale() const noexcept
{ return scale
; }
64 float GetScaledHeight() const noexcept
{ return height
/ scale
; }
65 float GetScaledWidth() const noexcept
{ return width
/ scale
; }
66 int CountBytes() const noexcept
;
67 const unsigned char *Pixels() const noexcept
;
68 void SetPixel(int x
, int y
, ColourRGBA colour
) noexcept
;
69 static void BGRAFromRGBA(unsigned char *pixelsBGRA
, const unsigned char *pixelsRGBA
, size_t count
) noexcept
;
73 * A collection of RGBAImage pixmaps indexed by integer id.
76 typedef std::map
<int, std::unique_ptr
<RGBAImage
>> ImageMap
;
78 mutable int height
; ///< Memorize largest height of the set.
79 mutable int width
; ///< Memorize largest width of the set.
82 // Deleted so RGBAImageSet objects can not be copied.
83 RGBAImageSet(const RGBAImageSet
&) = delete;
84 RGBAImageSet(RGBAImageSet
&&) = delete;
85 RGBAImageSet
&operator=(const RGBAImageSet
&) = delete;
86 RGBAImageSet
&operator=(RGBAImageSet
&&) = delete;
88 /// Remove all images.
89 void Clear() noexcept
;
91 void AddImage(int ident
, std::unique_ptr
<RGBAImage
> image
);
93 RGBAImage
*Get(int ident
);
94 /// Give the largest height of the set.
95 int GetHeight() const;
96 /// Give the largest width of the set.