#ifndef INCLUDE_DYNAMIC_TEXTURE_DATA_IMPLEMENTATION # error Never include this file directly include 'dynamic_texture_buffer.hpp' #endif inline dynamic_texture_buffer::dynamic_texture_buffer( std::unique_ptr&& data, const dim_type width, const dim_type height, const components::texture::flags components ) : m_data{ std::move(data) }, m_width{ width }, m_height{ height }, m_components{ components } {}; inline dynamic_texture_buffer::dynamic_texture_buffer(const dynamic_texture_buffer& other) : m_data{ new value_type[other.component_count()] }, m_width{ other.m_width }, m_height{ other.m_height }, m_components{ other.m_components } { std::copy_n(other.m_data.get(), other.m_width * other.m_height, this->m_data.get()); } inline dynamic_texture_buffer::dynamic_texture_buffer(dynamic_texture_buffer&& other) noexcept : m_data{ std::move(other.m_data) }, m_width{ other.m_width }, m_height{ other.m_height }, m_components{ other.m_components } { other.m_width = 0; other.m_height = 0; other.m_components = components::texture::flags::none; } inline dynamic_texture_buffer& dynamic_texture_buffer::operator=(const dynamic_texture_buffer& other) { if (this != &other) [[likely]] { const auto m_size = this->component_count(); const auto o_size = other.component_count(); if (o_size > m_size) { this->~dynamic_texture_buffer(); this->m_data.reset(new value_type[o_size]); } std::copy_n(other.m_data.get(), o_size, this->m_data.get()); this->m_width = other.m_width; this->m_height = other.m_height; this->m_components = other.m_components; } return *this; } inline dynamic_texture_buffer& dynamic_texture_buffer::operator=(dynamic_texture_buffer&& other) noexcept { if (this != &other) [[likely]] { this->~dynamic_texture_buffer(); this->m_data = std::move(other.m_data); this->m_width = other.m_width; this->m_height = other.m_height; other.m_width = 0; other.m_height = 0; other.m_components = components::texture::flags::none; } return *this; } inline components::texture::flags dynamic_texture_buffer::components() const { return m_components; } inline dynamic_texture_buffer::dim_type dynamic_texture_buffer::width() const { return m_width; } inline dynamic_texture_buffer::dim_type dynamic_texture_buffer::height() const { return m_height; } inline std::pair dynamic_texture_buffer::dimensions() const { return { m_width, m_height }; } inline dynamic_texture_buffer::size_type dynamic_texture_buffer::pixel_count() const { return static_cast(m_width) * static_cast(m_height); } inline dynamic_texture_buffer::size_type dynamic_texture_buffer::component_count() const { return std::popcount(static_cast>(m_components)); } inline dynamic_texture_buffer::size_type dynamic_texture_buffer::size() const { return pixel_count() * component_count(); } inline dynamic_texture_buffer::const_pointer dynamic_texture_buffer::data() const { return m_data.get(); } inline dynamic_texture_buffer::pointer dynamic_texture_buffer::data() { return m_data.get(); } inline dynamic_texture_buffer::const_iterator dynamic_texture_buffer::begin() const { return data(); } inline dynamic_texture_buffer::iterator dynamic_texture_buffer::begin() { return data(); } inline dynamic_texture_buffer::const_iterator dynamic_texture_buffer::end() const { return begin() + component_count(); } inline dynamic_texture_buffer::iterator dynamic_texture_buffer::end() { return begin() + component_count(); } inline dynamic_texture_buffer::const_iterator dynamic_texture_buffer::cbegin() const { return const_cast(begin()); } inline dynamic_texture_buffer::const_iterator dynamic_texture_buffer::cend() const { return const_cast(begin()); }