<commit_before>#line 2 "togo/image/pixmap/pixmap.cpp"
/**
@copyright MIT license; see @ref index or the accompanying LICENSE file.
*/

#include <togo/image/config.hpp>
#include <togo/core/error/assert.hpp>
#include <togo/core/utility/utility.hpp>
#include <togo/core/math/math.hpp>
#include <togo/core/log/log.hpp>
#include <togo/core/memory/memory.hpp>
#include <togo/image/pixmap/pixmap.hpp>
#include <togo/image/pixmap/impl/private.ipp>

#include <cstring>

namespace togo {

PixelFormatInfo const pixel_format_info[]{
	{{1, 1, 1, 0}, {16, 8, 0, 0} , {0xFFu << 16, 0xFFu << 8 , 0xFFu << 0, 0}}, // rgb
	{{1, 1, 1, 0}, {24, 16, 8, 0}, {0xFFu << 24, 0xFFu << 16, 0xFFu << 8, 0}}, // rgbx
	{{1, 1, 1, 0}, {16, 8, 0, 0} , {0xFFu << 16, 0xFFu << 8 , 0xFFu << 0, 0}}, // xrgb
	{{1, 1, 1, 1}, {24, 16, 8, 0}, {0xFFu << 24, 0xFFu << 16, 0xFFu << 8, 0xFFu << 0}}, // rgba
	{{1, 1, 1, 1}, {16, 8, 0, 24}, {0xFFu << 16, 0xFFu << 8 , 0xFFu << 0, 0xFFu << 24}}, // argb
};

// Pixmap interface

Pixmap::~Pixmap() {
	pixmap::free(*this);
}

Pixmap::Pixmap(PixelFormat format)
	: data(nullptr)
	, data_capacity(0)
	, data_size(0)
	, size(0, 0)
	, format(format)
{}

Pixmap::Pixmap(PixelFormatID format_id)
	: data(nullptr)
	, data_capacity(0)
	, data_size(0)
	, size(0, 0)
	, format{format_id}
{}

Pixmap::Pixmap(UVec2 size, PixelFormat format)
	: data(nullptr)
	, data_capacity(0)
	, data_size(0)
	, size(0, 0)
	, format(format)
{
	pixmap::resize(*this, size);
}

Pixmap::Pixmap(UVec2 size, PixelFormatID format_id)
	: data(nullptr)
	, data_capacity(0)
	, data_size(0)
	, size(0, 0)
	, format{format_id}
{
	pixmap::resize(*this, size);
}

Pixmap::Pixmap(Pixmap&&) {
	pixmap::free(*this);
}

Pixmap& Pixmap::operator=(Pixmap&& other) {
	pixmap::free(*this);
	this->data = other.data;
	this->data_capacity = other.data_capacity;
	this->data_size = other.data_size;
	this->size = other.size;
	this->format = other.format;
	other.data = nullptr;
	other.data_capacity = 0;
	other.data_size = 0;
	other.size = UVec2{0, 0};
	return *this;
}

/// Resize.
///<commit_msg>lib/image/pixmap: use maop in mctor to initialize Pixmap.<commit_after>#line 2 "togo/image/pixmap/pixmap.cpp"
/**
@copyright MIT license; see @ref index or the accompanying LICENSE file.
*/

#include <togo/image/config.hpp>
#include <togo/core/error/assert.hpp>
#include <togo/core/utility/utility.hpp>
#include <togo/core/math/math.hpp>
#include <togo/core/log/log.hpp>
#include <togo/core/memory/memory.hpp>
#include <togo/image/pixmap/pixmap.hpp>
#include <togo/image/pixmap/impl/private.ipp>

#include <cstring>

namespace togo {

PixelFormatInfo const pixel_format_info[]{
	{{1, 1, 1, 0}, {16, 8, 0, 0} , {0xFFu << 16, 0xFFu << 8 , 0xFFu << 0, 0}}, // rgb
	{{1, 1, 1, 0}, {24, 16, 8, 0}, {0xFFu << 24, 0xFFu << 16, 0xFFu << 8, 0}}, // rgbx
	{{1, 1, 1, 0}, {16, 8, 0, 0} , {0xFFu << 16, 0xFFu << 8 , 0xFFu << 0, 0}}, // xrgb
	{{1, 1, 1, 1}, {24, 16, 8, 0}, {0xFFu << 24, 0xFFu << 16, 0xFFu << 8, 0xFFu << 0}}, // rgba
	{{1, 1, 1, 1}, {16, 8, 0, 24}, {0xFFu << 16, 0xFFu << 8 , 0xFFu << 0, 0xFFu << 24}}, // argb
};

// Pixmap interface

Pixmap::~Pixmap() {
	pixmap::free(*this);
}

Pixmap::Pixmap(PixelFormat format)
	: data(nullptr)
	, data_capacity(0)
	, data_size(0)
	, size(0, 0)
	, format(format)
{}

Pixmap::Pixmap(PixelFormatID format_id)
	: data(nullptr)
	, data_capacity(0)
	, data_size(0)
	, size(0, 0)
	, format{format_id}
{}

Pixmap::Pixmap(UVec2 size, PixelFormat format)
	: data(nullptr)
	, data_capacity(0)
	, data_size(0)
	, size(0, 0)
	, format(format)
{
	pixmap::resize(*this, size);
}

Pixmap::Pixmap(UVec2 size, PixelFormatID format_id)
	: data(nullptr)
	, data_capacity(0)
	, data_size(0)
	, size(0, 0)
	, format{format_id}
{
	pixmap::resize(*this, size);
}

Pixmap::Pixmap(Pixmap&& other) {
	*this = rvalue_ref(other);
}

Pixmap& Pixmap::operator=(Pixmap&& other) {
	pixmap::free(*this);
	this->data = other.data;
	this->data_capacity = other.data_capacity;
	this->data_size = other.data_size;
	this->size = other.size;
	this->format = other.format;
	other.data = nullptr;
	other.data_capacity = 0;
	other.data_size = 0;
	other.size = UVec2{0, 0};
	return *this;
}

/// Resize.
///
{'fraction_non_alphanumeric': 0.20562770562770563, 'fraction_numerical': 0.05627705627705628, 'mean_word_length': 4.238035264483627, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4217845', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1798, 'n_words': 391}