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 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
;
36 static std::vector
<const char *>LinesFormFromTextForm(const char *textForm
);
40 * A translucent image stored as a sequence of RGBA bytes.
46 std::vector
<unsigned char> pixelBytes
;
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
;
63 * A collection of RGBAImage pixmaps indexed by integer id.
66 typedef std::map
<int, std::unique_ptr
<RGBAImage
>> ImageMap
;
68 mutable int height
; ///< Memorize largest height of the set.
69 mutable int width
; ///< Memorize largest width of the set.
72 /// Remove all images.
73 void Clear() noexcept
;
75 void AddImage(int ident
, std::unique_ptr
<RGBAImage
> image
);
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
;