libcruft-util/image.hpp

83 lines
2.4 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 {
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-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-04 14:34:13 +10:00
constexpr size_t area (void) const;
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-06-03 23:28:45 +10:00
T operator[] (point<2,size_t>) const;
T& operator[] (point<2,size_t>);
2015-06-03 23:28:45 +10:00
T operator[] (size_t) const;
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-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