Gorgon Game Engine
Bitmap.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdexcept>
4 #include <memory>
5 
6 #include "../Graphics/Animations.h"
7 #include "../Graphics/Texture.h"
8 #include "../Containers/Image.h"
9 #include "../Geometry/Margin.h"
10 
11 namespace Gorgon { namespace Graphics {
12 
13 
22  class Bitmap :
23  public virtual Graphics::RectangularAnimationProvider, public virtual Graphics::Image,
24  public virtual Graphics::RectangularAnimation, protected virtual Graphics::Texture, public virtual Graphics::TextureSource
25  {
26  friend class BitmapWrapper;
27  public:
28 
30 
31  enum AtlasMargin {
33  None,
34 
37 
40 
42  Wrap
43  };
44 
49  Minimum
50  };
51 
53  Bitmap() {
54 
55  }
56 
60  data(new Containers::Image{size, mode}) {
61 
62 #ifndef NDEBUG
63  if(size.Width<0 || size.Height<0) {
64  throw std::runtime_error("Size of an image cannot be negative.");
65  }
66 #endif
67  }
68 
69  Bitmap(int width, int height, Graphics::ColorMode mode) : Bitmap({width, height}, mode) { }
70 
72  Bitmap(const Bitmap &) = delete;
73 
75  Bitmap(Bitmap &&other) {
76  Swap(other);
77  }
78 
80  Bitmap(Containers::Image &&imagedata) : data(new Containers::Image) {
81  data->Swap(imagedata);
82  }
83 
85  virtual void Swap(Bitmap &other) {
86  using std::swap;
87 
88  swap(data, other.data);
89 
91  }
92 
93  //types are derived not to type the same code for every class
94  virtual auto MoveOutProvider() -> decltype(*this) override {
95  auto ret = new std::remove_reference<decltype(*this)>::type(std::move(*this));
96 
97  return *ret;
98  }
99 
101  Bitmap &operator=(Bitmap &) = delete;
102 
105  Discard();
107 
108  Swap(other);
109 
110  return *this;
111  }
112 
117  Bitmap Duplicate() const {
118  Bitmap img;
119  if(data)
120  img.Assign(*data);
121 
122  return img;
123  }
124 
125  void Destroy() {
127  delete data;
128  data=nullptr;
129  }
130 
132  virtual ~Bitmap() {
133  delete data;
134  }
135 
140 
141  Bitmap &CreateAnimation(Gorgon::Animation::ControllerBase &) const override { return const_cast<Bitmap &>(*this); }
142 
143  Bitmap &CreateAnimation(bool =false) const override { return const_cast<Bitmap &>(*this); }
144 
146  virtual void DeleteAnimation() const override { }
147 
150 
154 
158  auto sz = Graphics::Texture::size;
159  return {Graphics::Texture::Release(), GetMode(), sz};
160  }
161 
163  bool HasData() const {
164  return data!=nullptr;
165  }
166 
169  if(!data)
170  throw std::runtime_error("Bitmap data is not set");
171 
172  return *data;
173  }
174 
176  bool HasTexture() const {
177  return Graphics::Texture::id!=0;
178  }
179 
183  void Assign(const Containers::Image &image) {
184  if(!data) {
186  }
187 
188  *data = image.Duplicate();
189  }
190 
201  if(!data) {
203  }
204 
205  data->Assign(newdata, size, mode);
206  }
207 
215  void Assign(Byte *newdata) {
216  if(!data) {
217  throw std::runtime_error("Data is not set");
218  }
219 
220  data->Assign(newdata);
221  }
222 
226  void Assume(Containers::Image &image) {
227  if(!data) {
229  }
230 
231  *data = std::move(image);
232  }
233 
243  if(!data) {
245  }
246 
247  data->Assume(newdata, size, mode);
248  }
249 
254  void Assume(Byte *newdata) {
255  if(!data) {
256  throw std::runtime_error("Data is not set");
257  }
258 
259  data->Assume(newdata);
260  }
261 
265  if(!data) {
267  }
268 
269  data->Resize(size, mode);
270  }
271 
275  Resize({w, h}, mode);
276  }
277 
281  Byte &operator()(const Geometry::Point &p, unsigned component=0) {
282 #ifndef NDEBUG
283  if(!data) {
284  throw std::runtime_error("Data is not set");
285  }
286 #endif
287 
288  return (*data)(p, component);
289  }
290 
293  Byte operator()(const Geometry::Point &p, unsigned component=0) const {
294 #ifndef NDEBUG
295  if(!data) {
296  throw std::runtime_error("Data is not set");
297  }
298 #endif
299 
300  return (*data)(p, component);
301  }
302 
306  Byte &operator()(int x, int y, unsigned component=0) {
307 #ifndef NDEBUG
308  if(!data) {
309  throw std::runtime_error("Data is not set");
310  }
311 #endif
312 
313  return (*data)(x, y, component);
314  }
315 
318  Byte operator()(int x, int y, unsigned component=0) const {
319 #ifndef NDEBUG
320  if(!data) {
321  throw std::runtime_error("Data is not set");
322  }
323 #endif
324 
325  return (*data)(x, y, component);
326  }
327 
331  Byte Get(const Geometry::Point &p, unsigned component = 0) const {
332 #ifndef NDEBUG
333  if (!data) {
334  throw std::runtime_error("Data is not set");
335  }
336 #endif
337 
338  return data->Get(p, component);
339  }
340 
344  Byte Get(const Geometry::Point &p, Byte def, unsigned component = 0) const {
345 #ifndef NDEBUG
346  if (!data) {
347  throw std::runtime_error("Data is not set");
348  }
349 #endif
350 
351  return data->Get(p, def, component);
352  }
353 
357  Byte GetAlphaAt(int x, int y) const {
358 #ifndef NDEBUG
359  if(!data) {
360  throw std::runtime_error("Bitmap data is not set");
361  }
362 #endif
363  return data->GetAlphaAt(x, y);
364  }
365 
370  return GetAlphaAt(p.X, p.Y);
371  }
372 
376  RGBA GetRGBAAt(int x, int y) const {
377 #ifndef NDEBUG
378  if(!data) {
379  throw std::runtime_error("Bitmap data is not set");
380  }
381 #endif
382 
383  return data->GetRGBAAt(x, y);
384  }
385 
390  return GetRGBAAt(p.X, p.Y);
391  }
392 
395  void SetRGBAAt(int x, int y, RGBA color) {
396 #ifndef NDEBUG
397  if(!data) {
398  throw std::runtime_error("Bitmap data is not set");
399  }
400 #endif
401 
402  data->SetRGBAAt(x, y, color);
403  }
404 
407  void SetRGBAAt(Geometry::Point p, RGBA color) {
408  SetRGBAAt(p.X, p.Y, color);
409  }
410 
412  int GetChannelsPerPixel() const {
413 #ifndef NDEBUG
414  if(!data) {
415  throw std::runtime_error("Bitmap data is not set");
416  }
417 #endif
418  return data->GetChannelsPerPixel();
419  }
420 
422  Graphics::ColorMode GetMode() const override {
423  if(Graphics::Texture::id!=0) {
425  }
426 #ifndef NDEBUG
427  if(!data) {
428  throw std::runtime_error("Bitmap data is not set");
429  }
430 #endif
431  return data->GetMode();
432  }
433 
436  Geometry::Size GetSize() const override {
437  if(Graphics::Texture::id!=0) {
439  }
440  else if(data) {
441  return data->GetSize();
442  }
443  else {
444 #ifndef NDEBUG
445  throw std::runtime_error("Bitmap contains no data");
446 #endif
447 
448  return{0, 0};
449  }
450  }
451 
453  bool HasAlpha() const {
454 #ifndef NDEBUG
455  if(!data) {
456  throw std::runtime_error("Bitmap data is not set");
457  }
458 #endif
459 
460  return data->HasAlpha();
461  }
462 
464  int GetAlphaIndex() const {
465 #ifndef NDEBUG
466  if(!data) {
467  throw std::runtime_error("Bitmap data is not set");
468  }
469 #endif
470 
471  return data->GetAlphaIndex();
472  }
473 
476  int GetWidth() const { return GetSize().Width; }
477 
480  int GetHeight() const { return GetSize().Height; }
481 
483  virtual void Prepare();
484 
486  virtual void Discard();
487 
491  bool ImportPNG(const std::string &filename);
492 
495  bool ImportJPEG(const std::string &filename);
496 
499  bool ImportBMP(const std::string &filename);
500 
504  bool ImportPNG(std::istream &file);
505 
508  bool ImportJPEG(std::istream &file);
509 
512  bool ImportBMP(std::istream &file);
513 
517  bool Import(const std::string &filename);
518 
521  bool Import(std::istream &file);
522 
527  bool ExportPNG(const std::string &filename);
528 
533  bool ExportPNG(std::ostream &out);
534 
539  bool ExportBMP(const std::string &filename);
540 
545  bool ExportBMP(std::ostream &out);
546 
550  bool ExportJPG(const std::string &filename, int quality = 90);
551 
555  bool ExportJPG(std::ostream &out, int quality = 90);
556 
563  Bitmap Blur(float amount, int windowsize=-1) const;
564 
571  Bitmap Shadow(float amount, int windowsize=-1) const;
572 
578  void Grayscale(float ratio=1.0f, GrayscaleConversionMethod method = Luminance);
579 
581  void StripAlpha();
582 
584  void StripRGB();
585 
588  Geometry::Margin Trim(bool left, bool top, bool right, bool bottom);
589 
593  return Trim(true, true, true, true);
594  }
595 
598  Geometry::Margin Trim(bool horizontal, bool vertical) {
599  return Trim(horizontal, vertical, horizontal, vertical);
600  }
601 
605  Geometry::Margin Trim(Geometry::Bounds bounds, bool left, bool top, bool right, bool bottom);
606 
610  Geometry::Margin Trim(Geometry::Bounds bounds, bool horizontal, bool vertical) {
611  return Trim(bounds, horizontal, vertical, horizontal, vertical);
612  }
613 
618  return Trim(bounds, true, true, true, true);
619  }
620 
622  void ForAllPixels(std::function<void(int, int)> fn) const {
623  for(int y=0; y<data->GetHeight(); y++)
624  for(int x=0; x<data->GetWidth(); x++)
625  fn(x, y);
626  }
627 
629  void ForAllPixels(std::function<void(int, int, int)> fn) const {
630  for(int y=0; y<data->GetHeight(); y++)
631  for(int x=0; x<data->GetWidth(); x++)
632  for(int c=0; c<GetChannelsPerPixel(); c++)
633  fn(x, y, c);
634  }
635 
638  bool ForPixels(std::function<bool(int, int)> fn) const {
639  for(int y=0; y<data->GetHeight(); y++)
640  for(int x=0; x<data->GetWidth(); x++)
641  if(!fn(x, y)) return false;
642 
643  return true;
644  }
645 
648  bool ForPixels(std::function<bool(int, int, int)> fn) const {
649  for(int y=0; y<data->GetHeight(); y++)
650  for(int x=0; x<data->GetWidth(); x++)
651  for(int c=0; c<GetChannelsPerPixel(); c++)
652  if(!fn(x, y, c)) return false;
653 
654  return true;
655  }
656 
658  void ForAllPixels(std::function<void(Byte&)> fn, int channel) {
659  for(int y=0; y<data->GetHeight(); y++)
660  for(int x=0; x<data->GetWidth(); x++)
661  fn(this->operator()(x, y, channel));
662  }
663 
665  void ForAllPixels(std::function<void(Byte)> fn, int channel) const {
666  for(int y=0; y<data->GetHeight(); y++)
667  for(int x=0; x<data->GetWidth(); x++)
668  fn(this->operator()(x, y, channel));
669  }
670 
672  void ForAllValues(std::function<void(Byte&)> fn) {
673  for(int y=0; y<data->GetHeight(); y++)
674  for(int x=0; x<data->GetWidth(); x++)
675  for(int c=0; c<GetChannelsPerPixel(); c++)
676  fn(this->operator()(x, y, c));
677  }
678 
680  void ForAllValues(std::function<void(Byte)> fn) const {
681  for(int y=0; y<data->GetHeight(); y++)
682  for(int x=0; x<data->GetWidth(); x++)
683  for(int c=0; c<GetChannelsPerPixel(); c++)
684  fn(this->operator()(x, y, c));
685  }
686 
689  bool ForPixels(std::function<bool(Byte&)> fn, int channel) {
690  for(int y=0; y<data->GetHeight(); y++)
691  for(int x=0; x<data->GetWidth(); x++)
692  if(!fn(this->operator()(x, y, channel)))
693  return false;
694 
695  return true;
696  }
697 
700  bool ForPixels(std::function<bool(Byte)> fn, int channel) const {
701  for(int y=0; y<data->GetHeight(); y++)
702  for(int x=0; x<data->GetWidth(); x++)
703  if(!fn(this->operator()(x, y, channel)))
704  return false;
705 
706  return true;
707  }
708 
710  bool IsEmpty(Geometry::Bounds bounds) const;
711 
713  bool IsEmpty() const {
714  return IsEmpty({0,0, GetSize()});
715  }
716 
718  Graphics::Bitmap Rotate90() const;
719 
721  Graphics::Bitmap Rotate180() const;
722 
724  Graphics::Bitmap Rotate270() const;
725 
727  Graphics::Bitmap ZoomMultiple(int factor) const;
728 
730  void Clear() {
731  ASSERT(data, "Bitmap data is not set");
732  data->Clear();
733  }
734 
739  std::vector<Geometry::Bounds> CreateLinearAtlas(Containers::Collection<const Bitmap> list, AtlasMargin margins = None);
740 
743  std::vector<TextureImage> CreateAtlasImages(std::vector<Geometry::Bounds> boundaries) const;
744 
746  Bitmap Slice(Geometry::Bounds bounds) const {
747  ASSERT(data, "Bitmap data is not set");
748 
749  Bitmap ret(bounds.GetSize(), GetMode());
750 
751  data->CopyTo(ret.GetData(), bounds);
752 
753  return ret;
754  }
755 
756  protected:
758  bool Progress(unsigned &) override { return true; }
759 
760  int GetDuration() const override { return 0; }
761 
762  Geometry::Size getsize() const override {
763  return GetSize();
764  }
765 
768 
769  using Texture::size;
770  };
771 } }
Gorgon::Graphics::Bitmap::ReleaseTexture
Graphics::TextureImage ReleaseTexture()
Releases the texture held by this image.
Definition: Bitmap.h:157
Gorgon::Graphics::Bitmap::Trim
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
Gorgon::Graphics::Bitmap::HasTexture
bool HasTexture() const
Checks if this image resource has a texture attached to it.
Definition: Bitmap.h:176
Gorgon::Geometry::basic_Bounds
This class represents boundaries of 2D objects.
Definition: Bounds.h:27
Gorgon::Graphics::Bitmap::Assign
void Assign(Byte *newdata)
Assigns the image to the copy of the given data.
Definition: Bitmap.h:215
Gorgon::Graphics::Bitmap::Luminance
@ Luminance
Definition: Bitmap.h:46
Gorgon::Graphics::Bitmap::GetChannelsPerPixel
int GetChannelsPerPixel() const
Returns the bytes occupied by a single pixel of this image.
Definition: Bitmap.h:412
Gorgon::swap
void swap(Event< Source_, Args_... > &l, Event< Source_, Args_... > &r)
Swaps two events.
Definition: Event.h:351
Gorgon::Graphics::Bitmap::DeleteAnimation
virtual void DeleteAnimation() const override
if used as animation, this object will not be deleted
Definition: Bitmap.h:146
Gorgon::Graphics::RGBA
This class represents a color information.
Definition: Color.h:91
Gorgon::Graphics::Bitmap::Bitmap
Bitmap(const Bitmap &)=delete
Copy constructor is disabled.
Gorgon::Graphics::RGBA::Blend
void Blend(const RGBA &color)
Blends the given color into this one.
Definition: Color.h:248
Gorgon::Containers::basic_Image::GetMode
Graphics::ColorMode GetMode() const
Returns the color mode of the image.
Definition: Image.h:1311
Gorgon::Graphics::Bitmap::GetAlphaIndex
int GetAlphaIndex() const
Returns the index of alpha channel. Value of -1 denotes no alpha channel.
Definition: Bitmap.h:464
Gorgon::Graphics::Bitmap::Trim
Geometry::Margin Trim()
Trims the empty parts of the image, alpha channel = 0 is used to determine empty portions.
Definition: Bitmap.h:592
Gorgon::Containers::basic_Image::HasAlpha
bool HasAlpha() const
Returns if this image has alpha channel.
Definition: Image.h:1331
Gorgon::Containers::basic_Image::Resize
void Resize(const Geometry::Size &size, Graphics::ColorMode mode)
Resizes the image to the given size and color mode.
Definition: Image.h:71
Gorgon::Containers::Image
basic_Image< Byte > Image
Definition: Image.h:1364
Gorgon::Graphics::Bitmap::ForPixels
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
Gorgon::Containers::basic_Image::GetAlphaIndex
int GetAlphaIndex() const
Returns the index of alpha channel. Value of -1 denotes no alpha channel.
Definition: Image.h:1336
Gorgon::Containers::basic_Image::ImportBMP
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
Gorgon::Graphics::Bitmap::Duplicate
Bitmap Duplicate() const
Duplicates this image.
Definition: Bitmap.h:117
Gorgon::Graphics::ColorMode
ColorMode
Color modes for images.
Definition: Color.h:16
Gorgon::Geometry::basic_Margin::Left
T_ Left
Left margin.
Definition: Margin.h:167
Gorgon::Graphics::Bitmap::Trim
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
Gorgon::Graphics::Texture
This class represents an image depends on a GL texture.
Definition: Texture.h:17
Gorgon::Encoding::Png
PNG Png
A ready to use PNG class.
Definition: PNG.cpp:304
Gorgon::Graphics::Bitmap::ForPixels
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
Gorgon::Graphics::Bitmap::ZoomMultiple
Graphics::Bitmap ZoomMultiple(int factor) const
Zooms the image while preserving the colors.
Definition: Bitmap.cpp:746
Gorgon::Graphics::Bitmap::HasAlpha
bool HasAlpha() const
Returns if this image has alpha channel.
Definition: Bitmap.h:453
Gorgon::Graphics::Bitmap::Blur
Bitmap Blur(float amount, int windowsize=-1) const
Creates the blurred version of this image as a new separate image.
Gorgon::Graphics::Texture::mode
ColorMode mode
Color mode of the texture, necessary to choose correct texture.
Definition: Texture.h:198
Gorgon::Graphics::ColorMode::RGB
@ RGB
24bit red, green, blue color mode that has red component in the lowest byte order
Gorgon::Graphics::ColorMode::Invalid
@ Invalid
This is used to mark invalid color data.
Gorgon::Animation::ControllerBase
Controllers are required to progress animations.
Definition: Animation.h:65
Gorgon::Graphics::Texture::GetCoordinates
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
Gorgon::Graphics::Bitmap::Minimum
@ Minimum
Definition: Bitmap.h:49
Gorgon::Graphics::Bitmap::GetRGBAAt
RGBA GetRGBAAt(Geometry::Point p) const
Returns the alpha at the given location.
Definition: Bitmap.h:389
Gorgon::Graphics::Bitmap::Progress
bool Progress(unsigned &) override
When used as animation, an image is always persistent and it never finishes.
Definition: Bitmap.h:758
Gorgon::Geometry::basic_Point::X
T_ X
X coordinate.
Definition: Point.h:368
Gorgon::Graphics::Bitmap::CreateAnimation
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
Gorgon::Graphics::Bitmap::operator()
Byte & operator()(const Geometry::Point &p, unsigned component=0)
Provides access to the given component in x and y coordinates.
Definition: Bitmap.h:281
Gorgon::Graphics::Bitmap::Zero
@ Zero
If there is transparency, transparent, otherwise black borders.
Definition: Bitmap.h:36
Gorgon::Graphics::Bitmap::ForAllValues
void ForAllValues(std::function< void(Byte)> fn) const
Loops through all channels of all pixels of the image.
Definition: Bitmap.h:680
Gorgon::Containers::basic_Image::ChangeMode
void ChangeMode(Graphics::ColorMode value)
Changes the color mode of the image.
Definition: Image.h:1317
Gorgon::Geometry::basic_Size::Height
T_ Height
Height of this size object.
Definition: Size.h:261
Gorgon::Graphics::ColorMode::RGBA
@ RGBA
32bit red, green, blue and alpha channel image. Red component is in the lowest byte order and
Gorgon::Graphics::Bitmap::Average
@ Average
Definition: Bitmap.h:47
Gorgon::Graphics::Bitmap::ExportJPG
bool ExportJPG(const std::string &filename, int quality=90)
Exports the data of the image resource to a JPG file.
Definition: Bitmap.cpp:210
Gorgon::Graphics::Bitmap::Swap
virtual void Swap(Bitmap &other)
Swaps two images, mostly used for move constructor,.
Definition: Bitmap.h:85
Gorgon::Graphics::Bitmap::GetHeight
int GetHeight() const
Returns the height of the bitmap.
Definition: Bitmap.h:480
Gorgon::Containers::basic_Image::GetAlphaAt
Byte GetAlphaAt(int x, int y) const
Returns the alpha at the given location.
Definition: Image.h:1193
Gorgon::Graphics::Bitmap::Maximum
@ Maximum
Definition: Bitmap.h:48
Gorgon::Containers::Collection::GetSize
long GetSize() const
Returns number of elements.
Definition: Collection.h:241
Gorgon::Graphics::Texture::Release
GL::Texture Release()
Releases the texture id that might be owned by this object without destroying it.
Definition: Texture.h:180
Gorgon::Encoding::PNG::Encode
void Encode(const Containers::Image &input, std::ostream &output, bool replace_colormode=false)
Encodes a given input.
Definition: PNG.h:163
Gorgon::Graphics::Bitmap::Bitmap
Bitmap()
Default constructor will create an empty bitmap.
Definition: Bitmap.h:53
Gorgon::Graphics::Bitmap::GetMode
Graphics::ColorMode GetMode() const override
Returns the color mode of the image.
Definition: Bitmap.h:422
Gorgon::Graphics::Bitmap::Trim
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
Gorgon::Containers::basic_Image::GetWidth
int GetWidth() const
Returns the width of the image.
Definition: Image.h:1296
Gorgon::Graphics::Bitmap::None
@ None
Atlas will be tight packed.
Definition: Bitmap.h:33
Gorgon::Graphics::Bitmap::Assume
void Assume(Containers::Image &image)
Assumes the contents of the given image as image data.
Definition: Bitmap.h:226
Gorgon::Input::Keyboard::Keycodes::N
constexpr Key N
Definition: Keyboard.h:93
Gorgon::Graphics::Bitmap::BitmapWrapper
friend class BitmapWrapper
Definition: Bitmap.h:26
Gorgon::Graphics::Bitmap::Wrap
@ Wrap
Wraps to the other side.
Definition: Bitmap.h:42
Gorgon::Graphics::Bitmap::Grayscale
void Grayscale(float ratio=1.0f, GrayscaleConversionMethod method=Luminance)
Transforms this image to a grayscale image.
Definition: Bitmap.cpp:291
Gorgon::Graphics::Bitmap::data
Containers::Image * data
Container for the image data, could be null indicating its discarded.
Definition: Bitmap.h:767
Gorgon::Containers::basic_Image::Get
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
Gorgon::Graphics::ColorMode::Grayscale
@ Grayscale
8bit gray scale color mode
Gorgon::Graphics::Bitmap::Rotate90
Graphics::Bitmap Rotate90() const
Rotates image data without any losses.
Definition: Bitmap.cpp:706
Gorgon::Graphics::Bitmap::Bitmap
Bitmap(Bitmap &&other)
Move constructor.
Definition: Bitmap.h:75
Gorgon::Graphics::Bitmap::Bitmap
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
Gorgon::Graphics::Bitmap::Rotate270
Graphics::Bitmap Rotate270() const
Rotates image data without any losses.
Definition: Bitmap.cpp:733
Gorgon::Geometry::basic_Bounds::Left
T_ Left
Left-most boundary.
Definition: Bounds.h:399
Gorgon::Geometry::basic_Margin::Top
T_ Top
Top margin.
Definition: Margin.h:170
Gorgon::Graphics::Bitmap::Slice
Bitmap Slice(Geometry::Bounds bounds) const
Returns a new bitmap containing a slice of this bitmap.
Definition: Bitmap.h:746
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Geometry::basic_Size
This class represents a 2D geometric size.
Definition: Size.h:23
Gorgon::Containers::basic_Image::Clear
void Clear()
Cleans the contents of the buffer by setting every byte it contains to 0.
Definition: Image.h:177
Gorgon::Graphics::Bitmap::GrayscaleConversionMethod
GrayscaleConversionMethod
Definition: Bitmap.h:45
Gorgon::Animation::Base
This is the base class for all animations.
Definition: Animation.h:306
Gorgon::Graphics::Bitmap::operator()
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
Gorgon::Graphics::Texture::GetImageSize
virtual Geometry::Size GetImageSize() const override final
Returns the size of the texture in pixels. Declared final to allow inlining.
Definition: Texture.h:156
Gorgon::Graphics::Bitmap::HasData
bool HasData() const
Checks if this image resource has a data attached to it.
Definition: Bitmap.h:163
Gorgon::Graphics::Image
This is an interface for solid texture based image.
Definition: Drawables.h:511
Gorgon::Graphics::Bitmap::ForAllValues
void ForAllValues(std::function< void(Byte &)> fn)
Loops through all channels of all pixels of the image.
Definition: Bitmap.h:672
Gorgon::Graphics::Bitmap::GetDuration
int GetDuration() const override
Returns the duration of the animation if it is a known apriori.
Definition: Bitmap.h:760
Gorgon::IO::ReadUInt32
unsigned long ReadUInt32(std::istream &stream)
Reads a 32-bit unsigned integer from the stream.
Definition: Stream.h:35
Gorgon::Graphics::RectangularAnimation
Rectangular drawable animation.
Definition: Animations.h:19
Gorgon::Graphics::TextureSource::GetID
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.
Gorgon::Graphics::Bitmap::Assign
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
Bitmap.h
ASSERT
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
Gorgon::Graphics::Bitmap::StripRGB
void StripRGB()
This function removes color channels, leaving only alpha channel.
Definition: Bitmap.cpp:250
Gorgon::Graphics::Bitmap::AtlasMargin
AtlasMargin
Definition: Bitmap.h:31
Gorgon::Containers::Collection
Collection is a container for reference typed objects.
Definition: Collection.h:21
Gorgon::Graphics::Bitmap::Assume
void Assume(Byte *newdata, const Geometry::Size &size, Graphics::ColorMode mode)
Assumes the ownership of the given data.
Definition: Bitmap.h:242
Gorgon::String::ToLower
std::string ToLower(std::string str)
Converts the given string to lowercase.
Definition: String.h:416
Gorgon::Containers::basic_Image::ExportBMP
bool ExportBMP(const std::string &filename, bool usev4=false, bool dib=false)
Exports the image as a bitmap.
Definition: Image.h:893
Gorgon::Graphics::Bitmap::ReleaseData
Containers::Image ReleaseData()
Releases the image data.
Definition: Bitmap.cpp:667
Gorgon::Graphics::Bitmap
This object contains an bitmap image.
Definition: Bitmap.h:25
Gorgon::Graphics::TextureImage
This is a solid texture based image class.
Definition: Texture.h:211
Gorgon::Graphics::Bitmap::IsEmpty
bool IsEmpty() const
Checks if this bitmap is empty: either 0x0 in size or completely transparent.
Definition: Bitmap.h:713
Gorgon::Graphics::Texture::size
Geometry::Size size
Size of the texture.
Definition: Texture.h:195
Gorgon::Geometry::basic_Size::Cells
T_ Cells() const
Returns the number of fully encompassed cells.
Definition: Size.h:235
Gorgon::Graphics::Bitmap::Resize
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
Gorgon::Containers::basic_Image::Duplicate
basic_Image Duplicate() const
Duplicates this image, essentially performing the work of copy constructor.
Definition: Image.h:62
Gorgon::Graphics::Bitmap::SetRGBAAt
void SetRGBAAt(Geometry::Point p, RGBA color)
Sets the color at the given location to the specified RGBA value.
Definition: Bitmap.h:407
Gorgon::Graphics::Bitmap::Assign
void Assign(const Containers::Image &image)
Assigns the given image as the data of this image resource.
Definition: Bitmap.h:183
Gorgon::Geometry::Bounds
basic_Bounds< int > Bounds
Definition: Bounds.h:722
Gorgon::Graphics::Texture::id
GL::Texture id
GL texture id.
Definition: Texture.h:192
Gorgon::Geometry::basic_Margin::Bottom
T_ Bottom
Bottom margin.
Definition: Margin.h:176
Gorgon::Graphics::Bitmap::GetSize
Geometry::Size GetSize() const override
Returns the size of this image resource.
Definition: Bitmap.h:436
Gorgon::Graphics::ColorMode::Alpha
@ Alpha
8bit alpha only color mode
Gorgon::Containers::basic_Image::Assign
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
Gorgon::Graphics::Bitmap::Get
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
Gorgon::Geometry::basic_Point
This class represents a 2D point.
Definition: Point.h:32
Gorgon::Graphics::Bitmap::CreateAnimation
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
Gorgon::Graphics::Bitmap::operator=
Bitmap & operator=(Bitmap &)=delete
Copy assignment is disabled.
Gorgon::Graphics::Bitmap::SetController
virtual void SetController(Gorgon::Animation::ControllerBase &) override
Bitmap cannot be controlled.
Definition: Bitmap.h:149
Gorgon::Graphics::Bitmap::CreateLinearAtlas
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
Gorgon::Encoding::Jpg
JPEG Jpg
Definition: JPEG.cpp:327
Gorgon::Graphics::Bitmap::ExportPNG
bool ExportPNG(const std::string &filename)
Exports the data of the image resource to a PNG file.
Definition: Bitmap.cpp:152
Gorgon::Graphics::Bitmap::CreateAtlasImages
std::vector< TextureImage > CreateAtlasImages(std::vector< Geometry::Bounds > boundaries) const
Creates images from the given atlas image and map.
Definition: Bitmap.cpp:528
Gorgon::Graphics::Texture::GetID
virtual GL::Texture GetID() const override final
Returns GL::Texture to be drawn. Declared final to allow inlining.
Definition: Texture.h:151
Gorgon::Containers::basic_Image::SetRGBAAt
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
Gorgon::Graphics::Texture::Swap
void Swap(Texture &other)
Swaps two textures.
Definition: Texture.h:53
Gorgon::Byte
unsigned char Byte
Represents smallest cell in memory.
Definition: Types.h:9
Gorgon::Graphics::RectangularAnimationProvider
This class provides rectangular animations.
Definition: Animations.h:48
Gorgon::Geometry::basic_Bounds::Right
T_ Right
Right-most boundary.
Definition: Bounds.h:405
Gorgon::Geometry::basic_Margin::Right
T_ Right
Right margin.
Definition: Margin.h:173
Gorgon::Graphics::Bitmap::Bitmap
Bitmap(Containers::Image &&imagedata)
Move constructor.
Definition: Bitmap.h:80
Gorgon::UI::Graphics
@ Graphics
Definition: Template.h:164
Gorgon::Graphics::Bitmap::ForPixels
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
Gorgon::Graphics::Bitmap::Bitmap
Bitmap(int width, int height, Graphics::ColorMode mode)
Definition: Bitmap.h:69
Gorgon::Graphics::TextureSource
This interface represents a GL texture source.
Definition: Graphics.h:480
Gorgon::Graphics::Bitmap::~Bitmap
virtual ~Bitmap()
Destroys image data.
Definition: Bitmap.h:132
Gorgon::Graphics::Bitmap::ImportJPEG
bool ImportJPEG(const std::string &filename)
Imports a JPEG file to become the new data of this image resource.
Definition: Bitmap.cpp:103
Gorgon::Graphics::Bitmap::GetRGBAAt
RGBA GetRGBAAt(int x, int y) const
Returns the alpha at the given location.
Definition: Bitmap.h:376
Gorgon::Containers::basic_Image::CopyTo
bool CopyTo(basic_Image &dest, Geometry::Point target={0, 0}) const
Copies data from one image to another.
Definition: Image.h:318
Gorgon::Graphics::Bitmap::Repeat
@ Repeat
Repeats the last pixel.
Definition: Bitmap.h:39
Gorgon::Geometry::basic_Bounds::Bottom
T_ Bottom
Bottom-most boundary.
Definition: Bounds.h:408
Gorgon::Graphics::Texture::GetMode
ColorMode GetMode() const override
Definition: Texture.h:165
Gorgon::Graphics::Bitmap::Shadow
Bitmap Shadow(float amount, int windowsize=-1) const
Creates a smooth drop shadow by using alpha channel of this image.
Gorgon::Containers::basic_Image
This class is a container for image data.
Definition: Image.h:19
Gorgon::Input::Keyboard::Keycodes::C
constexpr Key C
Definition: Keyboard.h:82
Gorgon::Graphics::Bitmap::Prepare
virtual void Prepare()
This function prepares image for drawing.
Definition: Bitmap.cpp:14
Gorgon::Geometry::basic_Point::Y
T_ Y
Y coordinate.
Definition: Point.h:371
Gorgon::Graphics::Bitmap::operator()
Byte & operator()(int x, int y, unsigned component=0)
Provides access to the given component in x and y coordinates.
Definition: Bitmap.h:306
Gorgon::Encoding::PNG::Decode
void Decode(std::istream &input, Containers::Image &output)
Decodes the given PNG data.
Definition: PNG.h:186
Gorgon::Geometry::basic_Size::Width
T_ Width
Width of this size object.
Definition: Size.h:258
Gorgon::Graphics::Bitmap::MoveOutProvider
virtual auto MoveOutProvider() -> decltype(*this) override
This function moves this animation provider into a new provider.
Definition: Bitmap.h:94
Gorgon::Geometry::basic_Bounds::GetSize
basic_Size< T_ > GetSize() const
Returns the size of the bounds object.
Definition: Bounds.h:141
Gorgon::Graphics::Bitmap::Import
bool Import(const std::string &filename)
Imports an image file to become the new data of this image resource.
Definition: Bitmap.cpp:27
Gorgon::Graphics::Bitmap::ForAllPixels
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
Gorgon::Graphics::Bitmap::ImportBMP
bool ImportBMP(const std::string &filename)
Imports a BMP file to become the new data of this image resource.
Definition: Bitmap.cpp:116
Gorgon::Graphics::Texture::Set
void Set(const Containers::Image &image)
Sets the texture to the given id with the given size.
Definition: Texture.h:69
Gorgon::Graphics::Bitmap::Assume
void Assume(Byte *newdata)
Assumes the ownership of the given data.
Definition: Bitmap.h:254
Gorgon::Graphics::Bitmap::GetWidth
int GetWidth() const
Returns the width of the bitmap.
Definition: Bitmap.h:476
Gorgon::Graphics::Bitmap::getsize
Geometry::Size getsize() const override
Should return the exact size of this object.
Definition: Bitmap.h:762
Gorgon::Containers::basic_Image::Assume
void Assume(Byte *newdata, const Geometry::Size &size, Graphics::ColorMode mode)
Assumes the ownership of the given data.
Definition: Image.h:139
Gorgon::Graphics::Bitmap::StripAlpha
void StripAlpha()
This function removes transparency information from the image.
Definition: Bitmap.cpp:268
Gorgon::Graphics::Bitmap::Resize
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
Gorgon::Graphics::Bitmap::ExportBMP
bool ExportBMP(const std::string &filename)
Exports the data of the image resource to a bitmap file.
Definition: Bitmap.cpp:192
Gorgon::Geometry::basic_Margin
This class defines Margin of an object or an area.
Definition: Margin.h:22
Gorgon::Containers::basic_Image::GetHeight
int GetHeight() const
Returns the height of the image.
Definition: Image.h:1301
Gorgon::Encoding::JPEG::Decode
void Decode(std::istream &input, Containers::Image &output)
Decodes given JPG data from the given input and creates the image.
Definition: JPEG.h:130
Gorgon::Containers::basic_Image::Swap
void Swap(basic_Image &other)
Swaps this image with another. This function is used to implement move semantics.
Definition: Image.h:200
Gorgon::Graphics::Bitmap::operator()
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
Gorgon::Graphics::Bitmap::ForAllPixels
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
Gorgon::Graphics::Bitmap::Discard
virtual void Discard()
This function discards image data.
Definition: Bitmap.cpp:20
Gorgon::Graphics::Bitmap::Destroy
void Destroy()
Definition: Bitmap.h:125
ASSERT_DUMP
#define ASSERT_DUMP(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:182
Gorgon::Graphics::Bitmap::GetAlphaAt
Byte GetAlphaAt(int x, int y) const
Returns the alpha at the given location.
Definition: Bitmap.h:357
Gorgon::Graphics::Bitmap::ForAllPixels
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
Gorgon::Encoding::JPEG::Encode
void Encode(Containers::Image &input, std::ostream &output, int quality=90)
Encode given image to JPG compressed data.
Definition: JPEG.h:162
Gorgon::Graphics::Bitmap::size
Geometry::Size size
Size of the texture.
Definition: Texture.h:195
Gorgon::Graphics::Bitmap::GetData
Containers::Image & GetData() const
Returns the data attached to this bitmap. If no data is present, this function throws.
Definition: Bitmap.h:168
Gorgon::Graphics::Bitmap::ForPixels
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
Gorgon::Graphics::Texture::Destroy
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
Gorgon::Graphics::Bitmap::Get
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
Gorgon::Graphics::Bitmap::Clear
void Clear()
Cleans the contents of the buffer by setting every byte it contains to 0.
Definition: Bitmap.h:730
Gorgon::Graphics::Bitmap::SetRGBAAt
void SetRGBAAt(int x, int y, RGBA color)
Sets the color at the given location to the specified RGBA value.
Definition: Bitmap.h:395
Gorgon::Containers::basic_Image::GetRGBAAt
Graphics::RGBA GetRGBAAt(int x, int y) const
Returns the alpha at the given location.
Definition: Image.h:1207
Gorgon::Containers::basic_Image::GetSize
Geometry::Size GetSize() const
Returns the size of the image.
Definition: Image.h:1291
Gorgon::Geometry::basic_Bounds::Top
T_ Top
Top-most boundary.
Definition: Bounds.h:402
Gorgon::Graphics::Bitmap::GetAlphaAt
Byte GetAlphaAt(Geometry::Point p) const
Returns the alpha at the given location.
Definition: Bitmap.h:369
Gorgon::Graphics::Bitmap::Rotate180
Graphics::Bitmap Rotate180() const
Rotates image data without any losses.
Definition: Bitmap.cpp:719
Gorgon::Graphics::Bitmap::ForAllPixels
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
Gorgon::Containers::basic_Image::GetChannelsPerPixel
unsigned GetChannelsPerPixel() const
Returns the number units occupied by a single pixel of this image.
Definition: Image.h:1326
Gorgon::Graphics::Bitmap::ImportPNG
bool ImportPNG(const std::string &filename)
Imports a PNG file to become the new data of this image resource.
Definition: Bitmap.cpp:90