File: Image.h

package info (click to toggle)
minetestmapper 20241111-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 300 kB
  • sloc: cpp: 2,635; python: 143; sh: 68; ansic: 30; makefile: 9
file content (34 lines) | stat: -rw-r--r-- 833 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once

#include "types.h"
#include <string>
#include <gd.h>

struct Color {
	Color() : r(0), g(0), b(0), a(0) {};
	Color(u8 r, u8 g, u8 b) : r(r), g(g), b(b), a(255) {};
	Color(u8 r, u8 g, u8 b, u8 a) : r(r), g(g), b(b), a(a) {};

	u8 r, g, b, a;
};

class Image {
public:
	Image(int width, int height);
	~Image();

	Image(const Image&) = delete;
	Image& operator=(const Image&) = delete;

	void setPixel(int x, int y, const Color &c);
	Color getPixel(int x, int y);
	void drawLine(int x1, int y1, int x2, int y2, const Color &c);
	void drawText(int x, int y, const std::string &s, const Color &c);
	void drawFilledRect(int x, int y, int w, int h, const Color &c);
	void drawCircle(int x, int y, int diameter, const Color &c);
	void save(const std::string &filename);

private:
	int m_width, m_height;
	gdImagePtr m_image;
};