1 /* FreeRDP: A Remote Desktop Protocol Client
2 * YCoCg<->RGB Color conversion operations.
3 * vi:ts=4 sw=4:
4 *
5 * (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <freerdp/types.h>
25 #include <freerdp/primitives.h>
26
27 #include "prim_internal.h"
28
29 /* ------------------------------------------------------------------------- */
general_YCoCgToRGB_8u_AC4R(const BYTE * pSrc,INT32 srcStep,BYTE * pDst,UINT32 DstFormat,INT32 dstStep,UINT32 width,UINT32 height,UINT8 shift,BOOL withAlpha)30 static pstatus_t general_YCoCgToRGB_8u_AC4R(const BYTE* pSrc, INT32 srcStep, BYTE* pDst,
31 UINT32 DstFormat, INT32 dstStep, UINT32 width,
32 UINT32 height, UINT8 shift, BOOL withAlpha)
33 {
34 BYTE A;
35 UINT32 x, y;
36 BYTE* dptr = pDst;
37 const BYTE* sptr = pSrc;
38 INT16 Cg, Co, Y, T, R, G, B;
39 const DWORD formatSize = GetBytesPerPixel(DstFormat);
40 fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, TRUE);
41 int cll = shift - 1; /* -1 builds in the /2's */
42 UINT32 srcPad = srcStep - (width * 4);
43 UINT32 dstPad = dstStep - (width * formatSize);
44
45 for (y = 0; y < height; y++)
46 {
47 for (x = 0; x < width; x++)
48 {
49 /* Note: shifts must be done before sign-conversion. */
50 Cg = (INT16)((INT8)((*sptr++) << cll));
51 Co = (INT16)((INT8)((*sptr++) << cll));
52 Y = (INT16)(*sptr++); /* UINT8->INT16 */
53 A = *sptr++;
54
55 if (!withAlpha)
56 A = 0xFFU;
57
58 T = Y - Cg;
59 B = T + Co;
60 G = Y + Cg;
61 R = T - Co;
62 dptr = writePixel(dptr, formatSize, DstFormat, CLIP(R), CLIP(G), CLIP(B), A);
63 }
64
65 sptr += srcPad;
66 dptr += dstPad;
67 }
68
69 return PRIMITIVES_SUCCESS;
70 }
71
72 /* ------------------------------------------------------------------------- */
primitives_init_YCoCg(primitives_t * prims)73 void primitives_init_YCoCg(primitives_t* prims)
74 {
75 prims->YCoCgToRGB_8u_AC4R = general_YCoCgToRGB_8u_AC4R;
76 }
77