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"
|
2015-06-03 23:17:37 +10:00
|
|
|
#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 {
|
|
|
|
template <typename T>
|
|
|
|
struct buffer {
|
|
|
|
typedef T value_type;
|
2015-02-06 13:52:44 +11:00
|
|
|
|
2015-06-04 14:35:02 +10:00
|
|
|
//---------------------------------------------------------------------
|
2015-06-03 23:28:45 +10:00
|
|
|
buffer (util::extent2u);
|
|
|
|
buffer (size_t w, size_t h);
|
|
|
|
buffer (size_t w, size_t h, size_t s);
|
|
|
|
buffer (size_t w, size_t h, size_t s, std::unique_ptr<T[]> &&data);
|
2015-02-04 15:59:06 +11:00
|
|
|
|
2015-06-03 23:28:45 +10:00
|
|
|
buffer (const buffer<T>&) = delete;
|
|
|
|
buffer (buffer<T> &&) = 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.
|
|
|
|
template <typename U = T> buffer<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
|
|
|
|
template <typename U = T> buffer<U> clone (void) const;
|
2015-06-11 19:28:18 +10:00
|
|
|
template <typename U> buffer<U> cast (void) const { return clone<U> (); }
|
2015-02-04 15:59:06 +11:00
|
|
|
|
2015-06-03 23:28:45 +10:00
|
|
|
buffer<T> downsample (float factor) const;
|
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-03 23:28:45 +10:00
|
|
|
size_t w;
|
|
|
|
size_t h;
|
|
|
|
size_t s;
|
2015-02-04 15:59:06 +11:00
|
|
|
|
2015-06-04 14:35:02 +10:00
|
|
|
//---------------------------------------------------------------------
|
2015-07-24 01:36:11 +10:00
|
|
|
constexpr size_t offset (point<2,size_t>) const;
|
2015-07-23 21:18:15 +10:00
|
|
|
|
2015-09-15 21:08:00 +10:00
|
|
|
const T& operator[] (point<2,size_t>) const;
|
2015-06-03 23:28:45 +10:00
|
|
|
T& operator[] (point<2,size_t>);
|
2015-06-03 23:17:37 +10:00
|
|
|
|
2015-09-15 21:08:00 +10:00
|
|
|
const T& operator[] (size_t) const;
|
2015-06-03 23:28:45 +10:00
|
|
|
T& operator[] (size_t);
|
2015-06-03 23:17:37 +10:00
|
|
|
|
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-05-18 14:09:34 +10:00
|
|
|
|
2015-06-03 23:28:45 +10:00
|
|
|
const T* begin (void) const;
|
|
|
|
const T* end (void) const;
|
|
|
|
const T* data (void) const;
|
2015-05-18 14:09:34 +10:00
|
|
|
|
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:
|
|
|
|
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
|