Blame libfreerdp/primitives/prim_YCoCg.c

Packit 1fb8d4
/* FreeRDP: A Remote Desktop Protocol Client
Packit 1fb8d4
 * YCoCg<->RGB Color conversion operations.
Packit 1fb8d4
 * vi:ts=4 sw=4:
Packit 1fb8d4
 *
Packit 1fb8d4
 * (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
Packit 1fb8d4
 *
Packit 1fb8d4
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit 1fb8d4
 * you may not use this file except in compliance with the License.
Packit 1fb8d4
 * You may obtain a copy of the License at
Packit 1fb8d4
 *
Packit 1fb8d4
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 1fb8d4
 *
Packit 1fb8d4
 * Unless required by applicable law or agreed to in writing, software
Packit 1fb8d4
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1fb8d4
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 1fb8d4
 * See the License for the specific language governing permissions and
Packit 1fb8d4
 * limitations under the License.
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#ifdef HAVE_CONFIG_H
Packit 1fb8d4
#include "config.h"
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#include <freerdp/types.h>
Packit 1fb8d4
#include <freerdp/primitives.h>
Packit 1fb8d4
Packit 1fb8d4
#include "prim_internal.h"
Packit 1fb8d4
Packit 1fb8d4
/* ------------------------------------------------------------------------- */
Packit 1fb8d4
static pstatus_t general_YCoCgToRGB_8u_AC4R(
Packit 1fb8d4
    const BYTE* pSrc, INT32 srcStep,
Packit 1fb8d4
    BYTE* pDst, UINT32 DstFormat, INT32 dstStep,
Packit 1fb8d4
    UINT32 width, UINT32 height,
Packit 1fb8d4
    UINT8 shift,
Packit 1fb8d4
    BOOL withAlpha)
Packit 1fb8d4
{
Packit 1fb8d4
	BYTE A;
Packit 1fb8d4
	UINT32 x, y;
Packit 1fb8d4
	BYTE* dptr = pDst;
Packit 1fb8d4
	const BYTE* sptr = pSrc;
Packit 1fb8d4
	INT16 Cg, Co, Y, T, R, G, B;
Packit 1fb8d4
	const DWORD formatSize = GetBytesPerPixel(DstFormat);
Packit 1fb8d4
	fkt_writePixel writePixel = getPixelWriteFunction(DstFormat);
Packit 1fb8d4
	int cll = shift - 1;  /* -1 builds in the /2's */
Packit 1fb8d4
	UINT32 srcPad = srcStep - (width * 4);
Packit 1fb8d4
	UINT32 dstPad = dstStep - (width * formatSize);
Packit 1fb8d4
Packit 1fb8d4
	for (y = 0; y < height; y++)
Packit 1fb8d4
	{
Packit 1fb8d4
		for (x = 0; x < width; x++)
Packit 1fb8d4
		{
Packit 1fb8d4
			/* Note: shifts must be done before sign-conversion. */
Packit 1fb8d4
			Cg = (INT16)((INT8)((*sptr++) << cll));
Packit 1fb8d4
			Co = (INT16)((INT8)((*sptr++) << cll));
Packit 1fb8d4
			Y = (INT16)(*sptr++);	/* UINT8->INT16 */
Packit 1fb8d4
			A = *sptr++;
Packit 1fb8d4
Packit 1fb8d4
			if (!withAlpha)
Packit 1fb8d4
				A = 0xFFU;
Packit 1fb8d4
Packit 1fb8d4
			T  = Y - Cg;
Packit 1fb8d4
			R  = T + Co;
Packit 1fb8d4
			G  = Y + Cg;
Packit 1fb8d4
			B  = T - Co;
Packit 1fb8d4
			dptr = (*writePixel)(dptr, formatSize, DstFormat, CLIP(R),
Packit 1fb8d4
			                     CLIP(G), CLIP(B), A);
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		sptr += srcPad;
Packit 1fb8d4
		dptr += dstPad;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return PRIMITIVES_SUCCESS;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
/* ------------------------------------------------------------------------- */
Packit 1fb8d4
void primitives_init_YCoCg(primitives_t* prims)
Packit 1fb8d4
{
Packit 1fb8d4
	prims->YCoCgToRGB_8u_AC4R = general_YCoCgToRGB_8u_AC4R;
Packit 1fb8d4
}