 |
Gorgon Game Engine
|
Go to the documentation of this file.
6 #include "../Graphics/Animations.h"
7 #include "../Graphics/Texture.h"
8 #include "../Containers/Image.h"
9 #include "../Geometry/Margin.h"
64 throw std::runtime_error(
"Size of an image cannot be negative.");
95 auto ret =
new std::remove_reference<decltype(*
this)>::type(std::move(*
this));
164 return data!=
nullptr;
170 throw std::runtime_error(
"Bitmap data is not set");
217 throw std::runtime_error(
"Data is not set");
231 *
data = std::move(image);
256 throw std::runtime_error(
"Data is not set");
284 throw std::runtime_error(
"Data is not set");
288 return (*
data)(p, component);
296 throw std::runtime_error(
"Data is not set");
300 return (*
data)(p, component);
309 throw std::runtime_error(
"Data is not set");
313 return (*
data)(x, y, component);
321 throw std::runtime_error(
"Data is not set");
325 return (*
data)(x, y, component);
334 throw std::runtime_error(
"Data is not set");
338 return data->
Get(p, component);
347 throw std::runtime_error(
"Data is not set");
351 return data->
Get(p, def, component);
360 throw std::runtime_error(
"Bitmap data is not set");
379 throw std::runtime_error(
"Bitmap data is not set");
398 throw std::runtime_error(
"Bitmap data is not set");
415 throw std::runtime_error(
"Bitmap data is not set");
428 throw std::runtime_error(
"Bitmap data is not set");
445 throw std::runtime_error(
"Bitmap contains no data");
456 throw std::runtime_error(
"Bitmap data is not set");
467 throw std::runtime_error(
"Bitmap data is not set");
491 bool ImportPNG(
const std::string &filename);
499 bool ImportBMP(
const std::string &filename);
517 bool Import(
const std::string &filename);
521 bool Import(std::istream &file);
527 bool ExportPNG(
const std::string &filename);
539 bool ExportBMP(
const std::string &filename);
550 bool ExportJPG(
const std::string &filename,
int quality = 90);
555 bool ExportJPG(std::ostream &out,
int quality = 90);
593 return Trim(
true,
true,
true,
true);
599 return Trim(horizontal, vertical, horizontal, vertical);
611 return Trim(bounds, horizontal, vertical, horizontal, vertical);
618 return Trim(bounds,
true,
true,
true,
true);
638 bool ForPixels(std::function<
bool(
int,
int)> fn)
const {
641 if(!fn(x, y))
return false;
648 bool ForPixels(std::function<
bool(
int,
int,
int)> fn)
const {
652 if(!fn(x, y, c))
return false;
661 fn(this->
operator()(x, y, channel));
668 fn(this->
operator()(x, y, channel));
676 fn(this->
operator()(x, y, c));
684 fn(this->
operator()(x, y, c));
692 if(!fn(this->
operator()(x, y, channel)))
703 if(!fn(this->
operator()(x, y, channel)))
743 std::vector<TextureImage>
CreateAtlasImages(std::vector<Geometry::Bounds> boundaries)
const;
758 bool Progress(
unsigned &)
override {
return true; }
Graphics::TextureImage ReleaseTexture()
Releases the texture held by this image.
Definition: Bitmap.h:157
Geometry::Margin Trim(Geometry::Bounds bounds)
Trims the empty parts of the image, alpha channel = 0 is used to determine empty potions.
Definition: Bitmap.h:617
bool HasTexture() const
Checks if this image resource has a texture attached to it.
Definition: Bitmap.h:176
This class represents boundaries of 2D objects.
Definition: Bounds.h:27
void Assign(Byte *newdata)
Assigns the image to the copy of the given data.
Definition: Bitmap.h:215
@ Luminance
Definition: Bitmap.h:46
int GetChannelsPerPixel() const
Returns the bytes occupied by a single pixel of this image.
Definition: Bitmap.h:412
void swap(Event< Source_, Args_... > &l, Event< Source_, Args_... > &r)
Swaps two events.
Definition: Event.h:351
virtual void DeleteAnimation() const override
if used as animation, this object will not be deleted
Definition: Bitmap.h:146
This class represents a color information.
Definition: Color.h:91
Bitmap(const Bitmap &)=delete
Copy constructor is disabled.
void Blend(const RGBA &color)
Blends the given color into this one.
Definition: Color.h:248
Graphics::ColorMode GetMode() const
Returns the color mode of the image.
Definition: Image.h:1311
int GetAlphaIndex() const
Returns the index of alpha channel. Value of -1 denotes no alpha channel.
Definition: Bitmap.h:464
Geometry::Margin Trim()
Trims the empty parts of the image, alpha channel = 0 is used to determine empty portions.
Definition: Bitmap.h:592
bool HasAlpha() const
Returns if this image has alpha channel.
Definition: Image.h:1331
void Resize(const Geometry::Size &size, Graphics::ColorMode mode)
Resizes the image to the given size and color mode.
Definition: Image.h:71
basic_Image< Byte > Image
Definition: Image.h:1364
bool ForPixels(std::function< bool(int, int)> fn) const
Loops through all pixels of the image, giving coordinates to your function.
Definition: Bitmap.h:638
int GetAlphaIndex() const
Returns the index of alpha channel. Value of -1 denotes no alpha channel.
Definition: Image.h:1336
bool ImportBMP(const std::string &filename, bool dib=false)
Imports a given bitmap file. BMP RLE compression and colorspaces are not supported.
Definition: Image.h:591
Bitmap Duplicate() const
Duplicates this image.
Definition: Bitmap.h:117
ColorMode
Color modes for images.
Definition: Color.h:16
T_ Left
Left margin.
Definition: Margin.h:167
Geometry::Margin Trim(bool horizontal, bool vertical)
Trims the empty parts of the image, alpha channel = 0 is used to determine empty portions.
Definition: Bitmap.h:598
This class represents an image depends on a GL texture.
Definition: Texture.h:17
PNG Png
A ready to use PNG class.
Definition: PNG.cpp:304
bool ForPixels(std::function< bool(Byte)> fn, int channel) const
Loops through all pixels of the image, giving the specified channel value to your function.
Definition: Bitmap.h:700
Graphics::Bitmap ZoomMultiple(int factor) const
Zooms the image while preserving the colors.
Definition: Bitmap.cpp:746
bool HasAlpha() const
Returns if this image has alpha channel.
Definition: Bitmap.h:453
Bitmap Blur(float amount, int windowsize=-1) const
Creates the blurred version of this image as a new separate image.
ColorMode mode
Color mode of the texture, necessary to choose correct texture.
Definition: Texture.h:198
@ RGB
24bit red, green, blue color mode that has red component in the lowest byte order
@ Invalid
This is used to mark invalid color data.
Controllers are required to progress animations.
Definition: Animation.h:65
virtual const Geometry::Pointf * GetCoordinates() const override final
Returns the coordinates of the texture to be used. Declared final to allow inlining.
Definition: Texture.h:161
@ Minimum
Definition: Bitmap.h:49
RGBA GetRGBAAt(Geometry::Point p) const
Returns the alpha at the given location.
Definition: Bitmap.h:389
bool Progress(unsigned &) override
When used as animation, an image is always persistent and it never finishes.
Definition: Bitmap.h:758
T_ X
X coordinate.
Definition: Point.h:368
Bitmap & CreateAnimation(bool=false) const override
This function should create and animation and depending on the create parameter, it should create its...
Definition: Bitmap.h:143
Byte & operator()(const Geometry::Point &p, unsigned component=0)
Provides access to the given component in x and y coordinates.
Definition: Bitmap.h:281
@ Zero
If there is transparency, transparent, otherwise black borders.
Definition: Bitmap.h:36
void ForAllValues(std::function< void(Byte)> fn) const
Loops through all channels of all pixels of the image.
Definition: Bitmap.h:680
void ChangeMode(Graphics::ColorMode value)
Changes the color mode of the image.
Definition: Image.h:1317
T_ Height
Height of this size object.
Definition: Size.h:261
@ RGBA
32bit red, green, blue and alpha channel image. Red component is in the lowest byte order and
@ Average
Definition: Bitmap.h:47
bool ExportJPG(const std::string &filename, int quality=90)
Exports the data of the image resource to a JPG file.
Definition: Bitmap.cpp:210
virtual void Swap(Bitmap &other)
Swaps two images, mostly used for move constructor,.
Definition: Bitmap.h:85
int GetHeight() const
Returns the height of the bitmap.
Definition: Bitmap.h:480
Byte GetAlphaAt(int x, int y) const
Returns the alpha at the given location.
Definition: Image.h:1193
@ Maximum
Definition: Bitmap.h:48
long GetSize() const
Returns number of elements.
Definition: Collection.h:241
GL::Texture Release()
Releases the texture id that might be owned by this object without destroying it.
Definition: Texture.h:180
void Encode(const Containers::Image &input, std::ostream &output, bool replace_colormode=false)
Encodes a given input.
Definition: PNG.h:163
Bitmap()
Default constructor will create an empty bitmap.
Definition: Bitmap.h:53
Graphics::ColorMode GetMode() const override
Returns the color mode of the image.
Definition: Bitmap.h:422
Geometry::Margin Trim(Geometry::Bounds bounds, bool horizontal, bool vertical)
Trims the empty parts of the image, alpha channel = 0 is used to determine empty potions.
Definition: Bitmap.h:610
int GetWidth() const
Returns the width of the image.
Definition: Image.h:1296
@ None
Atlas will be tight packed.
Definition: Bitmap.h:33
void Assume(Containers::Image &image)
Assumes the contents of the given image as image data.
Definition: Bitmap.h:226
friend class BitmapWrapper
Definition: Bitmap.h:26
@ Wrap
Wraps to the other side.
Definition: Bitmap.h:42
void Grayscale(float ratio=1.0f, GrayscaleConversionMethod method=Luminance)
Transforms this image to a grayscale image.
Definition: Bitmap.cpp:291
Containers::Image * data
Container for the image data, could be null indicating its discarded.
Definition: Bitmap.h:767
Byte Get(const Geometry::Point &p, unsigned component=0) const
Provides access to the given component in x and y coordinates.
Definition: Image.h:1138
@ Grayscale
8bit gray scale color mode
Graphics::Bitmap Rotate90() const
Rotates image data without any losses.
Definition: Bitmap.cpp:706
Bitmap(Bitmap &&other)
Move constructor.
Definition: Bitmap.h:75
Bitmap(const Geometry::Size &size, Graphics::ColorMode mode=Graphics::ColorMode::RGBA)
Creates an uninitialized image of the given size and color mode.
Definition: Bitmap.h:59
Graphics::Bitmap Rotate270() const
Rotates image data without any losses.
Definition: Bitmap.cpp:733
T_ Left
Left-most boundary.
Definition: Bounds.h:399
T_ Top
Top margin.
Definition: Margin.h:170
Bitmap Slice(Geometry::Bounds bounds) const
Returns a new bitmap containing a slice of this bitmap.
Definition: Bitmap.h:746
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
void Clear()
Cleans the contents of the buffer by setting every byte it contains to 0.
Definition: Image.h:177
GrayscaleConversionMethod
Definition: Bitmap.h:45
This is the base class for all animations.
Definition: Animation.h:306
Byte operator()(int x, int y, unsigned component=0) const
Provides access to the given component in x and y coordinates.
Definition: Bitmap.h:318
virtual Geometry::Size GetImageSize() const override final
Returns the size of the texture in pixels. Declared final to allow inlining.
Definition: Texture.h:156
bool HasData() const
Checks if this image resource has a data attached to it.
Definition: Bitmap.h:163
This is an interface for solid texture based image.
Definition: Drawables.h:511
void ForAllValues(std::function< void(Byte &)> fn)
Loops through all channels of all pixels of the image.
Definition: Bitmap.h:672
int GetDuration() const override
Returns the duration of the animation if it is a known apriori.
Definition: Bitmap.h:760
unsigned long ReadUInt32(std::istream &stream)
Reads a 32-bit unsigned integer from the stream.
Definition: Stream.h:35
Rectangular drawable animation.
Definition: Animations.h:19
virtual GL::Texture GetID() const =0
Should return GL::Texture to be drawn. This could be 0 to denote no texture is to be used.
void Assign(Byte *newdata, const Geometry::Size &size, Graphics::ColorMode mode)
Assigns the image to the copy of the given data.
Definition: Bitmap.h:200
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
void StripRGB()
This function removes color channels, leaving only alpha channel.
Definition: Bitmap.cpp:250
AtlasMargin
Definition: Bitmap.h:31
Collection is a container for reference typed objects.
Definition: Collection.h:21
void Assume(Byte *newdata, const Geometry::Size &size, Graphics::ColorMode mode)
Assumes the ownership of the given data.
Definition: Bitmap.h:242
std::string ToLower(std::string str)
Converts the given string to lowercase.
Definition: String.h:416
bool ExportBMP(const std::string &filename, bool usev4=false, bool dib=false)
Exports the image as a bitmap.
Definition: Image.h:893
Containers::Image ReleaseData()
Releases the image data.
Definition: Bitmap.cpp:667
This object contains an bitmap image.
Definition: Bitmap.h:25
This is a solid texture based image class.
Definition: Texture.h:211
bool IsEmpty() const
Checks if this bitmap is empty: either 0x0 in size or completely transparent.
Definition: Bitmap.h:713
Geometry::Size size
Size of the texture.
Definition: Texture.h:195
T_ Cells() const
Returns the number of fully encompassed cells.
Definition: Size.h:235
void Resize(const Geometry::Size &size, Graphics::ColorMode mode=Graphics::ColorMode::RGBA)
Resizes the image to the given size and color mode.
Definition: Bitmap.h:264
basic_Image Duplicate() const
Duplicates this image, essentially performing the work of copy constructor.
Definition: Image.h:62
void SetRGBAAt(Geometry::Point p, RGBA color)
Sets the color at the given location to the specified RGBA value.
Definition: Bitmap.h:407
void Assign(const Containers::Image &image)
Assigns the given image as the data of this image resource.
Definition: Bitmap.h:183
basic_Bounds< int > Bounds
Definition: Bounds.h:722
GL::Texture id
GL texture id.
Definition: Texture.h:192
T_ Bottom
Bottom margin.
Definition: Margin.h:176
Geometry::Size GetSize() const override
Returns the size of this image resource.
Definition: Bitmap.h:436
@ Alpha
8bit alpha only color mode
void Assign(Byte *newdata, const Geometry::Size &size, Graphics::ColorMode mode)
Assigns the image to the copy of the given data.
Definition: Image.h:100
Byte Get(const Geometry::Point &p, Byte def, unsigned component=0) const
Provides access to the given component in x and y coordinates.
Definition: Bitmap.h:344
This class represents a 2D point.
Definition: Point.h:32
Bitmap & CreateAnimation(Gorgon::Animation::ControllerBase &) const override
This function should create a new animation with the given controller and if owner parameter is set t...
Definition: Bitmap.h:141
Bitmap & operator=(Bitmap &)=delete
Copy assignment is disabled.
virtual void SetController(Gorgon::Animation::ControllerBase &) override
Bitmap cannot be controlled.
Definition: Bitmap.h:149
std::vector< Geometry::Bounds > CreateLinearAtlas(Containers::Collection< const Bitmap > list, AtlasMargin margins=None)
Assumes all image heights are similar and all images have same color mode.
Definition: Bitmap.cpp:374
JPEG Jpg
Definition: JPEG.cpp:327
bool ExportPNG(const std::string &filename)
Exports the data of the image resource to a PNG file.
Definition: Bitmap.cpp:152
std::vector< TextureImage > CreateAtlasImages(std::vector< Geometry::Bounds > boundaries) const
Creates images from the given atlas image and map.
Definition: Bitmap.cpp:528
virtual GL::Texture GetID() const override final
Returns GL::Texture to be drawn. Declared final to allow inlining.
Definition: Texture.h:151
void SetRGBAAt(int x, int y, Graphics::RGBA color)
Sets the color at the given location to the specified RGBA value.
Definition: Image.h:1241
void Swap(Texture &other)
Swaps two textures.
Definition: Texture.h:53
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
This class provides rectangular animations.
Definition: Animations.h:48
T_ Right
Right-most boundary.
Definition: Bounds.h:405
T_ Right
Right margin.
Definition: Margin.h:173
Bitmap(Containers::Image &&imagedata)
Move constructor.
Definition: Bitmap.h:80
@ Graphics
Definition: Template.h:164
bool ForPixels(std::function< bool(Byte &)> fn, int channel)
Loops through all pixels of the image, giving the specified channel value to your function.
Definition: Bitmap.h:689
Bitmap(int width, int height, Graphics::ColorMode mode)
Definition: Bitmap.h:69
This interface represents a GL texture source.
Definition: Graphics.h:480
virtual ~Bitmap()
Destroys image data.
Definition: Bitmap.h:132
bool ImportJPEG(const std::string &filename)
Imports a JPEG file to become the new data of this image resource.
Definition: Bitmap.cpp:103
RGBA GetRGBAAt(int x, int y) const
Returns the alpha at the given location.
Definition: Bitmap.h:376
bool CopyTo(basic_Image &dest, Geometry::Point target={0, 0}) const
Copies data from one image to another.
Definition: Image.h:318
@ Repeat
Repeats the last pixel.
Definition: Bitmap.h:39
T_ Bottom
Bottom-most boundary.
Definition: Bounds.h:408
ColorMode GetMode() const override
Definition: Texture.h:165
Bitmap Shadow(float amount, int windowsize=-1) const
Creates a smooth drop shadow by using alpha channel of this image.
This class is a container for image data.
Definition: Image.h:19
virtual void Prepare()
This function prepares image for drawing.
Definition: Bitmap.cpp:14
T_ Y
Y coordinate.
Definition: Point.h:371
Byte & operator()(int x, int y, unsigned component=0)
Provides access to the given component in x and y coordinates.
Definition: Bitmap.h:306
void Decode(std::istream &input, Containers::Image &output)
Decodes the given PNG data.
Definition: PNG.h:186
T_ Width
Width of this size object.
Definition: Size.h:258
virtual auto MoveOutProvider() -> decltype(*this) override
This function moves this animation provider into a new provider.
Definition: Bitmap.h:94
basic_Size< T_ > GetSize() const
Returns the size of the bounds object.
Definition: Bounds.h:141
bool Import(const std::string &filename)
Imports an image file to become the new data of this image resource.
Definition: Bitmap.cpp:27
void ForAllPixels(std::function< void(int, int, int)> fn) const
Loops through all pixels and channels of the image, giving coordinates to your function.
Definition: Bitmap.h:629
bool ImportBMP(const std::string &filename)
Imports a BMP file to become the new data of this image resource.
Definition: Bitmap.cpp:116
void Set(const Containers::Image &image)
Sets the texture to the given id with the given size.
Definition: Texture.h:69
void Assume(Byte *newdata)
Assumes the ownership of the given data.
Definition: Bitmap.h:254
int GetWidth() const
Returns the width of the bitmap.
Definition: Bitmap.h:476
Geometry::Size getsize() const override
Should return the exact size of this object.
Definition: Bitmap.h:762
void Assume(Byte *newdata, const Geometry::Size &size, Graphics::ColorMode mode)
Assumes the ownership of the given data.
Definition: Image.h:139
void StripAlpha()
This function removes transparency information from the image.
Definition: Bitmap.cpp:268
void Resize(int w, int h, Graphics::ColorMode mode=Graphics::ColorMode::RGBA)
Resizes the image to the given size and color mode.
Definition: Bitmap.h:274
bool ExportBMP(const std::string &filename)
Exports the data of the image resource to a bitmap file.
Definition: Bitmap.cpp:192
This class defines Margin of an object or an area.
Definition: Margin.h:22
int GetHeight() const
Returns the height of the image.
Definition: Image.h:1301
void Decode(std::istream &input, Containers::Image &output)
Decodes given JPG data from the given input and creates the image.
Definition: JPEG.h:130
void Swap(basic_Image &other)
Swaps this image with another. This function is used to implement move semantics.
Definition: Image.h:200
Byte operator()(const Geometry::Point &p, unsigned component=0) const
Provides access to the given component in x and y coordinates.
Definition: Bitmap.h:293
void ForAllPixels(std::function< void(int, int)> fn) const
Loops through all pixels of the image, giving coordinates to your function.
Definition: Bitmap.h:622
virtual void Discard()
This function discards image data.
Definition: Bitmap.cpp:20
void Destroy()
Definition: Bitmap.h:125
#define ASSERT_DUMP(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:182
Byte GetAlphaAt(int x, int y) const
Returns the alpha at the given location.
Definition: Bitmap.h:357
void ForAllPixels(std::function< void(Byte &)> fn, int channel)
Loops through all pixels of the image, giving the specified channel value to your function.
Definition: Bitmap.h:658
void Encode(Containers::Image &input, std::ostream &output, int quality=90)
Encode given image to JPG compressed data.
Definition: JPEG.h:162
Geometry::Size size
Size of the texture.
Definition: Texture.h:195
Containers::Image & GetData() const
Returns the data attached to this bitmap. If no data is present, this function throws.
Definition: Bitmap.h:168
bool ForPixels(std::function< bool(int, int, int)> fn) const
Loops through all pixels of the image, giving coordinates to your function.
Definition: Bitmap.h:648
void Destroy()
Remove the texture from this object. If this object is the owner of the texture, then it is destroyed...
Definition: Texture.h:170
Byte Get(const Geometry::Point &p, unsigned component=0) const
Provides access to the given component in x and y coordinates.
Definition: Bitmap.h:331
void Clear()
Cleans the contents of the buffer by setting every byte it contains to 0.
Definition: Bitmap.h:730
void SetRGBAAt(int x, int y, RGBA color)
Sets the color at the given location to the specified RGBA value.
Definition: Bitmap.h:395
Graphics::RGBA GetRGBAAt(int x, int y) const
Returns the alpha at the given location.
Definition: Image.h:1207
Geometry::Size GetSize() const
Returns the size of the image.
Definition: Image.h:1291
T_ Top
Top-most boundary.
Definition: Bounds.h:402
Byte GetAlphaAt(Geometry::Point p) const
Returns the alpha at the given location.
Definition: Bitmap.h:369
Graphics::Bitmap Rotate180() const
Rotates image data without any losses.
Definition: Bitmap.cpp:719
void ForAllPixels(std::function< void(Byte)> fn, int channel) const
Loops through all pixels of the image, giving the specified channel value to your function.
Definition: Bitmap.h:665
unsigned GetChannelsPerPixel() const
Returns the number units occupied by a single pixel of this image.
Definition: Image.h:1326
bool ImportPNG(const std::string &filename)
Imports a PNG file to become the new data of this image resource.
Definition: Bitmap.cpp:90