<commit_before>#include "ImageX11.h"
#include <algorithm>
#include "../ResourceManager.h"
#include "../../components/NullImage.h"
#include "../../log.h"

namespace {

tk::ResourceManagerSingleton resourceManager;

}

namespace tk {

namespace image {

char * duplicateBuffer(Params const & params) {
	auto totalBytesDest = params.dimensions_.area() * 4;
	char * result = static_cast<char *>(malloc(totalBytesDest));
	if( params.buffer_ ) {
		auto src = params.buffer_;
		auto dst = result;
		switch( params.type_ ) {
		case Type::BGRA:
			std::copy(src,src+totalBytesDest,dst);
			break;
		case Type::RGBA:
			for( size_t p = 0; p < params.dimensions_.area(); ++p ) {
				*dst++ = *(src+2);
				*dst++ = *(src+1);
				*dst++ = *src;
				*dst++ = *(src+3);
				src += 4;
			}
			break;
		case Type::RGB:
			for( size_t p = 0; p < params.dimensions_.area(); ++p ) {
				*dst++ = *(src+2);
				*dst++ = *(src+1);
				*dst++ = *src;
				*dst++ = 255;
				src += 3;
			}
			break;
		case Type::BGR:
			for( size_t p = 0; p < params.dimensions_.area(); ++p ) {
				*dst++ = *src++;
				*dst++ = *src++;
				*dst++ = *src++;
				*dst++ = 255;
			}
			break;
		case Type::gray:
			for( size_t p = 0; p < params.dimensions_.area(); ++p ) {
				*dst++ = *src;
				*dst++ = *src;
				*dst++ = *src;
				*dst++ = 255;
				++src;
			}
			break;
		default:
			log::error("image type not supported: ",static_cast<int>(params.type_));
		}
	}
	return result;
}

// nearest neighbor
int nnb(int d, int dLen, int sLen) {
	return d * sLen / dLen;
}
<commit_msg>ImageX11 - buffer is properly zeroed<commit_after>#include "ImageX11.h"
#include <algorithm>
#include "../ResourceManager.h"
#include "../../components/NullImage.h"
#include "../../log.h"

namespace {

tk::ResourceManagerSingleton resourceManager;

}

namespace tk {

namespace image {

char * duplicateBuffer(Params const & params) {
	auto totalBytesDest = params.dimensions_.area() * 4;
	char * result = static_cast<char *>(malloc(totalBytesDest));
	if( params.buffer_ ) {
		auto src = params.buffer_;
		auto dst = result;
		switch( params.type_ ) {
		case Type::BGRA:
			std::copy(src,src+totalBytesDest,dst);
			break;
		case Type::RGBA:
			for( size_t p = 0; p < params.dimensions_.area(); ++p ) {
				*dst++ = *(src+2);
				*dst++ = *(src+1);
				*dst++ = *src;
				*dst++ = *(src+3);
				src += 4;
			}
			break;
		case Type::RGB:
			for( size_t p = 0; p < params.dimensions_.area(); ++p ) {
				*dst++ = *(src+2);
				*dst++ = *(src+1);
				*dst++ = *src;
				*dst++ = 255;
				src += 3;
			}
			break;
		case Type::BGR:
			for( size_t p = 0; p < params.dimensions_.area(); ++p ) {
				*dst++ = *src++;
				*dst++ = *src++;
				*dst++ = *src++;
				*dst++ = 255;
			}
			break;
		case Type::gray:
			for( size_t p = 0; p < params.dimensions_.area(); ++p ) {
				*dst++ = *src;
				*dst++ = *src;
				*dst++ = *src;
				*dst++ = 255;
				++src;
			}
			break;
		default:
			log::error("image type not supported: ",static_cast<int>(params.type_));
		}
	} else {
		// image buffer default will have black transparent pixels
		std::fill(result,result+totalBytesDest,0);
	}
	return result;
}

// nearest neighbor
int nnb(int d, int dLen, int sLen) {
	return d * sLen / dLen;
}

{'fraction_non_alphanumeric': 0.2008692952499224, 'fraction_numerical': 0.015212666873641726, 'mean_word_length': 2.9436964504283964, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, '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': '1867458', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1226, 'n_words': 296}