/src/FreeRDP/libfreerdp/primitives/prim_shift.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* FreeRDP: A Remote Desktop Protocol Client |
2 | | * Shift operations. |
3 | | * vi:ts=4 sw=4: |
4 | | * |
5 | | * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. |
6 | | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
7 | | * not use this file except in compliance with the License. You may obtain |
8 | | * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. |
9 | | * Unless required by applicable law or agreed to in writing, software |
10 | | * distributed under the License is distributed on an "AS IS" BASIS, |
11 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
12 | | * or implied. See the License for the specific language governing |
13 | | * permissions and limitations under the License. |
14 | | */ |
15 | | |
16 | | #include <freerdp/config.h> |
17 | | |
18 | | #include <freerdp/types.h> |
19 | | #include <freerdp/primitives.h> |
20 | | |
21 | | #include "prim_internal.h" |
22 | | /* ------------------------------------------------------------------------- */ |
23 | | static INLINE pstatus_t general_lShiftC_16s(const INT16* pSrc, UINT32 val, INT16* pDst, UINT32 len) |
24 | 0 | { |
25 | 0 | if (val == 0) |
26 | 0 | return PRIMITIVES_SUCCESS; |
27 | 0 | if (val >= 16) |
28 | 0 | return -1; |
29 | | |
30 | 0 | while (len--) |
31 | 0 | *pDst++ = (INT16)((UINT16)*pSrc++ << val); |
32 | |
|
33 | 0 | return PRIMITIVES_SUCCESS; |
34 | 0 | } |
35 | | |
36 | | /* ------------------------------------------------------------------------- */ |
37 | | static INLINE pstatus_t general_rShiftC_16s(const INT16* pSrc, UINT32 val, INT16* pDst, UINT32 len) |
38 | 0 | { |
39 | 0 | if (val == 0) |
40 | 0 | return PRIMITIVES_SUCCESS; |
41 | 0 | if (val >= 16) |
42 | 0 | return -1; |
43 | | |
44 | 0 | while (len--) |
45 | 0 | *pDst++ = *pSrc++ >> val; |
46 | |
|
47 | 0 | return PRIMITIVES_SUCCESS; |
48 | 0 | } |
49 | | |
50 | | /* ------------------------------------------------------------------------- */ |
51 | | static INLINE pstatus_t general_lShiftC_16u(const UINT16* pSrc, UINT32 val, UINT16* pDst, |
52 | | UINT32 len) |
53 | 0 | { |
54 | 0 | if (val == 0) |
55 | 0 | return PRIMITIVES_SUCCESS; |
56 | 0 | if (val >= 16) |
57 | 0 | return -1; |
58 | | |
59 | 0 | while (len--) |
60 | 0 | *pDst++ = (INT16)((UINT16)*pSrc++ << val); |
61 | |
|
62 | 0 | return PRIMITIVES_SUCCESS; |
63 | 0 | } |
64 | | |
65 | | /* ------------------------------------------------------------------------- */ |
66 | | static INLINE pstatus_t general_rShiftC_16u(const UINT16* pSrc, UINT32 val, UINT16* pDst, |
67 | | UINT32 len) |
68 | 0 | { |
69 | 0 | if (val == 0) |
70 | 0 | return PRIMITIVES_SUCCESS; |
71 | 0 | if (val >= 16) |
72 | 0 | return -1; |
73 | | |
74 | 0 | while (len--) |
75 | 0 | *pDst++ = *pSrc++ >> val; |
76 | |
|
77 | 0 | return PRIMITIVES_SUCCESS; |
78 | 0 | } |
79 | | |
80 | | /* ------------------------------------------------------------------------- */ |
81 | | static INLINE pstatus_t general_shiftC_16s(const INT16* pSrc, INT32 val, INT16* pDst, UINT32 len) |
82 | 0 | { |
83 | 0 | if (val == 0) |
84 | 0 | return PRIMITIVES_SUCCESS; |
85 | | |
86 | 0 | if (val < 0) |
87 | 0 | return general_rShiftC_16s(pSrc, -val, pDst, len); |
88 | 0 | else |
89 | 0 | return general_lShiftC_16s(pSrc, val, pDst, len); |
90 | 0 | } |
91 | | |
92 | | /* ------------------------------------------------------------------------- */ |
93 | | static INLINE pstatus_t general_shiftC_16u(const UINT16* pSrc, INT32 val, UINT16* pDst, UINT32 len) |
94 | 0 | { |
95 | 0 | if (val == 0) |
96 | 0 | return PRIMITIVES_SUCCESS; |
97 | | |
98 | 0 | if (val < 0) |
99 | 0 | return general_rShiftC_16u(pSrc, -val, pDst, len); |
100 | 0 | else |
101 | 0 | return general_lShiftC_16u(pSrc, val, pDst, len); |
102 | 0 | } |
103 | | |
104 | | /* ------------------------------------------------------------------------- */ |
105 | | void primitives_init_shift(primitives_t* prims) |
106 | 1 | { |
107 | | /* Start with the default. */ |
108 | 1 | prims->lShiftC_16s = general_lShiftC_16s; |
109 | 1 | prims->rShiftC_16s = general_rShiftC_16s; |
110 | 1 | prims->lShiftC_16u = general_lShiftC_16u; |
111 | 1 | prims->rShiftC_16u = general_rShiftC_16u; |
112 | | /* Wrappers */ |
113 | 1 | prims->shiftC_16s = general_shiftC_16s; |
114 | 1 | prims->shiftC_16u = general_shiftC_16u; |
115 | 1 | } |