Blame libfreerdp/primitives/primitives.cl

Packit Service 5a9772
/**
Packit Service 5a9772
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit Service 5a9772
 * Optimized operations using openCL
Packit Service 5a9772
 * vi:ts=4 sw=4
Packit Service 5a9772
 *
Packit Service 5a9772
 * Copyright 2019 David Fort <contact@hardening-consulting.com>
Packit Service 5a9772
 * Copyright 2019 Rangee Gmbh
Packit Service 5a9772
 *
Packit Service 5a9772
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Packit Service 5a9772
 * not use this file except in compliance with the License. You may obtain
Packit Service 5a9772
 * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
Packit Service 5a9772
 * Unless required by applicable law or agreed to in writing, software
Packit Service 5a9772
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit Service 5a9772
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
Packit Service 5a9772
 * or implied. See the License for the specific language governing
Packit Service 5a9772
 * permissions and limitations under the License.
Packit Service 5a9772
 */
Packit Service 5a9772
Packit Service 5a9772
#define STRINGIFY(x) #x
Packit Service 5a9772
Packit Service 5a9772
STRINGIFY(
Packit Service 5a9772
uchar clamp_uc(int v, short l, short h)
Packit Service 5a9772
{
Packit Service 5a9772
    if (v > h)
Packit Service 5a9772
        v = h;
Packit Service 5a9772
    if (v < l)
Packit Service 5a9772
        v = l;
Packit Service 5a9772
    return (uchar)v;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
__kernel void yuv420_to_argb_1b(
Packit Service 5a9772
	__global const uchar *bufY, int strideY,
Packit Service 5a9772
	__global const uchar *bufU, int strideU,
Packit Service 5a9772
	__global const uchar *bufV, int strideV,
Packit Service 5a9772
	__global uchar *dest, int strideDest)
Packit Service 5a9772
{
Packit Service 5a9772
	unsigned int x = get_global_id(0);
Packit Service 5a9772
	unsigned int y = get_global_id(1);
Packit Service 5a9772
Packit Service 5a9772
	short Y = bufY[y * strideY + x];
Packit Service 5a9772
	short Udim = bufU[(y / 2) * strideU + (x / 2)] - 128;
Packit Service 5a9772
	short Vdim = bufV[(y / 2) * strideV + (x / 2)] - 128;
Packit Service 5a9772
Packit Service 5a9772
	__global uchar *destPtr = dest + (strideDest * y) + (x * 4);
Packit Service 5a9772
Packit Service 5a9772
	/**
Packit Service 5a9772
	 * | R |   ( | 256     0    403 | |    Y    | )
Packit Service 5a9772
	 * | G | = ( | 256   -48   -120 | | U - 128 | ) >> 8
Packit Service 5a9772
	 * | B |   ( | 256   475      0 | | V - 128 | )
Packit Service 5a9772
	 */
Packit Service 5a9772
	int y256 = 256 * Y;
Packit Service 5a9772
	destPtr[0] = 0xff; /* A */
Packit Service 5a9772
	destPtr[1] = clamp_uc((y256 + (403 * Vdim)) >> 8, 0, 255); /* R */
Packit Service 5a9772
	destPtr[2] = clamp_uc((y256 - (48 * Udim) - (120 * Vdim)) >> 8 , 0, 255); /* G */
Packit Service 5a9772
	destPtr[3] = clamp_uc((y256 + (475 * Udim)) >> 8, 0, 255); /* B */
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
__kernel void yuv420_to_bgra_1b(
Packit Service 5a9772
	__global const uchar *bufY, int strideY,
Packit Service 5a9772
	__global const uchar *bufU, int strideU,
Packit Service 5a9772
	__global const uchar *bufV, int strideV,
Packit Service 5a9772
	__global uchar *dest, int strideDest)
Packit Service 5a9772
{
Packit Service 5a9772
	unsigned int x = get_global_id(0);
Packit Service 5a9772
	unsigned int y = get_global_id(1);
Packit Service 5a9772
Packit Service 5a9772
	short Y = bufY[y * strideY + x];
Packit Service 5a9772
	short U = bufU[(y / 2) * strideU + (x / 2)] - 128;
Packit Service 5a9772
	short V = bufV[(y / 2) * strideV + (x / 2)] - 128;
Packit Service 5a9772
Packit Service 5a9772
	__global uchar *destPtr = dest + (strideDest * y) + (x * 4);
Packit Service 5a9772
Packit Service 5a9772
	/**
Packit Service 5a9772
	 * | R |   ( | 256     0    403 | |    Y    | )
Packit Service 5a9772
	 * | G | = ( | 256   -48   -120 | | U - 128 | ) >> 8
Packit Service 5a9772
	 * | B |   ( | 256   475      0 | | V - 128 | )
Packit Service 5a9772
	 */
Packit Service 5a9772
	int y256 = 256 * Y;
Packit Service 5a9772
	destPtr[0] = clamp_uc((y256 + (475 * U)) >> 8, 0, 255); /* B */
Packit Service 5a9772
	destPtr[1] = clamp_uc((y256 - ( 48 * U) - (120 * V)) >> 8 , 0, 255);	/* G */
Packit Service 5a9772
	destPtr[2] = clamp_uc((y256 + (403 * V)) >> 8, 0, 255); 	/* R */
Packit Service 5a9772
	destPtr[3] = 0xff; /* A */
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
__kernel void yuv444_to_bgra_1b(
Packit Service 5a9772
	__global const uchar *bufY, int strideY,
Packit Service 5a9772
	__global const uchar *bufU, int strideU,
Packit Service 5a9772
	__global const uchar *bufV, int strideV,
Packit Service 5a9772
	__global uchar *dest, int strideDest)
Packit Service 5a9772
{
Packit Service 5a9772
	unsigned int x = get_global_id(0);
Packit Service 5a9772
	unsigned int y = get_global_id(1);
Packit Service 5a9772
Packit Service 5a9772
	short Y = bufY[y * strideY + x];
Packit Service 5a9772
	short U = bufU[y * strideU + x] - 128;
Packit Service 5a9772
	short V = bufV[y * strideV + x] - 128;
Packit Service 5a9772
Packit Service 5a9772
	__global uchar *destPtr = dest + (strideDest * y) + (x * 4);
Packit Service 5a9772
Packit Service 5a9772
	/**
Packit Service 5a9772
	 * | R |   ( | 256     0    403 | |    Y    | )
Packit Service 5a9772
	 * | G | = ( | 256   -48   -120 | | U - 128 | ) >> 8
Packit Service 5a9772
	 * | B |   ( | 256   475      0 | | V - 128 | )
Packit Service 5a9772
	 */
Packit Service 5a9772
	int y256 = 256 * Y;
Packit Service 5a9772
	destPtr[0] = clamp_uc((y256 + (475 * U)) >> 8, 0, 255); /* B */
Packit Service 5a9772
	destPtr[1] = clamp_uc((y256 - ( 48 * U) - (120 * V)) >> 8 , 0, 255);	/* G */
Packit Service 5a9772
	destPtr[2] = clamp_uc((y256 + (403 * V)) >> 8, 0, 255); 	/* R */
Packit Service 5a9772
	destPtr[3] = 0xff; /* A */
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
__kernel void yuv444_to_argb_1b(
Packit Service 5a9772
	__global const uchar *bufY, int strideY,
Packit Service 5a9772
	__global const uchar *bufU, int strideU,
Packit Service 5a9772
	__global const uchar *bufV, int strideV,
Packit Service 5a9772
	__global uchar *dest, int strideDest)
Packit Service 5a9772
{
Packit Service 5a9772
	unsigned int x = get_global_id(0);
Packit Service 5a9772
	unsigned int y = get_global_id(1);
Packit Service 5a9772
Packit Service 5a9772
	short Y = bufY[y * strideY + x];
Packit Service 5a9772
	short U = bufU[y * strideU + x] - 128;
Packit Service 5a9772
	short V = bufV[y * strideV + x] - 128;
Packit Service 5a9772
Packit Service 5a9772
	__global uchar *destPtr = dest + (strideDest * y) + (x * 4);
Packit Service 5a9772
Packit Service 5a9772
	/**
Packit Service 5a9772
	 * | R |   ( | 256     0    403 | |    Y    | )
Packit Service 5a9772
	 * | G | = ( | 256   -48   -120 | | U - 128 | ) >> 8
Packit Service 5a9772
	 * | B |   ( | 256   475      0 | | V - 128 | )
Packit Service 5a9772
	 */
Packit Service 5a9772
	int y256 = 256 * Y;
Packit Service 5a9772
	destPtr[3] = clamp_uc((y256 + (475 * U)) >> 8, 0, 255); /* B */
Packit Service 5a9772
	destPtr[2] = clamp_uc((y256 - ( 48 * U) - (120 * V)) >> 8 , 0, 255);	/* G */
Packit Service 5a9772
	destPtr[1] = clamp_uc((y256 + (403 * V)) >> 8, 0, 255); 	/* R */
Packit Service 5a9772
	destPtr[0] = 0xff; /* A */
Packit Service 5a9772
}
Packit Service 5a9772
)