Coverage Report

Created: 2025-07-01 06:46

/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
0
{
32
0
  const int cll = shift - 1; /* -1 builds in the /2's */
33
0
  return (INT16)((INT8)(raw << cll));
34
0
}
35
36
/* ------------------------------------------------------------------------- */
37
static pstatus_t general_YCoCgToRGB_8u_AC4R(const BYTE* WINPR_RESTRICT pSrc, INT32 srcStep,
38
                                            BYTE* WINPR_RESTRICT pDst, UINT32 DstFormat,
39
                                            INT32 dstStep, UINT32 width, UINT32 height, UINT8 shift,
40
                                            BOOL withAlpha)
41
0
{
42
0
  const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat);
43
0
  fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, TRUE);
44
45
0
  for (size_t y = 0; y < height; y++)
46
0
  {
47
0
    const BYTE* sptr = &pSrc[y * WINPR_ASSERTING_INT_CAST(uint32_t, srcStep)];
48
0
    BYTE* dptr = &pDst[y * WINPR_ASSERTING_INT_CAST(uint32_t, dstStep)];
49
0
    for (size_t x = 0; x < width; x++)
50
0
    {
51
      /* Note: shifts must be done before sign-conversion. */
52
0
      const INT16 Cg = convert(*sptr++, shift);
53
0
      const INT16 Co = convert(*sptr++, shift);
54
0
      const INT16 Y = *sptr++; /* UINT8->INT16 */
55
0
      const INT16 T = (INT16)(Y - Cg);
56
0
      const INT16 B = (INT16)(T + Co);
57
0
      const INT16 G = (INT16)(Y + Cg);
58
0
      const INT16 R = (INT16)(T - Co);
59
0
      BYTE A = *sptr++;
60
61
0
      if (!withAlpha)
62
0
        A = 0xFFU;
63
64
0
      dptr = writePixel(dptr, formatSize, DstFormat, CLIP(R), CLIP(G), CLIP(B), A);
65
0
    }
66
0
  }
67
68
0
  return PRIMITIVES_SUCCESS;
69
0
}
70
71
/* ------------------------------------------------------------------------- */
72
void primitives_init_YCoCg(primitives_t* WINPR_RESTRICT prims)
73
0
{
74
0
  prims->YCoCgToRGB_8u_AC4R = general_YCoCgToRGB_8u_AC4R;
75
0
}
76
77
void primitives_init_YCoCg_opt(primitives_t* WINPR_RESTRICT prims)
78
0
{
79
0
  primitives_init_YCoCg(prims);
80
0
  primitives_init_YCoCg_ssse3(prims);
81
0
  primitives_init_YCoCg_neon(prims);
82
0
}