<commit_before>/*****************************************************************************
 * This file is part of gfxprim library.                                     *
 *                                                                           *
 * Gfxprim is free software; you can redistribute it and/or                  *
 * modify it under the terms of the GNU Lesser General Public                *
 * License as published by the Free Software Foundation; either              *
 * version 2.1 of the License, or (at your option) any later version.        *
 *                                                                           *
 * Gfxprim is distributed in the hope that it will be useful,                *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 * Lesser General Public License for more details.                           *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public          *
 * License along with gfxprim; if not, write to the Free Software            *
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,                        *
 * Boston, MA  02110-1301  USA                                               *
 *                                                                           *
 * Copyright (C) 2009-2013 <NAME> <<EMAIL>>                       *
 *                                                                           *
 *****************************************************************************/

#include "core/GP_Debug.h"
#include "GP_LineConvert.h"

static void xyz888_to_zyx888(const uint8_t *inbuf, uint8_t *outbuf, unsigned int len)
{
	unsigned int i;

	for (i = 0; i < len; i++) {
		outbuf[2] = inbuf[0];
		outbuf[0] = inbuf[2];
		outbuf[1] = inbuf[1];

		outbuf+=3;
		inbuf+=3;
	}
}

GP_LineConvert GP_LineConvertGet(GP_PixelType in, GP_PixelType out)
{
	switch (in) {
	case GP_PIXEL_RGB888:
		switch (out) {
		case GP_PIXEL_BGR888:
			return xyz888_to_zyx888;
		break;
		default:
		break;
		}
	break;
	case GP_PIXEL_BGR888:
		switch (out) {
		case GP_PIXEL_RGB888:
			return xyz888_to_zyx888;
		break;
		default:
		break;
		}
	break;
	default:
	break;
	}

	return NULL;
}

GP_PixelType GP_LineConvertible(GP_PixelType in, GP_PixelType out[])
{
	unsigned int i;

	GP_DEBUG(1, "Trying to find conversion for %s", GP_PixelTypeName(in));

	for (i = 0; out[i] != GP_PIXEL_UNKNOWN; i++) {
		if (GP_LineConvertGet(in, out[i])) {
			GP_DEBUG(1, "Found %s -> %s", GP_PixelTypeName(in),
			         GP_PixelTypeName(out[i]));
			return out[i];
		}
	}

	GP_DEBUG(1, "Not found");

	return GP_PIXEL_UNKNOWN;
}<commit_msg>loaders: LineConvert: Add more conversions.<commit_after>/*****************************************************************************
 * This file is part of gfxprim library.                                     *
 *                                                                           *
 * Gfxprim is free software; you can redistribute it and/or                  *
 * modify it under the terms of the GNU Lesser General Public                *
 * License as published by the Free Software Foundation; either              *
 * version 2.1 of the License, or (at your option) any later version.        *
 *                                                                           *
 * Gfxprim is distributed in the hope that it will be useful,                *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 * Lesser General Public License for more details.                           *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public          *
 * License along with gfxprim; if not, write to the Free Software            *
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,                        *
 * Boston, MA  02110-1301  USA                                               *
 *                                                                           *
 * Copyright (C) 2009-2013 <NAME> <<EMAIL>>                       *
 *                                                                           *
 *****************************************************************************/

#include "core/GP_Debug.h"
#include "GP_LineConvert.h"

static void ABC888_to_CBA888(const uint8_t *inbuf, uint8_t *outbuf,
                             unsigned int len)
{
	unsigned int i;

	for (i = 0; i < len; i++) {
		outbuf[2] = inbuf[0];
		outbuf[0] = inbuf[2];
		outbuf[1] = inbuf[1];

		outbuf+=3;
		inbuf+=3;
	}
}

static void xABC8888_to_ABC888(const uint8_t *inbuf, uint8_t *outbuf,
                               unsigned int len)
{
	unsigned int i;

	for (i = 0; i < len; i++) {
		outbuf[0] = inbuf[1];
		outbuf[1] = inbuf[2];
		outbuf[2] = inbuf[3];

		outbuf+=3;
		inbuf+=4;
	}
}

static void xABC8888_to_CBA888(const uint8_t *inbuf, uint8_t *outbuf,
                               unsigned int len)
{
	unsigned int i;

	for (i = 0; i < len; i++) {
		outbuf[0] = inbuf[3];
		outbuf[1] = inbuf[2];
		outbuf[2] = inbuf[1];

		outbuf+=3;
		inbuf+=4;
	}
}

GP_LineConvert GP_LineConvertGet(GP_PixelType in, GP_PixelType out)
{
	switch (in) {
	case GP_PIXEL_RGB888:
		switch (out) {
		case GP_PIXEL_BGR888:
			return ABC888_to_CBA888;
		break;
		default:
		break;
		}
	break;
	case GP_PIXEL_BGR888:
		switch (out) {
		case GP_PIXEL_RGB888:
			return ABC888_to_CBA888;
		break;
		default:
		break;
		}
	break;
	case GP_PIXEL_xRGB8888:
		switch (out) {
		case GP_PIXEL_RGB888:
			return xABC8888_to_ABC888;
		break;
		case GP_PIXEL_BGR888:
			return xABC8888_to_CBA888;
		break;
		default:
		break;
		}
	break;
	default:
	break;
	}

	return NULL;
}

GP_PixelType GP_LineConvertible(GP_PixelType in, GP_PixelType out[])
{
	unsigned int i;

	GP_DEBUG(1, "Trying to find conversion for %s", GP_PixelTypeName(in));


	for (i = 0; out[i] != GP_PIXEL_UNKNOWN; i++) {
		if (out[i] == in) {
			GP_DEBUG(1, "Found identity for %s", GP_PixelTypeName(in));
			return in;
		}
	}

	for (i = 0; out[i] != GP_PIXEL_UNKNOWN; i++) {
		if (GP_LineConvertGet(in, out[i])) {
			GP_DEBUG(1, "Found %s -> %s", GP_PixelTypeName(in),
			         GP_PixelTypeName(out[i]));
			return out[i];
		}
	}

	GP_DEBUG(1, "Not found");

	return GP_PIXEL_UNKNOWN;
}
{'fraction_non_alphanumeric': 0.13765120195988365, 'fraction_numerical': 0.029704486296126167, 'mean_word_length': 1.7376362112321877, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3686686', 'n_tokens_mistral': 2157, 'n_tokens_neox': 1913, 'n_words': 552}