/src/FreeRDP/libfreerdp/primitives/prim_add.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* FreeRDP: A Remote Desktop Protocol Client |
2 | | * Add 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 | | |
17 | | #include <freerdp/config.h> |
18 | | |
19 | | #include <freerdp/types.h> |
20 | | #include <freerdp/primitives.h> |
21 | | |
22 | | #include "prim_internal.h" |
23 | | |
24 | | /* ---------------------------------------------------------------------------- |
25 | | * 16-bit signed add with saturation (under and over). |
26 | | */ |
27 | | static pstatus_t general_add_16s(const INT16* pSrc1, const INT16* pSrc2, INT16* pDst, UINT32 len) |
28 | 0 | { |
29 | 0 | while (len--) |
30 | 0 | { |
31 | 0 | INT32 k = (INT32)(*pSrc1++) + (INT32)(*pSrc2++); |
32 | |
|
33 | 0 | if (k > 32767) |
34 | 0 | *pDst++ = ((INT16)32767); |
35 | 0 | else if (k < -32768) |
36 | 0 | *pDst++ = ((INT16)-32768); |
37 | 0 | else |
38 | 0 | *pDst++ = (INT16)k; |
39 | 0 | } |
40 | |
|
41 | 0 | return PRIMITIVES_SUCCESS; |
42 | 0 | } |
43 | | |
44 | | /* ------------------------------------------------------------------------- */ |
45 | | void primitives_init_add(primitives_t* prims) |
46 | 1 | { |
47 | 1 | prims->add_16s = general_add_16s; |
48 | 1 | } |