MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / Image

Class Image

source/core/StarImage.hpp:27–144  ·  view source on GitHub ↗

Holds an image of PixelFormat in row major order, with no padding, with (0, 0) defined to be the *lower left* corner.

Source from the content-addressed store, hash-verified

25// Holds an image of PixelFormat in row major order, with no padding, with (0,
26// 0) defined to be the *lower left* corner.
27class Image {
28public:
29 static Image readPng(IODevicePtr device);
30 static bool isPng(IODevicePtr device);
31 // Returns the size and pixel format that would be constructed from the given
32 // png file, without actually loading it.
33 static tuple<Vec2U, PixelFormat> readPngMetadata(IODevicePtr device);
34
35 static Image filled(Vec2U size, Vec4B color, PixelFormat pf = PixelFormat::RGBA32);
36
37 // Creates a zero size image
38 Image(PixelFormat pf = PixelFormat::RGBA32);
39 Image(Vec2U size, PixelFormat pf = PixelFormat::RGBA32);
40 Image(unsigned width, unsigned height, PixelFormat pf = PixelFormat::RGBA32);
41 ~Image();
42
43 Image(Image const& image);
44 Image(Image&& image);
45
46 Image& operator=(Image const& image);
47 Image& operator=(Image&& image);
48
49 uint8_t bitsPerPixel() const;
50 uint8_t bytesPerPixel() const;
51
52 unsigned width() const;
53 unsigned height() const;
54 Vec2U size() const;
55 // width or height is 0
56 bool empty() const;
57
58 PixelFormat pixelFormat() const;
59
60 // If the image is empty, the data ptr will be null
61 uint8_t const* data() const;
62 uint8_t* data();
63
64 // Reallocate the image with the given width, height, and pixel format. The
65 // contents of the image are always zeroed after a call to reset.
66 void reset(Vec2U size, Maybe<PixelFormat> pf = {});
67 void reset(unsigned width, unsigned height, Maybe<PixelFormat> pf = {});
68
69 // Fill the image with a given color
70 void fill(Vec3B const& c);
71 void fill(Vec4B const& c);
72
73 // Fill a rectangle with a given color
74 void fillRect(Vec2U const& pos, Vec2U const& size, Vec3B const& c);
75 void fillRect(Vec2U const& pos, Vec2U const& size, Vec4B const& c);
76
77 // Color parameters / return values here are in whatever the internal format
78 // is. Fourth byte, if missing or not provided, is assumed to be 255. If
79 // the position is out of range, then throws an exception.
80 void set(Vec2U const& pos, Vec4B const& c);
81 void set(Vec2U const& pos, Vec3B const& c);
82 Vec4B get(Vec2U const& pos) const;
83
84 // Same as set / get, except color parameters / return values here are always

Callers 1

addTextureMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected