Coverage Report

Created: 2024-09-08 06:18

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