Coverage Report

Created: 2024-09-08 06:16

/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* pSrc, INT32 srcStep, BYTE* pDst,
38
                                            UINT32 DstFormat, INT32 dstStep, UINT32 width,
39
                                            UINT32 height, UINT8 shift, BOOL withAlpha)
40
0
{
41
0
  const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat);
42
0
  fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, TRUE);
43
44
0
  for (size_t y = 0; y < height; y++)
45
0
  {
46
0
    const BYTE* sptr = &pSrc[y * srcStep];
47
0
    BYTE* dptr = &pDst[y * dstStep];
48
0
    for (size_t x = 0; x < width; x++)
49
0
    {
50
      /* Note: shifts must be done before sign-conversion. */
51
0
      const INT16 Cg = convert(*sptr++, shift);
52
0
      const INT16 Co = convert(*sptr++, shift);
53
0
      const INT16 Y = *sptr++; /* UINT8->INT16 */
54
0
      const INT16 T = Y - Cg;
55
0
      const INT16 B = T + Co;
56
0
      const INT16 G = Y + Cg;
57
0
      const INT16 R = T - Co;
58
0
      BYTE A = *sptr++;
59
60
0
      if (!withAlpha)
61
0
        A = 0xFFU;
62
63
0
      dptr = writePixel(dptr, formatSize, DstFormat, CLIP(R), CLIP(G), CLIP(B), A);
64
0
    }
65
0
  }
66
67
0
  return PRIMITIVES_SUCCESS;
68
0
}
69
70
/* ------------------------------------------------------------------------- */
71
void primitives_init_YCoCg(primitives_t* prims)
72
0
{
73
0
  prims->YCoCgToRGB_8u_AC4R = general_YCoCgToRGB_8u_AC4R;
74
0
}
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
}