/src/FreeRDP/libfreerdp/primitives/prim_YCoCg.c
Line | Count | Source |
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 | | #include <freerdp/config.h> |
21 | | |
22 | | #include <freerdp/types.h> |
23 | | #include <freerdp/primitives.h> |
24 | | |
25 | | #include "prim_internal.h" |
26 | | |
27 | | /* helper function to convert raw 8 bit values to signed 16bit values. |
28 | | */ |
29 | | static INT16 convert(UINT8 raw, int shift) |
30 | 2.50M | { |
31 | 2.50M | const int cll = shift - 1; /* -1 builds in the /2's */ |
32 | 2.50M | return (INT16)((INT8)(raw << cll)); |
33 | 2.50M | } |
34 | | |
35 | | /* ------------------------------------------------------------------------- */ |
36 | | static pstatus_t general_YCoCgToRGB_8u_AC4R(const BYTE* pSrc, INT32 srcStep, BYTE* pDst, |
37 | | UINT32 DstFormat, INT32 dstStep, UINT32 width, |
38 | | UINT32 height, UINT8 shift, BOOL withAlpha) |
39 | 640 | { |
40 | 640 | const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat); |
41 | 640 | fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, TRUE); |
42 | | |
43 | 27.3k | for (UINT32 y = 0; y < height; y++) |
44 | 26.6k | { |
45 | 26.6k | const BYTE* sptr = &pSrc[srcStep * y]; |
46 | 26.6k | BYTE* dptr = &pDst[dstStep * y]; |
47 | 1.27M | for (UINT32 x = 0; x < width; x++) |
48 | 1.25M | { |
49 | | /* Note: shifts must be done before sign-conversion. */ |
50 | 1.25M | const INT16 Cg = convert(*sptr++, shift); |
51 | 1.25M | const INT16 Co = convert(*sptr++, shift); |
52 | 1.25M | const INT16 Y = *sptr++; /* UINT8->INT16 */ |
53 | 1.25M | const INT16 T = Y - Cg; |
54 | 1.25M | const INT16 B = T + Co; |
55 | 1.25M | const INT16 G = Y + Cg; |
56 | 1.25M | const INT16 R = T - Co; |
57 | 1.25M | BYTE A = *sptr++; |
58 | | |
59 | 1.25M | if (!withAlpha) |
60 | 1.25M | A = 0xFFU; |
61 | | |
62 | 1.25M | dptr = writePixel(dptr, formatSize, DstFormat, CLIP(R), CLIP(G), CLIP(B), A); |
63 | 1.25M | } |
64 | 26.6k | } |
65 | | |
66 | 640 | return PRIMITIVES_SUCCESS; |
67 | 640 | } |
68 | | |
69 | | /* ------------------------------------------------------------------------- */ |
70 | | void primitives_init_YCoCg(primitives_t* prims) |
71 | 1 | { |
72 | 1 | prims->YCoCgToRGB_8u_AC4R = general_YCoCgToRGB_8u_AC4R; |
73 | 1 | } |