Spaces:
Runtime error
Runtime error
/* | |
* AltiVec-enhanced yuv2yuvX | |
* | |
* Copyright (C) 2004 Romain Dolbeau <[email protected]> | |
* based on the equivalent C code in swscale.c | |
* | |
* This file is part of FFmpeg. | |
* | |
* FFmpeg is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU Lesser General Public | |
* License as published by the Free Software Foundation; either | |
* version 2.1 of the License, or (at your option) any later version. | |
* | |
* FFmpeg is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
* Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public | |
* License along with FFmpeg; if not, write to the Free Software | |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
// The 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2). | |
// The neat trick: We only care for half the elements, | |
// high or low depending on (i<<3)%16 (it's 0 or 8 here), | |
// and we're going to use vec_mule, so we choose | |
// carefully how to "unpack" the elements into the even slots. | |
static void | |
yuv2plane1_float_u(const int32_t *src, float *dest, int dstW, int start) | |
{ | |
static const int big_endian = HAVE_BIGENDIAN; | |
static const int shift = 3; | |
static const float float_mult = 1.0f / 65535.0f; | |
int i, val; | |
uint16_t val_uint; | |
for (i = start; i < dstW; ++i){ | |
val = src[i] + (1 << (shift - 1)); | |
output_pixel(&val_uint, val, 0, uint); | |
dest[i] = float_mult * (float)val_uint; | |
} | |
} | |
static void | |
yuv2plane1_float_bswap_u(const int32_t *src, uint32_t *dest, int dstW, int start) | |
{ | |
static const int big_endian = HAVE_BIGENDIAN; | |
static const int shift = 3; | |
static const float float_mult = 1.0f / 65535.0f; | |
int i, val; | |
uint16_t val_uint; | |
for (i = start; i < dstW; ++i){ | |
val = src[i] + (1 << (shift - 1)); | |
output_pixel(&val_uint, val, 0, uint); | |
dest[i] = av_bswap32(av_float2int(float_mult * (float)val_uint)); | |
} | |
} | |
static void yuv2plane1_float_altivec(const int32_t *src, float *dest, int dstW) | |
{ | |
const int dst_u = -(uintptr_t)dest & 3; | |
const int shift = 3; | |
const int add = (1 << (shift - 1)); | |
const int clip = (1 << 16) - 1; | |
const float fmult = 1.0f / 65535.0f; | |
const vec_u32 vadd = (vec_u32) {add, add, add, add}; | |
const vec_u32 vshift = (vec_u32) vec_splat_u32(shift); | |
const vec_u32 vlargest = (vec_u32) {clip, clip, clip, clip}; | |
const vec_f vmul = (vec_f) {fmult, fmult, fmult, fmult}; | |
const vec_f vzero = (vec_f) {0, 0, 0, 0}; | |
vec_u32 v; | |
vec_f vd; | |
int i; | |
yuv2plane1_float_u(src, dest, dst_u, 0); | |
for (i = dst_u; i < dstW - 3; i += 4) { | |
v = vec_ld(0, (const uint32_t *) &src[i]); | |
v = vec_add(v, vadd); | |
v = vec_sr(v, vshift); | |
v = vec_min(v, vlargest); | |
vd = vec_ctf(v, 0); | |
vd = vec_madd(vd, vmul, vzero); | |
vec_st(vd, 0, &dest[i]); | |
} | |
yuv2plane1_float_u(src, dest, dstW, i); | |
} | |
static void yuv2plane1_float_bswap_altivec(const int32_t *src, uint32_t *dest, int dstW) | |
{ | |
const int dst_u = -(uintptr_t)dest & 3; | |
const int shift = 3; | |
const int add = (1 << (shift - 1)); | |
const int clip = (1 << 16) - 1; | |
const float fmult = 1.0f / 65535.0f; | |
const vec_u32 vadd = (vec_u32) {add, add, add, add}; | |
const vec_u32 vshift = (vec_u32) vec_splat_u32(shift); | |
const vec_u32 vlargest = (vec_u32) {clip, clip, clip, clip}; | |
const vec_f vmul = (vec_f) {fmult, fmult, fmult, fmult}; | |
const vec_f vzero = (vec_f) {0, 0, 0, 0}; | |
const vec_u32 vswapbig = (vec_u32) {16, 16, 16, 16}; | |
const vec_u16 vswapsmall = vec_splat_u16(8); | |
vec_u32 v; | |
vec_f vd; | |
int i; | |
yuv2plane1_float_bswap_u(src, dest, dst_u, 0); | |
for (i = dst_u; i < dstW - 3; i += 4) { | |
v = vec_ld(0, (const uint32_t *) &src[i]); | |
v = vec_add(v, vadd); | |
v = vec_sr(v, vshift); | |
v = vec_min(v, vlargest); | |
vd = vec_ctf(v, 0); | |
vd = vec_madd(vd, vmul, vzero); | |
vd = (vec_f) vec_rl((vec_u32) vd, vswapbig); | |
vd = (vec_f) vec_rl((vec_u16) vd, vswapsmall); | |
vec_st(vd, 0, (float *) &dest[i]); | |
} | |
yuv2plane1_float_bswap_u(src, dest, dstW, i); | |
} | |
yuv2plane1_float(yuv2plane1_float_altivec, float, BE) | |
yuv2plane1_float(yuv2plane1_float_bswap_altivec, uint32_t, LE) | |
yuv2plane1_float(yuv2plane1_float_altivec, float, LE) | |
yuv2plane1_float(yuv2plane1_float_bswap_altivec, uint32_t, BE) | |
av_cold void ff_sws_init_swscale_ppc(SwsContext *c) | |
{ | |
enum AVPixelFormat dstFormat = c->dstFormat; | |
if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) | |
return; | |
if (c->srcBpc == 8 && c->dstBpc <= 14) { | |
c->hyScale = c->hcScale = hScale_real_altivec; | |
} | |
if (!is16BPS(dstFormat) && !isNBPS(dstFormat) && !isSemiPlanarYUV(dstFormat) && | |
dstFormat != AV_PIX_FMT_GRAYF32BE && dstFormat != AV_PIX_FMT_GRAYF32LE && | |
!c->needAlpha) { | |
c->yuv2planeX = yuv2planeX_altivec; | |
} | |
if (dstFormat == AV_PIX_FMT_GRAYF32BE) { | |
c->yuv2plane1 = yuv2plane1_floatBE_altivec; | |
} else if (dstFormat == AV_PIX_FMT_GRAYF32LE) { | |
c->yuv2plane1 = yuv2plane1_floatLE_altivec; | |
} | |
/* The following list of supported dstFormat values should | |
* match what's found in the body of ff_yuv2packedX_altivec() */ | |
if (!(c->flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->needAlpha) { | |
switch (c->dstFormat) { | |
case AV_PIX_FMT_ABGR: | |
c->yuv2packedX = ff_yuv2abgr_X_altivec; | |
break; | |
case AV_PIX_FMT_BGRA: | |
c->yuv2packedX = ff_yuv2bgra_X_altivec; | |
break; | |
case AV_PIX_FMT_ARGB: | |
c->yuv2packedX = ff_yuv2argb_X_altivec; | |
break; | |
case AV_PIX_FMT_RGBA: | |
c->yuv2packedX = ff_yuv2rgba_X_altivec; | |
break; | |
case AV_PIX_FMT_BGR24: | |
c->yuv2packedX = ff_yuv2bgr24_X_altivec; | |
break; | |
case AV_PIX_FMT_RGB24: | |
c->yuv2packedX = ff_yuv2rgb24_X_altivec; | |
break; | |
} | |
} | |
ff_sws_init_swscale_vsx(c); | |
} | |