/* * 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 * * http://www.apache.org/licenses/LICENSE-2.0 * * 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. * * Copyright 2011-2015 Danny Robson */ #include "image.hpp" #include "debug.hpp" using util::image::buffer; //----------------------------------------------------------------------------- template util::image::buffer::buffer (util::extent2u _size): buffer (_size.w, _size.h) { ; } //----------------------------------------------------------------------------- template util::image::buffer::buffer (size_t _w, size_t _h, size_t _s): w (_w), h (_h), s (_s), m_data (std::make_unique (_h * _s)) { CHECK_NEQ (w * h, 0); CHECK_GE (s, w); } //----------------------------------------------------------------------------- template util::image::buffer::buffer (size_t _w, size_t _h): buffer (_w, _h, _w) { ; } //----------------------------------------------------------------------------- template util::image::buffer::buffer (size_t _w, size_t _h, size_t _s, std::unique_ptr &&_data): w (_w), h (_h), s (_s), m_data (std::move (_data)) { CHECK_NEQ (w * h, 0); CHECK_GE (s, w); } //----------------------------------------------------------------------------- template template util::image::buffer util::image::buffer::alloc (void) const { return buffer (w, h, s); } //----------------------------------------------------------------------------- template static U rescale (T v) { return v * sizeof (U) / sizeof (T); } //----------------------------------------------------------------------------- template template util::image::buffer util::image::buffer::clone (void) const { auto out = alloc (); std::transform (begin (), end (), out.begin (), renormalise); return out; } /////////////////////////////////////////////////////////////////////////////// template const T& buffer::operator[] (point<2,size_t> p) const { CHECK_LT (p.x, w); CHECK_LT (p.y, h); return begin ()[offset (p)]; } //----------------------------------------------------------------------------- template T& buffer::operator[] (point<2,size_t> p) { CHECK_LT (p.x, w); CHECK_LT (p.y, h); return begin ()[offset (p)]; } //----------------------------------------------------------------------------- template const T& buffer::operator[] (size_t idx) const { CHECK_LT (idx, h * s); return begin ()[idx]; } //----------------------------------------------------------------------------- template T& buffer::operator[] (size_t idx) { CHECK_LT (idx, h * s); return begin ()[idx]; } /////////////////////////////////////////////////////////////////////////////// template T* buffer::data (void) { return begin (); } //----------------------------------------------------------------------------- template T* buffer::begin (void) { return m_data.get (); } //----------------------------------------------------------------------------- template T* buffer::end (void) { return begin () + h * s; } //----------------------------------------------------------------------------- template const T* buffer::begin (void) const { return cbegin (); } //----------------------------------------------------------------------------- template const T* buffer::end (void) const { return cend (); } //----------------------------------------------------------------------------- template const T* buffer::data (void) const { return begin (); } //----------------------------------------------------------------------------- template const T* buffer::cbegin (void) const { return m_data.get (); } //----------------------------------------------------------------------------- template const T* buffer::cend (void) const { return cbegin () + h * s; } /////////////////////////////////////////////////////////////////////////////// template struct util::image::buffer; template struct util::image::buffer; template struct util::image::buffer; template struct util::image::buffer; template struct util::image::buffer< int32_t>; template struct util::image::buffer; template struct util::image::buffer; template util::image::buffer util::image::buffer::alloc (void) const; template util::image::buffer util::image::buffer::alloc (void) const; template util::image::buffer util::image::buffer::clone (void) const; template util::image::buffer util::image::buffer::clone (void) const; template util::image::buffer util::image::buffer::clone (void) const; template util::image::buffer util::image::buffer::alloc (void) const; template util::image::buffer util::image::buffer::alloc (void) const; template util::image::buffer< int32_t> util::image::buffer::alloc (void) const; template util::image::buffer util::image::buffer::clone (void) const; template util::image::buffer util::image::buffer::alloc (void) const;