1 | |
2 | // |
3 | // This source file is part of appleseed. |
4 | // Visit http://appleseedhq.net/ for additional information and resources. |
5 | // |
6 | // This software is released under the MIT license. |
7 | // |
8 | // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited |
9 | // Copyright (c) 2014-2017 Francois Beaune, The appleseedhq Organization |
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 |
16 | // furnished to do so, subject to the following conditions: |
17 | // |
18 | // The above copyright notice and this permission notice shall be included in |
19 | // all copies or substantial portions of the Software. |
20 | // |
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
27 | // THE SOFTWARE. |
28 | // |
29 | |
30 | #ifndef APPLESEED_FOUNDATION_IMAGE_IMAGE_H |
31 | #define APPLESEED_FOUNDATION_IMAGE_IMAGE_H |
32 | |
33 | // appleseed.foundation headers. |
34 | #include "foundation/core/concepts/iunknown.h" |
35 | #include "foundation/image/canvasproperties.h" |
36 | #include "foundation/image/icanvas.h" |
37 | #include "foundation/image/pixel.h" |
38 | #include "foundation/platform/compiler.h" |
39 | |
40 | // appleseed.main headers. |
41 | #include "main/dllsymbol.h" |
42 | |
43 | // Standard headers. |
44 | #include <cstddef> |
45 | |
46 | // Forward declarations. |
47 | namespace foundation { class Tile; } |
48 | |
49 | namespace foundation |
50 | { |
51 | |
52 | // |
53 | // An image whose tiles are lazily constructed. |
54 | // |
55 | // Tiles are initially blank. |
56 | // |
57 | |
58 | class APPLESEED_DLLSYMBOL Image |
59 | : public ICanvas |
60 | , public IUnknown |
61 | { |
62 | public: |
63 | // Construct an empty image. |
64 | Image( |
65 | const size_t image_width, // image width, in pixels |
66 | const size_t image_height, // image height, in pixels |
67 | const size_t tile_width, // tile width, in pixels |
68 | const size_t tile_height, // tile height, in pixels |
69 | const size_t channel_count, |
70 | const PixelFormat pixel_format); |
71 | |
72 | // An alternative way to construct an empty image. |
73 | explicit Image(const CanvasProperties& props); |
74 | |
75 | // Copy constructor, duplicates both the layout and the data of the source image. |
76 | Image(const Image& rhs); |
77 | |
78 | // Copy image data but allow to tweak the layout. |
79 | Image( |
80 | const Image& source, |
81 | const size_t tile_width, // tile width, in pixels |
82 | const size_t tile_height, // tile height, in pixels |
83 | const PixelFormat pixel_format); |
84 | |
85 | // Destructor. |
86 | virtual ~Image(); |
87 | |
88 | // Delete this instance. |
89 | virtual void release() APPLESEED_OVERRIDE; |
90 | |
91 | // Access canvas properties. |
92 | virtual const CanvasProperties& properties() const APPLESEED_OVERRIDE; |
93 | |
94 | // Direct access to a given tile. |
95 | virtual Tile& tile( |
96 | const size_t tile_x, |
97 | const size_t tile_y) APPLESEED_OVERRIDE; |
98 | virtual const Tile& tile( |
99 | const size_t tile_x, |
100 | const size_t tile_y) const APPLESEED_OVERRIDE; |
101 | |
102 | // Set a given tile. Ownership of the tile is transfered to the Image class. |
103 | // If a tile already exists at the given coordinates, it gets replaced. |
104 | void set_tile( |
105 | const size_t tile_x, |
106 | const size_t tile_y, |
107 | Tile* tile); |
108 | |
109 | protected: |
110 | CanvasProperties m_props; |
111 | Tile** m_tiles; |
112 | }; |
113 | |
114 | |
115 | // |
116 | // Image class implementation. |
117 | // |
118 | |
119 | inline const CanvasProperties& Image::properties() const |
120 | { |
121 | return m_props; |
122 | } |
123 | |
124 | } // namespace foundation |
125 | |
126 | #endif // !APPLESEED_FOUNDATION_IMAGE_IMAGE_H |
127 | |