1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 2017-2019, The LegacyClonk Team and contributors
5 *
6 * Distributed under the terms of the ISC license; see accompanying file
7 * "COPYING" for details.
8 *
9 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10 * See accompanying file "TRADEMARK" for details.
11 *
12 * To redistribute this file separately, substitute the full license texts
13 * for the above references.
14 */
15
16#pragma once
17
18#include <cstdint>
19#include <memory>
20
21// A B8G8R8 or B8G8R8A8 bitmap.
22class StdBitmap
23{
24public:
25 // Creates a B8G8R8 bitmap if useAlpha is false or an B8G8R8A8 bitmap otherwise.
26 StdBitmap(std::uint32_t width, std::uint32_t height, bool useAlpha);
27
28 // Returns a pointer to the bitmap bytes.
29 const void *GetBytes() const;
30 void *GetBytes();
31
32 // Returns a pointer to the pixel at the specified position.
33 const void *GetPixelAddr(std::uint32_t x, std::uint32_t y) const;
34 void *GetPixelAddr(std::uint32_t x, std::uint32_t y);
35 // Returns a pointer to the pixel at the specified position, assuming the bitmap is in B8G8R8 format.
36 const void *GetPixelAddr24(std::uint32_t x, std::uint32_t y) const;
37 void *GetPixelAddr24(std::uint32_t x, std::uint32_t y);
38 // Returns a pointer to the pixel in the bitmap bytes at the specified position, assuming the bitmap is in B8G8R8A8 format.
39 const void *GetPixelAddr32(std::uint32_t x, std::uint32_t y) const;
40 void *GetPixelAddr32(std::uint32_t x, std::uint32_t y);
41
42 // Returns the color of the pixel at the specified position.
43 std::uint32_t GetPixel(std::uint32_t x, std::uint32_t y) const;
44 // Returns the color of the pixel at the specified position, assuming the bitmap is in B8G8R8 format.
45 std::uint32_t GetPixel24(std::uint32_t x, std::uint32_t y) const;
46 // Returns the color of the pixel at the specified position, assuming the bitmap is in B8G8R8A8 format.
47 std::uint32_t GetPixel32(std::uint32_t x, std::uint32_t y) const;
48
49 // Sets the color of the pixel at the specified position.
50 void SetPixel(std::uint32_t x, std::uint32_t y, std::uint32_t value);
51 // Sets the color of the pixel at the specified position, assuming the bitmap is in B8G8R8 format.
52 void SetPixel24(std::uint32_t x, std::uint32_t y, std::uint32_t value);
53 // Sets the color of the pixel at the specified position, assuming the bitmap is in B8G8R8A8 format.
54 void SetPixel32(std::uint32_t x, std::uint32_t y, std::uint32_t value);
55
56private:
57 std::uint32_t width, height;
58 bool useAlpha;
59 const std::unique_ptr<std::uint8_t[]> bytes;
60};
61