libcruft-util/image.hpp

88 lines
2.8 KiB
C++
Raw Normal View History

2012-05-16 15:03:49 +10:00
/*
2015-04-13 18:05:28 +10:00
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
2012-05-16 15:03:49 +10:00
*
2015-04-13 18:05:28 +10:00
* http://www.apache.org/licenses/LICENSE-2.0
2015-02-04 15:59:06 +11:00
*
2015-04-13 18:05:28 +10:00
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
2012-05-16 15:03:49 +10:00
*
2015-02-04 15:59:06 +11:00
* Copyright 2011-2015 Danny Robson <danny@nerdcruft.net>
2012-05-16 15:03:49 +10:00
*/
#ifndef __UTIL_IMAGE_HPP
#define __UTIL_IMAGE_HPP
2015-05-26 16:25:21 +10:00
#include "extent.hpp"
#include "point.hpp"
2015-05-26 16:25:21 +10:00
2012-05-16 15:03:49 +10:00
#include <cstdint>
#include <cstdlib>
2015-02-04 15:59:06 +11:00
#include <memory>
2012-05-16 15:03:49 +10:00
2015-02-04 15:59:06 +11:00
2015-06-03 23:28:45 +10:00
namespace util { namespace image {
2015-10-20 16:53:32 +11:00
template <size_t C, typename T>
2015-06-03 23:28:45 +10:00
struct buffer {
typedef T value_type;
2015-02-06 13:52:44 +11:00
2015-06-04 14:35:02 +10:00
//---------------------------------------------------------------------
2015-10-19 17:43:48 +11:00
buffer (util::extentu<2>);
buffer (util::extentu<2>, std::unique_ptr<T[]> &&data);
2015-02-04 15:59:06 +11:00
2015-10-20 16:53:32 +11:00
buffer (const buffer&) = delete;
buffer (buffer &&) = default;
buffer& operator= (const buffer&) = default;
buffer& operator= (buffer&&) = default;
2015-02-04 15:59:06 +11:00
2015-06-04 14:35:02 +10:00
//---------------------------------------------------------------------
/// allocate and return a buffer of the same dimensions. contents are undefined.
2015-10-20 16:53:32 +11:00
template <typename U = T> buffer<C,U> alloc (void) const;
2015-02-04 15:59:06 +11:00
2015-06-04 14:35:02 +10:00
/// allocate and return a buffer with the same contents
2015-10-20 16:53:32 +11:00
template <typename U = T> buffer<C,U> clone (void) const;
template <typename U> buffer<C,U> cast (void) const { return clone<U> (); }
2015-02-04 15:59:06 +11:00
2015-06-04 14:35:02 +10:00
//---------------------------------------------------------------------
2015-06-09 15:34:17 +10:00
constexpr extent2u extent (void) const;
2015-07-23 21:17:57 +10:00
constexpr vector2u stride (void) const;
2015-06-15 17:48:19 +10:00
constexpr size_t size (void) const; // elements allocated
2015-06-09 15:34:17 +10:00
2015-06-04 14:34:13 +10:00
constexpr bool is_packed (void) const;
2015-06-04 14:35:02 +10:00
//---------------------------------------------------------------------
constexpr size_t offset (point<2,size_t>) const;
2015-07-23 21:18:15 +10:00
const T& operator[] (point<2,size_t>) const;
2015-06-03 23:28:45 +10:00
T& operator[] (point<2,size_t>);
const T& operator[] (size_t) const;
2015-06-03 23:28:45 +10:00
T& operator[] (size_t);
2015-06-04 14:35:02 +10:00
//---------------------------------------------------------------------
2015-06-03 23:28:45 +10:00
T* begin (void);
T* end (void);
T* data (void);
2015-06-03 23:28:45 +10:00
const T* begin (void) const;
const T* end (void) const;
const T* data (void) const;
2015-09-21 12:35:44 +10:00
const T* cbegin (void) const;
const T* cend (void) const;
2015-06-03 23:28:45 +10:00
private:
2015-10-19 17:43:48 +11:00
util::extent2u m_size;
util::vector2u m_stride;
2015-06-03 23:28:45 +10:00
std::unique_ptr<T[]> m_data;
};
} }
2012-05-16 15:03:49 +10:00
2015-06-04 14:34:13 +10:00
#include "image.ipp"
2012-05-16 15:03:49 +10:00
#endif