Image.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef DIMAGE_H_INCLUDED
34 #define DIMAGE_H_INCLUDED
35 
36 
37 #include <Dynacoe/Color.h>
38 #include <Dynacoe/Util/Vector.h>
39 #include <Dynacoe/Modules/Assets.h>
40 
41 
42 #include <vector>
43 #include <string>
44 
45 /* The standard Image class for Dynacoe */
46 
47 namespace Dynacoe {
48 class Renderer;
62 class Image : public Asset{
63 
64  public:
65 
68  class Frame {
69  public:
70 
73  Frame();
74  Frame(int textureObjectHandle);
75 
78  Frame(uint32_t w, uint32_t h);
79 
82  Frame(uint32_t w, uint32_t h, const std::vector<uint8_t> & data);
83 
86  Frame(const Frame & other);
87 
88  Frame & operator=(const Frame & other);
89  ~Frame();
90 
93  std::vector<uint8_t> GetData() const;
94 
98  void SetData(const std::vector<uint8_t> & data);
99 
102  uint32_t Width() const;
103 
106  uint32_t Height() const;
107 
108 
111  std::vector<Frame> Detilize(uint32_t smallWidth, uint32_t smallHeight) const;
112 
115  int GetHandle() const;
116  private:
117  int object;
118  };
119 
122  std::vector<Frame> frames;
123 
124 
127  Frame & CurrentFrame();
128 
129 
130  Image(const std::string &);
131  private:
132  uint32_t index;
133 };
134 };
135 
136 #endif
int GetHandle() const
Returns the object handle to be used with the Renderer.
Frame()
Creates an empty Frame.
Frame & CurrentFrame()
Currently active frame. Changes over time.
A 2D matrix of pixels.
Definition: Image.h:68
Definition: AssetID.h:37
std::vector< uint8_t > GetData() const
Returns the raw pixel data of a frame.
Class for abstracting visual data blocks.
Definition: Image.h:62
void SetData(const std::vector< uint8_t > &data)
Updates a frame with the given pixel data. Note that the data must match in dimensions the current Wi...
std::vector< Frame > frames
The frames of the Image.
Definition: Image.h:122
uint32_t Height() const
Returns the height of the frame.
std::vector< Frame > Detilize(uint32_t smallWidth, uint32_t smallHeight) const
Splits the frame into many sub-frames, each with the specified smallWidth and smallHeight.
uint32_t Width() const
Returns the width of the frame.