Gorgon Game Engine
Image.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdexcept>
4 #include <memory>
5 
6 #include "Base.h"
7 #include "AnimationStorage.h"
8 #include "../Graphics/Animations.h"
9 #include "../Graphics/Texture.h"
10 #include "../Containers/Image.h"
11 #include "../Graphics/Bitmap.h"
12 
13 namespace Gorgon { namespace Resource {
14  class File;
15  class Reader;
16 
21  class Image :
22  public Graphics::Bitmap, public AnimationStorage
23  {
24  public:
25  Image() = default;
26 
28  Image(Graphics::Bitmap &&source) {
29  Swap(source);
30  }
31 
32  virtual GID::Type GetGID() const override { return GID::Image; }
33 
34 
38  this->compression=compression;
39  }
40 
43  return compression;
44  }
45 
46  virtual void Prepare() override { Bitmap::Prepare(); }
47 
48  virtual void Discard() override { Bitmap::Discard(); }
49 
52 
54  bool Load();
55 
58  bool IsLoaded() const { return isloaded; }
59 
61  static Image *LoadResource(std::weak_ptr<File> file, std::shared_ptr<Reader> reader, unsigned long size);
62 
66  static void SaveThis(Writer &writer, const Graphics::Bitmap &bmp, GID::Type type = GID::Image);
67 
69 
70  protected:
71  virtual ~Image() { }
72 
74 
76  bool load(std::shared_ptr<Reader> reader, unsigned long size, bool forceload);
77 
78  void save(Writer &writer) const override;
79 
80  void loaded();
81 
82  //virtual void loaded() override { }
83 
86 
89  unsigned long entrypoint = -1;
90 
92  std::shared_ptr<Reader> reader;
93 
95  bool isloaded = true;
96  };
97 } }
Gorgon::Animation::basic_Storage
This class stores animations as a part of itself so that it can be moved around as a value rather tha...
Definition: Storage.h:21
Gorgon::Resource::GID::PNG
constexpr Type PNG
PNG compression.
Definition: GID.h:126
Gorgon::Resource::GID::File
constexpr Type File
File.
Definition: GID.h:84
Gorgon::Resource::Image::GetCompression
GID::Type GetCompression() const
Returns the compression mode of this image resource.
Definition: Image.h:42
Gorgon::Resource::Image::Discard
virtual void Discard() override
This function discards image data.
Definition: Image.h:48
Gorgon::Resource::Image::isloaded
bool isloaded
Whether this image resource is loaded or not.
Definition: Image.h:95
Gorgon::Resource::Image::animmoveout
virtual Graphics::RectangularAnimationStorage animmoveout() override
Definition: Image.cpp:210
Gorgon::Resource::Image::entrypoint
unsigned long entrypoint
Entry point of this resource within the physical file.
Definition: Image.h:89
Base.h
Gorgon::Resource::Image::SaveThis
static void SaveThis(Writer &writer, const Graphics::Bitmap &bmp, GID::Type type=GID::Image)
This function can be used to save a bitmap as image resource without modifying it.
Definition: Image.cpp:171
Gorgon::Resource::Image::SetCompression
void SetCompression(GID::Type compression)
Changes the compression mode.
Definition: Image.h:37
Gorgon::Graphics::Bitmap::Swap
virtual void Swap(Bitmap &other)
Swaps two images, mostly used for move constructor,.
Definition: Bitmap.h:85
Gorgon::Resource::Image::save
void save(Writer &writer) const override
Definition: Image.cpp:141
Gorgon::Resource::GID::Image
constexpr Type Image
Image resource.
Definition: GID.h:149
Gorgon::Resource::Image::Image
Image(Graphics::Bitmap &&source)
Assumes the given bitmap and converts it to a resource.
Definition: Image.h:28
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Resource::Image::Image
Image()=default
Gorgon::Resource::AnimationStorage
This class denotes the resource is an image animation storage.
Definition: AnimationStorage.h:12
Gorgon::Resource::Image::IsLoaded
bool IsLoaded() const
Returns whether the image data is loaded.
Definition: Image.h:58
Gorgon::Resource::Image::Prepare
virtual void Prepare() override
This function prepares image for drawing.
Definition: Image.h:46
Gorgon::Resource::Image::MoveOutAsBitmap
Graphics::Bitmap MoveOutAsBitmap()
Moves the data out of resource system. Use Prepare and Discard before moving to avoid data duplicatio...
Definition: Image.cpp:204
AnimationStorage.h
Gorgon::Graphics::Bitmap
This object contains an bitmap image.
Definition: Bitmap.h:25
Gorgon::Resource::Image::Load
bool Load()
Loads the image from the disk. This function requires image to be tied to a resource file.
Definition: Image.cpp:29
Gorgon::Resource::Image::compression
GID::Type compression
Compression mode.
Definition: Image.h:85
Gorgon::Resource::Image::reader
std::shared_ptr< Reader > reader
Used to handle late loading.
Definition: Image.h:92
Gorgon::Resource::Writer
This class allows resource objects to save their data to a stream.
Definition: Writer.h:59
Gorgon::Resource::Image::GetGID
virtual GID::Type GetGID() const override
This function shall return Gorgon ID of this resource.
Definition: Image.h:32
Gorgon::Resource::AnimationStorage::MoveOut
Graphics::RectangularAnimationStorage MoveOut()
Moves this animation out as a generic value type animation.
Definition: AnimationStorage.h:15
Gorgon::Resource::Image::loaded
void loaded()
Definition: Image.cpp:22
Gorgon::Resource::GID::Type
Type to store GID information.
Definition: GID.h:23
Gorgon::Resource::Image::~Image
virtual ~Image()
Definition: Image.h:71
Gorgon::Resource::Image::LoadResource
static Image * LoadResource(std::weak_ptr< File > file, std::shared_ptr< Reader > reader, unsigned long size)
This function loads a image resource from the given file.
Definition: Image.cpp:9
Gorgon::Graphics::Bitmap::size
Geometry::Size size
Size of the texture.
Definition: Texture.h:195
Gorgon::Resource::Image
This resource contains images.
Definition: Image.h:23
Gorgon::Resource::Image::load
bool load(std::shared_ptr< Reader > reader, unsigned long size, bool forceload)
Loads the image from the data stream.
Definition: Image.cpp:48