libcruft-util/image.hpp

90 lines
2.5 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
#include <cstdint>
#include <cstdlib>
2015-02-04 15:59:06 +11:00
#include <memory>
2012-05-16 15:03:49 +10:00
#include <boost/filesystem/path.hpp>
2015-02-04 15:59:06 +11:00
2012-05-16 15:03:49 +10:00
namespace util {
2015-02-04 15:59:06 +11:00
namespace image {
template <typename T>
struct buffer {
2015-02-06 13:52:44 +11:00
typedef T value_type;
2015-02-04 15:59:06 +11:00
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);
buffer (const buffer<T>&) = delete;
buffer (buffer<T> &&) = default;
void fill (T);
template <typename U>
buffer<U> alloc (void) const;
template <typename U>
buffer<U> clone (void) const;
buffer<T> downsample (float factor) const;
2015-02-04 15:59:06 +11:00
size_t w;
size_t h;
size_t s;
T* begin (void);
T* end (void);
T* data (void);
const T* begin (void) const;
const T* end (void) const;
const T* data (void) const;
private:
std::unique_ptr<T[]> m_data;
2015-02-04 15:59:06 +11:00
};
}
2012-05-16 15:03:49 +10:00
struct pgm {
static image::buffer<uint8_t> read (const boost::filesystem::path&);
static void write (const image::buffer<uint8_t> &src,
const boost::filesystem::path &);
2012-05-16 15:03:49 +10:00
static void write (const uint8_t *restrict pixels,
size_t width,
size_t height,
size_t stride,
const boost::filesystem::path &path);
};
struct ppm {
static void write (const uint8_t *restrict pixels,
size_t width,
size_t height,
size_t stride,
const boost::filesystem::path &path);
};
}
#endif