2 Copyright (C) 2012 fmaj7b5.info
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 typedef Image<T> image_type;
34 typedef std::uint8_t raw_type;
37 Image(const size_t width, const size_t height, const size_t stride = 0);
40 T& operator()(const size_t x, const size_t y);
41 const T& operator()(const size_t x, const size_t y) const;
44 size_t height() const;
46 size_t stride() const;
50 const T* data() const;
55 size_t m_byte_per_pixel;
58 std::shared_ptr<raw_type> m_data;
60 size_t align_up(const size_t size, const size_t alignment);
66 : m_width(0), m_height(0),
67 m_byte_per_pixel(sizeof(T)),
68 m_stride(0), m_size(0), m_data(0)
72 Image<T>::Image(const size_t width, const size_t height, const size_t stride)
73 : m_width(width), m_height(height),
74 m_byte_per_pixel(sizeof(T)),
75 m_stride(stride == 0 ? sizeof(T) * width : stride),
76 m_size(m_stride * height)
78 m_data.reset(new raw_type[m_size]);
87 Image<T>::operator()(const size_t x, const size_t y)
89 return *(reinterpret_cast<T*>(m_data.get() + m_stride * y + m_byte_per_pixel * x));
94 Image<T>::operator()(const size_t x, const size_t y) const
96 return *(reinterpret_cast<T*>(m_data.get() + m_stride * y + m_byte_per_pixel * x));
101 Image<T>::width() const
108 Image<T>::height() const
115 Image<T>::bpp() const
117 return m_byte_per_pixel;
122 Image<T>::stride() const
129 Image<T>::size() const
138 return reinterpret_cast<T*>(m_data.get());
143 Image<T>::data() const
145 return reinterpret_cast<const T*>(m_data.get());
150 Image<T>::align_up(const size_t size, const size_t alignment)
152 return size + (alignment - (size % alignment));
155 /* typedefs for convinience */
156 typedef Image<std::uint8_t> ImageGray;
159 #endif /* FM7b5_IMAGE_H */