<commit_before>/**
 * FreeRDP: A Remote Desktop Protocol Implementation
 * Color Conversion Routines
 *
 * Copyright 2010 <NAME> <<EMAIL>>
 * Copyright 2016 <NAME> <<EMAIL>>
 * Copyright 2016 Thincast Technologies GmbH
 *
 * 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.
 */

#ifndef FREERDP_CODEC_COLOR_H
#define FREERDP_CODEC_COLOR_H

#include <freerdp/api.h>
#include <winpr/wlog.h>
#include <freerdp/log.h>
#define CTAG FREERDP_TAG("codec.color")

#define FREERDP_PIXEL_FORMAT_TYPE_A		0
#define FREERDP_PIXEL_FORMAT_TYPE_ARGB		1
#define FREERDP_PIXEL_FORMAT_TYPE_ABGR		2
#define FREERDP_PIXEL_FORMAT_TYPE_RGBA		3
#define FREERDP_PIXEL_FORMAT_TYPE_BGRA		4

#define FREERDP_PIXEL_FORMAT_IS_ABGR(_format)	(FREERDP_PIXEL_FORMAT_TYPE(_format) == FREERDP_PIXEL_FORMAT_TYPE_ABGR)

#define FREERDP_FLIP_NONE			0
#define FREERDP_FLIP_VERTICAL		1
#define FREERDP_FLIP_HORIZONTAL		2

#define FREERDP_PIXEL_FORMAT(_bpp, _type, _a, _r, _g, _b) \
	((_bpp << 24) | (_type << 16) | (_a << 12) | (_r << 8) | (_g << 4) | (_b))

#define FREERDP_PIXEL_FORMAT_TYPE(_format)	(((_format) >> 16) & 0x07)

/*** Design considerations
 *
 * The format naming scheme is based on byte position in memory.
 * RGBA for example names a byte array with red on positon 0, green on 1 etc.
 *
 * To read and write the appropriate format from / to memory use ReadColor and
 * WriteColor.
 *
 * The single pixel manipulation functions use an intermediate integer representation
 * that must not be interpreted outside the functions as it is platform dependent.
 *
 * _VF denotes vertically flipped bitmaps.
 * X for alpha channel denotes unused (but existing) alpha channel data.
 */

/* 32bpp formats */
#define PIXEL_FORMAT_A8R8G8B8_F()	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 8, 8, 8, 8)

#define PIXEL_FORMAT_ARGB32		PIXEL_FORMAT_A8R8G8B8_F()

#define PIXEL_FORMAT_X8R8G8B8_F(_flip)	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8)
#define PIXEL_FORMAT_XRGB32		PIXEL_FORMAT_X8R8G8B8_F()

#define PIXEL_FORMAT_A8B8G8R8_F(_flip)	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 8, 8, 8, 8)
#define PIXEL_FORMAT_ABGR32		PIXEL_FORMAT_A8B8G8R8_F()

#define PIXEL_FORMAT_X8B8G8R8_F(_flip)	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8)
#define PIXEL_FORMAT_XBGR32		PIXEL_FORMAT_X8B8G8R8_F()

#define PIXEL_FORMAT_B8G8R8A8_F(_flip)	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 8, 8, 8, 8)
#define PIXEL_FORMAT_BGRA32		PIXEL_FORMAT_B8G8R8A8_F()

#define PIXEL_FORMAT_B8G8R8X8_F(_flip)	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 0, 8, 8, 8)
#define PIXEL_FORMAT_BGRX32		PIXEL_FORMAT_B8G8R8X8_F()

#define PIXEL_FORMAT_R8G8B8A8_F(_flip)	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 8, 8, 8, 8)
#define PIXEL_FORMAT_RGBA32		PIXEL_FORMAT_R8G8B8A8_F()

#define PIXEL_FORMAT_R8G8B8X8_F(_flip)	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 0, 8, 8, 8)
#define PIXEL_FORMAT_RGBX32		PIXEL_FORMAT_R8G8B8X8_F()

/* 24bpp formats */
#define PIXEL_FORMAT_R8G8B8_F(_flip)	FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8)
#define PIXEL_FORMAT_RGB24		PIXEL_FORMAT_R8G8B8_F()

#define PIXEL_FORMAT_B8G8R8_F(_flip)	FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8)
#define PIXEL_FORMAT_BGR24		PIXEL_FORMAT_B8G8R8_F()

/* 16bpp formats */
#define PIXEL_FORMAT_R5G6B5_F(_flip)	FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 6, 5)
#define PIXEL_FORMAT_RGB16		PIXEL_FORMAT_R5G6B5_F()

#define PIXEL_FORMAT_B5G6R5_F(_flip)	FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 6, 5)
#define PIXEL_FORMAT_BGR16		PIXEL_FORMAT_B5G6R5_F()

#define PIXEL_FORMAT_A1R5G5B5_F(_flip)	FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 1, 5, 5, 5)
#define PIXEL_FORMAT_ARGB15		PIXEL_FORMAT_A1R5G5B5_F()

#define PIXEL_FORMAT_X1R5G5B5_F(_flip)	FREERDP_PIXEL_FORMAT(15, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 5, 5)
#define PIXEL_FORMAT_RGB15		PIXEL_FORMAT_X1R5G5B5_F()

#define PIXEL_FORMAT_A1B5G5R5_F(_flip)	FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 1, 5, 5, 5)
#define PIXEL_FORMAT_ABGR15		PIXEL_FORMAT_A1B5G5R5_F()

#define PIXEL_FORMAT_X1B5G5R5_F(_flip)	FREERDP_PIXEL_FORMAT(15, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 5, 5)
#define PIXEL_FORMAT_BGR15		PIXEL_FORMAT_X1B5G5R5_F()

/* 8bpp formats */
#define PIXEL_FORMAT_A8_F(_flip)	FREERDP_PIXEL_FORMAT(8, FREERDP_PIXEL_FORMAT_TYPE_A, 8, 0, 0, 0)
#define PIXEL_FORMAT_RGB8		PIXEL_FORMAT_A8_F()

/* 4 bpp formats */
#define PIXEL_FORMAT_A4_F(_flip)	FREERDP_PIXEL_FORMAT(4, FREERDP_PIXEL_FORMAT_TYPE_A, 4, 0, 0, 0)
#define PIXEL_FORMAT_A4			PIXEL_FORMAT_A4_F()

/* 1bpp formats */
#define PIXEL_FORMAT_A1_F(_flip)	FREERDP_PIXEL_FORMAT(1, FREERDP_PIXEL_FORMAT_TYPE_A, 1, 0, 0, 0)
#define PIXEL_FORMAT_MONO		PIXEL_FORMAT_A1_F()

struct gdi_palette
{
	UINT32 format;
	UINT32 palette[256];
};
typedef struct gdi_palette gdiPalette;

#ifdef __cplusplus
extern "C" {<commit_msg>directly using FREERDP_PIXEL_FORMAT.<commit_after>/**
 * FreeRDP: A Remote Desktop Protocol Implementation
 * Color Conversion Routines
 *
 * Copyright 2010 <NAME> <<EMAIL>>
 * Copyright 2016 <NAME> <<EMAIL>>
 * Copyright 2016 Thincast Technologies GmbH
 *
 * 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.
 */

#ifndef FREERDP_CODEC_COLOR_H
#define FREERDP_CODEC_COLOR_H

#include <freerdp/api.h>
#include <winpr/wlog.h>
#include <freerdp/log.h>
#define CTAG FREERDP_TAG("codec.color")

#define FREERDP_PIXEL_FORMAT_TYPE_A		0
#define FREERDP_PIXEL_FORMAT_TYPE_ARGB		1
#define FREERDP_PIXEL_FORMAT_TYPE_ABGR		2
#define FREERDP_PIXEL_FORMAT_TYPE_RGBA		3
#define FREERDP_PIXEL_FORMAT_TYPE_BGRA		4

#define FREERDP_PIXEL_FORMAT_IS_ABGR(_format)	(FREERDP_PIXEL_FORMAT_TYPE(_format) == FREERDP_PIXEL_FORMAT_TYPE_ABGR)

#define FREERDP_FLIP_NONE			0
#define FREERDP_FLIP_VERTICAL		1
#define FREERDP_FLIP_HORIZONTAL		2

#define FREERDP_PIXEL_FORMAT(_bpp, _type, _a, _r, _g, _b) \
	((_bpp << 24) | (_type << 16) | (_a << 12) | (_r << 8) | (_g << 4) | (_b))

#define FREERDP_PIXEL_FORMAT_TYPE(_format)	(((_format) >> 16) & 0x07)

/*** Design considerations
 *
 * The format naming scheme is based on byte position in memory.
 * RGBA for example names a byte array with red on positon 0, green on 1 etc.
 *
 * To read and write the appropriate format from / to memory use ReadColor and
 * WriteColor.
 *
 * The single pixel manipulation functions use an intermediate integer representation
 * that must not be interpreted outside the functions as it is platform dependent.
 *
 * X for alpha channel denotes unused (but existing) alpha channel data.
 */

/* 32bpp formats */
#define PIXEL_FORMAT_ARGB32	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 8, 8, 8, 8)
#define PIXEL_FORMAT_XRGB32	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8)
#define PIXEL_FORMAT_ABGR32	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 8, 8, 8, 8)
#define PIXEL_FORMAT_XBGR32	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8)
#define PIXEL_FORMAT_BGRA32	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 8, 8, 8, 8)
#define PIXEL_FORMAT_BGRX32	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 0, 8, 8, 8)
#define PIXEL_FORMAT_RGBA32	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 8, 8, 8, 8)
#define PIXEL_FORMAT_RGBX32	FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 0, 8, 8, 8)

/* 24bpp formats */
#define PIXEL_FORMAT_RGB24	FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8)
#define PIXEL_FORMAT_BGR24	FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8)

/* 16bpp formats */
#define PIXEL_FORMAT_RGB16	FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 6, 5)
#define PIXEL_FORMAT_BGR16	FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 6, 5)
#define PIXEL_FORMAT_ARGB15	FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 1, 5, 5, 5)
#define PIXEL_FORMAT_RGB15	FREERDP_PIXEL_FORMAT(15, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 5, 5)
#define PIXEL_FORMAT_ABGR15	FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 1, 5, 5, 5)
#define PIXEL_FORMAT_BGR15	FREERDP_PIXEL_FORMAT(15, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 5, 5)

/* 8bpp formats */
#define PIXEL_FORMAT_RGB8	FREERDP_PIXEL_FORMAT(8, FREERDP_PIXEL_FORMAT_TYPE_A, 8, 0, 0, 0)

/* 4 bpp formats */
#define PIXEL_FORMAT_A4	FREERDP_PIXEL_FORMAT(4, FREERDP_PIXEL_FORMAT_TYPE_A, 4, 0, 0, 0)

/* 1bpp formats */
#define PIXEL_FORMAT_MONO	FREERDP_PIXEL_FORMAT(1, FREERDP_PIXEL_FORMAT_TYPE_A, 1, 0, 0, 0)

struct gdi_palette
{
	UINT32 format;
	UINT32 palette[256];
};
typedef struct gdi_palette gdiPalette;

#ifdef __cplusplus
extern "C" {
{'fraction_non_alphanumeric': 0.08596817524281876, 'fraction_numerical': 0.054350072328993596, 'mean_word_length': 6.57948316366484, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4413916', 'n_tokens_mistral': 4613, 'n_tokens_neox': 4265, 'n_words': 906}