2014-07-03 00:30:04 +04:00
|
|
|
/* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* YCoCg<->RGB Color conversion operations.
|
|
|
|
* vi:ts=4 sw=4:
|
|
|
|
*
|
|
|
|
* (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <freerdp/types.h>
|
|
|
|
#include <freerdp/primitives.h>
|
|
|
|
|
|
|
|
#include "prim_internal.h"
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2016-04-05 18:07:45 +03:00
|
|
|
static pstatus_t general_YCoCgToRGB_8u_AC4R(
|
2016-11-24 12:01:45 +03:00
|
|
|
const BYTE* pSrc, INT32 srcStep,
|
|
|
|
BYTE* pDst, UINT32 DstFormat, INT32 dstStep,
|
|
|
|
UINT32 width, UINT32 height,
|
|
|
|
UINT8 shift,
|
|
|
|
BOOL withAlpha)
|
2014-07-03 00:30:04 +04:00
|
|
|
{
|
2014-09-07 05:13:37 +04:00
|
|
|
BYTE A;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 x, y;
|
|
|
|
BYTE* dptr = pDst;
|
|
|
|
const BYTE* sptr = pSrc;
|
2014-09-07 05:13:37 +04:00
|
|
|
INT16 Cg, Co, Y, T, R, G, B;
|
2016-11-24 12:01:45 +03:00
|
|
|
const DWORD formatSize = GetBytesPerPixel(DstFormat);
|
2016-11-25 14:00:41 +03:00
|
|
|
fkt_writePixel writePixel = getPixelWriteFunction(DstFormat);
|
2014-07-03 00:30:04 +04:00
|
|
|
int cll = shift - 1; /* -1 builds in the /2's */
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 srcPad = srcStep - (width * 4);
|
2016-11-24 12:01:45 +03:00
|
|
|
UINT32 dstPad = dstStep - (width * formatSize);
|
2014-09-07 05:13:37 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
for (y = 0; y < height; y++)
|
2014-07-03 00:30:04 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
for (x = 0; x < width; x++)
|
2014-07-03 00:30:04 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
/* Note: shifts must be done before sign-conversion. */
|
|
|
|
Cg = (INT16)((INT8)((*sptr++) << cll));
|
|
|
|
Co = (INT16)((INT8)((*sptr++) << cll));
|
|
|
|
Y = (INT16)(*sptr++); /* UINT8->INT16 */
|
|
|
|
A = *sptr++;
|
|
|
|
|
|
|
|
if (!withAlpha)
|
|
|
|
A = 0xFFU;
|
|
|
|
|
|
|
|
T = Y - Cg;
|
|
|
|
R = T + Co;
|
|
|
|
G = Y + Cg;
|
|
|
|
B = T - Co;
|
2017-01-12 17:30:06 +03:00
|
|
|
dptr = (*writePixel)(dptr, formatSize, DstFormat, CLIP(R),
|
|
|
|
CLIP(G), CLIP(B), A);
|
2014-07-03 00:30:04 +04:00
|
|
|
}
|
2014-09-07 05:13:37 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
sptr += srcPad;
|
|
|
|
dptr += dstPad;
|
2014-07-03 00:30:04 +04:00
|
|
|
}
|
2014-09-07 05:13:37 +04:00
|
|
|
|
2014-07-03 00:30:04 +04:00
|
|
|
return PRIMITIVES_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
void primitives_init_YCoCg(primitives_t* prims)
|
|
|
|
{
|
2014-09-07 05:13:37 +04:00
|
|
|
prims->YCoCgToRGB_8u_AC4R = general_YCoCgToRGB_8u_AC4R;
|
2014-07-03 00:30:04 +04:00
|
|
|
}
|